| | |
| | | package com.ruoyi.order.controller; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.google.common.collect.Lists; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.BasePage; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.ChargingOrderAndUploadRealTimeMonitoringDataDto; |
| | |
| | | import com.ruoyi.order.api.model.*; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | | import com.ruoyi.order.api.query.TChargingCountQuery; |
| | | import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; |
| | | import com.ruoyi.order.api.vo.*; |
| | | import com.ruoyi.order.api.vo.ChargingOrderInfoVO; |
| | | import com.ruoyi.order.api.vo.ChargingOrderVO; |
| | | import com.ruoyi.order.api.vo.GetChargingOrderByLicensePlate; |
| | | import com.ruoyi.order.api.vo.TCharingOrderVO; |
| | | import com.ruoyi.order.dto.GetMyChargingOrderList; |
| | | import com.ruoyi.order.dto.GetNoInvoicedOrder; |
| | |
| | | import com.ruoyi.order.dto.OrderEvaluateVo; |
| | | import com.ruoyi.order.dto.*; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.service.impl.TChargingOrderServiceImpl; |
| | | import com.ruoyi.order.util.PreviousSixMonths; |
| | | import com.ruoyi.order.vo.EndOfChargePageInfo; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.vo.AliQueryOrder; |
| | | import com.ruoyi.payment.api.vo.WxRefundNotifyResp; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.models.auth.In; |
| | | import jdk.nashorn.internal.runtime.ListAdapter; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | |
| | | @RestController |
| | | @RequestMapping("/t-charging-order") |
| | | public class TChargingOrderController { |
| | | |
| | | private Logger log = LoggerFactory.getLogger(TChargingOrderController.class); |
| | | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | |
| | | private AliPaymentClient aliPaymentClient; |
| | | @Resource |
| | | private TShoppingOrderService shoppingOrderService; |
| | | |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | |
| | | @Resource |
| | |
| | | private AppUserCarClient appUserCarClient; |
| | | @Resource |
| | | private TChargingOrderAccountingStrategyService chargingOrderAccountingStrategyService; |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private TChargingOrderAccountingStrategyService chargingOrderAccountingStrategyService; |
| | | private TOrderInvoiceService invoiceService; |
| | | |
| | | |
| | | /** |
| | | * 远程调用根据枪id 查询最新的订单id 用户后台结束充电 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/queryOrderByGunId/{id}") |
| | | public R<String> queryOrderByGunId(@PathVariable("id") String id) { |
| | | List<Integer> integers = new ArrayList<>(); |
| | | integers.add(2); |
| | | integers.add(3); |
| | | integers.add(4); |
| | | TChargingOrder one = chargingOrderService.lambdaQuery() |
| | | .eq(TChargingOrder::getChargingGunId, id) |
| | | .in(TChargingOrder::getStatus, integers) |
| | | .one(); |
| | | if (one!=null){ |
| | | return R.ok(one.getId().toString()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping(value = "/pay/order/list") |
| | | @ApiOperation(value = "列表", tags = {"管理后台-支付订单-订单信息"}) |
| | | public R<PageInfo<PayOrderDto>> payOrderList(@RequestBody PayOrderQueryDto payOrderQueryDto) { |
| | | return chargingOrderService.payOrderQuery(payOrderQueryDto); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping(value = "/pay/order/refund") |
| | | @ApiOperation(value = "退款", tags = {"管理后台-支付订单-订单信息"}) |
| | | public R refund(@RequestBody PayOrderRefundDto payOrderQueryDto) { |
| | | return chargingOrderService.payRefund(payOrderQueryDto); |
| | | } |
| | | |
| | | @ResponseBody |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/pay/order/refund/list") |
| | | @ApiOperation(value = "充电信息", tags = {"管理后台-支付订单-退款订单"}) |
| | | @ApiOperation(value = "列表", tags = {"管理后台-支付订单-退款订单"}) |
| | | public R<PageInfo<TChargingOrderRefund>> refundList(@RequestBody ChargingRefundDto chargingRefundDto) { |
| | | return chargingOrderService.getRefundList(chargingRefundDto); |
| | | |
| | | } |
| | | @ResponseBody |
| | | @PostMapping(value = "/pay/order/refund/list1") |
| | | @ApiOperation(value = "列表1", tags = {"管理后台-支付订单-退款订单"}) |
| | | public R<PageInfo<TChargingOrderRefund>> refundList1(@RequestBody ChargingRefundDto chargingRefundDto) { |
| | | return chargingOrderService.getRefundList(chargingRefundDto); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | * @param |
| | | * @return |
| | | */ |
| | | @GetMapping(value = "/getCar") |
| | | public R<Long> getCar() { |
| | | @GetMapping(value = "/getCar/{id}") |
| | | public R<Long> getCar(@PathVariable("id")String id) { |
| | | List<TChargingOrder> list = chargingOrderService.list(new LambdaQueryWrapper<TChargingOrder>() |
| | | .eq(TChargingOrder::getAppUserId, tokenService.getLoginUserApplet().getUserId()) |
| | | .eq(TChargingOrder::getAppUserId, id) |
| | | .isNotNull(TChargingOrder::getAppUserCarId)); |
| | | if (!list.isEmpty()){ |
| | | // 最近使用的车辆id |
| | |
| | | |
| | | return R.ok(count); |
| | | } |
| | | |
| | | //订单详情 |
| | | @PostMapping(value = "/detail") |
| | | public R<TChargingOrder> detail(@RequestParam("orderId") Long orderId) { |
| | |
| | | |
| | | /** |
| | | * 充电充值支付回调 |
| | | * @param request |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/chargingOrderWXCallback") |
| | | public void chargingOrderWXCallback(HttpServletRequest request) { |
| | | Map<String, Object> data = wxPaymentClient.payNotify(request).getData(); |
| | | if (null != data) { |
| | | String out_trade_no = data.get("out_trade_no").toString(); |
| | | String transaction_id = data.get("transaction_id").toString(); |
| | | String attach = data.get("attach").toString(); |
| | | AjaxResult ajaxResult = chargingOrderService.chargingOrderCallback(1, out_trade_no, transaction_id, attach); |
| | | if (ajaxResult.isSuccess()) { |
| | | wxPaymentClient.ack(); |
| | | } |
| | | } |
| | | public void chargingOrderWXCallback(@RequestParam("out_trade_no") String out_trade_no, @RequestParam("transaction_id") String transaction_id, |
| | | @RequestParam("attach") String attach) { |
| | | AjaxResult ajaxResult = chargingOrderService.chargingOrderCallback(1, out_trade_no, transaction_id, attach); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 修改安全检测数据 |
| | | * @param securityDetection |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/securityDetection") |
| | | public void securityDetection(@RequestBody SecurityDetectionVO securityDetection){ |
| | | log.error("-------------------安全检测数据-------------------:" + securityDetection); |
| | | chargingOrderService.securityDetection(securityDetection); |
| | | } |
| | | |
| | | /** |
| | | * 远程启动充电应答 |
| | | * @param message |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/startChargeSuccessfully") |
| | | public void startChargeSuccessfully(@RequestBody PlatformStartChargingReplyMessageVO message){ |
| | | log.error("-------------------远程启动充电请求应答-------------------:" + message); |
| | | chargingOrderService.startChargeSuccessfully(message); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 支付宝支付成功后的回调 |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 远程启动失败后退款回调 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/chargingOrderStartupFailureWxRefund") |
| | | public void chargingOrderStartupFailureWxRefund(@RequestParam("out_refund_no") String out_refund_no, |
| | | @RequestParam("refund_id") String refund_id, |
| | | @RequestParam("tradeState") String tradeState, |
| | | @RequestParam("success_time") String success_time){ |
| | | chargingOrderService.chargingOrderStartupFailureWxRefund(out_refund_no, refund_id, tradeState, success_time); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | |
| | | public AjaxResult stopCharging(@PathVariable String id) { |
| | | return chargingOrderService.stopCharging(id); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 停止充电应答处理逻辑 |
| | | * @param platformStopChargingReply |
| | | */ |
| | | @PostMapping("/terminateSuccessfulResponse") |
| | | public void terminateSuccessfulResponse(@RequestBody PlatformStopChargingReplyVO platformStopChargingReply){ |
| | | log.error("-------------------远程停止充电请求应答-------------------:" + platformStopChargingReply); |
| | | chargingOrderService.terminateSuccessfulResponse(platformStopChargingReply); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 停止充电返回账单后计算费用 |
| | | * @param vo |
| | | */ |
| | | @PostMapping("/endChargeBillingCharge") |
| | | public void endChargeBillingCharge(@RequestBody TransactionRecordMessageVO vo){ |
| | | log.error("-------------------停止充电返回账单后计算费用及修改业务状态-------------------:" + vo); |
| | | chargingOrderService.endChargeBillingCharge(vo); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/six/charge") |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/work/shop") |
| | | @ApiOperation(value = "购物收入", tags = {"后台-工作台"}) |
| | | public R workShop(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | //count近6个月的数据 |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | List<Map<String,Object >> shopData = shoppingOrderService.getData(statisticsQueryDto); |
| | | return R.ok(shopData); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/six/vip") |
| | | @ApiOperation(value = "vip收入", tags = {"后台-数据分析-平台收入分析"}) |
| | | public R<List<SixVipDto>> vip() { |
| | |
| | | @ResponseBody |
| | | @GetMapping(value = "/six/total") |
| | | @ApiOperation(value = "底部数据分类", tags = {"后台-数据分析-平台收入分析"}) |
| | | public R<Map<String,BigDecimal>> total() { |
| | | public R<Map<String,Object>> total() { |
| | | //count近6个月的数据 |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | Map<String,BigDecimal> map = chargingOrderService.countAll(sixBefore); |
| | | Map<String,Object> map = chargingOrderService.countAll(sixBefore); |
| | | BigDecimal data = parkingLotClient.getRecordAmount(sixBefore).getData(); |
| | | map.put("parkingAmount",data); |
| | | BigDecimal data1 = shoppingOrderService.getSumAmount(sixBefore); |
| | |
| | | @ResponseBody |
| | | @PostMapping(value = "/watch/chargingOrder") |
| | | @ApiOperation(value = "监控订单", tags = {"管理后台-订单管理"}) |
| | | public AjaxResult<TCharingOrderVO> watchChargingOrder(@RequestBody ChargingOrderQuery dto) { |
| | | public R<List<ChargingOrderAndUploadRealTimeMonitoringDataDto>> watchChargingOrder(@RequestBody ChargingOrderQuery dto) { |
| | | Integer page = dto.getPageCurr(); |
| | | Integer pageSize = dto.getPageSize(); |
| | | List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData(); |
| | |
| | | for (UploadRealTimeMonitoringData uploadRealTimeMonitoringData : data1) { |
| | | ChargingOrderAndUploadRealTimeMonitoringDataDto dataDto = new ChargingOrderAndUploadRealTimeMonitoringDataDto(); |
| | | BeanUtils.copyProperties(uploadRealTimeMonitoringData,dataDto); |
| | | BeanUtils.copyProperties(map.get(uploadRealTimeMonitoringData.getCharging_pile_code()),dataDto); |
| | | TChargingOrder tChargingOrder = map.get(uploadRealTimeMonitoringData.getCharging_pile_code()); |
| | | if (tChargingOrder!=null) { |
| | | BeanUtils.copyProperties(tChargingOrder, dataDto); |
| | | } |
| | | dtos.add(dataDto); |
| | | } |
| | | |
| | | |
| | | return AjaxResult.success(res); |
| | | return R.ok(dtos); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 处理充电订单实时监控数据相关的业务逻辑 |
| | | * @param query |
| | | */ |
| | | @PostMapping("/chargeMonitoring") |
| | | public void chargeMonitoring(@RequestBody UploadRealTimeMonitoringDataQuery query){ |
| | | chargingOrderService.chargeMonitoring(query); |
| | | } |
| | | /** |
| | | * 通过流水号查询订单 |
| | | * @param code |
| | | * @return |
| | | */ |
| | | @PostMapping(value = "/getOrderByCode/{code}") |
| | | public R<TChargingOrder> getOrderByCode(@PathVariable("code") String code){ |
| | | return R.ok(chargingOrderService.getOne(Wrappers.lambdaQuery(TChargingOrder.class) |
| | | .eq(TChargingOrder::getCode,code))); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // @ResponseBody |
| | | // @PostMapping(value = "/charging/statistics") |
| | | // @ApiOperation(value = "统计", tags = {"管理后台-数据分析-充电运营分析"}) |
| | | // public R<TCharingOrderVO> watchChargingOrder(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto){ |
| | | // List<Integer> siteIds =new ArrayList<>(); |
| | | // if (statisticsQueryDto.getSiteId()==null) { |
| | | // Long userId = SecurityUtils.getUserId(); |
| | | // //获取当前登录的siteIds |
| | | // List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | // for (GetSiteListDTO datum : data) { |
| | | // siteIds.add(datum.getId()); |
| | | // } |
| | | // }else { |
| | | // siteIds.add(statisticsQueryDto.getSiteId()); |
| | | // } |
| | | // |
| | | // |
| | | // LocalDate start = null; |
| | | // LocalDate end = null; |
| | | // if (statisticsQueryDto.getDayType()==1){ |
| | | // start = LocalDate.now(); |
| | | // |
| | | // }else if (statisticsQueryDto.getDayType()==2){ |
| | | // LocalDate today = LocalDate.now(); |
| | | // |
| | | // // 获取本周一的日期 |
| | | // LocalDate mondayThisWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); |
| | | // |
| | | // System.out.println("本周一是: " + mondayThisWeek); |
| | | // } |
| | | // else if (statisticsQueryDto.getDayType()==3){ |
| | | // // 获取当前日期 |
| | | // LocalDate today = LocalDate.now(); |
| | | // |
| | | // // 获取本月1号的日期 |
| | | // YearMonth yearMonth = YearMonth.from(today); |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/charging/statistics") |
| | | @ApiOperation(value = "统计,充电订单分析", tags = {"管理后台-数据分析-充电运营分析"}) |
| | | public R<TCharingOrderMapVO> watchChargingOrder(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto){ |
| | | List<Integer> siteIds =new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId()==null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | }else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | TCharingOrderMapVO tCharingOrderMapVO = new TCharingOrderMapVO(); |
| | | |
| | | |
| | | LocalDate start = null; |
| | | LocalDate end = null; |
| | | if (statisticsQueryDto.getDayType()==1){ |
| | | start = LocalDate.now(); |
| | | |
| | | }else if (statisticsQueryDto.getDayType()==2){ |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // 获取本周一的日期 |
| | | LocalDate mondayThisWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); |
| | | |
| | | System.out.println("本周一是: " + mondayThisWeek); |
| | | } |
| | | else if (statisticsQueryDto.getDayType()==3){ |
| | | // 获取当前日期 |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // 获取本月1号的日期 |
| | | YearMonth yearMonth = YearMonth.from(today); |
| | | // start = yearMonth.atDay(1); |
| | | // |
| | | // System.out.println("本月1号是: " + start); |
| | | // }else if (statisticsQueryDto.getDayType()==4){ |
| | | // LocalDate today = LocalDate.now(); |
| | | // // 获取当前年份 |
| | | // int currentYear = today.getYear(); |
| | | // // 获取今年1月1日的日期 |
| | | // start = LocalDate.of(currentYear, 1, 1); |
| | | // System.out.println("今年1月1日是: " + start); |
| | | // }else if (statisticsQueryDto.getDayType()==5){ |
| | | // |
| | | // // 获取今年1月1日的日期 |
| | | // start = statisticsQueryDto.getStartTime(); |
| | | // end = statisticsQueryDto.getEndTime(); |
| | | // } |
| | | // List<TChargingOrder> list = chargingOrderService.lambdaQuery().ge(TChargingOrder::getStartTime, start).le(TChargingOrder::getEndTime, end).in(TChargingOrder::getSiteId, siteIds).list(); |
| | | // List<Long> chargingOrderIds = list.stream().map(TChargingOrder::getId).collect(Collectors.toList()); |
| | | // //上方饼图 |
| | | // List<Map<String,BigDecimal>> maps = chargingOrderService.getSumByType(chargingOrderIds); |
| | | // |
| | | // if (statisticsQueryDto.getDayType()==1){ |
| | | // List<Map<String,BigDecimal>> maps1 = chargingOrderService.getDateData(chargingOrderIds); |
| | | // |
| | | // }else if (statisticsQueryDto.getDayType()==2){ |
| | | // List<Map<String,BigDecimal>> maps1 = chargingOrderService.getWeekData(chargingOrderIds); |
| | | // }else if (statisticsQueryDto.getDayType()==3){ |
| | | // List<Map<String,BigDecimal>> maps1 = chargingOrderService.getMonthData(chargingOrderIds); |
| | | // }else if (statisticsQueryDto.getDayType()==4){ |
| | | // List<Map<String,BigDecimal>> maps1 = chargingOrderService.getYearData(chargingOrderIds); |
| | | // } |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // } |
| | | }else if (statisticsQueryDto.getDayType()==4){ |
| | | LocalDate today = LocalDate.now(); |
| | | // 获取当前年份 |
| | | int currentYear = today.getYear(); |
| | | // 获取今年1月1日的日期 |
| | | start = statisticsQueryDto.getStartTime(); |
| | | end = statisticsQueryDto.getEndTime(); |
| | | }else if (statisticsQueryDto.getDayType()==5){ |
| | | |
| | | public static void main(String[] args) { |
| | | // 示例数据 |
| | | List<TChargingOrder> list = getSampleData(); |
| | | System.err.println(list); |
| | | List<Map<String, BigDecimal>> result = processData(list); |
| | | // 获取今年1月1日的日期 |
| | | start = statisticsQueryDto.getStartTime(); |
| | | end = statisticsQueryDto.getEndTime(); |
| | | } |
| | | List<TChargingOrder> list = chargingOrderService.lambdaQuery().ge(TChargingOrder::getStartTime, start).le(TChargingOrder::getEndTime, end).in(TChargingOrder::getSiteId, siteIds).list(); |
| | | List<Long> chargingOrderIds = list.stream().map(TChargingOrder::getId).collect(Collectors.toList()); |
| | | //上方饼图 |
| | | List<Map<String,Object>> maps = chargingOrderService.getSumByType(chargingOrderIds); |
| | | |
| | | result.forEach(System.out::println); |
| | | if (statisticsQueryDto.getDayType()==1){ |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getDateData(chargingOrderIds); |
| | | tCharingOrderMapVO.setMaps1(maps1); |
| | | }else if (statisticsQueryDto.getDayType()==2){ |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getWeekData(chargingOrderIds); |
| | | tCharingOrderMapVO.setMaps1(maps1); |
| | | }else if (statisticsQueryDto.getDayType()==3){ |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getMonthData(chargingOrderIds); |
| | | tCharingOrderMapVO.setMaps1(maps1); |
| | | }else if (statisticsQueryDto.getDayType()==4){ |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getYearData(chargingOrderIds); |
| | | tCharingOrderMapVO.setMaps1(maps1); |
| | | }else if (statisticsQueryDto.getDayType()==5){ |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getByDate(chargingOrderIds); |
| | | tCharingOrderMapVO.setMaps1(maps1); |
| | | } |
| | | |
| | | |
| | | tCharingOrderMapVO.setMaps(maps); |
| | | |
| | | |
| | | return R.ok(tCharingOrderMapVO); |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/charging/power") |
| | | @ApiOperation(value = "功率", tags = {"管理后台-数据分析-充电运营分析"}) |
| | | public R<TCharingOrderPowerMapVO> power(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId() == null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | List<Map<String,Object>> maps1 = chargingOrderService.queryPower(siteIds); |
| | | |
| | | |
| | | Map<String,Object> map = chargingOrderService.qureryPowerLevel(siteIds,statisticsQueryDto); |
| | | |
| | | TCharingOrderPowerMapVO tCharingOrderPowerMapVO = new TCharingOrderPowerMapVO(); |
| | | tCharingOrderPowerMapVO.setMaps1(map); |
| | | tCharingOrderPowerMapVO.setMaps(maps1); |
| | | return R.ok(tCharingOrderPowerMapVO); |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/charging/users") |
| | | @ApiOperation(value = "除电站流量外", tags = {"管理后台-数据分析-充电用户分析"}) |
| | | public R<TCharingUserMapVO> users(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto){ |
| | | |
| | | TCharingUserMapVO tCharingUserMapVO = new TCharingUserMapVO(); |
| | | //上方折现 |
| | | if (statisticsQueryDto.getDayType()==1){ |
| | | List<Map<String,Object>> map = chargingOrderService.usersDay(); |
| | | |
| | | List<Map<String, Object>> charMap = new ArrayList<>(); |
| | | // 生成从 "00:00" 到 "23:00" 的时间数据 |
| | | for (int hour = 0; hour < 24; hour++) { |
| | | String time = String.format("%02d:00", hour); |
| | | Map<String, Object> mapWithTimeValue = findMapWithTimeValue(map, time); |
| | | if (mapWithTimeValue!=null){ |
| | | charMap.add(mapWithTimeValue); |
| | | }else { |
| | | Map<String, Object> timeMap = new HashMap<>(); |
| | | timeMap.put("time", time); // 初始化值为 null |
| | | timeMap.put("counts", 0); |
| | | |
| | | charMap.add(timeMap); |
| | | } |
| | | } |
| | | |
| | | List<Map<String,Object>> map1 = chargingOrderService.usersDay1(); |
| | | |
| | | List<Map<String, Object>> charMap1 = new ArrayList<>(); |
| | | // 生成从 "00:00" 到 "23:00" 的时间数据 |
| | | for (int hour = 0; hour < 24; hour++) { |
| | | String time = String.format("%02d:00", hour); |
| | | Map<String, Object> mapWithTimeValue = findMapWithTimeValue(map1, time); |
| | | if (mapWithTimeValue!=null){ |
| | | charMap1.add(mapWithTimeValue); |
| | | }else { |
| | | Map<String, Object> timeMap = new HashMap<>(); |
| | | timeMap.put("time", time); // 初始化值为 null |
| | | timeMap.put("counts", 0); |
| | | |
| | | charMap1.add(timeMap); |
| | | } |
| | | } |
| | | |
| | | |
| | | tCharingUserMapVO.setMap(charMap); |
| | | tCharingUserMapVO.setMap1(charMap1); |
| | | }else { |
| | | List<Map<String,Object>> map = chargingOrderService.usersByQuery(statisticsQueryDto); |
| | | |
| | | |
| | | //按日 |
| | | // 解析 startTime 和 endTime 为 LocalDate |
| | | LocalDate startDate = statisticsQueryDto.getStartTime(); |
| | | LocalDate endDate = statisticsQueryDto.getEndTime(); |
| | | |
| | | List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); |
| | | |
| | | // 遍历日期范围 |
| | | while (!startDate.isAfter(endDate)) { |
| | | String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | Map<String, Object> dailyStats = findMapWithDateValue(map, formattedDate); |
| | | |
| | | if (dailyStats != null) { |
| | | dateRangeStatistics.add(dailyStats); |
| | | } else { |
| | | Map<String, Object> dateMap = new HashMap<>(); |
| | | dateMap.put("time", formattedDate); |
| | | dateMap.put("counts", 0); |
| | | dateRangeStatistics.add(dateMap); |
| | | } |
| | | |
| | | // 移动到下一天 |
| | | startDate = startDate.plusDays(1); |
| | | } |
| | | |
| | | tCharingUserMapVO.setMap(map); |
| | | } |
| | | |
| | | //用户标签 |
| | | List<Map<String,Object>> maps = chargingOrderService.getUserTagCount(); |
| | | //会员标签 |
| | | List<Map<String,Object>> maps1 = chargingOrderService.getVipCount(); |
| | | |
| | | //单位消费 |
| | | List<Map<String, Object>> untiMap = chargingOrderService.unitConsumption(statisticsQueryDto); |
| | | |
| | | //车辆用途 |
| | | List<Map<String, Object>> carMap = chargingOrderService.carUserMethod(); |
| | | //车辆品牌 |
| | | List<Map<String, Object>> carBrandMap = chargingOrderService.carUserBrand(); |
| | | //本地车数量 |
| | | Map<String,Object> localCarMap = chargingOrderService.countLocalCar(); |
| | | |
| | | |
| | | tCharingUserMapVO.setUserMaps(maps); |
| | | tCharingUserMapVO.setVipMaps(maps1); |
| | | tCharingUserMapVO.setUntiMap(untiMap); |
| | | tCharingUserMapVO.setCarMap(carMap); |
| | | tCharingUserMapVO.setCarBrandMap(carBrandMap); |
| | | tCharingUserMapVO.setLocalCarMap(localCarMap); |
| | | return R.ok(tCharingUserMapVO); |
| | | |
| | | } |
| | | @ResponseBody |
| | | @PostMapping(value = "/charging/sites") |
| | | @ApiOperation(value = "电站评价", tags = {"管理后台-数据分析-充电用户分析"}) |
| | | public R<TCharingUserEvaluateVO> sites(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto){ |
| | | List<Integer> siteIds =new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId()==null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | }else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | //查询评价分 |
| | | Long aver = chargingOrderService.getAver(siteIds); |
| | | //查询各个分数 |
| | | List<Map<String,Object>> evaluate = chargingOrderService.getLevelEvaluate(siteIds); |
| | | //查询差评回复数 |
| | | Long count = orderEvaluateService.lambdaQuery().isNotNull(TOrderEvaluate::getResponseTime).count(); |
| | | TCharingUserEvaluateVO tCharingUserEvaluateVO = new TCharingUserEvaluateVO(); |
| | | tCharingUserEvaluateVO.setAver(aver); |
| | | tCharingUserEvaluateVO.setEvaluate(evaluate); |
| | | tCharingUserEvaluateVO.setBlackCount(count); |
| | | |
| | | |
| | | //好评标签 |
| | | List<Map<String,Object>> goodTop = orderEvaluateService.goodTop(siteIds); |
| | | //差评标签 |
| | | List<Map<String,Object>> badTop = orderEvaluateService.badTop(siteIds); |
| | | |
| | | //流量分析 |
| | | List<Map<String,Object>> sourceMap = chargingOrderService.countBySource(siteIds); |
| | | tCharingUserEvaluateVO.setGoodTop(goodTop); |
| | | tCharingUserEvaluateVO.setBadTop(badTop); |
| | | tCharingUserEvaluateVO.setFlow(sourceMap); |
| | | //流量 |
| | | return R.ok(tCharingUserEvaluateVO); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/charging/equipment") |
| | | @ApiOperation(value = "电站评价", tags = {"管理后台-数据分析-设备运维分析"}) |
| | | public R<TCharingUserEquimentVO> equipment(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto){ |
| | | List<Integer> siteIds =new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId()==null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | }else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | //直流可用率 |
| | | List<Map<String,Object>> equipmentMap1 = chargingOrderService.equipmentUserType1(siteIds,statisticsQueryDto); |
| | | //交流可用率 |
| | | List<Map<String,Object>> equipmentMap2= chargingOrderService.equipmentUserType2(siteIds,statisticsQueryDto); |
| | | |
| | | //取出直流可用率和交流可用率的percent的平均值保留两位小数 |
| | | |
| | | double average1 = calculateAveragePercent(equipmentMap1, equipmentMap2); |
| | | System.out.printf("The average percent is: %.2f\n", average1); |
| | | |
| | | |
| | | //直流故障率 |
| | | List<Map<String,Object>> equipmentMapbroke1 = chargingOrderService.equipmentMapbroke1(siteIds,statisticsQueryDto); |
| | | //交流故障率 |
| | | List<Map<String,Object>> equipmentMapbroke2 = chargingOrderService.equipmentMapbroke2(siteIds,statisticsQueryDto); |
| | | |
| | | |
| | | double average2 = calculateAveragePercent(equipmentMapbroke1, equipmentMapbroke2); |
| | | System.out.printf("The average percent is: %.2f\n", average2); |
| | | //直流离网率 |
| | | List<Map<String,Object>> equipmentMapOut1 = chargingOrderService.equipmentMapOut1(siteIds,statisticsQueryDto); |
| | | //交流离网率 |
| | | List<Map<String,Object>> equipmentMapOut2 = chargingOrderService.equipmentMapOut2(siteIds,statisticsQueryDto); |
| | | |
| | | double average3 = calculateAveragePercent(equipmentMapOut1, equipmentMapOut2); |
| | | System.out.printf("The average percent is: %.2f\n", average3); |
| | | |
| | | //需求电流满足率 |
| | | List<Map<String,Object>> needElec1 = chargingOrderService.needElec(siteIds,statisticsQueryDto); |
| | | List<Map<String,Object>> needElec2 = chargingOrderService.needElec1(siteIds,statisticsQueryDto); |
| | | |
| | | double average4 = calculateAveragePercent(needElec1, needElec2); |
| | | System.out.printf("The average percent is: %.2f\n", average4); |
| | | |
| | | |
| | | |
| | | TCharingUserEquimentVO tCharingUserEquimentVO = new TCharingUserEquimentVO(); |
| | | tCharingUserEquimentVO.setEquipmentMap1(equipmentMap1); |
| | | tCharingUserEquimentVO.setEquipmentMap2(equipmentMap2); |
| | | tCharingUserEquimentVO.setEquipmentMapbroke1(equipmentMapbroke1); |
| | | tCharingUserEquimentVO.setEquipmentMapbroke2(equipmentMapbroke2); |
| | | tCharingUserEquimentVO.setEquipmentMapOut1(equipmentMapOut1); |
| | | tCharingUserEquimentVO.setEquipmentMapOut2(equipmentMapOut2); |
| | | tCharingUserEquimentVO.setNeedElec1(needElec1); |
| | | tCharingUserEquimentVO.setNeedElec2(needElec2); |
| | | tCharingUserEquimentVO.setAverage1(average1); |
| | | tCharingUserEquimentVO.setAverage2(average2); |
| | | tCharingUserEquimentVO.setAverage3(average3); |
| | | tCharingUserEquimentVO.setAverage4(average4); |
| | | return R.ok(tCharingUserEquimentVO); |
| | | } |
| | | |
| | | |
| | | private static double calculateAveragePercent(List<Map<String, Object>> mapList1, List<Map<String, Object>> mapList2) { |
| | | int totalElements = mapList1.size() + mapList2.size(); |
| | | double sum = 0.0; |
| | | |
| | | // 累加两个列表中所有元素的 "percent" 值 |
| | | for (Map<String, Object> map : mapList1) { |
| | | if (map.containsKey("percent")) { |
| | | sum += Double.parseDouble((String) map.get("percent")); |
| | | } |
| | | } |
| | | for (Map<String, Object> map : mapList2) { |
| | | if (map.containsKey("percent")) { |
| | | sum += Double.parseDouble((String) map.get("percent")); |
| | | } |
| | | } |
| | | |
| | | // 防止除以零错误 |
| | | if (totalElements == 0) { |
| | | return 0.0; |
| | | } |
| | | |
| | | // 计算平均值 |
| | | return sum / totalElements; |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/work/charge") |
| | | @ApiOperation(value = "上方充电数据统计", tags = {"管理后台-工作台"}) |
| | | public R<TCharingWorkVO> workCharge(@RequestBody ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId() == null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | List<TChargingOrder> list = chargingOrderService.lambdaQuery().in(!siteIds.isEmpty(), TChargingOrder::getSiteId, siteIds).eq(statisticsQueryDto.getSiteId() != null, TChargingOrder::getSiteId, statisticsQueryDto.getSiteId()).list(); |
| | | //当日的订单总数 |
| | | int size = list.size(); |
| | | //计算list中paymentAmount的总和 |
| | | BigDecimal totalPaymentAmount = list.stream().map(TChargingOrder::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //计算list中electrovalence的总和 |
| | | BigDecimal totalElectrovalence = list.stream().map(TChargingOrder::getElectrovalence).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //计算list中serviceCharge的总和 |
| | | BigDecimal totalServiceCharge = list.stream().map(TChargingOrder::getServiceCharge).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //计算list中charging_capacity的总和 |
| | | BigDecimal totalChargingCapacity = list.stream().map(TChargingOrder::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | TCharingWorkVO tCharingWorkVO = new TCharingWorkVO(); |
| | | tCharingWorkVO.setCount(size); |
| | | tCharingWorkVO.setTotalPaymentAmount(totalPaymentAmount); |
| | | tCharingWorkVO.setTotalElectrovalence(totalElectrovalence); |
| | | tCharingWorkVO.setTotalServiceCharge(totalServiceCharge); |
| | | tCharingWorkVO.setTotalChargingCapacity(totalChargingCapacity); |
| | | return R.ok(tCharingWorkVO); |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/work/chargeDetail") |
| | | @ApiOperation(value = "运营情况", tags = {"管理后台-工作台"}) |
| | | public R workCharge(@RequestBody ChargingDetailQueryDto statisticsQueryDto) { |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId() == null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | if (statisticsQueryDto.getDayType()==1) { |
| | | List<Map<String,Object>> charMap1 = chargingOrderService.getHourType(siteIds,statisticsQueryDto); |
| | | List<Map<String, Object>> charMap = new ArrayList<>(); |
| | | // 生成从 "00:00" 到 "23:00" 的时间数据 |
| | | for (int hour = 0; hour < 24; hour++) { |
| | | String time = String.format("%02d:00", hour); |
| | | Map<String, Object> mapWithTimeValue = findMapWithTimeValue(charMap1, time); |
| | | if (mapWithTimeValue!=null){ |
| | | charMap.add(mapWithTimeValue); |
| | | }else { |
| | | Map<String, Object> timeMap = new HashMap<>(); |
| | | timeMap.put("time", time); // 初始化值为 null |
| | | timeMap.put("electrovalence", 0); |
| | | timeMap.put("orderCount", 0); |
| | | timeMap.put("servicecharge", 0); |
| | | timeMap.put("electricity", 0); |
| | | charMap.add(timeMap); |
| | | } |
| | | } |
| | | return R.ok(charMap); |
| | | }else if (statisticsQueryDto.getDayType()==2){ |
| | | // 假设 chargingOrderService.getDateType() 返回的是按天的数据 |
| | | List<Map<String, Object>> charMap1 = chargingOrderService.getDateType(siteIds, statisticsQueryDto); |
| | | |
| | | // 解析 startTime 和 endTime 为 LocalDate |
| | | LocalDate startDate = statisticsQueryDto.getStartTime(); |
| | | LocalDate endDate = statisticsQueryDto.getEndTime(); |
| | | |
| | | List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); |
| | | |
| | | // 遍历日期范围 |
| | | while (!startDate.isAfter(endDate)) { |
| | | String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | Map<String, Object> dailyStats = findMapWithDateValue(charMap1, formattedDate); |
| | | |
| | | if (dailyStats != null) { |
| | | dateRangeStatistics.add(dailyStats); |
| | | } else { |
| | | Map<String, Object> dateMap = new HashMap<>(); |
| | | dateMap.put("time", formattedDate); |
| | | dateMap.put("electrovalence", 0); |
| | | dateMap.put("orderCount", 0); |
| | | dateMap.put("servicecharge", 0); |
| | | dateMap.put("electricity", 0); |
| | | dateRangeStatistics.add(dateMap); |
| | | } |
| | | |
| | | // 移动到下一天 |
| | | startDate = startDate.plusDays(1); |
| | | } |
| | | |
| | | // return dateRangeStatistics; |
| | | return R.ok(dateRangeStatistics); |
| | | }else if (statisticsQueryDto.getDayType()==3){ |
| | | List<Map<String,Object>> charMap1 = chargingOrderService.getMonthType(siteIds,statisticsQueryDto); |
| | | // 解析 startTime 和 endTime 为 LocalDate |
| | | LocalDate startDate = statisticsQueryDto.getStartTime(); |
| | | LocalDate endDate = statisticsQueryDto.getEndTime(); |
| | | |
| | | List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); |
| | | |
| | | // 遍历日期范围 |
| | | while (!startDate.isAfter(endDate)) { |
| | | String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); |
| | | Map<String, Object> dailyStats = findMapWithDateValue(charMap1, formattedDate); |
| | | |
| | | if (dailyStats != null) { |
| | | dateRangeStatistics.add(dailyStats); |
| | | } else { |
| | | Map<String, Object> dateMap = new HashMap<>(); |
| | | dateMap.put("time", formattedDate); |
| | | dateMap.put("electrovalence", 0); |
| | | dateMap.put("orderCount", 0); |
| | | dateMap.put("servicecharge", 0); |
| | | dateMap.put("electricity", 0); |
| | | dateRangeStatistics.add(dateMap); |
| | | } |
| | | |
| | | // 移动到下一天 |
| | | startDate = startDate.plusMonths(1); |
| | | } |
| | | return R.ok(dateRangeStatistics); |
| | | |
| | | } |
| | | return R.ok(); |
| | | |
| | | |
| | | } |
| | | |
| | | private static Map<String, Object> findMapWithTimeValue(List<Map<String, Object>> charMap1,String timeValue) { |
| | | for (Map<String, Object> map : charMap1) { |
| | | if (map.containsKey("time") && map.get("time").equals(timeValue)) { |
| | | return map; |
| | | } |
| | | } |
| | | return null; // 如果没有找到,返回 null |
| | | } |
| | | |
| | | private Map<String, Object> findMapWithDateValue(List<Map<String, Object>> list, String date) { |
| | | for (Map<String, Object> map : list) { |
| | | if (date.equals(map.get("time"))) { |
| | | return map; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping(value = "/work/use") |
| | | @ApiOperation(value = "利用率", tags = {"管理后台-工作台"}) |
| | | public R workUse(@RequestBody ChargingDetailQueryDto statisticsQueryDto) { |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (statisticsQueryDto.getSiteId() == null) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //获取当前登录的siteIds |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } else { |
| | | siteIds.add(statisticsQueryDto.getSiteId()); |
| | | } |
| | | List<Map<String,Object>> capMap = chargingOrderService.getchargingCapacity(siteIds,statisticsQueryDto); |
| | | List<TChargingPile> chargingPiles = chargingPileClient.getChargingPileBySiteIds(siteIds).getData(); |
| | | //获取chargingPiles的ratedPower的总和再乘以chargingPiles的数量再乘以24 |
| | | BigDecimal totalRatedPower = chargingPiles.stream().map(TChargingPile::getRatedPower).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(chargingPiles.size())).multiply(new BigDecimal(24)); |
| | | |
| | | //将capMap的chargingCapacity除以totalRatedPower保留两位数 |
| | | capMap.forEach(map -> { |
| | | BigDecimal chargingCapacity = (BigDecimal) map.get("chargingCapacity"); |
| | | BigDecimal result = chargingCapacity.divide(totalRatedPower, 2, RoundingMode.HALF_UP); |
| | | map.put("chargingCapacity", result); |
| | | }); |
| | | |
| | | |
| | | |
| | | // |
| | | // 解析 startTime 和 endTime 为 LocalDate |
| | | LocalDate startDate = statisticsQueryDto.getStartTime(); |
| | | LocalDate endDate = statisticsQueryDto.getEndTime(); |
| | | |
| | | List<Map<String, Object>> dateRangeStatistics = new ArrayList<>(); |
| | | |
| | | // 遍历日期范围 |
| | | while (!startDate.isAfter(endDate)) { |
| | | String formattedDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | Map<String, Object> dailyStats = findMapWithDateValue(capMap, formattedDate); |
| | | |
| | | if (dailyStats != null) { |
| | | dateRangeStatistics.add(dailyStats); |
| | | } else { |
| | | Map<String, Object> dateMap = new HashMap<>(); |
| | | dateMap.put("time", formattedDate); |
| | | dateMap.put("chargingCapacity", 0); |
| | | dateRangeStatistics.add(dateMap); |
| | | } |
| | | |
| | | // 移动到下一天 |
| | | startDate = startDate.plusDays(1); |
| | | } |
| | | return R.ok(dateRangeStatistics); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/work/shopOrder") |
| | | @ApiOperation(value = "购物订单统计", tags = {"管理后台-工作台"}) |
| | | public R shopOrder() { |
| | | Long count = shoppingOrderService.lambdaQuery().eq(TShoppingOrder::getStatus, 1).count(); |
| | | Long count1 = shoppingOrderService.lambdaQuery().eq(TShoppingOrder::getStatus, 2).count(); |
| | | List<Long> counts = new ArrayList<>(); |
| | | counts.add(count); |
| | | counts.add(count1); |
| | | return R.ok(counts); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/work/invoice") |
| | | @ApiOperation(value = "开票统计", tags = {"管理后台-工作台"}) |
| | | public R invoice() { |
| | | Long count = invoiceService.lambdaQuery().eq(TOrderInvoice::getStatus, 1).count(); |
| | | Long count1 = invoiceService.lambdaQuery().eq(TOrderInvoice::getStatus, 3).count(); |
| | | List<Long> counts = new ArrayList<>(); |
| | | counts.add(count); |
| | | counts.add(count1); |
| | | return R.ok(counts); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/work/users/count") |
| | | @ApiOperation(value = "用户数量", tags = {"管理后台-工作台"}) |
| | | public R usersCount() { |
| | | List<Map<String,Object>> userMap = chargingOrderService.countAllUserData(); |
| | | return R.ok(userMap); |
| | | |
| | | } |
| | | |
| | | @GetMapping(value = "/getGunIdsByUserId") |
| | | @ApiOperation(value = "查询当前用户正在充电中的枪id集合", tags = {"小程序-首页-用户充电订单信息"}) |
| | | public R<List<Integer>> getGunIdsByUserId() { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | List<TChargingOrder> list = chargingOrderService.list(Wrappers.lambdaQuery(TChargingOrder.class) |
| | | .eq(TChargingOrder::getAppUserId, userId) |
| | | .eq(TChargingOrder::getStatus, 3)); |
| | | List<Integer> gunIds = list.stream().map(TChargingOrder::getChargingGunId).collect(Collectors.toList()); |
| | | return R.ok(gunIds); |
| | | } |
| | | |
| | | |
| | | |
| | | private static List<TChargingOrder> getSampleData() { |
| | |
| | | return resultList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 硬件充电结束后的处理逻辑 |
| | | * @param code |
| | | */ |
| | | @PostMapping("/endCharge") |
| | | public void endCharge(@RequestParam("code") String code){ |
| | | log.error(code + ":-------------------充电桩自动结束充电-------------------"); |
| | | chargingOrderService.endCharge(code, 2); |
| | | } |
| | | |
| | | /** |
| | | * 硬件异常结束充电后的处理逻辑 |
| | | * @param code |
| | | */ |
| | | @PostMapping("/excelEndCharge") |
| | | public void excelEndCharge(@RequestParam("code") String code){ |
| | | log.error(code + ":-------------------充电异常,停止充电-------------------"); |
| | | chargingOrderService.excelEndCharge(code); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据车牌号和时间查询有效的充电数据 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @PostMapping("/getChargingOrderByLicensePlate") |
| | | public R<TChargingOrder> getChargingOrderByLicensePlate(@RequestBody GetChargingOrderByLicensePlate query){ |
| | | TChargingOrder chargingOrder = chargingOrderService.getChargingOrderByLicensePlate(query); |
| | | return R.ok(chargingOrder); |
| | | } |
| | | /** |
| | | * 修改充电订单 |
| | | * @param chargingOrder |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateChargingOrder") |
| | | public R<String> updateChargingOrder(@RequestBody TChargingOrder chargingOrder){ |
| | | chargingOrderService.updateById(chargingOrder); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/getEndOfChargePageInfo/{id}") |
| | | @ApiOperation(value = "获取充电结束页面数据", tags = {"小程序-扫一扫"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "订单id", required = true) |
| | | }) |
| | | public AjaxResult<EndOfChargePageInfo> getEndOfChargePageInfo(@PathVariable("id") String id){ |
| | | EndOfChargePageInfo endOfChargePageInfo = chargingOrderService.getEndOfChargePageInfo(id); |
| | | return AjaxResult.success(endOfChargePageInfo); |
| | | } |
| | | } |