Commit e5ec5d41 authored by chenzhao's avatar chenzhao

收益预测接口 分析bug修复

parent 60f881c8
......@@ -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>
......@@ -446,14 +446,14 @@
</select>
<select id="getSubSystemInfo" resultType="java.util.Map">
SELECT
round(IFNULL( HEALTH_INDEX, 100 ), 1) AS healthIndex,
round(IFNULL( HEALTH_INDEX, 100 ), 1) AS healthIndex,``
SUB_SYSTEM AS subSystem
FROM
fan_health_index_latest_data
<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>
......
......@@ -209,6 +209,8 @@
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 ){
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));
lists.add(list);
}
return lists;
}
}
<?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>
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