5 лет назад
Родитель
Сommit
054529c1ab
19 измененных файлов с 293 добавлено и 14 удалено
  1. 13 0
      cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldController.java
  2. 21 0
      cloud-model/src/main/java/com/hssx/cloudmodel/controller/PacketLossRecordController.java
  3. 108 0
      cloud-model/src/main/java/com/hssx/cloudmodel/entity/PacketLossRecord.java
  4. 3 0
      cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldHistoryMapper.java
  5. 2 1
      cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldHistoryTimeMapper.java
  6. 16 0
      cloud-model/src/main/java/com/hssx/cloudmodel/mapper/PacketLossRecordMapper.java
  7. 2 0
      cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldService.java
  8. 16 0
      cloud-model/src/main/java/com/hssx/cloudmodel/service/PacketLossRecordService.java
  9. 10 3
      cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldHistoryServiceImpl.java
  10. 41 0
      cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldServiceImpl.java
  11. 20 0
      cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/PacketLossRecordServiceImpl.java
  12. 1 1
      cloud-model/src/main/java/com/hssx/cloudmodel/util/CodeGenerator.java
  13. 5 2
      cloud-model/src/main/resources/application-prod.properties
  14. 6 0
      cloud-model/src/main/resources/mapper/MouldHistoryMapper.xml
  15. 1 1
      cloud-model/src/main/resources/mapper/MouldHistoryTimeMapper.xml
  16. 2 2
      cloud-model/src/main/resources/mapper/MouldMapper.xml
  17. 19 0
      cloud-model/src/main/resources/mapper/PacketLossRecordMapper.xml
  18. 5 2
      target/classes/main/resources/application-prod.properties
  19. 2 2
      target/classes/main/resources/mapper/MouldMapper.xml

+ 13 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldController.java

@@ -161,6 +161,19 @@ public class MouldController {
         HttpRespMsg msg = mouldService.maintenanceReminder();
         return msg;
     }
+
+    /**
+     * 丢包数据检测
+     */
+    @ApiOperation("丢包数据检测")
+    @RequestMapping("/packageLoss")
+    @ResponseBody
+    @Scheduled(cron = "0 0 23 * * ?")//配置时间点触发(每日中午00点)
+    public HttpRespMsg packageLoss() throws Exception {
+        HttpRespMsg msg = mouldService.packageLoss();
+        return msg;
+    }
+
     /**
      * 是否开启模具保养提醒
      * 参数 isMaintain 是否开启保养 0-是 1-否

+ 21 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/PacketLossRecordController.java

@@ -0,0 +1,21 @@
+package com.hssx.cloudmodel.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-10-30
+ */
+@RestController
+@RequestMapping("/packet-loss-record")
+public class PacketLossRecordController {
+
+}
+

+ 108 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/entity/PacketLossRecord.java

@@ -0,0 +1,108 @@
+package com.hssx.cloudmodel.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-10-30
+ */
+public class PacketLossRecord extends Model<PacketLossRecord> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 丢包监测数据表主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 云模盒设备编号
+     */
+    @TableField("equipment_no")
+    private String equipmentNo;
+
+    /**
+     * 丢包次数
+     */
+    @TableField("count")
+    private Integer count;
+
+    /**
+     * 检测时间
+     */
+    @TableField("indate")
+    private LocalDateTime indate;
+
+    /**
+     * 丢包时间
+     */
+    @TableField("loss_time")
+    private LocalDateTime lossTime;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getEquipmentNo() {
+        return equipmentNo;
+    }
+
+    public void setEquipmentNo(String equipmentNo) {
+        this.equipmentNo = equipmentNo;
+    }
+
+    public Integer getCount() {
+        return count;
+    }
+
+    public void setCount(Integer count) {
+        this.count = count;
+    }
+
+    public LocalDateTime getIndate() {
+        return indate;
+    }
+
+    public void setIndate(LocalDateTime indate) {
+        this.indate = indate;
+    }
+
+    public LocalDateTime getLossTime() {
+        return lossTime;
+    }
+
+    public void setLossTime(LocalDateTime lossTime) {
+        this.lossTime = lossTime;
+    }
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+    @Override
+    public String toString() {
+        return "PacketLossRecord{" +
+        "id=" + id +
+        ", equipmentNo=" + equipmentNo +
+        ", count=" + count +
+        ", indate=" + indate +
+        ", lossTime=" + lossTime +
+        "}";
+    }
+}

