TvStatisticService.java 12.6 KB
package com.huaheng.api.tv.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import com.huaheng.api.tv.domain.*;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.framework.web.domain.AjaxResultTv;
import com.huaheng.framework.web.service.DictService;
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.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.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.srm.domain.*;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.RunFailException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.supplier.service.SupplierService;
import com.huaheng.pc.monitor.apilog.domain.ApiLog;
import com.huaheng.pc.srm.domain.*;
import com.huaheng.pc.srm.mapper.ICSASNMapper;
import com.huaheng.pc.srm.service.ICSASNDetailService;
import com.huaheng.pc.srm.service.ICSITEMLotService;
import com.huaheng.pc.srm.service.SrmDetailService;
import com.huaheng.pc.srm.service.SrmHeaderService;

@Service
public class TvStatisticService {

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


    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;
    @Resource
    private DictService dictService;


    /**
     * 获取库存数据
     * 长沙立库:根据容器判断 LKL(演示立库),LKM(大立库),LKS(高速堆垛机立库)
     * 昆山:LK,JLK
     * 徐州:LK
     * @param warehourseCode
     * @param zoneCode
     * @return
     */
    public AjaxResultTv getInventoryData(String warehourseCode, String zoneCode) {
        String zoneCodes=zoneCode;
        if(StringUtils.isEmpty(zoneCode)){
            if(warehourseCode.equals(QuantityConstant.WAREHOUSE_KS)){
                zoneCodes="LK,JLK";
            }else{
                zoneCodes="LK";
            }
        }
        String[] zonelist=zoneCodes.split(",");
        List<String> zoneList = java.util.Arrays.asList(zonelist);
        TvInventoryBean tvInventoryBean=new TvInventoryBean();
        tvInventoryBean.setInventoryCode(zoneCode);


        LambdaQueryWrapper<InventoryHeader> headerLambdaQueryWrapper = new LambdaQueryWrapper<>();
        headerLambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, warehourseCode)
                .in(InventoryHeader::getZoneCode, zoneList);
        headerLambdaQueryWrapper.select(InventoryHeader::getContainerCode, InventoryHeader::getLocationCode, InventoryHeader::getId);
        List<InventoryHeader> headerlist=inventoryHeaderService.list(headerLambdaQueryWrapper);

        List<TvInventoryListBean> tvInventoryListBeans=new ArrayList<>();
        for (InventoryHeader inventoryHeader : headerlist) {
            TvInventoryListBean tvInventoryListBean=new TvInventoryListBean();
            tvInventoryListBean.setContainerCode(inventoryHeader.getContainerCode());
            String locationCode=inventoryHeader.getLocationCode();
            if(StringUtils.isNotEmpty(locationCode)){
               if(locationCode.contains("-")||locationCode.contains("_")) {
                   tvInventoryListBean.setRow(Integer.valueOf(locationCode.substring(7, 8)));
                   tvInventoryListBean.setQueue(Integer.valueOf(locationCode.substring(1,2)));
                   tvInventoryListBean.setCol(Integer.valueOf(locationCode.substring(4,5)));
               }else{
                   tvInventoryListBean.setRow(Integer.valueOf(locationCode.substring(5, 6)));
                   tvInventoryListBean.setQueue(Integer.valueOf(locationCode.substring(1,2)));
                   tvInventoryListBean.setCol(Integer.valueOf(locationCode.substring(3,4)));
               }
            }
            //查询库粗详情
//            LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getWarehouseCode, warehourseCode);
//            inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader.getId());
//            inventoryDetailLambdaQueryWrapper.select(InventoryDetail::getMaterialCode, InventoryDetail::getMaterialName, InventoryDetail::getMaterialSpec,InventoryDetail::getQty, InventoryDetail::getContainerCode);
//
//            List<InventoryDetail> invnetorylist=inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
//            List<TvInventoryMaterialBean> materialBeans=new ArrayList<>();
//            for (InventoryDetail inventoryDetail : invnetorylist) {
//                TvInventoryMaterialBean materialBean=new TvInventoryMaterialBean();
//                materialBean.setType(inventoryDetail.getMaterialSpec());
//                materialBean.setMaterialCode(inventoryDetail.getMaterialCode());
//                materialBean.setMaterialName(inventoryDetail.getMaterialName());
//                materialBeans.add(materialBean);
//            }
//            tvInventoryListBean.setMaterialList(materialBeans);
            tvInventoryListBeans.add(tvInventoryListBean);
        }
        tvInventoryBean.setList(tvInventoryListBeans);

