Commit 13c8d106 authored by wangqiang's avatar wangqiang

采购计划导出功能开发(已测试ok)

parent f43aabd6
...@@ -401,4 +401,10 @@ public class Constants { ...@@ -401,4 +401,10 @@ public class Constants {
public static final String EXCEL_DELETE = "删除"; public static final String EXCEL_DELETE = "删除";
public static final String EXCEL_UPDATE = "更新"; public static final String EXCEL_UPDATE = "更新";
/**
* 采购计划相关属性
*/
public static final String PURCHASE_PLAN_EXCEL_NAME = "\\采购计划列表.xlsx";
public static final String PURCHASE_PLAN_TEMP_FILE_CODE_NAME ="采购计划001模板";
} }
...@@ -47,7 +47,7 @@ public class ExtPuchasePlanAttributeController<V extends ExtPuchasePlanAttribute ...@@ -47,7 +47,7 @@ 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) throws IOException {
return ApiResult.ok(extPuchasePlanAttributeService.ExportPurchasePlan(uploadFile.getInputStream()),"采购计划导入成功"); return ApiResult.ok(extPuchasePlanAttributeService.importPurchasePlan(uploadFile.getInputStream()),"采购计划导入成功");
} }
/** /**
......
...@@ -19,7 +19,7 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut ...@@ -19,7 +19,7 @@ public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttribut
public String ExportPurchasePlan(InputStream inputStream); public String importPurchasePlan(InputStream inputStream);
public String exportPurchasePlanFile(HttpServletResponse response, List<String> planCodeList) throws IOException; public String exportPurchasePlanFile(HttpServletResponse response, List<String> planCodeList) throws IOException;
} }
...@@ -3,9 +3,11 @@ package com.yonde.dcs.plan.core.service.impl; ...@@ -3,9 +3,11 @@ package com.yonde.dcs.plan.core.service.impl;
import cn.hutool.core.io.FileUtil; 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.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.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.FileUtils; import com.yonde.dcs.plan.core.util.FileUtils;
import com.yonde.dcs.plan.core.util.ResourceHelper;
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.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryCondition; import com.yonde.dex.basedata.data.search.SearchQueryCondition;
...@@ -15,6 +17,7 @@ import com.yonde.dex.basedata.entity.data.DxPageImpl; ...@@ -15,6 +17,7 @@ import com.yonde.dex.basedata.entity.data.DxPageImpl;
import com.yonde.dex.basedata.exception.DxBusinessException; import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dfs.feign.FileManagerFeignService; import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.dfs.feign.RepoFileFeignService; import com.yonde.dex.dfs.feign.RepoFileFeignService;
import com.yonde.dex.systemfile.feign.SystemFileFeignService;
import org.apache.commons.collections.CollectionUtils; 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;
...@@ -54,10 +57,12 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -54,10 +57,12 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
private RepoFileFeignService repoFileFeignService; private RepoFileFeignService repoFileFeignService;
@Autowired @Autowired
private FileManagerFeignService fileManagerFeignService; private FileManagerFeignService fileManagerFeignService;
@Autowired
private SystemFileFeignService systemFileFeignService;
@Override @Override
public String ExportPurchasePlan(InputStream inputStream) { public String importPurchasePlan(InputStream inputStream) {
EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class, EasyExcel.read(inputStream, ExtPuchasePlanExcelVO.class,
new PurchasePlanExcelReadListenner()) new PurchasePlanExcelReadListenner())
.sheet() .sheet()
...@@ -70,6 +75,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -70,6 +75,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
InputStream inputStream = null; InputStream inputStream = null;
CustomMultipartFile multipartFile = null; CustomMultipartFile multipartFile = null;
Long fileId = null;
SearchQueryCondition condition = SearchQueryCondition.builder() SearchQueryCondition condition = SearchQueryCondition.builder()
.searchItems(SearchItems.builder() .searchItems(SearchItems.builder()
...@@ -83,19 +89,21 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -83,19 +89,21 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
//数据转换,将PO转换成EXCEL-VO; //数据转换,将PO转换成EXCEL-VO;
List<ExtPuchasePlanExcelVO> extPuchasePlanExcelVOList = transformationObject(content); List<ExtPuchasePlanExcelVO> extPuchasePlanExcelVOList = transformationObject(content);
try { try {
multipartFile = fileManagerFeignService.feignDownloadIO(1626790903997L); fileId = systemFileFeignService.getSystemFileId(Constants.PURCHASE_PLAN_TEMP_FILE_CODE_NAME);
multipartFile = fileManagerFeignService.feignDownloadIO(fileId);
} catch (IOException e) { } catch (IOException e) {
log.info("[接口单] >>> 文件服务下载为文件:{}--失败!", 1626790903997L); log.info("[接口单] >>> 文件服务下载为文件:{}--失败!", fileId);
throw new DxBusinessException("500", "文件服务下载文件失败:" + 1626790903997L); throw new DxBusinessException("500", "文件服务下载文件失败:" + fileId);
} }
try { try {
inputStream = new ByteArrayInputStream(multipartFile.getBytes()); inputStream = new ByteArrayInputStream(multipartFile.getBytes());
} catch (IOException e) { } catch (IOException e) {
log.info("[接口单] >>> 文件服务下载的文件:{}--转换为输入流失败!", 1626790903997L); log.info("[接口单] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + 1626790903997L); throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
} }
File file = new File(ExtPuchasePlanAttributeServiceImpl.class.getResource("").getPath()); String dir = ResourceHelper.CreateTemDir().getPath();
String filePath = file.getAbsolutePath()+"采购计划列表.xlsx"; String filePath = dir+ Constants.PURCHASE_PLAN_EXCEL_NAME;
//创建采购计划列表.xlsx 文件
FileUtils.inputToFile(inputStream, filePath); FileUtils.inputToFile(inputStream, filePath);
//向表格中写入数据 //向表格中写入数据
EasyExcel.write(filePath, ExtPuchasePlanExcelVO.class) EasyExcel.write(filePath, ExtPuchasePlanExcelVO.class)
...@@ -103,7 +111,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -103,7 +111,7 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
.sheet("采购计划列表").doWrite(extPuchasePlanExcelVOList); .sheet("采购计划列表").doWrite(extPuchasePlanExcelVOList);
//导出数据 //导出数据
FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", "采购计划.xlsx"); FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", "采购计划.xlsx");
FileUtil.del(filePath); FileUtil.del(dir);
} else { } else {
log.info("根据计划ids:" + Ids.toString() + "未查到相关数据"); log.info("根据计划ids:" + Ids.toString() + "未查到相关数据");
......
package com.yonde.dcs.plan.core.util;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.system.ApplicationHome;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.UUID;
/**
* @program: service
* @description: 外部资源配置类
* @author: dang wei
* @create: 2021-01-04 11:29
*/
@Slf4j
public class ResourceHelper {
public static String baseHomeDir;
/**
* 获取外部资源配置
*
* @return
*/
public static Properties getResource() {
Properties prop = new Properties();
try {
prop.load(new FileInputStream("resource/esignConfig.properties"));
} catch (FileNotFoundException e) {
log.error("找不到配置资源文件:" + e.getMessage());
} catch (IOException e) {
log.error("读取外部配置资源文件报错:" + e.getMessage());
}
return prop;
}
/**
* 项目经费 模板文件目录
*
* @return
*/
public static String getFundsDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"funds";
}
/**
* 项目经费 模板文件目录
*
* @return
*/
public static String getIndexDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"index";
}
/**
* 手写体签名路径
*
* @return
*/
public static String getHandImage() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"handImage";
}
/**
* 受控文件路径
*
* @return
*/
public static String getSKImage() {
return getBaseHomeDir() + File.separator +
"config" + File.separator + "doc" + File.separator +
"skImage.png"
;
}
/**
* 作废文件路径
*
* @return
*/
public static String getZFImage() {
return getBaseHomeDir() + File.separator +
"config" + File.separator + "doc" + File.separator +
"zfImage.png";
}
/**
* 设计资源模板
*
* @return
*/
public static String getProductTemplateDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"product";
}
/**
* 明细表配置坐标
*
* @return
*/
public static String getScheduleDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"detailed";
}
/**
* 工序卡片 提取属性+模板目录
*
* @return
*/
public static String getOperationCardDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"operation";
}
/**
* 工艺 封面 路径
*
* @return
*/
public static String getPlanDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"operation" + File.separator +
"工艺模板";
}
/**
* 相关卡片 的坐标配置目录
*
* @return
*/
public static String getCardPositionDir() {
return getBaseHomeDir() + File.separator +
"config" + File.separator +
"operation" + File.separator +
"position";
}
/**
* 获取jar包所在目录
*
* @return
*/
public static String getBaseHomeDir() {
if (StringUtils.isEmpty(baseHomeDir)) {
ApplicationHome home = new ApplicationHome(ResourceHelper.class);
baseHomeDir = home.getSource().getParentFile().getPath();
}
return baseHomeDir;
}
public static File CreateTemDir() {
String uuid = UUID.randomUUID().toString().replace("-", "");
String temDir = getBaseHomeDir() + File.separator +
"tem" + File.separator +
uuid;
return FileUtil.mkdir(temDir);
}
}
...@@ -54,6 +54,11 @@ ...@@ -54,6 +54,11 @@
<artifactId>dex-basic-service-feign</artifactId> <artifactId>dex-basic-service-feign</artifactId>
<version>4.1-20240826-RELEASE</version> <version>4.1-20240826-RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>com.yonde.dex</groupId>
<artifactId>dex-systemfile-feign</artifactId>
<version>4.1-20240826-RELEASE</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
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