Forráskód Böngészése

仓储费计算方法

shanxin 4 éve
szülő
commit
f7ddc76d55

+ 2 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/mapper/TWarehouseAgreementMapper.java

@@ -67,4 +67,6 @@ public interface TWarehouseAgreementMapper {
      * @return 结果
      */
     public int deleteTWarehouseAgreementByIds(Long[] fIds);
+
+    List<TWarehouseAgreement> selectTWarehouseAgreementListOrderyByBeginDate(TWarehouseAgreement tWarehouseAgreement);
 }

+ 11 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/mapper/TWarehouseAgreementitemsMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.warehouseBusiness.mapper;
 
 
 import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -61,4 +62,14 @@ public interface TWarehouseAgreementitemsMapper {
     public int deleteTWarehouseAgreementitemsByIds(Long[] fIds);
 
     int deleteByFPid(Long fId);
+
+    /**
+     *
+     * @param fCorpid 出库客户Id
+     * @param fGoodsid 物资类型Id
+     * @return
+     */
+    List<TWarehouseAgreementitems> getItemsBytWarehouseAgreementMsg(@Param("fCorpid") Long fCorpid,
+                                                                    @Param("fGoodsid") Long fGoodsid,
+                                                                    @Param("feeUnitid") Long feeUnitid);
 }

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

@@ -1,6 +1,7 @@
 package com.ruoyi.warehouseBusiness.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -18,6 +19,7 @@ import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -160,4 +162,90 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
     public int deleteTWarehouseAgreementById(Long fId) {
         return tWarehouseAgreementMapper.deleteTWarehouseAgreementById(fId);
     }
+
+
+    /**
+     * 计算存储费用
+     * @author shanxin
+     * @param fCorpid   出库客户Id
+     * @param fGoodsid  物资类型Id
+     * @param days 时长天数
+     * @param feeUnitid 计价单位
+     * @param itemNums 数量
+     * @return
+     */
+    public BigDecimal getCarryingCost(Long fCorpid,
+                                      Long fGoodsid,
+                                      Long days,
+                                      Long feeUnitid,
+                                      Long itemNums) {
+
+        if (null == fCorpid ||
+                null == fGoodsid ||
+                null == days ||
+                null == feeUnitid ||
+                null == itemNums) {
+            return null;
+        }
+        List<TWarehouseAgreementitems> itemList =
+                this.tWarehouseAgreementitemsMapper.getItemsBytWarehouseAgreementMsg(fCorpid,fGoodsid,feeUnitid);
+
+        if (CollUtil.isEmpty(itemList)) {
+            return null;
+        }
+        BigDecimal money = new BigDecimal(0);
+        Long dayLength = 0L;
+        for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
+            if (days < 1) break;
+            dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L;
+            if (days >= dayLength) {
+                money = money.add(this.getCalculate(itemNums,tWarehouseAgreementitems.getfPrice(),dayLength));
+                days -=  dayLength;
+            } else {
+                money = money.add(this.getCalculate(itemNums,feeUnitid,days));
+            }
+        }
+        return money;
+    }
+
+
+    /**
+     * 数量 * 单价 * 天数
+     * @param itemNums 数量
+     * @param unitPrice 单价
+     * @param dateLength  天数
+     * @return
+     */
+    public BigDecimal getCalculate (Long itemNums,Long unitPrice,Long dateLength) {
+        BigDecimal money = new BigDecimal(0);
+        BigDecimal itemNumsBig = new BigDecimal(itemNums);
+        BigDecimal unitPriceBig = new BigDecimal(unitPrice);
+        BigDecimal bigDaysBig = new BigDecimal(dateLength);
+        money = itemNumsBig.multiply(unitPriceBig).multiply(bigDaysBig);
+        return money;
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 }

+ 36 - 0
ruoyi-warehouse/src/main/resources/mapper/warehouseBusiness/TWarehouseAgreementitemsMapper.xml

@@ -46,6 +46,42 @@
         where f_id = #{fId}
     </select>
 
+
+    <!-- 联查计费规则信息 -->
+    <select id="getItemsBytWarehouseAgreementMsg"
+            resultType="com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems"
+            parameterType="object">
+        SELECT
+            items.f_id,
+            items.f_pid,
+            items.f_lineno,
+            items.f_feeid,
+            items.f_feeUnitid,
+            items.f_fromdays,
+            items.f_endays,
+            items.f_price,
+            items.f_status,
+            items.del_flag,
+            items.create_by,
+            items.create_time,
+            items.update_by,
+            items.update_time,
+            items.remark
+        FROM
+            t_warehouse_agreement AS agreement
+            LEFT JOIN t_warehouse_agreementitems AS items ON agreement.f_id = items.f_pid
+        WHERE
+            agreement.f_corpid = #{fCorpid}
+            AND agreement.f_goodsid = #{fGoodsid}
+            AND items.f_feeUnitid = #{feeUnitid}
+            AND agreement.f_billstatus = 'T'
+            AND agreement.del_flag = '0'
+            AND items.del_flag = '0'
+            AND items.f_status = 'T'
+        ORDER BY
+            items.f_fromdays
+    </select>
+
     <insert id="insertTWarehouseAgreementitems" parameterType="TWarehouseAgreementitems" useGeneratedKeys="true"
             keyProperty="fId">
         insert into t_warehouse_agreementitems