From 4bb466546011753c19c0d576bed4b57352e9f92e Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Thu, 16 Oct 2025 16:26:14 +0800 Subject: [PATCH] update --- .../api/thirdparty/ChangZhouController.java | 38 ++++- .../BusinessStationInfoController.java | 20 +++ .../pile/mapper/OrderBasicInfoMapper.java | 7 + .../pile/service/OrderBasicInfoService.java | 9 ++ .../pile/service/PileStationInfoService.java | 2 + .../impl/OrderBasicInfoServiceImpl.java | 5 + .../impl/PileStationInfoServiceImpl.java | 149 ++++++++++++++++++ .../mapper/pile/OrderBasicInfoMapper.xml | 30 ++++ 8 files changed, 254 insertions(+), 6 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/ChangZhouController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/ChangZhouController.java index 42877c830..f3002c9c1 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/ChangZhouController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/ChangZhouController.java @@ -5,6 +5,7 @@ import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.dto.thirdparty.JCTCommonParamsDTO; import com.jsowell.common.dto.thirdparty.JCTPushRealTimeInfoDTO; +import com.jsowell.common.dto.thirdparty.JCTQueryEquipmentDTO; import com.jsowell.common.dto.thirdparty.JCTQueryStationInfoDTO; import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; @@ -172,8 +173,16 @@ public class ChangZhouController extends ThirdPartyBaseController { // 解析入参 QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); - // 执行逻辑 - Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + // 新方法 + JCTQueryStationInfoDTO jctQueryStationInfoDTO = new JCTQueryStationInfoDTO(); + BeanUtils.copyProperties(queryStationInfoDTO, jctQueryStationInfoDTO); + jctQueryStationInfoDTO.setPlatformType(platformType); + logger.info("请求参数转换后:{}" , JSON.toJSONString(jctQueryStationInfoDTO)); + Map map = thirdPartyService.queryStationStatus(jctQueryStationInfoDTO); + + // 旧方法 + // Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + logger.info("{}-设备接口状态查询 result:{}" , platformName , map); return CommonResult.success(0 , "设备接口状态查询成功!" , map.get("Data") , map.get("Sig")); } catch (Exception e) { @@ -207,8 +216,17 @@ public class ChangZhouController extends ThirdPartyBaseController { // 解析入参 QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); - // 执行逻辑 - Map map = platformLogic.queryStationStats(queryStationInfoDTO); + + // 新方法 + JCTQueryStationInfoDTO jctQueryStationInfoDTO = new JCTQueryStationInfoDTO(); + BeanUtils.copyProperties(queryStationInfoDTO, jctQueryStationInfoDTO); + jctQueryStationInfoDTO.setPlatformType(platformType); + logger.info("请求参数转换后:{}" , JSON.toJSONString(jctQueryStationInfoDTO)); + Map map = thirdPartyService.queryStationStats(jctQueryStationInfoDTO); + + // 旧方法 + // Map map = platformLogic.queryStationStats(queryStationInfoDTO); + logger.info("{}-查询统计信息 result:{}" , platformName , map); return CommonResult.success(0 , "查询统计信息成功!" , map.get("Data") , map.get("Sig")); } catch (Exception e) { @@ -244,8 +262,16 @@ public class ChangZhouController extends ThirdPartyBaseController { // 解析入参 QueryEquipmentDTO queryEquipmentDTO = parseParamsDTO(dto , QueryEquipmentDTO.class); - // 执行逻辑 - Map map = platformLogic.queryEquipAuth(queryEquipmentDTO); + // 新方法 + JCTQueryEquipmentDTO jctQueryEquipmentDTO = new JCTQueryEquipmentDTO(); + BeanUtils.copyProperties(queryEquipmentDTO, jctQueryEquipmentDTO); + jctQueryEquipmentDTO.setPlatformType(platformType); + logger.info("请求参数转换后:{}" , JSON.toJSONString(jctQueryEquipmentDTO)); + Map map = thirdPartyService.queryEquipAuth(jctQueryEquipmentDTO); + + // 旧方法 + // Map map = platformLogic.queryEquipAuth(queryEquipmentDTO); + logger.info("{}-请求设备认证 result:{}" , platformName , map); return CommonResult.success(0 , "请求设备认证成功!" , map.get("Data") , map.get("Sig")); } catch (Exception e) { diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessStationInfoController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessStationInfoController.java index dccac02d9..f78eca58a 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessStationInfoController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessStationInfoController.java @@ -71,6 +71,26 @@ public class BusinessStationInfoController extends BaseController { return response; } + /** + * 获取站点运营分析信息(7天、30天,1年) + * @param dto + * @return + */ + @PostMapping("/getStationBusinessAnalyzeInfoV1") + public RestApiResponse getStationBusinessAnalyzeInfoV1(@RequestBody StationBusinessAnalyzeInfoDTO dto){ + RestApiResponse response = null; + try { + StationBusinessAnalyzeInfoVO vo = pileStationInfoService.getStationBusinessAnalyzeInfoV1(dto); + response = new RestApiResponse<>(ImmutableMap.of("stationBusinessAnalyzeInfoVO", vo)); + } catch (Exception e) { + logger.error("获取站点运营分析信息 error", e); + response = new RestApiResponse<>(e); + } + logger.info("获取站点运营分析信息 params:{}, result:{}", JSONObject.toJSONString(dto), response); + return response; + } + + /** * 获取站点运营分析信息(12个月) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java index fcdb59e52..d410460d1 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java @@ -424,4 +424,11 @@ public interface OrderBasicInfoMapper { * @return */ List getSplitOrders(@Param("dto") QueryOrderSplitRecordDTO dto); + + List getOrderDetailByStationIdsForMonth( + @Param("stationIds") List stationIds, + @Param("startTime") String startTime, + @Param("endTime") String endTime + ); + } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java index b248bea07..e97e30425 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java @@ -622,4 +622,13 @@ public interface OrderBasicInfoService{ void checkOrUpdateOrderSplitRecord(AfterSettleOrderDTO afterSettleOrderDTO); List queryOrderSplitConfigList(String orderCode); + + /** + * 查询近一年的数据 + * @param stationIds + * @param startTime + * @param endTime + * @return + */ + List getOrderDetailByStationIdsForMonth(List stationIds , String startTime , String endTime); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileStationInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileStationInfoService.java index d14a31e52..4f006ed75 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileStationInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileStationInfoService.java @@ -187,6 +187,8 @@ public interface PileStationInfoService { */ StationBusinessAnalyzeInfoVO getStationBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto); + StationBusinessAnalyzeInfoVO getStationBusinessAnalyzeInfoV1(StationBusinessAnalyzeInfoDTO dto); + /** * 获取站点运营分析信息(12个月) * @param dto diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 07047c300..3251ac003 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -5907,5 +5907,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { logger.info("校验或更新订单分账信息-订单:{}, 获取的订单分账配置:{}", orderCode, JSON.toJSONString(resultList)); return resultList; } + + @Override + public List getOrderDetailByStationIdsForMonth(List stationIds , String startTime , String endTime) { + return orderBasicInfoMapper.getOrderDetailByStationIdsForMonth(stationIds, startTime, endTime); + } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java index a1361b5db..3f33428ff 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -1178,6 +1178,155 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { return vo; } + + /** + * 获取站点运营分析信息(7天、30天) + * + * @param dto + */ + @Override + public StationBusinessAnalyzeInfoVO getStationBusinessAnalyzeInfoV1(StationBusinessAnalyzeInfoDTO dto) { + StationBusinessAnalyzeInfoVO vo = new StationBusinessAnalyzeInfoVO(); + + String dateTime = dto.getDateTime(); + String type = dto.getType(); + List stationIds = dto.getStationIds(); + + // 如果没有传 stationIds,则查当前账号下所有站点 + if (CollectionUtils.isEmpty(stationIds)) { + List merchantInfoVOList = UserUtils.getMerchantInfoVOList(); + if (CollectionUtils.isEmpty(merchantInfoVOList)) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + List merchantIds = merchantInfoVOList.stream() + .map(MerchantInfoVO::getMerchantId) + .collect(Collectors.toList()); + + List pileStationInfos = getStationInfosByMerchantIds(merchantIds); + if (CollectionUtils.isEmpty(pileStationInfos)) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + stationIds = pileStationInfos.stream() + .map(x -> String.valueOf(x.getId())) + .collect(Collectors.toList()); + } + + List orderDetails; + + if (StringUtils.equals(Constants.THREE, type)) { + // 近12个月 + String startTime = DateUtils.getFirstDayOfLastYearMonth(); // 去年同月第一天 + String endTime = DateUtils.getLastDayOfCurrentMonth(); // 本月最后一天 + orderDetails = orderBasicInfoService.getOrderDetailByStationIdsForMonth(stationIds, startTime, endTime); + } else { + // 日期区间(7天或30天) + Date startDate; + if (StringUtils.equals(Constants.ONE, type)) { + startDate = DateUtils.addDays(new Date(), -7); + } else if (StringUtils.equals(Constants.TWO, type)) { + startDate = DateUtils.addDays(new Date(), -30); + } else { + // 默认7天 + startDate = DateUtils.addDays(new Date(), -7); + } + String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startDate); + String endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + orderDetails = orderBasicInfoService.getOrderDetailByStationIds(stationIds, startTime, endTime); + } + + if (CollectionUtils.isEmpty(orderDetails)) { + return vo; + } + + // 空值安全处理 + for (BusinessOrderDetailInfoVO orderDetail : orderDetails) { + orderDetail.setSharpAmount(Optional.ofNullable(orderDetail.getSharpAmount()).orElse(BigDecimal.ZERO)); + orderDetail.setPeakAmount(Optional.ofNullable(orderDetail.getPeakAmount()).orElse(BigDecimal.ZERO)); + orderDetail.setFlatAmount(Optional.ofNullable(orderDetail.getFlatAmount()).orElse(BigDecimal.ZERO)); + orderDetail.setValleyAmount(Optional.ofNullable(orderDetail.getValleyAmount()).orElse(BigDecimal.ZERO)); + orderDetail.setSharpUsedElectricity(Optional.ofNullable(orderDetail.getSharpUsedElectricity()).orElse(BigDecimal.ZERO)); + orderDetail.setPeakUsedElectricity(Optional.ofNullable(orderDetail.getPeakUsedElectricity()).orElse(BigDecimal.ZERO)); + orderDetail.setFlatUsedElectricity(Optional.ofNullable(orderDetail.getFlatUsedElectricity()).orElse(BigDecimal.ZERO)); + orderDetail.setValleyUsedElectricity(Optional.ofNullable(orderDetail.getValleyUsedElectricity()).orElse(BigDecimal.ZERO)); + orderDetail.setTotalServiceAmount(Optional.ofNullable(orderDetail.getTotalServiceAmount()).orElse(BigDecimal.ZERO)); + orderDetail.setSettleAmount(Optional.ofNullable(orderDetail.getSettleAmount()).orElse(BigDecimal.ZERO)); + } + + // 聚合汇总 + Map collect = orderDetails.stream() + .sorted(Comparator.comparing(BusinessOrderDetailInfoVO::getTradeDate)) + .collect(Collectors.toMap(BusinessOrderDetailInfoVO::getTradeDate, Function.identity(), (a, b) -> { + a.setSharpUsedElectricity(a.getSharpUsedElectricity().add(b.getSharpUsedElectricity())); + a.setSharpAmount(a.getSharpAmount().add(b.getSharpAmount())); + a.setPeakUsedElectricity(a.getPeakUsedElectricity().add(b.getPeakUsedElectricity())); + a.setPeakAmount(a.getPeakAmount().add(b.getPeakAmount())); + a.setFlatUsedElectricity(a.getFlatUsedElectricity().add(b.getFlatUsedElectricity())); + a.setFlatAmount(a.getFlatAmount().add(b.getFlatAmount())); + a.setValleyUsedElectricity(a.getValleyUsedElectricity().add(b.getValleyUsedElectricity())); + a.setValleyAmount(a.getValleyAmount().add(b.getValleyAmount())); + a.setTotalServiceAmount(a.getTotalServiceAmount().add(b.getTotalServiceAmount())); + a.setSettleAmount(a.getSettleAmount().add(b.getSettleAmount())); + a.setTotalUsedElectricity( + a.getSharpUsedElectricity() + .add(a.getPeakUsedElectricity()) + .add(a.getFlatUsedElectricity()) + .add(a.getValleyUsedElectricity()) + ); + return a; + })); + + // TreeMap 排序 + TreeMap map = new TreeMap<>(collect); + List detailList = new ArrayList<>(map.values()); + + // 对比变量 + BigDecimal todayUsed = BigDecimal.ZERO, yesterdayUsed = BigDecimal.ZERO; + BigDecimal todaySettle = BigDecimal.ZERO, yesterdaySettle = BigDecimal.ZERO; + BigDecimal todayService = BigDecimal.ZERO, yesterdayService = BigDecimal.ZERO; + + BusinessOrderDetailInfoVO todayInfo = null, yesterdayInfo = null; + + if (StringUtils.isNotBlank(dateTime)) { + todayInfo = map.get(dateTime); + String yesterdayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, + DateUtils.addDays(DateUtils.parseDate(dateTime), -1)); + yesterdayInfo = map.get(yesterdayStr); + } else if (!detailList.isEmpty() && detailList.size() > 1) { + todayInfo = detailList.get(detailList.size() - 1); + yesterdayInfo = detailList.get(detailList.size() - 2); + } + + if (todayInfo != null && yesterdayInfo != null) { + todayUsed = todayInfo.getTotalUsedElectricity(); + yesterdayUsed = yesterdayInfo.getTotalUsedElectricity(); + todaySettle = todayInfo.getSettleAmount(); + yesterdaySettle = yesterdayInfo.getSettleAmount(); + todayService = todayInfo.getTotalServiceAmount(); + yesterdayService = yesterdayInfo.getTotalServiceAmount(); + } + + // 计算增长率 + vo.setElectricityGrowthRate(calcGrowthRate(todayUsed, yesterdayUsed)); + vo.setOrderAmountGrowthRate(calcGrowthRate(todaySettle, yesterdaySettle)); + vo.setServiceAmountGrowthRate(calcGrowthRate(todayService, yesterdayService)); + vo.setBusinessOrderDetailInfoVOList(detailList); + + return vo; + } + + /** 计算增长率 */ + private String calcGrowthRate(BigDecimal now, BigDecimal last) { + if (last == null || last.compareTo(BigDecimal.ZERO) == 0) { + return "0%"; + } + BigDecimal rate = now.subtract(last) + .divide(last, 4, BigDecimal.ROUND_HALF_UP) + .multiply(new BigDecimal("100")); + return rate.stripTrailingZeros().toPlainString() + "%"; + } + + + /** * 获取站点运营分析信息(12个月) * diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml index b1216fabf..3e6626bd0 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml @@ -3421,4 +3421,34 @@ AND #{dto.endTime,jdbcType=VARCHAR} AND t1.`settle_amount` > 0; + +