feat(report): 添加销售报表导出功能

- 在 application-lets.yml 和 application-letsprod.yml 中添加报告相关配置
- 修改 TocofsSaleoutServiceImpl 中的导出逻辑,支持从配置文件读取模板路径
- 新增公共文件下载方法,用于处理导出文件下载
- 优化测试用例中的代码示例
This commit is contained in:
liuy 2024-11-04 17:47:29 +08:00
parent c01074d8e3
commit 34d46299a5
7 changed files with 163 additions and 45 deletions

View File

@ -51,6 +51,11 @@ letsofs:
appKey: 2097046829
secret: 35282f251476a3af4f00c7b36
#report
report:
templatesurl: /Users/liuyang/workspaces/hzya/kangarooDataCenterV3/service/src/main/resources/template/TOCTOB正向流程导出模版.xlsx
tempFile: /Users/liuyang/workspaces/hzya/tempfile
#钉钉
DING:
U8C_TEST_AGENTID: 3281181231

View File

@ -43,6 +43,11 @@ letsofs:
appKey: 2097046829
secret: 35282f251476a3af4f00c7b36
#report
report:
templatesurl: D:\server\tempFile\TOCTOB正向流程导出模版.xlsx
tempFile: D:\server\tempFile
#钉钉
DING:
U8C_TEST_AGENTID: 3281181231

View File

