HomeController.java 10.6 KB
package com.huaheng.pc.system.user.controller;

import com.huaheng.framework.config.HuaHengConfig;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.system.menu.domain.Menu;
import com.huaheng.pc.system.menu.service.IMenuService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("/admin")
public class HomeController extends BaseController {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private HuaHengConfig huahengConfig;
    @Resource
    ExcelReportMapper mapper;

    @Autowired
    private ReceiptDetailService receiptDetailService;
    @Autowired
    private ShipmentDetailService shipmentDetailService;
    @Autowired
    private LocationService locationService;
    @Autowired
    private InventoryDetailService InventoryDetailService;
    @Autowired
    private WarehouseService warehouseService;
    @Autowired
    private CompanyService companyService;



    private String prefix = "admin";

    //6个显示后台
    @GetMapping("home/getCommonData")
    @ResponseBody
    public AjaxResult getCommonData(){
//        String condition = " and warehouseId = " + ShiroUtils.getWarehouseId();
        String bllCount = "SELECT ifnull(sum(t.a),0) 'total' from (\n" +
                "SELECT COUNT(*) 'a' FROM receipt_header WHERE DATEDIFF(NOW(), created)=0 "  +
                " UNION \n" +
                "SELECT COUNT(*) 'a' FROM shipment_header WHERE DATEDIFF(NOW(), created)=0 " +
                ") t";
        String receiptTotal = "SELECT ifnull(sum(t.qty),0) 'total' from task_detail t\n" +
                "inner join receipt_header r on t.billCode=r.code and\n" +
                "t.status>100 and DATEDIFF(NOW(), t.lastUpdated)=0;";
        String shipmentTotal = "SELECT ifnull(sum(t.qty),0) 'total' from task_detail t\n" +
                "inner join shipment_header s on t.billCode=s.code and\n" +
                "t.status>100 and DATEDIFF(NOW(), t.lastUpdated)=0;";
        String inventoryTotal = "SELECT IFNULL(SUM(qty),0) 'total' from inventory_detail where 1=1 " ;
        String materialCount = "SELECT count(DISTINCT materialCode) 'total' from inventory_detail WHERE 1=1";
        String taskUncompletedTotal = "SELECT COUNT(*) 'total' from task_header WHERE status < 100 " ;

        Map<String, Object> map = new HashMap<>();
        List<LinkedHashMap<String, Object>> temp1 = mapper.selectCommon(bllCount);
        map.put("bllCount",temp1.get(0).entrySet().iterator().next().getValue());

        List<LinkedHashMap<String, Object>> temp2 = mapper.selectCommon(receiptTotal);
        map.put("receiptTotal",temp2.get(0).entrySet().stream().findFirst().get().getValue());

        List<LinkedHashMap<String, Object>> temp3 = mapper.selectCommon(shipmentTotal);
        map.put("shipmentTotal",temp3.get(0).entrySet().stream().findFirst().get().getValue());

        List<LinkedHashMap<String, Object>> temp4 = mapper.selectCommon(inventoryTotal);
        map.put("inventoryTotal",temp4.get(0).entrySet().stream().findFirst().get().getValue());

        List<LinkedHashMap<String, Object>> temp5 = mapper.selectCommon(materialCount);
        map.put("materialCount",temp5.get(0).entrySet().stream().findFirst().get().getValue());

        List<LinkedHashMap<String, Object>> temp6 = mapper.selectCommon(taskUncompletedTotal);
        map.put("taskUncompletedTotal",temp6.get(0).entrySet().stream().findFirst().get().getValue());

        return AjaxResult.success(map);
    }

