Commit 5925ec10 authored by lanbaoming's avatar lanbaoming

2024-05-01 报表修改

parent aeee811d
package cn.iocoder.yudao.framework.apollo.core.event.export;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/*
lanbm 2024-05-01 add
销售分析报表导出excel
*/
@Data
public class ReportCustomerAnalysisExcelExportEvent {
/**
* 操作用户
*/
private Long userId;
/**
* 端口
*/
private Integer userType;
/**
* 请求参数
*/
private String requestParams;
/**
* 国际化语言值,默认0中文, 具体取值I18nMessage.getLang()
*/
private Integer lang = 0;
/**
* 文件名称
*/
private String fileName;
/**
* 文件路径
*/
private String path;
/**
* 下载地址
*/
private String url;
/**
* 执行结果
*/
private String result;
@ApiModelProperty(value = "文件ID")
private Long fileId;
}
package cn.iocoder.yudao.framework.apollo.core.event.export;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/*
客户分析报表导出 lanbm 2024-05-01 add
*/
@Data
public class ReportSalesAnalysisExcelExportEvent {
/**
* 操作用户
*/
private Long userId;
/**
* 端口
*/
private Integer userType;
/**
* 请求参数
*/
private String requestParams;
/**
* 国际化语言值,默认0中文, 具体取值I18nMessage.getLang()
*/
private Integer lang = 0;
/**
* 文件名称
*/
private String fileName;
/**
* 文件路径
*/
private String path;
/**
* 下载地址
*/
private String url;
/**
* 执行结果
*/
private String result;
@ApiModelProperty(value = "文件ID")
private Long fileId;
}
......@@ -33,5 +33,12 @@
<artifactId>yudao-module-system-impl</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-infra-impl</artifactId>
<version>1.6.1-snapshot</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
......@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq;
......@@ -13,10 +14,15 @@ import cn.iocoder.yudao.module.delivery.entity.SalesAnalysisReq;
import cn.iocoder.yudao.module.delivery.entity.SalesAnalysisResp;
import cn.iocoder.yudao.module.delivery.service.SalesAnalysisService;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.file.FileMakeApi;
import cn.iocoder.yudao.module.system.api.file.dto.FileMakeReqDTO;
import cn.iocoder.yudao.module.system.enums.download.DownloadTypeEnum;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
......@@ -46,6 +52,9 @@ public class SalesAnalysisControl {
@Autowired
private DictDataApi dictDataApi;
@Resource
private FileMakeApi fileMakeApi;
/*
根据原始信息计算逻辑展示信息 lanbm 2024-04-29 add
*/
......@@ -164,13 +173,26 @@ public class SalesAnalysisControl {
@GetMapping("/exportExcel")
@ApiOperation("导出销售分析数据")
@OperateLog(type = EXPORT)
public void export(HttpServletResponse response,
public CommonResult<Boolean> export(HttpServletResponse response,
@Valid SalesAnalysisReq Req)
throws IOException {
System.out.println("订单分析查询数据导出查询条件:" + Req);
FileMakeReqDTO reqDTO = new FileMakeReqDTO();
reqDTO.setType(DownloadTypeEnum.REPORT_SALES_ANALYSIS.getType());
reqDTO.setName("销售分析数据");
reqDTO.setFileSuffix("xlsx");
reqDTO.setTemporaryFile(true);
reqDTO.setUserType(2);
reqDTO.setLang(I18nMessage.getLang());
reqDTO.setRequestParams(JSONObject.toJSONString(Req));
fileMakeApi.sendFileMake(reqDTO);
return CommonResult.success(true);
/*
List<SalesAnalysisExcelResp> list = salesAnalysisService.getList(Req);
ExcelUtils.write(response, "销售分析数据.xls", "销售分析数据",
SalesAnalysisExcelResp.class, list);
SalesAnalysisExcelResp.class, list);*/
}
}
......@@ -5,6 +5,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import java.math.BigDecimal;
/*
客户分析报表
逻辑数据大部分集中在表 ecw_customer
......@@ -29,10 +31,6 @@ public class CustomerAnalysisReq extends PageParam {
private String name;
private String searchtype;
/*
是否新客户
*/
private int isnew;
/*
客户国家
......@@ -71,6 +69,11 @@ public class CustomerAnalysisReq extends PageParam {
*/
private int first;
/*
业绩类型
*/
private int cusYjType;
/*
客户角色
*/
......@@ -81,17 +84,29 @@ public class CustomerAnalysisReq extends PageParam {
数据筛选类型
*/
private String searchDataType1;
private BigDecimal searchData1;//总V值查询
private String searchDataType2;
private BigDecimal searchData2;//海运拼柜
private String searchDataType3;
private BigDecimal searchData3; //专线空运
/*
客户时间筛选条件
客户创建时间
*/
private String searchDataType4;
private String sdate4;
private String edate4;
/*
首次成交时间
*/
private String sdate5;
private String edate5;
/*
时间筛选类型
首次成交日期,客户创建日期
......
......@@ -87,7 +87,6 @@ public class CustomerAnalysisResp {
*/
private String sumvolumeTbShow1;
/*
专线空运
*/
......@@ -120,22 +119,25 @@ public class CustomerAnalysisResp {
海运月均方数
*/
private String seaMonthAvg;
private BigDecimal seaMonthAvgZ;
/*
海运月均方数同比
*/
private String seaMonthAvgTb;
private BigDecimal seaMonthAvgTbZ;
/*
空运月均重量
*/
private String airMothAvg;
private BigDecimal airMothAvgZ;//数值
/*
空运月均同比
*/
private String airMothAvgTb;
private String airMothAvgTb;//显示字符串
private BigDecimal airMothAvgTbZ;//数值
/*
重货总V值
*/
......
package cn.iocoder.yudao.module.delivery.listener;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.apollo.core.event.export.ReportCustomerAnalysisExcelExportEvent;
import cn.iocoder.yudao.framework.apollo.core.event.export.ReportSalesAnalysisExcelExportEvent;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.module.delivery.convert.CustomerAnalysis;
import cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisExcelResp;
import cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq;
import cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisResp;
import cn.iocoder.yudao.module.delivery.service.CustomerAnalysisService;
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
import cn.iocoder.yudao.module.infra.service.file.FileService;
import cn.iocoder.yudao.module.system.framework.ue.UeProperties;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static cn.iocoder.yudao.framework.excel.constant.ExportConstant.DATA_FORMAT;
@Component("CustomerAnalysisExcelExportListener")
@AllArgsConstructor
@Slf4j
public class CustomerAnalysisExcelExportListener {
private UeProperties ueProperties;
private FileService fileService;
@Autowired
private CustomerAnalysisService customerAnalysisService;
/**
* 客户分析导出监听 lanbm 2024-05-01 add
*
* @param event 编号记录
*/
@EventListener(ReportCustomerAnalysisExcelExportEvent.class)
public void CustomerAnalysisExcelExportPushEvent(
ReportCustomerAnalysisExcelExportEvent event) {
if (StringUtils.isNotBlank(event.getRequestParams())) {
try {
System.out.println("开始数据导出");
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern(DATA_FORMAT);
String nowTime = formatter.format(LocalDateTime.now());
String dir = ueProperties.getTempDir().
concat("/CustomerAnalysis/excel/");
File fileDir = new File(dir);
if (!fileDir.exists()) {
fileDir.mkdirs();
}
CustomerAnalysisReq query =
JSONObject.parseObject(event.getRequestParams(),
CustomerAnalysisReq.class);
String fileName =
event.getUserId().toString().
concat(StrUtil.DASHED).concat(
event.getUserType().toString()).
concat(StrUtil.DASHED).
concat(nowTime).
concat("客户分析报表.xlsx");
List<CustomerAnalysisResp> list =
customerAnalysisService.getList(query);
List<CustomerAnalysisExcelResp> listExel =
CustomerAnalysis.INSTANCE.convertList(list);
String path = ExcelUtils.write(dir, fileName,
"客户分析报表",
CustomerAnalysisExcelResp.class,
listExel);
// 获取到临时文件
File file = new File(path);
// 创建FileInputStream对象
FileInputStream fileInputStream = new FileInputStream(file);
// 读取文件内容
byte[] fileBytes = new byte[(int) file.length()];
fileInputStream.read(fileBytes);
// 关闭文件流
fileInputStream.close();
// 将文件上传到资源服务器
FileDO fileDO = fileService.createFile(dir, fileName, fileBytes);
event.setPath(fileDO.getPath());
event.setFileName(fileDO.getPath());
event.setUrl(fileDO.getUrl());
event.setFileId(fileDO.getId());
} catch (Exception e) {
e.printStackTrace();
event.setResult(e.getMessage());
}
} else {
event.setResult("param fail");
}
}
}
package cn.iocoder.yudao.module.delivery.listener;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.apollo.core.event.export.ReportSalesAnalysisExcelExportEvent;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.module.delivery.entity.CustomerAnalysisReq;
import cn.iocoder.yudao.module.delivery.entity.SalesAnalysisExcelResp;
import cn.iocoder.yudao.module.delivery.entity.SalesAnalysisReq;
import cn.iocoder.yudao.module.delivery.entity.SalesAnalysisResp;
import cn.iocoder.yudao.module.delivery.service.SalesAnalysisService;
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
import cn.iocoder.yudao.module.infra.service.file.FileService;
import cn.iocoder.yudao.module.system.framework.ue.UeProperties;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static cn.iocoder.yudao.framework.excel.constant.ExportConstant.DATA_FORMAT;
@Component("SalesAnalysisExcelExportListener")
@AllArgsConstructor
@Slf4j
public class SalesAnalysisExcelExportListener {
private UeProperties ueProperties;
private FileService fileService;
@Autowired
private SalesAnalysisService salesAnalysisService;
/**
* 销售分析导出监听 lanbm 2024-05-01 add
* 参考网址
*https://www.cnblogs.com/h-java/p/9951547.html
* @param event 编号记录
*/
@EventListener(ReportSalesAnalysisExcelExportEvent.class)
public void SalesAnalysisExcelExportPushEvent(
ReportSalesAnalysisExcelExportEvent event) {
if (StringUtils.isNotBlank(event.getRequestParams())) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATA_FORMAT);
String nowTime = formatter.format(LocalDateTime.now());
String dir = ueProperties.getTempDir().concat("/SalesAnalysis/excel/");
File fileDir = new File(dir);
if (!fileDir.exists()) {
fileDir.mkdirs();
}
String fileName =
event.getUserId().toString().
concat(StrUtil.DASHED).
concat(event.getUserType().toString()).
concat(StrUtil.DASHED).
concat(nowTime).
concat("销售分析数据.xlsx");
SalesAnalysisReq query =
JSONObject.parseObject(event.getRequestParams(),
SalesAnalysisReq.class);
List<SalesAnalysisExcelResp> list =
salesAnalysisService.getList(query);
String path = ExcelUtils.write(dir, fileName,
"销售分析数据", SalesAnalysisExcelResp.class, list);
// 获取到临时文件
File file = new File(path);
// 创建FileInputStream对象
FileInputStream fileInputStream = new FileInputStream(file);
// 读取文件内容
byte[] fileBytes = new byte[(int) file.length()];
fileInputStream.read(fileBytes);
// 关闭文件流
fileInputStream.close();
// 将文件上传到资源服务器
FileDO fileDO = fileService.createFile(dir, fileName, fileBytes);
event.setPath(fileDO.getPath());
event.setFileName(fileDO.getPath());
event.setUrl(fileDO.getUrl());
event.setFileId(fileDO.getId());
} catch (Exception e) {
e.printStackTrace();
event.setResult(e.getMessage());
}
} else {
event.setResult("param fail");
}
}
}
......@@ -33,6 +33,6 @@ public interface CustomerAnalysisMapper {
*/
Long GetCount(CustomerAnalysisReq req);
List<CustomerAnalysisExcelResp>getList(CustomerAnalysisReq req);
List<CustomerAnalysisResp>getList(CustomerAnalysisReq req);
}
......@@ -17,7 +17,17 @@ public interface CustomerAnalysisService {
throws JsonProcessingException;
List<CustomerAnalysisExcelResp>getList(CustomerAnalysisReq req);
List<CustomerAnalysisResp> getList(CustomerAnalysisReq req);
PageResult<CustomerAnalysisResp> GetDataResult(CustomerAnalysisReq query)
throws JsonProcessingException;
List<CustomerAnalysisResp> GetDataListResult(CustomerAnalysisReq query)
throws JsonProcessingException;
CustomerAnalysisReq getReq(CustomerAnalysisReq Req);
CustomerAnalysisReq getDataWhere(CustomerAnalysisReq query);
}
package cn.iocoder.yudao.module.delivery.task;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/*
lanbm 2024-04-30 测试定时任务
*/
@Component
@TenantJob
@Slf4j
public class ReportTask implements JobHandler {
@Override
public String execute(String param) throws Exception {
int var1 = 30;
int var2 = 3;
int var3 = 6;
if (StringUtils.isNotBlank(param)){
String[] vars = param.split(StrUtil.COMMA);
if (vars.length > 0){
var1 = Integer.parseInt(vars[0]);
}
if (vars.length > 1){
var2 = Integer.parseInt(vars[1]);
}
if (vars.length > 2){
var3 = Integer.parseInt(vars[2]);
}
}
System.out.println("定时任务参数:" + param);
return "";
}
}
......@@ -164,6 +164,16 @@ public enum DownloadTypeEnum implements IntArrayValuable {
*/
ACHIEVEMENT_DETAIL_EXCEL_EXPORT(30),
/*
客户分析报表导出 lanbm 2024-05-01 add
*/
REPORT_CSSTOMER_ANALYSIS(31),
/*
销售分析报表导出 lanbm 2024-05-01 add
*/
REPORT_SALES_ANALYSIS(32),
// ....自己补充
;
......
......@@ -347,6 +347,14 @@ public class DownloadLogServiceImpl extends AbstractService<DownloadLogMapper, D
case ACHIEVEMENT_DETAIL_EXCEL_EXPORT:
achievementDetailExcelExportPushEvent(downloadLog);
break;
case REPORT_CSSTOMER_ANALYSIS:
//客户分析报表 lanbm 2024-05-01 add
REPORT_CSSTOMER_ANALYSIS_Event(downloadLog);
break;
case REPORT_SALES_ANALYSIS:
//销售分析报表 lanbm 2024-05-01 add
REPORT_SALES_ANALYSIS_Event(downloadLog);
break;
default:
downloadLog.setResult("unknown type");
break;
......@@ -801,4 +809,42 @@ public class DownloadLogServiceImpl extends AbstractService<DownloadLogMapper, D
downloadLog.setFileId(event.getFileId());
}
/*
lanbm 2024-05-01 add
客户分析
*/
private void REPORT_CSSTOMER_ANALYSIS_Event(DownloadLogDO downloadLog) {
ReportCustomerAnalysisExcelExportEvent event =
new ReportCustomerAnalysisExcelExportEvent();
event.setUserId(downloadLog.getUserId());
event.setUserType(downloadLog.getUserType());
event.setLang(downloadLog.getLang());
event.setRequestParams(downloadLog.getRequestParams());
applicationContext.publishEvent(event);
downloadLog.setFileName(event.getFileName());
downloadLog.setPath(event.getPath());
downloadLog.setDownloadUrl(event.getUrl());
downloadLog.setResult(event.getResult());
downloadLog.setFileId(event.getFileId());
}
/*
销售分析报表 lanbm 2024-05-01 add
*/
private void REPORT_SALES_ANALYSIS_Event(DownloadLogDO downloadLog) {
ReportSalesAnalysisExcelExportEvent event =
new ReportSalesAnalysisExcelExportEvent();
event.setUserId(downloadLog.getUserId());
event.setUserType(downloadLog.getUserType());
event.setLang(downloadLog.getLang());
event.setRequestParams(downloadLog.getRequestParams());
applicationContext.publishEvent(event);
downloadLog.setFileName(event.getFileName());
downloadLog.setPath(event.getPath());
downloadLog.setDownloadUrl(event.getUrl());
downloadLog.setResult(event.getResult());
downloadLog.setFileId(event.getFileId());
}
}
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