Commit a4ec1f62 authored by wangqiang's avatar wangqiang

IED计划导入、增加、删除、更新功能开发(已完成测测试);

IED计划导出功能开发(已完成测试)
parent dfe8fb4a
...@@ -18,124 +18,131 @@ public class ExtIEDPlanExcelVO { ...@@ -18,124 +18,131 @@ public class ExtIEDPlanExcelVO {
@ExcelProperty(value = {"IED计划","操作*"},index = 0) @ExcelProperty(value = {"IED计划","操作*"},index = 0)
@ColumnWidth(15) @ColumnWidth(20)
private String operation; private String operation;
/** /**
* 文件类型 * 文件类型
*/ */
@ExcelProperty(value = {"IED计划","文件类型*"},index = 1) @ExcelProperty(value = {"IED计划","文件类型*"},index = 1)
@ColumnWidth(15) @ColumnWidth(20)
private Integer fileType; private String fileType;
/** /**
* 文件分类 * 文件分类
*/ */
@ExcelProperty(value = {"IED计划","文件分类*"},index = 2) @ExcelProperty(value = {"IED计划","文件分类*"},index = 2)
@ColumnWidth(15) @ColumnWidth(20)
private Integer fileClassify; private String fileClassify;
/**
* 文件分类
*/
@ExcelProperty(value = {"IED计划","文件名称*"},index = 3)
@ColumnWidth(20)
private String fileName;
/** /**
* 文件编号 * 文件编号
*/ */
@ExcelProperty(value = {"IED计划","文件编号*"},index = 3) @ExcelProperty(value = {"IED计划","文件编号*"},index = 4)
@ColumnWidth(15) @ColumnWidth(20)
private String fileNumber; private String fileNumber;
/** /**
* 文件代号 * 文件代号
*/ */
@ExcelProperty(value = {"IED计划","文件代号*"},index = 4) @ExcelProperty(value = {"IED计划","文件代号*"},index = 5)
@ColumnWidth(15) @ColumnWidth(20)
private String fileCode; private String fileCode;
/** /**
* 管理员系统编码 * 管理员系统编码
*/ */
@ExcelProperty(value = {"IED计划","管理员系统编码*"},index = 5) @ExcelProperty(value = {"IED计划","管理员系统编码*"},index = 6)
@ColumnWidth(15) @ColumnWidth(20)
private String systemNumber; private String systemNumber;
/** /**
* 设备编号 * 设备编号
*/ */
@ExcelProperty(value = {"IED计划","设备编号*"},index = 6) @ExcelProperty(value = {"IED计划","设备编号*"},index = 7)
@ColumnWidth(15) @ColumnWidth(20)
private String deviceNumber; private String deviceNumber;
/** /**
* 阶段 * 阶段
*/ */
@ExcelProperty(value = {"IED计划","阶段*"},index = 7) @ExcelProperty(value = {"IED计划","阶段*"},index = 8)
@ColumnWidth(15) @ColumnWidth(20)
private String phase; private String phase;
/** /**
* 节点审核时间 * 节点审核时间
*/ */
@ExcelProperty(value = {"IED计划","节点审核时间*"},index = 8) @ExcelProperty(value = {"IED计划","节点审核时间*"},index = 9)
@ColumnWidth(15) @ColumnWidth(20)
private LocalDateTime auditTime; private LocalDateTime auditTime;
/** /**
* 文件提交时间 * 文件提交时间
*/ */
@ExcelProperty(value = {"IED计划","文件提交时间*"},index = 9) @ExcelProperty(value = {"IED计划","文件提交时间*"},index = 10)
@ColumnWidth(15) @ColumnWidth(20)
private LocalDateTime fileSubmitTime; private LocalDateTime fileSubmitTime;
/** /**
* 编写者 * 编写者
*/ */
@ExcelProperty(value = {"IED计划","编写*"},index = 10) @ExcelProperty(value = {"IED计划","编写*"},index = 11)
@ColumnWidth(15) @ColumnWidth(20)
private String editor; private String editor;
/** /**
* 校核者 * 校核者
*/ */
@ExcelProperty(value = {"IED计划","校核*"},index = 11) @ExcelProperty(value = {"IED计划","校核*"},index = 12)
@ColumnWidth(15) @ColumnWidth(20)
private String checker; private String checker;
/** /**
* 审核者 * 审核者
*/ */
@ExcelProperty(value = {"IED计划","审核*"},index = 12) @ExcelProperty(value = {"IED计划","审核*"},index = 13)
@ColumnWidth(15) @ColumnWidth(20)
private String auditor; private String auditor;
/** /**
* 审定者 * 审定者
*/ */
@ExcelProperty(value = {"IED计划","审定*"},index = 13) @ExcelProperty(value = {"IED计划","审定*"},index = 14)
@ColumnWidth(15) @ColumnWidth(20)
private String investigator; private String investigator;
/** /**
* 批准者 * 批准者
*/ */
@ExcelProperty(value = {"IED计划","批准*"},index = 14) @ExcelProperty(value = {"IED计划","批准*"},index = 15)
@ColumnWidth(15) @ColumnWidth(20)
private String ratifier; private String ratifier;
/** /**
* 备注 * 备注
*/ */
@ExcelProperty(value = {"IED计划","备注*"},index = 15) @ExcelProperty(value = {"IED计划","备注*"},index = 16)
@ColumnWidth(15) @ColumnWidth(20)
private String note; private String note;
/** /**
* 密级 * 密级
*/ */
@ExcelProperty(value = {"IED计划","密级*"},index = 16) @ExcelProperty(value = {"IED计划","密级*"},index = 17)
@ColumnWidth(15) @ColumnWidth(20)
private String secretCode; private String secretCode;
} }
......
...@@ -160,7 +160,7 @@ public class ExtIEDPlanVO extends IdOnlyVO implements IdVO ,DxContextVOHolder ,D ...@@ -160,7 +160,7 @@ public class ExtIEDPlanVO extends IdOnlyVO implements IdVO ,DxContextVOHolder ,D
/** /**
* 文件分类 * 文件分类
*/ */
private Integer fileClassify; private String fileClassify;
/** /**
* 文件代号 * 文件代号
...@@ -185,7 +185,7 @@ public class ExtIEDPlanVO extends IdOnlyVO implements IdVO ,DxContextVOHolder ,D ...@@ -185,7 +185,7 @@ public class ExtIEDPlanVO extends IdOnlyVO implements IdVO ,DxContextVOHolder ,D
/** /**
* 文件类型 * 文件类型
*/ */
private Integer fileType; private String fileType;
/** /**
* 审定者 * 审定者
......
...@@ -12,7 +12,9 @@ import io.swagger.annotations.Api; ...@@ -12,7 +12,9 @@ import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* @description: ExtIEDPlan-Controller * @description: ExtIEDPlan-Controller
...@@ -36,12 +38,23 @@ public class ExtIEDPlanController<V extends ExtIEDPlanVO, S extends ExtIEDPlanSe ...@@ -36,12 +38,23 @@ public class ExtIEDPlanController<V extends ExtIEDPlanVO, S extends ExtIEDPlanSe
* @return * @return
* @throws IOException * @throws IOException
*/ */
@ApiOperation("导入采购计划") @ApiOperation("导入IED计划")
@PostMapping(value = "/insertIEDPlan") @PostMapping(value = "/importIEDPlan")
public ApiResult insertPlan(@RequestParam("file") MultipartFile uploadFile) throws IOException { public ApiResult importPlan(@RequestParam("file") MultipartFile uploadFile) throws IOException {
return ApiResult.ok(extIEDPlanService.importIEDPlan(uploadFile.getInputStream()),"采购计划导入成功"); return ApiResult.ok(extIEDPlanService. importIEDPlan(uploadFile.getInputStream()),"IED计划导入成功");
} }
/**
* 导出计划
* @param response
* @param ids
* @throws IOException
*/
@ApiOperation(value = "导出IED计划", notes = "导出IED计划", httpMethod = "GET")
@GetMapping(value = "/exportIEDPlan")
public ApiResult exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids) throws IOException {
return ApiResult.ok(extIEDPlanService.exportIEDPlan(response, ids),"IED计划导出成功");
}
} }
...@@ -45,7 +45,7 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute ...@@ -45,7 +45,7 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute
* @throws IOException * @throws IOException
*/ */
@ApiOperation("导入采购计划") @ApiOperation("导入采购计划")
@PostMapping(value = "/insertPurchasePlan") @PostMapping(value = "/importPurchasePlan")
public ApiResult insertPlan(@RequestParam("file") MultipartFile uploadFile,@RequestParam("projectId") String projectId) throws IOException { public ApiResult insertPlan(@RequestParam("file") MultipartFile uploadFile,@RequestParam("projectId") String projectId) throws IOException {
return ApiResult.ok(extPuchasePlanAttributeService.importPurchasePlan(uploadFile.getInputStream(),projectId),"采购计划导入成功"); return ApiResult.ok(extPuchasePlanAttributeService.importPurchasePlan(uploadFile.getInputStream(),projectId),"采购计划导入成功");
} }
...@@ -56,7 +56,7 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute ...@@ -56,7 +56,7 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute
* @param ids * @param ids
* @throws IOException * @throws IOException
*/ */
@ApiOperation(value = "导出采购计划计划", notes = "导出计划", httpMethod = "GET") @ApiOperation(value = "导出采购计划", notes = "导出计划", httpMethod = "GET")
@GetMapping(value = "/exportPurchasePlan") @GetMapping(value = "/exportPurchasePlan")
public ApiResult exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids) throws IOException { public ApiResult exportPlan(HttpServletResponse response, @RequestParam("ids") List<Long> ids) throws IOException {
return ApiResult.ok(extPuchasePlanAttributeService.exportPurchasePlanFile(response, ids),"采购计划导出成功"); return ApiResult.ok(extPuchasePlanAttributeService.exportPurchasePlanFile(response, ids),"采购计划导出成功");
......
...@@ -12,6 +12,8 @@ import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO; ...@@ -12,6 +12,8 @@ import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import com.yonde.dcs.plan.core.service.ExtIEDPlanService; import com.yonde.dcs.plan.core.service.ExtIEDPlanService;
import com.yonde.dcs.plan.core.util.CommonUtils; import com.yonde.dcs.plan.core.util.CommonUtils;
import com.yonde.dex.basedata.data.search.SearchItem; import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryCondition;
import com.yonde.dex.basedata.entity.data.DxPageImpl; import com.yonde.dex.basedata.entity.data.DxPageImpl;
import com.yonde.dex.basedata.entity.data.OperatorType; import com.yonde.dex.basedata.entity.data.OperatorType;
import com.yonde.dex.basedata.exception.DxBusinessException; import com.yonde.dex.basedata.exception.DxBusinessException;
...@@ -43,6 +45,12 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -43,6 +45,12 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
*/ */
private List<ExtIEDPlanExcelVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); private List<ExtIEDPlanExcelVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
/**
* excel数据行数
*/
private Integer excelDataRow = 0;
/** /**
* 校验数据的错误信息 * 校验数据的错误信息
*/ */
...@@ -60,9 +68,16 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -60,9 +68,16 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
@Override @Override
public void invoke(ExtIEDPlanExcelVO extIEDPlanExcelVO, AnalysisContext analysisContext) { public void invoke(ExtIEDPlanExcelVO extIEDPlanExcelVO, AnalysisContext analysisContext) {
log.info("解析到一条数据:{}", extIEDPlanExcelVO); excelDataRow++;
//检查excel数据合法性 //判断是否是空数据行
checkDataForExcel(extIEDPlanExcelVO); if(!CommonUtils.checkAllPropertiesIsEmpty(extIEDPlanExcelVO)){
log.info("解析到一条数据:{}", extIEDPlanExcelVO);
//检查excel数据合法性
checkDataForExcel(extIEDPlanExcelVO);
}else {
log.info("解析到数据第{}行是空白数据请检查数据!",excelDataRow);
}
} }
...@@ -72,7 +87,7 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -72,7 +87,7 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
// 收尾工作,处理剩下的缓存数据。。。 // 收尾工作,处理剩下的缓存数据。。。
log.info("sheet={} 所有数据解析完成!", analysisContext.readSheetHolder().getSheetName()); log.info("sheet={} 所有数据解析完成!", analysisContext.readSheetHolder().getSheetName());
if (errorList.size() > 0) { if (errorList.size() > 0) {
throw new DxBusinessException("-1", "导入采购计划数据有误!!" + errorList.toString()); throw new DxBusinessException("-1", "IED计划数据有误!!" + errorList.toString());
} }
//处理全部检查通过的数据 //处理全部检查通过的数据
for (ExtIEDPlanExcelVO extIEDPlanExcelVO : cachedDataList) { for (ExtIEDPlanExcelVO extIEDPlanExcelVO : cachedDataList) {
...@@ -93,6 +108,11 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -93,6 +108,11 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
} }
} }
//数据处理完之后,进行初始化
errorList.clear();
cachedDataList.clear();
excelDataRow = 0;
} }
...@@ -117,26 +137,34 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -117,26 +137,34 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
StringBuffer errorString = new StringBuffer(); StringBuffer errorString = new StringBuffer();
//校验数据 //校验数据
if (!StringUtils.isEmpty(extIEDPlanExcelVO.getOperation()) && !StringUtils.isEmpty(extIEDPlanExcelVO.getFileNumber())) { if (!StringUtils.isEmpty(extIEDPlanExcelVO.getOperation()) && !StringUtils.isEmpty(extIEDPlanExcelVO.getFileNumber())) {
if (operationList.contains(extIEDPlanExcelVO.getOperation())) { if (!operationList.contains(extIEDPlanExcelVO.getOperation())) {
errorString.append("文件编号为:" + extIEDPlanExcelVO.getFileNumber() + "的操作符无法识别!!"); errorString.append("解析到数据第"+excelDataRow+"行文件编号为:" + extIEDPlanExcelVO.getFileNumber() + "的操作符无法识别!!");
errorList.add(errorString); errorList.add(errorString);
} }
//如果是新增,查看一下数据库中是不是已经存在
if (Constants.EXCEL_ADD.equals(extIEDPlanExcelVO.getOperation())) { if (Constants.EXCEL_ADD.equals(extIEDPlanExcelVO.getOperation())) {
//如果是新增,查看一下数据库中是不是已经存在
ExtIEDPlanVO extIEDPlanVO = getIEDPlanByFileNumber(extIEDPlanExcelVO.getFileNumber()); ExtIEDPlanVO extIEDPlanVO = getIEDPlanByFileNumber(extIEDPlanExcelVO.getFileNumber());
if (!ObjectUtils.isEmpty(extIEDPlanVO)) { if (!ObjectUtils.isEmpty(extIEDPlanVO)) {
errorString.append("新增IED计划的文件编号:" + extIEDPlanExcelVO.getFileNumber() + "已存在,不能重复添加!"); errorString.append("解析到数据第"+excelDataRow+"行,新增IED计划的文件编号:" + extIEDPlanExcelVO.getFileNumber() + "已存在,不能重复添加!");
errorList.add(errorString);
}
}else {
ExtIEDPlanVO extIEDPlanVO = getIEDPlanByFileNumberAndDeleted(extIEDPlanExcelVO.getFileNumber());
if (!ObjectUtils.isEmpty(extIEDPlanVO) && 1 == extIEDPlanVO.getDeleted()) {
errorString.append("解析到数据第"+excelDataRow+"行,更新IED计划的文件编号:" + extIEDPlanExcelVO.getFileNumber() + "已被删除,更新或删除失败!");
errorList.add(errorString); errorList.add(errorString);
} }
} }
} else { } else {
errorString.append("文件编号、操作符均不能为空!!"); errorString.append("解析到数据第"+excelDataRow+",文件编号、操作符均不能为空!!");
errorList.add(errorString); errorList.add(errorString);
} }
cachedDataList.add(extIEDPlanExcelVO); cachedDataList.add(extIEDPlanExcelVO);
} }
/** /**
* 转换数据,将EXCEL对象转换为PO对象 * 转换数据,将EXCEL对象转换为PO对象
*/ */
...@@ -145,6 +173,7 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -145,6 +173,7 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
extIEDPlanVO.setFileClassify(extIEDPlanExcelVO.getFileClassify()); extIEDPlanVO.setFileClassify(extIEDPlanExcelVO.getFileClassify());
extIEDPlanVO.setFileNumber(extIEDPlanExcelVO.getFileNumber()); extIEDPlanVO.setFileNumber(extIEDPlanExcelVO.getFileNumber());
extIEDPlanVO.setFileCode(extIEDPlanExcelVO.getFileCode()); extIEDPlanVO.setFileCode(extIEDPlanExcelVO.getFileCode());
extIEDPlanVO.setFileName(extIEDPlanExcelVO.getFileName());
extIEDPlanVO.setSystemNumber(extIEDPlanExcelVO.getSystemNumber()); extIEDPlanVO.setSystemNumber(extIEDPlanExcelVO.getSystemNumber());
extIEDPlanVO.setDeviceNumber(extIEDPlanExcelVO.getDeviceNumber()); extIEDPlanVO.setDeviceNumber(extIEDPlanExcelVO.getDeviceNumber());
extIEDPlanVO.setPhase(extIEDPlanExcelVO.getPhase()); extIEDPlanVO.setPhase(extIEDPlanExcelVO.getPhase());
...@@ -174,4 +203,29 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel ...@@ -174,4 +203,29 @@ public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIEDPlanExcel
return null; return null;
} }
/**
* 根据fileNumber查询已经删除的计划
* @param fileNumber
* @return
*/
private ExtIEDPlanVO getIEDPlanByFileNumberAndDeleted(String fileNumber) {
SearchQueryCondition condition = SearchQueryCondition.builder()
.searchItems(SearchItems.builder()
.item(new SearchItem("fileNumber", SearchItem.Operator.EQ, fileNumber, null))
.item(new SearchItem("deleted", SearchItem.Operator.EQ, 1, null))
.build())
.build();
//根据文件编号查询IED计划
DxPageImpl<ExtIEDPlanVO> IEDPlanPage = extIEDPlanService.findRecursion(condition);
if (!CollectionUtils.isEmpty(IEDPlanPage.getContent())) {
ExtIEDPlanVO extIEDPlanVOForDB = DxPageUtils.getFirst(IEDPlanPage);
return extIEDPlanVOForDB;
} else {
log.info("根据计划的文件编码:{},未查到相关计划", fileNumber);
}
return null;
}
} }
...@@ -41,6 +41,11 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -41,6 +41,11 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
private String projectId; private String projectId;
/**
* excel数据行数
*/
private Integer excelDataRow = 0;
/** /**
* 缓存的数据 * 缓存的数据
*/ */
...@@ -58,7 +63,12 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -58,7 +63,12 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
public void invoke(ExtPuchasePlanExcelVO extPuchasePlanExcelVO, AnalysisContext analysisContext) { public void invoke(ExtPuchasePlanExcelVO extPuchasePlanExcelVO, AnalysisContext analysisContext) {
log.info("解析到一条数据:{}", extPuchasePlanExcelVO); log.info("解析到一条数据:{}", extPuchasePlanExcelVO);
cachedDataList.add(extPuchasePlanExcelVO); if(!CommonUtils.checkAllPropertiesIsEmpty(extPuchasePlanExcelVO)){
cachedDataList.add(extPuchasePlanExcelVO);
}else {
log.info("解析到数据第{}行是空白数据请检查数据!",excelDataRow);
}
} }
......
...@@ -3,7 +3,10 @@ package com.yonde.dcs.plan.core.service; ...@@ -3,7 +3,10 @@ package com.yonde.dcs.plan.core.service;
import com.yonde.dcs.plan.common.vo.ExtIEDPlanVO; import com.yonde.dcs.plan.common.vo.ExtIEDPlanVO;
import com.yonde.dcs.plan.core.service.shadow.ExtIEDPlanServiceShadow; import com.yonde.dcs.plan.core.service.shadow.ExtIEDPlanServiceShadow;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List;
/** /**
* @description: ExtIEDPlan-service * @description: ExtIEDPlan-service
...@@ -14,4 +17,5 @@ import java.io.InputStream; ...@@ -14,4 +17,5 @@ import java.io.InputStream;
public interface ExtIEDPlanService<V extends ExtIEDPlanVO> extends ExtIEDPlanServiceShadow<V> { public interface ExtIEDPlanService<V extends ExtIEDPlanVO> extends ExtIEDPlanServiceShadow<V> {
String importIEDPlan(InputStream inputStream); String importIEDPlan(InputStream inputStream);
String exportIEDPlan(HttpServletResponse response, List<String> ids) throws IOException;
} }
...@@ -21,5 +21,5 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut ...@@ -21,5 +21,5 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut
public String importPurchasePlan(InputStream inputStream,String projectId); public String importPurchasePlan(InputStream inputStream,String projectId);
public String exportPurchasePlanFile(HttpServletResponse response, List<String> planCodeList) throws IOException; public String exportPurchasePlanFile(HttpServletResponse response, List<String> ids) throws IOException;
} }
package com.yonde.dcs.plan.core.service.impl; package com.yonde.dcs.plan.core.service.impl;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.vo.ExtIEDPlanExcelVO;
import com.yonde.dcs.plan.common.vo.ExtIEDPlanVO; import com.yonde.dcs.plan.common.vo.ExtIEDPlanVO;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO; import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO;
import com.yonde.dcs.plan.core.listener.IEDPlanExcelListenner; import com.yonde.dcs.plan.core.listener.IEDPlanExcelListenner;
import com.yonde.dcs.plan.core.listener.PurchasePlanExcelReadListenner; import com.yonde.dcs.plan.core.listener.PurchasePlanExcelReadListenner;
import com.yonde.dcs.plan.core.repository.ExtIEDPlanRepository; import com.yonde.dcs.plan.core.repository.ExtIEDPlanRepository;
import com.yonde.dcs.plan.core.service.ExtIEDPlanService; import com.yonde.dcs.plan.core.service.ExtIEDPlanService;
import com.yonde.dcs.plan.core.util.CommonUtils;
import com.yonde.dcs.plan.core.util.FileUtils;
import com.yonde.dcs.plan.core.util.ResourceHelper;
import com.yonde.dcs.plan.entity.po.ExtIEDPlan; import com.yonde.dcs.plan.entity.po.ExtIEDPlan;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryCondition;
import com.yonde.dex.basedata.entity.api.ApiResult; import com.yonde.dex.basedata.entity.api.ApiResult;
import com.yonde.dex.basedata.entity.api.CustomMultipartFile;
import com.yonde.dex.basedata.entity.data.DxPageImpl;
import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.systemfile.feign.SystemFileFeignService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletResponse;
/** /**
* @description: ExtIEDPlan-ServiceImpl * @description: ExtIEDPlan-ServiceImpl
* @author: dexadmin * @author: dexadmin
* @version: V * @version: V
* @date: 2024-9-11 15:49:41 * @date: 2024-9-11 15:49:41
**/ **/
@Slf4j @Slf4j
@Service(ExtIEDPlanServiceImpl.BEAN_NAME) @Service(ExtIEDPlanServiceImpl.BEAN_NAME)
public class ExtIEDPlanServiceImpl<V extends ExtIEDPlanVO> implements ExtIEDPlanService<V> { public class ExtIEDPlanServiceImpl<V extends ExtIEDPlanVO> implements ExtIEDPlanService<V> {
...@@ -35,15 +57,96 @@ public class ExtIEDPlanServiceImpl<V extends ExtIEDPlanVO> implements ExtIEDPlan ...@@ -35,15 +57,96 @@ public class ExtIEDPlanServiceImpl<V extends ExtIEDPlanVO> implements ExtIEDPlan
@Autowired @Autowired
ExtIEDPlanRepository<ExtIEDPlan> extIEDPlanRepository; ExtIEDPlanRepository<ExtIEDPlan> extIEDPlanRepository;
@Autowired
private SystemFileFeignService systemFileFeignService;
@Autowired
private FileManagerFeignService fileManagerFeignService;
@Override @Override
public String importIEDPlan(InputStream inputStream) { public String importIEDPlan(InputStream inputStream) {
EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class, EasyExcel.read(inputStream, ExtIEDPlanExcelVO.class,
new IEDPlanExcelListenner()) new IEDPlanExcelListenner())
.sheet() .sheet()
.doRead(); .doRead();
return ApiResult.SUCCESS; return ApiResult.SUCCESS;
} }
@Override
public String exportIEDPlan(HttpServletResponse response, List<String> ids) throws IOException {
InputStream inputStream = null;
CustomMultipartFile multipartFile = null;
Long fileId = null;
SearchQueryCondition condition = SearchQueryCondition.builder()
.searchItems(SearchItems.builder()
.item(new SearchItem("id", SearchItem.Operator.IN, ids, null))
.build())
.build();
//根据批量计划id获取计划集合
DxPageImpl<V> IEDPlanPage = this.findRecursion(condition);
if (CollectionUtils.isNotEmpty(IEDPlanPage.getContent())) {
List<V> content = IEDPlanPage.getContent();
//数据转换,将PO转换成EXCEL-VO;
List<ExtIEDPlanExcelVO> extIEDPlanExcelVOList = transformationObject(content);
try {
fileId = systemFileFeignService.getSystemFileId(Constants.IED_PLAN_TEMP_FILE_CODE_NAME);
multipartFile = fileManagerFeignService.feignDownloadIO(fileId);
} catch (IOException e) {
log.info("[接口单] >>> 文件服务下载为文件:{}--失败!", fileId);
throw new DxBusinessException("500", "文件服务下载文件失败:" + fileId);
}
try {
inputStream = new ByteArrayInputStream(multipartFile.getBytes());
} catch (IOException e) {
log.info("[接口单] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
}
String dir = ResourceHelper.CreateTemDir().getPath();
String filePath = dir + Constants.IED_PLAN_EXCEL_NAME;
//创建采购计划列表.xlsx 文件
FileUtils.inputToFile(inputStream, filePath);
//向表格中写入数据
EasyExcel.write(filePath, ExtIEDPlanExcelVO.class)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet("IED计划列表").doWrite(extIEDPlanExcelVOList);
//导出数据
FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", "采购计划.xlsx");
FileUtil.del(dir);
} else {
log.info("根据计划ids:" + ids.toString() + "未查到相关数据");
return "未查到相关IED计划数据";
}
return ApiResult.SUCCESS;
}
private List<ExtIEDPlanExcelVO> transformationObject(List<V> extIEDPlanList) {
List<ExtIEDPlanExcelVO> extIEDPlanExcelVOList = new ArrayList<>();
for (ExtIEDPlanVO extIEDPlanVO : extIEDPlanList) {
ExtIEDPlanExcelVO extIEDPlanExcelVO = new ExtIEDPlanExcelVO();
extIEDPlanExcelVO.setFileType(extIEDPlanVO.getFileType());
extIEDPlanExcelVO.setFileClassify(extIEDPlanVO.getFileClassify());
extIEDPlanExcelVO.setFileNumber(extIEDPlanVO.getFileNumber());
extIEDPlanExcelVO.setFileCode(extIEDPlanVO.getFileCode());
extIEDPlanExcelVO.setFileName(extIEDPlanVO.getFileName());
extIEDPlanExcelVO.setSystemNumber(extIEDPlanVO.getSystemNumber());
extIEDPlanExcelVO.setDeviceNumber(extIEDPlanVO.getDeviceNumber());
extIEDPlanExcelVO.setPhase(extIEDPlanVO.getPhase());
extIEDPlanExcelVO.setAuditTime(extIEDPlanVO.getAuditTime());
extIEDPlanExcelVO.setFileSubmitTime(extIEDPlanVO.getFileSubmitTime());
extIEDPlanExcelVO.setEditor(extIEDPlanVO.getEditor());
extIEDPlanExcelVO.setChecker(extIEDPlanVO.getChecker());
extIEDPlanExcelVO.setAuditor(extIEDPlanVO.getAuditor());
extIEDPlanExcelVO.setInvestigator(extIEDPlanVO.getInvestigator());
extIEDPlanExcelVO.setRatifier(extIEDPlanVO.getRatifier());
extIEDPlanExcelVO.setNote(extIEDPlanVO.getNote());
//获取密级code
String secretCode = CommonUtils.searchDictDataValueByDictCode(Constants.SECRET_CODE, extIEDPlanVO.getSecretCode());
extIEDPlanExcelVO.setSecretCode(secretCode);
extIEDPlanExcelVOList.add(extIEDPlanExcelVO);
}
return extIEDPlanExcelVOList;
}
} }
...@@ -72,7 +72,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -72,7 +72,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
} }
@Override @Override
public String exportPurchasePlanFile(HttpServletResponse response, List<String> Ids) throws IOException { public String exportPurchasePlanFile(HttpServletResponse response, List<String> ids) throws IOException {
InputStream inputStream = null; InputStream inputStream = null;
CustomMultipartFile multipartFile = null; CustomMultipartFile multipartFile = null;
...@@ -80,7 +80,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -80,7 +80,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
SearchQueryCondition condition = SearchQueryCondition.builder() SearchQueryCondition condition = SearchQueryCondition.builder()
.searchItems(SearchItems.builder() .searchItems(SearchItems.builder()
.item(new SearchItem("id", SearchItem.Operator.IN, Ids, null)) .item(new SearchItem("id", SearchItem.Operator.IN, ids, null))
.build()) .build())
.build(); .build();
//根据批量计划id获取计划集合 //根据批量计划id获取计划集合
...@@ -115,7 +115,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -115,7 +115,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
FileUtil.del(dir); FileUtil.del(dir);
} else { } else {
log.info("根据计划ids:" + Ids.toString() + "未查到相关数据"); log.info("根据计划ids:" + ids.toString() + "未查到相关数据");
} }
......
...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; ...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.List; import java.util.List;
...@@ -16,13 +17,15 @@ import java.util.List; ...@@ -16,13 +17,15 @@ import java.util.List;
public class CommonUtils { public class CommonUtils {
private static DictDataFeignService dictDataFeignService; private static DictDataFeignService dictDataFeignService;
public CommonUtils() { public CommonUtils() {
this.dictDataFeignService = ApplicationContextUtil.getBean(DictDataFeignService.class); this.dictDataFeignService = ApplicationContextUtil.getBean(DictDataFeignService.class);
} }
/** /**
*根据字典code获取字典code和字典项的值获取key(中文转英文,key是英文,value是中文) * 根据字典code获取字典code和字典项的值获取key(中文转英文,key是英文,value是中文)
*
* @param dictCode * @param dictCode
* @param dictValue * @param dictValue
* @return * @return
...@@ -49,7 +52,8 @@ public class CommonUtils { ...@@ -49,7 +52,8 @@ public class CommonUtils {
} }
/** /**
*根据字典code获取字典code和字典项的值获取key(英文转中文,key是英文,value是中文) * 根据字典code获取字典code和字典项的值获取key(英文转中文,key是英文,value是中文)
*
* @param dictCode * @param dictCode
* @return * @return
*/ */
...@@ -74,4 +78,24 @@ public class CommonUtils { ...@@ -74,4 +78,24 @@ public class CommonUtils {
return ""; return "";
} }
} /**
* 检查对象中的属性是否是空值
* @param obj
* @return
*/
public static boolean checkAllPropertiesIsEmpty(Object obj) {
Class<?> aClass = obj.getClass();
for(Field field:aClass.getDeclaredFields()){
field.setAccessible(true);
try{
if(field.get(obj) != null){
return false;
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return true;
}
}
\ No newline at end of file
...@@ -125,7 +125,7 @@ public class ExtIEDPlan extends IdOnlyEntity implements DxContextHolder ,DxObjFi ...@@ -125,7 +125,7 @@ public class ExtIEDPlan extends IdOnlyEntity implements DxContextHolder ,DxObjFi
/** /**
* 文件分类 * 文件分类
*/ */
private Integer fileClassify; private String fileClassify;
/** /**
* 文件代号 * 文件代号
*/ */
...@@ -146,7 +146,7 @@ public class ExtIEDPlan extends IdOnlyEntity implements DxContextHolder ,DxObjFi ...@@ -146,7 +146,7 @@ public class ExtIEDPlan extends IdOnlyEntity implements DxContextHolder ,DxObjFi
/** /**
* 文件类型 * 文件类型
*/ */
private Integer fileType; private String fileType;
/** /**
* 审定者 * 审定者
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment