Blame view

src/main/java/com/huaheng/pc/system/user/controller/IndexController.java 15.9 KB
tangying authored
1
2
3
4
package com.huaheng.pc.system.user.controller;

import java.util.*;
5
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
tangying authored
6
7
8
9
import com.github.abel533.echarts.Option;
import com.github.abel533.echarts.axis.Axis;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
xqs authored
10
import com.github.abel533.echarts.code.*;
tangying authored
11
12
13
14
15
16
17
18
import com.github.abel533.echarts.json.GsonUtil;
import com.github.abel533.echarts.series.Line;
import com.github.abel533.echarts.series.Pie;
import com.github.abel533.echarts.style.itemstyle.Normal;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper;
19
20
import com.huaheng.pc.system.notice.domain.SysNotice;
import com.huaheng.pc.system.notice.service.SysNoticeService;
tangying authored
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
import com.huaheng.pc.system.user.domain.ChartData;
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 com.huaheng.framework.config.HuaHengConfig;
import com.huaheng.framework.web.controller.BaseController;
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 org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 首页 业务处理
 * 
 * @author huaheng
 */
@Controller
public class IndexController extends BaseController
{
    @Autowired
    private IMenuService menuService;

    @Autowired
    private HuaHengConfig huahengConfig;
48
49
    @Resource
    private SysNoticeService noticeService;
tangying authored
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

    @Resource
    ExcelReportMapper mapper;

    @GetMapping("index/getInventoryStatus")
    @ResponseBody
    public String getInventoryStatus(){

        Option option = new Option();
//        option.title("库存状态分布").title().x("center");
        option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)");
        option.legend().setOrient(Orient.vertical);
        option.legend().setRight(10);
        option.legend().setTop(20);
        option.legend().setBottom(10);
        option.legend().setData(new ArrayList<String>());

        Pie pie = new Pie();
        pie.setName("库存状态");
        pie.setType(SeriesType.pie);
        pie.setRadius("70%");
        pie.setCenter(new String[]{"40%","50%"});
        Normal normal = new Normal();
        normal.setFormatter("{b} \n {c} ({d}%)");
        normal.setBarBorderColor("#eee");
        normal.setBorderWidth(1);
        normal.setBorderRadius(4);
        pie.label().normal(normal);
        pie.itemStyle().emphasis().setShadowBlur(10);
        pie.itemStyle().emphasis().setShadowOffsetX(0);
        pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)");
81
        String sql = "SELECT d.dictLabel '状态', i.qty '库存' FROM (SELECT inventorySts ,SUM(qty) qty FROM inventory_detail WHERE warehouseCode = '" + ShiroUtils.getWarehouseCode()+"' GROUP BY inventorySts) i INNER JOIN sys_dict_data d ON i.inventorySts= d.dictValue AND d.warehouseCode = '" + ShiroUtils.getWarehouseCode()+"' ;";
