|
|
|
|
@@ -2,12 +2,16 @@
|
|
|
|
|
package org.nl.wms.sb.run.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.nl.exception.BadRequestException;
|
|
|
|
|
import org.nl.modules.system.service.DeptService;
|
|
|
|
|
import org.nl.utils.PageUtil;
|
|
|
|
|
import org.nl.utils.SpringContextHolder;
|
|
|
|
|
import org.nl.wms.basedata.master.service.ClassstandardService;
|
|
|
|
|
import org.nl.wms.sb.run.service.DevicerunrecordService;
|
|
|
|
|
import org.nl.wms.sb.run.service.dto.DevicerunrecordDto;
|
|
|
|
|
@@ -18,9 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
@@ -46,16 +48,16 @@ public class DevicerunrecordServiceImpl implements DevicerunrecordService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
|
|
|
|
|
DeptService deptService = SpringContextHolder.getBean(DeptService.class);
|
|
|
|
|
|
|
|
|
|
String material_type_id = MapUtil.getStr(whereJson, "material_type_id");
|
|
|
|
|
String class_idStr = MapUtil.getStr(whereJson, "class_idStr");
|
|
|
|
|
String begin_time = MapUtil.getStr(whereJson, "begin_time");
|
|
|
|
|
String end_time = MapUtil.getStr(whereJson, "end_time");
|
|
|
|
|
String begin_time = MapUtil.getStr(whereJson, "begin_time").substring(0,10);
|
|
|
|
|
String end_time = MapUtil.getStr(whereJson, "end_time").substring(0,10);
|
|
|
|
|
String device_code = MapUtil.getStr(whereJson, "device_code");
|
|
|
|
|
|
|
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("flag", "1");
|
|
|
|
|
map.put("begin_time", begin_time);
|
|
|
|
|
map.put("end_time", end_time);
|
|
|
|
|
map.put("flag", "2");
|
|
|
|
|
if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code","%"+device_code+"%");
|
|
|
|
|
//处理物料当前节点的所有子节点
|
|
|
|
|
if (!StrUtil.isEmpty(material_type_id)) {
|
|
|
|
|
@@ -66,7 +68,40 @@ public class DevicerunrecordServiceImpl implements DevicerunrecordService {
|
|
|
|
|
String classIds = classstandardService.getAllChildIdStr(class_idStr);
|
|
|
|
|
map.put("classIds", classIds);
|
|
|
|
|
}
|
|
|
|
|
JSONObject json = WQL.getWO("EM_DEVICERUNRECORD001").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "file.device_code ASC,run.run_date ASC");
|
|
|
|
|
// 归属部门
|
|
|
|
|
String dept_id = MapUtil.getStr(whereJson, "dept_id");
|
|
|
|
|
if (!StrUtil.isEmpty(dept_id)) {
|
|
|
|
|
String deptIds = deptService.getChildIdStr(Long.parseLong(dept_id));
|
|
|
|
|
map.put("deptIds", deptIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<Object> objects = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
Date begin_date = DateUtil.parse(begin_time);
|
|
|
|
|
Date end_date = DateUtil.parse(end_time);
|
|
|
|
|
long betweenDay = DateUtil.between(begin_date, end_date, DateUnit.DAY);
|
|
|
|
|
|
|
|
|
|
if (betweenDay == 0) {
|
|
|
|
|
// 如果是某天则直接查
|
|
|
|
|
map.put("run_date", begin_time);
|
|
|
|
|
JSONArray arr = WQL.getWO("EM_DEVICERUNRECORD001").addParamMap(map).process().getResultJSONArray(0);
|
|
|
|
|
objects.addAll(arr);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果不是则根据日期递增循环查出 然后合并
|
|
|
|
|
for (int i = 0; i <= betweenDay; i++) {
|
|
|
|
|
String day_time = DateUtil.offsetDay(begin_date, i).toString().substring(0,10);
|
|
|
|
|
map.put("run_date",day_time);
|
|
|
|
|
JSONArray arr = WQL.getWO("EM_DEVICERUNRECORD001").addParamMap(map).process().getResultJSONArray(0);
|
|
|
|
|
objects.addAll(arr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 组织分页查询并返回
|
|
|
|
|
Map<String, Object> json = PageUtil.toPage(
|
|
|
|
|
PageUtil.toPage(page.getPageNumber(), page.getPageSize(), objects),
|
|
|
|
|
objects.size()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -158,6 +193,12 @@ public class DevicerunrecordServiceImpl implements DevicerunrecordService {
|
|
|
|
|
public void update(JSONObject whereJson) {
|
|
|
|
|
WQLObject tab = WQLObject.getWQLObject("EM_BI_DeviceRunRecord");
|
|
|
|
|
String devicerecord_id = whereJson.getString("devicerecord_id");
|
|
|
|
|
String runrecord_id = whereJson.getString("runrecord_id");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = tab.query("runrecord_id = '" + runrecord_id + "'").uniqueResult(0);
|
|
|
|
|
if (ObjectUtil.isEmpty(jsonObject)) {
|
|
|
|
|
throw new BadRequestException("请先填报");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject jsonFile = WQLObject.getWQLObject("EM_BI_EquipmentFile").query("devicerecord_id = '" + devicerecord_id + "'").uniqueResult(0);
|
|
|
|
|
|
|
|
|
|
@@ -203,4 +244,59 @@ public class DevicerunrecordServiceImpl implements DevicerunrecordService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void submit(JSONObject whereJson) {
|
|
|
|
|
WQLObject tab = WQLObject.getWQLObject("EM_BI_DeviceRunRecord");
|
|
|
|
|
|
|
|
|
|
Long currentUserId = SecurityUtils.getCurrentUserId();
|
|
|
|
|
String nickName = SecurityUtils.getNickName();
|
|
|
|
|
String now = DateUtil.now();
|
|
|
|
|
|
|
|
|
|
String devicerecord_id = whereJson.getString("devicerecord_id");
|
|
|
|
|
String run_date = whereJson.getString("run_date");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonFile = WQLObject.getWQLObject("EM_BI_EquipmentFile").query("devicerecord_id = '" + devicerecord_id + "'").uniqueResult(0);
|
|
|
|
|
String status = jsonFile.getString("status");
|
|
|
|
|
if (!"10,11,20,30,40".contains(status)) {
|
|
|
|
|
throw new BadRequestException("此设备不能填报");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double run_times = whereJson.getDoubleValue("run_times"); //生产时间
|
|
|
|
|
double prepare_times = whereJson.getDoubleValue("prepare_times");//准备时间
|
|
|
|
|
double error_times = whereJson.getDoubleValue("error_times"); //故障时间
|
|
|
|
|
double adjust_times = whereJson.getDoubleValue("adjust_times"); //工装调整时间
|
|
|
|
|
double product_qty = whereJson.getDoubleValue("product_qty"); //生产总量
|
|
|
|
|
double nok_qty = whereJson.getDoubleValue("nok_qty"); //不合格数
|
|
|
|
|
double theory_beat = jsonFile.getDoubleValue("theory_beat"); // 理论节拍
|
|
|
|
|
|
|
|
|
|
JSONObject jsonMst = tab.query("devicerecord_id = '" + devicerecord_id + "' and run_date = '" + run_date + "'").uniqueResult(0);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(jsonMst)) throw new BadRequestException("填报信息已存在");
|
|
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
json.put("runrecord_id", IdUtil.getSnowflake(1,1).nextId());
|
|
|
|
|
json.put("devicerecord_id", whereJson.get("devicerecord_id"));
|
|
|
|
|
json.put("run_date", whereJson.getString("run_date"));
|
|
|
|
|
json.put("run_times", whereJson.get("run_times"));
|
|
|
|
|
json.put("prepare_times", whereJson.get("prepare_times"));
|
|
|
|
|
json.put("error_times", whereJson.get("error_times"));
|
|
|
|
|
json.put("adjust_times", whereJson.get("adjust_times"));
|
|
|
|
|
json.put("product_qty", whereJson.get("product_qty"));
|
|
|
|
|
json.put("nok_qty", whereJson.get("nok_qty"));
|
|
|
|
|
json.put("remark", whereJson.getString("remark"));
|
|
|
|
|
json.put("create_id", currentUserId);
|
|
|
|
|
json.put("create_name", nickName);
|
|
|
|
|
json.put("create_time", now);
|
|
|
|
|
// 计算OEE指标
|
|
|
|
|
try {
|
|
|
|
|
BigDecimal div = NumberUtil.div(NumberUtil.sub(run_times, prepare_times, error_times, adjust_times), NumberUtil.sub(run_times, prepare_times, adjust_times));
|
|
|
|
|
BigDecimal div1 = NumberUtil.div(NumberUtil.mul(div, theory_beat, product_qty), NumberUtil.sub(run_times, prepare_times, error_times, adjust_times));
|
|
|
|
|
BigDecimal oee_value = NumberUtil.mul(div1, NumberUtil.div(NumberUtil.sub(product_qty, nok_qty), product_qty));
|
|
|
|
|
json.put("oee_value", oee_value);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
json.put("oee_value", 0);
|
|
|
|
|
}
|
|
|
|
|
tab.insert(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|