24282 1 gadu atpakaļ
vecāks
revīzija
c5e80b7a1d

+ 71 - 0
sd-business/src/main/java/com/sd/business/controller/order/OrderFlowExampleController.java

@@ -0,0 +1,71 @@
+package com.sd.business.controller.order;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.sd.business.entity.order.dto.OrderFlowExampleDto;
+import com.sd.business.entity.order.dto.OrderFlowExampleSelectDto;
+import com.sd.business.entity.order.vo.OrderFlowExampleVo;
+import com.sd.business.service.order.OrderFlowExampleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * <p>
+ * 订单流程 关联 前端控制器
+ * </p>
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@RestController
+@RequestMapping("/orderFlowExample")
+public class OrderFlowExampleController {
+
+    @Autowired
+    private OrderFlowExampleService orderFlowExampleService;
+
+    /**
+     * 订单流程 关联分页
+     */
+    @PostMapping("/page")
+    public Page<OrderFlowExampleVo> page(@RequestBody OrderFlowExampleSelectDto dto) {
+        return orderFlowExampleService.getPage(dto);
+    }
+
+    /**
+     * 订单流程 关联明细
+     */
+    @PostMapping("/detail")
+    public OrderFlowExampleVo detail(@RequestBody BaseSelectDto dto) {
+        return orderFlowExampleService.detail(dto.getId());
+    }
+
+    /**
+     * 订单流程 关联新增
+     */
+    @PostMapping("/add")
+    public void add(@RequestBody OrderFlowExampleDto dto) {
+        orderFlowExampleService.add(dto);
+    }
+
+    /**
+     * 订单流程 关联编辑
+     */
+    @PostMapping("/edit")
+    public void edit(@RequestBody OrderFlowExampleDto dto) {
+        orderFlowExampleService.edit(dto);
+    }
+
+    /**
+     * 订单流程 关联删除
+     */
+    @PostMapping("/delete")
+    public void delete(@RequestBody BaseSelectDto dto) {
+        orderFlowExampleService.delete(dto.getId());
+    }
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/entity/order/dto/OrderFlowExampleDto.java

@@ -0,0 +1,17 @@
+package com.sd.business.entity.order.dto;
+
+import com.sd.business.entity.order.po.OrderFlowExample;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 订单流程 关联新增编辑入参实体
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@Getter
+@Setter
+public class OrderFlowExampleDto extends OrderFlowExample {
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/entity/order/dto/OrderFlowExampleSelectDto.java

@@ -0,0 +1,17 @@
+package com.sd.business.entity.order.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 订单流程 关联列表查询入参实体
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@Getter
+@Setter
+public class OrderFlowExampleSelectDto extends BaseSelectDto {
+
+}

+ 36 - 0
sd-business/src/main/java/com/sd/business/entity/order/po/OrderFlowExample.java

@@ -0,0 +1,36 @@
+package com.sd.business.entity.order.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 订单流程 关联
+ * </p>
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@Getter
+@Setter
+@TableName("order_flow_example")
+public class OrderFlowExample extends BasePo {
+
+    /**
+     * 订单id
+     */
+    private Long orderId;
+
+    /**
+     * 流程id
+     */
+    private Long flowId;
+
+    /**
+     * 流程状态 0未发起 1进行中 2已通过 3已驳回 4已作废
+     */
+    private Integer flowStatus;
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/entity/order/vo/OrderFlowExampleVo.java

@@ -0,0 +1,17 @@
+package com.sd.business.entity.order.vo;
+
+import com.sd.business.entity.order.po.OrderFlowExample;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 订单流程 关联列表查询返回值实体
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@Getter
+@Setter
+public class OrderFlowExampleVo extends OrderFlowExample {
+
+}

+ 89 - 0
sd-business/src/main/java/com/sd/business/flow/OrderDeleteFlow.java

@@ -0,0 +1,89 @@
+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.BasePo;
+import com.ruoyi.common.utils.SecurityUtils;
+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.framework.util.Assert;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+/**
+ * 发起订单删除流程
+ */
+@Service
+public class OrderDeleteFlow extends FlowDelegate {
+
+    @Autowired
+    private OrderInfoService orderInfoService;
+
+    @Autowired
+    private OrderFlowExampleService orderFlowExampleService;
+
+    @Override
+    public String getFlowKey() {
+        return "order_delete";
+    }
+
+    @Override
+    public Long start(Long flowId, JSONObject submitData) {
+        Object id = submitData.get("id");
+        Assert.notNull(id, "订单Id不能为空");
+        OrderInfo orderInfo = orderInfoService.getById(Long.parseLong(id.toString()));
+        Assert.notNull(orderInfo, "未找到订单");
+
+        OrderFlowExample orderFlowExample = new OrderFlowExample();
+        orderFlowExample.setOrderId(orderInfo.getId());
+        orderFlowExample.setFlowId(flowId);
+        orderFlowExample.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
+        orderFlowExampleService.save(orderFlowExample);
+
+        return orderInfo.getId();
+    }
+
+    @Override
+    public void end(Long flowId, Long businessId, JSONObject submitData) {
+        orderInfoService.deleteAndStore(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()));
+    }
+
+
+    @Override
+    public void returnToOriginator(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+        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) {
+        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);
+    }
+}

+ 155 - 0
sd-business/src/main/java/com/sd/business/flow/OrderFlow.java

@@ -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);
+        }
+    }
+
+}

