#
vincentlu
2025-01-13 9d803fd9429f424648adab46d25f6c0bb49747ee
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
package com.zy.acs.manager.manager.controller;
 
import com.zy.acs.common.utils.CoolsQueue;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.manager.manager.service.*;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * Created by vincent on 4/25/2024
 */
@RequestMapping("/digital/charts")
@RestController
public class DigitalChartsController {
 
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
    public static final CoolsQueue<Map> agvChartsQueue = new CoolsQueue<>(Map.class,10);
 
    @Autowired
    private AgvService agvService;
    @Autowired
    private AgvDetailService agvDetailService;
    @Autowired
    private CodeService codeService;
    @Autowired
    private LocService locService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private ActionService actionService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @GetMapping("/actioncount")
    public R actioncount() {
        return R.ok().add(actionService.selectCountGroupByType());
    }
 
    @GetMapping("/agvcharts")
    public R agvcharts() {
        return R.ok().add(agvChartsQueue.data());
    }
 
    @GetMapping("/loccharts")
    public R loccharts() {
        return R.ok().add(locService.selectCountGroupByLocSts());
    }
 
    @GetMapping("/stock/info")
    public R getStockInfo() {
        return R.ok();
    }
 
 
    @GetMapping("/taskcharts")
    public R taskcharts() {
        List<Map<String, Object>> list = taskService.selectStatByLastSevenDays();
 
        LinkedHashSet<String> week = list.stream()
                .map(record -> (String)record.get("weekday"))
                .collect(Collectors.toCollection(LinkedHashSet::new));
 
        List<Map<String, Object>> data = transformDataSimplified(list, week);
 
        List<String> newWeek = new ArrayList<>();
        for (String str : week) {
            switch (str) {
                case "Monday":
                    newWeek.add("周一");
                    break;
                case "Tuesday":
                    newWeek.add("周二");
                    break;
                case "Wednesday":
                    newWeek.add("周三");
                    break;
                case "Thursday":
                    newWeek.add("周四");
                    break;
                case "Friday":
                    newWeek.add("周五");
                    break;
                case "Saturday":
                    newWeek.add("周六");
                    break;
                case "Sunday":
                    newWeek.add("周日");
                    break;
                default:
                    break;
            }
        }
 
        return R.ok().add(Cools.add("week", newWeek).add("data", data));
    }
 
    @GetMapping("/inout")
    public R inout() {
        return R.ok().add(actionService.selectRecentForInout());
    }
 
 
    public List<Map<String, Object>> transformDataSimplified(List<Map<String, Object>> rawData, LinkedHashSet<String> orderedWeekdaysSet) {
        Map<String, Map<String, Integer>> groupedByType = rawData.stream()
                .collect(Collectors.groupingBy(record -> (String) record.get("type"),
                        Collectors.toMap(
                                record -> (String) record.get("weekday"),
                                record -> ((Long) record.get("count")).intValue(),
                                (oldValue, newValue) -> oldValue,
                                LinkedHashMap::new
                        )));
 
        return groupedByType.entrySet().stream().map(entry -> {
            Map<String, Object> taskTypeEntry = new LinkedHashMap<>();
            taskTypeEntry.put("name", entry.getKey());
 
            List<Integer> counts = orderedWeekdaysSet.stream()
                    .map(weekday -> entry.getValue().getOrDefault(weekday, 0))
                    .collect(Collectors.toList());
 
            taskTypeEntry.put("data", counts);
            return taskTypeEntry;
        }).collect(Collectors.toList());
    }
 
 
}