对账单信息

tags/yfai-mes-ext-v2.0 yfai-mes-ext-v2.0
xiangwei.zhang 7 months ago
parent 2e525494c6
commit 20690c2ae2

@ -6,6 +6,7 @@ import cn.estsh.i3plus.ext.mes.apiservice.utils.BeanUtil;
import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException; import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException;
import cn.estsh.i3plus.ext.mes.pojo.model.MesLoadingListDetailModel; import cn.estsh.i3plus.ext.mes.pojo.model.MesLoadingListDetailModel;
import cn.estsh.i3plus.ext.mes.pojo.model.MesShippingOrderManagementDetailModel; import cn.estsh.i3plus.ext.mes.pojo.model.MesShippingOrderManagementDetailModel;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager; import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager; import cn.estsh.i3plus.pojo.base.common.Pager;
@ -26,6 +27,7 @@ import cn.estsh.i3plus.pojo.mes.repository.MesProductRecordLogRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.xxl.job.core.util.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.query.internal.NativeQueryImpl; import org.hibernate.query.internal.NativeQueryImpl;
@ -39,10 +41,7 @@ import org.springframework.util.StringUtils;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -545,7 +544,8 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
List<MesProductAccountResModel> partitionList = partition(mesProductAccountResModels, pager.getPageSize(), pager.getCurrentPage()); List<MesProductAccountResModel> partitionList = partition(mesProductAccountResModels, pager.getPageSize(), pager.getCurrentPage());
for (MesProductAccountResModel mesProductAccountResModel : partitionList) { for (MesProductAccountResModel mesProductAccountResModel : partitionList) {
boolean isErrorCount = false; boolean isErrorCount = false;
int size = mesProductAccountResModel.getPartNo().split(",").length == 1 ? mesProductAccountResModel.getPartNo().split(";").length : 1; int size = mesProductAccountResModel.getPartNo().split(",").length == 1 ? mesProductAccountResModel.getPartNo().split(";").length : mesProductAccountResModel.getPartNo().split(",").length;
int productCount = Integer.valueOf(mesProductAccountResModel.getProductCount()); int productCount = Integer.valueOf(mesProductAccountResModel.getProductCount());
int detailCount = Integer.valueOf(mesProductAccountResModel.getDetailCount()); int detailCount = Integer.valueOf(mesProductAccountResModel.getDetailCount());
if (detailCount * size > productCount) { if (detailCount * size > productCount) {
@ -564,12 +564,24 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
DdlPreparedPack.getOrderBy("createDatetime", CommonEnumUtil.ASC_OR_DESC.ASC.getValue(), packBean); DdlPreparedPack.getOrderBy("createDatetime", CommonEnumUtil.ASC_OR_DESC.ASC.getValue(), packBean);
List<MesProductRecordLog> recordLogs = mesProductRecordLogRepository.findByHqlWhere(packBean); List<MesProductRecordLog> recordLogs = mesProductRecordLogRepository.findByHqlWhere(packBean);
//
DdlPackBean packOffilinBean = DdlPackBean.getDdlPackBean("CK01");
DdlPreparedPack.getStringEqualPack(mesProductAccountResModel.getEquipmentCode(), "equipmentCode", packOffilinBean);
Date yesterday = TimeTool.getDateBefore(DateUtil.parseDateTime(productAccountModel.getStartTime()), 1);
String yesterdayStr = DateUtil.formatDateTime(yesterday);
DdlPreparedPack.getStringSmallerNotEqualPack(productAccountModel.getStartTime(), "createDatetime", packOffilinBean);
DdlPreparedPack.getStringBiggerPack(yesterdayStr, "createDatetime", packOffilinBean);
DdlPreparedPack.getStringEqualPack(mesProductAccountResModel.getPartNo(), "partNo", packOffilinBean);
DdlPreparedPack.getStringLikerPack("客户端", "message", packOffilinBean);
DdlPreparedPack.getOrderBy("createDatetime", CommonEnumUtil.ASC_OR_DESC.ASC.getValue(), packOffilinBean);
List<MesProductRecordLog> offlineRecordLogs = mesProductRecordLogRepository.findByHqlWhere(packOffilinBean);
recordLogs.addAll(offlineRecordLogs);
recordLogs = recordLogs.stream().sorted(Comparator.comparing(MesProductRecordLog::getCreateDatetime)).collect(Collectors.toList());
if (mesProductAccountResModel.getEquipmentCode().contains("HT")) { if (mesProductAccountResModel.getEquipmentCode().contains("HT")) {
// 1 判断2个 shotcount之间有没有加工记录如果没有就需要看 设备是不是192然后看是否是网络原因 // 1 判断2个 shotcount之间有没有加工记录如果没有就需要看 设备是不是192然后看是否是网络原因
String reason = handleHT(recordLogs); String reason = handleHT(recordLogs);
mesProductAccountResModel.setErrorReason(reason); mesProductAccountResModel.setErrorReason(reason);
} else if (equimentList.contains(mesProductAccountResModel.getEquipmentCode())) { } else if (equimentList.contains(mesProductAccountResModel.getEquipmentCode())) {
@ -590,16 +602,48 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
String startTime = ""; String startTime = "";
String endTime = ""; String endTime = "";
String reason = ""; String reason = "";
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失【%s】个;"; String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失";
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;";
String reasonQuality = "【%s】设备信号质量为0导致【%s】个完成信号丢失;"; String reasonQuality = "【%s】设备信号质量为0导致【%s】个完成信号丢失;";
String reasonBypass = "【%s】设备打BYPASS,导致【%s】个完成信号丢失;"; String reasonBypass = "【%s】的完成信号,设备打BYPASS,视为无效;";
// BYPASS 默认fasle
boolean bypassFlag = false; boolean bypassFlag = false;
boolean offlineFlag = false;
List<String> finishList = Stream.of("Product_finish","Part_Finish").collect(Collectors.toList()); List<String> finishList = Stream.of("Product_finish","Part_Finish").collect(Collectors.toList());
for (MesProductRecordLog recordLog : recordLogs) { for (MesProductRecordLog recordLog : recordLogs) {
int errorCount = 0; int errorCount = 0;
/*if (recordLog.getId() ==1834566428726444032l) {
int a = 1;
}*/
if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端下线")) {
startTime = recordLog.getCreateDatetime();
offlineFlag = true;
continue;
}
if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端上线") ) {
endTime = recordLog.getCreateDatetime();
offlineFlag = false;
if (errorCount > 0) {
reason += String.format(offlineReason, startTime, endTime, errorCount + "");
errorCount = 0;
}
//result = 0;
continue;
}
if (offlineFlag &&finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
if (result > 0) {
//endTime = recordLog.getCreateDatetime();
errorCount ++;
reason += String.format(offlineReason, startTime, startTime, errorCount + "");
continue;
}
errorCount ++;
result++;
continue ;
}
if (Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS")) { if (Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS")) {
if (Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (Objects.equal(recordLog.getEquipVariableValue(), "True")) {
if (StringUtils.isEmpty(startTime)) { if (StringUtils.isEmpty(startTime)) {
@ -628,19 +672,18 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
if (!finishList.contains(recordLog.getCategoryLevelTwo()) || !Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (!finishList.contains(recordLog.getCategoryLevelTwo()) || !Objects.equal(recordLog.getEquipVariableValue(), "True")) {
continue; continue;
} }
startTime = recordLog.getCreateDatetime();
result ++; result ++;
} else { } else {
if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
if (StringUtils.isEmpty(startTime)) {
startTime = recordLog.getCreateDatetime();
}
errorCount ++; errorCount ++;
endTime = recordLog.getCreateDatetime();
if (Objects.equal(recordLog.getQuality(), "192")) { if (Objects.equal(recordLog.getQuality(), "192")) {
reason += String.format(reasonOffline,startTime, errorCount +""); reason += String.format(reasonOffline,startTime, errorCount +"");
} else { } else {
reason += String.format(reasonQuality,startTime, errorCount +""); reason += String.format(reasonQuality,startTime, errorCount +"");
} }
startTime = recordLog.getCreateDatetime();
} }
if (recordLog.getType().equals("record")) { if (recordLog.getType().equals("record")) {
result --; result --;
@ -659,12 +702,12 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
// 错误个数 // 错误个数
// 异常原因 // 异常原因
String reason = ""; String reason = "";
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失【%s】个;"; String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;";
//String reasonOffline = "【%s】,客户端下线,导致【%s】个完成信号丢失"; String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失;";
String reasonQuality = "【%s】设备信号质量为0导致【%s】个完成信号丢失;"; String reasonQuality = "【%s】设备信号质量为0视为无效;";
String reasonBypass = "【%s】设备打BYPASS,导致【%s】个完成信号丢失;"; String reasonBypass = "【%s】的完成信号,设备打BYPASS,视为无效;";
String releaseBypass = "【%s】设备在MES没有发允许加工指令情况下,给了【%s】个完成信号;"; String releaseBypass = "【%s】的完成信号,未发送Release信号,视为无效;";
// BYPASS 默认fasle // BYPASS 默认fasle
@ -672,43 +715,96 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
// release 默认false // release 默认false
boolean releaseFlag = false; boolean releaseFlag = false;
// BYPASS 默认fasle
boolean offlineFlag = false;
//List<String> finishList = Stream.of("Product_finish","PART_OK","Part_Finish","Product_OK").collect(Collectors.toList()); //List<String> finishList = Stream.of("Product_finish","PART_OK","Part_Finish","Product_OK").collect(Collectors.toList());
List<String> finishList = Stream.of("Product_finish","Part_Finish").collect(Collectors.toList()); List<String> finishList = Stream.of("Product_finish","Part_Finish").collect(Collectors.toList());
String preReason = "";
for (MesProductRecordLog recordLog : recordLogs) { for (MesProductRecordLog recordLog : recordLogs) {
int errorCount = 0; int errorCount = 0;
if (recordLog.getId() ==1288411771211612170l) {
// BYPASS 逻辑开始 int a = 1;
// 第一次遇到BYPASS = true, 取下开始时间,后面的加工记录一直增加errorCount 直到出现 BYPASS = FALSE, }
if (Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS") && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端下线")) {
startTime = recordLog.getCreateDatetime(); startTime = recordLog.getCreateDatetime();
offlineFlag = true;
continue;
}
if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端上线") ) {
endTime = recordLog.getCreateDatetime(); endTime = recordLog.getCreateDatetime();
bypassFlag = true; offlineFlag = false;
if (result > 0) {
reason += String.format(offlineReason, startTime, endTime, 1 + "");
errorCount = 0;
}
//result = 0;
continue; continue;
} }
// 如果是bypass 遇到的所有加工完成指令 都计数并且原因是bypass导致
if (bypassFlag && finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (bypassFlag && finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
if (!StringUtils.isEmpty(preReason)) {
reason += preReason;
}
preReason = String.format(reasonBypass,startTime, 1 +"");
//reason += String.format(reasonBypass,startTime, 1 +"");
continue;
}
if (offlineFlag && finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
// 如果经过了1个finish然后再经过客户端下线再遇到finish则认为是客户端下线引起
if (result > 0) {
//endTime = recordLog.getCreateDatetime();
errorCount ++;
reason += String.format(offlineReason, startTime, startTime, errorCount + "");
continue;
}
errorCount ++; errorCount ++;
reason += String.format(reasonBypass,startTime, errorCount +""); result++;
continue ;
}
if (Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS") && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
startTime = recordLog.getCreateDatetime();
endTime = recordLog.getCreateDatetime();
bypassFlag = true;
continue; continue;
} }
// 遇到bypass = false 则重置错误次数
if (bypassFlag && Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS") && Objects.equal(recordLog.getEquipVariableValue(), "False")) { if (bypassFlag && Objects.equal(recordLog.getCategoryLevelTwo(), "BYPASS") && Objects.equal(recordLog.getEquipVariableValue(), "False")) {
endTime = recordLog.getCreateDatetime(); endTime = recordLog.getCreateDatetime();
errorCount = 0; errorCount = 0;
bypassFlag = false; bypassFlag = false;
continue; continue;
} }
// 如果没有发送release 就出现了加工完成信号,则记录错误原因,且预错误,遇到有加工记录则取消
/**
* release :release
*
*
*/
if (!releaseFlag) { if (!releaseFlag) {
if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
if (!StringUtils.isEmpty(preReason)) {
reason += preReason;
}
startTime = recordLog.getCreateDatetime(); startTime = recordLog.getCreateDatetime();
errorCount ++; errorCount ++;
reason += String.format(releaseBypass, startTime, errorCount + ""); preReason = String.format(releaseBypass, startTime, errorCount + "");
continue; continue;
} }
} }
// BYPASS 逻辑结束 result = 1 代表一个成功新型号,遇到一个加工记录就会-1 变成0 // BYPASS 逻辑结束 result = 1 代表一个成功新型号,遇到一个加工记录就会-1 变成0
if (result == 0) { if (result == 0) {
// 没有加工完成指令或者没有release指令但是有加工记录则也需要重置
if (recordLog.getType().equals("record")) {
releaseFlag = false;
bypassFlag = false;
preReason = "";
}
if (Objects.equal(recordLog.getCategoryLevelTwo(), "Work_Allow") && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (Objects.equal(recordLog.getCategoryLevelTwo(), "Work_Allow") && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
releaseFlag = true; releaseFlag = true;
continue; continue;
@ -717,28 +813,48 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
if (!finishList.contains(recordLog.getCategoryLevelTwo()) || !Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (!finishList.contains(recordLog.getCategoryLevelTwo()) || !Objects.equal(recordLog.getEquipVariableValue(), "True")) {
continue; continue;
} }
if (!releaseFlag) {
reason += preReason;
startTime = recordLog.getCreateDatetime();
preReason = String.format(releaseBypass, startTime, 1 + "");
result ++;
continue;
} if (!StringUtils.isEmpty(preReason)) {
reason += preReason;
}
result ++; result ++;
startTime = recordLog.getCreateDatetime();
} else { } else {
if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) { if (finishList.contains(recordLog.getCategoryLevelTwo()) && Objects.equal(recordLog.getEquipVariableValue(), "True")) {
startTime = recordLog.getCreateDatetime(); // 上一个加工记录信号还没走完这边又继续发一个加工记录且没有release 两个都要判定问题
if (!releaseFlag) {
errorCount ++; startTime = recordLog.getCreateDatetime();
endTime = recordLog.getCreateDatetime(); reason += String.format(releaseBypass, startTime, 1 + "");
if (Objects.equal(recordLog.getQuality(), "192")) {
reason += String.format(reasonOffline,startTime, errorCount +"");
} else { } else {
reason += String.format(reasonQuality,startTime, errorCount +""); if (Objects.equal(recordLog.getQuality(), "192")) {
reason += String.format(reasonOffline,startTime, 1 +"");
} else {
reason += String.format(reasonQuality,startTime, 1 +"");
}
} }
} }
if (recordLog.getType().equals("record")) { if (recordLog.getType().equals("record")) {
releaseFlag = false; releaseFlag = false;
bypassFlag = false; bypassFlag = false;
offlineFlag = false;
result --; result --;
preReason = "";
startTime = "";
errorCount = 0;
} }
} }
} }
// 如果走到最后,还有预编译的错误,则直接加上
if (!StringUtils.isEmpty(preReason)) {
reason += preReason;
}
return reason; return reason;
} }
@ -747,11 +863,34 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
String startTime = ""; String startTime = "";
String endTime = ""; String endTime = "";
String reason = ""; String reason = "";
String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失【%s】个;"; String offlineReason = "【%s】到【%s】,客户端下线,导致【%s】个完成信号丢失";
String reasonQuality = "【%s】设备信号质量为0导致【%s】个完成信号丢失;"; String reasonOffline = "因其他原因:系统,网络,发版等,导致【%s】的完成信号丢失;";
String reasonQuality = "【%s】设备信号质量为0导致完成信号丢失;";
boolean offlineFlag = false;
int errorCount = 0;
for (MesProductRecordLog recordLog : recordLogs) { for (MesProductRecordLog recordLog : recordLogs) {
int errorCount = 0; if (recordLog.getId() ==1284126441587343426l) {
int i = 1;
}
if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端下线")) {
startTime = recordLog.getCreateDatetime();
offlineFlag = true;
continue;
}
if (Objects.equal(recordLog.getType(), "monitor") && recordLog.getMessage().contains("客户端上线") && offlineFlag) {
endTime = recordLog.getCreateDatetime();
offlineFlag = false;
if (errorCount > 0) {
reason += String.format(offlineReason, startTime, endTime, errorCount + "");
errorCount = 0;
}
continue;
}
if (offlineFlag && Objects.equal(recordLog.getCategoryLevelTwo(),"shot_counter") && recordLog.getEquipVariableValue().compareTo("0") > 0) {
errorCount ++;
continue ;
}
if (result == 0) { if (result == 0) {
if (!Objects.equal(recordLog.getCategoryLevelTwo(),"shot_counter") ) { if (!Objects.equal(recordLog.getCategoryLevelTwo(),"shot_counter") ) {
@ -764,12 +903,11 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
if (Objects.equal(recordLog.getCategoryLevelTwo(),"shot_counter") && recordLog.getEquipVariableValue().compareTo("0") > 0) { if (Objects.equal(recordLog.getCategoryLevelTwo(),"shot_counter") && recordLog.getEquipVariableValue().compareTo("0") > 0) {
startTime = recordLog.getCreateDatetime(); startTime = recordLog.getCreateDatetime();
errorCount ++;
endTime = recordLog.getCreateDatetime(); endTime = recordLog.getCreateDatetime();
if (Objects.equal(recordLog.getQuality(), "192")) { if (Objects.equal(recordLog.getQuality(), "192")) {
reason += String.format(reasonOffline,startTime, errorCount +""); reason += String.format(reasonOffline,startTime, 1 +"");
} else { } else {
reason += String.format(reasonQuality,startTime, errorCount +""); reason += String.format(reasonQuality,startTime, 1 +"");
} }
} }
if (recordLog.getType().equals("record")) { if (recordLog.getType().equals("record")) {
@ -777,6 +915,9 @@ public class MesProductionRecordServiceImpl extends BaseMesService<MesProduction
} }
} }
} }
if (errorCount > 0 && offlineFlag) {
reason += String.format(offlineReason, startTime, "最后", errorCount + "");
}
return reason; return reason;
} }

Loading…
Cancel
Save