瀏覽代碼

预警推荐

wangchangsheng 3 年之前
父節點
當前提交
b39b710c2e
共有 21 個文件被更改,包括 713 次插入15 次删除
  1. 12 0
      pom.xml
  2. 2 0
      src/main/java/com/gyee/viewticket/ViewticketApplication.java
  3. 161 0
      src/main/java/com/gyee/viewticket/comm/base/SnowflakeGenerator.java
  4. 24 0
      src/main/java/com/gyee/viewticket/comm/vo/AlarmStatVo.java
  5. 21 0
      src/main/java/com/gyee/viewticket/controller/viewticket/AlarmstatController.java
  6. 20 0
      src/main/java/com/gyee/viewticket/feign/IAdapterService.java
  7. 24 0
      src/main/java/com/gyee/viewticket/feign/RemoteServiceBuilder.java
  8. 40 0
      src/main/java/com/gyee/viewticket/init/CacheContext.java
  9. 20 0
      src/main/java/com/gyee/viewticket/mapper/ticket/AlarmstatMapper.java
  10. 88 0
      src/main/java/com/gyee/viewticket/model/ticket/Alarmstat.java
  11. 55 0
      src/main/java/com/gyee/viewticket/service/impl/ticket/AlarmstatServiceImpl.java
  12. 2 2
      src/main/java/com/gyee/viewticket/service/impl/ticket/DatadictionaryServiceImpl.java
  13. 7 7
      src/main/java/com/gyee/viewticket/service/impl/ticket/LocationsServiceImpl.java
  14. 22 5
      src/main/java/com/gyee/viewticket/service/impl/ticket/WindfarmServiceImpl.java
  15. 12 0
      src/main/java/com/gyee/viewticket/service/impl/ticket/WindturbineServiceImpl.java
  16. 23 0
      src/main/java/com/gyee/viewticket/service/ticket/AlarmstatService.java
  17. 6 0
      src/main/java/com/gyee/viewticket/service/ticket/WindfarmService.java
  18. 2 0
      src/main/java/com/gyee/viewticket/service/ticket/WindturbineService.java
  19. 139 0
      src/main/java/com/gyee/viewticket/tasks/warningTask.java
  20. 32 0
      src/main/resources/mapper/ticket/AlarmstatMapper.xml
  21. 1 1
      src/test/java/com/gyee/viewticket/ViewticketApplicationTests.java

+ 12 - 0
pom.xml

@@ -104,6 +104,18 @@
             <scope>system</scope>
             <systemPath>${project.basedir}/src/main/resources/lib/sqljdbc42.jar</systemPath>
         </dependency>
+
+        <!--http请求-->
+        <dependency>
+            <groupId>com.netflix.feign</groupId>
+            <artifactId>feign-core</artifactId>
+            <version>8.18.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.netflix.feign</groupId>
+            <artifactId>feign-jackson</artifactId>
+            <version>8.18.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 2 - 0
src/main/java/com/gyee/viewticket/ViewticketApplication.java

