|
|
|
@ -5,10 +5,11 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
|
import com.thing.qingyuan.carbon.dto.QyGreenSumInfoDTO; |
|
|
|
import com.thing.qingyuan.carbon.dto.QyGreenCertificateInfoDTO; |
|
|
|
import com.thing.qingyuan.carbon.entity.QyGreenCertificateInfoEntity; |
|
|
|
import com.thing.qingyuan.carbon.mapper.QyGreenCertificateInfoMapper; |
|
|
|
import com.thing.qingyuan.carbon.service.QyGreenCertificateInfoService; |
|
|
|
import com.thing.qingyuan.carbon.util.Constant; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
@ -49,29 +50,51 @@ public class QyGreenCertificateInfoServiceImpl extends BaseServiceImpl<QyGreenCe |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取根据状态统计的绿证数量 |
|
|
|
* |
|
|
|
* @return 各状态的绿证数量 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, String> countGreenByState() { |
|
|
|
QueryWrapper queryWrapper1 = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL)) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY) |
|
|
|
.eq(QyGreenCertificateInfoEntity::getState,"1"); |
|
|
|
.eq(QyGreenCertificateInfoEntity::getState, "1"); |
|
|
|
//sum1 为待发放绿证 |
|
|
|
String sum1 = mapper.selectOneByQueryAs(queryWrapper1,String.class); |
|
|
|
String sum1 = mapper.selectOneByQueryAs(queryWrapper1, String.class); |
|
|
|
|
|
|
|
QueryWrapper queryWrapper2 = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL)) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY) |
|
|
|
.eq(QyGreenCertificateInfoEntity::getState,"2"); |
|
|
|
.eq(QyGreenCertificateInfoEntity::getState, "2"); |
|
|
|
//sum1 为已申请绿证 |
|
|
|
String sum2 = mapper.selectOneByQueryAs(queryWrapper2,String.class); |
|
|
|
String sum2 = mapper.selectOneByQueryAs(queryWrapper2, String.class); |
|
|
|
|
|
|
|
QueryWrapper queryWrapper3 = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY); |
|
|
|
//sum1 为累计绿证 (sum=sum1+sum2) |
|
|
|
String sum = mapper.selectOneByQueryAs(queryWrapper3,String.class); |
|
|
|
String sum = mapper.selectOneByQueryAs(queryWrapper3, String.class); |
|
|
|
// 获取今天的日期 |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
Long startOfDay = today.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
|
|
|
Long endOfDay = today.atTime(23, 59, 59, 999999999) |
|
|
|
.atZone(ZoneId.systemDefault()) |
|
|
|
.toInstant() |
|
|
|
.toEpochMilli(); |
|
|
|
|
|
|
|
QueryWrapper queryWrapperPrice = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.PRICE)) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY) |
|
|
|
.ge(QyGreenCertificateInfoEntity::getIssueDate, startOfDay) |
|
|
|
.le(QyGreenCertificateInfoEntity::getIssueDate, endOfDay); |
|
|
|
String sum2Price = mapper.selectOneByQueryAs(queryWrapperPrice, String.class); |
|
|
|
|
|
|
|
QueryWrapper queryWrapperTotal = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL)) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY) |
|
|
|
.ge(QyGreenCertificateInfoEntity::getIssueDate, startOfDay) |
|
|
|
.le(QyGreenCertificateInfoEntity::getIssueDate, endOfDay); |
|
|
|
String sum2Total = mapper.selectOneByQueryAs(queryWrapperTotal, String.class); |
|
|
|
|
|
|
|
Map<String, String> temMap = new HashMap<>(); |
|
|
|
//待发放绿证 |
|
|
|
@ -79,25 +102,26 @@ public class QyGreenCertificateInfoServiceImpl extends BaseServiceImpl<QyGreenCe |
|
|
|
//已申请绿证 |
|
|
|
temMap.put("applied", StringUtils.isBlank(sum2) ? "0" : sum2); |
|
|
|
//累计绿证 |
|
|
|
temMap.put("total1", StringUtils.isBlank(sum) ? "0" : sum); |
|
|
|
temMap.put("total", StringUtils.isBlank(sum) ? "0" : sum); |
|
|
|
temMap.put("todayPrice", StringUtils.isBlank(sum2Price) ? "0" : sum2Price); |
|
|
|
temMap.put("todayTotal", StringUtils.isBlank(sum2Total) ? "0" : sum2Total); |
|
|
|
return temMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据区域与小镇统计绿证,并计算每个小镇在所属区域内的绿证占比 |
|
|
|
* @return 返回一个Map,包含每个区域下每个小镇的绿证占比 |
|
|
|
* |
|
|
|
* @return 返回一个Map, 包含每个区域下每个小镇的绿证占比 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<Map<String, String>> getRegionGreenCertificatePercentage() { |
|
|
|
// 示例区域列表,可根据实际情况查询数据库中的区域列表 |
|
|
|
List<String> regions = Arrays.asList("天玉镇", "河东街道", "富滩镇", "值夏镇", "文陂镇", "富田镇", "东固畲族乡", "新圩镇"); |
|
|
|
// 根据区域查询成绿证总和 |
|
|
|
QueryWrapper queryWrapper = QueryWrapper.create() |
|
|
|
.select(QY_GREEN_CERTIFICATE_INFO_ENTITY.REGION,sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
.select(QY_GREEN_CERTIFICATE_INFO_ENTITY.REGION, sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY) |
|
|
|
.groupBy(QY_GREEN_CERTIFICATE_INFO_ENTITY.REGION); |
|
|
|
// 查询符合条件的小镇绿证数据 |
|
|
|
List<QyGreenSumInfoDTO> qyGreenSumInfoDTOList = mapper.selectListByQueryAs(queryWrapper, QyGreenSumInfoDTO.class); |
|
|
|
List<QyGreenCertificateInfoDTO> qyGreenSumInfoDTOList = mapper.selectListByQueryAs(queryWrapper, QyGreenCertificateInfoDTO.class); |
|
|
|
//查询绿证总能源量 |
|
|
|
QueryWrapper queryWrapper6 = QueryWrapper.create() |
|
|
|
.select(sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("total")) |
|
|
|
@ -106,59 +130,24 @@ public class QyGreenCertificateInfoServiceImpl extends BaseServiceImpl<QyGreenCe |
|
|
|
//存储最终结果 |
|
|
|
List<Map<String, String>> resultList = new ArrayList<>(); |
|
|
|
List<String> tempRegions = Lists.newArrayList(); |
|
|
|
for (QyGreenSumInfoDTO qyGreenSumInfoDTO : qyGreenSumInfoDTOList) { |
|
|
|
for (QyGreenCertificateInfoDTO qyGreenSumInfoDTO : qyGreenSumInfoDTOList) { |
|
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
|
//占比 |
|
|
|
tempMap.put("percent", new BigDecimal(qyGreenSumInfoDTO.getTotal()).divide(new BigDecimal(sumTotal), 2, RoundingMode.HALF_UP).toString()); |
|
|
|
tempMap.put("percent", qyGreenSumInfoDTO.getTotal().divide(new BigDecimal(sumTotal), 2, RoundingMode.HALF_UP).toString()); |
|
|
|
tempMap.put("region", qyGreenSumInfoDTO.getRegion()); |
|
|
|
resultList.add(tempMap); |
|
|
|
tempRegions.add(qyGreenSumInfoDTO.getRegion()); |
|
|
|
} |
|
|
|
//差集 |
|
|
|
Collection<String> disjunction = CollectionUtil.disjunction(regions, tempRegions); |
|
|
|
Collection<String> disjunction = CollectionUtil.disjunction(Constant.REGIONS, tempRegions); |
|
|
|
for (String s : disjunction) { |
|
|
|
Map<String, String> tempMap = new HashMap<>(); |
|
|
|
tempMap.put("percent", "0"); |
|
|
|
tempMap.put("region", s); |
|
|
|
resultList.add(tempMap); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultList; |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取今日的总成交量和今日总成交金额 |
|
|
|
* @return 今日的总成交量和今日总成交金额 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public QyGreenSumInfoDTO 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_GREEN_CERTIFICATE_INFO_ENTITY.TOTAL).as("greenTotal"), |
|
|
|
sum(QY_GREEN_CERTIFICATE_INFO_ENTITY.PRICE).as("price")) |
|
|
|
.ge(QyGreenCertificateInfoEntity::getApplicationDate, startOfDay) |
|
|
|
.le(QyGreenCertificateInfoEntity::getApplicationDate, endOfDay) |
|
|
|
.from(QY_GREEN_CERTIFICATE_INFO_ENTITY); |
|
|
|
|
|
|
|
// 执行查询,返回结果 |
|
|
|
QyGreenSumInfoDTO qyGreenSumInfoDTO = mapper.selectOneByQueryAs(queryWrapper, QyGreenSumInfoDTO.class); |
|
|
|
if (qyGreenSumInfoDTO == null) { |
|
|
|
qyGreenSumInfoDTO = new QyGreenSumInfoDTO(); |
|
|
|
qyGreenSumInfoDTO.setGreenTotal(0.0); |
|
|
|
qyGreenSumInfoDTO.setPrice(0.0); |
|
|
|
} |
|
|
|
return qyGreenSumInfoDTO; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|