yq 4 vuotta sitten
vanhempi
commit
fd677ae6d1

+ 129 - 0
fiveep-controller/src/main/java/com/bizmatics/controller/web/MybatisGeneratorUtils.java

@@ -0,0 +1,129 @@
+package com.bizmatics.controller.web;
+
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.*;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author yq
+ * @date 2021/7/6 11:42
+ */
+public class MybatisGeneratorUtils {
+    public static void main(String[] args) {
+        //修改成自己的模块名称
+        String[] models = {"fiveep-controller", "test-service", "test-model", "test-persistence"};
+        for (String model : models) {
+            shell(model);
+        }
+    }
+
+    private static void shell(String model) {
+
+        AutoGenerator mpg = new AutoGenerator();
+        //1、全局配置
+        GlobalConfig gc = new GlobalConfig();
+        File file = new File(model);
+        String path = file.getAbsolutePath();
+        gc.setOutputDir(path + "/src/main/java");  //生成路径(一般都是生成在此项目的src/main/java下面)
+        //修改为自己的名字
+        gc.setAuthor("ya"); //设置作者
+        gc.setOpen(false);
+        gc.setFileOverride(true); //第二次生成会把第一次生成的覆盖掉
+        gc.setServiceName("%sService"); //生成的service接口名字首字母是否为I,这样设置就没有
+        gc.setBaseResultMap(true); //生成resultMap
+        mpg.setGlobalConfig(gc);
+
+        //2、数据源配置
+        //修改数据源
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
+        dsc.setDriverName("com.mysql.jdbc.Driver");
+        dsc.setUsername("root");
+        dsc.setPassword(null);
+        mpg.setDataSource(dsc);
+
+        // 3、包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setParent("com.bizmatics");
+        pc.setController("controller.web");
+        pc.setEntity("model");
+        pc.setMapper("persistence.mapper");
+        pc.setService("service");
+        pc.setServiceImpl("service.impl");
+        //pc.setModuleName("test");
+        mpg.setPackageInfo(pc);
+
+        // 4、策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        strategy.setNaming(NamingStrategy.underline_to_camel);
+        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+        strategy.setSuperMapperClass("com.bizmatics.common.mvc.base.CrudMapper");
+        strategy.setSuperServiceClass("com.bizmatics.common.mvc.base.CrudService");
+        strategy.setSuperServiceImplClass("com.bizmatics.common.mvc.base.AbstractCrudService");
+        // strategy.setTablePrefix("t_"); // 表名前缀
+        strategy.setEntityLombokModel(true); //使用lombok
+        //修改自己想要生成的表
+        strategy.setInclude("test");  // 逆向工程使用的表   如果要生成多个,这里可以传入String[]
+        mpg.setStrategy(strategy);
+
+        // 关闭默认 xml 生成,调整生成 至 根目录
+        //修改对应的模块名称
+        TemplateConfig tc = new TemplateConfig();
+        if ("test-persistence".equals(model)) {
+            tc.setController(null);
+            tc.setEntity(null);
+            tc.setService(null);
+            tc.setServiceImpl(null);
+            // 自定义配置
+            InjectionConfig cfg = new InjectionConfig() {
+                @Override
+                public void initMap() {
+                    // to do nothing
+                }
+            };
+            //如果模板引擎是 velocity
+            String templatePath = "/templates/mapper.xml.vm";
+            // 自定义输出配置
+            List<FileOutConfig> focList = new ArrayList<>();
+            // 自定义配置会被优先输出
+            focList.add(new FileOutConfig(templatePath) {
+                @Override
+                public String outputFile(TableInfo tableInfo) {
+                    // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
+                    return path + "/src/main/resources/mapper/mysql/" + "/"
+                            + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
+                }
+            });
+            cfg.setFileOutConfigList(focList);
+            mpg.setCfg(cfg);
+            tc.setXml(null);
+        } else if ("test-model".equals(model)) {
+            tc.setController(null);
+            tc.setService(null);
+            tc.setServiceImpl(null);
+            tc.setMapper(null);
+            tc.setXml(null);
+        } else if ("test-service".equals(model)) {
+            tc.setController(null);
+            tc.setMapper(null);
+            tc.setXml(null);
+            tc.setEntity(null);
+        } else if ("test-controller".equals(model)) {
+            tc.setMapper(null);
+            tc.setXml(null);
+            tc.setService(null);
+            tc.setServiceImpl(null);
+            tc.setEntity(null);
+        }
+        mpg.setTemplate(tc);
+        //5、执行
+        mpg.execute();
+    }
+}