        return AjaxResultTv.success(tvInventoryBean);
    }
    /**
     * 获取库存数据
     * 长沙立库:根据容器判断 LKL(演示立库),LKM(大立库),LKS(高速堆垛机立库)
     * 昆山:LK,JLK
     * 徐州:LK
     * @return
     */
    public AjaxResultTv getInventoryDetailData(Integer id) {
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getInventoryHeaderId,id);
        inventoryDetailLambdaQueryWrapper.select(InventoryDetail::getMaterialCode, InventoryDetail::getMaterialName, InventoryDetail::getMaterialSpec,InventoryDetail::getQty, InventoryDetail::getContainerCode);

        List<InventoryDetail> invnetorylist=inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        List<TvInventoryMaterialBean> materialBeans=new ArrayList<>();
        for (InventoryDetail inventoryDetail : invnetorylist) {
            TvInventoryMaterialBean materialBean=new TvInventoryMaterialBean();
            materialBean.setType(inventoryDetail.getMaterialSpec());
            materialBean.setMaterialCode(inventoryDetail.getMaterialCode());
            materialBean.setMaterialName(inventoryDetail.getMaterialName());
            materialBeans.add(materialBean);
        }
        return AjaxResultTv.success(materialBeans);
    }

    /**
     * 获取任务数据
     * 长沙立库:根据容器判断 LKL(演示立库),LKM(大立库),LKS(高速堆垛机立库)
     * 昆山:LK,JLK
     * 徐州:LK
     * @param warehourseCode
     * @param zoneCode
     * @return
     */
    public AjaxResultTv getTaskData(String warehourseCode, String zoneCode) {
        String zoneCodes=zoneCode;
        if(StringUtils.isEmpty(zoneCode)){
            if(warehourseCode.equals(QuantityConstant.WAREHOUSE_KS)){
                zoneCodes="LK,JLK";
            }else{
                zoneCodes="LK";
            }
        }
        String[] zonelist=zoneCodes.split(",");
        List<String> zoneList = java.util.Arrays.asList(zonelist);
        TvInventoryBean tvInventoryBean=new TvInventoryBean();
        tvInventoryBean.setInventoryCode(zoneCode);
        //今天已完成任务数量
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, warehourseCode)
                .in(TaskHeader::getZoneCode, zoneList)
                .eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                .ge(TaskHeader::getCreated, DateUtils.parseDateToStr("yyyy-MM-dd 00:00:00", new Date()));
        int completedTaskCount=taskHeaderService.count(taskHeaderLambdaQueryWrapper);
        tvInventoryBean.setTaskNumber(completedTaskCount);
            //今天未完成任务数量
        LambdaQueryWrapper<TaskHeader> taskHeaderQueryWrapper = new LambdaQueryWrapper<>();
        taskHeaderQueryWrapper.eq(TaskHeader::getWarehouseCode, warehourseCode)
                .in(TaskHeader::getZoneCode, zoneList)
                .ge(TaskHeader::getCreated, DateUtils.parseDateToStr("yyyy-MM-dd 00:00:00", new Date()))
                .orderByAsc(TaskHeader::getStatus);
        List<TaskHeader> taskHeaderList=taskHeaderService.list(taskHeaderQueryWrapper);
        List<TvTaskListBean> taskListBeans=new ArrayList<>();
        for (TaskHeader taskHeader : taskHeaderList) {
            TvTaskListBean tvTaskListBean=new TvTaskListBean();
            String taskType=dictService.getLabel("taskType",taskHeader.getTaskType().toString());
            tvTaskListBean.setTaskName(taskType);
            String status=dictService.getLabel("taskStatus",taskHeader.getStatus().toString());
            tvTaskListBean.setTaskStatus(status);
            tvTaskListBean.setTaskNo(taskHeader.getId());
            tvTaskListBean.setToPort(taskHeader.getToLocation());
            tvTaskListBean.setContainerCode(taskHeader.getContainerCode());

//            LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
//            taskDetailLambdaQueryWrapper.eq(TaskDetail::getWarehouseCode, warehourseCode);
//            List<TaskDetail> taskDetails=taskDetailService.list(taskDetailLambdaQueryWrapper);
//            List<TvTaskScreenBean> tvTaskScreenBeans=new ArrayList<>();
//            for (TaskDetail taskDetail : taskDetails) {
//                TvTaskScreenBean tvTaskScreenBean=new TvTaskScreenBean();
//                tvTaskScreenBean.setMaterialName(taskDetail.getMaterialName());
//                tvTaskScreenBean.setType(taskDetail.getMaterialSpec());
//                tvTaskScreenBean.setQty(taskDetail.getQty());
//                tvTaskScreenBeans.add(tvTaskScreenBean);
//            }
//            tvTaskListBean.setScreenList(tvTaskScreenBeans);
            taskListBeans.add(tvTaskListBean);
        }

        return AjaxResultTv.success(taskListBeans);
    }
    /**
     * 获取库存数据
     * 长沙立库:根据容器判断 LKL(演示立库),LKM(大立库),LKS(高速堆垛机立库)
     * 昆山:LK,JLK
     * 徐州:LK
     * @return
     */
    public AjaxResultTv getTaskDetailData(Integer id) {
        LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, id);
        List<TaskDetail> taskDetails=taskDetailService.list(taskDetailLambdaQueryWrapper);
        List<TvTaskScreenBean> tvTaskScreenBeans=new ArrayList<>();
        for (TaskDetail taskDetail : taskDetails) {
            TvTaskScreenBean tvTaskScreenBean=new TvTaskScreenBean();
            tvTaskScreenBean.setMaterialName(taskDetail.getMaterialName());
            tvTaskScreenBean.setType(taskDetail.getMaterialSpec());
            tvTaskScreenBean.setQty(taskDetail.getQty());
            tvTaskScreenBeans.add(tvTaskScreenBean);
        }
        return AjaxResultTv.success(tvTaskScreenBeans);
    }
}