TvSCService.java 8.85 KB
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.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
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.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 TvSCService {

    @Autowired
    protected RedisTemplate<String, Object> redisTemplate;

    private static final Logger logger = LoggerFactory.getLogger(TvSCService.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 getTopData(String warehouseCode){
        ArrayList<Object> result = new ArrayList<>();
        LambdaQueryWrapper<InventoryTransaction> receiptLambdaQueryWrapper = Wrappers.lambdaQuery();
        receiptLambdaQueryWrapper.eq(InventoryTransaction::getWarehouseCode, warehouseCode);
        receiptLambdaQueryWrapper.ge(InventoryTransaction::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 30));
        receiptLambdaQueryWrapper.eq(InventoryTransaction::getTransactionType, QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
        List<InventoryTransaction> receiptlist = inventoryTransactionService.list(receiptLambdaQueryWrapper);


        LambdaQueryWrapper<InventoryTransaction> shipmentLambdaQueryWrapper = Wrappers.lambdaQuery();
        shipmentLambdaQueryWrapper.eq(InventoryTransaction::getWarehouseCode, warehouseCode);
        shipmentLambdaQueryWrapper.ge(InventoryTransaction::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 30));
        shipmentLambdaQueryWrapper.eq(InventoryTransaction::getTransactionType, QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
        List<InventoryTransaction> shipmentlist = inventoryTransactionService.list(shipmentLambdaQueryWrapper);


        HashMap<String, Integer> resultMap = new HashMap<>();

        List<Map<String, Object>> list=inventoryDetailService.csMaterialWarningMax(warehouseCode);
        //库存预警-最大
        List<Map<String, Object>> list1=inventoryDetailService.csMaterialWarningMin(warehouseCode);
        //库存预警-最小
        resultMap.put("warningMaterial",list.size()+list1.size());
        if (CollectionUtils.isNotEmpty(receiptlist)) {
            //统计receiptlist中taskQty(bigdecimal)总和
            BigDecimal total = receiptlist.stream()
                    .map(InventoryTransaction::getTaskQty)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            resultMap.put("receiptNum", total.intValue());
        } else {
            resultMap.put("receiptNum", 0);
        }
        if (CollectionUtils.isNotEmpty(shipmentlist)) {
            BigDecimal total = shipmentlist.stream()
                    .map(InventoryTransaction::getTaskQty)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            resultMap.put("shipmentNum", total.intValue());
        } else {
            resultMap.put("shipmentNum", 0);
        }
        LambdaQueryWrapper<Location> headerLambdaQueryWrapper = new LambdaQueryWrapper<>();
        headerLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
        headerLambdaQueryWrapper.eq(Location::getZoneCode, "LK");
        List<Location> locationList = locationService.list(headerLambdaQueryWrapper);
        if (CollectionUtils.isNotEmpty(locationList)) {
            resultMap.put("locationNum", locationList.size());
            //过滤locationList中containerCode为空的数据
            List<Location> locationList1 = locationList.stream().filter(location -> location.getContainerCode().equals("")).collect(Collectors.toList());
            resultMap.put("emptylocationNum", locationList1.size());
        } else {
            resultMap.put("locationNum", 0);
            resultMap.put("emptylocationNum", 0);
        }
        LambdaQueryWrapper<InventoryDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode);
        wrapper.eq(InventoryDetail::getZoneCode, "LK");
        List<InventoryDetail> inventoryDetails = inventoryDetailService.list(wrapper);
        if (CollectionUtils.isNotEmpty(inventoryDetails)) {
            //统计receiptlist中taskQty(bigdecimal)总和
            BigDecimal total = inventoryDetails.stream()
                    .map(InventoryDetail::getQty)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            resultMap.put("inventoryNum", total.intValue());
        } else {
            resultMap.put("inventoryNum", 0);
        }
        result.add(resultMap);
        return AjaxResult.success(result);
    }

    public AjaxResult taskOfWeek(String warehouseCode) {
        String startTime= DateUtils.getNowPreDays("yyyy-MM-dd", 8);
        String endTime= DateUtils.getNowPreDays("yyyy-MM-dd", 1);
        String endTimes=endTime+" 23:59:59";
        String zoneCodes="LK";
        List<Map<String, Object>> shipmentList=taskHeaderService.tvTaskHistoryDetail(startTime,endTimes,warehouseCode,zoneCodes,QuantityConstant.TASK_INTENERTYPE_SHIPMENT,null);
        List<Map<String, Object>> receiptList=taskHeaderService.tvTaskHistoryDetail(startTime,endTimes,warehouseCode,zoneCodes,QuantityConstant.TASK_INTENERTYPE_RECEIPT,null);
        List<LocalDate> datelist=DateUtils.getDayList(startTime,endTime);
        HashMap<String, Map<String, Object>> resultMap = new HashMap<>();
        Map<String, Object> shipmentResult=new HashMap<>();
        Map<String, Object> receiptResult=new HashMap<>();
        for (int a=0;a<datelist.size();a++){
            String days=datelist.get(a).toString();
            Map<String, Object> map=new HashMap<>();
            List<Map<String, Object>> shipmentList1 = shipmentList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
            if(shipmentList1!=null&&shipmentList1.size()>0){
                map=shipmentList1.get(0);
                shipmentResult.put(days,map.get("taskNum").toString());
            }else{
                shipmentResult.put(days,"0");
            }
            List<Map<String, Object>> receiptList1 = receiptList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
            if(receiptList1!=null&&receiptList1.size()>0){
                map=receiptList1.get(0);
                receiptResult.put(days,map.get("taskNum").toString());
            }else{
                receiptResult.put(days,"0");
            }
        }
        resultMap.put("receipt",receiptResult);
        resultMap.put("shipment",shipmentResult);
        return AjaxResult.success(resultMap);
    }
}