+ 3 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldHistoryMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.hssx.cloudmodel.entity.vo.MouldHistoryVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -18,4 +19,6 @@ import java.util.List;
 public interface MouldHistoryMapper extends BaseMapper<MouldHistory> {
 
     List<MouldHistoryVO> selectOpeningAndClosingTimesChart(@Param("equipmentNo") String equipmentNo, @Param("time") String time);
+
+    List<MouldHistory> selectListByTimeCondition(@Param("time")String lastOpenTimeDate);
 }

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

@@ -18,5 +18,6 @@ import java.util.List;
  */
 public interface MouldHistoryTimeMapper extends BaseMapper<MouldHistoryTime> {
 
-    List<MouldHistoryVO> getOpeningAndClosingTimesChartCycle(@Param("time")String time,@Param("equipmentNo")String equipmentNo);
+    List<MouldHistoryVO> getOpeningAndClosingTimesChartCycle(@Param("time")String time,@Param("equipmentNo")String equipmentNo
+    ,@Param("maxCycle")Integer maxCycle,@Param("minCycle")Integer minCycle);
 }

+ 16 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/PacketLossRecordMapper.java

@@ -0,0 +1,16 @@
+package com.hssx.cloudmodel.mapper;
+
+import com.hssx.cloudmodel.entity.PacketLossRecord;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-10-30
+ */
+public interface PacketLossRecordMapper extends BaseMapper<PacketLossRecord> {
+
+}

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

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

+ 16 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/PacketLossRecordService.java

@@ -0,0 +1,16 @@
+package com.hssx.cloudmodel.service;
+
+import com.hssx.cloudmodel.entity.PacketLossRecord;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-10-30
+ */
+public interface PacketLossRecordService extends IService<PacketLossRecord> {
+
+}

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

@@ -138,17 +138,24 @@ public class MouldHistoryServiceImpl extends ServiceImpl<MouldHistoryMapper, Mou
         MouldEquipment mouldEquipment = mouldEquipmentMapper.selectOne(new QueryWrapper<MouldEquipment>().eq("equipment_no", equipmentNo));
         Mould mould = mouldMapper.selectOne(new QueryWrapper<Mould>().eq("equipment_id", mouldEquipment.getId()));
         InjectionMolding molding = injectionMoldingMapper.selectOne(new QueryWrapper<InjectionMolding>().eq("mould_id", mould.getId()));
+        Integer cycle = 0;
+        if(molding != null){
+             cycle = (null == molding.getCycle())?40000:molding.getCycle();
+        }else{
+             cycle = 40000;
+        }
+        Integer maxCycle = cycle+10000;
+        Integer minCycle = cycle-10000;
         Map<String,MouldHistoryTimeVO> map = TimeAndCountUtil.getMap();
-        List<MouldHistoryVO> list = mouldHistoryTimeMapper.getOpeningAndClosingTimesChartCycle(time,equipmentNo);
+        List<MouldHistoryVO> list = mouldHistoryTimeMapper.getOpeningAndClosingTimesChartCycle(time,equipmentNo,maxCycle,minCycle);
         Integer count = 0;
         Map<String, List<MouldHistoryVO>> mapList = list.stream().collect(Collectors.groupingBy(MouldHistoryVO::getTime));
         MouldHistoryTimeVO vo = new MouldHistoryTimeVO();
         for(Map.Entry<String, List<MouldHistoryVO>> entry:mapList.entrySet()){
-            System.out.println("-----"+entry);
             vo.setMinCycle(entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).min().getAsInt());
             vo.setMaxCycle(entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).max().getAsInt());
             vo.setAvgCycle((int)entry.getValue().stream().mapToInt(MouldHistoryVO::getRunCnt).average().getAsDouble());
