|
|
@@ -77,13 +77,20 @@ public class MesProductController extends BaseController {
|
|
|
private MesShiftService mesShiftService;
|
|
|
@Autowired
|
|
|
private MesProcessAlarmService mesProcessAlarmService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private MesScrapService mesScrapService;
|
|
|
@Autowired
|
|
|
private MesToolLifeService mesToolLifeService;
|
|
|
@Autowired
|
|
|
private MesToolReplaceRecordService mesToolReplaceRecordService;
|
|
|
@Autowired
|
|
|
private MesProcessProductService mesProcessProductService;
|
|
|
+ @Autowired
|
|
|
+ private MesRepairItemsService mesRepairItemsService;
|
|
|
+ @Autowired
|
|
|
+ private MesDeviceAlarmService mesDeviceAlarmService;
|
|
|
+ @Autowired
|
|
|
+ private MesRepairService mesRepairService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -293,8 +300,13 @@ public class MesProductController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = {"screen", ""})
|
|
|
+ @RequestMapping(value = {"screen5", ""})
|
|
|
public String screen(Model model) {
|
|
|
+ return "modules/mes/mesScreen5";
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = {"screen4", ""})
|
|
|
+ public String screen2(Model model) {
|
|
|
return "modules/mes/mesScreen4";
|
|
|
}
|
|
|
|
|
|
@@ -414,7 +426,6 @@ public class MesProductController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@RequestMapping(value = "screenData4")
|
|
|
@ResponseBody
|
|
|
public CommonResp screenData4() {
|
|
|
@@ -438,7 +449,7 @@ public class MesProductController extends BaseController {
|
|
|
|
|
|
MesDevice mesDevice = new MesDevice();
|
|
|
Long deviceNum = mesDeviceService.findCount(mesDevice);
|
|
|
- data.put("devices", 15);
|
|
|
+ data.put("devices", deviceNum);
|
|
|
|
|
|
MesProduct mesProduct1 = new MesProduct();
|
|
|
mesProduct1.setState("1");
|
|
|
@@ -446,29 +457,81 @@ public class MesProductController extends BaseController {
|
|
|
data.put("actual", actualCount);
|
|
|
|
|
|
data.put("plan", 660);
|
|
|
- data.put("repair", 10);
|
|
|
- data.put("scrap", 12);
|
|
|
+ int scrapCount = mesScrapService.findList(new MesScrap()).size();
|
|
|
+ data.put("scrap", scrapCount);
|
|
|
|
|
|
+ // 产线不良率报警统计
|
|
|
List<Map<String, Object>> alarms = new ArrayList<>();
|
|
|
- MesProcessProduct processProductQuery = new MesProcessProduct();
|
|
|
- List<MesProcessProduct> processProductList = mesProcessProductService.findList(processProductQuery);
|
|
|
- logger.info("工位当前产品查询结果数量: " + (processProductList != null ? processProductList.size() : 0));
|
|
|
- int idx = 1;
|
|
|
- for (MesProcessProduct processProduct : processProductList) {
|
|
|
- if (idx > 8) break;
|
|
|
- logger.info("工位: " + processProduct.getOprno() + ", 工件码: " + processProduct.getSn());
|
|
|
- if (StringUtils.isNotEmpty(processProduct.getSn())) {
|
|
|
- Map<String, Object> alarmMap = MapUtils.newHashMap();
|
|
|
- alarmMap.put("id", idx);
|
|
|
- alarmMap.put("msg", processProduct.getOprno() + "-" + processProduct.getSn());
|
|
|
- alarms.add(alarmMap);
|
|
|
- idx++;
|
|
|
+ Calendar todayCal = Calendar.getInstance();
|
|
|
+ todayCal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ todayCal.set(Calendar.MINUTE, 0);
|
|
|
+ todayCal.set(Calendar.SECOND, 0);
|
|
|
+ todayCal.set(Calendar.MILLISECOND, 0);
|
|
|
+ Date todayStart = todayCal.getTime();
|
|
|
+ todayCal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date todayEnd = todayCal.getTime();
|
|
|
+
|
|
|
+ // 查询今日返修记录,按产线统计不同工件码数量
|
|
|
+ MesRepair repairQuery = new MesRepair();
|
|
|
+ repairQuery.setCreateDate_gte(todayStart);
|
|
|
+ repairQuery.setCreateDate_lte(todayEnd);
|
|
|
+ List<MesRepair> repairList = mesRepairService.findList(repairQuery);
|
|
|
+ Map<String, Set<String>> repairSnByLine = new HashMap<>();
|
|
|
+ if (repairList != null) {
|
|
|
+ for (MesRepair repair : repairList) {
|
|
|
+ String lineSn = repair.getLineSn();
|
|
|
+ String sn = repair.getSn();
|
|
|
+ if (StringUtils.isNotEmpty(lineSn) && StringUtils.isNotEmpty(sn)) {
|
|
|
+ repairSnByLine.computeIfAbsent(lineSn, k -> new HashSet<>()).add(sn);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 查询今日生产记录,按产线统计不同工件码数量
|
|
|
+ MesProductRecord recordQuery = new MesProductRecord();
|
|
|
+ recordQuery.setCreateDate_gte(todayStart);
|
|
|
+ recordQuery.setCreateDate_lte(todayEnd);
|
|
|
+ List<MesProductRecord> recordList = mesProductRecordService.findList(recordQuery);
|
|
|
+ Map<String, Set<String>> recordSnByLine = new HashMap<>();
|
|
|
+ if (recordList != null) {
|
|
|
+ for (MesProductRecord record : recordList) {
|
|
|
+ String lineSn = record.getLineSn();
|
|
|
+ String sn = record.getSn();
|
|
|
+ if (StringUtils.isNotEmpty(lineSn) && StringUtils.isNotEmpty(sn)) {
|
|
|
+ recordSnByLine.computeIfAbsent(lineSn, k -> new HashSet<>()).add(sn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算各产线不良率并生成报警
|
|
|
+ double[] thresholds = {10.0, 7.0, 5.0, 3.0};
|
|
|
+ int alarmIdx = 1;
|
|
|
+ int totalRepairCount = 0;
|
|
|
+ for (String lineSn : recordSnByLine.keySet()) {
|
|
|
+ int repairCount = repairSnByLine.containsKey(lineSn) ? repairSnByLine.get(lineSn).size() : 0;
|
|
|
+ int recordCount = recordSnByLine.get(lineSn).size();
|
|
|
+ if (recordCount == 0) continue;
|
|
|
+ totalRepairCount += repairCount;
|
|
|
+ double defectRate = (repairCount * 100.0) / recordCount;
|
|
|
+ defectRate = Math.round(defectRate * 10) / 10.0;
|
|
|
+
|
|
|
+ for (double threshold : thresholds) {
|
|
|
+ if (defectRate > threshold) {
|
|
|
+ Map<String, Object> alarmMap = MapUtils.newHashMap();
|
|
|
+ alarmMap.put("id", alarmIdx);
|
|
|
+ alarmMap.put("msg", lineSn + "产线不良率超过" + (int)threshold + "%");
|
|
|
+ alarms.add(alarmMap);
|
|
|
+ alarmIdx++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.put("repair", totalRepairCount);
|
|
|
data.put("alarms", alarms);
|
|
|
|
|
|
+ //工具剩余寿命查询
|
|
|
MesToolLife mesToolLifeQuery = new MesToolLife();
|
|
|
- mesToolLifeQuery.setStatus("0");
|
|
|
+ mesToolLifeQuery.setStatus("1");
|
|
|
List<MesToolLife> toolLifeList = mesToolLifeService.findList(mesToolLifeQuery);
|
|
|
logger.info("工具寿命查询结果数量: " + (toolLifeList != null ? toolLifeList.size() : 0));
|
|
|
|
|
|
@@ -485,11 +548,11 @@ public class MesProductController extends BaseController {
|
|
|
data.put("faulty2", ListUtils.newArrayList(0, 0, 0, 0, 0, 0, 0));
|
|
|
data.put("faulty3", ListUtils.newArrayList(0, 0, 0, 0, 0, 0, 0));
|
|
|
|
|
|
+ //近七日产量数据
|
|
|
List<String> dateList = new ArrayList<>();
|
|
|
List<Long> outputList = new ArrayList<>();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
for (int i = 6; i >= 0; i--) {
|
|
|
- calendar = Calendar.getInstance();
|
|
|
calendar.add(Calendar.DATE, -i);
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
@@ -549,6 +612,196 @@ public class MesProductController extends BaseController {
|
|
|
}
|
|
|
data.put("oprnoData", oprnoData);
|
|
|
|
|
|
+ // 查询返修问题清单并统计每个问题类型的返修数量
|
|
|
+ List<String> defectTitles = new ArrayList<>();
|
|
|
+ List<Long> defectCounts = new ArrayList<>();
|
|
|
+
|
|
|
+ MesRepairItems repairItemsQuery = new MesRepairItems();
|
|
|
+ repairItemsQuery.setStatus("0");
|
|
|
+ List<MesRepairItems> repairItemsList = mesRepairItemsService.findList(repairItemsQuery);
|
|
|
+ logger.info("查询到的返修问题清单数量: " + (repairItemsList != null ? repairItemsList.size() : 0));
|
|
|
+
|
|
|
+ // 统计每个 title 的数量(统计 mes_repair_items 表中相同 title 的记录数)
|
|
|
+ Map<String, Long> titleCountMap = new HashMap<>();
|
|
|
+ for (MesRepairItems item : repairItemsList) {
|
|
|
+ String title = item.getTitle();
|
|
|
+ if (StringUtils.isNotEmpty(title)) {
|
|
|
+ titleCountMap.put(title, titleCountMap.getOrDefault(title, 0L) + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("title 统计结果: " + titleCountMap);
|
|
|
+
|
|
|
+ // 去重并构建结果
|
|
|
+ for (Map.Entry<String, Long> entry : titleCountMap.entrySet()) {
|
|
|
+ defectTitles.add(entry.getKey());
|
|
|
+ defectCounts.add(entry.getValue());
|
|
|
+ logger.info("问题类型: " + entry.getKey() + ", 数量: " + entry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("defectTitles", defectTitles);
|
|
|
+ data.put("defectCounts", defectCounts);
|
|
|
+
|
|
|
+ // 查询设备报警记录,按类型统计数量并排序
|
|
|
+ List<String> alarmTypes = new ArrayList<>();
|
|
|
+ List<Long> alarmCounts = new ArrayList<>();
|
|
|
+
|
|
|
+ List<MesDeviceAlarm> alarmList = mesDeviceAlarmService.findList(new MesDeviceAlarm());
|
|
|
+ logger.info("查询到的设备报警记录数量: " + (alarmList != null ? alarmList.size() : 0));
|
|
|
+
|
|
|
+ // 统计每个类型的报警数量
|
|
|
+ Map<String, Long> typeCountMap = new HashMap<>();
|
|
|
+ for (MesDeviceAlarm alarm : alarmList) {
|
|
|
+ String type = alarm.getType();
|
|
|
+ if (StringUtils.isNotEmpty(type)) {
|
|
|
+ typeCountMap.put(type, typeCountMap.getOrDefault(type, 0L) + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("设备报警类型统计结果: " + typeCountMap);
|
|
|
+
|
|
|
+ // 按数量降序排序,取前5名
|
|
|
+ List<Map.Entry<String, Long>> sortedEntries = new ArrayList<>(typeCountMap.entrySet());
|
|
|
+ sortedEntries.sort((a, b) -> Long.compare(b.getValue(), a.getValue()));
|
|
|
+
|
|
|
+ // 取前5名
|
|
|
+ int maxSize = Math.min(sortedEntries.size(), 5);
|
|
|
+ for (int i = 0; i < maxSize; i++) {
|
|
|
+ Map.Entry<String, Long> entry = sortedEntries.get(i);
|
|
|
+ alarmTypes.add(entry.getKey());
|
|
|
+ alarmCounts.add(entry.getValue());
|
|
|
+ logger.info("故障类型排名 " + (i + 1) + ": " + entry.getKey() + ", 数量: " + entry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("alarmTypes", alarmTypes);
|
|
|
+ data.put("alarmCounts", alarmCounts);
|
|
|
+
|
|
|
+ // 统计近七日设备故障率
|
|
|
+ List<String> faultDates = new ArrayList<>();
|
|
|
+ List<Double> faultRates = new ArrayList<>();
|
|
|
+ List<Integer> faultDeviceCounts = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取总设备数量
|
|
|
+ long totalDeviceCount = mesDeviceService.findCount(new MesDevice());
|
|
|
+ logger.info("总设备数量: " + totalDeviceCount);
|
|
|
+
|
|
|
+ // 统计近7天每天的故障数量
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
+
|
|
|
+ for (int i = 6; i >= 0; i--) {
|
|
|
+ Calendar dayCal = (Calendar) cal.clone();
|
|
|
+ dayCal.add(Calendar.DAY_OF_MONTH, -i);
|
|
|
+
|
|
|
+ Date startDate = dayCal.getTime();
|
|
|
+ dayCal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date endDate = dayCal.getTime();
|
|
|
+
|
|
|
+ // 格式化日期显示
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
|
|
|
+ String dateStr = sdf.format(startDate);
|
|
|
+ faultDates.add(dateStr);
|
|
|
+
|
|
|
+ // 查询当天的故障设备数(按设备编号去重)
|
|
|
+ MesDeviceAlarm alarmQuery = new MesDeviceAlarm();
|
|
|
+ alarmQuery.setCreateDate_gte(startDate);
|
|
|
+ alarmQuery.setCreateDate_lte(endDate);
|
|
|
+ List<MesDeviceAlarm> dayAlarmList = mesDeviceAlarmService.findList(alarmQuery);
|
|
|
+ Set<String> faultDeviceSet = new HashSet<>();
|
|
|
+ if (dayAlarmList != null) {
|
|
|
+ for (MesDeviceAlarm alarm : dayAlarmList) {
|
|
|
+ if (StringUtils.isNotEmpty(alarm.getDeviceSn())) {
|
|
|
+ faultDeviceSet.add(alarm.getDeviceSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long faultDeviceCount = faultDeviceSet.size();
|
|
|
+
|
|
|
+ // 计算故障率
|
|
|
+ double rate = totalDeviceCount > 0 ? (faultDeviceCount * 100.0 / totalDeviceCount) : 0;
|
|
|
+ // 保留一位小数
|
|
|
+ rate = Math.round(rate * 10) / 10.0;
|
|
|
+ faultRates.add(rate);
|
|
|
+ faultDeviceCounts.add((int) faultDeviceCount);
|
|
|
+
|
|
|
+ logger.info("日期: " + dateStr + ", 故障设备数: " + faultDeviceCount + ", 故障率: " + rate + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("faultDates", faultDates);
|
|
|
+ data.put("faultRates", faultRates);
|
|
|
+ data.put("faultDeviceCounts", faultDeviceCounts);
|
|
|
+
|
|
|
+ resp.setData(data);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "screenDataHourly")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp screenDataHourly() {
|
|
|
+ CommonResp<Map<String, Object>> resp = new CommonResp<>();
|
|
|
+ Map<String, Object> data = MapUtils.newHashMap();
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+ cal.set(Calendar.MILLISECOND, 0);
|
|
|
+ Date todayStart = cal.getTime();
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date todayEnd = cal.getTime();
|
|
|
+
|
|
|
+ String[] lineNames = {"HEVXT", "B13XT"};
|
|
|
+ String[] offlineOprnos = {"OP220", "OP280"};
|
|
|
+
|
|
|
+ for (int lineIdx = 0; lineIdx < lineNames.length; lineIdx++) {
|
|
|
+ String lineSn = lineNames[lineIdx];
|
|
|
+ String offlineOprno = offlineOprnos[lineIdx];
|
|
|
+
|
|
|
+ List<Integer> onlineCounts = new ArrayList<>();
|
|
|
+ List<Integer> offlineCounts = new ArrayList<>();
|
|
|
+ List<String> hourLabels = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int h = 0; h < 24; h++) {
|
|
|
+ Calendar hourStart = (Calendar) Calendar.getInstance().clone();
|
|
|
+ hourStart.set(Calendar.HOUR_OF_DAY, h);
|
|
|
+ hourStart.set(Calendar.MINUTE, 0);
|
|
|
+ hourStart.set(Calendar.SECOND, 0);
|
|
|
+ hourStart.set(Calendar.MILLISECOND, 0);
|
|
|
+
|
|
|
+ Calendar hourEnd = (Calendar) hourStart.clone();
|
|
|
+ hourEnd.add(Calendar.HOUR_OF_DAY, 1);
|
|
|
+
|
|
|
+ String hourLabel = String.format("%02d:00", h);
|
|
|
+ hourLabels.add(hourLabel);
|
|
|
+
|
|
|
+ // 查询上线工位(OP010)记录数
|
|
|
+ MesProductRecord onlineQuery = new MesProductRecord();
|
|
|
+ onlineQuery.setLineSn(lineSn);
|
|
|
+ onlineQuery.setOprno("OP010A");
|
|
|
+ onlineQuery.setCreateDate_gte(hourStart.getTime());
|
|
|
+ onlineQuery.setCreateDate_lte(hourEnd.getTime());
|
|
|
+ long onlineCount = mesProductRecordService.findCount(onlineQuery);
|
|
|
+ onlineCounts.add((int) onlineCount);
|
|
|
+
|
|
|
+ // 查询下线工位记录数
|
|
|
+ MesProductRecord offlineQuery = new MesProductRecord();
|
|
|
+ offlineQuery.setLineSn(lineSn);
|
|
|
+ offlineQuery.setOprno(offlineOprno);
|
|
|
+ offlineQuery.setCreateDate_gte(hourStart.getTime());
|
|
|
+ offlineQuery.setCreateDate_lte(hourEnd.getTime());
|
|
|
+ long offlineCount = mesProductRecordService.findCount(offlineQuery);
|
|
|
+ offlineCounts.add((int) offlineCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> lineData = MapUtils.newHashMap();
|
|
|
+ lineData.put("hours", hourLabels);
|
|
|
+ lineData.put("online", onlineCounts);
|
|
|
+ lineData.put("offline", offlineCounts);
|
|
|
+ data.put(lineSn.toLowerCase(), lineData);
|
|
|
+ }
|
|
|
+
|
|
|
resp.setData(data);
|
|
|
resp.setResult(Global.TRUE);
|
|
|
return resp;
|