瀏覽代碼

整合es成功

yq 4 年之前
父節點
當前提交
277aa83b10

+ 2 - 0
fiveep-controller/src/main/java/com/bizmatics/controller/DemoControllerApplication.java

@@ -5,8 +5,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
+@EnableElasticsearchRepositories(basePackages = "com.bizmatics.persistence.mapper.es")
 @ServletComponentScan("com.bizmatics.service.config.SessionFilter")
 @EnableFeignClients("com.bizmatics")
 @ComponentScan("com.bizmatics")

+ 57 - 0
fiveep-controller/src/main/java/com/bizmatics/controller/web/es/RtAnalogControllerWeb.java

@@ -0,0 +1,57 @@
+package com.bizmatics.controller.web.es;
+
+import com.bizmatics.model.es.RtAnalog;
+import com.bizmatics.service.es.RtAnalogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author yq
+ * @date 2021/7/17 19:22
+ */
+@RestController
+@RequestMapping("rtAnalog")
+public class RtAnalogControllerWeb {
+
+    @Autowired
+    private RtAnalogService rtAnalogService;
+
+    @GetMapping("/init")
+    public void init(){
+        rtAnalogService.createIndex();
+        List<RtAnalog> list =new ArrayList<>();
+        RtAnalog rtAnalog = new RtAnalog();
+        rtAnalog.setId(1);
+        rtAnalog.setDeviceName("ali");
+
+        RtAnalog rtAnalog1 = new RtAnalog();
+        rtAnalog.setId(1);
+        rtAnalog.setDeviceName("ali");
+
+        RtAnalog rtAnalog2 = new RtAnalog();
+        rtAnalog.setId(1);
+        rtAnalog.setDeviceName("ali");
+
+        RtAnalog rtAnalog3 = new RtAnalog();
+        rtAnalog.setId(1);
+        rtAnalog.setDeviceName("ali");
+        list.add(rtAnalog);
+        list.add(rtAnalog1);
+        list.add(rtAnalog2);
+        list.add(rtAnalog3);
+        rtAnalogService.saveAll(list);
+
+    }
+
+    @GetMapping("/all")
+    public Iterator<RtAnalog> all(){
+        return rtAnalogService.findAll();
+    }
+
+}

+ 6 - 0
fiveep-controller/src/main/resources/application-dev.properties

@@ -62,3 +62,9 @@ spring.jackson.parser.allow-single-quotes=true
 # gzip
 server.compression.enabled=true
 server.compression.mime-types=application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
+
+
+#https://blog.csdn.net/haohaifeng002/article/details/102887921
+spring.elasticsearch.rest.uris=http://124.71.174.104:9200
+spring.elasticsearch.rest.username=
+spring.elasticsearch.rest.password=

+ 357 - 0
fiveep-model/src/main/java/com/bizmatics/model/es/RtAnalog.java

