Browse Source

Redis接口和MongoDB接口第一版

shilin 5 years ago
parent
commit
db79f480f6

+ 80 - 0
src/main/java/com/gyee/frame/common/conf/MongodbConfig.java

@@ -0,0 +1,80 @@
+package com.gyee.frame.common.conf;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 读取项目相关配置
+ * 
+ * @author gyee
+ */
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "mongodb")
+public class MongodbConfig
+{
+    public static String mongodb_ip;
+    public static String mongodb_port;
+    public static String mongodb_perHost;
+    public static String mongodb_threadsAllowed;
+    public static String mongodb_connectTimeout;
+    public static String mongodb_maxWaitTime;
+    public static String mongodb_socketTimeout;
+
+    public static String getMongodb_ip() {
+        return mongodb_ip;
+    }
+
+    public static void setMongodb_ip(String mongodb_ip) {
+        MongodbConfig.mongodb_ip = mongodb_ip;
+    }
+
+    public static String getMongodb_port() {
+        return mongodb_port;
+    }
+
+    public static void setMongodb_port(String mongodb_port) {
+        MongodbConfig.mongodb_port = mongodb_port;
+    }
+
+    public static String getMongodb_perHost() {
+        return mongodb_perHost;
+    }
+
+    public static void setMongodb_perHost(String mongodb_perHost) {
+        MongodbConfig.mongodb_perHost = mongodb_perHost;
+    }
+
+    public static String getMongodb_threadsAllowed() {
+        return mongodb_threadsAllowed;
+    }
+
+    public static void setMongodb_threadsAllowed(String mongodb_threadsAllowed) {
+        MongodbConfig.mongodb_threadsAllowed = mongodb_threadsAllowed;
+    }
+
+    public static String getMongodb_connectTimeout() {
+        return mongodb_connectTimeout;
+    }
+
+    public static void setMongodb_connectTimeout(String mongodb_connectTimeout) {
+        MongodbConfig.mongodb_connectTimeout = mongodb_connectTimeout;
+    }
+
+    public static String getMongodb_maxWaitTime() {
+        return mongodb_maxWaitTime;
+    }
+
+    public static void setMongodb_maxWaitTime(String mongodb_maxWaitTime) {
+        MongodbConfig.mongodb_maxWaitTime = mongodb_maxWaitTime;
+    }
+
+    public static String getMongodb_socketTimeout() {
+        return mongodb_socketTimeout;
+    }
+
+    public static void setMongodb_socketTimeout(String mongodb_socketTimeout) {
+        MongodbConfig.mongodb_socketTimeout = mongodb_socketTimeout;
+    }
+}

+ 81 - 0
src/main/java/com/gyee/frame/common/conf/RedisConfig.java

@@ -0,0 +1,81 @@
+package com.gyee.frame.common.conf;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+/**
+ * 读取项目相关配置
+ * 
+ * @author gyee
+ */
+
+@Configuration
+@ConfigurationProperties(prefix = "redis")
+public class RedisConfig
+{
+    public static String redis_ss_ip;
+    public static Integer redis_ss_port;
+    public static String redis_ls_ip;
+    public static Integer redis_ls_port;
+
+    @Bean(name = "ss_redis")
+    public static JedisPool redis_SS_Pool_Factory()  throws Exception{
+
+        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+        jedisPoolConfig.setMaxIdle(2000);
+        jedisPoolConfig.setMaxWaitMillis(500);
+
+        // 是否启用pool的jmx管理功能, 默认true
+        jedisPoolConfig.setJmxEnabled(true);
+        JedisPool jedisPool = new JedisPool(jedisPoolConfig, redis_ss_ip, redis_ss_port);
+        return jedisPool;
+    }
+
+    @Bean(name = "ls_redis")
+    public static JedisPool redis_LS_PoolFactory()  throws Exception{
+
+        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+        jedisPoolConfig.setMaxIdle(2000);
+        jedisPoolConfig.setMaxWaitMillis(500);
+
+        // 是否启用pool的jmx管理功能, 默认true
+        jedisPoolConfig.setJmxEnabled(true);
+        JedisPool jedisPool = new JedisPool(jedisPoolConfig, redis_ls_ip, redis_ls_port);
+        return jedisPool;
+    }
+
+    public static String getRedis_ss_ip() {
+        return redis_ss_ip;
+    }
+
+    public static void setRedis_ss_ip(String redis_ss_ip) {
+        RedisConfig.redis_ss_ip = redis_ss_ip;
+    }
+
+    public static Integer getRedis_ss_port() {
+        return redis_ss_port;
+    }
+
+    public static void setRedis_ss_port(Integer redis_ss_port) {
+        RedisConfig.redis_ss_port = redis_ss_port;
+    }
+
+    public static String getRedis_ls_ip() {
+        return redis_ls_ip;
+    }
+
+    public static void setRedis_ls_ip(String redis_ls_ip) {
+        RedisConfig.redis_ls_ip = redis_ls_ip;
+    }
+
+    public static Integer getRedis_ls_port() {
+        return redis_ls_port;
+    }
+
+    public static void setRedis_ls_port(Integer redis_ls_port) {
+        RedisConfig.redis_ls_port = redis_ls_port;
+    }
+}

+ 1 - 0
src/main/java/com/gyee/frame/common/conf/redis/CacheContext.java