-            vo.setTheoryCycle(molding.getCycle()==null?4000:molding.getCycle());
+            vo.setTheoryCycle(cycle);
             if("00".equals(entry.getKey())){
                 map.put("00:00-01:00",vo);
             }else if("01".equals(entry.getKey())){

+ 41 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.Resource;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -63,6 +64,13 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
     MouldFileMapper mouldFileMapper;
     @Resource
     InjectionMoldingMapper injectionMoldingMapper;
+    @Resource
+    MouldHistoryMapper mouldHistoryMapper;
+    @Resource
+    MouldHistoryTimeMapper mouldHistoryTimeMapper;
+    @Resource
+    PacketLossRecordMapper packetLossRecordMapper;
+
 
     @Override
     public HttpRespMsg addAndUpdateMould(Mould mould, User user, Integer dynamicId,InjectionMolding injectionMolding) {
@@ -577,4 +585,37 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         }
         return msg;
     }
+
+    @Override
+    public HttpRespMsg packageLoss() {
+        HttpRespMsg msg = new HttpRespMsg();
+        Date now = new Date();
+        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
+        int housTime = now.getDay()-1;
+        now.setDate(housTime);
+        String lastOpenTime = sdf1.format(now);
+        try {
+            String  lastOpenTimeDate = "2019-10-24 23:" + "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()));
+                System.out.println("count----->"+count+"     runCount---"+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);
+                        packetLossRecordMapper.updateById(record);
+                    }else{
+                        PacketLossRecord packRecord = new PacketLossRecord();
+                        packRecord.setCount(mouldHistory.getRunCnt()-count);
+                        packRecord.setEquipmentNo(mouldHistory.getEquipmentNo());
+                        packetLossRecordMapper.insert(packRecord);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return msg;
+    }
 }

+ 20 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/PacketLossRecordServiceImpl.java

@@ -0,0 +1,20 @@
+package com.hssx.cloudmodel.service.impl;
+
+import com.hssx.cloudmodel.entity.PacketLossRecord;
+import com.hssx.cloudmodel.mapper.PacketLossRecordMapper;
+import com.hssx.cloudmodel.service.PacketLossRecordService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-10-30
+ */
+@Service
+public class PacketLossRecordServiceImpl extends ServiceImpl<PacketLossRecordMapper, PacketLossRecord> implements PacketLossRecordService {
+
+}

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/util/CodeGenerator.java

@@ -204,7 +204,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //此处user是表名,多个英文逗号分割
-        strategy.setInclude("mould_down_packet");
+        strategy.setInclude("packet_loss_record");
 //        strategy.setExclude();//数据库表全生成
 //        strategy.setInclude(scanner("user").split(","));//表名,多个英文逗号分割
         strategy.setControllerMappingHyphenStyle(true);

+ 5 - 2
cloud-model/src/main/resources/application-prod.properties

@@ -16,9 +16,12 @@ 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_model_test?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.url=jdbc:mysql://127.0.0.1:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
-spring.datasource.password=p011430seya1026
+spring.datasource.password=Hssx2019.!
 #spring.datasource.druid.test-on-borrow=true
 #spring.datasource.druid.test-while-idle=true
 # ####################################################################################################

+ 6 - 0
cloud-model/src/main/resources/mapper/MouldHistoryMapper.xml

@@ -60,4 +60,10 @@
        ORDER BY indate
     </select>
 
+    <select id="selectListByTimeCondition" resultMap="BaseResultMap">
+        SELECT id, sim, equipment_no, run_cnt, crc_code, indate
+        FROM(SELECT id, sim, equipment_no, run_cnt, crc_code, indate FROM mould_history ORDER BY indate DESC LIMIT 10000) a
+        where DATE_FORMAT(indate,'%Y-%m-%d %H:%i:%s') &lt;= #{time} GROUP BY equipment_no
+    </select>
+
 </mapper>

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

