Commit 037d14f4 authored by zhengyi's avatar zhengyi

完善订单并行审批任务的审批类型状态替换更新

parent 7eb461fe
package cn.iocoder.yudao.framework.apollo.core.event;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 审批校验 Event
*
* @author zhengYi
*/
@Data
@AllArgsConstructor
public class BoxCheckOrderApprovalEvent {
/**
* 订单ID
*/
private Long orderId;
/**
* 自编号
*/
private String selfNo;
/**
* 类型
*/
private Integer auditType;
/**
* 结果
*/
private String auditResult;
/**
* 是否存在
*/
private Boolean isExists;
}
...@@ -66,6 +66,7 @@ import cn.iocoder.yudao.module.order.dal.dataobject.orderOperateLog.OrderOperate ...@@ -66,6 +66,7 @@ import cn.iocoder.yudao.module.order.dal.dataobject.orderOperateLog.OrderOperate
import cn.iocoder.yudao.module.order.dal.dataobject.orderPickup.OrderPickupDO; import cn.iocoder.yudao.module.order.dal.dataobject.orderPickup.OrderPickupDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderSpecialNeed.OrderSpecialNeedDO; import cn.iocoder.yudao.module.order.dal.dataobject.orderSpecialNeed.OrderSpecialNeedDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderTime.OrderTimeDO; import cn.iocoder.yudao.module.order.dal.dataobject.orderTime.OrderTimeDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderWarehouseApproval.OrderWarehouseApprovalDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderWarehouseIn.OrderWarehouseInDO; import cn.iocoder.yudao.module.order.dal.dataobject.orderWarehouseIn.OrderWarehouseInDO;
import cn.iocoder.yudao.module.order.dal.mysql.approval.OrderApprovalMapper; import cn.iocoder.yudao.module.order.dal.mysql.approval.OrderApprovalMapper;
import cn.iocoder.yudao.module.order.dal.mysql.order.OrderMapper; import cn.iocoder.yudao.module.order.dal.mysql.order.OrderMapper;
...@@ -83,6 +84,7 @@ import cn.iocoder.yudao.module.order.param.OrderChangePriceParam; ...@@ -83,6 +84,7 @@ import cn.iocoder.yudao.module.order.param.OrderChangePriceParam;
import cn.iocoder.yudao.module.order.service.order.*; import cn.iocoder.yudao.module.order.service.order.*;
import cn.iocoder.yudao.module.order.service.orderException.OrderExceptionService; import cn.iocoder.yudao.module.order.service.orderException.OrderExceptionService;
import cn.iocoder.yudao.module.order.service.orderOperateLog.OrderOperateLogService; import cn.iocoder.yudao.module.order.service.orderOperateLog.OrderOperateLogService;
import cn.iocoder.yudao.module.order.service.orderWarehouseApproval.OrderWarehouseApprovalService;
import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialApplyVO; import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialApplyVO;
import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialBatchApplyOrderItemDetailVO; import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialBatchApplyOrderItemDetailVO;
import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialBatchApplyVO; import cn.iocoder.yudao.module.order.vo.approval.OrderSpecialBatchApplyVO;
...@@ -134,6 +136,7 @@ import static cn.iocoder.yudao.framework.apollo.core.constants.Constants.*; ...@@ -134,6 +136,7 @@ import static cn.iocoder.yudao.framework.apollo.core.constants.Constants.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.order.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.order.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.order.enums.OrderApprovalTypeEnum.ORDER_UPDATE; import static cn.iocoder.yudao.module.order.enums.OrderApprovalTypeEnum.ORDER_UPDATE;
import static cn.iocoder.yudao.module.order.enums.OrderApprovalTypeResultEnum.*;
import static cn.iocoder.yudao.module.order.enums.OrderStatusEnum.DRAFT; import static cn.iocoder.yudao.module.order.enums.OrderStatusEnum.DRAFT;
/** /**
...@@ -182,6 +185,7 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl ...@@ -182,6 +185,7 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
private final CustomerCreditLogService customerCreditLogService; private final CustomerCreditLogService customerCreditLogService;
private final ParamValidatorService paramValidatorService; private final ParamValidatorService paramValidatorService;
private final OrderExceptionService orderExceptionService; private final OrderExceptionService orderExceptionService;
private final OrderWarehouseApprovalService orderWarehouseApprovalService;
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final IndirectCustomerService indirectCustomerService; private final IndirectCustomerService indirectCustomerService;
private final CurrencyApi currencyApi; private final CurrencyApi currencyApi;
...@@ -4323,6 +4327,9 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl ...@@ -4323,6 +4327,9 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
if (Objects.nonNull(auditType)) { if (Objects.nonNull(auditType)) {
// TODO 这里可能出现并行的审批任务,当结束一个审批任务变更为0时,需要同步查询当前正在进行的其他审批任务 // TODO 这里可能出现并行的审批任务,当结束一个审批任务变更为0时,需要同步查询当前正在进行的其他审批任务
if (auditType == 0) {
this.checkOrderProcessingApprovalType(orderId, currentOrderDO.getContainerNumber(), auditType, auditResult);
}
currentOrderDO.setAuditType(auditType); currentOrderDO.setAuditType(auditType);
if (StringUtils.isNotBlank(auditResult)) { if (StringUtils.isNotBlank(auditResult)) {
...@@ -4380,6 +4387,64 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl ...@@ -4380,6 +4387,64 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
return result; return result;
} }
/**
* 订单审批更新
*
* @param orderId 订单id
* @param containerNumber 自编号
* @param auditType 审批类型
* @param auditResult 审批结果
*/
private void checkOrderProcessingApprovalType(Long orderId, String containerNumber, Integer auditType, String auditResult) {
// 出货审批更新
if (StringUtils.isNotBlank(containerNumber)){
BoxCheckOrderApprovalEvent boxCheckOrderApprovalEvent = new BoxCheckOrderApprovalEvent(orderId, containerNumber, auditType, auditResult, false);
applicationContext.publishEvent(boxCheckOrderApprovalEvent);
if (boxCheckOrderApprovalEvent.getIsExists()) {
auditType = boxCheckOrderApprovalEvent.getAuditType();
auditResult = boxCheckOrderApprovalEvent.getAuditResult();
return;
}
}
// 入仓审批更新
OrderWarehouseApprovalDO warehouseApprovalDO = orderWarehouseApprovalService.getOne(new LambdaQueryWrapper<OrderWarehouseApprovalDO>()
.eq(OrderWarehouseApprovalDO::getOrderIds, orderId)
.eq(OrderWarehouseApprovalDO::getStatus, 1)
.orderByDesc(OrderWarehouseApprovalDO::getId)
.last("limit 1"));
if (Objects.nonNull(warehouseApprovalDO)){
switch (warehouseApprovalDO.getType()){
case 1:
// 入仓修改
auditType = warehouse_update_processing.getType();
auditResult = warehouse_update_processing.getDesc();
return;
case 2:
// 调仓
auditType = warehouse_adjust_processing.getType();
auditResult = warehouse_adjust_processing.getDesc();
return;
case 3:
// 退仓
auditType = warehouse_rollback_processing.getType();
auditResult = warehouse_rollback_processing.getDesc();
return;
}
}
// 订单审批更新
OrderApprovalDO approvalDO = orderApprovalService.getOne(new LambdaQueryWrapper<OrderApprovalDO>()
.eq(OrderApprovalDO::getOrderId, orderId)
.eq(OrderApprovalDO::getStatus, 1)
.orderByDesc(OrderApprovalDO::getOrderApprovalId)
.last("limit 1"));
if (Objects.nonNull(approvalDO)){
OrderApprovalTypeResultEnum resultEnum = OrderApprovalTypeResultEnum.typeAndResultOf(approvalDO.getType(), approvalDO.getStatus());
auditType = resultEnum.getType();
auditResult = resultEnum.getDesc();
return;
}
}
private void addPrefixStatus(OrderDO currentOrderDO, Integer prefixType) { private void addPrefixStatus(OrderDO currentOrderDO, Integer prefixType) {
String prefixStatusZh = ""; String prefixStatusZh = "";
String prefixStatusEn = ""; String prefixStatusEn = "";
...@@ -5058,10 +5123,10 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl ...@@ -5058,10 +5123,10 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
throw exception(ORDER_NOT_EXISTS); throw exception(ORDER_NOT_EXISTS);
} }
OrderApprovalTypeEnum typeEnum = OrderApprovalTypeEnum.valueOf(specialApplyVO.getApplyType()); OrderApprovalTypeEnum typeEnum = OrderApprovalTypeEnum.valueOf(specialApplyVO.getApplyType());
if (Objects.isNull(typeEnum)){ if (Objects.isNull(typeEnum)) {
throw exception(ORDER_APPROVAL_IS_NOT_EXISTS); throw exception(ORDER_APPROVAL_IS_NOT_EXISTS);
} }
OrderApprovalTypeCheckEvent approvalTypeCheckEvent = new OrderApprovalTypeCheckEvent(specialApplyVO.getOrderId(), Objects.nonNull(specialApplyVO.getOrderItemId())? OrderApprovalTypeCheckEvent approvalTypeCheckEvent = new OrderApprovalTypeCheckEvent(specialApplyVO.getOrderId(), Objects.nonNull(specialApplyVO.getOrderItemId()) ?
Collections.singletonList(specialApplyVO.getOrderItemId()) : null, typeEnum.getValue(), false); Collections.singletonList(specialApplyVO.getOrderItemId()) : null, typeEnum.getValue(), false);
applicationContext.publishEvent(approvalTypeCheckEvent); applicationContext.publishEvent(approvalTypeCheckEvent);
if (approvalTypeCheckEvent.getResult()) { if (approvalTypeCheckEvent.getResult()) {
...@@ -5261,7 +5326,7 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl ...@@ -5261,7 +5326,7 @@ public class OrderServiceImpl extends AbstractService<OrderMapper, OrderDO> impl
throw exception(ORDER_NOT_EXISTS); throw exception(ORDER_NOT_EXISTS);
} }
OrderApprovalTypeEnum typeEnum = OrderApprovalTypeEnum.valueOf(specialBatchApplyVO.getApplyType()); OrderApprovalTypeEnum typeEnum = OrderApprovalTypeEnum.valueOf(specialBatchApplyVO.getApplyType());
if (Objects.isNull(typeEnum)){ if (Objects.isNull(typeEnum)) {
throw exception(ORDER_APPROVAL_IS_NOT_EXISTS); throw exception(ORDER_APPROVAL_IS_NOT_EXISTS);
} }
List<Long> orderItemIdList = specialBatchApplyVO.getBatchApplyOrderItemDetailVOList().stream().map(OrderSpecialBatchApplyOrderItemDetailVO::getOrderItemId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> orderItemIdList = specialBatchApplyVO.getBatchApplyOrderItemDetailVOList().stream().map(OrderSpecialBatchApplyOrderItemDetailVO::getOrderItemId).filter(Objects::nonNull).collect(Collectors.toList());
......
...@@ -5,9 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; ...@@ -5,9 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper; import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO; import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.order.dal.dataobject.approval.OrderApprovalDO;
import cn.iocoder.yudao.module.shipment.dal.dataobject.BoxApprovalDO; import cn.iocoder.yudao.module.shipment.dal.dataobject.BoxApprovalDO;
import cn.iocoder.yudao.module.shipment.vo.boxApproval.BoxApprovalQueryVO; import cn.iocoder.yudao.module.shipment.vo.boxApproval.BoxApprovalQueryVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
/** /**
* 出货审核 Mapper * 出货审核 Mapper
...@@ -44,4 +48,18 @@ public interface BoxApprovalMapper extends AbstractMapper<BoxApprovalDO> { ...@@ -44,4 +48,18 @@ public interface BoxApprovalMapper extends AbstractMapper<BoxApprovalDO> {
return null; return null;
} }
@ResultType(BoxApprovalDO.class)
@Select({
"<script>",
"select",
" a.* ",
"from ecw_box_approval a",
"where ",
"a.shipment_id = #{shipmentId}",
"and (a.order_id is null or (a.order_id is not null and a.order_id = #{orderId}) )",
"order by a.id desc",
"</script>"
})
List<BoxApprovalDO> checkOrderProcessingApproval(@Param("shipmentId") Long shipmentId, @Param("orderId") Long orderId);
} }
package cn.iocoder.yudao.module.shipment.listener;
import cn.iocoder.yudao.framework.apollo.core.event.BoxCheckOrderApprovalEvent;
import cn.iocoder.yudao.module.shipment.dal.dataobject.BoxApprovalDO;
import cn.iocoder.yudao.module.shipment.dal.dataobject.BoxDO;
import cn.iocoder.yudao.module.shipment.enums.BoxApprovalTypeEnum;
import cn.iocoder.yudao.module.shipment.service.box.BoxService;
import cn.iocoder.yudao.module.shipment.service.boxApproval.BoxApprovalService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.module.order.enums.OrderApprovalTypeResultEnum.*;
/**
* 提供订单最新的进行中审批任务
*
* @author zhengYi
*/
@Component("BoxCheckOrderApprovalListener")
@AllArgsConstructor
@Slf4j
public class BoxCheckOrderApprovalListener {
private final BoxApprovalService boxApprovalService;
private final BoxService boxService;
/**
* 提供订单是否存在进行中的审批校验
*
* @param event 订单信息与结果
*/
@EventListener(BoxCheckOrderApprovalEvent.class)
public void checkOrderApproval(BoxCheckOrderApprovalEvent event) {
BoxDO boxDO = boxService.getOne(new LambdaQueryWrapper<BoxDO>().eq(BoxDO::getSelfNo, event.getSelfNo()));
if (boxDO == null) {
return;
}
List<BoxApprovalDO> boxApprovalDOList = boxApprovalService.checkOrderProcessingApproval(boxDO.getId(), event.getOrderId());
if (Objects.isNull(boxApprovalDOList)) {
return;
}
for (BoxApprovalDO boxApprovalDO : boxApprovalDOList) {
BoxApprovalTypeEnum typeEnum = BoxApprovalTypeEnum.getApprovalTypeByTypeValue(boxApprovalDO.getApprovalType());
if (Objects.isNull(typeEnum)) {
continue;
}
event.setIsExists(true);
switch (typeEnum) {
case PRELOAD:
//预装
event.setAuditType(pre_install_processing.getResult());
event.setAuditResult(pre_install_processing.getDesc());
return;
case SEALING_CABINET:
//装柜
event.setAuditType(closure_processing.getResult());
event.setAuditResult(closure_processing.getDesc());
return;
case UNLOAD_CABINET:
// 卸柜
event.setAuditType(unloading_cabinet_processing.getResult());
event.setAuditResult(unloading_cabinet_processing.getDesc());
return;
case PRELOAD_UMPIRE:
//预装反审
event.setAuditType(pre_install_back_processing.getResult());
event.setAuditResult(pre_install_back_processing.getDesc());
return;
case CUSTOMS_FULL_REFUND:
//报关全退
event.setAuditType(customs_exit_processing.getResult());
event.setAuditResult(customs_exit_processing.getDesc());
return;
case UNLOAD_UMPIRE:
//卸柜反审
event.setAuditType(unloading_cabinet_back_processing.getResult());
event.setAuditResult(unloading_cabinet_back_processing.getDesc());
return;
case SEALING_CABINET_UMPIRE:
//封柜反审
event.setAuditType(closure_back_processing.getResult());
event.setAuditResult(closure_back_processing.getDesc());
return;
case AIR_SORTING:
// 排单分拣
event.setAuditType(sorting_processing.getResult());
event.setAuditResult(sorting_processing.getDesc());
return;
case AIR_SORTING_BACK:
// 排单分拣反审
event.setAuditType(sorting_back_processing.getResult());
event.setAuditResult(sorting_back_processing.getDesc());
return;
case AIR_TO_WAREHOUSE:
// 到仓
event.setAuditType(warehoused_processing.getResult());
event.setAuditResult(warehoused_processing.getDesc());
return;
case AIR_TO_WAREHOUSE_BACK:
// 到仓反审
event.setAuditType(warehoused_back_processing.getResult());
event.setAuditResult(warehoused_back_processing.getDesc());
return;
case AIR_SHIPMENT:
// 出货
event.setAuditType(shipment_processing.getResult());
event.setAuditResult(shipment_processing.getDesc());
return;
case AIR_SHIPMENT_BACK:
// 出货反审
event.setAuditType(shipment_back_processing.getResult());
event.setAuditResult(shipment_back_processing.getDesc());
return;
case CLEARANCE_BACK:
// 撤销清关
event.setAuditType(clearance_back_processing.getResult());
event.setAuditResult(clearance_back_processing.getDesc());
return;
default:
event.setIsExists(false);
}
}
}
}
...@@ -101,4 +101,6 @@ public interface BoxApprovalService extends IService<BoxApprovalDO> { ...@@ -101,4 +101,6 @@ public interface BoxApprovalService extends IService<BoxApprovalDO> {
Integer getBackApprovalType(Long shipmentId); Integer getBackApprovalType(Long shipmentId);
List<BoxApprovalDO> getBackApprovalList(List<Long> idList); List<BoxApprovalDO> getBackApprovalList(List<Long> idList);
List<BoxApprovalDO> checkOrderProcessingApproval(Long shipmentId, Long orderId);
} }
...@@ -1634,4 +1634,9 @@ public class BoxApprovalServiceImpl extends AbstractService<BoxApprovalMapper, B ...@@ -1634,4 +1634,9 @@ public class BoxApprovalServiceImpl extends AbstractService<BoxApprovalMapper, B
.in(BoxApprovalDO::getApprovalType, backTypeList) .in(BoxApprovalDO::getApprovalType, backTypeList)
); );
} }
@Override
public List<BoxApprovalDO> checkOrderProcessingApproval(Long shipmentId, Long orderId) {
return boxApprovalMapper.checkOrderProcessingApproval(shipmentId, orderId);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment