فهرست منبع

修改平局周期逻辑

wutt 5 سال پیش
والد
کامیت
aca9fa9752

+ 1 - 18
cloud-model/src/main/java/com/hssx/cloudmodel/constant/Constant.java

@@ -1,22 +1,5 @@
 package com.hssx.cloudmodel.constant;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.hssx.cloudmodel.util.HttpKit;
-import com.hssx.cloudmodel.util.HttpRespMsg;
-import com.hssx.cloudmodel.util.WechatTemplateMessage;
-import org.apache.commons.lang3.StringEscapeUtils;
-
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * Author: 吴涛涛
  * Date : 2019 - 07 - 24 16:00
@@ -61,7 +44,7 @@ public class Constant {
     public static final Double ELECTRICITY_THRESHOLD = 0.2;//电量阈值
     public static final Double TEMPERATURE_THRESHOLD = 15.0;//温度阈值
     public static final String ELECTRICITY_TYPE = "电量告警";//告警类1 电量告警
-    public static final String ELECTRICITY_CONTENT= "电量过低";//告警内容 电量过低
+    public static final String ELECTRICITY_CONTENT = "电量过低";//告警内容 电量过低
     public static final String TEMPERATURE_TYPE = "温度告警";//告警类2 温度告警
     public static final String TEMPERATURE_CONTENT = "温度过高";//告警类2 温度过高
     public static final String MAIN_TAIN_TYPE = "保养计划";//告警类2 温度过高

+ 16 - 5
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldController.java

@@ -7,23 +7,21 @@ import com.hssx.cloudmodel.entity.Mould;
 import com.hssx.cloudmodel.entity.User;
 import com.hssx.cloudmodel.entity.vo.MouldVO;
 import com.hssx.cloudmodel.entity.vo.UserVO;
-import com.hssx.cloudmodel.service.*;
+import com.hssx.cloudmodel.service.MouldService;
+import com.hssx.cloudmodel.service.ProjectService;
+import com.hssx.cloudmodel.service.UserService;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.PageUtil;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.util.List;
-
 /**
  * @author 吴涛涛
  * @since 2019-07-30
@@ -234,5 +232,18 @@ public class MouldController {
 //        HttpRespMsg msg = new HttpRespMsg();
 //    }
 
+
+    /**
+     * 运行次数更新
+     */
+    @ApiOperation("运行次数更新")
+    @RequestMapping("/updateRuntimesTask")
+    @ResponseBody
+    @Scheduled(cron = "0 */5 * * * ?")//定时任务,每5分钟检测一次
+    public HttpRespMsg updateRuntimesTask() throws Exception {
+        HttpRespMsg msg = mouldService.updateRuntimesTask();
+        return msg;
+    }
+
 }
 

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

@@ -2,7 +2,6 @@ package com.hssx.cloudmodel.controller;
 
 
 import org.springframework.web.bind.annotation.RequestMapping;
