Browse Source

出入库、库存统计接口

Sun 3 years ago
parent
commit
7894f5e471

+ 15 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/reportManagement/TWarehousebillsitemsSummaryController.java

@@ -21,6 +21,7 @@ import java.util.Map;
 /**
  * 出入库汇总Controller
  * 总账统计
+ *
  * @author ruoyi
  * @date 2020-12-23
  */
@@ -53,6 +54,20 @@ public class TWarehousebillsitemsSummaryController extends BaseController {
         return util.statisticsExportExcel(list, "总账统计");
     }
 
+    /**
+     * 出入库、库存统计
+     */
+    @GetMapping("/stockStatistics")
+    public AjaxResult stockStatistics() {
+        return itWarehouseBillsService.stockStatistics();
+    }
 
+    /**
+     * 周期库存统计
+     */
+    @GetMapping("/cycleStockStatistics")
+    public AjaxResult cycleStockStatistics() {
+        return itWarehouseBillsService.cycleStockStatistics();
+    }
 
 }

+ 57 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -388,4 +388,61 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         return parseDateToStr(MM, date);
     }
 
+    public static String today() {
+        return dateTimeNow(YYYY_MM_DD);
+    }
+
+    public static String yesterday() {
+        return offsetDate(-1);
+    }
+
+    public static String beginOfWeek() {
+        Calendar cale = Calendar.getInstance();
+        cale.add(Calendar.WEEK_OF_MONTH, 0);
+        cale.set(Calendar.DAY_OF_WEEK, 2);
+        return dateTime(cale.getTime());
+    }
+
+    public static String endOfWeek() {
+        Calendar cale = Calendar.getInstance();
+        cale.set(Calendar.DAY_OF_WEEK, cale.getActualMaximum(Calendar.DAY_OF_WEEK));
+        cale.add(Calendar.DAY_OF_WEEK, 1);
+        return dateTime(cale.getTime());
+    }
+
+    public static String beginOfMonth() {
+        Calendar cale = Calendar.getInstance();
+        cale.add(Calendar.MONTH, 0);
+        cale.set(Calendar.DAY_OF_MONTH, 1);
+        return dateTime(cale.getTime());
+    }
+
+    public static String endOfMonth() {
+        Calendar cale = Calendar.getInstance();
+        cale.add(Calendar.MONTH, 1);
+        cale.set(Calendar.DAY_OF_MONTH, 0);
+        return dateTime(cale.getTime());
+    }
+
+    public static String beginOfLastMonth() {
+        Calendar cale = Calendar.getInstance();
+        cale.add(Calendar.MONTH, -1);
+        cale.set(Calendar.DAY_OF_MONTH, 1);
+        return dateTime(cale.getTime());
+    }
+
+    public static String endOfLastMonth() {
+        Calendar cale = Calendar.getInstance();
+        cale.add(Calendar.MONTH, 0);
+        cale.set(Calendar.DAY_OF_MONTH, 0);
+        return dateTime(cale.getTime());
+    }
+
+    public static String offsetDate(int num) {
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(new Date());
+        calendar.add(Calendar.DATE, num);
+        return dateTime(calendar.getTime());
+    }
+
 }

+ 8 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TCustomerContactMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.basicData.domain.TCustomerContact;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -69,4 +70,11 @@ public interface TCustomerContactMapper extends BaseMapper<TCustomerContact> {
      * @return
      */
     public int checkTelUnique(String ftel);
+
+    /**
+     *  查询客户名
+     * @param ftel
+     * @return
+     */
+    public Map<String, Object> getCustomerName(String ftel);
 }

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

@@ -157,4 +157,20 @@ public interface TWhgenlegMapper {
      * @return
      */
     List<WhgenlegVO> selectOtherDetailsList(TWhgenleg tWhgenleg);
+
+    /**
+     * 库存统计
+     * @param beginDate 起始时间
+     * @param endDate 截止时间
+     * @param external 外部用户
+     * @return
+     */
+    public Map<String, Object> stockStatistics(@Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("external") String external);
+
+    /**
+     * 库龄
+     * @param external 外部用户
+     * @return
+     */
+    public Map<String, Object> stockDays(@Param("external") String external);
 }

+ 12 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/mapper/TWarehousebillsfeesMapper.java

@@ -157,4 +157,16 @@ public interface TWarehousebillsfeesMapper extends BaseMapper<TWarehousebillsfee
      */
     public List<Map<String,Object>> selectQueryMenuList(TWarehousebillsfees tWarehousebillsfees);
 
