소스 검색

添加taos查询相关业务类

全业务考评 2 년 전
부모
커밋
f003ea2b0d

+ 6 - 0
power-fitting-JN/pom.xml

@@ -148,6 +148,12 @@
             <version>3.2.2</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
+            <version>3.5.0</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 291 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/mapper/AlarmTsMapper.java

@@ -0,0 +1,291 @@
+package com.gyee.power.fitting.mapper;
+
+
+
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.power.fitting.model.AlarmTs;
+import com.gyee.power.fitting.model.ProBasicFeatureStat;
+import com.gyee.power.fitting.model.vo.AlarmSimpleVo;
+import com.gyee.power.fitting.model.vo.AlarmTsVo;
+import com.gyee.power.fitting.model.vo.AlarmVo;
+import com.gyee.power.fitting.model.vo.SimpleVo2;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
+
+
+@DS("slave")
+public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
+
+
+    @Update("CREATE STABLE if not exists ${superTableName} (ts TIMESTAMP,val INT,oval INT,confirmed BOOL) " +
+            "TAGS (alarmid NCHAR(100),alarmtype NCHAR(50),characteristic NCHAR(50)," +
+            "components NCHAR(50),description NCHAR(500),deviceid NCHAR(50),devicename NCHAR(70)," +
+            "devicetype NCHAR(50),enabled BOOL,lineid NCHAR(50),linename NCHAR(70),modelId NCHAR(50),projectid NCHAR(50)," +
+            "projectname NCHAR(70),rank INT,resettable BOOL,stationid NCHAR(50),stationname NCHAR(70),subcomponents NCHAR(50)," +
+            "suffix NCHAR(50),tagid NCHAR(100),triggertype INT,uniformcode NCHAR(50));")
+    int createAlarmSuperTable(@Param("superTableName") String superTableName);
+
+
+
+    @Update("create table if not exists ${tbName} using ${superTableName} tags( #{alarmid}, #{alarmtype}," +
+            "#{characteristic}, #{components},  #{description}, #{deviceid}, #{devicename}," +
+            "#{devicetype}, #{enabled}, #{lineid}, #{linename}, #{modelId}, #{projectid}," +
+            "#{projectname}, #{rank}, #{resettable}, #{stationid}, #{stationname}, #{subcomponents}," +
+            "#{suffix},  #{tagid}, #{triggertype}, #{uniformcode}" +
+            ")")
+    int createTable(@Param("tbName") String tbName, @Param("alarmid") String alarmid, @Param("alarmtype") String alarmtype,
+                    @Param("characteristic") String characteristic, @Param("components") String components,
+                    @Param("description") String description,
+                    @Param("deviceid") String deviceid, @Param("devicename") String devicename,
+                    @Param("devicetype") String devicetype, @Param("enabled") Boolean enabled,
+                    @Param("lineid") String lineid, @Param("linename") String linename,
+                    @Param("modelId") String modelId, @Param("projectid") String projectid,
+                    @Param("projectname") String projectname, @Param("rank") Integer rank,
+                    @Param("resettable") Boolean resettable, @Param("stationid") String stationid,
+                    @Param("stationname") String stationname, @Param("subcomponents") String subcomponents,
+                    @Param("suffix") String suffix, @Param("tagid") String tagid,
+                    @Param("triggertype") Integer triggertype, @Param("uniformcode") String uniformcode, @Param("superTableName") String superTableName
+
+    );
+
+
+
+    @Update("create table  if not exists ${tbName} using ${superTableName} tags( #{alarmid}, #{alarmtype}," +
+            "#{characteristic}, #{components}, #{description}, #{deviceid}, #{devicename}," +
+            "#{devicetype}, #{enabled}, #{lineid}, #{linename}, #{modelId}, #{projectid}," +
+            "#{projectname}, #{rank}, #{resettable}, #{stationid}, #{stationname}, #{subcomponents}," +
+            "#{suffix},  #{tagid}, #{triggertype}, #{uniformcode}" +
+            ")")
+    int createTable(AlarmVo vo);
+
+    @Update("drop table if exists ${superTableName}")
+    void dropSuperTable(@Param("superTableName")String superTableName);
+
+    @Insert("insert into ${tbName} (ts, val,oval,confirmed) values(#{ts}, #{val}, #{oval}, #{confirmed})")
+    int insertOne(AlarmTs one);
+
+
+
+    @Insert("${sql}")
+    int insertList(@Param("sql") String sql);
+
+    @Select("select last_row(*),alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
+            "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode from #{stbaleName} group by tbname")
+    List<AlarmVo> findTags(@Param("stbaleName") String stbaleName);
+
+
+    @Select("select deviceid,description,count(*) as val from #{superTableName} where ts>=#{begin} and ts<=#{end}  stationid=#{stationid}  group by description,deviceid  ")
+    List<AlarmTsVo> selectByWpGroup(@Param("superTableName") String superTableName, @Param("stationid") String stationid, @Param("begin")long begin, @Param("end") long end);
+
+
+    @Select("select ts,val,oval,alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
+            "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode from #{tbName}   limit #{limit} , #{offset} ")
+    List<AlarmVo> selectByTbName(@Param("tbName") String tbName,@Param("limit") long limit,@Param("offset") long offset);
+
+    @Select("select alarmid,description,count(*) as val,max(rank),sum(timeLong) as timeLong) from #{superTableName} where ts>=#{begin} and ts<=#{end} and deviceid=#{deviceid}  group by description,alarmid  ")
+    List<AlarmTsVo> selectByWtGroup(@Param("superTableName") String superTableName, @Param("deviceid") String deviceid, @Param("begin")long begin, @Param("end") long end);
+
+
+    @Select("select projectname as name,count(*) total from #{superTableName} where ts>=#{begin} and ts<=#{end}   group by projectname  ")
+    List<SimpleVo2> selectByWp(@Param("superTableName") String superTableName, @Param("begin")long begin, @Param("end") long end);
+
+    @Select("select stationname as name,count(*) as total from #{superTableName} where ts>=#{begin} and ts<=#{end}   group by stationname  ")
+    List<SimpleVo2> selectByPj(@Param("superTableName") String superTableName, @Param("begin")long begin, @Param("end") long end);
+
+//    @Select("select ts,val,alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
+//            "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode from #{superTableName}  " +
+//            "#{whereSql}  order by ts desc limit #{limit} offset #{offset} ")
+
+//    @Select({"<script>",
+//            "select  last_row(ts) as lastts,ts,val,alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
+//                    "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode,nemCode ,faultCause,resolvent from #{superTableName} " ,
+//            "<where>" ,
+//
+//            "<if test='modelId != null'>",
+//            "and modelId= #{modelId}",
+//            "</if>",
+//            "<if test='description != null'>",
+//            "and description like #{description}",
+//            "</if>",
+//            "<if test='deviceid != null'>",
+//            "and deviceid = #{deviceid}",
+//            "</if>",
+//            "<if test='deviceType != null'>",
+//            "and deviceType = #{deviceType}",
+//            "</if>",
+//            "<if test='components != null'>",
+//            "and components = #{components}",
+//            "</if>",
+//            "<if test='stationid != null'>",
+//            "and stationid = #{stationid}",
+//            "</if>",
+//            "<if test='alarmid != null'>",
+//            "and alarmid = #{alarmid}",
+//            "</if>",
+//            "and ts &gt;= #{begin}",
+//            "and ts &lt;= #{end}",
+////            " and  confirmed = false ",
+//            " and  enabled = true ",
+//            "</where>",
+//            " group by tbname,alarmid,alarmtype,characteristic,components,description,deviceid,devicename,devicetype,enabled,lineid,linename,modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode,nemCode ,faultCause,resolvent ",
+//            " order by ts desc limit #{limit},#{offset} ",
+//            "</script>"})
+
+    @Select({"<script>",
+            "select  ts ,val ,confirmed ,endts ,timeLong,tbname as id,alarmid as alarmId,alarmtype as alarmType,characteristic,components,confirmed,description,deviceid as deviceId,devicename,devicetype as deviceType,enabled,lineid,linename," +
+                    "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode,nemCode ,faultCause,resolvent from #{superTableName} " ,
+            "<where>" ,
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+            "<if test='modelId != null'>",
+            "and modelId= #{modelId}",
+            "</if>",
+            "<if test='description != null'>",
+            "and description like #{description}",
+            "</if>",
+            "<if test='deviceid != null'>",
+            "and deviceid = #{deviceid}",
+            "</if>",
+            "<if test='deviceType != null'>",
+            "and deviceType = #{deviceType}",
+            "</if>",
+            "<if test='alarmType != null'>",
+            "and alarmType = #{alarmType}",
+            "</if>",
+            "<if test='components != null'>",
+            "and components = #{components}",
+            "</if>",
+            "<if test='stationid != null'>",
+            "and stationid = #{stationid}",
+            "</if>",
+            "<if test='alarmid != null'>",
+            "and alarmid = #{alarmid}",
+            "</if>",
+            "<if test='isclose== true'>",
+            "and endts is not null ",
+            "</if>",
+            "<if test='isclose== false'>",
+            "and endts is null ",
+            "</if>",
+
+            " and  enabled = true ",
+            "</where>",
+            " order by ts desc,rank desc limit #{limit},#{offset} ",
+            "</script>"})
+    List<AlarmVo> selectByWtLimit(@Param("begin")long begin,@Param("end")long end,@Param("modelId")String modelId,@Param("superTableName") String superTableName,@Param("alarmType")String alarmType,@Param("stationid")String stationid,@Param("deviceid")String deviceid,@Param("description")String description, @Param("deviceType")String deviceType, @Param("components")String components, @Param("alarmid")String alarmid, @Param("isclose")Boolean isclose,@Param("limit")int limit, @Param("offset") int offset);
+
+    @Select({"<script>",
+            "select count(tbname) from #{superTableName} " ,
+            "<where>" ,
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+            "<if test='modelId != null'>",
+            "and modelId= #{modelId}",
+            "</if>",
+            "<if test='description != null'>",
+            "and description like #{description}",
+            "</if>",
+            "<if test='deviceid != null'>",
+            "and deviceid = #{deviceid}",
+            "</if>",
+            "<if test='deviceType != null'>",
+            "and deviceType = #{deviceType}",
+            "</if>",
+            "<if test='components != null'>",
+            "and components = #{components}",
+            "</if>",
+            "<if test='stationid != null'>",
+            "and stationid = #{stationid}",
+            "</if>",
+            "<if test='alarmid != null'>",
+            "and alarmid = #{alarmid}",
+            "</if>",
+            "<if test='alarmType != null'>",
+            "and alarmType = #{alarmType}",
+            "</if>",
+            "<if test='isclose== true'>",
+            "and endts is null ",
+            "</if>",
+            "<if test='isclose== false'>",
+            "and endts is not null ",
+            "</if>",
+//            " and  confirmed = false ",
+            " and  enabled = true ",
+            "</where>",
+
+            "</script>"})
+    List<Integer> selectByWtCount(@Param("begin")long begin,@Param("end")long end,@Param("modelId")String modelId,@Param("superTableName") String superTableName,@Param("alarmType")String alarmType,@Param("stationid")String stationid,@Param("deviceid")String deviceid,@Param("description")String description, @Param("deviceType")String deviceType, @Param("components")String components,@Param("alarmid")String alarmid, @Param("isclose")Boolean isclose);
+//    @Select("select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmWt where ts>=#{begin} and ts<=#{end}  and alarmtype='windturbine'  and #{begin} group by deviceid,components,stationid,alarmid,description")
+
+    @Select({"<script>",
+            "select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from #{superTableName} " ,
+            "<where>" ,
+
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+            "and stationid = #{stationid}",
+
+            "<if test='alarmid != null'>",
+            "and alarmid in (${alarmid}) ",
+            "</if>",
+            "<if test='components != null'>",
+            "and components in (${components}) ",
+            "</if>",
+            "<if test='modelId != null'>",
+            "and modelId = #{modelId}",
+            "</if>",
+            "<if test='alarmType != null'>",
+            "and alarmType = #{alarmType}",
+            "</if>",
+
+            "</where>",
+
+            " group by deviceid,components,stationid,alarmid,description ",
+            " order by deviceid , total desc ",
+            "</script>"})
+    List<ProBasicFeatureStat> findWtFeatureStat(@Param("superTableName") String superTableName, @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId, @Param("components") String components, @Param("alarmid") String alarmid, @Param("alarmType") String alarmType);
+
+    @Select({"<script>",
+            "select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from #{superTableName} " ,
+            "<where>" ,
+
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+            "and deviceid = #{deviceid}",
+
+
+            "</where>",
+
+            " group by deviceid,components,stationid,alarmid,description ",
+            " order by deviceid , total desc  ",
+            "</script>"})
+    List<ProBasicFeatureStat> findWtFeatureStatWt(@Param("superTableName") String superTableName, @Param("begin")long begin, @Param("end") long end, @Param("deviceid") String deviceid);
+
+    @Select({"<script>",
+            "select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmCt " ,
+            "<where>" ,
+
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+
+            "and deviceid = #{wtId}",
+
+            "<if test='deviceType != null'>",
+            "and deviceType = #{deviceType}",
+            "</if>",
+            "</where>",
+
+            " group by deviceid,components,stationid,alarmid,description ",
+            " order by deviceid, total desc ",
+            "</script>"})
+    List<ProBasicFeatureStat> findCtFeatureStat(@Param("wtId") String wtId, @Param("begin")long begin, @Param("end") long end, @Param("deviceType")String deviceType);
+
+    @Select("${sql}")
+    List<AlarmSimpleVo> selectLastRowByTbname(@Param("sql") String sql);
+}

