瀏覽代碼

Merge remote-tracking branch 'origin/master'

1018653686@qq.com 1 年之前
父節點
當前提交
5caeeeed74
共有 86 個文件被更改,包括 2008 次插入860 次删除
  1. 6 0
      hx-account/src/main/java/com/fjhx/account/flow/AccountRequestFundsFlow.java
  2. 1 1
      hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountPaymentServiceImpl.java
  3. 1 1
      hx-admin/src/main/resources/application-prod.yml
  4. 0 9
      hx-form/src/main/java/com/fjhx/form/service/impl/ReportServiceImpl.java
  5. 20 72
      hx-form/src/main/java/com/fjhx/form/service/impl/StatisticsServiceImpl.java
  6. 4 0
      hx-iot/pom.xml
  7. 9 11
      hx-iot/src/main/java/com/fjhx/iot/controller/tda/TdaDeviceController.java
  8. 5 0
      hx-iot/src/main/java/com/fjhx/iot/entity/tda/dto/TdaDeviceSelectDto.java
  9. 33 20
      hx-iot/src/main/java/com/fjhx/iot/entity/tda/po/TdaDevice.java
  10. 32 0
      hx-iot/src/main/java/com/fjhx/iot/entity/tda/vo/TdaDeviceVo.java
  11. 3 1
      hx-iot/src/main/java/com/fjhx/iot/mapper/tda/TdaDeviceMapper.java
  12. 1 1
      hx-iot/src/main/java/com/fjhx/iot/service/tda/TdaDeviceService.java
  13. 49 9
      hx-iot/src/main/java/com/fjhx/iot/service/tda/impl/TdaDeviceServiceImpl.java
  14. 4 6
      hx-iot/src/main/java/com/fjhx/iot/service/tda/impl/TdaProductServiceImpl.java
  15. 13 18
      hx-iot/src/main/resources/mapper/tda/TdaDeviceMapper.xml
  16. 14 0
      hx-item/src/main/java/com/fjhx/item/entity/product/TechnologyBo.java
  17. 5 0
      hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java
  18. 6 1
      hx-jushuitan/src/main/java/com/fjhx/jushuitan/entity/jst/dto/JstOrderInfoDto.java
  19. 10 8
      hx-jushuitan/src/main/java/com/fjhx/jushuitan/service/jst/impl/JstOrderInfoServiceImpl.java
  20. 57 57
      hx-jxst/src/main/java/com/fjhx/jxst/flow/SalesContractFlow.java
  21. 4 0
      hx-mes/pom.xml
  22. 58 0
      hx-mes/src/main/java/com/fjhx/mes/controller/DeviceOpenController.java
  23. 1 1
      hx-mes/src/main/java/com/fjhx/mes/controller/production/ProduceOrderDetailController.java
  24. 9 0
      hx-mes/src/main/java/com/fjhx/mes/controller/production/ProductionSchedulingController.java
  25. 29 0
      hx-mes/src/main/java/com/fjhx/mes/controller/production/ProductionTaskProgressController.java
  26. 92 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/bo/WorkshopReportBo.java
  27. 5 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/dto/ProduceOrderDetailSelectDto.java
  28. 8 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/dto/ProductionSchedulingSelectDto.java
  29. 5 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/po/ProductionScheduling.java
  30. 6 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionOrderVo.java
  31. 33 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionReportingDetailVo.java
  32. 6 0
      hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionTaskProgressVo.java
  33. 5 1
      hx-mes/src/main/java/com/fjhx/mes/entity/work/dto/WorkOrderDto.java
  34. 30 1
      hx-mes/src/main/java/com/fjhx/mes/entity/work/po/WorkOrder.java
  35. 2 0
      hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProduceOrderDetailMapper.java
  36. 5 0
      hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionSchedulingMapper.java
  37. 7 0
      hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionTaskProgressMapper.java
  38. 17 0
      hx-mes/src/main/java/com/fjhx/mes/service/DeviceOpenService.java
  39. 93 0
      hx-mes/src/main/java/com/fjhx/mes/service/DeviceOpenServiceImpl.java
  40. 5 0
      hx-mes/src/main/java/com/fjhx/mes/service/production/ProductionSchedulingService.java
  41. 16 0
      hx-mes/src/main/java/com/fjhx/mes/service/production/ProductionTaskProgressService.java
  42. 28 12
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderDetailServiceImpl.java
  43. 258 30
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderServiceImpl.java
  44. 14 1
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionReportingDetailServiceImpl.java
  45. 21 7
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionReportingServiceImpl.java
  46. 60 4
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionSchedulingServiceImpl.java
  47. 53 0
      hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionTaskProgressServiceImpl.java
  48. 16 3
      hx-mes/src/main/resources/mapper/production/ProduceOrderDetailMapper.xml
  49. 1 1
      hx-mes/src/main/resources/mapper/production/ProductionProcessesMapper.xml
  50. 2 1
      hx-mes/src/main/resources/mapper/production/ProductionReportingDetailMapper.xml
  51. 8 0
      hx-mes/src/main/resources/mapper/production/ProductionSchedulingMapper.xml
  52. 56 0
      hx-mes/src/main/resources/mapper/production/ProductionTaskProgressMapper.xml
  53. 80 80
      hx-purchase/src/main/java/com/fjhx/purchase/flow/RefundFlow.java
  54. 1 1
      hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java
  55. 2 0
      hx-sale/src/main/java/com/fjhx/sale/entity/ext/dto/ExtQuotationProductSelectDto.java
  56. 10 0
      hx-sale/src/main/java/com/fjhx/sale/entity/ext/po/ExtQuotation.java
  57. 9 0
      hx-sale/src/main/java/com/fjhx/sale/entity/ext/vo/ExtQuotationProductVo.java
  58. 9 0
      hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBack.java
  59. 2 2
      hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBackDetails.java
  60. 9 0
      hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java
  61. 74 64
      hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseVo.java
  62. 12 0
      hx-sale/src/main/java/com/fjhx/sale/entity/quotation/po/QuotationProduct.java
  63. 7 0
      hx-sale/src/main/java/com/fjhx/sale/entity/sale/dto/SaleQuotationDto.java
  64. 15 0
      hx-sale/src/main/java/com/fjhx/sale/entity/sale/po/SaleQuotation.java
  65. 124 124
      hx-sale/src/main/java/com/fjhx/sale/flow/ClaimDelFlow.java
  66. 2 2
      hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java
  67. 15 143
      hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java
  68. 89 0
      hx-sale/src/main/java/com/fjhx/sale/flow/DiscussPriceFlow.java
  69. 21 9
      hx-sale/src/main/java/com/fjhx/sale/flow/PayFlow.java
  70. 4 1
      hx-sale/src/main/java/com/fjhx/sale/flow/PurchaseBackFlow.java
  71. 67 67
      hx-sale/src/main/java/com/fjhx/sale/flow/SampleFlow.java
  72. 66 66
      hx-sale/src/main/java/com/fjhx/sale/flow/SampleUpdateFlow.java
  73. 5 0
      hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java
  74. 3 0
      hx-sale/src/main/java/com/fjhx/sale/mapper/quotation/QuotationEstimateMapper.java
  75. 12 4
      hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java
  76. 51 1
      hx-sale/src/main/java/com/fjhx/sale/service/ext/impl/ExtQuotationProductServiceImpl.java
  77. 7 0
      hx-sale/src/main/java/com/fjhx/sale/service/ext/impl/ExtQuotationServiceImpl.java
  78. 37 13
      hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java
  79. 14 2
      hx-sale/src/main/java/com/fjhx/sale/service/quotation/impl/QuotationEstimateServiceImpl.java
  80. 12 0
      hx-sale/src/main/java/com/fjhx/sale/service/sale/impl/SaleQuotationServiceImpl.java
  81. 7 0
      hx-sale/src/main/resources/mapper/contract/ContractMapper.xml
  82. 6 2
      hx-sale/src/main/resources/mapper/ext/ExtQuotationProductMapper.xml
  83. 2 1
      hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml
  84. 2 0
      hx-sale/src/main/resources/mapper/purchase/PurchaseBackMapper.xml
  85. 5 0
      hx-sale/src/main/resources/mapper/quotation/QuotationEstimateMapper.xml
  86. 1 1
      hx-wms/src/main/java/com/fjhx/wms/entity/stock/dto/StockWaitSelectDto.java

+ 6 - 0
hx-account/src/main/java/com/fjhx/account/flow/AccountRequestFundsFlow.java

@@ -68,6 +68,11 @@ public class AccountRequestFundsFlow extends FlowDelegate {
 
         accountRequestFundsDto = commStart(accountRequestFundsDto, 0);
 
+        //回填数据
+        submitData.put("total", accountRequestFundsDto.getTotal());
+        submitData.put("createUserName", SecurityUtils.getLoginUser().getUser().getNickName());
+
+
         return accountRequestFundsDto.getId();
     }
 
