Blame view

src/main/java/com/huaheng/pc/system/user/controller/HomeController.java 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
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;
pengcheng authored
20
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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(type.equals("1")) {
            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){
pengcheng authored
171
172
        List<TaskDetail> receiptDetails=new ArrayList<>();
        List<TaskDetail> shipmentDetails=new ArrayList<>();
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
        Map map=new ModelMap();
        if(type.equals("1")) {
            receiptDetails = receiptDetailService.getReceiptQtyLast7Days();
            shipmentDetails = shipmentDetailService.getShipmentQtyLast7Days();
        }
        if(type.equals("2")){
            receiptDetails =receiptDetailService.getWarehouseReceipt();
            shipmentDetails=shipmentDetailService.getWarehouseShipment();
        }
        if(type.equals("3")){
            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(type.equals("1")) {
            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();
pengcheng authored
202
203
204
205
                if(list1!=null && list1.size()>0) {
                    map.put("warehouseName",item.getName());
                    map.put("list1", list1);
                    list.add(map);
206
207
208
209
210
211
212
213
                }
            }
        }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();
pengcheng authored
214
215
                if(list1!=null && list1.size()>0){
                    map.put("companyName",item.getName());
216
                    map.put("list1",list1);
pengcheng authored
217
                    list.add(map);
218
219
220
                }
            }
        }
221
        System.out.println(list);
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
        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";
    }
}