Explorar o código

订单新增分类字段,新增生产超领接口

fgd hai 1 ano
pai
achega
bc14984607
Modificáronse 26 ficheiros con 640 adicións e 24 borrados
  1. 46 0
      sd-business/src/main/java/com/sd/business/controller/production/ProductionExceedReceiveController.java
  2. 123 0
      sd-business/src/main/java/com/sd/business/entity/apply/vo/ApplyBuyBomAccessoryVo.java
  3. 33 2
      sd-business/src/main/java/com/sd/business/entity/excel/enums/ExcelTypeEnum.java
  4. 5 0
      sd-business/src/main/java/com/sd/business/entity/excel/po/ExcelGenerateLog.java
  5. 46 0
      sd-business/src/main/java/com/sd/business/entity/order/enums/OrderClassifyEnum.java
  6. 5 0
      sd-business/src/main/java/com/sd/business/entity/order/po/OrderInfo.java
  7. 12 0
      sd-business/src/main/java/com/sd/business/entity/production/dto/ProductionCostDto.java
  8. 32 0
      sd-business/src/main/java/com/sd/business/entity/production/dto/ProductionExceedReceiveDto.java
  9. 37 0
      sd-business/src/main/java/com/sd/business/entity/production/po/ProductionCost.java
  10. 12 0
      sd-business/src/main/java/com/sd/business/entity/production/vo/ProductionCostVo.java
  11. 18 0
      sd-business/src/main/java/com/sd/business/entity/statement/dto/DocumentInfoSelectDto.java
  12. 5 0
      sd-business/src/main/java/com/sd/business/entity/statement/dto/ExportDocumentDto.java
  13. 5 0
      sd-business/src/main/java/com/sd/business/entity/statement/dto/GetDocumentDto.java
  14. 5 0
      sd-business/src/main/java/com/sd/business/entity/warehouse/constant/WarehouseConstant.java
  15. 15 0
      sd-business/src/main/java/com/sd/business/mapper/production/ProductionCostMapper.java
  16. 10 4
      sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java
  17. 4 4
      sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java
  18. 4 2
      sd-business/src/main/java/com/sd/business/service/order/OrderService.java
  19. 8 0
      sd-business/src/main/java/com/sd/business/service/order/OrderSkuService.java
  20. 10 0
      sd-business/src/main/java/com/sd/business/service/order/impl/OrderExchangeServiceImpl.java
  21. 47 9
      sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java
  22. 25 0
      sd-business/src/main/java/com/sd/business/service/order/impl/OrderSkuServiceImpl.java
  23. 15 0
      sd-business/src/main/java/com/sd/business/service/production/ProductionCostService.java
  24. 6 0
      sd-business/src/main/java/com/sd/business/service/production/ProductionOrderService.java
  25. 19 0
      sd-business/src/main/java/com/sd/business/service/production/impl/ProductionCostServiceImpl.java
  26. 93 3
      sd-business/src/main/java/com/sd/business/service/production/impl/ProductionOrderServiceImpl.java

+ 46 - 0
sd-business/src/main/java/com/sd/business/controller/production/ProductionExceedReceiveController.java

@@ -0,0 +1,46 @@
+package com.sd.business.controller.production;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.sd.business.entity.order.vo.OrderSkuVo;
+import com.sd.business.entity.production.dto.ProductionExceedReceiveDto;
+import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.service.production.ProductionOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+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;
+
+import java.util.List;
+
+/**
+ * 生产超领
+ */
+@RestController
+@RequestMapping("/productionExceedReceive")
+public class ProductionExceedReceiveController {
+
+    @Autowired
+    private ProductionOrderService productionOrderService;
+
+    @Autowired
+    private OrderSkuService orderSkuService;
+
+    /**
+     * 生产超领
+     */
+    @PostMapping("/exceedReceive")
+    public void exceedReceive(@Validated @RequestBody ProductionExceedReceiveDto dto) {
+        productionOrderService.exceedReceive(dto);
+    }
+
+    /**
+     * 获取订单sku列表
+     */
+    @PostMapping("/getOrderSkuList")
+    public List<OrderSkuVo> getOrderSkuList(@RequestBody BaseSelectDto dto) {
+        return orderSkuService.getOrderSkuList(dto.getId());
+    }
+
+}

+ 123 - 0
sd-business/src/main/java/com/sd/business/entity/apply/vo/ApplyBuyBomAccessoryVo.java

