Browse Source

修改获取数据模板功能

wangyi 3 years ago
parent
commit
e7cbbc828f

+ 19 - 32
src/main/java/io/renren/modules/sys/controller/dataaccess/getTemplateController.java

@@ -2,10 +2,14 @@ package io.renren.modules.sys.controller.dataaccess;
 
 import io.renren.common.utils.R;
 import io.renren.datasource.annotation.DataSource;
+import io.renren.modules.dataSet.DataSetUtils.ToEnglish;
 import io.renren.modules.sys.entity.dataaccess.Reflect;
 import io.renren.modules.sys.service.DataAccessService;
 import io.renren.modules.sys.service.MeasurePointService;
 import io.renren.modules.sys.service.ReflectService;
+import io.renren.modules.sys.service.SubEquipmentService;
+import net.sourceforge.pinyin4j.PinyinHelper;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
@@ -40,6 +44,8 @@ public class getTemplateController {
     DataAccessService dataAccessService;
     @Autowired
     MeasurePointService measurePointService;
+    @Autowired
+    SubEquipmentService subEquipmentService;
 
     /**
      * Description:根据所选的测点,生成获取该测点实时数据的python模板
@@ -55,41 +61,22 @@ public class getTemplateController {
         for(int n=0;n<fieldIds.length;n++){
             measurepoints[n]= Integer.parseInt(fieldIds[n]);
         }
-        List<Reflect> searchReflects=new ArrayList<>();
-
-        Map<Integer,String> taskMap=new HashMap<>();
-        String measurePointsInfo="";
+        String temp="import happybase\n" +
+                "\n" +
+                "connection = happybase.Connection(host='"+resultToDB+"', port=9090)\n";
+        StringBuilder stringBuilder=new StringBuilder(temp);
         for(int i=0;i<measurepoints.length;i++){
-            List<Reflect> reflects=reflectService.selectByFieldId(measurepoints[i]);
-            Reflect reflect=reflects.get(reflects.size()-1);
-            searchReflects.add(reflect);
-            int taskId=reflect.getTaskId();
-            if (!taskMap.containsKey(taskId)){
-                String taskName=dataAccessService.selectByPrimaryKey(taskId).getName();
-                taskMap.put(taskId,taskName);
-            }
-            measurePointsInfo+="#"+measurePointService.selectByPrimaryKey(measurepoints[i]).getRemark()+"的reflectId为"+reflect.getId()+"\n";
-        }
+            String measurePointName=measurePointService.selectByPrimaryKey(measurepoints[i]).getName().substring(4);
+            String hbaseTableName=subEquipmentService.selectByPrimaryKey(measurePointService.getSubEquipmentId(measurepoints[i])).getHbaseTableName();
+            String measurePointPinYin=ToEnglish.getPinYin(measurePointName);
+            stringBuilder.append("name='"+hbaseTableName+"'\n");
+            stringBuilder.append("table=happybase.Table(name, connection)\n");
+            stringBuilder.append(measurePointPinYin+"=[]  #"+measurePointName+"数据\n");
+            stringBuilder.append("for key, value in table.scan():\n");
+            stringBuilder.append("  "+measurePointPinYin+".append(float(value[b'data:"+measurePointPinYin+"_after'].decode()))\n\n");
 
-        String kafkaString="from kafka import KafkaConsumer\n" +
-                "\n" +
-                "consumer = KafkaConsumer(bootstrap_servers=['"+realTimeKafka1+"','"+realTimeKafka2+"','"+realTimeKafka3+"'])\n" +
-                "consumer.subscribe(topics=topics)\n" +
-                "\n" +
-                "for message in consumer:\n" +
-                "    print(\"topic:%s partition:%d offset:%d: key=%s value=%s\" % (message.topic, message.partition,message.offset, message.key,message.value))\n";
-        String b="topics=()";
-        StringBuilder sb=new StringBuilder(b);
-        int index=sb.indexOf(")");
-        String insertString="";
-        for(int key:taskMap.keySet()){
-            insertString+="'"+taskMap.get(key)+"',";
         }
-        sb.insert(index,insertString.substring(0,insertString.length()-1));
-
-        b=sb.toString();//kafka的topics
-        String result=b+"\n"+measurePointsInfo+kafkaString;
-        return R.ok().put("code",result);
+        return R.ok().put("code",stringBuilder.toString());
     }
 
     /**

+ 7 - 0
src/main/java/io/renren/modules/sys/dao/dataaccess/MeasurePointMapper.java

@@ -6,4 +6,11 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface MeasurePointMapper {
     public MeasurePoint selectByPrimaryKey(int id);
+
+    /**
+     * 根据测点id获取其子设备id
+     * @param id
+     * @return
+     */
+    public int getSubEquipmentId(int id);
 }

+ 9 - 0
src/main/java/io/renren/modules/sys/dao/dataaccess/SubEquipmentMapper.java

@@ -0,0 +1,9 @@
+package io.renren.modules.sys.dao.dataaccess;
+
+import io.renren.modules.sys.entity.dataaccess.SubEquipment;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface SubEquipmentMapper {
+    public SubEquipment selectByPrimaryKey(int id);
+}

+ 2 - 0
src/main/java/io/renren/modules/sys/entity/dataaccess/MeasurePoint.java

@@ -10,6 +10,8 @@ public class MeasurePoint {
     @TableId
     private int id;
 
+    private String name;
+
     private String remark;
 
 }

+ 12 - 0
src/main/java/io/renren/modules/sys/entity/dataaccess/SubEquipment.java

