TvController.java 17.2 KB
package com.huaheng.api.tv.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.tv.domain.*;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.task.TaskDomain;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
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.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetailTv;
import com.huaheng.pc.shipment.shipmentDetail.mapper.ShipmentDetailMapper;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
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 com.huaheng.pc.task.taskHeader.service.TaskHeaderTvService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping
public class TvController extends BaseController {
    @Resource
    ExcelReportMapper mapper;
    @Resource
    ExcelReportMapper excelReportMapper;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private ContainerService containerService;
    @Resource
    private LocationService locationService;
    @Resource
    private InventoryTransactionService inventoryTransactionService;
    @Resource
    private ZoneService zoneService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private InventoryMaterialSummaryService inventoryMaterialSummaryService;
    @Resource
    private MaterialService materialService;
    @Resource
    private ShipmentDetailMapper shipmentDetailMapper;

    @Resource
    private TaskHeaderTvService taskHeaderTvService;
    @Resource
    private IDictDataService dictDataService;


    @CrossOrigin
    @GetMapping("/stackA")
    private AjaxResult mainA(@RequestParam String port) {
        return getTvView("A", port);
    }

    @CrossOrigin
    @GetMapping("/stackB")
    private AjaxResult mainB(@RequestParam String port) {
        return getTvView("B", port);
    }

    @CrossOrigin
    @GetMapping("/stackC")
    private AjaxResult mainC(@RequestParam String port) {
        return getTvView("C", port);
    }