@@ -164,6 +169,7 @@ public class AccountRequestFundsFlow extends FlowDelegate {
         accountPayment.setInterbankNumber(accountRequestFunds.getInterbankNumber());
         accountPayment.setDataUser(accountRequestFunds.getCreateUser());
         accountPayment.setAmount(BigDecimal.ZERO);
+        accountPayment.setCompanyId(accountRequestFunds.getCompanyId());
 
         // 如果是核销 核销数据审批通过后,根据“核销总额 - 预支总额”生成“待打款”数据
         if ("3".equals(accountRequestFunds.getType())) {

+ 1 - 1
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountPaymentServiceImpl.java

@@ -99,7 +99,7 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
 
         //权限过滤:打款-子公司看自己的
         wrapper.in("ap.company_id", SecurityUtils.getCompanyIds());
-        wrapper.eq("ap.company_id", dto.getCompanyId());
+        wrapper.eq(ObjectUtil.isNotEmpty(dto.getCompanyId()), "ap.company_id", dto.getCompanyId());
 
 
         Page<AccountPaymentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);

+ 1 - 1
hx-admin/src/main/resources/application-prod.yml

@@ -2,7 +2,7 @@
 spring:
     datasource:
         dynamic:
-          strict: true
+            strict: true
             primary: base
             datasource:
               base:

+ 0 - 9
hx-form/src/main/java/com/fjhx/form/service/impl/ReportServiceImpl.java

@@ -47,15 +47,6 @@ public class ReportServiceImpl implements ReportService {
         List<ProductionReportBo> productionReportBos = page.getRecords();
         List<Long> ptIds = productionReportBos.stream().map(ProductionReportBo::getId).collect(Collectors.toList());
 
-        //赋值产品信息
-        productInfoService.attributeAssign(productionReportBos, ProductionReportBo::getProductId, (item, productInfo) -> {
-            item.setProductName(productInfo.getName());
-            item.setProductCode(productInfo.getCustomCode());
-            item.setProductLength(productInfo.getLength());
-            item.setProductWidth(productInfo.getWidth());
-            item.setProductHeight(productInfo.getHeight());
-            item.setProductColor(productInfo.getColor());
-        });
 
         //获取部门列表
         List<SysDept> companyList = deptService.list();

+ 20 - 72
hx-form/src/main/java/com/fjhx/form/service/impl/StatisticsServiceImpl.java

@@ -1,27 +1,23 @@
 package com.fjhx.form.service.impl;
 
 import com.fjhx.account.entity.account.po.AccountRunningWater;
-import com.fjhx.account.service.account.AccountPaymentService;
 import com.fjhx.account.service.account.AccountRunningWaterService;
 import com.fjhx.common.enums.FlowStatusEnum1;
-import com.fjhx.customer.service.customer.CustomerService;
 import com.fjhx.flow.entity.flow.po.FlowExample;
 import com.fjhx.flow.service.flow.FlowExampleService;
 import com.fjhx.form.mapper.StatisticsMapper;
 import com.fjhx.form.service.StatisticsService;
 import com.fjhx.mes.entity.production.po.ProductionOrder;
 import com.fjhx.mes.service.production.ProduceOrderService;
-import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.sale.entity.contract.vo.ContractVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseVo;
 import com.fjhx.sale.entity.sale.po.SaleQuotation;
-import com.fjhx.sale.mapper.contract.ContractProductMapper;
-import com.fjhx.sale.mapper.sample.SampleMapper;
 import com.fjhx.sale.service.sale.SaleQuotationService;
 import com.fjhx.wms.entity.stock.dto.StockSelectDto;
-import com.fjhx.wms.entity.stock.dto.StockWaitDetailsSelectDto;
+import com.fjhx.wms.entity.stock.dto.StockWaitSelectDto;
 import com.fjhx.wms.service.stock.StockService;
 import com.fjhx.wms.service.stock.StockWaitDetailsService;
+import com.fjhx.wms.service.stock.StockWaitService;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,16 +34,6 @@ public class StatisticsServiceImpl implements StatisticsService {
     @Autowired
     private AccountRunningWaterService accountRunningWaterService;
     @Autowired
-    private SubscribeDetailService subscribeDetailService;
-    @Autowired
-    private SampleMapper sampleMapper;
-    @Autowired
-    private ContractProductMapper contractProductMapper;
-    @Autowired
-    private AccountPaymentService accountPaymentService;
-    @Autowired
-    private CustomerService customerService;
-    @Autowired
     private StatisticsMapper statisticsMapper;
     @Autowired
     private SaleQuotationService saleQuotationService;
@@ -57,6 +43,8 @@ public class StatisticsServiceImpl implements StatisticsService {
     private StockService stockService;
     @Autowired
     private StockWaitDetailsService stockWaitDetailsService;
+    @Autowired
+    private StockWaitService stockWaitService;
 
     /**
      * 工作统计
@@ -66,43 +54,39 @@ public class StatisticsServiceImpl implements StatisticsService {
         Long userId = SecurityUtils.getUserId();
 
         //权限过滤:子公司看自己的,总公司看全部
-        boolean flag;//是否是总公司
         List<Long> companyIds = SecurityUtils.getCompanyIds();
 
-        if (companyIds.contains(100L)) {
-            //总公司直接忽略归属公司条件
-            flag = true;
-        } else {
-            flag = false;
-        }
-        List<Long> finalCompanyIds = companyIds;//isEstimate
+        //是否是总公司
+        boolean isHeadOffice = companyIds.contains(100L);
 
         //统计待审批数据
         long waitFlowCount = flowExampleService.count(q -> q.in(FlowExample::getStatus, 1, 0).eq(FlowExample::getHandleUserId, userId));
         //待报价 总公司对内报价单 子公司 报价评估
         long waitQuotationCount = saleQuotationService.count(q -> q
-                .ne(!flag, SaleQuotation::getStatus, FlowStatusEnum1.DRAFT.getKey())//子公司
-                .ne(SaleQuotation::getStatus, FlowStatusEnum1.UPDATE.getKey())//总公司
-                .in(!flag, SaleQuotation::getCompanyId, finalCompanyIds)
+                //总公司
+                .in(SaleQuotation::getCompanyId, companyIds)
+                .ne(SaleQuotation::getStatus, FlowStatusEnum1.UPDATE.getKey())
+                //子公司
+                .ne(!isHeadOffice, SaleQuotation::getStatus, FlowStatusEnum1.DRAFT.getKey())
         );
         //待投产
         long waitProduceCount = produceOrderService.count(q -> q
                 .isNull(ProductionOrder::getProduceTime)
-                .in(!flag, ProductionOrder::getCompanyId, finalCompanyIds)
+                .in(!isHeadOffice, ProductionOrder::getCompanyId, companyIds)
         );
         //待入库
-        StockWaitDetailsSelectDto stockWaitDetailsSelectDto = new StockWaitDetailsSelectDto();
-        stockWaitDetailsSelectDto.setType(1);
-        long waitInStockCount = stockWaitDetailsService.getPage(stockWaitDetailsSelectDto).getTotal();
+        StockWaitSelectDto stockWaitSelectDto = new StockWaitSelectDto();
+        stockWaitSelectDto.setType(1);
+        long waitInStockCount = stockWaitService.getPage(stockWaitSelectDto).getTotal();
         //待出库
-        StockWaitDetailsSelectDto stockWaitDetailsSelectDto1 = new StockWaitDetailsSelectDto();
-        stockWaitDetailsSelectDto1.setType(2);
-        long waitOutStockCount = stockWaitDetailsService.getPage(stockWaitDetailsSelectDto1).getTotal();
+        StockWaitSelectDto stockWaitSelectDto1 = new StockWaitSelectDto();
+        stockWaitSelectDto1.setType(2);
+        long waitOutStockCount = stockWaitService.getPage(stockWaitSelectDto1).getTotal();
         //到账认领待认领计数-总公司
         long waitClaimCount = accountRunningWaterService.count(q -> q
                 .eq(AccountRunningWater::getReceived, 10)
                 .eq(AccountRunningWater::getIsClaim, 0)
-                .in(!flag, AccountRunningWater::getCompanyId, finalCompanyIds)
+                .in(!isHeadOffice, AccountRunningWater::getCompanyId, companyIds)
         );
         //库存预警-子公司看
         long stockWarnCount = stockService.stockWarningPage(new StockSelectDto()).getTotal();
@@ -110,13 +94,12 @@ public class StatisticsServiceImpl implements StatisticsService {
         //总数
         long sumCount = waitFlowCount + waitQuotationCount + waitProduceCount + waitInStockCount + waitOutStockCount;
 
-        if (flag) {
+        if (isHeadOffice) {
             sumCount += waitClaimCount;//总公司待认领
         } else {
             sumCount += stockWarnCount;//子公司库存预警
         }
 
-
         //输出结果
         Map<String, Long> map = new HashMap<>();
         map.put("waitFlowCount", waitFlowCount);
@@ -128,41 +111,6 @@ public class StatisticsServiceImpl implements StatisticsService {
         map.put("stockWarnCount", stockWarnCount);
         map.put("sumCount", sumCount);
 
-
-//        //到账认领计数
-//        long claimCount = accountRunningWaterService.count(q -> q.eq(AccountRunningWater::getReceived, 10).ne(AccountRunningWater::getIsClaim, 1));
-//        //待采购数量
-//        long waitPurchaseCount = subscribeDetailService.count(q -> q.in(SubscribeDetail::getStatus, Arrays.asList(15, 30)));
-//        //样品交接单
-//        Page<Object> page = new Page<>();
-//        page.setCurrent(1);
-//        page.setSize(1);
-//        IWrapper<Sample> wrapper = IWrapper.getWrapper();
-//        wrapper.eq("t2.`status`", 30);
-//        wrapper.ge("t1.expend_quantity", 0);
-//        long sampleHandoverCount = sampleMapper.sampleHandoverList(page, wrapper).getTotal();
-//        //合同样品单
-//        IWrapper<ContractProduct> wrapper1 = IWrapper.getWrapper();
-//        wrapper.eq("t2.`status`", 30);
-//        wrapper.ge("t1.expend_quantity", 0);
-//        long contractHandoverCount = contractProductMapper.contractHandoverPage(page, wrapper1).getTotal();
-//        //待打款
-//        long waitAccountPayCount = accountPaymentService.count(q -> q.ne(AccountPayment::getStatus, 10));
-
-        //总数
-//        long sumCount = unreadMailCount + waitFlowCount + claimCount + waitPurchaseCount + sampleHandoverCount + contractHandoverCount + waitAccountPayCount;
-
-
-//        map.put("unreadMailCount", unreadMailCount);
-//        map.put("waitFlowCount", waitFlowCount);
-//        map.put("claimCount", claimCount);
-//        map.put("waitPurchaseCount", waitPurchaseCount);
-//        map.put("sampleHandoverCount", sampleHandoverCount);
-//        map.put("contractHandoverCount", contractHandoverCount);
-//        map.put("waitAccountPayCount", waitAccountPayCount);
-//        map.put("sumCount", sumCount);
-
-
         return map;
     }
 

+ 4 - 0
hx-iot/pom.xml

@@ -36,6 +36,10 @@
             <artifactId>qpid-jms-client</artifactId>
             <version>0.61.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-item</artifactId>
+        </dependency>
 
 
     </dependencies>

+ 9 - 11
hx-iot/src/main/java/com/fjhx/iot/controller/tda/TdaDeviceController.java

@@ -2,10 +2,8 @@ package com.fjhx.iot.controller.tda;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.iot.constants.RedisConstant;
 import com.fjhx.iot.entity.tda.dto.TdaDeviceDto;
 import com.fjhx.iot.entity.tda.dto.TdaDeviceSelectDto;
-import com.fjhx.iot.entity.tda.po.TdaDevice;
 import com.fjhx.iot.entity.tda.vo.TdaDeviceVo;
 import com.fjhx.iot.service.tda.TdaDeviceService;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -54,20 +52,20 @@ public class TdaDeviceController {
         return tdaDeviceService.getComputerList(dto);
     }
 
-    /**
-     * 设备数据
-     */
-    @PostMapping("/data")
-    public Object getData(@RequestBody TdaDevice tdaDevice) {
-        return redisCache.getCacheObject(RedisConstant.DEVICE_PREFIX + tdaDevice.getDeviceId());
-    }
+//    /**
+//     * 设备数据
+//     */
+//    @PostMapping("/data")
+//    public Object getData(@RequestBody TdaDevice tdaDevice) {
+//        return redisCache.getCacheObject(RedisConstant.DEVICE_PREFIX + tdaDevice.getDeviceId());
+//    }
 
     /**
      * 设备管理明细
      */
     @PostMapping("/detail")
-    public TdaDeviceVo detail(@RequestBody BaseSelectDto dto) {
-        return tdaDeviceService.detail(dto.getId());
+    public TdaDeviceVo detail(@RequestBody TdaDeviceSelectDto dto) {
+        return tdaDeviceService.detail(dto);
     }
 
     /**

+ 5 - 0
hx-iot/src/main/java/com/fjhx/iot/entity/tda/dto/TdaDeviceSelectDto.java

@@ -19,4 +19,9 @@ public class TdaDeviceSelectDto extends BaseSelectDto {
      */
     private Long companyId;
 
+    /**
+     * 用户唯一标识
+     */
+    private String userUuid;
+
 }

+ 33 - 20
hx-iot/src/main/java/com/fjhx/iot/entity/tda/po/TdaDevice.java

@@ -51,35 +51,48 @@ public class TdaDevice extends BasePo {
      */
     private String remark;
 
-    //+=========================================s
-
-    /**
-     * 设备id
-     */
-    private String deviceId;
     /**
-     * 设备密匙
+     * 归属公司Id
      */
-    private String secret;
+    private Long companyId;
 
     /**
-     * 产品表id
+     * 生产模式
      */
-    private Long tdaProductId;
-
+    private Long prodMode;
     /**
-     * 华为tda产品id
+     * 生产任务id
      */
-    private String productId;
-
+    private Long prodTaskId;
     /**
-     * 设备节点(设备标识)
+     * 用户设备唯一标识
      */
-    private String nodeId;
+    private String userUuid;
 
-    /**
-     * 归属公司Id
-     */
-    private Long companyId;
+    //+=========================================s
+
+//    /**
+//     * 设备id
+//     */
+//    private String deviceId;
+//    /**
+//     * 设备密匙
+//     */
+//    private String secret;
+//
+//    /**
+//     * 产品表id
+//     */
+//    private Long tdaProductId;
+//
+//    /**
+//     * 华为tda产品id
+//     */
+//    private String productId;
+//
+//    /**
+//     * 设备节点(设备标识)
+//     */
+//    private String nodeId;
 
 }

+ 32 - 0
hx-iot/src/main/java/com/fjhx/iot/entity/tda/vo/TdaDeviceVo.java

@@ -4,6 +4,7 @@ import com.fjhx.iot.entity.tda.po.TdaDevice;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.Map;
 
@@ -52,4 +53,35 @@ public class TdaDeviceVo extends TdaDevice {
      */
     private String companyName;
 
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品编号
+     */
+    private String productCode;
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
+    /**
+     * 产品颜色
+     */
+    private String productColor;
+
+    /**
+     * 生产订单号
+     */
+    private String orderCode;
+
 }

+ 3 - 1
hx-iot/src/main/java/com/fjhx/iot/mapper/tda/TdaDeviceMapper.java

@@ -1,8 +1,8 @@
 package com.fjhx.iot.mapper.tda;
 
-import com.fjhx.iot.entity.tda.po.TdaDevice;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.iot.entity.tda.po.TdaDevice;
 import com.fjhx.iot.entity.tda.vo.TdaDeviceVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
@@ -23,4 +23,6 @@ public interface TdaDeviceMapper extends BaseMapper<TdaDevice> {
      */
     Page<TdaDeviceVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<TdaDevice> wrapper);
 
+    TdaDeviceVo detail(@Param("ew") IWrapper<TdaDevice> wrapper);
+
 }

+ 1 - 1
hx-iot/src/main/java/com/fjhx/iot/service/tda/TdaDeviceService.java

@@ -29,7 +29,7 @@ public interface TdaDeviceService extends BaseService<TdaDevice> {
     /**
      * 设备管理明细
      */
-    TdaDeviceVo detail(Long id);
+    TdaDeviceVo detail(TdaDeviceSelectDto dto);
 
     /**
      * 设备管理新增

+ 49 - 9
hx-iot/src/main/java/com/fjhx/iot/service/tda/impl/TdaDeviceServiceImpl.java

@@ -1,7 +1,8 @@
 package com.fjhx.iot.service.tda.impl;
 
-import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSONObject;
+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.iot.constants.RedisConstant;
@@ -11,8 +12,12 @@ import com.fjhx.iot.entity.tda.po.TdaDevice;
 import com.fjhx.iot.entity.tda.vo.TdaDeviceVo;
 import com.fjhx.iot.mapper.tda.TdaDeviceMapper;
 import com.fjhx.iot.service.tda.TdaDeviceService;
+import com.fjhx.item.entity.product.po.ProductInfo;
+import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.tenant.utils.DeptUstil;
+import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
@@ -20,10 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -40,6 +42,8 @@ public class TdaDeviceServiceImpl extends ServiceImpl<TdaDeviceMapper, TdaDevice
 
     @Autowired
     private RedisCache redisCache;
+    @Autowired
+    private ProductInfoService productInfoService;
 
     @Override
     public Page<TdaDeviceVo> getPage(TdaDeviceSelectDto dto) {
@@ -48,7 +52,7 @@ public class TdaDeviceServiceImpl extends ServiceImpl<TdaDeviceMapper, TdaDevice
         wrapper.keyword(dto, new SqlField("td.device_name"));
 
         //权限过滤:设备管理-子公司看自己的,总公司看全部
-            wrapper.in("td.company_id", SecurityUtils.getCompanyIds());
+        wrapper.in("td.company_id", SecurityUtils.getCompanyIds());
         wrapper.eq("td.company_id", dto.getCompanyId());
 
 
@@ -110,9 +114,32 @@ public class TdaDeviceServiceImpl extends ServiceImpl<TdaDeviceMapper, TdaDevice
     }
 
     @Override
-    public TdaDeviceVo detail(Long id) {
-        TdaDevice TdaDevice = this.getById(id);
-        TdaDeviceVo result = BeanUtil.toBean(TdaDevice, TdaDeviceVo.class);
+    public TdaDeviceVo detail(TdaDeviceSelectDto dto) {
+        if (ObjectUtil.isEmpty(dto.getId()) && ObjectUtil.isEmpty(dto.getUserUuid())) {
+            throw new ServiceException("设备id/用户唯一标识,其中之一不能为空!");
+        }
+
+        //赋值任务信息
+        IWrapper<TdaDevice> wrapper = getWrapper();
+        wrapper.eq("td", TdaDevice::getId, dto.getId());
+        wrapper.eq("td", TdaDevice::getUserUuid, dto.getUserUuid());
+        TdaDeviceVo result = baseMapper.detail(wrapper);
+
+        if (ObjectUtil.isEmpty(result)) {
+            return result;
+        }
+
+        //赋值产品信息
+        ProductInfo productInfo = productInfoService.getById(result.getProductId());
+        if (ObjectUtil.isNotEmpty(productInfo)) {
+            result.setProductName(productInfo.getName());
+            result.setProductCode(productInfo.getCustomCode());
+            result.setProductLength(productInfo.getLength());
+            result.setProductWidth(productInfo.getWidth());
+            result.setProductHeight(productInfo.getHeight());
+            result.setProductColor(productInfo.getColor());
+        }
+
         return result;
     }
 
@@ -145,7 +172,20 @@ public class TdaDeviceServiceImpl extends ServiceImpl<TdaDeviceMapper, TdaDevice
     }
 
     @Override
+    @DSTransactional
     public void edit(TdaDeviceDto tdaDeviceDto) {
+        String userUuid = tdaDeviceDto.getUserUuid();
+
+        //机台设置 更新用户设备唯一id
+        if (ObjectUtil.isNotEmpty(userUuid)) {
+            this.update(q -> q
+                    .eq(TdaDevice::getUserUuid, userUuid)
+                    .set(TdaDevice::getUserUuid, null)
+                    .set(BasePo::getUpdateTime, new Date())
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+        }
+
         this.updateById(tdaDeviceDto);
     }
 

+ 4 - 6
hx-iot/src/main/java/com/fjhx/iot/service/tda/impl/TdaProductServiceImpl.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.iot.entity.tda.dto.TdaProductDto;
 import com.fjhx.iot.entity.tda.dto.TdaProductSelectDto;
 import com.fjhx.iot.entity.tda.po.TdaApplication;
-import com.fjhx.iot.entity.tda.po.TdaDevice;
 import com.fjhx.iot.entity.tda.po.TdaProduct;
 import com.fjhx.iot.entity.tda.vo.TdaProductVo;
 import com.fjhx.iot.mapper.tda.TdaProductMapper;
@@ -14,7 +13,6 @@ import com.fjhx.iot.service.tda.TdaApplicationService;
 import com.fjhx.iot.service.tda.TdaDeviceService;
 import com.fjhx.iot.service.tda.TdaProductService;
 import com.fjhx.iot.utils.IoTDAUtil;
-import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -84,10 +82,10 @@ public class TdaProductServiceImpl extends ServiceImpl<TdaProductMapper, TdaProd
     public void delete(Long id) {
 
         // 查询产品是否已添加设备,已添加设备则不可删除
-        long count = tdaDeviceService.count(q -> q.eq(TdaDevice::getTdaProductId, id));
-        if (count > 0) {
-            throw new ServiceException("产品已添加设备,无法删除");
-        }
+//        long count = tdaDeviceService.count(q -> q.eq(TdaDevice::getTdaProductId, id));
+//        if (count > 0) {
+//            throw new ServiceException("产品已添加设备,无法删除");
+//        }
 
         // 华为ioDta删除产品
         TdaProduct tdaProduct = getById(id);

+ 13 - 18
hx-iot/src/main/resources/mapper/tda/TdaDeviceMapper.xml

@@ -2,23 +2,6 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.iot.mapper.tda.TdaDeviceMapper">
     <select id="getPage" resultType="com.fjhx.iot.entity.tda.vo.TdaDeviceVo">
-        --         select td.id,
---                td.tda_product_id,
---                td.product_id,
---                td.node_id,
---                td.device_name,
---                td.device_id,
---                td.secret,
---                td.create_user,
---                td.create_time,
---                td.update_user,
---                td.update_time,
---                tp.name        productName,
---                tp.device_type deviceType,
---                ta.app_name
---         from tda_device td
---                  left join tda_product tp on td.tda_product_id = tp.id
---                  left join tda_application ta on tp.tda_application_id = ta.id
         SELECT td.id,
                td.device_id,
                td.device_name,
@@ -32,9 +15,21 @@
                td.create_time,
                td.update_user,
                td.update_time,
-               td.company_id
+               td.company_id,
+               td.prod_mode,
+               td.prod_task_id,
+               td.user_uuid
         FROM tda_device td
             ${ew.customSqlSegment}
     </select>
+    <select id="detail" resultType="com.fjhx.iot.entity.tda.vo.TdaDeviceVo">
+        SELECT td.*,
+               pod.product_id,
+               po.`code` AS orderCode
+        FROM tda_device td
+                 LEFT JOIN production_order_detail pod ON td.prod_task_id = pod.id
+                 LEFT JOIN production_order po ON pod.produce_order_id = po.id
+            ${ew.customSqlSegment}
+    </select>
 
 </mapper>

+ 14 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/TechnologyBo.java

@@ -0,0 +1,14 @@
+package com.fjhx.item.entity.product;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class TechnologyBo {
+
+    /**
+     * 工艺线路
+     */
+    private String processRoute;
+}

+ 5 - 0
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -471,6 +471,11 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * 保存修改产品原材料
      */
     private void saveOrEditRawMaterial(ProductInfoDto productInfoDto) {
+        //操作非产品时跳过
+        if (ObjectUtil.notEqual(productInfoDto.getDefinition(), 1)) {
+            return;
+        }
+
         Long rawMaterialId = productInfoDto.getRawMaterialId();
         Assert.notEmpty(rawMaterialId, "原材料Id不能为空");
 

+ 6 - 1
hx-jushuitan/src/main/java/com/fjhx/jushuitan/entity/jst/dto/JstOrderInfoDto.java

@@ -1,17 +1,22 @@
 package com.fjhx.jushuitan.entity.jst.dto;
 
+import com.fjhx.jushuitan.entity.jst.po.JstOrderDetail;
 import com.fjhx.jushuitan.entity.jst.po.JstOrderInfo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 /**
  * 聚水潭订单表新增编辑入参实体
  *
- * @author 
+ * @author
  * @since 2024-01-20
  */
 @Getter
 @Setter
 public class JstOrderInfoDto extends JstOrderInfo {
 
+    List<JstOrderDetail> items;
+
 }

+ 10 - 8
hx-jushuitan/src/main/java/com/fjhx/jushuitan/service/jst/impl/JstOrderInfoServiceImpl.java

@@ -1,28 +1,28 @@
 package com.fjhx.jushuitan.service.jst.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
+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.jushuitan.entity.jst.dto.JstOrderInfoDto;
+import com.fjhx.jushuitan.entity.jst.dto.JstOrderInfoSelectDto;
 import com.fjhx.jushuitan.entity.jst.po.JstOrderDetail;
 import com.fjhx.jushuitan.entity.jst.po.JstOrderInfo;
 import com.fjhx.jushuitan.entity.jst.po.JstOrderPayInfo;
 import com.fjhx.jushuitan.entity.jst.vo.JstOrderDetailVo;
+import com.fjhx.jushuitan.entity.jst.vo.JstOrderInfoVo;
 import com.fjhx.jushuitan.mapper.jst.JstOrderInfoMapper;
 import com.fjhx.jushuitan.service.jst.JstOrderDetailService;
 import com.fjhx.jushuitan.service.jst.JstOrderInfoService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.jushuitan.service.jst.JstOrderPayInfoService;
-import org.springframework.stereotype.Service;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.jushuitan.entity.jst.vo.JstOrderInfoVo;
-import com.fjhx.jushuitan.entity.jst.dto.JstOrderInfoSelectDto;
 import com.ruoyi.common.utils.wrapper.IWrapper;
-import com.fjhx.jushuitan.entity.jst.dto.JstOrderInfoDto;
-import cn.hutool.core.bean.BeanUtil;
+import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.List;
-import java.util.Optional;
 
 /**
  * <p>
@@ -92,9 +92,11 @@ public class JstOrderInfoServiceImpl extends ServiceImpl<JstOrderInfoMapper, Jst
         this.save(jstOrderInfoDto);
     }
 
+    @DSTransactional
     @Override
     public void edit(JstOrderInfoDto jstOrderInfoDto) {
         this.updateById(jstOrderInfoDto);
+        jstOrderDetailService.updateBatchById(jstOrderInfoDto.getItems());
     }
 
     @Override

+ 57 - 57
hx-jxst/src/main/java/com/fjhx/jxst/flow/SalesContractFlow.java

@@ -1,57 +1,57 @@
-package com.fjhx.jxst.flow;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.jxst.entity.sales.dto.SalesContractDto;
-import com.fjhx.jxst.entity.sales.po.SalesContractDetails;
-import com.fjhx.jxst.service.sales.SalesContractDetailsService;
-import com.fjhx.jxst.service.sales.SalesContractService;
-import com.fjhx.mes.entity.work.dto.WorkOrderDto;
-import com.fjhx.mes.entity.work.po.WorkOrder;
-import com.fjhx.mes.service.work.WorkOrderService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-@Component
-public class SalesContractFlow extends FlowDelegate {
-
-    @Autowired
-    private SalesContractService salesContractService;
-    @Autowired
-    private SalesContractDetailsService salesContractDetailsService;
-    @Autowired
-    private WorkOrderService workOrderService;
-    @Override
-    public String getFlowKey() {
-        return "jxst_sales_contract_flow";
-    }
-
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        SalesContractDto salesContractDto = submitData.toJavaObject(SalesContractDto.class);
-        salesContractDto.setFlowId(flowId);
-        salesContractDto.setFlowKey(getFlowKey());
-        salesContractService.add(salesContractDto);
-        return salesContractDto.getId();
-    }
-
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        //按产品往“工单管理”中插入对应的工单数据
-        List<SalesContractDetails> salesContractDetailsList = salesContractDetailsService.list(q -> q.eq(SalesContractDetails::getSalesContractId, businessId));
-        for (SalesContractDetails salesContractDetails : salesContractDetailsList) {
-            WorkOrderDto workOrder = new WorkOrderDto();
-            workOrder.setSourceId(businessId);
-            workOrder.setSource("sales_contract");//销售合同
-            workOrder.setProductId(salesContractDetails.getProductId());
-            workOrder.setQuantity(salesContractDetails.getQuantity());
-            workOrder.setIsCustomized(salesContractDetails.getIsCustomized());
-            //添加工单
-            workOrderService.add(workOrder);
-        }
-    }
-
-}
+//package com.fjhx.jxst.flow;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.fjhx.flow.core.FlowDelegate;
+//import com.fjhx.flow.enums.FlowStatusEnum;
+//import com.fjhx.jxst.entity.sales.dto.SalesContractDto;
+//import com.fjhx.jxst.entity.sales.po.SalesContractDetails;
+//import com.fjhx.jxst.service.sales.SalesContractDetailsService;
+//import com.fjhx.jxst.service.sales.SalesContractService;
+//import com.fjhx.mes.entity.work.dto.WorkOrderDto;
+//import com.fjhx.mes.entity.work.po.WorkOrder;
+//import com.fjhx.mes.service.work.WorkOrderService;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//
+//import java.util.List;
+//
+//@Component
+//public class SalesContractFlow extends FlowDelegate {
+//
+//    @Autowired
+//    private SalesContractService salesContractService;
+//    @Autowired
+//    private SalesContractDetailsService salesContractDetailsService;
+//    @Autowired
+//    private WorkOrderService workOrderService;
+//    @Override
+//    public String getFlowKey() {
+//        return "jxst_sales_contract_flow";
+//    }
+//
+//    @Override
+//    public Long start(Long flowId, JSONObject submitData) {
+//        SalesContractDto salesContractDto = submitData.toJavaObject(SalesContractDto.class);
+//        salesContractDto.setFlowId(flowId);
+//        salesContractDto.setFlowKey(getFlowKey());
+//        salesContractService.add(salesContractDto);
+//        return salesContractDto.getId();
+//    }
+//
+//    @Override
+//    public void end(Long flowId, Long businessId, JSONObject submitData) {
+//        //按产品往“工单管理”中插入对应的工单数据
+//        List<SalesContractDetails> salesContractDetailsList = salesContractDetailsService.list(q -> q.eq(SalesContractDetails::getSalesContractId, businessId));
+//        for (SalesContractDetails salesContractDetails : salesContractDetailsList) {
+//            WorkOrderDto workOrder = new WorkOrderDto();
+//            workOrder.setSourceId(businessId);
+//            workOrder.setSource("sales_contract");//销售合同
+//            workOrder.setProductId(salesContractDetails.getProductId());
+//            workOrder.setQuantity(salesContractDetails.getQuantity());
+//            workOrder.setIsCustomized(salesContractDetails.getIsCustomized());
+//            //添加工单
+//            workOrderService.add(workOrder);
+//        }
+//    }
+//
+//}

+ 4 - 0
hx-mes/pom.xml

@@ -41,6 +41,10 @@
             <groupId>com.fjhx</groupId>
             <artifactId>hx-sale</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.fjhx</groupId>
+            <artifactId>hx-iot</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 58 - 0
hx-mes/src/main/java/com/fjhx/mes/controller/DeviceOpenController.java

@@ -0,0 +1,58 @@
+package com.fjhx.mes.controller;
+
+import com.fjhx.mes.entity.work.dto.WorkOrderDto;
+import com.fjhx.mes.service.DeviceOpenService;
+import com.ruoyi.common.core.domain.AjaxResult;
+import lombok.extern.slf4j.Slf4j;
+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;
+
+import java.util.HashMap;
+
+@Slf4j
+@RestController
+@RequestMapping("/open/device")
+public class DeviceOpenController {
+
+
+    @Autowired
+    private DeviceOpenService deviceOpenService;
+
+    /**
+     * 开始生产
+     */
+    @PostMapping("/startProduction")
+    public AjaxResult startProduction(@RequestBody WorkOrderDto dto) {
+        try {
+            AjaxResult success = AjaxResult.success("success", deviceOpenService.startProduction(dto));
+            success.put("success", true);
+            return success;
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            AjaxResult error = AjaxResult.error(e.getMessage(), new HashMap<>());
+            error.put("success", false);
+            return error;
+        }
+    }
+
+    /**
+     * 结束生产
+     */
+    @PostMapping("/endProduction")
+    public AjaxResult endProduction(@RequestBody WorkOrderDto dto) {
+        try {
+            deviceOpenService.endProduction(dto);
+            AjaxResult success = AjaxResult.success("success", new HashMap<>());
+            success.put("success", true);
+            return success;
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            AjaxResult error = AjaxResult.error(e.getMessage(), new HashMap<>());
+            error.put("success", false);
+            return error;
+        }
+    }
+}

+ 1 - 1
hx-mes/src/main/java/com/fjhx/mes/controller/production/ProduceOrderDetailController.java

@@ -43,7 +43,7 @@ public class ProduceOrderDetailController {
      */
     @PostMapping("/schedulingTaskPage")
     public Page<ProductionOrderDetailVo> schedulingTaskPage(@RequestBody ProduceOrderDetailSelectDto dto) {
-        return produceOrderDetailService.getPage(dto);
+        return produceOrderDetailService.schedulingTaskPage(dto);
     }
 
     /**

+ 9 - 0
hx-mes/src/main/java/com/fjhx/mes/controller/production/ProductionSchedulingController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingDto;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionScheduling;
+import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.fjhx.mes.service.production.ProductionSchedulingService;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -68,4 +69,12 @@ public class ProductionSchedulingController {
         productionSchedulingService.delete(dto.getId());
     }
 
+    /**
+     * 获取排程任务列表
+     */
+    @PostMapping("/schedulingTaskList")
+    public List<ProductionOrderDetailVo> schedulingTaskList() {
+        return productionSchedulingService.schedulingTaskList();
+    }
+
 }

+ 29 - 0
hx-mes/src/main/java/com/fjhx/mes/controller/production/ProductionTaskProgressController.java

@@ -1,8 +1,18 @@
 package com.fjhx.mes.controller.production;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.production.bo.WorkshopReportBo;
+import com.fjhx.mes.entity.production.dto.ProductionTaskProgressSelectDto;
+import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
+import com.fjhx.mes.service.production.ProductionTaskProgressService;
+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;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -16,5 +26,24 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/productionTaskProgress")
 public class ProductionTaskProgressController {
 
+    @Autowired
+    private ProductionTaskProgressService productionTaskProgressService;
+
+    /**
+     * 库存查询
+     */
+    @PostMapping("/workshopReportStatistics")
+    public List<ProductionTaskProgressVo> workshopReportStatistics(@RequestBody ProductionTaskProgressSelectDto dto) {
+        return productionTaskProgressService.workshopReportStatistics(dto);
+    }
+
+    /**
+     * 库存查询
+     */
+    @PostMapping("/workshopReport")
+    public Page<WorkshopReportBo> workshopReport(@RequestBody ProductionTaskProgressSelectDto dto) {
+        return productionTaskProgressService.workshopReport(dto);
+    }
+
 
 }

+ 92 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/bo/WorkshopReportBo.java

@@ -0,0 +1,92 @@
+package com.fjhx.mes.entity.production.bo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class WorkshopReportBo {
+    private Long id;
+    /**
+     * 任务id
+     */
+    private Long taskId;
+    /**
+     * 生产订单id
+     */
+    private Long produceOrderId;
+    /**
+     * 工序id
+     */
+    private Long progressId;
+    /**
+     * 工序名称
+     */
+    private String progressName;
+    /**
+     * 订单号
+     */
+    private String orderCode;
+    /**
+     * 产品id
+     */
+    private Long productId;
+    /**
+     * 产品编号
+     */
+    private String productCode;
+    /**
+     * 产品名称
+     */
+    private String productName;
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
+    /**
+     * 产品颜色
+     */
+    private String productColor;
+    /**
+     * 工单数量
+     */
+    private BigDecimal quantity;
+    /**
+     * 完工数量
+     */
+    private BigDecimal finishQuantity;
+    /**
+     * 欠量
+     */
+    private BigDecimal residueQuantity;
+    /**
+     * 昨天排程数量
+     */
+    private BigDecimal yesterdaySchedulingQuantity;
+    /**
+     * 昨天完成数量
+     */
+    private BigDecimal yesterdayFinishQuantity;
+    /**
+     * 今天排程数量
+     */
+    private BigDecimal todaySchedulingQuantity;
+    /**
+     * 今天完成数量
+     */
+    private BigDecimal todayFinishQuantity;
+    /**
+     * 明天完成数量
+     */
+    private BigDecimal tomorrowSchedulingQuantity;
+}

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/dto/ProduceOrderDetailSelectDto.java

@@ -57,4 +57,9 @@ public class ProduceOrderDetailSelectDto extends BaseSelectDto {
      */
     private Long contractCompanyId;
 
+    /**
+     * 工序id
+     */
+    private Long processesId;
+
 }

+ 8 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/dto/ProductionSchedulingSelectDto.java

@@ -1,9 +1,12 @@
 package com.fjhx.mes.entity.production.dto;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.Date;
+
 /**
  * 生产排程列表查询入参实体
  *
@@ -24,5 +27,10 @@ public class ProductionSchedulingSelectDto extends BaseSelectDto {
      */
     private Long processesId;
 
+    /**
+     * 排程时间
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    private Date schedulingDate;
 
 }

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/po/ProductionScheduling.java

@@ -47,4 +47,9 @@ public class ProductionScheduling extends BasePo {
      */
     private Long companyId;
 
+    /**
+     * 排程完成数
+     */
+    private Integer finishQuantity;
+
 }

+ 6 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionOrderVo.java

@@ -1,6 +1,7 @@
 package com.fjhx.mes.entity.production.vo;
 
 import com.fjhx.mes.entity.production.po.ProductionOrder;
+import com.fjhx.sale.entity.arrival.vo.ArrivalDetailVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.wms.entity.stock.vo.StockJournalDetailsVo;
 import lombok.Getter;
@@ -65,4 +66,9 @@ public class ProductionOrderVo extends ProductionOrder {
      */
     private String contractCompanyName;
 
+    /**
+     * 到货列表
+     */
+    private List<ArrivalDetailVo> arrivalDetailList;
+
 }

+ 33 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionReportingDetailVo.java

@@ -4,6 +4,8 @@ import com.fjhx.mes.entity.production.po.ProductionReportingDetail;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * 生产报工明细列表查询返回值实体
  *
@@ -36,4 +38,35 @@ public class ProductionReportingDetailVo extends ProductionReportingDetail {
      */
     private String userName;
 
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 产品编号
+     */
+    private String productCode;
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
+    /**
+     * 产品颜色
+     */
+    private String productColor;
+
 }

+ 6 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionTaskProgressVo.java

@@ -5,6 +5,7 @@ import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -32,4 +33,9 @@ public class ProductionTaskProgressVo extends ProductionTaskProgress {
      */
     private Integer schedulingCount;
 
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+
 }

+ 5 - 1
hx-mes/src/main/java/com/fjhx/mes/entity/work/dto/WorkOrderDto.java

@@ -7,11 +7,15 @@ import lombok.Setter;
 /**
  * 工单新增编辑入参实体
  *
- * @author 
+ * @author
  * @since 2023-03-29
  */
 @Getter
 @Setter
 public class WorkOrderDto extends WorkOrder {
 
+    /**
+     * 工单号
+     */
+    private Long artNum;
 }

+ 30 - 1
hx-mes/src/main/java/com/fjhx/mes/entity/work/po/WorkOrder.java

@@ -6,6 +6,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * <p>
@@ -49,7 +50,7 @@ public class WorkOrder extends BasePo {
     /**
      * 说明
      */
-    private String remarks;
+    private String remark;
 
     /**
      * 工单状态
@@ -75,4 +76,32 @@ public class WorkOrder extends BasePo {
      */
     private Long companyId;
 
+    private Long prodTaskId;
+    private Long prodOrderId;
+
+
+    /**
+     * 设备标识
+     */
+    private String deviceIdent;
+
+    /**
+     * 结果0正常 1失败
+     */
+    private Integer result;
+    /**
+     * 备注
+     */
+    private String remak;
+
+    /**
+     * 开始时间
+     */
+    private Date staTime;
+    /**
+     * 结束时间
+     */
+    private Date endTime;
+
+
 }

+ 2 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProduceOrderDetailMapper.java

@@ -23,4 +23,6 @@ public interface ProduceOrderDetailMapper extends BaseMapper<ProductionOrderDeta
      */
     Page<ProductionOrderDetailVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<ProductionOrderDetail> wrapper);
 
+    Page<ProductionOrderDetailVo> schedulingTaskPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<ProductionOrderDetail> wrapper);
+
 }

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionSchedulingMapper.java

