Browse Source

Merge branch 'dev-v1.0.0-jd' of http://39.106.8.246:3003/apm/energy-report into dev-v1.0.0-jd

lixing 3 years ago
parent
commit
fb35850d88

+ 4 - 2
pom.xml

@@ -95,9 +95,11 @@
             <version>2.4.2</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-elasticsearch -->
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-elasticsearch</artifactId>
+            <version>3.2.13.RELEASE</version>
         </dependency>
 
         <dependency>

+ 2 - 0
src/main/java/com/persagy/apm/energy/report/common/FeignClientNameConstants.java

@@ -17,4 +17,6 @@ public class FeignClientNameConstants {
 
     public static final String EQUIP_RUN_MANAGER = "equip-run-manager";
 
+    public static final String MANUAL_FILLING = "manual-filling";
+
 }

+ 23 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/client/ManualFillingWebClient.java

@@ -0,0 +1,23 @@
+package com.persagy.apm.energy.report.manualfilling.client;
+
+import com.persagy.apm.common.response.PoemsFeignResponse;
+import com.persagy.apm.energy.report.common.FeignClientNameConstants;
+import com.persagy.apm.energy.report.common.FeignConfig;
+import com.persagy.apm.energy.report.manualfilling.client.fallback.ManualFillingWebClientFallbackFactory;
+import com.persagy.apm.energy.report.manualfilling.model.dto.QueryIndicatorFillingDataDTO;
+import com.persagy.apm.energy.report.manualfilling.model.vo.IndicatorFillingDataVo;
+import com.persagy.apm.energy.report.workorder.model.dto.QueryWorkOrderListByParamDTO;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+
+/**
+ * 数据录入feign客户端
+ **/
+@FeignClient(name = FeignClientNameConstants.MANUAL_FILLING, fallbackFactory = ManualFillingWebClientFallbackFactory.class,
+        configuration = FeignConfig.class)
+public interface ManualFillingWebClient {
+
+    @PostMapping("/dataFillingManage/queryIndicatorFillingData")
+    PoemsFeignResponse<IndicatorFillingDataVo> listIndicatorFillingDataByParam(QueryIndicatorFillingDataDTO queryIndicatorFillingDataDTO);
+
+}

+ 13 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/client/fallback/ManualFillingWebClientFallbackFactory.java

@@ -0,0 +1,13 @@
+package com.persagy.apm.energy.report.manualfilling.client.fallback;
+
+import com.persagy.apm.energy.report.manualfilling.client.ManualFillingWebClient;
+import feign.hystrix.FallbackFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ManualFillingWebClientFallbackFactory implements FallbackFactory<ManualFillingWebClient> {
+    @Override
+    public ManualFillingWebClient create(Throwable throwable) {
+        return null;
+    }
+}

+ 26 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/model/dto/QueryIndicatorFillingDataDTO.java

@@ -0,0 +1,26 @@
+package com.persagy.apm.energy.report.manualfilling.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "获取指标录入数据入参")
+public class QueryIndicatorFillingDataDTO {
+
+    @ApiModelProperty(value = "项目id")
+    private String projectId;
+
+    @ApiModelProperty(value = "指标id")
+    private String indicatorId;
+
+    @ApiModelProperty(value = "查询时间类型")
+    private Integer timeType;
+
+    @ApiModelProperty(value = "开始时间")
+    private String startDate;
+
+    @ApiModelProperty(value = "结束时间")
+    private String endDate;
+
+}

+ 19 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/model/vo/IndicatorFillingDataVo.java

@@ -0,0 +1,19 @@
+package com.persagy.apm.energy.report.manualfilling.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@ApiModel
+public class IndicatorFillingDataVo {
+
+    @ApiModelProperty(value = "数据时间")
+    private String time;
+
+    @ApiModelProperty(value = "数据")
+    private String data;
+
+}

+ 18 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/service/IManualFilliingService.java

@@ -0,0 +1,18 @@
+package com.persagy.apm.energy.report.manualfilling.service;
+
+import java.util.Date;
+
+public interface IManualFilliingService {
+
+    /**
+     *
+     * @param pjId 项目id
+     * @param indicatorId 指标id
+     * @param timeType 查询时间类型(1-日,2-月,3-年,4-无周期(无周期数据跟时间没有关系))
+     * @param startDate 开始时间
+     * @param endDate 结束时间
+     * @return
+     */
+    String getIndicatorFillingData(String pjId, String indicatorId, Integer timeType, Date startDate, Date endDate);
+
+}

+ 47 - 0
src/main/java/com/persagy/apm/energy/report/manualfilling/service/impl/IManualFilliingServiceImpl.java

