Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

lwhhszx vor 1 Jahr
Ursprung
Commit
4334f6fddf

+ 1 - 1
src/main/java/cn/cslg/pas/service/business/CustomFieldService.java

@@ -276,7 +276,7 @@ public class CustomFieldService extends ServiceImpl<CustomFieldMapper, CustomFie
             AllCustomFieldVO allCustomFieldVO = allCustomFieldVOS.stream().filter(i -> i.getId().equals(item.getId()) && i.getType().equals(item.getTreeType())).findFirst().orElse(null);
             if (allCustomFieldVO == null) {
                 allCustomFieldVO = new AllCustomFieldVO();
-                allCustomFieldVO.setId(item.getId());
+                allCustomFieldVO.setId(item.getFieldId());
                 allCustomFieldVO.setSysOrder(order);
                 //1产品类别,2产品,3技术分类,4自定义树
                 switch (item.getTreeType()) {

+ 54 - 47
src/main/java/cn/cslg/pas/service/business/ProductCategoryService.java

@@ -26,6 +26,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -35,6 +36,7 @@ import java.util.stream.Collectors;
 
 /**
  * 产品类别的Service层
+ *
  * @Author xiexiang
  * @Date 2023/10/24
  */
@@ -70,16 +72,17 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
 
     /**
      * 查询产品类别
+     *
      * @param queryRequest
      * @return
      * @throws Exception
      */
     @Override
     public Object queryMessage(QueryRequest queryRequest) throws Exception {
-        List<String> sqls = formatQueryService.reSqls(queryRequest,"productCategory");
+        List<String> sqls = formatQueryService.reSqls(queryRequest, "productCategory");
         sqls = this.loadSearchSql(sqls);
         //根据sql查询产品类别信息
-        List<ProductCategoryVO> productCategoryVOS = productCategoryMapper.getProductCategory(sqls.get(0),sqls.get(1),sqls.get(2));
+        List<ProductCategoryVO> productCategoryVOS = productCategoryMapper.getProductCategory(sqls.get(0), sqls.get(1), sqls.get(2));
         //查询总数
         Long total = productCategoryMapper.getProductCategoryCount(sqls.get(0));
         //装载产品类别信息
@@ -95,6 +98,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
 
     /**
      * 新增产品类别
+     *
      * @param object
      * @param files
      * @return
@@ -103,17 +107,17 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
     public Object addMessage(Object object, List<MultipartFile> files) {
         //获取登陆人信息 用于设置创建人
         PersonnelVO personnelVO = new PersonnelVO();
-            personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
 
         //object to productCategoryDTO
-        ProductCategoryDTO productCategoryDTO = (ProductCategoryDTO)object;
+        ProductCategoryDTO productCategoryDTO = (ProductCategoryDTO) object;
         //检测名称是否不规范
         productCategoryDTO.setName(productCategoryDTO.getName().trim());
         //根据名称查询数据库中是否存在
         String name = productCategoryDTO.getName();
         LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ProductCategory::getName, name)
-                .eq(ProductCategory::getTenant,personnelVO.getTenantId());
+                .eq(ProductCategory::getTenant, personnelVO.getTenantId());
         List<ProductCategory> productCategories = this.list(queryWrapper);
         if (productCategories != null && productCategories.size() != 0) {
             throw new XiaoShiException("名称重复");
@@ -135,20 +139,22 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         assoProductCategoryPeople.add(assoProductCategoryAdmin);
         //设置的管理员
         List<String> adminIds = productCategoryDTO.getAdminIds();
-        for (String adminId : adminIds) {
-            AssoProductCategoryPerson admin = new AssoProductCategoryPerson();
-            admin.setProductCategoryId(productCategory.getId());
-            admin.setPersonId(adminId);
-            admin.setRole(0);
-            admin.setCreateId(personnelVO.getId());
-            assoProductCategoryPeople.add(admin);
+        if (!CollectionUtils.isEmpty(adminIds)) {
+            for (String adminId : adminIds) {
+                AssoProductCategoryPerson admin = new AssoProductCategoryPerson();
+                admin.setProductCategoryId(productCategory.getId());
+                admin.setPersonId(adminId);
+                admin.setRole(0);
+                admin.setCreateId(personnelVO.getId());
+                assoProductCategoryPeople.add(admin);
+            }
         }
         //判断可见类型:
         Integer showType = productCategoryDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = productCategoryDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds.size() != 0){
+            if (!CollectionUtils.isEmpty(showPersonIds)) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductCategoryPerson assoProductCategoryPerson = new AssoProductCategoryPerson();
                     assoProductCategoryPerson.setProductCategoryId(productCategory.getId());
@@ -166,7 +172,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
                 }
             }
         }
-        if(assoProductCategoryPeople != null && assoProductCategoryPeople.size() != 0){
+        if (!CollectionUtils.isEmpty(assoProductCategoryPeople)) {
             assoProductCategoryPersonService.saveBatch(assoProductCategoryPeople);
         }
         //判断文件是否为空
@@ -182,7 +188,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
                     assoProductCategoryFile.setCreateId(personnelVO.getId());
                     assoProductCategoryFiles.add(assoProductCategoryFile);
                 }
-                if (assoProductCategoryFiles != null && assoProductCategoryFiles.size() != 0) {
+                if (!CollectionUtils.isEmpty(assoProductCategoryFiles)) {
                     assoProductCategoryFileService.saveBatch(assoProductCategoryFiles);
                 }
             } catch (Exception e) {
@@ -195,6 +201,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
 
     /**
      * 删除产品类别
+     *
      * @param ids
      * @return
      */
@@ -229,6 +236,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
 
     /**
      * 更新产品类别
+     *
      * @param object
      * @param files
      * @return
@@ -236,14 +244,14 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
     @Override
     public Object updateMessage(Object object, List<MultipartFile> files) {
         //object to productCategory
-        UpdateProductCategoryDTO updateProductCategoryDTO = (UpdateProductCategoryDTO)object;
-        if(updateProductCategoryDTO == null || updateProductCategoryDTO.getId() == null){
+        UpdateProductCategoryDTO updateProductCategoryDTO = (UpdateProductCategoryDTO) object;
+        if (updateProductCategoryDTO == null || updateProductCategoryDTO.getId() == null) {
             throw new XiaoShiException("参数错误");
         }
         //获取登陆人信息 用于设置创建人
         PersonnelVO personnelVO = new PersonnelVO();
 
-            personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
 
         ProductCategory productCategory = this.getById(updateProductCategoryDTO.getId());
         //检测名称是否不规范
@@ -253,7 +261,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         LambdaQueryWrapper<ProductCategory> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ProductCategory::getName, name);
         List<ProductCategory> productCategories = this.list(queryWrapper);
-        if(!updateProductCategoryDTO.getName().equals(productCategory.getName()) && productCategories.size() != 0){
+        if (!updateProductCategoryDTO.getName().equals(productCategory.getName()) && productCategories.size() != 0) {
             throw new XiaoShiException("名称重复");
         }
         BeanUtils.copyProperties(updateProductCategoryDTO, productCategory);
@@ -285,10 +293,10 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         }
         //判断可见类型:
         Integer showType = updateProductCategoryDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = updateProductCategoryDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds != null && showPersonIds.size() != 0){
+            if (showPersonIds != null && showPersonIds.size() != 0) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductCategoryPerson assoProductCategoryPerson = new AssoProductCategoryPerson();
                     assoProductCategoryPerson.setProductCategoryId(productCategory.getId());
@@ -306,7 +314,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
                 }
             }
         }
-        if(assoProductCategoryPeople != null && assoProductCategoryPeople.size() != 0){
+        if (assoProductCategoryPeople != null && assoProductCategoryPeople.size() != 0) {
             assoProductCategoryPersonService.saveBatch(assoProductCategoryPeople);
         }
         /**
@@ -319,20 +327,20 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         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){
+        if (updateProductCategoryDTO.getGuids() != null && updateProductCategoryDTO.getGuids().size() != 0) {
             updateFileGuIds = updateProductCategoryDTO.getGuids();
             fileGuIds.retainAll(updateFileGuIds);
         }
         //做差获得被删除的文件id
-        if(fileGuIds.size() != 0){
+        if (fileGuIds.size() != 0) {
             //根据文件id删除产品类别与文件关联表记录
             LambdaQueryWrapper<AssoProductCategoryFile> deleteWrapper = new LambdaQueryWrapper<>();
             deleteWrapper.in(AssoProductCategoryFile::getFileGuid, fileGuIds);
             assoProductCategoryFileService.remove(deleteWrapper);
             //远程删除服务器上的文件
-            try{
+            try {
                 fileManagerService.deleteFileFromFMS(fileGuIds);
-            } catch (Exception e){
+            } catch (Exception e) {
 
             }
         }
@@ -359,7 +367,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
     }
 
     @Override
-    public GroupVO getGroup(GroupRequest groupRequest,String name) throws Exception {
+    public GroupVO getGroup(GroupRequest groupRequest, String name) throws Exception {
         return null;
     }
 
@@ -375,6 +383,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
 
     /**
      * 装载产品类别
+     *
      * @param productCategoryVOS
      * @throws IOException
      */
@@ -383,7 +392,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         List<Integer> ids = new ArrayList<>();
         productCategoryVOS.forEach(
                 item -> {
-                    if(item.getCreateId() != null){
+                    if (item.getCreateId() != null) {
                         createIds.add(item.getCreateId());
                     }
                     if (item.getId() != null) {
@@ -414,7 +423,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         //查询文件
         if (guids.size() != 0) {
             String res = fileManagerService.getSystemFileFromFMS(guids);
-            if(res!=null&&!res.trim().equals("")) {
+            if (res != null && !res.trim().equals("")) {
                 systemFiles = JSONObject.parseArray(res, SystemFile.class);
             }
         }
@@ -423,14 +432,14 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         for (ProductCategoryVO productCategoryVO : productCategoryVOS) {
             //装载人员信息
             Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productCategoryVO.getCreateId())).findFirst().orElse(null);
-            if(personnel != null){
+            if (personnel != null) {
                 productCategoryVO.setCreateName(personnel.getPersonnelName());
             } else {
                 throw new XiaoShiException("未获取到当前登陆人信息");
             }
             //装载文件信息
             List<AssoProductCategoryFile> assoProductCategoryFilesTemp = assoProductCategoryFiles.stream().filter(item -> item.getProductCategoryId().equals(productCategoryVO.getId())).collect(Collectors.toList());
-            if(assoProductCategoryFilesTemp.size() != 0){
+            if (assoProductCategoryFilesTemp.size() != 0) {
                 List<String> guidTemp = assoProductCategoryFilesTemp.stream().map(AssoProductCategoryFile::getFileGuid).collect(Collectors.toList());
                 if (guidTemp.size() != 0) {
                     List<SystemFile> systemFileTemp = systemFiles.stream().filter(item -> guidTemp.contains(item.getGuid())).collect(Collectors.toList());
@@ -441,7 +450,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
             }
             //根据showType到产品类别与可见人员关联表中查询可见人员
             Integer showType = productCategoryVO.getShowType();
-            if(showType.equals(2) || showType.equals(3)){
+            if (showType.equals(2) || showType.equals(3)) {
                 LambdaQueryWrapper<AssoProductCategoryPerson> queryWrapper = new LambdaQueryWrapper<>();
                 queryWrapper.eq(AssoProductCategoryPerson::getProductCategoryId, productCategoryVO.getId());
                 //如果showType为2,则查询的角色类型为1
@@ -501,28 +510,26 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
     }
 
     //装载查询语句
-    private List<String> loadSearchSql(List<String> sqls){
-        PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
-        String id =personnelVO.getId();
-        Integer tenantId= personnelVO.getTenantId();
+    private List<String> loadSearchSql(List<String> sqls) {
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        String id = personnelVO.getId();
+        Integer tenantId = personnelVO.getTenantId();
         Integer roleType = personnelVO.getRoleType();
         String rootSql = "";
         if (roleType == null || roleType.equals(0)) {
-            rootSql ="category.create_id="+id+" or(category.show_type =0 and category.tenant ="+tenantId+") or ( category.id in (select product_category_id from asso_product_category_person where" +
-                    " person_id="+id+" and role=0)) or (category.show_type=2 and  category.id in (select product_category_id from asso_product_category_person where" +
-                    " person_id="+id+" and role=1)) or(category.show_type =3 and category.id not in(select product_category_id from asso_product_category_person where" +
-                    " person_id="+id+" and role=2) and category.tenant="+tenantId+")";
+            rootSql = "category.create_id=" + id + " or(category.show_type =0 and category.tenant =" + tenantId + ") or ( category.id in (select product_category_id from asso_product_category_person where" +
+                    " person_id=" + id + " and role=0)) or (category.show_type=2 and  category.id in (select product_category_id from asso_product_category_person where" +
+                    " person_id=" + id + " and role=1)) or(category.show_type =3 and category.id not in(select product_category_id from asso_product_category_person where" +
+                    " person_id=" + id + " and role=2) and category.tenant=" + tenantId + ")";
 
-        }
-        else if(roleType.equals(2))
-        {
-            rootSql="category.tenant="+tenantId;
+        } else if (roleType.equals(2)) {
+            rootSql = "category.tenant=" + tenantId;
         }
 
         if (sqls.get(0) != null && !sqls.get(0).equals("") && !rootSql.equals("")) {
-            sqls.set(0, "("+rootSql+")" + " and" + "(" + sqls.get(0) + ")");
+            sqls.set(0, "(" + rootSql + ")" + " and" + "(" + sqls.get(0) + ")");
         } else if ((sqls.get(0) == null || sqls.get(0).equals("")) && !rootSql.equals("")) {
-            sqls.set(0, "("+rootSql+")");
+            sqls.set(0, "(" + rootSql + ")");
         }
 
 

+ 9 - 7
src/main/java/cn/cslg/pas/service/business/ProductService.java

@@ -169,13 +169,15 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         assoProductPeople.add(assoProductAdmin);
         //设置的管理员
         List<String> adminIds = productDTO.getAdminIds();
-        for (String adminId : adminIds) {
-            AssoProductPerson admin = new AssoProductPerson();
-            admin.setProductId(product.getId());
-            admin.setPersonId(adminId);
-            admin.setRole(0);
-            admin.setCreateId(personnelVO.getId());
-            assoProductPeople.add(admin);
+        if (!CollectionUtils.isEmpty(adminIds)) {
+            for (String adminId : adminIds) {
+                AssoProductPerson admin = new AssoProductPerson();
+                admin.setProductId(product.getId());
+                admin.setPersonId(adminId);
+                admin.setRole(0);
+                admin.setCreateId(personnelVO.getId());
+                assoProductPeople.add(admin);
+            }
         }
         //判断可见类型:
         Integer showType = productDTO.getShowType();