Explorar o código

添加仓储费计算 后端方法

阿伏兔 %!s(int64=4) %!d(string=hai) anos
pai
achega
fc31581323

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/warehouseBusiness/TStorageFeeCalculationController.java

@@ -65,7 +65,7 @@ public class TStorageFeeCalculationController extends BaseController {
     @PreAuthorize("@ss.hasPermi('warehouseBusiness:storageFeeCalculation:query')")
     @GetMapping(value = "/{fId}")
     public AjaxResult getInfo(@PathVariable("fId") Long fId) {
-        return AjaxResult.success(itWarehouseBillsService.selectTWarehousebillsById(fId));
+        return itWarehouseBillsService.selectStorageFeeById(fId);
     }
 
     /**

+ 1 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/reportManagement/mapper/TWhgenlegMapper.java

@@ -98,5 +98,5 @@ public interface TWhgenlegMapper {
      * @param tWarehouseBills
      * @return
      */
-    List<TWhgenleg> selectStorageFeeItemList(@Param("warehouse") TWarehouseBills tWarehouseBills);
+    List<Map<String, Object>> selectStorageFeeItemList(@Param("warehouse") TWarehouseBills tWarehouseBills);
 }

+ 1 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/mapper/TWarehousebillsitemsMapper.java

@@ -73,5 +73,5 @@ public interface TWarehousebillsitemsMapper extends BaseMapper<TWarehousebillsit
      * @param tWarehouseBills 查询条件
      * @return  结果
      */
-    List<TWarehousebillsitems> selectStorageFeeItemList(@Param("warehouse") TWarehouseBills tWarehouseBills);
+    List<Map<String, Object>> selectStorageFeeItemList(@Param("warehouse") TWarehouseBills tWarehouseBills);
 }

+ 7 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/ITWarehouseBillsService.java

@@ -131,4 +131,11 @@ public interface ITWarehouseBillsService {
      * @return
      */
     AjaxResult insertStorageFee(String warehouseBills, String warehouseItems, String warehouseFees, LoginUser loginUser, String billsType);
+
+    /**
+     *  根据id 查询仓储费计算明细
+     * @param fId
+     * @return
+     */
+    AjaxResult selectStorageFeeById(Long fId);
 }

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

@@ -283,7 +283,7 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
 
         for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
             if (days < 1) break;
-            if (earlySumDays >= tWarehouseAgreementitems.getfEndays()) break; //将已算账的天数 与 计费规则的 最后一天作比较如果 已算10天 > 规则结束  不算帐
+            if (earlySumDays >= tWarehouseAgreementitems.getfEndays()) continue; //将已算账的天数 与 计费规则的 最后一天作比较如果 已算10天 > 规则结束  不算帐
 
             dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L; //阶梯中的结束-开始日期
 

+ 211 - 205
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -389,22 +389,22 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             tWarehousebillsfeesMapper.deleteByFPid(fPid);
             tEnclosureMapper.deleteByFPid(fPid);
             // 删除  从表中 未打印账单的数据
-            deleteBillsitems(fPid,tWarehousebillsitems);
+            deleteBillsitems(fPid, tWarehousebillsitems);
         }
         // 库存明细添加
