拆分导入

This commit is contained in:
gaojiabao
2023-04-03 21:11:11 +08:00
parent c52c720884
commit d3c152f5b4
10 changed files with 870 additions and 263 deletions
@@ -6,6 +6,7 @@ import cn.hutool.core.util.ZipUtil;
import com.adc.da.att.controller.AttFileEOController;
import com.adc.da.att.entity.AttFileEO;
import com.adc.da.att.service.IAttFileEOService;
import com.adc.da.att.util.CommonExportUtil;
import com.adc.da.base.web.BaseController;
import com.adc.da.common.ConvertHtml2Excel;
import com.adc.da.common.FileUnZip;
@@ -546,8 +547,7 @@ public class SarFileSplitItemsEOController extends BaseController<SarFileSplitIt
// 导入参数设置,默认即可
ImportParams params = new ImportParams();
try {
String fields[] = {"条款号", "条款名称","内容简介","责任部门",
"FO","责任工程师","SVPPS","适用车辆类型","要求类型","企标覆盖关系"};
String fields[] = {"条款号", "条款名称","条款内容","条款附件"};
params.setImportFields(fields);
List<SarFileSplitItemsImportDto> result = new ArrayList<>();
// 解析excel,并返回校验信息
@@ -583,6 +583,12 @@ public class SarFileSplitItemsEOController extends BaseController<SarFileSplitIt
//是则不读取
continue;
}
//判断此行数据是否全部为空
if(sarStandImportDto.getItemsNum().contains("模板说明")){
i++;
//是则不读取
continue;
}
i = 0;
datasUpdate.add(sarStandImportDto);
}
@@ -658,5 +664,26 @@ public class SarFileSplitItemsEOController extends BaseController<SarFileSplitIt
return Result.error("0", "该条数据标准号在标准库中不存在");
}
//导入模板下载
@ApiOperation(value = "拆分导入模板下载")
@GetMapping(value = "/exportTemplate")
public void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception {
String[] headers = { "条款号","条款名称","条款内容","条款附件"};
try{
String fileName = "拆分导入模板下载/导入模板";
StringBuilder descBuilder = new StringBuilder()
.append("模板说明:")
.append("\n")
.append("1:条款号,条款名称,条款内容不能为空")
.append("\n")
.append("2:将附件存放在zip格式的文件夹中,名称与后缀输入于附件中即可")
.append("\n")
.append("3:图片格式格式为jpg")
.append("\n");
//生成模板
CommonExportUtil.exportTemplate(fileName,headers,descBuilder.toString(), response,request);
}catch (Exception e){
throw new AdcDaBaseException("下载文件失败,请重试");
}
}
}
@@ -1,12 +1,14 @@
package com.adc.da.slrs.standardSplit.dto;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
/**
* @Description:
* @Author: yangxuenan
* date: 2020/5/9 14:40
*/
@Data
public class SarFileSplitItemsImportDto {
@Excel(name = "条款号", orderNum = "1")
private String itemsNum;
@@ -14,32 +16,35 @@ public class SarFileSplitItemsImportDto {
@Excel(name = "条款名称", orderNum = "1")
private String itemsName;
@Excel(name = "内容简介", orderNum = "1")
@Excel(name = "条款附件", orderNum = "1")
private String itermsConditions;
@Excel(name = "责任部门", orderNum = "1")
private String responsibleUnit;
// @Excel(name = "责任部门", orderNum = "1")
// private String responsibleUnit;
@Excel(name = "条款内容", orderNum = "1")
private String mag;
// @Excel(name = "责任部门", orderNum = "1")
private String newcarPutTime;
// private String newcarPutTime;
@Excel(name = "FO", orderNum = "1")
private String fo;
// @Excel(name = "FO", orderNum = "1")
// private String fo;
@Excel(name = "责任工程师", orderNum = "1")
private String dutyEngineer;
// @Excel(name = "责任工程师", orderNum = "1")
// private String dutyEngineer;
//
// @Excel(name = "SVPPS", orderNum = "1")
// private String svpps;
@Excel(name = "SVPPS", orderNum = "1")
private String svpps;
@Excel(name = "适用车辆类型", orderNum = "1")
private String applyArctic;
@Excel(name = "要求类型", orderNum = "1")
private String claimType;
@Excel(name = "企标覆盖关系", orderNum = "1")
private String busStandCover;
// @Excel(name = "适用车辆类型", orderNum = "1")
// private String applyArctic;
//
// @Excel(name = "要求类型", orderNum = "1")
// private String claimType;
//
// @Excel(name = "企标覆盖关系", orderNum = "1")
// private String busStandCover;
@@ -56,93 +61,4 @@ public class SarFileSplitItemsImportDto {
// private String relevanceFile;
//
// private String relevanceFileName;
public String getItemsNum() {
return itemsNum;
}
public void setItemsNum(String itemsNum) {
this.itemsNum = itemsNum;
}
public String getItemsName() {
return itemsName;
}
public void setItemsName(String itemsName) {
this.itemsName = itemsName;
}
public String getItermsConditions() {
return itermsConditions;
}
public void setItermsConditions(String itermsConditions) {
this.itermsConditions = itermsConditions;
}
public String getResponsibleUnit() {
return responsibleUnit;
}
public void setResponsibleUnit(String responsibleUnit) {
this.responsibleUnit = responsibleUnit;
}
public String getNewcarPutTime() {
return newcarPutTime;
}
public void setNewcarPutTime(String newcarPutTime) {
this.newcarPutTime = newcarPutTime;
}
public String getFo() {
return fo;
}
public void setFo(String fo) {
this.fo = fo;
}
public String getDutyEngineer() {
return dutyEngineer;
}
public void setDutyEngineer(String dutyEngineer) {
this.dutyEngineer = dutyEngineer;
}
public String getSvpps() {
return svpps;
}
public void setSvpps(String svpps) {
this.svpps = svpps;
}
public String getApplyArctic() {
return applyArctic;
}
public void setApplyArctic(String applyArctic) {
this.applyArctic = applyArctic;
}
public String getClaimType() {
return claimType;
}
public void setClaimType(String claimType) {
this.claimType = claimType;
}
public String getBusStandCover() {
return busStandCover;
}
public void setBusStandCover(String busStandCover) {
this.busStandCover = busStandCover;
}
}
@@ -15,6 +15,9 @@ import com.adc.da.common.ReadWordTable;
import com.adc.da.slrs.standardSplit.entity.*;
import com.adc.da.slrs.standardSplit.service.SarFileSplitInfoEOService;
import com.adc.da.sys.common.SelectionResult;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.sys.entity.DicTypeEO;
import com.adc.da.sys.service.IDicTypeEOService;
import com.adc.da.sys.util.LoginUserUtil;
import com.adc.da.sys.util.UUIDUtils;
import org.apache.commons.collections4.CollectionUtils;
@@ -91,6 +94,10 @@ public class SarFileSplitInfoEOServiceImpl implements SarFileSplitInfoEOService
private SarFileSplitItemsParamsEODao sarFileSplitItemsParamsEODao;
@Autowired
private SarFileSplitInfoEODao dao;
@Autowired
private DicTypeEODao dicTypeEODao;
@Autowired
private IDicTypeEOService dicTypeEOService;
@Override
public List<SarFileSplitInfoEO> queryByPage(BasePage page) throws Exception{
@@ -735,6 +742,13 @@ public class SarFileSplitInfoEOServiceImpl implements SarFileSplitInfoEOService
// }
}
}
for (SarFileSplitInfoEO data : rows){
List<DicTypeEO> dicTypeEO = dicTypeEODao.selectPidByCode(data.getFileType());
if(dicTypeEO!=null){
data.setFileTypeShow(dicTypeEO.get(0).getDicTypeName());
}
}
return rows;
}
@@ -71,6 +71,9 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
@Autowired
private SarFileSplitInfoEOService sarFileSplitInfoEOService;
@Value("${elasticsearch.img}")
private String elasticsearchImg;//图片拆分自调地址
@Override
public Map<String, Object> getByPage(SarFileSplitItemsEOPage page) {
@@ -468,7 +471,6 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
}else {
infoId = UUIDUtils.randomUUID20();
}
//验证导入数据是否符合规则
Map map = validateImportDatas(list,filepath);
boolean isOk = (boolean) map.get("result");
if (!isOk) {
@@ -530,12 +532,13 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
List<File> nowfilelist = FileUnZip.readFileByFilename(filepath, valArr[i]);
if (nowfilelist != null && !nowfilelist.isEmpty()) {
AttFileVo attFileVo = attFileEOService.saveFileInfo(nowfilelist.get(0));
if(attFileVo!=null){
if (attFileVo != null) {
isText = false;
String path = "file" + attFileVo.getFilePath()+attFileVo.getFileName();
String imgCon = "<img class=\'wordImg\' src=\'" + path + "\'>";
//String path = "E:/data/slrs/file" + attFileVo.getFilePath()+attFileVo.getOldFileName();
String pathSrc = elasticsearchImg + "/api/att/attFile/getFileInfo?fileId=" + attFileVo.getId();
String imgCon = "<img class=\'wordImg\' src=\'" + pathSrc + "\'>";
valEO.setType("IMG");
valEO.setItemContent(imgCon);
valEO.setItemContent(imgCon + "<p>" + importDto.getMag() + "<p>");
}
}
if (isText) {
@@ -564,12 +567,13 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
List<File> nowfilelist = FileUnZip.readFileByFilename(filepath, valArr[i]);
if (nowfilelist != null && !nowfilelist.isEmpty()) {
AttFileVo attFileVo = attFileEOService.saveFileInfo(nowfilelist.get(0));
if(attFileVo!=null){
if (attFileVo != null) {
isText = false;
String path = "file" + attFileVo.getFilePath()+attFileVo.getFileName();
String imgCon = "<img class=\'wordImg\' src=\'" + path + "\'>";
//String path = "E:/data/slrs/file" + attFileVo.getFilePath()+attFileVo.getOldFileName();
String pathSrc = elasticsearchImg + "/api/att/attFile/getFileInfo?fileId=" + attFileVo.getId();
String imgCon = "<img class=\'wordImg\' src=\'" + pathSrc + "\'>";
valEO.setType("IMG");
valEO.setItemContent(imgCon);
valEO.setItemContent(imgCon + "<p>" + importDto.getMag() + "<p>");
}
}
if (isText) {
@@ -600,12 +604,13 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
List<File> nowfilelist = FileUnZip.readFileByFilename(filepath, valArr[i]);
if (nowfilelist != null && !nowfilelist.isEmpty()) {
AttFileVo attFileVo = attFileEOService.saveFileInfo(nowfilelist.get(0));
if(attFileVo!=null){
if (attFileVo != null) {
isText = false;
String path = "file" + attFileVo.getFilePath()+attFileVo.getFileName();
String imgCon = "<img class=\'wordImg\' src=\'" + path + "\'>";
//String path = "E:/data/slrs/file" + attFileVo.getFilePath()+attFileVo.getOldFileName();
String pathSrc = elasticsearchImg + "/api/att/attFile/getFileInfo?fileId=" + attFileVo.getId();
String imgCon = "<img class=\'wordImg\' src=\'" + pathSrc + "\'>";
valEO.setType("IMG");
valEO.setItemContent(imgCon);
valEO.setItemContent(imgCon + "<p>" + importDto.getMag() + "<p>");
}
}
if (isText) {
@@ -629,6 +634,7 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
sarFileSplitInfoEO.setValidFlag(0);
sarFileSplitInfoEO.setResult("1");
sarFileSplitInfoEO.setModifyUser(LoginUserUtil.getUserId());
sarFileSplitInfoEO.setStandId(sarFileSplitInfoEO.getStandId());
sarFileSplitInfoEOService.insertSelective(sarFileSplitInfoEO);
}
@@ -640,6 +646,14 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
menuPidMap.put("总目录",menuid );
}
for (SarFileSplitItemsEO itemsEO : addItemsEOList) {
List<SarFileSplitItemsValEO> itemValEOList = itemsEO.getItemValEOList();
if(itemValEOList!=null){
String tupian = "";
for (SarFileSplitItemsValEO data : itemValEOList){
tupian = tupian+data.getItemContent();
}
itemsEO.setItermsConditions(tupian);
}
String menuIdT = createItemsInfo(itemsEO,infoId,countSuccess,menuPidMap);
menuPidMap.put(itemsEO.getItemsNum(),menuIdT);
countSuccess++;
@@ -724,6 +738,11 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
int num = 0; //记录是第几条数据
//循环验证数据
for (SarFileSplitItemsImportDto dto : datas) {
if(dto.getItemsNum().contains("模板说明")){
continue;
}
i++;
int countError = 0; //记录失败数据数量
DicTypeEO dic = new DicTypeEO();
@@ -755,148 +774,151 @@ public class SarFileSplitItemsEOServiceImpl implements SarFileSplitItemsEOServic
countError++;
}
}
String saveApplyCode = "";
if (StringUtils.isNotEmpty(dto.getApplyArctic())) {
dto.setApplyArctic(dto.getApplyArctic().replace("", ","));
String applys[] = dto.getApplyArctic().split(",");
if(applys.length>20){
errorMsg += "适用车型选项不能超过20个;";
countError++;
} else if (dto.getApplyArctic().length() > 500) {
errorMsg += "适用车型不能超过500个字符;";
countError++;
} else {
Set set = new HashSet();
for (int a = 0; a < applys.length; a++) {
dic.setDicTypeName(applys[a]);
dic.setDicTypeCode("ENERGYTYPES");
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
if (getDic.size() == 1) {
saveApplyCode += getDic.get(0).getDicTypeCode() + ",";
} else if (getDic.size() > 0) {
errorMsg += "适用车型" + applys[a] + "不明确;";
countError++;
break;
} else {
errorMsg += "适用车型" + applys[a] + "不存在;";
countError++;
break;
}
set.add(applys[a]);
if (a==applys.length-1 && applys.length != set.size()){
errorMsg += "适用车型存在重复数据;";
countError++;
}
}
if (!saveApplyCode.equals("")){
dto.setApplyArctic(saveApplyCode.substring(0,saveApplyCode.length()-1));
}
}
}
if(!claimStypelist.contains(dto.getClaimType())) {
if (StringUtils.isNotEmpty(dto.getClaimType())) {
dic.setDicTypeName(dto.getClaimType());
dic.setDicTypeCode("REQUESTTYPE");
if (dto.getClaimType().length() > 500) {
errorMsg += "要求类型不能超过500个字符;";
countError++;
} else {
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
Set set = new HashSet();
if (getDic != null) {
if (getDic.size() == 1) {
dto.setClaimType(getDic.get(0).getDicTypeCode());
claimStypelist.add(getDic.get(0).getDicTypeCode());
} else if (getDic.size() > 0) {
errorMsg += "要求类型不明确;";
countError++;
} else {
errorMsg += "要求类型不存在;";
countError++;
}
} else {
errorMsg += "要求类型不存在;";
countError++;
}
}
}
}
if(StringUtils.isNotEmpty(dto.getItermsConditions())){
if(dto.getItermsConditions().length() > 50000){
errorMsg += "内容简介不能超过50000个字符;";
// String saveApplyCode = "";
// if (StringUtils.isNotEmpty(dto.getApplyArctic())) {
// dto.setApplyArctic(dto.getApplyArctic().replace("", ","));
// String applys[] = dto.getApplyArctic().split(",");
// if(applys.length>20){
// errorMsg += "适用车型选项不能超过20个;";
// countError++;
// } else if (dto.getApplyArctic().length() > 500) {
// errorMsg += "适用车型不能超过500个字符;";
// countError++;
// } else {
// Set set = new HashSet();
// for (int a = 0; a < applys.length; a++) {
// dic.setDicTypeName(applys[a]);
// dic.setDicTypeCode("ENERGYTYPES");
// getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
// if (getDic.size() == 1) {
// saveApplyCode += getDic.get(0).getDicTypeCode() + ",";
// } else if (getDic.size() > 0) {
// errorMsg += "适用车型" + applys[a] + "不明确;";
// countError++;
// break;
// } else {
// errorMsg += "适用车型" + applys[a] + "不存在;";
// countError++;
// break;
// }
// set.add(applys[a]);
// if (a==applys.length-1 && applys.length != set.size()){
// errorMsg += "适用车型存在重复数据;";
// countError++;
// }
// }
// if (!saveApplyCode.equals("")){
// dto.setApplyArctic(saveApplyCode.substring(0,saveApplyCode.length()-1));
// }
// }
// }
// if(!claimStypelist.contains(dto.getClaimType())) {
// if (StringUtils.isNotEmpty(dto.getClaimType())) {
// dic.setDicTypeName(dto.getClaimType());
// dic.setDicTypeCode("REQUESTTYPE");
// if (dto.getClaimType().length() > 500) {
// errorMsg += "要求类型不能超过500个字符;";
// countError++;
// } else {
// getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
// Set set = new HashSet();
// if (getDic != null) {
// if (getDic.size() == 1) {
// dto.setClaimType(getDic.get(0).getDicTypeCode());
// claimStypelist.add(getDic.get(0).getDicTypeCode());
// } else if (getDic.size() > 0) {
// errorMsg += "要求类型不明确;";
// countError++;
// } else {
// errorMsg += "要求类型不存在;";
// countError++;
// }
// } else {
// errorMsg += "要求类型不存在;";
// countError++;
// }
// }
// }
// }
if (StringUtils.isEmpty(dto.getMag())) {
errorMsg += "条款内容不能为空;";
countError++;
} else {
if(dto.getMag().length() > 50000){
errorMsg += "条款内容不能超过50000个字符;";
countError++;
}
}
if(!foList.contains(dto.getFo())) {
if (StringUtils.isNotEmpty(dto.getFo())) {
if (dto.getFo().length() > 200) {
errorMsg += "FO不能超过200个字符;";
countError++;
} else {
String uname = roleEODao.getIdsByNames(dto.getFo().split(","));
if (StringUtils.isNotBlank(uname)) {
dto.setFo(uname);
foList.addAll(Arrays.asList(uname.split(",")));
} else {
errorMsg += "FO不存在;";
countError++;
}
}
}
}
if(!dutyEngineerList.contains(dto.getDutyEngineer())) {
if (StringUtils.isNotEmpty(dto.getDutyEngineer())) {
if (dto.getDutyEngineer().length() > 100) {
errorMsg += "责任工程师不能超过100个字符;";
countError++;
} else {
String emList = roleEODao.getIdsByNames(dto.getDutyEngineer().split(","));
if (StringUtils.isNotBlank(emList)) {
dto.setDutyEngineer(emList);
dutyEngineerList.addAll(Arrays.asList(dto.getDutyEngineer().split(",")));
} else {
errorMsg += "系统中没有用户:" + dto.getDutyEngineer();
countError++;
}
}
}
}
if(StringUtils.isNotEmpty(dto.getSvpps())){
if(dto.getSvpps().length() > 200){
errorMsg += "SVPPS不能超过200个字符;";
countError++;
}else {
String svppsShow = sysInfoEOService.getSvppsIdByName(dto.getSvpps());
dto.setSvpps(svppsShow);
}
}
if(StringUtils.isNotEmpty(dto.getBusStandCover())){
if(dto.getBusStandCover().length() > 200){
errorMsg += "企标覆盖关系不能超过200个字符;";
countError++;
}else {
List<DicTypeEO> getDicType = dicTypeEODao.getDicTypeByDicCode("BZFGGXOUIUJ");
for (DicTypeEO dicTypeEO:getDicType) {
if (dicTypeEO.getDicTypeName().equals(dto.getBusStandCover())){
dto.setBusStandCover(dicTypeEO.getDicTypeCode());
}
}
}
}
if(StringUtils.isNotBlank(dto.getResponsibleUnit())){
if(dto.getResponsibleUnit().length() > 100){
errorMsg += "责任部门不能超过100个字符;";
countError++;
}else {
String id = sysInfoEOService.getOrgIdByName(dto.getResponsibleUnit(),"DEPART");
if(StringUtils.isNotBlank(id)){
dto.setResponsibleUnit(id);
} else {
errorMsg += "系统中没有部门"+dto.getResponsibleUnit();
countError++;
}
}
}
// if(!foList.contains(dto.getFo())) {
// if (StringUtils.isNotEmpty(dto.getFo())) {
// if (dto.getFo().length() > 200) {
// errorMsg += "FO不能超过200个字符;";
// countError++;
// } else {
// String uname = roleEODao.getIdsByNames(dto.getFo().split(","));
// if (StringUtils.isNotBlank(uname)) {
// dto.setFo(uname);
// foList.addAll(Arrays.asList(uname.split(",")));
// } else {
// errorMsg += "FO不存在;";
// countError++;
// }
// }
// }
// }
// if(!dutyEngineerList.contains(dto.getDutyEngineer())) {
// if (StringUtils.isNotEmpty(dto.getDutyEngineer())) {
// if (dto.getDutyEngineer().length() > 100) {
// errorMsg += "责任工程师不能超过100个字符;";
// countError++;
// } else {
// String emList = roleEODao.getIdsByNames(dto.getDutyEngineer().split(","));
// if (StringUtils.isNotBlank(emList)) {
// dto.setDutyEngineer(emList);
// dutyEngineerList.addAll(Arrays.asList(dto.getDutyEngineer().split(",")));
// } else {
// errorMsg += "系统中没有用户:" + dto.getDutyEngineer();
// countError++;
// }
// }
// }
// }
// if(StringUtils.isNotEmpty(dto.getSvpps())){
// if(dto.getSvpps().length() > 200){
// errorMsg += "SVPPS不能超过200个字符;";
// countError++;
// }else {
// String svppsShow = sysInfoEOService.getSvppsIdByName(dto.getSvpps());
// dto.setSvpps(svppsShow);
// }
// }
// if(StringUtils.isNotEmpty(dto.getBusStandCover())){
// if(dto.getBusStandCover().length() > 200){
// errorMsg += "企标覆盖关系不能超过200个字符;";
// countError++;
// }else {
// List<DicTypeEO> getDicType = dicTypeEODao.getDicTypeByDicCode("BZFGGXOUIUJ");
// for (DicTypeEO dicTypeEO:getDicType) {
// if (dicTypeEO.getDicTypeName().equals(dto.getBusStandCover())){
// dto.setBusStandCover(dicTypeEO.getDicTypeCode());
// }
// }
// }
// }
// if(StringUtils.isNotBlank(dto.getResponsibleUnit())){
// if(dto.getResponsibleUnit().length() > 100){
// errorMsg += "责任部门不能超过100个字符;";
// countError++;
// }else {
// String id = sysInfoEOService.getOrgIdByName(dto.getResponsibleUnit(),"DEPART");
// if(StringUtils.isNotBlank(id)){
// dto.setResponsibleUnit(id);
// } else {
// errorMsg += "系统中没有部门"+dto.getResponsibleUnit();
// countError++;
// }
// }
// }
if (countError > 0) {
stringMessage.add(errorMsg);
}