| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | fillAppletExtra(records); |
| | | page.setRecords(records); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> appletDetail(Long chargingOrderId) { |
| | | TVinChargingOrder order = getAuthorizedAppletOrder(chargingOrderId); |
| | | if (order == null) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("id", String.valueOf(order.getId())); |
| | | result.put("chargingGunId", order.getChargingGunId()); |
| | | result.put("code", order.getCode()); |
| | | result.put("createTime", order.getCreateTime() == null ? null |
| | | : order.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | result.put("status", order.getStatus()); |
| | | result.put("licensePlate", order.getPlateNum()); |
| | | result.put("startTime", toEpochMilli(order.getStartTime())); |
| | | result.put("endTime", toEpochMilli(order.getEndTime())); |
| | | result.put("orderAmount", order.getOrderAmount()); |
| | | result.put("paymentAmount", order.getPaymentAmount()); |
| | | result.put("rechargeAmount", order.getRechargeAmount()); |
| | | result.put("couponDiscountAmount", order.getCouponDiscountAmount()); |
| | | result.put("vipDiscountAmount", order.getVipDiscountAmount()); |
| | | result.put("refundAmount", order.getRefundAmount()); |
| | | result.put("electricMoney", order.getElectrovalence()); |
| | | result.put("serviceMoney", order.getServiceCharge()); |
| | | result.put("totalElectricQuantity", order.getChargingCapacity()); |
| | | result.put("stageCost", baseMapper.accountingStrategyList(order.getId())); |
| | | result.put("actionable", 0); |
| | | result.put("isAppeal", 0); |
| | | |
| | | Site site = getSite(order.getSiteId()); |
| | | result.put("title", site == null ? "未知电站" : site.getName()); |
| | | TChargingGun gun = getGun(order.getChargingGunId()); |
| | | result.put("chargeMode", gun == null ? null : gun.getChargeMode()); |
| | | result.put("name", gun == null ? null : gun.getName()); |
| | | fillAppletMonitoring(result, order.getCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | .orElse(Collections.emptyList()).stream().map(GetSiteListDTO::getId).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private TVinChargingOrder getAuthorizedAppletOrder(Long chargingOrderId) { |
| | | if (chargingOrderId == null || tokenService.getLoginUserApplet() == null |
| | | || tokenService.getLoginUserApplet().getUserId() == null) { |
| | | return null; |
| | | } |
| | | TVinChargingOrder order = getById(chargingOrderId); |
| | | if (order == null || order.getVinId() == null) { |
| | | return null; |
| | | } |
| | | R<List<Long>> response = vinManagementClient.getVinIdsByAppUserId( |
| | | tokenService.getLoginUserApplet().getUserId()); |
| | | List<Long> vinIds = response == null ? Collections.emptyList() |
| | | : Optional.ofNullable(response.getData()).orElse(Collections.emptyList()); |
| | | return vinIds.contains(order.getVinId()) ? order : null; |
| | | } |
| | | |
| | | private Long toEpochMilli(LocalDateTime time) { |
| | | return time == null ? null : time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | } |
| | | |
| | | private Site getSite(Integer siteId) { |
| | | if (siteId == null) { |
| | | return null; |
| | | } |
| | | R<List<Site>> response = siteClient.getSiteByIds(Collections.singletonList(siteId)); |
| | | List<Site> sites = response == null ? Collections.emptyList() |
| | | : Optional.ofNullable(response.getData()).orElse(Collections.emptyList()); |
| | | return sites.stream().findFirst().orElse(null); |
| | | } |
| | | |
| | | private TChargingGun getGun(Integer gunId) { |
| | | if (gunId == null) { |
| | | return null; |
| | | } |
| | | R<TChargingGun> response = chargingGunClient.getChargingGunById(gunId); |
| | | return response == null ? null : response.getData(); |
| | | } |
| | | |
| | | private void fillAppletMonitoring(Map<String, Object> result, String orderCode) { |
| | | List<UploadRealTimeMonitoringData> dataList = orderCode == null ? Collections.emptyList() |
| | | : monitoringDataService.getDataByOrderCode(orderCode); |
| | | if (dataList == null || dataList.isEmpty()) { |
| | | result.put("currentAndVoltage", Collections.emptyList()); |
| | | result.put("power", Collections.emptyList()); |
| | | return; |
| | | } |
| | | SimpleDateFormat formatter = new SimpleDateFormat("HH:mm"); |
| | | Map<String, UploadRealTimeMonitoringData> minuteData = new java.util.LinkedHashMap<>(); |
| | | for (UploadRealTimeMonitoringData data : dataList) { |
| | | if (data != null && data.getCreate_time() != null) { |
| | | minuteData.putIfAbsent(formatter.format(data.getCreate_time()), data); |
| | | } |
| | | } |
| | | List<Map<String, Object>> currentAndVoltage = new ArrayList<>(); |
| | | List<Map<String, Object>> power = new ArrayList<>(); |
| | | for (Map.Entry<String, UploadRealTimeMonitoringData> entry : minuteData.entrySet()) { |
| | | UploadRealTimeMonitoringData data = entry.getValue(); |
| | | Map<String, Object> currentItem = new HashMap<>(); |
| | | currentItem.put("time", entry.getKey()); |
| | | currentItem.put("electricity", data.getOutput_current()); |
| | | currentItem.put("voltage", data.getOutput_voltage()); |
| | | currentAndVoltage.add(currentItem); |
| | | |
| | | Map<String, Object> powerItem = new HashMap<>(); |
| | | powerItem.put("time", entry.getKey()); |
| | | powerItem.put("soc", data.getSoc()); |
| | | BigDecimal outputPower = data.getOutput_current() == null || data.getOutput_voltage() == null ? null |
| | | : data.getOutput_current().multiply(data.getOutput_voltage()) |
| | | .divide(new BigDecimal("1000"), 2, RoundingMode.HALF_DOWN); |
| | | powerItem.put("power", outputPower); |
| | | power.add(powerItem); |
| | | } |
| | | result.put("currentAndVoltage", currentAndVoltage); |
| | | result.put("power", power); |
| | | } |
| | | |
| | | private void fillAppletExtra(List<MyVinChargingOrderList> list) { |
| | | if (list == null || list.isEmpty()) { |
| | | return; |