|
|
@ -4,10 +4,11 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
import com.thing.qingyuan.carbon.dto.QyCcerSumInfoDTO; |
|
|
|
|
|
|
|
|
import com.thing.qingyuan.carbon.dto.QyCcerInfoDTO; |
|
|
import com.thing.qingyuan.carbon.entity.QyCcerInfoEntity; |
|
|
import com.thing.qingyuan.carbon.entity.QyCcerInfoEntity; |
|
|
import com.thing.qingyuan.carbon.mapper.QyCcerInfoMapper; |
|
|
import com.thing.qingyuan.carbon.mapper.QyCcerInfoMapper; |
|
|
import com.thing.qingyuan.carbon.service.QyCcerInfoService; |
|
|
import com.thing.qingyuan.carbon.service.QyCcerInfoService; |
|
|
|
|
|
import com.thing.qingyuan.carbon.util.Constant; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
@ -83,19 +84,19 @@ public class QyCcerInfoServiceImpl extends BaseServiceImpl<QyCcerInfoMapper, QyC |
|
|
@Override |
|
|
@Override |
|
|
public Map<String, String> countCcerByState() { |
|
|
public Map<String, String> countCcerByState() { |
|
|
QueryWrapper queryWrapper1 = QueryWrapper.create() |
|
|
QueryWrapper queryWrapper1 = QueryWrapper.create() |
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL)) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.eq(QyCcerInfoEntity::getState, "1"); |
|
|
.eq(QyCcerInfoEntity::getState, "1"); |
|
|
//sum1 待申请CCER |
|
|
//sum1 待申请CCER |
|
|
String sum1 = mapper.selectOneByQueryAs(queryWrapper1, String.class); |
|
|
String sum1 = mapper.selectOneByQueryAs(queryWrapper1, String.class); |
|
|
QueryWrapper queryWrapper2 = QueryWrapper.create() |
|
|
QueryWrapper queryWrapper2 = QueryWrapper.create() |
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL)) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.eq(QyCcerInfoEntity::getState, "2"); |
|
|
.eq(QyCcerInfoEntity::getState, "2"); |
|
|
//sum2 已申请CCER |
|
|
//sum2 已申请CCER |
|
|
String sum2 = mapper.selectOneByQueryAs(queryWrapper2, String.class); |
|
|
String sum2 = mapper.selectOneByQueryAs(queryWrapper2, String.class); |
|
|
QueryWrapper queryWrapper3 = QueryWrapper.create() |
|
|
QueryWrapper queryWrapper3 = QueryWrapper.create() |
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL)) |
|
|
.from(QY_CCER_INFO_ENTITY); |
|
|
.from(QY_CCER_INFO_ENTITY); |
|
|
//sum3 累计CCER(sum=sum1+sum2) |
|
|
//sum3 累计CCER(sum=sum1+sum2) |
|
|
String sum3 = mapper.selectOneByQueryAs(queryWrapper3, String.class); |
|
|
String sum3 = mapper.selectOneByQueryAs(queryWrapper3, String.class); |
|
|
@ -106,7 +107,33 @@ public class QyCcerInfoServiceImpl extends BaseServiceImpl<QyCcerInfoMapper, QyC |
|
|
//已申请CCER |
|
|
//已申请CCER |
|
|
temMap.put("applied", StringUtils.isBlank(sum2) ? "0" : sum2); |
|
|
temMap.put("applied", StringUtils.isBlank(sum2) ? "0" : sum2); |
|
|
//累计CCER |
|
|
//累计CCER |
|
|
temMap.put("total1", StringUtils.isBlank(sum3) ? "0" : sum3); |
|
|
|
|
|
|
|
|
temMap.put("total", StringUtils.isBlank(sum3) ? "0" : sum3); |
|
|
|
|
|
|
|
|
|
|
|
// 获取今天的日期 |
|
|
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
|
|
// 将今天的日期转换为 Date 类型 |
|
|
|
|
|
Long startOfDay = today.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
|
|
|
|
|
Long endOfDay = today.atTime(23, 59, 59, 999999999) |
|
|
|
|
|
.atZone(ZoneId.systemDefault()) |
|
|
|
|
|
.toInstant() |
|
|
|
|
|
.toEpochMilli(); |
|
|
|
|
|
|
|
|
|
|
|
QueryWrapper queryWrapperDay = QueryWrapper.create() |
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL)) |
|
|
|
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
|
|
|
.ge(QyCcerInfoEntity::getIssueDate, startOfDay) |
|
|
|
|
|
.le(QyCcerInfoEntity::getIssueDate, endOfDay) |
|
|
|
|
|
; |
|
|
|
|
|
String todayTotal = mapper.selectOneByQueryAs(queryWrapperDay, String.class); |
|
|
|
|
|
temMap.put("todayTotal", StringUtils.isBlank(todayTotal) ? "0" : todayTotal); |
|
|
|
|
|
QueryWrapper queryWrapperDay1 = QueryWrapper.create() |
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.PRICE)) |
|
|
|
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
|
|
|
.ge(QyCcerInfoEntity::getIssueDate, startOfDay) |
|
|
|
|
|
.le(QyCcerInfoEntity::getIssueDate, endOfDay) |
|
|
|
|
|
; |
|
|
|
|
|
String todayPriceTotal = mapper.selectOneByQueryAs(queryWrapperDay1, String.class); |
|
|
|
|
|
temMap.put("todayPriceTotal", StringUtils.isBlank(todayPriceTotal) ? "0" : todayPriceTotal); |
|
|
return temMap; |
|
|
return temMap; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -116,34 +143,32 @@ public class QyCcerInfoServiceImpl extends BaseServiceImpl<QyCcerInfoMapper, QyC |
|
|
* @return 返回所有指定小镇的减排量占比 |
|
|
* @return 返回所有指定小镇的减排量占比 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public List<Map<String, String>> getEmissionReductionPercentagesByState() { |
|
|
|
|
|
// 示例区域列表,可根据实际情况查询数据库中的区域列表 |
|
|
|
|
|
List<String> regions = Arrays.asList("天玉镇", "河东街道", "富滩镇", "值夏镇", "文陂镇", "富田镇", "东固畲族乡", "新圩镇"); |
|
|
|
|
|
|
|
|
public List<Map<String, String>> getByRegion() { |
|
|
// 根据区域查询成交量总和 |
|
|
// 根据区域查询成交量总和 |
|
|
QueryWrapper queryWrapper = QueryWrapper.create() |
|
|
QueryWrapper queryWrapper = QueryWrapper.create() |
|
|
.select(QY_CCER_INFO_ENTITY.REGION, sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
.select(QY_CCER_INFO_ENTITY.REGION, sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.from(QY_CCER_INFO_ENTITY) |
|
|
.groupBy(QY_CCER_INFO_ENTITY.REGION); |
|
|
.groupBy(QY_CCER_INFO_ENTITY.REGION); |
|
|
// 查询符合条件的小镇成交量数据 |
|
|
// 查询符合条件的小镇成交量数据 |
|
|
List<QyCcerSumInfoDTO> quotaList1 = mapper.selectListByQueryAs(queryWrapper, QyCcerSumInfoDTO.class); |
|
|
|
|
|
|
|
|
List<QyCcerInfoDTO> quotaList1 = mapper.selectListByQueryAs(queryWrapper, QyCcerInfoDTO.class); |
|
|
//查询总量 |
|
|
//查询总量 |
|
|
QueryWrapper queryWrapper2 = QueryWrapper.create() |
|
|
QueryWrapper queryWrapper2 = QueryWrapper.create() |
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.TOTAL)) |
|
|
.from(QY_CCER_INFO_ENTITY); |
|
|
.from(QY_CCER_INFO_ENTITY); |
|
|
String sumTotal = mapper.selectOneByQueryAs(queryWrapper2, String.class); |
|
|
String sumTotal = mapper.selectOneByQueryAs(queryWrapper2, String.class); |
|
|
// 存储最终结果 |
|
|
// 存储最终结果 |
|
|
List<Map<String, String>> resultList = new ArrayList<>(); |
|
|
List<Map<String, String>> resultList = new ArrayList<>(); |
|
|
List<String> tempRegions = Lists.newArrayList(); |
|
|
List<String> tempRegions = Lists.newArrayList(); |
|
|
for (QyCcerSumInfoDTO quotaInfoDTO : quotaList1) { |
|
|
|
|
|
|
|
|
for (QyCcerInfoDTO quotaInfoDTO : quotaList1) { |
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
//占比 |
|
|
//占比 |
|
|
tempMap.put("percent", new BigDecimal(quotaInfoDTO.getTotal()).divide(new BigDecimal(sumTotal), 2, RoundingMode.HALF_UP).toString()); |
|
|
|
|
|
tempMap.put("region", quotaInfoDTO.getBelongRegion()); |
|
|
|
|
|
|
|
|
tempMap.put("percent", quotaInfoDTO.getTotal().divide(new BigDecimal(sumTotal), 2, RoundingMode.HALF_UP).toString()); |
|
|
|
|
|
tempMap.put("region", quotaInfoDTO.getRegion()); |
|
|
resultList.add(tempMap); |
|
|
resultList.add(tempMap); |
|
|
tempRegions.add(quotaInfoDTO.getBelongRegion()); |
|
|
|
|
|
|
|
|
tempRegions.add(quotaInfoDTO.getRegion()); |
|
|
} |
|
|
} |
|
|
//差集 |
|
|
//差集 |
|
|
Collection<String> disjunction = CollectionUtil.disjunction(regions, tempRegions); |
|
|
|
|
|
|
|
|
Collection<String> disjunction = CollectionUtil.disjunction(Constant.REGIONS, tempRegions); |
|
|
for (String s : disjunction) { |
|
|
for (String s : disjunction) { |
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
tempMap.put("percent", "0"); |
|
|
tempMap.put("percent", "0"); |
|
|
@ -154,39 +179,5 @@ public class QyCcerInfoServiceImpl extends BaseServiceImpl<QyCcerInfoMapper, QyC |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取今日的总成交量和总成交金额 |
|
|
|
|
|
* |
|
|
|
|
|
* @return 今日的总成交量和总成交金额 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public QyCcerSumInfoDTO getTodayTotalTransactionVolumeAndPriceByTime() { |
|
|
|
|
|
// 获取今天的日期 |
|
|
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
|
|
// 将今天的日期转换为 Date 类型 |
|
|
|
|
|
Long startOfDay = today.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
|
|
|
|
|
Long endOfDay = today.atTime(23, 59, 59, 999999999) |
|
|
|
|
|
.atZone(ZoneId.systemDefault()) |
|
|
|
|
|
.toInstant() |
|
|
|
|
|
.toEpochMilli(); |
|
|
|
|
|
// 查询今天的总成交量和总成交金额 |
|
|
|
|
|
QueryWrapper queryWrapper = QueryWrapper.create() |
|
|
|
|
|
.select(sum(QY_CCER_INFO_ENTITY.ISSUE_DATE).as("recordEmission"), |
|
|
|
|
|
sum(QY_CCER_INFO_ENTITY.PRICE).as("price")) |
|
|
|
|
|
.ge(QyCcerInfoEntity::getIssueDate, startOfDay) |
|
|
|
|
|
.le(QyCcerInfoEntity::getIssueDate, endOfDay) |
|
|
|
|
|
.from(QY_CCER_INFO_ENTITY); |
|
|
|
|
|
|
|
|
|
|
|
// 执行查询,返回结果 |
|
|
|
|
|
QyCcerSumInfoDTO qyCcerSumInfoDTO = mapper.selectOneByQueryAs(queryWrapper, QyCcerSumInfoDTO.class); |
|
|
|
|
|
if (qyCcerSumInfoDTO == null) { |
|
|
|
|
|
qyCcerSumInfoDTO = new QyCcerSumInfoDTO(); |
|
|
|
|
|
qyCcerSumInfoDTO.setRecordEmission(0.0); |
|
|
|
|
|
qyCcerSumInfoDTO.setPrice(0.0); |
|
|
|
|
|
} |
|
|
|
|
|
return qyCcerSumInfoDTO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|