@@ -5,7 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
+@EnableScheduling
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
 public class ViewticketApplication {
 

+ 161 - 0
src/main/java/com/gyee/viewticket/comm/base/SnowflakeGenerator.java

@@ -0,0 +1,161 @@
+package com.gyee.viewticket.comm.base;
+
+/**
+ * Twitter_Snowflake<br>
+ * SnowFlake的结构如下(每部分用-分开):<br>
+ * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
+ * 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0<br>
+ * 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
+ * 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
+ * 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId<br>
+ * 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br>
+ * 加起来刚好64位,为一个Long型。<br>
+ * SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
+ */
+public class SnowflakeGenerator {
+
+    // ==============================Fields===========================================
+    /** 开始时间截 (2015-01-01) */
+    private final long twepoch = 1420041600000L;
+
+    /** 机器id所占的位数 */
+    private final long workerIdBits = 5L;
+
+    /** 数据标识id所占的位数 */
+    private final long datacenterIdBits = 5L;
+
+    /** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+
+    /** 支持的最大数据标识id,结果是31 */
+    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+
+    /** 序列在id中占的位数 */
+    private final long sequenceBits = 12L;
+
+    /** 机器ID向左移12位 */
+    private final long workerIdShift = sequenceBits;
+
+    /** 数据标识id向左移17位(12+5) */
+    private final long datacenterIdShift = sequenceBits + workerIdBits;
+
+    /** 时间截向左移22位(5+5+12) */
+    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+
+    /** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+
+    /** 工作机器ID(0~31) */
+    private long workerId;
+
+    /** 数据中心ID(0~31) */
+    private long datacenterId;
+
+    /** 毫秒内序列(0~4095) */
+    private long sequence = 0L;
+
+    /** 上次生成ID的时间截 */
+    private long lastTimestamp = -1L;
+
+    //==============================Constructors=====================================
+    /**
+     * 构造函数
+     * @param workerId 工作ID (0~31)
+     * @param datacenterId 数据中心ID (0~31)
+     */
+    public SnowflakeGenerator(long workerId, long datacenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+        }
+        this.workerId = workerId;
+        this.datacenterId = datacenterId;
+    }
+
+    // ==============================Methods==========================================
+    /**
+     * 获得下一个ID (该方法是线程安全的)
+     * @return SnowflakeId
+     */
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(
+                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            //毫秒内序列溢出
+            if (sequence == 0) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+
+        //移位并通过或运算拼到一起组成64位的ID
+        return ((timestamp - twepoch) << timestampLeftShift) //
+                | (datacenterId << datacenterIdShift) //
+                | (workerId << workerIdShift) //
+                | sequence;
+    }
+
+    /**
+     * 阻塞到下一个毫秒,直到获得新的时间戳
+     * @param lastTimestamp 上次生成ID的时间截
+     * @return 当前时间戳
+     */
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+
+    /**
+     * 返回以毫秒为单位的当前时间
+     * @return 当前时间(毫秒)
+     */
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+
+
+    private static SnowflakeGenerator idWorker = null;
+
+    public synchronized static SnowflakeGenerator getIdWorker() {
+
+        if (idWorker == null)
+            idWorker = new SnowflakeGenerator(2, 3);
+
+        return idWorker;
+    }
+
+    public static long generateId() {
+        //if (idWorker == null)
+        //idWorker = new SnowflakeGenerator(0, 0);
+
+        //return idWorker.nextId();
+        SnowflakeGenerator snowflakeGenerator = getIdWorker();
+
+        return snowflakeGenerator.nextId();
+//        for (int i = 0; i < 1000; i++) {
+//            long id = idWorker.nextId();
+//            System.out.println(Long.toBinaryString(id));
+//            System.out.println(id);
+//        }
+    }
+}

+ 24 - 0
src/main/java/com/gyee/viewticket/comm/vo/AlarmStatVo.java

@@ -0,0 +1,24 @@
+package com.gyee.viewticket.comm.vo;
+
+
+import lombok.Data;
+
+@Data
+public class AlarmStatVo {
+
+    private Long snapId;
+
+    private String stationId;
+
+    private String windturbineId;
+
+    private String alertText;
+
+    private int count;
+
+    private double time;
+    //关联部件编号
+    private String relateParts;
+    //关联部件名称
+    private String relatePartsText;
+}

+ 21 - 0
src/main/java/com/gyee/viewticket/controller/viewticket/AlarmstatController.java

@@ -0,0 +1,21 @@
+package com.gyee.viewticket.controller.viewticket;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author admin
+ * @since 2022-03-08
+ */
+@RestController
+@RequestMapping("/alarmstat")
+public class AlarmstatController {
+
+}
+

+ 20 - 0
src/main/java/com/gyee/viewticket/feign/IAdapterService.java

@@ -0,0 +1,20 @@
+package com.gyee.viewticket.feign;
+
+import com.gyee.viewticket.comm.vo.AlarmStatVo;
+import feign.Param;
+import feign.RequestLine;
+import java.util.List;
+import java.util.Map;
+
+public interface IAdapterService {
+
+    //获取当前正在活跃的故障
+    //http://192.168.1.18:8075/alarm/count/query/new2?stationid=MHS_FDC&startdate=2022-03-07&enddate=2022-03-09
+    @RequestLine("GET /alarm/count/query/new?stationid={stationid}&startdate={startdate}&enddate={enddate}")
+    List<Map.Entry<String, List<AlarmStatVo>>> querynew(
+            @Param(value = "stationid") String stationid,
+            @Param(value = "startdate") String startdate,
+            @Param(value = "enddate") String enddate);
+
+
+}

+ 24 - 0
src/main/java/com/gyee/viewticket/feign/RemoteServiceBuilder.java

