| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserCarClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.vo.*; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取小程序充电记录列表数据 |
| | | * @param query |
| | |
| | | .orderByAsc(TChargingOrderAccountingStrategy::getStartTime) |
| | | ); |
| | | myChargingOrderInfo.setStageCost(stageCost); |
| | | // todo 待完善 |
| | | //再MongoDB中获取数据 |
| | | myChargingOrderInfo.setCurrentAndVoltage(null); |
| | | //再MongoDB中获取数据 |
| | | myChargingOrderInfo.setPower(null); |
| | | List<UploadRealTimeMonitoringData> dataList = uploadRealTimeMonitoringDataClient.getDataByOrderCode(chargingOrder.getCode()).getData(); |
| | | if(null != dataList){ |
| | | //在MongoDB中获取数据 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); |
| | | List<String> time = dataList.stream().map(s -> sdf.format(s.getCreate_time())).collect(Collectors.toList()); |
| | | List<BigDecimal> outputVoltage = dataList.stream().map(UploadRealTimeMonitoringData::getOutput_voltage).collect(Collectors.toList()); |
| | | List<BigDecimal> outputCurrent = dataList.stream().map(UploadRealTimeMonitoringData::getOutput_current).collect(Collectors.toList()); |
| | | List<Map<String, Object>> currentAndVoltage = new ArrayList<>(); |
| | | for (int i = 0; i < time.size(); i++) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("time", time.get(i)); |
| | | //电流 |
| | | map.put("electricity", outputCurrent.get(i)); |
| | | //电压 |
| | | map.put("voltage", outputVoltage.get(i)); |
| | | currentAndVoltage.add(map); |
| | | } |
| | | myChargingOrderInfo.setCurrentAndVoltage(currentAndVoltage); |
| | | //在MongoDB中获取数据 |
| | | List<Integer> soc = dataList.stream().map(UploadRealTimeMonitoringData::getSoc).collect(Collectors.toList()); |
| | | List<BigDecimal> po = dataList.stream().map(s -> s.getOutput_current().multiply(s.getOutput_voltage()).divide(new BigDecimal(1000))).collect(Collectors.toList()); |
| | | List<Map<String, Object>> power = new ArrayList<>(); |
| | | for (int i = 0; i < time.size(); i++) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("time", time.get(i)); |
| | | //soc |
| | | map.put("soc", soc.get(i)); |
| | | //电压 |
| | | map.put("power", po.get(i)); |
| | | power.add(map); |
| | | } |
| | | myChargingOrderInfo.setPower(power); |
| | | } |
| | | myChargingOrderInfo.setActionable(myChargingOrderInfo.getEndTime() + 604800000L > System.currentTimeMillis() ? 0 : 1); |
| | | return myChargingOrderInfo; |
| | | } |
| | |
| | | @Override |
| | | public TCharingOrderVO chargingOrder(ChargingOrderQuery dto) { |
| | | TCharingOrderVO tCharingOrderVO = new TCharingOrderVO(); |
| | | |
| | | |
| | | String startTime1 = null; |
| | | String startTime2 = null; |
| | | String endTime1 = null; |
| | |
| | | endTime1 = split[0]; |
| | | endTime2 = split[1]; |
| | | } |
| | | PageInfo<ChargingOrderVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | |
| | | if (StringUtils.hasLength(dto.getPhone())){ |
| | | List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData(); |
| | | if (data.isEmpty()){ |
| | | data.add(0L); |
| | | tCharingOrderVO.setList(pageInfo); |
| | | return tCharingOrderVO; |
| | | } |
| | | dto.setUserIds(data); |
| | | } |
| | | PageInfo<ChargingOrderVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | List<ChargingOrderVO> list = this.baseMapper.chargingOrder(pageInfo,dto,startTime1,startTime2,endTime1,endTime2); |
| | | |
| | | BigDecimal total = new BigDecimal("0"); |
| | | long time = 0L; |
| | | BigDecimal income = new BigDecimal("0"); |
| | | BigDecimal electronicMoney = new BigDecimal("0"); |
| | | BigDecimal serviceMoney = new BigDecimal("0"); |
| | | for (ChargingOrderVO chargingOrderVO : list) { |
| | | if (chargingOrderVO.getChargingCapacity()!=null){ |
| | | total = total.add(chargingOrderVO.getChargingCapacity()); |
| | | } |
| | | // 充电订单 明细记录 |
| | | List<TChargingOrderAccountingStrategy> chargingOrderId = chargingOrderAccountingStrategyService.list(new QueryWrapper<TChargingOrderAccountingStrategy>() |
| | | .eq("charging_order_id", chargingOrderVO.getId())); |
| | | // 单个订单累计电费 |
| | | BigDecimal electronicMoney1 = new BigDecimal("0"); |
| | | // 单个订单累计服务费 |
| | | BigDecimal serviceMoney1 = new BigDecimal("0"); |
| | | LocalDateTime startTime = chargingOrderVO.getStartTime(); |
| | | LocalDateTime endTime = chargingOrderVO.getEndTime(); |
| | | // 计算时间差 秒 充电时长 |
| | | if (startTime!=null && endTime!=null){ |
| | | long between = ChronoUnit.SECONDS.between(startTime, endTime); |
| | | chargingOrderVO.setChargingSecond(between); |
| | | time += between; |
| | | } |
| | | // 总收入 |
| | | if (chargingOrderVO.getRefundStatus() == 2){ |
| | | income = income.add(chargingOrderVO.getPaymentAmount().subtract(chargingOrderVO.getRefundAmount())); |
| | | }else{ |
| | | income = income.add(chargingOrderVO.getPaymentAmount()); |
| | | } |
| | | for (TChargingOrderAccountingStrategy tChargingOrderAccountingStrategy : chargingOrderId) { |
| | | // 累计电费 |
| | | electronicMoney1 = electronicMoney1.add(tChargingOrderAccountingStrategy.getElectrovalence() |
| | | .multiply(tChargingOrderAccountingStrategy.getChargingCapacity())); |
| | | electronicMoney = electronicMoney.add(electronicMoney1); |
| | | // 累计服务费 |
| | | serviceMoney1 = serviceMoney1.add(tChargingOrderAccountingStrategy.getServiceCharge()); |
| | | serviceMoney = serviceMoney.add(serviceMoney1); |
| | | } |
| | | chargingOrderVO.setServiceCharge(serviceMoney1); |
| | | chargingOrderVO.setElectrovalence(electronicMoney1); |
| | | // 充电时段数 |
| | | int size = chargingOrderId.size(); |
| | | chargingOrderVO.setCount(size); |
| | | // 用户手机号 |
| | | TAppUser data = appUserClient.getUserById(chargingOrderVO.getAppUserId()).getData(); |
| | | if (data!=null){ |
| | | // 车牌号 |
| | | chargingOrderVO.setPhone(data.getPhone()); |
| | | List<Long> longs = new ArrayList<>(); |
| | | longs.add(chargingOrderVO.getAppUserCarId()); |
| | | List<TAppUserCar> data1 = appUserCarClient.getCarByIds(longs).getData(); |
| | | if (!data1.isEmpty()){ |
| | | chargingOrderVO.setLicensePlate(data1.get(0).getLicensePlate()); |
| | | } |
| | | } |
| | | } |
| | | tCharingOrderVO.setTotal(total); |
| | | tCharingOrderVO.setTime(time); |
| | | tCharingOrderVO.setIncome(income); |
| | | tCharingOrderVO.setElectronicMoney(electronicMoney); |
| | | tCharingOrderVO.setServiceMoney(serviceMoney); |
| | | pageInfo.setRecords(list); |
| | | tCharingOrderVO.setList(pageInfo); |
| | | return tCharingOrderVO; |