Browse Source

golden数据导出功能

chenminghua 3 years ago
parent
commit
8753c3bb42

+ 14 - 1
pom.xml

@@ -117,7 +117,7 @@
 		<dependency>
 			<groupId>com.taosdata.jdbc</groupId>
 			<artifactId>taos-jdbcdriver</artifactId>
-			<version>2.0.20</version>
+			<version>2.0.30</version>
 		</dependency>
 		<!-- mysql驱动8.0
 		 <dependency> 
@@ -353,6 +353,19 @@
 			<version>1.6.1</version>
 		</dependency>
 		<!-- webservice-->
+
+		<!--http请求-->
+		<dependency>
+			<groupId>com.netflix.feign</groupId>
+			<artifactId>feign-core</artifactId>
+			<version>8.18.0</version>
+		</dependency>
+		<dependency>
+			<groupId>com.netflix.feign</groupId>
+			<artifactId>feign-jackson</artifactId>
+			<version>8.18.0</version>
+		</dependency>
+		<!--http请求-->
 	</dependencies>
 
 

+ 2 - 0
src/main/java/com/gyee/SpringbootStart.java

@@ -4,6 +4,7 @@ import com.gyee.frame.common.spring.InitialRedis;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
 
 
 /**
@@ -11,6 +12,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  * @author gyee
  *
  */
+@EnableCaching
 @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
 public class SpringbootStart {
 

+ 25 - 0
src/main/java/com/gyee/frame/common/conf/ExportConfig.java

@@ -0,0 +1,25 @@
+package com.gyee.frame.common.conf;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 庚顿数据导出配置
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "exportcode")
+public class ExportConfig {
+
+    private List<String> template1;
+
+    private Map<String, String> template2swdl;
+
+    private Map<String, String> template2swgl;
+
+    private Map<String, String> template2cft;
+}

+ 20 - 0
src/main/java/com/gyee/frame/common/exception/GlobalExceptionResolver.java

@@ -1,6 +1,7 @@
 package com.gyee.frame.common.exception;
 
 import javax.servlet.http.HttpServletRequest;
+
 import org.apache.shiro.authz.AuthorizationException;
 import org.apache.shiro.authz.UnauthenticatedException;
 import org.apache.shiro.authz.UnauthorizedException;
@@ -14,6 +15,7 @@ import org.springframework.web.servlet.ModelAndView;
 import com.gyee.frame.common.domain.AjaxResult;
 import com.gyee.frame.common.exception.demo.DemoModeException;
 import com.gyee.frame.util.ServletUtils;
+import org.thymeleaf.exceptions.TemplateInputException;
 
 /**
  * 全局异常处理
@@ -118,4 +120,22 @@ public class GlobalExceptionResolver{
         return AjaxResult.error("运行时异常:" + e.getMessage());
     }
 
+    /**
+     * 拦截自定义异常
+     */
+    @ExceptionHandler(QiNiuException.class)
+    public AjaxResult qiniuException(QiNiuException e)
+    {
+        logger.error(e.getMessage());
+        return AjaxResult.error(e.getCode(), e.getMessage());
+    }
+
+
+    @ExceptionHandler(TemplateInputException.class)
+    public AjaxResult templateException(TemplateInputException e)
+    {
+        logger.error(e.getMessage());
+        return AjaxResult.error(e.getMessage());
+    }
+
 }

+ 6 - 1
src/main/java/com/gyee/frame/common/exception/enums/QiNiuErrorEnum.java

