Commit 0d23dee0 authored by wangqiang's avatar wangqiang

采购计划导入数据校验功能开发;导入计划数据的密级不能大于项目密级bug修复

parent ea954424
...@@ -68,6 +68,24 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute ...@@ -68,6 +68,24 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute
public ApiResult autoImportPurchasePlan( @RequestParam("id")long id){ public ApiResult autoImportPurchasePlan( @RequestParam("id")long id){
return ApiResult.ok(extPuchasePlanAttributeService.autoImportPurchasePlan(id),"采购计划自动导入成功"); return ApiResult.ok(extPuchasePlanAttributeService.autoImportPurchasePlan(id),"采购计划自动导入成功");
} }
/**
* 导入采购计划
*
* @param fileId
* @param projectId
* @param projectSecret
* @return
* @throws IOException
*/
@ApiOperation("校验上传的excel中的采购计划列表是否合法")
@PostMapping(value = "/verifyExcelDataIsValid")
public ApiResult verifyExcelDataIsValid(@RequestParam(value = "fileId",required = true)Long fileId,
@RequestParam(value ="projectId",required = true) String projectId,
@RequestParam(value ="projectSecret",required = true) String projectSecret)
throws IOException {
return ApiResult.ok(extPuchasePlanAttributeService.verifyExcelDataIsValid(fileId,projectId,projectSecret),"校验成功!");
}
} }
...@@ -109,12 +109,12 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -109,12 +109,12 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
extPuchasePlanAttributeService.saveRecursion(extPuchasePlanAttributeVO); extPuchasePlanAttributeService.saveRecursion(extPuchasePlanAttributeVO);
} else if (Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())) { //更新 } else if (Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())) { //更新
//根据计划编号获取采购计划 //根据计划编号获取采购计划
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode()); ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
purPlanForDB.setOperator(OperatorType.MODIFY); purPlanForDB.setOperator(OperatorType.MODIFY);
extPuchasePlanAttributeService.saveRecursion(transformObject(purPlanForDB,extPuchasePlanExcelVO)); extPuchasePlanAttributeService.saveRecursion(transformObject(purPlanForDB,extPuchasePlanExcelVO));
} else if (Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation())) { //删除; } else if (Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation())) { //删除;
//根据计划编号获取采购计划 //根据计划编号获取采购计划
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode()); ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
purPlanForDB.setOperator(OperatorType.REMOVE); purPlanForDB.setOperator(OperatorType.REMOVE);
extPuchasePlanAttributeService.remove(purPlanForDB.getId()); extPuchasePlanAttributeService.remove(purPlanForDB.getId());
} else { } else {
...@@ -175,24 +175,31 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -175,24 +175,31 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
StringBuffer errString = new StringBuffer(); StringBuffer errString = new StringBuffer();
//校验excel必填字段是否有效 //校验excel必填字段是否有效
verifyExcelRequiredFields(extPuchasePlanExcelVO,errString); verifyExcelRequiredFields(extPuchasePlanExcelVO,errString);
//校验新增,更新,删除的逻辑
if(!StringUtils.isEmpty(extPuchasePlanExcelVO.getOperation()) && !StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){ if(!StringUtils.isEmpty(extPuchasePlanExcelVO.getOperation()) && !StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){
if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isNotEmpty(extPuchasePlanExcelVO.getPlanCode())){ ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode()); if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation())){
if(!ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){ if(!ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
errString.append("新增计划编号:" + extPuchasePlanExcelVO.getPlanCode() + "已存在,不能重复导入!!"); errString.append("解析到数据第"+excelDataRow+"行,新增计划编号:" + extPuchasePlanExcelVO.getPlanCode() + "已存在,不能重复导入,新增失败!!");
errorList.add(errString); errorList.add(errString);
} }
}else if(Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){ }else if(Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())){
errString.append("更新计划编号:项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的计划编号不能为空"); if(ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
errString.append("解析到数据第"+excelDataRow+"行,计划编号是:"+extPuchasePlanExcelVO.getPlanCode()+"在数据库不存在,更新失败!!");
errorList.add(errString); errorList.add(errString);
}else if(Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){ }
errString.append("删除计划编号:项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的计划编号不能为空");
}else if(Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation())){
if(ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
errString.append("解析到数据第"+excelDataRow+"行,计划编号是:"+extPuchasePlanExcelVO.getPlanCode()+"在数据库不存在,删除失败!!");
errorList.add(errString); errorList.add(errString);
}
}else{ }else{
log.info("无法识别该操作符:"+extPuchasePlanExcelVO.getOperation()); errString.append("解析到数据第"+excelDataRow+",行无法识别该操作符:"+extPuchasePlanExcelVO.getOperation());
errorList.add(errString);
} }
}else { }else {
errString.append("项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的操作符不能为空"); errString.append("解析到数据第"+excelDataRow+"行,的操作符或计划编码不能为空");
errorList.add(errString); errorList.add(errString);
} }
...@@ -257,15 +264,18 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc ...@@ -257,15 +264,18 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
/** /**
* 根据计划编号查询计划 * 根据计划编号查询计划
* @param planCode * @param planCode
* @param deleteFlag true已删除 false未删除
* @return * @return
*/ */
public ExtPuchasePlanAttributeVO getPurchasePlanByPlanCode(String planCode){ public ExtPuchasePlanAttributeVO getPurchasePlanByPlanCode(String planCode,boolean deleteFlag){
SearchItems purchasePlanSearch = new SearchItems(); SearchItems purchasePlanSearch = new SearchItems();
SearchItem planCodeFilter = new SearchItem("planCode", SearchItem.Operator.EQ, planCode, (Object)null); SearchItem planCodeFilter = new SearchItem("planCode", SearchItem.Operator.EQ, planCode, (Object)null);
SearchItem projectIdFilter = new SearchItem("dxContextId", SearchItem.Operator.EQ, projectId, (Object)null); SearchItem projectIdFilter = new SearchItem("dxContextId", SearchItem.Operator.EQ, projectId, (Object)null);
SearchItem deleteFilter = new SearchItem("deleted", SearchItem.Operator.EQ, deleteFlag, (Object)null);
purchasePlanSearch.addItem(planCodeFilter); purchasePlanSearch.addItem(planCodeFilter);
purchasePlanSearch.addItem(projectIdFilter); purchasePlanSearch.addItem(projectIdFilter);
purchasePlanSearch.addItem(deleteFilter);
SearchQueryCondition searchQuery = SearchQueryCondition.builder().searchItems(purchasePlanSearch).build(); SearchQueryCondition searchQuery = SearchQueryCondition.builder().searchItems(purchasePlanSearch).build();
//根据计划编号获取数据库中采购计划数据 //根据计划编号获取数据库中采购计划数据
......
...@@ -24,4 +24,6 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut ...@@ -24,4 +24,6 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut
public String exportPurchasePlanFile(HttpServletResponse response, List<String> ids) throws IOException; public String exportPurchasePlanFile(HttpServletResponse response, List<String> ids) throws IOException;
public String autoImportPurchasePlan(long id); public String autoImportPurchasePlan(long id);
public String verifyExcelDataIsValid(Long fileId,String projectId,String projectSecret);
} }
...@@ -7,6 +7,7 @@ import com.yonde.dcs.document.common.entity.vo.DxDocumentVO; ...@@ -7,6 +7,7 @@ import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
import com.yonde.dcs.document.feign.expand.ExtDxDocumentServiceFeign; import com.yonde.dcs.document.feign.expand.ExtDxDocumentServiceFeign;
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.PurchasePlanExcelDataVerifyListenner;
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.CommonUtils;
import com.yonde.dcs.plan.core.util.FileUtils; import com.yonde.dcs.plan.core.util.FileUtils;
...@@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.*;
import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService; import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
import com.yonde.dcs.plan.core.repository.ExtPuchasePlanAttributeRepository; import com.yonde.dcs.plan.core.repository.ExtPuchasePlanAttributeRepository;
import com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute; import com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -162,6 +164,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -162,6 +164,9 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
return ApiResult.SUCCESS; return ApiResult.SUCCESS;
} }
/** /**
* 数据转换,将PO转换成EXCEL-VO; * 数据转换,将PO转换成EXCEL-VO;
* @param content * @param content
...@@ -186,6 +191,32 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -186,6 +191,32 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
} }
return extPuchasePlanExcelVOList; return extPuchasePlanExcelVOList;
} }
/**
* 在采购计划设计文件走流程之前校验一下主内容的excel表格中的数据是否有效
* @param fileId
* @param projectId
* @return
*/
@Override
public String verifyExcelDataIsValid(Long fileId, String projectId,String projectSecret) {
MultipartFile multipartFile = null;
InputStream inputStream = null;
try {
multipartFile = fileManagerFeignService.feignDownloadIO(fileId);
inputStream = new ByteArrayInputStream(multipartFile.getBytes());
} catch (IOException e) {
throw new DxBusinessException("-1","文件id:"+fileId+"在系统中未找到!");
}
EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class,
new PurchasePlanExcelDataVerifyListenner(projectId,projectSecret))
.sheet()
.doRead();
return ApiResult.SUCCESS;
}
} }
package com.yonde.dcs.plan.core.util; package com.yonde.dcs.plan.core.util;
import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dao.service.util.ApplicationContextUtil; import com.yonde.dex.dao.service.util.ApplicationContextUtil;
import com.yonde.dex.dict.feign.DictDataFeignService; import com.yonde.dex.dict.feign.DictDataFeignService;
import com.yonde.dex.dict.service.vo.DictDataVO; import com.yonde.dex.dict.service.vo.DictDataVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import mssql.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -11,6 +14,7 @@ import org.springframework.util.StringUtils; ...@@ -11,6 +14,7 @@ import org.springframework.util.StringUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -120,4 +124,31 @@ public class CommonUtils { ...@@ -120,4 +124,31 @@ public class CommonUtils {
} }
return dictMap.get(key); return dictMap.get(key);
} }
/**
* 校验密级等级
* @return
*/
public static Boolean verifySecretLevel(String sourceSecret,String targetSecret){
Map<Object,Object> secretMap= new LinkedHashMap<>();
secretMap.put("公开",1);
secretMap.put("非密",2);
secretMap.put("内部",3);
secretMap.put("秘密",4);
secretMap.put("机密",5);
Integer sourceLevel = (Integer) secretMap.get(sourceSecret);
Integer targetLevel = (Integer) secretMap.get(targetSecret);
if(ObjectUtils.isEmpty(sourceLevel)){
throw new DxBusinessException("-1","原密级不存在,请检查数据!");
}else if (ObjectUtils.isEmpty(targetLevel)){
throw new DxBusinessException("-1","目标密级不存在,请检查数据!");
}else {
if(targetLevel > sourceLevel){
return false;
}
return true;
}
}
} }
\ No newline at end of file
...@@ -53,6 +53,11 @@ ...@@ -53,6 +53,11 @@
<artifactId>inet-doc-expand-feign</artifactId> <artifactId>inet-doc-expand-feign</artifactId>
<version>4.1-20240919-RELEASE</version> <version>4.1-20240919-RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>com.yonde.dex</groupId>
<artifactId>dex-basic-service-expand-feign</artifactId>
<version>4.1-20240919-RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>com.yonde.dex</groupId> <groupId>com.yonde.dex</groupId>
<artifactId>dex-basic-service-feign</artifactId> <artifactId>dex-basic-service-feign</artifactId>
......
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