Pārlūkot izejas kodu

修改启用到启用中...

5 gadi atpakaļ
vecāks
revīzija
999d2310c7

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldEquipmentController.java

@@ -74,7 +74,7 @@ public class MouldEquipmentController {
      * 云平台下行配置数据包接口
      * lowPowerLimit 低电量报警限值:(1 字节,十六进制)如:1e=31
      * hotAlarmLimit 热报警限值:(1 字节,十六进制)如:50=80
-     * isUse:0-停止,1-启动,2-启用中,3-停用中
+     * isUse:0-停止,1-启动
      * equipmentNo 设备编号(可能是多个或者一个)多个以“,”隔开传  如:"123456"(单个),"123456,456878,123589"(多个)
      */
     @ApiOperation("启用设备")

+ 7 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldEquipmentServiceImpl.java

@@ -116,7 +116,13 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
             for (String str : split) {
                 packet = mouldDownPacketMapper.selectOne(new QueryWrapper<MouldDownPacket>().eq("equipment_no", str));
                 MouldEquipment equipment = new MouldEquipment();
-                equipment.setIsUse(mouldEquipment.getIsUse());
+                if(1 == mouldEquipment.getIsUse()){
+                    //启用中
+                    equipment.setIsUse(2);
+                }else if(0 == mouldEquipment.getIsUse()){
+                    //停用中
+                    equipment.setIsUse(3);
+                }
                 equipment.setEquipmentNo(mouldEquipment.getEquipmentNo());
                 equipment.setHillNumber(mouldEquipment.getLowPowerLimit()+"");
                 equipment.setTemperature(mouldEquipment.getHotAlarmLimit());

+ 112 - 99
cloud-socket/src/com/js/kbt/socket/UserHandler.java

@@ -76,7 +76,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		System.out.println("收到===" + arg1 + "\n");
 		String equipmentNo = processMsg(arg1);
 		// 以下是配置下行数据
-		// sendPackage(equipmentNo);
+		 sendPackage(equipmentNo);
 	}
 
 	private String processMsg(String input) throws ParseException {
@@ -176,7 +176,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 			// 本次运行周期内的开合模次数
 			int periodCnt = (end - start * 2) / 24;
 			logger.info("本次开合模次数==" + periodCnt);
-			long  aHeadOpenTimeLongVal = 0L;
+			long aHeadOpenTimeLongVal = 0L;
 			for (int pos = 0; pos < periodCnt; pos++) {
 				// 合模时间
 				MouldHistoryTime time = new MouldHistoryTime();
@@ -188,18 +188,18 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 				// 开模时间
 				Date openTime = parseDate(input, start, pos, 6);
 				time.setOpenTime(openTime);
-				if(pos==0){
+				if (pos == 0) {
 					time.setTimeCost(0);
-				}else{
-					logger.info("本次开合周期--"+(openTime.getTime() - aHeadOpenTimeLongVal));
-					time.setTimeCost((int)(openTime.getTime() - aHeadOpenTimeLongVal));
+				} else {
+					logger.info("本次开合周期--" + (openTime.getTime() - aHeadOpenTimeLongVal));
+					time.setTimeCost((int) (openTime.getTime() - aHeadOpenTimeLongVal));
 				}
 				mouldHistoryTimeMapper.insertSelective(time);
-				//处理周期逻辑
-				handleMouldCycleRuntimeLogic(openTime,item);
+				// 处理周期逻辑
+				handleMouldCycleRuntimeLogic(openTime, item);
 				logger.info("mouldHistoryTime数据添加完毕");
 				aHeadOpenTimeLongVal = openTime.getTime();
-				logger.info("上一包数据的开合时间戳--"+aHeadOpenTimeLongVal);
+				logger.info("上一包数据的开合时间戳--" + aHeadOpenTimeLongVal);
 			}
 		} else {
 			logger.info("本次开合模次数==0");
@@ -222,27 +222,29 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		List<MouldHistoryTime> historyList = mouldHistoryTimeMapper.selectByExample(mtExp);
 		int avgTime = 0;
 		int totalTime = 0;
-//		if (historyList.size() == 1) {
-//			// 证明盒子动了,找寻上一条记录
-//			if (newList.size() > 0) {
-//				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 (historyList.size() > 1) {
-				for (int j = 0; j < historyList.size() - 1; j++) {
-					totalTime += (historyList.get(j + 1).getOpenTime().getTime()
-							- historyList.get(j).getOpenTime().getTime());
-				}
-				logger.info("totalTime" + totalTime);
-				avgTime = (int)(totalTime / (historyList.size() - 1));
+		// if (historyList.size() == 1) {
+		// // 证明盒子动了,找寻上一条记录
+		// if (newList.size() > 0) {
+		// 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 (historyList.size() > 1) {
+			for (int j = 0; j < historyList.size() - 1; j++) {
+				totalTime += (historyList.get(j + 1).getOpenTime().getTime()
+						- historyList.get(j).getOpenTime().getTime());
 			}
-//		}
+			logger.info("totalTime" + totalTime);
+			avgTime = (int) (totalTime / (historyList.size() - 1));
+		}
+		// }
 		logger.info("avgTime-->" + avgTime);
-		
+
 		handleModLogic(item, avgTime);
 		// 判断预留字节的
 		if ("02".equals(mobilePart)) {
@@ -266,9 +268,16 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		List<MouldDownPacket> list = mouldDownPacketMapper.selectByExample(exp);
 		if (list.size() > 0) {
 			MouldDownPacket packet = list.get(0);
-			if (0 == packet.getIsUse()) {
-				logger.info("开始下发数据包==>" + packet.getPacketStr());
-				sendMsg(packet.getPacketStr());
+			TbMouldEquipmentExample meqExp = new TbMouldEquipmentExample();
+			meqExp.createCriteria().andEquipmentNoEqualTo(equipmentNo);
+			long count = tbMouldEquipmentMapper.countByExample(meqExp);
+			// 下发数据包,下发完后修改状态
+			logger.info("开始下发数据包==>" + packet.getPacketStr());
+			sendMsg(packet.getPacketStr());
+			if (count > 0) {
+				TbMouldEquipment me = tbMouldEquipmentMapper.selectByExample(meqExp).get(0);
+				me.setIsUse(packet.getIsUse());
+				tbMouldEquipmentMapper.updateByPrimaryKeySelective(me);
 			}
 		}
 	}
@@ -294,7 +303,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 
 	private void handleModLogic(MouldHistory item, int avgTime) {
 		logger.info("进了handleModLogic逻辑--");
-		logger.info("item==>"+item);
+		logger.info("item==>" + item);
 		TbMouldEquipmentExample meqExp = new TbMouldEquipmentExample();
 		meqExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
 		if (tbMouldEquipmentMapper.countByExample(meqExp) > 0) {
@@ -361,15 +370,18 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 	}
 
 	private static Date parseDate(String input, int start, int pos, int dateStartPos) {
-		//pos为开合的一组的下标,一个开合时间占位是12*2
+		// pos为开合的一组的下标,一个开合时间占位是12*2
 		String year = input.substring((start + pos * 12 + dateStartPos) * 2, (start + pos * 12 + 1 + dateStartPos) * 2);
 		String month = input.substring((start + pos * 12 + 1 + dateStartPos) * 2,
 				(start + pos * 12 + 2 + dateStartPos) * 2);
 		String day = input.substring((start + pos * 12 + 2 + dateStartPos) * 2,
 				(start + pos * 12 + 3 + dateStartPos) * 2);
-		String hh = input.substring((start + pos * 12 + 3 + dateStartPos) * 2, (start + pos * 12 + 4 + dateStartPos) * 2);
-		String mm = input.substring((start + pos * 12 + 4 + dateStartPos) * 2, (start + pos * 12 + 5 + dateStartPos) * 2);
-		String ss = input.substring((start + pos * 12 + 5 + dateStartPos) * 2, (start + pos * 12 + 6 + dateStartPos) * 2);
+		String hh = input.substring((start + pos * 12 + 3 + dateStartPos) * 2,
+				(start + pos * 12 + 4 + dateStartPos) * 2);
+		String mm = input.substring((start + pos * 12 + 4 + dateStartPos) * 2,
+				(start + pos * 12 + 5 + dateStartPos) * 2);
+		String ss = input.substring((start + pos * 12 + 5 + dateStartPos) * 2,
+				(start + pos * 12 + 6 + dateStartPos) * 2);
 		StringBuilder sb = new StringBuilder();
 		int yearInt = Integer.parseInt(year, 16);
 		if (yearInt == 0) {
@@ -394,86 +406,88 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		}
 		return parseDate;
 	}
-	
-	private void handleMouldCycleRuntimeLogic(Date openTime,MouldHistory item) throws ParseException{
+
+	private void handleMouldCycleRuntimeLogic(Date openTime, MouldHistory item) throws ParseException {
 		MouldCycleRuntime mcr = new MouldCycleRuntime();
 		Integer hours = openTime.getHours();
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
-		int housTime = openTime.getHours()-1;
+		int housTime = openTime.getHours() - 1;
 		openTime.setHours(housTime);
 		String lastOpenTime = sdf.format(openTime);
-		Date lastOpenTimeDate = sdf1.parse(lastOpenTime+"59:59");
+		Date lastOpenTimeDate = sdf1.parse(lastOpenTime + "59:59");
 		MouldHistoryTimeExample mExp = new MouldHistoryTimeExample();
 		mExp.setOrderByClause("open_time desc limit 1");
-		mExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo()).andOpenTimeLessThanOrEqualTo(lastOpenTimeDate);
+		mExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo())
+				.andOpenTimeLessThanOrEqualTo(lastOpenTimeDate);
 		List<MouldHistoryTime> list = mouldHistoryTimeMapper.selectByExample(mExp);
-		if(list.size()>0){
+		if (list.size() > 0) {
 			MouldHistory mouldHistory = mouldHistoryMapper.selectByPrimaryKey(list.get(0).getHistoryId());
 			mcr.setDateStr(sdf.format(openTime));
 			mcr.setEquipmentNo(item.getEquipmentNo());
 			mcr.setRuntime(item.getRunCnt() - mouldHistory.getRunCnt());
-			if(hours==0){
+			if (hours == 0) {
 				mcr.setTimeSlot("00:00-01:00");
-			}else if(hours==1){
+			} else if (hours == 1) {
 				mcr.setTimeSlot("01:00-02:00");
-			}else if(hours==2){
+			} else if (hours == 2) {
 				mcr.setTimeSlot("02:00-03:00");
-			}else if(hours==3){
+			} else if (hours == 3) {
 				mcr.setTimeSlot("03:00-04:00");
-			}else if(hours==4){
+			} else if (hours == 4) {
 				mcr.setTimeSlot("04:00-05:00");
-			}else if(hours==5){
+			} else if (hours == 5) {
 				mcr.setTimeSlot("05:00-06:00");
-			}else if(hours==6){
+			} else if (hours == 6) {
 				mcr.setTimeSlot("06:00-07:00");
-			}else if(hours==7){
+			} else if (hours == 7) {
 				mcr.setTimeSlot("07:00-08:00");
-			}else if(hours==8){
+			} else if (hours == 8) {
 				mcr.setTimeSlot("08:00-09:00");
-			}else if(hours==9){
+			} else if (hours == 9) {
 				mcr.setTimeSlot("09:00-10:00");
-			}else if(hours==10){
+			} else if (hours == 10) {
 				mcr.setTimeSlot("10:00-11:00");
-			}else if(hours==11){
+			} else if (hours == 11) {
 				mcr.setTimeSlot("11:00-12:00");
-			}else if(hours==12){
+			} else if (hours == 12) {
 				mcr.setTimeSlot("12:00-13:00");
-			}else if(hours==13){
+			} else if (hours == 13) {
 				mcr.setTimeSlot("13:00-14:00");
-			}else if(hours==14){
+			} else if (hours == 14) {
 				mcr.setTimeSlot("14:00-15:00");
-			}else if(hours==15){
+			} else if (hours == 15) {
 				mcr.setTimeSlot("15:00-16:00");
-			}else if(hours==16){
+			} else if (hours == 16) {
 				mcr.setTimeSlot("16:00-17:00");
-			}else if(hours==17){
+			} else if (hours == 17) {
 				mcr.setTimeSlot("17:00-18:00");
-			}else if(hours==18){
+			} else if (hours == 18) {
 				mcr.setTimeSlot("18:00-19:00");
-			}else if(hours==19){
+			} else if (hours == 19) {
 				mcr.setTimeSlot("19:00-20:00");
-			}else if(hours==20){
+			} else if (hours == 20) {
 				mcr.setTimeSlot("20:00-21:00");
-			}else if(hours==21){
+			} else if (hours == 21) {
 				mcr.setTimeSlot("21:00-22:00");
-			}else if(hours==22){
+			} else if (hours == 22) {
 				mcr.setTimeSlot("22:00-23:00");
-			}else if(hours==23){
+			} else if (hours == 23) {
 				mcr.setTimeSlot("23:00-00:00");
 			}
 			MouldCycleRuntimeExample mcrExp = new MouldCycleRuntimeExample();
-			mcrExp.createCriteria().andDateStrEqualTo(mcr.getDateStr()).andEquipmentNoEqualTo(item.getEquipmentNo()).andTimeSlotEqualTo(mcr.getTimeSlot());
+			mcrExp.createCriteria().andDateStrEqualTo(mcr.getDateStr()).andEquipmentNoEqualTo(item.getEquipmentNo())
+					.andTimeSlotEqualTo(mcr.getTimeSlot());
 			List<MouldCycleRuntime> mList = mouldCycleRuntimeMapper.selectByExample(mcrExp);
-			if(mList.size()>0){
+			if (mList.size() > 0) {
 				mcr.setId(mList.get(0).getId());
 				mouldCycleRuntimeMapper.updateByPrimaryKeySelective(mcr);
-			}else{
+			} else {
 				mouldCycleRuntimeMapper.insertSelective(mcr);
 			}
 		}
 	}
-	
+
 	private static String getStringFromHexStr(String hexStr) {
 		StringBuilder sb = new StringBuilder();
 		for (int i = 0; i < hexStr.length() / 2; i++) {
@@ -610,12 +624,12 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 	}
 
 	public static void main(String[] args) throws ParseException {
-//		UserHandler h = new UserHandler();
-//		h.timeCalibration();
+		// UserHandler h = new UserHandler();
+		// h.timeCalibration();
 		String a = "00:25:32";
 		SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss");
 		Date d = new Date();
-//		System.out.println(s.parse(a).getHours());
+		// System.out.println(s.parse(a).getHours());
 		// Date date = new Date();
 		// SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd,HH:mm:ss");
 		// String dateStr = sdf.format(date);
@@ -628,8 +642,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 
 		// String str = "1F51";
 		String input = "FAAF530000000000000000000000003137333030303239343310010000000000000000000"
-				+ "000000000000000000000001F51E85F00000000000045004A"
-				+ "54000100110000001308160F171F1308160F2D188FCA";
+				+ "000000000000000000000001F51E85F00000000000045004A" + "54000100110000001308160F171F1308160F2D188FCA";
 		// String temp = "0x"+str;
 		// int i = Integer.decode(temp);
 		// System.out.println(i);
@@ -639,29 +652,29 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		// System.out.println(str.substring(69*2));
 		// Date d = parseDate(str, start, 0, 0);
 		// System.out.println(d.toGMTString());
-//		int start = 69;
-//		int end = input.length() - 4; // 最后2位 0xXX,0xXX ,是CRC校验位
-//		logger.info("时间信息==" + input.substring(start * 2, end));
-//		if (end - start * 2 >= 24) {// 时间最少6位,1位显示0x00,开合算两个时间,所以是6*2*2=24
-//			// 本次运行周期内的开合模次数
-//			int periodCnt = (end - start * 2) / 24;
-//			logger.info("本次开合模次数==" + periodCnt);
-//			for (int pos = 0; pos < periodCnt; pos++) {
-//				// 合模时间
-//				MouldHistoryTime time = new MouldHistoryTime();
-//				time.setSeq(pos + 1);
-//				Date closeTime = parseDate(input, start, pos, 0);
-//				System.out.println(closeTime);
-//				time.setCloseTime(closeTime);
-//				// 开模时间
-//				Date openTime = parseDate(input, start, pos, 6);
-//				time.setOpenTime(openTime);
-//				System.out.println(openTime);
-//				int timeCost = (int) (openTime.getTime() - closeTime.getTime());
-//				time.setTimeCost(timeCost);
-//			}
-//		} else {
-//			logger.info("本次开合模次数==0");
-//		}
+		// int start = 69;
+		// int end = input.length() - 4; // 最后2位 0xXX,0xXX ,是CRC校验位
+		// logger.info("时间信息==" + input.substring(start * 2, end));
+		// if (end - start * 2 >= 24) {// 时间最少6位,1位显示0x00,开合算两个时间,所以是6*2*2=24
+		// // 本次运行周期内的开合模次数
+		// int periodCnt = (end - start * 2) / 24;
+		// logger.info("本次开合模次数==" + periodCnt);
+		// for (int pos = 0; pos < periodCnt; pos++) {
+		// // 合模时间
+		// MouldHistoryTime time = new MouldHistoryTime();
+		// time.setSeq(pos + 1);
+		// Date closeTime = parseDate(input, start, pos, 0);
+		// System.out.println(closeTime);
+		// time.setCloseTime(closeTime);
+		// // 开模时间
+		// Date openTime = parseDate(input, start, pos, 6);
+		// time.setOpenTime(openTime);
+		// System.out.println(openTime);
+		// int timeCost = (int) (openTime.getTime() - closeTime.getTime());
+		// time.setTimeCost(timeCost);
+		// }
+		// } else {
+		// logger.info("本次开合模次数==0");
+		// }
 	}
 }