This commit is contained in:
2022-07-28 18:38:15 +08:00
parent eee9d0b9cc
commit 8869716a86
2 changed files with 264 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ package org.nl.wms.ext.bigScreen.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -24,10 +26,23 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
//正常运行:有工单正在工作的;暂未生产:有工单没有在工作的;空闲设备:没有工单的,没故障的;故障设备:状态为故障的
JSONArray device_rows = WQLObject.getWQLObject("PDM_BI_Device").query("is_active = '1' AND is_delete = '0'").getResultJSONArray(0);
int total_num = device_rows.size();
int run_device = 0;
int prepare_device = 0;
int free_device = 0;
int err_device = 0;
//查询故障设备
JSONArray err_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "7").process().getResultJSONArray(0);
int err_device = err_rows.size();
//查询运行设备
JSONArray run_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "8").process().getResultJSONArray(0);
int run_device = run_rows.size();
//查询有工单,没有故障的设备
JSONArray task_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "9").process().getResultJSONArray(0);
//查询暂未生产设备
int prepare_device = task_rows.size() - run_device;
//空闲设备
int free_device = total_num - task_rows.size() - err_device;
JSONObject result = new JSONObject();
result.put("total_num", total_num);
@@ -85,7 +100,7 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
@Override
public JSONObject deviceManage(JSONObject param) {
String today = DateUtil.today()+"%";
String today = DateUtil.today() + "%";
Date today_begin = DateUtil.beginOfDay(DateUtil.date());
//弯头工段
JSONObject jo1 = new JSONObject();
@@ -293,9 +308,9 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
jo3.put("err_times", cp_err_rows.size());
JSONObject result = new JSONObject();
result.put("jo1",jo1);
result.put("jo2",jo2);
result.put("jo3",jo3);
result.put("jo1", jo1);
result.put("jo2", jo2);
result.put("jo3", jo3);
JSONObject returnjo = new JSONObject();
returnjo.put("code", "1");
returnjo.put("desc", "查询成功!");
@@ -305,13 +320,47 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
@Override
public JSONObject deviceCensus(JSONObject param) {
return null;
JSONArray pro_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "6").process().getResultJSONArray(0);
JSONArray result = new JSONArray();
for (int i = 0; i < pro_rows.size(); i++) {
JSONObject pro = pro_rows.getJSONObject(i);
JSONObject jo = new JSONObject();
int total_num = pro.getIntValue("total_num");
String workprocedure_id = pro.getString("workprocedure_id");
//查询故障设备
JSONArray err_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "7").addParam("workprocedure_id",workprocedure_id).process().getResultJSONArray(0);
int err_device = err_rows.size();
//查询运行设备
JSONArray run_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "8").addParam("workprocedure_id",workprocedure_id).process().getResultJSONArray(0);
int run_device = run_rows.size();
//查询有工单,没有故障的设备
JSONArray task_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "9").addParam("workprocedure_id",workprocedure_id).process().getResultJSONArray(0);
//查询暂未生产设备
int prepare_device = task_rows.size() - run_device;
//空闲设备
int free_device = total_num - task_rows.size() - err_device;
jo.put("run_device", run_device);
jo.put("prepare_device", prepare_device);
jo.put("free_device", free_device);
jo.put("err_device", err_device);
jo.put("workprocedure_name", pro.getString("workprocedure_name"));
result.add(jo);
}
JSONObject returnjo = new JSONObject();
returnjo.put("code", "1");
returnjo.put("desc", "查询成功!");
returnjo.put("result", result);
return returnjo;
}
@Override
public JSONObject deviceErrorInfo(JSONObject param) {
String today = DateUtil.today()+"%";
JSONArray result = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "5").addParam("today",today).process().getResultJSONArray(0);
String today = DateUtil.today() + "%";
JSONArray result = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "5").addParam("today", today).process().getResultJSONArray(0);
JSONObject returnjo = new JSONObject();
returnjo.put("code", "1");
returnjo.put("desc", "查询成功!");
@@ -321,12 +370,56 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
@Override
public JSONObject deviceUseRate(JSONObject param) {
return null;
JSONArray pro_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "6").process().getResultJSONArray(0);
JSONArray result = new JSONArray();
for (int i = 0; i < pro_rows.size(); i++) {
JSONObject pro = pro_rows.getJSONObject(i);
JSONObject jo = new JSONObject();
jo.put("workprocedure_name", pro.getString("workprocedure_name"));
jo.put("teep",(i+1)*10);
}
JSONObject returnjo = new JSONObject();
returnjo.put("code", "1");
returnjo.put("desc", "查询成功!");
returnjo.put("result", result);
return returnjo;
}
@Override
public JSONObject deviceStatusList(JSONObject param) {
return null;
String date = DateUtil.today() + "%";
JSONArray device_rows = WQL.getWO("QDEVICE_SCREEN").addParam("flag", "11").process().getResultJSONArray(0);
JSONArray result = new JSONArray();
for (int i = 0; i < device_rows.size(); i++) {
int product_qty = 0;
JSONObject device = device_rows.getJSONObject(i);
String device_id = device.getString("device_id");
JSONArray order_rows = WQLObject.getWQLObject("mps_bd_produceshiftorder").query("device_id = '"+device_id+"' AND produce_date like '"+date+"' AND is_delete = '0'").getResultJSONArray(0);
for (int j = 0; j < order_rows.size(); j++) {
JSONObject order = order_rows.getJSONObject(i);
product_qty += order.getIntValue("real_qty");
}
device.put("product_qty",product_qty);
//查询最近的一条开机状态
JSONObject start_jo = WQLObject.getWQLObject("pdm_bi_devicerunstatusrecord").query("device_id = '"+device_id+"' AND status_type = '02' order by end_time desc").uniqueResult(0);
device.put("start_time",start_jo.getString("end_time"));
if (StrUtil.isEmpty(device.getString("end_time"))){
//查询最近的一条关机状态
JSONObject end_jo = WQLObject.getWQLObject("pdm_bi_devicerunstatusrecord").query("device_id = '"+device_id+"' AND status_type = '01' order by end_time desc").uniqueResult(0);
device.put("end_time",end_jo.getString("end_time"));
}
//查询最近的一个工单
JSONObject order_jo = WQLObject.getWQLObject("mps_bd_produceshiftorder").query("device_id = '"+device_id+"' AND is_delete = '0' AND is_actice = '1' order by realproducestart_date desc").uniqueResult(0);
device.put("product_time",order_jo.getString("produce_date"));
result.add(device);
}
JSONObject returnjo = new JSONObject();
returnjo.put("code", "1");
returnjo.put("desc", "查询成功!");
returnjo.put("result", result);
return returnjo;
}
@Override
@@ -338,4 +431,60 @@ public class DeviceScreenServiceImpl implements DeviceScreenService {
returnjo.put("result", result);
return returnjo;
}
public JSONObject calculate(JSONObject jo) {
String date = jo.getString("date")+"%";
String device_id = jo.getString("device_id");
//type:1、目标2、实际
String type = jo.getString("type");
//查询当天该设备的产量
int total_qty = 0;
JSONArray order_rows = WQLObject.getWQLObject("mps_bd_produceshiftorder").query("device_id = '"+device_id+"' AND produce_date like '"+date+"' AND is_delete = '0'").getResultJSONArray(0);
for (int i = 0; i < order_rows.size(); i++) {
JSONObject order = order_rows.getJSONObject(i);
total_qty += order.getIntValue("real_qty");
}
//查询该设备对应的产能
JSONObject device = WQLObject.getWQLObject("PDM_BI_Device").query("device_id = '"+device_id+"'").uniqueResult(0);
double productivity = device.getDoubleValue("productivity");
//故障时间汇总
JSONArray err_rows = WQLObject.getWQLObject("pdm_bi_devicerunstatusrecord").query("device_id = '"+device_id+"' AND status_type = '05' AND start_time like '"+date+"'").getResultJSONArray(0);
double err_time = 0;
for (int i = 0; i < err_rows.size(); i++) {
JSONObject err_jo = err_rows.getJSONObject(i);
String start_time = err_jo.getString("start_time");
String end_time = err_jo.getString("end_time");
if (StrUtil.isEmpty(end_time)){
end_time = DateUtil.now();
}
long between = DateUtil.between(DateUtil.parse(start_time), DateUtil.parse(end_time), DateUnit.MINUTE);
err_time += between;
}
err_time = NumberUtil.round(err_time,2).doubleValue();
double oee = 0.0;
//OEE计算目标当天汇总/产能x负荷时间实际班制时间-故障时间)/班制时间 * (当天工单汇总/(产能*(符合时间-故障时间)))* 98%
if (type.equals("1")){
//8是指符合时间也就是每天的工作时间
oee = NumberUtil.div(total_qty,NumberUtil.mul(8,productivity));
}else {
//(班制时间-故障时间)/班制时间
double value1 = NumberUtil.div(NumberUtil.sub(8*60,err_time),8*60);
//(产能*(符合时间-故障时间)
double value2 = NumberUtil.div(total_qty,NumberUtil.mul(productivity,value1));
oee = NumberUtil.mul(value1,value2);
}
double teep = 0.0;
//TEEP计算OEE*(班制时间-计划停机时间)/班制时间
teep = NumberUtil.div(oee,0.9);
JSONObject result = new JSONObject();
result.put("oee",oee);
result.put("teep",teep);
return result;
}
}