@@ -3,6 +3,7 @@ package com.fjhx.mes.mapper.production;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.mes.entity.production.po.ProductionScheduling;
+import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
@@ -29,4 +30,8 @@ public interface ProductionSchedulingMapper extends BaseMapper<ProductionSchedul
      */
     List<ProductionSchedulingVo> listSumQuantity(@Param("ew") IWrapper<ProductionScheduling> wrapper);
 
+    /**
+     * 排程任务列表
+     */
+    List<ProductionOrderDetailVo> schedulingTaskList(@Param("ew") IWrapper<Object> wrapper);
 }

+ 7 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionTaskProgressMapper.java

@@ -1,6 +1,8 @@
 package com.fjhx.mes.mapper.production;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.production.bo.WorkshopReportBo;
 import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
 import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
@@ -26,4 +28,9 @@ public interface ProductionTaskProgressMapper extends BaseMapper<ProductionTaskP
      */
     List<ProductionTaskProgressVo> getList(@Param("ew") IWrapper<ProductionTaskProgress> wrapper);
 
+
+    List<ProductionTaskProgressVo> workshopReportStatistics(@Param("ew") IWrapper<ProductionTaskProgress> wrapper);
+
+    Page<WorkshopReportBo> workshopReport(@Param("page") Page<Object> page, @Param("ew") IWrapper<ProductionTaskProgress> wrapper);
+
 }

+ 17 - 0
hx-mes/src/main/java/com/fjhx/mes/service/DeviceOpenService.java

@@ -0,0 +1,17 @@
+package com.fjhx.mes.service;
+
+import com.fjhx.mes.entity.work.dto.WorkOrderDto;
+
+import java.util.Map;
+
+public interface DeviceOpenService {
+    /**
+     * 生产开始
+     */
+    Map<String, Object> startProduction(WorkOrderDto dto);
+
+    /**
+     * 生产结束
+     */
+    void endProduction(WorkOrderDto dto);
+}

+ 93 - 0
hx-mes/src/main/java/com/fjhx/mes/service/DeviceOpenServiceImpl.java

@@ -0,0 +1,93 @@
+package com.fjhx.mes.service;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+import com.fjhx.common.utils.Assert;
+import com.fjhx.file.entity.FileInfoVo;
+import com.fjhx.file.utils.ObsFileUtil;
+import com.fjhx.iot.entity.tda.po.TdaDevice;
+import com.fjhx.iot.service.tda.TdaDeviceService;
+import com.fjhx.mes.entity.production.po.ProductionOrderDetail;
+import com.fjhx.mes.entity.work.dto.WorkOrderDto;
+import com.fjhx.mes.entity.work.po.WorkOrder;
+import com.fjhx.mes.service.production.ProduceOrderDetailService;
+import com.fjhx.mes.service.work.WorkOrderService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+@Service
+public class DeviceOpenServiceImpl implements DeviceOpenService {
+
+    @Autowired
+    private TdaDeviceService tdaDeviceService;
+    @Autowired
+    private ProduceOrderDetailService produceOrderDetailService;
+    @Autowired
+    private WorkOrderService workOrderService;
+
+    /**
+     * 开始生产
+     */
+    @DSTransactional
+    @Override
+    public Map<String, Object> startProduction(WorkOrderDto dto) {
+        SecurityUtils.setTenantId("000000");
+
+        //根据设备标识获取任务信息
+        String deviceIdent = dto.getDeviceIdent();
+        TdaDevice tdaDevice = tdaDeviceService.getOne(q -> q.eq(TdaDevice::getDeviceCode, deviceIdent));
+        Assert.notEmpty(tdaDevice, "查询不到设备信息");
+        ProductionOrderDetail productionOrderDetail = produceOrderDetailService.getById(tdaDevice.getProdTaskId());
+        Assert.notEmpty(productionOrderDetail, "查询不到任务信息");
+
+        //获取文件信息
+        Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(Arrays.asList(productionOrderDetail.getContractDetailId()), 2);
+        List<FileInfoVo> fileInfoList = fileMap.getOrDefault(productionOrderDetail.getContractDetailId(), new ArrayList<>());
+        if (ObjectUtil.isEmpty(fileInfoList)) {
+            throw new ServiceException("查询不到生产文件信息!");
+        }
+
+        //创建工单
+        dto.setContractId(productionOrderDetail.getContractId());
+        dto.setContractDetailsId(productionOrderDetail.getContractDetailId());
+        dto.setProdTaskId(productionOrderDetail.getId());
+        dto.setProdOrderId(productionOrderDetail.getProduceOrderId());
+        dto.setProductId(productionOrderDetail.getProductId());
+        dto.setQuantity(BigDecimal.ONE);
+        dto.setStatus(1);//进行中
+        dto.setStaTime(new Date());
+        workOrderService.save(dto);
+
+        SecurityUtils.clearTenantId();
+
+        Map<String, Object> data = new HashMap<>();
+        data.put("artNum", dto.getId());//工单号
+        data.put("fileUrl", fileInfoList.get(0).getFileUrl());//生产文件
+        return data;
+    }
+
+    /**
+     * 结束生产
+     */
+    @Override
+    public void endProduction(WorkOrderDto dto) {
+        SecurityUtils.setTenantId("000000");
+
+        Long artNum = dto.getArtNum();
+        Assert.notEmpty(artNum, "工单号不能为空!");
+        WorkOrder byId = workOrderService.getById(artNum);
+        Assert.notEmpty(byId, "查询不到工单信息!");
+
+        dto.setId(artNum);
+        dto.setStatus(2);//已完成
+        dto.setEndTime(new Date());
+        workOrderService.updateById(dto);
+
+        SecurityUtils.clearTenantId();
+    }
+}

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/service/production/ProductionSchedulingService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingDto;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionScheduling;
+import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.ruoyi.common.core.service.BaseService;
 
@@ -39,4 +40,8 @@ public interface ProductionSchedulingService extends BaseService<ProductionSched
      */
     void delete(Long id);
 
+    /**
+     * 获取排程任务列表
+     */
+    List<ProductionOrderDetailVo> schedulingTaskList();
 }

+ 16 - 0
hx-mes/src/main/java/com/fjhx/mes/service/production/ProductionTaskProgressService.java

@@ -1,8 +1,14 @@
 package com.fjhx.mes.service.production;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.production.bo.WorkshopReportBo;
+import com.fjhx.mes.entity.production.dto.ProductionTaskProgressSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
+import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
 import com.ruoyi.common.core.service.BaseService;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -14,4 +20,14 @@ import com.ruoyi.common.core.service.BaseService;
  */
 public interface ProductionTaskProgressService extends BaseService<ProductionTaskProgress> {
 
+
+    /**
+     * 车间统计
+     */
+    List<ProductionTaskProgressVo> workshopReportStatistics(ProductionTaskProgressSelectDto dto);
+
+    /**
+     * 车间看板
+     */
+    Page<WorkshopReportBo> workshopReport(ProductionTaskProgressSelectDto dto);
 }

+ 28 - 12
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderDetailServiceImpl.java

@@ -68,8 +68,34 @@ public class ProduceOrderDetailServiceImpl extends ServiceImpl<ProduceOrderDetai
 
     @Override
     public Page<ProductionOrderDetailVo> getPage(ProduceOrderDetailSelectDto dto) {
+        IWrapper<ProductionOrderDetail> wrapper = getPageCommWrapper(dto);
+
+        Page<ProductionOrderDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+
+        return commPage(page);
+    }
+
+    @Override
+    public Page<ProductionOrderDetailVo> schedulingTaskPage(ProduceOrderDetailSelectDto dto) {
+        IWrapper<ProductionOrderDetail> wrapper = getPageCommWrapper(dto);
+
+        //显示当前工序,未排程完的任务
+        wrapper.eq("ptp.processes_id", dto.getProcessesId());
+        wrapper.groupBy("pod.id");
+        wrapper.having("IFNULL(SUM( ps.quantity ),0)<pod.quantity");
+
+        Page<ProductionOrderDetailVo> page = this.baseMapper.schedulingTaskPage(dto.getPage(), wrapper);
+
+        return commPage(page);
+    }
+
+    private IWrapper<ProductionOrderDetail> getPageCommWrapper(ProduceOrderDetailSelectDto dto) {
         IWrapper<ProductionOrderDetail> wrapper = getWrapper();
 
+        //只显示投产的数据
+        wrapper.isNotNull("po.produce_time");
+
+
         //生产状态
         wrapper.eq("pod", ProductionOrderDetail::getProduceStatus, dto.getProduceStatus());
         //交期-时间范围过滤
@@ -108,22 +134,12 @@ public class ProduceOrderDetailServiceImpl extends ServiceImpl<ProduceOrderDetai
         if (ObjectUtil.isNotEmpty(dto.getContractType())) {
             wrapper.eq("c.contract_type", dto.getContractType());
         }
-
-        return commPage(dto, wrapper);
+        return wrapper;
     }
 