-
 import org.springframework.web.bind.annotation.RestController;
 
 /**

+ 3 - 2
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldHistoryTimeMapper.java

@@ -1,8 +1,7 @@
 package com.hssx.cloudmodel.mapper;
 
-import com.hssx.cloudmodel.entity.MouldHistoryTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hssx.cloudmodel.entity.vo.MouldHistoryTimeVO;
+import com.hssx.cloudmodel.entity.MouldHistoryTime;
 import com.hssx.cloudmodel.entity.vo.MouldHistoryVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -23,4 +22,6 @@ public interface MouldHistoryTimeMapper extends BaseMapper<MouldHistoryTime> {
 
     List<MouldHistoryTime> getOpeningAndClosingTimesChartCycleExcel(@Param("startTime")String startTime,@Param("endTime")String time,@Param("equipmentNo")String equipmentNo
             );
+
+    List<MouldHistoryTime> selectListByTime(@Param("time")String time);
 }

+ 0 - 2
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldMapper.java

@@ -27,8 +27,6 @@ public interface MouldMapper extends BaseMapper<Mould> {
 
     MouldVO getDetailById(@Param("mouldVO")MouldVO mouldVO);
 
-    List<MouldVO> maintainMouldList(UserVO userVO);
-
     List<MouldVO> selectListByCompanyId(@Param("companyId")Integer companyId,@Param("projectId")Integer projectId);
 
     void updateModelProjectIdAndEquipmentIdToNullById(@Param("model")Mould model);

+ 2 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldService.java

@@ -35,4 +35,6 @@ public interface MouldService extends IService<Mould> {
     HttpRespMsg changeMouldEquipment(Mould mould,Integer mouldId, String token);
 
     HttpRespMsg packageLoss();
+
+    HttpRespMsg updateRuntimesTask();
 }

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

@@ -1,28 +1,24 @@
 package com.hssx.cloudmodel.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hssx.cloudmodel.entity.*;
 import com.hssx.cloudmodel.entity.vo.MouldHistoryTimeVO;
 import com.hssx.cloudmodel.entity.vo.MouldHistoryVO;
 import com.hssx.cloudmodel.mapper.*;
 import com.hssx.cloudmodel.service.MouldHistoryService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hssx.cloudmodel.util.ExcelUtil;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.TimeAndCountUtil;
-import org.apache.xmlbeans.impl.common.ConcurrentReaderHashMap;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.thymeleaf.expression.Maps;
 
 import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.text.SimpleDateFormat;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * <p>
@@ -139,8 +135,9 @@ public class MouldHistoryServiceImpl extends ServiceImpl<MouldHistoryMapper, Mou
         } else {
             cycle = 40000;
         }
-        Integer maxCycle = cycle + 10000;
-        Integer minCycle = cycle - 10000;
+        //筛选10s-200s
+        Integer maxCycle = 10000*200;
+        Integer minCycle = 10000;
         Map<String, MouldHistoryTimeVO> map = TimeAndCountUtil.getMap();
         List<MouldHistoryVO> list = mouldHistoryTimeMapper.getOpeningAndClosingTimesChartCycle(time, equipmentNo, maxCycle, minCycle);
         Integer count = 0;

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

@@ -1,31 +1,27 @@
 package com.hssx.cloudmodel.service.impl;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hssx.cloudmodel.constant.Constant;
 import com.hssx.cloudmodel.entity.*;
-import com.hssx.cloudmodel.entity.vo.MouldEquipmentVO;
 import com.hssx.cloudmodel.entity.vo.MouldVO;
 import com.hssx.cloudmodel.entity.vo.ProjectVO;
 import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.mapper.*;
-import com.hssx.cloudmodel.service.InjectionMoldingService;
 import com.hssx.cloudmodel.service.MouldService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.hssx.cloudmodel.util.*;
+import com.hssx.cloudmodel.util.GainTokenUtil;
+import com.hssx.cloudmodel.util.HttpRespMsg;
+import com.hssx.cloudmodel.util.ListUtil;
+import com.hssx.cloudmodel.util.WechatTemplateUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringEscapeUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -70,16 +66,18 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
     MouldHistoryTimeMapper mouldHistoryTimeMapper;
     @Resource
     PacketLossRecordMapper packetLossRecordMapper;
+    @Resource
+    MouldCycleRuntimeMapper mouldCycleRuntimeMapper;
 
 
     @Override
-    public HttpRespMsg addAndUpdateMould(Mould mould, User user, Integer dynamicId,InjectionMolding injectionMolding) {
+    public HttpRespMsg addAndUpdateMould(Mould mould, User user, Integer dynamicId, InjectionMolding injectionMolding) {
         HttpRespMsg msg = new HttpRespMsg();
         if (mould.getId() != null) {
             //修改
             Mould mou = mouldMapper.selectById(mould.getId());
             Mould m = mouldMapper.selectOne(new QueryWrapper<Mould>().eq("model_no", mould.getModelNo()));
-            if (mou.getModelNo().equals(mould.getModelNo())  || m == null){
+            if (mou.getModelNo().equals(mould.getModelNo()) || m == null) {
                 if (mould.getProduceCompanyId() != null) {
                     Company company = companyMapper.selectById(mould.getProduceCompanyId());
                     mould.setProduceCompanyName(company.getCompanyName());
@@ -225,7 +223,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         } else {
             MouldVO mould = mouldMapper.getDetailById(mouldVO);
             InjectionMolding molding = injectionMoldingMapper.selectOne(new QueryWrapper<InjectionMolding>().eq("mould_id", mouldVO.getId()));
-            if(null != molding){
+            if (null != molding) {
                 mould.setInjectionMolding(molding);
             }
             map.put("vo", mould);
@@ -331,9 +329,9 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                 uids.add(-1);
                 List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", uids).isNotNull("openid").eq("is_disable", 1));
                 //公众号的推送to do
-                userList.forEach(u ->{
+                userList.forEach(u -> {
                     try {
-                        WechatTemplateUtil.sendMaintainTemplateMessage(u.getOpenid(),mould.getModelNo()+"-"+mould.getModelName(),Constant.MAIN_TAIN_TYPE,Constant.MAIN_TAIN_CONTENT +sumCount+"次数",token);
+                        WechatTemplateUtil.sendMaintainTemplateMessage(u.getOpenid(), mould.getModelNo() + "-" + mould.getModelName(), Constant.MAIN_TAIN_TYPE, Constant.MAIN_TAIN_CONTENT + sumCount + "次数", token);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -556,7 +554,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
     }
 
     @Override
-    public HttpRespMsg changeMouldEquipment(Mould mould,Integer mouldId,String token) {
+    public HttpRespMsg changeMouldEquipment(Mould mould, Integer mouldId, String token) {
         HttpRespMsg msg = new HttpRespMsg();
         User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
         if (currentUser != null) {
@@ -591,22 +589,22 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         HttpRespMsg msg = new HttpRespMsg();
         Date now = new Date();
         SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
-        int housTime = now.getDay()-1;
+        int housTime = now.getDay() - 1;
         now.setDate(housTime);
         String lastOpenTime = sdf1.format(now);
         try {
-            String  lastOpenTimeDate =  lastOpenTime+ "59:59";
+            String lastOpenTimeDate = lastOpenTime + "59:59";
             List<MouldHistory> mouldHistorys = mouldHistoryMapper.selectListByTimeCondition(lastOpenTimeDate);
             for (MouldHistory mouldHistory : mouldHistorys) {
                 Integer count = mouldHistoryTimeMapper.selectCount(new QueryWrapper<MouldHistoryTime>().eq("equipment_no", mouldHistory.getEquipmentNo()).lt("history_id", mouldHistory.getId()));
-                if(!count .equals(mouldHistory.getRunCnt())){
+                if (!count.equals(mouldHistory.getRunCnt())) {
                     PacketLossRecord record = packetLossRecordMapper.selectOne(new QueryWrapper<PacketLossRecord>().eq("equipment_no", mouldHistory.getEquipmentNo()));
-                    if(record != null){
-                        record.setCount(mouldHistory.getRunCnt()-count);
+                    if (record != null) {
+                        record.setCount(mouldHistory.getRunCnt() - count);
                         packetLossRecordMapper.updateById(record);
-                    }else{
+                    } else {
                         PacketLossRecord packRecord = new PacketLossRecord();
-                        packRecord.setCount(mouldHistory.getRunCnt()-count);
+                        packRecord.setCount(mouldHistory.getRunCnt() - count);
                         packRecord.setEquipmentNo(mouldHistory.getEquipmentNo());
                         packetLossRecordMapper.insert(packRecord);
                     }
@@ -617,4 +615,40 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         }
         return msg;
     }
+
+    @Override
+    public HttpRespMsg updateRuntimesTask() {
+        List<MouldHistoryTime> list = mouldHistoryTimeMapper.selectListByTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
+        Map<String, List<MouldHistoryTime>> map = list.stream().collect(Collectors.groupingBy(MouldHistoryTime::getEquipmentNo));
+        for (Map.Entry<String, List<MouldHistoryTime>> stringListEntry : map.entrySet()) {
+            for (int i = 0; i < 24; i++) {
+                MouldCycleRuntime mr = new MouldCycleRuntime();
+                final int first = i;
+                final int second = i + 1;
+                List<MouldHistoryTime> collect = stringListEntry.getValue().stream().filter(x -> (x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second)).collect(Collectors.toList());
+                System.out.println(collect);
+                System.out.println((int) stringListEntry.getValue().stream().filter(x -> x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second).count());
+                mr.setRuntime((int) stringListEntry.getValue().stream().filter(x -> (x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second)).count());
+                String iStr = i < 10 ? ("0" + i) : i + "";
+                int i1 = i + 1;
+                String iStrAfterOne = (i1) < 10 ? ("0" + i1) : i1 + "";
+                mr.setTimeSlot(iStr + ":00-" + iStrAfterOne + ":00");
+                if(!CollectionUtils.isEmpty(stringListEntry.getValue())){
+                    mr.setDateStr(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(stringListEntry.getValue().get(0).getOpenTime()));
+                }else{
+                    mr.setDateStr(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
+                }
+                mr.setEquipmentNo(stringListEntry.getKey());
+                MouldCycleRuntime id = mouldCycleRuntimeMapper.selectOne(new QueryWrapper<MouldCycleRuntime>().eq("time_slot",mr.getTimeSlot()).eq("equipment_no",mr.getEquipmentNo()).eq("date_str",mr.getDateStr()).select("id"));
+                if (null != id) {
+                    mr.setId(id.getId());
+                    mouldCycleRuntimeMapper.updateById(mr);
+                } else {
+                    mouldCycleRuntimeMapper.insert(mr);
+                }
+            }
+        }
+        return new HttpRespMsg();
+    }
 }
+

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

@@ -243,7 +243,8 @@ public class QcloudUntil {
 
 //        PutObjectResult upload = upload("D:\\1\\爱你.txt","ai.txt");
 //        System.out.println(upload.ge);
-        downLoadFile("upload_files/ai.txt","D:\\34.txt");
-//        System.out.println("存储桶列表" + getBucketList("/upload_files/"));
+//        downLoadFile("upload_files/","D:\\34.txt");
+        //d7608996819d4be69805fdbcc53bbb84.txt
+        System.out.println("存储桶列表" + getBucketList("/upload_files/"));
     }
 }

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

@@ -14,7 +14,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?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_mould?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

+ 9 - 0
cloud-model/src/main/resources/mapper/MouldHistoryTimeMapper.xml

@@ -47,4 +47,13 @@
         </where>
         ORDER BY open_time
     </select>
+
+    <select id="selectListByTime" resultMap="BaseResultMap">
+        select
+            history_id, seq, close_time, open_time, time_cost, equipment_no
+        from
+            `mould_history_time`
+        where
+            DATE_FORMAT(open_time,'%Y-%m-%d')= #{time}
+    </select>
 </mapper>

+ 4 - 5
cloud-model/src/main/resources/mapper/MouldMapper.xml

@@ -88,11 +88,10 @@
         select
         tbm.id id,tbm.model_no model_no, tbm.model_name model_name,tbm.initial_modulus initial_modulus,tbm.rfid rfid,tbm.creator_id creator_id,tbm.equipment_id equipment_id,tbm.is_maintain,tbm.holes,
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbc.company_name companyName,tbco.company_name produceCompany,tbm.pre_update_id,
-        tbp.manager mangerName,tbco.company_address area,tbmp.hill_number hillNumber,tbm.oc_cycle oc_cycle,tbp.manager_id managerId,tbmp.equipment_name equipmentName,
+        tbp.manager mangerName,tbco.company_address area,tbm.oc_cycle oc_cycle,tbp.manager_id managerId,tbmp.equipment_name equipmentName,
         tbmp.equipment_no equipmentNo,tbm.setting_life setting_life,tbp.owner_company_name ownerCompanyName,tbm.run_times run_times,
         tbmp.lng,tbmp.lat,tbmp.stage,(SELECT indate FROM `mould_history` WHERE equipment_no=equipmentNo ORDER BY indate DESC LIMIT 1) lastopentime
-        ,tbmp.curhill_number hill_number,
-        tbmp.curtemperature temperature
+        ,tbmp.curhill_number hillNumber,tbmp.curtemperature temperature
         from
         tb_mould tbm
         left join
@@ -142,7 +141,7 @@
         tbp.manager mangerName,tbco.company_address area,tbm.oc_cycle oc_cycle,tbm.creator_id creator_id,tbmp.equipment_name equipmentName,
         tbmp.equipment_no equipmentNo,tbm.setting_life setting_life,tbp.owner_company_name ownerCompanyName,tbm.run_times run_times,
         tbmp.lng,tbmp.lat,tbmp.stage,(SELECT indate FROM `mould_history` WHERE equipment_no=equipmentNo ORDER BY indate DESC LIMIT 1) lastopentime,
-        tbmp.curhill_number hill_number,
+        tbmp.curhill_number hillNumber,
         tbmp.curtemperature temperature
         from
         tb_mould tbm
@@ -193,7 +192,7 @@
         tbm.id id,tbm.model_no model_no, tbm.model_name,tbm.initial_modulus initial_modulus,tbp.manager_id managerId,tbm.produce_company_id produce_company_id,
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbco.company_name produceCompany,tbm.creator_id creator_id,tbm.holes,
         tbp.manager mangerName,tbco.company_address area,tbm.rfid rfid,tbm.oc_cycle oc_cycle,tbc.company_name companyName,tbm.pre_update_id,tbmp.equipment_name equipmentName,
-        tbmp.equipment_no equipmentNo,tbmp.curhill_number hill_number,
+        tbmp.equipment_no equipmentNo,tbmp.curhill_number hillNumber,
         tbmp.curtemperature temperature,tbm.setting_life setting_life,tbm.run_times run_times,tbmp.stage
         from
         tb_mould tbm

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 380 - 319
cloud-socket/src/com/js/kbt/socket/UserHandler.java


+ 5 - 1
cloud-socket/src/log4j.properties

@@ -23,4 +23,8 @@ log4j.logger.com.ibatis.common.jdbc.ScriptRunner=INFO
 log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=INFO
 log4j.logger.java.sql.Connection=INFO
 log4j.logger.java.sql.Statement=INFO
-log4j.logger.java.sql.PreparedStatement=INFO, A1     
+log4j.logger.java.sql.PreparedStatement=INFO, A1     
+
+
+
+