#
luxiaotao1123
2021-03-06 8e13b1cf8fd11809837fa2c958d608a1c38732db
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
package zy.cloud.wms.manager.controller;
 
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 zy.cloud.wms.manager.entity.WrkSts;
import zy.cloud.wms.manager.service.WrkStsService;
 
import java.util.List;
import java.util.Map;
import java.util.Optional;
 
/**
 * Created by vincent on 2021/3/5
 */
@RestController
@RequestMapping("console")
public class ConsoleController extends BaseController {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private WrkStsService wrkStsService;
 
    /**
     * 当天数据:select * from tableName where datediff(day, 字段名,getdate())=0
     * 本周数据:select * from tableName where datediff(week, 字段名,getdate())=0
     * 本月:select * from tableName where datediff(month, 字段名,getdate())=0
     * 本季度:内select * from tableName where datediff(quarter, 字段名,getdate())=0
     * 本年:select * from tableName where datediff(year, 字段名,getdate())=0
     */
    @RequestMapping(value = "/header/auth")
    public R header() {
        Integer combQtyDay = jdbcTemplate.queryForObject("select count(*) from man_comb where datediff(day, create_time, getdate())=0", Integer.class);
        Integer combQty = jdbcTemplate.queryForObject("select count(*) from man_comb", Integer.class);
 
        Integer matQty = jdbcTemplate.queryForObject("select count(*) from man_mat", Integer.class);
        Integer nodeQty = jdbcTemplate.queryForObject("select count(*) from man_node where type = 3", Integer.class);
 
        Integer pakoutQty = jdbcTemplate.queryForObject("select count(*) from man_pakout", Integer.class);
        Integer pakoutQtyMonth = jdbcTemplate.queryForObject("select count(*) from man_pakout where datediff(month, create_time, getdate())=0", Integer.class);
 
        Integer usersQty = jdbcTemplate.queryForObject("select count(*) from sys_user", Integer.class);
        Integer deptQty = jdbcTemplate.queryForObject("select count(*) from sys_dept", Integer.class);
 
        return R.ok().add(Cools
                .add("combQtyDay", Optional.ofNullable(combQtyDay).orElse(0)) // 组托数量(当天)
                .add("combQty", Optional.ofNullable(combQty).orElse(0)) // 组托数量
 
                .add("matQty", Optional.ofNullable(matQty).orElse(0)) // 物料数量
                .add("nodeQty", Optional.ofNullable(nodeQty).orElse(0)) // 货位数量
 
                .add("pakoutQty", Optional.ofNullable(pakoutQty).orElse(0)) // 总出库单数
                .add("pakoutQtyMonth", Optional.ofNullable(pakoutQtyMonth).orElse(0)) // 出库单数(当月)
 
                .add("usersQty", Optional.ofNullable(usersQty).orElse(0)) // 用户数量
                .add("deptQty", Optional.ofNullable(deptQty).orElse(0)) // 部门数量
        );
    }
 
    @RequestMapping(value = "/body/auth")
    public R body() {
        // 组托
        List<Map<String, Object>> combList = jdbcTemplate.queryForList("select top 10 * from man_comb where 1=1 order by create_time desc");
        for (int i=0;i<combList.size();i++) {
            Object create_time = combList.get(i).get("create_time");
            combList.get(i).put("time", String.valueOf(create_time).substring(11, 16));
            combList.get(i).put("active", i<3?"active":"");
        }
        // 拣货单
        List<Map<String, Object>> pakoutList = jdbcTemplate.queryForList("select top 5 * from man_pakout where 1=1 order by create_time desc");
        for (int i=0;i<pakoutList.size();i++) {
            pakoutList.get(i).put("no", i+1);
            String wrk_sts = String.valueOf(pakoutList.get(i).get("wrk_sts"));
            switch (wrk_sts) {
                case "1":
                    pakoutList.get(i).put("style", "text-warning");
                    break;
                case "2":
                    pakoutList.get(i).put("style", "text-danger");
                    break;
                case "3":
                    pakoutList.get(i).put("style", "text-success");
                    break;
                default:
                    pakoutList.get(i).put("style", "text-info");
                    break;
            }
            WrkSts wrkSts = wrkStsService.selectById(Integer.parseInt(wrk_sts));
            if (null != wrkSts) {
                pakoutList.get(i).put("wrkStsName", wrkSts.getStsName());
            }
        }
        // 安全库存警告
        List<Map<String, Object>> safeQuaList = jdbcTemplate.queryForList("select \n" +
                "top 10\n" +
                "mp.node_id,\n" +
                "mp.node_name,\n" +
                "mp.matnr,\n" +
                "mp.maktx,\n" +
                "mp.safe_qua,\n" +
                "mld.anfme,\n" +
                "(mp.safe_qua - mld.anfme) as dValue\n" +
                "from man_prior mp\n" +
                "left join \n" +
                "(select SUM(anfme) as anfme, node_id from man_loc_detl where 1=1 group by node_id) mld on mp.node_id = mld.node_id\n" +
                "where 1=1 \n" +
                "order by (mp.safe_qua - mld.anfme) desc");
        for (int i=0;i<safeQuaList.size();i++) {
            safeQuaList.get(i).put("no", i+1);
        }
 
        return R.ok().add(Cools
                .add("combList", combList) // 组托最新动态
                .add("pakoutList", pakoutList) // 最新拣货单
                .add("safeQuaList", safeQuaList) // 安全库存警告
        );
    }
 
}