| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy; |
| | | import com.ruoyi.order.mapper.TChargingOrderAccountingStrategyMapper; |
| | | import com.ruoyi.order.service.TChargingOrderAccountingStrategyService; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Service |
| | | public class TChargingOrderAccountingStrategyServiceImpl extends ServiceImpl<TChargingOrderAccountingStrategyMapper, TChargingOrderAccountingStrategy> implements TChargingOrderAccountingStrategyService { |
| | | |
| | | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取给定天数范围内的充电量统计 |
| | | * @param days 天数 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<List<Map<String, Object>>> getTotalElectricQuantity(Integer days) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - days); |
| | | String startTime = sdf.format(calendar.getTime()) + " 00:00:00"; |
| | | List<TChargingOrder> list = chargingOrderService.list(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getStatus, 5) |
| | | .eq(TChargingOrder::getDelFlag, 0).last(" and end_time between '" + startTime + "' and DATE_FORMAT('%Y-%m-%d %H:%i:%s', now())")); |
| | | List<TChargingOrderAccountingStrategy> list1 = this.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().in(TChargingOrderAccountingStrategy::getChargingOrderId)); |
| | | |
| | | List<List<Map<String, Object>>> list2 = new ArrayList<>(); |
| | | Calendar nowDateTime = Calendar.getInstance(); |
| | | for (int i = days; i >= 0; i--) { |
| | | nowDateTime.set(Calendar.DAY_OF_YEAR, nowDateTime.get(Calendar.DAY_OF_YEAR) - i); |
| | | List<TChargingOrder> collect = list.stream().filter(s -> sdf.format(s.getEndTime()).equals(sdf.format(nowDateTime.getTime()))).collect(Collectors.toList()); |
| | | List<Long> orderIds = collect.stream().map(TChargingOrder::getId).collect(Collectors.toList()); |
| | | |
| | | |
| | | List<Map<String, Object>> datas = new ArrayList<>(); |
| | | Map<String, Object> map1 = new HashMap<>(); |
| | | map1.put("name", "尖"); |
| | | BigDecimal value1 = list1.stream().filter(s -> orderIds.contains(s.getChargingOrderId()) && s.getType() == 1) |
| | | .map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | map1.put("value", value1.setScale(2, RoundingMode.HALF_EVEN)); |
| | | datas.add(map1); |
| | | |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("name", "峰"); |
| | | BigDecimal value2 = list1.stream().filter(s -> orderIds.contains(s.getChargingOrderId()) && s.getType() == 2) |
| | | .map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | map1.put("value", value2.setScale(2, RoundingMode.HALF_EVEN)); |
| | | datas.add(map2); |
| | | |
| | | Map<String, Object> map3 = new HashMap<>(); |
| | | map3.put("name", "平"); |
| | | BigDecimal value3 = list1.stream().filter(s -> orderIds.contains(s.getChargingOrderId()) && s.getType() == 3) |
| | | .map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | map1.put("value", value3.setScale(2, RoundingMode.HALF_EVEN)); |
| | | datas.add(map3); |
| | | |
| | | Map<String, Object> map4 = new HashMap<>(); |
| | | map4.put("name", "谷"); |
| | | BigDecimal value4 = list1.stream().filter(s -> orderIds.contains(s.getChargingOrderId()) && s.getType() == 4) |
| | | .map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | map1.put("value", value4.setScale(2, RoundingMode.HALF_EVEN)); |
| | | datas.add(map4); |
| | | list2.add(datas); |
| | | } |
| | | return list2; |
| | | } |
| | | } |