-        List<TWarehousebillsitems> tWarehousebillsitemsList=new ArrayList<>();
-        if (tWarehousebillsitems != null ) {
+        List<TWarehousebillsitems> tWarehousebillsitemsList = new ArrayList<>();
+        if (tWarehousebillsitems != null) {
             JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
             List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
             for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
                 // 仓储计费日期
                 wbItem.setfChargedate(warehouseBills.getfChargedate());
                 wbItem.setfBilltype(billsType);
-                if(null!=wbItem.getfId()){
+                if (null != wbItem.getfId()) {
                     wbItem.setUpdateBy(loginUser.getUser().getUserName());
                     wbItem.setUpdateTime(new Date());
                     tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
-                }else{
+                } else {
                     // 添加主表 业务单号
                     wbItem.setfBillno(warehouseBills.getfBillno());
                     wbItem.setfMblno(warehouseBills.getfMblno());
@@ -413,9 +413,9 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                     wbItem.setCreateTime(new Date());
                     wbItem.setfBillstatus(10L);
                     tWarehousebillsitemsMapper.insertTWarehousebillsitems(wbItem);
-                    if(!billsType.equals("HQZY")){
+                    if (!billsType.equals("HQZY")) {
                         // 添加状态log
-                        insertTWarehousebillsLog(wbItem, 10L,loginUser);
+                        insertTWarehousebillsLog(wbItem, 10L, loginUser);
                     }
                 }
                 tWarehousebillsitemsList.add(wbItem);
@@ -478,7 +478,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
      */
     @Override
     @Transactional
-    public AjaxResult addCredit(String warehouseBills, String warehousebillsitems,  LoginUser loginUser, String billsType) {
+    public AjaxResult addCredit(String warehouseBills, String warehousebillsitems, LoginUser loginUser, String billsType) {
         Long fPid = null;
         Map<String, Object> map = new HashMap<>();
         if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
@@ -497,8 +497,8 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
         for (TWarehousebillsitems item : warehousebillsitemsList) {
             // 查询库容量  是否可入库
-            int m=calculation(tWarehouseBills.getfWarehouseid(),item.getfGrossweight());
-            if(m == 0){
+            int m = calculation(tWarehouseBills.getfWarehouseid(), item.getfGrossweight());
+            if (m == 0) {
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return AjaxResult.error("更新库存总账失败-->入库毛重大于库容");
             }
@@ -524,7 +524,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 item.setUpdateTime(new Date());
                 num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
                 // 添加状态log
-                insertTWarehousebillsLog(item,40L,loginUser);
+                insertTWarehousebillsLog(item, 40L, loginUser);
             }
             if (num <= 0) {
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -671,9 +671,9 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 wbItem.setUpdateBy(loginUser.getUser().getUserName());
                 wbItem.setUpdateTime(new Date());
                 num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
-                if("SJCK".equals(billsType)){
+                if ("SJCK".equals(billsType)) {
                     // 添加状态log
-                    insertTWarehousebillsLog(wbItem,40L,loginUser);
+                    insertTWarehousebillsLog(wbItem, 40L, loginUser);
                 }
             }
             if (num <= 0) {
@@ -692,7 +692,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
 
 
     @Override
-    public AjaxResult waitWarehousing(String warehouseBills, String warehousebillsitems, LoginUser loginUser, Long status,String billtystatus) {
+    public AjaxResult waitWarehousing(String warehouseBills, String warehousebillsitems, LoginUser loginUser, Long status, String billtystatus) {
         Map<String, Object> map = new HashMap<>();
         if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
             return AjaxResult.error("未找到主表信息");
@@ -706,19 +706,19 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             tWarehouseBills.setUpdateTime(new Date());
             tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
         }
-        List<TWarehousebillsitems> tWarehousebillsitemsList=new ArrayList<>();
+        List<TWarehousebillsitems> tWarehousebillsitemsList = new ArrayList<>();
         JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
         List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
         for (TWarehousebillsitems item : warehousebillsitemsList) {
             // 生成流水号
             Date time = new Date();
             String serialNumber;
-            if(billtystatus.equals("20")){ // 生成 入库 流水号
-                 serialNumber = billnoSerialServiceImpl.getSerialNumber("RK", time);
-                 item.setfSerialNumber(serialNumber);
-            } else if (billtystatus.equals("70")){ //生成 出库 流水号
-                 serialNumber = billnoSerialServiceImpl.getSerialNumber("CK", time);
-                 item.setfSerialNumber(serialNumber);
+            if (billtystatus.equals("20")) { // 生成 入库 流水号
+                serialNumber = billnoSerialServiceImpl.getSerialNumber("RK", time);
+                item.setfSerialNumber(serialNumber);
+            } else if (billtystatus.equals("70")) { //生成 出库 流水号
+                serialNumber = billnoSerialServiceImpl.getSerialNumber("CK", time);
+                item.setfSerialNumber(serialNumber);
             }
             int num = 0;
             if (StringUtils.isNotNull(item.getfId())) {
@@ -727,7 +727,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 item.setUpdateBy(loginUser.getUser().getUserName());
                 num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
                 // 添加状态log
-                insertTWarehousebillsLog(item,status,loginUser);
+                insertTWarehousebillsLog(item, status, loginUser);
             } else {
                 item.setfPid(tWarehouseBills.getfId());
                 item.setfBillno(tWarehouseBills.getfBillno());
@@ -736,8 +736,8 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 item.setCreateBy(loginUser.getUser().getUserName());
                 num = tWarehousebillsitemsMapper.insertTWarehousebillsitems(item);
                 // 添加状态log
-                insertTWarehousebillsLog(item,10L,loginUser);
-                insertTWarehousebillsLog(item,status,loginUser);
+                insertTWarehousebillsLog(item, 10L, loginUser);
+                insertTWarehousebillsLog(item, status, loginUser);
             }
             if (num <= 0) {
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -750,12 +750,86 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         return AjaxResult.success("成功", map);
     }
 
+    public Map<String, Object> getWarehouseItems(TWarehouseBills warehouseBills, List<Map<String, Object>> mapItem, LoginUser loginUser) {
+        Map<String, Object> map = new HashMap<>();
+        long feeId = 0L;
+        BigDecimal sumAmt = new BigDecimal(0);
+        List<TWarehousebillsitems> itemsList = new ArrayList<>();
+        for (Map<String, Object> item : mapItem) {
+            if (StringUtils.isNull(item.get("fBillingway"))) {
+                map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
+                return map;
+            }
+            long fGoodsid = Long.parseLong((String) item.get("fTypeid"));
+            long fCorpid = warehouseBills.getfCorpid();
+            long dateDay = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
+            long fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
+            Long dictLabel = Long.valueOf(String.valueOf(item.get("fBillingway")));
+            BigDecimal fQty = this.acquiredQuantity(item, dictLabel);
+            if (fQty.equals(BigDecimal.ZERO)) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到计费单位,请确认");
+            }
+            // 计算仓储费明细
+            Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, dateDay, dictLabel, fQty, fInventoryDays);
+            if (StringUtils.isNull(objectMap)) {
+                map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
+                return map;
+            }
+            String fBilltype = (String) objectMap.get("fBilltype");
+            feeId = Long.valueOf(String.valueOf(objectMap.get("feeId"))).longValue();
+            BigDecimal amt = (BigDecimal) objectMap.get("amt");
+            map.put("feeId", feeId);
+            map.put("itemFeeId", objectMap.get("feeId"));
+            sumAmt = sumAmt.add(amt);
+            TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
+            tWarehousebillsitems.setfAmt(amt);
+            tWarehousebillsitems.setfBillstatus(50L);
+            tWarehousebillsitems.setfBillingQty(fQty);
+            tWarehousebillsitems.setfBilltype(fBilltype);
+            tWarehousebillsitems.setfBillingDays(dateDay);
+            tWarehousebillsitems.setCreateTime(new Date());
+            tWarehousebillsitems.setfPid(warehouseBills.getfId());
+            tWarehousebillsitems.setfInventoryDays(fInventoryDays);
+            tWarehousebillsitems.setfBsdate((Date) item.get("fBsdate"));
+            tWarehousebillsitems.setfBillno((String) item.get("fBillno"));
+            tWarehousebillsitems.setfGoodsid(Long.valueOf(String.valueOf(item.get("fGoodsid"))).longValue());
+            tWarehousebillsitems.setCreateBy(loginUser.getUser().getUserName());
+            tWarehousebillsitems.setfBillingway(Long.valueOf(String.valueOf(item.get("fBillingway"))).longValue());
+            tWarehousebillsitems.setfChargedate((Date) item.get("fChargedate"));
+            tWarehousebillsitems.setfOriginalbilldate((Date) item.get("fOriginalbilldate"));
+            tWarehousebillsitems.setfBillingDeadline(warehouseBills.getfBillingDeadline());
+            tWarehousebillsitemsMapper.insertTWarehousebillsitems(tWarehousebillsitems);
+            itemsList.add(tWarehousebillsitems);
+        }
+        TWarehousebillsfees fees = new TWarehousebillsfees();
+        fees.setfPid(warehouseBills.getfId());
+        fees.setfFeeid(feeId);
+        fees.setfCorpid(warehouseBills.getfCorpid());
+        fees.setfFeeunitid(2L);
+        fees.setfQty(new BigDecimal(1));
+        fees.setfUnitprice(sumAmt);
+        fees.setfAmount(sumAmt);
+        fees.setfExrate(new BigDecimal(1));
+        fees.setfCurrency("RMB");
+        List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
+        fees.setfDc("D");
+        fees.setfTaxrate(new BigDecimal(taxRate.get(0).getDictValue()));
+        fees.setCreateBy(loginUser.getUser().getUserName());
+        fees.setCreateTime(new Date());
+        map.put("fees", fees);
+        map.put("sumAmt", sumAmt);
+        map.put("itemsList", itemsList);
+        return map;
+    }
+
     /**
      * 新增库存费计算
-     * @param tWarehouseBills   主表的查询条件
-     * @param loginUser         登录用户
-     * @param billsType         状态
-     * @return  结果
+     *
+     * @param tWarehouseBills 主表的查询条件
+     * @param loginUser       登录用户
+     * @param billsType       状态
+     * @return 结果
      */
     @Override
     @Transactional
@@ -773,12 +847,12 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
             fPid = tWarehouseBills.getfId();
         } else {
-            fPid = tWarehouseBills.getfId();
+            tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
+            tWarehousebillsitemsMapper.deleteByFPid(tWarehouseBills.getfId());
             tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
             tWarehouseBills.setUpdateTime(new Date());
             tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
-            tWarehousebillsfeesMapper.deleteByFPid(fPid);
-            tWarehousebillsitemsMapper.deleteByFPid(fPid);
+            fPid = tWarehouseBills.getfId();
         }
         // 应收费用明细
         List<TWarehousebillsfees> warehousebillsfeesList = new ArrayList<>();
@@ -786,124 +860,39 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         List<TWarehousebillsitems> itemsList = new ArrayList<>();
         BigDecimal bigDecimal = new BigDecimal(0);
         Map<String, Object> map = new HashMap<>();
-        // 库存明细id
-        long itemFeeId = 0;
         // 库存总账id
         long whgenlegFeeId = 0;
         // 计费单位
         long feeUnitid = 1;
         // 查询 出库 货转的库存明细
-        List<TWarehousebillsitems> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
+        List<Map<String, Object>> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
         if (StringUtils.isNotNull(warehousebillsitemsList)) {
-            // 出库货转的金额总和
-            BigDecimal sumAmt = new BigDecimal(0);
-            long fCorpid = tWarehouseBills.getfCorpid();
-            for (TWarehousebillsitems item : warehousebillsitemsList) {
-                if (StringUtils.isNull(item.getfBillingway())) {
-                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                    return AjaxResult.error("未找到库存总账的计费单位,请确认");
-                }
-                TGoods tGoods = tGoodsMapper.selectTGoodsById(item.getfGoodsid());
-                long fGoodsid = tGoods.getfTypeid();
-                long dateDay = DateUtils.getDateDay(tWarehouseBills.getfBillingDeadline(), item.getfChargedate());
-                long fInventoryDays = DateUtils.getDateDay(tWarehouseBills.getfBillingDeadline(), item.getfOriginalbilldate());
-                Long dictLabel = item.getfBillingway();
-                BigDecimal fQty = this.acquiredQuantity(item, dictLabel);
-                if (fQty.compareTo(bigDecimal) == 0) {
-                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                    return AjaxResult.error("未找到计费单位,请确认");
-                }
-                // 计算仓储费明细
-                Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, dateDay, dictLabel, fQty , fInventoryDays);
-                itemFeeId = (long)objectMap.get("feeId");
-                BigDecimal amt = (BigDecimal) objectMap.get("amt");
-                sumAmt = sumAmt.add(amt);
-                item.setfAmt(amt);
-                item.setfBillingQty(fQty);
-                item.setfInventoryDays(fInventoryDays);
-                item.setfBillstatus(50L);
-                item.setfChargedate(tWarehouseBills.getfBillingDeadline());
-                item.setfBillingDeadline(tWarehouseBills.getfBillingDeadline());
-                item.setUpdateBy(loginUser.getUser().getUserName());
-                item.setUpdateTime(new Date());
-                item.setfId(null);
-                item.setfPid(fPid);
-                tWarehousebillsitemsMapper.insertTWarehousebillsitems(item);
-                itemsList.add(item);
+            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, warehousebillsitemsList, loginUser);
+            if (mapItem.containsKey("error")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error((String) mapItem.get("error"));
             }
-            TWarehousebillsfees fees = new TWarehousebillsfees();
-            fees.setfPid(fPid);
-            fees.setfFeeid(itemFeeId);
-            fees.setfCorpid(tWarehouseBills.getfCorpid());
-//            fees.setfFeeUnitid(feeUnitid);
-            fees.setfQty(new BigDecimal(1));
-            fees.setfUnitprice(sumAmt);
-            fees.setfAmount(sumAmt);
-            fees.setfExrate(new BigDecimal(1));
-            fees.setfCurrency("RMB");
-            List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
-            fees.setfDc("D");
-            fees.setfTaxrate(new BigDecimal(taxRate.get(0).getDictValue()));
-            fees.setCreateBy(loginUser.getUser().getUserName());
-            fees.setCreateTime(new Date());
+            TWarehousebillsfees fees = (TWarehousebillsfees) mapItem.get("fees");
             tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
+            itemsList = (List<TWarehousebillsitems>) mapItem.get("itemsList");
             warehousebillsfeesList.add(fees);
         }
-        List<TWhgenleg> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
-        if (StringUtils.isNotNull(tWhgenlegs)) {
-            // 出库货转的金额总和
-            BigDecimal sumAmt = new BigDecimal(0);
-            for (TWhgenleg wg : tWhgenlegs) {
-                TGoods tGoods = tGoodsMapper.selectTGoodsById(wg.getfGoodsid());
-                long fGoodsid = tGoods.getfTypeid();
-                long dateDay = DateUtils.getDateDay(tWarehouseBills.getfBillingDeadline(), wg.getfChargedate());
-                long fInventoryDays = DateUtils.getDateDay(tWarehouseBills.getfBillingDeadline(), wg.getfOriginalbilldate());
-                wg.setfChargedate(tWarehouseBills.getfBillingDeadline());
-                long dictLabel = wg.getfBillingway();
-                BigDecimal fQty = this.getInventoryQuantity(wg, dictLabel);
-                if (fQty.compareTo(bigDecimal) == 0) {
-                    return AjaxResult.error("未找到计费单位,请确认");
-                }
-                // 计算仓储费明细
-                Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(wg.getfCorpid(), fGoodsid, dateDay, dictLabel, fQty , fInventoryDays);
-                whgenlegFeeId = (long)objectMap.get("feeId");
-                BigDecimal amt = (BigDecimal) objectMap.get("amt");
-                sumAmt = sumAmt.add(amt);
-                TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
-                tWarehousebillsitems.setfPid(fPid);
-                // 仓库总账
-                tWarehousebillsitems.setfBilltype("CKZZ");
-                tWarehousebillsitems.setfBillno(wg.getfOriginalbillno());
-                tWarehousebillsitems.setfGoodsid(wg.getfGoodsid());
-                tWarehousebillsitems.setfOriginalbilldate(wg.getfOriginalbilldate());
-                tWarehousebillsitems.setfBillingway(wg.getfBillingway());
-                tWarehousebillsitems.setfBillingQty(fQty);
-                tWarehousebillsitems.setfChargedate(wg.getfChargedate());
-                tWarehousebillsitems.setfBillingDeadline(tWarehouseBills.getfBillingDeadline());
-                tWarehousebillsitems.setfBillingDays(dateDay);
-                tWarehousebillsitems.setfAmt(amt);
-                tWarehousebillsitems.setCreateBy(loginUser.getUser().getUserName());
-                tWarehousebillsitems.setCreateTime(new Date());
-                tWarehousebillsitems.setfBillstatus(50L);
-                tWarehousebillsitemsMapper.insertTWarehousebillsitems(tWarehousebillsitems);
-                itemsList.add(tWarehousebillsitems);
+        List<Map<String, Object>> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
+        if (StringUtils.isNotNull(tWhgenlegs) && "[]".equals(tWhgenlegs)) {
+            System.out.println(tWhgenlegs);
+            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, tWhgenlegs, loginUser);
+            if (mapItem.containsKey("error")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error((String) mapItem.get("error"));
             }
-            TWarehousebillsfees fees = new TWarehousebillsfees();
-            fees.setfPid(fPid);
-            fees.setfFeeid(whgenlegFeeId);
-            fees.setfCorpid(tWarehouseBills.getfCorpid());
-//        fees.setfFeeUnitid(feeUnitid);
-            fees.setfQty(new BigDecimal(1));
-            fees.setfUnitprice(sumAmt);
-            fees.setfAmount(sumAmt);
-            fees.setfExrate(new BigDecimal(1));
-            fees.setfCurrency("RMB");
-            List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
-            fees.setfDc("D");
-            fees.setfTaxrate(new BigDecimal(taxRate.get(0).getDictValue()));
-            fees.setCreateBy(loginUser.getUser().getUserName());
-            fees.setCreateTime(new Date());
+            TWarehousebillsfees fees = (TWarehousebillsfees) mapItem.get("fees");
             tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
+            List<TWarehousebillsitems> itemList = (List<TWarehousebillsitems>) mapItem.get("itemsList");
+            if (itemList.size() != 0) {
+                for (TWarehousebillsitems ite : itemList) {
+                    itemsList.add(ite);
+                }
+            }
             warehousebillsfeesList.add(fees);
         }
         TGoods tGoods = new TGoods();
@@ -911,11 +900,12 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         tGoods.setDelFlag("0");
         List<TGoods> goods = tGoodsMapper.selectTGoodsList(tGoods);
         TFees tFees = new TFees();
-        tFees.setfStatus("0");
+        tFees.setfStatus("2");
         tFees.setDelFlag("0");
         List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
         map.put("goodsList", goods);
         map.put("feesList", feesList);
+        map.put("warehouseBills", tWarehouseBills);
         map.put("warehouseItemList", itemsList);
         map.put("warehouseFeesList", warehousebillsfeesList);
         return AjaxResult.success(map);
@@ -923,6 +913,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
 
     /**
      * 仓储费计算提交以及暂存
+     *
      * @param warehouseBills
      * @param warehouseItems
      * @param warehouseFees
@@ -982,44 +973,56 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
-     *  根据不同计费单位获取不同 计算库存明细数量
-     * @param item      库存明细
-     * @param dictLabel 计费单位
-     * @return 结果
+     *  根据id查询仓储费计算信息
+     * @param fId
+     * @return
      */
-    public BigDecimal acquiredQuantity (TWarehousebillsitems item, Long dictLabel) {
-        BigDecimal fQty = new BigDecimal(0);
-        // 件数
-        long boxNum = 1;
-        // 毛重
-        long grossWeight = 2;
-        // 净重
-        long netWeight = 3;
-        // 尺码
-        long size = 4;
-        // 尺码
-        long fixed = 5;
-        if (dictLabel.equals(boxNum)) {
-            fQty = new BigDecimal(item.getfQty());
-        } else if (dictLabel.equals(grossWeight)) {
-            fQty = item.getfGrossweight();
-        } else if (dictLabel.equals(netWeight)) {
-            fQty = item.getfNetweight();
-        } else if (dictLabel.equals(size)) {
-            fQty = item.getfVolumn();
-        } else if (dictLabel.equals(fixed)){
-            fQty = new BigDecimal(1);
+    @Override
+    public AjaxResult selectStorageFeeById(Long fId) {
+        TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
+        if (StringUtils.isNull(tWarehouseBills)) {
+            return AjaxResult.error("未找到信息,请刷新页面重试");
         }
-        return fQty;
+        Map<String, Object> map = new HashMap<>();
+        TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
+        tWarehousebillsitems.setfPid(fId);
+        List<TWarehousebillsitems> warehouseItemsList = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
+        TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
+        warehousebillsfees.setfPid(fId);
+        List<TWarehousebillsfees> warehouseFeesList = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
+        TGoods tGoods = new TGoods();
+        tGoods.setfStatus("0");
+        tGoods.setDelFlag("0");
+        List<TGoods> goods = tGoodsMapper.selectTGoodsList(tGoods);
+        TFees tFees = new TFees();
+        tFees.setfStatus("2");
+        tFees.setDelFlag("0");
+        List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
+        // 查询联系人
+        List<SysUser> sysUserList = new ArrayList<>();
+        SysUser sysUser = sysUserMapper.selectUserByUserName(tWarehouseBills.getCreateBy());
+        if (StringUtils.isNotNull(sysUser)) {
+            sysUserList.add(sysUser);
+        }
+        TCorps corps = tCorpsMapper.selectTCorpsById(tWarehouseBills.getfCorpid());
+        map.put("corps", corps);
+        map.put("goodsList", goods);
+        map.put("feesList", feesList);
+        map.put("sysUser", sysUserList);
+        map.put("warehouse", tWarehouseBills);
+        map.put("warehouseFeesList", warehouseFeesList);
+        map.put("warehouseItemsList", warehouseItemsList);
+        return AjaxResult.success(map);
     }
 
     /**
-     *  根据不同计费单位获取不同 计算库存总账数量
-     * @param whegen    库存总账
+     * 根据不同计费单位获取不同 计算库存明细数量
+     *
+     * @param item      库存明细
      * @param dictLabel 计费单位
      * @return 结果
      */
-    public BigDecimal getInventoryQuantity (TWhgenleg whegen, Long dictLabel) {
+    public BigDecimal acquiredQuantity(Map<String, Object> item, Long dictLabel) {
         BigDecimal fQty = new BigDecimal(0);
         // 件数
         long boxNum = 1;
@@ -1029,23 +1032,22 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         long netWeight = 3;
         // 尺码
         long size = 4;
-        // 尺码
+        // 统一
         long fixed = 5;
         if (dictLabel.equals(boxNum)) {
-            fQty = new BigDecimal(whegen.getfQtyblc());
+            fQty = new BigDecimal(((Number) item.get("fQty")).doubleValue());
         } else if (dictLabel.equals(grossWeight)) {
-            fQty = whegen.getfGrossweightblc();
+            fQty = new BigDecimal(((Number) item.get("fGrossweight")).doubleValue());
         } else if (dictLabel.equals(netWeight)) {
-            fQty = whegen.getfNetweightc();
+            fQty = new BigDecimal(((Number) item.get("fNetweight")).doubleValue());
         } else if (dictLabel.equals(size)) {
-            fQty = whegen.getfVolumnblc();
-        } else if (dictLabel.equals(fixed)){
+            fQty = new BigDecimal(((Number) item.get("fVolumn")).doubleValue());
+        } else if (dictLabel.equals(fixed)) {
             fQty = new BigDecimal(1);
         }
         return fQty;
     }
 
-
     // 入库 收费明细 校验
     public Long check(BigDecimal number, BigDecimal unitPrice) {
         BigDecimal result1 = number.multiply(unitPrice);
@@ -1283,9 +1285,9 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
-     *   主表、库存明细表 更新 入账状态
+     * 主表、库存明细表 更新 入账状态
      */
-    public  void  updateWarehousebillsItemsStatus(TWarehouseBills warehouseBill){
+    public void updateWarehousebillsItemsStatus(TWarehouseBills warehouseBill) {
         // 查询所有库存明细 修改仓库主表状态
         int notInStorage = 0;
         int Stored = 0;
@@ -1293,7 +1295,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         tWarehousebillsitems.setfPid(warehouseBill.getfId());
         List<TWarehousebillsitems> warehousebillsitemsList1 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
         for (TWarehousebillsitems item : warehousebillsitemsList1) {
-             if (item.getfBillstatus().equals(40L) | item.getfBillstatus().equals(90L)) {
+            if (item.getfBillstatus().equals(40L) | item.getfBillstatus().equals(90L)) {
                 Stored++;
             } else {
                 notInStorage++;
@@ -1314,14 +1316,15 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
-     *  添加 库存明细状态
+     * 添加 库存明细状态
+     *
      * @param wbItem
      * @param status
      * @param loginUser
      */
-    public  void  insertTWarehousebillsLog(TWarehousebillsitems wbItem,Long status,LoginUser loginUser){
+    public void insertTWarehousebillsLog(TWarehousebillsitems wbItem, Long status, LoginUser loginUser) {
         // 添加状态log
-        TWarehousebillsLog tWarehousebillsLog =new TWarehousebillsLog();
+        TWarehousebillsLog tWarehousebillsLog = new TWarehousebillsLog();
         tWarehousebillsLog.setfPid(wbItem.getfPid());
         tWarehousebillsLog.setfItmeid(wbItem.getfId());
         tWarehousebillsLog.setfItmestatus(status);
@@ -1331,11 +1334,12 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
-     *   删除 库存明细
+     * 删除 库存明细
+     *
      * @param fid
      * @param tWarehousebillsitems
      */
-    public  void  deleteBillsitems(Long fid,String tWarehousebillsitems){
+    public void deleteBillsitems(Long fid, String tWarehousebillsitems) {
         List<Long> oldList = new ArrayList<Long>();
         List<Long> newList = new ArrayList<Long>();
 
@@ -1348,10 +1352,10 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         );
 
         // 获取提交从表数据ID
-        if (tWarehousebillsitems != null ) {
+        if (tWarehousebillsitems != null) {
             JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
             List<TWarehousebillsitems> warehousebillsitemsLists = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
-            warehousebillsitemsLists.forEach(wb->
+            warehousebillsitemsLists.forEach(wb ->
                     newList.add(wb.getfId())
             );
         }
@@ -1364,51 +1368,53 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
-     *   库容-结余毛重
+     * 库容-结余毛重
+     *
      * @param fTotalgross
      * @param fGrossweightblc
      * @return
      */
-    public static BigDecimal  calculation1(String  fTotalgross, String fGrossweightblc){
+    public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
         BigDecimal num1 = new BigDecimal(fTotalgross);
         BigDecimal num2 = new BigDecimal(fGrossweightblc);
         BigDecimal result = num1.subtract(num2);
-        return result.setScale(2,BigDecimal.ROUND_HALF_UP);
+        return result.setScale(2, BigDecimal.ROUND_HALF_UP);
     }
 
     /**
-     *   判断  是否允许 入库
+     * 判断  是否允许 入库
+     *
      * @param fId
      */
-    public  int  calculation (Long fId,BigDecimal fGrossweight){
+    public int calculation(Long fId, BigDecimal fGrossweight) {
         // 仓库库容
         TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(fId);
         // 总账使用
-        List<Map<String, Object>> whouseList= tWhgenlegMapper.selectWareHouseListWhouse(fId);
-        if(whouseList!=null && whouseList.size()>0){
-            String  fTotalgross = null;
+        List<Map<String, Object>> whouseList = tWhgenlegMapper.selectWareHouseListWhouse(fId);
+        if (whouseList != null && whouseList.size() > 0) {
+            String fTotalgross = null;
             String fGrossweightblc = null;
-            for (Map<String, Object> m : whouseList){
-                for (String k : m.keySet()){
+            for (Map<String, Object> m : whouseList) {
+                for (String k : m.keySet()) {
                     // 获取毛重库容
-                    if(k.equals("fTotalgross")){
-                        fTotalgross= m.get(k).toString();
+                    if (k.equals("fTotalgross")) {
+                        fTotalgross = m.get(k).toString();
                     }
-                    if(k.equals("fGrossweightD")){
-                        fGrossweightblc=  m.get(k).toString();
+                    if (k.equals("fGrossweightD")) {
+                        fGrossweightblc = m.get(k).toString();
                     }
                 }
             }
-            BigDecimal result = calculation1(fTotalgross,fGrossweightblc);
-            if(result.compareTo(fGrossweight) == -1){
+            BigDecimal result = calculation1(fTotalgross, fGrossweightblc);
+            if (result.compareTo(fGrossweight) == -1) {
                 return 0;// 结余库容小于入库数
-            }else{
+            } else {
                 return 1;
             }
-        }else{
-            if(tWarehouse.getfTotalgross().compareTo(fGrossweight) == -1){
+        } else {
+            if (tWarehouse.getfTotalgross().compareTo(fGrossweight) == -1) {
                 return 0;// 库容小于入库数
-            }else{
+            } else {
                 return 1;
             }
         }

+ 20 - 5
ruoyi-warehouse/src/main/resources/mapper/reportManagement/TWhgenlegMapper.xml

@@ -480,12 +480,27 @@
 
     <select id="selectStorageFeeItemList" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehouseBills"
             resultMap="TWhgenlegResult">
-        <include refid="selectTWhgenlegVo"/>
+        SELECT
+            wh.f_originalbillno AS fBillno,
+            wh.f_goodsid AS fGoodsid,
+            wh.f_originalbilldate AS fBsdate,
+            wh.f_billingway AS fBillingway,
+            wh.f_chargedate AS fChargedate,
+            wh.f_originalbilldate AS fOriginalbilldate,
+            wh.f_volumnblc AS fVolumn,
+            wh.f_qtyblc AS fQty,
+            wh.f_grossweightblc AS fGrossweight,
+            wh.f_netweightblc AS fNetweight,
+            "KCZZ" AS fBilltype,
+            goods.f_typeid AS fTypeid
+        FROM
+            t_whgenleg wh
+            LEFT JOIN t_goods goods ON goods.f_id = wh.f_goodsid
         <where>
-            f_corpid = #{warehouse.fCorpid}
-            and f_chargedate &lt; #{warehouse.fBillingDeadline}
-            <if test="warehouse.fGoodsid != null">and f_goodsid = #{warehouse.fGoodsid}</if>
-            <if test="warehouse.fMblno != null">and f_mblno = #{warehouse.fMblno}</if>
+            wh.f_corpid = #{warehouse.fCorpid}
+            and wh.f_chargedate &lt;= #{warehouse.fBillingDeadline}
+            <if test="warehouse.fGoodsid != null">and wh.f_goodsid = #{warehouse.fGoodsid}</if>
+            <if test="warehouse.fMblno != null">and wh.f_mblno = #{warehouse.fMblno}</if>
         </where>
     </select>
 

+ 2 - 2
ruoyi-warehouse/src/main/resources/mapper/warehouseBusiness/TWarehousebillsfeesMapper.xml

@@ -115,7 +115,7 @@
             <if test="fLineno != null">#{fLineno},</if>
             <if test="fCorpid != null">#{fCorpid},</if>
             <if test="fFeeid != null">#{fFeeid},</if>
-            <if test="fFeeunitid != null">#{fFeeunitid},</if>
+            <if test="fFeeUnitid != null">#{fFeeUnitid},</if>
             <if test="fQty != null">#{fQty},</if>
             <if test="fUnitprice != null">#{fUnitprice},</if>
             <if test="fAmount != null">#{fAmount},</if>
@@ -150,7 +150,7 @@
             <if test="fLineno != null">f_lineno = #{fLineno},</if>
             <if test="fCorpid != null">f_corpid = #{fCorpid},</if>
             <if test="fFeeid != null">f_feeid = #{fFeeid},</if>
-            <if test="fFeeunitid != null">f_feeUnitid = #{fFeeunitid},</if>
+            <if test="fFeeUnitid != null">f_feeUnitid = #{fFeeUnitid},</if>
             <if test="fQty != null">f_qty = #{fQty},</if>
             <if test="fUnitprice != null">f_unitprice = #{fUnitprice},</if>
             <if test="fAmount != null">f_amount = #{fAmount},</if>

+ 17 - 5
ruoyi-warehouse/src/main/resources/mapper/warehouseBusiness/TWarehousebillsitemsMapper.xml

@@ -316,21 +316,33 @@
     </delete>
 
     <delete id="deleteByFPid" parameterType="Long">
-        delete from t_warehousebillsitems where f_id = #{fId}
+        delete from t_warehousebillsitems where f_pid = #{fId}
     </delete>
 
     <select id="selectStorageFeeItemList" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehouseBills"
-            resultMap="TWarehousebillsitemsResult">
+            resultType="Map">
         SELECT
-            item.*
+            item.f_billno AS fBillno,
+            item.f_goodsid AS fGoodsid,
+            item.f_bsdate AS fBsdate,
+            item.f_billingway AS fBillingway,
+            item.f_chargedate AS fChargedate,
+            item.f_originalbilldate AS fOriginalbilldate,
+            item.f_volumn AS fVolumn,
+            item.f_qty AS fQty,
+            item.f_grossweight AS fGrossweight,
+            item.f_netweight AS fNetweight,
+            item.f_billtype AS fBilltype,
+            goods.f_typeid AS fTypeid
         FROM
             t_warehousebills ware
             LEFT JOIN t_warehousebillsitems item ON item.f_pid = ware.f_id
+            LEFT JOIN t_goods goods ON goods.f_id = item.f_goodsid
         <where>
             ware.f_corpid = #{warehouse.fCorpid}
             and ware.f_billtype in ("HQZY", "SJCK")
-            and item.f_billstatus = "40"
-            and item.f_chargedate &lt; #{warehouse.fBillingDeadline}
+            and item.f_billstatus = 40
+            and item.f_chargedate &lt;= #{warehouse.fBillingDeadline}
             <if test="warehouse.fGoodsid != null">and item.f_goodsid = #{warehouse.fGoodsid}</if>
             <if test="warehouse.fMblno != null">and ware.f_mblno = #{warehouse.fMblno}</if>
         </where>