-    @Override
-    public Page<ProductionOrderDetailVo> schedulingTaskPage(ProduceOrderDetailSelectDto dto) {
-        IWrapper<ProductionOrderDetail> wrapper = getWrapper();
-
-        return commPage(dto, wrapper);
-    }
+    private Page<ProductionOrderDetailVo> commPage(Page<ProductionOrderDetailVo> page) {
 
-    private Page<ProductionOrderDetailVo> commPage(ProduceOrderDetailSelectDto dto, IWrapper<ProductionOrderDetail> wrapper) {
-        //只显示投产的数据
-        wrapper.isNotNull("po.produce_time");
 
-        Page<ProductionOrderDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<ProductionOrderDetailVo> records = page.getRecords();
         if (ObjectUtil.isEmpty(records)) {
             return page;

+ 258 - 30
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.entity.AvailableStockBo;
@@ -29,18 +30,22 @@ import com.fjhx.mes.service.production.ProduceOrderService;
 import com.fjhx.mes.service.production.ProductionTaskProgressService;
 import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
+import com.fjhx.sale.entity.arrival.po.ArrivalDetail;
+import com.fjhx.sale.entity.arrival.vo.ArrivalDetailVo;
 import com.fjhx.sale.entity.contract.po.Contract;
 import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.fjhx.sale.entity.contract.po.ContractProductBom;
 import com.fjhx.sale.entity.contract.vo.ContractProductBomVo;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
+import com.fjhx.sale.mapper.arrival.ArrivalDetailMapper;
 import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.contract.ContractProductBomService;
 import com.fjhx.sale.service.contract.ContractProductService;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.socket.core.PushTypeEnum;
 import com.fjhx.socket.core.WebSocketPush;
+import com.fjhx.supply.service.supplier.SupplierInfoService;
 import com.fjhx.tenant.utils.DeptUstil;
 import com.fjhx.wms.entity.stock.emums.JournalType;
 import com.fjhx.wms.entity.stock.po.StockJournalDetails;
@@ -52,7 +57,6 @@ import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.domain.entity.SysDept;
-import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
@@ -107,6 +111,10 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
     private StockWaitService stockWaitService;
     @Autowired
     private StockWaitDetailsService stockWaitDetailsService;
+    @Autowired
+    private ArrivalDetailMapper arrivalDetailMapper;
+    @Autowired
+    private SupplierInfoService supplierInfoService;
 
     @Override
     public Page<ProductionOrderVo> getPage(ProduceOrderSelectDto dto) {
@@ -252,6 +260,12 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
         Long contractId = produceOrderDto.getContractId();
         Assert.notEmpty(produceOrderDto.getContractId(), "合同id不能为空!");
 
+        //赋值原订单信息
+        ProductionOrder one = this.getOne(q -> q.eq(ProductionOrder::getContractId, contractId));
+        if (ObjectUtil.isNotEmpty(one)) {
+            produceOrderDto.setId(one.getId());
+        }
+
         //将数据移到归属公司下
         SysDept produceCompany = sysDeptService.getById(produceOrderDto.getProduceCompanyId());
         Assert.notEmpty(produceCompany, "查询不到生产公司信息");
@@ -273,7 +287,7 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
 
         produceOrderDto.setCode(contract.getCode());
         produceOrderDto.setProduceStatus(0);
-        this.save(produceOrderDto);
+        this.saveOrUpdate(produceOrderDto);
 
 
         //消息推送:给归属公司的 子公司总经理
@@ -367,12 +381,8 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             inOutBoMap.put(materialId, inOutBo);
         }
 
-        List<Long> materialIds = cpBList.stream().map(ContractProductBom::getMaterialId).collect(Collectors.toList());
-        Map<Long, ProductInfo> materialMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, materialIds));
-
         //计算并生成待出库数据
         List<SubscribeDetail> subscribeDetailList = new ArrayList<>();
-
         //获取待采购物料列表
         List<AvailableStockBo> collect = inOutBoMap.values().stream().collect(Collectors.toList());
         //操作可用库存计数需要采购量
@@ -393,11 +403,136 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
                 subscribeDetailList.add(subscribeDetail);
             }
         }
-
         //保存待采购明细
         subscribeDetailService.saveBatch(subscribeDetailList);
     }
 
+    void updateMaterialWaitPurchase(Long newContractId) {
+        Contract newContract = contractService.getById(newContractId);
+        Long oldContractId = newContract.getOldContractId();
+        Long companyId = newContract.getCompanyId();
+        //---------------------------------------------------------------
+        List<ContractProductBomVo> oldProductBomListSum = contractProductBomService.getContractProductBomQuantitySum(oldContractId);
+
+        //获取新合同物料数量Map
+        List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(newContractId);
+        Map<Long, BigDecimal> newQuantityMap = contractProductBomQuantitySum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
+
+
+        List<AvailableStockBo> availableStockBoList = new ArrayList<>();
+
+        //获取已采购数量
+        List<EhsdPurchaseProductVo> purchaseQuantitySumByContractId = ehsdPurchaseProductMapper.getPurchaseQuantitySumByContractId(newContractId);
+        Map<Long, BigDecimal> collect = purchaseQuantitySumByContractId.stream().collect(Collectors.toMap(EhsdPurchaseProduct::getProductId, EhsdPurchaseProduct::getQuantity));
+
+        //旧数据处理
+        for (ContractProductBomVo oldContractProductBom : oldProductBomListSum) {
+            Long materialId = oldContractProductBom.getMaterialId();
+
+            //新数量
+            BigDecimal newQuantity = newQuantityMap.get(materialId);
+            //已采购数量
+            BigDecimal purchaseQuantity = collect.getOrDefault(materialId, BigDecimal.ZERO);
+
+            //获取原需采购量
+            SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q
+                    .eq(SubscribeDetail::getContractId, newContractId)
+                    .eq(SubscribeDetail::getProductId, materialId)
+            );
+            BigDecimal demandPurchaseCount = BigDecimal.ZERO;
+            if (ObjectUtils.isNotEmpty(subscribeDetail)) {
+                demandPurchaseCount = subscribeDetail.getCount();
+            }
+
+
+            //生成操作可用库存的实体
+            AvailableStockBo availableStockBo = new AvailableStockBo();
+            availableStockBo.setProductId(materialId);
+            availableStockBo.setQuantity(oldContractProductBom.getQuantity());
+            availableStockBo.setNewQuantity(newQuantity);
+            availableStockBo.setInStockQuantity(purchaseQuantity);
+            availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
+
+            availableStockBoList.add(availableStockBo);
+
+        }
+
+        //新添加的数据处理
+        Map<Long, BigDecimal> oldQuantityMap = oldProductBomListSum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
+        for (ContractProductBomVo newPurchaseProduct : contractProductBomQuantitySum) {
+            Long materialId = newPurchaseProduct.getMaterialId();
+
+            BigDecimal bigDecimal = oldQuantityMap.get(materialId);
+            //忽略掉变更前有的物料
+            if (ObjectUtils.isNotEmpty(bigDecimal)) {
+                continue;
+            }
+
+            //生成操作可用库存的实体
+            AvailableStockBo availableStockBo = new AvailableStockBo();
+            availableStockBo.setProductId(materialId);
+            availableStockBo.setQuantity(BigDecimal.ZERO);
+            availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
+            availableStockBo.setInStockQuantity(BigDecimal.ZERO);
+            availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
+
+            availableStockBoList.add(availableStockBo);
+        }
+
+
+        //修改可用库存
+        productInfoService.editAvailableQuantity(availableStockBoList, newContractId, ProductAvailableRecordType.SALE_UPDATE, companyId);
+
+
+        //修该待采购量为需采购量
+        for (AvailableStockBo availableStockBo : availableStockBoList) {
+
+            Long materialId = availableStockBo.getProductId();
+            SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q.eq(SubscribeDetail::getContractId, newContractId)
+                    .eq(SubscribeDetail::getProductId, materialId)
+            );
+
+            BigDecimal requiredQuantity = availableStockBo.getNewQuantity();
+
+
+            //需采购量>0
+            if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
+                if (ObjectUtils.isEmpty(subscribeDetail)) {
+                    //生成待采购
+                    subscribeDetail = new SubscribeDetail();
+                    subscribeDetail.setProductId(materialId);
+                    subscribeDetail.setCount(BigDecimal.ZERO);
+                    subscribeDetail.setStatus(15);//待采购
+                    subscribeDetail.setContractId(newContractId);
+                    subscribeDetail.setDataType(1);
+                    subscribeDetail.setCompanyId(companyId);
+                }
+
+                //修改待采购量
+                subscribeDetail.setCount(requiredQuantity);
+
+                //计算状态
+                BigDecimal purchaseQuantity = availableStockBo.getInStockQuantity();
+                int status = purchaseQuantity.compareTo(requiredQuantity) >= 0 ? 20 : 30;
+                if (purchaseQuantity.compareTo(BigDecimal.ZERO) == 0) {
+                    status = 15;
+                }
+                subscribeDetail.setStatus(status);
+
+                subscribeDetailService.saveOrUpdate(subscribeDetail);
+            } else {
+                //需采购==0不显示或删除,<不存在
+                if (ObjectUtils.isNotEmpty(subscribeDetail)) {
+                    subscribeDetailService.removeById(subscribeDetail);
+                }
+            }
+
+
+        }
+
+        //---------------------------------------------------------------
+    }
+
     /**
      * 创建生产任务
      */
@@ -413,19 +548,49 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
         List<ProductionOrderDetail> productionOrderDetailList = new ArrayList<>();
         List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contractId));
 
+        //将被删除的任务作废
+        List<Long> cpIds = contractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
+        produceOrderDetailService.update(q -> q
+                .eq(ProductionOrderDetail::getProduceOrderId, orderDtoId)
+                .eq(ProductionOrderDetail::getContractId, contractId)
+                .notIn(ProductionOrderDetail::getContractDetailId, cpIds)
+                .set(ProductionOrderDetail::getProduceStatus, 99)
+        );
+
         for (ContractProduct contractProduct : contractProductList) {
-            ProductionOrderDetail productionOrderDetail = new ProductionOrderDetail();
+            ProductionOrderDetail productionOrderDetail = produceOrderDetailService.getOne(q -> q
+                    .eq(ProductionOrderDetail::getProduceOrderId, orderDtoId)
+                    .eq(ProductionOrderDetail::getContractId, contractId)
+                    .eq(ProductionOrderDetail::getContractDetailId, contractProduct.getId())
+            );
+            if (ObjectUtil.isEmpty(productionOrderDetail)) {
+                productionOrderDetail = new ProductionOrderDetail();
+                productionOrderDetail.setFinishQuantity(BigDecimal.ZERO);
+            }
             productionOrderDetail.setProduceOrderId(orderDtoId);
             productionOrderDetail.setContractId(contractId);
             productionOrderDetail.setContractDetailId(contractProduct.getId());
             productionOrderDetail.setProductId(contractProduct.getProductId());
             productionOrderDetail.setQuantity(contractProduct.getQuantity());
-            productionOrderDetail.setFinishQuantity(BigDecimal.ZERO);
+
+            //修改状态
+            if (productionOrderDetail.getFinishQuantity().compareTo(productionOrderDetail.getQuantity()) >= 0) {
+                //生产完成
+                productionOrderDetail.setProduceStatus(2);
+            } else {
+                //进行中
+                productionOrderDetail.setProduceStatus(1);
+            }
+            if (productionOrderDetail.getFinishQuantity().compareTo(BigDecimal.ZERO) == 0) {
+                //未开始
+                productionOrderDetail.setProduceStatus(0);
+            }
+
             productionOrderDetail.setProduceStatus(0);
             productionOrderDetail.setCompanyId(companyId);
             productionOrderDetailList.add(productionOrderDetail);
         }
-        produceOrderDetailService.saveBatch(productionOrderDetailList);
+        produceOrderDetailService.saveOrUpdateBatch(productionOrderDetailList);
 
         List<Long> productIds = productionOrderDetailList.stream().map(ProductionOrderDetail::getProductId).collect(Collectors.toList());
 
@@ -436,21 +601,31 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
         for (ProductionOrderDetail productionOrderDetail : productionOrderDetailList) {
             List<ProductionProcessesVo> productionProcessesVos = processesMap.getOrDefault(productionOrderDetail.getProductId(), new ArrayList<>());
             for (ProductionProcessesVo productionProcessesVo : productionProcessesVos) {
-                ProductionTaskProgress prodTaskProgress = new ProductionTaskProgress();
+                ProductionTaskProgress prodTaskProgress = productionTaskProgressService.getOne(q -> q
+                        .eq(ProductionTaskProgress::getTaskId, productionOrderDetail.getId())
+                        .eq(ProductionTaskProgress::getProcessesId, productionProcessesVo.getId())
+                );
+                if (ObjectUtil.isEmpty(prodTaskProgress)) {
+                    prodTaskProgress = new ProductionTaskProgress();
+                    prodTaskProgress.setFinishQuantity(BigDecimal.ZERO);
+                }
                 prodTaskProgress.setTaskId(productionOrderDetail.getId());
                 prodTaskProgress.setProcessesId(productionProcessesVo.getId());
-                prodTaskProgress.setFinishQuantity(BigDecimal.ZERO);
 
                 //如果是第一道工序,结存数量直接等于任务数量
                 prodTaskProgress.setBalanceQuantity(BigDecimal.ZERO);
                 if (ObjectUtil.equals(productionProcessesVo.getSourceProcessesId(), 1L)) {
-                    prodTaskProgress.setBalanceQuantity(productionOrderDetail.getQuantity());
+                    BigDecimal balanceQuantity = productionOrderDetail.getQuantity().subtract(prodTaskProgress.getFinishQuantity());
+                    if (balanceQuantity.compareTo(BigDecimal.ZERO) < 0) {
+                        balanceQuantity = BigDecimal.ZERO;
+                    }
+                    prodTaskProgress.setBalanceQuantity(balanceQuantity);
                 }
 
                 productionTaskProgressList.add(prodTaskProgress);
             }
         }