@@ -12,6 +12,7 @@ public class CacheContext {
     @Autowired
     private RedisTemplate redisTemplate;
     public <T> T getObjectFromCache(String str){
+
         byte[] by = (byte[])redisTemplate.opsForValue().get(str);
         T t = (T)cacheConfig.deserialize(by);
         return t;

+ 47 - 0
src/main/java/com/gyee/frame/common/spring/InitialRunner.java

@@ -0,0 +1,47 @@
+package com.gyee.frame.common.spring;
+
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.auto.RMConfigExample;
+import com.gyee.frame.service.RMConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 服务启动执行
+ */
+@Component
+public class InitialRunner implements CommandLineRunner {
+
+
+    @Autowired
+    private RMConfigService rMConfigService;
+    //RMConfig
+
+    public static Map<String, RMConfig> rmcmap = new HashMap<String, RMConfig>();
+    @Override
+    public void run(String... args) throws Exception {
+        System.out.println(">>>>>>>>>>>>>>>服务启动执行,换成测点关联数据 <<<<<<<<<<<<<");
+
+        RMConfigExample example=new RMConfigExample();
+
+        example.setOrderByClause("id ASC");
+
+        example.createCriteria().getAllCriteria();
+
+        List<RMConfig> list= rMConfigService.selectByExample(example);
+
+        if(!list.isEmpty())
+        {
+            for(RMConfig rm:list)
+            {
+                rmcmap.put(rm.getId(),rm);
+            }
+        }
+    }
+
+}

+ 7 - 0
src/main/java/com/gyee/frame/model/custom/DNAStatVal.java

@@ -0,0 +1,7 @@
+package com.gyee.frame.model.custom;
+
+public class DNAStatVal {
+	public DNAVal avg = new DNAVal();
+	public DNAVal max = new DNAVal();
+	public DNAVal min = new DNAVal();
+}

+ 6 - 0
src/main/java/com/gyee/frame/model/custom/DNAVal.java

@@ -0,0 +1,6 @@
+package com.gyee.frame.model.custom;
+public class DNAVal {
+	public double DValue;
+	public int Time;
+	public short Status;
+}

+ 55 - 0
src/main/java/com/gyee/frame/model/custom/PointData.java

@@ -0,0 +1,55 @@
+package com.gyee.frame.model.custom;
+
+public class PointData {
+
+	private double pointValueInDouble;
+
+	private Long pointTime;
+
+	private String pointValue;
+
+	private String pointName;// z自定义名称
+
+	private String ednaId;// edna全局id
+
+	public String getEdnaId() {
+		return ednaId;
+	}
+
+	public String getPointName() {
+		return pointName;
+	}
+
+	public Long getPointTime() {
+		return pointTime;
+	}
+
+	public String getPointValue() {
+		return pointValue;
+	}
+
+	public double getPointValueInDouble() {
+		return pointValueInDouble;
+	}
+
+	public void setEdnaId(String ednaId) {
+		this.ednaId = ednaId;
+	}
+
+	public void setPointName(String pointName) {
+		this.pointName = pointName;
+	}
+
+	public void setPointTime(Long pointTime) {
+		this.pointTime = pointTime;
+	}
+
+	public void setPointValue(String pointValue) {
+		this.pointValue = pointValue;
+	}
+
+	public void setPointValueInDouble(double pointValueInDouble) {
+		this.pointValueInDouble = pointValueInDouble;
+	}
+
+}

+ 124 - 0
src/main/java/com/gyee/frame/model/custom/WindPowerStationTestingPoint.java

@@ -0,0 +1,124 @@
+package com.gyee.frame.model.custom;
+
+
+public class WindPowerStationTestingPoint implements java.io.Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private String code;
+	private String typeid;
+	private String name;
+	private String model;
+	private String valueunit;
+	private String englishname;
+	private String modelid;
+	private Double maxval;
+	private Double minval;
+	private Double reasonablemaxval;
+	private Double reasonableminval;
+	private String uniformcode;
+	private String shortid;
+	private String longid;
+	private String windpowerstationid;
+	private String realtimeid;
+	public String getCode() {
+    	return code;
+    }
+	public void setCode(String code) {
+    	this.code = code;
+    }
+	public String getTypeid() {
+    	return typeid;
+    }
+	public void setTypeid(String typeid) {
+    	this.typeid = typeid;
+    }
+	public String getName() {
+    	return name;
+    }
+	public void setName(String name) {
+    	this.name = name;
+    }
+	public String getModel() {
+    	return model;
+    }
+	public void setModel(String model) {
+    	this.model = model;
+    }
+	public String getValueunit() {
+    	return valueunit;
+    }
+	public void setValueunit(String valueunit) {
+    	this.valueunit = valueunit;
+    }
+	public String getEnglishname() {
+    	return englishname;
+    }
+	public void setEnglishname(String englishname) {
+    	this.englishname = englishname;
+    }
+	public String getModelid() {
+    	return modelid;
+    }
+	public void setModelid(String modelid) {
+    	this.modelid = modelid;
+    }
+	public Double getMaxval() {
+    	return maxval;
+    }
+	public void setMaxval(Double maxval) {
+    	this.maxval = maxval;
+    }
+	public Double getMinval() {
+    	return minval;
+    }
+	public void setMinval(Double minval) {
+    	this.minval = minval;
+    }
+	public Double getReasonablemaxval() {
+    	return reasonablemaxval;
+    }
+	public void setReasonablemaxval(Double reasonablemaxval) {
+    	this.reasonablemaxval = reasonablemaxval;
+    }
+	public Double getReasonableminval() {
+    	return reasonableminval;
+    }
+	public void setReasonableminval(Double reasonableminval) {
+    	this.reasonableminval = reasonableminval;
+    }
+	public String getUniformcode() {
+    	return uniformcode;
+    }
+	public void setUniformcode(String uniformcode) {
+    	this.uniformcode = uniformcode;
+    }
+	public String getShortid() {
+    	return shortid;
+    }
+	public void setShortid(String shortid) {
+    	this.shortid = shortid;
+    }
+	public String getLongid() {
+    	return longid;
+    }
+	public void setLongid(String longid) {
+    	this.longid = longid;
+    }
+	public String getWindpowerstationid() {
+    	return windpowerstationid;
+    }
+	public void setWindpowerstationid(String windpowerstationid) {
+    	this.windpowerstationid = windpowerstationid;
+    }
+	public String getRealtimeid() {
+    	return realtimeid;
+    }
+	public void setRealtimeid(String realtimeid) {
+    	this.realtimeid = realtimeid;
+    }
+
+
+	
+
+}

+ 180 - 0
src/main/java/com/gyee/frame/model/custom/WindTurbineTestingPointAi.java

@@ -0,0 +1,180 @@
+package com.gyee.frame.model.custom;
+
+
+public class WindTurbineTestingPointAi implements java.io.Serializable {
+
+	private static final long serialVersionUID = -7413709575956310328L;
+	// Fields
+
+	private String id;
+	private String code;
+	private String name;
+	private String model;
+	private String valueunit;
+	private String englishname;
+	private String typeid;
+	private String modelid;
+	private Double maxval;
+	private Double minval;
+	private Double reasonablemaxval;
+	private Double reasonableminval;
+	private String windturbineid;
+	private String uniformcode;
+	private String shortid;
+	private String longid;
+	private String windpowerstationid;
+	private String realtimeid;
+
+	// Constructors
+
+	/** default constructor */
+	public WindTurbineTestingPointAi() {
+	}
+
+	public String getId() {
+    	return id;
+    }
+
+	public void setId(String id) {
+    	this.id = id;
+    }
+
+	public String getCode() {
+    	return code;
+    }
+
+	public void setCode(String code) {
+    	this.code = code;
+    }
+
+	public String getName() {
+    	return name;
+    }
+
+	public void setName(String name) {
+    	this.name = name;
+    }
+
+	public String getModel() {
+    	return model;
+    }
+
+	public void setModel(String model) {
+    	this.model = model;
+    }
+
+	public String getValueunit() {
+    	return valueunit;
+    }
+
+	public void setValueunit(String valueunit) {
+    	this.valueunit = valueunit;
+    }
+
+	public String getEnglishname() {
+    	return englishname;
+    }
+
+	public void setEnglishname(String englishname) {
+    	this.englishname = englishname;
+    }
+
+	public String getTypeid() {
+    	return typeid;
+    }
+
+	public void setTypeid(String typeid) {
+    	this.typeid = typeid;
+    }
+
+	public String getModelid() {
+    	return modelid;
+    }
+
+	public void setModelid(String modelid) {
+    	this.modelid = modelid;
+    }
+
+	public Double getMaxval() {
+    	return maxval;
+    }
+
+	public void setMaxval(Double maxval) {
+    	this.maxval = maxval;
+    }
+
+	public Double getMinval() {
+    	return minval;
+    }
+
+	public void setMinval(Double minval) {
+    	this.minval = minval;
+    }
+
+	public Double getReasonablemaxval() {
+    	return reasonablemaxval;
+    }
+
+	public void setReasonablemaxval(Double reasonablemaxval) {
+    	this.reasonablemaxval = reasonablemaxval;
+    }
+
+	public Double getReasonableminval() {
+    	return reasonableminval;
+    }
+
+	public void setReasonableminval(Double reasonableminval) {
+    	this.reasonableminval = reasonableminval;
+    }
+
+	public String getWindturbineid() {
+    	return windturbineid;
+    }
+
+	public void setWindturbineid(String windturbineid) {
+    	this.windturbineid = windturbineid;
+    }
+
+	public String getUniformcode() {
+    	return uniformcode;
+    }
+
+	public void setUniformcode(String uniformcode) {
+    	this.uniformcode = uniformcode;
+    }
+
+	public String getShortid() {
+    	return shortid;
+    }
+
+	public void setShortid(String shortid) {
+    	this.shortid = shortid;
+    }
+
+	public String getLongid() {
+    	return longid;
+    }
+
+	public void setLongid(String longid) {
+    	this.longid = longid;
+    }
+
+	public String getWindpowerstationid() {
+    	return windpowerstationid;
+    }
+
+	public void setWindpowerstationid(String windpowerstationid) {
+    	this.windpowerstationid = windpowerstationid;
+    }
+
+	public String getRealtimeid() {
+    	return realtimeid;
+    }
+
+	public void setRealtimeid(String realtimeid) {
+    	this.realtimeid = realtimeid;
+    }
+
+	
+
+}

+ 107 - 0
src/main/java/com/gyee/frame/service/RMConfigService.java

@@ -0,0 +1,107 @@
+package com.gyee.frame.service;
+
+
+import com.gyee.frame.common.base.BaseService;
+import com.gyee.frame.common.support.Convert;
+import com.gyee.frame.mapper.auto.RMConfigMapper;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.auto.RMConfigExample;
+import com.gyee.frame.util.SnowflakeIdWorker;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 线路 LineService
+ * @Title: LineService.java 
+ * @Package com.gyee.frame.service 
+ * @author gyee_自动生成
+ * @email 1@qq.com
+ * @date 2019-12-31 14:58:09  
+ **/
+@Service
+public class RMConfigService implements BaseService<RMConfig, RMConfigExample> {
+
+	@Resource
+	private RMConfigMapper rMConfigMapper;
+	
+      	   	      	      	      	      	      	      	      	      	      	
+
+
+	@Override
+	public int deleteByPrimaryKey(String ids) {
+				
+			List<String> lista= Convert.toListStrArray(ids);
+			RMConfigExample example=new RMConfigExample();
+			example.createCriteria().andIdIn(lista);
+			return rMConfigMapper.deleteByExample(example);
+			
+				
+	}
+	
+	
+	@Override
+	public RMConfig selectByPrimaryKey(String id) {
+				
+			return rMConfigMapper.selectByPrimaryKey(id);
+				
+	}
+
+	
+	@Override
+	public int updateByPrimaryKeySelective(RMConfig record) {
+		return rMConfigMapper.updateByPrimaryKeySelective(record);
+	}
+	
+	
+	/**
+	 * 添加
+	 */
+	@Override
+	public int insertSelective(RMConfig record) {
+				
+		//添加雪花主键id
+		record.setId(SnowflakeIdWorker.getUUID());
+			
+				
+		return rMConfigMapper.insertSelective(record);
+	}
+	
+	
+	@Override
+	public int updateByExampleSelective(RMConfig record, RMConfigExample example) {
+		
+		return rMConfigMapper.updateByExampleSelective(record, example);
+	}
+
+	
+	@Override
+	public int updateByExample(RMConfig record, RMConfigExample example) {
+		
+		return rMConfigMapper.updateByExample(record, example);
+	}
+
+	@Override
+	public List<RMConfig> selectByExample(RMConfigExample example) {
+		
+		return rMConfigMapper.selectByExample(example);
+	}
+
+	
+	@Override
+	public long countByExample(RMConfigExample example) {
+		
+		return rMConfigMapper.countByExample(example);
+	}
+
+	
+	@Override
+	public int deleteByExample(RMConfigExample example) {
+		
+		return rMConfigMapper.deleteByExample(example);
+	}
+	
+
+
+}

+ 65 - 4
src/main/java/com/gyee/frame/util/DateUtils.java

@@ -1,12 +1,13 @@
 package com.gyee.frame.util;
 
+import org.apache.commons.lang3.time.DateFormatUtils;
+
 import java.lang.management.ManagementFactory;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 
-import org.apache.commons.lang3.time.DateFormatUtils;
-
 /**
  * 日期处理
  * @ClassName: DateUtils
@@ -36,8 +37,10 @@ public class DateUtils  extends org.apache.commons.lang3.time.DateUtils{
         }
         return null;
     }
-    
-    
+
+    public static Date parseLongToDate(long time) {
+        return new Date(time);
+    }
     
     public static String YYYY = "yyyy";
 
@@ -178,4 +181,62 @@ public class DateUtils  extends org.apache.commons.lang3.time.DateUtils{
         // long sec = diff % nd % nh % nm / ns;
         return day + "天" + hour + "小时" + min + "分钟";
     }
+
+    /**
+     * 计算两个时间之间差的小时数(取整后)
+     * @param d1
+     * @param d2
+     * @return
+     */
+    public static int hoursDiff(Date d1, Date d2) {
+        return (int) Math.floor(Math.abs((d1.getTime() - d2.getTime()))/(60*60*1000));
+    }
+
+    /**
+     * 计算两个时间之间差的分钟数(取整后)
+     * @param d1
+     * @param d2
+     * @return
+     */
+    public static int minutesDiff(Date d1, Date d2) {
+        return (int) Math.floor(Math.abs((d1.getTime() - d2.getTime()))/(60*1000));
+    }
+
+    /**
+     * 计算两个时间之间差的秒数(取整后)
+     * @param d1
+     * @param d2
+     * @return
+     */
+    public static long secondsDiff(Date d1, Date d2) {
+        return (long) Math.floor(Math.abs((d1.getTime() - d2.getTime()))/(1000));
+    }
+
+    /**
+     * 计算两个时间之间差的天数(取整后)
+     * @param d1
+     * @param d2
+     * @return
+     */
+    public static int daysDiff(Date d1, Date d2) {
+        return (int) Math.floor(Math.abs((d1.getTime() - d2.getTime()))/(60*60*24*1000));
+    }
+
+    /**
+     * 计算两个时间之间的月差
+     * @param d1
+     * @param d2
+     * @return
+     */
+    public static int monthsDiff(Date d1, Date d2) {
+        Calendar cal1 = Calendar.getInstance();
+        Calendar cal2 = Calendar.getInstance();
+        cal1.setTime(d1);
+        cal2.setTime(d2);
+
+        return (int) Math.abs((cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR))*12 +
+                cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH));
+    }
+
+
 }

+ 58 - 0
src/main/java/com/gyee/frame/util/mongodb/ApiMongoDb.java

