TvCSService.java 25.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
package com.huaheng.api.tv.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.tv.domain.*;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.redis.RedisUtils;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.AjaxResultTv;
import com.huaheng.framework.web.service.DictService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransactionReport;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class TvCSService {

    @Autowired
    protected RedisTemplate<String, Object> redisTemplate;

    private static final Logger logger = LoggerFactory.getLogger(TvCSService.class);


    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ReceiptDetailService receiptDetailService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private InventoryTransactionService inventoryTransactionService;

    @Resource
    private LocationService locationService;
    @Resource
    ExcelReportMapper mapper;


    public AjaxResult csTopParam(String warehouseCode){
        HashMap<String, Object> resultMap = new HashMap<>();
        //库存预警数
//        LambdaQueryWrapper<InventoryDetail> wrapper=new LambdaQueryWrapper<>();
//        wrapper.eq(InventoryDetail::getWarehouseCode,warehouseCode);
//        wrapper.groupBy(InventoryDetail::getMaterialCode);
        List<Map<String, Object>> list=inventoryDetailService.csMaterialWarningMax(warehouseCode);
        //库存预警-最大
        resultMap.put("warningMax",list.size());
        List<Map<String, Object>> list1=inventoryDetailService.csMaterialWarningMin(warehouseCode);
        //库存预警-最小
        resultMap.put("warningMin",list1.size());

        //近7天任务数
        String endTime= DateUtils.getNowPreDays("yyyy-MM-dd", 7);
        LambdaQueryWrapper<TaskHeader> taskWrapper=new LambdaQueryWrapper<>();
        taskWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        taskWrapper.in(TaskHeader::getInternalTaskType,QuantityConstant.TASK_INTENERTYPE_RECEIPT,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        taskWrapper.ge(TaskHeader::getCreated,endTime);
        int taskCount=taskHeaderService.count(taskWrapper);
        resultMap.put("taskWeek",taskCount);
        return AjaxResult.success(resultMap);
    }

    /**
     * 近一周单据数量
     * 当天入库量 当天未入量 当月入库量 当月未入量
     * @param warehouseCode
     * @return
     */
    public AjaxResult csReceipt(String warehouseCode){
//        ArrayList<Object> result = new ArrayList<>();
        HashMap<String, Object> resultMap2 = new HashMap<>();
        String endTime1= DateUtils.getNowPreDays("yyyy-MM-dd", 6);
        String endTime= DateUtils.getNowPreDays("yyyy-MM-dd", 0);
        // 获取当月第一天
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfMonth = today.withDayOfMonth(1);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = firstDayOfMonth.format(formatter);

        LambdaQueryWrapper<ReceiptHeader> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(ReceiptHeader::getWarehouseCode,warehouseCode);
        wrapper.ge(ReceiptHeader::getCreated,endTime);
        wrapper.eq(ReceiptHeader::getLastStatus,QuantityConstant.RECEIPT_HEADER_POSTING);
        int dayHaveComplete=receiptHeaderService.count(wrapper);
        LambdaQueryWrapper<ReceiptHeader> wrapper2=new LambdaQueryWrapper<>();
        wrapper2.eq(ReceiptHeader::getWarehouseCode,warehouseCode);
        wrapper2.ge(ReceiptHeader::getCreated,endTime);
        wrapper2.lt(ReceiptHeader::getLastStatus,QuantityConstant.RECEIPT_HEADER_POSTING);
        int dayNoComplete=receiptHeaderService.count(wrapper2);

        LambdaQueryWrapper<ReceiptHeader> wrapper3=new LambdaQueryWrapper<>();
        wrapper3.eq(ReceiptHeader::getWarehouseCode,warehouseCode);
        wrapper3.ge(ReceiptHeader::getCreated,formattedDate);
        wrapper3.lt(ReceiptHeader::getLastStatus,QuantityConstant.RECEIPT_HEADER_POSTING);
        int monthHaveComplete=receiptHeaderService.count(wrapper3);
        LambdaQueryWrapper<ReceiptHeader> wrapper4=new LambdaQueryWrapper<>();
        wrapper4.eq(ReceiptHeader::getWarehouseCode,warehouseCode);
        wrapper4.ge(ReceiptHeader::getCreated,formattedDate);
        wrapper4.lt(ReceiptHeader::getLastStatus,QuantityConstant.RECEIPT_HEADER_POSTING);
        int monthNoComplete=receiptHeaderService.count(wrapper4);

        List<Map<String, Object>> receiptHeaderList=receiptHeaderService.csReceipt(endTime1,warehouseCode);

        List<LocalDate> datelist=DateUtils.getDayList(endTime1,endTime);
        //查找receiptHeaderList中每天receiptType数量最多的前3种,并计算数量
        List<Map<String, Object>> list=new ArrayList<>();
        for (int a=0;a<datelist.size();a++){
            String days=datelist.get(a).toString();
            List<Map<String, Object>> shipmentList1 = receiptHeaderList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
            if(shipmentList1==null||shipmentList1.size()==0){
                shipmentList1=new ArrayList<>();
            }
            if(shipmentList1.size()>3){
                shipmentList1=shipmentList1.subList(0,3);
            }
            list.addAll(shipmentList1);
        }
//        result.add(resultMap);
        resultMap2.put("dayHaveComplete",dayHaveComplete);
        resultMap2.put("dayNoComplete",dayNoComplete);
        resultMap2.put("monthHaveComplete",monthHaveComplete);
        resultMap2.put("monthNoComplete",monthNoComplete);
        resultMap2.put("weekdaysList",list);
        return AjaxResult.success(resultMap2);
    }
    /**
     * 近一周单据数量
     * 当天出库量 当天未出量 当月出库量 当月未出量
     * @param warehouseCode
     * @return
     */
    public AjaxResult csShipment(String warehouseCode){
        ArrayList<Object> result = new ArrayList<>();
//        HashMap<String, Object> resultMap = new HashMap<>();
        HashMap<String, Object> resultMap2 = new HashMap<>();
        String endTime1= DateUtils.getNowPreDays("yyyy-MM-dd", 6);
        String endTime= DateUtils.getNowPreDays("yyyy-MM-dd", 0);
        // 获取当月第一天
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfMonth = today.withDayOfMonth(1);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = firstDayOfMonth.format(formatter);

        LambdaQueryWrapper<ShipmentHeader> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(ShipmentHeader::getWarehouseCode,warehouseCode);
        wrapper.ge(ShipmentHeader::getCreated,endTime);
        wrapper.eq(ShipmentHeader::getLastStatus,QuantityConstant.SHIPMENT_HEADER_COMPLETED);
        int dayHaveComplete=shipmentHeaderService.count(wrapper);
        LambdaQueryWrapper<ShipmentHeader> wrapper2=new LambdaQueryWrapper<>();
        wrapper2.eq(ShipmentHeader::getWarehouseCode,warehouseCode);
        wrapper2.ge(ShipmentHeader::getCreated,endTime);
        wrapper2.lt(ShipmentHeader::getLastStatus,QuantityConstant.SHIPMENT_HEADER_COMPLETED);
        int dayNoComplete=shipmentHeaderService.count(wrapper2);

        LambdaQueryWrapper<ShipmentHeader> wrapper3=new LambdaQueryWrapper<>();
        wrapper3.eq(ShipmentHeader::getWarehouseCode,warehouseCode);
        wrapper3.ge(ShipmentHeader::getCreated,formattedDate);
        wrapper3.lt(ShipmentHeader::getLastStatus,QuantityConstant.SHIPMENT_HEADER_COMPLETED);
        int monthHaveComplete=shipmentHeaderService.count(wrapper3);
        LambdaQueryWrapper<ShipmentHeader> wrapper4=new LambdaQueryWrapper<>();
        wrapper4.eq(ShipmentHeader::getWarehouseCode,warehouseCode);
        wrapper4.ge(ShipmentHeader::getCreated,formattedDate);
        wrapper4.lt(ShipmentHeader::getLastStatus,QuantityConstant.SHIPMENT_HEADER_COMPLETED);
        int monthNoComplete=shipmentHeaderService.count(wrapper4);

        List<Map<String, Object>> receiptHeaderList=shipmentHeaderService.csShipment(endTime1,warehouseCode);
        List<LocalDate> datelist=DateUtils.getDayList(endTime1,endTime);
        //查找receiptHeaderList中每天receiptType数量最多的前3种,并计算数量
        List<Map<String, Object>> list=new ArrayList<>();
        for (int a=0;a<datelist.size();a++){
            String days=datelist.get(a).toString();
            List<Map<String, Object>> shipmentList1 = receiptHeaderList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
            if(shipmentList1==null||shipmentList1.size()==0){
                shipmentList1=new ArrayList<>();
                continue;
            }
            if(shipmentList1.size()>3){
                shipmentList1=shipmentList1.subList(0,3);
            }
            list.addAll(shipmentList1);
        }
        resultMap2.put("dayHaveComplete",dayHaveComplete);
        resultMap2.put("dayNoComplete",dayNoComplete);
        resultMap2.put("monthHaveComplete",monthHaveComplete);
        resultMap2.put("monthNoComplete",monthNoComplete);
        resultMap2.put("weekdaysList",list);
        return AjaxResult.success(resultMap2);
    }
    public AjaxResult csReceiptTask(String warehouseCode){
        HashMap<String, Object> resultMap = new HashMap<>();
        String endTime1= DateUtils.getNowPreDays("yyyy-MM-dd", 0);
        LambdaQueryWrapper<TaskHeader> taskWrapper=new LambdaQueryWrapper<>();
        taskWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        taskWrapper.in(TaskHeader::getInternalTaskType,QuantityConstant.TASK_INTENERTYPE_RECEIPT,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        taskWrapper.lt(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
        taskWrapper.ge(TaskHeader::getCreated,endTime1);
        taskWrapper.select(TaskHeader::getContainerCode,TaskHeader::getToLocation,TaskHeader::getPort,TaskHeader::getCreated,TaskHeader::getInternalTaskType);
        List<TaskHeader> taskHeaderList=taskHeaderService.list(taskWrapper);
        if(taskHeaderList.size()>0){
            resultMap.put("taskCount",taskHeaderList);
            resultMap.put("taskHistoryCount",new ArrayList<>());
            return AjaxResult.success(resultMap);
        }
        LambdaQueryWrapper<TaskHeader> taskHisWrapper=new LambdaQueryWrapper<>();
        taskHisWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        taskHisWrapper.in(TaskHeader::getInternalTaskType,QuantityConstant.TASK_INTENERTYPE_RECEIPT,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        taskHisWrapper.eq(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
        taskHisWrapper.last("limit 10");
        taskHisWrapper.orderByDesc(TaskHeader::getCreated);
        taskHisWrapper.select(TaskHeader::getContainerCode,TaskHeader::getToLocation,TaskHeader::getPort,TaskHeader::getCreated);
        List<TaskHeader> taskHeaderHis=taskHeaderService.list(taskHisWrapper);
        resultMap.put("taskCount",new ArrayList<>());
        resultMap.put("taskHistoryCount",taskHeaderHis);
//        result.add(resultMap);
        return AjaxResult.success(resultMap);
    }
    public AjaxResult csShipmentTask(String warehouseCode){
        HashMap<String, Object> resultMap = new HashMap<>();
        String endTime1= DateUtils.getNowPreDays("yyyy-MM-dd", 0);
        LambdaQueryWrapper<TaskHeader> taskWrapper=new LambdaQueryWrapper<>();
        taskWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        taskWrapper.eq(TaskHeader::getInternalTaskType,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        taskWrapper.lt(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
        taskWrapper.ge(TaskHeader::getCreated,endTime1);
        taskWrapper.select(TaskHeader::getContainerCode,TaskHeader::getToLocation,TaskHeader::getPort,TaskHeader::getCreated);
        List<TaskHeader> taskHeaderList=taskHeaderService.list(taskWrapper);
        if(taskHeaderList.size()>0){
            resultMap.put("taskCount",taskHeaderList);
            resultMap.put("taskHistoryCount",new ArrayList<>());
            return AjaxResult.success(resultMap);
        }
        LambdaQueryWrapper<TaskHeader> taskHisWrapper=new LambdaQueryWrapper<>();
        taskHisWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        taskHisWrapper.eq(TaskHeader::getInternalTaskType,QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        taskHisWrapper.eq(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
//        taskHisWrapper.ge(TaskHeader::getCreated,endTime1);
        taskHisWrapper.last("limit 10");
        taskHisWrapper.orderByDesc(TaskHeader::getCreated);
        taskHisWrapper.select(TaskHeader::getContainerCode,TaskHeader::getFromLocation,TaskHeader::getPort,TaskHeader::getCreated);
        List<TaskHeader> taskHeaderHis=taskHeaderService.list(taskHisWrapper);
        resultMap.put("taskCount",new ArrayList<>());
        resultMap.put("taskHistoryCount",taskHeaderHis);
//        result.add(resultMap);
        return AjaxResult.success(resultMap);
    }
    public AjaxResult csLocation(String warehouseCode){
        ArrayList<Object> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = new LambdaQueryWrapper<>();
        locationLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
        locationLambdaQueryWrapper.eq(Location::getZoneCode, "LK");
        locationLambdaQueryWrapper.in(Location::getRoadway, 1,2);
        List<Location> locationList = locationService.list(locationLambdaQueryWrapper);

        int haveContainerNum = (int) locationList.stream().filter(l -> StringUtils.isNotEmpty(l.getContainerCode())).count();
        int unHaveContainerNum = locationList.size() - haveContainerNum;
        resultMap.put("haveContainerNum", String.valueOf(haveContainerNum));
        resultMap.put("unHaveContainerNum", String.valueOf(unHaveContainerNum));
        result.add(resultMap);
        return AjaxResult.success(result);
    }

    public AjaxResult csMaterialHot(String warehouseCode){
        String endTime1= DateUtils.getNowPreDays("yyyy-MM-dd", 30);
        InventoryTransaction inventoryTransaction=new InventoryTransaction();
        inventoryTransaction.setWarehouseCode(warehouseCode);
        inventoryTransaction.setUserDef1(endTime1);
        List<InventoryTransactionReport> list=inventoryTransactionService.csMaterialHot(inventoryTransaction);
        return AjaxResult.success(list);
    }
    public AjaxResult csMaterialDull(String warehouseCode){
        LambdaQueryWrapper<InventoryDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode);
        wrapper.orderByAsc(InventoryDetail::getCreated);
        wrapper.last("LIMIT 15");
        wrapper.select(InventoryDetail::getMaterialCode,InventoryDetail::getMaterialName,InventoryDetail::getQty,InventoryDetail::getCreated);
        List<InventoryDetail> list = inventoryDetailService.list(wrapper);
        if(list.size()==0){
            return AjaxResult.success(list);
        }
        //list去掉重复的物料名称数据得到新的list
        List<InventoryDetail> list1 = list.stream()
                .collect(Collectors.collectingAndThen(
                        Collectors.toCollection(
                                () -> new TreeSet<>(Comparator.comparing(InventoryDetail::getMaterialName))
                        ), ArrayList::new
                ));
//        //取前10个
        if(list1.size()>10){
            list1=list1.subList(0,10);
        }
        for (InventoryDetail inventoryDetail:list1){
            Date now = DateUtils.getNowDate();
            Date date = inventoryDetail.getCreated();
            int days = Math.toIntExact((now.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
            inventoryDetail.setDays(days);
        }
        return AjaxResult.success(list1);
    }
    public AjaxResult csMaterialCont(String warehouseCode){
        ArrayList<Object> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();
        QueryWrapper<InventoryDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("warehouseCode", warehouseCode);
        wrapper.select("sum(qty) as qty");
        Map<String, Object> materialMap = inventoryDetailService.getMap(wrapper);
        BigDecimal totalqty=materialMap.get("qty")==null?BigDecimal.ZERO:BigDecimal.valueOf(Double.parseDouble(materialMap.get("qty").toString()));

        String sql = "SELECT i.`materialName`,sum(i.qty) as total from inventory_detail i where  i.warehouseCode = '"+ warehouseCode+"' \n" +
                "GROUP BY i.`materialName` ORDER BY total desc limit 10;";
        List<LinkedHashMap<String, Object>> results = mapper.selectCommon(sql);

        float sum=100;
        for (LinkedHashMap<String, Object> i:results){
            String materialName=i.get("materialName").toString();
            BigDecimal qty=BigDecimal.valueOf(Double.parseDouble(i.get("total").toString()));
            resultMap.put(materialName,qty.divide(totalqty,2,BigDecimal.ROUND_HALF_UP).floatValue()*100);
            sum-=qty.divide(totalqty,2,BigDecimal.ROUND_HALF_UP).floatValue()*100;
        }
        resultMap.put("其他",sum);
//        result.add(resultMap);
        return AjaxResult.success(resultMap);
    }

    /**
     * 仓库物流看板
     * 顶部统计:只统计有工作令的
     * 库存准确率:一个月内  物品盘点数量/盘点库存总数
     * 库存周转率、 平均库存在库天数=所有库存在库天数/总数
     * 入库及时率、 已入库数量/入库数量
     * 出库及时率、已出库数量/出库数量
     * 库位利用率: 已使用库位/库位总数
     * @return
     */
    public AjaxResult csWarehouseCont(){
        HashMap<String, Object> resultMap = new HashMap<>();
        String warehouseCode=QuantityConstant.WAREHOUSE_CS;
        //库存准确率
        resultMap.put("库存准确率","100%");
        //库存周转率 所有库存在库天数/总数
        String endTime_month= DateUtils.getNowPreDays("yyyy-MM-dd", 30);
        String endTime_week= DateUtils.getNowPreDays("yyyy-MM-dd", 7);
        LambdaQueryWrapper<InventoryTransaction> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryTransaction::getWarehouseCode, warehouseCode);
        wrapper.ne(InventoryTransaction::getMoCode, QuantityConstant.EMPTY_STRING);
        wrapper.eq(InventoryTransaction::getTransactionType, QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
        wrapper.ge(InventoryTransaction::getCreated,endTime_month);
        List<InventoryTransaction> list = inventoryTransactionService.list(wrapper);
        int days=0;
        for (InventoryTransaction inventoryTransaction:list){
            days+=inventoryTransaction.getDays();
        }
        if(days!=0){
            BigDecimal days_decimal=BigDecimal.valueOf(days);
            BigDecimal size_decimal=BigDecimal.valueOf(list.size());
            BigDecimal averaDays=days_decimal.divide(size_decimal,3,BigDecimal.ROUND_HALF_UP);
            BigDecimal percent=averaDays.multiply(new BigDecimal("100"));
            resultMap.put("库存周转率(天)",percent.setScale(1,BigDecimal.ROUND_HALF_UP));
        }else{
            resultMap.put("库存周转率(天)",0);
        }
        //入库及时率 已入库数量/入库数量
        LambdaQueryWrapper<ReceiptDetail> wrapperReceipt = new LambdaQueryWrapper<>();
        wrapperReceipt.eq(ReceiptDetail::getWarehouseCode, warehouseCode);
//        wrapperReceipt.ne(ReceiptDetail::getReferCode, QuantityConstant.EMPTY_STRING);
        wrapperReceipt.ge(ReceiptDetail::getCreated,endTime_week);
        List<ReceiptDetail> receiptlist = receiptDetailService.list(wrapperReceipt);
        BigDecimal receiptQty=BigDecimal.ZERO;
        BigDecimal completeQty=BigDecimal.ZERO;
        for (ReceiptDetail receiptDetail:receiptlist){
            BigDecimal qty=receiptDetail.getQty();
            BigDecimal backQty=receiptDetail.getBackQty();
            receiptQty=receiptQty.add(qty);
            completeQty=completeQty.add(backQty);
        }
        if(receiptQty.compareTo(BigDecimal.ZERO)==0){
            resultMap.put("入库及时率","100%");
        }else{
            BigDecimal receiptPecent= completeQty.divide(receiptQty,3,BigDecimal.ROUND_HALF_UP);
            BigDecimal percent=receiptPecent.multiply(new BigDecimal("100"));
            resultMap.put("入库及时率",percent.setScale(1,BigDecimal.ROUND_HALF_UP)+"%");
        }
        //出库及时率 已出库数量/出库数量
        LambdaQueryWrapper<ShipmentDetail> wrapperShipment = new LambdaQueryWrapper<>();
        wrapperShipment.eq(ShipmentDetail::getWarehouseCode, warehouseCode);
//        wrapperShipment.ne(ShipmentDetail::getReferCode, QuantityConstant.EMPTY_STRING);
        wrapperShipment.ge(ShipmentDetail::getCreated,endTime_week);
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(wrapperShipment);
        BigDecimal shipmentQty=BigDecimal.ZERO;
        BigDecimal completeQtyShip=BigDecimal.ZERO;
        for (ShipmentDetail shipmentDetail:shipmentDetails){
            shipmentQty=shipmentQty.add(shipmentDetail.getQty());
            completeQtyShip=completeQtyShip.add(shipmentDetail.getBackQty());
        }
        if(shipmentQty.compareTo(BigDecimal.ZERO)==0){
            resultMap.put("出库及时率","100%");
        }else{
            BigDecimal shipmentPecent= completeQtyShip.divide(shipmentQty,3,BigDecimal.ROUND_HALF_UP);
            BigDecimal percent=shipmentPecent.multiply(new BigDecimal("100"));
            resultMap.put("出库及时率",percent.setScale(1,BigDecimal.ROUND_HALF_UP)+"%");
        }

        //库位利用率 已使用库位/库位总数
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
        locationLambdaQueryWrapper.in(Location::getRoadway, 1,2);
        locationLambdaQueryWrapper.eq(Location::getZoneCode, "LK");
        List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
        int haveContainerNum = (int) locationList.stream().filter(l -> StringUtils.isNotEmpty(l.getContainerCode())).count();
        BigDecimal localhost_decimal=BigDecimal.valueOf(locationList.size());
        BigDecimal haveCon_decimal=BigDecimal.valueOf(haveContainerNum);
        BigDecimal locationPecent=haveCon_decimal.divide(localhost_decimal,3,BigDecimal.ROUND_HALF_UP);
        BigDecimal percent=locationPecent.multiply(new BigDecimal("100"));
        resultMap.put("库位利用率",percent.setScale(1,BigDecimal.ROUND_HALF_UP)+"%");

        return AjaxResult.success(resultMap);
    }
}