瀏覽代碼

生产备料

yzc 1 年之前
父節點
當前提交
1bf21b83df

+ 3 - 3
code/src/test/java/MesDataSource.java

@@ -4,9 +4,9 @@ public class MesDataSource {
 
     public static void main(String[] args) {
         GeneratorApplication.builder()
-                .url("jdbc:mysql://36.134.91.96:17330/bytesailing_mes?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true")
-                .username("fjhx2012mysql")
-                .password("3PN-Mzn#vnP&q6d")
+                .url(DataSourceInfo.URL)
+                .username(DataSourceInfo.USER_NAME)
+                .password(DataSourceInfo.PASSWORD)
                 .port(9989)
                 .module("hx-mes")
                 .parent("com.fjhx.mes")

+ 14 - 8
hx-item/src/main/java/com/fjhx/item/controller/product/ProductBomInfoController.java

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 
 /**
@@ -72,15 +73,20 @@ public class ProductBomInfoController {
     public void edit(@RequestBody ProductBomInfoDto dto) {
         Assert.notEmpty(dto.getId(), "产品id不能为空");
 
-        productInfoService.update(q -> q
-                .eq(ProductInfo::getId, dto.getId())
-                .set(ProductInfo::getRawMaterialId, dto.getRawMaterialId())
-                .set(ProductInfo::getUpdateTime, new Date())
-                .set(ProductInfo::getUpdateUser, SecurityUtils.getUserId())
-        );
-
         List<ProductBomDetail> productBomDetailList = dto.getProductBomDetailList();
-        productBomDetailList.forEach(item -> item.setProductId(dto.getId()));
+        for (ProductBomDetail productBomDetail : productBomDetailList) {
+            productBomDetail.setProductId(dto.getId());
+
+            //赋值原材料
+            if (Objects.equals(productBomDetail.getType(), 1)) {
+                productInfoService.update(q -> q
+                        .eq(ProductInfo::getId, dto.getId())
+                        .set(ProductInfo::getRawMaterialId, productBomDetail.getMaterialId())
+                        .set(ProductInfo::getUpdateTime, new Date())
+                        .set(ProductInfo::getUpdateUser, SecurityUtils.getUserId())
+                );
+            }
+        }
 
         productBomDetailService.editLinked(productBomDetailList, ProductBomDetail::getProductId, dto.getId());
     }

+ 5 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/po/ProductBomDetail.java

@@ -35,4 +35,9 @@ public class ProductBomDetail extends BasePo {
      */
     private BigDecimal quantity;
 
+    /**
+     * 1原材料 2包材辅材
+     */
+    private Integer type;
+
 }

+ 37 - 0
hx-mes/src/main/java/com/fjhx/mes/controller/material/MaterialPreparationController.java

@@ -0,0 +1,37 @@
+package com.fjhx.mes.controller.material;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.material.dto.MaterialPreparationSelectDto;
+import com.fjhx.mes.entity.material.vo.MaterialPreparationVo;
+import com.fjhx.mes.service.material.MaterialPreparationService;
+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 2024-01-11
+ */
+@RestController
+@RequestMapping("/materialPreparation")
+public class MaterialPreparationController {
+
+    @Autowired
+    private MaterialPreparationService materialPreparationService;
+
+    /**
+     * 生产备料分页
+     */
+    @PostMapping("/page")
+    public Page<MaterialPreparationVo> page(@RequestBody MaterialPreparationSelectDto dto) {
+        return materialPreparationService.getPage(dto);
+    }
+
+}

+ 17 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/material/dto/MaterialPreparationDto.java

@@ -0,0 +1,17 @@
+package com.fjhx.mes.entity.material.dto;
+
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 生产备料新增编辑入参实体
+ *
+ * @author
+ * @since 2024-01-11
+ */
+@Getter
+@Setter
+public class MaterialPreparationDto extends MaterialPreparation {
+
+}

+ 22 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/material/dto/MaterialPreparationSelectDto.java

@@ -0,0 +1,22 @@
+package com.fjhx.mes.entity.material.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 生产备料列表查询入参实体
+ *
+ * @author
+ * @since 2024-01-11
+ */
+@Getter
+@Setter
+public class MaterialPreparationSelectDto extends BaseSelectDto {
+
+    /**
+     * 备料状态 0未备料 1已备料
+     */
+    private Integer status;
+
+}

+ 69 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/material/po/MaterialPreparation.java

@@ -0,0 +1,69 @@
+package com.fjhx.mes.entity.material.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * <p>
+ * 生产备料
+ * </p>
+ *
+ * @author
+ * @since 2024-01-11
+ */
+@Getter
+@Setter
+@TableName("material_preparation")
+public class MaterialPreparation extends BasePo {
+
+    /**
+     * 合同id
+     */
+    private Long contractId;
+
+    /**
+     * 合同明细id
+     */
+    private Long contractDetailId;
+
+    /**
+     * 生产订单id
+     */
+    private Long productionOrderId;
+
+    /**
+     * 生产订单明细id
+     */
+    private Long productionOrderDetailId;
+
+    /**
+     * 物料id
+     */
+    private Long materialId;
+
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 备料期限
+     */
+    private Date preparationDeadline;
+
+    /**
+     * 投产时间
+     */
+    private Date productionTime;
+
+    /**
+     * 备料状态 0未备料 1已备料
+     */
+    private Integer status;
+
+}

+ 26 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/material/vo/MaterialPreparationVo.java

@@ -0,0 +1,26 @@
+package com.fjhx.mes.entity.material.vo;
+
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 生产备料列表查询返回值实体
+ *
+ * @author
+ * @since 2024-01-11
+ */
+@Getter
+@Setter
+public class MaterialPreparationVo extends MaterialPreparation {
+
+    /**
+     * 物料名称
+     */
+    private String materialName;
+    /**
+     * 物料编号
+     */
+    private String materialCode;
+
+}

+ 26 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/material/MaterialPreparationMapper.java

@@ -0,0 +1,26 @@
+package com.fjhx.mes.mapper.material;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
+import com.fjhx.mes.entity.material.vo.MaterialPreparationVo;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Param;
+
+
+/**
+ * <p>
+ * 生产备料 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2024-01-11
+ */
+public interface MaterialPreparationMapper extends BaseMapper<MaterialPreparation> {
+
+    /**
+     * 生产备料分页
+     */
+    Page<MaterialPreparationVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<MaterialPreparation> wrapper);
+
+}

