feat: 老法规系统Excel导入

This commit is contained in:
2023-10-23 10:48:59 +08:00
parent baed2e341d
commit e5647848d0
6 changed files with 367 additions and 6 deletions
@@ -13,6 +13,7 @@ import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.MessageUtils;
import com.jero.common.util.MinioUtil;
import com.jero.modules.activiti.process.esAnnualInit.entity.ProcessEsAnnualInit;
import com.jero.modules.laws.common.util.ImportUtil;
import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.common.constant.ResultCommon;
@@ -21,10 +22,12 @@ import com.jero.modules.laws.common.service.ILawsCommonService;
import com.jero.modules.laws.common.vo.ManyStandardSelectionBox;
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardInspectContent;
import com.jero.modules.laws.enterprise.entity.OldSystemImportDTO;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserService;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardInspectContentService;
import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
import com.jero.modules.laws.enterprise.util.WaterMarkUtil;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
import com.jero.modules.laws.standard.entity.LawsNodeRelation;
import com.jero.modules.laws.standard.entity.LawsTreeNode;
import com.jero.modules.laws.standard.service.*;
@@ -56,6 +59,8 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -0,0 +1,191 @@
package com.jero.modules.laws.enterprise.entity;
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 = "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", format = "yyyyMMdd")
private Date fbrq;
@Excel(name = "SSRQ", width = 15, orderNum = "14", format = "yyyyMMdd")
private Date ssrq;
@Excel(name = "TY", width = 15, orderNum = "15")
private String ty;
@Excel(name = "BZZT", width = 15, orderNum = "16", dicCode = "enterprise_standard_state")
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;
/**
* 判断是否是空行
* @return 如果所有字段都为null或空字符串,返回true,否则返回false
*/
public boolean isEmptyRow() {
return id == null && bzh == 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;
}
}
@@ -1,5 +1,6 @@
package com.jero.modules.laws.enterprise.util;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.DictModel;
import com.jero.modules.laws.common.constant.FieldCommon;
@@ -10,6 +11,8 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -139,4 +142,27 @@ public class EnterpriseStandardUtil {
// TODO 校验企标编号是否有效
return true;
}
public static Map<String, String> splitStandardNumber(String standardNumber) {
// 使用正则表达式匹配所需的各个部分
Pattern pattern = Pattern.compile("([A-Za-z]{1,2})\\/([A-Za-z]{1,2}) (\\d)(\\d{4})-(\\d{4})");
Matcher matcher = pattern.matcher(standardNumber);
Map<String, String> map = new HashMap<>();
if (matcher.find()) {
String esCode = matcher.group(1);
String eNameCode = matcher.group(2);
String sCategoryCode = matcher.group(3);
String yearNum = matcher.group(5);
map.put(FieldCommon.ENTERPRISE_STANDARD_CODE, esCode);
map.put(FieldCommon.ENTERPRISE_NAME_CODE, eNameCode);
map.put(FieldCommon.STANDARD_CATEGORY_CODE, sCategoryCode);
map.put(FieldCommon.YEAR_NUMBER, yearNum);
} else {
log.error("企标标准号拆分失败");
throw new JeroBootException("企标标准号拆分失败");
}
return map;
}
}
@@ -15,6 +15,7 @@ import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserServic
import com.jero.modules.laws.enterprise.service.EnterpriseStandardReviewMeetingRecordService;
import com.jero.modules.laws.standard.entity.LawsUpdateRecord;
import com.jero.modules.laws.standard.entity.LawsStandardTempPermission;
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.laws.standard.service.ILawsNodeRelationService;
import com.jero.modules.laws.standard.service.ILawsUpdateRecordService;
import com.jero.modules.personal.service.ILawsStandardCollectionService;
@@ -62,6 +63,9 @@ public class LawsEnterpriseController {
@Resource
private EnterpriseStandardReviewMeetingRecordService esReviewMeetingService;
@Resource
private ILawsEnterpriseStandardService enterpriseStandardService;
private static final String MODULE_VALUE = TableNameEnum.ENTERPRISE_STANDARDS.getValue();
@AutoLog(value = "企业法规标准-分页列表查询")
@@ -238,11 +242,8 @@ public class LawsEnterpriseController {
@ApiOperation(value="企业法规标准-老法规企标数据库Excel导入", notes="企业法规标准-老法规企标数据库Excel导入")
@PostMapping("/importExcelOldSystem")
public Result<?> importExcelOldSystem(@RequestParam("file") MultipartFile file) {
List<String> errorMessages = lawsCommonService.importExcelWithData(file, TableNameEnum.ENTERPRISE_STANDARDS.getValue());
if (errorMessages.size() > 0) {
return Result.error(MessageUtils.getMessage(ResultCommon.IMPORT_ERROR), errorMessages);
}
return Result.OK();
enterpriseStandardService.importExcelOldSystem(file);
return Result.OK("导入成功");
}
/**
@@ -2,6 +2,9 @@ package com.jero.modules.laws.standard.service;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
/**
* @author ThinkBook
@@ -15,4 +18,10 @@ public interface ILawsEnterpriseStandardService extends IService<LawsEnterpriseS
*/
LawsEnterpriseStandard queryByStandardNumber(String standardNumber);
/**
* 老法规系统Excel导入
* @param file
* @return
*/
void importExcelOldSystem(MultipartFile file);
}
@@ -1,19 +1,30 @@
package com.jero.modules.laws.standard.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.CommonAPI;
import com.jero.common.constant.CommonConstant;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.SysDictItemCore;
import com.jero.modules.activiti.util.ExcelUtils;
import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.enterprise.entity.OldSystemImportDTO;
import com.jero.modules.laws.enterprise.service.ESSequenceNumberProvider;
import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -21,11 +32,21 @@ import java.util.stream.Collectors;
* @description 针对表【laws_enterprise_standard(企业标准)】的数据库操作Service实现
* @createDate 2023-09-18 14:49:51
*/
@Slf4j
@Service
@Transactional(rollbackFor = JeroBootException.class)
public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpriseStandardMapper, LawsEnterpriseStandard>
implements ILawsEnterpriseStandardService, ESSequenceNumberProvider {
@Resource
private LawsEnterpriseStandardMapper esMapper;
@Resource
private ExcelUtils excelUtils;
@Resource
private CommonAPI commonAPI;
@Override
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
if (StringUtils.isBlank(standardNumber)){
@@ -38,6 +59,114 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
return getOne(wrapper);
}
@Override
public void importExcelOldSystem(MultipartFile file) {
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
// 获取数据
List<OldSystemImportDTO> list = null;
try {
// 获取当前时间戳(毫秒)
long startTime = System.currentTimeMillis();
list = ExcelImportUtil.importExcel(file.getInputStream(), OldSystemImportDTO.class, params);
// 删除空行
for (int i = 0; i < list.size(); i++) {
OldSystemImportDTO oldSystemImportDTO = list.get(i);
if (oldSystemImportDTO.isEmptyRow()) {
list.remove(i);
i--;
}
}
log.info("获取数据成功,数据条数:{}", list.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
long executionTime = endTime - startTime;
log.info("代码执行时间:" + executionTime + " 毫秒");
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
// 转换数据
List<LawsEnterpriseStandard> esList = new ArrayList<>();
// list判空
if (list == null || list.isEmpty()) {
throw new JeroBootException("导入数据为空");
}
for (OldSystemImportDTO dto : list) {
LawsEnterpriseStandard es = new LawsEnterpriseStandard();
es.setStandardNumber(dto.getBzh());
es.setStandardName(dto.getBzmc());
es.setEnglishName(dto.getBzywmc());
es.setReleaseDate(dto.getFbrq());
es.setImplementationDate(dto.getSsrq());
es.setStandardState(Integer.parseInt(dto.getBzzt()));
es.setSubstituteStandardNumber(dto.getTdbzh());
es.setReplacedByStandardNumber(dto.getBtdbzh());
// 等级分类默认值
es.setGradeClassification("1");
esList.add(es);
}
// 处理数据
this.handleESData(esList);
// 保存数据
// 1. 首先获取所有现有的标准号
List<LawsEnterpriseStandard> existingEntities = esMapper.selectList(new QueryWrapper<>());
// 2. 创建一个Map,用于快速查找是否存在相同的标准号
Map<String, LawsEnterpriseStandard> standardNumberToEntityMap = new HashMap<>();
for (LawsEnterpriseStandard existingEntity : existingEntities) {
standardNumberToEntityMap.put(existingEntity.getStandardNumber(), existingEntity);
}
// 3. 遍历待保存或更新的列表,设置ID
List<LawsEnterpriseStandard> toSaveOrUpdate = new ArrayList<>();
for (LawsEnterpriseStandard entity : esList) {
LawsEnterpriseStandard existingEntity = standardNumberToEntityMap.get(entity.getStandardNumber());
if (existingEntity != null) {
// 如果存在,则设置ID以进行更新
entity.setId(existingEntity.getId());
}
toSaveOrUpdate.add(entity);
}
// 4. 最后,执行批量保存或更新
saveOrUpdateBatch(toSaveOrUpdate);
}
private void handleESData(List<LawsEnterpriseStandard> esList) {
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
// 编号拆分
for (LawsEnterpriseStandard es : esList) {
String standardNumber = es.getStandardNumber();
if (StringUtils.isNotBlank(standardNumber)) {
Map<String, String> map = EnterpriseStandardUtil.splitStandardNumber(standardNumber);
es.setStandardCode(map.get(FieldCommon.ENTERPRISE_STANDARD_CODE));
es.setNameCode(map.get(FieldCommon.ENTERPRISE_NAME_CODE));
es.setCategoryCode(map.get(FieldCommon.STANDARD_CATEGORY_CODE));
es.setYearNumber(map.get(FieldCommon.YEAR_NUMBER));
}
}
// 翻译
for (LawsEnterpriseStandard es : esList) {
String standardCode = es.getStandardCode();
String nameCode = es.getNameCode();
String categoryCode = es.getCategoryCode();
if (StringUtils.isNotBlank(standardCode)) {
es.setStandardCode(excelUtils.translateDictValue("enterprise_standard_code", standardCode, listDict));
}
if (StringUtils.isNotBlank(nameCode)) {
es.setNameCode(excelUtils.translateDictValue("enterprise_name_code", nameCode, listDict));
}
if (StringUtils.isNotBlank(categoryCode)) {
es.setCategoryCode(excelUtils.translateDictValue("standard_category_code", categoryCode, listDict));
}
}
}
@Override
public List<String> getSequenceNumbers(String esCodeDictValue, String esNameCodeDictValue, String categoryCodeDictValue) {
// 已经存在的标准