Commit 6df27433 authored by wangqiang's avatar wangqiang

采购计划添加项目id

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