@@ -0,0 +1,58 @@
+package com.gyee.frame.util.mongodb;
+
+
+import com.gyee.frame.common.conf.MongodbConfig;
+import com.mongodb.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ClassName:ApiEdos <br/>
+ * Function: TODO ADD FUNCTION. <br/>
+ * Reason: TODO ADD REASON. <br/>
+ * Date: 2016-7-25 下午12:26:14 <br/>
+ * 
+ * @author 石林
+ * @version
+ * @since JDK 1.6
+ * @see
+ */
+public class ApiMongoDb {
+
+	private static MongoClient mongoClient = null;
+	// 获得配置文件edos ip地址 和端口号
+	static String mongodb_ip = MongodbConfig.mongodb_ip;
+	static int mongodb_port = Integer.valueOf(MongodbConfig.mongodb_port);
+	static int mongodb_perHost = Integer.valueOf(MongodbConfig.mongodb_perHost);
+	static int mongodb_threadsAllowed = Integer.valueOf(MongodbConfig.mongodb_threadsAllowed);
+	static int mongodb_connectTimeout = Integer.valueOf(MongodbConfig.mongodb_connectTimeout);
+	static int mongodb_maxWaitTime = Integer.valueOf(MongodbConfig.mongodb_maxWaitTime);
+	static int mongodb_socketTimeout = Integer.valueOf(MongodbConfig.mongodb_socketTimeout);
+
+	private ApiMongoDb() {
+	}
+
+	public static MongoClient getInstance() throws Exception {
+
+		if (mongoClient == null) {
+
+			ServerAddress serverAddress = new ServerAddress(mongodb_ip, mongodb_port);
+			List<ServerAddress> addrs = new ArrayList<ServerAddress>();
+			addrs.add(serverAddress);
+			// MongoClientOptions options=new MongoClientOptions();
+
+			WriteConcern writeConcern = new WriteConcern(1, 0);
+
+			MongoClientOptions options = new MongoClientOptions.Builder().connectionsPerHost(mongodb_threadsAllowed).threadsAllowedToBlockForConnectionMultiplier(mongodb_threadsAllowed).connectTimeout(mongodb_connectTimeout).maxWaitTime(mongodb_maxWaitTime)
+					// .socketKeepAlive(true)
+					.socketTimeout(mongodb_socketTimeout).writeConcern(writeConcern).readPreference(ReadPreference.secondaryPreferred()).build();
+
+			mongoClient = new MongoClient(serverAddress, options);
+
+		}
+		return mongoClient;
+
+	}
+
+}

+ 346 - 0
src/main/java/com/gyee/frame/util/mongodb/HistoryDatasRawUtil.java

@@ -0,0 +1,346 @@
+package com.gyee.frame.util.mongodb;
+
+import com.alibaba.fastjson.JSONArray;
+import com.google.common.collect.Lists;
+import com.gyee.frame.common.spring.InitialRunner;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.StringUtils;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+
+import java.util.*;
+
+/**
+ */
+public class HistoryDatasRawUtil {
+
+
+
+	private String mongodb_c = "C";
+	private String mongodb_db = "H";
+	private String mongodb_p = "K";
+	private String mongodb_ls = "M";
+	private String mongodb_key = "M.S";
+	private String mongodb_value = "M.V";
+	private String po_key = "S";
+	private String po_value = "V";
+
+
+	@SuppressWarnings({ "unused" })
+	public  void findHistoryDatasRaw(String point, Long beginDate, Long endDate, List<PointData> ls, JedisPool jedisPool2) throws Exception {
+
+		if (InitialRunner.rmcmap.containsKey(point)) {
+
+			Date beginQuery = new Date(beginDate * 1000);
+			Date endQuery = new Date(endDate * 1000);
+
+			RMConfig rmc = InitialRunner.rmcmap.get(point);
+
+			Calendar cal = Calendar.getInstance();
+			cal.set(Calendar.HOUR_OF_DAY, 0);
+			cal.set(Calendar.MINUTE, 0);
+			cal.set(Calendar.SECOND, 0);
+			cal.set(Calendar.MILLISECOND, 0);
+
+			Date begin = cal.getTime();
+			cal.add(Calendar.DAY_OF_MONTH, 1);
+			Date end = cal.getTime();
+			// 当前日期
+			if (beginQuery.getTime() >= (begin.getTime()) && endQuery.getTime() <= (end.getTime())) {
+
+
+				relData(point,  ls, jedisPool2, beginQuery, rmc, cal);
+
+			} else if (beginQuery.getTime() < (begin.getTime()) && endQuery.getTime() <= (begin.getTime())) {
+
+				hisData(point,  ls, jedisPool2, beginQuery, endQuery, rmc, cal);
+			} else if (beginQuery.getTime() == (begin.getTime()) && endQuery.getTime() > (end.getTime())) {
+
+				relData(point,  ls, jedisPool2, beginQuery, rmc, cal);
+				
+			} else if (beginQuery.getTime() < (begin.getTime()) ) {
+				
+				realAndhistData(point,  ls, jedisPool2, beginQuery, endQuery, rmc, cal);
+			}
+
+			// mongoClient.close();
+		}
+
+
+	}
+
+	@SuppressWarnings("unchecked")
+	private void realAndhistData(String point, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal) throws Exception {
+
+		
+/*******************************************************************************************************/	
+		Map<Integer, Double> tempmap = new TreeMap<Integer, Double>(
+	                new Comparator<Integer>() {
+	                    public int compare(Integer obj1, Integer obj2) {
+	                        // 升序排序
+	                        return obj1.compareTo(obj2);
+	                    }
+	                });
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+		
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				tempmap.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+			// System.out.println(i + "___" + mongoCursor.next());
+			// i++;
+		}
+		
+/*******************************************************************************************************/		
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+		
+			if (StringUtils.isNotNull(hmap)) {
+				String str = hmap.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+					
+				}
+
+			}
+			
+			jedis.close();
+		}
+/*******************************************************************************************************/	
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+		
+			if (StringUtils.isNotNull(hmap)) {
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+				
+				Long begin = beginQuery.getTime() / 1000;
+					Long end = endQuery.getTime() / 1000;
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						
+						int key=Integer.valueOf(String.valueOf(m.get(po_key)));
+						
+						if(key>=begin && key<=end)
+						{
+							double value = Double.valueOf(String.valueOf(m.get(po_value)));
+							// System.out.println("S:"++"_V:"+m.get(po_value));
+							tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+						}
+
+					}
+					
+				}
+
+			}
+			
+			jedis.close();
+		}
+		
+		/*******************************************************************************************************/			
+		Set<Map.Entry<Integer, Double>> set = tempmap.entrySet();
+		for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+			Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+			PointData po = new PointData();
+			po.setEdnaId(point);
+//			System.out.println(entry.getKey() + "--->" + entry.getValue());
+			po.setPointTime(Long.valueOf(String.valueOf(entry.getKey())));
+			po.setPointValueInDouble(entry.getValue());
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	private void hisData(String point, List<PointData> ls,JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal) throws Exception {
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+		 Map<Integer, Double> map = new TreeMap<Integer, Double>(
+	                new Comparator<Integer>() {
+	                    public int compare(Integer obj1, Integer obj2) {
+	                        // 升序排序
+	                        return obj1.compareTo(obj2);
+	                    }
+	                });
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				map.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+			// System.out.println(i + "___" + mongoCursor.next());
+			// i++;
+		}
+
+		/*******************************************************************************************************/		
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+		
+			if (StringUtils.isNotNull(hmap)) {
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+				
+				Long begin = beginQuery.getTime() / 1000;
+					Long end = endQuery.getTime() / 1000;
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						
+						int key=Integer.valueOf(String.valueOf(m.get(po_key)));
+						
+						if(key>=begin && key<=end)
+						{
+							double value = Double.valueOf(String.valueOf(m.get(po_value)));
+							// System.out.println("S:"++"_V:"+m.get(po_value));
+							map.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+						}
+
+					}
+					
+				}
+
+			}
+			
+			jedis.close();
+		}
+		
+		/*******************************************************************************************************/
+
+		Set<Map.Entry<Integer, Double>> set = map.entrySet();
+		for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+			Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+			PointData po = new PointData();
+			po.setEdnaId(point);
+//			System.out.println(entry.getKey() + "--->" + entry.getValue());
+			po.setPointTime(Long.valueOf(String.valueOf(entry.getKey())));
+			po.setPointValueInDouble(entry.getValue());
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	private void relData(String point,  List<PointData> ls, JedisPool jedisPool2, Date beginQuery, RMConfig rmc, Calendar cal) {
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> map = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			//Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+		     Map<Integer, Double> tempmap = new TreeMap<Integer, Double>(
+		                new Comparator<Integer>() {
+		                    public int compare(Integer obj1, Integer obj2) {
+		                        // 升序排序
+		                        return obj1.compareTo(obj2);
+		                    }
+		                });
+			if (StringUtils.isNotNull(map)) {
+				String str = map.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+
+					
+					Set<Map.Entry<Integer, Double>> set = tempmap.entrySet();
+					for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+						Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+						PointData po = new PointData();
+						po.setEdnaId(point);
+//						System.out.println(entry.getKey() + "--->" + entry.getValue());
+						po.setPointTime(Long.valueOf(String.valueOf(entry.getKey())));
+						po.setPointValueInDouble(entry.getValue());
+					}
+				 
+				}
+
+			}
+			
+			jedis.close();
+		}
+	}
+}

+ 458 - 0
src/main/java/com/gyee/frame/util/mongodb/HistorySnapUtil.java

