From 5b60b28f6c9556ad438f55fe57c8d3edc32716ae Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期四, 20 十一月 2025 09:46:03 +0800
Subject: [PATCH] 功能修改
---
multi-system/src/main/java/com/gkhy/exam/system/service/impl/SysDeptServiceImpl.java | 239 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 195 insertions(+), 44 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 77338d2..f8f60f1 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,28 +2,27 @@
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.api.CommonPage;
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.NaturalOrderComparator;
+import com.gkhy.exam.common.utils.PageUtils;
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.SysDeptManage;
import com.gkhy.exam.system.domain.SysDeptResponsibility;
import com.gkhy.exam.system.domain.SysFunctionalDistribution;
+import com.gkhy.exam.system.domain.SysFunctionalRemark;
+import com.gkhy.exam.system.domain.req.SysDeptPageReq;
import com.gkhy.exam.system.domain.vo.*;
-import com.gkhy.exam.system.mapper.SysDeptMapper;
-import com.gkhy.exam.system.mapper.SysDeptResponsibilityMapper;
-import com.gkhy.exam.system.mapper.SysFunctionalDistributionMapper;
-import com.gkhy.exam.system.mapper.SysRoleMapper;
+import com.gkhy.exam.system.mapper.*;
import com.gkhy.exam.system.service.ISysDeptService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +31,7 @@
import java.time.LocalDateTime;
import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -53,8 +53,36 @@
@Autowired
private SysFunctionalDistributionMapper sysFunctionalDistributionMapper;
- public static final String[] DEPT_ROOT = {"4.1", "4.2", "4.3", "4.4", "5.1", "5.2", "5.3","6.1", "6.2", "6.3",
- "7.1.1", "7.1.2", "7.1.3", "7.1.4", "7.1.5", "7.1.6"};
+
+ @Autowired
+ private SysFunctionalRemarkMapper sysFunctionalRemarkMapper;
+
+ public static final String[] DEPT_ROOT = {"4","4.1", "4.2", "4.3", "4.4","5", "5.1", "5.2", "5.3","6","6.1", "6.2", "6.3"
+ ,"7","7.1.1", "7.1.2", "7.1.3", "7.1.4", "7.1.5", "7.1.6","7.2", "7.3", "7.4", "7.5", "7.6","8","8.1","8.2","8.2.1","8.2.2", "8.2.3", "8.2.4", "8.3", "8.3.1", "8.3.2", "8.3.3", "8.3.4", "8.3.5", "8.3.6", "8.3.7", "8.3.8", "8.4",
+ "8.4.1", "8.4.2", "8.4.3", "8.5", "8.5.1", "8.5.2", "8.5.3", "8.5.4", "8.5.5", "8.5.6", "8.5.7", "8.6","8.7","9","9.1","9.1.1","9.1.2","9.1.3","9.2", "9.3","10","10.1"
+ ,"10.2", "10.3"};
+
+ @Override
+ public CommonPage selectDeptPageList(SysDeptPageReq req) {
+
+ PageUtils.startPage();
+
+ List<DeptVo> deptVos = deptMapper.selectDeptPageList(req);
+ if (ObjectUtil.isNotEmpty(deptVos)){
+ for (DeptVo deptVo : deptVos) {
+ List<CaluseVO1> caluseVO1List = deptVo.getCaluseVO1List();
+ if (ObjectUtil.isNotEmpty(caluseVO1List)){
+ caluseVO1List.sort(Comparator.comparing(CaluseVO1::getClauseNum, new NaturalOrderComparator()));
+ }
+
+ }
+ }
+
+ CommonPage<DeptVo> deptVoCommonPage = CommonPage.restPage(deptVos);
+ return deptVoCommonPage;
+
+ }
+
/**
* 查询部门管理数据
*
@@ -68,7 +96,17 @@
if (dept.getCompanyId() == null){
dept.setCompanyId(SecurityUtils.getCompanyId());
}
- return deptMapper.selectDeptList(dept);
+ List<DeptVo> deptVos = deptMapper.selectDeptList(dept);
+ if (ObjectUtil.isNotEmpty(deptVos)){
+ for (DeptVo deptVo : deptVos) {
+ List<CaluseVO1> caluseVO1List = deptVo.getCaluseVO1List();
+ if (ObjectUtil.isNotEmpty(caluseVO1List)){
+ caluseVO1List.sort(Comparator.comparing(CaluseVO1::getClauseNum, new NaturalOrderComparator()));
+ }
+
+ }
+ }
+ return deptVos;
}
@Override
@@ -86,7 +124,13 @@
public List<TreeSelect> selectDeptTreeList(SysDept dept)
{
List<SysDept> depts = SpringUtils.getAopProxy(this).getOutDeptList(dept);
+
return buildDeptTreeSelect(depts);
+ }
+
+ @Override
+ public List<SysDept> getParentInfo(Long deptId) {
+ return deptMapper.getParentInfo(deptId);
}
/**
@@ -159,6 +203,9 @@
.eq(SysDeptResponsibility::getDelFlag, UserConstant.ENABLE)
.orderByAsc(SysDeptResponsibility::getClauseNum);
List<SysDeptResponsibility> sysDeptResponsibilities = deptResponsibilityMapper.selectList(lambdaQueryWrapper);
+ if (ObjectUtil.isNotEmpty(sysDeptResponsibilities)){
+ sysDeptResponsibilities.sort(Comparator.comparing(SysDeptResponsibility::getClauseNum, new NaturalOrderComparator()));
+ }
deptDetialVo.setSysDeptResponsibilitys(sysDeptResponsibilities);
return deptDetialVo ;
@@ -230,7 +277,7 @@
@Override
public void checkDeptDataScope(Long deptId)
{
- if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && ObjectUtil.isNotNull(deptId))
+ if (!SecurityUtils.adminUser() && ObjectUtil.isNotNull(deptId))
{
SysDept dept = new SysDept();
dept.setDeptId(deptId);
@@ -262,24 +309,41 @@
}
@Override
- @Transactional
+ @Transactional(rollbackFor = RuntimeException.class)
public int saveDept(SysDeptSaveDTOReq dept) {
- Long companyId = SecurityUtils.getCompanyId();
- if (!companyId.equals(dept.getCompanyId())){
- throw new ApiException("无权操作!");
- }
+// Long companyId = SecurityUtils.getCompanyId();
+// if (!companyId.equals(dept.getCompanyId())){
+// throw new ApiException("无权操作!");
+// }
SysDept sysDept = new SysDept();
BeanUtils.copyProperties(dept, sysDept);
- sysDept.setCompanyId(companyId);
boolean b = checkDeptNameUnique(sysDept);
if (!b){
throw new ApiException("部门名称已存在!");
}
+ SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
+
int i = 0;
if (sysDept.getDeptId() == null){
+ if (ObjectUtil.isNotNull(newParentDept)){
+ String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+ dept.setAncestors(newAncestors);
+ }
sysDept.setCreateBy(SecurityUtils.getUsername());
i = deptMapper.insertDept(sysDept);
}else {
+ if (sysDept.getParentId().equals(sysDept.getDeptId())){
+ throw new ApiException("上级部门不能是自己!");
+ }
+
+ SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
+ if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept))
+ {
+ String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+ String oldAncestors = oldDept.getAncestors();
+ dept.setAncestors(newAncestors);
+ updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+ }
sysDept.setUpdateBy(SecurityUtils.getUsername());
sysDept.setUpdateTime(LocalDateTime.now());
i = deptMapper.updateDept(sysDept);
@@ -291,25 +355,42 @@
delCaluse(sysDept.getDeptId(), delCaluseIds);
}
//处理条款
- batchSaveCaluse(sysDept.getDeptId(), companyId, dept.getCaluseVO1List());
+ batchSaveCaluse(sysDept.getDeptId(), dept.getCompanyId(), dept.getCaluseVO1List());
}
return sysDept.getDeptId().byteValue();
}
- @Override
- @Transactional
- public int saveDeptResponsibility(SysDeptResponsibilityReqVo reqVo) {
- Long companyId = SecurityUtils.getCompanyId();
- if (!companyId.equals(reqVo.getCompanyId())){
- throw new ApiException("无权操作!");
+ private void bacthInsertManager(Long deptId, List<Long> managerIds,Long companyId) {
+ deptMapper.deleteMangeBatch(deptId);
+ if (managerIds != null && !managerIds.isEmpty())
+ {
+ List<SysDeptManage> sysDeptManagers = new ArrayList<>();
+ for (Long managerId : managerIds)
+ {
+ SysDeptManage sysDeptManage = new SysDeptManage();
+ sysDeptManage.setDeptId(deptId);
+ sysDeptManage.setSubDeptId(managerId);
+ sysDeptManage.setCompanyId(companyId);
+ sysDeptManagers.add(sysDeptManage);
+ }
+ deptMapper.insetMangeBatch(sysDeptManagers);
}
+ }
+
+ @Override
+ @Transactional(rollbackFor = RuntimeException.class)
+ public int saveDeptResponsibility(SysDeptResponsibilityReqVo reqVo) {
+// Long companyId = SecurityUtils.getCompanyId();
+// if (!companyId.equals(reqVo.getCompanyId())){
+// throw new ApiException("无权操作!");
+// }
SysDept sysDept = deptMapper.selectDeptById(reqVo.getDeptId());
if (null == sysDept){
throw new ApiException("部门不存在!");
}
- if (!companyId.equals(sysDept.getCompanyId())){
+ if (!reqVo.getCompanyId().equals(sysDept.getCompanyId())){
throw new ApiException("无权操作!");
}
SysDept dept = new SysDept();
@@ -330,26 +411,37 @@
@Override
public List<SysFunctionalDistribution> getFunctionalDistributionList(Long companyId) {
- if (companyId != null){
- companyId = SecurityUtils.getCompanyId();
- }
+
return sysFunctionalDistributionMapper.selectListVo(companyId);
}
@Override
+ @Transactional(rollbackFor = RuntimeException.class)
public int initFunctionalDistribution(Long companyId) {
- if (!companyId.equals(SecurityUtils.getCompanyId())){
- throw new ApiException("无权操作!");
- }
- sysFunctionalDistributionMapper.delete(new LambdaQueryWrapper<SysFunctionalDistribution>().eq(SysFunctionalDistribution::getCompanyId, SecurityUtils.getLoginUser().getUser().getCompanyId()));
-
+ sysFunctionalDistributionMapper.delByCompanyId(companyId);
+ sysFunctionalRemarkMapper.delByCompanyId(companyId);
SysDept sysDept = new SysDept();
sysDept.setCompanyId(companyId);
+ sysDept.setResponsType("1");
List<DeptVo> deptVos = deptMapper.selectDeptList(sysDept);
if (deptVos != null && !deptVos.isEmpty()){
List<SysFunctionalDistribution> sysFunctionalDistributions = new ArrayList<>();
+ Map<String, CaluseVO1> clauseNumMap = new HashMap<>();
+ Map<String, Integer> clauseNumSetNum = new HashMap<>();
+ Set<String> clauseNumSet = new HashSet<>();
for (DeptVo deptVo : deptVos) {
+ List<CaluseVO1> caluseVO1List = deptVo.getCaluseVO1List();
+ if (ObjectUtil.isNotEmpty(caluseVO1List)){
+ // 转成 Map<String, CaluseVO1>,key 是 clauseNum
+ clauseNumMap = caluseVO1List.stream()
+ .collect(Collectors.toMap(
+ CaluseVO1::getClauseNum, // key
+ Function.identity(), // value
+ (existing, replacement) -> existing // 如果有重复 key,保留现有的值
+ ));
+ }
+ //加入职能
for (String s : DEPT_ROOT) {
SysFunctionalDistribution sysFunctionalDistribution = new SysFunctionalDistribution();
sysFunctionalDistribution.setDeptId(deptVo.getDeptId());
@@ -357,12 +449,42 @@
sysFunctionalDistribution.setCreateBy(SecurityUtils.getUsername());
sysFunctionalDistribution.setCreateTime(LocalDateTime.now());
sysFunctionalDistribution.setClauseNum(s);
- sysFunctionalDistribution.setChooseLab(0);
+ if (clauseNumMap.isEmpty()){
+ sysFunctionalDistribution.setChooseLab(0);
+ }else if (clauseNumMap.containsKey(s)){
+ sysFunctionalDistribution.setChooseLab(1);
+ if (deptVo.getDeptType().equals("0")){
+ Integer i = clauseNumSetNum.get(s);
+ if (i == null){
+ i = 0;
+ clauseNumSetNum.put(s, ++i);
+ }else {
+ clauseNumSetNum.put(s, ++i);
+ clauseNumSet.add(s);
+ }
+ }
+ }else {
+ sysFunctionalDistribution.setChooseLab(0);
+ }
+
sysFunctionalDistributions.add(sysFunctionalDistribution);
}
}
int i = sysFunctionalDistributionMapper.batchInsert(sysFunctionalDistributions);
+ if (clauseNumSet.size() > 0){
+ List<SysFunctionalRemark> sysFunctionalRemarks = new ArrayList<>();
+ for (String clauseNum : clauseNumSet) {
+ SysFunctionalRemark sysFunctionalRemark = new SysFunctionalRemark();
+ sysFunctionalRemark.setCompanyId(companyId);
+ sysFunctionalRemark.setClauseNum(clauseNum);
+ sysFunctionalRemark.setRemark(" ");
+ sysFunctionalRemark.setCreateBy(SecurityUtils.getUsername());
+ sysFunctionalRemark.setCreateTime(LocalDateTime.now());
+ sysFunctionalRemarks.add(sysFunctionalRemark);
+ }
+ int j = sysFunctionalRemarkMapper.batchInsert(sysFunctionalRemarks);
+ }
if (i < 1){
throw new ApiException("初始化失败!");
}
@@ -372,17 +494,43 @@
}
@Override
+ @Transactional(rollbackFor = RuntimeException.class)
public int saveFunctionalDistribution(FunctionalDistributionVo reqVo) {
- Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
- if (!companyId.equals(reqVo.getCompanyId())){
- throw new ApiException("无权操作!");
- }
+// Long companyId = SecurityUtils.getCompanyId();
+// if (!companyId.equals(reqVo.getCompanyId())){
+// throw new ApiException("无权操作!");
+// }
List<SysFunctionalDistribution> list = reqVo.getList();
- int i = sysFunctionalDistributionMapper.batchUpdate(list);
- if (i < 1){
- throw new ApiException("保存失败!");
+ if (list != null && !list.isEmpty())
+ {
+ list.forEach(e ->{
+ e.setCompanyId(reqVo.getCompanyId());
+ e.setUpdateBy(SecurityUtils.getUsername());
+ e.setUpdateTime(LocalDateTime.now());
+ });
+ int i = sysFunctionalDistributionMapper.batchUpdate(list);
+ }
+
+
+ List<SysFunctionalRemark> remarks = reqVo.getRemarks();
+ if (remarks != null && !remarks.isEmpty())
+ {
+ sysFunctionalRemarkMapper.delByCompanyId(reqVo.getCompanyId());
+
+ remarks.forEach(e ->{
+ e.setCompanyId(reqVo.getCompanyId());
+ e.setCreateBy(SecurityUtils.getUsername());
+ e.setCreateTime(LocalDateTime.now());
+ });
+
+ int i1 = sysFunctionalRemarkMapper.batchInsert(remarks);
}
return 1;
+ }
+
+ @Override
+ public List<SysFunctionalRemark> getFunctionalRemarkList(Long companyId) {
+ return sysFunctionalRemarkMapper.selectListVo(companyId);
}
@@ -412,7 +560,9 @@
if (!emptyIdClauseNums.isEmpty()){
List<SysDeptResponsibility> sysDeptResponsibilities = deptResponsibilityMapper.selectList(new LambdaQueryWrapper<SysDeptResponsibility>()
- .eq(SysDeptResponsibility::getDeptId, reqVo.getDeptId()).in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums).notIn(SysDeptResponsibility::getId, emptyIdClauseIds));
+ .eq(SysDeptResponsibility::getDeptId, reqVo.getDeptId())
+ .in(SysDeptResponsibility::getClauseNum, emptyIdClauseNums)
+ .notIn(SysDeptResponsibility::getId, emptyIdClauseIds).eq(SysDeptResponsibility::getDelFlag, "0"));
if (!sysDeptResponsibilities.isEmpty()){
throw new ApiException("部门条款编码重复!");
}
@@ -451,7 +601,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("部门条款编码重复!");
}
--
Gitblit v1.9.2