From 2892b2a80babdde59f8dcf6750b26870a6d6a853 Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期一, 16 六月 2025 14:05:41 +0800
Subject: [PATCH] 部分功能调整

---
 multi-system/src/main/java/com/gkhy/exam/system/domain/SysClauseManagement.java                  |    4 ++
 multi-common/src/main/java/com/gkhy/exam/common/utils/SecurityUtils.java                         |   18 +++++++++
 multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java             |   28 +++++++++++---
 multi-system/src/main/resources/mapper/system/SysDeptMapper.xml                                  |   16 ++++----
 multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java           |   36 +++++++++---------
 multi-system/src/main/java/com/gkhy/exam/system/service/impl/InformationPlatformServiceImpl.java |    4 +-
 multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysClauseManagementServiceImpl.java |    9 ++--
 multi-system/src/main/resources/mapper/system/SysFunctionalDistributionMapper.xml                |    5 +-
 8 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java b/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
index 907972f..646990a 100644
--- a/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
+++ b/multi-admin/src/main/java/com/gkhy/exam/admin/controller/system/SysDeptController.java
@@ -31,7 +31,7 @@
  * 
  * @author expert
  */
-@Api(tags = "部门-业务处室")
+@Api(tags = "部门管理")
 @RestController
 @RequestMapping("/system/dept")
 public class SysDeptController
@@ -60,17 +60,17 @@
      * 查询部门列表(排除节点)
      */
     //@PreAuthorize("hasAnyAuthority('system:dept:list')")
-    @GetMapping("/list/exclude/{deptId}")
-    @ApiImplicitParams({
-            @ApiImplicitParam(paramType = "query", name = "deptId", dataType = "Long", required = true, value = "部门id"),
-    })
-    @ApiOperation(value = "查询部门列表(排除节点)")
-    public CommonResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
-    {
-        List<SysDept> depts = deptService.getOutDeptList(new SysDept());
-        depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
-        return CommonResult.success(depts);
-    }
+//    @GetMapping("/list/exclude/{deptId}")
+//    @ApiImplicitParams({
+//            @ApiImplicitParam(paramType = "query", name = "deptId", dataType = "Long", required = true, value = "部门id"),
+//    })
+//    @ApiOperation(value = "查询部门列表(排除节点)")
+//    public CommonResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
+//    {
+//        List<SysDept> depts = deptService.getOutDeptList(new SysDept());
+//        depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
+//        return CommonResult.success(depts);
+//    }
 
     /**
      * 根据部门编号获取详细信息
@@ -182,19 +182,19 @@
      */
     //@PreAuthorize("hasAnyAuthority('system:dept:remove')")
     @DeleteMapping("/{deptId}")
-    @ApiOperation(value = "删除部门门业务处室")
+    @ApiOperation(value = "删除部门")
     public CommonResult remove(@PathVariable Long deptId)
     {
         if (deptService.hasChildByDeptId(deptId))
         {
             return CommonResult.failed("存在下级部门,不允许删除");
         }
-        if (deptService.checkDeptExistUser(deptId))
-        {
-            return CommonResult.failed("部门存在用户,不允许删除");
-        }
+//        if (deptService.checkDeptExistUser(deptId))
+//        {
+//            return CommonResult.failed("部门存在用户,不允许删除");
+//        }
         //todo  校验专家是否申请复用
-        deptService.checkDeptDataScope(deptId);
+//        deptService.checkDeptDataScope(deptId);
         return CommonResult.success(deptService.deleteDeptById(deptId));
     }
 }
diff --git a/multi-common/src/main/java/com/gkhy/exam/common/utils/SecurityUtils.java b/multi-common/src/main/java/com/gkhy/exam/common/utils/SecurityUtils.java
index ef46723..59d75ab 100644
--- a/multi-common/src/main/java/com/gkhy/exam/common/utils/SecurityUtils.java
+++ b/multi-common/src/main/java/com/gkhy/exam/common/utils/SecurityUtils.java
@@ -48,6 +48,24 @@
 
 
 
