Преглед изворни кода

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 година
родитељ
комит
6667b11b40

+ 50 - 28
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -94,9 +94,9 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     System.out.println("上传文件名称" + file.getName() + ", dir = " + dir.getAbsolutePath());
                     int pos = fileName.lastIndexOf(".");
                     String rand = UUID.randomUUID().toString().replaceAll("-", "");
-                    String sufix = fileName.substring(pos);
-                    fileName = rand + sufix;
-                    projectFile.setFileType(sufix);//文件后缀
+                    String sufix1 = fileName.substring(pos);
+                    fileName = rand + sufix1;
+                    projectFile.setFileType(sufix1);//文件后缀
                     projectFile.setFileUrl("/upload/" + fileName);
                     projectFile.setBlongType(blongType);
                     File saveFile = new File(dir, fileName);
@@ -112,16 +112,18 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     }
                     //模具报废情况下,设置files2
                     String dFile2 = "";
+                    String fileName2 = "";
+                    String sufix2 = "";
                     if (blongType == 5 && file2 != null && !file2.isEmpty()) {
-                        String fileName2 = file2.getOriginalFilename();
+                        fileName2 = file2.getOriginalFilename();
                         projectFile.setFileName2(fileName2);
                         projectFile.setFileSize2(FileUtil.getReadableFileSize(file2.getSize()));
                         System.out.println("上传文件2名称" + file2.getName() + ", dir = " + dir.getAbsolutePath());
                         pos = fileName2.lastIndexOf(".");
                         rand = UUID.randomUUID().toString().replaceAll("-", "");
-                        sufix = fileName2.substring(pos);
-                        fileName2 = rand + sufix;
-                        projectFile.setFileType2(sufix);//文件后缀
+                        sufix2 = fileName2.substring(pos);
+                        fileName2 = rand + sufix2;
+                        projectFile.setFileType2(sufix2);//文件后缀
                         projectFile.setFileUrl2("/upload/" + fileName2);
                         File saveFile2 = new File(dir, fileName2);
                         try {
@@ -144,34 +146,54 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                         projectFile.setDwgType(userVO.getDwgType());
                     }
                     mouldFileMapper.insert(projectFile);
-                    //上传完,需要生成pdf
-                    String dFile1 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
-                    openOfficeService.start();
-                    File testFile = new File(dFile1);
-                    if (!testFile.exists()) {
-                        openOfficeService.office2PDF(path + fileName, dFile1);
-                    }
-                    PdfFile pdfFile = new PdfFile();
-                    pdfFile.setPdfUrl("/upload/" + dFile1.substring(path.length()));
-                    pdfFile.setFileId(projectFile.getId());
-                    pdfFile.setType(0);
-                    pdfFile.setRafId(projectFile.getModelId());
-                    pdfFile.setSourceFileUrl(projectFile.getFileUrl());
-                    pdfFileMapper.insert(pdfFile);
-                    if (blongType == 5 && file2 != null && !file2.isEmpty()) {
-                        dFile2 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
-                        testFile = new File(dFile2);
+                    if(".pdf".equals(sufix1)){
+                        PdfFile pdfFile = new PdfFile();
+                        pdfFile.setPdfUrl(projectFile.getFileUrl());
+                        pdfFile.setFileId(projectFile.getId());
+                        pdfFile.setType(0);
+                        pdfFile.setRafId(projectFile.getModelId());
+                        pdfFile.setSourceFileUrl(projectFile.getFileUrl());
+                        pdfFileMapper.insert(pdfFile);
+                    }else{
+                        //上传完,需要生成pdf
+                        String dFile1 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
+                        openOfficeService.start();
+                        File testFile = new File(dFile1);
                         if (!testFile.exists()) {
-                            openOfficeService.office2PDF(path + fileName, dFile2);
+                            openOfficeService.office2PDF(path + fileName, dFile1);
                         }
-                        pdfFile = new PdfFile();
-                        pdfFile.setPdfUrl("/upload/" + dFile2.substring(path.length()));
+                        PdfFile pdfFile = new PdfFile();
+                        pdfFile.setPdfUrl("/upload/" + dFile1.substring(path.length()));
                         pdfFile.setFileId(projectFile.getId());
                         pdfFile.setType(0);
                         pdfFile.setRafId(projectFile.getModelId());
-                        pdfFile.setSourceFileUrl(projectFile.getFileUrl2());
+                        pdfFile.setSourceFileUrl(projectFile.getFileUrl());
                         pdfFileMapper.insert(pdfFile);
                     }
+                    if (blongType == 5 && file2 != null && !file2.isEmpty()) {
+                        if(".pdf".equals(sufix2)){
+                            PdfFile pdfFile = new PdfFile();
+                            pdfFile.setPdfUrl(projectFile.getFileUrl2());
+                            pdfFile.setFileId(projectFile.getId());
+                            pdfFile.setType(0);
+                            pdfFile.setRafId(projectFile.getModelId());
+                            pdfFile.setSourceFileUrl(projectFile.getFileUrl2());
+                            pdfFileMapper.insert(pdfFile);
+                        }else{
+                            dFile2 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
+                            File testFile = new File(dFile2);
+                            if (!testFile.exists()) {
+                                openOfficeService.office2PDF(path + fileName2, dFile2);
+                            }
+                            PdfFile pdfFile = new PdfFile();
+                            pdfFile.setPdfUrl("/upload/" + dFile2.substring(path.length()));
+                            pdfFile.setFileId(projectFile.getId());
+                            pdfFile.setType(0);
+                            pdfFile.setRafId(projectFile.getModelId());
+                            pdfFile.setSourceFileUrl(projectFile.getFileUrl2());
+                            pdfFileMapper.insert(pdfFile);
+                        }
+                    }
                     //关闭openOffice
                     openOfficeService.shutdown();
                     Project project = projectMapper.selectById(mould.getProjectId());

+ 24 - 24
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldHistoryServiceImpl.java

@@ -40,53 +40,53 @@ public class MouldHistoryServiceImpl extends ServiceImpl<MouldHistoryMapper, Mou
         Map<String, List<MouldHistoryVO>> mapList = list.stream().collect(Collectors.groupingBy(MouldHistoryVO::getTime));
         for(Map.Entry<String, List<MouldHistoryVO>> entry:mapList.entrySet()){
             if("00".equals(entry.getKey())){
-                map.put("00:00-01:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("00:00-01:00",(int)(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("01".equals(entry.getKey())){
-                map.put("01:00-02:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("01:00-02:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("02".equals(entry.getKey())){
-                map.put("02:00-03:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("02:00-03:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("03".equals(entry.getKey())){
-                map.put("03:00-04:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("03:00-04:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("04".equals(entry.getKey())){
-                map.put("04:00-05:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("04:00-05:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("05".equals(entry.getKey())){
-                map.put("05:00-06:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("05:00-06:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("06".equals(entry.getKey())){
-                map.put("06:00-07:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("06:00-07:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("07".equals(entry.getKey())){
-                map.put("07:00-08:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("07:00-08:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("08".equals(entry.getKey())){
-                map.put("08:00-09:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("08:00-09:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("09".equals(entry.getKey())){
-                map.put("09:00-10:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("09:00-10:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("10".equals(entry.getKey())){
-                map.put("10:00-11:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("10:00-11:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("11".equals(entry.getKey())){
-                map.put("11:00-12:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("11:00-12:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("12".equals(entry.getKey())){
-                map.put("12:00-13:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("12:00-13:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("13".equals(entry.getKey())){
-                map.put("13:00-14:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("13:00-14:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("14".equals(entry.getKey())){
-                map.put("14:00-15:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("14:00-15:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("15".equals(entry.getKey())){
-                map.put("15:00-16:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("15:00-16:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("16".equals(entry.getKey())){
-                map.put("16:00-17:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("16:00-17:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("17".equals(entry.getKey())){
-                map.put("17:00-18:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("17:00-18:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("18".equals(entry.getKey())){
-                map.put("18:00-19:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("18:00-19:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("19".equals(entry.getKey())){
-                map.put("19:00-20:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("19:00-20:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("20".equals(entry.getKey())){
-                map.put("20:00-21:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("20:00-21:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("21".equals(entry.getKey())){
-                map.put("21:00-22:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("21:00-22:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("22".equals(entry.getKey())){
-                map.put("22:00-23:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("22:00-23:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }else if("23".equals(entry.getKey())){
-                map.put("23:00-24:00",entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).sum());
+                map.put("23:00-24:00",(int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
             }
         }
         System.out.println("原来的map===>"+map);

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

@@ -35,7 +35,7 @@ public class PdfFileServiceImpl extends ServiceImpl<PdfFileMapper, PdfFile> impl
             if(newPdfFile!=null){
                 msg.data = newPdfFile.getPdfUrl();
             }else{
-                msg.setError("文件未找到,请联系管理员");
+                msg.setError("此文件暂不支持在线预览操作");
             }
         return msg;
     }

+ 2 - 2
cloud-model/src/main/java/com/hssx/cloudmodel/util/OpenOfficeService.java

@@ -106,8 +106,8 @@ public class OpenOfficeService {
 
 	public static void main(String[] args) {
 		OpenOfficeService service = new OpenOfficeService();
-		String sFile = "D:\\wttxls.xls";
-		String dFile = "D:\\wttxls.pdf";
+		String sFile = "D:\\1.pdf";
+		String dFile = "D:\\wttxls111000000000000000.pdf";
 		service.start();
 		File testFile = new File(dFile);
 		if(!testFile .exists()){

+ 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/cloud_model_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/new_cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=p011430seya1026
 #spring.datasource.druid.test-on-borrow=true

+ 37 - 23
cloud-socket/src/com/js/kbt/socket/UserHandler.java

@@ -169,6 +169,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 			// 本次运行周期内的开合模次数
 			int periodCnt = (end - start * 2) / 24;
 			logger.info("本次开合模次数==" + periodCnt);
+			long  aHeadOpenTimeLongVal = 0L;
 			for (int pos = 0; pos < periodCnt; pos++) {
 				// 合模时间
 				MouldHistoryTime time = new MouldHistoryTime();
@@ -180,10 +181,16 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 				// 开模时间
 				Date openTime = parseDate(input, start, pos, 6);
 				time.setOpenTime(openTime);
-				int timeCost = (int) (openTime.getTime() - closeTime.getTime());
-				time.setTimeCost(timeCost);
+				if(pos==0){
+					time.setTimeCost(0);
+				}else{
+					logger.info("本次开合周期--"+(openTime.getTime() - aHeadOpenTimeLongVal));
+					time.setTimeCost((int)(openTime.getTime() - aHeadOpenTimeLongVal));
+				}
 				mouldHistoryTimeMapper.insertSelective(time);
 				logger.info("mouldHistoryTime数据添加完毕");
+				aHeadOpenTimeLongVal = openTime.getTime();
+				logger.info("上一包数据的开合时间戳--"+aHeadOpenTimeLongVal);
 			}
 		} else {
 			logger.info("本次开合模次数==0");
@@ -206,16 +213,16 @@ 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) {
+//			// 证明盒子动了,找寻上一条记录
+//			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()
@@ -224,7 +231,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 				logger.info("totalTime" + totalTime);
 				avgTime = (int)(totalTime / (historyList.size() - 1));
 			}
-		}
+//		}
 		logger.info("avgTime-->" + avgTime);
 		
 		handleModLogic(item, avgTime);
@@ -278,12 +285,14 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 
 	private void handleModLogic(MouldHistory item, int avgTime) {
 		logger.info("进了handleModLogic逻辑--");
+		logger.info("item==>"+item);
 		TbMouldEquipmentExample meqExp = new TbMouldEquipmentExample();
 		meqExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
 		if (tbMouldEquipmentMapper.countByExample(meqExp) > 0) {
 			TbMouldEquipment me = tbMouldEquipmentMapper.selectByExample(meqExp).get(0);
 			me.setHillNumber(item.getBattery() + "");
 			if (item.getLng() != null) {
+				logger.info("更新经纬度:");
 				me.setLng(Double.parseDouble(item.getLng()));
 				me.setLat(Double.parseDouble(item.getLat()));
 			}
@@ -306,10 +315,12 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 
 			}
 			tbMouldEquipmentMapper.updateByPrimaryKeySelective(me);
+			logger.info("更新完了tbMouldEquipment的状态和温度以及经纬度");
 			TbMouldExample tExp = new TbMouldExample();
 			tExp.setOrderByClause("id desc limit 1");
 			tExp.createCriteria().andEquipmentIdEqualTo(me.getId());
 			if (tbMouldMapper.countByExample(tExp) > 0) {
+				logger.info("准备更新运行次数:");
 				TbMould tm = tbMouldMapper.selectByExample(tExp).get(0);
 				tm.setState(item.getStatus());
 				// 云模盒运行次数+模具的历史运行次数
@@ -342,14 +353,15 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 	}
 
 	private static Date parseDate(String input, int start, int pos, int dateStartPos) {
-		String year = input.substring((start + pos * 6 + dateStartPos) * 2, (start + pos * 6 + 1 + dateStartPos) * 2);
-		String month = input.substring((start + pos * 6 + 1 + dateStartPos) * 2,
-				(start + pos * 6 + 2 + dateStartPos) * 2);
-		String day = input.substring((start + pos * 6 + 2 + dateStartPos) * 2,
-				(start + pos * 6 + 3 + dateStartPos) * 2);
-		String hh = input.substring((start + pos * 6 + 3 + dateStartPos) * 2, (start + pos * 6 + 4 + dateStartPos) * 2);
-		String mm = input.substring((start + pos * 6 + 4 + dateStartPos) * 2, (start + pos * 6 + 5 + dateStartPos) * 2);
-		String ss = input.substring((start + pos * 6 + 5 + dateStartPos) * 2, (start + pos * 6 + 6 + dateStartPos) * 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);
 		StringBuilder sb = new StringBuilder();
 		int yearInt = Integer.parseInt(year, 16);
 		if (yearInt == 0) {
@@ -374,7 +386,7 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		}
 		return parseDate;
 	}
-
+	
 	private static String getStringFromHexStr(String hexStr) {
 		StringBuilder sb = new StringBuilder();
 		for (int i = 0; i < hexStr.length() / 2; i++) {
@@ -524,7 +536,9 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
 		// System.out.println("reverseParseHex-----"+reverseParseHex);
 
 		// String str = "1F51";
-		String input = "FAAF530000000000000000000000003137333030303239343310010000000000000000000000000000000000000000001F51E85F00000000000045004A54000100110000001308160F171F1308160F2D188FCA";
+		String input = "FAAF530000000000000000000000003137333030303239343310010000000000000000000"
+				+ "000000000000000000000001F51E85F00000000000045004A"
+				+ "54000100110000001308160F171F1308160F2D188FCA";
 		// String temp = "0x"+str;
 		// int i = Integer.decode(temp);
 		// System.out.println(i);