Commit 813cef9f authored by 侯彦文's avatar 侯彦文

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/service/impl/ExtPuchasePlanAttributeServiceImpl.java
parents 505a08da 0d23dee0
......@@ -68,6 +68,24 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute
public ApiResult autoImportPurchasePlan( @RequestParam("id")long 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
extPuchasePlanAttributeService.saveRecursion(extPuchasePlanAttributeVO);
} else if (Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())) { //更新
//根据计划编号获取采购计划
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode());
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
purPlanForDB.setOperator(OperatorType.MODIFY);
extPuchasePlanAttributeService.saveRecursion(transformObject(purPlanForDB,extPuchasePlanExcelVO));
} else if (Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation())) { //删除;
//根据计划编号获取采购计划
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode());
ExtPuchasePlanAttributeVO purPlanForDB = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
purPlanForDB.setOperator(OperatorType.REMOVE);
extPuchasePlanAttributeService.remove(purPlanForDB.getId());
} else {
......@@ -175,24 +175,31 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
StringBuffer errString = new StringBuffer();
//校验excel必填字段是否有效
verifyExcelRequiredFields(extPuchasePlanExcelVO,errString);
//校验新增,更新,删除的逻辑
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());
ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = getPurchasePlanByPlanCode(extPuchasePlanExcelVO.getPlanCode(),false);
if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation())){
if(!ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
errString.append("新增计划编号:" + extPuchasePlanExcelVO.getPlanCode() + "已存在,不能重复导入!!");
errString.append("解析到数据第"+excelDataRow+"行,新增计划编号:" + extPuchasePlanExcelVO.getPlanCode() + "已存在,不能重复导入,新增失败!!");
errorList.add(errString);
}
}else if(Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation()) && StringUtils.isEmpty(extPuchasePlanExcelVO.getPlanCode())){
errString.append("更新计划编号:项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的计划编号不能为空");
}else if(Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())){
if(ObjectUtils.isEmpty(extPuchasePlanAttributeVO)){
errString.append("解析到数据第"+excelDataRow+"行,计划编号是:"+extPuchasePlanExcelVO.getPlanCode()+"在数据库不存在,更新失败!!");
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);
}
}else{
log.info("无法识别该操作符:"+extPuchasePlanExcelVO.getOperation());
errString.append("解析到数据第"+excelDataRow+",行无法识别该操作符:"+extPuchasePlanExcelVO.getOperation());
errorList.add(errString);
}
}else {
errString.append("项目代号为" + extPuchasePlanExcelVO.getProjectCode() + "的操作符不能为空");
errString.append("解析到数据第"+excelDataRow+"行,的操作符或计划编码不能为空");
errorList.add(errString);
}
......@@ -257,15 +264,18 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
/**
* 根据计划编号查询计划
* @param planCode
* @param deleteFlag true已删除 false未删除
* @return
*/
public ExtPuchasePlanAttributeVO getPurchasePlanByPlanCode(String planCode){
public ExtPuchasePlanAttributeVO getPurchasePlanByPlanCode(String planCode,boolean deleteFlag){
SearchItems purchasePlanSearch = new SearchItems();
SearchItem planCodeFilter = new SearchItem("planCode", SearchItem.Operator.EQ, planCode, (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(projectIdFilter);
purchasePlanSearch.addItem(deleteFilter);
SearchQueryCondition searchQuery = SearchQueryCondition.builder().searchItems(purchasePlanSearch).build();
//根据计划编号获取数据库中采购计划数据
......
......@@ -24,4 +24,6 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut
public String exportPurchasePlanFile(HttpServletResponse response, List<String> ids) throws IOException;
public String autoImportPurchasePlan(long id);
public String verifyExcelDataIsValid(Long fileId,String projectId,String projectSecret);
}
......@@ -3,18 +3,15 @@ package com.yonde.dcs.plan.core.service.impl;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.inet.dcs.document.feign.expand.ExtDxDocumentServiceFeign;
import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
import com.yonde.dcs.document.feign.expand.ExtDxDocumentServiceFeign;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
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.repository.ExtPuchasePlanAttributeRepository;
import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
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.ExtPuchasePlanAttribute;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryCondition;
......@@ -25,20 +22,28 @@ import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.dfs.feign.RepoFileFeignService;
import com.yonde.dex.systemfile.feign.SystemFileFeignService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
import com.yonde.dcs.plan.core.repository.ExtPuchasePlanAttributeRepository;
import com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* @description: ExtPuchasePlanAttribute-ServiceImpl
* @author: dexadmin
......@@ -65,7 +70,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
@Override
public String importPurchasePlan(InputStream inputStream, String projectId) {
public String importPurchasePlan(InputStream inputStream,String projectId) {
EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class,
new PurchasePlanExcelReadListenner(projectId))
.sheet()
......@@ -105,7 +110,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
}
String dir = ResourceHelper.CreateTemDir().getPath();
String filePath = dir + Constants.PURCHASE_PLAN_EXCEL_NAME;
String filePath = dir+ Constants.PURCHASE_PLAN_EXCEL_NAME;
//创建采购计划列表.xlsx 文件
FileUtils.inputToFile(inputStream, filePath);
//向表格中写入数据
......@@ -126,7 +131,6 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
/**
* 计划文件签审通过之后,调用该方法,自动导入计划
*
* @param id 文档id
* @return
*/
......@@ -137,7 +141,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
CustomMultipartFile multipartFile = null;
Long fileId = null;
DxDocumentVO dxDocumentVO = docCenterFeignService.getDocumentWithFiles(id);
if (!ObjectUtils.isEmpty(dxDocumentVO)) {
if(!ObjectUtils.isEmpty(dxDocumentVO)){
try {
//todo 取固定类型附件
fileId = dxDocumentVO.getObjFileLinks().get(0).getTarget().getId();
......@@ -148,21 +152,23 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
}
try {
inputStream = new ByteArrayInputStream(multipartFile.getBytes());
importPurchasePlan(inputStream, dxDocumentVO.getDxContextId().toString());
importPurchasePlan(inputStream,dxDocumentVO.getDxContextId().toString());
} catch (IOException e) {
log.info("[自动导入采购计划] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
}
} else {
}else {
log.info("根据计划文档id:" + id + "未查到相关数据");
}
return ApiResult.SUCCESS;
}
/**
* 数据转换,将PO转换成EXCEL-VO;
*
* @param content
* @return
*/
......@@ -185,6 +191,32 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
}
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;
import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dao.service.util.ApplicationContextUtil;
import com.yonde.dex.dict.feign.DictDataFeignService;
import com.yonde.dex.dict.service.vo.DictDataVO;
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.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
......@@ -11,6 +14,7 @@ import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -120,4 +124,31 @@ public class CommonUtils {
}
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 @@
<artifactId>inet-doc-expand-feign</artifactId>
<version>4.1-20240919-RELEASE</version>
</dependency>
<dependency>
<groupId>com.yonde.dex</groupId>
<artifactId>dex-basic-service-expand-feign</artifactId>
<version>4.1-20240919-RELEASE</version>
</dependency>
<dependency>
<groupId>com.yonde.dex</groupId>
<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