@@ -14,13 +14,18 @@ public enum QiNiuErrorEnum {
     TOKEN_GENERATOR_ERROR(502,"token生成失败"),
     NO_UUID(503,"uuid为空"),
     SQL_ILLEGAL(504,"sql非法"),
+	TEMPLATE_NO_SUPPORT(505,"模板不支持"),
 
     //用户权限错误
     INVALID_TOKEN(1001,"token不合法"),
 
     //七牛OSS错误
     OSS_CONFIG_ERROR(10050,"七牛配置信息错误"),
-    OSS_UPLOAD_ERROR(10051,"OSSBookNote上传失败");
+    OSS_UPLOAD_ERROR(10051,"OSSBookNote上传失败"),
+
+	//数据库错误
+	ERROR_CONNECT(4005, "数据库连接异常"),
+	ERROR_DATA(4006, "数据查询失败");
 
     private int code;
     private String msg;

+ 30 - 0
src/main/java/com/gyee/frame/common/feign/IAdapterService.java

@@ -0,0 +1,30 @@
+package com.gyee.frame.common.feign;
+
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.frame.model.custom.export.TsPointData;
+import feign.Headers;
+import feign.Param;
+import feign.RequestLine;
+
+import java.util.List;
+
+
+public interface IAdapterService {
+
+
+    @Headers({"Content-Type: application/json", "Accept: application/json"})
+    @RequestLine("GET /ts/latest?keys={points}")
+    JSONObject getLatest(@Param(value = "points") String points);
+
+
+    @Headers({"Content-Type: application/json", "Accept: application/json"})
+    @RequestLine("GET /ts/history/snap?tagName={tagName}&startTs={startTs}&endTs={endTs}&interval={interval}")
+    List<TsPointData> getHistorySnap(@Param(value = "tagName") String tagName, @Param(value = "startTs") long startTs,
+                                     @Param(value = "endTs") long endTs, @Param(value = "interval") Integer interval);
+
+
+    @Headers({"Content-Type: application/json", "Accept: application/json"})
+    @RequestLine("GET /ts/history/section?tagNames={tagNames}&ts={ts}")
+    List<TsPointData> getHistorySection(@Param(value = "tagNames") String tagNames, @Param(value = "ts") long ts);
+
+}

+ 30 - 0
src/main/java/com/gyee/frame/common/feign/RemoteServiceBuilder.java

@@ -0,0 +1,30 @@
+package com.gyee.frame.common.feign;
+
+import feign.Feign;
+import feign.Request;
+import feign.Retryer;
+import feign.jackson.JacksonDecoder;
+import feign.jackson.JacksonEncoder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+@Slf4j
+@Configuration
+public class RemoteServiceBuilder {
+
+    @Value("${goldenUrl:http://10.155.32.4:8011}")
+    private String shardingUrlString;
+
+    @Bean
+    public IAdapterService ShardingService() {
+        return Feign.builder()
+                .encoder(new JacksonEncoder())
+                .decoder(new JacksonDecoder())
+                .options(new Request.Options(5000, 600000))
+                .retryer(new Retryer.Default(10000, 10000, 3))
+                .target(IAdapterService.class, shardingUrlString);
+    }
+}

+ 89 - 0
src/main/java/com/gyee/frame/controller/export/GoldenController.java

@@ -0,0 +1,89 @@
+package com.gyee.frame.controller.export;
+
+
+import com.gyee.frame.common.conf.AjaxStatus;
+import com.gyee.frame.common.domain.AjaxResult;
+import com.gyee.frame.service.WindpowerstationService;
+import com.gyee.frame.service.export.GoldenService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@RestController
+@RequestMapping("/export")
+@Api(value = "golden数据导出功能",tags =  "golden数据导出功能")
+public class GoldenController {
+
+    @Resource
+    private GoldenService goldenService;
+    @Resource
+    private WindpowerstationService stationService;
+
+    /**
+     * 查询所有的场站
+     *
+     * @return
+     */
+    @GetMapping("/databases")
+    @ApiOperation(value = "查询风电场", notes = "查询风电场")
+    public AjaxResult getDatabases() {
+        List<Map<String, String>> list = stationService.findStationAll();
+        return AjaxResult.successData(AjaxStatus.success.code, list);
+    }
+
+
+
+    /**
+     * 通过模板导出单个风机数据
+     *
+     * @param station  场站
+     * @param wtId     风机ID
+     * @param id       模板ID
+     * @param startTs  开始时间
+     * @param endTs    结束时间
+     * @param interval 时间间隔
+     * @return
+     */
+    @GetMapping("/history/snap")
+    public AjaxResult getHistory(
+            @RequestParam(value = "station") String station,
+            @RequestParam(value = "wtId", required = false) String wtId,
+            @RequestParam(value = "templateId") Integer id,
+            @RequestParam(value = "startTs") Long startTs,
+            @RequestParam(value = "endTs") Long endTs,
+            @RequestParam(value = "interval", required = false) Optional<Integer> interval) {
+
+        int val = interval.isPresent() ? interval.get() : 1800;
+
+        List<Object> list = goldenService.getHistoryDataSingle(station, wtId, id, startTs, endTs, val);
+        return AjaxResult.successData(AjaxStatus.success.code, list);
+    }
+
+    /**
+     * 通过模板导出所有风机数据
+     *
+     * @param id       模板ID
+     * @param startTs  开始时间
+     * @param endTs    结束时间
+     * @param interval 时间间隔
+     * @return
+     */
+    @GetMapping("/history/all")
+    public AjaxResult getHistoryAll(
+            @RequestParam(value = "station") String station,
+            @RequestParam(value = "templateId") Integer id,
+            @RequestParam(value = "startTs") Long startTs,
+            @RequestParam(value = "endTs") Long endTs,
+            @RequestParam(value = "interval", required = false) Optional<Integer> interval) {
+
+        int val = interval.isPresent() ? interval.get() : 1800;
+
+        Map<String, List<Object>> map = goldenService.getHistoryDataAll(station, id, startTs, endTs, val);
+        return AjaxResult.successData(AjaxStatus.success.code, map);
+    }
+}

+ 36 - 0
src/main/java/com/gyee/frame/model/custom/export/TsPointData.java

@@ -0,0 +1,36 @@
+package com.gyee.frame.model.custom.export;
+
+import java.math.BigDecimal;
+
+public class TsPointData {
+
+    private long ts;
+    private int status;
+    private double doubleValue;
+
+    public long getTs() {
+        return ts;
+    }
+
+    public void setTs(long ts) {
+        this.ts = ts;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public double getDoubleValue() {
+        return doubleValue;
+    }
+
+    public void setDoubleValue(double doubleValue) {
+        BigDecimal bg = new BigDecimal(doubleValue);
+        double v = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+        this.doubleValue = v;
+    }
+}

+ 25 - 0
src/main/java/com/gyee/frame/service/WindTurbineTestingPointAiService.java

@@ -9,8 +9,11 @@ import com.gyee.frame.mapper.auto.WindTurbineTestingPointAi2Mapper;
 import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
 import com.gyee.frame.model.auto.WindTurbineTestingPointAi2Example;
 import com.gyee.frame.model.custom.Tablepar;
+import com.gyee.frame.model.custom.weather.Wind;
 import com.gyee.frame.util.SnowflakeIdWorker;
 import com.gyee.frame.util.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.CacheConfig;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -25,6 +28,8 @@ import java.util.Map;
  * @email 1@qq.com
  * @date 2019-12-31 14:58:09  
  **/
+@Slf4j
+@CacheConfig(cacheNames = "tsPoints")
 @Service
 public class WindTurbineTestingPointAiService implements BaseService<WindTurbineTestingPointAi2, WindTurbineTestingPointAi2Example> {
 	@Resource
@@ -155,4 +160,24 @@ public class WindTurbineTestingPointAiService implements BaseService<WindTurbine
 
 		return point;
 	}
+
+
+	/**
+	 * 通过统一编码查询指定场站的点
+	 *
+	 * @param station     场站
+	 * @param wtId        风机ID
+	 * @param uniformCode 统一编码
+	 * @return
+	 */
+	public List<WindTurbineTestingPointAi2> findPointsByUniformCodeAndStation(String station, String wtId, String uniformCode) {
+		WindTurbineTestingPointAi2Example example = new WindTurbineTestingPointAi2Example();
+		example.createCriteria().andUniformcodeEqualTo(uniformCode)
+			                    .andWindturbineidEqualTo(wtId)
+								.andWindpowerstationidEqualTo(station);
+
+		List<WindTurbineTestingPointAi2> list = windTurbineTestingPointAi2Mapper.selectByExample(example);
+
+		return list;
+	}
 }

+ 31 - 0
src/main/java/com/gyee/frame/service/WindpowerstationService.java

@@ -9,10 +9,16 @@ import com.gyee.frame.model.auto.Windpowerstation;
 import com.gyee.frame.model.auto.WindpowerstationExample;
 import com.gyee.frame.model.custom.Tablepar;
 import com.gyee.frame.util.SnowflakeIdWorker;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 风场 WindpowerstationService
@@ -22,6 +28,8 @@ import java.util.List;
  * @email 1@qq.com
  * @date 2019-12-31 14:58:09  
  **/
+@Slf4j
+@CacheConfig(cacheNames = "stations")
 @Service
 public class WindpowerstationService implements BaseService<Windpowerstation, WindpowerstationExample> {
 	@Resource
@@ -132,5 +140,28 @@ public class WindpowerstationService implements BaseService<Windpowerstation, Wi
 		return list.size();
 	}
 
+	/**
+	 * 查询所有的场站
+	 *
+	 * @return key:SBQ_FDC  value:石板泉风电场
+	 */
+	@Cacheable(cacheNames = "findStationAll")
+	public List<Map<String, String>> findStationAll() {
+		List<Map<String, String>> list = new ArrayList<>();
+
+		WindpowerstationExample example = new WindpowerstationExample();
+		example.setOrderByClause("ordernum ASC");
 
+		List<Windpowerstation> stations = windpowerstationMapper.selectByExample(example);
+		for (Windpowerstation station : stations){
+			// 只显示风场
+			if (station.getId().contains("_FDC")) {
+				Map<String, String> map = new HashMap<>();
+				map.put(station.getId(), station.getName());
+				list.add(map);
+			}
+		}
+
+		return list;
+	}
 }