@@ -0,0 +1,458 @@
+package com.gyee.frame.util.mongodb;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.google.common.collect.Lists;
+import com.gyee.frame.common.spring.InitialRunner;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.StringUtils;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+
+import java.util.*;
+
+/**
+ */
+public class HistorySnapUtil {
+
+
+
+	private String mongodb_c = "C";
+	private String mongodb_db = "H";
+	private String mongodb_p = "K";
+	private String mongodb_ls = "M";
+	private String mongodb_key = "M.S";
+	private String mongodb_value = "M.V";
+	private String po_key = "S";
+	private String po_value = "V";
+
+
+	@SuppressWarnings({ "unused" })
+	public void findHistoryDatasSnap(String point, Long beginDate, Long endDate, Long count, Long pried, List<PointData> ls, JedisPool jedisPool2) throws Exception {
+
+		if (InitialRunner.rmcmap.containsKey(point)) {
+
+			Date beginQuery = new Date(beginDate * 1000);
+			Date endQuery = new Date(endDate * 1000);
+
+			RMConfig rmc = InitialRunner.rmcmap.get(point);
+
+			Calendar cal = Calendar.getInstance();
+			cal.set(Calendar.HOUR_OF_DAY, 0);
+			cal.set(Calendar.MINUTE, 0);
+			cal.set(Calendar.SECOND, 0);
+			cal.set(Calendar.MILLISECOND, 0);
+
+			Date begin = cal.getTime();
+			cal.add(Calendar.DAY_OF_MONTH, 1);
+			Date end = cal.getTime();
+			// 当前日期
+			if (beginQuery.getTime() >= (begin.getTime()) && endQuery.getTime() <= (end.getTime())) {
+
+				relData(point, count, pried, ls, jedisPool2, beginQuery, rmc, cal);
+
+			} else if (beginQuery.getTime() < (begin.getTime()) && endQuery.getTime() <= (begin.getTime())) {
+
+				hisData(point, count, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal);
+			} else if (beginQuery.getTime() == (begin.getTime()) && endQuery.getTime() > (end.getTime())) {
+
+				relData(point, count, pried, ls, jedisPool2, beginQuery, rmc, cal);
+
+			} else if (beginQuery.getTime() < (begin.getTime())) {
+
+				// realAndhistData(point, count, pried, ls, jedisPool2,
+				// beginQuery, endQuery, rmc, cal);
+				hisData(point, count, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal);
+			}
+
+			// mongoClient.close();
+		}
+
+	}
+
+	@SuppressWarnings("unchecked")
+	private void realAndhistData(String point, Long count, Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal) throws Exception {
+		// Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+		Map<Integer, Double> tempmap = new TreeMap<Integer, Double>(new Comparator<Integer>() {
+			public int compare(Integer obj1, Integer obj2) {
+				// 升序排序
+				return obj1.compareTo(obj2);
+			}
+		});
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				tempmap.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+
+		}
+
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			if (StringUtils.isNotNull(hmap)) {
+				String str = hmap.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+
+				}
+
+			}
+			jedis.close();
+		}
+
+		/*******************************************************************************************************/
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			if (StringUtils.isNotNull(hmap)) {
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+
+				Calendar c = Calendar.getInstance();
+				c.set(Calendar.HOUR_OF_DAY, 0);
+				c.set(Calendar.MINUTE, 0);
+				c.set(Calendar.SECOND, 0);
+				Long begin = c.getTime().getTime() / 1000;
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+
+						int key = Integer.valueOf(String.valueOf(m.get(po_key)));
+
+						if (key == begin) {
+							double value = Double.valueOf(String.valueOf(m.get(po_value)));
+							// System.out.println("S:"++"_V:"+m.get(po_value));
+							tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+
+							break;
+						}
+
+					}
+
+				}
+
+			}
+
+			jedis.close();
+		}
+
+
+		cal.setTime(beginQuery);
+
+		for (int i = 0; i < count + 1; i++) {
+			Long querydate = cal.getTime().getTime() / 1000;
+			PointData po = new PointData();
+			po.setEdnaId(point);
+			po.setPointTime(querydate);
+
+			if (tempmap.containsKey(querydate.intValue())) {
+
+				po.setPointValueInDouble(tempmap.get(querydate.intValue()));
+			} else {
+				int num = 0;
+				double tempvalue = 0.0;
+				Set<Map.Entry<Integer, Double>> set = tempmap.entrySet();
+				for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+					Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+
+					if (entry.getKey() > querydate.intValue()) {
+
+						break;
+					} else {
+						po.setPointValueInDouble(entry.getValue());
+					}
+
+				}
+			}
+			ls.add(po);
+			cal.add(Calendar.SECOND, pried.intValue());
+
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	private void hisData(String point, Long count, Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal) throws Exception {
+
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		Map<Integer, Double> map = new TreeMap<Integer, Double>(new Comparator<Integer>() {
+			public int compare(Integer obj1, Integer obj2) {
+				// 升序排序
+				return obj1.compareTo(obj2);
+			}
+		});
+
+
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lt", beginQuery.getTime() / 1000)));
+		query.put("$and", phoneList);
+
+		Document doc = collection.find(query).projection(fields).first();
+		if (StringUtils.isNotNull(doc)) {
+			List<Document> vos = (List<Document>) doc.get(mongodb_ls);
+			if (StringUtils.isNotNull(vos) && !vos.isEmpty()) {
+				Document dc = vos.get(vos.size() - 1);
+				map.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+		}
+
+		query = new BasicDBObject();
+		phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+		// Map<Integer, Double> map = new HashMap<Integer, Double>();
+
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				map.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+			// System.out.println(i + "___" + mongoCursor.next());
+			// i++;
+		}
+		/*******************************************************************************************************/
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			if (StringUtils.isNotNull(hmap)) {
+
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+
+
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+
+						int key = Integer.valueOf(String.valueOf(m.get(po_key)));
+
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+
+						map.put(key, value);
+
+					}
+
+				}
+
+				String str2 = hmap.get("1");
+				JSONArray array2 = JSONArray.parseArray(str2);
+
+				if (StringUtils.isNotNull(array2)) {
+					for (int i = 0; i < array2.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array2.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						map.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+				}
+
+			}
+
+			jedis.close();
+		}
+
+		/*******************************************************************************************************/
+		cal.setTime(beginQuery);
+
+		for (int i = 0; i < count + 1; i++) {
+			Long querydate = cal.getTime().getTime() / 1000;
+
+			PointData po = new PointData();
+			po.setEdnaId(point);
+			po.setPointTime(querydate);
+
+			if (map.containsKey(querydate.intValue())) {
+
+				po.setPointValueInDouble(map.get(querydate.intValue()));
+			} else {
+
+				Set<Map.Entry<Integer, Double>> set = map.entrySet();
+				for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+					Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+
+					if (entry.getKey() > querydate.intValue()) {
+
+						break;
+					} else {
+						po.setPointValueInDouble(entry.getValue());
+					}
+
+				}
+			}
+			ls.add(po);
+			cal.add(Calendar.SECOND, pried.intValue());
+
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	private void relData(String point, Long count, Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, RMConfig rmc, Calendar cal) {
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> map = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			// Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+			Map<Integer, Double> tempmap = new TreeMap<Integer, Double>(new Comparator<Integer>() {
+				public int compare(Integer obj1, Integer obj2) {
+					// 升序排序
+					return obj1.compareTo(obj2);
+				}
+			});
+			if (StringUtils.isNotNull(map)) {
+				String str = map.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+
+				String str2 = map.get("3");
+				JSONArray array2 = JSONArray.parseArray(str2);
+				if (StringUtils.isNotNull(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+
+					Calendar c = Calendar.getInstance();
+					c.set(Calendar.HOUR_OF_DAY, 0);
+					c.set(Calendar.MINUTE, 0);
+					c.set(Calendar.SECOND, 0);
+					Long begin = c.getTime().getTime() / 1000;
+					if (StringUtils.isNotNull(array2)) {
+						for (int i = 0; i < array2.size(); i++) {
+							Map<String, Object> m = (Map<String, Object>) array2.get(i);
+
+							int key = Integer.valueOf(String.valueOf(m.get(po_key)));
+
+							if (key == begin) {
+								double value = Double.valueOf(String.valueOf(m.get(po_value)));
+								// System.out.println("S:"++"_V:"+m.get(po_value));
+								tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+
+								break;
+							}
+
+						}
+
+					}
+					cal.setTime(beginQuery);
+
+					for (int i = 0; i < count + 1; i++) {
+						Long querydate = cal.getTime().getTime() / 1000;
+						PointData po = new PointData();
+						po.setEdnaId(point);
+						po.setPointTime(querydate);
+
+						if (tempmap.containsKey(querydate.intValue())) {
+
+							po.setPointValueInDouble(tempmap.get(querydate.intValue()));
+						} else {
+							int num = 0;
+							double tempvalue = 0.0;
+							Set<Map.Entry<Integer, Double>> set = tempmap.entrySet();
+							for (Iterator<Map.Entry<Integer, Double>> it = set.iterator(); it.hasNext();) {
+								Map.Entry<Integer, Double> entry = (Map.Entry<Integer, Double>) it.next();
+
+								if (entry.getKey() > querydate.intValue()) {
+
+									break;
+								} else {
+									po.setPointValueInDouble(entry.getValue());
+								}
+							}
+						}
+						ls.add(po);
+						cal.add(Calendar.SECOND, pried.intValue());
+					}
+				}
+
+			}
+
+			/*******************************************************************************************************/
+
+			jedis.close();
+		}
+	}
+
+}

+ 372 - 0
src/main/java/com/gyee/frame/util/mongodb/HistoryStatUtil.java

