| 
					
				 | 
			
			
				@@ -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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 |