|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.business.ProductCategoryDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.UpdateProductCategoryDTO;
|
|
|
import cn.cslg.pas.common.model.cronModel.*;
|
|
|
import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
@@ -61,6 +62,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
|
|
|
@Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private PermissionService permissionService;
|
|
|
|
|
@@ -69,6 +71,15 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
List<String> sqls = formatQueryService.reSqls(queryRequest,"productCategory");
|
|
|
//根据sql查询产品类别信息
|
|
|
List<ProductCategoryVO> productCategoryVOS = productCategoryMapper.getProductCategory(sqls.get(0),sqls.get(1),sqls.get(2));
|
|
|
+ productCategoryVOS.forEach(item -> {
|
|
|
+ Integer showType = item.getShowType();
|
|
|
+ LambdaQueryWrapper<AssoProductCategoryPerson> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AssoProductCategoryPerson::getProductCategoryId, item.getId());
|
|
|
+ queryWrapper.eq(AssoProductCategoryPerson::getRole,showType);
|
|
|
+ List<AssoProductCategoryPerson> assoProductCategoryPeople = assoProductCategoryPersonService.list(queryWrapper);
|
|
|
+ List<Integer> showPersonIds = assoProductCategoryPeople.stream().map(AssoProductCategoryPerson::getPersonId).collect(Collectors.toList());
|
|
|
+ item.setShowPersonIds(showPersonIds);
|
|
|
+ });
|
|
|
//查询总数
|
|
|
Long total = productCategoryMapper.getProductCategoryCount(sqls.get(0));
|
|
|
//装载产品类别信息
|
|
@@ -111,11 +122,13 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
//产品类别入表
|
|
|
ProductCategory productCategory = new ProductCategory();
|
|
|
BeanUtils.copyProperties(productCategoryDTO, productCategory);
|
|
|
+ productCategory.setCreateId(personnelVO.getId());
|
|
|
+ productCategory.setTenant(personnelVO.getTenantId());
|
|
|
productCategory.insert();
|
|
|
//判断可见类型:
|
|
|
Integer showType = productCategoryDTO.getShowType();
|
|
|
if(showType != 0 && showType != 1){
|
|
|
- List<Integer> showPersonIds = productCategoryDTO.getShowPersonId();
|
|
|
+ List<Integer> showPersonIds = productCategoryDTO.getShowPersonIds();
|
|
|
//0所有人可见,1本人可见
|
|
|
if(showPersonIds !=null && showPersonIds.size() != 0){
|
|
|
List<AssoProductCategoryPerson> assoProductCategoryPeople = new ArrayList<>();
|
|
@@ -196,27 +209,56 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
|
|
|
@Override
|
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
//object to productCategory
|
|
|
- ProductCategoryDTO productCategoryDTO = (ProductCategoryDTO)object;
|
|
|
+ UpdateProductCategoryDTO updateProductCategoryDTO = (UpdateProductCategoryDTO)object;
|
|
|
+ if(updateProductCategoryDTO == null || updateProductCategoryDTO.getId() == null){
|
|
|
+ throw new XiaoShiException("参数错误");
|
|
|
+ }
|
|
|
+ ProductCategory productCategory = this.getById(updateProductCategoryDTO.getId());
|
|
|
//检测名称是否不规范
|
|
|
- productCategoryDTO.setName(productCategoryDTO.getName().trim());
|
|
|
+ updateProductCategoryDTO.setName(updateProductCategoryDTO.getName().trim());
|
|
|
//根据名称查询数据库中是否存在
|
|
|
- String name = productCategoryDTO.getName();
|
|
|
+ String name = updateProductCategoryDTO.getName();
|
|
|
LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(ProductCategory::getName, name);
|
|
|
List<ProductCategory> productCategories = this.list(queryWrapper);
|
|
|
- if (productCategories == null && productCategories.size() == 0) {
|
|
|
- return null;
|
|
|
+ if(updateProductCategoryDTO.getName() == productCategory.getName() && productCategories.size() != 0){
|
|
|
+ throw new XiaoShiException("名称重复");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(updateProductCategoryDTO, productCategory);
|
|
|
+ productCategory.updateById();
|
|
|
+ //根据产品类别id查询对应的附件id
|
|
|
+ LambdaQueryWrapper<AssoProductCategoryFile> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AssoProductCategoryFile::getProductCategoryId, updateProductCategoryDTO.getId());
|
|
|
+ List<AssoProductCategoryFile> assoFiles = assoProductCategoryFileService.list(wrapper);
|
|
|
+ List<String> fileGuIds = assoFiles.stream().map(AssoProductCategoryFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ //获取更新后的附件ids
|
|
|
+ List<String> updateFileGuIds = new ArrayList<>();
|
|
|
+ if(updateProductCategoryDTO.getGuids() != null && updateProductCategoryDTO.getGuids().size() != 0){
|
|
|
+ updateFileGuIds = updateProductCategoryDTO.getGuids();
|
|
|
+ }
|
|
|
+ fileGuIds.retainAll(updateFileGuIds);
|
|
|
+ //做差获得被删除的文件id
|
|
|
+ if(fileGuIds.size() != 0){
|
|
|
+ //根据文件id删除产品类别与文件关联表记录
|
|
|
+ LambdaQueryWrapper<AssoProductCategoryFile> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
+ deleteWrapper.in(AssoProductCategoryFile::getFileGuid, fileGuIds);
|
|
|
+ assoProductCategoryFileService.remove(deleteWrapper);
|
|
|
+
|
|
|
+ //远程删除服务器上传文件
|
|
|
+ try{
|
|
|
+ fileManagerService.deleteFileFromFMS(fileGuIds);
|
|
|
+ } catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
//获取登陆人信息 用于设置创建人
|
|
|
- PersonnelVO personnelVO;
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
try {
|
|
|
personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
} catch (Exception e) {
|
|
|
throw new UnLoginException("未登录");
|
|
|
}
|
|
|
- ProductCategory productCategory = this.getById(productCategoryDTO.getId());
|
|
|
- BeanUtils.copyProperties(productCategoryDTO, productCategory);
|
|
|
- productCategory.insert();
|
|
|
+ //添加文件
|
|
|
if (files != null && files.size() != 0) {
|
|
|
try {
|
|
|
List<String> guids = fileManagerService.uploadFileGetGuid(files);
|