#
mrzhssss
2022-03-24 4c1e8761e3fa0516d5e6d316e838e83c8e0f5edf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
171
package zy.cloud.wms.manager.controller;
 
import com.core.common.Arith;
import com.core.common.Cools;
import com.core.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zy.cloud.wms.common.web.BaseController;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2021/8/28
 */
@RestController
@RequestMapping("datav")
public class DatavController extends BaseController {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    /**
     * 页面头部数据
     * 入库总量 出库总量 在库数量 订单数量 商品总量 货位总数 客户数量 用户数量 操作次数
     */
    @RequestMapping(value = "/head/auth")
    public R head(){
        // 入库量
        Integer pakin = jdbcTemplate.queryForObject("select ISNULL(sum(anfme),0) from man_pakin", Integer.class);
        // 出库量
        Integer pakout = jdbcTemplate.queryForObject("select ISNULL(sum(anfme),0) from man_pakout", Integer.class);
        // 在库数量
        Integer locDetl = jdbcTemplate.queryForObject("select ISNULL(sum(anfme),0) from man_loc_detl", Integer.class);
        // 订单数量
        Integer order = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from man_order", Integer.class);
        // 商品总量
        Integer mat = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from man_mat", Integer.class);
        // 货位总数
        Integer node = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from man_node where type = 3", Integer.class);
        // 客户数量
        Integer cstmr = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from man_cstmr", Integer.class);
        // 用户数量
        Integer user = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from sys_user", Integer.class);
        // 操作次数
        Integer opt = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from sys_operate_log", Integer.class);
        return R.ok().add(Cools
                .add("pakin", pakin)
                .add("pakout", pakout)
                .add("locDetl", locDetl)
                .add("order", order)
                .add("mat", mat)
                .add("node", node)
                .add("cstmr", cstmr)
                .add("user", user)
                .add("opt", opt)
        );
    }
 
    /**
     * 页面左侧数据
     * 库存倒叙排序
     */
    @RequestMapping(value = "/left/auth")
    public R left(){
        List<Map<String, Object>> result = jdbcTemplate.queryForList("select top 9 * from (\n" +
                "select \n" +
                "distinct matnr, maktx as name,\n" +
                "ISNULL(sum(anfme),0) as value\n" +
                "from man_loc_detl\n" +
                "where 1=1\n" +
                "group by matnr, maktx\n" +
                ") r\n" +
                "order by value desc");
        return R.ok().add(result);
    }
 
    /**
     * 订单出库商品倒叙占比图 - 饼图
     */
    @RequestMapping(value = "/rose/chart/auth")
    public R matOutOrderSort(){
        List<Map<String, Object>> result = jdbcTemplate.queryForList("select\n" +
                "top 9 \n" +
                "matnr as name1,\n" +
                "maktx as name,\n" +
                "ISNULL(sum(anfme),0) as value\n" +
                "from man_pakout\n" +
                "where 1=1\n" +
                "and wrk_sts = 3\n" +
                "group by matnr,maktx\n" +
                "order by value desc");
        for (Map<String, Object> map : result) {
            map.put("name", String.valueOf(map.get("name")).substring(0, 5));
        }
        // 随机打乱
        Collections.shuffle(result);
        return R.ok().add(result);
    }
 
    /**
     * 水占比数据
     */
    @RequestMapping(value = "/water/level/auth")
    public R waterLevel(){
        // 已使用库位
        Integer usedNode = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from (select distinct node_id from man_loc_detl) t\n", Integer.class);
        // 货位总数
        int node = jdbcTemplate.queryForObject("select ISNULL(count(1),0) from man_node where type = 3", Integer.class);
        double percentage;
        if (node == 0) {
            percentage = 0.0D;
        } else {
            // 占比
            percentage = Arith.divides(3, usedNode, node);
        }
        percentage = Arith.multiplys(1, percentage, 100);
        return R.ok().add(Cools
                .add("usedNode", usedNode)
                .add("node", node)
                .add("percentage", new Double[]{percentage})
        );
    }
 
    /**
     * 最新操作记录
     */
    @RequestMapping(value = "/opt/latest/auth")
    public R optLatest(){
        List<Map<String, Object>> result = jdbcTemplate.queryForList("select top 10 * from (\n" +
                "\tselect create_time, matnr, maktx, anfme, '入库' as type from man_pakin where 1=1 \n" +
                "\tunion\n" +
                "\tselect create_time, matnr, maktx, anfme, '出库' as type from man_pakout where 1=1 \n" +
                ") t order by create_time desc");
        List<List<String>> res = new ArrayList<>();
        for (Map<String, Object> map : result) {
            List<String> list = new ArrayList<>();
            list.add(String.valueOf(map.get("create_time")).substring(0, 19));
//            list.add(String.valueOf(map.get("matnr")));
            list.add(String.valueOf(map.get("maktx")));
            list.add(String.valueOf((int)Double.parseDouble(String.valueOf(map.get("anfme")))));
            list.add(String.valueOf(map.get("type")));
            res.add(list);
        }
        return R.ok().add(res);
    }
 
    /**
     * 底部订单卡片排序
     */
    @RequestMapping(value = "/order/card/auth")
    public R orderCard(){
        List<Map<String, Object>> orders = jdbcTemplate.queryForList("select \n" +
                "top 5\n" +
                "order_id,\n" +
                "sum(anfme) as count\n" +
                "from man_order_detl\n" +
                "group by order_id\n" +
                "order by count desc");
        for (Map<String, Object> map : orders) {
 
        }
        return R.ok().add(orders);
    }
 
 
}