@@ -0,0 +1,372 @@
+package com.gyee.frame.util.mongodb;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.google.common.collect.Lists;
+import com.gyee.frame.common.conf.MongodbConfig;
+import com.gyee.frame.common.spring.InitialRunner;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.DateUtils;
+import com.gyee.frame.util.StringUtils;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+
+/**
+ */
+public class HistoryStatUtil {
+
+
+
+	private String mongodb_ip = MongodbConfig.mongodb_ip;
+	private int mongodb_port = Integer.valueOf(MongodbConfig.mongodb_port);
+	private String mongodb_c = "C";
+	private String mongodb_db = "H";
+	private String mongodb_p = "K";
+	private String mongodb_ls = "M";
+	private String mongodb_key = "M.S";
+	private String mongodb_value = "M.V";
+	private String po_key = "S";
+	private String po_value = "V";
+	// private Logger logger = Logger.getLogger(this.getClass().getName());
+
+	
+
+	@SuppressWarnings({ "unused" })
+	public void findHistoryDatasStat(String point, Long beginDate, Long endDate, Long pried, List<PointData> ls, JedisPool jedisPool2, int type) throws Exception {
+
+		if (InitialRunner.rmcmap.containsKey(point)) {
+
+			Date beginQuery = new Date(beginDate * 1000);
+			Date endQuery = new Date(endDate * 1000);
+
+			RMConfig rmc = InitialRunner.rmcmap.get(point);
+
+			Calendar cal = Calendar.getInstance();
+			cal.set(Calendar.HOUR_OF_DAY, 0);
+			cal.set(Calendar.MINUTE, 0);
+			cal.set(Calendar.SECOND, 0);
+			cal.set(Calendar.MILLISECOND, 0);
+
+			Date begin = cal.getTime();
+			cal.add(Calendar.DAY_OF_MONTH, 1);
+			Date end = cal.getTime();
+			// 当前日期
+			if (beginQuery.getTime() >= (begin.getTime()) && endQuery.getTime() <= (end.getTime())) {
+
+
+				relData(point, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal, type);
+
+			} else if (beginQuery.getTime() < (begin.getTime()) && endQuery.getTime() <= (begin.getTime())) {
+
+				hisData(point, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal, type);
+			} else if (beginQuery.getTime() == (begin.getTime()) && endQuery.getTime() > (end.getTime())) {
+
+				relData(point, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal, type);
+				
+//			} else if (beginQuery.getTime() < (begin.getTime()) && endQuery.getTime() >= (end.getTime())) {
+			} else if (beginQuery.getTime() < (begin.getTime()) ) {
+				
+				realAndhistData(point, pried, ls, jedisPool2, beginQuery, endQuery, rmc, cal, type);
+			}
+
+			// mongoClient.close();
+		}
+
+	}
+
+	@SuppressWarnings("unchecked")
+	private void realAndhistData(String point,  Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal, int type) throws Exception {
+		Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				tempmap.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+			// System.out.println(i + "___" + mongoCursor.next());
+			// i++;
+		}
+
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			if (StringUtils.isNotEmpty(hmap)) {
+				String str = hmap.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+				if (StringUtils.isNotEmpty(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+
+				}
+
+			}
+			jedis.close();
+		}
+		/*******************************************************************************************************/		
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+		
+			if (StringUtils.isNotEmpty(hmap)) {
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+				
+				Long begin = beginQuery.getTime() / 1000;
+					Long end = endQuery.getTime() / 1000;
+				if (StringUtils.isNotEmpty(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						
+						int key=Integer.valueOf(String.valueOf(m.get(po_key)));
+						
+						if(key>=begin && key<=end)
+						{
+							double value = Double.valueOf(String.valueOf(m.get(po_value)));
+							// System.out.println("S:"++"_V:"+m.get(po_value));
+							tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+						}
+
+					}
+					
+				}
+
+			}
+			
+			jedis.close();
+		}
+		
+		/*******************************************************************************************************/
+		setStatData(point, pried, ls, beginQuery, endQuery, cal, type, tempmap);
+	}
+
+	@SuppressWarnings("unchecked")
+	private void hisData(String point,  Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal, int type) throws Exception {
+		StringBuilder sdb = new StringBuilder();
+
+		int db = rmc.getMongodbindex();
+
+		sdb.append(mongodb_db).append(db);
+
+		// MongoClient mongoClient = new MongoClient(mongodb_ip,
+		// mongodb_port);// 创建客户端
+		MongoClient mongoClient = ApiMongoDb.getInstance();// 创建客户端
+		MongoDatabase mongoDatabase = mongoClient.getDatabase(String.valueOf(sdb));// 获得数据库名
+		StringBuilder sc = new StringBuilder();
+		sc.append(mongodb_c).append(rmc.getCollindex());
+		MongoCollection<Document> collection = mongoDatabase.getCollection(String.valueOf(sc));// 获得集合名字
+
+		BasicDBObject fields = new BasicDBObject();
+		fields.put("_id", 0);
+		fields.put(mongodb_key, 1);
+		fields.put(mongodb_value, 1);
+		BasicDBObject query = new BasicDBObject();
+		List<DBObject> phoneList = Lists.newArrayList();
+		phoneList.add(new BasicDBObject(mongodb_p, rmc.getUkey()));
+
+		Long time = beginQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$gte", time)));
+		time = endQuery.getTime() / 1000;
+		phoneList.add(new BasicDBObject(mongodb_key, new BasicDBObject("$lte", time)));
+		query.put("$and", phoneList);
+		FindIterable<Document> docs = collection.find(query).projection(fields);
+		Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+		MongoCursor<Document> mongoCursor = docs.iterator();
+		// int i = 0;
+		while (mongoCursor.hasNext()) {
+
+			List<Document> vos = (List<Document>) mongoCursor.next().get(mongodb_ls);
+			for (Document dc : vos) {
+				tempmap.put(dc.getInteger(po_key), dc.getDouble(po_value));
+			}
+			// System.out.println(i + "___" + mongoCursor.next());
+			// i++;
+		}
+		/*******************************************************************************************************/		
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> hmap = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+		
+			if (StringUtils.isNotEmpty(hmap)) {
+				String str = hmap.get("3");
+				JSONArray array = JSONArray.parseArray(str);
+				
+				Long begin = beginQuery.getTime() / 1000;
+					Long end = endQuery.getTime() / 1000;
+				if (StringUtils.isNotEmpty(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						
+						int key=Integer.valueOf(String.valueOf(m.get(po_key)));
+						
+						if(key>=begin && key<=end)
+						{
+							double value = Double.valueOf(String.valueOf(m.get(po_value)));
+							// System.out.println("S:"++"_V:"+m.get(po_value));
+							tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+						}
+
+					}
+					
+				}
+
+			}
+			
+			jedis.close();
+		}
+		
+		/*******************************************************************************************************/
+		setStatData(point, pried, ls, beginQuery, endQuery, cal, type, tempmap);
+
+	}
+
+	@SuppressWarnings("unchecked")
+	private void relData(String point, Long pried, List<PointData> ls, JedisPool jedisPool2, Date beginQuery, Date endQuery, RMConfig rmc, Calendar cal, int type) {
+		if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+			Jedis jedis = jedisPool2.getResource();
+			jedis.select(rmc.getMongodbindex());
+			Map<String, String> map = jedis.hgetAll(String.valueOf(rmc.getUkey()));
+
+			Map<Integer, Double> tempmap = new HashMap<Integer, Double>();
+			if (StringUtils.isNotEmpty(map)) {
+				String str = map.get("1");
+				JSONArray array = JSONArray.parseArray(str);
+				if (StringUtils.isNotEmpty(array)) {
+					for (int i = 0; i < array.size(); i++) {
+						Map<String, Object> m = (Map<String, Object>) array.get(i);
+						double value = Double.valueOf(String.valueOf(m.get(po_value)));
+						// System.out.println("S:"++"_V:"+m.get(po_value));
+						tempmap.put(Integer.valueOf(String.valueOf(m.get(po_key))), value);
+					}
+					setStatData(point, pried, ls, beginQuery, endQuery, cal, type, tempmap);
+				}
+
+			}
+			jedis.close();
+		}
+	}
+
+	private void setStatData(String point, Long pried, List<PointData> ls, Date beginQuery, Date endQuery, Calendar cal, int type, Map<Integer, Double> tempmap) {
+		cal.setTime(beginQuery);
+
+		int num = DateUtils.minutesDiff(beginQuery, endQuery);
+
+		int step = 0;
+		double total = 0;
+		double max = 0.0;
+		double min = 0.0;
+		num = num + 1;
+
+		for (int i = 0; i < num; i++) {
+
+			Long temp = cal.getTime().getTime() / 1000;
+
+			
+
+			if (tempmap.containsKey(temp.intValue())) {
+
+				double dtemp = tempmap.get(temp.intValue());
+
+				if (step == pried) {
+
+					PointData po = new PointData();
+					po.setEdnaId(point);
+					po.setPointTime(temp);
+					
+					switch (type) {
+					case 0:
+						po.setPointValueInDouble(max);
+						break;
+					case 1:
+						po.setPointValueInDouble(min);
+						break;
+					case 2:
+						total = new BigDecimal(total).divide(new BigDecimal(step), 2, RoundingMode.HALF_EVEN).doubleValue();
+						po.setPointValueInDouble(total);
+						break;
+					default:
+						break;
+					}
+					
+					ls.add(po);
+					total = 0;
+					step = 0;
+					max = dtemp;
+					min = dtemp;
+				}
+
+				if (i == 0) {
+					max = dtemp;
+					min = dtemp;
+				}
+
+				if (dtemp > max) {
+					max = dtemp;
+				} else if (dtemp < min) {
+					min = dtemp;
+				}
+
+				total = total + dtemp;
+				step++;
+
+			}
+
+			cal.add(Calendar.MINUTE, 1);
+
+		}
+	}
+}

+ 68 - 0
src/main/java/com/gyee/frame/util/mongodb/IMongodbUtil.java

