Browse Source

作者:张哲
时间:2023/05/18
类型:优化
描述:里程碑(1) 组织架构改为多级

zizg 2 years ago
parent
commit
8151ba3785

+ 3 - 2
src/main/java/com/redxun/knowledge/controller/KnowledgeApproveController.java

@@ -15,6 +15,7 @@ import com.redxun.knowledge.common.UserService;
 import com.redxun.knowledge.entity.dao.KnowledgeApprove;
 import com.redxun.knowledge.entity.dto.KnowledgeApproveDto;
 import com.redxun.knowledge.service.KnowledgeApproveServiceImpl;
+import com.redxun.knowledge.utils.ObjectUtil;
 import com.redxun.web.controller.BaseController;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -82,7 +83,7 @@ public class KnowledgeApproveController extends BaseController<KnowledgeApprove>
         knowledgeApproveDto.setActualApprover(userService.queryLoginUsername());
         knowledgeApproveDto.setActualApproverName(userService.queryLoginFullName());
         BeanUtils.copyProperties(knowledgeApproveDto, knowledgeApprove);
-        if (!Objects.isNull(knowledgeApproveDto.getOrganizationIds())){
+        if (!ObjectUtil.valueAllNull(knowledgeApproveDto.getOrganizationIds())){
             String organizationId = JSON.toJSON(knowledgeApproveDto.getOrganizationIds()).toString();
             knowledgeApprove.setOrganizationId(organizationId);
         }
@@ -107,7 +108,7 @@ public class KnowledgeApproveController extends BaseController<KnowledgeApprove>
             knowledgeApprove.setActualApproverName(userService.queryLoginFullName());
             knowledgeApprove.setRemark(knowledgeApproveDto.getRemark());
             knowledgeApprove.setApprovalTime(new Date());
-            if (!Objects.isNull(knowledgeApproveDto.getOrganizationIds())){
+            if (!ObjectUtil.valueAllNull(knowledgeApproveDto.getOrganizationIds())){
                 String organizationId = JSON.toJSON(knowledgeApproveDto.getOrganizationIds()).toString();
                 knowledgeApprove.setOrganizationId(organizationId);
             }

+ 3 - 0
src/main/java/com/redxun/knowledge/entity/vo/KnowledgeApprovalListVo.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.redxun.knowledge.entity.dto.OrganizationDto;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
@@ -83,5 +84,7 @@ public class KnowledgeApprovalListVo {
     private Integer isAudit;
 
     private String organizationId;
+
+    private OrganizationDto organizationIds;
 }
 

+ 6 - 0
src/main/java/com/redxun/knowledge/service/KnowledgeApproveServiceImpl.java

@@ -3,6 +3,7 @@ package com.redxun.knowledge.service;
 
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -21,6 +22,7 @@ import com.redxun.knowledge.common.MessageService;
 import com.redxun.knowledge.common.UserService;
 import com.redxun.knowledge.entity.dao.Knowledge;
 import com.redxun.knowledge.entity.dao.KnowledgeApprove;
+import com.redxun.knowledge.entity.dto.OrganizationDto;
 import com.redxun.knowledge.entity.vo.KnowledgeApprovalListVo;
 import com.redxun.knowledge.entity.vo.KnowledgeCategoryAdminVo;
 import com.redxun.knowledge.mapper.KnowledgeApproveMapper;
@@ -129,6 +131,10 @@ public class KnowledgeApproveServiceImpl extends SuperServiceImpl<KnowledgeAppro
             String categoryId = e.getCategoryId();
             KnowledgeCategoryAdminVo knowledgeCategoryAdminVo = knowledgeCategoryService.findAllParentByCategoryId(categoryId);
             e.setKnowledgeCategoryAdminVo(knowledgeCategoryAdminVo);
+            if (StringUtils.isNotEmpty(e.getOrganizationId())){
+                OrganizationDto organizationDto = JSON.parseObject(e.getOrganizationId(), OrganizationDto.class);
+                e.setOrganizationIds(organizationDto);
+            }
         });
         // 判断当前登录人是否可以审核每一条知识
         collect.forEach(e -> {

+ 14 - 19
src/main/java/com/redxun/knowledge/service/KnowledgeServiceImpl.java

@@ -29,6 +29,7 @@ import com.redxun.knowledge.entity.vo.*;
 import com.redxun.knowledge.map.entity.dao.MapContent;
 import com.redxun.knowledge.map.mapper.MapContentMapper;
 import com.redxun.knowledge.mapper.*;
+import com.redxun.knowledge.utils.ObjectUtil;
 import com.redxun.knowledge.utils.PageListUtils;
 import com.redxun.search.service.SearchService;
 import lombok.extern.slf4j.Slf4j;
@@ -115,7 +116,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
      */
     @Transactional(rollbackFor = Exception.class)
     public String create(KnowledgeDto knowledgeDto) {
-        if (Objects.isNull(knowledgeCategoryMapper.selectById(knowledgeDto.getCategoryId()))){
+        if (Objects.isNull(knowledgeCategoryMapper.selectById(knowledgeDto.getCategoryId())) && knowledgeDto.getIsDraft() == 1){
             throw new RuntimeException("输入的分类不存在,请重新输入");
         }
         if (knowledgeDto != null) {
@@ -146,7 +147,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             knowledge.setCreateTime(new Date());
             knowledge.setUpdateBy(users.getUserId());
             knowledge.setUpdateTime(new Date());
-            if (!Objects.isNull(knowledgeDto.getOrganizationIds())){
+            if (!ObjectUtil.valueAllNull(knowledgeDto.getOrganizationIds())){
                 String organizationId = JSON.toJSON(knowledgeDto.getOrganizationIds()).toString();
                 knowledge.setOrganizationId(organizationId);
             }
@@ -285,6 +286,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
         if (flag != null && flag == 1 && knowledgeVo.getApprovalStatus() == 5 && !knowledge.getCreateBy().equals(userService.queryLoginUser())) {
              knowledgeVo = parseOrganization(knowledge.getOrganizationId(), true, knowledgeVo);
         }
+        if (knowledgeVo.getIsOrganizationId() != null && knowledgeVo.getIsOrganizationId() == 1){
+            return null;
+        }
         return knowledgeVo;
     }
 
@@ -362,7 +366,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
         }
         Knowledge knowledge = this.get(entity.getPkId());
         //处理组织架构
-        if (!Objects.isNull(entity.getOrganizationIds())){
+        if (!ObjectUtil.valueAllNull(entity.getOrganizationIds())){
             String organizationId = JSON.toJSON(entity.getOrganizationIds()).toString();
             knowledge.setOrganizationId(organizationId);
         }
@@ -413,7 +417,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                 }
             }
             // 组织架构/职系/职等信息
-            if (Objects.isNull(entity.getOrganizationIds())){
+            if (ObjectUtil.valueAllNull(entity.getOrganizationIds())){
                 entity.setOrganizationId("");
             }
             return this.getRepository().updateById(entity);
@@ -464,6 +468,10 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             String categoryId = e.getCategoryId();
             KnowledgeCategoryAdminVo knowledgeCategoryAdminVo = knowledgeCategoryService.findAllParentByCategoryId(categoryId);
             e.setKnowledgeCategoryAdminVo(knowledgeCategoryAdminVo);
+            if (StringUtils.isNotEmpty(e.getOrganizationId())){
+                OrganizationDto organizationDto = JSON.parseObject(e.getOrganizationId(), OrganizationDto.class);
+                e.setOrganizationIds(organizationDto);
+            }
             // 判断当前登录人是否可以审核每一条知识
             String userNo = userService.queryLoginUsername();
             String userId = userService.queryLoginUser();
@@ -647,6 +655,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
 
         // 解析组织架构/职系/职等数据
         OrganizationDto organizationDto = JSON.parseObject(organizationId, OrganizationDto.class);
+        log.info("解析出组织架构信息 -> {}",organizationDto);
         knowledgeVo.setOrganizationIds(organizationDto);
         // 获取当前登录人的组织架构/职系/职等数据
         String sequenceCode = osUserDto.getSequenceCode();
@@ -675,11 +684,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -693,11 +700,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -711,11 +716,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -728,11 +731,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -745,11 +746,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -762,11 +761,9 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
 
@@ -779,14 +776,12 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
                     addCountViews(osUserDto.getUserId(), knowledgeVo.getPkId());
                 }
                 knowledgeVo.setIsOrganizationId(0);
-                return knowledgeVo;
             } else {
                 // 没有权限(不增加点击量)
                 knowledgeVo.setIsOrganizationId(1);
-                return null;
             }
         }
-        return null;
+        return knowledgeVo;
     }
 
 

+ 54 - 0
src/main/java/com/redxun/knowledge/utils/ObjectUtil.java

@@ -0,0 +1,54 @@
+package com.redxun.knowledge.utils;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * 文件名: ObjectUtils
+ * 作者: zizg
+ * 时间: 2023/5/17
+ * 描述: 校验对象属性
+ * 修改人:
+ * 修改时间:
+ * 修改内容:
+ */
+public class ObjectUtil {
+
+    private ObjectUtil(){
+
+    }
+
+    /**
+     * 对象属性是否都为空
+     * @param t
+     * @param <T>
+     * @return 是否都为空
+     */
+    public static <T> boolean valueAllNull(T t) {
+
+        if (t == null) {
+            return true;
+        }
+
+        boolean flag = true;
+        Class<?> clazz = t.getClass();
+        Field[] fileds = clazz.getDeclaredFields();
+        for (Field field : fileds) {
+            field.setAccessible(true);
+            Collection coll = null;
+            try {
+                coll = (Collection) field.get(t);
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            } finally {
+                field.setAccessible(false);
+            }
+            if (coll != null && !coll.isEmpty()) {
+                flag = false;
+                break;
+            }
+        }
+        return flag;
+    }
+}