Selaa lähdekoodia

2024-08-29 缓存今日入库 今日出库

luguang 2 kuukautta sitten
vanhempi
commit
090f899eef

+ 64 - 16
src/main/java/com/sy/coinage/workshop/component/ScreenComponent.java

@@ -63,33 +63,35 @@ public class ScreenComponent {
      * 币种库存占比与出入库完成率
      */
     public void loadInventoryInfo() {
-        Dept d = deptService.getByName("造币二部");
+        Dept dept = deptService.getByName("造币二部");
         this.cacheProportionInfo();
-        this.cacheSecuritiesInfo(d);
+        this.cacheSecuritiesInfo(dept);
     }
 
     /**
      * 总库与品名 库存 出入库
      */
     public void loadWareInfo() {
-        this.cacheWareList();
-        this.cacheDayList();
+        Date date = new Date();
+        Dept dept = deptService.getByName("造币二部");
+        this.cacheWareList(date, dept);
+        this.cacheDayList(date, dept);
     }
 
     public void loadDept() {
-        Dept d = deptService.getByName("造币二部");
-        this.cacheDeptYield(d);
+        Dept dept = deptService.getByName("造币二部");
+        this.cacheDeptYield(dept);
     }
 
     /**
      * 缓存大屏昨日产能
      */
-    public void cacheDeptYield(Dept d) {
+    public void cacheDeptYield(Dept dept) {
         Integer data = 0;
         Date start = DateUtils.getBeginDayOfYesterday();
         Date end = DateUtils.getEndDayOfYesterDay();
         LambdaQueryWrapper<WorkshopAccount> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(WorkshopAccount::getDept, d.getName());
+        queryWrapper.eq(WorkshopAccount::getDept, dept.getName());
         queryWrapper.eq(WorkshopAccount::getRedFlashFlag, 1);
         queryWrapper.between(WorkshopAccount::getCreateTime, start, end);
         queryWrapper.eq(WorkshopAccount::getLocFrom, 2);
@@ -105,7 +107,11 @@ public class ScreenComponent {
         this.redisService.set(CacheKey.DEPT_YIELD + "造币二部", String.valueOf(data), CacheKey.EXPIRED_ONE_DAY);
     }
 
-    private void cacheWareList() {
+    private void cacheWareList(Date date, Dept dept) {
+        // 取实物收发卡收入
+        List<WorkshopAccount> accountListIn = this.workshopAccountList(1, date, dept);
+        // 取实物收发卡付出
+        List<WorkshopAccount> accountListOut = this.workshopAccountList(2, date, dept);
         List<Stock> stockList = this.getStockList(2);
         List<ScreenWareVO> list = new ArrayList<>();
         if (stockList != null && stockList.size() > 0) {
@@ -113,27 +119,47 @@ public class ScreenComponent {
                 ScreenWareVO vo = new ScreenWareVO();
                 vo.setWareCn(stock.getWareCn());
                 vo.setSecurities(stock.getSecurities());
+                vo.setDayInQty(0);
+                vo.setDayOutQty(0);
                 Product p = this.productService.getByCache(stock.getSecuritiesId());
                 vo.setQty((stock.getBoxNum() == null ? 0 : stock.getBoxNum()) + (stock.getRacketNum() == null ? 0 : stock.getRacketNum()) * p.getBoxAmount());
-                vo.setDayInQty(RandomUtil.randomMax(4000));
-                vo.setDayOutQty(RandomUtil.randomMax(4000));
+                if (accountListIn != null && accountListIn.size() > 0) {
+                    Integer totalQty = accountListIn.stream().filter(item -> item.getWareId().intValue() == stock.getWareId().intValue() && item.getSecuritiesId().intValue() == stock.getSecuritiesId().intValue()).collect(Collectors.toList()).stream().mapToInt(item -> item.getIncomeQty()).sum();
+                    vo.setDayInQty(totalQty);
+                }
+                if (accountListOut != null && accountListOut.size() > 0) {
+                    Integer totalQty = accountListOut.stream().filter(item -> item.getWareId().intValue() == stock.getWareId().intValue() && item.getSecuritiesId().intValue() == stock.getSecuritiesId().intValue()).collect(Collectors.toList()).stream().mapToInt(item -> item.getPayQty()).sum();
+                    vo.setDayOutQty(totalQty);
+                }
                 list.add(vo);
             }
         }
         this.redisService.set("screen_ware", JSON.toJSONString(list));
     }
 
-    private void cacheDayList() {
+    private void cacheDayList(Date date, Dept dept) {
+        // 取实物收发卡收入
+        List<WorkshopAccount> accountListIn = this.workshopAccountList(1, date, dept);
+        // 取实物收发卡付出
+        List<WorkshopAccount> accountListOut = this.workshopAccountList(2, date, dept);
         List<Stock> stockList = this.getStockList(1);
         List<ScreenWareVO> list = new ArrayList<>();
         if (stockList != null && stockList.size() > 0) {
             for (Stock stock : stockList) {
                 ScreenWareVO vo = new ScreenWareVO();
                 vo.setSecurities(stock.getSecurities());
+                vo.setDayInQty(0);
+                vo.setDayOutQty(0);
                 Product p = this.productService.getByCache(stock.getSecuritiesId());
                 vo.setQty((stock.getBoxNum() == null ? 0 : stock.getBoxNum()) + (stock.getRacketNum() == null ? 0 : stock.getRacketNum()) * p.getBoxAmount());
-                vo.setDayInQty(RandomUtil.randomMax(4000));
-                vo.setDayOutQty(RandomUtil.randomMax(4000));
+                if (accountListIn != null && accountListIn.size() > 0) {
+                    Integer totalQty = accountListIn.stream().filter(item -> item.getSecuritiesId().intValue() == stock.getSecuritiesId().intValue()).collect(Collectors.toList()).stream().mapToInt(item -> item.getIncomeQty()).sum();
+                    vo.setDayInQty(totalQty);
+                }
+                if (accountListOut != null && accountListOut.size() > 0) {
+                    Integer totalQty = accountListOut.stream().filter(item -> item.getSecuritiesId().intValue() == stock.getSecuritiesId().intValue()).collect(Collectors.toList()).stream().mapToInt(item -> item.getPayQty()).sum();
+                    vo.setDayOutQty(totalQty);
+                }
                 list.add(vo);
             }
         }
@@ -187,7 +213,7 @@ public class ScreenComponent {
         this.redisService.set("screen_proportion", JSON.toJSONString(info));
     }
 
-    private void cacheSecuritiesInfo(Dept d) {
+    private void cacheSecuritiesInfo(Dept dept) {
         List<ProductPlan> list = this.productPlanService.cacheList();
         ScreenDeptVO data = new ScreenDeptVO();
         if (list != null && list.size() > 0) {
@@ -198,7 +224,7 @@ public class ScreenComponent {
             // 获取所有解缴单
             for (ProductPlan productPlan : list) {
                 Integer totalBox = this.getTotalBox(productPlan.getCrownFrom(), productPlan.getCrownTo());
-                List<WorkshopOutbound> out = this.outList(productPlan.getProductId(), productPlan.getCreateTime(), d.getId());
+                List<WorkshopOutbound> out = this.outList(productPlan.getProductId(), productPlan.getCreateTime(), dept.getId());
                 if (out != null && out.size() > 0 && totalBox > 0) {
                     // 取合计箱数
                     Integer total = out.stream().mapToInt(s -> s.getTotalBoxAmount()).sum();
@@ -278,8 +304,30 @@ public class ScreenComponent {
         // 状态:1.新建 2.已出库 3.已入库
         queryWrapper.eq(WorkshopOutbound::getStatus, 3);
         queryWrapper.gt(WorkshopOutbound::getCreateTime, createTime);
+
         return this.workshopOutboundService.list(queryWrapper);
     }
 
+    /**
+     * @param type 1入库 2发货
+     * @param date
+     * @param dept
+     * @return
+     */
+    public List<WorkshopAccount> workshopAccountList(int type, Date date, Dept dept) {
+        LambdaQueryWrapper<WorkshopAccount> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(WorkshopAccount::getDept, dept.getName());
+        queryWrapper.eq(WorkshopAccount::getRedFlashFlag, 1);
+        if (type == 1) {
+            queryWrapper.eq(WorkshopAccount::getLocTo, 1);
+        } else {
+            queryWrapper.eq(WorkshopAccount::getLocFrom, 1);
+        }
+        // 实物收发卡
+        queryWrapper.eq(WorkshopAccount::getStatType, 2);
+        queryWrapper.between(WorkshopAccount::getCreateTime, DateUtils.getDayStartTime(date), DateUtils.getDayEndTime(date));
+        List<WorkshopAccount> list = this.workshopAccountService.list(queryWrapper);
+        return list;
+    }
 
 }