BigScreenController.java 8.05 KB
package com.huaheng.api.tv.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.api.tv.domain.BigScreenTask;
import com.huaheng.api.tv.service.BigScreenService;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.system.user.controller.IndexController;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
public class BigScreenController {
    @Resource
    private IndexController indexController;
    @Resource
    ExcelReportMapper mapper;
    @Resource
    private BigScreenService bigScreenService;


    @CrossOrigin
    @RequestMapping("/mainA")
    private JSON mainA() {
        return BigScreenData("A");
    }

    @CrossOrigin
    @RequestMapping("/mainB")
    private JSON mainB() {
        return BigScreenData("B");
    }

    @CrossOrigin
    @RequestMapping("/mainC")
    private JSON mainC() {
        return BigScreenData("C");
    }

    //主看板

    private JSON BigScreenData(String zone) {
        JSONObject jsonObject = new JSONObject();
        //左上方
        Map<String, Object> upperLeft = (Map<String, Object>) upperLeft(zone).getData();
        jsonObject.put("upperLeft", upperLeft);

        //右上方
        Map<String, Object> upperRight = (Map<String, Object>) upperRight(zone).getData();
        jsonObject.put("upperRight", upperRight);

        //右下方
        Map<String, Object> bottomRight = (Map<String, Object>) bottomRight(zone).getData();
        jsonObject.put("bottomRight", bottomRight);
        return jsonObject;
    }


    //左上方
    public AjaxResult upperLeft(String zone) {
        Map<String, Object> map = new HashMap<>();
        //库位利用率(矮库位有货、矮库位无货、高库位有货、高库位无货)
        String sql1 = "SELECT\n" +
                "SUM(CASE WHEN zoneCode='" + zone + "' AND warehouseCode = 'CS0001' AND containerCode !='' AND high = 0 THEN 1 ELSE 0 END) AS 'lowInStock',\n" +
                "SUM(CASE WHEN zoneCode='" + zone + "' AND warehouseCode = 'CS0001' AND containerCode ='' AND high = 0 THEN 1 ELSE 0 END) AS 'lowSoldOut',\n" +
                "SUM(CASE WHEN zoneCode='" + zone + "' AND warehouseCode = 'CS0001' AND containerCode !='' AND high = 1 THEN 1 ELSE 0 END) AS 'highInStock',\n" +
                "SUM(CASE WHEN zoneCode='" + zone + "' AND warehouseCode = 'CS0001' AND containerCode ='' AND high = 1 THEN 1 ELSE 0 END) AS 'highSoldOut'\n" +
                "FROM location;";
        List<LinkedHashMap<String, Object>> locationProportion = mapper.selectCommon(sql1);
        map.put("locationProportion", locationProportion);


        //库存物料
        String sql2 = "SELECT m.`name`,sum(i.qty) as total from inventory_detail i join material m on i.materialCode = m.`code`  and zoneCode='" + zone + "' and i.warehouseCode = m.warehouseCode AND i.warehouseCode = '" + ShiroUtils.getWarehouseCodeCS0001() + "' \n" +
                "GROUP BY m.`name` ORDER BY total desc;";
        List<LinkedHashMap<String, Object>> inventoryMaterial = mapper.selectCommon(sql2);
        map.put("inventoryMaterial", inventoryMaterial);


        //空托盘
        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;";
        }
        List<LinkedHashMap<String, Object>> emptyPallet = mapper.selectCommon(sql3);
        map.put("emptyPallet", emptyPallet);

        return AjaxResult.success(map);
    }


    //右下方
    public AjaxResult bottomRight(String zone) {
        Map<String, Object> map = new HashMap<>();
        //出入库任务
        List<BigScreenTask> receiptTasks = bigScreenService.selectReceiptTask(zone);
        List<BigScreenTask> shipmentTasks = bigScreenService.selectShipmentTask(zone);
        map.put("receiptTasks", receiptTasks);
        map.put("shipmentTasks", shipmentTasks);
        return AjaxResult.success(map);
    }

    //右上方
    public AjaxResult upperRight(String zone) {
        String condition = " and warehouseCode = '" + ShiroUtils.getWarehouseCodeCS0001() + "'";
        Map<String, Object> map = new HashMap<>();

        //库存交易量
        String bllCount = "select ifnull(sum( d.qty ),0) 'total' FROM task_header h join task_detail d on h.id =d.taskId WHERE DATEDIFF(NOW(), h.completeTime) = 0 and (h.taskType=100 or h.taskType=200 or h.taskType=300 or h.taskType=400) and h.zoneCode='" + zone + "' and h.status=100";
        List<LinkedHashMap<String, Object>> temp1 = mapper.selectCommon(bllCount);
        map.put("bllCount", temp1.get(0).entrySet().iterator().next().getValue());

        //今日入库量
        String receiptTotal = "select ifnull(sum( d.qty ),0) 'total' FROM task_header h join task_detail d on h.id =d.taskId WHERE DATEDIFF(NOW(), h.completeTime) = 0 and (h.taskType=100 or h.taskType=200) and h.zoneCode='" + zone + "' and  h.status=100";
        List<LinkedHashMap<String, Object>> temp2 = mapper.selectCommon(receiptTotal);
        map.put("receiptTotal", temp2.get(0).entrySet().stream().findFirst().get().getValue());

        //今日出库量
        String shipmentTotal = "select ifnull(sum( d.qty ),0) 'total' FROM task_header h join task_detail d on h.id =d.taskId WHERE DATEDIFF(NOW(), h.completeTime) = 0 and (h.taskType=300 or h.taskType=400) and h.zoneCode='" + zone + "' and h.status=100";
        List<LinkedHashMap<String, Object>> temp3 = mapper.selectCommon(shipmentTotal);
        map.put("shipmentTotal", temp3.get(0).entrySet().stream().findFirst().get().getValue());

        //库存总量
        String inventoryTotal = "SELECT IFNULL(SUM(totalQty),0) 'total' from inventory_header  where 1=1  and zoneCode='" + zone + "'";
        List<LinkedHashMap<String, Object>> temp4 = mapper.selectCommon(inventoryTotal);
        map.put("inventoryTotal", temp4.get(0).entrySet().stream().findFirst().get().getValue());


        //空闲库位数
        String availableLocationCount = "SELECT COUNT(*) 'total' from location where containerCode is null or trim(containerCode)='' and zoneCode='" + zone + "' and status='empty'";
        List<LinkedHashMap<String, Object>> temp5 = mapper.selectCommon(availableLocationCount);
        map.put("availableLocationCount", temp5.get(0).entrySet().stream().findFirst().get().getValue());


        //未完成任务
        String taskUncompletedTotal = "SELECT ifnull(COUNT(*),0) 'total' from task_header  WHERE zoneCode='" + zone + "' and  status < 100";
        List<LinkedHashMap<String, Object>> temp6 = mapper.selectCommon(taskUncompletedTotal);
        map.put("taskUncompletedTotal", temp6.get(0).entrySet().stream().findFirst().get().getValue());


        //String materialCount = "SELECT ifnull(count(DISTINCT materialCode),0) 'total'  from inventory_detail  WHERE h.zoneCode='" + zone + "'";
        //List<LinkedHashMap<String, Object>> temp7 = mapper.selectCommon(materialCount);
        //map.put("materialCount", temp7.get(0).entrySet().stream().findFirst().get().getValue());

        return AjaxResult.success(map);
    }
}