@ -27,7 +27,7 @@ public class ConsignmachiningInTest {
@Test
public void startImplement() {
// String code = "LETS-RE2024082300000007";
String code = "LETS-RE2024102200000018";
String code = "LETS-RE2024103000000089";
consignmachiningIn.startImplement(code);
// consignmachiningIn.startImplement("2024-09-24 13:49:15", "2024-09-24 13:49:17");

Binary file not shown.

View File

@ -23,6 +23,7 @@ import com.hzya.frame.uuid.UUIDLong;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
@ -54,6 +55,7 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
@Override
public JsonResultEntity queryToCSalesReport(JSONObject jsonObject) throws Exception {
Assert.notNull(jsonObject, "jsonObject不能为空");
JSONObject jsonStr = getstrObj("jsonStr", jsonObject);
//提供两种模式查询模式 query导出模式 excel
@ -161,25 +163,36 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
}
}
@Value("${report.templatesurl}")
private String reportTemplatesurl;
@Override
public JsonResultEntity exportToCSalesReportExcel(JSONObject jsonObject) throws Exception {
Assert.notNull(jsonObject, "jsonObject不能为空");
jsonObject.put("qType", "excel");
String businessType = jsonObject.getString("businessType");
JSONObject jsonStr = getstrObj("jsonStr", jsonObject);
Assert.notNull(jsonStr, "jsonStr对象不能为空");
jsonStr.put("qType", "excel");
//覆盖一遍
jsonObject.put("jsonStr", jsonStr);
String businessType = jsonStr.getString("businessType");
Assert.notNull(businessType, "businessType不能为空!");
JsonResultEntity jsonResultEntity = queryToCSalesReport(jsonObject);
if (jsonResultEntity != null && jsonResultEntity.getAttribute() != null) {
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("template/TOCTOB正向流程导出模版.xlsx");
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream(reportTemplatesurl);
String[] excelFile = createExcelFile();
if (businessType.equals("TOC_ORDER")) {
List<TocofsSaleoutDetailedDto> tocofsSaleoutDetailedEntityList = (List<TocofsSaleoutDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TocofsSaleoutDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tocofsSaleoutDetailedEntityList);
return BaseResult.getSuccessMessageEntity(excelFile[1]);
} else if (businessType.equals("TOB_ORDER")) {
List<TobofsSaleoutDetailedDto> tobofsSaleoutDetailedEntityList = (List<TobofsSaleoutDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TobofsSaleoutDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tobofsSaleoutDetailedEntityList);
return BaseResult.getSuccessMessageEntity(excelFile[1]);
} else {
return BaseResult.getFailureMessageEntity("查询失败无法确定TOB、TOC请选择TOC_ORDER、或者TOB_ORDER");
}
@ -187,13 +200,17 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
return BaseResult.getFailureMessageEntity("生成TOC、TOB销售业务对应的Excel文件失败");
}
@Value("${report.tempFile}")
private String reportTempFile;
/**
* 2024年7月19日 11:11:55 生成新Excel文件的路径
*
* @author liuyang
*/
private String[] createExcelFile() {
String projectPath = System.getProperty("user.dir");
// String projectPath = System.getProperty("user.dir");
String projectPath = reportTempFile;
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(projectPath);
@ -218,6 +235,7 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
@Override
public JsonResultEntity queryToCReturnReport(JSONObject jsonObject) throws Exception {
// long startTime = System.currentTimeMillis();
Assert.notNull(jsonObject, "jsonObject不能为空");
JSONObject jsonStr = getstrObj("jsonStr", jsonObject);
//提供两种模式查询模式 query导出模式 excel
@ -314,11 +332,11 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
PageInfo pageInfo = new PageInfo(tocofsSaleoutDetailedEntityPageAttribute);
return BaseResult.getSuccessMessageEntity("查询成功", pageInfo);
} else if ("excel".equals(qType)) {
if (businessType.equals("TOC_ORDER")) {
if (businessType.equals("TOC_RETURN")) {
//TOC退货
List<TocofsReturnGoodsDetailedDto> tocofsReturnGoodsDetailedDtos = iTocofsReturngoodsDetailedDao.queryEntityListBaseToc(tocofsSaleoutDetailedEntity);
return BaseResult.getSuccessMessageEntity("查询成功", tocofsReturnGoodsDetailedDtos);
} else if (businessType.equals("TOB_ORDER")) {
} else if (businessType.equals("TOB_RETURN")) {
//TOB退货
List<TobofsReturnGoodsDetailedDto> tobofsReturnGoodsDetailedDtos = iTocofsReturngoodsDetailedDao.queryEntityListBaseTob(tocofsSaleoutDetailedEntity);
return BaseResult.getSuccessMessageEntity("查询成功", tobofsReturnGoodsDetailedDtos);
@ -333,22 +351,30 @@ public class TocofsSaleoutServiceImpl extends BaseService<TocofsSaleoutEntity, S
@Override
public JsonResultEntity exportToCReturnReportExcel(JSONObject jsonObject) throws Exception {
Assert.notNull(jsonObject, "jsonObject不能为空");
jsonObject.put("qType", "excel");
String businessType = jsonObject.getString("businessType");
Assert.notNull(businessType, "businessType不能为空!");
JSONObject jsonStr = getstrObj("jsonStr", jsonObject);
Assert.notNull(jsonStr, "jsonStr对象不能为空");
jsonStr.put("qType", "excel");
//覆盖一遍
jsonObject.put("jsonStr", jsonStr);
String businessType = jsonStr.getString("businesstype");
Assert.notNull(businessType, "businesstype不能为空!");
JsonResultEntity jsonResultEntity = queryToCReturnReport(jsonObject);
if (jsonResultEntity != null && jsonResultEntity.getAttribute() != null) {
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("template/TOCTOB正向流程导出模版.xlsx");
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream(reportTemplatesurl);
String[] excelFile = createExcelFile();
if (businessType.equals("TOC_ORDER")) {
List<TocofsSaleoutDetailedDto> tocofsSaleoutDetailedEntityList = (List<TocofsSaleoutDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TocofsSaleoutDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tocofsSaleoutDetailedEntityList);
} else if (businessType.equals("TOB_ORDER")) {
List<TobofsSaleoutDetailedDto> tobofsSaleoutDetailedEntityList = (List<TobofsSaleoutDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TobofsSaleoutDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tobofsSaleoutDetailedEntityList);
if (businessType.equals("TOC_RETURN")) {
List<TocofsReturnGoodsDetailedDto> tocofsSaleoutDetailedEntityList = (List<TocofsReturnGoodsDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TocofsReturnGoodsDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tocofsSaleoutDetailedEntityList);
return BaseResult.getSuccessMessageEntity(excelFile[1]);
} else if (businessType.equals("TOB_RETURN")) {
List<TobofsReturnGoodsDetailedDto> tobofsSaleoutDetailedEntityList = (List<TobofsReturnGoodsDetailedDto>) jsonResultEntity.getAttribute();
EasyExcel.write(excelFile[0], TobofsReturnGoodsDetailedDto.class).withTemplate(templateFileName).sheet().doWrite(tobofsSaleoutDetailedEntityList);
return BaseResult.getSuccessMessageEntity(excelFile[1]);
} else {
return BaseResult.getFailureMessageEntity("查询失败无法确定TOB、TOC请选择TOC_ORDER、或者TOB_ORDER");
}

View File

@ -13,7 +13,9 @@ import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import com.hzya.frame.web.exception.BaseSystemException;
import com.hzya.frame.webapp.entrance.service.IEntranceService;
import com.hzya.frame.webapp.entrance.util.FileDownloadUtil;
import org.apache.commons.io.FileUtils;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -70,11 +72,13 @@ public class EntranceController {
protected IFileDownloadService filedownloadService;
@Resource
protected ISysApplicationService sysApplicationService;
@RequestMapping(value = "/option")
@ResponseBody
public JsonResultEntity option(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
return entranceService.doBusiness(servletRequest, servletResponse);
}
//平台接口
@RequestMapping(value = "/platformInterface")
@ResponseBody
@ -152,7 +156,6 @@ public class EntranceController {
}
/**
* 根据文件保存的新名称下载文件
*
@ -178,6 +181,7 @@ public class EntranceController {
}
return responseEntity;
}
/**
* 根据文件保存的新名称下载文件
*
@ -203,6 +207,7 @@ public class EntranceController {
}
return responseEntity;
}
@RequestMapping(value = "/testOption")
@ResponseBody
public EsbReturnEntity testOption(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
@ -234,5 +239,27 @@ public class EntranceController {
return null;
}
@Value("${report.tempFile}")
private String reportTempFile;
/**
* 公共文件文件下载
*/
@RequestMapping(value = "/option/downFilesBasedFileNameFileType")
public void downFilesBasedFileNameFileType(HttpServletRequest request, HttpServletResponse response, @Param("filename") String filename) {
try {
StringBuffer filePath = new StringBuffer();
filePath.append(reportTempFile);
filePath.append(File.separator);
filePath.append("excelfile");
filePath.append(File.separator);
filePath.append(filename);
//处理文件下载或者预览
FileDownloadUtil.downLoad(filePath.toString(), response, false, "附件下载.xlsx");
} catch (Exception e) {
e.printStackTrace();
logger.error("downFilesBasedFileNameFileType", e.getMessage());
}
}
}

View File

@ -0,0 +1,55 @@
package com.hzya.frame.webapp.entrance.util;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URL;
/**
* 文件下载处理方法
*
* @Authorliuyang
* @Packagecom.hzya.frame.webapp.entrance.util
* @ProjectkangarooDataCenter
* @nameFileDownloadUtil
* @Date2024/7/19 17:08
* @FilenameFileDownloadUtil
*/
public class FileDownloadUtil {
/**
* 加载打开文件
*
* @param filePath 文件地址
* @param response 响应对象
* @param isOnLine 是否在线打开
*/
public static void downLoad(String filePath, HttpServletResponse response, boolean isOnLine, String filename) throws Exception {
File f = new File(filePath);
if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset(); //非常重要
if (isOnLine) { //在线打开方式
URL u = new URL("file:///" + filePath);
response.setContentType(u.openConnection().getContentType());
response.setHeader("Content-Disposition", "inline; filename=" + new String((filename).getBytes("UTF-8"), "ISO8859-1"));
//文件名应该编码成UTF-8
} else { //纯下载方式
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(filename.getBytes("UTF-8"), "ISO8859-1"));
}
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
br.close();
out.close();
}
}