@@ -0,0 +1,68 @@
+package com.gyee.frame.util.mongodb;
+
+
+import com.gyee.frame.model.custom.DNAStatVal;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.model.custom.WindPowerStationTestingPoint;
+import com.gyee.frame.model.custom.WindTurbineTestingPointAi;
+
+import java.util.List;
+import java.util.Map;
+
+
+
+public interface IMongodbUtil {
+    // 通过风场测点获得测点实时数据
+    public PointData getRealData(WindPowerStationTestingPoint point) throws Exception;
+
+    // 通过风场测点获得测点实时数据
+    public List<PointData> getHistoryDatasSnap(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried) throws Exception;
+
+    // 通过风场测点获得测点实时数据
+    public List<PointData> getHistoryDatasRaw(WindPowerStationTestingPoint point, Long beginDate, Long endDate) throws Exception;
+
+    // 通过风机测点获得测点实时数据
+    public PointData getRealData(WindTurbineTestingPointAi point) throws Exception;
+
+    // 通过风机测点获得测点实时数据
+    public List<PointData> getHistoryDatasSnap(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried) throws Exception;
+
+    // 通过风机测点获得测点实时数据
+    public List<PointData> getHistoryDatasRaw(WindTurbineTestingPointAi point, Long beginDate, Long endDate) throws Exception;
+
+    // 通过全局点名获得测点实时数据
+    public PointData getRealData(String pointid) throws Exception;
+ // 通过全局点名获得测点实时数据 读取多个点
+    public List<PointData> getRealData(String... pointids) throws Exception;
+    
+    public List<PointData> getRealData(List<String> pointids) throws Exception;
+    
+    public Map<String,Double> getRealDataMap(String... pointids) throws Exception;
+    
+    public Map<String,Double> getRealDataMap(List<String> pointids) throws Exception;
+
+    // 通过全局点名获得历史数据快照
+    public List<PointData> getHistoryDatasSnap(String pointid, Long beginDate, Long endDate, Long count, Long pried) throws Exception;
+
+    // 通过全局点名获得历史数据
+    public List<PointData> getHistoryDatasRaw(String pointid, Long beginDate, Long endDate) throws Exception;
+
+    /*
+     * //通过全局点名获得测点实时数据 public PointData getRealDataByTime(String pointid)
+     * throws Exception; //通过风场测点获得测点实时数据 public PointData
+     * getRealDataByTime(WindPowerStationTestingPoint point) throws Exception;
+     */
+    // 通过风机测点获得特殊数据
+    public List<PointData> getHistStat(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception;
+
+    // 通过场站测点获得特殊数据
+    public List<PointData> getHistStat(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception;
+
+    // 通过全局点名获得特殊数据
+    public List<PointData> getHistStat(String pointid, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception;
+
+    // 通过场站测点获得特殊数据
+    public DNAStatVal[] getHistStat(String point, Long beginDate, Long endDate, Integer pried) throws Exception;
+    //更新单点实时数据
+    public void updatePoint(PointData point) throws Exception;
+}

+ 363 - 0
src/main/java/com/gyee/frame/util/mongodb/JedisPoolUtil.java

@@ -0,0 +1,363 @@
+package com.gyee.frame.util.mongodb;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.frame.common.spring.InitialRunner;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.StringUtils;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.Pipeline;
+import redis.clients.jedis.Response;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * ClassName:JedisPool <br/>
+ *
+ * @author 石林
+ * @see
+ * @since JDK 1.8
+ */
+@Component
+public class JedisPoolUtil {
+
+    @Resource
+    @Qualifier("ss_redis")
+    private JedisPool jedisPool;// 非切片连接池
+
+    private final Integer ARR_NUM = 18;
+
+    /**
+     * 释放jedis资源
+     *
+     * @param jedis
+     */
+    public static void returnResource(final Jedis jedis) {
+        if (jedis != null) {
+            jedis.close();
+        }
+    }
+
+
+
+    public PointData getRealData(String code) throws IOException {
+
+        PointData po = new PointData();
+
+
+
+        Map<String, Response<String>> resmap = new HashMap<String, Response<String>>();
+
+        Jedis jedis = jedisPool.getResource();
+
+        Pipeline pipelined = jedis.pipelined();
+
+
+        if(InitialRunner.rmcmap.containsKey(code))
+        {
+            RMConfig rmc = InitialRunner.rmcmap.get(code);
+
+            pipelined.select(rmc.getRedisindex());
+
+            resmap.put(code, pipelined.get(code));
+
+            pipelined.sync();
+
+            String result = resmap.get(code).get();
+
+
+            setPointData(code, rmc, po, result);
+        }else
+        {
+
+            pipelined.select(ARR_NUM);
+
+            resmap.put(code, pipelined.get(code));
+
+            pipelined.sync();
+
+            String result = resmap.get(code).get();
+
+            if(StringUtils.isNotNull(result))
+            {
+                setPointData(code,  po, result);
+            }
+
+        }
+
+        returnResource(jedis);
+
+        return po;
+
+
+    }
+
+    @SuppressWarnings("unchecked")
+    private void setPointData(String code, RMConfig rmc, PointData po, String result) {
+        Map<Object, Object> json = (Map<Object, Object>) JSONObject.parse(result);
+
+        po.setEdnaId(code);
+
+        for (Object map : json.entrySet()) {
+
+            Map.Entry<Object, Object> tempmap = (Map.Entry<Object, Object>) map;
+            Long time = Long.valueOf(String.valueOf(tempmap.getKey()));
+
+            Double value = Double.valueOf(String.valueOf(tempmap.getValue()));
+            po.setPointValueInDouble(value);
+            po.setPointTime(time * 1000);
+        }
+    }
+
+    private void setPointData(String code, PointData po, String result) {
+        Map<Object, Object> json = (Map<Object, Object>) JSONObject.parse(result);
+
+        po.setEdnaId(code);
+
+        for (Object map : json.entrySet()) {
+
+            Map.Entry<Object, Object> tempmap = (Map.Entry<Object, Object>) map;
+            Long time = Long.valueOf(String.valueOf(tempmap.getKey()));
+
+            Double value = Double.valueOf(String.valueOf(tempmap.getValue()));
+            po.setPointValueInDouble(value);
+            po.setPointTime(time * 1000);
+        }
+    }
+
+    public List<PointData> getRealData(String... key) throws IOException {
+
+        List<PointData> ls = new ArrayList<PointData>();
+
+        if (StringUtils.isNotNull(key) && key.length > 0) {
+
+
+            Map<String, Response<String>> resmap = new LinkedHashMap<String, Response<String>>();
+            Jedis jedis = jedisPool.getResource();
+
+            Pipeline pipelined = jedis.pipelined();
+            for (String code : key) {
+
+                if (InitialRunner.rmcmap.containsKey(code)) {
+
+                    RMConfig rmc = InitialRunner.rmcmap.get(code);
+
+                    pipelined.select(rmc.getRedisindex());
+
+                    resmap.put(code, pipelined.get(code));
+
+                }else
+                {
+
+                    pipelined.select(ARR_NUM);
+
+                    resmap.put(code, pipelined.get(code));
+
+                }
+
+            }
+            pipelined.sync();
+            pipelined.close();
+            for (String code : resmap.keySet()) {
+
+                String result = resmap.get(code).get();
+                if (result != null && result.length() > 0) {
+                    PointData po = new PointData();
+                    setPointData(code, po, result);
+                    ls.add(po);
+                }
+            }
+
+            returnResource(jedis);
+        }
+
+        return ls;
+    }
+
+    public List<PointData> getRealData(List<String> key) throws IOException {
+
+        List<PointData> ls = new ArrayList<PointData>();
+
+        if (StringUtils.isNotNull(key) && key.size() > 0) {
+            Map<String, Response<String>> resmap = new LinkedHashMap<String, Response<String>>();
+            Jedis jedis = jedisPool.getResource();
+
+            Pipeline pipelined = jedis.pipelined();
+            for (String code : key) {
+
+                if (InitialRunner.rmcmap.containsKey(code)) {
+
+                    RMConfig rmc = InitialRunner.rmcmap.get(code);
+
+                    pipelined.select(rmc.getRedisindex());
+
+                    resmap.put(code, pipelined.get(code));
+
+                }else
+                {
+
+                    pipelined.select(ARR_NUM);
+
+                    resmap.put(code, pipelined.get(code));
+
+                }
+
+            }
+            pipelined.sync();
+            pipelined.close();
+            for (String code : resmap.keySet()) {
+                String result = resmap.get(code).get();
+                if (result != null && result.length() > 0) {
+                    PointData po = new PointData();
+                    setPointData(code, po, result);
+                    ls.add(po);
+                }
+            }
+            returnResource(jedis);
+        }
+
+        return ls;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<String, Double> getRealDataMap(String... key) throws IOException {
+
+        Map<String, Double> map = new HashMap<String, Double>();
+
+        if (StringUtils.isNotNull(key) && key.length > 0) {
+
+            Map<String, Response<String>> resmap = new LinkedHashMap<String, Response<String>>();
+            Jedis jedis = jedisPool.getResource();
+
+            Pipeline pipelined = jedis.pipelined();
+            for (String code : key) {
+
+                if (InitialRunner.rmcmap.containsKey(code)) {
+
+                    RMConfig rmc = InitialRunner.rmcmap.get(code);
+
+                    pipelined.select(rmc.getRedisindex());
+
+                    resmap.put(code, pipelined.get(code));
+
+                }else
+                {
+
+                    pipelined.select(ARR_NUM);
+
+                    resmap.put(code, pipelined.get(code));
+
+                }
+
+            }
+            pipelined.sync();
+            pipelined.close();
+
+            for (String code : resmap.keySet()) {
+                String result = resmap.get(code).get();
+                if (result != null && result.length() > 0) {
+                    Map<Object, Object> json = (Map<Object, Object>) JSONObject.parse(result);
+
+                    Double value = 0.0;
+                    for (Object jsonmap : json.entrySet()) {
+
+                        Map.Entry<Object, Object> tempmap = (Map.Entry<Object, Object>) jsonmap;
+
+                        value = Double.valueOf(String.valueOf(tempmap.getValue()));
+
+                    }
+                    map.put(code, value);
+                }
+            }
+
+            returnResource(jedis);
+        }
+
+        return map;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<String, Double> getRealDataMap(List<String> key) throws IOException {
+
+        Map<String, Double> map = new HashMap<String, Double>();
+
+        if (StringUtils.isNotNull(key) && !key.isEmpty()) {
+
+            Map<String, Response<String>> resmap = new HashMap<String, Response<String>>();
+            Jedis jedis = jedisPool.getResource();
+
+            Pipeline pipelined = jedis.pipelined();
+            for (String code : key) {
+
+                if (InitialRunner.rmcmap.containsKey(code)) {
+
+                    RMConfig rmc = InitialRunner.rmcmap.get(code);
+
+                    pipelined.select(rmc.getRedisindex());
+
+                    resmap.put(code, pipelined.get(code));
+
+                }else
+                {
+
+                    pipelined.select(ARR_NUM);
+
+                    resmap.put(code, pipelined.get(code));
+
+                }
+
+            }
+            pipelined.sync();
+            pipelined.close();
+
+            for (String code : resmap.keySet()) {
+                String result = resmap.get(code).get();
+                if (result != null && result.length() > 0) {
+                    Map<Object, Object> json = (Map<Object, Object>) JSONObject.parse(result);
+
+                    Double value = 0.0;
+                    for (Object jsonmap : json.entrySet()) {
+
+                        Map.Entry<Object, Object> tempmap = (Map.Entry<Object, Object>) jsonmap;
+
+                        value = Double.valueOf(String.valueOf(tempmap.getValue()));
+
+                    }
+                    map.put(code, value);
+                }
+            }
+
+            returnResource(jedis);
+        }
+
+        return map;
+    }
+
+
+    public Object[] readKeyArray(String key) {
+
+        // 验证
+        Jedis jedis = jedisPool.getResource();
+        jedis.select(0);
+        String result = jedis.get(key);
+
+        JSONArray array = JSONArray.parseArray(result);
+
+        Object[] arr = (Object[]) array.toArray();
+
+        returnResource(jedis);
+
+        return arr;
+    }
+
+
+    public JedisPool getJedisPool() {
+        return jedisPool;
+    }
+}

+ 547 - 0
src/main/java/com/gyee/frame/util/mongodb/MongoDbUtil.java

@@ -0,0 +1,547 @@
+package com.gyee.frame.util.mongodb;
+
+import com.gyee.frame.model.custom.*;
+import com.gyee.frame.util.StringUtils;
+import com.mongodb.BasicDBObject;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+import redis.clients.jedis.JedisPool;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ */
+
+@Component
+public class MongoDbUtil {
+	private static Logger logger = LoggerFactory.getLogger(MongoDbUtil.class);
+	private String po_key = "S";
+	private String po_value = "V";
+
+	@Resource
+	@Qualifier("ls_redis")
+	private JedisPool jedisPool;
+
+
+	public List<PointData> getHistoryDatasSnap(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+
+//		long startStamp = System.currentTimeMillis();
+//		Date startDate = DateUtils.parseLongToDate(startStamp);
+//		System.out.println("开始执行任务,任务开始时间:" + DateUtils.toDate(startDate));
+
+		List<PointData> ls = new ArrayList<PointData>();
+		HistorySnapUtil snap=new HistorySnapUtil();
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getCode()) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+			snap.findHistoryDatasSnap(point.getCode(), beginDate,  endDate, count, pried, ls,jedisPool);
+
+		}
+
+//		long cost = System.currentTimeMillis() - startStamp;
+//		System.out.println("任务执行结束,耗时:" + cost / 1000 + "秒!........");
+
+		return ls;
+	}
+
+	public List<PointData> getHistoryDatasSnap(String pointid, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		HistorySnapUtil snap=new HistorySnapUtil();
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(pointid) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+
+			snap.findHistoryDatasSnap(pointid, beginDate,  endDate, count, pried, ls,jedisPool);
+
+		}
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public List<PointData> getHistoryDatasSnap(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		HistorySnapUtil snap=new HistorySnapUtil();
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getId()) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+		//	findHistoryDatasSnap(point.getId(), beginDate, count, pried, ls);
+			snap.findHistoryDatasSnap(point.getId(), beginDate,  endDate, count, pried, ls,jedisPool);
+		}
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	
+
+
+
+
+	private DNAStatVal[] findHistoryDatasStat(String point, Long beginDate, Long count, Long pried) throws Exception {
+
+		DNAStatVal[] statResult = null;
+		
+
+		return statResult;
+	}
+
+	private void setDnaStatValue(DNAStatVal po, int type, String point, Object[] obj, MongoCollection<Document> collection, long begintemp, int i, Document doc) {
+		BasicDBObject query;
+
+		if (StringUtils.isNotNull(doc)) {
+
+			setDNAStatVal(point, obj, po, doc, type);
+
+			logger.debug(i + "__时间:" + begintemp + "__数值:" + doc.getDouble(po_value));
+		} else if (StringUtils.isNotEmpty(doc)) {
+			query = new BasicDBObject();
+			query.put(po_key, new BasicDBObject("$lte", begintemp));
+			doc = collection.find(query).first();
+			if (StringUtils.isNotNull(doc)) {
+				setDNAStatVal(point, obj, po, doc, type);
+				logger.debug("补充记录" + i + "__时间:" + begintemp + "__数值:" + doc.getDouble(po_value));
+			} else {
+				switch (type) {
+				case 0:
+					po.avg.Time = Integer.valueOf(String.valueOf(begintemp));
+					po.avg.DValue = 0.0;
+					break;
+				case 1:
+					po.max.Time = Integer.valueOf(String.valueOf(begintemp));
+					po.max.DValue = 0.0;
+					break;
+				case 2:
+					po.min.Time = Integer.valueOf(String.valueOf(begintemp));
+					po.min.DValue = 0.0;
+					break;
+				default:
+					break;
+				}
+
+				logger.debug("缺失" + i + "__时间:" + begintemp + "__数值:" + 0);
+			}
+		}
+
+	}
+
+	public List<PointData> getHistStat(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getCode()) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+			HistoryStatUtil stat=new HistoryStatUtil();
+			stat.findHistoryDatasStat(point.getId(), beginDate, endDate, pried, ls, jedisPool, type);
+
+
+		}
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public DNAStatVal[] getHistStat(String point, Long beginDate, Long endDate, Integer pried) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		DNAStatVal[] statResult = null;
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(pried)) {
+
+			long total = endDate - beginDate;
+			long temp = Long.valueOf(pried);
+			long count = 0;
+			if (temp != 0) {
+				count = total / temp;
+			}
+			statResult = findHistoryDatasStat(point, beginDate, count, temp);
+
+		}
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		// // String id = point.substring(point.indexOf(".") + 1).replace(".",
+		// // "_");
+		// String id = point;
+		// DNAStatVal[] statResult = null;
+		//
+		// try {
+		// statResult = entry.getHistStat(id, beginDate.intValue(),
+		// endDate.intValue(), pried.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + id);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return statResult;
+
+	}
+
+	public List<PointData> getHistStat(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getCode()) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+			HistoryStatUtil stat=new HistoryStatUtil();
+			stat.findHistoryDatasStat(point.getCode(), beginDate, endDate, pried, ls, jedisPool, type);
+		}
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		// // String id = point.getCode().substring(point.getCode().indexOf(".")
+		// +
+		// // 1).replace(".", "_");
+		// String id = point.getCode();
+		// DNAStatVal[] statResult = null;
+		//
+		// try {
+		// statResult = entry.getHistStat(id, beginDate.intValue(),
+		// endDate.intValue(), pried.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + id);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+		// List<PointData> ls = new ArrayList<PointData>();
+		// if (statResult.length > 0) {
+		// for (int i = 0; i < statResult.length; i++) {
+		// PointData po = new PointData();
+		// switch (type) {
+		// case 0:// 最大值
+		// po.setPointTime(Long.valueOf(statResult[i].max.Time));
+		// po.setPointValueInDouble(statResult[i].max.DValue);
+		// break;
+		// case 1:// 最小值
+		// po.setPointTime(Long.valueOf(statResult[i].min.Time));
+		// po.setPointValueInDouble(statResult[i].min.DValue);
+		// break;
+		// case 2:// 平均值
+		// po.setPointTime(Long.valueOf(statResult[i].avg.Time));
+		// po.setPointValueInDouble(statResult[i].avg.DValue);
+		// break;
+		// default:
+		// break;
+		// }
+		//
+		// ls.add(po);
+		// }
+		//
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public List<PointData> getHistStat(String pointid, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(pointid) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate) && StringUtils.isNotNull(count) && StringUtils.isNotNull(pried)) {
+			HistoryStatUtil stat=new HistoryStatUtil();
+			stat.findHistoryDatasStat(pointid, beginDate, endDate, pried, ls, jedisPool, type);
+
+		}
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		//
+		// DNAStatVal[] statResult = null;
+		//
+		// try {
+		// statResult = entry.getHistStat(pointid, beginDate.intValue(),
+		// endDate.intValue(), pried.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + pointid);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+		// List<PointData> ls = new ArrayList<PointData>();
+		// if (statResult.length > 0) {
+		// for (int i = 0; i < statResult.length; i++) {
+		// PointData po = new PointData();
+		// switch (type) {
+		// case 0:// 最大值
+		// po.setPointTime(Long.valueOf(statResult[i].max.Time));
+		// po.setPointValueInDouble(statResult[i].max.DValue);
+		// break;
+		// case 1:// 最小值
+		// po.setPointTime(Long.valueOf(statResult[i].min.Time));
+		// po.setPointValueInDouble(statResult[i].min.DValue);
+		// break;
+		// case 2:// 平均值
+		// po.setPointTime(Long.valueOf(statResult[i].avg.Time));
+		// po.setPointValueInDouble(statResult[i].avg.DValue);
+		// break;
+		// default:
+		// break;
+		// }
+		//
+		// ls.add(po);
+		// }
+		//
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public List<PointData> getHistoryDatasRaw(WindTurbineTestingPointAi point, Long beginDate, Long endDate) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		List<PointData> ls = new ArrayList<PointData>();
+
+		HistoryDatasRawUtil raw=new HistoryDatasRawUtil();
+		raw.findHistoryDatasRaw(point.getId(), beginDate, endDate, ls, jedisPool);
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		// // String id = point.getId().substring(point.getId().indexOf(".") +
+		// // 1).replace(".", "_");
+		// String id = point.getId();
+		//
+		// DNAVal[] statResult = null;
+		// try {
+		// statResult = entry.getHistRaw(id, beginDate.intValue(),
+		// endDate.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + id);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+		// List<PointData> ls = new ArrayList<PointData>();
+		// if (statResult.length > 0) {
+		// for (int i = 0; i < statResult.length; i++) {
+		// PointData po = new PointData();
+		// po.setPointTime(Long.valueOf(statResult[i].Time));
+		// po.setPointValueInDouble(statResult[i].DValue);
+		// ls.add(po);
+		// }
+		//
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public List<PointData> getHistoryDatasRaw(WindPowerStationTestingPoint point, Long beginDate, Long endDate) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getCode()) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate)) {
+			HistoryDatasRawUtil raw=new HistoryDatasRawUtil();
+			raw.findHistoryDatasRaw(point.getCode(), beginDate, endDate, ls, jedisPool);
+
+		}
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		// // String id = point.getCode().substring(point.getCode().indexOf(".")
+		// +
+		// // 1).replace(".", "_");
+		// String id = point.getCode();
+		//
+		// DNAVal[] statResult = null;
+		// try {
+		// statResult = entry.getHistRaw(id, beginDate.intValue(),
+		// endDate.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + id);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+		// List<PointData> ls = new ArrayList<PointData>();
+		// if (statResult.length > 0) {
+		// for (int i = 0; i < statResult.length; i++) {
+		// PointData po = new PointData();
+		// po.setPointTime(Long.valueOf(statResult[i].Time));
+		// po.setPointValueInDouble(statResult[i].DValue);
+		// ls.add(po);
+		// }
+		//
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	public List<PointData> getHistoryDatasRaw(String pointid, Long beginDate, Long endDate) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+		List<PointData> ls = new ArrayList<PointData>();
+
+		if (StringUtils.isNotNull(pointid) && StringUtils.isNotNull(beginDate) && StringUtils.isNotNull(endDate)) {
+			HistoryDatasRawUtil raw=new HistoryDatasRawUtil();
+			raw.findHistoryDatasRaw(pointid, beginDate, endDate, ls, jedisPool);
+
+		}
+
+		// ApiEntry entry = ApiEdos.getInstance();
+		//
+		// // DNAVal[] statResult = entry.getHistRaw(pointid,
+		// beginDate.intValue(),
+		// // endDate.intValue());
+		// DNAVal[] statResult = null;
+		// try {
+		// statResult = entry.getHistRaw(pointid, beginDate.intValue(),
+		// endDate.intValue());
+		// } catch (Exception e) {
+		// logger.info("测点编号" + pointid);
+		// logger.info(e.getMessage());
+		// long endStamp = System.currentTimeMillis();
+		// long cost = endStamp - startStamp;
+		// logger.info("==================结束时刻: " +
+		// DateUtils.parseLongToDate(endStamp));
+		// logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		// throw e;
+		// }
+		// List<PointData> ls = new ArrayList<PointData>();
+		// if (statResult.length > 0) {
+		// for (int i = 0; i < statResult.length; i++) {
+		// PointData po = new PointData();
+		// po.setPointTime(Long.valueOf(statResult[i].Time));
+		// po.setPointValueInDouble(statResult[i].DValue);
+		// ls.add(po);
+		// }
+		//
+		// }
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+		return ls;
+	}
+
+	// private static List<DBObject> getMobileQuery(Date beginDate, Date
+	// endDate) {
+	// List<DBObject> phoneList = Lists.newArrayList();
+	// phoneList.add(new BasicDBObject(po_key, new BasicDBObject("$gt",
+	// beginDate.getTime() / 1000)));
+	// phoneList.add(new BasicDBObject(po_key, new BasicDBObject("$lt",
+	// endDate.getTime() / 1000)));
+	// return phoneList;
+	// }
+
+	private void setPointData(String code, Object[] obj, PointData po, Document doc) {
+
+		po.setEdnaId(code);
+
+		Long time = Long.valueOf(doc.getString(po_key));
+
+		int type = (Integer) obj[2];
+		if (type == 0) {
+			Boolean value = Boolean.valueOf(doc.getString(po_value));
+			if (value) {
+				po.setPointValueInDouble(1);
+			} else {
+				po.setPointValueInDouble(0);
+			}
+
+		} else {
+			Double value = Double.valueOf(doc.getString(po_value));
+			po.setPointValueInDouble(value);
+		}
+
+		po.setPointTime(time * 1000);
+
+	}
+
+	private void setDNAStatVal(String code, Object[] obj, DNAStatVal po, Document doc, int dtype) {
+
+		DNAVal val = null;
+		switch (dtype) {
+		case 0:
+			val = po.avg;
+			break;
+		case 1:
+			val = po.max;
+			break;
+		case 2:
+			val = po.min;
+			break;
+		default:
+			break;
+		}
+
+		// po..setEdnaId(code);
+		Integer time = Integer.valueOf(doc.getString(po_key));
+		int type = (Integer) obj[2];
+		if (type == 0) {
+			Boolean value = Boolean.valueOf(doc.getString(po_value));
+			if (value) {
+				val.DValue = 1;
+
+			} else {
+				val.DValue = 0;
+			}
+
+		} else {
+			Double value = Double.valueOf(doc.getString(po_value));
+			val.DValue = value;
+		}
+
+		val.Time = time;
+
+	}
+
+	public void updatePoint(PointData point,JedisPool jedisPool_ss) throws Exception {
+
+		UpdateDataUtil ud=new UpdateDataUtil();
+		ud.updateData(point,jedisPool_ss, jedisPool);
+		
+
+	}
+
+}

