|
@@ -0,0 +1,155 @@
|
|
|
+package com.sd.business.flow;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.sd.business.entity.order.dto.OrderInfoDto;
|
|
|
+import com.sd.business.entity.order.dto.OrderSkuDto;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderFlowExample;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.service.order.OrderFlowExampleService;
|
|
|
+import com.sd.business.service.order.OrderInfoService;
|
|
|
+import com.sd.business.service.production.ProductionWorkOrderService;
|
|
|
+import com.sd.mq.config.ArtworkConfig;
|
|
|
+import com.sd.mq.entity.TempArtworkMessage;
|
|
|
+import com.sd.mq.util.RabbitMqUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发起采购流程
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrderFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderInfoService orderInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderFlowExampleService orderFlowExampleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionWorkOrderService productionWorkOrderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "order";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+
|
|
|
+ OrderInfoDto dto = submitData.toJavaObject(OrderInfoDto.class);
|
|
|
+ dto.setFlowId(flowId);
|
|
|
+ dto.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+
|
|
|
+ if (dto.getId() == null) {
|
|
|
+ orderInfoService.add(dto);
|
|
|
+ } else {
|
|
|
+ orderInfoService.edit(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderFlowExample orderFlowExample = new OrderFlowExample();
|
|
|
+ orderFlowExample.setOrderId(dto.getId());
|
|
|
+ orderFlowExample.setFlowId(flowId);
|
|
|
+ orderFlowExample.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ orderFlowExampleService.save(orderFlowExample);
|
|
|
+ return dto.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+ OrderInfoDto dto = submitData.toJavaObject(OrderInfoDto.class);
|
|
|
+ orderInfoService.edit(dto);
|
|
|
+
|
|
|
+ // 查询委外订单是否存在包材
|
|
|
+ Boolean isExist = orderInfoService.isExistOrderSkuBom(businessId);
|
|
|
+
|
|
|
+ orderInfoService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, businessId)
|
|
|
+ .set(OrderInfo::getFlowStatus, FlowStatusEnum.PASS.getKey())
|
|
|
+ // 委外订单不存在包材则直接修改为生产中
|
|
|
+ .set(OrderInfo::getStatus, !isExist ? OrderStatusEnum.IN_PRODUCTION.getKey() : OrderStatusEnum.STOCK_PREPARATION.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!isExist) {
|
|
|
+ // 生成生产任务和工单
|
|
|
+ productionWorkOrderService.addByOrderId(businessId);
|
|
|
+ }
|
|
|
+
|
|
|
+ orderFlowExampleService.update(q -> q.eq(OrderFlowExample::getOrderId, businessId)
|
|
|
+ .eq(OrderFlowExample::getFlowId, flowId)
|
|
|
+ .set(OrderFlowExample::getFlowStatus, FlowStatusEnum.PASS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId()));
|
|
|
+
|
|
|
+ sendMq(dto);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void returnToOriginator(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ orderInfoService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, businessId)
|
|
|
+ .set(OrderInfo::getFlowStatus, flowStatus.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ orderFlowExampleService.update(q -> q.eq(OrderFlowExample::getOrderId, businessId)
|
|
|
+ .eq(OrderFlowExample::getFlowId, flowId)
|
|
|
+ .set(OrderFlowExample::getFlowStatus, flowStatus.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
+ OrderInfoDto dto = submitData.toJavaObject(OrderInfoDto.class);
|
|
|
+ dto.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ orderInfoService.edit(dto);
|
|
|
+ orderFlowExampleService.update(q -> q.eq(OrderFlowExample::getOrderId, businessId)
|
|
|
+ .eq(OrderFlowExample::getFlowId, flowId)
|
|
|
+ .set(OrderFlowExample::getFlowStatus, FlowStatusEnum.IN_PROGRESS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ returnToOriginator(flowId, businessId, flowStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ returnToOriginator(flowId, businessId, flowStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void sendMq(OrderInfoDto dto) {
|
|
|
+
|
|
|
+ List<OrderSkuDto> orderSkuList = dto.getOrderSkuList();
|
|
|
+
|
|
|
+ for (OrderSkuDto orderSkuDto : orderSkuList) {
|
|
|
+
|
|
|
+ if (orderSkuDto.getArtworkLibraryId() == null || orderSkuDto.getArtworkLibraryId() == 0L) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ TempArtworkMessage tempArtworkMessage = new TempArtworkMessage();
|
|
|
+ tempArtworkMessage.setImgUrl(orderSkuDto.getBlueprint());
|
|
|
+ tempArtworkMessage.setFileUrl(orderSkuDto.getProductionDocument());
|
|
|
+
|
|
|
+ RabbitMqUtil.send(ArtworkConfig.DIRECT_EXCHANGE_NAME, ArtworkConfig.TEMP_ARTWORK_QUEUE_NAME, tempArtworkMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|