-        productionTaskProgressService.saveBatch(productionTaskProgressList);
+        productionTaskProgressService.saveOrUpdateBatch(productionTaskProgressList);
     }
 
     /**
@@ -480,18 +655,29 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             for (ContractProductBom bomDetail : contractProductBomList) {
                 BigDecimal multiply = bomDetail.getQuantity().multiply(productionOrderDetail.getQuantity());
 
-                MaterialPreparation materialPreparation = new MaterialPreparation();
+                MaterialPreparation materialPreparation = materialPreparationService.getOne(q -> q
+                        .eq(MaterialPreparation::getProductionOrderDetailId, productionOrderDetail.getId())
+                        .eq(MaterialPreparation::getMaterialId, bomDetail.getMaterialId())
+                );
+
+                if (ObjectUtil.isEmpty(materialPreparation)) {
+                    materialPreparation = new MaterialPreparation();
+                    materialPreparation.setStatus(0);
+                } else {
+                    if (materialPreparation.getQuantity().compareTo(multiply) != 0 && materialPreparation.getStatus() == 1) {
+                        materialPreparation.setStatus(0);
+                    }
+                }
                 materialPreparation.setContractId(contractId);
                 materialPreparation.setContractDetailId(productionOrderDetail.getContractDetailId());
                 materialPreparation.setProductionOrderId(productionOrder.getId());
                 materialPreparation.setProductionOrderDetailId(productionOrderDetail.getId());
                 materialPreparation.setMaterialId(bomDetail.getMaterialId());
                 materialPreparation.setQuantity(multiply);
-                materialPreparation.setStatus(0);
                 materialPreparation.setCompanyId(companyId);
                 materialPreparationList.add(materialPreparation);
             }
-            materialPreparationService.saveBatch(materialPreparationList);
+            materialPreparationService.saveOrUpdateBatch(materialPreparationList);
         }
 
         produceOrderDetailService.updateBatchById(productionOrderDetailList);
@@ -523,16 +709,21 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             msg.put("business_id", productionOrder.getId());
             WebSocketPush.byUser(PushTypeEnum.MESSAGE, productionOrder.getCreateUser(), title, PushBusinessTypeEnum.PRODUCTION_ORDER_REJECT.getType(), msg.toString());
         } else {
-            //创建待采购
-            createMaterialWaitPurchase(productionOrder);
+            if (produceOrderDetailService.count(q -> q.eq(ProductionOrderDetail::getProduceOrderId, dto.getId())) > 0) {
+                //创建待采购
+                createMaterialWaitPurchase(productionOrder);
+            } else {
+                //修改待采购
+                updateMaterialWaitPurchase(productionOrder.getContractId());
+            }
 
             //创建生产任务
             createOrderDetails(productionOrder);
 
-            //投产
-            if (ObjectUtil.isNotEmpty(productionOrder.getProduceTime())) {
-                throw new ServiceException("该订单已投产,请勿重复投产!!");
-            }
+//            //投产
+//            if (ObjectUtil.isNotEmpty(productionOrder.getProduceTime())) {
+//                throw new ServiceException("该订单已投产,请勿重复投产!!");
+//            }
 
             //生成待备料
             createMaterialPreparation(productionOrder);
@@ -549,28 +740,47 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
 
     private void createStockWait(ProductionOrder productionOrder) {
         //生成待出库
-        StockWait stockWait = new StockWait();
+        StockWait stockWait = stockWaitService.getOne(q -> q
+                .eq(StockWait::getBusinessId, productionOrder.getId())
+                .eq(StockWait::getBusinessType, JournalType.PROD_OUT.getDetailType())
+        );
+
+        if (ObjectUtil.isEmpty(stockWait)) {
+            stockWait = new StockWait();
+            stockWait.setStatus(0);//待出库
+        } else {
+            stockWait.setStatus(1);//部分出库
+        }
         stockWait.setCompanyId(SecurityUtils.getCompanyId());
         stockWait.setBusinessId(productionOrder.getId());
         stockWait.setType(2);//出库
-        stockWait.setStatus(0);//待出库
+
         stockWait.setBusinessType(JournalType.PROD_OUT.getDetailType());//生产任务出库
         stockWait.setContractId(productionOrder.getContractId());
         stockWait.setBusinessCode(productionOrder.getCode());
-        stockWaitService.save(stockWait);
+        stockWaitService.saveOrUpdate(stockWait);
 
         List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
         List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(productionOrder.getContractId());
         for (ContractProductBomVo contractProductBomVo : contractProductBomQuantitySum) {
             //创建待出库明细
-            StockWaitDetails stockWaitDetails = new StockWaitDetails();
-            stockWaitDetails.setStockWaitId(stockWait.getId());
+            Long stockWaitId = stockWait.getId();
+            StockWaitDetails stockWaitDetails = stockWaitDetailsService.getOne(q -> q
+                    .eq(StockWaitDetails::getStockWaitId, stockWaitId)
+                    .eq(StockWaitDetails::getProductId, contractProductBomVo.getMaterialId())
+            );
+
+            if (ObjectUtil.isEmpty(stockWaitDetails)) {
+                stockWaitDetails = new StockWaitDetails();
+                stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
+            }
+
+            stockWaitDetails.setStockWaitId(stockWaitId);
             stockWaitDetails.setProductId(contractProductBomVo.getMaterialId());
             stockWaitDetails.setQuantity(contractProductBomVo.getQuantity());
-            stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
             stockWaitDetailsList.add(stockWaitDetails);
         }
-        stockWaitDetailsService.saveBatch(stockWaitDetailsList);
+        stockWaitDetailsService.saveOrUpdateBatch(stockWaitDetailsList);
     }
 
     @Override
@@ -589,9 +799,14 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
         Assert.notEmpty(productionOrder, "查询不到生产订单信息");
         ProductionOrderVo productionOrderVo = BeanUtil.copyProperties(productionOrder, ProductionOrderVo.class);
 
+        //采购记录
         List<EhsdPurchaseProductVo> ehsdPurchaseProductVos = ehsdPurchaseProductMapper.getList(IWrapper.<EhsdPurchaseProduct>getWrapper()
                 .eq("epp", EhsdPurchaseProduct::getContractId, productionOrder.getContractId())
         );
+        //赋值卖方信息
+        supplierInfoService.attributeAssign(ehsdPurchaseProductVos, EhsdPurchaseProductVo::getSellCorporationId, (item, supplier) -> {
+            item.setSellCorporationName(supplier.getName());
+        });
         //赋值产品信息
         productInfoService.attributeAssign(ehsdPurchaseProductVos, EhsdPurchaseProductVo::getProductId, (detail, product) -> {
             detail.setProductCode(product.getCustomCode());
@@ -603,6 +818,7 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             detail.setProductColor(product.getColor());
         });
 
+        //出入库流水记录
         List<StockJournalDetailsVo> stockJournalDetailsVos = stockJournalDetailsMapper.getList(IWrapper.<StockJournalDetails>getWrapper()
                 .eq("sj", StockJournalDetails::getContractId, productionOrder.getContractId())
         );
@@ -618,6 +834,18 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
             detail.setProductColor(product.getColor());
         });
 
+        //到货通知记录
+        List<Long> pIds = ehsdPurchaseProductVos.stream().map(item -> item.getPurchaseId()).collect(Collectors.toList());
+        if (ObjectUtil.isNotEmpty(pIds)) {
+            List<ArrivalDetailVo> arrivalDetailVos = arrivalDetailMapper.getList(IWrapper.<ArrivalDetail>getWrapper()
+                    .in("ad.purchase_id", pIds)
+            );
+
+            //赋值结果
+            productionOrderVo.setArrivalDetailList(arrivalDetailVos);
+        }
+
+        //赋值结果
         productionOrderVo.setPurchaseProductList(ehsdPurchaseProductVos);
         productionOrderVo.setStockJournalDetailsList(stockJournalDetailsVos);
 

+ 14 - 1
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionReportingDetailServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
 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.item.service.product.ProductInfoService;
 import com.fjhx.mes.entity.production.dto.ProductionReportingDetailDto;
 import com.fjhx.mes.entity.production.dto.ProductionReportingDetailSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionReportingDetail;
@@ -37,10 +38,12 @@ import java.util.stream.Collectors;
 public class ProductionReportingDetailServiceImpl extends ServiceImpl<ProductionReportingDetailMapper, ProductionReportingDetail> implements ProductionReportingDetailService {
 
     private final ISysUserService sysUserService;
+    private final ProductInfoService productInfoService;
 
     @Autowired
-    public ProductionReportingDetailServiceImpl(ISysUserService sysUserService) {
+    public ProductionReportingDetailServiceImpl(ISysUserService sysUserService, ProductInfoService productInfoService) {
         this.sysUserService = sysUserService;
+        this.productInfoService = productInfoService;
     }
 
     @Override
@@ -85,6 +88,16 @@ public class ProductionReportingDetailServiceImpl extends ServiceImpl<Production
             record.setCompanyName(companyNameMap.get(record.getCompanyId()));
         }
 
+        //赋值产品信息
+        productInfoService.attributeAssign(records, ProductionReportingDetailVo::getProductId, (item, productInfo) -> {
+            item.setProductName(productInfo.getName());
+            item.setProductCode(productInfo.getCustomCode());
+            item.setProductLength(productInfo.getLength());
+            item.setProductWidth(productInfo.getWidth());
+            item.setProductHeight(productInfo.getHeight());
+            item.setProductColor(productInfo.getColor());
+        });
+
         return page;
     }
 

+ 21 - 7
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionReportingServiceImpl.java

@@ -57,6 +57,8 @@ public class ProductionReportingServiceImpl extends ServiceImpl<ProductionReport
     private TechnologyProcessLineService technologyProcessLineService;
     @Autowired
     private ProduceOrderService produceOrderService;
+    @Autowired
+    private ProductionSchedulingService productionSchedulingService;
 
 
     @Override
@@ -160,6 +162,16 @@ public class ProductionReportingServiceImpl extends ServiceImpl<ProductionReport
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
 
+        //更新排程信息
+        productionSchedulingService.update(q -> q
+                .eq(ProductionScheduling::getTaskId, productionTaskId)
+                .eq(ProductionScheduling::getProcessesId, productionProcessesId)
+                .setSql("finish_quantity = finish_quantity + " + dto.getQuantity())
+                .set(BasePo::getUpdateTime, newDateTime)
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+
         //更新完工数量
         ProductionOrderDetail productionOrderDetail = produceOrderDetailService.getById(productionTaskId);
         Assert.notEmpty(productionOrderDetail, "查询不到生产任务信息!");
@@ -173,13 +185,15 @@ public class ProductionReportingServiceImpl extends ServiceImpl<ProductionReport
                 .eq(TechnologyProcessLine::getSourceProcessesId, productionProcessesId)
                 .ne(TechnologyProcessLine::getTargetProcessesId, 99)
         );
-        productionTaskProgressService.update(q -> q
-                .eq(ProductionTaskProgress::getTaskId, productionTaskId)
-                .in(ProductionTaskProgress::getProcessesId, nextProcessIds)
-                .setSql("balance_quantity = balance_quantity + " + dto.getQuantity())
-                .set(BasePo::getUpdateTime, newDateTime)
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
+        if (ObjectUtil.isNotEmpty(nextProcessIds)) {
+            productionTaskProgressService.update(q -> q
+                    .eq(ProductionTaskProgress::getTaskId, productionTaskId)
+                    .in(ProductionTaskProgress::getProcessesId, nextProcessIds)
+                    .setSql("balance_quantity = balance_quantity + " + dto.getQuantity())
+                    .set(BasePo::getUpdateTime, newDateTime)
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+        }
 
 
         //判断报工工序是不是最后一道工序,是增加完工数量

+ 60 - 4
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionSchedulingServiceImpl.java

@@ -4,19 +4,23 @@ import cn.hutool.core.util.ObjectUtil;
 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.service.product.ProductInfoService;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingDto;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionOrder;
 import com.fjhx.mes.entity.production.po.ProductionScheduling;
+import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.fjhx.mes.mapper.production.ProductionSchedulingMapper;
 import com.fjhx.mes.service.production.ProductionSchedulingService;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -50,6 +54,11 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
         wrapper.in("po", ProductionOrder::getCompanyId, SecurityUtils.getCompanyIds());
         wrapper.eq("po", ProductionOrder::getCompanyId, dto.getCompanyId());
 
+        //排程日期过滤
+        wrapper.eq("ps", ProductionScheduling::getSchedulingDate, dto.getSchedulingDate());
+
+        wrapper.orderByDesc("ps.scheduling_date");
+
         Page<ProductionSchedulingVo> page = baseMapper.getPage(dto.getPage(), wrapper);
         List<ProductionSchedulingVo> records = page.getRecords();
         if (ObjectUtil.isEmpty(records)) {
@@ -88,20 +97,67 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
     @DSTransactional
     @Override
     public void add(List<ProductionScheduling> dtoList) {
-        for (ProductionScheduling productionSchedulingDto : dtoList) {
-            productionSchedulingDto.setCompanyId(SecurityUtils.getCompanyId());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        for (ProductionScheduling dto : dtoList) {
+            dto.setCompanyId(SecurityUtils.getCompanyId());
+
+            long count = this.count(q -> q
+                    .eq(ProductionScheduling::getTaskId, dto.getTaskId())
+                    .eq(ProductionScheduling::getProcessesId, dto.getProcessesId())
+                    .eq(ProductionScheduling::getSchedulingDate, dto.getSchedulingDate())
+            );
+            if (count > 0) {
+                throw new ServiceException(sdf.format(dto.getSchedulingDate()) + "已有排程信息,请前往修改或删除!");
+            }
         }
         this.saveBatch(dtoList);
     }
 
     @Override
-    public void edit(ProductionSchedulingDto productionSchedulingDto) {
-        this.updateById(productionSchedulingDto);
+    public void edit(ProductionSchedulingDto dto) {
+        ProductionScheduling oldPs = this.getById(dto.getId());
+        Assert.notEmpty(oldPs, "查询不到排程信息!");
+
+        if (dto.getQuantity() < oldPs.getFinishQuantity()) {
+            throw new ServiceException("排程数量不能小于已完工数量!");
+        }
+
+        this.updateById(dto);
     }
 
     @Override
     public void delete(Long id) {
+        ProductionScheduling oldPs = this.getById(id);
+        Assert.notEmpty(oldPs, "查询不到排程信息!");
+
+        if (oldPs.getFinishQuantity() > 0) {
+            throw new ServiceException("该排程已有完工信息,禁止删除!");
+        }
+
         this.removeById(id);
     }
 
+    @Override
+    public List<ProductionOrderDetailVo> schedulingTaskList() {
+        IWrapper<Object> wrapper = IWrapper.getWrapper();
+        //获取当天排程的任务
+        wrapper.eq("DATEDIFF( now(), ps.scheduling_date )", 0);
+        wrapper.groupBy("pod.id");
+        List<ProductionOrderDetailVo> voList = baseMapper.schedulingTaskList(wrapper);
+
+        //赋值产品信息
+        productInfoService.attributeAssign(voList, ProductionOrderDetailVo::getProductId, (item, productInfo) -> {
+            item.setProductName(productInfo.getName());
+            item.setProductCode(productInfo.getCustomCode());
+            item.setProductLength(productInfo.getLength());
+            item.setProductWidth(productInfo.getWidth());
+            item.setProductHeight(productInfo.getHeight());
+            item.setProductColor(productInfo.getColor());
+        });
+
+        //赋值任务信息
+
+        return voList;
+    }
+
 }

+ 53 - 0
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionTaskProgressServiceImpl.java

@@ -1,11 +1,22 @@
 package com.fjhx.mes.service.production.impl;
 
+import cn.hutool.core.util.ObjectUtil;
+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.production.bo.WorkshopReportBo;
+import com.fjhx.mes.entity.production.dto.ProductionTaskProgressSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
+import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
 import com.fjhx.mes.mapper.production.ProductionTaskProgressMapper;
 import com.fjhx.mes.service.production.ProductionTaskProgressService;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -18,4 +29,46 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProductionTaskProgressServiceImpl extends ServiceImpl<ProductionTaskProgressMapper, ProductionTaskProgress> implements ProductionTaskProgressService {
 
+    @Autowired
+    private ProductInfoService productInfoService;
+
+    private IWrapper<ProductionTaskProgress> getWorkshopReportWrapper(ProductionTaskProgressSelectDto dto) {
+        IWrapper<ProductionTaskProgress> wrapper = getWrapper();
+        wrapper.in("pod.company_id", SecurityUtils.getCompanyIds());
+        return wrapper;
+    }
+
+    @Override
+    public List<ProductionTaskProgressVo> workshopReportStatistics(ProductionTaskProgressSelectDto dto) {
+        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper(dto);
+        wrapper.eq("DATEDIFF(  ps.scheduling_date,now() )", 0);
+        wrapper.groupBy("ptp.processes_id");
+        List<ProductionTaskProgressVo> workshopReportStatistics = baseMapper.workshopReportStatistics(wrapper);
+        return workshopReportStatistics;
+    }
+
+    @Override
+    public Page<WorkshopReportBo> workshopReport(ProductionTaskProgressSelectDto dto) {
+        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper(dto);
+
+        //过滤 昨天 今天 明天
+        wrapper.in("DATEDIFF(ps.scheduling_date, now())", -1, 0, 1);
+        wrapper.groupBy("ptp.id");
+
+        Page<WorkshopReportBo> workshopReportBoPage = baseMapper.workshopReport(dto.getPage(), wrapper);
+        List<WorkshopReportBo> records = workshopReportBoPage.getRecords();
+        if (ObjectUtil.isEmpty(records)) {
+            return workshopReportBoPage;
+        }
+        //赋值产品信息
+        productInfoService.attributeAssign(records, WorkshopReportBo::getProductId, (item, productInfo) -> {
+            item.setProductName(productInfo.getName());
+            item.setProductCode(productInfo.getCustomCode());
+            item.setProductLength(productInfo.getLength());
+            item.setProductWidth(productInfo.getWidth());
+            item.setProductHeight(productInfo.getHeight());
+            item.setProductColor(productInfo.getColor());
+        });
+        return workshopReportBoPage;
+    }
 }

+ 16 - 3
hx-mes/src/main/resources/mapper/production/ProduceOrderDetailMapper.xml

@@ -1,8 +1,9 @@
 <?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.production.ProduceOrderDetailMapper">
-	<select id="getPage" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo">
-		SELECT pod.id,
+
+    <sql id="page">
+        SELECT pod.id,
                pod.produce_order_id,
                pod.contract_id,
                pod.contract_detail_id,
@@ -32,6 +33,18 @@
         FROM production_order_detail pod
                  LEFT JOIN production_order po ON pod.produce_order_id = po.id
                  LEFT JOIN contract c ON pod.contract_id = c.id
-            ${ew.customSqlSegment}
+    </sql>
+
+    <select id="getPage" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo">
+        <include refid="page"/>
+        ${ew.customSqlSegment}
+    </select>
+
+    <select id="schedulingTaskPage" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo">
+        <include refid="page"/>
+        LEFT JOIN production_task_progress ptp ON ptp.task_id = pod.id
+        LEFT JOIN production_scheduling ps ON ps.task_id = ptp.task_id
+        AND ps.processes_id = ptp.processes_id
+        ${ew.customSqlSegment}
     </select>
 </mapper>

+ 1 - 1
hx-mes/src/main/resources/mapper/production/ProductionProcessesMapper.xml

@@ -29,7 +29,7 @@
                pi.id as productId,
                tpl.source_processes_id
         FROM production_processes pp
-                 JOIN technology_process_line tpl ON tpl.source_processes_id = pp.id
+                 JOIN technology_process_line tpl ON tpl.target_processes_id = pp.id
                  JOIN product_info pi ON pi.technology_id = tpl.technology_id
             ${ew.customSqlSegment}
     </select>

+ 2 - 1
hx-mes/src/main/resources/mapper/production/ProductionReportingDetailMapper.xml

@@ -13,7 +13,8 @@
                po.`code` AS orderCode,
                pp.`name` AS processesName,
                prd.company_id,
-               prd.user_id
+               prd.user_id,
+               pod.product_id
         FROM production_reporting_detail prd
                  LEFT JOIN production_order_detail pod ON prd.production_task_id = pod.id
                  LEFT JOIN production_order po ON pod.produce_order_id = po.id

+ 8 - 0
hx-mes/src/main/resources/mapper/production/ProductionSchedulingMapper.xml

@@ -35,5 +35,13 @@
                  JOIN production_processes pp ON ps.processes_id = pp.id
             ${ew.customSqlSegment}
     </select>
+    <select id="schedulingTaskList" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo">
+        SELECT pod.*,
+               po.`code` AS orderCode
+        FROM production_order_detail pod
+                 LEFT JOIN production_order po ON pod.produce_order_id = po.id
+                 JOIN production_scheduling ps ON ps.task_id = pod.id
+            ${ew.customSqlSegment}
+    </select>
 
 </mapper>

+ 56 - 0
hx-mes/src/main/resources/mapper/production/ProductionTaskProgressMapper.xml

@@ -13,4 +13,60 @@
                  LEFT JOIN production_processes pp ON ptp.processes_id = pp.id
             ${ew.customSqlSegment}
     </select>
+    <select id="workshopReport" resultType="com.fjhx.mes.entity.production.bo.WorkshopReportBo">
+        SELECT ptp.id,
+               pod.id                                                       AS task_id,
+               pod.produce_order_id,
+               pp.id                                                        AS progressId,
+               pp.`name`                                                    AS progressName,
+               po.`code`                                                    AS orderCode,
+               pod.product_id,
+               pod.quantity,
+               ptp.finish_quantity,
+               (pod.quantity - ptp.finish_quantity)                         AS residueQuantity,
+               IFNULL((SELECT sum(quantity)
+                       FROM production_scheduling ps
+                       WHERE ps.task_id = pod.id
+                         AND ps.processes_id = ptp.processes_id
+                         AND DATEDIFF(ps.scheduling_date, now()) = - 1), 0) as yesterdaySchedulingQuantity,
+               IFNULL((SELECT sum(finish_quantity)
+                       FROM production_scheduling ps
+                       WHERE ps.task_id = pod.id
+                         AND ps.processes_id = ptp.processes_id
+                         AND DATEDIFF(ps.scheduling_date, now()) = - 1), 0) as yesterdayFinishQuantity,
+               IFNULL((SELECT sum(quantity)
+                       FROM production_scheduling ps
+                       WHERE ps.task_id = pod.id
+                         AND ps.processes_id = ptp.processes_id
+                         AND DATEDIFF(ps.scheduling_date, now()) = 0), 0)   as todaySchedulingQuantity,
+               IFNULL((SELECT sum(finish_quantity)
+                       FROM production_scheduling ps
+                       WHERE ps.task_id = pod.id
+                         AND ps.processes_id = ptp.processes_id
+                         AND DATEDIFF(ps.scheduling_date, now()) = 0), 0)   as todayFinishQuantity,
+               IFNULL((SELECT sum(quantity)
+                       FROM production_scheduling ps
+                       WHERE ps.task_id = pod.id
+                         AND ps.processes_id = ptp.processes_id
+                         AND DATEDIFF(ps.scheduling_date, now()) = 1), 0)   as tomorrowSchedulingQuantity
+        FROM production_task_progress ptp
+                 LEFT JOIN production_processes pp ON ptp.processes_id = pp.id
+                 LEFT JOIN production_order_detail pod ON ptp.task_id = pod.id
+                 LEFT JOIN production_order po ON pod.produce_order_id = po.id
+                 LEFT JOIN production_scheduling ps on ps.task_id = pod.id AND ps.processes_id = ptp.processes_id
+            ${ew.customSqlSegment}
+    </select>
+    <select id="workshopReportStatistics"
+            resultType="com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo">
+        SELECT ptp.processes_id,
+               pp.`name`                          AS progressName,
+               IFNULL(sum(ps.quantity), 0)        AS quantity,
+               IFNULL(sum(ps.finish_quantity), 0) AS finishQuantity
+        FROM production_task_progress ptp
+                 LEFT JOIN production_processes pp ON ptp.processes_id = pp.id
+                 LEFT JOIN production_order_detail pod ON ptp.task_id = pod.id
+                 LEFT JOIN production_scheduling ps ON ps.task_id = pod.id
+            AND ps.processes_id = ptp.processes_id
+            ${ew.customSqlSegment}
+    </select>
 </mapper>

+ 80 - 80
hx-purchase/src/main/java/com/fjhx/purchase/flow/RefundFlow.java

@@ -1,80 +1,80 @@
-package com.fjhx.purchase.flow;
-
-import cn.hutool.extra.spring.SpringUtil;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
-import com.fjhx.common.constant.SourceConstant;
-import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.purchase.entity.pay.enums.PayStatusEnum1;
-import com.fjhx.purchase.entity.refund.po.Refund;
-import com.fjhx.purchase.entity.refund.po.RefundDetail;
-import com.fjhx.purchase.service.refund.RefundDetailService;
-import com.fjhx.purchase.service.refund.RefundService;
-import com.ruoyi.common.exception.ServiceException;
-import org.springframework.stereotype.Component;
-
-import java.util.Date;
-import java.util.List;
-
-/**
- * 退货流程
- * @Author:caozj
- * @DATE:2023/4/3 17:38
- */
-//@DS(SourceConstant.PURCHASE)
-@Component
-public class RefundFlow extends FlowDelegate {
-
-    @Override
-    public String getFlowKey() {
-        return "refund_flow";
-    }
-
-
-    /**
-     * 发起流程
-     * @param flowId 流程ID
-     * @param submitData 数据
-     * @return
-     */
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        RefundService refundService = SpringUtil.getBean(RefundService.class);
-        RefundDetailService refundDetailService = SpringUtil.getBean(RefundDetailService.class);
-        Refund refund = submitData.toJavaObject(Refund.class);
-        refund.setStatus(PayStatusEnum1.UNDER_REVIEW.getKey());
-        refundService.save(refund);
-        List<RefundDetail> refundDetailList = refund.getRefundDetailList();
-        if(CollectionUtils.isNotEmpty(refundDetailList)){
-            for(RefundDetail s : refundDetailList){
-                s.setRefundId(refund.getId());
-            }
-            refundDetailService.saveBatch(refundDetailList);
-        }
-        return refund.getId();
-    }
-
-    /**
-     * 结束流程
-     * @param flowId 流程ID
-     * @param businessId 业务ID
-     * @param submitData 数据
-     */
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        RefundService refundService = SpringUtil.getBean(RefundService.class);
-        //通过业务ID查询申购数据
-        Refund refund = refundService.getById(businessId);
-        if(ObjectUtils.isEmpty(refund)){
-            throw new ServiceException("退款单不存在");
-        }
-        //修改采购状态为审批通过
-        refund.setStatus(PayStatusEnum1.PASS.getKey());
-        refund.setApprovedDate(new Date());
-        refundService.updateById(refund);
-    }
-
-}
+//package com.fjhx.purchase.flow;
+//
+//import cn.hutool.extra.spring.SpringUtil;
+//import com.alibaba.fastjson.JSONObject;
+//import com.baomidou.dynamic.datasource.annotation.DS;
+//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+//import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+//import com.fjhx.common.constant.SourceConstant;
+//import com.fjhx.flow.core.FlowDelegate;
+//import com.fjhx.flow.enums.FlowStatusEnum;
+//import com.fjhx.purchase.entity.pay.enums.PayStatusEnum1;
+//import com.fjhx.purchase.entity.refund.po.Refund;
+//import com.fjhx.purchase.entity.refund.po.RefundDetail;
+//import com.fjhx.purchase.service.refund.RefundDetailService;
+//import com.fjhx.purchase.service.refund.RefundService;
+//import com.ruoyi.common.exception.ServiceException;
+//import org.springframework.stereotype.Component;
+//
+//import java.util.Date;
+//import java.util.List;
+//
+///**
+// * 退货流程
+// * @Author:caozj
+// * @DATE:2023/4/3 17:38
+// */
+////@DS(SourceConstant.PURCHASE)
+//@Component
+//public class RefundFlow extends FlowDelegate {
+//
+//    @Override
+//    public String getFlowKey() {
+//        return "refund_flow";
+//    }
+//
+//
+//    /**
+//     * 发起流程
+//     * @param flowId 流程ID
+//     * @param submitData 数据
+//     * @return
+//     */
+//    @Override
+//    public Long start(Long flowId, JSONObject submitData) {
+//        RefundService refundService = SpringUtil.getBean(RefundService.class);
+//        RefundDetailService refundDetailService = SpringUtil.getBean(RefundDetailService.class);
+//        Refund refund = submitData.toJavaObject(Refund.class);
+//        refund.setStatus(PayStatusEnum1.UNDER_REVIEW.getKey());
+//        refundService.save(refund);
+//        List<RefundDetail> refundDetailList = refund.getRefundDetailList();
+//        if(CollectionUtils.isNotEmpty(refundDetailList)){
+//            for(RefundDetail s : refundDetailList){
+//                s.setRefundId(refund.getId());
+//            }
+//            refundDetailService.saveBatch(refundDetailList);
+//        }
+//        return refund.getId();
+//    }
+//
+//    /**
+//     * 结束流程
+//     * @param flowId 流程ID
+//     * @param businessId 业务ID
+//     * @param submitData 数据
+//     */
+//    @Override
+//    public void end(Long flowId, Long businessId, JSONObject submitData) {
+//        RefundService refundService = SpringUtil.getBean(RefundService.class);
+//        //通过业务ID查询申购数据
+//        Refund refund = refundService.getById(businessId);
+//        if(ObjectUtils.isEmpty(refund)){
+//            throw new ServiceException("退款单不存在");
+//        }
+//        //修改采购状态为审批通过
+//        refund.setStatus(PayStatusEnum1.PASS.getKey());
+//        refund.setApprovedDate(new Date());
+//        refundService.updateById(refund);
+//    }
+//
+//}

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java