+ 25 - 22
fiveep-controller/src/main/java/com/bizmatics/controller/web/es/RtAnalogControllerWeb.java

@@ -2,12 +2,14 @@ package com.bizmatics.controller.web.es;
 
 import com.bizmatics.model.es.RtAnalog;
 import com.bizmatics.service.es.RtAnalogService;
+import com.bizmatics.service.job.RatAnalogTask;
 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.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -21,32 +23,12 @@ public class RtAnalogControllerWeb {
 
     @Autowired
     private RtAnalogService rtAnalogService;
+    @Autowired
+    private RatAnalogTask ratAnalogTask;
 
     @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")
@@ -54,4 +36,25 @@ public class RtAnalogControllerWeb {
         return rtAnalogService.findAll();
     }
 
+    @GetMapping("/delete")
+    public void delete(){
+        rtAnalogService.deleteIndex("fiveep");
+    }
+
+    @GetMapping("/addAll")
+    public void addAll(){
+        ratAnalogTask.addAll();
+    }
+
+    @GetMapping("/list")
+    public List<RtAnalog> list(Integer userId, Date startTime,Date endTime){
+        return rtAnalogService.list(startTime,endTime,userId);
+    }
+
+
+    @GetMapping("/page")
+    public List<RtAnalog> page(){
+        return rtAnalogService.page();
+    }
+
 }

+ 4 - 2
fiveep-model/src/main/java/com/bizmatics/model/HtAnalogData.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
+import java.util.Date;
+
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -401,13 +403,13 @@ public class HtAnalogData implements Serializable {
      * 冻结时间
      */
     @TableField("freezingTime")
-    private LocalDate freezingTime;
+    private Date freezingTime;
 
     /**
      * 上报时间
      */
     @TableField("dataTime")
-    private LocalDateTime dataTime;
+    private Date dataTime;
 
 
 }

+ 54 - 2
fiveep-model/src/main/java/com/bizmatics/model/es/RtAnalog.java

@@ -14,6 +14,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.Date;
 
 /**
  * @author yq
@@ -103,255 +104,306 @@ public class RtAnalog {
     /**
      * 平段反向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epn3;
 
     /**
      * 谷段反向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epn4;
 
     /**
      * 三相正向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epp;
 
     /**
      * 尖段正向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epp1;
 
     /**
      * 峰段正向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epp2;
 
     /**
      * 平段正向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epp3;
 
     /**
      * 谷段正向有功电度
      */
+    @Field(type = FieldType.Double)
     private Double Epp4;
 
     /**
      * 三相反向无功电度
      */
+    @Field(type = FieldType.Double)
     private Double Eqn;
 
     /**
      * 三相正向无功电度
      */
+    @Field(type = FieldType.Double)
     private Double Eqp;
 
     /**
      * 频率
      */
+    @Field(type = FieldType.Double)
     private Double f;
 
     /**
      * 零序电流
      */
+    @Field(type = FieldType.Double)
     private Double i0;
 
     /**
      * 负序电流
      */
+    @Field(type = FieldType.Double)
     private Double i2;
 
     /**
      * A相总谐波电流
      */
+    @Field(type = FieldType.Double)
     private Double IHa;
 
     /**
      * B相总谐波电流
      */
+    @Field(type = FieldType.Double)
     private Double IHb;
 
     /**
      * C相总谐波电流
      */
+    @Field(type = FieldType.Double)
     private Double IHc;
 
     /**
      * A相电流
      */
+    @Field(type = FieldType.Double)
     private Double Ia;
 
     /**
      * B相电流
      */
+    @Field(type = FieldType.Double)
     private Double Ib;
 
     /**
      * C相电流
      */
+    @Field(type = FieldType.Double)
     private Double Ic;
 
     /**
      * 剩余电流
      */
+    @Field(type = FieldType.Double)
     private Double Ir;
 
     /**
      * 昨日有功最大需量
      */
+    @Field(type = FieldType.Double)
     private Double LastDayMD;
 
     /**
      * 昨日有功最大需量发生时间
      */
+    @Field(type = FieldType.Double)
     private Double LastDayMDt;
 
     /**
      * 三相总有功功率
      */
