From c5cd059cbf5cec74bf82f1dab96235eaeb60151b Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期三, 25 六月 2025 09:54:13 +0800
Subject: [PATCH] 部分功能调整

---
 multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

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..a1a7909 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
@@ -2,21 +2,17 @@
 
 
 import cn.hutool.core.convert.Convert;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.gkhy.exam.common.constant.Constants;
 import com.gkhy.exam.common.constant.UserConstant;
 import com.gkhy.exam.common.domain.TreeSelect;
 import com.gkhy.exam.common.domain.entity.SysDept;
 import com.gkhy.exam.common.domain.entity.SysRole;
-import com.gkhy.exam.common.domain.entity.SysUser;
 import com.gkhy.exam.common.exception.ApiException;
 import com.gkhy.exam.common.utils.SecurityUtils;
 import com.gkhy.exam.common.utils.SpringUtils;
-import com.gkhy.exam.system.domain.ExPaperStudent;
 import com.gkhy.exam.system.domain.SysDeptResponsibility;
 import com.gkhy.exam.system.domain.SysFunctionalDistribution;
 import com.gkhy.exam.system.domain.vo.*;
@@ -28,6 +24,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 +61,9 @@
 
     public List<DeptVo> selectDeptList(SysDept dept)
     {
+        if (dept.getCompanyId() == null){
+            dept.setCompanyId(SecurityUtils.getCompanyId());
+        }
         return deptMapper.selectDeptList(dept);
     }
 
@@ -208,7 +208,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 +258,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 +295,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,17 +326,21 @@
 
     @Override
     public List<SysFunctionalDistribution> getFunctionalDistributionList(Long companyId) {
+        if (companyId != null){
+            companyId = SecurityUtils.getCompanyId();
+        }
        return sysFunctionalDistributionMapper.selectListVo(companyId);
     }
 
     @Override
+    @Transactional
     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()));
 
+        sysFunctionalDistributionMapper.delByCompanyId(companyId);
         SysDept sysDept = new SysDept();
         sysDept.setCompanyId(companyId);
         List<DeptVo> deptVos = deptMapper.selectDeptList(sysDept);
@@ -396,9 +402,16 @@
         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).eq(SysDeptResponsibility::getDelFlag, "0"));
             if (!sysDeptResponsibilities.isEmpty()){
                 throw new ApiException("部门条款编码重复!");
             }
@@ -426,7 +439,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) {
@@ -437,7 +450,8 @@
                 .collect(Collectors.toList());
         if (!emptyIdClauseNums.isEmpty()){
             List<SysDeptResponsibility> sysDeptResponsibilities = deptResponsibilityMapper.selectList(new LambdaQueryWrapper<SysDeptResponsibility>()
-                    .eq(SysDeptResponsibility::getDeptId, deptId).in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums));
+                    .eq(SysDeptResponsibility::getDeptId, deptId).in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums)
+                    .eq(SysDeptResponsibility::getCompanyId, companyId).eq(SysDeptResponsibility::getDelFlag, "0"));
             if (!sysDeptResponsibilities.isEmpty()){
                 throw new ApiException("部门条款编码重复!");
             }
@@ -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());

--
Gitblit v1.9.2