+    /**
+     * 出入库统计
+     * @param beginDate 起始时间
+     * @param endDate 截止时间
+     * @param billType 单据类型
+     * @param external 外部用户
+     * @return
+     */
+    public Map<String, Object> inAndOutStockStatistics(@Param("billType") String billType,
+                                                       @Param("beginDate") String beginDate,
+                                                       @Param("endDate") String endDate,
+                                                       @Param("external") String external);
 }

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

@@ -756,4 +756,19 @@ public interface ITWarehouseBillsService {
      * @return
      */
     AjaxResult quickStaging(WarehousebillsDTO warehousebillsDTO, LoginUser loginUser);
+
+    /**
+     * 出入库、库存统计
+     *
+     * @return
+     */
+    AjaxResult stockStatistics();
+
+    /**
+     * 周期库存统计
+     *
+     * @return
+     */
+    AjaxResult cycleStockStatistics();
+
 }

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

@@ -1,6 +1,5 @@
 package com.ruoyi.warehouseBusiness.service.impl;
 
-
 import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -110,6 +109,12 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     private TCorpsMapper tCorpsMapper;
 
     @Autowired
+    private TCustomerContactMapper tCustomerContactMapper;
+
+    @Autowired
+    private SysConfigMapper configMapper;
+
+    @Autowired
     private TVoyageMapper tVoyageMapper;
 
     @Autowired
@@ -7653,5 +7658,99 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         return AjaxResult.success();
     }
 
+    /**
+     * 出入库、库存统计
+     *
+     * @return
+     */
+    @Override
+    public AjaxResult stockStatistics() {
+        String external = null;
+        String customerName;
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        if ("外部用户".equals(user.getDept().getDeptName())) {
+            external = user.getUserName();
+            customerName = String.valueOf(tCustomerContactMapper.getCustomerName(external).get("customerName"));
+        } else {
+            SysConfig config = new SysConfig();
+            config.setConfigKey("data_print_title");
+            customerName = configMapper.selectConfig(config).getConfigValue();
+        }
+
+        Map<String, String> data = new HashMap<>();
+        // 客户名称
+        data.put("customerName", customerName);
+        // 全部库存
+        data.put("stockTotal", stockStatistics(null, null, external));
+
+        // 今天
+        data.put("inStockTotalToday", inAndOutStockStatistics("SJRK", DateUtils.today(), DateUtils.today(), external));
+        data.put("outStockTotalToday", inAndOutStockStatistics("SJCK", DateUtils.today(), DateUtils.today(), external));
+        // 昨天
+        data.put("inStockTotalYesterday", inAndOutStockStatistics("SJRK", DateUtils.yesterday(), DateUtils.yesterday(), external));
+        data.put("outStockTotalYesterday", inAndOutStockStatistics("SJCK", DateUtils.yesterday(), DateUtils.yesterday(), external));
+        // 本周
+        data.put("inStockTotalWeek", inAndOutStockStatistics("SJRK", DateUtils.beginOfWeek(), DateUtils.endOfWeek(), external));
+        data.put("outStockTotalWeek", inAndOutStockStatistics("SJCK", DateUtils.beginOfWeek(), DateUtils.endOfWeek(), external));
+        // 本月
+        data.put("inStockTotalMonth", inAndOutStockStatistics("SJRK", DateUtils.beginOfMonth(), DateUtils.endOfMonth(), external));
+        data.put("outStockTotalMonth", inAndOutStockStatistics("SJCK", DateUtils.beginOfMonth(), DateUtils.endOfMonth(), external));
+        // 上个月
+        data.put("inStockTotalLastMonth", inAndOutStockStatistics("SJRK", DateUtils.beginOfLastMonth(), DateUtils.endOfLastMonth(), external));
+        data.put("outStockTotalLastMonth", inAndOutStockStatistics("SJCK", DateUtils.beginOfLastMonth(), DateUtils.endOfLastMonth(), external));
+
+        // 库龄
+        data.put("stockDays", String.valueOf(tWhgenlegMapper.stockDays(external).get("days")));
+        return AjaxResult.success(data);
+    }
+
+    /**
+     * 周期库存统计
+     *
+     * @return
+     */
+    @Override
+    public AjaxResult cycleStockStatistics() {
+        String external = null;
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        if ("外部用户".equals(user.getDept().getDeptName())) {
+            external = user.getUserName();
+        }
+
+        Map<String, String> data = new HashMap<>();
+        // 7天
+        data.put("stockTotalA", stockStatistics(DateUtils.offsetDate(-6), null, external));
+        // 15天
+        data.put("stockTotalB", stockStatistics(DateUtils.offsetDate(-14), DateUtils.offsetDate(-6), external));
+        // 30天
+        data.put("stockTotalC", stockStatistics(DateUtils.offsetDate(-29), DateUtils.offsetDate(-14), external));
+        // 60天
+        data.put("stockTotalD", stockStatistics(DateUtils.offsetDate(-59), DateUtils.offsetDate(-29), external));
+        // 90天
+        data.put("stockTotalE", stockStatistics(DateUtils.offsetDate(-89), DateUtils.offsetDate(-59), external));
+        // 180天
+        data.put("stockTotalF", stockStatistics(DateUtils.offsetDate(-179), DateUtils.offsetDate(-89), external));
+        // 180天+
+        data.put("stockTotalG", stockStatistics(null, DateUtils.offsetDate(-179), external));
+        return AjaxResult.success(data);
+    }
+
+    private String inAndOutStockStatistics(String billType, String beginDate, String endDate, String external) {
+        beginDate += " 00:00:00";
+        endDate += " 23:59:59";
+        Map<String, Object> statistics = tWarehousebillsfeesMapper.inAndOutStockStatistics(billType, beginDate, endDate, external);
+        return String.valueOf(statistics.get("total"));
+    }
+
+    private String stockStatistics(String beginDate, String endDate, String external) {
+        if (StringUtils.isNotEmpty(beginDate)) {
+            beginDate += " 00:00:00";
+        }
+        if (StringUtils.isNotEmpty(endDate)) {
+            endDate += " 00:00:00";
+        }
+        Map<String, Object> statistics = tWhgenlegMapper.stockStatistics(beginDate, endDate, external);
+        return String.valueOf(statistics.get("total"));
+    }
 
 }

