Просмотр исходного кода

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	target/classes/main/resources/mapper/MouldEquipmentMapper.xml
#	target/classes/main/resources/mapper/MouldMapper.xml
5 лет назад
Родитель
Сommit
d8bff30911

+ 1 - 1
cloud-model/src/main/resources/application.properties

@@ -13,7 +13,7 @@ spring.thymeleaf.jackson.date-format=yyyy-MM-dd HH:mm:ss
 # ####################################################################################################
 # Êý¾ÝÔ´ÅäÖÃ
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.url=jdbc:mysql://118.190.47.230:3306/new_cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=p011430seya1026
 #spring.datasource.druid.test-on-borrow=true

+ 1 - 1
cloud-socket/.classpath

@@ -4,7 +4,7 @@
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
 	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0"/>
 	<classpathentry kind="output" path="build/classes"/>
 </classpath>

+ 3 - 3
cloud-socket/.settings/org.eclipse.jdt.core.prefs

@@ -1,12 +1,12 @@
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
 org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.8
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8

+ 3 - 0
cloud-socket/src/com/js/kbt/mapper/MouldHistoryTimeMapper.java

@@ -1,5 +1,6 @@
 package com.js.kbt.mapper;
 
+import com.js.kbt.model.MouldHistory;
 import com.js.kbt.model.MouldHistoryTime;
 import com.js.kbt.model.MouldHistoryTimeExample;
 import java.util.List;
@@ -51,4 +52,6 @@ public interface MouldHistoryTimeMapper {
 	int updateByExample(@Param("record") MouldHistoryTime record, @Param("example") MouldHistoryTimeExample example);
 
 	List<MouldHistoryTime> selectByEquipmentNoAndThanZero(@Param("equipmentNo") String equipmentNo);
+
+	MouldHistoryTime getDateByHistory(@Param("id")Long id);
 }

+ 4 - 0
cloud-socket/src/com/js/kbt/mapper/MouldHistoryTimeMapper.xml

@@ -244,4 +244,8 @@
   select  history_id, seq, close_time, open_time, time_cost, equipment_no
   from mould_history_time where equipment_no = #{equipmentNo} and time_cost &gt; 0
   </select>
+  <select id="getDateByHistory" resultMap="BaseResultMap">
+  select history_id, seq, close_time, open_time, time_cost, equipment_no
+  from mould_history_time where history_id = #{id}
+  </select>
 </mapper>

+ 35 - 25
cloud-socket/src/com/js/kbt/socket/UserHandler.java

@@ -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);
 			}
 		}

+ 1 - 1
target/classes/main/resources/application.properties

@@ -13,7 +13,7 @@ spring.thymeleaf.jackson.date-format=yyyy-MM-dd HH:mm:ss
 # ####################################################################################################
 # Êý¾ÝÔ´ÅäÖÃ
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.url=jdbc:mysql://118.190.47.230:3306/new_cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=p011430seya1026
 #spring.datasource.druid.test-on-borrow=true