+ 25 - 0
src/main/java/com/gyee/frame/service/WindturbineService.java

@@ -9,9 +9,13 @@ import com.gyee.frame.model.auto.Windturbine;
 import com.gyee.frame.model.auto.WindturbineExample;
 import com.gyee.frame.model.custom.Tablepar;
 import com.gyee.frame.util.SnowflakeIdWorker;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -22,6 +26,8 @@ import java.util.List;
  * @email 1@qq.com
  * @date 2019-12-30 17:00:04  
  **/
+@Slf4j
+@CacheConfig(cacheNames = "windTurbine")
 @Service
 public class WindturbineService implements BaseService<Windturbine, WindturbineExample> {
 	@Resource
@@ -132,5 +138,24 @@ public class WindturbineService implements BaseService<Windturbine, WindturbineE
 		return list.size();
 	}
 
+	/**
+	 * 查询所有的风机
+	 *
+	 * @param station 场站名  SBQ_FDC
+	 * @return SG01_01
+	 */
+	@Cacheable(cacheNames = "findWindTurbines")
+	public List<String> findWindTurbineAll(String station) {
+		List<String> list = new ArrayList<>();
+
+		WindturbineExample example = new WindturbineExample();
+		example.createCriteria().andWindpowerstationidEqualTo(station);
+		example.setOrderByClause("id ASC");
 
+		List<Windturbine> winds = windturbineMapper.selectByExample(example);
+		for (Windturbine wind : winds)
+			list.add(wind.getId());
+
+		return list;
+	}
 }