@@ -30,7 +30,7 @@
             <if test="time != null and time != ''">
                AND DATE_FORMAT(open_time,'%Y-%m-%d') = #{time}
             </if>
-            and time_cost BETWEEN 30000 AND 50000
+            and time_cost BETWEEN #{minCycle} AND #{maxCycle}
         </where>
         ORDER BY open_time
     </select>

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

@@ -111,7 +111,6 @@
         on
         tbco.id = tbm.produce_company_id
         <where>
-            tbp.is_delete = 0
             <if test="userVO.parentId != 0">
                 AND  tbm.company_id = #{userVO.companyId}
             </if>
@@ -128,6 +127,7 @@
                 AND tbm.equipment_id is not null
                 AND tbm.state != 4
                 AND tbm.project_id is not null
+                AND tbp.is_delete = 0
             </if>
             <if test="userVO.mouleMap == -1">
                 AND tbmp.lng IS NOT NULL and tbmp.lat IS NOT NULL
@@ -162,7 +162,6 @@
         on
         tbco.id = tbm.produce_company_id
         <where>
-            tbp.is_delete = 0
             <if test="userVO.searchType == 0 and userVO.keyName != '' and userVO.keyName != null">
                 AND tbm.model_no like concat('%',#{userVO.keyName},'%')
             </if>
@@ -176,6 +175,7 @@
                 AND tbm.equipment_id is not null
                 AND tbm.state != 4
                 AND tbm.project_id is not null
+                tbp.is_delete = 0
             </if>
             AND tbm.project_id in
             <foreach item="item" index="index" collection="list"

+ 19 - 0
cloud-model/src/main/resources/mapper/PacketLossRecordMapper.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.hssx.cloudmodel.mapper.PacketLossRecordMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.hssx.cloudmodel.entity.PacketLossRecord">
+        <id column="id" property="id" />
+        <result column="equipment_no" property="equipmentNo" />
+        <result column="count" property="count" />
+        <result column="indate" property="indate" />
+        <result column="loss_time" property="lossTime" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, equipment_no, count, indate, loss_time
+    </sql>
+
+</mapper>

+ 5 - 2
target/classes/main/resources/application-prod.properties

@@ -16,9 +16,12 @@ 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_model_test?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.url=jdbc:mysql://127.0.0.1:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
-spring.datasource.password=p011430seya1026
+spring.datasource.password=Hssx2019.!
 #spring.datasource.druid.test-on-borrow=true
 #spring.datasource.druid.test-while-idle=true
 # ####################################################################################################

+ 2 - 2
target/classes/main/resources/mapper/MouldMapper.xml

@@ -111,7 +111,6 @@
         on
         tbco.id = tbm.produce_company_id
         <where>
-            tbp.is_delete = 0
             <if test="userVO.parentId != 0">
                 AND  tbm.company_id = #{userVO.companyId}
             </if>
@@ -128,6 +127,7 @@
                 AND tbm.equipment_id is not null
                 AND tbm.state != 4
                 AND tbm.project_id is not null
+                AND tbp.is_delete = 0
             </if>
             <if test="userVO.mouleMap == -1">
                 AND tbmp.lng IS NOT NULL and tbmp.lat IS NOT NULL
@@ -162,7 +162,6 @@
         on
         tbco.id = tbm.produce_company_id
         <where>
-            tbp.is_delete = 0
             <if test="userVO.searchType == 0 and userVO.keyName != '' and userVO.keyName != null">
                 AND tbm.model_no like concat('%',#{userVO.keyName},'%')
             </if>
@@ -176,6 +175,7 @@
                 AND tbm.equipment_id is not null
                 AND tbm.state != 4
                 AND tbm.project_id is not null
+                tbp.is_delete = 0
             </if>
             AND tbm.project_id in
             <foreach item="item" index="index" collection="list"