Browse Source

解决优化仓储费

caifc 3 years ago
parent
commit
5261595f9f

+ 23 - 21
ruoyi-warehouse/src/main/java/com/ruoyi/approvalFlow/service/impl/AuditPathsServiceImpl.java

@@ -357,28 +357,30 @@ public class AuditPathsServiceImpl implements IAuditPathsService {
                             tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
                         }
                         tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
-                        if (Objects.equals(auditItems.getActId(), 120L)) {
-                            List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
-                            // 过滤出明细信息查询是否存在已计算仓储费
-                            List<Long> ids = feesList.stream().map(TWarehousebillsfees::getSrcId).distinct().collect(toList());
-                            if (CollectionUtils.isNotEmpty(ids) && tWarehousebillsitemsMapper.selectIsCalculateStorageFeesByIds(ids) > 0) {
-                                throw new WarehouseException("计算费用中存在已计算仓储费信息");
+                        if (Objects.equals(fettle, 6L)) {
+                            if (Objects.equals(auditItems.getActId(), 120L)) {
+                                List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
+                                // 过滤出明细信息查询是否存在已计算仓储费
+                                List<Long> ids = feesList.stream().map(TWarehousebillsfees::getSrcId).distinct().collect(toList());
+                                if (CollectionUtils.isNotEmpty(ids) && tWarehousebillsitemsMapper.selectIsCalculateStorageFeesByIds(ids) > 0) {
+                                    throw new WarehouseException("计算费用中存在已计算仓储费信息");
+                                }
+                                // 获取仓储费,并判断费用中是否存在仓储费
+                                TFees ccf = feesMapper.seletFeesByCCF();
+                                if (Objects.isNull(ccf)) {
+                                    throw new WarehouseException("未找到仓储费费用信息");
+                                }
+                                // 过滤出费用类型等于仓储费并且有商机id,并取出来进行更新仓储费计费日期
+                                long count = feesList.stream().filter(li -> Objects.equals(li.getfFeeid(), ccf.getfId()) && Objects.nonNull(li.getSrcId()))
+                                        .count();
+                                if (count > 0) {
+                                    TWarehousebillsfees warehousebillsfees = feesList.stream().findFirst().orElseThrow(() -> new WarehouseException("未找到费用明细"));
+                                    // 更新子表仓储费截止日期
+                                    tWarehousebillsitemsMapper.updateItemStorageFeeDeadlineByPId(warehousebillsfees.getfPid(), warehousebillsfees.getfBillingDeadline());
+                                }
+                            } else if (Objects.equals(auditItems.getActId(), 150L)) {
+                                tWarehouseBillsService.approvedStorageFee(auditItems.getBillId(), fettle, at.getAuditItem());
                             }
-                            // 获取仓储费,并判断费用中是否存在仓储费
-                            TFees ccf = feesMapper.seletFeesByCCF();
-                            if (Objects.isNull(ccf)) {
-                                throw new WarehouseException("未找到仓储费费用信息");
-                            }
-                            // 过滤出费用类型等于仓储费并且有商机id,并取出来进行更新仓储费计费日期
-                            long count = feesList.stream().filter(li -> Objects.equals(li.getfFeeid(), ccf.getfId()) && Objects.nonNull(li.getSrcId()))
-                                    .count();
-                            if (count > 0) {
-                                TWarehousebillsfees warehousebillsfees = feesList.stream().findFirst().orElseThrow(() -> new WarehouseException("未找到费用明细"));
-                                // 更新子表仓储费截止日期
-                                tWarehousebillsitemsMapper.updateItemStorageFeeDeadlineByPId(warehousebillsfees.getfPid(), warehousebillsfees.getfBillingDeadline());
-                            }
-                        } else if (Objects.equals(auditItems.getActId(), 150L)) {
-                            tWarehouseBillsService.approvedStorageFee(auditItems.getBillId(), fettle, at.getAuditItem());
                         }
                     } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
                         // 财务模块

+ 2 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseAgreementServiceImpl.java

@@ -490,6 +490,8 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
             }
 
             if (storageFeesDto.getDays() >= dayLength) {
+                dayLength -= storageFeesDto.getEarlySumDays();
+                storageFeesDto.setEarlySumDays(0L);
                 feeId = tWarehouseAgreementitems.getfFeeid();
                 BigDecimal calculate = this.getCalculate(qty, tWarehouseAgreementitems.getfPrice(), dayLength);
                 money = money.add(calculate);

+ 61 - 53
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -3611,9 +3611,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             throw new WarehouseException("贸易方式不得与原贸易方式一致");
         }
         for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