@@ -0,0 +1,47 @@
+package com.persagy.apm.energy.report.manualfilling.service.impl;
+
+import com.persagy.apm.common.response.PoemsFeignResponse;
+import com.persagy.apm.energy.report.common.utils.DateUtils;
+import com.persagy.apm.energy.report.manualfilling.client.ManualFillingWebClient;
+import com.persagy.apm.energy.report.manualfilling.model.dto.QueryIndicatorFillingDataDTO;
+import com.persagy.apm.energy.report.manualfilling.model.vo.IndicatorFillingDataVo;
+import com.persagy.apm.energy.report.manualfilling.service.IManualFilliingService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Date;
+import java.util.List;
+
+@Service
+@Slf4j
+public class IManualFilliingServiceImpl implements IManualFilliingService {
+    @Autowired
+    ManualFillingWebClient ManualFillingWebClient;
+
+    @Override
+    public String getIndicatorFillingData(String pjId, String indicatorId, Integer timeType, Date reportDate, Date endDate) {
+        String result = "";
+        try {
+            QueryIndicatorFillingDataDTO queryIndicatorFillingDataDTO = new QueryIndicatorFillingDataDTO();
+            queryIndicatorFillingDataDTO.setProjectId(pjId);
+            queryIndicatorFillingDataDTO.setIndicatorId(indicatorId);
+            queryIndicatorFillingDataDTO.setTimeType(timeType);
+            queryIndicatorFillingDataDTO.setStartDate(DateUtils.date2Str(reportDate, DateUtils.SDF_SECOND));
+            queryIndicatorFillingDataDTO.setEndDate(DateUtils.date2Str(endDate, DateUtils.SDF_SECOND));
+            PoemsFeignResponse<IndicatorFillingDataVo> response = ManualFillingWebClient.listIndicatorFillingDataByParam(queryIndicatorFillingDataDTO);
+            List<IndicatorFillingDataVo> indicatorFillingDataVoList = response.getContent();
+            if (!CollectionUtils.isEmpty(indicatorFillingDataVoList)) {
+                for (IndicatorFillingDataVo vo : indicatorFillingDataVoList) {
+                    if (DateUtils.date2Str(reportDate, DateUtils.SDF_SECOND).equals(vo.getTime())) {
+                        result = vo.getData();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询指标录入数据异常:", e);
+        }
+        return result;
+    }
+}

+ 79 - 0
src/main/java/com/persagy/apm/energy/report/workorder/config/ElasticsearchCustomConfig.java

@@ -0,0 +1,79 @@
+package com.persagy.apm.energy.report.workorder.config;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.TransportAddress;
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
+import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
+import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.support.DefaultConversionService;
+import org.springframework.core.env.Environment;
+import org.springframework.data.elasticsearch.config.ElasticsearchConfigurationSupport;
+import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
+import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.EntityMapper;
+import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
+
+import javax.annotation.PostConstruct;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+
+@Configuration
+@AutoConfigureAfter({ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class})
+public class ElasticsearchCustomConfig extends ElasticsearchConfigurationSupport {
+    @Autowired
+    private Environment environment;
+
+    @PostConstruct
+    void init() {
+        System.setProperty("es.set.netty.runtime.available.processors", "false");
+    }
+
+    @Bean
+    @Override
+    public EntityMapper entityMapper() {
+        ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(
+                elasticsearchMappingContext(), new DefaultConversionService());
+        entityMapper.setConversions(elasticsearchCustomConversions());
+        return entityMapper;
+    }
+
+    @Bean
+    @Override
+    public ElasticsearchCustomConversions elasticsearchCustomConversions() {
+        return new ElasticsearchCustomConversions(Arrays.asList(new WorkorderToMap(), new MapToWorkorder()));
+    }
+
+    @Bean(name = {"elasticsearchOperations", "elasticsearchTemplate"})
+    public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
+        return new ElasticsearchTemplate(elasticsearchClient(), entityMapper());
+    }
+
+    @Bean
+    public Client elasticsearchClient() throws UnknownHostException {
+        String clusterName = environment.getProperty("spring.data.elasticsearch.cluster-name");
+        String clusterNodes = environment.getProperty("spring.data.elasticsearch.cluster-nodes");
+        if (StringUtils.isBlank(clusterName)) {
+            clusterName = "elasticsearch";
+        }
+        if (StringUtils.isBlank(clusterNodes)) {
+            clusterNodes = "127.0.0.1:9300";
+        }
+        Settings settings = Settings.builder().put("cluster.name", clusterName).build();
+        TransportClient client = new PreBuiltTransportClient(settings);
+        String[] split = clusterNodes.split(",");
+        for (int i = 0; i < split.length; i++) {
+            String[] addrs = split[i].split(":");
+            client.addTransportAddress(new TransportAddress(InetAddress.getByName(addrs[0]), Integer.valueOf(addrs[1])));
+        }
+        return client;
+    }
+}

+ 16 - 0
src/main/java/com/persagy/apm/energy/report/workorder/config/MapToWorkorder.java

@@ -0,0 +1,16 @@
+package com.persagy.apm.energy.report.workorder.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.apm.energy.report.workorder.model.WorkOrder;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.convert.ReadingConverter;
+
+import java.util.Map;
+
+@ReadingConverter
+public class MapToWorkorder implements Converter<Map<String, Object>, WorkOrder> {
+    @Override
+    public WorkOrder convert(Map<String, Object> source) {
+        return JSONObject.parseObject(JSONObject.toJSONString(source), WorkOrder.class);
+    }
+}

+ 17 - 0
src/main/java/com/persagy/apm/energy/report/workorder/config/WorkorderToMap.java

@@ -0,0 +1,17 @@
+package com.persagy.apm.energy.report.workorder.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.apm.energy.report.workorder.model.WorkOrder;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.convert.WritingConverter;
+
+import java.util.Map;
+
+@WritingConverter
+public class WorkorderToMap implements Converter<WorkOrder, Map<String, Object>> {
+
+    @Override
+    public Map<String, Object> convert(WorkOrder source) {
+        return JSONObject.parseObject(JSONObject.toJSONString(source), Map.class);
+    }
+}