+ 314 - 0
src/main/java/com/gyee/frame/util/mongodb/MongodbUtilImpl.java

@@ -0,0 +1,314 @@
+package com.gyee.frame.util.mongodb;
+
+
+import com.gyee.frame.common.spring.SpringUtils;
+import com.gyee.frame.model.custom.DNAStatVal;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.model.custom.WindPowerStationTestingPoint;
+import com.gyee.frame.model.custom.WindTurbineTestingPointAi;
+import com.gyee.frame.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+public class MongodbUtilImpl implements IMongodbUtil {
+
+
+    private JedisPoolUtil jedisPoolUtil= SpringUtils.getBean(JedisPoolUtil.class);
+    private MongoDbUtil mdb = SpringUtils.getBean(MongoDbUtil.class);
+    private static Logger logger = LoggerFactory.getLogger(MongoDbUtil.class);
+
+    public PointData getRealData(WindPowerStationTestingPoint point) throws Exception {
+
+        PointData po = jedisPoolUtil.getRealData(point.getCode());
+        return po;
+    }
+
+    public List<PointData> getHistoryDatasSnap(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistoryDatasSnap(point, beginDate, endDate, count, pried);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public List<PointData> getHistoryDatasSnap(String pointid, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistoryDatasSnap(pointid, beginDate, endDate, count, pried);
+
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public List<PointData> getHistStat(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistStat(point, beginDate, endDate, count, pried, type);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public DNAStatVal[] getHistStat(String point, Long beginDate, Long endDate, Integer pried) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        DNAStatVal[] statResult = mdb.getHistStat(point, beginDate, endDate, pried);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return statResult;
+
+    }
+
+    public List<PointData> getHistStat(WindPowerStationTestingPoint point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistStat(point, beginDate, endDate, count, pried, type);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public List<PointData> getHistStat(String pointid, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistStat(pointid, beginDate, endDate, count, pried, type);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public PointData getRealData1(WindTurbineTestingPointAi point) throws Exception {
+//		long startStamp = System.currentTimeMillis();
+//		logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        PointData po = jedisPoolUtil.getRealData(point.getId());
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return po;
+    }
+
+    public PointData getRealData(WindTurbineTestingPointAi point) throws Exception {
+        // long startStamp = System.currentTimeMillis();
+        // logger.info("==================开始时刻: " +
+        // DateUtils.parseLongToDate(startStamp));
+
+        PointData po = jedisPoolUtil.getRealData(point.getId());
+
+        // long endStamp = System.currentTimeMillis();
+        // long cost = endStamp - startStamp;
+        // logger.info("==================结束时刻: " +
+        // DateUtils.parseLongToDate(endStamp));
+        // logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return po;
+    }
+
+    public List<PointData> getHistoryDatasSnap(WindTurbineTestingPointAi point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+
+        List<PointData> ls = mdb.getHistoryDatasSnap(point, beginDate, endDate, count, pried);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public PointData getRealData1(String pointid) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        PointData po = jedisPoolUtil.getRealData(pointid);
+
+        // long endStamp = System.currentTimeMillis();
+        // long cost = endStamp - startStamp;
+        // logger.info("==================结束时刻: " +
+        // DateUtils.parseLongToDate(endStamp));
+        // logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return po;
+    }
+
+    public PointData getRealData(String pointid) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        PointData po = jedisPoolUtil.getRealData(pointid);
+
+        // long endStamp = System.currentTimeMillis();
+        // long cost = endStamp - startStamp;
+        // logger.info("==================结束时刻: " +
+        // DateUtils.parseLongToDate(endStamp));
+        // logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return po;
+
+    }
+
+    /**
+     * 一次读取多个点
+     *
+     * @param pointids
+     * @return
+     * @throws Exception
+     */
+    public List<PointData> getRealData(String... pointids) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        List<PointData> list = jedisPoolUtil.getRealData(pointids);
+
+        if (StringUtils.isEmpty(list)) {
+            list = new ArrayList<PointData>();
+        }
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return list;
+    }
+
+    public List<PointData> getRealData(List<String> pointids) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        List<PointData> list = jedisPoolUtil.getRealData(pointids);
+
+        if (StringUtils.isEmpty(list)) {
+            list = new ArrayList<PointData>();
+        }
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return list;
+    }
+
+    /**
+     * 一次读取多个点
+     *
+     * @param pointids
+     * @return
+     * @throws Exception
+     */
+    public Map<String, Double> getRealDataMap(String... pointids) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        Map<String, Double> map = jedisPoolUtil.getRealDataMap(pointids);
+
+        if (StringUtils.isEmpty(map)) {
+            map = new HashMap<String, Double>();
+        }
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return map;
+    }
+
+
+    public Map<String, Double> getRealDataMap(List<String> pointids) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        Map<String, Double> map = jedisPoolUtil.getRealDataMap(pointids);
+
+        if (StringUtils.isEmpty(map)) {
+            map = new HashMap<String, Double>();
+        }
+
+//		long endStamp = System.currentTimeMillis();
+//		long cost = endStamp - startStamp;
+//		logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//		logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+
+        return map;
+    }
+
+    public List<PointData> getHistoryDatasRaw(WindTurbineTestingPointAi point, Long beginDate, Long endDate) throws Exception {
+        //        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        List<PointData> ls = mdb.getHistoryDatasRaw(point, beginDate, endDate);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public List<PointData> getHistoryDatasRaw(WindPowerStationTestingPoint point, Long beginDate, Long endDate) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        List<PointData> ls = mdb.getHistoryDatasRaw(point, beginDate, endDate);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    public List<PointData> getHistoryDatasRaw(String pointid, Long beginDate, Long endDate) throws Exception {
+//        long startStamp = System.currentTimeMillis();
+//        logger.info("==================开始时刻: " + DateUtils.parseLongToDate(startStamp));
+        List<PointData> ls = mdb.getHistoryDatasRaw(pointid, beginDate, endDate);
+
+//        long endStamp = System.currentTimeMillis();
+//        long cost = endStamp - startStamp;
+//        logger.info("==================结束时刻: " + DateUtils.parseLongToDate(endStamp));
+//        logger.info("调度程执行结束,耗时:" + cost / 1000 + "秒!........");
+        return ls;
+    }
+
+    /**
+     * 更新单点实时数据
+     *
+     * @return
+     * @throws Exception
+     */
+    public void updatePoint(PointData point) throws Exception {
+
+        mdb.updatePoint(point, jedisPoolUtil.getJedisPool());
+    }
+
+
+}