@@ -0,0 +1,12 @@
+package io.renren.modules.sys.entity.dataaccess;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("subequipment")
+public class SubEquipment {
+    private int id;
+
+    private String hbaseTableName;
+}

+ 2 - 0
src/main/java/io/renren/modules/sys/service/MeasurePointService.java

@@ -4,4 +4,6 @@ import io.renren.modules.sys.entity.dataaccess.MeasurePoint;
 
 public interface MeasurePointService {
     MeasurePoint selectByPrimaryKey(int id);
+
+    int getSubEquipmentId(int id);
 }

+ 7 - 0
src/main/java/io/renren/modules/sys/service/SubEquipmentService.java

@@ -0,0 +1,7 @@
+package io.renren.modules.sys.service;
+
+import io.renren.modules.sys.entity.dataaccess.SubEquipment;
+
+public interface SubEquipmentService {
+    SubEquipment selectByPrimaryKey(int id);
+}

+ 5 - 0
src/main/java/io/renren/modules/sys/service/impl/MeasurePointServiceImpl.java

@@ -14,4 +14,9 @@ public class MeasurePointServiceImpl implements MeasurePointService {
     public MeasurePoint selectByPrimaryKey(int id) {
         return measurePointMapper.selectByPrimaryKey(id);
     }
+
+    @Override
+    public int getSubEquipmentId(int id) {
+        return measurePointMapper.getSubEquipmentId(id);
+    }
 }

+ 18 - 0
src/main/java/io/renren/modules/sys/service/impl/SubEquipmentServiceImpl.java

@@ -0,0 +1,18 @@
+package io.renren.modules.sys.service.impl;
+
+import io.renren.modules.sys.dao.dataaccess.SubEquipmentMapper;
+import io.renren.modules.sys.entity.dataaccess.SubEquipment;
+import io.renren.modules.sys.service.SubEquipmentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SubEquipmentServiceImpl implements SubEquipmentService {
+    @Autowired
+    SubEquipmentMapper subEquipmentMapper;
+
+    @Override
+    public SubEquipment selectByPrimaryKey(int id) {
+        return subEquipmentMapper.selectByPrimaryKey(id);
+    }
+}

+ 11 - 11
src/main/resources/application.yml

@@ -18,22 +18,22 @@ minio:
 #docker远程连接
 docker:
   #url: https://192.168.25.101:2376
-  url: https://10.168.57.11:2376
-remote-docker: 10.168.57.11
+  url: https://150.158.138.99:2376
+remote-docker: 150.158.138.99
 #上传文件到远程服务器地址,用户名及密码,上传文件的基础路径
-host: 10.168.57.11
+host: 150.158.138.99
 host-username: root
-host-password: root
+host-password: XDU520bdm
 host-basepath: /opt/uploadFile
 host-port: 22
-key-needed: false
-key-location: F:/Program Files/secretKey/lab1
+key-needed: true
+key-location: D:/Program Files/secretKey/lab1
 
 #docker证书存放路径
-docker_ca: F:/aiplat/school_ca
+docker_ca: D:/aiplat/school_ca
 
 #minio暂存文件地址
-tempFileLocation: F:/aiplat/test0708/testPython.py
+tempFileLocation: D:/aiplat/test0708/testPython.py
 
 #获取kafka实时数据ip与端口
 realTimeKafka1: 10.168.57.10:9092
@@ -41,13 +41,13 @@ realTimeKafka2: 10.168.57.11:9092
 realTimeKafka3: 10.168.57.12:9092
 
 #算法结果入库模板ip
-resultToDB: 10.168.57.10
+resultToDB: 49.235.67.21
 
 #数据预处理数据集存放文件夹
-datasetLocation: F:/aiplat/demoCSV
+datasetLocation: D:/aiplat/demoCSV
 
 #数据预处理python文件存放文件夹
-dataPreProcessLocation: F:/aiplat/dataPreProcess
+dataPreProcessLocation: D:/aiplat/dataPreProcess
 
 spring:
   # 环境 dev|test|prod

+ 8 - 2
src/main/resources/mapper/dataaccess/MeasurePointMapper.xml

@@ -5,10 +5,11 @@
 <mapper namespace="io.renren.modules.sys.dao.dataaccess.MeasurePointMapper">
     <resultMap id="BaseResultMap" type="io.renren.modules.sys.entity.dataaccess.MeasurePoint">
         <id column="id" jdbcType="INTEGER" property="id" />
-        <result column="remark" jdbcType="INTEGER" property="remark" />
+        <result column="name" jdbcType="VARCHAR" property="name" />
+        <result column="remark" jdbcType="VARCHAR" property="remark" />
     </resultMap>
     <sql id="Base_Column_List">
-        id,remark
+        id,name,remark
     </sql>
     <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
         select
@@ -16,4 +17,9 @@
         from measurepoint
         where id=#{id}
     </select>
+
+    <select id="getSubEquipmentId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
+        select subEquipmentId from subequipment_measurepoint
+        where measurePointId=#{id}
+    </select>
 </mapper>

+ 19 - 0
src/main/resources/mapper/dataaccess/SubEquipmentMapper.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="io.renren.modules.sys.dao.dataaccess.SubEquipmentMapper">
+    <resultMap id="BaseResultMap" type="io.renren.modules.sys.entity.dataaccess.SubEquipment">
+        <id column="id" jdbcType="INTEGER" property="id" />
+        <result column="hbaseTableName" jdbcType="VARCHAR" property="hbaseTableName" />
+    </resultMap>
+    <sql id="Base_Column_List">
+        id,hbaseTableName
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List" />
+        from subequipment
+        where id=#{id}
+    </select>
+</mapper>