feat: 老法规导入接口
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
package com.jero.modules.laws.oldSystem.controller;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/11/10 14:46
|
||||
*/
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.aspect.annotation.Translation;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
|
||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
@ApiSupport(order = 10101)
|
||||
@Api(tags="老法规系统")
|
||||
@RestController
|
||||
@RequestMapping("/oldSystem")
|
||||
@Slf4j
|
||||
public class OldSystemController {
|
||||
|
||||
@Resource
|
||||
private OldSystemDepartRelationService oldSystemService;
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
@ApiOperation(value = "老法规系统-老部门现部门关系导入", notes = "老法规系统-老部门现部门关系导入")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@AutoLog(value = "老法规系统-老部门现部门关系导入")
|
||||
public Result<?> importExcel(@ApiParam(value = "要上传的文件", required = true) @RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> resultMap = oldSystemService.importData(file);
|
||||
Object flag = resultMap.get("flag");
|
||||
if (flag == YesOrNoEnum.YES.getValue()) {
|
||||
return Result.OK(resultMap.get("dataList"));
|
||||
} else {
|
||||
return Result.error("导入失败", resultMap.get("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
@Resource
|
||||
private ILawsEnterpriseStandardService enterpriseStandardService;
|
||||
|
||||
@PostMapping("/importOldSystemESZip")
|
||||
@AutoLog(value = "老法规系统-老法规企标国标数据库Zip导入")
|
||||
@ApiOperation(value="老法规系统-老法规企标国标数据库Zip导入", notes="老法规系统-老法规企标国标数据库Zip导入", produces = "application/octet-stream")
|
||||
@ApiOperationSupport(order = 2)
|
||||
public void importOldSystemESZip(@RequestParam("file") MultipartFile file,
|
||||
@ApiParam(value = "0不导入 1导入企标 2导入国标 3一起导入", required = true)
|
||||
@RequestParam("type") String type,
|
||||
HttpServletResponse response) {
|
||||
enterpriseStandardService.importExcelOldSystem(file, type, response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName old_system_depart_relation
|
||||
*/
|
||||
@TableName(value ="old_system_depart_relation")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OldSystemDepartRelation implements Serializable {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 组织部门
|
||||
*/
|
||||
@Excel(name = "组织部门", width = 15)
|
||||
@ApiModelProperty(value = "组织部门")
|
||||
private String oldOrgName;
|
||||
|
||||
/**
|
||||
* 上级组织
|
||||
*/
|
||||
@Excel(name = "上级组织", width = 15)
|
||||
@ApiModelProperty(value = "上级组织")
|
||||
private String oldOrgSuperior;
|
||||
|
||||
/**
|
||||
* 组织级别
|
||||
*/
|
||||
@Excel(name = "组织级别", width = 15)
|
||||
@ApiModelProperty(value = "组织级别")
|
||||
private String orgLevel;
|
||||
|
||||
/**
|
||||
* 现组织部门
|
||||
*/
|
||||
@Excel(name = "现组织部门", width = 15)
|
||||
@ApiModelProperty(value = "现组织部门")
|
||||
private String curOrgName;
|
||||
|
||||
/**
|
||||
* 上级组织
|
||||
*/
|
||||
@Excel(name = "现上级组织", width = 15)
|
||||
@ApiModelProperty(value = "现上级组织")
|
||||
private String curOrgSuperior;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.jero.modules.laws.oldSystem.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName old_system_problem
|
||||
*/
|
||||
@TableName(value ="old_system_problem")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class OldSystemProblem implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
private String orgCode;
|
||||
|
||||
/**
|
||||
* 问题类型(1老法规国标导入 2老法规企标导入)
|
||||
*/
|
||||
@Excel(name = "问题类型", width = 15)
|
||||
@ApiModelProperty(value = "问题类型")
|
||||
private String problemType;
|
||||
|
||||
/**
|
||||
* 问题描述
|
||||
*/
|
||||
@Excel(name = "问题描述", width = 15)
|
||||
@ApiModelProperty(value = "问题描述")
|
||||
private String problemDescription;
|
||||
|
||||
/**
|
||||
* 问题标准号
|
||||
*/
|
||||
@Excel(name = "问题标准号", width = 15)
|
||||
@ApiModelProperty(value = "问题标准号")
|
||||
private String problemStandardNo;
|
||||
|
||||
/**
|
||||
* 最终结果
|
||||
*/
|
||||
@Excel(name = "最终结果", width = 15)
|
||||
@ApiModelProperty(value = "最终结果")
|
||||
private String result;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.jero.modules.laws.oldSystem.mapper;
|
||||
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_depart_relation】的数据库操作Mapper
|
||||
* @createDate 2023-11-10 14:17:20
|
||||
* @Entity com.jero.modules.laws.entity.OldSystemDepartRelation
|
||||
*/
|
||||
public interface OldSystemDepartRelationMapper extends BaseMapper<OldSystemDepartRelation> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.jero.modules.laws.oldSystem.mapper;
|
||||
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemProblem;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_problem】的数据库操作Mapper
|
||||
* @createDate 2023-11-10 18:18:36
|
||||
* @Entity com.jero.modules.laws.oldSystem.entity.OldSystemProblem
|
||||
*/
|
||||
public interface OldSystemProblemMapper extends BaseMapper<OldSystemProblem> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.jero.modules.laws.oldSystem.service;
|
||||
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_depart_relation】的数据库操作Service
|
||||
* @createDate 2023-11-10 14:17:20
|
||||
*/
|
||||
public interface OldSystemDepartRelationService extends IService<OldSystemDepartRelation> {
|
||||
|
||||
Map<String, Object> importData(MultipartFile file);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.jero.modules.laws.oldSystem.service;
|
||||
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemProblem;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_problem】的数据库操作Service
|
||||
* @createDate 2023-11-10 18:18:36
|
||||
*/
|
||||
public interface OldSystemProblemService extends IService<OldSystemProblem> {
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.jero.modules.laws.oldSystem.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.SysDictItemCore;
|
||||
import com.jero.modules.activiti.process.esAnnualInit.entity.ProcessEsAnnualInit;
|
||||
import com.jero.modules.activiti.util.ExcelUtils;
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
|
||||
import com.jero.modules.laws.oldSystem.mapper.OldSystemDepartRelationMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_depart_relation】的数据库操作Service实现
|
||||
* @createDate 2023-11-10 14:17:20
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class OldSystemDepartRelationServiceImpl extends ServiceImpl<OldSystemDepartRelationMapper, OldSystemDepartRelation>
|
||||
implements OldSystemDepartRelationService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> importData(MultipartFile file) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
List<String> errorMsgs = new ArrayList<>();
|
||||
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(0);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
|
||||
try {
|
||||
List<OldSystemDepartRelation> list = ExcelImportUtil.importExcel(file.getInputStream(), OldSystemDepartRelation.class, params);
|
||||
saveBatch(list, list.size());
|
||||
} catch (Exception e) {
|
||||
errorMsgs.add("文件导入异常:" + e.getMessage());
|
||||
resultMap.put("msg", errorMsgs);
|
||||
resultMap.put("flag", YesOrNoEnum.NO.getValue());
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.jero.modules.laws.oldSystem.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.modules.laws.oldSystem.entity.OldSystemProblem;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemProblemService;
|
||||
import com.jero.modules.laws.oldSystem.mapper.OldSystemProblemMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【old_system_problem】的数据库操作Service实现
|
||||
* @createDate 2023-11-10 18:18:36
|
||||
*/
|
||||
@Service
|
||||
public class OldSystemProblemServiceImpl extends ServiceImpl<OldSystemProblemMapper, OldSystemProblem>
|
||||
implements OldSystemProblemService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-2
@@ -4,7 +4,7 @@ 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;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
@@ -20,8 +20,10 @@ public interface ILawsEnterpriseStandardService extends IService<LawsEnterpriseS
|
||||
|
||||
/**
|
||||
* 老法规系统Excel导入
|
||||
*
|
||||
* @param file
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
void importExcelOldSystem(MultipartFile file, String type);
|
||||
void importExcelOldSystem(MultipartFile file, String type, HttpServletResponse response);
|
||||
}
|
||||
|
||||
+175
-87
@@ -1,26 +1,38 @@
|
||||
package com.jero.modules.laws.standard.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.CommonAPI;
|
||||
import com.jero.common.api.vo.ResultCommon;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.SysDictItemCore;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
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.oldSystem.entity.OldSystemDepartRelation;
|
||||
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
|
||||
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
|
||||
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||
import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||
import com.jero.modules.laws.standard.mapper.LawsEnterpriseStandardMapper;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -28,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
@@ -63,6 +76,15 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
@Resource
|
||||
private ILawsReplacedStandardService lawsReplacedStandardService;
|
||||
|
||||
@Resource
|
||||
private OldSystemDepartRelationService oldDeptService;
|
||||
|
||||
@Resource
|
||||
private ISysDepartService departService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
||||
if (StringUtils.isBlank(standardNumber)) {
|
||||
@@ -75,51 +97,10 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
return getOne(wrapper);
|
||||
}
|
||||
|
||||
|
||||
private void handleESData(List<LawsEnterpriseStandard> esList) {
|
||||
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
|
||||
// 编号拆分
|
||||
for (LawsEnterpriseStandard es : esList) {
|
||||
String standardNumber = es.getStandardNumber();
|
||||
// 如果标准号中有错误符号 则需要修正一下
|
||||
// 正则表达式用于检测是否存在错误的“-”作为分隔符
|
||||
String regex = "([A-Za-z]{1,2})-([A-Za-z]{1,2}) (\\d{4,5}(\\.\\d+)?)-(\\d{4})";
|
||||
|
||||
// 使用Pattern和Matcher检测是否匹配
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(standardNumber);
|
||||
if (matcher.find()) {
|
||||
// 如果匹配,将第一个“-”替换为“/”
|
||||
standardNumber = standardNumber.replaceFirst("-", "/");
|
||||
es.setStandardNumber(standardNumber);
|
||||
}
|
||||
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 void importExcelOldSystem(MultipartFile zipFile, String type) {
|
||||
public void importExcelOldSystem(MultipartFile zipFile, String type, HttpServletResponse response) {
|
||||
List<OldSystemImportDTO> errImportList = new ArrayList<>();
|
||||
|
||||
// 验证文件是否为压缩格式
|
||||
if (!Objects.requireNonNull(zipFile.getContentType()).contains("zip")) {
|
||||
throw new JeroBootException("文件格式不正确,请上传zip格式的压缩包。");
|
||||
@@ -197,7 +178,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
if (esDatalist.isEmpty()) {
|
||||
log.info("企标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysESImport(esDatalist);
|
||||
this.oldSysESImport(esDatalist, errImportList);
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
@@ -206,40 +187,108 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
if (gbDatalist.isEmpty()) {
|
||||
log.info("国标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysGBImport(gbDatalist);
|
||||
this.oldSysGBImport(gbDatalist, errImportList);
|
||||
}
|
||||
case "3":
|
||||
// 判断是否需要跳过
|
||||
if (esDatalist.isEmpty()) {
|
||||
log.info("企标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysESImport(esDatalist, errImportList);
|
||||
}
|
||||
// 导入国标
|
||||
// 判断是否需要跳过
|
||||
if (gbDatalist.isEmpty()) {
|
||||
log.info("国标数据为空,跳过导入");
|
||||
} else {
|
||||
this.oldSysGBImport(gbDatalist, errImportList);
|
||||
}
|
||||
}
|
||||
this.exportWithExcel(response, errImportList);
|
||||
}
|
||||
|
||||
public void exportWithExcel(HttpServletResponse response, List<OldSystemImportDTO> dtoList) {
|
||||
try {
|
||||
// 设置导出参数
|
||||
ExportParams exportParams = new ExportParams(null, "有问题的老法规"); // 可以为标题添加更多的配置
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, OldSystemImportDTO.class, dtoList);
|
||||
|
||||
// 设置响应头和内容类型
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=有问题的老法规.xls");
|
||||
|
||||
// 写出到响应流
|
||||
workbook.write(response.getOutputStream());
|
||||
workbook.close();
|
||||
} catch (Exception e) {
|
||||
log.error("导出excel异常", e);
|
||||
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.EXPORT_ERROR), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void oldSysGBImport(List<OldSystemImportDTO> gbDatalist) {
|
||||
private void oldSysGBImport(List<OldSystemImportDTO> gbDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
// 找到所有人 并且用 姓名加工号做key
|
||||
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));
|
||||
|
||||
// 现所有部门
|
||||
List<SysDepart> curDepartList = departService.list();
|
||||
Map<String, List<SysDepart>> curDeptMap = curDepartList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
|
||||
|
||||
// 部门关系列表
|
||||
List<OldSystemDepartRelation> list = oldDeptService.list();
|
||||
list = list.stream().filter(o -> StrUtil.isNotBlank(o.getOldOrgName())).collect(Collectors.toList());
|
||||
Map<String, List<OldSystemDepartRelation>> oldDeptMap = list.stream().collect(Collectors.groupingBy(OldSystemDepartRelation::getOldOrgName));
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 转换数据
|
||||
List<LawsDomesticStandard> gbList = new ArrayList<>();
|
||||
for (OldSystemImportDTO dto : gbDatalist) {
|
||||
LawsDomesticStandard gb = new LawsDomesticStandard();
|
||||
gb.setStandardNumber(dto.getBzh());
|
||||
try {
|
||||
LawsDomesticStandard gb = new LawsDomesticStandard();
|
||||
gb.setStandardNumber(dto.getBzh());
|
||||
|
||||
String[] parts = dto.getBzh().split("[-\\s]"); // 使用空格或破折号作为分隔符
|
||||
if (parts.length < 3) {
|
||||
parts = dto.getBzh().split("[—\\s]"); // 使用空格或破折号作为分隔符
|
||||
String[] parts = dto.getBzh().split("[-\\s]"); // 使用空格或破折号作为分隔符
|
||||
if (parts.length < 3) {
|
||||
parts = dto.getBzh().split("[—\\s]"); // 使用空格或破折号作为分隔符
|
||||
}
|
||||
// 标准类别
|
||||
gb.setStandardClass(parts[0]);
|
||||
// 标准号
|
||||
gb.setStandardNumberTemp(parts[1]);
|
||||
// 年代号
|
||||
gb.setYearNumber(parts[2]);
|
||||
|
||||
gb.setStandardName(dto.getBzmc());
|
||||
gb.setStandardEnglishName(dto.getBzywmc());
|
||||
gb.setReleaseDate(dto.getFbrq());
|
||||
gb.setImplementationDate(dto.getSsrq());
|
||||
String standardState = dto.getBzzt();
|
||||
gb.setStandardState(standardState.equals("现行有效") ? "6" : "7");
|
||||
// 代替被代替特殊逻辑
|
||||
gb.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
gb.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
|
||||
String zrbm = dto.getZrbm();
|
||||
if (oldDeptMap.get(zrbm) != null && oldDeptMap.get(zrbm).get(0) != null) {
|
||||
String curOrgName = oldDeptMap.get(zrbm).get(0).getCurOrgName();
|
||||
if (StrUtil.isNotBlank(curOrgName)) {
|
||||
List<SysDepart> departList = curDeptMap.get(curOrgName);
|
||||
if (departList.size() != 0) {
|
||||
gb.setResponsibleDepartment(departList.get(0).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
String zrr = dto.getZrr();
|
||||
String zrrid = dto.getZrrid();
|
||||
if (StrUtil.isNotBlank(zrr) && StrUtil.isNotBlank(zrrid)) {
|
||||
gb.setResponsibleDepartment(allUserMap.get(zrr + zrrid).getId());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导入转换国标数据时发生错误:{}", e.getMessage());
|
||||
log.error("错误数据:{}", dto.toString());
|
||||
errImportList.add(dto);
|
||||
}
|
||||
// 标准类别
|
||||
gb.setStandardClass(parts[0]);
|
||||
// 标准号
|
||||
gb.setStandardNumberTemp(parts[1]);
|
||||
// 年代号
|
||||
gb.setYearNumber(parts[2]);
|
||||
|
||||
gb.setStandardName(dto.getBzmc());
|
||||
gb.setStandardEnglishName(dto.getBzywmc());
|
||||
gb.setReleaseDate(dto.getFbrq());
|
||||
gb.setImplementationDate(dto.getSsrq());
|
||||
String standardState = dto.getBzzt();
|
||||
gb.setStandardState(standardState.equals("现行有效") ? "6" : "7");
|
||||
// 代替被代替特殊逻辑
|
||||
gb.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
gb.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
gbList.add(gb);
|
||||
}
|
||||
// 保存数据
|
||||
// 1. 首先获取所有现有的企标标准号
|
||||
@@ -285,30 +334,69 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
log.info("代码执行时间:" + executionTime + " 毫秒");
|
||||
}
|
||||
|
||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist) {
|
||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 转换数据
|
||||
List<LawsEnterpriseStandard> esList = new ArrayList<>();
|
||||
|
||||
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
|
||||
// 导入企标
|
||||
for (OldSystemImportDTO dto : esDatalist) {
|
||||
LawsEnterpriseStandard es = new LawsEnterpriseStandard();
|
||||
es.setStandardNumber(dto.getBzh());
|
||||
es.setStandardName(dto.getBzmc());
|
||||
es.setStandardEnglishName(dto.getBzywmc());
|
||||
es.setReleaseDate(dto.getFbrq());
|
||||
es.setImplementationDate(dto.getSsrq());
|
||||
String standardState = dto.getBzzt();
|
||||
es.setStandardState(standardState.equals("现行有效") ? "8" : "9");
|
||||
// 代替被代替特殊逻辑
|
||||
es.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
es.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
// 等级分类默认值
|
||||
es.setGradeClassification("1");
|
||||
esList.add(es);
|
||||
try {
|
||||
LawsEnterpriseStandard es = new LawsEnterpriseStandard();
|
||||
|
||||
es.setStandardNumber(dto.getBzh());
|
||||
es.setStandardName(dto.getBzmc());
|
||||
es.setStandardEnglishName(dto.getBzywmc());
|
||||
es.setReleaseDate(dto.getFbrq());
|
||||
es.setImplementationDate(dto.getSsrq());
|
||||
String standardState = dto.getBzzt();
|
||||
es.setStandardState(standardState.equals("现行有效") ? "8" : "9");
|
||||
es.setGradeClassification("1");
|
||||
// 代替被代替特殊逻辑
|
||||
es.setSubstituteStandardNumber(dto.getTdbzh());
|
||||
es.setReplacedByStandardNumber(dto.getBtdbzh());
|
||||
|
||||
String standardNumber = dto.getBzh();
|
||||
// 如果标准号中有错误符号 则需要修正一下
|
||||
// 正则表达式用于检测是否存在错误的“-”作为分隔符
|
||||
String regex = "([A-Za-z]{1,2})-([A-Za-z]{1,2}) (\\d{4,5}(\\.\\d+)?)-(\\d{4})";
|
||||
|
||||
// 使用Pattern和Matcher检测是否匹配
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(standardNumber);
|
||||
if (matcher.find()) {
|
||||
// 如果匹配,将第一个“-”替换为“/”
|
||||
standardNumber = standardNumber.replaceFirst("-", "/");
|
||||
es.setStandardNumber(standardNumber);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
// 翻译
|
||||
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));
|
||||
}
|
||||
esList.add(es);
|
||||
} catch (Exception e) {
|
||||
log.error("导入转换企标数据时发生错误:{}", e.getMessage());
|
||||
log.error("错误数据:{}", dto.toString());
|
||||
errImportList.add(dto);
|
||||
}
|
||||
}
|
||||
// 处理数据
|
||||
this.handleESData(esList);
|
||||
// 保存数据
|
||||
// 1. 首先获取所有现有的企标标准号
|
||||
List<LawsEnterpriseStandard> existingEntities = this.list();
|
||||
|
||||
Reference in New Issue
Block a user