    //库龄展示
    @GetMapping("home/getInventoryStatus")
    @ResponseBody
    public AjaxResult getInventoryStatus(String type){
        List<Map<String, Object>> list=new ArrayList<>();
        if("1".equals(type)) {
            Warehouse warehouse=new Warehouse();
            List<Warehouse> warehouseList=warehouseService.selectListEntityByEqual(warehouse);
            for(Warehouse item:warehouseList) {
                List<String> list1=new ArrayList<>();
                Integer a=0;
                Integer b=3;
                String  num1 = InventoryDetailService.getWarehouseInventoryStatus(item.getCode(),a,b);
                list1.add(num1);
                 a=3;
                 b=6;
                String  num2 = InventoryDetailService.getWarehouseInventoryStatus(item.getCode(),a,b);
                list1.add(num2);
                 a=6;
                 b=9;
                String  num3 = InventoryDetailService.getWarehouseInventoryStatus(item.getCode(),a,b);
                list1.add(num3);
                 a=9;
                 b=12;
                String  num4 = InventoryDetailService.getWarehouseInventoryStatus(item.getCode(),a,b);
                list1.add(num4);
                 a=12;
                String  num5 = InventoryDetailService.getWarehouseInventoryStatuss(item.getCode(),a);
                list1.add(num5);
               Map map=new ModelMap();
               map.put("warehouseName",item.getName());
               map.put("list1",list1);
               list.add(map);
            }
        }else {
            Company company=new Company();
            List<Company> companyList=companyService.selectListEntityByEqual(company);
            for(Company item:companyList) {
                List<String> list1=new ArrayList<>();
                Integer a=0;
                Integer b=3;
                String  num1 = InventoryDetailService.getCompanyInventoryStatus(item.getCode(),a,b);
                list1.add(num1);
                a=3;
                b=6;
                String  num2 = InventoryDetailService.getCompanyInventoryStatus(item.getCode(),a,b);
                list1.add(num2);
                a=6;
                b=9;
                String  num3 = InventoryDetailService.getCompanyInventoryStatus(item.getCode(),a,b);
                list1.add(num3);
                a=9;
                b=12;
                String  num4 = InventoryDetailService.getCompanyInventoryStatus(item.getCode(),a,b);
                list1.add(num4);
                a=12;
                String  num5 = InventoryDetailService.getCompanyInventoryStatuss(item.getCode(),a);
                list1.add(num5);
                Map map=new ModelMap();
                map.put("companyName",item.getName());
                map.put("list1",list1);
                list.add(map);
            }
        }
    return AjaxResult.success(list);
    }

    //获得七天的出入库量
    @GetMapping("home/getShipmentsLast7Days")
    @ResponseBody
    public AjaxResult getQtyLast7Days(String type){
        List<TaskDetail> receiptDetails=new ArrayList<>();
        List<TaskDetail> shipmentDetails=new ArrayList<>();
        Map map=new ModelMap();
        if("1".equals(type)) {
            receiptDetails = receiptDetailService.getReceiptQtyLast7Days();
            shipmentDetails = shipmentDetailService.getShipmentQtyLast7Days();
        }
        if("2".equals(type)){
            receiptDetails =receiptDetailService.getWarehouseReceipt();
            shipmentDetails=shipmentDetailService.getWarehouseShipment();
        }
        if("3".equals(type)){
            receiptDetails =receiptDetailService.getCompanyReceipt();
            shipmentDetails=shipmentDetailService.getCompanyShipment();
        }
        map.put("receiptDetails", receiptDetails);
        map.put("shipmentDetails", shipmentDetails);
        return AjaxResult.success(map);
    }

    //库存分布
    @GetMapping("home/getInventoryProp")
    @ResponseBody
    public AjaxResult getInventoryProp(String type){
        List<Map<String, Object>> list=new ArrayList<>();
        if("1".equals(type)) {
            Warehouse warehouse=new Warehouse();
            List<Warehouse> warehouseList=warehouseService.selectListEntityByEqual(warehouse);
            for(Warehouse item:warehouseList) {
                List<LinkedHashMap<String, Object>>  list1 = InventoryDetailService.getWarehouseInventoryProp(item.getCode());
                Map map=new ModelMap();
                if(list1!=null && list1.size()>0) {
                    map.put("warehouseName",item.getName());
                    map.put("list1", list1);
                    list.add(map);
                }
            }
        }else {
            Company company=new Company();
            List<Company> companyList=companyService.selectListEntityByEqual(company);
            for(Company item:companyList) {
                List<LinkedHashMap<String, Object>>  list1 = InventoryDetailService.getCompanyInventoryProp(item.getCode());
                Map map=new ModelMap();
                if(list1!=null && list1.size()>0){
                    map.put("companyName",item.getName());
                    map.put("list1",list1);
                    list.add(map);
                }
            }
        }
        System.out.println(list);
        return AjaxResult.success(list);
    }

    //库位利用率
    @GetMapping("home/getLocationProp")
    @ResponseBody
    public AjaxResult getLocationProp(){
        List<LinkedHashMap<String, Object>> list =locationService.getLocationProp();
        return AjaxResult.success(list);
    }

    @GetMapping("/home")
    public String home(ModelMap mmap)
    {
        // 取身份信息
        User user = getUser();
        // 根据用户id取出菜单
        List<Menu> menus = menuService.selectMenusByUserId(user.getId());
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", huahengConfig.getCopyrightYear());
        return prefix + "/home";
    }


    // 系统介绍
    @GetMapping("/main")
    public String main(ModelMap mmap) {
        mmap.put("version", huahengConfig.getVersion());
        return prefix + "/main";
    }
}