@@ -0,0 +1,24 @@
+package com.gyee.viewticket.feign;
+
+
+import feign.Feign;
+import feign.Request;
+import feign.Retryer;
+import feign.jackson.JacksonDecoder;
+import feign.jackson.JacksonEncoder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RemoteServiceBuilder {
+
+    @Bean
+    public IAdapterService earlyService() {
+        return Feign.builder()
+                .encoder(new JacksonEncoder())
+                .decoder(new JacksonDecoder())
+                .options(new Request.Options(5000, 600000))
+                .retryer(new Retryer.Default(10000, 10000, 3))
+                .target(IAdapterService.class, "http://192.168.1.18:8075");
+    }
+}

+ 40 - 0
src/main/java/com/gyee/viewticket/init/CacheContext.java

@@ -0,0 +1,40 @@
+package com.gyee.viewticket.init;
+
+import com.gyee.viewticket.model.ticket.Windturbine;
+import com.gyee.viewticket.service.ticket.WindturbineService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class CacheContext implements CommandLineRunner {
+
+
+    @Autowired
+    private WindturbineService windturbineService;
+
+    private static final Logger logger = LoggerFactory.getLogger(CacheContext.class);
+
+
+    public static List<Windturbine> wdlist = new ArrayList<>();
+
+    public static Map<String, Windturbine> wdmap = new HashMap<>();//风机
+
+    @Override
+    public void run(String... args) throws Exception {
+        logger.info("-------------------------------缓存开始--------------------------------------");
+
+        wdlist = windturbineService.getWindturbineAllList();
+        wdlist.stream().forEach(i->{
+            wdmap.put(i.getWtid(),i);
+        });
+
+    }
+}

+ 20 - 0
src/main/java/com/gyee/viewticket/mapper/ticket/AlarmstatMapper.java

@@ -0,0 +1,20 @@
+package com.gyee.viewticket.mapper.ticket;
+
+import com.gyee.viewticket.model.ticket.Alarmstat;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author admin
+ * @since 2022-03-08
+ */
+@Mapper
+@Repository
+public interface AlarmstatMapper extends BaseMapper<Alarmstat> {
+
+}

+ 88 - 0
src/main/java/com/gyee/viewticket/model/ticket/Alarmstat.java

@@ -0,0 +1,88 @@
+package com.gyee.viewticket.model.ticket;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author admin
+ * @since 2022-03-08
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@TableName("ALARMSTAT")
+public class Alarmstat extends Model<Alarmstat> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "ID")
+    private long id;
+
+    @TableField("STATIONID")
+    private String stationid;
+
+    @TableField("WINDTURBINEID")
+    private String windturbineid;
+
+    @TableField("RELATEPARTSTEXT")
+    private String relatepartstext;
+
+    @TableField("RELATEPARTS")
+    private String relateparts;
+
+    @TableField("ALERTTEXT")
+    private String alerttext;
+
+    @TableField("STARTDATE")
+    private Date startdate;
+
+    @TableField("ENDDATE")
+    private Date enddate;
+
+    @TableField("CREATTIME")
+    private Date creattime;
+
+    @TableField("LASTUPDATETIME")
+    private Date lastupdatetime;
+
+    @TableField("COUNT")
+    private int count;
+
+    @TableField("TIME")
+    private Double time;
+
+    @TableField("TICKETNUM")
+    private String ticketnum;
+
+    @TableField("LEVEL")
+    private String level;
+
+    @TableField("CONFIRM")
+    private String confirm;
+
+    @TableField("PROCESS")
+    private String process;
+
+    @TableField("LOCATION")
+    private String location;
+
+    @TableField("WONUM")
+    private String wonum;
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 55 - 0
src/main/java/com/gyee/viewticket/service/impl/ticket/AlarmstatServiceImpl.java

