|  | @@ -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"));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 |