+    @Field(type = FieldType.Double)
     private Double p;
 
     /**
      * A相有功功率
      */
+    @Field(type = FieldType.Double)
     private Double Pa;
 
     /**
      * B相有功功率
      */
+    @Field(type = FieldType.Double)
     private Double Pb;
 
     /**
      * C相有功功率
      */
+    @Field(type = FieldType.Double)
     private Double Pc;
 
     /**
      * 三相总无功功率
      */
+    @Field(type = FieldType.Double)
     private Double q;
 
     /**
      * A相无功功率
      */
+    @Field(type = FieldType.Double)
     private Double Qa;
 
     /**
      * B相无功功率
      */
+    @Field(type = FieldType.Double)
     private Double Qb;
 
     /**
      * C相无功功率
      */
+    @Field(type = FieldType.Double)
     private Double Qc;
 
     /**
      * 信号强度
      */
+    @Field(type = FieldType.Double)
     private Double SignalIntensity;
 
     /**
      * 第1路温度
      */
+    @Field(type = FieldType.Double)
     private Double t1;
 
     /**
      * 第2路温度
      */
+    @Field(type = FieldType.Double)
     private Double t2;
 
     /**
      * 第3路温度
      */
+    @Field(type = FieldType.Double)
     private Double t3;
 
     /**
      * 第4路温度
      */
+    @Field(type = FieldType.Double)
     private Double t4;
 
     /**
      * A相电压THD
      */
+    @Field(type = FieldType.Double)
     private Double THDUa;
 
     /**
      * B相电压THD
      */
+    @Field(type = FieldType.Double)
     private Double THDUb;
 
     /**
      * C相电压THD
      */
+    @Field(type = FieldType.Double)
     private Double THDUc;
 
     /**
      * A相电压
      */
+    @Field(type = FieldType.Double)
     private Double Ua;
 
     /**
      * AB线电压
      */
+    @Field(type = FieldType.Double)
     private Double Uab;
 
     /**
      * B相电压
      */
+    @Field(type = FieldType.Double)
     private Double Ub;
 
     /**
      * BC线电压
      */
+    @Field(type = FieldType.Double)
     private Double Ubc;
 
     /**
      * 零序电压不平衡度
      */
+    @Field(type = FieldType.Double)
     private Double UblU0;
 
     /**
      * 负序电压不平衡度
      */
+    @Field(type = FieldType.Double)
     private Double UblU2;
 
     /**
      * C相电压
      */
+    @Field(type = FieldType.Double)
     private Double Uc;
 
     /**
      * CA线电压
      */
+    @Field(type = FieldType.Double)
     private Double Uca;
 
     /**
      * 电压暂降次数
      */
+    @Field(type = FieldType.Integer)
     private Integer Udt;
 
     /**
      * 线路侧电压
      */
+    @Field(type = FieldType.Double)
     private Double Ul;
 
     /**
      * 电压暂升次数
      */
+    @Field(type = FieldType.Integer)
     private Integer Upt;
 
     /**
      * 电压短时中断次数
      */
+    @Field(type = FieldType.Integer)
     private Integer Ust;
 
     /**
      * 冻结时间
      */
-    private LocalDate freezingTime;
+    @Field(type = FieldType.Date)
+    private Date freezingTime;
 
     /**
      * 上报时间
      */
-    private LocalDateTime dataTime;
+    @Field(type = FieldType.Date)
+    private Date dataTime;
 }

+ 2 - 2
fiveep-persistence/src/main/resources/mapper/mysql/HtAnalogDataMapper.xml

@@ -77,8 +77,8 @@
         select *
         from ht_analog_data
         <where>
-            <if test="siteId != null and siteId != 0">
-                and d.site_id = #{siteId}
+            <if test="id != null and id != 0">
+                and id > #{id}
             </if>
             <if test="endTime != null and startTime != null">
                 and dataTime BETWEEN #{startTime} and #{endTime}

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

@@ -3,6 +3,7 @@ package com.bizmatics.service.es;
 import com.bizmatics.model.es.RtAnalog;
 import org.springframework.data.domain.Page;
 
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -22,4 +23,10 @@ public interface RtAnalogService {
 
     Iterator<RtAnalog> findAll();
 
+
+    List<RtAnalog> list(Date startTime, Date endTime, Integer userId);
+
+
+    List<RtAnalog> page();
+
 }

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