@@ -0,0 +1,55 @@
+package com.gyee.viewticket.service.impl.ticket;
+
+import com.gyee.viewticket.comm.base.ExcludeQueryWrapper;
+import com.gyee.viewticket.model.ticket.Alarmstat;
+import com.gyee.viewticket.mapper.ticket.AlarmstatMapper;
+import com.gyee.viewticket.model.ticket.Windfarm;
+import com.gyee.viewticket.service.ticket.AlarmstatService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author admin
+ * @since 2022-03-08
+ */
+@Service
+public class AlarmstatServiceImpl extends ServiceImpl<AlarmstatMapper, Alarmstat> implements AlarmstatService {
+
+    @Override
+    public int insetAlarmstat(Alarmstat alarmstat) {
+
+        int code = -1;
+        ExcludeQueryWrapper<Alarmstat> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.eq("STATIONID", alarmstat.getStationid());
+        wrapper.eq("WINDTURBINEID", alarmstat.getWindturbineid());
+        wrapper.eq("RELATEPARTS",alarmstat.getRelateparts());
+        wrapper.eq("ALERTTEXT",alarmstat.getAlerttext());
+        wrapper.isNull("TICKETNUM");
+        wrapper.isNull("WONUM");
+        List<Alarmstat> list = baseMapper.selectList(wrapper);
+
+        if(null != list && list.size() > 0){
+
+            Alarmstat orias = list.get(0);
+            orias.setCount(alarmstat.getCount() + orias.getCount());
+            orias.setTime(alarmstat.getTime() + orias.getTime());
+            orias.setEnddate(alarmstat.getEnddate());
+            orias.setLastupdatetime(new Date());
+            code = baseMapper.updateById(orias);
+
+        }else {
+            code = baseMapper.insert(alarmstat);
+        }
+
+
+        return code;
+    }
+
+}

+ 2 - 2
src/main/java/com/gyee/viewticket/service/impl/ticket/DatadictionaryServiceImpl.java

@@ -31,9 +31,9 @@ public class DatadictionaryServiceImpl extends ServiceImpl<DatadictionaryMapper,
     }
 
     @Override
-    public List<Datadictionary> getValueList(String[] value) {
+    public List<Datadictionary> getValueList(String[] val) {
         ExcludeQueryWrapper<Datadictionary> wrapper = new ExcludeQueryWrapper<>();
-        wrapper.in("value",value)
+        wrapper.in("value",val)
                 .orderByAsc("id");
         List<Datadictionary> list = baseMapper.selectList(wrapper);
         return list;

+ 7 - 7
src/main/java/com/gyee/viewticket/service/impl/ticket/LocationsServiceImpl.java

@@ -31,23 +31,23 @@ public class LocationsServiceImpl extends ServiceImpl<LocationsMapper, Locations
         return null;
     }
 
+
+
     @Override
     public String getLocations(String location) {
-
-        int d = 2;
+        int d = 4;
         StringBuilder sb = new StringBuilder();
         while (null !=location && location.length() >=d){
+            if (d==6){
+                d = d+2;
+                continue;
+            }
             List<Locations> list  = locationsMapper.selectLocations(location.substring(0,d));
-
             if (null != list && list.size()>0){
-
                 sb.append("/").append(list.get(0).getDescription());
             }
             d = d+2;
-
         }
-
-
         return sb.toString();
     }
 

+ 22 - 5
src/main/java/com/gyee/viewticket/service/impl/ticket/WindfarmServiceImpl.java

@@ -8,11 +8,12 @@ import com.gyee.viewticket.service.ticket.WindfarmService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author admin
@@ -22,11 +23,27 @@ import java.util.List;
 public class WindfarmServiceImpl extends ServiceImpl<WindfarmMapper, Windfarm> implements WindfarmService {
 
 
+    private List<Windfarm> all = new ArrayList<>();
+    private List<Windfarm> fd = new ArrayList<>();
+
     @Override
     public List<Windfarm> getWindfarmList() {
-        ExcludeQueryWrapper<Windfarm> wrapper = new ExcludeQueryWrapper<>();
-        wrapper.orderByAsc("WFNUM");
-        List<Windfarm> list = baseMapper.selectList(wrapper);
-        return list;
+        if (null == all || all.size() <= 0) {
+            ExcludeQueryWrapper<Windfarm> wrapper = new ExcludeQueryWrapper<>();
+            wrapper.orderByAsc("WFNUM");
+            all = baseMapper.selectList(wrapper);
+        }
+        return all;
+    }
+
+    @Override
+    public List<Windfarm> getWindfarmFdList() {
+        if (null == fd || fd.size() <= 0) {
+            ExcludeQueryWrapper<Windfarm> wrapper = new ExcludeQueryWrapper<>();
+            wrapper.like("WFSHORTNAME", "%MHS_FDC%");
+            wrapper.orderByAsc("WFNUM");
+            fd = baseMapper.selectList(wrapper);
+        }
+        return fd;
     }
 }

+ 12 - 0
src/main/java/com/gyee/viewticket/service/impl/ticket/WindturbineServiceImpl.java

@@ -2,6 +2,8 @@ package com.gyee.viewticket.service.impl.ticket;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gyee.viewticket.comm.base.ExcludeQueryWrapper;
+import com.gyee.viewticket.model.ticket.Windfarm;
 import com.gyee.viewticket.model.ticket.Windturbine;
 import com.gyee.viewticket.mapper.ticket.WindturbineMapper;
 import com.gyee.viewticket.service.ticket.WindturbineService;
@@ -39,5 +41,15 @@ public class WindturbineServiceImpl extends ServiceImpl<WindturbineMapper, Windt
         return lists;
     }
 