+ 17 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/AlarmTs.java

@@ -0,0 +1,17 @@
+package com.gyee.power.fitting.model;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.sql.Timestamp;
+
+@Data
+@ToString
+public class AlarmTs {
+
+    private Timestamp ts;
+    private Integer val;
+    private Integer oval;
+    private Boolean confirmed;
+    private String tbName;
+}

+ 93 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/ProBasicFeatureStat.java

@@ -0,0 +1,93 @@
+package com.gyee.power.fitting.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.sql.Timestamp;
+
+/**
+ * <p>
+ * 设备功能统计
+ * </p>
+ *
+ * @author shilin
+ * @since 2023-08-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ProBasicFeatureStat extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 编号
+     */
+    @TableId(value = "ID",type = IdType.INPUT)
+    private String id;
+
+    /**
+     * 设备编号
+     */
+    private String wtId;
+
+    /**
+     * 场站编号
+     */
+    private String stationId;
+
+    /**
+     * 统计时间
+     */
+    private Timestamp statDate;
+
+    /**
+     * 总次数
+     */
+    private Long total;
+
+    /**
+     * 总时间
+     */
+    private Double totalSeconds;
+
+    /**
+     * 平均时长
+     */
+    private Double avgSeconds;
+
+    /**
+     * 最大时长
+     */
+    private Double maxSeconds;
+
+    /**
+     * 最小时长
+     */
+    private Double minSeconds;
+
+    /**
+     * 类型编码
+     */
+    private String typeCode;
+
+    /**
+     * 类型名称
+     */
+    private String typeName;
+    /**
+     * 报警编号
+     */
+    private String alarmid;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    @TableField(exist = false)
+    private String code;
+}