@@ -349,7 +349,7 @@ public class Contract extends BasePo {
     private Integer isShow;
 
     /**
-     * 订单下发状态
+     * 订单下发状态 0未下发 1已下发
      */
     private Integer orderDistributeStatus;
 

+ 2 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/ext/dto/ExtQuotationProductSelectDto.java

@@ -14,4 +14,6 @@ import lombok.Setter;
 @Setter
 public class ExtQuotationProductSelectDto extends BaseSelectDto {
 
+    private Long companyId;
+
 }

+ 10 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/ext/po/ExtQuotation.java

@@ -130,4 +130,14 @@ public class ExtQuotation extends BasePo {
      * 创建产品状态 0待创建 1创建中 2已创建
      */
     private Integer createProductStatus;
+
+    /**
+     * 归属部门id
+     */
+    private Long ofDeptId;
+
+    /**
+     * 生成待创建产品时间
+     */
+    private Date waitProductTime;
 }

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/ext/vo/ExtQuotationProductVo.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -18,6 +19,9 @@ import java.util.List;
 public class ExtQuotationProductVo extends ExtQuotationProduct {
 
     List<ExtQuotationProductBomVo> quotationProductBomList;
+    private String extQuotationCode;
+    private String quotationCode;
+
     private String productCode;
     private String productName;
     private BigDecimal productLength;
@@ -67,4 +71,9 @@ public class ExtQuotationProductVo extends ExtQuotationProduct {
      */
     private String rawMaterialNetWeight;
 
+    /**
+     * 待创建产品生成时间
+     */
+    private Date waitProductTime;
+
 }

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBack.java

@@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * sale_采购退货
@@ -43,4 +45,11 @@ public class PurchaseBack extends BasePo {
      */
     private Long companyId;
 
+    /**
+     * 退货金额
+     */
+    private BigDecimal amount;
+
+    private Long flowId;
+
 }

+ 2 - 2
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBackDetails.java

@@ -46,9 +46,9 @@ public class PurchaseBackDetails extends BasePo {
     private BigDecimal quantity;
 
     /**
-     * 金额
+     * 单价
      */
-    private BigDecimal amount;
+    private BigDecimal price;
 
     /**
      * 备注

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java

@@ -88,4 +88,13 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
     private String productColor;
 
     private BigDecimal arrivalQuantity;
+
+    /**
+     * 供应商id
+     */
+    private Long sellCorporationId;
+    /**
+     * 供应商名称
+     */
+    private String sellCorporationName;
 }

+ 74 - 64
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseVo.java

@@ -20,71 +20,71 @@ import java.util.List;
 @Setter
 public class EhsdPurchaseVo extends EhsdPurchase {
 
-	/**
-	 * 历史毛利信息
-	 */
-	List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
-	/**
-	 * 采购商品列表
-	 */
-	private List<EhsdPurchaseProductVo> purchaseProductList;
-	/**
-	 * 装箱明细
-	 */
-	private List<PackDetailProductVo> packDetailProductList;
-	/**
-	 * 买方名称
-	 */
-	private String buyCorporationName;
-	/**
-	 * 卖方名称
-	 */
-	private String sellCorporationName;
-	/**
-	 * 卖方国家表名称
-	 */
-	private String sellCountryName;
-	/**
-	 * 卖方省份名称
-	 */
-	private String sellProvinceName;
-	/**
-	 * 卖方城市名称
-	 */
-	private String sellCityName;
-	/**
-	 * 开户银行
-	 */
-	private String openingBank;
-	/**
-	 * 账户名
-	 */
-	private String openingName;
-	/**
-	 * 联系人
-	 */
-	private String contactPerson;
-	/**
-	 * 账户
-	 */
-	private String accountOpening;
-	/**
-	 * 流程Id
-	 */
-	private Long flowId;
-	/**
-	 * 发票总金额
-	 */
-	private BigDecimal sumInvoiceMoney;
-	/**
-	 * 付款总金额
-	 */
-	private BigDecimal sumPayMoney;
+    /**
+     * 历史毛利信息
+     */
+    List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
+    /**
+     * 采购商品列表
+     */
+    private List<EhsdPurchaseProductVo> purchaseProductList;
+    /**
+     * 装箱明细
+     */
+    private List<PackDetailProductVo> packDetailProductList;
+    /**
+     * 买方名称
+     */
+    private String buyCorporationName;
+    /**
+     * 卖方名称
+     */
+    private String sellCorporationName;
+    /**
+     * 卖方国家表名称
+     */
+    private String sellCountryName;
+    /**
+     * 卖方省份名称
+     */
+    private String sellProvinceName;
+    /**
+     * 卖方城市名称
+     */
+    private String sellCityName;
+    /**
+     * 开户银行
+     */
+    private String openingBank;
+    /**
+     * 账户名
+     */
+    private String openingName;
+    /**
+     * 联系人
+     */
+    private String contactPerson;
+    /**
+     * 账户
+     */
+    private String accountOpening;
+    /**
+     * 流程Id
+     */
+    private Long flowId;
+    /**
+     * 发票总金额
+     */
+    private BigDecimal sumInvoiceMoney;
+    /**
+     * 付款总金额
+     */
+    private BigDecimal sumPayMoney;
 
-	/**
-	 * 创建人名称
-	 */
-	private String createUserName;
+    /**
+     * 创建人名称
+     */
+    private String createUserName;
 
     /**
      * 创建人手机
@@ -102,4 +102,14 @@ public class EhsdPurchaseVo extends EhsdPurchase {
      * 到货明细记录
      */
     private List<ArrivalDetailVo> arrivalDetailList;
+
+    /**
+     * 退货金额
+     */
+    private BigDecimal backAmount;
+
+    /**
+     * 应付金额
+     */
+    private BigDecimal payableAmount;
 }

+ 12 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/quotation/po/QuotationProduct.java

@@ -147,4 +147,16 @@ public class QuotationProduct extends BasePo {
      */
     private Long technologyId;
 
+    /**
+     * 议价价格
+     */
+    private BigDecimal discussPrice;
+
+    /**
+     * 业务成本价
+     */
+    private BigDecimal businessCostPrice;
+
+    private BigDecimal maxPrice;
+
 }

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/sale/dto/SaleQuotationDto.java

@@ -1,5 +1,6 @@
 package com.fjhx.sale.entity.sale.dto;
 
+import com.fjhx.file.entity.ObsFile;
 import com.fjhx.sale.entity.quotation.dto.QuotationProductDto;
 import com.fjhx.sale.entity.sale.po.SaleQuotation;
 import lombok.Getter;
@@ -22,6 +23,12 @@ public class SaleQuotationDto extends SaleQuotation {
      */
     private List<QuotationProductDto> quotationProductList;
 
+    /**
+     * 议价
+     */
+    private List<ObsFile> discussFileList;
+
+
 //    /**
 //     *报价 -收费项目表
 //     */

+ 15 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/sale/po/SaleQuotation.java

@@ -127,4 +127,19 @@ public class SaleQuotation extends BasePo {
     private Integer confirmStatus;
 
     private BigDecimal prodAmount;
+
+    /**
+     * 归属部门id
+     */
+    private Long ofDeptId;
+
+    /**
+     * 议价备注
+     */
+    private String discussRemark;
+
+    /**
+     * 业务成本总金额
+     */
+    private BigDecimal businessCostAmount;
 }

+ 124 - 124
hx-sale/src/main/java/com/fjhx/sale/flow/ClaimDelFlow.java

@@ -1,124 +1,124 @@
-package com.fjhx.sale.flow;
-
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.fjhx.account.entity.account.po.AccountRunningWater;
-import com.fjhx.account.service.account.AccountRunningWaterService;
-import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.sale.entity.claim.po.Claim;
-import com.fjhx.sale.entity.claim.po.ClaimContract;
-import com.fjhx.sale.service.claim.ClaimContractService;
-import com.fjhx.sale.service.claim.ClaimService;
-import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.utils.SecurityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 外销合同流程
- *
- * @Author:caozj
- * @DATE:2023/4/3 17:38
- */
-@Component
-//@DS(SourceConstant.SALE)
-public class ClaimDelFlow extends FlowDelegate {
-
-    @Autowired
-    private ClaimService claimService;
-
-    @Autowired
-    private AccountRunningWaterService accountRunningWaterService;
-
-    @Autowired
-    private ClaimContractService claimContractService;
-
-    @Override
-    public String getFlowKey() {
-        return "claim_del_flow";
-    }
-
-    /**
-     * 发起流程
-     *
-     * @param flowId     流程ID
-     * @param submitData
-     * @return 业务id
-     */
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        AccountRunningWater water = submitData.toJavaObject(AccountRunningWater.class);
-        return water.getId();
-    }
-
-    /**
-     * 结束流程
-     *
-     * @param flowId     流程ID
-     * @param businessId 业务ID
-     * @param submitData 数据
-     */
-    @Override
-    @DSTransactional
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        //通过流水ID查找出到账认领的数据
-        List<Claim> claimList = claimService.list(Wrappers.<Claim>query().lambda().eq(Claim::getBusinessId, businessId));
-        if (CollectionUtils.isEmpty(claimList)) {
-            throw new ServiceException("当前流水暂无认领合同,不能取消认领");
-        }
-        List<Long> claimIds = claimList.stream().map(Claim::getId).collect(Collectors.toList());
-        claimService.removeBatchByIds(claimIds);
-        claimContractService.remove(Wrappers.<ClaimContract>query().lambda().in(ClaimContract::getClaimId, claimIds));
-        //更新流水数据为认领状态---已认领金额还原
-        AccountRunningWater water = new AccountRunningWater();
-        water.setCompanyId(SecurityUtils.getCompanyId());
-
-        water.setId(businessId);
-        water.setIsClaim(0);//未认领状态
-        water.setClaimAmount(BigDecimal.ZERO);
-        accountRunningWaterService.updateById(water);
-    }
-
-    /**
-     * 重新发起
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
-     * @param submitData
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
-
-    }
-
-    /**
-     * 驳回
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
-     */
-    @Override
-    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-
-    }
-
-    /**
-     * 退回发起人
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
-     */
-    @Override
-    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-
-    }
-}
+//package com.fjhx.sale.flow;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+//import com.fjhx.account.entity.account.po.AccountRunningWater;
+//import com.fjhx.account.service.account.AccountRunningWaterService;
+//import com.fjhx.flow.core.FlowDelegate;
+//import com.fjhx.flow.enums.FlowStatusEnum;
+//import com.fjhx.sale.entity.claim.po.Claim;
+//import com.fjhx.sale.entity.claim.po.ClaimContract;
+//import com.fjhx.sale.service.claim.ClaimContractService;
+//import com.fjhx.sale.service.claim.ClaimService;
+//import com.ruoyi.common.exception.ServiceException;
+//import com.ruoyi.common.utils.SecurityUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//import org.springframework.transaction.annotation.Transactional;
+//
+//import java.math.BigDecimal;
+//import java.util.List;
+//import java.util.stream.Collectors;
+//
+///**
+// * 外销合同流程
+// *
+// * @Author:caozj
+// * @DATE:2023/4/3 17:38
+// */
+//@Component
+////@DS(SourceConstant.SALE)
+//public class ClaimDelFlow extends FlowDelegate {
+//
+//    @Autowired
+//    private ClaimService claimService;
+//
+//    @Autowired
+//    private AccountRunningWaterService accountRunningWaterService;
+//
+//    @Autowired
+//    private ClaimContractService claimContractService;
+//
+//    @Override
+//    public String getFlowKey() {
+//        return "claim_del_flow";
+//    }
+//
+//    /**
+//     * 发起流程
+//     *
+//     * @param flowId     流程ID
+//     * @param submitData
+//     * @return 业务id
+//     */
+//    @Override
+//    public Long start(Long flowId, JSONObject submitData) {
+//        AccountRunningWater water = submitData.toJavaObject(AccountRunningWater.class);
+//        return water.getId();
+//    }
+//
+//    /**
+//     * 结束流程
+//     *
+//     * @param flowId     流程ID
+//     * @param businessId 业务ID
+//     * @param submitData 数据
+//     */
+//    @Override
+//    @DSTransactional
+//    public void end(Long flowId, Long businessId, JSONObject submitData) {
+//        //通过流水ID查找出到账认领的数据
+//        List<Claim> claimList = claimService.list(Wrappers.<Claim>query().lambda().eq(Claim::getBusinessId, businessId));
+//        if (CollectionUtils.isEmpty(claimList)) {
+//            throw new ServiceException("当前流水暂无认领合同,不能取消认领");
+//        }
+//        List<Long> claimIds = claimList.stream().map(Claim::getId).collect(Collectors.toList());
+//        claimService.removeBatchByIds(claimIds);
+//        claimContractService.remove(Wrappers.<ClaimContract>query().lambda().in(ClaimContract::getClaimId, claimIds));
+//        //更新流水数据为认领状态---已认领金额还原
+//        AccountRunningWater water = new AccountRunningWater();
+//        water.setCompanyId(SecurityUtils.getCompanyId());
+//
+//        water.setId(businessId);
+//        water.setIsClaim(0);//未认领状态
+//        water.setClaimAmount(BigDecimal.ZERO);
+//        accountRunningWaterService.updateById(water);
+//    }
+//
+//    /**
+//     * 重新发起
+//     * @param flowId
+//     * @param businessId
+//     * @param flowStatus
+//     * @param submitData
+//     */
+//    @Override
+//    @Transactional(rollbackFor = Exception.class)
+//    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
+//
+//    }
+//
+//    /**
+//     * 驳回
+//     * @param flowId
+//     * @param businessId
+//     * @param flowStatus
+//     */
+//    @Override
+//    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//
+//    }
+//
+//    /**
+//     * 退回发起人
+//     * @param flowId
+//     * @param businessId
+//     * @param flowStatus
+//     */
+//    @Override
+//    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//
+//    }
+//}

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

