feat: 老法规企标体系关联导入
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/12/5 10:49
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ESOldStandardSystem {
|
||||
|
||||
@Excel(name = "ID", width = 15, orderNum = "0")
|
||||
private String id;
|
||||
|
||||
@Excel(name = "BZH", width = 15, orderNum = "1")
|
||||
private String bzh;
|
||||
|
||||
@Excel(name = "BZMC", width = 15, orderNum = "4")
|
||||
private String bzmc;
|
||||
|
||||
@Excel(name = "BZYWMC", width = 15, orderNum = "5")
|
||||
private String bzywmc;
|
||||
|
||||
@Excel(name = "BZFL-NEW", width = 15, orderNum = "6")
|
||||
private String bzfl;
|
||||
|
||||
@Excel(name = "错误信息", width = 35, orderNum = "52")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
/**
|
||||
* 判断是否是空行
|
||||
* @return 如果所有字段都为null或空字符串,返回true,否则返回false
|
||||
*/
|
||||
public boolean isEmptyRow() {
|
||||
return id == null && bzmc == null && bzywmc == null && bzfl == null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/10/20 16:17
|
||||
*/
|
||||
@Data
|
||||
public class OldSystemImportDTO {
|
||||
|
||||
@Excel(name = "ID", width = 15, orderNum = "0")
|
||||
private String id;
|
||||
|
||||
@Excel(name = "BZH", width = 15, orderNum = "1")
|
||||
private String bzh;
|
||||
|
||||
@Excel(name = "STATUS", width = 15, orderNum = "2")
|
||||
private String status;
|
||||
|
||||
@Excel(name = "CYBZH", width = 15, orderNum = "3")
|
||||
private String cybzh;
|
||||
|
||||
@Excel(name = "BZMC", width = 15, orderNum = "4")
|
||||
private String bzmc;
|
||||
|
||||
@Excel(name = "BZYWMC", width = 15, orderNum = "5")
|
||||
private String bzywmc;
|
||||
|
||||
@Excel(name = "BZFL", width = 15, orderNum = "6")
|
||||
private String bzfl;
|
||||
|
||||
@Excel(name = "国家/地区", width = 15, orderNum = "6", dicCode = "country_or_region")
|
||||
private String country;
|
||||
|
||||
@Excel(name = "BZYYTYPE", width = 15, orderNum = "7")
|
||||
private String bzyytype;
|
||||
|
||||
@Excel(name = "BZDJTYPE", width = 15, orderNum = "8")
|
||||
private String bzdjtype;
|
||||
|
||||
@Excel(name = "BZLBTYPE", width = 15, orderNum = "9")
|
||||
private String bzlbtype;
|
||||
|
||||
@Excel(name = "BZLCFJ", width = 15, orderNum = "10")
|
||||
private String bzlcgj;
|
||||
|
||||
@Excel(name = "BZSYDW", width = 15, orderNum = "11")
|
||||
private String bzsydw;
|
||||
|
||||
@Excel(name = "ZTC", width = 15, orderNum = "12")
|
||||
private String ztc;
|
||||
|
||||
@Excel(name = "FBRQ", width = 15, orderNum = "13")
|
||||
private String fbrq;
|
||||
|
||||
@Excel(name = "SSRQ", width = 15, orderNum = "14")
|
||||
private String ssrq;
|
||||
|
||||
@Excel(name = "TY", width = 15, orderNum = "15")
|
||||
private String ty;
|
||||
|
||||
@Excel(name = "BZZT", width = 15, orderNum = "16")
|
||||
private String bzzt;
|
||||
|
||||
@Excel(name = "BZXZ", width = 15, orderNum = "17")
|
||||
private String bzxz;
|
||||
|
||||
@Excel(name = "TDBZH", width = 15, orderNum = "18")
|
||||
private String tdbzh;
|
||||
|
||||
@Excel(name = "BTDBZH", width = 15, orderNum = "19")
|
||||
private String btdbzh;
|
||||
|
||||
@Excel(name = "BZLY", width = 15, orderNum = "20")
|
||||
private String bzly;
|
||||
|
||||
@Excel(name = "BGFS", width = 15, orderNum = "21")
|
||||
private String bgfs;
|
||||
|
||||
@Excel(name = "BGDD", width = 15, orderNum = "22")
|
||||
private String bgdd;
|
||||
|
||||
@Excel(name = "FZRQ", width = 15, orderNum = "23")
|
||||
private String fzrq;
|
||||
|
||||
@Excel(name = "LRRQ", width = 15, orderNum = "24")
|
||||
private String lrrq;
|
||||
|
||||
@Excel(name = "LRR", width = 15, orderNum = "25")
|
||||
private String lrr;
|
||||
|
||||
@Excel(name = "LRRID", width = 15, orderNum = "26")
|
||||
private String lrrid;
|
||||
|
||||
@Excel(name = "LRGS", width = 15, orderNum = "27")
|
||||
private String lrgs;
|
||||
|
||||
@Excel(name = "LRBM", width = 15, orderNum = "28")
|
||||
private String lrbm;
|
||||
|
||||
@Excel(name = "BZ", width = 15, orderNum = "29")
|
||||
private String bz;
|
||||
|
||||
@Excel(name = "GKYF", width = 15, orderNum = "30")
|
||||
private String gkyf;
|
||||
|
||||
@Excel(name = "SCLJ", width = 15, orderNum = "31")
|
||||
private String sclj;
|
||||
|
||||
@Excel(name = "SWFLJ", width = 15, orderNum = "32")
|
||||
private String swflj;
|
||||
|
||||
@Excel(name = "DOCLJ", width = 15, orderNum = "33")
|
||||
private String doclj;
|
||||
|
||||
@Excel(name = "BZJD", width = 15, orderNum = "34")
|
||||
private String bzjd;
|
||||
|
||||
@Excel(name = "BZJDRQ", width = 15, orderNum = "35")
|
||||
private String bzjdrq;
|
||||
|
||||
@Excel(name = "BZSH", width = 15, orderNum = "36")
|
||||
private String bzsh;
|
||||
|
||||
@Excel(name = "BZSHRQ", width = 15, orderNum = "37")
|
||||
private String bzshrq;
|
||||
|
||||
@Excel(name = "QSQC", width = 15, orderNum = "38")
|
||||
private String qsqc;
|
||||
|
||||
@Excel(name = "QSJD", width = 15, orderNum = "39")
|
||||
private String qsjd;
|
||||
|
||||
@Excel(name = "QSSH", width = 15, orderNum = "40")
|
||||
private String qssh;
|
||||
|
||||
@Excel(name = "QSBZH", width = 15, orderNum = "41")
|
||||
private String qsbzh;
|
||||
|
||||
@Excel(name = "QSHQ", width = 15, orderNum = "42")
|
||||
private String qshq;
|
||||
|
||||
@Excel(name = "QSPZ", width = 15, orderNum = "43")
|
||||
private String qspz;
|
||||
|
||||
@Excel(name = "QSRQ", width = 15, orderNum = "44")
|
||||
private String qsrq;
|
||||
|
||||
@Excel(name = "SYZY", width = 15, orderNum = "45")
|
||||
private String syzy;
|
||||
|
||||
@Excel(name = "BAZT", width = 15, orderNum = "46")
|
||||
private String bazt;
|
||||
|
||||
@Excel(name = "BAJB", width = 15, orderNum = "47")
|
||||
private String bajb;
|
||||
|
||||
@Excel(name = "ZRR", width = 15, orderNum = "48")
|
||||
private String zrr;
|
||||
|
||||
@Excel(name = "ZRRID", width = 15, orderNum = "49")
|
||||
private String zrrid;
|
||||
|
||||
@Excel(name = "ZRBM", width = 15, orderNum = "50")
|
||||
private String zrbm;
|
||||
|
||||
@Excel(name = "BZCOUNTRY", width = 15, orderNum = "51")
|
||||
private String bzcountry;
|
||||
|
||||
@Excel(name = "错误信息", width = 35, orderNum = "52")
|
||||
@TableField(exist = false)
|
||||
private String errorInfo;
|
||||
|
||||
/**
|
||||
* 判断是否是空行
|
||||
* @return 如果所有字段都为null或空字符串,返回true,否则返回false
|
||||
*/
|
||||
public boolean isEmptyRow() {
|
||||
return id == null && status == null && cybzh == null
|
||||
&& bzmc == null && bzywmc == null && bzfl == null && bzyytype == null
|
||||
&& bzdjtype == null && bzlbtype == null && bzlcgj == null && bzsydw == null
|
||||
&& ztc == null && fbrq == null && ssrq == null && ty == null
|
||||
&& bzzt == null && bzxz == null && tdbzh == null && btdbzh == null
|
||||
&& bzly == null && bgfs == null && bgdd == null && fzrq == null
|
||||
&& lrrq == null && lrr == null && lrrid == null && lrgs == null
|
||||
&& lrbm == null && bz == null && gkyf == null && sclj == null
|
||||
&& swflj == null && doclj == null && bzjd == null && bzjdrq == null
|
||||
&& bzsh == null && bzshrq == null && qsqc == null && qsjd == null
|
||||
&& qssh == null && qsbzh == null && qshq == null && qspz == null
|
||||
&& qsrq == null && syzy == null && bazt == null && bajb == null
|
||||
&& zrr == null && zrrid == null && zrbm == null && bzcountry == null;
|
||||
}
|
||||
|
||||
}
|
||||
+115
-9
@@ -16,25 +16,21 @@ import com.jero.modules.activiti.util.ExcelUtils;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardAuthDept;
|
||||
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardAuthUser;
|
||||
import com.jero.modules.laws.enterprise.entity.OldSystemImportDTO;
|
||||
import com.jero.modules.laws.enterprise.entity.vo.LawsTreeNodeModel;
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemImportDTO;
|
||||
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthDeptService;
|
||||
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserService;
|
||||
import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
|
||||
import com.jero.modules.laws.home.service.ILawsHomeSearchService;
|
||||
import com.jero.modules.laws.oldSystem.entity.ESAuthAll;
|
||||
import com.jero.modules.laws.oldSystem.entity.ESAuthDept;
|
||||
import com.jero.modules.laws.oldSystem.entity.ESAuthUser;
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.jero.modules.laws.oldSystem.entity.*;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemService;
|
||||
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsOverseasStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsTreeNode;
|
||||
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
||||
import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsOverseasStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
import com.jero.modules.laws.standard.service.*;
|
||||
import com.jero.modules.laws.standard.util.StandardSplitUtils;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
@@ -42,6 +38,7 @@ import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.tag.enums.TableNameEnum;
|
||||
import io.minio.errors.MinioException;
|
||||
import lombok.Cleanup;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -52,6 +49,7 @@ 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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -124,6 +122,12 @@ public class OldSystemServiceImpl implements OldSystemService {
|
||||
@Resource
|
||||
private ILawsEnterpriseStandardService esService;
|
||||
|
||||
@Resource
|
||||
private ILawsTreeNodeService treeNodeService;
|
||||
|
||||
@Resource
|
||||
private ILawsNodeRelationService lawsNodeRelationService;
|
||||
|
||||
@Override
|
||||
public void importExcelOldSystem(MultipartFile file, String type, HttpServletResponse response) {
|
||||
List<OldSystemImportDTO> errImportList = new ArrayList<>();
|
||||
@@ -858,7 +862,109 @@ public class OldSystemServiceImpl implements OldSystemService {
|
||||
|
||||
@Override
|
||||
public void importEsStandSystem(MultipartFile file, HttpServletResponse response) {
|
||||
List<ESOldStandardSystem> errImportList = new ArrayList<>();
|
||||
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
|
||||
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
||||
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(0);
|
||||
params.setNeedSave(true);
|
||||
|
||||
// 获取所有企标转为Map
|
||||
// 筛选有oldSystemId的数据
|
||||
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
|
||||
List<LawsEnterpriseStandard> esList = esService.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
|
||||
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
|
||||
|
||||
// 获取所有企标体系节点并转为Map
|
||||
String moduleCode = TableNameEnum.ENTERPRISE_STANDARDS.getValue();
|
||||
LambdaQueryWrapper<LawsTreeNode> treeNodeWrapper = new LambdaQueryWrapper<>();
|
||||
treeNodeWrapper.eq(LawsTreeNode::getModuleCode, moduleCode);
|
||||
treeNodeWrapper.eq(LawsTreeNode::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||
List<LawsTreeNode> treeNodeList = treeNodeService.list(treeNodeWrapper);
|
||||
Map<String, LawsTreeNode> nodeIdMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getId, o -> o));
|
||||
// 构建路径Map
|
||||
Map<String, LawsTreeNode> pathMap = treeNodeList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
node -> buildPathToRoot(node.getId(), nodeIdMap),
|
||||
o -> o));
|
||||
|
||||
// 获取数据
|
||||
List<ESOldStandardSystem> datalist;
|
||||
try {
|
||||
// 获取当前时间戳(毫秒)
|
||||
long startTime = System.currentTimeMillis();
|
||||
@Cleanup
|
||||
InputStream inputStream = file.getInputStream();
|
||||
datalist = ExcelImportUtil.importExcel(inputStream, ESOldStandardSystem.class, params);
|
||||
// 删除空行
|
||||
datalist.removeIf(ESOldStandardSystem::isEmptyRow);
|
||||
// 只取用企标数据
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算执行时间(毫秒)
|
||||
long executionTime = endTime - startTime;
|
||||
log.info("数据转换执行时间:" + executionTime + " 毫秒");
|
||||
|
||||
for (ESOldStandardSystem ss : datalist) {
|
||||
try {
|
||||
String bzfl = ss.getBzfl();
|
||||
// 根据标准分类找到对应的节点
|
||||
LawsTreeNode treeNode = pathMap.get(bzfl);
|
||||
if (treeNode == null) {
|
||||
throw new JeroBootException("未找到该节点,节点名称:" + bzfl);
|
||||
}
|
||||
// 根据当前数据的id找到对应的企标
|
||||
LawsEnterpriseStandard es = esMap.get(ss.getId());
|
||||
if (es == null) {
|
||||
throw new JeroBootException("未找到该企标,标准编号:" + ss.getBzh() + ",标准名称:" + ss.getBzmc());
|
||||
}
|
||||
lawsNodeRelationService.removeByStandardId(es.getId());
|
||||
lawsNodeRelationService.addRelation(treeNode.getId(), null, es.getId());
|
||||
}catch (Exception e) {
|
||||
log.error("错误数据:{}", ss.toString());
|
||||
ss.setErrorInfo(e.getMessage());
|
||||
errImportList.add(ss);
|
||||
}
|
||||
}
|
||||
log.info("企标体系导入成功");
|
||||
} catch (Exception e) {
|
||||
log.error("导入失败;{}", e.getMessage());
|
||||
|
||||
}
|
||||
if (!errImportList.isEmpty()) {
|
||||
log.info("导入失败数据条数:{}", errImportList.size());
|
||||
this.exportWithExcel(response, errImportList, "ESStandSystemErrorData.xls");
|
||||
}
|
||||
log.info("企标体系导入结束");
|
||||
}
|
||||
|
||||
// 获取父节点的nodeCode
|
||||
private String getParentNodeCode(String nodeCode) {
|
||||
if (nodeCode.length() > 3) {
|
||||
return nodeCode.substring(0, nodeCode.length() - 3);
|
||||
} else {
|
||||
return null; // 没有父节点
|
||||
}
|
||||
}
|
||||
|
||||
// 在您的类中添加这个方法
|
||||
private String buildPathToRoot(String nodeId, Map<String, LawsTreeNode> nodeIdMap) {
|
||||
// 获取当前节点
|
||||
LawsTreeNode currentNode = nodeIdMap.get(nodeId);
|
||||
if (currentNode == null) {
|
||||
return ""; // 或者处理节点不存在的情况
|
||||
}
|
||||
// 检查是否是根节点
|
||||
if (currentNode.getParentId() == null || currentNode.getParentId().isEmpty()) {
|
||||
return currentNode.getNodeName(); // 根节点的情况
|
||||
}
|
||||
// 递归地构建路径
|
||||
String parentPath = buildPathToRoot(currentNode.getParentId(), nodeIdMap);
|
||||
return parentPath + "/" + currentNode.getNodeName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user