BigScreenController.java 5.29 KB
package com.huaheng.api.general.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.api.wcs.domain.WcsTasksInfo;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.system.user.controller.IndexController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

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

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

    @PostMapping("/bigScreen")
    private JSON BigScreenData(){

        Map<String,Object> data = (Map<String,Object>)indexController.getCommonData().getData();

        String sql = "SELECT m.`name`,sum(i.qty) as total from inventory_detail i join material m on i.materialCode = m.`code` and i.warehouseCode = m.warehouseCode AND i.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' \n" +
                "GROUP BY m.`name` ORDER BY total desc;";
        List<LinkedHashMap<String, Object>> getInventoryProp = mapper.selectCommon(sql);

        String sql1 = "SELECT (SELECT count(1) FROM location WHERE\tIFNULL(containerCode,'') !='' AND warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ) as '有货', (SELECT count(1) FROM location WHERE\tIFNULL(containerCode,'') ='' AND warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ) as '无货'  from DUAL";

        List<LinkedHashMap<String, Object>> locationProp = mapper.selectCommon(sql1);

        String sql2 = "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" +
                " FROM (\n" +
                " SELECT curdate() as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 1 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 2 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 3 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 4 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 5 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 6 day) as click_date ) a\n" +
                " LEFT JOIN (\n" +
                " SELECT DATE(h.completeTime) AS completeTime , SUM(d.qty) AS taskQty\n" +
                " FROM task_detail d join task_header h\n" +
                " ON d.taskId = h.id and h.warehouseCode='CS0001'\n" +
                " WHERE h.completeTime >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND h.status=100 and h.taskType=300 GROUP BY DATE(h.completeTime)) b\n" +
                " ON a.click_date = b.completeTime ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> receiptNum = mapper.selectCommon(sql2);

        String sql3 =  "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" +
                " FROM (\n" +
                " SELECT curdate() as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 1 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 2 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 3 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 4 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 5 day) as click_date\n" +
                " UNION all\n" +
                " SELECT date_sub(curdate(), interval 6 day) as click_date ) a\n" +
                " LEFT JOIN (\n" +
                " SELECT DATE(h.completeTime) AS completeTime , SUM(d.qty) AS taskQty\n" +
                " FROM task_detail d join task_header h\n" +
                " ON d.taskId = h.id and h.warehouseCode='CS0001'\n" +
                " WHERE h.completeTime >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND h.status=100 and h.taskType=100 GROUP BY DATE(h.completeTime)) b\n" +
                " ON a.click_date = b.completeTime ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> shipmentNum = mapper.selectCommon(sql3);

//        List<WcsTasksInfo> itemReceipts = indexController.itemReceipts();
//        List<WcsTasksInfo> itemShipments = indexController.itemShipments();
        JSONObject jsonObject=new JSONObject();

        jsonObject.put("CommonData",data);
        jsonObject.put("inventoryProp",getInventoryProp);
        jsonObject.put("locationProp",locationProp);
        jsonObject.put("receiptNum",receiptNum);
        jsonObject.put("shipmentNum",shipmentNum);
//        jsonObject.put("itemReceipts",itemReceipts);
//        jsonObject.put("itemShipments",itemShipments);
        return jsonObject;
    }
}