New file |
| | |
| | | package com.ruoyi.order.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.BasePojo; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import com.ruoyi.order.vo.LargeChargingPowerVo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api(tags = "大屏") |
| | | @RestController |
| | | @RequestMapping("/large-screen") |
| | | public class LargeScreenController { |
| | | |
| | | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | | |
| | | |
| | | @SneakyThrows |
| | | @ApiOperation(tags = {"大屏-停车场充电功率曲线图"},value = "停车场充电功率曲线图") |
| | | @GetMapping("/getChargingPower") |
| | | public R<List<LargeChargingPowerVo>> getChargingPower(){ |
| | | String sevenDayAgo = LocalDate.now().minusDays(7) + " 00:00:00"; |
| | | String oneDayAgo = LocalDate.now().minusDays(1) + " 23:59:59"; |
| | | Date oneDayAgoTime = format.parse(oneDayAgo); |
| | | Date sevenDayAgoTime = format.parse(sevenDayAgo); |
| | | ArrayList<LargeChargingPowerVo> largeChargingPowerVos = new ArrayList<>(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | List<TChargingOrder> list1 = chargingOrderService.list(new LambdaQueryWrapper<TChargingOrder>().between(BasePojo::getCreateTime, sevenDayAgoTime, oneDayAgoTime).eq(BasePojo::getDelFlag, 0)); |
| | | |
| | | for (int count = 7; count > 0; count--) { |
| | | LargeChargingPowerVo largeChargingPowerVo = new LargeChargingPowerVo(); |
| | | String time = LocalDate.now().minusDays(count).toString(); |
| | | |
| | | List<TChargingOrder> list = list1.stream().filter(e ->e.getCreateTime().toString().contains(time)).collect(Collectors.toList()); |
| | | if(!list.isEmpty()){ |
| | | System.out.println(list); |
| | | list.stream().forEach(e -> { |
| | | if(e.getChargingPower()==null){ |
| | | e.setChargingPower(BigDecimal.ZERO); |
| | | } |
| | | }); |
| | | BigDecimal powerAverage = list.stream().map(TChargingOrder::getChargingPower).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(list.size()), 0, RoundingMode.HALF_UP); |
| | | largeChargingPowerVo.setPower(powerAverage); |
| | | } |
| | | largeChargingPowerVo.setTime(time); |
| | | largeChargingPowerVos.add(largeChargingPowerVo); |
| | | } |
| | | |
| | | return R.ok(largeChargingPowerVos); |
| | | } |
| | | |
| | | |
| | | |
| | | } |