Commit 4d39eea6 authored by wangqiang's avatar wangqiang

计划模板下载功能开发

parent ead13b20
......@@ -412,5 +412,9 @@ public class Constants {
*/
public static final String IED_PLAN_EXCEL_NAME = "\\IED计划列表.xlsx";
public static final String IED_PLAN_TEMP_FILE_CODE_NAME ="IED计划001模板";
/**
* 计划模板
*/
public static final String PLAN_TEMP_FILE_NAME ="\\计划模板.xlsx";
}
package com.yonde.dcs.plan.core.controller;
import com.yonde.dcs.plan.core.service.ExtFileTemplateManagerService;
import com.yonde.dex.basedata.entity.api.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @description: ExtIEDPlan-Controller
* @author: dexadmin
* @version: V
* @date: 2024-9-11 15:49:41
**/
@Api(tags = "ExtIEDPlan管理服务")
@RequestMapping("/ExtFileTemplateManager")
@ResponseBody()
@Controller
public class ExtFileTemplateManagerController {
@Autowired
private ExtFileTemplateManagerService extFileTemplateManagerService;
/**
* 采购计划、IED计划、ICM计划模板导出
* @param response
* @param fileType =1采购计划模板导出、=2 IED计划模板导出、=3 ICM计划摸模板导出
* @throws IOException
*/
@ApiOperation(value = "下载计划模板", notes = "下载计划模板", httpMethod = "GET")
@GetMapping(value = "/planTemplateDownload")
public ApiResult planTemplateDownload(HttpServletResponse response, @RequestParam("fileType") Integer fileType) throws IOException {
return ApiResult.ok(extFileTemplateManagerService.FileTemplateDownload(response, fileType),"模板下载成功");
}
}
package com.yonde.dcs.plan.core.service;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
public interface ExtFileTemplateManagerService {
public String FileTemplateDownload(HttpServletResponse response,Integer fileType) throws IOException;
}
package com.yonde.dcs.plan.core.service.impl;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.core.service.ExtFileTemplateManagerService;
import com.yonde.dcs.plan.core.util.FileUtils;
import com.yonde.dcs.plan.core.util.ResourceHelper;
import com.yonde.dex.basedata.entity.api.ApiResult;
import com.yonde.dex.basedata.entity.api.CustomMultipartFile;
import com.yonde.dex.basedata.exception.DxBusinessException;
import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.systemfile.feign.SystemFileFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@Slf4j
@Service
public class ExtFileTemplateManagerServiceImpl implements ExtFileTemplateManagerService {
@Autowired
private SystemFileFeignService systemFileFeignService;
@Autowired
private FileManagerFeignService fileManagerFeignService;
@Override
public String FileTemplateDownload(HttpServletResponse response, Integer fileType) throws IOException {
InputStream inputStream = null;
CustomMultipartFile multipartFile = null;
Long fileId = null;
try {
if(fileType == 1){ //采购计划模板下载
fileId = systemFileFeignService.getSystemFileId(Constants.PURCHASE_PLAN_TEMP_FILE_CODE_NAME);
}else if(fileType == 2){ //IED计划模板下载
fileId = systemFileFeignService.getSystemFileId(Constants.IED_PLAN_TEMP_FILE_CODE_NAME);
}else if(fileType == 3){ //ICM计划模板下载
//todo ICM计划暂时还未创建模板
}else {
log.info("未知文件类型:{}",fileType);
}
multipartFile = fileManagerFeignService.feignDownloadIO(fileId);
} catch (IOException e) {
log.info("[计划模板] >>> 文件服务下载为文件:{}--失败!", fileId);
throw new DxBusinessException("500", "文件服务下载文件失败:" + fileId);
}
try {
inputStream = new ByteArrayInputStream(multipartFile.getBytes());
} catch (IOException e) {
log.info("[计划模板] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
}
String dir = ResourceHelper.CreateTemDir().getPath();
String filePath = dir + Constants.PLAN_TEMP_FILE_NAME;
//创建采购计划列表.xlsx 文件
FileUtils.inputToFile(inputStream, filePath);
//导出数据
FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", "计划模板.xlsx");
return ApiResult.SUCCESS;
}
}
......@@ -92,13 +92,13 @@ public class ExtIEDPlanServiceImpl<V extends ExtIEDPlanVO> implements ExtIEDPlan
fileId = systemFileFeignService.getSystemFileId(Constants.IED_PLAN_TEMP_FILE_CODE_NAME);
multipartFile = fileManagerFeignService.feignDownloadIO(fileId);
} catch (IOException e) {
log.info("[接口单] >>> 文件服务下载为文件:{}--失败!", fileId);
log.info("[IED计划模板] >>> 文件服务下载为文件:{}--失败!", fileId);
throw new DxBusinessException("500", "文件服务下载文件失败:" + fileId);
}
try {
inputStream = new ByteArrayInputStream(multipartFile.getBytes());
} catch (IOException e) {
log.info("[接口单] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
log.info("[IED计划模板] >>> 文件服务下载的文件:{}--转换为输入流失败!", fileId);
throw new DxBusinessException("500", "文件服务下载的文件转换为输入流失败:" + fileId);
}
String dir = ResourceHelper.CreateTemDir().getPath();
......
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