tangying authored
82
83
84
85
        List<LinkedHashMap<String, Object>> results = mapper.selectCommon(sql);
        for(LinkedHashMap<String, Object> item : results){
            ChartData chartData = new ChartData();
            for(Map.Entry<String, Object> entries : item.entrySet()){
xqs authored
86
                if("状态".equals(entries.getKey())){
tangying authored
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
                    option.legend().getData().add(entries.getValue());
                    chartData.setName(entries.getValue().toString());
                }else{
                    chartData.setValue(Convert.toDouble(entries.getValue()));
                }
            }
            pie.data().add(chartData);
        }
        option.series().add(pie);
        return GsonUtil.format(option);
    }

    @GetMapping("index/getCommonData")
    @ResponseBody
    public AjaxResult getCommonData(){
102
        String condition = " and warehouseCode = '" + ShiroUtils.getWarehouseCode() +"'";
tangying authored
103
104
105
106
107
        String bllCount = "SELECT ifnull(sum(t.a),0) 'total' from (\n" +
                "SELECT COUNT(*) 'a' FROM receipt_header WHERE DATEDIFF(NOW(), created)=0 " + condition +
                " UNION \n" +
                "SELECT COUNT(*) 'a' FROM shipment_header WHERE DATEDIFF(NOW(), created)=0 " + condition +
                ") t";
xqs authored
108
109
        String receiptTotal = "SELECT IFNULL(SUM(d.qty),0) 'total' FROM receipt_container_detail d join receipt_container_header h on d.receiptContainerId = h.id WHERE DATEDIFF(NOW(), h.created) = 0 AND d.status > 19 AND h.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ;";
        String shipmentTotal = "SELECT IFNULL(SUM(d.qty),0) 'total' from shipment_container_detail d JOIN shipment_container_header h on d.shippingContainerId = h.id WHERE DATEDIFF(NOW(), h.created) = 0 AND h.status > 19 AND h.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ;";
110
111
        String inventoryTotal = "SELECT IFNULL(SUM(totalQty),0) 'total' from inventory_header where 1=1 " + condition;
        String materialCount = "SELECT count(DISTINCT materialSkuQty) 'total' from inventory_header WHERE 1=1" + condition;
112
        String taskUncompletedTotal = "SELECT COUNT(*) 'total' from task_detail WHERE status < 100 " + condition;
tangying authored
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

        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("index/getShipmentsLast7Days")
    @ResponseBody
    public String getShipmentsLast7Days(){
        String sql = "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\n" +
                ") a left join (\n" +
155
                "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from shipment_container_detail d join shipment_container_header h on d.shippingContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND h.status=30 GROUP BY DATE(h.created)\n" +
tangying authored
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
                ") b on a.click_date = b.created ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql);

        sql = "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\n" +
                ") a left join (\n" +
175
                "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from receipt_container_detail d join receipt_container_header h on d.receiptContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND d.status=30 GROUP BY DATE(h.created)\n" +
tangying authored
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                ") b on a.click_date = b.created ORDER BY a.click_date;";
        List<LinkedHashMap<String, Object>> list2 = mapper.selectCommon(sql);

        Option option = new Option();
//        option.title("七日发货量");
        option.tooltip().trigger(Trigger.axis).axisPointer().type(PointerType.cross);
        option.grid().setLeft("3%");
        option.grid().setRight("4%");
        option.grid().setBottom("3%");
        option.grid().containLabel(true);
        option.legend().data().add("收货量");
        option.legend().data().add("发货量");
        Map<Object, Object> map = new HashMap<>();
        Axis axis = new CategoryAxis() ;
        axis.boundaryGap(false);
        Line line = new Line();
        line.setName("发货量");
        for(LinkedHashMap<String, Object> item : list){
            Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator();
            Object o1 = iterator.next().getValue();
            Object o2 = iterator.next().getValue();
            axis.data().add(o1);
            line.data().add(o2);
        }
        Line line2 = new Line();
        line2.setName("收货量");
        for(LinkedHashMap<String, Object> item : list2){
            Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator();
            Object o1 = iterator.next().getValue();
            Object o2 = iterator.next().getValue();
            line2.data().add(o2);
        }

        option.setxAxis(Arrays.asList(axis));
        ValueAxis yAxis = new ValueAxis();
        option.setyAxis(Arrays.asList(yAxis));
        option.series(line,line2);
        return GsonUtil.format(option);
    }

    @GetMapping("index/getInventoryProp")
    @ResponseBody
    public String getInventoryProp(){
219
        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" +
tangying authored
220
221
222
223
224
225
226
227
228
229
230
                "GROUP BY m.`name` ORDER BY total desc;";
        List<LinkedHashMap<String, Object>> results = mapper.selectCommon(sql);

        Option option = new Option();
//        option.title("库存状态分布").title().x("center");
        option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)");
        option.legend().setOrient(Orient.vertical);
        option.legend().setRight(10);
        option.legend().setTop(10);
        option.legend().setBottom(10);
        option.legend().setData(new ArrayList<String>());
xqs authored
231
232
        option.legend().setType(LegendType.scroll);
        // option.legend().setType("scroll");
tangying authored
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

        Pie pie = new Pie();
        pie.setName("库存");
        pie.setType(SeriesType.pie);
        pie.setRadius("55%");
        pie.setCenter(new String[]{"40%","50%"});
        pie.itemStyle().emphasis().setShadowBlur(10);
        pie.itemStyle().emphasis().setShadowOffsetX(0);
        pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)");
        Normal normal = new Normal();
        normal.setFormatter("{b} \n {c} ({d}%)");
        normal.setBarBorderColor("#eee");
        normal.setBorderWidth(1);
        normal.setBorderRadius(4);
        pie.label().normal(normal);

        int i = 0;
        Map<String, Boolean> map = new HashMap<>();
        for(LinkedHashMap<String,Object> item : results){
            Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator();
            Object o1 = iterator.next().getValue();
            Object o2 = iterator.next().getValue();
            option.legend().data().add(o1);
            pie.data().add(new ChartData(o1.toString(), Convert.toDouble(o2)));
            if(i<6){
                map.put(o1.toString(),true);
            }else{
                map.put(o1.toString(),false);
            }
            i++;
        }
        option.series(pie);
        option.legend().setSelected(map);
        return GsonUtil.format(option);
    }

    @GetMapping("index/getLocationProp")
    @ResponseBody
    public String getLocationProp(){
272
        String sql = "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";
tangying authored
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
        List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql);

        Option option = new Option();
//        option.title("库存状态分布").title().x("center");
        option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)");
        option.legend().setOrient(Orient.vertical);
        option.legend().setRight(10);
        option.legend().setTop(20);
        option.legend().setBottom(20);
        option.legend().setData(new ArrayList<String>());

        Pie pie = new Pie();
        pie.setName("货位状态");
        pie.setType(SeriesType.pie);
        pie.setRadius("55%");
        pie.setCenter(new String[]{"40%","50%"});
        Normal normal = new Normal();
        normal.setFormatter("{b} \n {c} ({d}%)");
        normal.setBarBorderColor("#eee");
        normal.setBorderWidth(1);
        normal.setBorderRadius(4);
        pie.label().normal(normal);
        pie.itemStyle().emphasis().setShadowBlur(10);
        pie.itemStyle().emphasis().setShadowOffsetX(0);
        pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)");

        for(LinkedHashMap<String,Object> item : list){
            Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator();
            Map.Entry<String, Object> next = iterator.next();
            option.legend().data().add(next.getKey());
            pie.data().add(new ChartData(next.getKey(), Convert.toDouble(next.getValue())));
            next = iterator.next();
            option.legend().data().add(next.getKey());
            pie.data().add(new ChartData(next.getKey(), Convert.toDouble(next.getValue())));
        }

        option.series(pie);
        return GsonUtil.format(option);
    }

    // 系统首页
    @GetMapping("/index")
315
    public String index(ModelMap mmap) {
tangying authored
316
317
318
319
320
        // 取身份信息
        User user = getUser();
        // 根据用户id取出菜单
        List<Menu> menus = menuService.selectPCMenusByUserId(user.getId());
        mmap.put("menus", menus);
321
        System.out.println(menus);
tangying authored
322
323
        mmap.put("user", user);
        mmap.put("copyrightYear", huahengConfig.getCopyrightYear());
324
        mmap.put("notices", noticeService.getMyNotice(0));
tangying authored
325
326
327
328
329
330
331
332
333
334
335
336
        return "index";
    }

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

}