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

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.framework.web.domain.TVResult;
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.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 io.swagger.annotations.ApiOperation;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.*;

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

@RestController
@CrossOrigin
@RequestMapping("/API/WMS/v2")
public class TvController extends BaseController {

    @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
    ExcelReportMapper mapper;

    //入库看板
    //@PostMapping("/getTvReceiptView")
    //@ResponseBody
    ////@ApiLogger(apiName = "看板入库", from = "TV")
    //public TVResult getTvReceiptView() {
    //    AllBean allBean = new AllBean();
    //    LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
    //    List<String> str = Arrays.asList("100", "200");
    //    queryWrapper.in(TaskDetail::getTaskType, str)
    //            .last(" and created >= CURRENT_DATE() and `status`>=100");
    //    List<TaskDetail> list = taskDetailService.list(queryWrapper);
    //    List<TopBean> topList = new ArrayList<>();
    //    if (!list.isEmpty()) {
    //        topList = taskDetailService.getTvReceiptView("1");
    //    }
    //    allBean.setTopList(topList);
    //    List<UpBean> upList = taskDetailService.getTvNotReceiptList("1");
    //    allBean.setUpList(upList);
    //    return TVResult.success(allBean);
    //}
    @GetMapping("/queryAllPicture")
    public List<String> queryAllPicture() {
        //String directoryPath = "D:/Huaheng/uploadPath/file/";
        String directoryPath = "/Users/yiwenpeng/Desktop/素材";
        return listImageFiles(directoryPath);
    }

    public List<String> listImageFiles(String directoryPath) {
        List<String> imageFiles = new ArrayList<>();

        File directory = new File(directoryPath);
        File[] files = directory.listFiles();

        if (files != null) {
            for (File file : files) {
                if (file.isFile() && isImageFile(file.getName())) {
                    imageFiles.add(file.getAbsolutePath());
                }
            }
        }

        return imageFiles;
    }

    public boolean isImageFile(String fileName) {
        String[] imageExtensions = {".jpg", ".jpeg", ".png", ".gif", ".bmp"};
        for (String extension : imageExtensions) {
            if (fileName.toLowerCase().endsWith(extension)) {
                return true;
            }
        }
        return false;
    }


    //入库看板1,240221(未完成任务)
    @PostMapping("/getReceiptTv1")
    @ResponseBody
    //@ApiLogger(apiName = "看板入库", from = "TV")
    public TVResult getTvUndoneTasks() {
        List<UndoneTask> undoneTasks = getUndoneTasks();
        return TVResult.success(undoneTasks);
    }

    private List<UndoneTask> getUndoneTasks() {
        List<TaskHeader> list = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>()
                .eq(TaskHeader::getInternalTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT)
                .ne(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED));