+ 19 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/vo/AlarmSimpleVo.java

@@ -0,0 +1,19 @@
+package com.gyee.power.fitting.model.vo;
+
+
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+@Data
+public class AlarmSimpleVo {
+
+    private  String tbName;
+    private Timestamp ts;
+    private Integer val;
+    private Integer oval;
+    private  Boolean confirmed;
+    private Timestamp endts;
+    private Double timelong;
+
+}

+ 17 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/vo/AlarmTsVo.java

@@ -0,0 +1,17 @@
+package com.gyee.power.fitting.model.vo;
+
+
+import lombok.Data;
+
+@Data
+public class AlarmTsVo {
+
+
+    private String alarmid;
+    private String description;
+    private String deviceid;
+    private Integer val;
+    private Integer rank;
+    private Double timeLong;
+
+}

+ 69 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/vo/AlarmVo.java

@@ -0,0 +1,69 @@
+package com.gyee.power.fitting.model.vo;
+
+
+import lombok.Data;
+
+@Data
+public class AlarmVo {
+
+    private  String tbName;
+    private String alarmId;
+    private String alarmType;
+    private String characteristic;
+    private String components;
+    private Boolean confirmed;
+    private String description;
+    private String deviceId;
+    private String devicename;
+    private String deviceType;
+    private Boolean enabled;
+    private String lineid;
+    private String linename;
+    private String modelId;
+    private String projectid;
+    private String projectname;
+    private Integer rank;
+    private Boolean resettable;
+    private String stationid;
+    private String stationname;
+    private String subcomponents;
+    private String suffix;
+    private String tagid;
+    private Integer triggertype;
+    private String uniformcode;
+    private String superTableName;
+
+    private long ts;
+    private Integer val;
+    private Integer oval;
+
+    private long endts;
+
+    private Double timelong;
+
+    /**
+     * 故障名称
+     */
+    private String name;
+
+    /**
+     *故障码
+     */
+    private String nemCode;
+
+    /**
+     * 故障原因
+     */
+    private String faultCause;
+
+    /**
+     * 排查方法
+     */
+    private String resolvent;
+    private String wpName;
+    private String code;
+    private String wpId;
+    private String faultType;
+    private String id;
+    private String aname;
+}

+ 32 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/vo/SimpleVo2.java

@@ -0,0 +1,32 @@
+package com.gyee.power.fitting.model.vo;
+
+public class SimpleVo2 {
+
+    private String id;
+    private String name;
+    private Integer total;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Integer getTotal() {
+        return total;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}