mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
分析页统计:生产单状态、生产单/排单单量、生产单/排单平方数统计接口实现和完善
This commit is contained in:
+12
@@ -64,4 +64,16 @@ public class OrderStatisticsController {
|
||||
public CommonResult<Map<String, Object>> getOrderStatusCount(@Valid OrderStatisticsReqVO reqVO) {
|
||||
return success(orderStatisticsService.getOrderStatusCount(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/orderAndPlanCount/group")
|
||||
@Operation(summary = "生产单、排单单量分组统计")
|
||||
public CommonResult<Map<String, Object>> getOrderAndPlanCountGroup(@Valid OrderStatisticsReqVO reqVO) {
|
||||
return success(orderStatisticsService.getOrderAndPlanCountGroup(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/orderAndPlanArea/group")
|
||||
@Operation(summary = "生产单、排单平方数分组统计")
|
||||
public CommonResult<Map<String, Object>> getOrderAndPlanAreaGroup(@Valid OrderStatisticsReqVO reqVO) {
|
||||
return success(orderStatisticsService.getOrderAndPlanAreaSumGroup(reqVO));
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.cf.imes.module.executor.controller.admin.order.vo.order;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 生产单平方数统计")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class OrderStatisticsAreaRespVO implements Comparable<OrderStatisticsAreaRespVO> {
|
||||
@Schema(description = "订单平方数")
|
||||
private BigDecimal areaSum;
|
||||
|
||||
@Schema(description = "生产单时间")
|
||||
private String date;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull OrderStatisticsAreaRespVO other) {
|
||||
// 解析 orderDate 字符串为年、月、周
|
||||
String[] partsThis = date.split("-");
|
||||
String[] partsOther = other.date.split("-");
|
||||
|
||||
// 比较年份
|
||||
int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
|
||||
if (yearComparison != 0) {
|
||||
return yearComparison;
|
||||
}
|
||||
|
||||
// 比较月份
|
||||
if (partsThis.length > 1 && partsOther.length > 1) {
|
||||
int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1]));
|
||||
if (monthComparison != 0) {
|
||||
return monthComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 比较周数
|
||||
if (partsThis.length > 2 && partsOther.length > 2) {
|
||||
int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2]));
|
||||
if (weekComparison != 0) {
|
||||
return weekComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有部分都相同,则按状态排序
|
||||
return this.areaSum.compareTo(other.areaSum);
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -10,21 +10,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class OrderStatusRespVO implements Comparable<OrderStatusRespVO> {
|
||||
public class OrderStatisticsStatusRespVO implements Comparable<OrderStatisticsStatusRespVO> {
|
||||
@Schema(description = "订单状态")
|
||||
private Integer orderState;
|
||||
private Integer orderStatus;
|
||||
|
||||
@Schema(description = "订单数量")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "生产单时间")
|
||||
private String orderDate;
|
||||
private String date;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull OrderStatusRespVO other) {
|
||||
public int compareTo(@NotNull OrderStatisticsStatusRespVO other) {
|
||||
// 解析 orderDate 字符串为年、月、周
|
||||
String[] partsThis = orderDate.split("-");
|
||||
String[] partsOther = other.orderDate.split("-");
|
||||
String[] partsThis = date.split("-");
|
||||
String[] partsOther = other.date.split("-");
|
||||
|
||||
// 比较年份
|
||||
int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
|
||||
@@ -49,6 +49,6 @@ public class OrderStatusRespVO implements Comparable<OrderStatusRespVO> {
|
||||
}
|
||||
|
||||
// 如果所有部分都相同,则按状态排序
|
||||
return this.orderState.compareTo(other.orderState);
|
||||
return this.orderStatus.compareTo(other.orderStatus);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2024/8/7 15:12
|
||||
*/
|
||||
|
||||
@Schema(description = "管理后台 - 排单统计RespVO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class OrderPlanStatisticsAreaRespVO implements Comparable<OrderPlanStatisticsAreaRespVO> {
|
||||
@Schema(description = "统计时间")
|
||||
private String date;
|
||||
|
||||
@Schema(description = "面积总和")
|
||||
private BigDecimal areaSum;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull OrderPlanStatisticsAreaRespVO other) {
|
||||
// 解析 date 字符串为年、月、周
|
||||
String[] partsThis = date.split("-");
|
||||
String[] partsOther = other.date.split("-");
|
||||
|
||||
// 比较年份
|
||||
int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
|
||||
if (yearComparison != 0) {
|
||||
return yearComparison;
|
||||
}
|
||||
|
||||
// 比较月份
|
||||
if (partsThis.length > 1 && partsOther.length > 1) {
|
||||
int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1]));
|
||||
if (monthComparison != 0) {
|
||||
return monthComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 比较周数
|
||||
if (partsThis.length > 2 && partsOther.length > 2) {
|
||||
int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2]));
|
||||
if (weekComparison != 0) {
|
||||
return weekComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有部分都相同,则按面积排序
|
||||
return this.areaSum.compareTo(other.areaSum);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2024/8/7 15:12
|
||||
*/
|
||||
|
||||
@Schema(description = "管理后台 - 排单统计RespVO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class OrderPlanStatisticsCountRespVO implements Comparable<OrderPlanStatisticsCountRespVO> {
|
||||
|
||||
@Schema(description = "数量")
|
||||
private Integer count;
|
||||
|
||||
@Schema(description = "统计时间")
|
||||
private String date;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull OrderPlanStatisticsCountRespVO other) {
|
||||
// 解析 date 字符串为年、月、周
|
||||
String[] partsThis = date.split("-");
|
||||
String[] partsOther = other.date.split("-");
|
||||
|
||||
// 比较年份
|
||||
int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
|
||||
if (yearComparison != 0) {
|
||||
return yearComparison;
|
||||
}
|
||||
|
||||
// 比较月份
|
||||
if (partsThis.length > 1 && partsOther.length > 1) {
|
||||
int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1]));
|
||||
if (monthComparison != 0) {
|
||||
return monthComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 比较周数
|
||||
if (partsThis.length > 2 && partsOther.length > 2) {
|
||||
int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2]));
|
||||
if (weekComparison != 0) {
|
||||
return weekComparison;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有部分都相同,则按面积排序
|
||||
return this.count.compareTo(other.count);
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -2,8 +2,9 @@ package com.cf.imes.module.executor.dal.mysql.order;
|
||||
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatusRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -70,10 +71,26 @@ public interface OrderStatisticsMapper extends BaseMapperX<OrderDO> {
|
||||
Integer selectOrderSquareProduce(@Param("organId") Long organId);
|
||||
|
||||
/**
|
||||
* 生产单状态按时间分组统计
|
||||
* 生产单状态按时间分组统计数量
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
List<OrderStatusRespVO> selectOrderStatusCount(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
List<OrderStatisticsStatusRespVO> selectOrderStatusCountGroupBy(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 生产单按时间分组统计数量
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
List<OrderStatisticsStatusRespVO> selectOrderCountGroupByOrderDate(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 生产单按时间分组统计面积
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
List<OrderStatisticsAreaRespVO> selectOrderAreaGroupByOrderDate(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
}
|
||||
|
||||
+17
-8
@@ -2,15 +2,16 @@ package com.cf.imes.module.executor.dal.mysql.plan;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plan.PlanDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.planitem.PlanItemDO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -26,7 +27,7 @@ import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.ge
|
||||
public interface PlanMapper extends BaseMapperX<PlanDO> {
|
||||
|
||||
default PageResult<PlanDO> selectPage(PlanPageReqVO reqVO) {
|
||||
if(StrUtil.isNotBlank(reqVO.getCustomer())) {
|
||||
if(StringUtils.isNotBlank(reqVO.getCustomer())) {
|
||||
return selectJoinPage(reqVO, PlanDO.class, new MPJLambdaWrapperX<PlanDO>()
|
||||
.eq(PlanDO::getDeleted,false)
|
||||
.eq(PlanDO::getOrganId,getUserOrganId())
|
||||
@@ -85,10 +86,18 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
|
||||
.eq(PlanDO::getMachineId,machineId));
|
||||
}
|
||||
|
||||
//
|
||||
// default PlanDO selectByOrderId(Long orderId) {
|
||||
// return selectOne(new MPJLambdaWrapperX<PlanDO>()
|
||||
// .like(PlanDO::getOrderNos, orderId));
|
||||
//
|
||||
// }
|
||||
/**
|
||||
* 排单按时间分组统计数量
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
List<OrderPlanStatisticsCountRespVO> selectPlanCountGroupByCreateTime(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 排单按时间分组统计面积
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
List<OrderPlanStatisticsAreaRespVO> selectPlanAreaGroupByCreateTime(@Param("req") OrderStatisticsReqVO reqVO);
|
||||
}
|
||||
+18
-1
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 生产单统计 order_{N} Service 接口
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/8/5 16:57
|
||||
*/
|
||||
@@ -36,7 +37,23 @@ public interface OrderStatisticsService {
|
||||
Integer orderSquareProduce(OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 生产单状态统计
|
||||
* 生产单状态分组统计
|
||||
*/
|
||||
Map<String, Object> getOrderStatusCount(OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 生产单、排单单量分组统计
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 生产单、排单平方数统计
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO);
|
||||
}
|
||||
|
||||
+166
-14
@@ -4,15 +4,23 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.OrderStatusEnum;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatusRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsAreaRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO;
|
||||
import com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
|
||||
import com.cf.imes.module.executor.enums.OrderStatisticsUnit;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -21,7 +29,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -34,6 +41,9 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
@Resource
|
||||
private OrderStatisticsMapper orderStatisticsMapper;
|
||||
|
||||
@Resource
|
||||
private PlanMapper planMapper;
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public Integer orderCount(OrderStatisticsReqVO reqVO) {
|
||||
@@ -69,37 +79,44 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
public Map<String, Object> getOrderStatusCount(OrderStatisticsReqVO reqVO) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
// 获取机构id
|
||||
reqVO.setOrganId(getOrganIdParam(reqVO));
|
||||
|
||||
// 计算时间跨度
|
||||
getTimeSpan(reqVO);
|
||||
|
||||
// 查询订单状态统计数据
|
||||
List<OrderStatusRespVO> orderStatusRespVOS = orderStatisticsMapper.selectOrderStatusCount(reqVO);
|
||||
List<OrderStatisticsStatusRespVO> orderStatusRespVOS = orderStatisticsMapper.selectOrderStatusCountGroupBy(reqVO);
|
||||
|
||||
// 基于相同的orderDate分组
|
||||
Map<String, List<OrderStatusRespVO>> orderDateMap = orderStatusRespVOS.stream()
|
||||
Map<String, List<OrderStatisticsStatusRespVO>> orderDateMap = orderStatusRespVOS.stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrderStatusRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList()));
|
||||
.collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
// 所有的日期集合
|
||||
Set<String> dateList = orderDateMap.keySet();
|
||||
List<String> dateList = generateDateRange(reqVO);
|
||||
resultMap.put("dateList", dateList);
|
||||
|
||||
// 遍历订单状态所有枚举值
|
||||
List<Map<String, Object>> series = new ArrayList<>();
|
||||
for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
|
||||
Map<String, Object> seriesItem = new HashMap<>();
|
||||
int[] sumArr = new int[orderDateMap.size()];
|
||||
int[] sumArr = new int[dateList.size()];
|
||||
|
||||
// 遍历日期map记录status下的orderCount到sumArr数组
|
||||
// 遍历完整的日期范围
|
||||
int index = 0;
|
||||
for (Map.Entry<String, List<OrderStatusRespVO>> entry : orderDateMap.entrySet()) {
|
||||
for (String dateStr : dateList) {
|
||||
// 查找匹配的订单状态
|
||||
Optional<OrderStatusRespVO> matchingStatus = entry.getValue().stream()
|
||||
.filter(respVO -> Objects.equals(orderStatusEnum.getStatus(), respVO.getOrderState()))
|
||||
.findFirst();
|
||||
List<OrderStatisticsStatusRespVO> listForDate = orderDateMap.get(dateStr);
|
||||
int count = 0;
|
||||
if (listForDate != null) {
|
||||
count = listForDate.stream()
|
||||
.filter(respVO -> Objects.equals(orderStatusEnum.getStatus(), respVO.getOrderStatus()))
|
||||
.mapToInt(OrderStatisticsStatusRespVO::getOrderCount)
|
||||
.sum();
|
||||
}
|
||||
|
||||
// 没有匹配的补齐0
|
||||
sumArr[index++] = matchingStatus.map(OrderStatusRespVO::getOrderCount).orElse(0);
|
||||
sumArr[index++] = count;
|
||||
}
|
||||
|
||||
seriesItem.put("data", sumArr);
|
||||
@@ -112,6 +129,90 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public Map<String, Object> getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
|
||||
// 获取机构id
|
||||
reqVO.setOrganId(getOrganIdParam(reqVO));
|
||||
|
||||
// 计算时间跨度
|
||||
getTimeSpan(reqVO);
|
||||
|
||||
// 所有的日期集合
|
||||
List<String> dateList = generateDateRange(reqVO);
|
||||
|
||||
Map<String, List<OrderStatisticsStatusRespVO>> orderRespMap = orderStatisticsMapper.selectOrderCountGroupByOrderDate(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
Map<String, List<OrderPlanStatisticsCountRespVO>> planRespMap = planMapper.selectPlanCountGroupByCreateTime(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrderPlanStatisticsCountRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
// 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组
|
||||
for (int i = 0; i < dateList.size(); i++) {
|
||||
String dateStr = dateList.get(i);
|
||||
int[] countArr = new int[2];
|
||||
// 存入生产单数量
|
||||
Integer orderCount = Optional.ofNullable(orderRespMap.get(dateStr))
|
||||
.map(list -> list.stream().findFirst().orElse(new OrderStatisticsStatusRespVO()))
|
||||
.map(OrderStatisticsStatusRespVO::getOrderCount)
|
||||
.orElse(0);
|
||||
countArr[0] = orderCount;
|
||||
|
||||
// 存入排单数量
|
||||
Integer planCount = Optional.ofNullable(planRespMap.get(dateStr))
|
||||
.map(list -> list.stream().findFirst().orElse(new OrderPlanStatisticsCountRespVO()))
|
||||
.map(OrderPlanStatisticsCountRespVO::getCount)
|
||||
.orElse(0);
|
||||
countArr[1] = planCount;
|
||||
|
||||
resultMap.put(dateStr, countArr);
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public Map<String, Object> getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
|
||||
// 获取机构id
|
||||
reqVO.setOrganId(getOrganIdParam(reqVO));
|
||||
|
||||
// 计算时间跨度
|
||||
getTimeSpan(reqVO);
|
||||
|
||||
// 所有的日期集合
|
||||
List<String> dateList = generateDateRange(reqVO);
|
||||
|
||||
Map<String, List<OrderStatisticsAreaRespVO>> orderRespMap = orderStatisticsMapper.selectOrderAreaGroupByOrderDate(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrderStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
Map<String, List<OrderPlanStatisticsAreaRespVO>> planRespMap = planMapper.selectPlanAreaGroupByCreateTime(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrderPlanStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
// 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组
|
||||
for (String dateStr : dateList) {
|
||||
BigDecimal[] areaArr = new BigDecimal[2];
|
||||
|
||||
// 存生产单面积
|
||||
List<OrderStatisticsAreaRespVO> orderCountRespVOS = orderRespMap.get(dateStr);
|
||||
areaArr[0] = orderCountRespVOS != null && !orderCountRespVOS.isEmpty() ? orderCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO;
|
||||
|
||||
// 存排单面积
|
||||
List<OrderPlanStatisticsAreaRespVO> planCountRespVOS = planRespMap.get(dateStr);
|
||||
areaArr[1] = planCountRespVOS != null && !planCountRespVOS.isEmpty() ? planCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO;
|
||||
|
||||
resultMap.put(dateStr, areaArr);
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统计的时间跨度
|
||||
* 计算起止时间:前端不传入时间就根据维度单位从当前日期计算
|
||||
@@ -150,6 +251,57 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日期范围内的所有格式字符串
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
private List<String> generateDateRange(OrderStatisticsReqVO reqVO) {
|
||||
Integer unit = reqVO.getUnit();
|
||||
// 计算时间跨度
|
||||
getTimeSpan(reqVO);
|
||||
// 计算后的开始和结束时间
|
||||
LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]);
|
||||
LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]);
|
||||
|
||||
List<String> dates = new ArrayList<>();
|
||||
while (!startDate.isAfter(endDate)) {
|
||||
String dateStr;
|
||||
switch (OrderStatisticsUnit.fromValue(unit)) {
|
||||
case QUARTER:
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-Q"));
|
||||
// 加一季度(3个月)
|
||||
startDate = startDate.plusMonths(3);
|
||||
break;
|
||||
case MONTH:
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M"));
|
||||
// 加一月
|
||||
startDate = startDate.plusMonths(1);
|
||||
break;
|
||||
case WEEK:
|
||||
// 使用自定义格式表示月份
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M"));
|
||||
// 计算从月份第一天到当前日期经过了多少周
|
||||
LocalDate monthStart = startDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
long weeksInMonth = ChronoUnit.WEEKS.between(monthStart, startDate) + 1;
|
||||
dateStr = dateStr + "-" + weeksInMonth;
|
||||
// 加一周
|
||||
startDate = startDate.plusWeeks(1);
|
||||
break;
|
||||
case DAY:
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M-d"));
|
||||
// 加一天
|
||||
startDate = startDate.plusDays(1);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported unit: " + unit);
|
||||
}
|
||||
dates.add(dateStr);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端传组织否则查当前用户所在的组织
|
||||
*
|
||||
|
||||
+54
-9
@@ -10,27 +10,72 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectOrderStatusCount"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatusRespVO">
|
||||
select o.status as orderState,
|
||||
<select id="selectOrderStatusCountGroupBy"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO">
|
||||
select o.status as orderStatus,
|
||||
count(o.id) as orderCount
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', QUARTER(o.order_date)) as orderDate
|
||||
,CONCAT(YEAR(o.order_date), '-', QUARTER(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date)) as orderDate
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', FLOOR((DayOfMonth(o.order_date)-1)/7)+1) AS
|
||||
orderDate
|
||||
date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', DAY(o.order_date)) as orderDate
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', DAY(o.order_date)) as date
|
||||
</if>
|
||||
from orders o
|
||||
where o.organ_id = #{organId}
|
||||
where o.organ_id = #{req.organId}
|
||||
and o.order_date between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and o.deleted = 0
|
||||
group by o.status, orderDate;
|
||||
group by orderStatus, date;
|
||||
</select>
|
||||
|
||||
<select id="selectOrderCountGroupByOrderDate"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO">
|
||||
select count(o.id) as orderCount
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', QUARTER(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', FLOOR((DayOfMonth(o.order_date)-1)/7)+1) AS date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', DAY(o.order_date)) as date
|
||||
</if>
|
||||
from orders o
|
||||
where o.organ_id = #{req.organId}
|
||||
and o.order_date between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and o.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
|
||||
<select id="selectOrderAreaGroupByOrderDate"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO">
|
||||
select sum(op.area) as areaSum
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', QUARTER(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', FLOOR((DayOfMonth(o.order_date)-1)/7)+1) AS date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', DAY(o.order_date)) as date
|
||||
</if>
|
||||
from orders o
|
||||
join order_plate op on op.order_id = o.id and op.organ_id = #{req.organId}
|
||||
where o.organ_id = #{req.organId}
|
||||
and o.order_date between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and o.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
</mapper>
|
||||
+48
@@ -123,4 +123,52 @@
|
||||
|
||||
<select id="selectPlanByOrderIds" resultType="com.cf.imes.module.executor.dal.dataobject.plan.PlanDO"></select>
|
||||
|
||||
<select id="selectPlanCountGroupByCreateTime"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO">
|
||||
select
|
||||
count(p.id) as count
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', QUARTER(p.create_time)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', FLOOR((DayOfMonth(p.create_time)-1)/7)+1) AS date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', DAY(p.create_time)) as date
|
||||
</if>
|
||||
from order_plan p
|
||||
where p.organ_id = #{req.organId}
|
||||
and p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and p.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
|
||||
<select id="selectPlanAreaGroupByCreateTime"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsAreaRespVO">
|
||||
select sum(op.area) areaSum
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', QUARTER(p.create_time)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', FLOOR((DayOfMonth(p.create_time)-1)/7)+1) AS
|
||||
date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.module.executor.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', DAY(p.create_time)) as date
|
||||
</if>
|
||||
from order_plan p
|
||||
join order_plan_item opi on p.id = opi.plan_id and opi.organ_id = #{req.organId}
|
||||
join order_item oi on oi.id = opi.item_id and oi.organ_id = #{req.organId}
|
||||
join order_plate op on oi.plate_id = op.id and op.organ_id = #{req.organId}
|
||||
where p.organ_id = #{req.organId}
|
||||
and p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and p.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user