Commit 813d0df3 authored by 朱晨阳's avatar 朱晨阳

Merge remote-tracking branch 'origin/developer' into developer

parents 1f189d7f 554a1b0c
......@@ -147,7 +147,12 @@ public class ImasterUtils {
} else {
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
try {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} catch (Exception e) {
e.printStackTrace();
logger.error("华为数据解析错误(getResPonseOther):" + jsonArray.toJSONString());
}
}
}
} else {
......@@ -207,15 +212,16 @@ public class ImasterUtils {
JSONObject jsonObject = JSONObject.parseObject(response);
JSONArray jsonArray = new JSONArray();
JSONArray jsonArrayRet = new JSONArray();
if (ObjectUtil.isNotEmpty(resultResovle)) {
if (ObjectUtil.isNotEmpty(resultResovle)&&ObjectUtil.isNotEmpty(jsonObject)) {
String[] rules = resultResovle.split(",");
if (rules.length > 0) {
for (int i = 0; i < rules.length; i++) {
if ("ACCESS_FREQUENCY_IS_TOO_HIGH".equals(jsonObject.get(rules[i]))) {
logger.error("华为数据解析错误(handlerResponseByResultResolveruleOther):请求系统次数太频繁,无法获取接口数据");
continue;
}
try {
jsonObject = (JSONObject) jsonObject.get(rules[i]);
if (jsonObject == null) {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
}
} catch (Exception exception) {
try {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
......
......@@ -116,7 +116,14 @@ public class SunlightUtil {
{
put("1", "在线");
put("0", "离线");
put("2","报警" );
}
};
public static final HashMap<String, String> gzzt= new HashMap<String, String>() {
{
put("1", "故障");
put("2", "报警");
put("4", "正常" );
}
};
......
......@@ -19,7 +19,7 @@ public class ImasterInverterListDetails {
Double mppt_total_cap ;
Double pv24_i ;
Double pv8_u ;
Double open_time ;
String open_time ;
Double pv22_u ;
Double a_i ;
Double pv24_u ;
......@@ -43,7 +43,7 @@ public class ImasterInverterListDetails {
Double mppt_power ;
Double pv13_u ;
int run_state ;
Double close_time ;
String close_time ;
Double pv19_i ;
Double mppt_7_cap ;
Double mppt_5_cap ;
......
......@@ -5,7 +5,10 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.JsonObject;
import com.qiniu.util.Json;
import com.yeejoin.amos.api.householdapi.Utils.SunlightUtil;
import com.yeejoin.amos.api.householdapi.constant.ImasterConstant;
import com.yeejoin.amos.api.householdapi.constant.KSolarConstant;
......@@ -43,6 +46,8 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
/**
* @description:
* @author: tw
......@@ -114,7 +119,6 @@ public class SunlightServiceImpl implements SunlightService {
for (Sunlight sunlight : list) {
sunlight.setCreatedTime(System.currentTimeMillis());
sunlightMapper.insert(sunlight);
}
logger.info("-------阳光同步电站/逆变器/采集器结束" + ts + "------- " + sdf.format(new Date()));
......@@ -194,36 +198,69 @@ public class SunlightServiceImpl implements SunlightService {
jpStation.setSnCode(sunlightDto.getPs_id().toString());// sncode
Map<String, String> map = sunlightDto.getTotal_capcity();
jpStation.setCapacity(
map != null && map.get("unit") != null ? SunlightUtil.zj.get(String.valueOf(map.get("unit")))
* Double.valueOf(String.valueOf(map.get("value"))) : null);// 装机容量
Map<String, String> map1 = sunlightDto.getCurr_power();
jpStation.setRealTimePower(
map1 != null && map1.get("unit") != null ? SunlightUtil.GL.get(String.valueOf(map1.get("unit")))
* Double.valueOf(String.valueOf(map1.get("value"))) : null);// 实时功率
Map<String, String> map2 = sunlightDto.getToday_energy();
jpStation.setDayGenerate(
map2 != null && map2.get("unit") != null ? SunlightUtil.fd.get(String.valueOf(map2.get("unit")))
* Double.valueOf(String.valueOf(map2.get("value"))) : null);// 日发电量
Map<String, String> map3 = sunlightDto.getTotal_energy();
jpStation.setAccumulatedPower(
map3 != null && map3.get("unit") != null ? SunlightUtil.fd.get(String.valueOf(map3.get("unit")))
* Double.valueOf(String.valueOf(map3.get("value"))) : null);// 累计发电量
Map<String, String> map4 = sunlightDto.getToday_income();
jpStation.setDayIncome(
map4 != null && map4.get("unit") != null ? SunlightUtil.sy.get(String.valueOf(map4.get("unit")))
* Double.valueOf(String.valueOf(map4.get("value"))) : null);// 日收益
Map<String, String> map5 = sunlightDto.getTotal_income();
jpStation.setCumulativeIncome(
map5 != null && map5.get("unit") != null ? SunlightUtil.sy.get(String.valueOf(map5.get("unit")))
* Double.valueOf(String.valueOf(map5.get("value"))) : null);// 累计收益
if (sunlightDto.getPs_fault_status() > 2) {
jpStation.setState(SunlightUtil.zt.get(sunlightDto.getPs_status() + ""));// 电站状态
try {
Map<String, String> map = sunlightDto.getTotal_capcity();
if (map != null && map.get("unit") != null && !map.get("unit").isEmpty()
&& !"--".equals(map.get("value"))) {
jpStation.setCapacity(SunlightUtil.zj.get(String.valueOf(map.get("unit")))
* Double.valueOf(String.valueOf(map.get("value"))));// 装机容量
}
Map<String, String> map1 = sunlightDto.getCurr_power();
if (map1 != null && map1.get("unit") != null && !map1.get("unit").isEmpty()
&& !"--".equals(map1.get("value"))) {
jpStation.setRealTimePower(SunlightUtil.GL.get(String.valueOf(map1.get("unit")))
* Double.valueOf(String.valueOf(map1.get("value"))));// 实时功率
}
Map<String, String> map2 = sunlightDto.getToday_energy();
if (map2 != null && map2.get("unit") != null && !map2.get("unit").isEmpty()
&& !"--".equals(map2.get("value"))) {
jpStation.setDayGenerate(SunlightUtil.fd.get(String.valueOf(map2.get("unit")))
* Double.valueOf(String.valueOf(map2.get("value"))));// 日发电量
}
Map<String, String> map3 = sunlightDto.getTotal_energy();
if (map3 != null && map3.get("unit") != null && !map3.get("unit").isEmpty()
&& !"--".equals(map3.get("value"))) {
jpStation.setAccumulatedPower(SunlightUtil.fd.get(String.valueOf(map3.get("unit")))
* Double.valueOf(String.valueOf(map3.get("value"))));// 累计发电量
}
Map<String, String> map4 = sunlightDto.getToday_income();
if (map4 != null && map4.get("unit") != null && !map4.get("unit").isEmpty()
&& !"--".equals(map4.get("value"))) {
jpStation.setDayIncome(SunlightUtil.sy.get(String.valueOf(map4.get("unit")))
* Double.valueOf(String.valueOf(map4.get("value"))));// 日收益
}
Map<String, String> map5 = sunlightDto.getTotal_income();
if (map5 != null && map5.get("unit") != null && !map5.get("unit").isEmpty()
&& !"--".equals(map5.get("value"))) {
jpStation.setCumulativeIncome(SunlightUtil.sy.get(String.valueOf(map5.get("unit")))
* Double.valueOf(String.valueOf(map5.get("value"))));// 累计收益
}
} catch (Exception e) {
e.printStackTrace();
logger.error("阳光数据错误:" + com.alibaba.fastjson.JSONObject.toJSONString(sunlightDto));
}
// 0离线 1在线
// 1故障 2告警 4正常
if ("0".equals(sunlightDto.getPs_status().toString())) {
jpStation.setState("离线");
} else if ("1".equals(sunlightDto.getPs_status().toString())) {
if ("1".equals(sunlightDto.getPs_fault_status().toString())
|| "2".equals(sunlightDto.getPs_fault_status().toString())) {
jpStation.setState("报警");
} else if ("4".equals(sunlightDto.getPs_fault_status().toString())) {
jpStation.setState("在线");
} else {
jpStation.setState("在线");
}
} else {
jpStation.setState("报警");// 电站状态
jpStation.setState("在线");
}
// 获取电站下通讯模块
......@@ -307,11 +344,6 @@ public class SunlightServiceImpl implements SunlightService {
jpStation.setYearGenerate(js != null ? Double.valueOf(js.get(0).get("4") + "") / 1000 : null);
// 年收益
jpStation.setYearIncome(js != null ? Double.valueOf(js.get(0).get("4") + "") / 1000 : null);
if (!ObjectUtils.isEmpty(jpStation.getSequenceNbr())) {
jpStationMapper.updateById(jpStation);
} else {
jpStationMapper.insert(jpStation);
}
String today = DateUtil.today();
String hour = new Date().getHours() + ":00";
......@@ -373,11 +405,22 @@ public class SunlightServiceImpl implements SunlightService {
// tdJpStation.setCreatedTime(System.currentTimeMillis());
// tdJpStationMapper.insert(tdJpStation);
// }
}
JpStation jpStationOld = jpStationMapper.selectOne(
new LambdaQueryWrapper<JpStation>().eq(JpStation::getThirdStationId, jpStation.getThirdStationId())
.eq(JpStation::getThirdCode, PVProducerInfoEnum.YG.getCode()));
this.setJpInverte(listd, jpStation, listdtx);
this.collectorDetail(listd, jpStation);
if (jpStationOld != null) {
jpStation.setSequenceNbr(jpStationOld.getSequenceNbr());
jpStationMapper.updateById(jpStation);
} else {
jpStationMapper.insert(jpStation);
}
this.setJpInverte(listd, jpStation, listdtx);
this.collectorDetail(listd, jpStation);
// 电站报表
// 户用场站日发电量
Date today1 = new Date();
......@@ -490,7 +533,6 @@ public class SunlightServiceImpl implements SunlightService {
@Override
public void run() {
try {
for (Device device : devices) {
if (device != null) {
// 获取逆变器信息存库
......@@ -505,12 +547,24 @@ public class SunlightServiceImpl implements SunlightService {
jpInverter.setSnCode(device.getDevice_sn());
jpInverter.setId(device.getUuid().toString());
if (device.getGetPs_fault_status() > 2) {
jpInverter.setState(SunlightUtil.zt.get(device.getDev_status() + ""));
// 0离线 1在线
// 1故障 2告警 4正常
if ("0".equals(device.getDev_status())) {
jpInverter.setState("离线");
} else if ("1".equals(device.getDev_status())) {
if ("1".equals(device.getDev_fault_status())
|| "2".equals(device.getDev_fault_status())) {
jpInverter.setState("报警");
} else if ("4".equals(device.getDev_fault_status())) {
jpInverter.setState("在线");
} else {
jpInverter.setState("在线");
}
} else {
jpInverter.setState("报警");// 电站状态
jpInverter.setState("在线");
}
// logger.error("阳光数据解析(逆变器),无法获取状态:" +
// com.alibaba.fastjson.JSONObject.toJSONString(device));
jpInverter.setUpdateTime(new Date());
jpInverter.setDayPowerGeneration(jpStation.getDayGenerate());
jpInverter.setMonthPowerGeneration(jpStation.getMonthGenerate());
......@@ -916,7 +970,7 @@ public class SunlightServiceImpl implements SunlightService {
jpCollector.setState("报警");// 电站状态
}
} else {
//如果获取不了逆变器状态 并且逆变器没状态就默认离线
// 如果获取不了逆变器状态 并且逆变器没状态就默认离线
if (jpCollector.getState() == null) {
jpCollector.setState("离线");
}
......
......@@ -13,6 +13,7 @@ import com.yeejoin.amos.boot.module.jxiop.biz.Enum.WarningPeriodEnum;
import com.yeejoin.amos.boot.module.jxiop.biz.service.IPermissionService;
import com.yeejoin.amos.boot.module.jxiop.biz.tdengine.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
......@@ -241,26 +242,25 @@ public class TDBigScreenAnalyseController extends BaseController {
List<Integer> jgList = new ArrayList<>();
List<String> list = new ArrayList<>();
FeignClientResult<List<CompanyModel>> listFeignClientResult = Privilege.companyClient.queryAgencyList("AREA");
List<CompanyModel> companyModels = new ArrayList<>();
if (!ObjectUtils.isEmpty(listFeignClientResult)) {
if (listFeignClientResult.getStatus() == 200) {
companyModels = listFeignClientResult.getResult();
} else {
throw new RuntimeException(listFeignClientResult.getMessage());
}
}
List<String> collect = companyModels.stream().map(t -> t.getCompanyName()).collect(Collectors.toList());
// FeignClientResult<List<CompanyModel>> listFeignClientResult = Privilege.companyClient.queryAgencyList("AREA");
//
// List<CompanyModel> companyModels = new ArrayList<>();
//
// if (!ObjectUtils.isEmpty(listFeignClientResult)) {
// if (listFeignClientResult.getStatus() == 200) {
// companyModels = listFeignClientResult.getResult();
// } else {
// throw new RuntimeException(listFeignClientResult.getMessage());
// }
// }
// List<String> collect = companyModels.stream().map(t -> t.getCompanyName()).collect(Collectors.toList());
if ("idx_biz_fan_warning_record".equals(tableName)) {
list = collect;
// list = Arrays.asList("华中片区", "西北片区", "西南片区", "华南片区", "华东片区", "东北片区", "华北片区");
// list = collect;
list = Arrays.asList("华中区域", "西北区域", "西南区域", "华南区域", "华东区域", "东北区域", "华北区域");
} else {
list = collect;
Collections.reverse(list);
// list = Arrays.asList("华北片区", "东北片区", "华东片区", "华南片区", "西南片区", "西北片区", "华中片区");
// list = collect;
list = Arrays.asList("华北区域", "东北区域", "华东区域", "华南区域", "西南区域", "西北区域", "华中区域");
}
list.forEach(item -> {
wxList.add(wxMap.getOrDefault(item, 0));
......@@ -295,18 +295,22 @@ public class TDBigScreenAnalyseController extends BaseController {
List<String> list = new ArrayList<>();
FeignClientResult<List<CompanyModel>> listFeignClientResult = Privilege.companyClient.queryAgencyList("AREA");
// FeignClientResult<List<CompanyModel>> listFeignClientResult = Privilege.companyClient.queryAgencyList("AREA");
//
// List<CompanyModel> companyModels = new ArrayList<>();
//
// if (!ObjectUtils.isEmpty(listFeignClientResult)) {
// if (listFeignClientResult.getStatus() == 200) {
// companyModels = listFeignClientResult.getResult();
// } else {
// throw new RuntimeException(listFeignClientResult.getMessage());
// }
// }
// list = companyModels.stream().map(CompanyModel::getCompanyName).collect(Collectors.toList());
//
list = Arrays.asList("华北区域", "东北区域", "华东区域", "华南区域", "西南区域", "西北区域", "华中区域");
List<CompanyModel> companyModels = new ArrayList<>();
if (!ObjectUtils.isEmpty(listFeignClientResult)) {
if (listFeignClientResult.getStatus() == 200) {
companyModels = listFeignClientResult.getResult();
} else {
throw new RuntimeException(listFeignClientResult.getMessage());
}
}
list = companyModels.stream().map(CompanyModel::getCompanyName).collect(Collectors.toList());
List<Object> seriesData = new ArrayList<>();
list.forEach(item -> seriesData.add(collect.getOrDefault(item, 100.0)));
resultMap.put("axisData", list);
......@@ -337,6 +341,10 @@ public class TDBigScreenAnalyseController extends BaseController {
}
Integer count = fanWaringRecordMapper.getEquipWarningInfoByPageCount(arae, station, stationType, warningName,
stationId, startDate, endDate);
//前端存在分页bug 此处限制分页后筛选导致页面超出问题
if (count > 0 && current > (count/10 + 1)){
current = 1;
}
// List<IdxBizFanWarningRecord> idxBizFanWarningRecordIPage =
// idxBizFanWarningRecordMapper.getEquipWarningInfoByPage(arae, station,
// stationType, (current - 1) * size, size, warningName, stationId, startDate,
......@@ -347,6 +355,7 @@ public class TDBigScreenAnalyseController extends BaseController {
Page<FanWarningRecord> idxBizFanWarningRecordPage = new Page<>(current, size);
idxBizFanWarningRecordPage.setRecords(idxBizFanWarningRecordIPage);
idxBizFanWarningRecordPage.setTotal(count);
idxBizFanWarningRecordPage.setCurrent(current);
return ResponseHelper.buildResponse(idxBizFanWarningRecordPage);
}
......@@ -816,9 +825,11 @@ public class TDBigScreenAnalyseController extends BaseController {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String nameByIndexAddress = idxBizFanHealthIndexMapper.getPointNameByIndexAddress(indexAddress, tableName,
stationBasic.getFanGatewayId());
int num = 0 ;
if (StringUtils.isNotEmpty(tableName2)){
num = idxBizFanHealthIndexMapper.getIsWarningByPointId(indexAddress, stationBasic.getFanGatewayId(), tableName2);
}
int num = idxBizFanHealthIndexMapper.getIsWarningByPointId(indexAddress, stationBasic.getFanGatewayId(),
tableName2);
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("text", nameByIndexAddress);
......
......@@ -167,7 +167,12 @@ public class TdengineTimeServiceImpl {
levelDesc = item.getHealthLevel();
break;
}
if (healthIndex == 0 && item.getGroupLowerLimit() == healthIndex){
levelDesc = item.getHealthLevel();
break;
}
}
return levelDesc;
}
......
......@@ -290,7 +290,7 @@
<where>
ANALYSIS_OBJ_TYPE = '场站'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="areaCode != null and areaCode != ''">
AND ARAE like concat('%', #{areaCode}, '%')
</if>
......@@ -306,7 +306,7 @@
<where>
ANALYSIS_OBJ_TYPE = '场站'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="areaCode != null and areaCode != ''">
AND ARAE like concat('%', #{areaCode}, '%')
</if>
......@@ -453,7 +453,7 @@
<where>
ANALYSIS_OBJ_TYPE = '子系统'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="equipmentName != null and equipmentName != ''">
AND EQUIPMENT_NAME like concat( '%', #{equipmentName} ,'风机')
</if>
......@@ -490,7 +490,7 @@
<where>
ANALYSIS_OBJ_TYPE = '设备'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="gatewayId != null and gatewayId != ''">
AND GATEWAY_ID = #{gatewayId}
</if>
......@@ -608,7 +608,7 @@
<where>
ANALYSIS_OBJ_TYPE = '子阵'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="gatewayId != null and gatewayId != ''">
AND GATEWAY_ID = #{gatewayId}
</if>
......@@ -625,7 +625,7 @@
<where>
ANALYSIS_OBJ_TYPE = '设备'
AND ANALYSIS_TYPE = '按天'
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE
AND DATE_FORMAT( REC_DATE, "%Y-%m-%d" ) = CURRENT_DATE - INTERVAL 1 DAY
<if test="subarray != null and subarray != ''">
AND SUBARRAY = concat('#', #{subarray})
</if>
......
......@@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
@FeignClient(name = "${amos.idx.name:AMOS-IDX}", path = "idx", configuration = {FeignConfiguration.class})
......@@ -24,4 +28,23 @@ public interface IdxFeign {
@GetMapping("/table/getPage")
FeignClientResult<Page<Map<String, Object>>> getPage(@RequestParam Map<String, Object> map);
@RequestMapping(value = "/publicAnalysis/getStationMessage", method = RequestMethod.GET, consumes = "application/json")
FeignClientResult<List<Map<String, Object>>> getStationMark(@RequestParam(value = "code") String code);
@RequestMapping(value = "/publicAnalysis/appletSroce", method = RequestMethod.GET, consumes = "application/json")
Map<String, Object> getStationMarkList(@RequestParam(value = "code") String code,
@RequestParam(value = "pageNumber") String pageNumber,
@RequestParam(value = "pageSize") String pageSize);
@RequestMapping(value = "/jxIopAnalysis/stationRanking", method = RequestMethod.GET, consumes = "application/json")
FeignClientResult<Map<String, Object>> stationRanking(@RequestParam("pageNumber") Long pageNumber,
@RequestParam("pageSize") Long pageSize,
@RequestParam(required = false, value = "stationType") String type,
@RequestParam(required = false, value = "parentCode") String parentCode);
}
......@@ -69,4 +69,8 @@ public interface StationBasicMapper extends BaseMapper<StationBasic> {
*/
List<StationBasicDto> getStationBasicListAll();
StationBasicDto getStationInfoByCode(@Param("stationCode")String stationCode);
List<StationBasicDto> getStationsByAreaCode(@Param("areaCode")String stationCode);
}
......@@ -192,4 +192,25 @@
FROM
station_basic
</select>
<select id="getStationInfoByCode" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto">
select
*
from
station_basic
where
station_code = #{stationCode}
</select>
<select id="getStationsByAreaCode" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto">
select
*
from
station_basic
where
area_code = #{areaCode}
and
is_delete = 0
</select>
</mapper>
package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import cn.hutool.core.map.MapBuilder;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.CommonMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.EarningsForecastImpl;
import org.apache.http.client.HttpClient;
import org.elasticsearch.action.get.GetResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.toJSONString;
import static java.lang.Boolean.TRUE;
@RestController
@RequestMapping("earningsForecast")
public class EarningsForecastController {
@Autowired
private StationBasicMapper stationBasicMapper;
@Autowired
private EarningsForecastImpl earningsForecast;
@RequestMapping(value = "earningsForecast",method = RequestMethod.GET)
@TycloudOperation(needAuth = false,ApiLevel = UserType.AGENCY)
public ResponseModel<Object> earningsForecast (@RequestParam(required = true,value = "stationId") Long stationId,
@RequestParam(required = true,value = "type") String type){
return ResponseHelper.buildResponse(earningsForecast.earningsForecast(stationId,type));
}
@RequestMapping(value = "getStationListByArae",method = RequestMethod.GET)
@TycloudOperation(needAuth = false,ApiLevel = UserType.AGENCY)
public ResponseModel<List<Map<String,Object>>> getStationListByArae(String araeCode,String stationType){
List<Map<String,Object>> maps = new ArrayList<>();
if (stationType.equals("FDZ")){
stationBasicMapper.getStationsByAreaCode(araeCode).stream().filter(a->a.getStationType().equals(stationType)).forEach(e->{
maps.add(MapBuilder.<String,Object>create().put("text",e.getStationName()).put("value",e.getSequenceNbr()).build());
});
}else {
stationBasicMapper.getStationsByAreaCode(araeCode).stream().filter(a->!a.getStationType().equals(stationType)).forEach(e->{
maps.add(MapBuilder.<String,Object>create().put("text",e.getStationName()).put("value",e.getSequenceNbr()).build());
});
}
return ResponseHelper.buildResponse(maps);
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
public interface CommonMapper {
List<Map<String,String>> selectAgo10Month();
List<Map<String,String>> selectLast3Month();
}
......@@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Sum;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
......@@ -423,7 +424,7 @@ public class CommonServiceImpl {
return null;
}
public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Class<T> tClass, Map<String, String> likeQuerCondtion) {
public <T> TreeMap<String, Double> getListDataByCondtionsSum(Map<String, List<String>> mustQuerCondtion, List<Map<String, String>> shouldQuerCondtion, Class<T> tClass, Map<String, String> likeQuerCondtion) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(mustQuerCondtion)) {
for (String key : mustQuerCondtion.keySet()) {
......@@ -432,9 +433,14 @@ public class CommonServiceImpl {
}
}
if (!ObjectUtils.isEmpty(shouldQuerCondtion)) {
for (String key : shouldQuerCondtion.keySet()) {
queryBuilder.should(QueryBuilders.wildcardQuery(key, shouldQuerCondtion.get(key)));
}
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
shouldQuerCondtion.forEach(e->{
for (String key : e.keySet()) {
boolQueryBuilder.should(QueryBuilders.wildcardQuery(key, e.get(key)));
}
});
boolQueryBuilder.minimumShouldMatch(1);
queryBuilder.must(boolQueryBuilder);
}
if (!ObjectUtils.isEmpty(likeQuerCondtion)) {
......@@ -442,15 +448,33 @@ public class CommonServiceImpl {
queryBuilder.must(QueryBuilders.wildcardQuery(key, "*" + likeQuerCondtion.get(key) + "*"));
}
}
// 如果只对一个字段进行分组写一个就好
TermsAggregationBuilder tb1 = AggregationBuilders.terms("group_day").field("day.keyword");// gatewayId
tb1.subAggregation(AggregationBuilders.sum("sum_valueDouble").field("value"));
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.withQuery(queryBuilder).addAggregation(tb1)
.build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, tClass);
if (search.hasSearchHits()) {
List<SearchHit<T>> searchHitList = search.getSearchHits();
List<T> list = searchHitList.stream().map(hit -> hit.getContent()).collect(Collectors.toList());
return list;
Terms groupDayAgg = search.getAggregations().get("group_day");
TreeMap<String, Double> groupedSums = new TreeMap<>();
for (Terms.Bucket entry : groupDayAgg.getBuckets()) {
// 获取分组的键(即 "day" 字段的值)
String day = entry.getKeyAsString();
// 获取该分组下的 "sum_valueDouble" 聚合结果
Sum sumAgg = entry.getAggregations().get("sum_valueDouble");
double sumValue = sumAgg.getValue();
// 在这里处理每个分组和对应的总和
// 例如,你可以将它们存储在一个Map中,键是日期,值是总和
groupedSums.put(day, sumValue);
}
return groupedSums;
}
return null;
}
......
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.CommonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class EarningsForecastImpl {
@Autowired
private CommonServiceImpl commonService;
@Autowired
private CommonMapper commonMapper;
@Value("${forecast.url}")
private String forecastUrl;
@Autowired
private StationBasicMapper stationBasicMapper;
public Object earningsForecast (Long stationId, String type){
List<Map<String, String>> list = commonMapper.selectAgo10Month();
List<Map<String, String>> lastThreeMonth = commonMapper.selectLast3Month();
Map<String, List<String>> queryCondtion1 = new HashMap<>();
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
if (type.equals("FDZ")){
queryCondtion1.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
}else {
queryCondtion1.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getBoosterGatewayId()));
}
List<Map<String, String>> objects = new ArrayList<>();
TreeMap<String, String> months= new TreeMap<>();
list.forEach(e->{
Map<String, String> likeQueryCondtion = new HashMap<>();
likeQueryCondtion.put("id.keyword",e.get("MonthYear")+"*");
objects.add(likeQueryCondtion);
String key = e.get("MonthYear").split("-")[1];
months.put(String.valueOf(Integer.parseInt(key)),e.get("MonthYear"));
});
TreeMap<String, Double> map = commonService.getListDataByCondtionsSum(queryCondtion1,objects, ESMoonPowerGeneration.class,null);
TreeMap<String, Double> carbonDioxide = new TreeMap<>();
TreeMap<String, Double> standardCoal = new TreeMap<>();
TreeMap<String, Double> toner = new TreeMap<>();
TreeMap<String, Double> sulfurDioxide = new TreeMap<>();
//计算历史月发电量的收益
map.keySet().forEach(e->{
carbonDioxide.put(months.get(e), Double.valueOf(String.format("%.3f",map.get(e) * CommonConstans.carbonDioxide)));
standardCoal.put(months.get(e),Double.valueOf(String.format("%.3f",map.get(e) * CommonConstans.standardCoal)));
toner.put(months.get(e),Double.valueOf(String.format("%.3f",map.get(e) * CommonConstans.toner)));
sulfurDioxide.put(months.get(e),Double.valueOf(String.format("%.3f",map.get(e) * CommonConstans.sulfurDioxide)));
});
List<TreeMap<String,List<List<String>>>> resultList = new ArrayList<>();
TreeMap<String,List<List<String>>> Co2Map = new TreeMap();
TreeMap<String,List<List<String>>> standardCoalMap = new TreeMap();
TreeMap<String,List<List<String>>> tonerMap = new TreeMap();
TreeMap<String,List<List<String>>> sulfurDioxideMap = new TreeMap();
TreeMap<String,List<List<String>>> Co2ForecastMap = new TreeMap();
TreeMap<String,List<List<String>>> standardCoalForecastMap = new TreeMap();
TreeMap<String,List<List<String>>> tonerForecastMap = new TreeMap();
TreeMap<String,List<List<String>>> sulfurDioxideForecastMap = new TreeMap();
//组装历史数据折线图数据
List<List<String>> Co2List = this.buildResultData(carbonDioxide);
Co2Map.put("data",Co2List);
List<List<String>> standardCoalList = this.buildResultData(standardCoal);
standardCoalMap.put("data",standardCoalList);
List<List<String>> tonerList = this.buildResultData(toner);
tonerMap.put("data",tonerList);
List<List<String>> sulfurDioxideList = this.buildResultData(sulfurDioxide);
sulfurDioxideMap.put("data",sulfurDioxideList);
//查询预测收益接口
JSONObject carbonDioxideData = getResponse("二氧化碳减排量", carbonDioxide.values().stream().collect(Collectors.toList()));
JSONObject standardCoalData = getResponse("标准煤减排量", standardCoal.values().stream().collect(Collectors.toList()));
JSONObject tonerData = getResponse("炭粉尘减排量", toner.values().stream().collect(Collectors.toList()));
JSONObject sulfurDioxideData = getResponse("二氧化硫减排量", sulfurDioxide.values().stream().collect(Collectors.toList()));
//将预测返回的数据组装成组件需要的格式
List<List<String>> carbonDioxideList = this.buildData(lastThreeMonth, carbonDioxideData, Co2List);
Co2ForecastMap.put("data",carbonDioxideList);
List<List<String>> standardCoalLists = this.buildData(lastThreeMonth, standardCoalData, standardCoalList);
standardCoalForecastMap.put("data",standardCoalLists);
List<List<String>> tonerLists = this.buildData(lastThreeMonth, tonerData, tonerList);
tonerForecastMap.put("data",tonerLists);
List<List<String>> sulfurDioxideLists = this.buildData(lastThreeMonth, sulfurDioxideData, sulfurDioxideList);
sulfurDioxideForecastMap .put("data",sulfurDioxideLists);
resultList.add(Co2Map);
resultList.add(standardCoalMap);
resultList.add(tonerMap);
resultList.add(sulfurDioxideMap);
resultList.add(Co2ForecastMap);
resultList.add(standardCoalForecastMap);
resultList.add(tonerForecastMap);
resultList.add(sulfurDioxideForecastMap);
return resultList;
}
List<List<String>> buildResultData( TreeMap<String, Double> map){
List<List<String>> lists = new ArrayList<>();
map.keySet().forEach(e->{
List<String> list = Arrays.asList(e, String.valueOf(map.get(e)));
lists.add(list);
});
return lists;
}
String buildParams(String name, List<Double> values){
HashMap<Object, Object> requestParams = new HashMap<>();
HashMap<Object, Object> valueLabel = new HashMap<>();
HashMap<Object, Object> value = new HashMap<>();
value.put("值",values);
valueLabel.put(name,value);
value.put("名称",name);
HashMap<Object, Object> params = new HashMap<>();
HashMap<Object, Object> basic = new HashMap<>();
HashMap<Object, Object> dispPrecision = new HashMap<>();
dispPrecision.put("disp_precision",3);
params.put("config",dispPrecision);
basic.put("data",name);
basic.put("seasonal_length",values.size()/2);
basic.put("model_type","additive");
basic.put("model_component_type","seasonal_only");
basic.put("is_generate_forecast",true);
basic.put("forecast_number","3");
params.put("basic",basic);
requestParams.put("params",params);
requestParams.put("dataset",valueLabel);
return JSON.toJSONString(requestParams);
}
JSONObject getResponse(String name, List<Double> values){
String requestParam=buildParams(name,values);
Map<String, String> hashMaphead = new HashMap<>();
hashMaphead.put("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
String respone = HttpUtil.createPost(forecastUrl).headerMap(hashMaphead, false).
body(requestParam).execute().body();
return JSONObject.parseObject(respone);
}
List<List<String>> buildData(List<Map<String, String>> data,JSONObject obj,List<List<String>> lists ){
List<List<String>> newList = new ArrayList<>();
newList.addAll(lists);
JSONObject dataObject = obj.getJSONObject("data");
// 从data对象中提取forecast和history数组
JSONArray forecastArray = dataObject.getJSONArray("forecast");
for (int i = 0; i < forecastArray.size(); i++) {
List<String> list = Arrays.asList(data.get(i).get("MonthYear"),forecastArray.getString(i));
newList.add(list);
}
return newList;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.jxiop.biz.mapper2.CommonMapper">
<select id="selectAgo10Month" resultType="map">
WITH RECURSIVE month_sequence AS (
SELECT 0 AS num
UNION ALL
SELECT num + 1 FROM month_sequence WHERE num &lt; 9
)
SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL (num + 1) MONTH), '%Y-%m') AS MonthYear
FROM month_sequence
ORDER BY MonthYear DESC;
</select>
<select id="selectLast3Month" resultType="map">
WITH RECURSIVE month_sequence AS (
SELECT 0 AS num
UNION ALL
SELECT num + 1 FROM month_sequence WHERE num &lt; 2
)
SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL -(num ) MONTH), '%Y-%m') AS MonthYear
FROM month_sequence
ORDER BY MonthYear ASC;
</select>
</mapper>
package com.yeejoin.amos.boot.module.jxiop.api.amosprojectmapper;
public interface CompanyMapper {
public String getAreaCompanyCode(String code);
}
package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.util.CommonResponse;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.AppletMonitorServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.MonitorFanIndicatorImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.tdmapper.IndicatorDataMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.*;
@RestController
@Api(tags = "小程序-监盘")
@RequestMapping(value = "/applet")
public class AppletMonitorController {
@Autowired
AppletMonitorServiceImpl appletMonitorService;
@Autowired
StationBasicMapper stationBasicMapper;
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图-总概览")
@GetMapping("/CockpitData")
public ResponseModel<Map<String, Object>> getData(@RequestParam(value = "code") String code,
@RequestParam(value = "level") String level) {
if ("station".equals(level)){
StationBasicDto stationBasic = stationBasicMapper.getStationInfoByCode(code);
if (stationBasic.getStationType().equals("FDZ")) {
return ResponseHelper.buildResponse(appletMonitorService.getFanStationInfo(stationBasic));
}else {
return ResponseHelper.buildResponse(appletMonitorService.getPvStationInfo(stationBasic));
}
}else {
return ResponseHelper.buildResponse(appletMonitorService.getAreaInfo(code));
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.jxiop.api.amosprojectmapper.CompanyMapper">
<select id="getAreaCompanyCode" resultType="string">
select
ORG_CODE
from
privilege_company
where
COMPANY_CODE = #{code}
and
LEVEL = 'area'
and IS_DELETED = 0
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment