luobang 2 vuotta sitten
vanhempi
commit
88c8fd419d

+ 1 - 0
src/main/java/com/steerinfo/dil/mapper/BmstruckDetailsOrderMapper.java

@@ -240,4 +240,5 @@ public interface BmstruckDetailsOrderMapper extends IBaseMapper<BmstruckDetailsO
 
     List<BigDecimal> getOrderIds(BigDecimal orderId);
 
+    BigDecimal getWeightBatchNetWeight(BigDecimal weightBatchId);
 }

+ 90 - 4
src/main/java/com/steerinfo/dil/service/impl/BmstruckDetailsOrderServiceImpl.java

@@ -262,6 +262,75 @@ public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderSer
         //    return 0;
         //}
         int result = 0;
+        //优先根据计量批次新增详单
+        List<Map<String,Object>> batchIdList = bmstruckDetailsOrderMapper.getWeightBatchIds(orderId);
+        if(batchIdList.size()>0){
+            for(Map<String, Object> map : batchIdList){
+                if(map == null) {
+                    System.out.println("空Map,释放");
+                    continue;
+                }
+                BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
+                //判断该批次有没有结算数据
+                if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrderByBatch(weightBatchId) > 0 ){
+                    continue;
+                }
+                try {
+                    BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
+                    BigDecimal priceValue = getPriceValue(priceId);
+                    BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
+                    // 得到计费公式
+                    String formula_string = null;
+                    if (orderType.intValue() == 3) {
+                        // 得到采购汽运计费公式
+                        formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(8));
+                        // 替换采购汽运运计算公式
+                        formula_string = formula_string.replace("到厂计量湿吨",netWeight.toString())
+                                .replace("单价",priceValue.toString());
+                    }
+                    if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
+                        // 得到销售10km差距内的汽运计费公式
+                        formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
+                        // 替换采购汽运运计算公式
+                        formula_string = formula_string.replace("运输单价",priceValue.toString())
+                                .replace("物资净重",netWeight.toString());
+                    }
+                    String s = toSufExpr(formula_string);
+                    BigDecimal  detailsAmountOld = calSufExpr(s);
+                    Double amount = detailsAmountOld.doubleValue();
+                    BigDecimal detailsAmount = new BigDecimal(amount).setScale(2,RoundingMode.HALF_UP);
+                    BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
+                    if (orderType.intValue() == 3) {
+                        BigDecimal purchaseOrderId = getFormulaMembers(orderId);
+                        bmstruckDetailsOrder.setPurchaseOrderId(purchaseOrderId);
+                    }
+                    if (orderType.intValue() == 2 || orderType.intValue() == 1) {
+                        bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
+                    }
+                    // 得到最大id
+                    BigDecimal detailsId = selectMaxId();
+                    String detailsNo = noUtil.setResultNo("QYXD", detailsId);
+                    bmstruckDetailsOrder.setDetailsId(detailsId);
+                    bmstruckDetailsOrder.setWeightBatchId(weightBatchId);
+                    bmstruckDetailsOrder.setOrderId(orderId);
+                    bmstruckDetailsOrder.setDetailsNo(detailsNo);
+                    bmstruckDetailsOrder.setPriceId(priceId);
+                    bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
+                    bmstruckDetailsOrder.setDetailsTime(new Date());
+                    // 设置常规字段
+                    bmstruckDetailsOrder.setInsertTime(new Date());
+                    bmstruckDetailsOrder.setUpdateTime(new Date());
+                    bmstruckDetailsOrder.setInsertUsername("admin");
+                    bmstruckDetailsOrder.setUpdateUsername("admin");
+                    bmstruckDetailsOrder.setInsertUpdateRemark("无");
+                    result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
+                }catch (Exception e){
+                    //不打印给控制台(有可能是正常情况)
+                    e.printStackTrace();
+                }
+            }
+            return result;
+        }
         for (Map<String, Object> map : weightTaskResultIdList) {
             if(map == null) {
                 System.out.println("map为空");
@@ -543,6 +612,7 @@ public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderSer
     public BigDecimal updateSteelAmounts(Map<String,Object> map) throws Exception {
         BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
         BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
+        BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
         BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
         BigDecimal priceId = DataChange.dataToBigDecimal(map.get("priceId"));
         BigDecimal priceValue = getPriceValue(priceId);
@@ -550,7 +620,12 @@ public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderSer
             //单价为Null,则返回0
             return new BigDecimal(0);
         }
-        BigDecimal netWeight = getNetWeight(weightTaskResultId);
+        BigDecimal netWeight = null;
+        if(weightBatchId != null && weightBatchId.intValue() != 0) {
+            netWeight = getWeightBatchNetWeight(weightBatchId);
+        }else{
+            netWeight = getNetWeight(weightTaskResultId);
+        }
         // 得到计费公式
         String formula_string = null;
         if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
@@ -576,6 +651,10 @@ public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderSer
         return calSufExpr(s);
     }
 
+    private BigDecimal getWeightBatchNetWeight(BigDecimal weightBatchId) {
+        return bmstruckDetailsOrderMapper.getWeightBatchNetWeight(weightBatchId);
+    }
+
 
     /**
      * 中缀转换后缀表达式
@@ -835,10 +914,17 @@ public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderSer
             bmstruckDetailsOrder.setPriceids(priceId1+","+priceId);
             bmstruckDetailsOrder.setPriceId(priceId);
             BigDecimal weightTaskResultId = bmstruckDetailsOrder.getWeightTaskResultId();
+            BigDecimal weightBatchId = bmstruckDetailsOrder.getWeightBatchId();
             Map<String,Object> map = new HashMap<>();
-            map.put("orderId",orderId);
-            map.put("weightTaskResultId",weightTaskResultId);
-            map.put("priceId",priceId);
+            if(weightBatchId != null) {
+                map.put("orderId",orderId);
+                map.put("weightBatchId",weightBatchId);
+                map.put("priceId",priceId);
+            }else{
+                map.put("orderId",orderId);
+                map.put("weightTaskResultId",weightTaskResultId);
+                map.put("priceId",priceId);
+            }
             try {
                 // 计算出新的详单金额
                 BigDecimal newAmount = updateSteelAmounts(map);

+ 4 - 0
src/main/resources/com/steerinfo/dil/mapper/BmstruckDetailsOrderMapper.xml

@@ -2675,4 +2675,8 @@
                   WHERE ORDER_ID = #{orderId}
               )
     </select>
+    <select id="getWeightBatchNetWeight" resultType="java.math.BigDecimal" parameterType="decimal">
+        SELECT SUM(BATCH_NET_WEIGHT) FROM TMSTRUCK_WEIGHT_BATCH
+        WHERE WEIGHT_BATCH_ID = #{weightBatchId}
+    </select>
 </mapper>