View File

@@ -16,6 +16,7 @@
输入.flag TYPEAS s_string
输入.worksection_type_scode TYPEAS s_string
输入.today TYPEAS s_string
输入.workprocedure_id TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
@@ -157,6 +158,107 @@
ENDQUERY
ENDIF
IF 输入.flag = "7"
QUERY
SELECT
device_id
FROM
pdm_bi_devicerunstatusrecord run
LEFT JOIN pdm_bi_device device ON device.device_id = run.device_id
WHERE
status_type = '05'
AND
IFNULL( end_time, '' ) = ''
OPTION 输入.workprocedure_id <> ""
device.workprocedure_id = 输入.workprocedure_id
ENDOPTION
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "8"
QUERY
SELECT
device_id
FROM
pdm_bi_devicerunstatusrecord run
LEFT JOIN pdm_bi_device device ON device.device_id = run.device_id
WHERE
status_type = '03'
AND
IFNULL( end_time, '' ) = ''
OPTION 输入.workprocedure_id <> ""
device.workprocedure_id = 输入.workprocedure_id
ENDOPTION
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "9"
QUERY
SELECT DISTINCT
device.device_id
FROM
pdm_bi_device device
LEFT JOIN mps_bd_produceshiftorder shift ON shift.device_id = device.device_id
LEFT JOIN pdm_bi_devicerunstatusrecord run ON run.device_id = device.device_id
WHERE
shift.is_delete = '0'
AND
shift.order_status <> '04'
AND
run.status_type <> '05'
OPTION 输入.workprocedure_id <> ""
device.workprocedure_id = 输入.workprocedure_id
ENDOPTION
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "10"
QUERY
SELECT
device.workprocedure_id,
COUNT(device_id) AS total_num,
MAX(pro.workprocedure_name) AS workprocedure_name
FROM
pdm_bi_device device
LEFT JOIN pdm_bi_workprocedure pro ON pro.workprocedure_id = device.workprocedure_id
WHERE
device.is_delete = '0'
AND
device.is_active = '1'
GROUP BY
device.workprocedure_id
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "11"
QUERY
SELECT
device.device_code,
device.device_name,
pro.workprocedure_name,
(case when run.status_type is null then '关机'
when run.status_type = '02' then '开机'
when run.status_type = '03' then '生产中'
when run.status_type = '04' then '待机'
when run.status_type = '05' then '故障'
end
) AS device_status,
device.device_id,
run.status_type
FROM
pdm_bi_device device
LEFT JOIN pdm_bi_devicerunstatusrecord run ON run.device_id = device.device_id AND IFNULL(run.end_time,'') = ''
LEFT JOIN pdm_bi_workprocedure pro ON pro.workprocedure_id = device.workprocedure_id
ENDSELECT
ENDQUERY
ENDIF