@@ -0,0 +1,123 @@
+package com.sd.business.entity.apply.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.HeadFontStyle;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 申购单bom附件数据
+ */
+@Getter
+@Setter
+@HeadFontStyle(fontHeightInPoints = 12)
+public class ApplyBuyBomAccessoryVo {
+
+    /**
+     * 品号
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "C5料号", index = 0)
+    private String bomSpecCode;
+
+    /**
+     * 规格说明
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "规格说明", index = 1)
+    private String specification;
+
+    /**
+     * 品名
+     */
+    @ColumnWidth(25)
+    @ExcelProperty(value = "品种说明", index = 2)
+    private String bomSpecName;
+
+    /**
+     * 颜色
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "颜色说明", index = 3)
+    private String colour;
+
+    /**
+     * 库存数量
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "体育库存", index = 4)
+    private BigDecimal stockQuantity;
+
+    /**
+     * 在途数量
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "体育仓在途", index = 5)
+    private BigDecimal inTransitQuantity;
+
+    /**
+     * 当月销售
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "当月销售", index = 6)
+    private BigDecimal currentMonthSales;
+
+    /**
+     * 上个月销售
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "上个月销售", index = 7)
+    private BigDecimal lastMonthSales;
+
+    /**
+     * 上上个月销售
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "上上个月销售", index = 8)
+    private BigDecimal beforeLastMonthSales;
+
+    /**
+     * 月平均消耗
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "月平均消耗", index = 9)
+    private BigDecimal averageMonthSales;
+
+    /**
+     * 实际销量可消耗天数
+     */
+    @ColumnWidth(18)
+    @ExcelProperty(value = "实际销量可消耗天数", index = 10)
+    private BigDecimal actualSalesDays;
+
+    /**
+     * 短缺数量合计
+     */
+    @ColumnWidth(18)
+    @ExcelProperty(value = "短缺数量合计(实际销量)", index = 11)
+    private BigDecimal shortageQuantity;
+
+    /**
+     * 申购数量
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "申购数量", index = 12)
+    private BigDecimal applyBuyQuantity;
+
+    /**
+     * 备注
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "备注", index = 13)
+    private String remark;
+
+    /**
+     * 附注
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "附注", index = 14)
+    private String annotation;
+}

+ 33 - 2
sd-business/src/main/java/com/sd/business/entity/excel/enums/ExcelTypeEnum.java

@@ -1,17 +1,48 @@
 package com.sd.business.entity.excel.enums;
 
+import com.ruoyi.common.exception.ServiceException;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
+import java.util.HashMap;
+import java.util.Map;
+
 @Getter
 @AllArgsConstructor
 public enum ExcelTypeEnum {
 
-    DOCUMENT_BY_ORDER(1, "订单对账单"),
-    STATISTICS_DOCUMENT_BY_ORDER(2, "订单对账报表"),
+    DOCUMENT_BY_WLN_ORDER(1, "万里牛订单对账单"),
+    DOCUMENT_BY_PURCHASE_ORDER(2, "采购订单对账单"),
+    DOCUMENT_BY_OUTSOURCE_ORDER(3, "委外订单对账单"),
+    DOCUMENT_BY_AFTER_SALE_ORDER(4, "售后订单对账单"),
+    DOCUMENT_BY_NO_REASON_ORDER(5, "无理由订单对账单"),
+    STATISTICS_DOCUMENT_BY_WLN_ORDER(6, "万里牛订单对账报表"),
+    STATISTICS_DOCUMENT_BY_PURCHASE_ORDER(7, "采购订单对账报表"),
+    STATISTICS_DOCUMENT_BY_OUTSOURCE_ORDER(8, "委外订单对账报表"),
+    STATISTICS_DOCUMENT_BY_AFTER_SALE_ORDER(9, "售后订单对账报表"),
+    STATISTICS_DOCUMENT_BY_NO_REASON_ORDER(10, "无理由订单对账报表"),
     ;
 
     private final Integer type;
     private final String explain;
 
+    private static final Map<Integer, ExcelTypeEnum> map = new HashMap<>();
+
+    static {
+        for (ExcelTypeEnum excelTypeEnum : values()) {
+            map.put(excelTypeEnum.getType(), excelTypeEnum);
+        }
+    }
+
+    /**
+     * 通过key获取名称
+     */
+    public static ExcelTypeEnum get(Integer key) {
+        ExcelTypeEnum excelTypeEnum = map.get(key);
+        if (excelTypeEnum == null) {
+            throw new ServiceException("未知导出状态:" + key);
+        }
+        return excelTypeEnum;
+    }
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/excel/po/ExcelGenerateLog.java

@@ -31,6 +31,11 @@ public class ExcelGenerateLog extends BasePo {
     private Integer status;
 
     /**
+     * 对账单订单分类 1-万里牛订单,2-采购订单,3-委外订单,4-售后订单,5-无理由订单
+     */
+    private Integer orderClassify;
+
+    /**
      * excel文件名称
      */
     private String excelName;

+ 46 - 0
sd-business/src/main/java/com/sd/business/entity/order/enums/OrderClassifyEnum.java

@@ -0,0 +1,46 @@
+package com.sd.business.entity.order.enums;
+
+import com.ruoyi.common.exception.ServiceException;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 订单类型
+ */
+@Getter
+@AllArgsConstructor
+public enum OrderClassifyEnum {
+    WLN_ORDER(1, "万里牛订单"),
+    PURCHASE_ORDER(2, "采购订单"),
+    OUTSOURCE_ORDER(3, "委外订单"),
+    AFTER_SALE_ORDER(4, "售后订单"),
+    NO_REASON_ORDER(5, "无理由订单")
+
+    ;
+
+    private static final Map<Integer, OrderClassifyEnum> map = new HashMap<>();
+
+    static {
+        for (OrderClassifyEnum orderClassifyEnum : values()) {
+            map.put(orderClassifyEnum.getKey(), orderClassifyEnum);
+        }
+    }
+
+    private final Integer key;
+    private final String value;
+
+    /**
+     * 通过key获取名称
+     */
+    public static OrderClassifyEnum getEnum(Integer key) {
+        OrderClassifyEnum orderClassifyEnum = map.get(key);
+        if (orderClassifyEnum == null) {
+            throw new ServiceException("未知订单类型:" + key);
+        }
+        return orderClassifyEnum;
+    }
+
+}

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/order/po/OrderInfo.java

@@ -35,6 +35,11 @@ public class OrderInfo extends BasePo {
     private Integer type;
 
     /**
+     * 订单分类 1-万里牛订单,2-采购订单,3-委外订单,4-售后订单,5-无理由订单
+     */
+    private Integer classify;
+
+    /**
      * 事业部id
      */
     @NotNull(message = "事业部id不能为空")

+ 12 - 0
sd-business/src/main/java/com/sd/business/entity/production/dto/ProductionCostDto.java

@@ -0,0 +1,12 @@
+package com.sd.business.entity.production.dto;
+
+import com.sd.business.entity.production.po.ProductionCost;
+
+/**
+ * 生产成本新增编辑入参实体
+ *
+ * @author
+ * @since 2023-10-05
+ */
+public class ProductionCostDto extends ProductionCost {
+}

+ 32 - 0
sd-business/src/main/java/com/sd/business/entity/production/dto/ProductionExceedReceiveDto.java

@@ -0,0 +1,32 @@
+package com.sd.business.entity.production.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Getter
+@Setter
+public class ProductionExceedReceiveDto {
+    /**
+     * 订单id
+     */
+    @NotNull(message = "订单id不能为空")
+    private Long orderId;
+
+    /**
+     * 超领原因 1-制作损坏,2-裸垫质量不良
+     */
+    @NotNull(message = "超领原因不能为空")
+    private Integer exceedReceiveReason;
+
+    /**
+     * 订单sku超领明细
+     */
+    @Valid
+    @NotEmpty(message = "订单sku超领明细列表不能为空")
+    private List<ProductionCostDto> productionCostList;
+}

+ 37 - 0
sd-business/src/main/java/com/sd/business/entity/production/po/ProductionCost.java

@@ -0,0 +1,37 @@
+package com.sd.business.entity.production.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * <p>
+ * 生产任务
+ * </p>
+ *
+ * @author
+ * @since 2023-10-05
+ */
+@Getter
+@Setter
+@TableName("production_cost")
+public class ProductionCost extends BasePo {
+
+    /**
+     * 订单id
+     */
+    private Long orderId;
+
+    /**
+     * bom规格id
+     */
+    private Long bomSpecId;
+
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+}

+ 12 - 0
sd-business/src/main/java/com/sd/business/entity/production/vo/ProductionCostVo.java

@@ -0,0 +1,12 @@
+package com.sd.business.entity.production.vo;
+
+import com.sd.business.entity.production.po.ProductionCost;
+
+/**
+ * 生产成本查询返回值实体
+ *
+ * @author
+ * @since 2023-10-05
+ */
+public class ProductionCostVo extends ProductionCost {
+}

+ 18 - 0
sd-business/src/main/java/com/sd/business/entity/statement/dto/DocumentInfoSelectDto.java

@@ -0,0 +1,18 @@
+package com.sd.business.entity.statement.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 对账单详情查询入参实体
+ */
+@Getter
+@Setter
+public class DocumentInfoSelectDto extends BaseSelectDto {
+
+    /**
+     * 对账单订单分类 1-万里牛订单,2-采购订单,3-委外订单,4-售后订单,5-无理由订单
+     */
+    private Integer orderClassify;
+}

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/statement/dto/ExportDocumentDto.java

@@ -30,4 +30,9 @@ public class ExportDocumentDto {
      */
     private String endDate;
 
+    /**
+     * 订单分类 1-万里牛订单,2-采购订单,3-委外订单,4-售后订单,5-无理由订单
+     */
+    private Integer orderClassify;
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/statement/dto/GetDocumentDto.java

@@ -15,4 +15,9 @@ public class GetDocumentDto {
     @NotBlank(message = "对账单id集合不能为空")
     private String idGroupConcat;
 
+    /**
+     * 对账单订单分类 1-万里牛订单,2-采购订单,3-委外订单,4-售后订单,5-无理由订单
+     */
+    private Integer orderClassify;
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/warehouse/constant/WarehouseConstant.java

@@ -20,4 +20,9 @@ public interface WarehouseConstant {
      */
     Long PURCHASE_DEFECTIVE = 1684037092708990977L;
 
+    /**
+     * 生产次品仓
+     */
+    Long PRODUCTION_DEFECTIVE = 1684037092708990977L;
+
 }

+ 15 - 0
sd-business/src/main/java/com/sd/business/mapper/production/ProductionCostMapper.java

@@ -0,0 +1,15 @@
+package com.sd.business.mapper.production;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sd.business.entity.production.po.ProductionCost;
+
+/**
+ * <p>
+ * 生产成本 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-10-05
+ */
+public interface ProductionCostMapper extends BaseMapper<ProductionCost> {
+}

+ 10 - 4
sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java

@@ -104,13 +104,19 @@ public interface InventoryService extends BaseService<Inventory> {
     void purchaseInStorage(Long purchaseId, Long departmentId, Long warehouseId, List<? extends InOutFun> list);
 
     /**
-     * 锁定采购次品仓库存
+     * 锁定库存
+     * @param map 操作bom数量信息
+     * @param warehouseId 仓库id
+     * @return
      */
-    boolean lockPurchaseDefectiveStorage(Map<Long, BigDecimal> map);
+    boolean lockStorage(Map<Long, BigDecimal> map, Long warehouseId);
 
     /**
-     * 解锁采购次品仓库存
+     * 解锁库存
+     * @param map 操作bom数量信息
+     * @param warehouseId 仓库id
+     * @return
      */
-    void unlockPurchaseDefectiveStorage(Map<Long, BigDecimal> map);
+    void unlockStorage(Map<Long, BigDecimal> map, Long warehouseId);
 
 }

+ 4 - 4
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -474,7 +474,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     }
 
     @Override
-    public boolean lockPurchaseDefectiveStorage(Map<Long, BigDecimal> map) {
+    public boolean lockStorage(Map<Long, BigDecimal> map, Long warehouseId) {
         if (ObjectUtil.isEmpty(map)) {
             return true;
         }
@@ -482,7 +482,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
             List<Inventory> list = list(q -> q
                     .in(Inventory::getBomSpecId, map.keySet())
-                    .eq(Inventory::getWarehouseId, WarehouseConstant.PURCHASE_DEFECTIVE)
+                    .eq(Inventory::getWarehouseId, warehouseId)
                     .eq(Inventory::getDepartmentId, DepartmentConstant.SD_SPORTS)
             );
 
@@ -508,7 +508,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
 
     @Override
-    public void unlockPurchaseDefectiveStorage(Map<Long, BigDecimal> map) {
+    public void unlockStorage(Map<Long, BigDecimal> map, Long warehouseId) {
 
         if (ObjectUtil.isEmpty(map)) {
             return;
@@ -518,7 +518,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
             List<Inventory> list = list(q -> q
                     .in(Inventory::getBomSpecId, map.keySet())
-                    .eq(Inventory::getWarehouseId, WarehouseConstant.PURCHASE_DEFECTIVE)
+                    .eq(Inventory::getWarehouseId, warehouseId)
                     .eq(Inventory::getDepartmentId, DepartmentConstant.SD_SPORTS)
             );
 

+ 4 - 2
sd-business/src/main/java/com/sd/business/service/order/OrderService.java

@@ -12,6 +12,7 @@ import com.sd.business.entity.order.vo.OrderInfoVo;
 import com.sd.business.entity.order.vo.SkuSpecPriceVo;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * <p>
@@ -97,10 +98,11 @@ public interface OrderService extends BaseService<OrderInfo> {
      * 获取订单bom的出库数量
      *
      * @param bomSpecId bom规格id
-     * @param days      查询多少天前的数据
+     * @param startDate 开始时间
+     * @param endDate 结束时间
      * @return
      */
-    BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Integer days);
+    BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Date startDate, Date endDate);
 
     /**
      * 获取万里牛单号

+ 8 - 0
sd-business/src/main/java/com/sd/business/service/order/OrderSkuService.java

@@ -6,6 +6,8 @@ import com.sd.business.entity.order.dto.OrderSkuSelectDto;
 import com.sd.business.entity.order.po.OrderSku;
 import com.sd.business.entity.order.vo.OrderSkuVo;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -27,4 +29,10 @@ public interface OrderSkuService extends BaseService<OrderSku> {
      */
     String getOrderWlnCodeStr(OrderSkuSelectDto dto);
 
+    /**
+     * 获取订单sku列表
+     * @param orderId
+     * @return
+     */
+    List<OrderSkuVo> getOrderSkuList(Long orderId);
 }

+ 10 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderExchangeServiceImpl.java

@@ -15,6 +15,7 @@ import com.ruoyi.system.utils.UserUtil;
 import com.sd.business.entity.department.po.Department;
 import com.sd.business.entity.order.dto.OrderExchangeDto;
 import com.sd.business.entity.order.dto.OrderExchangeSelectDto;
+import com.sd.business.entity.order.enums.OrderClassifyEnum;
 import com.sd.business.entity.order.po.OrderExchange;
 import com.sd.business.entity.order.po.OrderExchangeDetail;
 import com.sd.business.entity.order.po.OrderInfo;
@@ -24,6 +25,7 @@ import com.sd.business.entity.order.vo.OrderExchangeVo;
 import com.sd.business.mapper.order.OrderExchangeMapper;
 import com.sd.business.service.order.OrderExchangeDetailService;
 import com.sd.business.service.order.OrderExchangeService;
+import com.sd.business.service.order.OrderService;
 import com.sd.business.service.order.OrderSkuService;
 import com.sd.business.service.sku.SkuSpecService;
 import com.sd.business.util.CodeEnum;
@@ -55,6 +57,9 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
     @Autowired
     private SkuSpecService skuSpecService;
 
+    @Autowired
+    private OrderService orderService;
+
     @Override
     public Page<OrderExchangeVo> getPage(OrderExchangeSelectDto dto) {
         IWrapper<OrderExchange> wrapper = getWrapper();
@@ -195,6 +200,11 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
         save(orderExchangeDto);
         orderExchangeDetailService.saveBatch(orderExchangeDetailList);
         ObsFileUtil.saveFile(orderExchangeDto.getFileList(), orderExchangeDto.getId());
+
+        // 订单分类修改为售后订单
+        orderService.update(q -> q
+                .set(OrderInfo::getClassify, OrderClassifyEnum.AFTER_SALE_ORDER.getKey())
+                .eq(BaseIdPo::getId, orderExchangeDto.getOrderInfoId()));
     }
 
     @Override

+ 47 - 9
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -2,7 +2,6 @@ package com.sd.business.service.order.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.convert.Convert;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSON;
@@ -19,6 +18,7 @@ import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.system.service.ISysRoleService;
 import com.ruoyi.system.service.ISysUserService;
 import com.sd.business.entity.bom.bo.BomSpecBo;
 import com.sd.business.entity.bom.po.Bom;
@@ -30,6 +30,7 @@ import com.sd.business.entity.in.emums.InOutTypeEnum;
 import com.sd.business.entity.in.po.InOutStorageBom;
 import com.sd.business.entity.inventory.po.Inventory;
 import com.sd.business.entity.order.dto.*;
+import com.sd.business.entity.order.enums.OrderClassifyEnum;
 import com.sd.business.entity.order.enums.OrderExceptionTypeEnum;
 import com.sd.business.entity.order.enums.OrderStatusEnum;
 import com.sd.business.entity.order.po.*;
@@ -118,6 +119,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     @Autowired
     private ProductionTaskService productionTaskService;
 
+    @Autowired
+    private ISysRoleService roleService;
+
     @Override
     public Page<OrderInfoVo> getPage(OrderSelectDto dto) {
         IWrapper<OrderInfo> wrapper = getWrapper();
@@ -272,6 +276,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         orderDto.setTaxRate(new BigDecimal("10.00"));
         orderDto.setTag("0");
         orderDto.setExceptionType(OrderExceptionTypeEnum.NORMAL.getKey().toString());
+        if (Objects.equals(orderDto.getType(), 2)) {
+            orderDto.setClassify(OrderClassifyEnum.OUTSOURCE_ORDER.getKey());
+        } else if (Objects.equals(orderDto.getType(), 1)) {
+            // 拥有采购角色的账号创建的自主订单为采购订单
+            Long userId = SecurityUtils.getUserId();
+            Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+                orderDto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
+            }
+        }
         this.save(orderDto);
 
         // 新增订单产品包材配件
@@ -331,6 +345,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     @DSTransactional
     @Override
     public void edit(OrderInfoDto dto) {
+        // 订单为委外订单时,订单分类为委外订单
+        if (Objects.equals(dto.getType(), 2)) {
+            dto.setClassify(OrderClassifyEnum.OUTSOURCE_ORDER.getKey());
+        } else if (Objects.equals(dto.getType(), 1)) {
+            // 拥有采购角色的账号创建的自主订单为采购订单
+            Long userId = dto.getCreateUser();
+            Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+                dto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
+            }
+        }
 
         // 更新订单
         this.updateById(dto);
@@ -409,6 +434,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
 
         // 更新订单
         dto.setStatus(OrderStatusEnum.STOCK_PREPARATION.getKey());
+        // 订单为委外订单时,订单分类为委外订单
+        if (Objects.equals(dto.getType(), 2)) {
+            dto.setClassify(OrderClassifyEnum.OUTSOURCE_ORDER.getKey());
+        } else if (Objects.equals(dto.getType(), 1)) {
+            // 拥有采购角色的账号创建的自主订单为采购订单
+            Long userId = dto.getCreateUser();
+            Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+                dto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
+            }
+        }
         this.updateById(dto);
 
         // 更新订单产品
@@ -606,6 +642,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         // 对已生产的订单生成对账单
         if (Arrays.asList(exceptionType.split(",")).contains(OrderExceptionTypeEnum.ORDER_CLOSURE.getKey().toString())
                 && ObjectUtil.equals(orderInfo.getStatus(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey())) {
+            // 订单分类修改为无理由订单
+            update(q -> q
+                    .eq(BaseIdPo::getId, orderInfo.getId())
+                    .set(OrderInfo::getClassify, OrderClassifyEnum.NO_REASON_ORDER.getKey())
+            );
             StatementOfAccountDto statement = new StatementOfAccountDto();
             statement.setDepartmentId(orderInfo.getDepartmentId());
             statement.setOrderIdList(Collections.singletonList(orderInfo.getId()));
@@ -740,12 +781,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     }
 
     @Override
-    public BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Integer days) {
-        Date date = DateUtil.date();
-        Date offsetDay = DateUtil.offsetDay(date, -days);
-
+    public BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Date startDate, Date endDate) {
         // 根据对账时间获取有对账单的订单
-        List<StatementOfAccount> list = statementOfAccountService.list(q -> q.ge(StatementOfAccount::getTimePeriod, offsetDay));
+        List<StatementOfAccount> list = statementOfAccountService.list(q -> q.between(StatementOfAccount::getTimePeriod, startDate, endDate));
         List<Long> accountIds = list.stream().map(StatementOfAccount::getId).collect(Collectors.toList());
 
         Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(Collections.singleton(bomSpecId));
@@ -776,14 +814,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     public Boolean isExistOrderSkuBom(Long orderId) {
         OrderInfo orderInfo = this.getById(orderId);
         if (!ObjectUtil.equals(orderInfo.getType(), 2)) {
-            return false;
+            return true;
         }
-        boolean flag = 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 = false;
+                flag = true;
             }
         }
         return flag;

+ 25 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderSkuServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sd.business.service.order.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -14,7 +15,10 @@ import com.sd.business.entity.order.po.OrderSku;
 import com.sd.business.entity.order.vo.OrderSkuVo;
 import com.sd.business.entity.sku.po.SkuSpec;
 import com.sd.business.mapper.order.OrderSkuMapper;
+import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.service.sku.SkuSpecService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -32,6 +36,12 @@ import java.util.stream.Collectors;
 @Service
 public class OrderSkuServiceImpl extends ServiceImpl<OrderSkuMapper, OrderSku> implements OrderSkuService {
 
+    @Autowired
+    private SkuSpecService skuSpecService;
+
+    @Autowired
+    private BomSpecService bomSpecService;
+
     @Override
     public Page<OrderSkuVo> getPage(OrderSkuSelectDto dto) {
         IWrapper<OrderSku> wrapper = getWrapper();
@@ -68,4 +78,19 @@ public class OrderSkuServiceImpl extends ServiceImpl<OrderSkuMapper, OrderSku> i
         return JSON.toJSONString(wlnCodeList);
     }
 
+    @Override
+    public List<OrderSkuVo> getOrderSkuList(Long orderId) {
+        List<OrderSku> tempOrderSkuList = this.list(q -> q.eq(OrderSku::getOrderId, orderId));
+        List<OrderSkuVo> orderSkuList = BeanUtil.copyToList(tempOrderSkuList, OrderSkuVo.class);
+        skuSpecService.attributeAssign(orderSkuList, OrderSkuVo::getSkuSpecId, (item, skuSpec) -> {
+            item.setName(skuSpec.getName());
+            item.setCode(skuSpec.getCode());
+        });
+        bomSpecService.attributeAssign(orderSkuList, OrderSkuVo::getBomSpecId, (item, bomSpec) -> {
+            item.setBomName(bomSpec.getName());
+            item.setBomCode(bomSpec.getCode());
+        });
+        return orderSkuList;
+    }
+
 }

+ 15 - 0
sd-business/src/main/java/com/sd/business/service/production/ProductionCostService.java

@@ -0,0 +1,15 @@
+package com.sd.business.service.production;
+
+import com.ruoyi.common.core.service.BaseService;
+import com.sd.business.entity.production.po.ProductionCost;
+
+/**
+ * <p>
+ * 生产成本 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-10-05
+ */
+public interface ProductionCostService extends BaseService<ProductionCost> {
+}

+ 6 - 0
sd-business/src/main/java/com/sd/business/service/production/ProductionOrderService.java

@@ -2,6 +2,7 @@ package com.sd.business.service.production;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.sd.business.entity.production.dto.ProductionExceedReceiveDto;
 import com.sd.business.entity.production.dto.ProductionOrderDto;
 import com.sd.business.entity.production.dto.RapidPackagingDto;
 import com.sd.business.entity.production.dto.SetTagDto;
@@ -30,4 +31,9 @@ public interface ProductionOrderService {
      */
     void rapidPackaging(RapidPackagingDto dto);
 
+    /**
+     * 生产超领
+     * @param dto
+     */
+    void exceedReceive(ProductionExceedReceiveDto dto);
 }

+ 19 - 0
sd-business/src/main/java/com/sd/business/service/production/impl/ProductionCostServiceImpl.java

@@ -0,0 +1,19 @@
+package com.sd.business.service.production.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sd.business.entity.production.po.ProductionCost;
+import com.sd.business.mapper.production.ProductionCostMapper;
+import com.sd.business.service.production.ProductionCostService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 生产成本 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2023-10-05
+ */
+@Service
+public class ProductionCostServiceImpl extends ServiceImpl<ProductionCostMapper, ProductionCost> implements ProductionCostService {
+}

+ 93 - 3
sd-business/src/main/java/com/sd/business/service/production/impl/ProductionOrderServiceImpl.java

@@ -1,29 +1,40 @@
 package com.sd.business.service.production.impl;
 
+import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.sd.business.entity.department.constant.DepartmentConstant;
+import com.sd.business.entity.in.dto.InOutStorageDto;
+import com.sd.business.entity.in.emums.InDetailTypeEnum;
+import com.sd.business.entity.in.emums.InOutTypeEnum;
+import com.sd.business.entity.in.emums.OutDetailTypeEnum;
+import com.sd.business.entity.in.po.InOutStorageBom;
 import com.sd.business.entity.order.enums.OrderStatusEnum;
 import com.sd.business.entity.order.po.OrderInfo;
 import com.sd.business.entity.order.po.OrderPackageBom;
 import com.sd.business.entity.order.po.OrderSku;
-import com.sd.business.entity.production.dto.ProductionOrderDto;
-import com.sd.business.entity.production.dto.RapidPackagingDto;
-import com.sd.business.entity.production.dto.SetTagDto;
+import com.sd.business.entity.production.dto.*;
+import com.sd.business.entity.production.po.ProductionCost;
 import com.sd.business.entity.production.po.ProductionTask;
 import com.sd.business.entity.production.vo.ProductionOrderDetailVo;
 import com.sd.business.entity.production.vo.ProductionOrderScheduleVo;
 import com.sd.business.entity.production.vo.ProductionOrderVo;
 import com.sd.business.entity.statement.dto.StatementOfAccountDto;
+import com.sd.business.entity.warehouse.constant.WarehouseConstant;
 import com.sd.business.mapper.production.ProductionOrderMapper;
 import com.sd.business.service.bom.BomSpecService;
+import com.sd.business.service.in.InOutStorageService;
+import com.sd.business.service.inventory.InventoryService;
 import com.sd.business.service.order.OrderPackageBomService;
 import com.sd.business.service.order.OrderService;
 import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.service.production.ProductionCostService;
 import com.sd.business.service.production.ProductionOrderService;
 import com.sd.business.service.production.ProductionTaskService;
 import com.sd.business.service.sku.SkuService;
@@ -32,7 +43,9 @@ import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -67,6 +80,15 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
     @Autowired
     private StatementOfAccountService statementOfAccountService;
 
+    @Autowired
+    private InventoryService inventoryService;
+
+    @Autowired
+    private InOutStorageService inOutStorageService;
+
+    @Autowired
+    private ProductionCostService productionCostService;
+
     @Override
     public Page<ProductionOrderVo> getPage(ProductionOrderDto dto) {
 
@@ -169,6 +191,74 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
         statementOfAccountService.add(statement);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void exceedReceive(ProductionExceedReceiveDto dto) {
+        Long orderId = dto.getOrderId();
+        OrderInfo orderInfo = orderService.getById(orderId);
+        if (orderInfo == null) {
+            throw new ServiceException("未知订单");
+        }
+        if (!Objects.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey())) {
+            throw new ServiceException("操作失败,请选择生产中的订单");
+        }
+        List<ProductionCostDto> productionCostList = dto.getProductionCostList();
+        Map<Long, BigDecimal> map = productionCostList.stream()
+                .filter(item -> item.getQuantity() != null
+                        && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
+                .collect(Collectors.toMap(
+                        ProductionCostDto::getBomSpecId,
+                        ProductionCostDto::getQuantity,
+                        BigDecimal::add
+                ));
+        boolean result = inventoryService.lockStorage(map, WarehouseConstant.SEMI_FINISHED_PRODUCT);
+        if (!result) {
+            throw new ServiceException("库存不足,超领失败!");
+        }
+        // 出入库信息
+        List<InOutStorageBom> inOutStorageBomList = map.keySet().stream().map(item -> {
+            InOutStorageBom inOutStorageBom = new InOutStorageBom();
+            inOutStorageBom.setBomSpecId(item);
+            inOutStorageBom.setQuantity(map.get(item));
+            return inOutStorageBom;
+        }).collect(Collectors.toList());
+        // 出库
+        InOutStorageDto lockPurchaseDefective = new InOutStorageDto();
+        lockPurchaseDefective.setType(InOutTypeEnum.OUT.getKey());
+        lockPurchaseDefective.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
+        lockPurchaseDefective.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
+        lockPurchaseDefective.setDepartmentId(DepartmentConstant.SD_SPORTS);
+        lockPurchaseDefective.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
+        lockPurchaseDefective.setRemark("订单超领出库");
+        lockPurchaseDefective.setLockStorage(StatusConstant.YES);
+        lockPurchaseDefective.setInOutStorageBomList(JSON.parseArray(JSON.toJSONString(inOutStorageBomList), InOutStorageBom.class));
+        inOutStorageService.add(lockPurchaseDefective);
+        // 入库
+        InOutStorageDto inStorageDto = new InOutStorageDto();
+        inStorageDto.setType(InOutTypeEnum.IN.getKey());
+        inStorageDto.setDetailType(InDetailTypeEnum.ABANDON.getKey());
+        // 制作损坏入库到生产次品仓,裸垫质量不良入库到采购次品仓
+        if (Objects.equals(dto.getExceedReceiveReason(), 1)) {
+            inStorageDto.setWarehouseId(WarehouseConstant.PRODUCTION_DEFECTIVE);
+        } else {
+            inStorageDto.setWarehouseId(WarehouseConstant.PURCHASE_DEFECTIVE);
+        }
+        inStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
+        inStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
+        inStorageDto.setRemark("订单超领报废入库");
+        inStorageDto.setInOutStorageBomList(inOutStorageBomList);
+        inOutStorageService.add(inStorageDto);
+        // 人为损坏, 新增生产成本表
+        if (Objects.equals(dto.getExceedReceiveReason(), 1)) {
+            List<ProductionCost> tempProductionCostList = productionCostList.stream()
+                    .filter(item -> item.getQuantity() != null
+                            && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
+                    .map(item -> (ProductionCost) item)
+                    .collect(Collectors.toList());
+            productionCostService.saveBatch(tempProductionCostList);
+        }
+    }
+
     private List<ProductionOrderDetailVo.SkuSpec> getSkuSpecList(Long orderId) {
 
         // 获取订单sku规格