|
@@ -1,8 +1,6 @@
|
|
|
package com.kingtom.shengtai.api.controller;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
@@ -13,12 +11,15 @@ import com.kingtom.kirin.api.system.model.SystemUserDTO;
|
|
|
import com.kingtom.kirin.app.security.base.SessionData;
|
|
|
import com.kingtom.kirin.app.system.SystemConst;
|
|
|
import com.kingtom.kirin.app.system.model.SystemUser;
|
|
|
+import com.kingtom.kirin.core.common.CommonConst;
|
|
|
import com.kingtom.kirin.core.common.base.PageInfo;
|
|
|
import com.kingtom.kirin.core.common.base.Result;
|
|
|
import com.kingtom.kirin.core.common.utils.CollectionUtils;
|
|
|
import com.kingtom.kirin.core.common.utils.JsonUtils;
|
|
|
import com.kingtom.shengtai.api.mapper.SrmMapper;
|
|
|
import com.kingtom.shengtai.api.model.SrmSupplierDTO;
|
|
|
+import com.kingtom.shengtai.app.product.model.ProductDir;
|
|
|
+import com.kingtom.shengtai.app.product.service.IProductDirService;
|
|
|
import com.kingtom.shengtai.app.srm.model.SrmSupplier;
|
|
|
import com.kingtom.shengtai.app.srm.model.SrmSupplierDO;
|
|
|
import com.kingtom.shengtai.app.srm.service.ISrmSupplierService;
|
|
@@ -27,6 +28,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -44,10 +46,14 @@ public class SrmSupplierController{
|
|
|
@Autowired
|
|
|
private ISrmSupplierService iSrmSupplierService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IProductDirService productDirService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加供应商信息表。
|
|
|
*
|
|
|
- * @param dto 供应商信息表
|
|
|
+ * @param dto
|
|
|
+ * 供应商信息表
|
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
|
*/
|
|
|
@Operation(summary = "添加供应商信息表。", description = "添加供应商信息表。")
|
|
@@ -62,7 +68,8 @@ public class SrmSupplierController{
|
|
|
/**
|
|
|
* 根据主键删除供应商信息表。
|
|
|
*
|
|
|
- * @param id 主键
|
|
|
+ * @param id
|
|
|
+ * 主键
|
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
|
*/
|
|
|
@Parameter(name = "id", description = "主键", in = ParameterIn.PATH, required = true)
|
|
@@ -77,7 +84,8 @@ public class SrmSupplierController{
|
|
|
/**
|
|
|
* 根据主键删除供应商信息表。
|
|
|
*
|
|
|
- * @param ids 主键
|
|
|
+ * @param ids
|
|
|
+ * 主键
|
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
|
*/
|
|
|
@Operation(summary = "根据主键批量删除供应商信息表。", description = "根据主键批量删除供应商信息表。")
|
|
@@ -91,7 +99,8 @@ public class SrmSupplierController{
|
|
|
/**
|
|
|
* 根据主键更新供应商信息表。
|
|
|
*
|
|
|
- * @param dto 供应商信息表
|
|
|
+ * @param dto
|
|
|
+ * 供应商信息表
|
|
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
|
|
*/
|
|
|
@Parameter(name = "id", description = "", in = ParameterIn.PATH, required = true)
|
|
@@ -99,16 +108,20 @@ public class SrmSupplierController{
|
|
|
@PostMapping("/{id}/info")
|
|
|
@SaCheckPermission(value = {"AuthMenu:srm_supplier:Execute"})
|
|
|
public Result<SrmSupplierDTO> update(@RequestBody SrmSupplierDTO dto, @PathVariable String id){
|
|
|
- SrmSupplier convert = SrmMapper.INSTANCE.convert(dto);
|
|
|
- convert.setId(id);
|
|
|
- SrmSupplierDO supplierDO = iSrmSupplierService.update(convert);
|
|
|
+ //只能更新评分和类型
|
|
|
+ SrmSupplier update = new SrmSupplier();
|
|
|
+ update.setId(id);
|
|
|
+ update.setMark(dto.getMark());
|
|
|
+ update.setType(dto.getType());
|
|
|
+ SrmSupplierDO supplierDO = iSrmSupplierService.update(update);
|
|
|
return Result.ok(SrmSupplierDTO.convert(supplierDO));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据供应商信息表主键获取详细信息。
|
|
|
*
|
|
|
- * @param id 供应商信息表主键
|
|
|
+ * @param id
|
|
|
+ * 供应商信息表主键
|
|
|
* @return 供应商信息表详情
|
|
|
*/
|
|
|
@Parameter(name = "id", description = "供应商信息表主键", in = ParameterIn.PATH, required = true)
|
|
@@ -123,9 +136,12 @@ public class SrmSupplierController{
|
|
|
/**
|
|
|
* 分页查询供应商信息表。
|
|
|
*
|
|
|
- * @param query 查询条件
|
|
|
- * @param pageNum 当前页码
|
|
|
- * @param pageSize 每页数量
|
|
|
+ * @param query
|
|
|
+ * 查询条件
|
|
|
+ * @param pageNum
|
|
|
+ * 当前页码
|
|
|
+ * @param pageSize
|
|
|
+ * 每页数量
|
|
|
* @return 分页对象
|
|
|
*/
|
|
|
@Operation(summary = "分页查询供应商信息表。", description = "分页查询供应商信息表。")
|
|
@@ -137,8 +153,8 @@ public class SrmSupplierController{
|
|
|
String type = object.get("type") instanceof String ? object.get("type").toString() : null;
|
|
|
String state = object.get("state") instanceof String ? object.get("state").toString() : null;
|
|
|
List<String> products = object.get("products") instanceof Collection<?> ?
|
|
|
- ((Collection<?>) object.get("products")).stream().map(e -> e instanceof String ? ((String) e) : null)
|
|
|
- .collect(Collectors.toList()) : null;
|
|
|
+ ((Collection<?>)object.get("products")).stream().map(e -> e instanceof String ? ((String)e) : null)
|
|
|
+ .collect(Collectors.toList()) : null;
|
|
|
Page<SrmSupplierDO> page = iSrmSupplierService.page(name, type, state, products, pageNum, pageSize);
|
|
|
return Result.ok(CollectionUtils.convertPage(page, SrmSupplierDTO::convert));
|
|
|
}
|
|
@@ -171,4 +187,53 @@ public class SrmSupplierController{
|
|
|
return Result.ok(null);
|
|
|
}
|
|
|
|
|
|
+ @Operation(description = "供应商修改自己的供应商信息")
|
|
|
+ @PostMapping("/self/info")
|
|
|
+ @SaCheckRole(value = {"supplier"})
|
|
|
+ public Result<SrmSupplierDTO> updateSelf(@RequestBody SrmSupplierDTO dto){
|
|
|
+ SessionData sessionData = SaSecurityUtils.findSessionData();
|
|
|
+ String userId = sessionData.getUserId();
|
|
|
+ SrmSupplier supplier = iSrmSupplierService.findByPerson(userId);
|
|
|
+ if(supplier == null){
|
|
|
+ return Result.fail("没有找到供应商信息");
|
|
|
+ }
|
|
|
+ SrmSupplier convert = SrmMapper.INSTANCE.convert(dto);
|
|
|
+ convert.setId(supplier.getId());
|
|
|
+ //不能更新评分和类型
|
|
|
+ convert.setMark(null);
|
|
|
+ convert.setType(null);
|
|
|
+ //兼容移动端不能发送字符串数组问题
|
|
|
+ if(StringUtils.isNotEmpty(dto.getImageStr())){
|
|
|
+ List<String> images = Arrays.asList(dto.getImageStr().split(CommonConst.COMMA_STRING));
|
|
|
+ convert.setImage(JsonUtils.toJson(images));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(dto.getProductStr())){
|
|
|
+ List<String> products = Arrays.asList(dto.getProductStr().split(CommonConst.COMMA_STRING));
|
|
|
+ convert.setProduct(JsonUtils.toJson(products));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(dto.getCertificatesStr())){
|
|
|
+ List<String> certificates = Arrays.asList(dto.getCertificatesStr().split(CommonConst.COMMA_STRING));
|
|
|
+ convert.setCertificates(JsonUtils.toJson(certificates));
|
|
|
+ }
|
|
|
+ SrmSupplierDO update = iSrmSupplierService.update(convert);
|
|
|
+ return Result.ok(SrmMapper.INSTANCE.convert(update.getSupplier()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(description = "供应商移动端首页,获取自己的优势产品")
|
|
|
+ @GetMapping("/self/product/info")
|
|
|
+ @SaCheckRole(value = {"supplier"})
|
|
|
+ public Result<LinkedHashMap<String, String>> getSelfProducts(){
|
|
|
+ SessionData sessionData = SaSecurityUtils.findSessionData();
|
|
|
+ String userId = sessionData.getUserId();
|
|
|
+ SrmSupplier supplier = iSrmSupplierService.findByPerson(userId);
|
|
|
+ if(supplier == null){
|
|
|
+ return Result.fail("没有找到供应商信息");
|
|
|
+ }
|
|
|
+ List<String> productIds = JsonUtils.toObjectList(supplier.getProduct(), String.class);
|
|
|
+ List<ProductDir> dirs = productDirService.findByIds(productIds);
|
|
|
+ LinkedHashMap<String,String> map = new LinkedHashMap<>(dirs.size());
|
|
|
+ dirs.forEach(e-> map.put(e.getCode(),e.getName()));
|
|
|
+ return Result.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
}
|