feat: 企标授权部门数据修复

(cherry picked from commit 64f367de24c2517a3b29d70b5aa1d259eb1c8f2f)
This commit is contained in:
2024-01-04 20:09:04 +08:00
parent 293920aab5
commit c078a70d0d
3 changed files with 139 additions and 0 deletions
@@ -150,5 +150,12 @@ public class OldSystemController {
HttpServletResponse response) throws IOException {
oldSystemService.importGbStandSystem(file, response, "recommend");
}
@GetMapping("/esAuthDeptDataFix")
@AutoLog(value = "老法规系统-企标授权部门数据修复")
@ApiOperation(value="老法规系统-企标授权部门数据修复", notes="老法规系统-企标授权部门数据修复", produces = "application/octet-stream")
@ApiOperationSupport(order = 100)
public void esAuthDeptDataFix() {
oldSystemDeptRelationService.esAuthDeptDataFix();
}
}
@@ -22,4 +22,5 @@ public interface OldSystemDepartRelationService extends IService<OldSystemDepart
*/
void importDepartRelationData(MultipartFile file, HttpServletResponse response);
void esAuthDeptDataFix();
}
@@ -6,11 +6,15 @@ import com.jero.common.api.vo.ResultCommon;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.SysDepartTreeModel;
import com.jero.common.system.vo.SysDictItemCore;
import com.jero.common.util.MessageUtils;
import com.jero.modules.activiti.process.esAnnualInit.entity.ProcessEsAnnualInit;
import com.jero.modules.activiti.util.ExcelUtils;
import com.jero.modules.laws.oldSystem.entity.ESAuthDept;
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardAuthDept;
import com.jero.modules.laws.enterprise.mapper.EnterpriseStandardAuthDeptMapper;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthDeptService;
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
import com.jero.modules.laws.oldSystem.mapper.OldSystemDepartRelationMapper;
@@ -18,22 +22,32 @@ import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.service.ISysDepartService;
import lombok.Cleanup;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.laws.standard.service.ILawsTreeNodeService;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.service.ISysDepartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author ThinkBook
@@ -52,6 +66,18 @@ public class OldSystemDepartRelationServiceImpl extends ServiceImpl<OldSystemDep
@Resource
private ILawsEnterpriseStandardService enterpriseStandardService;
@Resource
private EnterpriseStandardAuthDeptService esAdService;
@Resource
private ILawsEnterpriseStandardService esService;
@Resource
private ISysDepartService departService;
@Resource
private EnterpriseStandardAuthDeptMapper esAdMapper;
@Override
public void importDepartRelationData(MultipartFile file, HttpServletResponse response) {
List<OldSystemDepartRelation> errImportList = new ArrayList<>();
@@ -166,6 +192,111 @@ public class OldSystemDepartRelationServiceImpl extends ServiceImpl<OldSystemDep
}
}
@Override
public void esAuthDeptDataFix() {
List<EnterpriseStandardAuthDept> needSaveAllData = new ArrayList<>();
// 获取所有没有被删除的部门
LambdaQueryWrapper<SysDepart> departWrapper = new LambdaQueryWrapper<>();
departWrapper.eq(SysDepart::getDelFlag, YesOrNoEnum.NO.getValue());
List<SysDepartTreeModel> departListTree = departService.queryTreeList();
// 找到所有已有授权部门权限
LambdaQueryWrapper<EnterpriseStandardAuthDept> esAdWrapper = new LambdaQueryWrapper<>();
esAdWrapper.isNull(EnterpriseStandardAuthDept::getAuthExpireDate);
List<EnterpriseStandardAuthDept> esAdList = esAdService.list(esAdWrapper);
Map<String, List<EnterpriseStandardAuthDept>> esAdMap = esAdList.stream()
.collect(Collectors.groupingBy(EnterpriseStandardAuthDept::getStandardId));
List<String> esIdList = esAdList.stream()
.map(EnterpriseStandardAuthDept::getStandardId).distinct().collect(Collectors.toList());
// 找到所有授权部门不为空的企标
List<LawsEnterpriseStandard> lawsEnterpriseStandards = esService.listByIds(esIdList);
// 遍历企标数据的现有授权部门
for (LawsEnterpriseStandard es : lawsEnterpriseStandards) {
String curStandardId = es.getId();
Set<String> authDeptIdList = esAdMap.get(es.getId()).stream()
.map(EnterpriseStandardAuthDept::getAuthDept)
.collect(Collectors.toSet());
// 创建一个部门Id Set 根据现有授权部门的部门Id找到所有子部门Id
Set<String> childDeptIdSet = new HashSet<>();
// 根据现有授权部门的部门Id找到所有子部门Id
for (String authDeptId : authDeptIdList) {
List<String> childDeptIdList = this.queryChildDeptIdList(authDeptId, departListTree);
if (childDeptIdList.isEmpty()) {
continue;
}
childDeptIdSet.addAll(childDeptIdList);
}
// 根据authDeptIdList去重
childDeptIdSet.removeAll(authDeptIdList);
// 构造需要保存的数据
for (String childDeptId : childDeptIdSet) {
EnterpriseStandardAuthDept esAd = new EnterpriseStandardAuthDept();
esAd.setStandardId(curStandardId);
esAd.setAuthDept(childDeptId);
needSaveAllData.add(esAd);
}
if (childDeptIdSet.isEmpty()) {
log.info("企标编号为{}的企标没有需要修复的数据", es.getStandardNumber());
} else {
log.info("企标编号为{}的企标需要修复的数据条数为:{}", es.getStandardNumber(), childDeptIdSet.size());
}
}
if (needSaveAllData.isEmpty()) {
return;
}
// 根据standardId和authDept去重
List<EnterpriseStandardAuthDept> distinctData = needSaveAllData.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(o -> o.getStandardId() + ";" + o.getAuthDept()))), ArrayList::new));
log.info("需要保存的数据条数为:{}", distinctData.size());
esAdService.saveBatch(needSaveAllData, distinctData.size());
}
// 递归查询所有子部门Id
private List<String> queryChildDeptIdList(String parentId, List<SysDepartTreeModel> departListTree) {
List<String> childDeptIdList = new ArrayList<>();
SysDepartTreeModel depart = getDepartTreeModel(parentId, departListTree);
if (depart != null) {
childDeptIdList.add(depart.getId());
List<SysDepartTreeModel> childList = depart.getChildren();
if (childList != null && !childList.isEmpty()) {
for (SysDepartTreeModel child : childList) {
// 这里改为传递完整的 departList
childDeptIdList.addAll(queryChildDeptIdList(child.getId(), departListTree));
}
}
}
return childDeptIdList;
}
private SysDepartTreeModel getDepartTreeModel(String parentId, List<SysDepartTreeModel> departListTree) {
return getSysDepartTreeModel(parentId, departListTree);
}
private SysDepartTreeModel findDepartInTree(String parentId, List<SysDepartTreeModel> children) {
if (children == null || children.isEmpty()) {
return null;
}
return getSysDepartTreeModel(parentId, children);
}
@Nullable
private SysDepartTreeModel getSysDepartTreeModel(String parentId, List<SysDepartTreeModel> children) {
for (SysDepartTreeModel child : children) {
if (parentId.equals(child.getId())) {
return child;
}
// 继续在子节点的子节点中查找
SysDepartTreeModel found = findDepartInTree(parentId, child.getChildren());
if (found != null) {
return found;
}
}
return null;
}
}