+    @Override
+    public List<Windturbine> getWindturbineAllList() {
+
+        ExcludeQueryWrapper<Windturbine> wrapper = new ExcludeQueryWrapper<>();
+        wrapper.orderByAsc("id");
+        List<Windturbine> list = baseMapper.selectList(wrapper);
+
+        return list;
+    }
+
 
 }

+ 23 - 0
src/main/java/com/gyee/viewticket/service/ticket/AlarmstatService.java

@@ -0,0 +1,23 @@
+package com.gyee.viewticket.service.ticket;
+
+import com.gyee.viewticket.model.ticket.Alarmstat;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author admin
+ * @since 2022-03-08
+ */
+@Service
+public interface AlarmstatService extends IService<Alarmstat> {
+
+    int insetAlarmstat(Alarmstat alarmstat);
+
+
+}

+ 6 - 0
src/main/java/com/gyee/viewticket/service/ticket/WindfarmService.java

@@ -22,5 +22,11 @@ public interface WindfarmService extends IService<Windfarm> {
      * @return
      */
     List<Windfarm> getWindfarmList();
+    /**
+     * 查询所有的数据
+     * @return
+     */
+    List<Windfarm> getWindfarmFdList();
+
 
 }

+ 2 - 0
src/main/java/com/gyee/viewticket/service/ticket/WindturbineService.java

@@ -24,6 +24,8 @@ public interface WindturbineService extends IService<Windturbine> {
 
     List<Map> getWindturbinePageList(String wtid);
 
+    List<Windturbine> getWindturbineAllList();
+
 
 
 

+ 139 - 0
src/main/java/com/gyee/viewticket/tasks/warningTask.java

@@ -0,0 +1,139 @@
+package com.gyee.viewticket.tasks;
+
+import com.gyee.viewticket.comm.base.SnowflakeGenerator;
+import com.gyee.viewticket.comm.vo.AlarmStatVo;
+import com.gyee.viewticket.feign.RemoteServiceBuilder;
+import com.gyee.viewticket.init.CacheContext;
+import com.gyee.viewticket.mapper.ticket.AlarmstatMapper;
+import com.gyee.viewticket.model.ticket.Alarmstat;
+import com.gyee.viewticket.model.ticket.Windfarm;
+import com.gyee.viewticket.service.ticket.AlarmstatService;
+import com.gyee.viewticket.service.ticket.WindfarmService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class warningTask {
+
+
+    private RestTemplate restTemplate = new RestTemplate();
+
+    @Autowired
+    private RemoteServiceBuilder remoteService;
+
+    @Autowired
+    private WindfarmService windfarmService;
+
+    @Autowired
+    private AlarmstatMapper alarmstatMapper;
+
+    @Autowired
+    private  AlarmstatService alarmstatService;
+
+    //"0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发
+    @Scheduled(cron = "0 25 10 ? * FRI")
+//    @Scheduled(fixedDelay = 2000)
+    public void task() {
+
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date());
+        String  endDate =df.format(cal.getTimeInMillis());
+        cal.add(Calendar.DATE, -7);//设置1天后
+        String  beginDate =df.format(cal.getTimeInMillis());
+
+        List<Windfarm> windfarmList = windfarmService.getWindfarmFdList();
+        windfarmList.stream().forEach(w -> {
+
+            List<Map.Entry<String, List<AlarmStatVo>>> list = remoteService.earlyService().querynew(w.getWfshortname(), beginDate, endDate);
+            System.out.println(w.getWfshortname());
+            System.out.println(list.size());
+            list.stream().forEach(m -> {
+
+                System.out.println(m.getKey());
+                List<AlarmStatVo> statVos = m.getValue();
+                statVos.stream().forEach(i -> {
+
+                    try {
+                        if (i.getTime()<= 0 ||  i.getCount()<=0){
+                            return;
+                        }
+                        if (i.getTime() / i.getCount() < 20) {
+                            return;
+                        }
+                        Alarmstat alarmstat = new Alarmstat();
+                        alarmstat.setId(SnowflakeGenerator.generateId());
+                        alarmstat.setStationid(w.getWfshortname());
+                        alarmstat.setWindturbineid(i.getWindturbineId());
+                        alarmstat.setRelatepartstext(null == i.getRelateParts() ?  "其它" :i.getRelatePartsText());
+                        alarmstat.setRelateparts(null == i.getRelateParts() ?  "QT" :i.getRelateParts());
+                        alarmstat.setAlerttext(i.getAlertText());
+                        alarmstat.setStartdate(df.parse(beginDate));
+                        alarmstat.setEnddate(df.parse(endDate));
+                        alarmstat.setCreattime(new Date());
+                        alarmstat.setCount(i.getCount());
+                        alarmstat.setTime(i.getTime());
+                        alarmstat.setLevel(getLevel(i.getRelateParts()));
+                        alarmstat.setLocation(CacheContext.wdmap.get(i.getWindturbineId()).getLocation());
+                        alarmstatService.insetAlarmstat(alarmstat);
+                    } catch (ParseException e) {
+                        e.printStackTrace();
+                    }
+
+                });
+            });
+        });
+    }
+
+    private static String getLevel(String key) {
+
+        // A: 发电机 FDJ, 齿轮箱 CLX, 变桨系统 BJXT,
+        // B: 测风系统 CFXT, 传动链 CDL, 机舱 JC,
+        // C: 塔底柜 TDG, 其它 QT,
+
+        String level = null;
+        if(null == key){
+            key = "";
+        }
+        switch (key) {
+            case "FDJ": //发电机
+                level = "A";
+                break;
+            case "CLX": //齿轮箱
+                level = "A";
+                break;
+            case "BJXT": //变桨系统
+                level = "A";
+                break;
+            case "CFXT": //测风系统
+                level = "B";
+                break;
+            case "CDL": //传动链
+                level = "B";
+                break;
+            case "JC": //机舱
+                level = "B";
+                break;
+            case "TDG": //塔底柜
+                level = "C";
+                break;
+            default: //其它
+                level = "C";
+                break;
+
+        }
+
+        return level;
+    }
+
+
+}