@@ -1,18 +1,34 @@
 package com.bizmatics.service.es.impl;
 
+import com.bizmatics.model.Device;
+import com.bizmatics.model.UserSite;
 import com.bizmatics.model.es.RtAnalog;
+import com.bizmatics.persistence.mapper.DeviceMapper;
 import com.bizmatics.persistence.mapper.es.ElasticRepository;
 import com.bizmatics.service.RtAnalogDataService;
 import com.bizmatics.service.es.RtAnalogService;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.MatchQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.elasticsearch.search.sort.FieldSortBuilder;
+import org.elasticsearch.search.sort.SortBuilders;
+import org.elasticsearch.search.sort.SortOrder;
 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.data.elasticsearch.core.query.NativeSearchQueryBuilder;
+import org.springframework.data.elasticsearch.core.query.SearchQuery;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.elasticsearch.index.query.QueryBuilders.*;
 
 /**
  * @author yq
@@ -25,6 +41,8 @@ public class RtAnalogServiceImpl implements RtAnalogService {
     private ElasticsearchRestTemplate elasticsearchTemplate;
     @Autowired
     private ElasticRepository elasticRepository;
+    @Autowired
+    private DeviceMapper deviceMapper;
 
     private Pageable pageable = PageRequest.of(0,10);
 
@@ -53,5 +71,31 @@ public class RtAnalogServiceImpl implements RtAnalogService {
         return elasticRepository.findAll().iterator();
     }
 
+    @Override
+    public List<RtAnalog> list(Date startTime,Date endTime,Integer userId) {
+        List<Device> list = deviceMapper.list(userId, null, null, null, null, null);
+        System.out.println(list.size());
+        List<String> deviceCodes = list.stream().map(Device::getDeviceCode).collect(Collectors.toList());
+        SearchQuery searchQuery = new NativeSearchQueryBuilder()
+                .withQuery(boolQuery()
+                        .must(termsQuery("deviceName", deviceCodes))
+                        ).build();
+        List<RtAnalog> rtAnalogs = elasticsearchTemplate.queryForList(searchQuery, RtAnalog.class);
+        System.out.println(rtAnalogs.size());
+        return rtAnalogs;
+
+    }
+
+    @Override
+    public List<RtAnalog> page() {
+        //构建查询
+        SearchQuery query = new NativeSearchQueryBuilder()
+                .withPageable(pageable)
+                .build();
+        Page<RtAnalog> searchResponse = elasticRepository.search(query);
+        System.out.println(searchResponse.getTotalPages());
+        return searchResponse.getContent();
+    }
+
 
 }

+ 34 - 0
fiveep-service/src/main/java/com/bizmatics/service/job/RatAnalogTask.java

@@ -1,18 +1,52 @@
 package com.bizmatics.service.job;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.bizmatics.common.core.util.BeanMapperUtils;
+import com.bizmatics.model.AlarmPower;
+import com.bizmatics.model.HtAnalogData;
+import com.bizmatics.model.RtAnalogData;
+import com.bizmatics.model.es.RtAnalog;
 import com.bizmatics.persistence.mapper.HtAnalogDataMapper;
 import com.bizmatics.persistence.mapper.RtAnalogDataMapper;
+import com.bizmatics.service.es.RtAnalogService;
+import com.bizmatics.service.util.SessionLocal;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author yq
  * @date 2021/7/17 19:41
  */
+@Slf4j
 @Service
 public class RatAnalogTask {
 
 
     @Autowired
     private HtAnalogDataMapper htAnalogDataMapper;
+    @Autowired
+    private RtAnalogService rtAnalogService;
+
+
+    public void addAll(){
+        List<HtAnalogData> list = null;
+        Integer id = 0;
+        Integer index = 1;
+        do {
+            Page<HtAnalogData> page = new Page<>(index, 2000);
+            page = htAnalogDataMapper.page(page, null,null,id);
+            list = page.getRecords();
+            if (!CollectionUtils.isEmpty(list)){
+                rtAnalogService.saveAll(BeanMapperUtils.mapList(list, HtAnalogData.class, RtAnalog.class));
+                id = list.get(list.size()-1).getId();
+                index++;
+            }
+            log.info("处理到最大id"+id);
+        }while (!CollectionUtils.isEmpty(list));
+    }
 }