+ 274 - 0
src/main/java/com/gyee/frame/service/export/GoldenService.java

@@ -0,0 +1,274 @@
+package com.gyee.frame.service.export;
+
+import com.gyee.frame.common.conf.ExportConfig;
+import com.gyee.frame.common.exception.QiNiuException;
+import com.gyee.frame.common.exception.enums.QiNiuErrorEnum;
+import com.gyee.frame.common.feign.RemoteServiceBuilder;
+import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
+import com.gyee.frame.model.custom.export.TsPointData;
+import com.gyee.frame.service.WindTurbineTestingPointAiService;
+import com.gyee.frame.service.WindturbineService;
+import com.gyee.frame.util.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+@Slf4j
+@Service
+public class GoldenService {
+
+
+    @Resource
+    private ExportConfig exportConfig;
+    @Resource
+    private RemoteServiceBuilder remoteService;
+    @Resource
+    private WindturbineService windturbineService;
+    @Resource
+    private WindTurbineTestingPointAiService windService;
+
+    /**
+     * 一天的时间戳
+     */
+    public static final Integer TIMES_TAMP_DAY = 86400;
+
+    /**
+     * 根据场站和风机ID查询
+     *
+     * @param station
+     * @param wtId
+     * @param templateId
+     * @param startTs
+     * @param endTs
+     * @param interval
+     * @return
+     */
+    public List<Object> getHistoryDataSingle(String station, String wtId, int templateId, long startTs, long endTs, int interval) {
+        switch (templateId) {
+            case 1:
+                return getTemplateHistory1(station, wtId, startTs, endTs, interval);
+            default:
+                throw new QiNiuException(QiNiuErrorEnum.TEMPLATE_NO_SUPPORT);
+        }
+    }
+
+
+    /**
+     * 查询所有风机
+     *
+     * @param station
+     * @param templateId
+     * @param startTs
+     * @param endTs
+     * @param interval
+     * @return
+     */
+    public Map<String, List<Object>> getHistoryDataAll(String station, int templateId, long startTs, long endTs, int interval) {
+        switch (templateId) {
+            case 1:
+                return getTemplateHistory1(station, startTs, endTs, interval);
+            case 2:
+                return getTemplateHistory2(station, startTs, endTs, interval);
+            default:
+                throw new QiNiuException(QiNiuErrorEnum.TEMPLATE_NO_SUPPORT);
+        }
+    }
+
+
+    /**
+     * 模板1  场站所有风机数据
+     *
+     * @param station
+     * @param startTs
+     * @param endTs
+     * @param interval
+     * @return
+     */
+    private Map<String, List<Object>> getTemplateHistory1(String station, long startTs, long endTs, int interval) {
+        // 风机ID、数据
+        Map<String, List<Object>> map = new LinkedHashMap<>();
+
+        try {
+            List<String> winds = windturbineService.findWindTurbineAll(station);
+            if (winds == null)
+                return map;
+
+            for (String wind : winds) {
+                List<Object> data = getTemplateHistory1(station, wind, startTs, endTs, interval);
+                map.put(wind, data);
+            }
+        } catch (QiNiuException e) {
+            log.error(e.getMessage());
+            throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
+        }
+
+        return map;
+    }
+
+
+    /**
+     * 模板1  单机数据
+     *
+     * @param station
+     * @param wtId
+     * @param startTs
+     * @param endTs
+     * @param interval
+     * @return
+     */
+    private List<Object> getTemplateHistory1(String station, String wtId, long startTs, long endTs, int interval) {
+        List<Object> list = new ArrayList<>();
+        List<String> codes = exportConfig.getTemplate1();
+
+        // 第一列添加时间
+        List<String> intervals = dateInterval(startTs, endTs, interval);
+        list.add(intervals);
+
+        try {
+            for (String code : codes) {
+                List<WindTurbineTestingPointAi2> windPoints = windService.findPointsByUniformCodeAndStation(station, wtId, code);
+                if (windPoints == null || windPoints.size() == 0)
+                    continue;
+
+                WindTurbineTestingPointAi2 windPoint = windPoints.get(0);
+                List<TsPointData> data = remoteService.ShardingService().getHistorySnap(windPoint.getId(), startTs, endTs, interval);
+
+                List<Object> collect = new ArrayList<>();
+                // 故障状态或限电状态都是整型0或1
+                if (code.equals("GZZT") || code.equals("XDZT")) {
+                    if (data.size() == 0) {
+                        for (int i = 0; i < intervals.size(); i++)
+                            collect.add(0);
+                    } else {
+                        collect = data.stream().map(point -> (int) point.getDoubleValue()).collect(Collectors.toList());
+                    }
+                    list.add(collect);
+                } else {
+                    if (data.size() == 0) {
+                        for (int i = 0; i < intervals.size(); i++)
+                            collect.add(0.0);
+                    } else {
+                        collect = data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList());
+                    }
+                    list.add(collect);
+                }
+            }
+        } catch (QiNiuException e) {
+            log.error(e.getMessage());
+            throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
+        }
+
+        return list;
+    }
+
+
+    /**
+     * 模板2  场站所有风机数据  日上网电量、上网功率、测风塔数据
+     *
+     * @param station
+     * @param startTs
+     * @param endTs
+     * @return
+     */
+    private Map<String, List<Object>> getTemplateHistory2(String station, long startTs, long endTs, int interval) {
+        // 风机ID、数据
+        Map<String, List<Object>> map = new LinkedHashMap<>();
+
+        try {
+            // 上网电量
+            String point = exportConfig.getTemplate2swdl().get(station);
+            List<TsPointData> data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, TIMES_TAMP_DAY);
+            List<Object> list = new ArrayList<>();
+            list.add(data.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_PATTERN)).collect(Collectors.toList()));
+            list.add(data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
+            map.put("swdl", list);
+
+            // 上网功率
+            String point2 = exportConfig.getTemplate2swgl().get(station);
+            List<TsPointData> data2 = remoteService.ShardingService().getHistorySnap(point2, startTs, endTs, interval);
+            List<Object> list2 = new ArrayList<>();
+            list2.add(data2.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_TIME_PATTERN)).collect(Collectors.toList()));
+            list2.add(data2.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
+            map.put("swgl", list2);
+
+            // 测风塔数据
+            String point3 = exportConfig.getTemplate2cft().get(station);
+            List<Object> maps = getTemplateHistory2(startTs, endTs, interval, point3);
+            map.put("cft", maps);
+
+        } catch (QiNiuException e) {
+            log.error(e.getMessage());
+            throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
+        }
+
+        return map;
+    }
+
+
+    /**
+     * 模板2  场站数据
+     *
+     * @param startTs
+     * @param endTs
+     * @param interval
+     * @param points
+     * @return
+     */
+    private List<Object> getTemplateHistory2(long startTs, long endTs, int interval, String points) {
+        List<Object> list = new ArrayList<>();
+
+        // 第一列添加时间
+        List<String> intervals = dateInterval(startTs, endTs, interval);
+        list.add(intervals);
+
+        try {
+            String[] splits = points.split(",");
+            for (String point : splits) {
+                List<TsPointData> data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
+
+                List<Object> collect = new ArrayList<>();
+                if (data.size() == 0){
+                    for (int i = 0; i < intervals.size(); i++)
+                        collect.add(0);
+                }else{
+                    collect = data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList());
+                }
+                list.add(collect);
+            }
+
+        } catch (QiNiuException e) {
+            log.error(e.getMessage());
+            throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
+        }
+
+        return list;
+    }
+
+
+    /**
+     * 分割时间
+     *
+     * @param st
+     * @param et
+     * @param interval
+     * @return
+     */
+    private List<String> dateInterval(long st, long et, int interval) {
+        List<String> list = new ArrayList<>();
+        int val = interval * 1000;
+        while (st < et - val) {
+            list.add(DateUtils.format(st, DateUtils.DATE_TIME_PATTERN));
+            st += val;
+        }
+
+        return list;
+    }
+
+}

+ 14 - 0
src/main/java/com/gyee/frame/util/DateUtils.java

@@ -48,6 +48,20 @@ public class DateUtils  extends org.apache.commons.lang3.time.DateUtils {
         return null;
     }
 
+    /**
+     * 时间转换
+     *
+     * @param time
+     * @param pattern
+     * @return
+     */
+    public static String format(Long time, String pattern) {
+        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+        Date date = new Date(time);
+        String format = sdf.format(date);
+        return format;
+    }
+
 
     public static String YYYY = "yyyy";
 

File diff suppressed because it is too large
+ 24 - 3
src/main/resources/application.yml