|
|
@@ -80,6 +80,15 @@ public class MesProductController extends BaseController {
|
|
|
@Autowired
|
|
|
private MesProcessAlarmService mesProcessAlarmService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MesRepairService mesRepairService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesScrapService mesScrapService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesQualityService mesQualityService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取数据
|
|
|
*/
|
|
|
@@ -619,6 +628,157 @@ public class MesProductController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 综合大屏 - 当天返修数量 / 报废数量
|
|
|
+ * 返修数据来自 mes_repair(返工记录表),报废数据来自 mes_scrap(报废记录表)
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "dashboardCount")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp<Map<String, Object>> dashboardCount() {
|
|
|
+ CommonResp<Map<String, Object>> resp = new CommonResp<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ String start = today.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
|
|
|
+ String end = today.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
|
|
|
+
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ try {
|
|
|
+ Long repair = mesRepairService.countByDateRange(start, end);
|
|
|
+ Long scrap = mesScrapService.countByDateRange(start, end);
|
|
|
+ map.put("repair", repair == null ? 0 : repair);
|
|
|
+ map.put("scrap", scrap == null ? 0 : scrap);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("dashboardCount error: {}", e.getMessage(), e);
|
|
|
+ map.put("repair", 0);
|
|
|
+ map.put("scrap", 0);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 综合大屏 - 不良类型柱状图:按返工白名单(mes_repair_items.title)分组统计返工次数(默认当天)
|
|
|
+ * 返回 {labels:[], data:[], max: N}
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "defectTypeData")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp<Map<String, Object>> defectTypeData() {
|
|
|
+ CommonResp<Map<String, Object>> resp = new CommonResp<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ String start = today.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
|
|
|
+ String end = today.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
|
|
|
+
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ try {
|
|
|
+ List<Map<String, Object>> rows = mesRepairService.countGroupByItemTitle(start, end);
|
|
|
+ List<String> labels = new ArrayList<>();
|
|
|
+ List<Integer> data = new ArrayList<>();
|
|
|
+ int max = 0;
|
|
|
+ if (rows != null) {
|
|
|
+ for (Map<String, Object> row : rows) {
|
|
|
+ Object t = row.get("title");
|
|
|
+ Object c = row.get("cnt");
|
|
|
+ String title = t == null ? "未分类" : String.valueOf(t);
|
|
|
+ int cnt = c == null ? 0 : ((Number) c).intValue();
|
|
|
+ labels.add(title);
|
|
|
+ data.add(cnt);
|
|
|
+ if (cnt > max) max = cnt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 留 20% 余量,避免最大柱顶到边
|
|
|
+ int yMax = (int) Math.ceil(Math.max(10, max) * 1.2);
|
|
|
+ map.put("labels", labels);
|
|
|
+ map.put("data", data);
|
|
|
+ map.put("max", yMax);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("defectTypeData error: {}", e.getMessage(), e);
|
|
|
+ map.put("labels", new ArrayList<>());
|
|
|
+ map.put("data", new ArrayList<>());
|
|
|
+ map.put("max", 10);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 综合大屏 - 近七日产品抽检盘点:按天统计 mes_quality 的 OK/NG 次数
|
|
|
+ * 返回 {labels:['6月7日',...], qualified:[OK次数...], defect:[NG次数...], max: N}
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "qualityInspectData")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp<Map<String, Object>> qualityInspectData() {
|
|
|
+ CommonResp<Map<String, Object>> resp = new CommonResp<>();
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ try {
|
|
|
+ DateTimeFormatter ymd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter ymdHms = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate start = today.minusDays(6); // 含今天,共7天
|
|
|
+ LocalDate end = today.plusDays(1);
|
|
|
+ String sdate = start.format(ymd) + " 00:00:00";
|
|
|
+ String edate = end.format(ymd) + " 00:00:00";
|
|
|
+
|
|
|
+ List<Map<String, Object>> rows = mesQualityService.countDailyByResult(sdate, edate);
|
|
|
+ // 用 day -> {OK:n, NG:n} 整理
|
|
|
+ java.util.Map<String, int[]> idx = new java.util.HashMap<>();
|
|
|
+ if (rows != null) {
|
|
|
+ for (Map<String, Object> row : rows) {
|
|
|
+ String day = row.get("day") == null ? "" : String.valueOf(row.get("day"));
|
|
|
+ String r = row.get("result") == null ? "" : String.valueOf(row.get("result")).trim().toUpperCase();
|
|
|
+ int cnt = row.get("cnt") == null ? 0 : ((Number) row.get("cnt")).intValue();
|
|
|
+ int[] arr = idx.computeIfAbsent(day, k -> new int[2]); // [ok, ng]
|
|
|
+ if ("OK".equals(r)) {
|
|
|
+ arr[0] += cnt;
|
|
|
+ } else if ("NG".equals(r)) {
|
|
|
+ arr[1] += cnt;
|
|
|
+ }
|
|
|
+ // 其它 result 值忽略,避免污染图表
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> labels = new ArrayList<>();
|
|
|
+ List<Integer> qualified = new ArrayList<>();
|
|
|
+ List<Integer> defect = new ArrayList<>();
|
|
|
+ int max = 0;
|
|
|
+ LocalDate d = start;
|
|
|
+ for (int i = 0; i < 7; i++) {
|
|
|
+ String key = d.format(ymd);
|
|
|
+ int[] arr = idx.getOrDefault(key, new int[2]);
|
|
|
+ labels.add((d.getMonthValue()) + "月" + d.getDayOfMonth() + "日");
|
|
|
+ qualified.add(arr[0]);
|
|
|
+ defect.add(arr[1]);
|
|
|
+ if (arr[0] > max) max = arr[0];
|
|
|
+ if (arr[1] > max) max = arr[1];
|
|
|
+ d = d.plusDays(1);
|
|
|
+ }
|
|
|
+ int yMax = (int) Math.ceil(Math.max(10, max) * 1.2);
|
|
|
+
|
|
|
+ map.put("labels", labels);
|
|
|
+ map.put("qualified", qualified);
|
|
|
+ map.put("defect", defect);
|
|
|
+ map.put("max", yMax);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("qualityInspectData error: {}", e.getMessage(), e);
|
|
|
+ map.put("labels", new ArrayList<>());
|
|
|
+ map.put("qualified", new ArrayList<>());
|
|
|
+ map.put("defect", new ArrayList<>());
|
|
|
+ map.put("max", 10);
|
|
|
+ resp.setData(map);
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
@RequestMapping(value = "indexTj")
|
|
|
@ResponseBody
|
|
|
public CommonResp indexTj( HttpServletRequest req) {
|