@@ -0,0 +1,357 @@
+package com.bizmatics.model.es;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.elasticsearch.annotations.Document;
+import org.springframework.data.elasticsearch.annotations.Field;
+import org.springframework.data.elasticsearch.annotations.FieldType;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * @author yq
+ * @date 2021/7/17 18:25
+ */
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+@Document(indexName = "fiveep",type = "rtAnalog", shards = 1, replicas = 0)
+public class RtAnalog {
+
+    @Id
+    private Integer id;
+
+    /**
+     * 阿里云平台设备名称
+     */
+    @Field(type = FieldType.Keyword)
+    private String deviceName;
+
+    /**
+     * 母线停电次数
+     */
+    @Field(type = FieldType.Integer)
+    private Integer Busot;
+
+    /**
+     * 三相功率因数
+     */
+    @Field(type = FieldType.Double)
+    private Double cos;
+
+    /**
+     * A相功率因数
+     */
+    @Field(type = FieldType.Double)
+    private Double COSa;
+
+    /**
+     * B相功率因数
+     */
+    @Field(type = FieldType.Double)
+    private Double COSb;
+
+    /**
+     * C相功率因数
+     */
+    @Field(type = FieldType.Double)
+    private Double COSc;
+
+    /**
+     * 实时有功需量
+     */
+    @Field(type = FieldType.Double)
+    private Double Demand;
+
+    /**
+     * 设备复位次数
+     */
+    @Field(type = FieldType.Integer)
+    private Integer DevResetTimes;
+
+    /**
+     * 设备温度
+     */
+    @Field(type = FieldType.Double)
+    private Double DeviceTemp;
+
+    /**
+     * 三相反向有功电度
+     */
+    @Field(type = FieldType.Double)
+    private Double Epn;
+
+    /**
+     * 尖段反向有功电度
+     */
+    @Field(type = FieldType.Double)
+    private Double Epn1;
+
+    /**
+     * 峰段反向有功电度
+     */
+    @Field(type = FieldType.Double)
+    private Double Epn2;
+
+    /**
+     * 平段反向有功电度
+     */
+    private Double Epn3;
+
+    /**
+     * 谷段反向有功电度
+     */
+    private Double Epn4;
+
+    /**
+     * 三相正向有功电度
+     */
+    private Double Epp;
+
+    /**
+     * 尖段正向有功电度
+     */
+    private Double Epp1;
+
+    /**
+     * 峰段正向有功电度
+     */
+    private Double Epp2;
+
+    /**
+     * 平段正向有功电度
+     */
+    private Double Epp3;
+
+    /**
+     * 谷段正向有功电度
+     */
+    private Double Epp4;
+
+    /**
+     * 三相反向无功电度
+     */
+    private Double Eqn;
+
+    /**
+     * 三相正向无功电度
+     */
+    private Double Eqp;
+
+    /**
+     * 频率
+     */
+    private Double f;
+
+    /**
+     * 零序电流
+     */
+    private Double i0;
+
+    /**
+     * 负序电流
+     */
+    private Double i2;
+
+    /**
+     * A相总谐波电流
+     */
+    private Double IHa;
+
+    /**
+     * B相总谐波电流
+     */
+    private Double IHb;
+
+    /**
+     * C相总谐波电流
+     */
+    private Double IHc;
+
+    /**
+     * A相电流
+     */
+    private Double Ia;
+
+    /**
+     * B相电流
+     */
+    private Double Ib;
+
+    /**
+     * C相电流
+     */
+    private Double Ic;
+
+    /**
+     * 剩余电流
+     */
+    private Double Ir;
+
+    /**
+     * 昨日有功最大需量
+     */
+    private Double LastDayMD;
+
+    /**
+     * 昨日有功最大需量发生时间
+     */
+    private Double LastDayMDt;
+
+    /**
+     * 三相总有功功率
+     */
+    private Double p;
+
+    /**
+     * A相有功功率
+     */
+    private Double Pa;
+
+    /**
+     * B相有功功率
+     */
+    private Double Pb;
+
+    /**
+     * C相有功功率
+     */
+    private Double Pc;
+
+    /**
+     * 三相总无功功率
+     */
+    private Double q;
+
+    /**
+     * A相无功功率
+     */
+    private Double Qa;
+
+    /**
+     * B相无功功率
+     */
+    private Double Qb;
+
+    /**
+     * C相无功功率
+     */
+    private Double Qc;
+
+    /**
+     * 信号强度
+     */
+    private Double SignalIntensity;
+
+    /**
+     * 第1路温度
+     */
+    private Double t1;
+
+    /**
+     * 第2路温度
+     */
+    private Double t2;
+
+    /**
+     * 第3路温度
+     */
+    private Double t3;
+
+    /**
+     * 第4路温度
+     */
+    private Double t4;
+
+    /**
+     * A相电压THD
+     */
+    private Double THDUa;
+
+    /**
+     * B相电压THD
+     */
+    private Double THDUb;
+
+    /**
+     * C相电压THD
+     */
+    private Double THDUc;
+
+    /**
+     * A相电压
+     */
+    private Double Ua;
+
+    /**
+     * AB线电压
+     */
+    private Double Uab;
+
+    /**
+     * B相电压
+     */
+    private Double Ub;
+
+    /**
+     * BC线电压
+     */
+    private Double Ubc;
+
+    /**
+     * 零序电压不平衡度
+     */
+    private Double UblU0;
+
+    /**
+     * 负序电压不平衡度
+     */
+    private Double UblU2;
+
+    /**
+     * C相电压
+     */
+    private Double Uc;
+
+    /**
+     * CA线电压
+     */
+    private Double Uca;
+
+    /**
+     * 电压暂降次数
+     */
+    private Integer Udt;
+
+    /**
+     * 线路侧电压
+     */
+    private Double Ul;
+
+    /**
+     * 电压暂升次数
+     */
+    private Integer Upt;
+
+    /**
+     * 电压短时中断次数
+     */
+    private Integer Ust;
+
+    /**
+     * 冻结时间
+     */
+    private LocalDate freezingTime;
+
+    /**
+     * 上报时间
+     */
+    private LocalDateTime dataTime;
+}