@@ -146,9 +146,9 @@ public class ContractFlow extends FlowDelegate {
             //赋值合同Id
             cp.setContractId(contract.getId());
             //保存设计稿图
-            ObsFileUtil.editFile(cp.getFileList(), cp.getId());
+            ObsFileUtil.editFile(cp.getFileList(), cp.getId(), 1);
             //保存生产源文件
-            ObsFileUtil.copyFileAndSave(cp.getProdFileList(), cp.getId(), 1);
+            ObsFileUtil.copyFileAndSave(cp.getProdFileList(), cp.getId(), 2);
 
             //赋值产品BOM信息
             List<ContractProductBom> contractProductBomList = cp.getContractProductBomList();

+ 15 - 143
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -5,17 +5,14 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.fjhx.common.entity.AvailableStockBo;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.common.utils.Utils;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.item.enums.ProductAvailableRecordType;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
-import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.sale.entity.contract.dto.ContractDto;
 import com.fjhx.sale.entity.contract.dto.ContractProductDto;
@@ -23,23 +20,21 @@ import com.fjhx.sale.entity.contract.po.Contract;
 import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.fjhx.sale.entity.contract.po.ContractProductBom;
 import com.fjhx.sale.entity.contract.po.ContractProject;
-import com.fjhx.sale.entity.contract.vo.ContractProductBomVo;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
-import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
+import com.fjhx.sale.mapper.contract.ContractMapper;
 import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.contract.ContractProductBomService;
 import com.fjhx.sale.service.contract.ContractProductService;
 import com.fjhx.sale.service.contract.ContractProjectService;
 import com.fjhx.sale.service.contract.ContractService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.math.BigDecimal;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 import java.util.stream.Collectors;
 
 /**
@@ -63,11 +58,11 @@ public class ContractUpdateFlow extends FlowDelegate {
     @Autowired
     private ProductInfoService productInfoService;
     @Autowired
-    private EhsdPurchaseProductService ehsdPurchaseProductService;
-    @Autowired
     private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
     @Autowired
     private SubscribeDetailService subscribeDetailService;
+    @Autowired
+    private ContractMapper contractMapper;
 
     @Override
     public String getFlowKey() {
@@ -149,21 +144,23 @@ public class ContractUpdateFlow extends FlowDelegate {
 
         Contract oldContract = contractService.getById(oldContractId);
 
-        //修改采购状态为审批通过
+        //修改状态为审批通过
         newContract.setStatus(PurchaseStatusEnum.PASS.getKey());
         newContract.setApprovedDate(new Date());
+
+        //修改下发状态未为未下发
+        newContract.setOrderDistributeStatus(0);
+        newContract.setOrderDistributeTime(null);
+        contractService.update(q -> q.eq(Contract::getId, newContract.getId()).set(Contract::getOrderDistributeTime, null));
+        //修改生产订单交期确认状态为未确认
+        contractMapper.setProductionOrderConfirmStatus(newContract.getId(), 0);
+        //更新新合同
         contractService.updateById(newContract);
 
         //原合同改为 已变更
         oldContract.setStatus(FlowStatusEnum1.UPDATE.getKey());
         contractService.updateById(oldContract);
 
-
-        //----------修改可用库存---------
-        if (Objects.equals(1, oldContract.getOrderDistributeStatus())) {
-
-            editAvailableStock(oldContract, oldContractId, businessId);
-        }
         //-----------------
         //交换合同产品BOM中的合同id
         List<ContractProductBom> oldCpbList = contractProductBomService.list(q -> q.eq(ContractProductBom::getContractId, oldContractId));
@@ -237,133 +234,8 @@ public class ContractUpdateFlow extends FlowDelegate {
         }
         ObsFileUtil.exchangeBusinessId(oldContractId, businessId);
 
-//        throw new ServiceException("1111111111111111111111111");
-
     }
 
-    void editAvailableStock(Contract oldContract, Long oldContractId, Long businessId) {
-        //---------------------------------------------------------------
-        List<ContractProductBomVo> oldProductBomListSum = contractProductBomService.getContractProductBomQuantitySum(oldContractId);
-
-        //获取新合同物料数量Map
-        List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(businessId);
-        Map<Long, BigDecimal> newQuantityMap = contractProductBomQuantitySum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
-
-
-        List<AvailableStockBo> availableStockBoList = new ArrayList<>();
-
-        //获取原合同已采购数量
-        List<EhsdPurchaseProductVo> purchaseQuantitySumByContractId = ehsdPurchaseProductMapper.getPurchaseQuantitySumByContractId(oldContractId);
-        Map<Long, BigDecimal> collect = purchaseQuantitySumByContractId.stream().collect(Collectors.toMap(EhsdPurchaseProduct::getProductId, EhsdPurchaseProduct::getQuantity));
-
-        //旧数据处理
-        for (ContractProductBomVo oldContractProductBom : oldProductBomListSum) {
-            Long materialId = oldContractProductBom.getMaterialId();
-
-            //新数量
-            BigDecimal newQuantity = newQuantityMap.get(materialId);
-            //已采购数量
-            BigDecimal purchaseQuantity = collect.getOrDefault(materialId, BigDecimal.ZERO);
-
-            //获取原需采购量
-            SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q.eq(SubscribeDetail::getContractId, oldContractId)
-                    .eq(SubscribeDetail::getProductId, materialId)
-            );
-            BigDecimal demandPurchaseCount = BigDecimal.ZERO;
-            if (ObjectUtils.isNotEmpty(subscribeDetail)) {
-                demandPurchaseCount = subscribeDetail.getCount();
-            }
-
-
-            //生成操作可用库存的实体
-            AvailableStockBo availableStockBo = new AvailableStockBo();
-            availableStockBo.setProductId(materialId);
-            availableStockBo.setQuantity(oldContractProductBom.getQuantity());
-            availableStockBo.setNewQuantity(newQuantity);
-            availableStockBo.setInStockQuantity(purchaseQuantity);
-            availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
-
-            availableStockBoList.add(availableStockBo);
-
-        }
-
-        //新添加的数据处理
-        Map<Long, BigDecimal> oldQuantityMap = oldProductBomListSum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
-        for (ContractProductBomVo newPurchaseProduct : contractProductBomQuantitySum) {
-            Long materialId = newPurchaseProduct.getMaterialId();
-
-            BigDecimal bigDecimal = oldQuantityMap.get(materialId);
-            //忽略掉变更前有的物料
-            if (ObjectUtils.isNotEmpty(bigDecimal)) {
-                continue;
-            }
-
-            //生成操作可用库存的实体
-            AvailableStockBo availableStockBo = new AvailableStockBo();
-            availableStockBo.setProductId(materialId);
-            availableStockBo.setQuantity(BigDecimal.ZERO);
-            availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
-            availableStockBo.setInStockQuantity(BigDecimal.ZERO);
-            availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
-
-            availableStockBoList.add(availableStockBo);
-        }
-
-
-        //修改可用库存
-        productInfoService.editAvailableQuantity(availableStockBoList, businessId, ProductAvailableRecordType.SALE_UPDATE, oldContract.getCompanyId());
-
-
-        //修该待采购量为需采购量
-        for (AvailableStockBo availableStockBo : availableStockBoList) {
-
-            Long materialId = availableStockBo.getProductId();
-            SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q.eq(SubscribeDetail::getContractId, oldContractId)
-                    .eq(SubscribeDetail::getProductId, materialId)
-            );
-
-            BigDecimal requiredQuantity = availableStockBo.getNewQuantity();
-
-
-            //需采购量>0
-            if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
-                if (ObjectUtils.isEmpty(subscribeDetail)) {
-                    //生成待采购
-                    subscribeDetail = new SubscribeDetail();
-                    subscribeDetail.setProductId(materialId);
-                    subscribeDetail.setCount(BigDecimal.ZERO);
-                    subscribeDetail.setStatus(15);//待采购
-                    subscribeDetail.setContractId(oldContractId);
-                    subscribeDetail.setDataType(1);
-                    subscribeDetail.setCompanyId(oldContract.getCompanyId());
-                }
-
-                //修改待采购量
-                subscribeDetail.setCount(requiredQuantity);
-
-                //计算状态
-                BigDecimal purchaseQuantity = availableStockBo.getInStockQuantity();
-                int status = purchaseQuantity.compareTo(requiredQuantity) >= 0 ? 20 : 30;
-                if (purchaseQuantity.compareTo(BigDecimal.ZERO) == 0) {
-                    status = 15;
-                }
-                subscribeDetail.setStatus(status);
-
-                subscribeDetailService.saveOrUpdate(subscribeDetail);
-            } else {
-                //需采购==0不显示或删除,<不存在
-                if (ObjectUtils.isNotEmpty(subscribeDetail)) {
-                    subscribeDetailService.removeById(subscribeDetail);
-                }
-            }
-
-
-        }
-
-        //---------------------------------------------------------------
-    }
-
-
     /**
      * 重新发起
      */

+ 89 - 0
hx-sale/src/main/java/com/fjhx/sale/flow/DiscussPriceFlow.java

@@ -0,0 +1,89 @@
+package com.fjhx.sale.flow;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fjhx.file.entity.ObsFile;
+import com.fjhx.file.utils.ObsFileUtil;
+import com.fjhx.flow.core.FlowDelegate;
+import com.fjhx.sale.entity.quotation.dto.QuotationProductDto;
+import com.fjhx.sale.entity.quotation.po.QuotationProduct;
+import com.fjhx.sale.entity.sale.dto.SaleQuotationDto;
+import com.fjhx.sale.entity.sale.po.SaleQuotation;
+import com.fjhx.sale.service.quotation.QuotationProductService;
+import com.fjhx.sale.service.sale.SaleQuotationService;
+import com.ruoyi.common.core.domain.BasePo;
+import com.ruoyi.common.utils.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class DiscussPriceFlow extends FlowDelegate {
+
+    @Autowired
+    private SaleQuotationService saleQuotationService;
+    @Autowired
+    private QuotationProductService quotationProductService;
+
+    @Override
+    public String getFlowKey() {
+        return "discuss_price_flow";
+    }
+
+    @Override
+    public Long start(Long flowId, JSONObject submitData) {
+        SaleQuotationDto saleQuotationDto = submitData.toJavaObject(SaleQuotationDto.class);
+        List<QuotationProductDto> quotationProductList = saleQuotationDto.getQuotationProductList();
+        for (QuotationProductDto quotationProductDto : quotationProductList) {
+            //复制议价格信息
+            quotationProductDto.setDiscussPrice(quotationProductDto.getPrice());
+            quotationProductDto.setPrice(null);
+        }
+
+        //议价附件
+        List<ObsFile> discussFileList = saleQuotationDto.getDiscussFileList();
+        ObsFileUtil.editFile(discussFileList, saleQuotationDto.getId(), 10);
+
+        saleQuotationService.updateById(saleQuotationDto);
+        quotationProductService.updateBatchById(BeanUtil.copyToList(quotationProductList, QuotationProduct.class));
+
+        //将code赋值给流程引擎
+        SaleQuotation byId = saleQuotationService.getById(saleQuotationDto.getId());
+        submitData.put("code", byId.getCode());
+
+        return saleQuotationDto.getId();
+    }
+
+    @Override
+    public void end(Long flowId, Long businessId, JSONObject submitData) {
+        quotationProductService.update(q -> q
+                .eq(QuotationProduct::getSaleQuotationId, businessId)
+                .setSql("price = discuss_price")
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                .set(BasePo::getUpdateTime, new Date())
+        );
+
+        //刷新最低价,和最高价
+        List<QuotationProduct> quotationProductList = quotationProductService.list(q -> q.eq(QuotationProduct::getSaleQuotationId, businessId));
+        for (QuotationProduct quotationProduct : quotationProductList) {
+            BigDecimal minPrice = quotationProduct.getMinPrice();
+            BigDecimal maxPrice = quotationProduct.getMaxPrice();
+            BigDecimal discussPrice = quotationProduct.getDiscussPrice();
+
+            //修改最低价
+            if (discussPrice.compareTo(minPrice) < 0) {
+                quotationProduct.setMinPrice(discussPrice);
+            }
+
+            //修改最高价
+            if (discussPrice.compareTo(maxPrice) > 0) {
+                quotationProduct.setMaxPrice(discussPrice);
+            }
+        }
+        quotationProductService.updateBatchById(quotationProductList);
+    }
+
+}

+ 21 - 9
hx-sale/src/main/java/com/fjhx/sale/flow/PayFlow.java

@@ -18,7 +18,9 @@ import com.fjhx.purchase.entity.pay.po.PayDetail;
 import com.fjhx.purchase.service.pay.PayDetailService;
 import com.fjhx.purchase.service.pay.PayService;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
+import com.fjhx.sale.entity.purchase.po.PurchaseBack;
 import com.fjhx.sale.service.purchase.EhsdPurchaseService;
+import com.fjhx.sale.service.purchase.PurchaseBackService;
 import com.fjhx.supply.entity.supplier.po.SupplierInfo;
 import com.fjhx.supply.service.supplier.SupplierInfoService;
 import com.ruoyi.common.core.domain.BasePo;
@@ -28,10 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -58,6 +57,8 @@ public class PayFlow extends FlowDelegate {
 
     @Autowired
     private SupplierInfoService supplierInfoService;
+    @Autowired
+    private PurchaseBackService purchaseBackService;
 
     @Override
     public String getFlowKey() {
@@ -176,6 +177,13 @@ public class PayFlow extends FlowDelegate {
         // 获取合同列表
         List<EhsdPurchase> purchaseList = purchaseService.listByIds(purchaseIdList);
 
+
+        //获取采购退货金额
+        Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
+                .in(PurchaseBack::getPurchaseId, purchaseIdList)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+        );
+
         for (EhsdPurchase purchase : purchaseList) {
 
             Integer payStatus = purchase.getPayStatus();
@@ -187,11 +195,15 @@ public class PayFlow extends FlowDelegate {
 
             // 获取合同付款金额
             BigDecimal payMoney = map.getOrDefault(purchase.getId(), BigDecimal.ZERO);
-            // 获取合同金额
-            BigDecimal amount = purchase.getAmount();
-
-            // 合同付款金额大于等于合同金额,已付款
-            if (payMoney.compareTo(amount) >= 0) {
+//            // 获取合同金额
+//            BigDecimal amount = purchase.getAmount();
+            //获取应付金额
+            List<PurchaseBack> purchaseBackList = purchaseBackMap.getOrDefault(purchase.getId(), new ArrayList<>());
+            BigDecimal backAmount = purchaseBackList.stream().map(PurchaseBack::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal payableAmount = purchase.getAmount().subtract(backAmount);
+
+            // 合同付款金额大于等于应付金额,已付款
+            if (payMoney.compareTo(payableAmount) >= 0) {
                 purchase.setPayStatus(20);
             }
             // 否则进行中

+ 4 - 1
hx-sale/src/main/java/com/fjhx/sale/flow/PurchaseBackFlow.java

@@ -55,6 +55,7 @@ public class PurchaseBackFlow extends FlowDelegate {
     @Override
     public Long start(Long flowId, JSONObject submitData) {
         PurchaseBackDto purchaseBackDto = submitData.toJavaObject(PurchaseBackDto.class);
+        purchaseBackDto.setFlowId(flowId);
 
         if (ObjectUtil.isEmpty(purchaseBackDto.getCompanyId())) {
             purchaseBackDto.setCompanyId(SecurityUtils.getCompanyId());
@@ -81,8 +82,10 @@ public class PurchaseBackFlow extends FlowDelegate {
         }
         purchaseBackDetailsService.saveOrUpdateBatch(purchaseBackDetailsList);
 
-        //回传单号
+        //回传数据给流程引擎
         submitData.put("code", purchaseBackDto.getCode());
+        submitData.put("amount", purchaseBackDto.getAmount());
+
         return purchaseBackDto.getId();
     }
 

+ 67 - 67
hx-sale/src/main/java/com/fjhx/sale/flow/SampleFlow.java

@@ -1,67 +1,67 @@
-package com.fjhx.sale.flow;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.enums.FlowStatusEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-/**
- * 样品单流程
- */
-@Component
-public class SampleFlow extends FlowDelegate {
-
-    private final ContractFlow contractFlow;
-
-    @Autowired
-    public SampleFlow(ContractFlow contractFlow) {
-        this.contractFlow = contractFlow;
-    }
-
-    @Override
-    public String getFlowKey() {
-        return "sample_flow";
-    }
-
-    /**
-     * 发起流程
-     */
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        return contractFlow.start(flowId, submitData);
-    }
-
-    /**
-     * 重新发起
-     */
-    @Override
-    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
-        contractFlow.relaunch(flowId, businessId, flowStatus, submitData);
-    }
-
-    /**
-     * 驳回
-     */
-    @Override
-    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        contractFlow.reject(flowId, businessId, flowStatus);
-    }
-
-
-    /**
-     * 结束流程
-     */
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        contractFlow.end(flowId, businessId, submitData);
-    }
-
-    /**
-     * 作废
-     */
-    @Override
-    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        contractFlow.cancellation(flowId, businessId, flowStatus);
-    }
-}
+//package com.fjhx.sale.flow;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.fjhx.flow.core.FlowDelegate;
+//import com.fjhx.flow.enums.FlowStatusEnum;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//
+///**
+// * 样品单流程
+// */
+//@Component
+//public class SampleFlow extends FlowDelegate {
+//
+//    private final ContractFlow contractFlow;
+//
+//    @Autowired
+//    public SampleFlow(ContractFlow contractFlow) {
+//        this.contractFlow = contractFlow;
+//    }
+//
+//    @Override
+//    public String getFlowKey() {
+//        return "sample_flow";
+//    }
+//
+//    /**
+//     * 发起流程
+//     */
+//    @Override
+//    public Long start(Long flowId, JSONObject submitData) {
+//        return contractFlow.start(flowId, submitData);
+//    }
+//
+//    /**
+//     * 重新发起
+//     */
+//    @Override
+//    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
+//        contractFlow.relaunch(flowId, businessId, flowStatus, submitData);
+//    }
+//
+//    /**
+//     * 驳回
+//     */
+//    @Override
+//    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//        contractFlow.reject(flowId, businessId, flowStatus);
+//    }
+//
+//
+//    /**
+//     * 结束流程
+//     */
+//    @Override
+//    public void end(Long flowId, Long businessId, JSONObject submitData) {
+//        contractFlow.end(flowId, businessId, submitData);
+//    }
+//
+//    /**
+//     * 作废
+//     */
+//    @Override
+//    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//        contractFlow.cancellation(flowId, businessId, flowStatus);
+//    }
+//}

+ 66 - 66
hx-sale/src/main/java/com/fjhx/sale/flow/SampleUpdateFlow.java

@@ -1,66 +1,66 @@
-package com.fjhx.sale.flow;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.enums.FlowStatusEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-/**
- * 样品单变更流程
- */
-@Component
-public class SampleUpdateFlow extends FlowDelegate {
-    private final ContractUpdateFlow contractUpdateFlow;
-
-    @Autowired
-    public SampleUpdateFlow(ContractUpdateFlow contractUpdateFlow) {
-        this.contractUpdateFlow = contractUpdateFlow;
-    }
-
-    @Override
-    public String getFlowKey() {
-        return "sample_update_flow";
-    }
-
-    /**
-     * 发起流程
-     */
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        return contractUpdateFlow.start(flowId, submitData);
-    }
-
-    /**
-     * 结束流程
-     */
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        contractUpdateFlow.end(flowId, businessId, submitData);
-    }
-
-
-    /**
-     * 驳回
-     */
-    @Override
-    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        contractUpdateFlow.reject(flowId, businessId, flowStatus);
-    }
-
-    /**
-     * 重新发起
-     */
-    @Override
-    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
-        contractUpdateFlow.relaunch(flowId, businessId, flowStatus, submitData);
-    }
-
-    /**
-     * 作废
-     */
-    @Override
-    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        contractUpdateFlow.cancellation(flowId, businessId, flowStatus);
-    }
-}
+//package com.fjhx.sale.flow;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.fjhx.flow.core.FlowDelegate;
+//import com.fjhx.flow.enums.FlowStatusEnum;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//
+///**
+// * 样品单变更流程
+// */
+//@Component
+//public class SampleUpdateFlow extends FlowDelegate {
+//    private final ContractUpdateFlow contractUpdateFlow;
+//
+//    @Autowired
+//    public SampleUpdateFlow(ContractUpdateFlow contractUpdateFlow) {
+//        this.contractUpdateFlow = contractUpdateFlow;
+//    }
+//
+//    @Override
+//    public String getFlowKey() {
+//        return "sample_update_flow";
+//    }
+//
+//    /**
+//     * 发起流程
+//     */
+//    @Override
+//    public Long start(Long flowId, JSONObject submitData) {
+//        return contractUpdateFlow.start(flowId, submitData);
+//    }
+//
+//    /**
+//     * 结束流程
+//     */
+//    @Override
+//    public void end(Long flowId, Long businessId, JSONObject submitData) {
+//        contractUpdateFlow.end(flowId, businessId, submitData);
+//    }
+//
+//
+//    /**
+//     * 驳回
+//     */
+//    @Override
+//    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//        contractUpdateFlow.reject(flowId, businessId, flowStatus);
+//    }
+//
+//    /**
+//     * 重新发起
+//     */
+//    @Override
+//    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
+//        contractUpdateFlow.relaunch(flowId, businessId, flowStatus, submitData);
+//    }
+//
+//    /**
+//     * 作废
+//     */
+//    @Override
+//    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+//        contractUpdateFlow.cancellation(flowId, businessId, flowStatus);
+//    }
+//}

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java

@@ -162,4 +162,9 @@ public interface ContractMapper extends BaseMapper<Contract> {
      * 删除合同相关的生产备料
      */
     void removeMaterialPreparationoByContractId(Long contractId);
+
+    /**
+     * 修改生产订单交期确认状态
+     */
+    void setProductionOrderConfirmStatus(Long id, Integer confirmStatus);
 }

