feat(sales): 为销售报表添加订单明细查询功能
- 在 CrmOrderItemMapper 中添加根据订单ID列表查询订单明细的方法 - 实现 MyBatis 查询语句支持批量订单ID查询订单明细 - 修改销售报表服务类注入 CrmOrderItemMapper 依赖 - 扩展销售报表查询逻辑以包含订单明细数据 - 在销售报表 VO 中添加订单明细列表字段 - 使用流式处理和分组收集优化订单明细关联逻辑
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.klp.crm.domain.CrmOrderItem;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -190,6 +191,11 @@ public class CrmSalesReportVo {
|
||||
*/
|
||||
@ExcelProperty(value = "异议数量")
|
||||
private Integer objectionCount;
|
||||
|
||||
/**
|
||||
* 订单明细列表
|
||||
*/
|
||||
private List<CrmOrderItem> orderItemList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.klp.crm.mapper;
|
||||
import com.klp.crm.domain.CrmOrderItem;
|
||||
import com.klp.crm.domain.vo.CrmOrderItemVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 正式订单明细Mapper接口
|
||||
@@ -12,4 +15,11 @@ import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
*/
|
||||
public interface CrmOrderItemMapper extends BaseMapperPlus<CrmOrderItemMapper, CrmOrderItem, CrmOrderItemVo> {
|
||||
|
||||
/**
|
||||
* 根据订单ID查询订单明细列表
|
||||
*
|
||||
* @param orderIds 订单ID列表
|
||||
* @return 订单明细列表
|
||||
*/
|
||||
List<CrmOrderItem> selectOrderItemsByOrderIds(@Param("orderIds") List<String> orderIds);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.klp.crm.service.impl;
|
||||
|
||||
import com.klp.crm.domain.CrmOrderItem;
|
||||
import com.klp.crm.mapper.CrmOrderItemMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
@@ -12,7 +14,10 @@ import com.klp.crm.service.ICrmSalesReportService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 销售报表Service业务层处理
|
||||
@@ -26,6 +31,8 @@ public class CrmSalesReportServiceImpl implements ICrmSalesReportService {
|
||||
|
||||
private final CrmSalesReportMapper baseMapper;
|
||||
|
||||
private final CrmOrderItemMapper crmOrderItemMapper;
|
||||
|
||||
/**
|
||||
* 查询销售报表汇总数据
|
||||
*/
|
||||
@@ -58,7 +65,36 @@ public class CrmSalesReportServiceImpl implements ICrmSalesReportService {
|
||||
*/
|
||||
@Override
|
||||
public List<CrmSalesReportVo.OrderDetail> queryOrderDetailList(CrmSalesReportBo bo) {
|
||||
return baseMapper.selectOrderDetailList(bo);
|
||||
List<CrmSalesReportVo.OrderDetail> orderDetails = baseMapper.selectOrderDetailList(bo);
|
||||
if (StringUtils.isNotNull(orderDetails) && !orderDetails.isEmpty()) {
|
||||
// 提取所有订单ID
|
||||
List<String> orderIds = orderDetails.stream()
|
||||
.map(CrmSalesReportVo.OrderDetail::getOrderId)
|
||||
.filter(StringUtils::isNotNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 根据订单ID列表查询对应的明细
|
||||
if (!orderIds.isEmpty()) {
|
||||
List<CrmOrderItem> orderItems = crmOrderItemMapper.selectOrderItemsByOrderIds(orderIds);
|
||||
|
||||
// 将明细按订单ID分组
|
||||
Map<String, List<CrmOrderItem>> orderItemMap = orderItems.stream()
|
||||
.collect(Collectors.groupingBy(CrmOrderItem::getOrderId));
|
||||
|
||||
// 为每个订单设置对应的明细列表
|
||||
for (CrmSalesReportVo.OrderDetail orderDetail : orderDetails) {
|
||||
List<CrmOrderItem> items = orderItemMap.get(orderDetail.getOrderId());
|
||||
orderDetail.setOrderItemList(items != null ? items : new ArrayList<>());
|
||||
}
|
||||
} else {
|
||||
// 如果没有有效的订单ID,初始化明细列表为空
|
||||
for (CrmSalesReportVo.OrderDetail orderDetail : orderDetails) {
|
||||
orderDetail.setOrderItemList(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
return orderDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
</resultMap>
|
||||
<!-- 根据订单ID列表查询订单明细 -->
|
||||
<select id="selectOrderItemsByOrderIds" resultMap="CrmOrderItemResult">
|
||||
SELECT
|
||||
item_id,
|
||||
order_id,
|
||||
product_type,
|
||||
spec_require,
|
||||
product_num,
|
||||
special_require,
|
||||
item_amount,
|
||||
remark,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
del_flag
|
||||
FROM crm_order_item
|
||||
WHERE del_flag = 0
|
||||
AND order_id IN
|
||||
<foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
ORDER BY item_id ASC
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user