        List<UndoneTask> undoneTasks = new ArrayList<>();
        for (TaskHeader taskHeader : list) {
            UndoneTask undoneTask = new UndoneTask();
            undoneTask.setId(taskHeader.getId());
            //undoneTask.setQty(taskHeader.getQty());
            //undoneTask.setMaterialCode(taskDetail.getMaterialCode());
            //undoneTask.setMaterialName(taskDetail.getMaterialName());
            undoneTask.setFromLocation(taskHeader.getFromLocation());
            undoneTask.setToLocation(taskHeader.getToLocation());
            undoneTask.setContainerCode(taskHeader.getContainerCode());
            undoneTask.setCreated(taskHeader.getCreated());
            if (taskHeader.getStatus() == 1) {
                undoneTask.setStatus("创建状态");
            } else if (taskHeader.getStatus() == 50) {
                undoneTask.setStatus("到达拣选台");
            } else {
                undoneTask.setStatus("执行状态");
            }
            if (taskHeader.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLERECEIPT)) {
                undoneTask.setTaskType("整盘入库");
            } else {
                undoneTask.setTaskType("分拣入库");
            }
            undoneTasks.add(undoneTask);
        }
        return undoneTasks;
    }


    //入库看板2,240221,(显示巷道库位状态、出入库次数和出入库数量)
    @PostMapping("/getTvReceiptFrequencyAndQty")
    @ResponseBody
    public TVResult getReceiptTv2() {
        //巷道库位状态
        List<RoadwayLocationStatus> roadwayLocationStatusList = new ArrayList<>();
        //获取所有巷道
        List<String> roadways = locationService.getDistinctRoadways();
        for (String roadway : roadways) {
            RoadwayLocationStatus roadwayLocationStatus = getRoadwayLocationStatus(roadway);
            roadwayLocationStatusList.add(roadwayLocationStatus);
        }

        //数量
        String sql = "SELECT a.click_date AS DATE,ifnull( b.taskQty, 0 ) AS qty FROM(SELECT curdate() AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 1 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 2 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 3 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 4 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 5 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 6 DAY ) AS click_date ) a LEFT JOIN (SELECT DATE ( h.completeTime ) AS completeTime,SUM( d.qty ) AS taskQty  FROM task_detail d JOIN task_header h ON d.taskId = h.id WHERE h.completeTime >= DATE_SUB( CURDATE(), INTERVAL 7 DAY ) AND h.STATUS = 100 AND h.internalTaskType=100 GROUP BY DATE ( h.completeTime )) b ON a.click_date = b.completeTime ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql);
        //次数
        //String sql2 = "SELECT a.click_date AS DATE,ifnull( b.taskCount, 0 ) AS count FROM(SELECT curdate() AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 1 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 2 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 3 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 4 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 5 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 6 DAY ) AS click_date ) a LEFT JOIN (SELECT DATE ( h.completeTime ) AS completeTime,COUNT( DISTINCT h.id ) AS taskCount FROM task_detail d JOIN task_header h ON d.taskId = h.id WHERE h.completeTime >= DATE_SUB( CURDATE(), INTERVAL 7 DAY ) AND h.STATUS = 100 AND h.internalTaskType=100 GROUP BY DATE ( h.completeTime )) b ON a.click_date = b.completeTime ORDER BY a.click_date;";
        //List<LinkedHashMap<String, Object>> list2 = mapper.selectCommon(sql2);

        //数量
        String sql3 = "SELECT a.click_date AS DATE,ifnull( b.taskQty, 0 ) AS qty FROM(SELECT curdate() AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 1 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 2 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 3 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 4 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 5 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 6 DAY ) AS click_date ) a LEFT JOIN (SELECT DATE ( h.completeTime ) AS completeTime,SUM( d.qty ) AS taskQty  FROM task_detail d JOIN task_header h ON d.taskId = h.id WHERE h.completeTime >= DATE_SUB( CURDATE(), INTERVAL 7 DAY ) AND h.STATUS = 100 AND h.internalTaskType=200 GROUP BY DATE ( h.completeTime )) b ON a.click_date = b.completeTime ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> list3 = mapper.selectCommon(sql3);
        //次数
        //String sql4 = "SELECT a.click_date AS DATE,ifnull( b.taskCount, 0 ) AS count FROM(SELECT curdate() AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 1 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 2 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 3 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 4 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 5 DAY ) AS click_date UNION ALL SELECT date_sub( curdate(), INTERVAL 6 DAY ) AS click_date ) a LEFT JOIN (SELECT DATE ( h.completeTime ) AS completeTime,COUNT( DISTINCT h.id ) AS taskCount FROM task_detail d JOIN task_header h ON d.taskId = h.id WHERE h.completeTime >= DATE_SUB( CURDATE(), INTERVAL 7 DAY ) AND h.STATUS = 100 AND h.internalTaskType=200 GROUP BY DATE ( h.completeTime )) b ON a.click_date = b.completeTime ORDER BY a.click_date;";
        //List<LinkedHashMap<String, Object>> list4 = mapper.selectCommon(sql4);

        ReceiptFrequencyAndQty resultData = new ReceiptFrequencyAndQty();
        resultData.setRoadwayLocationStatusList(roadwayLocationStatusList);
        resultData.setReceiptQty(list);
        //resultData.setReceiptFrequency(list2);
        resultData.setShipmentQty(list3);
        //resultData.setShipmentFrequency(list4);
        return TVResult.success(resultData);
    }


    //入库看板3,240221,(二厂入库看板)
    //1、上面内容,显示巷道库位状态(指定一个巷道)
    //2、下面柱状图,改为每日出入库数量,标签上的数值,取整数
    @GetMapping("/getReceiptTv3/{roadway}")
    @ResponseBody
    public TVResult getReceiptTv3(@PathVariable("roadway") String roadway) {
        RoadwayLocationStatus roadwayLocationStatus = getRoadwayLocationStatus(roadway);
        List<UndoneTask> undoneTasks = getUndoneTasks();
        ReceiptTv2 receiptTv2 = new ReceiptTv2();
        receiptTv2.setUndoneTaskList(undoneTasks);
        receiptTv2.setRoadwayLocationStatus(roadwayLocationStatus);
        return TVResult.success(receiptTv2);
    }

    //出库看板
    @PostMapping("/getTvShipmentView")
    @ResponseBody
    //@ApiLogger(apiName = "看板出库", from = "TV")
    public TVResult getTvShipmentView(@RequestBody Map<String, String> map) {
        AllBean allBean = new AllBean();
        String par = map.get("par");
        String roadway = map.get("roadway");
        //List<String> str = Arrays.asList("300", "400");
        //List<TaskDetail> list = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
        //        .in(TaskDetail::getTaskType, str)
        //        .last(" and created >= CURRENT_DATE() and `status`>=100"));
        //List<TopBean> topList = new ArrayList<>();
        //if (!list.isEmpty()) {
        //    topList = taskDetailService.getTvReceiptView("2");//出库物料统计
        //}
        //allBean.setTopList(topList);
        //List<UpBean> upList = taskDetailService.getTvNotReceiptList("2");//获取未完成订单看板
        //allBean.setUpList(upList);

        RoadwayLocationStatus roadwayLocationStatus = getRoadwayLocationStatus(roadway);
        List<ShipmentDetailTv> portList = shipmentDetailMapper.getTvOutList(par);//当前站台出库明细
        allBean.setPortList(portList);
        allBean.setRoadwayLocationStatus(roadwayLocationStatus);
        return TVResult.success(allBean);
    }


    private RoadwayLocationStatus getRoadwayLocationStatus(String roadway) {
        RoadwayLocationStatus roadwayLocationStatus = new RoadwayLocationStatus();
        int highEmptyContainer = getCount(2, roadway); //高库位空托
        int middleEmptyContainer = getCount(1, roadway); //中库位空托
        int lowEmptyContainer = getCount(0, roadway); //矮库位空托

        //高库位无货
        int highEmptyLocation = locationService.count(new LambdaQueryWrapper<Location>().eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY).eq(Location::getContainerCode, QuantityConstant.EMPTY_STRING).eq(Location::getHigh, 2).eq(Location::getRoadway, roadway));
        //中库位无货
        int middleEmptyLocation = locationService.count(new LambdaQueryWrapper<Location>().eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY).eq(Location::getContainerCode, QuantityConstant.EMPTY_STRING).eq(Location::getHigh, 1).eq(Location::getRoadway, roadway));
        //矮库位无货
        int lowEmptyLocation = locationService.count(new LambdaQueryWrapper<Location>().eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY).eq(Location::getContainerCode, QuantityConstant.EMPTY_STRING).eq(Location::getHigh, 0).eq(Location::getRoadway, roadway));

        roadwayLocationStatus.setRoadway(roadway);
        roadwayLocationStatus.setHighEmptyLocation(highEmptyLocation);
        roadwayLocationStatus.setHighEmptyContainer(highEmptyContainer);
        roadwayLocationStatus.setMiddleEmptyLocation(middleEmptyLocation);
        roadwayLocationStatus.setMiddleEmptyContainer(middleEmptyContainer);
        roadwayLocationStatus.setLowEmptyLocation(lowEmptyLocation);
        roadwayLocationStatus.setLowEmptyContainer(lowEmptyContainer);
        return roadwayLocationStatus;
    }


    public int getCount(int high, String roadway) {
        return locationService.count(new LambdaQueryWrapper<Location>()
                .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
                .ne(Location::getContainerCode, QuantityConstant.EMPTY_STRING)
                .eq(Location::getHigh, high)
                .eq(Location::getZoneCode, "L")
                .eq(Location::getRoadway, roadway)
                .inSql(Location::getContainerCode, "SELECT code FROM container WHERE status ='empty' "));
    }

    @PostMapping("/getTvView")
    //@ApiLogger(apiName = "获取电视信息", from="TV")
    @ResponseBody
    public TVResult getTvView(@RequestBody WcsTask wcsTask) {
        String area = wcsTask.getArea();
        List<TaskHeader> taskHeaderList = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>()
                .eq(TaskHeader::getArea, area)
                .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                .orderByDesc(TaskHeader::getId));

        //写入物料编码
        if (taskHeaderList != null && !taskHeaderList.isEmpty()) {
            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());
                }
            }
        }

        //获取指定库区的空托盘数量
        List<Container> containerEmptyList = containerService.list(new LambdaQueryWrapper<Container>()
                .eq(Container::getArea, area)
                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
                .ne(Container::getLocationCode, ""));
        int containerEmptySize = containerEmptyList.size();

        //获取指定库区的有货托盘数量
        //List<Container> manyEmptyList = containerService.list(new LambdaQueryWrapper<Container>()
        //        .eq(Container::getArea, area)
        //        .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY)
        //        .ne(Container::getLocationCode, ""));
        //int manyEmptyListSize = manyEmptyList.size();
        //空托盘的数量+有货托盘数量*6   (有货托盘数量这个项目好像没有啊,所以直接返回空托盘数量)
        //containerEmptySize = containerEmptySize + manyEmptyListSize * 6;

        //获取指定库区的有货托盘数量
        List<Container> containerSomeList = containerService.list(new LambdaQueryWrapper<Container>()
                .eq(Container::getArea, area)
                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME)
                .ne(Container::getLocationCode, ""));
        int containerSomeSize = containerSomeList.size();

        //指定库区总库位数
        List<Location> locationList = locationService.list(new LambdaQueryWrapper<Location>().eq(Location::getArea, area));
        int totalLocationSize = locationList.size();


        //获取指定区域的所有库存数
        Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getArea, area));
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(new LambdaQueryWrapper<InventoryDetail>()
                .eq(InventoryDetail::getZoneCode, zone.getCode()));
        int inventorySize = inventoryDetailList.size();


        //库存物料汇总
        List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(new LambdaQueryWrapper<InventoryMaterialSummary>()
                .eq(InventoryMaterialSummary::getZoneCode, zone.getCode()));
        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 TVResult.success(tvBean);
    }

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