|
@@ -96,7 +96,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
// 校准时间
|
|
|
timeCalibration();
|
|
|
//验证是否需要切换ip
|
|
|
- sendChangeIp();
|
|
|
+// sendChangeIp();
|
|
|
System.out.println("收到===" + arg1 + "\n");
|
|
|
String equipmentNo = processMsg(arg1);
|
|
|
// 以下是配置下行数据
|
|
@@ -234,39 +234,41 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
// 开模时间
|
|
|
Date openTime = parseDate(input, start, pos, 6);
|
|
|
time.setOpenTime(openTime);
|
|
|
+ logger.info("第"+(pos+1)+"包");
|
|
|
if (pos == 0) {
|
|
|
time.setTimeCost(0);
|
|
|
} else {
|
|
|
+ logger.info("本包开合时间戳--" + openTime.getTime());
|
|
|
logger.info("本次开合周期--" + (openTime.getTime() - aHeadOpenTimeLongVal));
|
|
|
time.setTimeCost((int) (openTime.getTime() - aHeadOpenTimeLongVal));
|
|
|
}
|
|
|
mouldHistoryTimeMapper.insertSelective(time);
|
|
|
// 处理最后一包周期逻辑
|
|
|
- if(pos==periodCnt-1){
|
|
|
+ aHeadOpenTimeLongVal = openTime.getTime();
|
|
|
+// if(pos==periodCnt-1){
|
|
|
handleMouldCycleRuntimeLogic(openTime, item);
|
|
|
- }
|
|
|
+// }
|
|
|
logger.info("mouldHistoryTime数据添加完毕");
|
|
|
- aHeadOpenTimeLongVal = openTime.getTime();
|
|
|
logger.info("上一包数据的开合时间戳--" + aHeadOpenTimeLongVal);
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("本次开合模次数==0");
|
|
|
}
|
|
|
// 统计该模盒的平均开合周期
|
|
|
- MouldHistoryExample exp = new MouldHistoryExample();
|
|
|
- exp.setOrderByClause("id");
|
|
|
- exp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo()).andRunCntEqualTo(item.getRunCnt());
|
|
|
+// MouldHistoryExample exp = new MouldHistoryExample();
|
|
|
+// exp.setOrderByClause("id");
|
|
|
+// exp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo()).andRunCntEqualTo(item.getRunCnt());
|
|
|
// List<MouldHistoryTime> list =
|
|
|
// mouldHistoryTimeMapper.selectByEquipmentNoAndThanZero(item.getEquipmentNo());
|
|
|
- List<MouldHistory> list = mouldHistoryMapper.selectByExample(exp);
|
|
|
- List<Long> historyIds = new ArrayList<>();
|
|
|
- historyIds.add(-1L);
|
|
|
- for (MouldHistory mouldHistory : list) {
|
|
|
- historyIds.add(mouldHistory.getId());
|
|
|
- }
|
|
|
+// List<MouldHistory> list = mouldHistoryMapper.selectByExample(exp);
|
|
|
+// 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);
|
|
|
+ mtExp.createCriteria().andHistoryIdEqualTo(item.getId()).andTimeCostGreaterThan(0);
|
|
|
List<MouldHistoryTime> historyList = mouldHistoryTimeMapper.selectByExample(mtExp);
|
|
|
int avgTime = 0;
|
|
|
int totalTime = 0;
|
|
@@ -283,12 +285,12 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
// }
|
|
|
// } else {
|
|
|
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());
|
|
|
+ for (MouldHistoryTime mouldHistoryTime : historyList) {
|
|
|
+ logger.info("totalTime" + totalTime);
|
|
|
+ totalTime += mouldHistoryTime.getTimeCost();
|
|
|
}
|
|
|
logger.info("totalTime" + totalTime);
|
|
|
- avgTime = (int) (totalTime / (historyList.size() - 1));
|
|
|
+ avgTime = (int) (totalTime / historyList.size());
|
|
|
}
|
|
|
// }
|
|
|
logger.info("avgTime-->" + avgTime);
|
|
@@ -350,8 +352,11 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
}
|
|
|
if (count > 0) {
|
|
|
TbMouldEquipment me = tbMouldEquipmentMapper.selectByExample(meqExp).get(0);
|
|
|
- me.setIsUse(packet.getIsUse());
|
|
|
- tbMouldEquipmentMapper.updateByPrimaryKeySelective(me);
|
|
|
+ TbMouldEquipment tme = new TbMouldEquipment();
|
|
|
+ tme.setId(me.getId());
|
|
|
+ tme.setIsUse(packet.getIsUse());
|
|
|
+ tbMouldEquipmentMapper.updateByPrimaryKeySelective(tme);
|
|
|
+ logger.info("将启用中的云模盒改为启用成功==>" + me.getEquipmentNo());
|
|
|
}
|
|
|
//下发完删除数据
|
|
|
mouldDownPacketMapper.deleteByPrimaryKey(packet.getId());
|
|
@@ -487,13 +492,18 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
private void handleMouldCycleRuntimeLogic(Date openTime, MouldHistory item) throws ParseException {
|
|
|
System.out.println("开始handleMouldCycleRuntimeLogic逻辑开合时间"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(openTime));
|
|
|
MouldCycleRuntime mcr = new MouldCycleRuntime();
|
|
|
- Integer hours = openTime.getHours();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ mcr.setDateStr(sdf.format(openTime));
|
|
|
+ Integer hours = openTime.getHours();
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
|
|
|
int housTime = openTime.getHours() - 1;
|
|
|
openTime.setHours(housTime);
|
|
|
String lastOpenTime = sdf1.format(openTime);
|
|
|
- Date lastOpenTimeDate = sdf1.parse(lastOpenTime + "59:59");
|
|
|
+ Date lastOpenTimeDate = sdf1.parse(lastOpenTime);
|
|
|
+ //此处直接拼接字符串“59:59”会导致分和秒丢失,所以才去set的方法设置时分秒
|
|
|
+ lastOpenTimeDate.setMinutes(59);
|
|
|
+ lastOpenTimeDate.setSeconds(59);
|
|
|
+ logger.info("当前开合时间减一小时的时间条件:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(lastOpenTimeDate));
|
|
|
MouldHistoryTimeExample mExp = new MouldHistoryTimeExample();
|
|
|
mExp.setOrderByClause("open_time desc limit 1");
|
|
|
mExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo())
|
|
@@ -503,7 +513,6 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
if (list.size() > 0) {
|
|
|
MouldHistory mouldHistory = mouldHistoryMapper.selectByPrimaryKey(list.get(0).getHistoryId());
|
|
|
logger.info("本次运行次数: " + item.getRunCnt()+" 上一小时的运行次数:"+mouldHistory.getRunCnt()+" 上一小时的historyId:"+mouldHistory.getId());
|
|
|
- mcr.setDateStr(sdf.format(openTime));
|
|
|
mcr.setEquipmentNo(item.getEquipmentNo());
|
|
|
mcr.setRuntime(item.getRunCnt() - mouldHistory.getRunCnt());
|
|
|
if (hours == 0) {
|
|
@@ -706,6 +715,14 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
public static void main(String[] args) throws ParseException {
|
|
|
// UserHandler h = new UserHandler();
|
|
|
// h.timeCalibration();
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
|
|
|
+ Date date = new Date();
|
|
|
+ String lastOpenTime = sdf1.format(date);
|
|
|
+ System.out.println(lastOpenTime);
|
|
|
+ Date lastOpenTimeDate = sdf1.parse(lastOpenTime);
|
|
|
+ lastOpenTimeDate.setMinutes(59);
|
|
|
+ lastOpenTimeDate.setSeconds(59);
|
|
|
+ System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(lastOpenTimeDate));
|
|
|
String a = "00:25:32";
|
|
|
SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss");
|
|
|
Date d = new Date();
|