Browse Source

feat: 大屏修改-提交

master
李永德 10 months ago
parent
commit
7413925eeb
  1. 119
      lms/nladmin-system/src/main/java/org/nl/wms/dashboard/service/DashboardService.java
  2. 8
      lms/nladmin-system/src/main/java/org/nl/wms/dashboard/wql/DASHBOARD.wql

119
lms/nladmin-system/src/main/java/org/nl/wms/dashboard/service/DashboardService.java

@ -2,9 +2,11 @@ package org.nl.wms.dashboard.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.wms.ext.acs.service.WmsToAcsService;
@ -21,6 +23,7 @@ import java.util.stream.Collectors;
*/
@RequiredArgsConstructor
@Service
@Slf4j
public class DashboardService {
private final WmsToAcsService wmsToAcsService;
@ -79,7 +82,12 @@ public class DashboardService {
}
int fulfillmentRate = orderFulfillmentRate.getDoubleValue("plan") == 0.00 ? 100 : (int) (orderFulfillmentRate.getDoubleValue("real") / orderFulfillmentRate.getDoubleValue("plan") * 100);
todayProduction.put("message", "今日共需生产" + todayTotalPlan + "块,物料种类" + materialCount.size() + "种,已完成包装" + sortCompleted + "托,共" + sortCompletedQty + "块," + sortMaterialCount.size() + "个物料,完成率" + fulfillmentRate + "%。");
todayProduction.put("todayTotalPlan", todayTotalPlan);
todayProduction.put("materialCountSize", materialCount.size());
todayProduction.put("sortCompleted", sortCompleted);
todayProduction.put("sortCompletedQty", sortCompletedQty);
todayProduction.put("sortMaterialCountSize", sortMaterialCount.size());
todayProduction.put("fulfillmentRate", fulfillmentRate);
// 当日混料 -----------------------------------------------------------------------------------------------------
Map<String, JSONObject> todayMixMaterialPlan = new HashMap<>();
List<JSONObject> todayMixPlanWorkOrders = todayPlanWorkOrders.stream().filter(o -> "HL".equals(o.getString("region_code"))).collect(Collectors.toList());
@ -126,7 +134,7 @@ public class DashboardService {
return o1;
});
}
result.put("inventory", todaySortMaterialPlan.values().stream().sorted((o1, o2) -> -(Double.compare(o1.getDoubleValue("qty"), o2.getDoubleValue("qty")))).limit(7L).collect(Collectors.toList()));
result.put("inventory", inventory.values().stream().sorted((o1, o2) -> -(Double.compare(o1.getDoubleValue("qty"), o2.getDoubleValue("qty")))).limit(7L).collect(Collectors.toList()));
// 历史分析 -----------------------------------------------------------------------------------------------------
JSONArray history = new JSONArray();
@ -153,33 +161,58 @@ public class DashboardService {
JSONArray devices = WQLObject.getWQLObject("pdm_bi_device").query("is_delete = '0'").getResultJSONArray(0);
JSONObject deviceStatus = wmsToAcsService.getDeviceStatus2(devices);
result.put("acs_data", deviceStatus);
// 设备产能利用 --------------------------------------------------------------------------------------------------
JSONObject capacityRate = new JSONObject();
result.put("capacityRate", capacityRate);
capacityRate.put("mix", Math.random() * (90 - 50) + 50);
capacityRate.put("press", Math.random() * (90 - 50) + 50);
capacityRate.put("dry", Math.random() * (90 - 50) + 50);
capacityRate.put("sort", Math.random() * (90 - 50) + 50);
JSONArray capacityRate = new JSONArray();
JSONObject device1 = new JSONObject();
JSONObject device2 = new JSONObject();
JSONObject device3 = new JSONObject();
JSONObject device4 = new JSONObject();
result.put("capacityRate", capacityRate);
device1.put("numerical", Math.random() * (90 - 50) + 50);
device2.put("numerical", Math.random() * (90 - 50) + 50);
device3.put("numerical", Math.random() * (90 - 50) + 50);
device4.put("numerical", Math.random() * (90 - 50) + 50);
device1.put("device_name", "混料设备");
device2.put("device_name", "压制设备");
device3.put("device_name", "干燥设备");
device4.put("device_name", "包装设备");
capacityRate.add(device1);
capacityRate.add(device2);
capacityRate.add(device3);
capacityRate.add(device4);
// 设备运行统计 --------------------------------------------------------------------------------------------------
JSONObject stateStatistics = new JSONObject();
JSONObject stateStatistics1 = new JSONObject();
JSONObject stateStatistics2 = new JSONObject();
JSONObject stateStatistics3 = new JSONObject();
JSONObject stateStatistics4 = new JSONObject();
JSONArray stateStatisticsList = new JSONArray();
result.put("stateStatistics", stateStatistics);
// 初始化 0
stateStatistics.put("count", devices.size());
stateStatistics.put("running", 0);
stateStatistics.put("pausing", 0);
stateStatistics.put("shutdown", 0);
stateStatistics.put("inTrouble", 0);
stateStatistics.put("fourState", stateStatisticsList);
stateStatisticsList.add(stateStatistics1);
stateStatisticsList.add(stateStatistics2);
stateStatisticsList.add(stateStatistics3);
stateStatisticsList.add(stateStatistics4);
stateStatistics1.put("status", 0);
stateStatistics2.put("status", 0);
stateStatistics3.put("status", 0);
stateStatistics4.put("status", 0);
stateStatistics1.put("stateName", "正常运行");
stateStatistics2.put("stateName", "暂未生产");
stateStatistics3.put("stateName", "空闲设备");
stateStatistics4.put("stateName", "故障设备");
// 真实获取
if (deviceStatus.getIntValue("status") == HttpStatus.OK.value()) {
JSONArray data = deviceStatus.getJSONArray("data");
stateStatistics.put("running", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 2).count());
stateStatistics.put("pausing", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 1).count());
stateStatistics.put("shutdown", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 0).count());
stateStatistics.put("inTrouble", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 3).count());
stateStatistics1.put("status", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 2).count());
stateStatistics2.put("status", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 1).count());
stateStatistics3.put("status", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 0).count());
stateStatistics4.put("status", data.stream().filter(o -> ((JSONObject) o).getIntValue("status") == 3).count());
}
// 工序设备状态 --------------------------------------------------------------------------------------------------
@ -273,20 +306,23 @@ public class DashboardService {
row.put("deviceName", device.getString("device_name"));
if (deviceStatus.getIntValue("status") == HttpStatus.OK.value()) {
JSONObject data = deviceStatus.getJSONArray("data").stream().map(o -> (JSONObject) o).filter(o -> device.getString("device_code").equals(o.getString("device_code"))).collect(Collectors.toList()).get(0);
row.put("status", this.deviceStatusToChinese(data.getIntValue("status")));
} else{
row.put("status", "未知");
}
JSONObject wo = inProductionWorkOrder.stream().filter(o -> device.getString("device_code").equals(o.getString("device_code"))).collect(Collectors.toList()).get(0);
row.put("workOrder", wo.getString("workorder_code"));
row.put("bom", wo.getString("material_code").substring(5, 11));
row.put("material", wo.getString("material_code"));
if ("HL".equals(device.getString("region_code"))) {
row.put("qty", wo.getIntValue("plan_qty") + "千克");
row.put("status", data.getIntValue("status"));
} else {
row.put("qty", wo.getIntValue("plan_qty") + "块");
row.put("status", 99);
}
List<JSONObject> collect = inProductionWorkOrder.stream().filter(o -> device.getString("device_code").equals(o.getString("device_code"))).collect(Collectors.toList());
JSONObject wo = ObjectUtil.isNotEmpty(collect) ? collect.get(0) : null;
if (ObjectUtil.isNotEmpty(wo)) {
row.put("workOrder", wo.getString("workorder_code"));
row.put("bom", wo.getString("material_code").substring(5, 11));
row.put("material", wo.getString("material_code"));
if ("HL".equals(device.getString("region_code"))) {
row.put("qty", wo.getIntValue("plan_qty") + "千克");
} else {
row.put("qty", wo.getIntValue("plan_qty") + "块");
}
row.put("startTime", wo.getString("realproducestart_date"));
}
row.put("startTime", wo.getString("realproducestart_date"));
deviceWorkOrder.add(row);
}
@ -300,10 +336,29 @@ public class DashboardService {
*/
public JSONObject homepageEquipment() {
JSONObject result = new JSONObject();
JSONArray devices = WQLObject.getWQLObject("pdm_bi_device").query("is_delete = '0'").getResultJSONArray(0);
JSONObject deviceStatus = wmsToAcsService.getDeviceStatus2(devices);
result.put("acs_data", deviceStatus);
// 生产完成 => 组盘成功的数据,近20条
JSONArray productReport = WQL.getWO("DASHBOARD").addParam("flag", "5").process().getResultJSONArray(0);
JSONArray deviceReport = WQL.getWO("DASHBOARD").addParam("flag", "6").process().getResultJSONArray(0);
result.put("productReport", productReport);
result.put("deviceReport", deviceReport);
// 换成实时数据
// 真实获取
if (deviceStatus.getIntValue("status") == HttpStatus.OK.value()) {
List<Map<String, Object>> deviceInfoList = deviceStatus.getJSONArray("data")
.stream()
.map(JSONObject.class::cast)
.map(jsonObject -> {
// 组合参数
Map<String, Object> deviceInfo = new HashMap<>();
deviceInfo.put("failure_info", ObjectUtil.isNotEmpty(jsonObject.getString("status")) ? jsonObject.getString("status") : "0");
deviceInfo.put("device_code", jsonObject.getString("device_name"));
deviceInfo.put("failure_time", DateUtil.now());
return deviceInfo;
})
.collect(Collectors.toList());
result.put("deviceReport", deviceInfoList);
}
return result;
}

8
lms/nladmin-system/src/main/java/org/nl/wms/dashboard/wql/DASHBOARD.wql

@ -53,7 +53,7 @@
LEFT JOIN md_me_materialbase mb ON wo.material_id = mb.material_id
WHERE
wo.is_delete = '0'
AND TO_DAYS(wo.plan_date) = TO_DAYS(NOW())
AND TO_DAYS(wo.plan_date) = TO_DAYS(NOW()) OR wo.order_status = '3'
ENDSELECT
ENDQUERY
ENDIF
@ -81,7 +81,7 @@
IF 输入.flag = "3"
QUERY
SELECT
d.device_name AS "deviceName",
d.device_name,
COUNT(dn.device_code) AS "count"
FROM
das_device_number dn LEFT JOIN pdm_bi_device d ON dn.device_code = d.device_code
@ -89,7 +89,7 @@
dn.failure_info = 3
AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= DATE( dn.failure_time )
GROUP BY
dn.device_code
dn.device_code, d.device_name
ORDER BY
count DESC
LIMIT
@ -140,7 +140,7 @@
SELECT
dn.device_code,
dn.failure_time,
IF(ISNULL(dn.failure_info), '-', dn.failure_info) AS failure_info
IF(ISNULL(dn.failure_info), '0', dn.failure_info) AS failure_info
FROM
`das_device_number` dn
WHERE

Loading…
Cancel
Save