+ 16 - 0
sd-business/src/main/java/com/sd/business/mapper/order/OrderFlowExampleMapper.java

@@ -0,0 +1,16 @@
+package com.sd.business.mapper.order;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sd.business.entity.order.po.OrderFlowExample;
+
+/**
+ * <p>
+ * 订单流程 关联 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-12-14
+ */
+public interface OrderFlowExampleMapper extends BaseMapper<OrderFlowExample> {
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/service/order/OrderFlowExampleService.java

@@ -0,0 +1,17 @@
+package com.sd.business.service.order;
+
+import com.ruoyi.common.core.service.BaseService;
+import com.sd.business.entity.order.po.OrderFlowExample;
+
+
+/**
+ * <p>
+ * 订单流程 关联 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-12-14
+ */
+public interface OrderFlowExampleService extends BaseService<OrderFlowExample> {
+
+}

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/order/OrderInfoService.java

@@ -58,4 +58,9 @@ public interface OrderInfoService extends BaseService<OrderInfo> {
      */
     void confirmation(OrderInfoDto dto);
 
+    /**
+     * 订单是否存在包材
+     */
+    Boolean isExistOrderSkuBom(Long orderId);
+
 }

+ 21 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderFlowExampleServiceImpl.java

@@ -0,0 +1,21 @@
+package com.sd.business.service.order.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sd.business.entity.order.po.OrderFlowExample;
+import com.sd.business.mapper.order.OrderFlowExampleMapper;
+import com.sd.business.service.order.OrderFlowExampleService;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * <p>
+ * 订单流程 关联 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2023-12-14
+ */
+@Service
+public class OrderFlowExampleServiceImpl extends ServiceImpl<OrderFlowExampleMapper, OrderFlowExample> implements OrderFlowExampleService {
+
+}

+ 17 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderInfoServiceImpl.java

@@ -718,6 +718,23 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
         sendMq(dto);
     }
 
+    @Override
+    public Boolean isExistOrderSkuBom(Long orderId) {
+        OrderInfo orderInfo = this.getById(orderId);
+        if (!ObjectUtil.equals(orderInfo.getType(), 2)) {
+            return true;
+        }
+        boolean flag = false;
+        List<OrderSku> list = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderInfo.getId()));
+        for (OrderSku orderSku : list) {
+            long count = orderSkuBomService.count(q -> q.eq(OrderSkuBom::getOrderSkuId, orderSku.getId()));
+            if (count != 0) {
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
     /**
      * 解锁库存
      */

+ 5 - 0
sd-business/src/main/resources/mapper/order/OrderFlowExampleMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sd.business.mapper.order.OrderFlowExampleMapper">
+
+</mapper>