+    /*
+     **
+     * 用户ID
+     **/
+    public static Long getCompanyId()
+    {
+        try
+        {
+            return getLoginUser().getUser().getCompanyId();
+        }
+        catch (Exception e)
+        {
+            throw new ApiException("获取用户公司异常");
+        }
+    }
+
+
+
     /**
      * 获取用户账户
      **/
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/domain/SysClauseManagement.java b/multi-system/src/main/java/com/gkhy/exam/system/domain/SysClauseManagement.java
index c820bc5..d96eddf 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/domain/SysClauseManagement.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/domain/SysClauseManagement.java
@@ -16,6 +16,10 @@
     @ApiModelProperty("排序")
     private Integer sort;
 
+    @ApiModelProperty("条款名称")
+    @NotBlank(message = "条款名称不能为空")
+    private String name;
+
     @ApiModelProperty("条款编码")
     @NotBlank(message = "条款编码不能为空")
     private String clauseNum;
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/InformationPlatformServiceImpl.java b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/InformationPlatformServiceImpl.java
index aa04a95..5c21ccc 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/InformationPlatformServiceImpl.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/InformationPlatformServiceImpl.java
@@ -27,7 +27,7 @@
     @Override
     public List<InformationPlatform> getInformationPlatforms(Long companyId) {
         if (companyId == null) {
-            companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
+            companyId = SecurityUtils.getCompanyId();
         }
         LambdaQueryWrapper<InformationPlatform> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(InformationPlatform::getCompanyId, companyId);
@@ -41,7 +41,7 @@
     @Override
     public int saveInformationPlatform(InformationPlatform informationPlatform) {
         Long companyId = informationPlatform.getCompanyId();
-        if (!companyId.equals(SecurityUtils.getLoginUser().getUser().getCompanyId())){
+        if (!companyId.equals(SecurityUtils.getCompanyId())){
             throw new ApiException("无权操作!");
         }
 
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysClauseManagementServiceImpl.java b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysClauseManagementServiceImpl.java
index 1de4082..08d1d5e 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysClauseManagementServiceImpl.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysClauseManagementServiceImpl.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gkhy.exam.common.exception.ApiException;
 import com.gkhy.exam.common.utils.SecurityUtils;
 import com.gkhy.exam.system.domain.SysClauseManagement;
 import com.gkhy.exam.system.mapper.SysClauseManagementMapper;
@@ -29,13 +30,13 @@
     @Override
     public int saveSysClauseManagement(SysClauseManagement sysClauseManagement) {
         if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
-            throw new RuntimeException("没有权限访问!");
+            throw new ApiException("没有权限访问!");
         }
         LambdaQueryWrapper<SysClauseManagement> lambdaQueryWrapper = Wrappers.<SysClauseManagement>lambdaQuery()
                 .eq(SysClauseManagement::getDelFlag, "0").eq(SysClauseManagement::getClauseNum, sysClauseManagement.getClauseNum());
         if (sysClauseManagement.getId() == null){
             if (baseMapper.selectCount(lambdaQueryWrapper) > 0){
-                throw new RuntimeException("条款编号已存在!");
+                throw new ApiException("条款编号已存在!");
             }
             sysClauseManagement.setCreateBy(SecurityUtils.getUsername());
             sysClauseManagement.setCreateTime(LocalDateTime.now());
@@ -43,7 +44,7 @@
         }else {
             lambdaQueryWrapper.ne(SysClauseManagement::getId, sysClauseManagement.getId());
             if (baseMapper.selectCount(lambdaQueryWrapper) > 0){
-                throw new RuntimeException("条款编号已存在!");
+                throw new ApiException("条款编号已存在!");
             }
             sysClauseManagement.setUpdateBy(SecurityUtils.getUsername());
             sysClauseManagement.setUpdateTime(LocalDateTime.now());
@@ -56,7 +57,7 @@
     @Override
     public int delSysClauseManagement(Long id) {
         if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
-            throw new RuntimeException("没有权限访问!");
+            throw new ApiException("没有权限访问!");
         }
         //todo 校验已使用的?
         SysClauseManagement sysClauseManagement = new SysClauseManagement();
diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
index a35cc97..77338d2 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java
@@ -28,6 +28,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 java.time.LocalDateTime;
 import java.util.*;
@@ -64,6 +65,9 @@
 
     public List<DeptVo> selectDeptList(SysDept dept)
     {
+        if (dept.getCompanyId() == null){
+            dept.setCompanyId(SecurityUtils.getCompanyId());
+        }
         return deptMapper.selectDeptList(dept);
     }
 
@@ -208,7 +212,7 @@
     public boolean checkDeptNameUnique(SysDept dept)
     {
         Long deptId = ObjectUtil.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
-        Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
+        Long companyId = SecurityUtils.getCompanyId();
 
         SysDept info = deptMapper.checkDeptNameUnique(companyId,dept.getDeptName(), dept.getParentId());
         if (ObjectUtil.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
@@ -258,8 +262,9 @@
     }
 
     @Override
+    @Transactional
     public int saveDept(SysDeptSaveDTOReq dept) {
-        Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
+        Long companyId = SecurityUtils.getCompanyId();
         if (!companyId.equals(dept.getCompanyId())){
             throw new ApiException("无权操作!");
         }
@@ -294,8 +299,9 @@
     }
 
     @Override
+    @Transactional
     public int saveDeptResponsibility(SysDeptResponsibilityReqVo reqVo) {
-        Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
+        Long companyId = SecurityUtils.getCompanyId();
         if (!companyId.equals(reqVo.getCompanyId())){
             throw new ApiException("无权操作!");
         }
@@ -324,13 +330,16 @@
 
     @Override
     public List<SysFunctionalDistribution> getFunctionalDistributionList(Long companyId) {
+        if (companyId != null){
+            companyId = SecurityUtils.getCompanyId();
+        }
        return sysFunctionalDistributionMapper.selectListVo(companyId);
     }
 
     @Override
     public int initFunctionalDistribution(Long companyId) {
 
-        if (!companyId.equals(SecurityUtils.getLoginUser().getUser().getCompanyId())){
+        if (!companyId.equals(SecurityUtils.getCompanyId())){
             throw new ApiException("无权操作!");
         }
         sysFunctionalDistributionMapper.delete(new LambdaQueryWrapper<SysFunctionalDistribution>().eq(SysFunctionalDistribution::getCompanyId, SecurityUtils.getLoginUser().getUser().getCompanyId()));
@@ -396,9 +405,14 @@
         if (emptyIdClauseNumSet.size() !=  emptyIdClauseNums.size()){
             throw new ApiException("部门条款编码重复!");
         }
+        List<Long> emptyIdClauseIds = sysDeptResponsibilityList.stream()
+                .filter(item -> item.getId() != null)
+                .map(SysDeptResponsibility::getId)
+                .collect(Collectors.toList());
+
         if (!emptyIdClauseNums.isEmpty()){
             List<SysDeptResponsibility> sysDeptResponsibilities = deptResponsibilityMapper.selectList(new LambdaQueryWrapper<SysDeptResponsibility>()
-                    .eq(SysDeptResponsibility::getDeptId, reqVo.getDeptId()).in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums));
+                    .eq(SysDeptResponsibility::getDeptId, reqVo.getDeptId()).in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums).notIn(SysDeptResponsibility::getId, emptyIdClauseIds));
             if (!sysDeptResponsibilities.isEmpty()){
                 throw new ApiException("部门条款编码重复!");
             }
@@ -426,7 +440,7 @@
                 .update(new SysDeptResponsibility(),
                         new LambdaUpdateWrapper<SysDeptResponsibility>().set(SysDeptResponsibility::getDelFlag, UserConstant.DEPT_DISABLE)
                                 .set(SysDeptResponsibility::getUpdateTime, LocalDateTime.now()).set(SysDeptResponsibility::getUpdateBy, SecurityUtils.getUsername())
-                                .eq(SysDeptResponsibility::getDeptId, deptId));
+                                .eq(SysDeptResponsibility::getDeptId, deptId).in(SysDeptResponsibility::getId, delCaluseIds));
     }
 
     private void batchSaveCaluse(Long deptId,Long companyId, List<CaluseVO1> caluseVO1List) {
@@ -449,9 +463,11 @@
             sysDeptResponsibility.setCompanyId(companyId);
             sysDeptResponsibility.setDeptId(deptId);
 
+
             if (sysDeptResponsibility.getId() == null){
                 sysDeptResponsibility.setCreateBy(SecurityUtils.getUsername());
                 sysDeptResponsibility.setCreateTime(LocalDateTime.now());
+                sysDeptResponsibility.setDataType("2");
                 deptResponsibilityMapper.insert(sysDeptResponsibility);
             }else {
                 sysDeptResponsibility.setUpdateBy(SecurityUtils.getUsername());
diff --git a/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 25c1557..acf425c 100644
--- a/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/multi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -42,24 +42,24 @@
 		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader_user_id, d.company_id, d.status, d.del_flag, d.create_by, d.create_time,d.person_num,d.internal_auditors,
 		d.responsibilities,u.name as leader_name,d2.dept_name as parent_name, dr.content ,dr.clause_num
 		from sys_dept d
-		left join sys_user u on d.leader_user_id = u.user_id
+		left join sys_user u on d.leader_user_id = u.id
 		left join sys_dept d2 on d.parent_id = d2.dept_id
 		left join sys_dept_responsibility dr on d.dept_id = dr.dept_id and dr.del_flag = '0' and data_type = 2
         where d.del_flag = '0'
 		<if test="companyId != null and companyId != 0">
-			AND company_id = #{companyId}
+			AND d.company_id = #{companyId}
 		</if>
 		<if test="deptId != null and deptId != 0">
-			AND dept_id = #{deptId}
+			AND d.dept_id = #{deptId}
 		</if>
         <if test="parentId != null and parentId != 0">
-			AND parent_id = #{parentId}
+			AND d.parent_id = #{parentId}
 		</if>
 		<if test="deptName != null and deptName != ''">
-			AND dept_name like concat('%', #{deptName}, '%')
+			AND d.dept_name like concat('%', #{deptName}, '%')
 		</if>
 		<if test="status != null and status != ''">
-			AND status = #{status}
+			AND d.status = #{status}
 		</if>
 		order by d.parent_id, d.order_num
     </select>
@@ -131,7 +131,7 @@
 		and del_flag = '0' limit 1
 	</select>
     
-    <insert id="insertDept" parameterType="com.gkhy.exam.common.domain.entity.SysDept">
+    <insert id="insertDept" parameterType="com.gkhy.exam.common.domain.entity.SysDept" useGeneratedKeys="true" keyProperty="deptId">
  		insert into sys_dept(
  			<if test="deptId != null and deptId != 0">dept_id,</if>
  			<if test="parentId != null and parentId != 0">parent_id,</if>
@@ -202,7 +202,7 @@
 	</update>
 	
 	<delete id="deleteDeptById" parameterType="Long">
-		update sys_dept set del_flag = '2' where dept_id = #{deptId}
+		update sys_dept set del_flag = '1' where dept_id = #{deptId}
 	</delete>
 
 </mapper> 
\ No newline at end of file
diff --git a/multi-system/src/main/resources/mapper/system/SysFunctionalDistributionMapper.xml b/multi-system/src/main/resources/mapper/system/SysFunctionalDistributionMapper.xml
index 2602307..0b505ee 100644
--- a/multi-system/src/main/resources/mapper/system/SysFunctionalDistributionMapper.xml
+++ b/multi-system/src/main/resources/mapper/system/SysFunctionalDistributionMapper.xml
@@ -24,13 +24,12 @@
 		a.company_id,
 		a.clause_num,
 		a.choose_lab,
-		a.dept_name,
 		a.create_by,
 		a.create_time,
 		a.update_by,
 			a.update_time
 		from sys_functional_distribution a
-		left join sys_dept b on a.dept_id = b.id
+		left join sys_dept b on a.dept_id = b.dept_id
 		where 1=1 and a.company_id = #{companyId}
 		order by a.clause_num asc
 
@@ -45,7 +44,7 @@
 		<foreach collection="list" item="item" separator=";">
 			update sys_functional_distribution
 			<trim prefix="SET" suffixOverrides=",">
-				<if test="item.score != null">choose_lab = #{item.chooseLab},</if>
+				<if test="item.chooseLab != null">choose_lab = #{item.chooseLab},</if>
 				<if test="item.updateBy != null">update_by = #{item.updateBy},</if>
 				<if test="item.updateTime != null">update_time = #{item.updateTime},</if>
 			</trim>

--
Gitblit v1.9.2