Commit 6df27433 authored by wangqiang's avatar wangqiang

采购计划添加项目id

parent f23ce0cf
package com.yonde.dcs.plan.common.vo; package com.yonde.dcs.plan.common.vo;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.ContentRowHeight;
...@@ -76,20 +77,21 @@ public class ExtPuchasePlanExcelVO { ...@@ -76,20 +77,21 @@ public class ExtPuchasePlanExcelVO {
/** /**
* 项目代号 * 项目代号
*/ */
@ExcelProperty(value = {"采购计划","项目代号*"},index = 7) @ExcelIgnore
@ExcelProperty(value = {"采购计划","项目代号*"})
@ColumnWidth(20) @ColumnWidth(20)
private String projectCode; private String projectCode;
/** /**
* 密级 * 密级
*/ */
@ExcelProperty(value = {"采购计划","密级*"},index = 8) @ExcelProperty(value = {"采购计划","密级*"},index = 7)
@ColumnWidth(20) @ColumnWidth(20)
private String secretCode; private String secretCode;
/** /**
* 计划编码 * 计划编码
*/ */
@ExcelProperty(value = {"采购计划","计划编码*"},index = 9) @ExcelProperty(value = {"采购计划","计划编码*"},index = 8)
@ColumnWidth(20) @ColumnWidth(20)
private String planCode; private String planCode;
...@@ -97,7 +99,7 @@ public class ExtPuchasePlanExcelVO { ...@@ -97,7 +99,7 @@ public class ExtPuchasePlanExcelVO {
/** /**
* 备注 * 备注
*/ */
@ExcelProperty(value = {"采购计划","备注*"},index = 10) @ExcelProperty(value = {"采购计划","备注*"},index = 9)
@ColumnWidth(20) @ColumnWidth(20)
private String note; private String note;
......
...@@ -27,7 +27,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -27,7 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
* @version: V * @version: V
* @date: 2024-8-29 17:14:49 * @date: 2024-8-29 17:14:49
**/ **/
@Api(tags = "ExtPuchasePlanAttribute管理服务") @Api(tags = "ExtPuchasePlanAttribute采购计划属性管理服务")
@RequestMapping("/ExtPuchasePlanAttribute") @RequestMapping("/ExtPuchasePlanAttribute")
@ResponseBody() @ResponseBody()
@BasePermission("inet-plan:ExtPuchasePlanAttribute") @BasePermission("inet-plan:ExtPuchasePlanAttribute")
...@@ -46,8 +46,8 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute ...@@ -46,8 +46,8 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute
*/ */
@ApiOperation("导入采购计划") @ApiOperation("导入采购计划")
@PostMapping(value = "/insertPurchasePlan") @PostMapping(value = "/insertPurchasePlan")
public ApiResult insertPlan(@RequestParam("file") MultipartFile uploadFile) throws IOException { public ApiResult insertPlan(@RequestParam("file") MultipartFile uploadFile,@RequestParam("projectId") String projectId) throws IOException {
return ApiResult.ok(extPuchasePlanAttributeService.importPurchasePlan(uploadFile.getInputStream()),"采购计划导入成功"); return ApiResult.ok(extPuchasePlanAttributeService.importPurchasePlan(uploadFile.getInputStream(),projectId),"采购计划导入成功");
} }
/** /**
......
...@@ -32,7 +32,6 @@ import java.util.List; ...@@ -32,7 +32,6 @@ import java.util.List;
@Slf4j @Slf4j
public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuchasePlanExcelVO> implements ServletContextListener { public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuchasePlanExcelVO> implements ServletContextListener {
@Autowired
private ExtPuchasePlanAttributeService extPuchasePlanAttributeService; private ExtPuchasePlanAttributeService extPuchasePlanAttributeService;
/** /**
...@@ -40,13 +39,19 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -40,13 +39,19 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
*/ */
private static final int BATCH_COUNT = 100; private static final int BATCH_COUNT = 100;
private String projectId;
/** /**
* 缓存的数据 * 缓存的数据
*/ */
private List<ExtPuchasePlanExcelVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); private List<ExtPuchasePlanExcelVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
public PurchasePlanExcelReadListenner() { public PurchasePlanExcelReadListenner() {}
public PurchasePlanExcelReadListenner(String projectId) {
this.extPuchasePlanAttributeService = ApplicationContextUtil.getBean(ExtPuchasePlanAttributeService.class); this.extPuchasePlanAttributeService = ApplicationContextUtil.getBean(ExtPuchasePlanAttributeService.class);
this.projectId = projectId;
} }
@Override @Override
...@@ -89,6 +94,8 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -89,6 +94,8 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
log.info("sheet={} ,操作符={}无效!", analysisContext.readSheetHolder().getSheetName(), extPuchasePlanExcelVO.getOperation()); log.info("sheet={} ,操作符={}无效!", analysisContext.readSheetHolder().getSheetName(), extPuchasePlanExcelVO.getOperation());
} }
} }
//清理list ,方便内存回收
cachedDataList.clear();
} }
...@@ -121,6 +128,7 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -121,6 +128,7 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
extPuchasePlanAttributeVO.setSecretCode(secretCode); extPuchasePlanAttributeVO.setSecretCode(secretCode);
extPuchasePlanAttributeVO.setPlanCode(extPuchasePlanExcelVO.getPlanCode()); extPuchasePlanAttributeVO.setPlanCode(extPuchasePlanExcelVO.getPlanCode());
extPuchasePlanAttributeVO.setNote(extPuchasePlanExcelVO.getNote()); extPuchasePlanAttributeVO.setNote(extPuchasePlanExcelVO.getNote());
extPuchasePlanAttributeVO.setDxContextId(Long.parseLong(projectId));
//todo wq:excel中的项目代号对应项目属性中什么? //todo wq:excel中的项目代号对应项目属性中什么?
return extPuchasePlanAttributeVO; return extPuchasePlanAttributeVO;
} }
...@@ -135,6 +143,7 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -135,6 +143,7 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
if (cachedDataList.size() > 0) { if (cachedDataList.size() > 0) {
for (ExtPuchasePlanExcelVO extPuchasePlanExcelVO : cachedDataList) { for (ExtPuchasePlanExcelVO extPuchasePlanExcelVO : cachedDataList) {
StringBuffer errString = new StringBuffer(); StringBuffer errString = new StringBuffer();
if(!StringUtils.isEmpty(extPuchasePlanExcelVO.getOperation())){
if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isNotEmpty(extPuchasePlanExcelVO.getPlanCode())){ if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isNotEmpty(extPuchasePlanExcelVO.getPlanCode())){
ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode()); ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode());
if(!ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){ if(!ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
...@@ -147,7 +156,14 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -147,7 +156,14 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
}else if(Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){ }else if(Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){
errString.append("删除计划编码:项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的计划编码不能为空"); errString.append("删除计划编码:项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的计划编码不能为空");
errorList.add(errString); errorList.add(errString);
}else{
log.info("无法识别该操作符:"+extPuchasePlanExcelVO.getOperation());
} }
}else {
errString.append("项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的操作符不能为空");
errorList.add(errString);
}
} }
} }
......
...@@ -19,7 +19,7 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut ...@@ -19,7 +19,7 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut
public String importPurchasePlan(InputStream inputStream); public String importPurchasePlan(InputStream inputStream,String projectId);
public String exportPurchasePlanFile(HttpServletResponse response, List<String> planCodeList) throws IOException; public String exportPurchasePlanFile(HttpServletResponse response, List<String> planCodeList) throws IOException;
} }
...@@ -6,6 +6,7 @@ import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy ...@@ -6,6 +6,7 @@ import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
import com.yonde.dcs.plan.common.constants.Constants; import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO; import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO;
import com.yonde.dcs.plan.core.listener.PurchasePlanExcelReadListenner; import com.yonde.dcs.plan.core.listener.PurchasePlanExcelReadListenner;
import com.yonde.dcs.plan.core.util.CommonUtils;
import com.yonde.dcs.plan.core.util.FileUtils; import com.yonde.dcs.plan.core.util.FileUtils;
import com.yonde.dcs.plan.core.util.ResourceHelper; import com.yonde.dcs.plan.core.util.ResourceHelper;
import com.yonde.dex.basedata.data.search.SearchItem; import com.yonde.dex.basedata.data.search.SearchItem;
...@@ -62,9 +63,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -62,9 +63,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
@Override @Override
public String importPurchasePlan(InputStream inputStream) { public String importPurchasePlan(InputStream inputStream,String projectId) {
EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class, EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class,
new PurchasePlanExcelReadListenner()) new PurchasePlanExcelReadListenner(projectId))
.sheet() .sheet()
.doRead(); .doRead();
return ApiResult.SUCCESS; return ApiResult.SUCCESS;
...@@ -121,6 +122,11 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -121,6 +122,11 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
return ApiResult.SUCCESS; return ApiResult.SUCCESS;
} }
/**
* 数据转换,将PO转换成EXCEL-VO;
* @param content
* @return
*/
public List<ExtPuchasePlanExcelVO> transformationObject(List<V> content) { public List<ExtPuchasePlanExcelVO> transformationObject(List<V> content) {
List<ExtPuchasePlanExcelVO> extPuchasePlanExcelVOList = new ArrayList<>(); List<ExtPuchasePlanExcelVO> extPuchasePlanExcelVOList = new ArrayList<>();
for (V extPuchasePlanAttribute : content) { for (V extPuchasePlanAttribute : content) {
...@@ -131,7 +137,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -131,7 +137,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
extPuchasePlanExcelVO.setContractActualDeliveryTime(extPuchasePlanAttribute.getContractActualDeliveryTime()); extPuchasePlanExcelVO.setContractActualDeliveryTime(extPuchasePlanAttribute.getContractActualDeliveryTime());
extPuchasePlanExcelVO.setPurDesignFileManager(extPuchasePlanAttribute.getPurDesignFileManager()); extPuchasePlanExcelVO.setPurDesignFileManager(extPuchasePlanAttribute.getPurDesignFileManager());
extPuchasePlanExcelVO.setPurchaseBudget(extPuchasePlanAttribute.getPurchaseBudget()); extPuchasePlanExcelVO.setPurchaseBudget(extPuchasePlanAttribute.getPurchaseBudget());
extPuchasePlanExcelVO.setSecretCode(extPuchasePlanAttribute.getSecretCode()); //将密级转换为中文
String secretCode = CommonUtils.searchDictDataValueByDictCode(Constants.SECRET_CODE, extPuchasePlanAttribute.getSecretCode());
extPuchasePlanExcelVO.setSecretCode(secretCode);
extPuchasePlanExcelVO.setPlanCode(extPuchasePlanAttribute.getPlanCode()); extPuchasePlanExcelVO.setPlanCode(extPuchasePlanAttribute.getPlanCode());
extPuchasePlanExcelVO.setNote(extPuchasePlanAttribute.getNote()); extPuchasePlanExcelVO.setNote(extPuchasePlanAttribute.getNote());
extPuchasePlanExcelVOList.add(extPuchasePlanExcelVO); extPuchasePlanExcelVOList.add(extPuchasePlanExcelVO);
......
...@@ -22,7 +22,7 @@ public class CommonUtils { ...@@ -22,7 +22,7 @@ public class CommonUtils {
/** /**
*根据字典code获取字典code和字典项的值获取key *根据字典code获取字典code和字典项的值获取key(中文转英文,key是英文,value是中文)
* @param dictCode * @param dictCode
* @param dictValue * @param dictValue
* @return * @return
...@@ -48,4 +48,30 @@ public class CommonUtils { ...@@ -48,4 +48,30 @@ public class CommonUtils {
return ""; return "";
} }
/**
*根据字典code获取字典code和字典项的值获取key(英文转中文,key是英文,value是中文)
* @param dictCode
* @return
*/
public static String searchDictDataValueByDictCode(String dictCode, String dictKey) {
if (!StringUtils.isEmpty(dictKey)) {
//字典type 项目代号 ProjectCode
List<DictDataVO> dictDatasByDictCode = dictDataFeignService.getDictDatas(dictCode);
if (CollectionUtils.isEmpty(dictDatasByDictCode)) {
log.error("所查字典为空!字典code为:" + dictCode);
return "";
} else {
for (DictDataVO dictDataVO : dictDatasByDictCode) {
if (dictKey.equals(dictDataVO.getDictKey())) {
return dictDataVO.getDictValue();
}
}
log.error("所查字典数据项为空!字典code为:" + dictCode);
return "";
}
}
log.error("所查字典Key为空!字典code为:" + dictCode);
return "";
}
} }
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