+ 25 - 0
hx-mes/src/main/java/com/fjhx/mes/service/material/MaterialPreparationService.java

@@ -0,0 +1,25 @@
+package com.fjhx.mes.service.material;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.material.dto.MaterialPreparationSelectDto;
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
+import com.fjhx.mes.entity.material.vo.MaterialPreparationVo;
+import com.ruoyi.common.core.service.BaseService;
+
+
+/**
+ * <p>
+ * 生产备料 服务类
+ * </p>
+ *
+ * @author
+ * @since 2024-01-11
+ */
+public interface MaterialPreparationService extends BaseService<MaterialPreparation> {
+
+    /**
+     * 生产备料分页
+     */
+    Page<MaterialPreparationVo> getPage(MaterialPreparationSelectDto dto);
+
+}

+ 52 - 0
hx-mes/src/main/java/com/fjhx/mes/service/material/impl/MaterialPreparationServiceImpl.java

@@ -0,0 +1,52 @@
+package com.fjhx.mes.service.material.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.item.service.product.ProductInfoService;
+import com.fjhx.mes.entity.material.dto.MaterialPreparationSelectDto;
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
+import com.fjhx.mes.entity.material.vo.MaterialPreparationVo;
+import com.fjhx.mes.mapper.material.MaterialPreparationMapper;
+import com.fjhx.mes.service.material.MaterialPreparationService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.common.utils.wrapper.SqlField;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * <p>
+ * 生产备料 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2024-01-11
+ */
+@Service
+public class MaterialPreparationServiceImpl extends ServiceImpl<MaterialPreparationMapper, MaterialPreparation> implements MaterialPreparationService {
+
+    @Autowired
+    private ProductInfoService productInfoService;
+
+    @Override
+    public Page<MaterialPreparationVo> getPage(MaterialPreparationSelectDto dto) {
+        IWrapper<MaterialPreparation> wrapper = getWrapper();
+
+        wrapper.eq(MaterialPreparation::getStatus, dto.getStatus());
+
+        //时间范围过滤
+        wrapper.ge("mp", MaterialPreparation::getCreateTime, dto.getBeginTime());
+        wrapper.le("mp", MaterialPreparation::getCreateTime, dto.getEndTime());
+
+        //关键字过滤
+        wrapper.keyword(dto.getKeyword(), new SqlField("pi.code"));
+
+        wrapper.orderByDesc("mp", MaterialPreparation::getCreateTime);
+        wrapper.orderByDesc("mp", MaterialPreparation::getId);
+
+        Page<MaterialPreparationVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+
+        return page;
+    }
+
+}

+ 44 - 0
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderServiceImpl.java

@@ -6,7 +6,11 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.utils.Assert;
+import com.fjhx.item.entity.product.po.ProductBomDetail;
+import com.fjhx.item.entity.product.po.ProductInfo;
+import com.fjhx.item.service.product.ProductBomDetailService;
 import com.fjhx.item.service.product.ProductInfoService;
+import com.fjhx.mes.entity.material.po.MaterialPreparation;
 import com.fjhx.mes.entity.production.dto.ProduceOrderSelectDto;
 import com.fjhx.mes.entity.production.dto.ProductionOrderDto;
 import com.fjhx.mes.entity.production.po.ProductionOrder;
@@ -15,6 +19,7 @@ import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionOrderVo;
 import com.fjhx.mes.entity.work.po.WorkOrder;
 import com.fjhx.mes.mapper.production.ProduceOrderMapper;
+import com.fjhx.mes.service.material.MaterialPreparationService;
 import com.fjhx.mes.service.production.ProduceOrderDetailService;
 import com.fjhx.mes.service.production.ProduceOrderService;
 import com.fjhx.mes.service.work.WorkOrderService;
