禅道bug#1726修复

This commit is contained in:
gaoqr
2026-06-25 16:19:13 +08:00
parent 940f895d4c
commit adb8260697
9 changed files with 199 additions and 25 deletions
@@ -120,6 +120,12 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
return this; return this;
} }
@Override
public LambdaQueryWrapperX<T> orderByAsc(SFunction<T, ?> column) {
super.orderByAsc(true, column);
return this;
}
@Override @Override
public LambdaQueryWrapperX<T> last(String lastSql) { public LambdaQueryWrapperX<T> last(String lastSql) {
super.last(lastSql); super.last(lastSql);
@@ -39,6 +39,7 @@ public class ErrorCodeConstants {
public static final ErrorCode ORDER_PLAN_ID_NOT_NULL = new ErrorCode(1_003_109_005, "订单或排单ID至少传入一个"); public static final ErrorCode ORDER_PLAN_ID_NOT_NULL = new ErrorCode(1_003_109_005, "订单或排单ID至少传入一个");
public static final ErrorCode ORDER_PLAN_ID_IS_ONE = new ErrorCode(1_003_109_006, "订单id与排单id与大板分类ID只能传一个"); public static final ErrorCode ORDER_PLAN_ID_IS_ONE = new ErrorCode(1_003_109_006, "订单id与排单id与大板分类ID只能传一个");
public static final ErrorCode PARENT_ORDER_NOT_EXISTS = new ErrorCode(1_003_109_007, "parent.order.not.exists"); public static final ErrorCode PARENT_ORDER_NOT_EXISTS = new ErrorCode(1_003_109_007, "parent.order.not.exists");
public static final ErrorCode SUB_ORDER_CAN_NOT_CANCEL = new ErrorCode(1_003_109_008, "sub.order.can.not.cancel");
// ========== 订单板件 1_003_113_000 ========== // ========== 订单板件 1_003_113_000 ==========
public static final ErrorCode PLATE_NOT_EXISTS = new ErrorCode(1_003_113_000, "order.plate.not.exists"); public static final ErrorCode PLATE_NOT_EXISTS = new ErrorCode(1_003_113_000, "order.plate.not.exists");
@@ -1,6 +1,5 @@
package com.cf.imes.module.executor.controller.admin.order; package com.cf.imes.module.executor.controller.admin.order;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.exception.ServiceException;
@@ -19,7 +18,6 @@ import com.cf.imes.module.executor.controller.admin.order.vo.product.OrderBodyRe
import com.cf.imes.module.executor.controller.admin.order.vo.product.OrderRoomBodyRespVO; import com.cf.imes.module.executor.controller.admin.order.vo.product.OrderRoomBodyRespVO;
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRespVO; import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRespVO;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
import com.cf.imes.module.executor.enums.CategoryEnum; import com.cf.imes.module.executor.enums.CategoryEnum;
import com.cf.imes.module.executor.enums.OrderDeletedEnum; import com.cf.imes.module.executor.enums.OrderDeletedEnum;
import com.cf.imes.module.executor.enums.OrderStatusEnum; import com.cf.imes.module.executor.enums.OrderStatusEnum;
@@ -57,7 +55,6 @@ import static com.cf.imes.framework.common.pojo.CommonResult.error;
import static com.cf.imes.framework.common.pojo.CommonResult.success; import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.IMPORT; import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.IMPORT;
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId; 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.ErrorCodeConstants.*;
@@ -72,9 +69,6 @@ public class OrderController {
@Resource @Resource
private OrderService orderService; private OrderService orderService;
@Resource
private OrderMapper orderMapper;
@Resource @Resource
private LargeFilesUtils largeFilesUtils; private LargeFilesUtils largeFilesUtils;
@@ -168,7 +162,7 @@ public class OrderController {
@Parameter(name = "orderId", description = "订单id", required = true, example = "1") @Parameter(name = "orderId", description = "订单id", required = true, example = "1")
@PreAuthorize("@ss.hasPermission('production:manager-list:nullify')") @PreAuthorize("@ss.hasPermission('production:manager-list:nullify')")
public CommonResult<Boolean> deleteOrder(@RequestParam("orderId") Long orderId) { public CommonResult<Boolean> deleteOrder(@RequestParam("orderId") Long orderId) {
Integer index = orderService.updateOrderDel(orderId, OrderDeletedEnum.DELETED.getStatus()); Integer index = orderService.invalidOrder(orderId);
if (index == 0) { if (index == 0) {
throw new ServiceException(ORDER_DELETED_ERR); throw new ServiceException(ORDER_DELETED_ERR);
} }
@@ -181,7 +175,7 @@ public class OrderController {
@PreAuthorize("@ss.hasPermission('production:manager-list:backOrder')") @PreAuthorize("@ss.hasPermission('production:manager-list:backOrder')")
public CommonResult<Boolean> restoreOrder(@RequestBody JSONObject jsonObject) { public CommonResult<Boolean> restoreOrder(@RequestBody JSONObject jsonObject) {
Long orderId = jsonObject.getLong("orderId"); Long orderId = jsonObject.getLong("orderId");
Integer index = orderService.updateOrderDel(orderId, OrderDeletedEnum.NOT_DELETED.getStatus()); Integer index = orderService.restoreOrder(orderId);
if (index == 0) { if (index == 0) {
throw new ServiceException(ORDER_RESTORE_ERR); throw new ServiceException(ORDER_RESTORE_ERR);
} }
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.cf.imes.framework.common.enums.DeletedCodeEnum;
import com.cf.imes.framework.common.enums.OrderPackageStatusEnum; import com.cf.imes.framework.common.enums.OrderPackageStatusEnum;
import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
@@ -103,6 +104,29 @@ public interface OrderMapper extends BaseMapperX<OrderDO> {
return selectPage(reqVO, query); return selectPage(reqVO, query);
} }
/**
* 分页查询已作废订单
* @param reqVO
* @return
*/
default PageResult<OrderDO> selectDeletedPage(OrderPageReqVO reqVO) {
LambdaQueryWrapperX<OrderDO> query = new LambdaQueryWrapperX<OrderDO>()
.likeIfPresent(OrderDO::getId, reqVO.getId() == null ? null : reqVO.getId())
.betweenIfPresent(OrderDO::getDeliveryDate, reqVO.getDeliveryDate())
.betweenIfPresent(OrderDO::getOrderDate, reqVO.getOrderDate())
.eqIfPresent(OrderDO::getStatus, reqVO.getStatus())
.likeIfPresent(OrderDO::getCustomOrderNo, reqVO.getCustomOrderNo())
.likeIfPresent(OrderDO::getDealer, reqVO.getDealer())
.likeIfPresent(OrderDO::getAddress, reqVO.getAddress())
.eqIfPresent(OrderDO::getDealerPhoneNumber, reqVO.getDealerPhoneNumber())
.eqIfPresent(OrderDO::getDeleted, DeletedCodeEnum.DELETED.getStatus())
.betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(OrderDO::getRootId)
.orderByAsc(OrderDO::getId);
return selectPage(reqVO, query);
}
/** /**
* 分页查询主单id(带子单过滤) * 分页查询主单id(带子单过滤)
* *
@@ -188,10 +188,20 @@ public interface OrderService {
/** /**
* 修改订单是否删除 * 作废订单
*
* @param orderId
* @return
*/ */
Integer updateOrderDel(Long orderId, Integer status); Integer invalidOrder(Long orderId);
/**
* 还原订单
*
* @param orderId
* @return
*/
Integer restoreOrder(Long orderId);
/** /**
* 作废中删除 * 作废中删除
@@ -326,6 +326,12 @@ public class OrderServiceImpl implements OrderService {
@Override @Override
public PageResult<OrderDO> getMainOrderPage(OrderPageReqVO pageReqVO) { public PageResult<OrderDO> getMainOrderPage(OrderPageReqVO pageReqVO) {
IPage<OrderDO> page = new PageDTO<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()); IPage<OrderDO> page = new PageDTO<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
// 删除展示平铺订单列表
if (pageReqVO.getDeleted()) {
return orderMapper.selectDeletedPage(pageReqVO);
}
// 1. 查询主单ID分页 // 1. 查询主单ID分页
IPage<Long> pageResult = orderMapper.selectMainOrderIds(page, pageReqVO); IPage<Long> pageResult = orderMapper.selectMainOrderIds(page, pageReqVO);
Long pageResultTotal = pageResult.getTotal(); Long pageResultTotal = pageResult.getTotal();
@@ -870,35 +876,165 @@ public class OrderServiceImpl implements OrderService {
} }
@Override @Override
public Integer updateOrderDel(Long orderId, Integer deleted) { @Transactional(rollbackFor = Exception.class)
Integer index = deleted == 1 ? 0 : 1; public Integer invalidOrder(Long orderId) {
Integer notDeletedStatus = OrderDeletedEnum.NOT_DELETED.getStatus();
Integer deletedStatus = OrderDeletedEnum.DELETED.getStatus();
// 校验存在 // 校验存在
OrderDO orderDO = orderMapper.selectOrderOne(orderId, getUserOrganId(), index); OrderDO orderDO = orderMapper.selectOrderOne(orderId, getUserOrganId(), notDeletedStatus);
if (orderDO == null) if (orderDO == null) {
throw new ServiceException(ORDER_NOT_EXISTS); throw new ServiceException(ORDER_NOT_EXISTS);
}
// 是否主单
boolean isMainOrder = Objects.equals(orderDO.getOrderType(), OrderTypeEnum.MAIN_ORDER.getStatus());
if (isMainOrder) {
// 主单:查询所有子单
List<OrderDO> childOrders = orderMapper.selectList(new LambdaQueryWrapper<OrderDO>()
.eq(OrderDO::getParentId, orderId)
.eq(OrderDO::getDeleted, notDeletedStatus));
if (CollUtil.isNotEmpty(childOrders)) {
// 作废:检查所有子单是否可作废
boolean hasUncancellable = childOrders.stream().anyMatch(child ->
!Objects.equals(child.getStatus(), OrderStatusEnum.EMPTY.getStatus()) &&
!Objects.equals(child.getStatus(), OrderStatusEnum.NEW_ORDER.getStatus()));
if (hasUncancellable) {
throw new ServiceException(SUB_ORDER_CAN_NOT_CANCEL);
}
List<Long> allIds = new ArrayList<>();
allIds.add(orderId);
childOrders.forEach(child -> allIds.add(child.getId()));
// 批量作废主子单
return orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.in(OrderDO::getId, allIds)
.eq(OrderDO::getDeleted, notDeletedStatus)
.set(OrderDO::getDeleted, deletedStatus)
);
}
}
// 状态排除 // 状态排除
if (!Objects.equals(orderDO.getStatus(), OrderStatusEnum.EMPTY.getStatus()) && if (!Objects.equals(orderDO.getStatus(), OrderStatusEnum.EMPTY.getStatus()) &&
!Objects.equals(orderDO.getStatus(), OrderStatusEnum.NEW_ORDER.getStatus())) !Objects.equals(orderDO.getStatus(), OrderStatusEnum.NEW_ORDER.getStatus())) {
throw new ServiceException(ORDER_CAN_NOT_CANCEL); throw new ServiceException(ORDER_CAN_NOT_CANCEL);
return orderMapper.updateOrderDeleted(orderId, deleted, getUserOrganId()); }
return orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.eq(OrderDO::getId, orderId)
.eq(OrderDO::getDeleted, notDeletedStatus)
.set(OrderDO::getDeleted, deletedStatus)
);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer restoreOrder(Long orderId) {
Integer notDeletedStatus = OrderDeletedEnum.NOT_DELETED.getStatus();
Integer deletedStatus = OrderDeletedEnum.DELETED.getStatus();
Long organId = getUserOrganId();
OrderDO orderDO = orderMapper.selectOrderOne(orderId, organId, deletedStatus);
if (orderDO == null) {
throw new ServiceException(ORDER_NOT_EXISTS);
}
boolean isMainOrder = Objects.equals(orderDO.getOrderType(), OrderTypeEnum.MAIN_ORDER.getStatus());
if (isMainOrder) {
// 主单:查询所有已作废的子单,一起还原
List<OrderDO> deletedChildOrders = orderMapper.selectList(new LambdaQueryWrapper<OrderDO>()
.eq(OrderDO::getParentId, orderId)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getDeleted, deletedStatus));
if (CollUtil.isNotEmpty(deletedChildOrders)) {
List<Long> allIds = new ArrayList<>();
allIds.add(orderId);
deletedChildOrders.forEach(child -> allIds.add(child.getId()));
return orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.in(OrderDO::getId, allIds)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getDeleted, deletedStatus)
.set(OrderDO::getDeleted, notDeletedStatus)
);
}
} else {
// 子单:还原自身 + 对应主单,不还原其他子单
Long parentId = orderDO.getParentId();
List<Long> restoreIds = new ArrayList<>();
restoreIds.add(orderId);
restoreIds.add(parentId);
return orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.in(OrderDO::getId, restoreIds)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getDeleted, deletedStatus)
.set(OrderDO::getDeleted, notDeletedStatus)
);
}
// 主单无子单,直接还原
return orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.eq(OrderDO::getId, orderId)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getDeleted, deletedStatus)
.set(OrderDO::getDeleted, notDeletedStatus)
);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void realDeletedOrder(Long orderId) { public void realDeletedOrder(Long orderId) {
validateOrderExists(orderId, getUserOrganId(), OrderDeletedEnum.DELETED.getStatus()); Long organId = getUserOrganId();
Integer deletedStatus = OrderDeletedEnum.DELETED.getStatus();
Integer notDeletedStatus = OrderDeletedEnum.NOT_DELETED.getStatus();
// 作废 订单表,bodygroupgoodspartsplateraw_goods OrderDO orderDO = orderMapper.selectOrderOne(orderId, organId, deletedStatus);
goodsMapper.deleteByOrderId(orderId, getUserOrganId()); if (orderDO == null) {
orderItemMapper.deleteByOrderId(orderId, getUserOrganId()); throw new ServiceException(ORDER_NOT_EXISTS);
orderBodyMapper.deleteByOrderId(orderId, getUserOrganId()); }
orderGroupMapper.deleteByOrderId(orderId, getUserOrganId());
orderPartsMapper.deleteByOrderId(orderId, getUserOrganId()); boolean isMainOrder = Objects.equals(orderDO.getOrderType(), OrderTypeEnum.MAIN_ORDER.getStatus());
plateMapper.deleteByOrderId(orderId, getUserOrganId()); if (isMainOrder) {
// 检查是否存在未作废的子单
long activeChildCount = orderMapper.selectCount(new LambdaQueryWrapper<OrderDO>()
.eq(OrderDO::getParentId, orderId)
.eq(OrderDO::getDeleted, notDeletedStatus));
orderMapper.deleteOrder(orderId, getUserOrganId()); // 订单删除 if (activeChildCount > 0) {
throw new ServiceException(SUB_ORDER_CAN_NOT_CANCEL);
}
// 主单:连同所有子单一起删除
List<OrderDO> childOrders = orderMapper.selectList(new LambdaQueryWrapper<OrderDO>()
.eq(OrderDO::getParentId, orderId)
.eq(OrderDO::getDeleted, deletedStatus));
if (CollUtil.isNotEmpty(childOrders)) {
childOrders.forEach(child -> deleteOrderData(child.getId(), organId));
}
return;
}
deleteOrderData(orderId, organId);
}
/**
* 删除订单数据
*
* @param orderId
* @param organId
*/
private void deleteOrderData(Long orderId, Long organId) {
goodsMapper.deleteByOrderId(orderId, organId);
orderItemMapper.deleteByOrderId(orderId, organId);
orderBodyMapper.deleteByOrderId(orderId, organId);
orderGroupMapper.deleteByOrderId(orderId, organId);
orderPartsMapper.deleteByOrderId(orderId, organId);
plateMapper.deleteByOrderId(orderId, organId);
orderMapper.deleteOrder(orderId, organId);
} }
/** /**
@@ -17,6 +17,7 @@ be.kicked.out=您的賬號於 {0} 在別處登錄,已被迫下線。登錄IP
order.not.exists=訂單不存在 order.not.exists=訂單不存在
parent.order.not.exists=上級訂單{0}不存在 parent.order.not.exists=上級訂單{0}不存在
order.can.not.cancel=訂單已進入生產狀態,無法作廢 order.can.not.cancel=訂單已進入生產狀態,無法作廢
sub.order.can.not.cancel=訂單下存在已進入生產狀態的子單,無法作廢
order.plate.is.plan=目標訂單中存在已排單板件,請從排單中移除後再選擇刪除 order.plate.is.plan=目標訂單中存在已排單板件,請從排單中移除後再選擇刪除
order.check.customno.exists=自定義訂單號已存在,請刪除原訂單或修改自定義訂單號後再次操作 order.check.customno.exists=自定義訂單號已存在,請刪除原訂單或修改自定義訂單號後再次操作
order.body.not.exists=當前櫃體不存在 order.body.not.exists=當前櫃體不存在
@@ -17,6 +17,7 @@ be.kicked.out=Your account was logged in elsewhere at {0} and has been forced to
order.not.exists=Order does not exist order.not.exists=Order does not exist
parent.order.not.exists=Parent order {0} does not exist parent.order.not.exists=Parent order {0} does not exist
order.can.not.cancel=Order has entered production and cannot be canceled order.can.not.cancel=Order has entered production and cannot be canceled
sub.order.can.not.cancel=There are sub-orders under the order that have entered the production state and cannot be invalidated
order.plate.is.plan=Some plates in the target order have been scheduled. Please remove them before deletion order.plate.is.plan=Some plates in the target order have been scheduled. Please remove them before deletion
order.check.customno.exists=The custom order number already exists. Please delete the original order or modify the custom order number and then operate again order.check.customno.exists=The custom order number already exists. Please delete the original order or modify the custom order number and then operate again
order.body.not.exists=Cabinet does not exist order.body.not.exists=Cabinet does not exist
@@ -17,6 +17,7 @@ be.kicked.out=您的账号于 {0} 在别处登录,已被迫下线。登录IP
order.not.exists=订单不存在 order.not.exists=订单不存在
parent.order.not.exists=上级订单{0}不存在 parent.order.not.exists=上级订单{0}不存在
order.can.not.cancel=订单已进入生产状态,无法作废 order.can.not.cancel=订单已进入生产状态,无法作废
sub.order.can.not.cancel=订单下存在已进入生产状态的子单,无法作废
order.plate.is.plan=目标订单中存在已排单板件,请从排单中移除后再选择删除 order.plate.is.plan=目标订单中存在已排单板件,请从排单中移除后再选择删除
order.check.customno.exists=自定义订单号已存在,请删除原订单或修改自定义订单号后再次操作 order.check.customno.exists=自定义订单号已存在,请删除原订单或修改自定义订单号后再次操作
order.body.not.exists=当前柜体不存在 order.body.not.exists=当前柜体不存在