+ 7 - 1
ruoyi-warehouse/src/main/resources/mapper/basicData/TCustomerContactMapper.xml

@@ -135,4 +135,10 @@
         delete from t_customer_contact where f_pid = #{fPid}
     </delete>
 
-</mapper>
+    <select id="getCustomerName" resultType="map">
+        select tc.f_name as customerName
+        from t_customer_contact tcc left join t_corps tc on tcc.f_pid = tc.f_id
+        where tcc.f_tel = #{ftel};
+    </select>
+
+</mapper>

+ 26 - 0
ruoyi-warehouse/src/main/resources/mapper/reportManagement/TWhgenlegMapper.xml

@@ -1060,4 +1060,30 @@
         GROUP BY t.f_id
     </select>
 
+    <select id="stockStatistics" resultType="map">
+        select
+            round(ifnull(sum(f_grossweightblc) / 1000, 0)) as total
+        from
+            t_whgenleg
+        <where>
+            <if test="beginDate != null and beginDate != ''">and f_bsdate &gt;= #{beginDate}</if>
+            <if test="endDate != null and endDate != ''">and f_bsdate &lt; #{endDate}</if>
+            <if test="external != null and external != ''">
+                and f_corpid = (select f_corpid from t_customer_contact where f_tel = #{external})
+            </if>
+        </where>
+    </select>
+
+    <select id="stockDays" resultType="map">
+        select
+            datediff(date_format(now(),'%Y-%m-%d'),date_format(min(f_bsdate),'%Y-%m-%d')) as days
+        from
+            t_whgenleg
+        where
+            f_grossweightblc > 0
+            <if test="external != null and external != ''">
+                and f_corpid = (select f_corpid from t_customer_contact where f_tel = #{external})
+            </if>
+    </select>
+
 </mapper>

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

@@ -904,4 +904,22 @@
         </where>
         ORDER BY tf.f_bsdate desc
     </select>
+
+    <select id="inAndOutStockStatistics" resultType="map">
+        select
+            round(ifnull(sum(ts.f_grossweight) / 1000, 0)) as total
+        from t_warehousebillsitems ts
+        left join t_warehousebills tb on ts.f_mblno = tb.f_mblno and ts.f_billno = tb.f_billno
+        where
+            ts.f_billstatus = '40'
+            <if test="billType != null and billType != ''">and tb.f_billtype = #{billType}</if>
+            <if test="beginDate != null and beginDate != ''">and ts.f_bsdate &gt;= #{beginDate}</if>
+            <if test="endDate != null and endDate != ''">and ts.f_bsdate &lt;= #{endDate}</if>
+            <if test="external != null and external != ''">
+                and tb.f_warehouseid in (
+                    select distinct f_warehouseid
+                    from t_customer_contact t1 left join t_whgenleg t2 on t1.f_pid = t2.f_corpid
+                    where f_tel = #{external})
+            </if>
+    </select>
 </mapper>