mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
排单分页接口性能优化
This commit is contained in:
+6
@@ -2,6 +2,7 @@ package com.cf.imes.framework.mybatis.core.query;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.cf.imes.framework.common.util.collection.ArrayUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
@@ -100,6 +101,11 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
|
||||
return betweenIfPresent(column, val1, val2);
|
||||
}
|
||||
|
||||
public LambdaQueryWrapperX<T> selectX(SFunction<T, ?>... columns) {
|
||||
super.doSelect(true, CollectionUtils.toList(columns));
|
||||
return this;
|
||||
}
|
||||
|
||||
// ========== 重写父类方法,方便链式调用 ==========
|
||||
|
||||
@Override
|
||||
|
||||
-11
@@ -103,17 +103,6 @@ public class PlanController {
|
||||
return success(planService.getPlanSortPage());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("getPlanList")
|
||||
@Operation(summary = "查询排单(未分页)")
|
||||
@PreAuthorize("@ss.hasPermission('placeorder:query')")
|
||||
public CommonResult<List<PlanRespVO>> getPlanList() {
|
||||
|
||||
return success(planService.getPlanList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PutMapping("/setSort")
|
||||
@Operation(summary = "设置排单优先级")
|
||||
@PreAuthorize("@ss.hasPermission('placeorder:priority')")
|
||||
|
||||
-4
@@ -322,10 +322,6 @@ public interface OrderMapper extends BaseMapperX<OrderDO> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<PlanOrderRespVO> selectPlanOrderList(@Param("planIds") List<Long> planIds, @Param("organId") Long organId);
|
||||
|
||||
|
||||
IPage<OrderRespVOCopy> selectFilterOrderPagePlate(@Param("page") IPage<OrderRespVOCopy> page, @Param(Constants.WRAPPER) Wrapper<OrderDO> wrapper);
|
||||
|
||||
List<Long> selectFilterOrderPlateList(@Param(Constants.WRAPPER) QueryWrapperX<OrderDO> queryWrapperX);
|
||||
|
||||
+9
@@ -20,6 +20,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -192,4 +193,12 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
|
||||
* @return
|
||||
*/
|
||||
List<OrderGoodsPlateRespVO> selectTopTenBoardCountGroupByOptimizeTime(@Param("goodsCodes") List<String> goodsCodes, @Param("req") OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 批量删除排单
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
int physicalDeleteByIds(@Param("ids") Collection<Long> ids, @Param("organId") Long organId);
|
||||
}
|
||||
+10
-2
@@ -13,6 +13,7 @@ import com.cf.imes.module.executor.dal.dataobject.plate.PlateDetailDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -72,8 +73,15 @@ public interface PlanItemMapper extends BaseMapperX<PlanItemDO> {
|
||||
*/
|
||||
List<PlateDetailDO> selectPlanPlateDetailList(@Param("planId") Long planId, @Param("orderIds") List<Long> orderIds, @Param("organId") Long organId);
|
||||
|
||||
|
||||
List<PlateInfoVO> selectOrderPlanPlateList(@Param("planIds") List<Long> planIds, @Param("organId") Long organId);
|
||||
/**
|
||||
* 查询排单大板列表
|
||||
*
|
||||
* @param planIds 排单id列表
|
||||
* @param orderIds 订单id列表
|
||||
* @param organId 组织id
|
||||
* @return 排单小板列表
|
||||
*/
|
||||
List<PlateInfoVO> selectOrderPlanGoodsList(@Param("planIds") List<Long> planIds, @Param("orderIds") Collection<Long> orderIds, @Param("organId") Long organId);
|
||||
|
||||
List<PlateResList> selectPlateListByPlanId(@Param("planId") Long planId, @Param("organId") Long organId);
|
||||
|
||||
|
||||
+9
@@ -465,4 +465,13 @@ public interface PlateMapper extends BaseMapperX<PlateDO> {
|
||||
* @return
|
||||
*/
|
||||
int physicalDeleteByOrderIds(@Param("ids") List<Long> ids);
|
||||
|
||||
/**
|
||||
* 查询订单下板件的排单id列表
|
||||
*
|
||||
* @param orderIds
|
||||
* @param customer
|
||||
* @return
|
||||
*/
|
||||
List<Long> selectPlanIdsByOrderCondition(@Param("orderIds") List<Long> orderIds, @Param("customer") String customer, @Param("organId") Long organId);
|
||||
}
|
||||
-2
@@ -62,8 +62,6 @@ public interface PlanService {
|
||||
*/
|
||||
List<PlanRespVO> getPlanSortPage();
|
||||
|
||||
List<PlanRespVO> getPlanList();
|
||||
|
||||
/**
|
||||
* 未排订单分页查询
|
||||
*
|
||||
|
||||
+60
-69
@@ -81,7 +81,6 @@ import static com.cf.imes.framework.common.util.json.JsonUtils.parseArray;
|
||||
import static com.cf.imes.framework.redis.constants.RedisKeyConstants.ORDER_PLAN_OPTIMIZE_KEY;
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
|
||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
||||
|
||||
/**
|
||||
* 订单开料排单 Service 实现类
|
||||
@@ -290,7 +289,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
});
|
||||
|
||||
// 删除排单信息,更新排单对应的余料板的排单ID为0
|
||||
planMapper.deleteByIds(planIds);
|
||||
planMapper.physicalDeleteByIds(planIds, getUserOrganId());
|
||||
|
||||
remainPlateMapper.deletePlanRemainPlate(planIds, getUserOrganId());
|
||||
|
||||
@@ -384,6 +383,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
@Override
|
||||
public PageResult<PlanRespVO> getPlanPage(PlanPageReqVO pageReqVO) {
|
||||
Long organId = getUserOrganId();
|
||||
|
||||
PageDTO<PlanDO> page = new PageDTO<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
|
||||
|
||||
@@ -398,17 +398,40 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
QueryWrapperX<PlanDO> queryWrapperX = new QueryWrapperX<>();
|
||||
queryWrapperX
|
||||
.eq("op.organ_id",getUserOrganId())
|
||||
.eq("op.organ_id", organId)
|
||||
.eq(FIELD_OP_DELETED,false)
|
||||
.eqIfPresent("op.is_scheduled",pageReqVO.getIsScheduled())
|
||||
.eqIfPresent(FIELD_OP_ID, pageReqVO.getId())
|
||||
.eqIfPresent("op.sort", pageReqVO.getSort())
|
||||
.eqIfPresent("op.type", pageReqVO.getType())
|
||||
.inIfPresent("op.status", pageReqVO.getStatus())
|
||||
.betweenIfPresent("op.plan_time", pageReqVO.getPlanTime())
|
||||
.likeIfPresent("op.order_nos", pageReqVO.getOrderNos())
|
||||
.likeIfPresent(FIELD_CUSTOMER, pageReqVO.getCustomer());
|
||||
.betweenIfPresent("op.plan_time", pageReqVO.getPlanTime());
|
||||
|
||||
// 入参有订单号跟客户的时候,从订单表查,然后查订单下板件的排单号,然后做排单id去做分页
|
||||
if (StringUtils.isNotEmpty(pageReqVO.getOrderNos()) || StringUtils.isNotEmpty(pageReqVO.getCustomer())) {
|
||||
LambdaQueryWrapperX<OrderDO> orderQuery = new LambdaQueryWrapperX<OrderDO>()
|
||||
.eq(OrderDO::getOrganId, organId)
|
||||
.eq(OrderDO::getDeleted, false)
|
||||
.eqIfPresent(OrderDO::getId, pageReqVO.getOrderNos())
|
||||
.likeIfPresent(OrderDO::getCustomer, pageReqVO.getCustomer())
|
||||
.selectX(OrderDO::getId);
|
||||
|
||||
List<Long> orderIds = orderMapper.selectList(orderQuery)
|
||||
.stream().map(OrderDO::getId).toList();
|
||||
|
||||
if (CollUtil.isEmpty(orderIds)) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
List<Long> planIds = plateMapper.selectPlanIdsByOrderCondition(orderIds, pageReqVO.getCustomer(), organId);
|
||||
|
||||
if (CollUtil.isEmpty(planIds)) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
queryWrapperX.in(FIELD_OP_ID, planIds);
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
planDOPageResult = planMapper.selectPlanPageList(page,queryWrapperX);
|
||||
|
||||
if (CollUtil.isEmpty(planDOPageResult.getRecords())) {
|
||||
@@ -427,6 +450,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
.filter(p -> ObjectUtil.equals(PlanTypeEnum.MIXEDORDERPLAN.getType(), p.getType()))
|
||||
.toList();
|
||||
|
||||
// 查询混单实际使用板材的信息
|
||||
if (CollUtil.isNotEmpty(mixedPlans)) {
|
||||
|
||||
List<String> goodsIds = mixedPlans.stream()
|
||||
@@ -450,12 +474,24 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
List<Long> planIds = records.stream().map(PlanDO::getId).toList();
|
||||
|
||||
// 整理出所有排单涉及的订单
|
||||
Set<Long> orderIdSet = records.stream()
|
||||
.map(PlanDO::getOrderNos)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.flatMap(orderNos -> JSON.parseArray(orderNos)
|
||||
.toJavaList(Long.class)
|
||||
.stream())
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
// 查询排单对应的大板板材信息以及 统计小板数量和面积
|
||||
List<PlateInfoVO> plateInfoVOS = planItemMapper.selectOrderPlanPlateList(planIds, getUserOrganId());
|
||||
|
||||
// 获取排单对应的订单的信息
|
||||
List<PlanOrderRespVO> planOrderRespVOS = orderMapper.selectPlanOrderList(planIds, getUserOrganId());
|
||||
// 查询排单对应的大板板材信息
|
||||
List<PlateInfoVO> plateInfoVOS = planItemMapper.selectOrderPlanGoodsList(planIds, orderIdSet, organId);
|
||||
|
||||
// 获取排单涉及的所有订单信息
|
||||
Map<Long, OrderDO> orderMap = CollUtil.isEmpty(orderIdSet)
|
||||
? Collections.emptyMap()
|
||||
: orderMapper.selectByIds(orderIdSet).stream()
|
||||
.collect(Collectors.toMap(OrderDO::getId, Function.identity()));
|
||||
|
||||
|
||||
List<PlanRespVO> planRespVOPageResult = BeanUtils.toBean(records, PlanRespVO.class);
|
||||
@@ -469,7 +505,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
// 未优化小板数量
|
||||
e.setUnOptimizePlateCount(e.getPlateNum() - e.getOptimizedPlateNum());
|
||||
// 订单信息
|
||||
e.setOrderList(getOrderList(e.getId(), planOrderRespVOS));
|
||||
e.setOrderList(getOrderList(e.getOrderNos(), orderMap));
|
||||
});
|
||||
|
||||
|
||||
@@ -481,59 +517,6 @@ public class PlanServiceImpl implements PlanService {
|
||||
return BeanUtil.copyToList(planMapper.selectPlanSortList(), PlanRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlanRespVO> getPlanList() {
|
||||
|
||||
List<Integer> status = Arrays.asList(PlanStatusEnum.NOCUTTING.getStatus(),PlanStatusEnum.OPENING.getStatus());
|
||||
|
||||
List<PlanDO> planDOList = planMapper.selectPlanSortList(status, getUserOrganId());
|
||||
|
||||
if (CollUtil.isEmpty(planDOList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Long> planIds = planDOList.stream().map(PlanDO::getId).toList();
|
||||
|
||||
// 查询排单对应的大板板材信息
|
||||
List<PlateInfoVO> plateInfoVOS = goodsMapper.selectOrderGoodsPlateList(planIds, getUserOrganId());
|
||||
|
||||
|
||||
if(CollUtil.isNotEmpty(plateInfoVOS)) {
|
||||
// 查询排单对应的小板数量和小板面积
|
||||
plateInfoVOS.forEach(m -> {
|
||||
|
||||
m.setCount((int) m.getPlatePages().stream().map(PlatePage::getPlateId).count());
|
||||
|
||||
m.setArea(m.getPlatePages().stream().map(PlatePage::getArea).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
m.setPlatePages(null);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// 获取排单对应的订单的信息
|
||||
List<PlanOrderRespVO> planOrderRespVOS = orderMapper.selectPlanOrderList(planIds, getUserOrganId());
|
||||
|
||||
|
||||
List<PlanRespVO> planRespVOList = BeanUtils.toBean(planDOList, PlanRespVO.class);
|
||||
|
||||
|
||||
planRespVOList.forEach(e -> {
|
||||
// 板材信息列表
|
||||
e.setPlateInfoList(getPlateInfoList(e.getId(), plateInfoVOS));
|
||||
// 小板总数量
|
||||
e.setPlateNum(getPlateNum(e.getId(), plateInfoVOS));
|
||||
// 未优化小板数量
|
||||
e.setUnOptimizePlateCount(e.getPlateNum() - e.getOptimizedPlateNum());
|
||||
// 订单信息
|
||||
e.setOrderList(getOrderList(e.getId(), planOrderRespVOS));
|
||||
});
|
||||
|
||||
|
||||
return planRespVOList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PageResult<OrderRespVOCopy> getOrderPage(OrderPageReqVOCopy pageReqVO) {
|
||||
@@ -1184,10 +1167,18 @@ public class PlanServiceImpl implements PlanService {
|
||||
}
|
||||
|
||||
// 订单信息
|
||||
private List<PlanOrderRespVO> getOrderList(Long planId, List<PlanOrderRespVO> planOrderRespVos) {
|
||||
return planOrderRespVos.stream()
|
||||
.filter(f -> Objects.equals(f.getPlanId(), planId))
|
||||
.toList();
|
||||
private List<PlanOrderRespVO> getOrderList(String orderNos, Map<Long, OrderDO> orderMap) {
|
||||
List<PlanOrderRespVO> orderList = JSON.parseArray(orderNos).toJavaList(Long.class).stream()
|
||||
.map(orderMap::get)
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(Comparator.comparing(OrderDO::getId).reversed())
|
||||
.map(order -> {
|
||||
PlanOrderRespVO vo = BeanUtils.toBean(order, PlanOrderRespVO.class);
|
||||
vo.setSalesman(order.getSalesman());
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return orderList;
|
||||
}
|
||||
|
||||
|
||||
@@ -1276,7 +1267,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
.stream().filter(m -> m.getCount() == 0).map(OrderPlanPlateStatisticsRespVO::getPlanId).distinct().collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(deleteEmptyPlanIdList)) {
|
||||
planMapper.deleteByIds(deleteEmptyPlanIdList);
|
||||
planMapper.physicalDeleteByIds(deleteEmptyPlanIdList, getUserOrganId());
|
||||
}
|
||||
|
||||
// 更新排单下的订单列表
|
||||
|
||||
-29
@@ -489,35 +489,6 @@
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectPlanOrderList"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlanOrderRespVO">
|
||||
|
||||
|
||||
select distinct
|
||||
o.id,
|
||||
o.order_type,
|
||||
op.plan_id,
|
||||
o.order_date,
|
||||
o.delivery_date,
|
||||
o.custom_order_no,
|
||||
o.customer,
|
||||
o.address,
|
||||
o.phone_number,
|
||||
o.dealer,
|
||||
o.dealer_phone_number,
|
||||
o.salesman,
|
||||
o.splitter,
|
||||
o.remark
|
||||
from orders o
|
||||
join order_plate op on o.organ_id = op.organ_id and o.id = op.order_id
|
||||
where op.organ_id = #{organId}
|
||||
and op.plan_id in
|
||||
<foreach collection="planIds" item="ids" open="(" close=")" separator=",">
|
||||
#{ids}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectFilterOrderPagePlate"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.plan.vo.OrderRespVOCopy">
|
||||
|
||||
|
||||
+8
-5
@@ -15,10 +15,7 @@
|
||||
|
||||
select distinct op.*
|
||||
from order_plan op
|
||||
join order_plate opt on op.organ_id = opt.organ_id and op.id = opt.plan_id
|
||||
left join orders o on op.organ_id = o.organ_id and opt.order_id = o.id
|
||||
|
||||
${ew.customSqlSegment}
|
||||
${ew.customSqlSegment}
|
||||
|
||||
ORDER BY op.sort
|
||||
</select>
|
||||
@@ -26,7 +23,6 @@
|
||||
<select id="selectPlanSortList" resultType="com.cf.imes.module.executor.dal.dataobject.plan.PlanDO">
|
||||
select distinct op.*
|
||||
from order_plan op
|
||||
join order_plate opt on op.organ_id = opt.organ_id and op.id = opt.plan_id and opt.deleted = false
|
||||
where op.status != 3 and op.deleted = false
|
||||
ORDER BY op.sort
|
||||
</select>
|
||||
@@ -393,4 +389,11 @@
|
||||
orderDate
|
||||
</select>
|
||||
|
||||
<delete id="physicalDeleteByIds">
|
||||
DELETE FROM order_plan WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
and organ_id = #{organId}
|
||||
</delete>
|
||||
</mapper>
|
||||
+8
-4
@@ -183,7 +183,7 @@
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectOrderPlanPlateList" resultMap="GoodsListMap" parameterType="java.lang.Long">
|
||||
<select id="selectOrderPlanGoodsList" resultMap="GoodsListMap" parameterType="java.lang.Long">
|
||||
|
||||
select distinct
|
||||
op.plan_id as planId,
|
||||
@@ -195,9 +195,13 @@
|
||||
join order_goods og on op.organ_id = og.organ_id and op.goods_id = og.id
|
||||
|
||||
where op.organ_id = #{organId}
|
||||
and op.plan_id in
|
||||
<foreach collection="planIds" item="planIds" open="(" close=")" separator=",">
|
||||
#{planIds}
|
||||
and op.order_id in
|
||||
<foreach collection="orderIds" item="orderId" open="(" close=")" separator=",">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
and op.plan_id in
|
||||
<foreach collection="planIds" item="planId" open="(" close=")" separator=",">
|
||||
#{planId}
|
||||
</foreach>
|
||||
GROUP BY
|
||||
planId,
|
||||
|
||||
+20
@@ -1692,6 +1692,26 @@
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectPlanIdsByOrderCondition" resultType="java.lang.Long">
|
||||
SELECT DISTINCT op.plan_id
|
||||
FROM orders o
|
||||
JOIN order_plate op ON o.organ_id = op.organ_id
|
||||
AND o.id = op.order_id
|
||||
AND op.plan_id != 0
|
||||
AND op.deleted = false
|
||||
WHERE o.organ_id = #{organId}
|
||||
AND o.deleted = false
|
||||
<if test="orderIds != null and orderIds.size() > 0">
|
||||
AND o.id IN
|
||||
<foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="customer != null and customer != ''">
|
||||
AND o.customer LIKE CONCAT('%', #{customer}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<resultMap id="orderItemMap" type="com.cf.imes.module.executor.controller.admin.manage.query.vo.pack.PackageDetailsRespVO">
|
||||
<result property="packageNo" column="packageId"/>
|
||||
<result property="roomName" column="roomName"/>
|
||||
|
||||
Reference in New Issue
Block a user