    public AjaxResult<TvTask> getTvView(String zone, String port) {
        TvTask tvTask = new TvTask();
        //库位利用率(矮库位有货、矮库位无货、高库位有货、高库位无货、高库位空托、低库位空托)
        String sql1 = "SELECT\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "'  AND l.warehouseCode = 'CS0001' AND containerCode != '' AND c.`status` = 'some' AND high = 0 THEN 1 ELSE 0 END ) AS 'lowInStock',\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "' AND l.warehouseCode = 'CS0001' AND containerCode = '' AND l.`status`='empty' AND high = 0 THEN 1 ELSE 0 END ) AS 'lowSoldOut',\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "' AND l.warehouseCode = 'CS0001' AND containerCode != '' AND c.`status` = 'some' AND high = 1 THEN 1 ELSE 0 END ) AS 'highInStock',\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "' AND l.warehouseCode = 'CS0001' AND containerCode = '' AND l.`status`='empty' AND high = 1 THEN 1 ELSE 0 END ) AS 'highSoldOut',\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "' AND l.warehouseCode = 'CS0001' AND containerCode != '' AND c.`status` = 'empty' AND high = 1 THEN 1 ELSE 0 END ) AS 'hiePallets',\n" +
                "\tSUM( CASE WHEN zoneCode='" + zone + "' AND l.warehouseCode = 'CS0001' AND containerCode != '' AND c.`status` = 'empty' AND high = 0 THEN 1 ELSE 0 END ) AS 'lieSupport'\n" +
                "FROM\n" +
                "\tlocation l\n" +
                "\tLEFT JOIN container c ON l.CODE = c.locationCode;";
        List<LinkedHashMap<String, Object>> locationProportion = excelReportMapper.selectCommon(sql1);
        JSONObject location = new JSONObject();
        location.put("locationProportion", locationProportion);


        //空托盘
        String sql3 = "";
        if ("A".equals(zone)) {
            sql3 = "SELECT ct.name, COUNT(*) AS count FROM container c JOIN container_type ct ON c.containerType = ct.code \n" +
                    "WHERE c.status = 'empty' and c.locationCode!='' AND c.containerType in ('A') GROUP BY ct.name;";
        } else if ("B".equals(zone)) {
            sql3 = "SELECT ct.name, COUNT(*) AS count FROM container c JOIN container_type ct ON c.containerType = ct.code \n" +
                    "WHERE c.status = 'empty' and c.locationCode!='' AND c.containerType in ('B', 'C', 'D', 'E') GROUP BY ct.name;";
        } else {
            sql3 = "SELECT ct.name, COUNT(*) AS count FROM container c JOIN container_type ct ON c.containerType = ct.code \n" +
                    "WHERE c.status = 'empty' and c.locationCode!='' AND c.containerType in ('F', 'G') GROUP BY ct.name;";
            //成品栈口数据
            JSONObject productPort = new JSONObject();
            Map<String, Object> productPortData = (Map<String, Object>) productPortData().getData();
            productPort.put("productPort", productPortData);
            tvTask.setProductPort(productPort);
        }
        List<LinkedHashMap<String, Object>> emptyPallet = excelReportMapper.selectCommon(sql3);
        JSONObject empty = new JSONObject();
        empty.put("emptyPallet", emptyPallet);


        //任务
        List<TaskDomain> taskDomainList = new ArrayList<>();
        //port多个站台用,分隔,查出所有头表
        List<DictData> dictlist = dictDataService.selectDictDataByType("taskType");
        List<TaskHeader> taskList = new ArrayList<>();
        for (String p : port.split(",")) {
            List<TaskHeader> tmpTaskList = taskHeaderTvService.getTaskByTvPort(p);
            taskList.addAll(tmpTaskList);
        }

        lable1:
        for (TaskHeader task : taskList) {
            if (task.getInternalTaskType() == 100) {
                task.setFromLocation(task.getToLocation());
            }
            lable2:
            for (DictData dictData : dictlist) {
                if (task.getTaskType().toString().equals(dictData.getDictValue())) {
                    task.setUserDef1(dictData.getDictLabel());
                    break lable2;
                }
            }
            TaskDomain taskDomain = new TaskDomain();
            List<TaskDetail> taskDetails = taskDetailService.findByTaskId(task.getId());
            taskDomain.setTaskHeader(task);
            taskDomain.setTaskDetails(taskDetails);
            taskDomainList.add(taskDomain);
        }

        taskDomainList.sort((o1, o2) -> {
            TaskHeader task1 = o1.getTaskHeader();
            TaskHeader task2 = o2.getTaskHeader();
            int ret = task2.getStatus() - task1.getStatus();
            if (ret == 0) {
                ret = (int) (task2.getLastUpdated().getTime() - task1.getLastUpdated().getTime());
            }
            return ret;
        });


        tvTask.setTaskDomains(taskDomainList);
        tvTask.setEmptyPallet(empty);
        tvTask.setLocationProportion(location);
        return AjaxResult.success(tvTask);
    }

    //成品栈口数据
    private AjaxResult productPortData() {
        Map<String, Object> map = new HashMap<>();

        //双幅托盘有货
        String sql1 = "select count(*) from container where status='some' and containerType='G'";
        List<LinkedHashMap<String, Object>> temp1 = mapper.selectCommon(sql1);
        map.put("data1", temp1.get(0).entrySet().iterator().next().getValue());

        //单幅托盘有货
        String sql2 = "select count(*) from container where status='some' and containerType='F'";
        List<LinkedHashMap<String, Object>> temp2 = mapper.selectCommon(sql2);
        map.put("data2", temp2.get(0).entrySet().iterator().next().getValue());

        //双幅空托
        String sql3 = "select count(*) from container where status='empty' and containerType='G' and locationCode!=''";
        List<LinkedHashMap<String, Object>> temp3 = mapper.selectCommon(sql3);
        map.put("data3", temp3.get(0).entrySet().iterator().next().getValue());

        //单幅空托
        String sql4 = "select count(*) from container where status='empty' and containerType='F' and locationCode!=''";
        List<LinkedHashMap<String, Object>> temp4 = mapper.selectCommon(sql4);
        map.put("data4", temp4.get(0).entrySet().iterator().next().getValue());

        //空闲库位
        String sql5 = "select count(*) from location where status='empty' and locationType='C' and containerCode=''";
        List<LinkedHashMap<String, Object>> temp5 = mapper.selectCommon(sql5);
        map.put("data5", temp5.get(0).entrySet().iterator().next().getValue());

        //锁定库位
        String sql6 = "select count(*) from location where status='lock' and locationType='C'";
        List<LinkedHashMap<String, Object>> temp6 = mapper.selectCommon(sql6);
        map.put("data6", temp6.get(0).entrySet().iterator().next().getValue());
        return AjaxResult.success(map);
    }


    @PostMapping("/getTvView")
    //@ApiOperation("获取电视信息")
    @CrossOrigin
    //@ApiLogger(apiName = "获取电视信息", from="TV")
    @ResponseBody
    public AjaxResult getTvView(@RequestBody WcsTask wcsTask) {
        String area = wcsTask.getArea();
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getArea, area)
                .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                .orderByDesc(TaskHeader::getId);
        List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
        if (taskHeaderList != null && taskHeaderList.size() > 0) {
            for (TaskHeader taskHeader : taskHeaderList) {
                String materialCode = taskHeader.getMaterialCode();
                String warehouseCode = taskHeader.getWarehouseCode();
                Material material = materialService.getMaterialByCode(materialCode, warehouseCode);
                if (material != null) {
                    taskHeader.setMaterialCode(material.getName());
                }
            }
        }

        LambdaQueryWrapper<Container> containerEmptyLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerEmptyLambdaQueryWrapper.eq(Container::getArea, area)
                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
                .ne(Container::getLocationCode, "");
        List<Container> containerEmptyList = containerService.list(containerEmptyLambdaQueryWrapper);
        int containerEmptySize = containerEmptyList.size();

        LambdaQueryWrapper<Container> containerManyLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerManyLambdaQueryWrapper.eq(Container::getArea, area)
                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY)
                .ne(Container::getLocationCode, "");
        List<Container> manyEmptyList = containerService.list(containerManyLambdaQueryWrapper);
        int manyEmptyListSize = manyEmptyList.size();
        containerEmptySize = containerEmptySize + manyEmptyListSize * 6;
        LambdaQueryWrapper<Container> containerSomeLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerSomeLambdaQueryWrapper.eq(Container::getArea, area)
                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME)
                .ne(Container::getLocationCode, "");
        List<Container> containerSomeList = containerService.list(containerSomeLambdaQueryWrapper);
        int containerSomeSize = containerSomeList.size();

        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getArea, area);
        List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
        int totalLocationSize = locationList.size();

        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getZoneCode, zone.getCode());
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        int inventorySize = inventoryDetailList.size();


        LambdaQueryWrapper<InventoryMaterialSummary> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(InventoryMaterialSummary::getZoneCode, zone.getCode());
        List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(lambdaQueryWrapper);
        if (list == null) {
            list = Collections.emptyList();
        }
        //筛选库存汇总数据的专用方法
        List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);

        TvBean tvBean = new TvBean();
        tvBean.setDetails(details);
        tvBean.setContainerEmptySize(containerEmptySize);
        tvBean.setContainerSomeSize(containerSomeSize);
        tvBean.setTotalLocationSize(totalLocationSize);
        tvBean.setTaskHeaderList(taskHeaderList);
        tvBean.setInventorySize(inventorySize);
        return AjaxResult.success(tvBean);
    }

    @PostMapping("/getTvReceiptView")
    //@ApiOperation("获取电视入库信息")
    @CrossOrigin
    @ResponseBody
    //@ApiLogger(apiName = "获取电视入库信息", from = "TV")
    public AjaxResult getTvReceiptView() {
        AllBean allBean = new AllBean();
        LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
        List<String> str = Arrays.asList("100", "200");
        queryWrapper.in(TaskDetail::getTaskType, str)
                .last(" and  date_format( created, '%Y-%m-%d' )= date_format( now(), '%Y-%m-%d' ) and `status`>=100");
        List<TaskDetail> list = taskDetailService.list(queryWrapper);
        List<TopBean> topList = new ArrayList<>();
        if (list.size() > 0) {
            topList = taskDetailService.getTvReceiptView("1");
        }
        allBean.setTopList(topList);
        List<UpBean> upList = taskDetailService.getTvNotReceiptList("1");
        allBean.setUpList(upList);
        return AjaxResult.success(allBean);
    }

    @PostMapping("/getTvShipmentView")
    //@ApiOperation("获取电视出库信息")
    @CrossOrigin
    @ResponseBody
    //@ApiLogger(apiName = "获取电视出库信息", from = "TV")
    public AjaxResult getTvShipmentView(@RequestBody Map<String, String> map) {
        AllBean allBean = new AllBean();
        LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
        List<String> str = Arrays.asList("300", "400");
        queryWrapper.in(TaskDetail::getTaskType, str)
                .last(" and  date_format( created, '%Y-%m-%d' )= date_format( now(), '%Y-%m-%d' ) and `status`>=100");
        List<TaskDetail> list = taskDetailService.list(queryWrapper);
        List<TopBean> topList = new ArrayList<>();
        if (list.size() > 0) {
            topList = taskDetailService.getTvReceiptView("2");
        }
        allBean.setTopList(topList);
        List<UpBean> upList = taskDetailService.getTvNotReceiptList("2");
        allBean.setUpList(upList);
        String par = map.get("par");
        List<ShipmentDetailTv> portList = shipmentDetailMapper.getTvOutList(par);
        allBean.setPortList(portList);
        return AjaxResult.success(allBean);
    }

    @PostMapping("/getTvPortShipmentView")
    @ApiOperation("获取出站口出库信息")
    @CrossOrigin
    @ResponseBody
    @ApiLogger(apiName = "获取出站口出库信息", from = "TV")
    public AjaxResult getTvPortShipmentView(@RequestBody Map<String, String> map) {
        String par = map.get("par");
        List<ShipmentDetailTv> upList = shipmentDetailMapper.getTvOutList(par);
        return AjaxResult.success(upList);
    }
}