feat: init yueqian-erp based on xingyun
- Change groupId: com.lframework -> com.yueqian - Change artifactId: xingyun -> yueqian-erp - Rename modules: xingyun-* -> yueqian-erp-* - Update Java packages: com.lframework.xingyun -> com.yueqian.xingyun - Preserve external Jugg framework dependencies as com.lframework - Update README and documentation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yueqian-erp</artifactId>
|
||||
<groupId>com.yueqian</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yueqian-erp-chart</artifactId>
|
||||
<name>【${project.artifactId}】图表服务层</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yueqian</groupId>
|
||||
<artifactId>yueqian-erp-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.yueqian.xingyun.chart.bo;
|
||||
|
||||
import com.lframework.starter.web.core.bo.BaseBo;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartSameMonthBo extends BaseBo<OrderChartSameMonthDto> {
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
@Schema(description = "单据总金额")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据总数量
|
||||
*/
|
||||
@Schema(description = "单据总数量")
|
||||
private Integer totalNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private String createDate;
|
||||
|
||||
public OrderChartSameMonthBo() {
|
||||
|
||||
}
|
||||
|
||||
public OrderChartSameMonthBo(OrderChartSameMonthDto dto) {
|
||||
|
||||
super(dto);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.yueqian.xingyun.chart.bo;
|
||||
|
||||
import com.lframework.starter.web.core.bo.BaseBo;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSumDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartSameMonthSumBo extends BaseBo<OrderChartSumDto> {
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
@Schema(description = "单据总金额")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据数量
|
||||
*/
|
||||
@Schema(description = "单据数量")
|
||||
private Long totalNum;
|
||||
|
||||
/**
|
||||
* 图表数据
|
||||
*/
|
||||
@Schema(description = "图表数据")
|
||||
private List<OrderChartSameMonthBo> charts;
|
||||
|
||||
public OrderChartSameMonthSumBo() {
|
||||
|
||||
}
|
||||
|
||||
public OrderChartSameMonthSumBo(OrderChartSumDto dto) {
|
||||
|
||||
super(dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.yueqian.xingyun.chart.bo;
|
||||
|
||||
import com.lframework.starter.web.core.bo.BaseBo;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartTodayDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartTodayBo extends BaseBo<OrderChartTodayDto> {
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
@Schema(description = "单据总金额")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据总数量
|
||||
*/
|
||||
@Schema(description = "单据总数量")
|
||||
private Integer totalNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private String createHour;
|
||||
|
||||
public OrderChartTodayBo() {
|
||||
|
||||
}
|
||||
|
||||
public OrderChartTodayBo(OrderChartTodayDto dto) {
|
||||
|
||||
super(dto);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.yueqian.xingyun.chart.bo;
|
||||
|
||||
import com.lframework.starter.web.core.bo.BaseBo;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSumDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartTodaySumBo extends BaseBo<OrderChartSumDto> {
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
@Schema(description = "单据总金额")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据数量
|
||||
*/
|
||||
@Schema(description = "单据数量")
|
||||
private Long totalNum;
|
||||
|
||||
/**
|
||||
* 图表数据
|
||||
*/
|
||||
@Schema(description = "图表数据")
|
||||
private List<OrderChartTodayBo> charts;
|
||||
|
||||
public OrderChartTodaySumBo() {
|
||||
|
||||
}
|
||||
|
||||
public OrderChartTodaySumBo(OrderChartSumDto dto) {
|
||||
|
||||
super(dto);
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package com.yueqian.xingyun.chart.controller;
|
||||
|
||||
import com.lframework.starter.common.utils.CollectionUtil;
|
||||
import com.lframework.starter.web.core.bo.BaseBo;
|
||||
import com.lframework.starter.web.core.controller.DefaultBaseController;
|
||||
import com.lframework.starter.web.core.components.resp.InvokeResult;
|
||||
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
|
||||
import com.yueqian.xingyun.chart.bo.OrderChartSameMonthBo;
|
||||
import com.yueqian.xingyun.chart.bo.OrderChartSameMonthSumBo;
|
||||
import com.yueqian.xingyun.chart.bo.OrderChartTodayBo;
|
||||
import com.yueqian.xingyun.chart.bo.OrderChartTodaySumBo;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartTodayDto;
|
||||
import com.yueqian.xingyun.chart.enums.OrderChartBizType;
|
||||
import com.yueqian.xingyun.chart.service.OrderChartService;
|
||||
import com.yueqian.xingyun.chart.vo.GetOrderChartVo;
|
||||
import com.yueqian.xingyun.chart.vo.QueryOrderChartVo;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 报表
|
||||
*
|
||||
* @author zmj
|
||||
*/
|
||||
@Tag(name = "报表")
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/chart")
|
||||
public class ChartController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private OrderChartService orderChartService;
|
||||
|
||||
/**
|
||||
* 订单报表
|
||||
*/
|
||||
@Operation(summary = "订单报表")
|
||||
@GetMapping("/order")
|
||||
public InvokeResult<Map<String, Map<String, ? extends BaseBo>>> orderChart() {
|
||||
|
||||
//当日数据
|
||||
Map<String, OrderChartTodaySumBo> todayMap = new HashMap<>(2, 1);
|
||||
//当月数据
|
||||
Map<String, OrderChartSameMonthSumBo> sameMonthMap = new HashMap<>(2, 1);
|
||||
|
||||
List<Integer> orderBizTypes = CollectionUtil.toList(OrderChartBizType.PURCHASE_ORDER.getCode(),
|
||||
OrderChartBizType.SALE_ORDER.getCode(), OrderChartBizType.RETAIL_OUT_SHEET.getCode());
|
||||
todayMap.put("order", getTodayChart(orderBizTypes));
|
||||
sameMonthMap.put("order", getSameMonthChart(orderBizTypes));
|
||||
|
||||
List<Integer> returnBizTypes = CollectionUtil.toList(
|
||||
OrderChartBizType.PURCHASE_RETURN.getCode(),
|
||||
OrderChartBizType.SALE_RETURN.getCode(), OrderChartBizType.RETAIL_RETURN.getCode());
|
||||
todayMap.put("returned", getTodayChart(returnBizTypes));
|
||||
sameMonthMap.put("returned", getSameMonthChart(returnBizTypes));
|
||||
|
||||
Map<String, Map<String, ? extends BaseBo>> result = new HashMap<>(2, 1);
|
||||
result.put("today", todayMap);
|
||||
result.put("sameMonth", sameMonthMap);
|
||||
|
||||
return InvokeResultBuilder.success(result);
|
||||
}
|
||||
|
||||
private OrderChartTodaySumBo getTodayChart(List<Integer> bizTypes) {
|
||||
|
||||
GetOrderChartVo orderSumVo = new GetOrderChartVo();
|
||||
orderSumVo.setBizTypes(bizTypes);
|
||||
// 今日订单汇总数据
|
||||
OrderChartTodaySumBo orderSumBo = new OrderChartTodaySumBo(
|
||||
orderChartService.getTodayChartSum(orderSumVo));
|
||||
// 今日订单图表数据
|
||||
QueryOrderChartVo chartVo = new QueryOrderChartVo();
|
||||
chartVo.setBizTypes(bizTypes);
|
||||
List<OrderChartTodayDto> charts = orderChartService.queryTodayChart(chartVo);
|
||||
List<OrderChartTodayBo> chartResults = CollectionUtil.emptyList();
|
||||
if (!CollectionUtil.isEmpty(charts)) {
|
||||
chartResults = charts.stream().map(OrderChartTodayBo::new).collect(Collectors.toList());
|
||||
}
|
||||
orderSumBo.setCharts(chartResults);
|
||||
|
||||
return orderSumBo;
|
||||
}
|
||||
|
||||
private OrderChartSameMonthSumBo getSameMonthChart(List<Integer> bizTypes) {
|
||||
|
||||
GetOrderChartVo orderSumVo = new GetOrderChartVo();
|
||||
orderSumVo.setBizTypes(bizTypes);
|
||||
// 当月订单汇总数据
|
||||
OrderChartSameMonthSumBo sameMonthOrderSumBo = new OrderChartSameMonthSumBo(
|
||||
orderChartService.getSameMonthChartSum(orderSumVo));
|
||||
// 当月订单图表数据
|
||||
QueryOrderChartVo chartVo = new QueryOrderChartVo();
|
||||
chartVo.setBizTypes(bizTypes);
|
||||
List<OrderChartSameMonthDto> sameMonthCharts = orderChartService.querySameMonthChart(chartVo);
|
||||
List<OrderChartSameMonthBo> sameMonthChartResults = CollectionUtil.emptyList();
|
||||
if (!CollectionUtil.isEmpty(sameMonthCharts)) {
|
||||
sameMonthChartResults = sameMonthCharts.stream().map(OrderChartSameMonthBo::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
sameMonthOrderSumBo.setCharts(sameMonthChartResults);
|
||||
|
||||
return sameMonthOrderSumBo;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.yueqian.xingyun.chart.dto;
|
||||
|
||||
import com.lframework.starter.web.core.dto.BaseDto;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartSameMonthDto implements BaseDto, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据总数量
|
||||
*/
|
||||
private Integer totalNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createDate;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yueqian.xingyun.chart.dto;
|
||||
|
||||
import com.lframework.starter.web.core.dto.BaseDto;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartSumDto implements BaseDto, Serializable {
|
||||
|
||||
public static final String CACHE_NAME = "OrderChartSumDto";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据数量
|
||||
*/
|
||||
private Long totalNum;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yueqian.xingyun.chart.dto;
|
||||
|
||||
import com.lframework.starter.web.core.dto.BaseDto;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderChartTodayDto implements BaseDto, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 单据总数量
|
||||
*/
|
||||
private Integer totalNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createHour;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.yueqian.xingyun.chart.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.lframework.starter.web.core.entity.BaseEntity;
|
||||
import com.lframework.starter.web.core.dto.BaseDto;
|
||||
import com.yueqian.xingyun.chart.enums.OrderChartBizType;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author zmj
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
@Data
|
||||
@TableName("tbl_order_chart")
|
||||
public class OrderChart extends BaseEntity implements BaseDto {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 创建时间 新增时赋值
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private String createDate;
|
||||
|
||||
/**
|
||||
* 创建时间(小时)
|
||||
*/
|
||||
private String createHour;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private OrderChartBizType bizType;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.yueqian.xingyun.chart.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.lframework.starter.web.core.enums.BaseEnum;
|
||||
|
||||
public enum OrderChartBizType implements BaseEnum<Integer> {
|
||||
PURCHASE_ORDER(0, "采购订单"), PURCHASE_RETURN(1, "采购退单"), SALE_ORDER(2, "销售订单"), SALE_RETURN(3,
|
||||
"销售退单"), RETAIL_OUT_SHEET(4, "零售出库单"), RETAIL_RETURN(5, "零售退单");
|
||||
|
||||
@EnumValue
|
||||
private final Integer code;
|
||||
|
||||
private final String desc;
|
||||
|
||||
OrderChartBizType(Integer code, String desc) {
|
||||
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
|
||||
return this.desc;
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package com.yueqian.xingyun.chart.impl;
|
||||
|
||||
import com.lframework.starter.common.constants.StringPool;
|
||||
import com.lframework.starter.common.utils.DateUtil;
|
||||
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
||||
import com.lframework.starter.web.core.utils.EnumUtil;
|
||||
import com.lframework.starter.web.core.utils.IdUtil;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSumDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartTodayDto;
|
||||
import com.yueqian.xingyun.chart.entity.OrderChart;
|
||||
import com.yueqian.xingyun.chart.enums.OrderChartBizType;
|
||||
import com.yueqian.xingyun.chart.mappers.OrderChartMapper;
|
||||
import com.yueqian.xingyun.chart.service.OrderChartService;
|
||||
import com.yueqian.xingyun.chart.vo.CreateOrderChartVo;
|
||||
import com.yueqian.xingyun.chart.vo.GetOrderChartVo;
|
||||
import com.yueqian.xingyun.chart.vo.QueryOrderChartVo;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class OrderChartServiceImpl extends BaseMpServiceImpl<OrderChartMapper, OrderChart>
|
||||
implements OrderChartService {
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String create(CreateOrderChartVo vo) {
|
||||
|
||||
if (vo.getCreateTime() == null) {
|
||||
vo.setCreateTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
OrderChart record = new OrderChart();
|
||||
record.setId(IdUtil.getId());
|
||||
record.setTotalAmount(vo.getTotalAmount());
|
||||
record.setCreateTime(vo.getCreateTime());
|
||||
record.setBizType(EnumUtil.getByCode(OrderChartBizType.class, vo.getBizType()));
|
||||
record.setCreateDate(DateUtil.formatDate(vo.getCreateTime().toLocalDate()));
|
||||
record.setCreateHour(DateUtil.format(vo.getCreateTime(), StringPool.DATE_TIME_HOUR_PATTER));
|
||||
|
||||
getBaseMapper().insert(record);
|
||||
|
||||
return record.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderChartSumDto getTodayChartSum(GetOrderChartVo vo) {
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
OrderChartSumDto data = getBaseMapper().getChartSum(vo.getBizTypes(),
|
||||
DateUtil.toLocalDateTime(now),
|
||||
DateUtil.toLocalDateTimeMax(now));
|
||||
if (data == null) {
|
||||
data = new OrderChartSumDto();
|
||||
data.setTotalAmount(BigDecimal.ZERO);
|
||||
data.setTotalNum(0L);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderChartSumDto getSameMonthChartSum(GetOrderChartVo vo) {
|
||||
|
||||
LocalDate startDate = LocalDate.now().withDayOfMonth(1);
|
||||
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
||||
|
||||
OrderChartSumDto data = getBaseMapper().getChartSum(vo.getBizTypes(),
|
||||
DateUtil.toLocalDateTime(startDate),
|
||||
DateUtil.toLocalDateTimeMax(endDate));
|
||||
if (data == null) {
|
||||
data = new OrderChartSumDto();
|
||||
data.setTotalAmount(BigDecimal.ZERO);
|
||||
data.setTotalNum(0L);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderChartTodayDto> queryTodayChart(QueryOrderChartVo vo) {
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
List<OrderChartTodayDto> results = getBaseMapper().queryToday(vo.getBizTypes(),
|
||||
DateUtil.toLocalDateTime(now),
|
||||
DateUtil.toLocalDateTimeMax(now));
|
||||
|
||||
int offset = 24;
|
||||
List<OrderChartTodayDto> newResults = new ArrayList<>(offset);
|
||||
|
||||
for (int i = 0; i < offset; i++) {
|
||||
LocalTime localTime = LocalTime.of(i, 0, 0);
|
||||
String filterDateStr = DateUtil.formatDateTime(LocalDateTime.of(now, localTime),
|
||||
StringPool.DATE_TIME_HOUR_PATTER);
|
||||
OrderChartTodayDto result = results.stream()
|
||||
.filter(t -> t.getCreateHour().equals(filterDateStr))
|
||||
.findFirst().orElse(null);
|
||||
if (result == null) {
|
||||
result = new OrderChartTodayDto();
|
||||
result.setCreateHour(filterDateStr);
|
||||
result.setTotalAmount(BigDecimal.ZERO);
|
||||
result.setTotalNum(0);
|
||||
}
|
||||
|
||||
newResults.add(result);
|
||||
}
|
||||
|
||||
return newResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderChartSameMonthDto> querySameMonthChart(QueryOrderChartVo vo) {
|
||||
|
||||
LocalDate startDate = LocalDate.now().withDayOfMonth(1);
|
||||
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
||||
|
||||
List<OrderChartSameMonthDto> results = getBaseMapper().querySameMonth(vo.getBizTypes(),
|
||||
DateUtil.toLocalDateTime(startDate), DateUtil.toLocalDateTimeMax(endDate));
|
||||
|
||||
LocalDate lastDate = startDate.plusMonths(1).minusDays(1);
|
||||
int offset = lastDate.getDayOfMonth() - startDate.getDayOfMonth() + 1;
|
||||
List<OrderChartSameMonthDto> newResults = new ArrayList<>(offset);
|
||||
|
||||
for (int i = 0; i < offset; i++) {
|
||||
String filterDateStr = DateUtil.formatDate(startDate.plusDays(i));
|
||||
OrderChartSameMonthDto result = results.stream()
|
||||
.filter(t -> t.getCreateDate().equals(filterDateStr))
|
||||
.findFirst().orElse(null);
|
||||
if (result == null) {
|
||||
result = new OrderChartSameMonthDto();
|
||||
result.setCreateDate(filterDateStr);
|
||||
result.setTotalAmount(BigDecimal.ZERO);
|
||||
result.setTotalNum(0);
|
||||
}
|
||||
|
||||
newResults.add(result);
|
||||
}
|
||||
|
||||
return newResults;
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.yueqian.xingyun.chart.listeners.mq;
|
||||
|
||||
import com.yueqian.xingyun.chart.enums.OrderChartBizType;
|
||||
import com.yueqian.xingyun.chart.service.OrderChartService;
|
||||
import com.yueqian.xingyun.chart.vo.CreateOrderChartVo;
|
||||
import com.lframework.starter.web.inner.dto.order.ApprovePassOrderDto;
|
||||
import com.yueqian.xingyun.core.queue.MqStringPool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OrderDataToChartListener {
|
||||
|
||||
@Autowired
|
||||
private OrderChartService orderChartService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RabbitListener(bindings = {
|
||||
@QueueBinding(value = @Queue(value = "chart.approve_pass_order"), exchange = @Exchange(value = MqStringPool.APPROVE_PASS_ORDER_EXCHANGE, type = ExchangeTypes.FANOUT))})
|
||||
public void execute(Message<ApprovePassOrderDto> message) {
|
||||
ApprovePassOrderDto event = message.getPayload();
|
||||
OrderChartBizType bizType = this.convertBizType(event.getOrderType());
|
||||
if (event.getOrderType() == null) {
|
||||
log.error("orderType={},无法匹配业务类型", event.getOrderType());
|
||||
return;
|
||||
}
|
||||
|
||||
CreateOrderChartVo vo = new CreateOrderChartVo();
|
||||
vo.setTotalAmount(event.getTotalAmount());
|
||||
vo.setCreateTime(event.getApproveTime());
|
||||
vo.setBizType(bizType.getCode());
|
||||
|
||||
orderChartService.create(vo);
|
||||
}
|
||||
|
||||
private OrderChartBizType convertBizType(ApprovePassOrderDto.OrderType orderType) {
|
||||
|
||||
if (orderType == ApprovePassOrderDto.OrderType.PURCHASE_ORDER) {
|
||||
return OrderChartBizType.PURCHASE_ORDER;
|
||||
}
|
||||
if (orderType == ApprovePassOrderDto.OrderType.PURCHASE_RETURN) {
|
||||
return OrderChartBizType.PURCHASE_RETURN;
|
||||
}
|
||||
if (orderType == ApprovePassOrderDto.OrderType.SALE_ORDER) {
|
||||
return OrderChartBizType.SALE_ORDER;
|
||||
}
|
||||
if (orderType == ApprovePassOrderDto.OrderType.SALE_RETURN) {
|
||||
return OrderChartBizType.SALE_RETURN;
|
||||
}
|
||||
if (orderType == ApprovePassOrderDto.OrderType.RETAIL_OUT_SHEET) {
|
||||
return OrderChartBizType.RETAIL_OUT_SHEET;
|
||||
}
|
||||
if (orderType == ApprovePassOrderDto.OrderType.RETAIL_RETURN) {
|
||||
return OrderChartBizType.RETAIL_RETURN;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.yueqian.xingyun.chart.mappers;
|
||||
|
||||
import com.lframework.starter.web.core.mapper.BaseMapper;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSumDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartTodayDto;
|
||||
import com.yueqian.xingyun.chart.entity.OrderChart;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author zmj
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
public interface OrderChartMapper extends BaseMapper<OrderChart> {
|
||||
|
||||
/**
|
||||
* 汇总数据
|
||||
*
|
||||
* @param bizTypes
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
OrderChartSumDto getChartSum(@Param("bizTypes") List<Integer> bizTypes,
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
* @param bizTypes
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
List<OrderChartSameMonthDto> querySameMonth(@Param("bizTypes") List<Integer> bizTypes,
|
||||
@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询当日数据列表
|
||||
*
|
||||
* @param bizTypes
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
List<OrderChartTodayDto> queryToday(@Param("bizTypes") List<Integer> bizTypes,
|
||||
@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.yueqian.xingyun.chart.service;
|
||||
|
||||
import com.lframework.starter.web.core.service.BaseMpService;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartSumDto;
|
||||
import com.yueqian.xingyun.chart.dto.OrderChartTodayDto;
|
||||
import com.yueqian.xingyun.chart.entity.OrderChart;
|
||||
import com.yueqian.xingyun.chart.vo.CreateOrderChartVo;
|
||||
import com.yueqian.xingyun.chart.vo.GetOrderChartVo;
|
||||
import com.yueqian.xingyun.chart.vo.QueryOrderChartVo;
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderChartService extends BaseMpService<OrderChart> {
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
String create(CreateOrderChartVo vo);
|
||||
|
||||
/**
|
||||
* 查询当日汇总数据
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
OrderChartSumDto getTodayChartSum(GetOrderChartVo vo);
|
||||
|
||||
/**
|
||||
* 查询当月汇总数据
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
OrderChartSumDto getSameMonthChartSum(GetOrderChartVo vo);
|
||||
|
||||
/**
|
||||
* 查询当日数据
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
List<OrderChartTodayDto> queryTodayChart(QueryOrderChartVo vo);
|
||||
|
||||
/**
|
||||
* 查询当月数据
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
List<OrderChartSameMonthDto> querySameMonthChart(QueryOrderChartVo vo);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.yueqian.xingyun.chart.vo;
|
||||
|
||||
import com.lframework.starter.web.core.components.validation.IsEnum;
|
||||
import com.lframework.starter.web.core.vo.BaseVo;
|
||||
import com.yueqian.xingyun.chart.enums.OrderChartBizType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateOrderChartVo implements BaseVo, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 单据总金额
|
||||
*/
|
||||
@Schema(description = "单据总金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "单据总金额不能为空!")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "业务类型不能为空!")
|
||||
@IsEnum(message = "业务类型不存在!", enumClass = OrderChartBizType.class)
|
||||
private Integer bizType;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yueqian.xingyun.chart.vo;
|
||||
|
||||
import com.lframework.starter.web.core.vo.BaseVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GetOrderChartVo implements BaseVo, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "业务类型不能为空!")
|
||||
private List<Integer> bizTypes;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yueqian.xingyun.chart.vo;
|
||||
|
||||
import com.lframework.starter.web.core.vo.BaseVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QueryOrderChartVo implements BaseVo, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "业务类型不能为空!")
|
||||
private List<Integer> bizTypes;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
config.stopBubbling=true
|
||||
lombok.equalsAndHashCode.callSuper=call
|
||||
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yueqian.xingyun.chart.mappers.OrderChartMapper">
|
||||
|
||||
<resultMap id="OrderChartSumDto" type="com.yueqian.xingyun.chart.dto.OrderChartSumDto">
|
||||
<result column="total_amount" property="totalAmount"/>
|
||||
<result column="total_num" property="totalNum"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="OrderChartSameMonthDto" type="com.yueqian.xingyun.chart.dto.OrderChartSameMonthDto">
|
||||
<result column="total_amount" property="totalAmount"/>
|
||||
<result column="total_num" property="totalNum"/>
|
||||
<result column="create_date" property="createDate"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="OrderChartTodayDto" type="com.yueqian.xingyun.chart.dto.OrderChartTodayDto">
|
||||
<result column="total_amount" property="totalAmount"/>
|
||||
<result column="total_num" property="totalNum"/>
|
||||
<result column="create_hour" property="createHour"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="querySameMonth" resultMap="OrderChartSameMonthDto">
|
||||
SELECT
|
||||
IFNULL(SUM(c.total_amount), 0) AS total_amount,
|
||||
COUNT(1) AS total_num,
|
||||
c.create_date
|
||||
FROM tbl_order_chart AS c
|
||||
<where>
|
||||
<if test="startTime != null">
|
||||
AND c.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
<![CDATA[
|
||||
AND c.create_time <= #{endTime}
|
||||
]]>
|
||||
</if>
|
||||
<if test="bizTypes != null and bizTypes.size() > 0">
|
||||
AND c.biz_type IN <foreach collection="bizTypes" open="(" separator="," close=")" item="item">#{item}</foreach>
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY c.create_date
|
||||
</select>
|
||||
<select id="queryToday" resultMap="OrderChartTodayDto">
|
||||
SELECT
|
||||
IFNULL(SUM(c.total_amount), 0) AS total_amount,
|
||||
COUNT(1) AS total_num,
|
||||
c.create_hour
|
||||
FROM tbl_order_chart AS c
|
||||
<where>
|
||||
<if test="startTime != null">
|
||||
AND c.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
<![CDATA[
|
||||
AND c.create_time <= #{endTime}
|
||||
]]>
|
||||
</if>
|
||||
<if test="bizTypes != null and bizTypes.size() > 0">
|
||||
AND c.biz_type IN <foreach collection="bizTypes" open="(" separator="," close=")" item="item">#{item}</foreach>
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY c.create_hour
|
||||
</select>
|
||||
<select id="getChartSum" resultMap="OrderChartSumDto">
|
||||
SELECT
|
||||
IFNULL(SUM(c.total_amount), 0) AS total_amount,
|
||||
COUNT(1) AS total_num
|
||||
FROM tbl_order_chart AS c
|
||||
<where>
|
||||
<if test="startTime != null">
|
||||
AND c.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
<![CDATA[
|
||||
AND c.create_time <= #{endTime}
|
||||
]]>
|
||||
</if>
|
||||
<if test="bizTypes != null and bizTypes.size() > 0">
|
||||
AND c.biz_type IN <foreach collection="bizTypes" open="(" separator="," close=")" item="item">#{item}</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user