+ 27 - 0
fiveep-persistence/src/main/java/com/bizmatics/persistence/mapper/es/ElasticRepository.java

@@ -0,0 +1,27 @@
+package com.bizmatics.persistence.mapper.es;
+
+
+import com.bizmatics.model.es.RtAnalog;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.elasticsearch.annotations.Query;
+import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+
+
+/**
+ * @author yq
+ * @date 2021/7/17 19:14
+ */
+public interface ElasticRepository extends ElasticsearchRepository<RtAnalog, Long> {
+
+//    //默认的注释
+//    //@Query("{\"bool\" : {\"must\" : {\"field\" : {\"content\" : \"?\"}}}}")
+//    Page<RtAnalog> findByContent(String content, Pageable pageable);
+//
+//    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"firstCode.keyword\" : \"?\"}}}}")
+//    Page<RtAnalog> findByFirstCode(String firstCode, Pageable pageable);
+//
+//    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"secordCode.keyword\" : \"?\"}}}}")
+//    Page<RtAnalog> findBySecordCode(String secordCode, Pageable pageable);
+
+}

+ 25 - 0
fiveep-service/src/main/java/com/bizmatics/service/es/RtAnalogService.java

@@ -0,0 +1,25 @@
+package com.bizmatics.service.es;
+
+import com.bizmatics.model.es.RtAnalog;
+import org.springframework.data.domain.Page;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author yq
+ * @date 2021/7/17 19:18
+ */
+public interface RtAnalogService {
+
+    void createIndex();
+
+    void deleteIndex(String index);
+
+    void save(RtAnalog rtAnalog);
+
+    void saveAll(List<RtAnalog> list);
+
+    Iterator<RtAnalog> findAll();
+
+}

+ 57 - 0
fiveep-service/src/main/java/com/bizmatics/service/es/impl/RtAnalogServiceImpl.java

@@ -0,0 +1,57 @@
+package com.bizmatics.service.es.impl;
+
+import com.bizmatics.model.es.RtAnalog;
+import com.bizmatics.persistence.mapper.es.ElasticRepository;
+import com.bizmatics.service.RtAnalogDataService;
+import com.bizmatics.service.es.RtAnalogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author yq
+ * @date 2021/7/17 19:18
+ */
+@Service
+public class RtAnalogServiceImpl implements RtAnalogService {
+
+    @Autowired
+    private ElasticsearchRestTemplate elasticsearchTemplate;
+    @Autowired
+    private ElasticRepository elasticRepository;
+
+    private Pageable pageable = PageRequest.of(0,10);
+
+    @Override
+    public void createIndex() {
+        elasticsearchTemplate.createIndex(RtAnalog.class);
+    }
+
+    @Override
+    public void deleteIndex(String index) {
+        elasticsearchTemplate.deleteIndex(index);
+    }
+
+    @Override
+    public void save(RtAnalog docBean) {
+        elasticRepository.save(docBean);
+    }
+
+    @Override
+    public void saveAll(List<RtAnalog> list) {
+        elasticRepository.saveAll(list);
+    }
+
+    @Override
+    public Iterator<RtAnalog> findAll() {
+        return elasticRepository.findAll().iterator();
+    }
+
+
+}