+ 3 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/quotation/QuotationEstimateMapper.java

@@ -2,6 +2,7 @@ package com.fjhx.sale.mapper.quotation;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fjhx.item.entity.product.ProcessesBo;
+import com.fjhx.item.entity.product.TechnologyBo;
 import com.fjhx.sale.entity.quotation.po.QuotationEstimate;
 import com.fjhx.sale.entity.quotation.vo.QuotationEstimateVo;
 
@@ -20,6 +21,8 @@ public interface QuotationEstimateMapper extends BaseMapper<QuotationEstimate> {
 
     List<ProcessesBo> getProductionProcessesList();
 
+    TechnologyBo getTechnologyInfo(Long id);
+
     List<QuotationEstimateVo> getMoldInfoList(List<Long> moldIds);
 
 }

+ 12 - 4
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -438,6 +438,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         if (CollectionUtils.isEmpty(list)) {
             return page;
         }
+
+        //赋值创建人名称
+        UserUtil.assignmentNickName(list, ContractVo::getCreateUser, ContractVo::setSalesmanName);
+
+
         //获取部门列表
         List<SysDept> companyList = deptService.list();
         Map<Long, String> companyMap = companyList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
@@ -1285,10 +1290,13 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         }
 
         //赋值归属公司
-        SysDept company = deptService.getById(result.getCompanyId());
-        if (ObjectUtil.isNotEmpty(company)) {
-            result.setCompanyName(company.getDeptName());
-        }
+        List<SysDept> companyList = deptService.list();
+        Map<Long, String> companyMap = companyList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
+
+        result.setCompanyName(companyMap.get(result.getCompanyId()));
+        result.setOfCompanyName(companyMap.get(result.getOfCompanyId()));
+        result.setDeptName(companyMap.get(result.getDeptId()));
+
 
         return result;
     }

+ 51 - 1
hx-sale/src/main/java/com/fjhx/sale/service/ext/impl/ExtQuotationProductServiceImpl.java

@@ -22,14 +22,21 @@ import com.fjhx.sale.entity.ext.po.ExtQuotationProductCustomInfo;
 import com.fjhx.sale.entity.ext.vo.ExtQuotationProductBomVo;
 import com.fjhx.sale.entity.ext.vo.ExtQuotationProductCustomInfoVo;
 import com.fjhx.sale.entity.ext.vo.ExtQuotationProductVo;
+import com.fjhx.sale.entity.quotation.po.QuotationProduct;
+import com.fjhx.sale.entity.quotation.po.QuotationProductBom;
+import com.fjhx.sale.entity.quotation.po.QuotationProductCustomInfo;
 import com.fjhx.sale.mapper.ext.ExtQuotationProductMapper;
 import com.fjhx.sale.service.ext.ExtQuotationProductBomService;
 import com.fjhx.sale.service.ext.ExtQuotationProductCustomInfoService;
 import com.fjhx.sale.service.ext.ExtQuotationProductService;
 import com.fjhx.sale.service.ext.ExtQuotationService;
+import com.fjhx.sale.service.quotation.QuotationProductBomService;
+import com.fjhx.sale.service.quotation.QuotationProductCustomInfoService;
+import com.fjhx.sale.service.quotation.QuotationProductService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.utils.SecurityUtils;
 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;
 
@@ -60,6 +67,12 @@ public class ExtQuotationProductServiceImpl extends ServiceImpl<ExtQuotationProd
     private ExtQuotationProductService extQuotationProductService;
     @Autowired
     private ExtQuotationService extQuotationService;
+    @Autowired
+    private QuotationProductService quotationProductService;
+    @Autowired
+    private QuotationProductBomService quotationProductBomService;
+    @Autowired
+    private QuotationProductCustomInfoService quotationProductCustomInfoService;
 
     @Override
     public Page<ExtQuotationProductVo> waitCreateProductPage(ExtQuotationProductSelectDto dto) {
@@ -67,6 +80,16 @@ public class ExtQuotationProductServiceImpl extends ServiceImpl<ExtQuotationProd
         //过滤待创建产品数据
         wrapper.eq("eq.create_product_status", 1);
         wrapper.isNull("eqp.product_id");
+        wrapper.orderByDesc("eq.wait_product_time");
+
+        wrapper.keyword(dto.getKeyword(), new SqlField("eq.code"));
+
+        //权限过滤:待建产品
+        wrapper.in("eq.company_id", SecurityUtils.getCompanyIds());
+        wrapper.eq("eq.company_id", dto.getCompanyId());
+
+        wrapper.groupBy("eqp.id");
+
         Page<ExtQuotationProductVo> page = baseMapper.waitCreateProductPage(dto.getPage(), wrapper);
         List<ExtQuotationProductVo> records = page.getRecords();
         if (ObjectUtil.isEmpty(records)) {
@@ -111,6 +134,7 @@ public class ExtQuotationProductServiceImpl extends ServiceImpl<ExtQuotationProd
 
         //赋值信息
         for (ExtQuotationProductVo record : records) {
+            //赋值单号
             //赋值BOM信息
             record.setQuotationProductBomList(eqpbMap.get(record.getId()));
             //赋值定制信息
@@ -138,8 +162,10 @@ public class ExtQuotationProductServiceImpl extends ServiceImpl<ExtQuotationProd
         ExtQuotationProduct extQuotationProduct = this.getById(extQuotationProductId);
         Assert.notEmpty(extQuotationProduct, "查询不到对外报价单产品信息");
 
+
+        //更新对外产品信息
         this.update(q -> q
-                .eq(ExtQuotationProduct::getQuotationProductId, extQuotationProductId)
+                .eq(ExtQuotationProduct::getId, extQuotationProductId)
                 .set(ExtQuotationProduct::getProductId, productInfoDto.getId())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
                 .set(BasePo::getUpdateTime, new Date())
@@ -159,6 +185,30 @@ public class ExtQuotationProductServiceImpl extends ServiceImpl<ExtQuotationProd
                 .set(BasePo::getUpdateTime, new Date())
         );
 
+        //更新对内报价单产品信息
+        Long quotationProductId = extQuotationProduct.getQuotationProductId();
+
+        quotationProductService.update(q -> q
+                .eq(QuotationProduct::getId, quotationProductId)
+                .set(QuotationProduct::getProductId, productInfoDto.getId())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                .set(BasePo::getUpdateTime, new Date())
+        );
+
+        quotationProductBomService.update(q -> q
+                .eq(QuotationProductBom::getQuotationProductId, quotationProductId)
+                .set(QuotationProductBom::getProductId, productInfoDto.getId())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                .set(BasePo::getUpdateTime, new Date())
+        );
+
+        quotationProductCustomInfoService.update(q -> q
+                .eq(QuotationProductCustomInfo::getQuotationProductId, quotationProductId)
+                .set(QuotationProductCustomInfo::getProductId, productInfoDto.getId())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                .set(BasePo::getUpdateTime, new Date())
+        );
+
         //更新状态
         List<ExtQuotationProduct> list = extQuotationProductService.list(q -> q
                 .eq(ExtQuotationProduct::getSaleQuotationId, extQuotationProduct.getSaleQuotationId())

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/service/ext/impl/ExtQuotationServiceImpl.java

@@ -145,6 +145,12 @@ public class ExtQuotationServiceImpl extends ServiceImpl<ExtQuotationMapper, Ext
         List<Long> ids = records.stream().map(ExtQuotationVo::getId).collect(Collectors.toList());
         List<ExtQuotationProduct> pList = extQuotationProductService.list(q -> q.in(ExtQuotationProduct::getSaleQuotationId, ids));
         List<ExtQuotationProductVo> quotationProductVos = BeanUtil.copyToList(pList, ExtQuotationProductVo.class);
+        for (ExtQuotationProductVo quotationProductVo : quotationProductVos) {
+            //定制产品名称先显示定制
+            if (ObjectUtil.isEmpty(quotationProductVo.getProductId())) {
+                quotationProductVo.setProductName("定制");
+            }
+        }
         //赋值产品信息
         productInfoService.attributeAssign(quotationProductVos, ExtQuotationProductVo::getProductId, (item, productInfo) -> {
             item.setProductCode(productInfo.getCustomCode());
@@ -490,6 +496,7 @@ public class ExtQuotationServiceImpl extends ServiceImpl<ExtQuotationMapper, Ext
         this.update(q -> q
                 .eq(ExtQuotation::getId, id)
                 .set(ExtQuotation::getCreateProductStatus, 1)
+                .set(ExtQuotation::getWaitProductTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
                 .set(BasePo::getUpdateTime, new Date())
         );

+ 37 - 13
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -53,10 +53,7 @@ import com.fjhx.sale.entity.pack.po.PackDetailProduct;
 import com.fjhx.sale.entity.pack.vo.PackDetailProductVo;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseSelectDto;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProductMountings;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
+import com.fjhx.sale.entity.purchase.po.*;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseDocumentaryVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseVo;
@@ -66,10 +63,7 @@ import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.sale.service.pack.PackDetailProductService;
 import com.fjhx.sale.service.pack.PackDetailService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductMountingsService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseService;
+import com.fjhx.sale.service.purchase.*;
 import com.fjhx.supply.entity.supplier.po.SupplierInfo;
 import com.fjhx.supply.entity.supplier.po.SupplierPrice;
 import com.fjhx.supply.entity.supplier.vo.SupplierPriceVo;
@@ -77,7 +71,6 @@ import com.fjhx.supply.service.supplier.SupplierInfoService;
 import com.fjhx.supply.service.supplier.SupplierPriceService;
 import com.fjhx.tenant.utils.DeptUstil;
 import com.fjhx.wms.entity.stock.po.StockWait;
-import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -155,7 +148,7 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
     @Autowired
     private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
     @Autowired
-    private StockWaitDetailsService stockWaitDetailsService;
+    private PurchaseBackService purchaseBackService;
 
     /**
      * 分页
@@ -182,8 +175,8 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         }
 
         //权限过滤:采购
-            wrapper.in("t1", EhsdPurchase::getCompanyId, SecurityUtils.getCompanyIds());
-            wrapper.eq("t1", EhsdPurchase::getCompanyId, dto.getCompanyId());
+        wrapper.in("t1", EhsdPurchase::getCompanyId, SecurityUtils.getCompanyIds());
+        wrapper.eq("t1", EhsdPurchase::getCompanyId, dto.getCompanyId());
 
 
         wrapper.orderByDesc("t1", EhsdPurchase::getCreateTime);
@@ -199,15 +192,33 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //  赋值流程id
         flowExampleService.setFlowId(records, EhsdPurchaseVo::setFlowId);
 
-        //赋值付款金额
+        //赋值付款金额
         List<Long> pids = records.stream().map(EhsdPurchaseVo::getId).collect(Collectors.toList());
         List<PayDetailVo> payDetailVoList = payDetailService.getSumMoneyByPurchaseIds(pids);
         Map<Long, BigDecimal> payMap = payDetailVoList.stream().collect(Collectors.toMap(PayDetailVo::getPurchaseId, PayDetailVo::getSumMoney));
         records.forEach(item -> item.setSumPayMoney(payMap.getOrDefault(item.getId(), BigDecimal.ZERO)));
 
+        //赋值采购退货金额
+        Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
+                .in(PurchaseBack::getPurchaseId, pids)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+        );
+        for (EhsdPurchaseVo record : records) {
+            //赋值退货金额、应付金额
+            List<PurchaseBack> purchaseBackList = purchaseBackMap.getOrDefault(record.getId(), new ArrayList<>());
+            BigDecimal backAmount = purchaseBackList.stream().map(PurchaseBack::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            record.setBackAmount(backAmount);
+            record.setPayableAmount(record.getAmount().subtract(backAmount));
+        }
+
         //赋值用户名称
         UserUtil.assignmentNickName(records, EhsdPurchase::getCreateUser, EhsdPurchase::setUserName);
 
+        //赋值供应商名称
+        supplierInfoService.attributeAssign(records, EhsdPurchase::getSellCorporationId, (item, supply) -> {
+            item.setSellCorporationName(supply.getName());
+        });
+
         //获取生产公司信息
         List<Long> companyIds = records.stream().map(EhsdPurchase::getCompanyId).collect(Collectors.toList());
         Map<Long, String> companyNameMap = DeptUstil.getDeptNameMap(companyIds);
@@ -587,6 +598,13 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
 
         List<EhsdPurchaseVo> ehsdPurchases = BeanUtil.copyToList(list, EhsdPurchaseVo.class);
         List<Long> ids = list.stream().distinct().map(EhsdPurchase::getId).collect(Collectors.toList());
+
+        //赋值采购退货金额
+        Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
+                .in(PurchaseBack::getPurchaseId, ids)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+        );
+
         List<InvoiceDetailsVo> invoiceDetailsList = invoiceDetailsService.getSumMoneyByPurchaseIds(ids);
         Map<Long, BigDecimal> invoiceMap = invoiceDetailsList.stream().collect(Collectors.toMap(InvoiceDetailsVo::getPurchaseId, InvoiceDetailsVo::getSumMoney));
         List<PayDetailVo> payDetailVoList = payDetailService.getSumMoneyByPurchaseIds(ids);
@@ -602,6 +620,12 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
             } else {
                 p.setSumPayMoney(BigDecimal.ZERO);
             }
+
+            //赋值退货金额、应付金额
+            List<PurchaseBack> purchaseBackList = purchaseBackMap.getOrDefault(p.getId(), new ArrayList<>());
+            BigDecimal backAmount = purchaseBackList.stream().map(PurchaseBack::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            p.setBackAmount(backAmount);
+            p.setPayableAmount(p.getAmount().subtract(backAmount));
         }
 
         return ehsdPurchases;

+ 14 - 2
hx-sale/src/main/java/com/fjhx/sale/service/quotation/impl/QuotationEstimateServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.item.entity.product.ProcessesBo;
+import com.fjhx.item.entity.product.TechnologyBo;
 import com.fjhx.item.entity.product.po.ProductInfo;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.sale.entity.quotation.dto.QuotationEstimateDto;
@@ -102,9 +103,20 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
                 quotationEstimateVos.add(quotationEstimate);
             }
 
+            //赋值工序信息
+            List<ProcessesBo> processesList = baseMapper.getProductionProcessesList();
+            Map<Long, ProcessesBo> collect = processesList.stream().collect(Collectors.toMap(ProcessesBo::getId, Function.identity()));
 
-            List<ProcessesBo> processesList = productInfoService.getProcessesByTechnologyId(technologyId);
-            for (ProcessesBo processesBo : processesList) {
+            TechnologyBo technologyInfo = baseMapper.getTechnologyInfo(technologyId);
+            String processRoute = technologyInfo.getProcessRoute();
+            String[] split = processRoute.split(",");
+
+            for (String processIdStr : split) {
+                long processId = Long.parseLong(processIdStr);
+                ProcessesBo processesBo = collect.get(processId);
+                if (ObjectUtil.isEmpty(processesBo)) {
+                    continue;
+                }
                 QuotationEstimateVo quotationEstimate = new QuotationEstimateVo();
                 quotationEstimate.setProcessesId(processesBo.getId());
                 quotationEstimate.setCode(processesBo.getCode());

+ 12 - 0
hx-sale/src/main/java/com/fjhx/sale/service/sale/impl/SaleQuotationServiceImpl.java

@@ -200,6 +200,13 @@ public class SaleQuotationServiceImpl extends ServiceImpl<SaleQuotationMapper, S
             item.setProductWidth(productInfo.getWidth());
             item.setProductWidth(productInfo.getHeight());
         });
+
+        for (QuotationProductVo quotationPayVo : quotationPayVos) {
+            if (ObjectUtil.isEmpty(quotationPayVo.getProductId())) {
+                quotationPayVo.setProductName("定制");
+            }
+        }
+
         Map<Long, List<QuotationProductVo>> pMap = quotationPayVos.stream().collect(Collectors.groupingBy(QuotationProduct::getSaleQuotationId));
 
         for (SaleQuotationVo saleQuotationVo : records) {
@@ -330,6 +337,11 @@ public class SaleQuotationServiceImpl extends ServiceImpl<SaleQuotationMapper, S
                     quotationProductBom.setProductId(quotationProductDto.getProductId());
                     quotationProductBom.setQuotationProductId(quotationProductDto.getId());
                     quotationProductBom.setSaleQuotationId(saleQuotationDto.getId());
+
+                    //如果是原材料,且数量为空默认赋值1
+                    if (ObjectUtil.equals(quotationProductBom.getType(), 1) && ObjectUtil.isEmpty(quotationProductBom.getQuantity())) {
+                        quotationProductBom.setQuantity(BigDecimal.ONE);
+                    }
                 }
                 quotationProductBomService.editLinked(quotationProductBomList, QuotationProductBom::getQuotationProductId, quotationProductDto.getId());
 

+ 7 - 0
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -578,4 +578,11 @@
         FROM material_preparation
         WHERE contract_id = #{contractId};
     </delete>
+
+    <update id="setProductionOrderConfirmStatus">
+        UPDATE production_order
+        SET confirm_status = #{confirmStatus}
+        WHERE id = #{id}
+    </update>
+
 </mapper>

+ 6 - 2
hx-sale/src/main/resources/mapper/ext/ExtQuotationProductMapper.xml

@@ -2,9 +2,13 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.sale.mapper.ext.ExtQuotationProductMapper">
     <select id="waitCreateProductPage" resultType="com.fjhx.sale.entity.ext.vo.ExtQuotationProductVo">
-        SELECT eqp.*
+        SELECT eqp.*,
+               eq.`code` AS extQuotationCode,
+               eq.wait_product_time,
+               sq.`code` AS quotationCode
         FROM ext_quotation_product eqp
-                 JOIN ext_quotation eq
+                 JOIN ext_quotation eq ON eqp.sale_quotation_id = eq.id
+                 JOIN sale_quotation sq ON eq.sale_quotation_id
             ${ew.customSqlSegment}
     </select>
 </mapper>

+ 2 - 1
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -132,7 +132,8 @@
                      epp.old_purchase_product_id,
                      (SELECT IFNULL(sum(swd.receipt_quantity), 0)
                       FROM stock_wait_details swd
-                      WHERE swd.purchase_detail_id = epp.id) AS arrivalQuantity
+                      WHERE swd.purchase_detail_id = epp.id) AS arrivalQuantity,
+                     ep.sell_corporation_id
               FROM ehsd_purchase_product epp
                        LEFT JOIN ehsd_purchase ep ON epp.purchase_id = ep.id) epp
             ${ew.customSqlSegment}

+ 2 - 0
hx-sale/src/main/resources/mapper/purchase/PurchaseBackMapper.xml

@@ -11,6 +11,8 @@
                pb.create_time,
                pb.update_user,
                pb.update_time,
+               pb.amount,
+               pb.company_id,
                p.`code` AS purchaseCode
         FROM purchase_back pb
                  LEFT JOIN ehsd_purchase p ON pb.purchase_id = p.id

+ 5 - 0
hx-sale/src/main/resources/mapper/quotation/QuotationEstimateMapper.xml

@@ -16,4 +16,9 @@
             </foreach>
         </where>
     </select>
+    <select id="getTechnologyInfo" resultType="com.fjhx.item.entity.product.TechnologyBo">
+        SELECT *
+        FROM technology t
+        where t.id = #{id}
+    </select>
 </mapper>

+ 1 - 1
hx-wms/src/main/java/com/fjhx/wms/entity/stock/dto/StockWaitSelectDto.java

@@ -17,7 +17,7 @@ public class StockWaitSelectDto extends BaseSelectDto {
     /**
      * 数据类型 1入库 2出库
      */
-    private String type;
+    private Integer type;
 
     /**
      * 入库状态过滤