feat: 标准通用导入体系支持路径模式匹配体系和部门

This commit is contained in:
2024-07-03 10:34:38 +08:00
parent c4d6872394
commit 2e5bf23510
5 changed files with 330 additions and 234 deletions
@@ -10,8 +10,7 @@ import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import java.util.*;
/**
* <p>
@@ -164,4 +163,35 @@ public class SysDepart implements Serializable {
delFlag, createBy, createTime, updateBy, updateTime,
company, headOfDepartment, leadersInCharge, deputyLeader);
}
public static Map<String, String> buildPaths(List<SysDepart> departments) {
Map<String, String> paths = new HashMap<>();
Map<String, SysDepart> departmentMap = new HashMap<>();
// Store departments in a map by ID for quick lookup
for (SysDepart dept : departments) {
departmentMap.put(dept.getId(), dept);
}
// Build path for each department
for (SysDepart dept : departments) {
String path = buildPath(dept, departmentMap);
paths.put(path, dept.getId());
}
return paths;
}
private static String buildPath(SysDepart dept, Map<String, SysDepart> departmentMap) {
if (dept.getParentId() == null || dept.getParentId().isEmpty()) {
return dept.getDepartName(); // Return just this department's name if no parent
} else {
SysDepart parent = departmentMap.get(dept.getParentId());
if (parent == null) {
return dept.getDepartName(); // Parent does not exist in the map
} else {
return buildPath(parent, departmentMap) + "/" + dept.getDepartName();
}
}
}
}
@@ -1396,20 +1396,13 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
**/
@Override
public void setStandardNumber(Map<String, Object> parameterMap) {
// 标准类别
String standardClass = (String) parameterMap.get(FieldCommon.STANDARD_CLASS);
// 法规编号不能为空(新增页面)
String standardNumber = (String) parameterMap.get(FieldCommon.STANDARD_NUMBER_TEMP);
// 年代号
String yearNumber = (String) parameterMap.get(FieldCommon.YEAR_NUMBER);
if (StringUtils.isBlank(standardClass)) {
throw new JeroBootException(ResultCommon.EMPTY_COMMON, FieldCommon.STANDARD_CLASS);
}
if (StringUtils.isBlank(standardNumber)) {
throw new JeroBootException(ResultCommon.EMPTY_STANDARD_NUMBER);
}
// 最后生成的法规编号
standardNumber = standardClass + " " + standardNumber;
if (StringUtils.isNotBlank(yearNumber)) {
standardNumber = standardNumber + "" + yearNumber;
}
@@ -1690,19 +1683,22 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR));
}
String excelName = excelfilelist.get(0).getName();
String moduleCode = "";
if (tableName.equals(TableNameEnum.ENTERPRISE_STANDARDS.getTableName())) {
// 检查Excel的文件名
if (!excelName.equals("企业标准导入模板.xls")) {
if (!excelName.equals("企业标准法规导入模板.xls")) {
FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR));
}
moduleCode = TableNameEnum.ENTERPRISE_STANDARDS.getValue();
}
if (tableName.equals(TableNameEnum.DOMESTIC_REGULATIONS.getTableName())) {
// 检查Excel的文件名
if (!excelName.equals("标准导入模板.xls")) {
if (!excelName.equals("标准法规导入模板.xls")) {
FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR));
}
moduleCode = TableNameEnum.DOMESTIC_REGULATIONS.getValue();
}
// 数据内容格式校验
Map<String, File> fileMap = new HashMap<>();
@@ -1735,6 +1731,14 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
Map<String, LawsTag> headerMap = fieldList.stream().collect(Collectors.toMap(
LawsTag::getDbFieldTxt, lawsTag -> lawsTag
));
// 准备体系校验的数据
List<LawsTreeNode> treeNodeList = this.getTreeNodeList(moduleCode);
Map<String, List<LawsTreeNode>> treeNodeMap = treeNodeList.stream().collect(Collectors.groupingBy(LawsTreeNode::getNodeName));
Map<String, String> treeNodePathMap = LawsTreeNode.buildPaths(treeNodeList);
// 准备部门校验的数据
List<SysDepart> departList = sysDepartService.list();
Map<String, List<SysDepart>> sysDeaprtMap = departList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
Map<String, String> sysDepartPathMap = SysDepart.buildPaths(departList);
// 按照实际顺序创建headerList
List<LawsTag> headerList = new ArrayList<>();
for (Cell cell : hearderRow) {
@@ -1758,11 +1762,19 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// headerList.add(inspectContentTag);
// }
// 获取错误信息
errMsgList = importUtil.validExcelData(sheet, headerList, fileMap, insertDataList);
errMsgList = importUtil.validExcelData(sheet, headerList, fileMap, insertDataList,
treeNodeMap, treeNodePathMap,
sysDeaprtMap,sysDepartPathMap);
}
return errMsgList;
}
private List<LawsTreeNode> getTreeNodeList(String moduleCode) {
LambdaQueryWrapper<LawsTreeNode> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(LawsTreeNode::getModuleCode, moduleCode);
return lawsTreeNodeService.list(queryWrapper);
}
private static void populateFileMap(File rootDir, File currentDir, Map<String, File> fileMap) {
File[] files = currentDir.listFiles(); // 列出所有文件和子目录
if (files != null) {
@@ -69,10 +69,16 @@ public class ImportUtil {
private ILawsDomesticStandardService lawsDomeStandardService;
@Resource
private ILawsPartNameService IPartNameService;
private ILawsPartNameService partNameService;
public List<String> validExcelData(Sheet sheet, List<LawsTag> headerList, Map<String, File> fileMap, List<Map<String, Object>> insertDataList) {
public List<String> validExcelData(Sheet sheet, List<LawsTag> headerList, Map<String, File> fileMap,
List<Map<String, Object>> insertDataList,
Map<String, List<LawsTreeNode>> treeNodeMap,
Map<String, String> treeNodePathMap,
Map<String, List<SysDepart>> sysDepartMap,
Map<String, String> sysDepartPathMap
) {
List<String> errMsgList = new ArrayList<>();
Map<String, Integer> keyMap = new HashMap<>();
// 从数据行开始遍历
@@ -106,12 +112,11 @@ public class ImportUtil {
// 获取当前单元格内容对应的字段
LawsTag tag = headerList.get(j);
// 将国标和外标的三个标准号组成元素取出
// 将外部标准的两个标准号组成元素取出
if (!standardValidFlag) {
if ((TableNameEnum.DOMESTIC_REGULATIONS.getValue().equals(tag.getIsModel()))
&&
(FieldCommon.STANDARD_NUMBER_TEMP.equals(tag.getDbFieldName()) ||
FieldCommon.STANDARD_CLASS.equals(tag.getDbFieldName()) ||
FieldCommon.YEAR_NUMBER.equals(tag.getDbFieldName()))
) {
if (FieldCommon.STANDARD_NUMBER_TEMP.equals(tag.getDbFieldName())) {
@@ -134,20 +139,8 @@ public class ImportUtil {
break;
}
}
if (FieldCommon.STANDARD_CLASS.equals(tag.getDbFieldName())) {
if (cell == null) {
log.error("" + row + "" + tag.getDbFieldTxt() + "为必填 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("为必填 ");
break;
}
standardClass = cell.toString().trim();
}
if (FieldCommon.YEAR_NUMBER.equals(tag.getDbFieldName())) {
if (cell == null || StrUtil.isBlank(cell.toString().trim())) {
// 当前年
Calendar date = Calendar.getInstance();
yearNumber = String.valueOf(date.get(Calendar.YEAR));
} else {
if (cell != null && StrUtil.isNotBlank(cell.toString().trim())) {
// 校验是否是正确的四位数字年
if (!cell.toString().trim().matches("^[0-9]{4}$")) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
@@ -155,20 +148,21 @@ public class ImportUtil {
break;
}
yearNumber = String.valueOf(Integer.parseInt(cell.toString().trim()));
} else {
yearNumber = "BLANK";
}
}
// 如果三个都不为空则校验标准号
if (StrUtil.isNotBlank(standardNumber) && StrUtil.isNotBlank(standardClass) && StrUtil.isNotBlank(yearNumber)) {
// 校验标准号
if (StrUtil.isNotBlank(standardNumber) && StrUtil.isNotBlank(yearNumber)) {
if ((TableNameEnum.DOMESTIC_REGULATIONS.getValue().equals(tag.getIsModel()))) {
// 校验standardClass
if (!this.dictValid("standard_type", standardClass)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else if (!this.yearValid(yearNumber)) {
if (!yearNumber.equals("BLANK") && !this.yearValid(yearNumber)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
String domesticStandardNumber = standardNumber + " " + standardClass + "-" + yearNumber;
String domesticStandardNumber = standardNumber;
if (!yearNumber.equals("BLANK")) {
domesticStandardNumber = standardNumber + "——" + yearNumber;
}
QueryWrapper<LawsDomesticStandard> domesticStandardQueryWrapper = new QueryWrapper<>();
domesticStandardQueryWrapper.eq(FieldCommon.STANDARD_NUMBER, domesticStandardNumber);
domesticStandardQueryWrapper.eq(FieldCommon.DEL_FLAG, YesOrNoEnum.NO.getValue());
@@ -179,7 +173,6 @@ public class ImportUtil {
errMsg.append("").append(line).append("行的标准编号已存在");
break;
}
standardClass = this.convertDictValue("standard_type", standardClass);
// 判断是否有重复数据
if (keyMap.containsKey(domesticStandardNumber)) {
errMsgList.add("" + keyMap.get(domesticStandardNumber) + "行'标准编号'与第" + line + "行数据重复。");
@@ -191,7 +184,6 @@ public class ImportUtil {
}
// 将转好的值加入Map
parameterMap.put(FieldCommon.STANDARD_NUMBER_TEMP, standardNumber);
parameterMap.put(FieldCommon.STANDARD_CLASS, standardClass);
parameterMap.put(FieldCommon.YEAR_NUMBER, yearNumber);
}
}
@@ -296,12 +288,15 @@ public class ImportUtil {
// 单选组织机构
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
if (!this.singleOrgValid(cellValue)) {
List<SysDepart> departList = sysDepartService.list();
Map<String, List<SysDepart>> deaprtMap = departList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
Map<String, String> departPartMap = SysDepart.buildPaths(departList);
if (!this.multiOrgValid(cellValue, deaprtMap, departPartMap)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
// 转为id
cellValue = this.convertSingleOrgId(cellValue);
cellValue = this.convertMultiOrgId(cellValue, deaprtMap, departPartMap);
}
}
// 单选人员
@@ -316,12 +311,12 @@ public class ImportUtil {
}
// 多选组织机构
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
if (!this.multiOrgValid(cellValue)) {
if (!this.multiOrgValid(cellValue, sysDepartMap, sysDepartPathMap)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
// 转为id
cellValue = this.convertMultiOrgId(cellValue);
cellValue = this.convertMultiOrgId(cellValue, sysDepartMap, sysDepartPathMap);
}
}
// 零部件
@@ -336,13 +331,12 @@ public class ImportUtil {
}
// 体系
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
if (!this.standardSystemValid(cellValue)) {
if (!this.standardSystemValid(cellValue, treeNodeMap, treeNodePathMap)) {
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
// 转为id
String moduleCode = tag.getIsModel();
cellValue = this.convertStandardSystem(cellValue, moduleCode);
cellValue = this.convertStandardSystem(cellValue, treeNodeMap, treeNodePathMap);
}
}
// 文件
@@ -411,17 +405,17 @@ public class ImportUtil {
parameterMap.put(tag.getDbFieldName(), cellValue);
// 企标稽查内容文件导入
if (FieldShowTypeEnum.INSPECT_CONTENT_FILE_UPLOAD.getValue().equals(tag.getFieldShowType())) {
if (!this.inspectContentFileValid(cellValue, fileMap)) {
cellValue = null;
log.error("" + row + "" + tag.getDbFieldTxt() + "填写错误 ");
errMsg.append("").append(row).append("").append(tag.getDbFieldTxt()).append("填写错误 ");
} else {
// 转为List
// 将转好的值加入Map
parameterMap.put(tag.getDbFieldName(), this.convertInspectContentFile(cellValue, fileMap));
}
}
// if (FieldShowTypeEnum.INSPECT_CONTENT_FILE_UPLOAD.getValue().equals(tag.getFieldShowType())) {
// if (!this.inspectContentFileValid(cellValue, fileMap)) {
// cellValue = null;
// log.error("第" + row + "列" + tag.getDbFieldTxt() + "填写错误 ");
// errMsg.append("第").append(row).append("列").append(tag.getDbFieldTxt()).append("填写错误 ");
// } else {
// // 转为List
// // 将转好的值加入Map
// parameterMap.put(tag.getDbFieldName(), this.convertInspectContentFile(cellValue, fileMap));
// }
// }
}
if (errMsg.toString().contains("") || errMsg.toString().contains("重复") || errMsg.toString().contains("已存在")) {
errMsgList.add(errMsg.toString());
@@ -432,6 +426,99 @@ public class ImportUtil {
return errMsgList;
}
// 体系校验
public boolean standardSystemValid(String cellValue, Map<String, List<LawsTreeNode>> treeNodeMap, Map<String, String> treeNodePathMap) {
String[] cellValues = cellValue.split(",");
for (String value : cellValues) {
String[] splitValue = value.split("/");
List<LawsTreeNode> lawsTreeNodes = treeNodeMap.get(splitValue[splitValue.length - 1]);
if (lawsTreeNodes != null) {
if (lawsTreeNodes.size() == 1) return true;
if (lawsTreeNodes.size() > 1) {
// 叶子节点名称重复,需要寻找全路径
String nodeId = treeNodePathMap.get(value);
return StrUtil.isNotBlank(nodeId);
}
}
}
return true;
}
// 体系转换
private String convertStandardSystem(String cellValue, Map<String, List<LawsTreeNode>> treeNodeMap, Map<String, String> treeNodePathMap) {
if (StrUtil.isBlank(cellValue)) {
return null;
}
StringBuilder result = new StringBuilder();
String[] cellValues = cellValue.split(",");
for (String value : cellValues) {
String[] splitValue = value.split("/");
List<LawsTreeNode> lawsTreeNodes = treeNodeMap.get(splitValue[splitValue.length - 1]);
if (lawsTreeNodes != null) {
if (lawsTreeNodes.size() == 1) {
result.append(lawsTreeNodes.get(0).getId()).append(",");
}
if (lawsTreeNodes.size() > 1) {
// 叶子节点名称重复,需要寻找全路径
String nodeId = treeNodePathMap.get(value);
result.append(nodeId).append(",");
}
}
}
// 去除掉最后的逗号
return result.substring(0, result.length() - 1);
}
// 多选部门转换
public String convertMultiOrgId(String cellValue, Map<String, List<SysDepart>> sysDepartMap, Map<String, String> sysDepartPathMap) {
if (StrUtil.isBlank(cellValue)) {
return null;
}
StringBuilder result = new StringBuilder();
String[] cellValues = cellValue.split(",");
for (String value : cellValues) {
String[] splitValue = value.split("/");
List<SysDepart> sysDeparts = sysDepartMap.get(splitValue[splitValue.length - 1]);
if (sysDeparts != null) {
if (sysDeparts.size() == 1) {
result.append(sysDeparts.get(0).getId()).append(",");
}
if (sysDeparts.size() > 1) {
// 叶子节点名称重复,需要寻找全路径
String nodeId = sysDepartPathMap.get(value);
result.append(nodeId).append(",");
}
}
}
// 去除掉最后的逗号
return result.substring(0, result.length() - 1);
}
// 组织机构
public boolean multiOrgValid(String cellValue, Map<String, List<SysDepart>> sysDepartMap, Map<String, String> sysDepartPathMap) {
String[] cellValues = cellValue.split(",");
for (String value : cellValues) {
String[] splitValue = value.split("/");
List<SysDepart> sysDeparts = sysDepartMap.get(splitValue[splitValue.length - 1]);
if (sysDeparts != null) {
if (sysDeparts.size() == 1) return true;
if (sysDeparts.size() > 1) {
// 叶子节点名称重复,需要寻找全路径
String nodeId = sysDepartPathMap.get(value);
return StrUtil.isNotBlank(nodeId);
}
}
}
return true;
}
// 单选部门转换
public String convertSingleOrgId(String cellValue) {
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
return sysDepartService.getOne(sysDepartLambdaQueryWrapper).getId();
}
public Date convertDate(String cellValue) {
if (StrUtil.isBlank(cellValue)) {
return null;
@@ -610,26 +697,6 @@ public class ImportUtil {
return fileIds.deleteCharAt(fileIds.length() - 1).toString();
}
// 体系转换
public String convertStandardSystem(String cellValue, String moduleCode) {
if (StrUtil.isBlank(cellValue)) {
return null;
}
List<String> valueList = Arrays.asList(cellValue.split(","));
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
treeNodeLambdaQueryWrapper.eq(LawsTreeNode::getModuleCode, moduleCode);
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
StringBuilder result = new StringBuilder();
for (String value : valueList) {
result.append(systemMap.get(value)).append(",");
}
// 去除掉最后的逗号
return result.substring(0, result.length() - 1);
}
// 单选用户转换
public String convertSingleUserId(String cellValue) {
QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
@@ -642,7 +709,7 @@ public class ImportUtil {
List<String> valueList = Arrays.asList(cellValue.split(","));
LambdaQueryWrapper<PartName> partNameLambdaQueryWrapper = new LambdaQueryWrapper<>();
partNameLambdaQueryWrapper.in(PartName::getName, valueList);
List<PartName> partNameList = IPartNameService.list(partNameLambdaQueryWrapper);
List<PartName> partNameList = partNameService.list(partNameLambdaQueryWrapper);
Map<String, String> partMap = partNameList.stream().collect(Collectors.toMap(PartName::getName, PartName::getCode));
StringBuilder result = new StringBuilder();
@@ -653,29 +720,6 @@ public class ImportUtil {
return result.substring(0, result.length() - 1);
}
// 多选部门转换
public String convertMultiOrgId(String cellValue) {
List<String> valueList = Arrays.asList(cellValue.split(","));
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
List<SysDepart> deptList = sysDepartService.list(sysDepartLambdaQueryWrapper);
Map<String, String> deptMap = deptList.stream().collect(Collectors.toMap(SysDepart::getDepartName, SysDepart::getId));
StringBuilder result = new StringBuilder();
for (String value : valueList) {
result.append(deptMap.get(value)).append(",");
}
// 去除掉最后的逗号
return result.substring(0, result.length() - 1);
}
// 单选部门转换
public String convertSingleOrgId(String cellValue) {
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
return sysDepartService.getOne(sysDepartLambdaQueryWrapper).getId();
}
// 字典转换
public String convertDictValue(String dictCode, String cellValue) {
String[] valueList = cellValue.split(",");
@@ -723,13 +767,6 @@ public class ImportUtil {
return true;
}
// 单选组织机构
public boolean singleOrgValid(String cellValue) {
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
return Objects.nonNull(sysDepartService.getOne(sysDepartLambdaQueryWrapper));
}
// 改为校验人员+姓名 单选人员
public boolean singleUserValid(String cellValue) {
QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
@@ -737,21 +774,12 @@ public class ImportUtil {
return Objects.nonNull(sysUserService.getOne(wrapper));
}
// 多选组织机构
public boolean multiOrgValid(String cellValue) {
List<String> valueList = Arrays.asList(cellValue.split(","));
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
List<SysDepart> list = sysDepartService.list(sysDepartLambdaQueryWrapper);
return valueList.size() == list.size();
}
// 零部件
public boolean partValid(String cellValue) {
String[] valueList = cellValue.split(",");
LambdaQueryWrapper<PartName> partNameWrapper = new LambdaQueryWrapper<>();
partNameWrapper.in(PartName::getName, Arrays.asList(valueList));
List<PartName> list = IPartNameService.list(partNameWrapper);
List<PartName> list = partNameService.list(partNameWrapper);
Map<String, String> partNameMap = list.stream().collect(Collectors.toMap(PartName::getName, PartName::getCode));
for (String value : valueList) {
if (partNameMap.get(value) == null) {
@@ -761,21 +789,6 @@ public class ImportUtil {
return true;
}
// 体系校验
public boolean standardSystemValid(String cellValue) {
List<String> valueList = Arrays.asList(cellValue.split(","));
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
for (String value : valueList) {
if (systemMap.get(value) == null) {
return false;
}
}
return true;
}
// 体系校验
public boolean enStandardSystemValid(String cellValue) {
List<String> valueList = Arrays.asList(cellValue.split(","));
@@ -142,106 +142,106 @@ public class EnterpriseStandardPlanServiceImpl extends ServiceImpl<EnterpriseSta
@Override
public void importAnnualRevisionPlan(MultipartFile file, HttpServletResponse response) throws IOException {
log.info("importAnnualRevisionPlan");
log.info("开始导入年度制修订计划表");
List<EnterpriseStandardPlanImport> importErrorList = new ArrayList<>();
@Cleanup
InputStream inputStream = file.getInputStream();
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setNeedSave(true);
List<EnterpriseStandardPlanImport> importList = new ArrayList<>();
try {
importList = ExcelImportUtil.importExcel(inputStream, EnterpriseStandardPlanImport.class, params);
} catch (Exception e) {
log.error("导入失败: " + e.getMessage());
}
log.info("获取数据成功,总数据条数:{}", importList.size());
String errorInfo = "";
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
for (EnterpriseStandardPlanImport item : importList) {
if (item.isBlankRow()) {
continue;
}
if (item.isUselessRow()) {
errorInfo = "当前行数据制修订类型既不是制定也不是修订,该行不予导入,不作处理";
log.info(errorInfo);
log.info(item.toString());
item.setErrorInfo(errorInfo);
importErrorList.add(item);
continue;
}
EnterpriseStandardPlan esp = new EnterpriseStandardPlan();
try {
// esp.setApplicationCategory(ESPProjectType.getValueByName(item.getApplicationCategory()));
esp.setOriginEnStandardNo(item.getOriginEnStandardNo());
esp.setNewEnStandardNo(item.getNewEnStandardNo());
// esp.setProjectStatus(ESPProjectStatus.getValueByName(item.getProjectStatus()));
// esp.setChangeStatus(ESPChangeType.getValueByName(item.getChangeStatus()));
esp.setNewEnStandardName(item.getNewEnStandardName());
esp.setEnStandardCode(item.getEnStandardCode());
esp.setEnNameCode(item.getEnNameCode());
esp.setStandardCategoryCode(item.getStandardCategoryCode());
esp.setDecadeCode(item.getNewEnStandardNo().substring(item.getNewEnStandardNo().length() - 4));
esp.setEnStandardSystem(importUtil.convertStandardSystem(item.getEnStandardSystem(), "3"));
esp.setStandardType(excelUtils.translateDictValue("esp_standard_type", item.getStandardType(), listDict));
esp.setEnStandardClassification(item.getEnStandardClassification());
esp.setDraftPlannedCompleteDate(importUtil.convertDate(item.getDraftPlannedCompleteDate()));
esp.setSolicitationDraftPlanCompleteDate(importUtil.convertDate(item.getSolicitationDraftPlanCompleteDate()));
esp.setPlanApprovalDate(importUtil.convertDate(item.getPlanApprovalDate()));
esp.setComponentName(excelUtils.translateDictValue("name", "code", "laws_part_name", item.getComponentName(), listDict));
esp.setAuthDept(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getAuthDept(), listDict));
esp.setMainDraftingUser(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getMainDraftingUser(), listDict));
esp.setMainDraftingUnit(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getMainDraftingUnit(), listDict));
esp.setMainDraftingUnitResponsiblePerson(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getMainDraftingUnitResponsiblePerson(), listDict));
esp.setStandardPromoter(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getStandardPromoter(), listDict));
esp.setCooperationUnit(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getCooperationUnit(), listDict));
} catch (Exception e) {
errorInfo = "数据转换异常:" + e.getMessage();
log.info(errorInfo);
log.info(item.toString());
log.error(e.getMessage(), e);
item.setErrorInfo("数据转换异常:" + e.getMessage());
importErrorList.add(item);
continue;
}
// 制定的,拿新企标编号在企标表里查,查到的话要报错,不予导入,统计并反馈;查不到的,数据正常录入plan表
if ("制定".equals(item.getApplicationCategory())) {
ManyStandardSelectionBox singleStandard = lawsCommonService.getSingleStandard(esp.getNewEnStandardNo(), null);
if (ObjectUtils.isNotEmpty(singleStandard)) {
// 查到的话要报错,不予导入,统计并反馈
errorInfo = "该制定类型数据的新企标编号已经在系统中存在,不予导入";
log.info(errorInfo);
log.info(item.toString());
item.setErrorInfo(errorInfo);
importErrorList.add(item);
continue;
} else { // 查不到正常,直接保存
this.save(esp);
}
}
// 修订的,拿旧企标编号在企标表里查,查不到的要报错,不予导入,统计并反馈;查得到的,数据正常录入plan表
if ("修订".equals(item.getApplicationCategory())) {
ManyStandardSelectionBox singleStandard = lawsCommonService.getSingleStandard(esp.getOriginEnStandardNo(), null);
if (ObjectUtils.isEmpty(singleStandard)) {
//查不到的要报错,不予导入
errorInfo = "该修订类型数据的原企标编号在系统中不存在,不予导入";
log.info(errorInfo);
log.info(item.toString());
item.setErrorInfo(errorInfo);
importErrorList.add(item);
continue;
} else { // 查得到正常,直接保存
this.save(esp);
}
}
}
if (!importErrorList.isEmpty()) {
log.info("问题数据条数:{}", importErrorList.size());
excelUtils.exportWithExcel(response, importErrorList, "importAnnualRevisionPlan-ImportErrorData.xls");
}
log.info("年度制修订计划表数据导入结束");
// log.info("importAnnualRevisionPlan");
// log.info("开始导入年度制修订计划表");
// List<EnterpriseStandardPlanImport> importErrorList = new ArrayList<>();
// @Cleanup
// InputStream inputStream = file.getInputStream();
// ImportParams params = new ImportParams();
// params.setTitleRows(0);
// params.setNeedSave(true);
// List<EnterpriseStandardPlanImport> importList = new ArrayList<>();
// try {
// importList = ExcelImportUtil.importExcel(inputStream, EnterpriseStandardPlanImport.class, params);
// } catch (Exception e) {
// log.error("导入失败: " + e.getMessage());
// }
// log.info("获取数据成功,总数据条数:{}", importList.size());
// String errorInfo = "";
// List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
// for (EnterpriseStandardPlanImport item : importList) {
// if (item.isBlankRow()) {
// continue;
// }
// if (item.isUselessRow()) {
// errorInfo = "当前行数据制修订类型既不是制定也不是修订,该行不予导入,不作处理";
// log.info(errorInfo);
// log.info(item.toString());
// item.setErrorInfo(errorInfo);
// importErrorList.add(item);
// continue;
// }
// EnterpriseStandardPlan esp = new EnterpriseStandardPlan();
// try {
//// esp.setApplicationCategory(ESPProjectType.getValueByName(item.getApplicationCategory()));
// esp.setOriginEnStandardNo(item.getOriginEnStandardNo());
// esp.setNewEnStandardNo(item.getNewEnStandardNo());
//// esp.setProjectStatus(ESPProjectStatus.getValueByName(item.getProjectStatus()));
//// esp.setChangeStatus(ESPChangeType.getValueByName(item.getChangeStatus()));
// esp.setNewEnStandardName(item.getNewEnStandardName());
// esp.setEnStandardCode(item.getEnStandardCode());
// esp.setEnNameCode(item.getEnNameCode());
// esp.setStandardCategoryCode(item.getStandardCategoryCode());
// esp.setDecadeCode(item.getNewEnStandardNo().substring(item.getNewEnStandardNo().length() - 4));
// esp.setEnStandardSystem(importUtil.convertStandardSystem(item.getEnStandardSystem(), "3"));
// esp.setStandardType(excelUtils.translateDictValue("esp_standard_type", item.getStandardType(), listDict));
// esp.setEnStandardClassification(item.getEnStandardClassification());
// esp.setDraftPlannedCompleteDate(importUtil.convertDate(item.getDraftPlannedCompleteDate()));
// esp.setSolicitationDraftPlanCompleteDate(importUtil.convertDate(item.getSolicitationDraftPlanCompleteDate()));
// esp.setPlanApprovalDate(importUtil.convertDate(item.getPlanApprovalDate()));
// esp.setComponentName(excelUtils.translateDictValue("name", "code", "laws_part_name", item.getComponentName(), listDict));
// esp.setAuthDept(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getAuthDept(), listDict));
// esp.setMainDraftingUser(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getMainDraftingUser(), listDict));
// esp.setMainDraftingUnit(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getMainDraftingUnit(), listDict));
// esp.setMainDraftingUnitResponsiblePerson(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getMainDraftingUnitResponsiblePerson(), listDict));
// esp.setStandardPromoter(excelUtils.translateDictValue("CONCAT(realname, '(', username, ')')", "id", "sys_user", item.getStandardPromoter(), listDict));
// esp.setCooperationUnit(excelUtils.translateDictValue("depart_name", "id", "sys_depart", item.getCooperationUnit(), listDict));
// } catch (Exception e) {
// errorInfo = "数据转换异常:" + e.getMessage();
// log.info(errorInfo);
// log.info(item.toString());
// log.error(e.getMessage(), e);
// item.setErrorInfo("数据转换异常:" + e.getMessage());
// importErrorList.add(item);
// continue;
// }
// // 制定的,拿新企标编号在企标表里查,查到的话要报错,不予导入,统计并反馈;查不到的,数据正常录入plan表
// if ("制定".equals(item.getApplicationCategory())) {
// ManyStandardSelectionBox singleStandard = lawsCommonService.getSingleStandard(esp.getNewEnStandardNo(), null);
// if (ObjectUtils.isNotEmpty(singleStandard)) {
// // 查到的话要报错,不予导入,统计并反馈
// errorInfo = "该制定类型数据的新企标编号已经在系统中存在,不予导入";
// log.info(errorInfo);
// log.info(item.toString());
// item.setErrorInfo(errorInfo);
// importErrorList.add(item);
// continue;
// } else { // 查不到正常,直接保存
// this.save(esp);
// }
// }
// // 修订的,拿旧企标编号在企标表里查,查不到的要报错,不予导入,统计并反馈;查得到的,数据正常录入plan表
// if ("修订".equals(item.getApplicationCategory())) {
// ManyStandardSelectionBox singleStandard = lawsCommonService.getSingleStandard(esp.getOriginEnStandardNo(), null);
// if (ObjectUtils.isEmpty(singleStandard)) {
// //查不到的要报错,不予导入
// errorInfo = "该修订类型数据的原企标编号在系统中不存在,不予导入";
// log.info(errorInfo);
// log.info(item.toString());
// item.setErrorInfo(errorInfo);
// importErrorList.add(item);
// continue;
// } else { // 查得到正常,直接保存
// this.save(esp);
// }
// }
//
// }
// if (!importErrorList.isEmpty()) {
// log.info("问题数据条数:{}", importErrorList.size());
// excelUtils.exportWithExcel(response, importErrorList, "importAnnualRevisionPlan-ImportErrorData.xls");
// }
// log.info("年度制修订计划表数据导入结束");
}
}
@@ -2,8 +2,9 @@ package com.jero.modules.laws.standard.entity;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.*;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -81,4 +82,44 @@ public class LawsTreeNode implements Serializable {
/**排序*/
@ApiModelProperty(value = "排序")
private java.lang.Integer nodeOrder;
public LawsTreeNode(String id, String parentId, String name) {
this.id = id;
this.parentId = parentId;
this.nodeName = name;
}
// 构建路径的方法
public static Map<String, String> buildPaths(List<LawsTreeNode> nodes) {
Map<String, String> paths = new HashMap<>();
Map<String, LawsTreeNode> nodeMap = new HashMap<>();
// 将节点存储在map中,便于快速查找
for (LawsTreeNode node : nodes) {
nodeMap.put(node.getId(), node);
}
// 构建路径
for (LawsTreeNode node : nodes) {
String path = buildPath(node, nodeMap);
paths.put(path, node.getId());
}
return paths;
}
// 递归构建路径
private static String buildPath(LawsTreeNode node, Map<String, LawsTreeNode> nodeMap) {
if (node.getParentId() == null || node.getParentId().isEmpty()) {
return node.getNodeName();
} else {
LawsTreeNode parent = nodeMap.get(node.getParentId());
if (parent == null) {
return node.getNodeName(); // 父节点不存在
} else {
return buildPath(parent, nodeMap) + "/" + node.getNodeName();
}
}
}
}