@@ -58,6 +63,10 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
     private ProductInfoService productInfoService;
     @Autowired
     private WorkOrderService workOrderService;
+    @Autowired
+    private ProductBomDetailService productBomDetailService;
+    @Autowired
+    private MaterialPreparationService materialPreparationService;
 
     @Override
     public Page<ProductionOrderVo> getPage(ProduceOrderSelectDto dto) {
@@ -127,6 +136,12 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
         //创建生产订单明细
         List<ProductionOrderDetail> productionOrderDetailList = new ArrayList<>();
         List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contractId));
+
+        //获取产品id
+        List<Long> productIds = contractProductList.stream().map(ContractProduct::getProductId).collect(Collectors.toList());
+        Map<Long, ProductInfo> productInfoMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, productIds));
+        Map<Long, List<ProductBomDetail>> productBomDetailMap = productBomDetailService.mapKGroup(ProductBomDetail::getProductId, q -> q.in(ProductBomDetail::getProductId, productIds));
+
         for (ContractProduct contractProduct : contractProductList) {
             ProductionOrderDetail productionOrderDetail = new ProductionOrderDetail();
             productionOrderDetail.setProduceOrderId(produceOrderDto.getId());
@@ -138,6 +153,35 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             productionOrderDetail.setProduceStatus(0);
             productionOrderDetail.setTenantId(tenantId);
             productionOrderDetailList.add(productionOrderDetail);
+
+            //创建备料
+            Long productId = contractProduct.getProductId();
+            ProductInfo productInfo = productInfoMap.get(productId);
+            Assert.notEmpty(productInfo, "查询不到产品信息");
+
+//            //创建原材料
+//            ProductBomDetail productBomDetail = new ProductBomDetail();
+//            productBomDetail.setProductId(productInfo.getId());
+//            productBomDetail.setMaterialId(productInfo.getRawMaterialId());
+//            productBomDetail.setQuantity(BigDecimal.ONE);
+            List<ProductBomDetail> productBomDetailList = productBomDetailMap.get(productId);
+//            productBomDetailList.add(productBomDetail);
+
+            List<MaterialPreparation> materialPreparationList = new ArrayList<>();
+            for (ProductBomDetail bomDetail : productBomDetailList) {
+                BigDecimal multiply = bomDetail.getQuantity().multiply(contractProduct.getQuantity());
+
+                MaterialPreparation materialPreparation = new MaterialPreparation();
+                materialPreparation.setContractId(contractId);
+                materialPreparation.setContractDetailId(contractProduct.getId());
+                materialPreparation.setProductionOrderId(produceOrderDto.getId());
+                materialPreparation.setProductionOrderDetailId(productionOrderDetail.getId());
+                materialPreparation.setMaterialId(bomDetail.getMaterialId());
+                materialPreparation.setQuantity(multiply);
+                materialPreparation.setStatus(0);
+                materialPreparationList.add(materialPreparation);
+            }
+            materialPreparationService.saveBatch(materialPreparationList);
         }
         produceOrderDetailService.saveBatch(productionOrderDetailList);
 

+ 26 - 0
hx-mes/src/main/resources/mapper/material/MaterialPreparationMapper.xml

@@ -0,0 +1,26 @@
+<?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.fjhx.mes.mapper.material.MaterialPreparationMapper">
+    <select id="getPage" resultType="com.fjhx.mes.entity.material.vo.MaterialPreparationVo">
+        select mp.id,
+               mp.contract_id,
+               mp.contract_detail_id,
+               mp.production_order_id,
+               mp.production_order_detail_id,
+               mp.material_id,
+               mp.quantity,
+               mp.preparation_deadline,
+               mp.production_time,
+               mp.status,
+               mp.create_user,
+               mp.create_time,
+               mp.update_user,
+               mp.update_time,
+               pi.`name`      as materialName,
+               pi.custom_code as materialCode
+        from material_preparation mp
+                 left join product_info pi on mp.material_id = pi.id
+            ${ew.customSqlSegment}
+    </select>
+
+</mapper>

+ 5 - 5
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -259,11 +259,11 @@ public class ContractFlow extends FlowDelegate {
             //获取物料列表,以及原材料
             List<ProductBomDetail> productBomDetails = productBomMap.get(productId);
             ProductBomDetail rawMaterial = new ProductBomDetail();
-            //添加原材料
-            rawMaterial.setMaterialId(productInfo.getRawMaterialId());
-            rawMaterial.setProductId(productId);
-            rawMaterial.setQuantity(BigDecimal.ONE);
-            productBomDetails.add(rawMaterial);
+//            //添加原材料
+//            rawMaterial.setMaterialId(productInfo.getRawMaterialId());
+//            rawMaterial.setProductId(productId);
+//            rawMaterial.setQuantity(BigDecimal.ONE);
+//            productBomDetails.add(rawMaterial);
 
             if (ObjectUtil.isNotEmpty(productBomDetails)) {
                 List<Long> materialIds = productBomDetails.stream().map(ProductBomDetail::getMaterialId).collect(Collectors.toList());