| 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()); | 
|     } | 
|   | 
|   | 
| } |