|
@@ -3,14 +3,13 @@ package com.js.kbt.socket;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
-
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.js.kbt.mapper.MouldDownPacketMapper;
|
|
|
import com.js.kbt.mapper.MouldHistoryMapper;
|
|
@@ -154,7 +153,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
item.setCrcCode("" + reverseParseHex(crcStr));
|
|
|
// 找寻上一条最新记录
|
|
|
MouldHistoryExample mExp = new MouldHistoryExample();
|
|
|
- mExp.setOrderByClause("order by id desc limit 1");
|
|
|
+ mExp.setOrderByClause("id desc limit 1");
|
|
|
mExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
|
|
|
// 存入数据库
|
|
|
List<MouldHistory> newList = mouldHistoryMapper.selectByExample(mExp);
|
|
@@ -196,30 +195,38 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
// List<MouldHistoryTime> list =
|
|
|
// mouldHistoryTimeMapper.selectByEquipmentNoAndThanZero(item.getEquipmentNo());
|
|
|
List<MouldHistory> list = mouldHistoryMapper.selectByExample(exp);
|
|
|
- Long avgTime = 0L;
|
|
|
- Long totalTime = 0L;
|
|
|
- if (list.size() == 1) {
|
|
|
+ List<Long> historyIds = new ArrayList<>();
|
|
|
+ historyIds.add(-1L);
|
|
|
+ for (MouldHistory mouldHistory : list) {
|
|
|
+ historyIds.add(mouldHistory.getId());
|
|
|
+ }
|
|
|
+ MouldHistoryTimeExample mtExp = new MouldHistoryTimeExample();
|
|
|
+ mtExp.setOrderByClause("seq");
|
|
|
+ mtExp.createCriteria().andHistoryIdIn(historyIds);
|
|
|
+ List<MouldHistoryTime> historyList = mouldHistoryTimeMapper.selectByExample(mtExp);
|
|
|
+ int avgTime = 0;
|
|
|
+ int totalTime = 0;
|
|
|
+ if (historyList.size() == 1) {
|
|
|
// 证明盒子动了,找寻上一条记录
|
|
|
if (newList.size() > 0) {
|
|
|
- avgTime = ((list.get(0).getIndate().getTime()) - (newList.get(0).getIndate().getTime()));
|
|
|
+ MouldHistoryTime now = historyList.get(0);
|
|
|
+ MouldHistoryTime last = mouldHistoryTimeMapper.getDateByHistory(newList.get(0).getId());
|
|
|
+ if (null != now && null != last) {
|
|
|
+ avgTime = (int)((now.getOpenTime().getTime()) - (last.getOpenTime().getTime()));
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- if (list.size() > 1) {
|
|
|
- for (int j = 0; j < list.size()-1; j++) {
|
|
|
- // 删选掉负值的数据
|
|
|
- // logger.info("第i条数据开合模周期耗时-------------》》"+t.getTimeCost());
|
|
|
- totalTime = (list.get(j+1).getIndate().getTime() - list.get(j).getIndate().getTime());
|
|
|
+ if (historyList.size() > 1) {
|
|
|
+ for (int j = 0; j < historyList.size() - 1; j++) {
|
|
|
+ totalTime += (historyList.get(j + 1).getOpenTime().getTime()
|
|
|
+ - historyList.get(j).getOpenTime().getTime());
|
|
|
}
|
|
|
- avgTime = totalTime/(list.size()-1);
|
|
|
+ logger.info("totalTime" + totalTime);
|
|
|
+ avgTime = (int)(totalTime / (historyList.size() - 1));
|
|
|
}
|
|
|
}
|
|
|
-// // logger.info("开合模周期总耗时次数==》"+totalTime);
|
|
|
-// if (list.size() == 0) {
|
|
|
-// avgTime = 0L;
|
|
|
-// } else {
|
|
|
-// avgTime = totalTime / list.size();
|
|
|
-// }
|
|
|
- // logger.info("开合模平均周期耗时次数==》"+avgTime);
|
|
|
+ logger.info("avgTime-->" + avgTime);
|
|
|
+
|
|
|
handleModLogic(item, avgTime);
|
|
|
// 判断预留字节的
|
|
|
if ("02".equals(mobilePart)) {
|
|
@@ -269,7 +276,8 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void handleModLogic(MouldHistory item, Long avgTime) {
|
|
|
+ private void handleModLogic(MouldHistory item, int avgTime) {
|
|
|
+ logger.info("进了handleModLogic逻辑--");
|
|
|
TbMouldEquipmentExample meqExp = new TbMouldEquipmentExample();
|
|
|
meqExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
|
|
|
if (tbMouldEquipmentMapper.countByExample(meqExp) > 0) {
|
|
@@ -279,7 +287,6 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
me.setLng(Double.parseDouble(item.getLng()));
|
|
|
me.setLat(Double.parseDouble(item.getLat()));
|
|
|
}
|
|
|
-
|
|
|
me.setTemperature(item.getTemperature());
|
|
|
if (item.getAlarm() == 8) {
|
|
|
me.setStage(3);// 安装被拆
|
|
@@ -308,8 +315,11 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
// 云模盒运行次数+模具的历史运行次数
|
|
|
tm.setRunTimes(item.getRunCnt() + tm.getHistoryRunTimes());
|
|
|
// 处理每模平均周期(单位秒)
|
|
|
- BigDecimal bd = new BigDecimal(avgTime * 1.00 / 1000);
|
|
|
- tm.setOcCycle(bd);
|
|
|
+ if (0 != avgTime) {
|
|
|
+ logger.info("开始修改平均每模周期值为:" + avgTime);
|
|
|
+ BigDecimal bd = new BigDecimal(avgTime * 1.00 / 1000);
|
|
|
+ tm.setOcCycle(bd);
|
|
|
+ }
|
|
|
tbMouldMapper.updateByPrimaryKeySelective(tm);
|
|
|
}
|
|
|
}
|