+ 32 - 0
src/main/resources/mapper/ticket/AlarmstatMapper.xml

@@ -0,0 +1,32 @@
+<?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.gyee.viewticket.mapper.ticket.AlarmstatMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.gyee.viewticket.model.ticket.Alarmstat">
+        <id column="ID" property="id" />
+        <result column="STATIONID" property="stationid" />
+        <result column="WINDTURBINEID" property="windturbineid" />
+        <result column="RELATEPARTSTEXT" property="relatepartstext" />
+        <result column="RELATEPARTS" property="relateparts" />
+        <result column="ALERTTEXT" property="alerttext" />
+        <result column="STARTDATE" property="startdate" />
+        <result column="ENDDATE" property="enddate" />
+        <result column="CREATTIME" property="creattime" />
+        <result column="LASTUPDATETIME" property="lastupdatetime" />
+        <result column="COUNT" property="count" />
+        <result column="TIME" property="time" />
+        <result column="TICKETNUM" property="ticketnum" />
+        <result column="LEVEL" property="level" />
+        <result column="CONFIRM" property="confirm" />
+        <result column="PROCESS" property="process" />
+        <result column="LOCATION" property="location" />
+
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        ID, STATIONID, WINDTURBINEID, RELATEPARTSTEXT, RELATEPARTS, ALERTTEXT, STARTDATE, ENDDATE, CREATTIME, LASTUPDATETIME, COUNT, TIME, TICKETNUM, LEVEL, CONFIRM, PROCESS, LOCATION
+    </sql>
+
+</mapper>

+ 1 - 1
src/test/java/com/gyee/viewticket/ViewticketApplicationTests.java

@@ -21,7 +21,7 @@ class ViewticketApplicationTests {
             long start = System.currentTimeMillis();
             List<String> list = new ArrayList<String>();
 
-            for (int i = 1; i <= 3000; i++) {
+            for (int i = 1; i <= 3001; i++) {
                 list.add(i + "");
             }
             // 每500条数据开启一条线程