+ 110 - 0
src/main/java/com/gyee/frame/util/mongodb/UpdateDataUtil.java

@@ -0,0 +1,110 @@
+package com.gyee.frame.util.mongodb;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.gyee.frame.common.spring.InitialRunner;
+import com.gyee.frame.model.auto.RMConfig;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.StringUtils;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ */
+public class UpdateDataUtil {
+
+
+
+	private String po_key = "S";
+
+	// private Logger logger = Logger.getLogger(this.getClass().getName());
+
+	
+
+
+	@SuppressWarnings("unchecked")
+	public void updateData(PointData point, JedisPool jedisPool_ss, JedisPool jedisPool_db) throws Exception {
+
+		if (StringUtils.isNotNull(point) && StringUtils.isNotNull(point.getEdnaId()) && StringUtils.isNotNull(point.getPointTime()) && StringUtils.isNotNull(point.getPointValueInDouble())) {
+			
+			if ( InitialRunner.rmcmap.containsKey(point.getEdnaId())) {
+				
+				Date queryDate = new Date(point.getPointTime() * 1000);
+				
+				RMConfig rmc = InitialRunner.rmcmap.get(point.getEdnaId());
+
+				Calendar cal = Calendar.getInstance();
+				cal.set(Calendar.HOUR_OF_DAY, 0);
+				cal.set(Calendar.MINUTE, 0);
+				cal.set(Calendar.SECOND, 0);
+				cal.set(Calendar.MILLISECOND, 0);
+
+				Date begin = cal.getTime();
+				cal.add(Calendar.DAY_OF_MONTH, 1);
+				Date end = cal.getTime();
+				// 当前日期
+				if (queryDate.getTime() >= (begin.getTime()) && queryDate.getTime() <= (end.getTime())) {
+
+					Map<String, Object> rm =new HashMap<String, Object>();
+					rm.put(String.valueOf(point.getPointTime()),point.getPointValueInDouble() );
+					
+					Jedis rmjedis =jedisPool_ss.getResource();
+					rmjedis.select(rmc.getRedisindex());
+					rmjedis.set(point.getEdnaId(), JSON.toJSONString(rm));
+					rmjedis.close();
+					if (StringUtils.isNotNull(rmc.getUkey()) && StringUtils.isNotNull(rmc.getMongodbindex())) {
+						Jedis jedis = jedisPool_db.getResource();
+						jedis.select(rmc.getMongodbindex());
+						String str = jedis.hget(String.valueOf(rmc.getUkey()),"1");
+						JSONArray array = JSONArray.parseArray(str);
+						
+						int state=0;
+						
+							for (int i = 0; i < array.size(); i++) {
+								Map<String, Object> m = (Map<String, Object>) array.get(i);
+														
+								int key=Integer.valueOf(String.valueOf(m.get(po_key)));
+								if(key==point.getPointTime().intValue())
+								{
+									m.put("V",point.getPointValueInDouble());
+									state++;
+								}
+							
+							}
+							
+							if(state==0)
+							{
+								Map<String, Object> m =new HashMap<String, Object>();
+								m.put("V",point.getPointValueInDouble() );
+								m.put("S",point.getPointTime().intValue() );
+								
+								array.add(m);
+							}
+			
+						jedis.hset(String.valueOf(rmc.getUkey()),"1", JSON.toJSONString(array));
+						
+						jedis.close();
+					}
+
+				} else  {
+
+					
+				} 
+
+			}
+
+			
+			// mongoClient.close();
+		}
+
+	}
+
+	
+
+	
+}