-            if (StringUtils.isNull(wbItem.getfSrcid())) {
-                throw new WarehouseException("仓储明细找不对库存总帐信息");
-            }
             // 如果业务时间超出当前时间则不允许
             if (wbItem.getfBsdate().after(new Date())) {
                 throw new WarehouseException("业务日期不得超出当前日期");
@@ -3659,22 +3656,21 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 updateTWhgenlegData(wbItem, tWhgenle.getfId(), billsType);
                 wbItem.setfBillstatus(40L);
             } else if (WarehouseTypeEnum.CKDB.getType().equals(billsType) || WarehouseTypeEnum.HWTG.getType().equals(billsType)) { // 调拨查询
-                if (Objects.equals(wbItem.getfWarehouselocid(), wbItem.getfTransferWarehouselocid())) {
-                    throw new WarehouseException("库存明细第" + i + "行调入调出仓库不能一致");
-                }
                 //校验计费日期是等于库存总帐计费日,如果不相等则报错
                 checkWhgenleg(wbItem, tWhgenle);
-                if (tWhgenle.getfQtyblc() < wbItem.getfQty()) {  //  1、  库存 <  调拨件数  提示库存不足
-                    throw new WarehouseException("库存明细第" + i + "行库存不足");
-                } else {  // 2、 库存足够 先 进行出库操作
-                    updateTWhgenlegData(wbItem, tWhgenle.getfId(), WarehouseTypeEnum.SJCK.getType());
-                }
-                // 3、 进行入库操作 查询是否存在库存
-                TWhgenleg tWhgenle1 = queryWhgenlegService.secondStockWhgenleg(tWarehouseBills, wbItem, goods.getIfCntrno(), WarehouseTypeEnum.NOT_JUDGE_BOX.getType());
-                if (StringUtils.isNull(tWhgenle1)) {   // 5、 不存在 进行新增库存
-                    instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
-                } else { // 4、 存在 进行跟新库存
-                    updateTWhgenlegData(wbItem, tWhgenle1.getfId(), WarehouseTypeEnum.SJRK.getType());
+                if (!Objects.equals(wbItem.getfWarehouselocid(), wbItem.getfTransferWarehouselocid())) {
+                    if (tWhgenle.getfQtyblc() < wbItem.getfQty()) {  //  1、  库存 <  调拨件数  提示库存不足
+                        throw new WarehouseException("库存明细第" + i + "行库存不足");
+                    } else {  // 2、 库存足够 先 进行出库操作
+                        updateTWhgenlegData(wbItem, tWhgenle.getfId(), WarehouseTypeEnum.SJCK.getType());
+                    }
+                    // 3、 进行入库操作 查询是否存在库存
+                    TWhgenleg tWhgenle1 = queryWhgenlegService.secondStockWhgenleg(tWarehouseBills, wbItem, goods.getIfCntrno(), WarehouseTypeEnum.NOT_JUDGE_BOX.getType());
+                    if (StringUtils.isNull(tWhgenle1)) {   // 5、 不存在 进行新增库存
+                        instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
+                    } else { // 4、 存在 进行跟新库存
+                        updateTWhgenlegData(wbItem, tWhgenle1.getfId(), WarehouseTypeEnum.SJRK.getType());
+                    }
                 }
                 wbItem.setfBillstatus(40L);
             } else if (WarehouseTypeEnum.HQZY.getType().equals(billsType)) { // 货转
@@ -4109,11 +4105,11 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             storageFeesDto.setCangKey(cangKey);
             storageFeesDto.setWarehouseId(Long.parseLong(String.valueOf(item.getWarehouse())));
 
-            String fGoodsid = item.getFTypeid();
-            if (StringUtils.isNotEmpty(fGoodsid)) {
-                fGoodsid = "\"" + fGoodsid + "\"";
+            String goodsTypeids = item.getFTypeid();
+            if (StringUtils.isNotEmpty(goodsTypeids)) {
+                goodsTypeids = "\"" + goodsTypeids + "\"";
             }
-            storageFeesDto.setfGoodsid(fGoodsid);
+            storageFeesDto.setfGoodsid(goodsTypeids);
 
             long fId = item.getFId();
             // 累计计费天数
@@ -4190,7 +4186,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             fees.setSrcBillNo(item.getFBillno());
             fees.setCreateBy(loginUser.getUser().getUserName());
             fees.setfWarehouseid(storageFeesDto.getWarehouseId());
-            fees.setfProductName(item.getFGoodsids());
+            fees.setfProductName(item.getGoodsName());
             if (WarehouseTypeEnum.SJCK.getType().equals(item.getFBilltype()) ||
                     WarehouseTypeEnum.HQZY.getType().equals(item.getFBilltype())) {
                 fees.setfBillingDeadline(item.getFBsdate());
@@ -4349,15 +4345,15 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         tWarehouseBills.setfId(fPid);
         if (CollectionUtils.isNotEmpty(feesInfoVOList)) {
             StorageFeeCalculationResultVO resultVO = getWarehouseItems1(tWarehouseBills, feesInfoVOList, loginUser, cangKey);
-            if (CollectionUtils.isEmpty(resultVO.getItemFeesList())) {
-                throw new WarehouseException("计费明细信息为空");
+            if (CollectionUtils.isNotEmpty(resultVO.getItemFeesList())) {
+                // 给仓库信息赋值
+                resultVO.getItemFeesList().forEach(li -> {
+                    TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
+                            .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
+                    li.setWarehouseName(tWarehouse.getfName());
+                });
+                itemsList = resultVO.getItemFeesList();
             }
-            // 给仓库信息赋值
-            resultVO.getItemFeesList().forEach(li -> {
-                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
-                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
-                li.setWarehouseName(tWarehouse.getfName());
-            });
         }
         List<CalculateStorageFeesInfoVO> whgenlegfeesInfoVOList = tWhgenlegMapper.selectStorageFeeItemList1(tWarehouseBills);
         if (CollectionUtils.isNotEmpty(whgenlegfeesInfoVOList)) {
@@ -4366,15 +4362,14 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 updateWhgenlegs1(tWarehouseBills, whgenlegfeesInfoVOList);
             }
             StorageFeeCalculationResultVO resultVO = getWarehouseItems1(tWarehouseBills, whgenlegfeesInfoVOList, loginUser, cangKey);
-            if (CollectionUtils.isEmpty(resultVO.getItemFeesList())) {
-                throw new WarehouseException("计费明细信息为空");
-            }
-            // 给仓库信息赋值
-            for (TWarehousebillsfees li : resultVO.getItemFeesList()) {
-                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
-                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
-                li.setWarehouseName(tWarehouse.getfName());
-                itemsList.add(li);
+            if (CollectionUtils.isNotEmpty(resultVO.getItemFeesList())) {
+                // 给仓库信息赋值
+                for (TWarehousebillsfees li : resultVO.getItemFeesList()) {
+                    TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
+                            .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
+                    li.setWarehouseName(tWarehouse.getfName());
+                    itemsList.add(li);
+                }
             }
         }
         TFees tFees = new TFees();
@@ -4397,14 +4392,14 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
      * @param tWhgenlegs
      * @return
      */
-    private List<Map<String, Object>> updateWhgenlegs(TWarehouseBills tWarehouseBills, List<Map<String, Object>> tWhgenlegs) {
+    private void updateWhgenlegs(TWarehouseBills tWarehouseBills, List<Map<String, Object>> tWhgenlegs) {
         // 获取区间时间
         tWarehouseBills.setItemBsDateList(timeConversion(tWarehouseBills.getfBillingDeadline(), new Date()));
         // 查询时间区间内的仓储业务明细信息
         List<TWarehousebillsitems> warehousebillsitemsList = tWarehousebillsitemsMapper.selectListByCorpId(tWarehouseBills);
         // 如果没有则直接结束此方法
         if (CollectionUtils.isEmpty(warehousebillsitemsList)) {
-            return tWhgenlegs;
+            return;
         }
         tWhgenlegs.forEach(whgenleg -> {
             // 判断是否计算箱号 0为 不计算 1为计算
@@ -4449,7 +4444,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             whgenleg.put("fNetweight", tWhgenleg.getfNetweightblc());
             whgenleg.put("fGrossweight", tWhgenleg.getfGrossweightblc());
         });
-        return tWhgenlegs;
     }
 
     private void updateWhgenlegs1(TWarehouseBills tWarehouseBills, List<CalculateStorageFeesInfoVO> infoVOList) {
@@ -4475,6 +4469,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             tWhgenleg.setfNetweightblc(whgenleg.getFNetweight());
             tWhgenleg.setfGrossweightblc(whgenleg.getFGrossweight());
             tWhgenleg.setfWarehouseid(whgenleg.getWarehouseLocationid());
+            tWhgenleg.setfOriginalbilldate(whgenleg.getFOriginalbilldate());
 
             log.info("每次yuan件数、毛重、净重、:{}, {}, {}, {}", tWhgenleg.getfQtyblc(), tWhgenleg.getfVolumnblc(), tWhgenleg.getfNetweightblc(),
                     tWhgenleg.getfGrossweightblc());
@@ -4482,8 +4477,10 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             List<TWarehousebillsitems> itemList = new ArrayList<>();
             for (TWarehousebillsitems li : warehousebillsitemsList) {
                 if ((!Objects.equals(li.getfGoodsid(), tWhgenleg.getfGoodsid())) ||
-                        (!Objects.equals(li.getfWarehouselocid(), tWhgenleg.getfWarehouseid()) || Objects.equals(li.getfTransferWarehouselocid(), tWhgenleg.getfWarehouseid())) ||
+                        (!Objects.equals(li.getfWarehouselocid(), tWhgenleg.getfWarehouseid()) ||
+                                Objects.equals(li.getfTransferWarehouselocid(), tWhgenleg.getfWarehouseid())) ||
                         !li.getfMblno().equals(tWhgenleg.getfMblno()) ||
+                        !Objects.equals(li.getfOriginalbilldate(), tWhgenleg.getfOriginalbilldate()) ||
                         (!li.getfMarks().equals(tWhgenleg.getfMarks())) ||
                         (ifCntrno && !li.getfCntrno().equals(tWhgenleg.getfCntrno()))
                 ) {
@@ -4922,7 +4919,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         for (TWarehousebillsfees fees : feesList) {
             storageFeeUpdateItem(warehouseBills, fees);
         }
-        warehouseBills.setfBillstatus(6L);
+        warehouseBills.setfBillstatus(fettle);
         warehouseBills.setUpdateTime(new Date());
         tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);
     }
@@ -6142,18 +6139,26 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                     }
                     wb.setfBillstatus(10L);
                 } else if (WarehouseTypeEnum.CKDB_REVOKE.getType().equals(billsType)) { // 调拨 撤销
-                    //  1、新货权方撤销入库
-                    TWhgenleg tWhgenle = queryWhgenlegService.secondStockWhgenleg(tWarehousebills, wb, goods.getIfCntrno(), WarehouseTypeEnum.CONFIRM_OPERATION.getType());
-                    if (StringUtils.isNotNull(tWhgenle) && (wb.getfQty() <= tWhgenle.getfQtyblc())) {
-                        updateTWhgenlegData(wb, tWhgenle.getfId(), WarehouseTypeEnum.SJRK_REVOKE.getType());
-                    } else {
-                        throw new WarehouseException("第" + i + "行撤销数大于库存结余数");
+                    if (wb.getCreateTime().before(new Date(1637025878284L))) {
+                        throw new WarehouseException("该单据已被锁定,请联系管理员");
+                    }
+                    if (!Objects.equals(wb.getfWarehouselocid(), wb.getfTransferWarehouselocid())) {
+                        //  1、新货权方撤销入库
+                        TWhgenleg tWhgenle = queryWhgenlegService.secondStockWhgenleg(tWarehousebills, wb, goods.getIfCntrno(), WarehouseTypeEnum.CONFIRM_OPERATION.getType());
+                        if (StringUtils.isNotNull(tWhgenle) && (wb.getfQty() <= tWhgenle.getfQtyblc())) {
+                            updateTWhgenlegData(wb, tWhgenle.getfId(), WarehouseTypeEnum.SJRK_REVOKE.getType());
+                        } else {
+                            throw new WarehouseException("第" + i + "行撤销数大于库存结余数");
+                        }
+                        //  2、原货权方撤销出库
+                        TWhgenleg whgenleg = queryWhgenlegService.stockWhgenleg(tWarehousebills, wb, goods.getIfCntrno(), WarehouseTypeEnum.UNDO_OPERATION.getType());
+                        updateTWhgenlegData(wb, whgenleg.getfId(), WarehouseTypeEnum.SJCK_REVOKE.getType());
                     }
-                    //  2、原货权方撤销出库
-                    TWhgenleg whgenleg = queryWhgenlegService.stockWhgenleg(tWarehousebills, wb, goods.getIfCntrno(), WarehouseTypeEnum.UNDO_OPERATION.getType());
-                    updateTWhgenlegData(wb, whgenleg.getfId(), WarehouseTypeEnum.SJCK_REVOKE.getType());
                     wb.setfBillstatus(10L);
                 } else if (WarehouseTypeEnum.HWTG_REVOKE.getType().equals(billsType)) { // 调拨 撤销
+                    if (wb.getCreateTime().before(new Date(1637025878284L))) {
+                        throw new WarehouseException("该单据已被锁定,请联系管理员");
+                    }
                     //  1、新货权方撤销入库
                     // 查询库存总账
                     TWhgenleg tWhgenle = queryWhgenlegService.secondStockWhgenleg(tWarehousebills, wb, goods.getIfCntrno(), WarehouseTypeEnum.CONFIRM_OPERATION.getType());
@@ -6169,6 +6174,9 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                     updateTWhgenlegData(wb, whgenleg.getfId(), WarehouseTypeEnum.SJCK_REVOKE.getType());
                     wb.setfBillstatus(10L);
                 } else if (WarehouseTypeEnum.HQZY_REVOKE.getType().equals(billsType)) { // 货转撤销
+                    if (wb.getCreateTime().before(new Date(1637025878284L))) {
+                        throw new WarehouseException("该单据已被锁定,请联系管理员");
+                    }
                     Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
                     Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
                     //  1、新货权方撤销入库

+ 4 - 3
ruoyi-warehouse/src/main/resources/mapper/reportManagement/TWhgenlegMapper.xml

@@ -59,6 +59,7 @@
         <result property="fMblno" column="f_mblno"/>
         <result property="fVolumn" column="f_volumn"/>
         <result property="fMarks" column="f_marks"/>
+        <result property="ifCntrno" column="if_cntrno"/>
         <result property="fBillingDays" column="f_billing_days"/>
         <result property="fIsInventory" column="f_is_inventory"/>
         <result property="fQty" column="f_qty"/>
@@ -68,7 +69,7 @@
         <result property="fNetweight" column="f_netweight"/>
         <result property="fBilltype" column="f_billtype"/>
         <result property="fTypeid" column="f_typeid"/>
-        <result property="ifCntrno" column="f_cntrno"/>
+        <result property="fCntrno" column="f_cntrno"/>
         <result property="goodsName" column="goods_name"/>
     </resultMap>
 
@@ -586,7 +587,7 @@
             wh.f_id,
             wh.f_originalbillno AS f_billno,
             wh.f_goodsid,
-            wh.f_bsdate,
+            wh.f_originalbilldate AS f_bsdate,
             wh.f_billingway,
             wh.f_mblno,
             wh.f_chargedate,
@@ -600,7 +601,7 @@
             wh.f_warehouseid,
             wh.f_warehouse_locationid,
             "KCZZ" AS f_billtype,
-            goods.if_cntrno AS if_cntrno,
+            goods.if_cntrno,
             goods.f_typeid AS f_typeid,
             goods.f_name AS goods_name
         FROM