ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
@@ -35,7 +35,7 @@ @Override public R<TAppUser> getUserById(Long id) { return R.fail("根据id查询用户失败:"+throwable.getMessage()); throw new RuntimeException("根据id查询用户失败:"+throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserVipDetailFallbackFactory.java
@@ -26,7 +26,12 @@ @Override public R<TAppUserVipDetail> getAppUserVipDetail(GetAppUserVipDetail getAppUserVipDetail) { return R.fail("获取用户当前有效的VIP明细调用失败:" + throwable.getMessage()); throw new RuntimeException("获取用户当前有效的VIP明细调用失败:" + throwable.getMessage()); } @Override public void updateAppUserVipDetail(TAppUserVipDetail appUserVipDetail) { throw new RuntimeException(throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserVipDetailClient.java
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.R; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; /** * @author zhibing.pu @@ -24,4 +25,10 @@ R<TAppUserVipDetail> getAppUserVipDetail(GetAppUserVipDetail getAppUserVipDetail); /** * 修改会员明细 * @param appUserVipDetail */ @PostMapping("/appUserVipDetail/updateAppUserVipDetail") void updateAppUserVipDetail(@RequestBody TAppUserVipDetail appUserVipDetail); } ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/AccountingStrategyDetailFallbackFactory.java
New file @@ -0,0 +1,31 @@ package com.ruoyi.chargingPile.api.factory; import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyDetailClient; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.common.core.domain.R; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; /** * @author zhibing.pu * @Date 2024/8/28 18:33 */ @Component public class AccountingStrategyDetailFallbackFactory implements FallbackFactory<AccountingStrategyDetailClient> { private static final Logger log = LoggerFactory.getLogger(AccountingStrategyDetailFallbackFactory.class); @Override public AccountingStrategyDetailClient create(Throwable throwable) { log.error("计费策略调用失败:{}", throwable.getMessage()); return new AccountingStrategyDetailClient(){ @Override public R<TAccountingStrategyDetail> getNowData(Integer accountingStrategyId) { return R.fail("获取当前有效的计费策略明细失败:" + throwable.getMessage()); } }; } } ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/ChargingGunFallbackFactory.java
@@ -35,7 +35,7 @@ @Override public R<TChargingGun> getChargingGunById(Integer id) { return R.fail("根据id获取充电枪失败:" + throwable.getMessage()); throw new RuntimeException("根据id获取充电枪失败:" + throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/feignClient/AccountingStrategyDetailClient.java
New file @@ -0,0 +1,26 @@ package com.ruoyi.chargingPile.api.feignClient; import com.ruoyi.chargingPile.api.factory.AccountingStrategyDetailFallbackFactory; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; /** * @author zhibing.pu * @Date 2024/8/28 18:33 */ @FeignClient(contextId = "AccountingStrategyDetailClient", value = ServiceNameConstants.CHARGINGPILE_SERVICE, fallbackFactory = AccountingStrategyDetailFallbackFactory.class) public interface AccountingStrategyDetailClient { /** * 获取当前有效的计费策略明细 * @param accountingStrategyId * @return */ @PostMapping("/t-accounting-strategy-detail/getNowData") R<TAccountingStrategyDetail> getNowData(@RequestParam("accountingStrategyId") Integer accountingStrategyId); } ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TAccountingStrategy.java
@@ -85,6 +85,8 @@ @TableField("two_audit_time") private LocalDateTime twoAuditTime; @ApiModelProperty(value = "父级id 上一次已审核通过的id 为空则代表是新增,或者本次数据状态审核中或已拒绝") @TableField("parent_id") private Integer parentId; } ruoyi-api/ruoyi-api-chargingPile/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,4 +1,5 @@ com.ruoyi.chargingPile.api.factory.ChargingPileFallbackFactory com.ruoyi.chargingPile.api.factory.SiteFallbackFactory com.ruoyi.chargingPile.api.factory.ParkingLotFallbackFactory com.ruoyi.chargingPile.api.factory.ChargingGunFallbackFactory com.ruoyi.chargingPile.api.factory.ChargingGunFallbackFactory com.ruoyi.chargingPile.api.factory.AccountingStrategyDetailFallbackFactory ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/PlatformStartChargingReplyFallbackFactory.java
New file @@ -0,0 +1,34 @@ package com.ruoyi.integration.api.factory; import com.ruoyi.common.core.domain.R; import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient; import com.ruoyi.integration.api.model.PlatformStartChargingReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; import java.util.List; /** * @author zhibing.pu * @Date 2024/8/31 15:16 */ @Component public class PlatformStartChargingReplyFallbackFactory implements FallbackFactory<PlatformStartChargingReplyClient> { private static final Logger log = LoggerFactory.getLogger(PlatformStartChargingReplyFallbackFactory.class); @Override public PlatformStartChargingReplyClient create(Throwable throwable) { log.error("远程启机应答调用失败:{}", throwable.getMessage()); return new PlatformStartChargingReplyClient(){ @Override public R<List<PlatformStartChargingReply>> getPlatformStartChargingReply(String code) { return R.fail("根据订单编号查询远程启机应答结果失败:" + throwable.getMessage()); } }; } } ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SendMessageFallbackFactory.java
@@ -28,6 +28,7 @@ @Override public void platformStartCharging(PlatformStartCharging platformStartCharging) { throw new RuntimeException("远程启机失败" + throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/PlatformStartChargingReplyClient.java
New file @@ -0,0 +1,28 @@ package com.ruoyi.integration.api.feignClient; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.integration.api.factory.PlatformStartChargingReplyFallbackFactory; import com.ruoyi.integration.api.model.PlatformStartChargingReply; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; /** * @author zhibing.pu * @Date 2024/8/31 15:16 */ @FeignClient(contextId = "PlatformStartChargingReplyClient", value = ServiceNameConstants.INTEGRATION_SERVICE, fallbackFactory = PlatformStartChargingReplyFallbackFactory.class) public interface PlatformStartChargingReplyClient { /** * 根据订单编号查询远程启机应答结果 * @param code * @return */ @PostMapping("/platformStartChargingReply/getPlatformStartChargingReply") R<List<PlatformStartChargingReply>> getPlatformStartChargingReply(@RequestParam("code") String code); } ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SendMessageClient.java
@@ -2,7 +2,6 @@ import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.integration.api.factory.SendMessageFallbackFactory; import com.ruoyi.integration.api.model.EndCharge; import com.ruoyi.integration.api.model.PlatformStartCharging; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/UploadRealTimeMonitoringData.java
@@ -3,7 +3,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import java.math.BigDecimal; @@ -17,7 +16,6 @@ @Accessors(chain = true) public class UploadRealTimeMonitoringData extends BaseModel { @Id private String transaction_serial_number; // 交易流水号 private String charging_pile_code; // 桩编码 private String charging_gun_code; // 抢号 @@ -45,6 +43,8 @@ private BigDecimal period_service_price;// @ApiModelProperty("时段服务费") private BigDecimal period_charging_degree;// @ApiModelProperty("时段充电度数") } ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,4 +1,5 @@ com.ruoyi.integration.api.factory.IntegrationFallbackFactory com.ruoyi.integration.api.factory.UploadRealTimeMonitoringDataFallbackFactory com.ruoyi.integration.api.factory.ChargingHandshakeFallbackFactory com.ruoyi.integration.api.factory.SendMessageFallbackFactory com.ruoyi.integration.api.factory.SendMessageFallbackFactory com.ruoyi.integration.api.factory.PlatformStartChargingReplyFallbackFactory ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/factory/ChargingOrderFallbackFactory.java
@@ -6,6 +6,7 @@ import com.ruoyi.order.api.feignClient.ChargingOrderClient; import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.query.TChargingCountQuery; import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -63,6 +64,10 @@ public R<Long> getCar() { return R.fail("获取用户最近使用车辆充电的车辆id:" + throwable.getMessage()); } @Override public void chargeMonitoring(UploadRealTimeMonitoringDataQuery query) { } }; } } ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/feignClient/ChargingOrderClient.java
@@ -7,6 +7,7 @@ import com.ruoyi.order.api.factory.ChargingOrderFallbackFactory; import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.query.TChargingCountQuery; import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -60,4 +61,13 @@ */ @GetMapping(value = "/t-charging-order/getCar") public R<Long> getCar(); /** * 处理充电订单实时监控数据相关的业务逻辑 * @param query * @return */ @PostMapping(value = "/t-charging-order/chargeMonitoring") void chargeMonitoring(@RequestBody UploadRealTimeMonitoringDataQuery query); } ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java
@@ -122,6 +122,10 @@ @ApiModelProperty(value = "充值支付第三方流水号") @TableField("recharge_serial_number") private String rechargeSerialNumber; @ApiModelProperty(value = "剩余金额(用于前端展示)") @TableField("residual_amount") private BigDecimal residualAmount; @ApiModelProperty(value = "订单金额(总金额)") @TableField("order_amount") @@ -182,11 +186,4 @@ @TableField("pay_time") private LocalDateTime payTime; @ApiModelProperty(value = "累计服务费") @TableField("service_charge") private BigDecimal serviceCharge; @ApiModelProperty(value = "累计电费") @TableField("electrovalence") private BigDecimal electrovalence; } ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/query/UploadRealTimeMonitoringDataQuery.java
New file @@ -0,0 +1,36 @@ package com.ruoyi.order.api.query; import lombok.Data; import java.math.BigDecimal; import java.util.Date; /** * 上传实时监测数据 **/ @Data public class UploadRealTimeMonitoringDataQuery { private String transaction_serial_number; // 交易流水号 private String charging_pile_code; // 桩编码 private String charging_gun_code; // 抢号 private Integer charging_gun_status; // 状态(0:离线,1:故障,2:空闲,3:充电) private Integer homing_status; // 枪是否归位(0:否,1:是,2:未知) private Integer insertion_status; // 是否插枪(0:否,1:是) private BigDecimal output_voltage; // 输出电压,精确到小数点后一位;待机置零 private BigDecimal output_current; // 输出电流,精确到小数点后一位;待机置零 private Integer gun_line_temperature; // 枪线温度,整形,偏移量-50;待机置零 private String gun_line_code; // 枪线编码,没有置零 private Integer soc; // SOC待机置零;交流桩置零 private Integer battery_temperature; // 电池组最高温度,整形,偏移量-50 ºC;待机置零;交流桩置零 private Integer cumulative_charging_time; // 累计充电时间,单位:min;待机置零 private Integer time_remaining; // 剩余时间,单位:min;待机置零、交流桩置零 private BigDecimal charging_degree; // 充电度数,精确到小数点后四位;待机置零 private BigDecimal loss_of_charging_degree; // 计损充电度数,精确到小数点后四位;待机置零,未设置计损比例时等于充电度数 private BigDecimal paid_amount; // 已充金额,精确到小数点后四位;待机置零(电费+服务费)*计损充电度数 private Integer hardware_fault; // 硬件故障(1:急停按钮动作故障;2:无可用整流模块;3:出风口温度过高;4:交流防雷故障;5:交直流模块 DC20 通信中断;6:绝缘检测模块 FC08 通信中断;7:电度表通信中断;8:读卡器通信中断;9:RC10 通信中断;10:风扇调速板故障;11:直流熔断器故障;12:高压接触器故障;13:门打开) private Date create_time; } ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/vo/TOrderAppealVO.java
@@ -35,5 +35,7 @@ private String gunName; @ApiModelProperty(value = "枪号") private String gunNumber; @ApiModelProperty(value = "结束方式(0=异常终止,1=主动终止,2=满电终止,3=费用不足终止)") private Integer endMode; } ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserVipDetailController.java
@@ -56,6 +56,15 @@ } return R.ok(list); } /** * 修改会员明细 * @param appUserVipDetail */ @PostMapping("/updateAppUserVipDetail") public void updateAppUserVipDetail(@RequestBody TAppUserVipDetail appUserVipDetail){ appUserVipDetailService.updateById(appUserVipDetail); } } ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TAccountingStrategyController.java
@@ -16,6 +16,7 @@ import com.ruoyi.chargingPile.service.TChargingPileService; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.dto.SteategyPassDto; import com.ruoyi.common.core.enums.AuditStateEnum; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.BaseDelete; import com.ruoyi.common.core.web.page.PageInfo; @@ -40,6 +41,7 @@ import java.time.LocalTime; import java.util.Arrays; import java.util.List; import java.util.Objects; import static com.ruoyi.common.core.context.SecurityContextHolder.getUserId; @@ -115,7 +117,6 @@ // 添加明细 dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); // TODO 硬件 同步策略到充电桩 return AjaxResult.ok(dto.getId()); } @@ -125,19 +126,52 @@ @Log(title = "修改计费策略", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE) @ApiOperation(tags = {"后台-计费策略", "管理后台-站点管理"},value = "修改计费策略") @PostMapping(value = "/update") public AjaxResult<Boolean> update(@RequestBody TAccountingStrategyDTO dto) { public AjaxResult<String> update(@RequestBody TAccountingStrategyDTO dto) { Boolean flag = accountingStrategyDetailService.isStrategy24Hour(dto.getAccountingStrategyDetails()); if(flag){ return AjaxResult.error("计费模板时间设置有误差"); } // 删除计费策略明细信息 accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, dto.getId())); accountingStrategyService.updateById(dto); // 添加明细 dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); // TODO 硬件 同步策略到充电桩 return AjaxResult.ok(accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails())); // 判断修改的计费策略是否为已通过 if(dto.getAuditStatus() == 3 || dto.getAuditStatus() == 4){ // 查询是否有下级审核中的策略 TAccountingStrategy children = accountingStrategyService.getOne(Wrappers.lambdaQuery(TAccountingStrategy.class) .eq(TAccountingStrategy::getParentId, dto.getId()) .ne(TAccountingStrategy::getAuditStatus, Arrays.asList(3,4))); if(Objects.nonNull(children)){ // 删除计费策略明细信息 accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, children.getId())); dto.setAuditStatus(1); accountingStrategyService.updateById(dto); // 添加明细 dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); }else { Long userId = SecurityUtils.getLoginUser().getUserid(); dto.setUserId(userId); dto.setAuditStatus(1); dto.setId(null); dto.setParentId(dto.getId()); accountingStrategyService.save(dto); // 添加明细 List<TAccountingStrategyDetail> accountingStrategyDetails = dto.getAccountingStrategyDetails(); accountingStrategyDetails.forEach(detail -> { detail.setAccountingStrategyId(dto.getId()); detail.setId(null); }); accountingStrategyDetailService.saveBatch(accountingStrategyDetails); } }else { // 删除计费策略明细信息 accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, dto.getId())); dto.setAuditStatus(1); accountingStrategyService.updateById(dto); // 添加明细 dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId())); accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()); } return AjaxResult.success(); } /** @@ -162,12 +196,61 @@ } /** * 查看计费策略详情-修改后 */ @ApiOperation(tags = {"后台-计费策略", "管理后台-站点管理"},value = "查看计费策略详情修改后children的数据") @GetMapping(value = "/getDetailChildrenById") public AjaxResult<TAccountingStrategyVO> getDetailChildrenById(@RequestParam("id") Integer id) { TAccountingStrategyVO accountingStrategyVO = new TAccountingStrategyVO(); // 先查询children对象 TAccountingStrategy children = accountingStrategyService.getOne(Wrappers.lambdaQuery(TAccountingStrategy.class) .eq(TAccountingStrategy::getParentId, id) .orderByDesc(TAccountingStrategy::getCreateTime) .last("LIMIT 1")); if(Objects.nonNull(children)){ BeanUtils.copyProperties(children,accountingStrategyVO); // 查询用户信息 if(null != children.getFirstUserId()){ String firstUserName = sysUserClient.getSysUser(children.getFirstUserId()).getData().getNickName(); accountingStrategyVO.setFirstUserName(firstUserName); } if(null != children.getTwoUserId()){ String twoUserName = sysUserClient.getSysUser(children.getTwoUserId()).getData().getNickName(); accountingStrategyVO.setTwoUserName(twoUserName); } accountingStrategyVO.setAccountingStrategyDetailList(accountingStrategyDetailService.list(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, children.getId()))); }else { TAccountingStrategy accountingStrategy = accountingStrategyService.getById(id); BeanUtils.copyProperties(accountingStrategy,accountingStrategyVO); // 查询用户信息 if(null != accountingStrategy.getFirstUserId()){ String firstUserName = sysUserClient.getSysUser(accountingStrategy.getFirstUserId()).getData().getNickName(); accountingStrategyVO.setFirstUserName(firstUserName); } if(null != accountingStrategy.getTwoUserId()){ String twoUserName = sysUserClient.getSysUser(accountingStrategy.getTwoUserId()).getData().getNickName(); accountingStrategyVO.setTwoUserName(twoUserName); } accountingStrategyVO.setAccountingStrategyDetailList(accountingStrategyDetailService.list(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, id))); } return AjaxResult.ok(accountingStrategyVO); } /** * 删除计费策略 */ @Log(title = "删除计费策略", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE) @ApiOperation(tags = {"后台-计费策略"},value = "删除计费策略") @DeleteMapping(value = "/deleteById") public AjaxResult<Boolean> deleteById(@RequestParam("id") Integer id) { // 判断策略是否在使用 long count = siteService.count(Wrappers.lambdaQuery(Site.class) .eq(Site::getAccountingStrategyId, id)); if(count>0){ return AjaxResult.error("该计费策略正在使用中,无法删除"); } // 刪除计费策略明细信息 accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .eq(TAccountingStrategyDetail::getAccountingStrategyId, id)); @@ -182,6 +265,12 @@ @DeleteMapping(value = "/deleteByIds") public AjaxResult<Boolean> deleteByIds(@RequestParam String ids) { String[] split = ids.split(","); // 判断策略是否在使用 long count = siteService.count(Wrappers.lambdaQuery(Site.class) .in(Site::getAccountingStrategyId, Arrays.asList(split))); if(count>0){ return AjaxResult.error("该计费策略正在使用中,无法删除"); } // 刪除计费策略明细信息 accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class) .in(TAccountingStrategyDetail::getAccountingStrategyId, Arrays.asList(split))); ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TAccountingStrategyDetailController.java
@@ -1,23 +1,23 @@ package com.ruoyi.chargingPile.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.chargingPile.api.model.Site; import com.ruoyi.chargingPile.api.model.TAccountingStrategy; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.chargingPile.api.vo.StrategyPriceVO; import com.ruoyi.chargingPile.api.vo.TAccountingStrategyDetailVO; import com.ruoyi.chargingPile.service.ISiteService; import com.ruoyi.chargingPile.service.TAccountingStrategyDetailService; import com.ruoyi.chargingPile.service.TAccountingStrategyService; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.web.domain.AjaxResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Objects; @@ -77,6 +77,19 @@ public AjaxResult<StrategyPriceVO> queryPrice(@RequestParam("siteId") Integer siteId) { return AjaxResult.ok(accountingStrategyDetailService.queryPrice(siteId)); } /** * 获取当前有效的计费模板 * @param accountingStrategyId * @return */ @PostMapping("/getNowData") public R<TAccountingStrategyDetail> getNowData(@RequestParam("accountingStrategyId") Integer accountingStrategyId){ TAccountingStrategyDetail one = accountingStrategyDetailService.getOne(new LambdaQueryWrapper<TAccountingStrategyDetail>() .eq(TAccountingStrategyDetail::getAccountingStrategyId, accountingStrategyId) .last(" and DATE_FORMAT(now(), '%H:%i') between start_time and end_time")); return R.ok(one); } } ruoyi-service/ruoyi-chargingPile/src/main/resources/mapper/chargingPile/TAccountingStrategyMapper.xml
@@ -18,15 +18,16 @@ <result column="two_audit_time" property="twoAuditTime" /> <result column="create_time" property="createTime" /> <result column="del_flag" property="delFlag" /> <result column="parent_id" property="parentId" /> </resultMap> <!-- 通用查询结果列 --> <sql id="Base_Column_List"> id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag,parent_id </sql> <select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO"> SELECT id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag,user_id id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag,user_id,parent_id FROM t_accounting_strategy <where> <if test="query.name != null and query.name != ''"> @@ -45,7 +46,7 @@ <select id="getPlatformAccountingStrategy" resultType="com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO"> SELECT id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag id, site_id, `name`, description, discount,first_user_id,two_user_id,first_remark,two_remark,audit_status,first_audit_time,two_audit_time, create_time, del_flag,parent_id FROM t_accounting_strategy where del_flag = 0 and site_id is not null order by create_time desc </select> </mapper> ruoyi-service/ruoyi-integration/pom.xml
@@ -164,8 +164,11 @@ <artifactId>huaweicloud-sdk-bundle</artifactId> <version>3.1.87</version> </dependency> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-order</artifactId> </dependency> </dependencies> <build> ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/controller/PlatformStartChargingReplyController.java
New file @@ -0,0 +1,35 @@ package com.ruoyi.integration.controller; import com.ruoyi.common.core.domain.R; import com.ruoyi.integration.api.model.PlatformStartChargingReply; import com.ruoyi.integration.mongodb.service.PlatformStartChargingReplyService; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; /** * @author zhibing.pu * @Date 2024/8/31 15:09 */ @RestController @RequestMapping("/platformStartChargingReply") public class PlatformStartChargingReplyController { @Resource private PlatformStartChargingReplyService platformStartChargingReplyService; /** * 根据订单编号查询远程启机应答结果 * @param code * @return */ @PostMapping("/getPlatformStartChargingReply") public R<List<PlatformStartChargingReply>> getPlatformStartChargingReply(@RequestParam("code") String code){ List<PlatformStartChargingReply> platformStartChargingReply = platformStartChargingReplyService.getPlatformStartChargingReply(code); return R.ok(platformStartChargingReply); } } ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/constant/SendTagConstant.java
New file @@ -0,0 +1,109 @@ package com.ruoyi.integration.iotda.constant; /** * @author xiaochen * @Date 2024/8/22 15:28 */ public class SendTagConstant { /** * 充电桩登录认证 */ public static final String ONLINE ="online"; /** * 充电桩心跳包 */ public static final String PING ="ping"; /** * 计费模型验证请求 */ public static final String BILLING_MODE_VERIFY ="billing_mode_verify"; /** * 充电桩计费模型请求 */ public static final String ACQUISITION_BILLING_MODE ="acquisition_billing_mode"; /** * 上传实时监测数据 */ public static final String UPLOAD_REAL_TIME_MONITORING_DATA ="upload_real_time_monitoring_data"; /** * 充电握手 */ public static final String CHARGING_HANDSHAKE ="charging_handshake"; /** * 充电阶段BMS中止 */ public static final String BMS_ABORT ="bms_abort"; /** * 充电阶段充电机中止 */ public static final String MOTOR_ABORT ="motor_abort"; /** * 充电过程BMS需求、充电机输出 */ public static final String BMS_DEMAND_AND_CHARGER_EXPORTATION ="bms_demand_and_charger_exportation"; /** * 充电过程BMS信息 */ public static final String BMS_INFORMATION ="bms_information"; /** * 充电桩主动申请启动充电 */ public static final String CHARGING_PILE_STARTS_CHARGING ="charging_pile_starts_charging"; /** * 远程启机命令回复 */ public static final String PLATFORM_START_CHARGING_REPLY ="platform_start_charging_reply"; /** * 远程停机命令回复 */ public static final String PLATFORM_STOP_CHARGING_REPLY ="platform_stop_charging_reply"; /** * 交易记录 */ public static final String TRANSACTION_RECORD ="transaction_record"; /** * 余额更新应答 */ public static final String UPDATE_BALANCE_REPLY ="update_balance_reply"; /** * 卡数据同步应答 */ public static final String SYNCHRONIZE_OFFLINE_CARD_REPLY ="synchronize_offline_card_reply"; /** * 离线卡数据清除应答 */ public static final String CLEAR_OFFLINE_CARD_REPLY ="clear_offline_card_reply"; /** * 离线卡数据查询应答 */ public static final String QUERY_OFFLINE_CARD_REPLY ="query_offline_card_reply"; /** * 充电桩工作参数设置应答 */ public static final String WORKING_PARAMETER_SETTING_REPLY ="working_parameter_setting_reply"; /** * 对时设置应答 */ public static final String TIMING_SETTING_REPLY ="timing_setting_reply"; /** * 计费模型应答 */ public static final String SETUP_BILLING_MODEL_REPLY ="setup_billing_model_reply"; /** * 地锁数据上送(充电桩上送) */ public static final String GROUND_LOCK_REAL_TIME_DATA ="ground_lock_real_time_data"; /** * 充电桩返回数据(上行) */ public static final String CHARGING_PILE_RETURNS_GROUND_LOCK_DATA ="charging_pile_returns_ground_lock_data"; /** * 远程重启应答 */ public static final String PLATFORM_RESTART_REPLY ="platform_restart_reply"; /** * 远程更新应答 */ public final static String PLATFORM_REMOTE_UPDATE_REPLY ="platform_remote_update_reply"; } ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/enums/SendTagMenu.java
File was deleted ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
@@ -2,7 +2,11 @@ import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.integration.iotda.constant.SendTagConstant; import com.ruoyi.integration.rocket.produce.EnhanceProduce; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.client.producer.SendResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -16,6 +20,8 @@ @RestController public class IotMessageListener { @Autowired private EnhanceProduce enhanceProduce; /** * 设备消息监听 @@ -27,9 +33,85 @@ public AjaxResult<String> message(@RequestBody JSONObject jsonObject) throws IOException { log.info("接收到消息中转:{}",jsonObject); JSONObject content = jsonObject.getJSONObject("content"); if (content.getString("name").equals("device_status_change")){ //设备状态改变 String service_id = content.getString("service_id"); log.info("服务id:{}",service_id); SendResult sendResult; // 设备消息下发 switch (service_id){ case SendTagConstant.ONLINE: sendResult = enhanceProduce.onlineMessage(content); break; case SendTagConstant.PING: sendResult = enhanceProduce.pingMessage(content); break; case SendTagConstant.BILLING_MODE_VERIFY: sendResult = enhanceProduce.billingModeVerifyMessage(content); break; case SendTagConstant.ACQUISITION_BILLING_MODE: sendResult = enhanceProduce.acquisitionBillingModeMessage(content); break; case SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA: sendResult = enhanceProduce.uploadRealTimeMonitoringDataMessage(content); break; case SendTagConstant.CHARGING_HANDSHAKE: sendResult = enhanceProduce.chargingHandshakeMessage(content); break; case SendTagConstant.BMS_ABORT: sendResult = enhanceProduce.bmsAbortMessage(content); break; case SendTagConstant.MOTOR_ABORT: sendResult = enhanceProduce.motorAbortMessage(content); break; case SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION: sendResult = enhanceProduce.bmsDemandAndChargerExportationMessage(content); break; case SendTagConstant.BMS_INFORMATION: sendResult = enhanceProduce.bmsInformationMessage(content); break; case SendTagConstant.CHARGING_PILE_STARTS_CHARGING: sendResult = enhanceProduce.chargingPileStartsChargingMessage(content); break; case SendTagConstant.PLATFORM_START_CHARGING_REPLY: sendResult = enhanceProduce.platformStartChargingReplyMessage(content); break; case SendTagConstant.PLATFORM_STOP_CHARGING_REPLY: sendResult = enhanceProduce.platformStopChargingReplyMessage(content); break; case SendTagConstant.TRANSACTION_RECORD: sendResult = enhanceProduce.transactionRecordMessage(content); break; case SendTagConstant.UPDATE_BALANCE_REPLY: sendResult = enhanceProduce.updateBalanceReplyMessage(content); break; case SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY: sendResult = enhanceProduce.synchronizeOfflineCardReplyMessage(content); break; case SendTagConstant.CLEAR_OFFLINE_CARD_REPLY: sendResult = enhanceProduce.clearOfflineCardReplyMessage(content); break; case SendTagConstant.WORKING_PARAMETER_SETTING_REPLY: sendResult = enhanceProduce.workingParameterSettingReplyMessage(content); break; case SendTagConstant.TIMING_SETTING_REPLY: sendResult = enhanceProduce.timingSettingReplyMessage(content); break; case SendTagConstant.SETUP_BILLING_MODEL_REPLY: sendResult = enhanceProduce.setupBillingModelReplyMessage(content); break; case SendTagConstant.GROUND_LOCK_REAL_TIME_DATA: sendResult = enhanceProduce.groundLockRealTimeDataMessage(content); break; case SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA: sendResult = enhanceProduce.chargingPileReturnsGroundLockDataMessage(content); break; case SendTagConstant.PLATFORM_RESTART_REPLY: sendResult = enhanceProduce.platformRestartReplyMessage(content); break; default: sendResult = enhanceProduce.platformRemoteUpdateReplyMessage(content); break; } log.info("rocketmq消息下发结果:{}",sendResult); return AjaxResult.success(); } ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/mongodb/service/PlatformStartChargingReplyService.java
@@ -2,6 +2,17 @@ import com.ruoyi.integration.api.model.PlatformStartChargingReply; import com.ruoyi.integration.mongodb.base.BaseService; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; public interface PlatformStartChargingReplyService extends BaseService<PlatformStartChargingReply> { /** * 根据订单编号查询远程启机应答数据 * @param code * @return */ List<PlatformStartChargingReply> getPlatformStartChargingReply(String code); } ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/mongodb/service/impl/PlatformStartChargingReplyServiceImpl.java
@@ -5,6 +5,8 @@ import com.ruoyi.integration.mongodb.service.PlatformStartChargingReplyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import java.util.List; @@ -29,4 +31,18 @@ public List<PlatformStartChargingReply> findAll() { return mongoTemplate.findAll(PlatformStartChargingReply.class); } /** * 根据订单编号查询远程启机应答数据 * @param code * @return */ @Override public List<PlatformStartChargingReply> getPlatformStartChargingReply(String code) { Query query = new Query(); query.addCriteria(Criteria.where("transaction_serial_number").is(code)); List<PlatformStartChargingReply> platformStartChargingReplies = mongoTemplate.find(query, PlatformStartChargingReply.class); return platformStartChargingReplies; } } ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/listener/OnlineMessageListener.java
@@ -1,6 +1,10 @@ package com.ruoyi.integration.rocket.listener; import com.ruoyi.integration.api.model.Online; import com.ruoyi.integration.api.model.OnlineReply; import com.ruoyi.integration.iotda.enums.ServiceIdMenu; import com.ruoyi.integration.iotda.utils.produce.IotMessageProduce; import com.ruoyi.integration.iotda.utils.tools.MessageUtil; import com.ruoyi.integration.mongodb.service.OnlineService; import com.ruoyi.integration.rocket.model.OnlineMessage; import com.ruoyi.integration.rocket.model.OnlineMessage; @@ -24,6 +28,10 @@ @Autowired private OnlineService onlineService; @Autowired private MessageUtil messageUtil; @Autowired private IotMessageProduce iotMessageProduce; @Override protected void handleMessage(OnlineMessage message) throws Exception { @@ -33,7 +41,12 @@ Online online = new Online(); BeanUtils.copyProperties(message,online); onlineService.create(online); // 业务处理 // 业务处理 登录认证应答 OnlineReply onlineReply = new OnlineReply(); onlineReply.setCharging_pile_code(message.getCharging_pile_code()); onlineReply.setOnline_result(0); String result = iotMessageProduce.sendMessage(onlineReply.getCharging_pile_code(), ServiceIdMenu.ONLINE_REPLY.getKey(), messageUtil.onlineReply(onlineReply)); log.info("充电桩登录认证-返回结果:{}",result); } @Override ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/listener/PingMessageListener.java
@@ -2,6 +2,10 @@ import com.ruoyi.integration.api.model.Online; import com.ruoyi.integration.api.model.Ping; import com.ruoyi.integration.api.model.Pong; import com.ruoyi.integration.iotda.enums.ServiceIdMenu; import com.ruoyi.integration.iotda.utils.produce.IotMessageProduce; import com.ruoyi.integration.iotda.utils.tools.MessageUtil; import com.ruoyi.integration.mongodb.service.OnlineService; import com.ruoyi.integration.mongodb.service.PingService; import com.ruoyi.integration.rocket.model.PingMessage; @@ -25,7 +29,10 @@ @Autowired private PingService pingService; @Autowired private MessageUtil messageUtil; @Autowired private IotMessageProduce iotMessageProduce; @Override protected void handleMessage(PingMessage message) throws Exception { // 此时这里才是最终的业务处理,代码只需要处理资源类关闭异常,其他的可以交给父类重试 @@ -35,6 +42,12 @@ BeanUtils.copyProperties(message,ping); pingService.create(ping); // 业务处理 Pong pong = new Pong(); pong.setCharging_pile_code(message.getCharging_pile_code()); pong.setCharging_gun_code(message.getCharging_gun_code()); pong.setCharging_gun_status(0); String result = iotMessageProduce.sendMessage(pong.getCharging_pile_code(), ServiceIdMenu.PONG.getKey(), messageUtil.pong(pong)); log.info("充电桩心跳包-返回结果:{}",result); } @Override ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/listener/UploadRealTimeMonitoringDataMessageListener.java
@@ -5,12 +5,16 @@ import com.ruoyi.integration.mongodb.service.UploadRealTimeMonitoringDataService; import com.ruoyi.integration.rocket.model.UploadRealTimeMonitoringDataMessage; import com.ruoyi.integration.rocket.util.EnhanceMessageHandler; import com.ruoyi.order.api.feignClient.ChargingOrderClient; import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; import org.apache.rocketmq.spring.core.RocketMQListener; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; @Slf4j @Component @@ -24,6 +28,15 @@ @Autowired private UploadRealTimeMonitoringDataService uploadRealTimeMonitoringDataService; @Resource private ChargingOrderClient chargingOrderClient; @Override protected void handleMessage(UploadRealTimeMonitoringDataMessage message) throws Exception { // 此时这里才是最终的业务处理,代码只需要处理资源类关闭异常,其他的可以交给父类重试 @@ -33,6 +46,9 @@ BeanUtils.copyProperties(message,uploadRealTimeMonitoringData); uploadRealTimeMonitoringDataService.create(uploadRealTimeMonitoringData); // 业务处理 UploadRealTimeMonitoringDataQuery query = new UploadRealTimeMonitoringDataQuery(); BeanUtils.copyProperties(uploadRealTimeMonitoringData, query); chargingOrderClient.chargeMonitoring(query); } @Override ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java
File was renamed from ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduceController.java @@ -2,22 +2,22 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.integration.iotda.enums.SendTagMenu; import com.ruoyi.integration.iotda.constant.SendTagConstant; import com.ruoyi.integration.rocket.model.*; import com.ruoyi.integration.rocket.util.RocketMQEnhanceTemplate; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.client.producer.SendResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.UUID; @RestController @RequestMapping("enhance") @Slf4j public class EnhanceProduceController { @Component public class EnhanceProduce { //注入增强后的模板,可以自动实现环境隔离,日志记录 @Setter(onMethod_ = @Autowired) @@ -33,8 +33,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.ONLINE.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.ONLINE.getValue(), message); message.setSource(SendTagConstant.ONLINE); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ONLINE, message); } /** @@ -45,8 +45,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.PING.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.PING.getValue(), message); message.setSource(SendTagConstant.PING); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PING, message); } /** @@ -57,8 +57,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.BILLING_MODE_VERIFY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.BILLING_MODE_VERIFY.getValue(), message); message.setSource(SendTagConstant.BILLING_MODE_VERIFY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BILLING_MODE_VERIFY, message); } /** @@ -69,8 +69,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.ACQUISITION_BILLING_MODE.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.ACQUISITION_BILLING_MODE.getValue(), message); message.setSource(SendTagConstant.ACQUISITION_BILLING_MODE); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ACQUISITION_BILLING_MODE, message); } /** @@ -81,8 +81,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.UPLOAD_REAL_TIME_MONITORING_DATA.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.UPLOAD_REAL_TIME_MONITORING_DATA.getValue(), message); message.setSource(SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA, message); } /** @@ -93,8 +93,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.CHARGING_HANDSHAKE.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.CHARGING_HANDSHAKE.getValue(), message); message.setSource(SendTagConstant.CHARGING_HANDSHAKE); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_HANDSHAKE, message); } /** @@ -105,8 +105,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.BMS_ABORT.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.BMS_ABORT.getValue(), message); message.setSource(SendTagConstant.BMS_ABORT); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_ABORT, message); } /** @@ -117,8 +117,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.MOTOR_ABORT.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.MOTOR_ABORT.getValue(), message); message.setSource(SendTagConstant.MOTOR_ABORT); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.MOTOR_ABORT, message); } /** @@ -129,8 +129,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.BMS_DEMAND_AND_CHARGER_EXPORTATION.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.BMS_DEMAND_AND_CHARGER_EXPORTATION.getValue(), message); message.setSource(SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION, message); } /** @@ -141,8 +141,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.BMS_INFORMATION.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.BMS_INFORMATION.getValue(), message); message.setSource(SendTagConstant.BMS_INFORMATION); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_INFORMATION, message); } /** @@ -153,8 +153,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.CHARGING_PILE_STARTS_CHARGING.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.CHARGING_PILE_STARTS_CHARGING.getValue(), message); message.setSource(SendTagConstant.CHARGING_PILE_STARTS_CHARGING); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_STARTS_CHARGING, message); } /** @@ -165,8 +165,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.PLATFORM_START_CHARGING_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.PLATFORM_START_CHARGING_REPLY.getValue(), message); message.setSource(SendTagConstant.PLATFORM_START_CHARGING_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_START_CHARGING_REPLY, message); } /** @@ -177,8 +177,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.PLATFORM_STOP_CHARGING_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.PLATFORM_STOP_CHARGING_REPLY.getValue(), message); message.setSource(SendTagConstant.PLATFORM_STOP_CHARGING_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_STOP_CHARGING_REPLY, message); } /** @@ -189,8 +189,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.TRANSACTION_RECORD.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.TRANSACTION_RECORD.getValue(), message); message.setSource(SendTagConstant.TRANSACTION_RECORD); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TRANSACTION_RECORD, message); } /** @@ -201,8 +201,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.UPDATE_BALANCE_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.UPDATE_BALANCE_REPLY.getValue(), message); message.setSource(SendTagConstant.UPDATE_BALANCE_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPDATE_BALANCE_REPLY, message); } /** @@ -213,8 +213,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.SYNCHRONIZE_OFFLINE_CARD_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.SYNCHRONIZE_OFFLINE_CARD_REPLY.getValue(), message); message.setSource(SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY, message); } /** @@ -225,8 +225,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.CLEAR_OFFLINE_CARD_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.CLEAR_OFFLINE_CARD_REPLY.getValue(), message); message.setSource(SendTagConstant.CLEAR_OFFLINE_CARD_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CLEAR_OFFLINE_CARD_REPLY, message); } /** @@ -237,8 +237,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.WORKING_PARAMETER_SETTING_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.WORKING_PARAMETER_SETTING_REPLY.getValue(), message); message.setSource(SendTagConstant.WORKING_PARAMETER_SETTING_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.WORKING_PARAMETER_SETTING_REPLY, message); } /** @@ -249,8 +249,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.TIMING_SETTING_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.TIMING_SETTING_REPLY.getValue(), message); message.setSource(SendTagConstant.TIMING_SETTING_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TIMING_SETTING_REPLY, message); } /** @@ -261,8 +261,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.SETUP_BILLING_MODEL_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.SETUP_BILLING_MODEL_REPLY.getValue(), message); message.setSource(SendTagConstant.SETUP_BILLING_MODEL_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SETUP_BILLING_MODEL_REPLY, message); } /** @@ -273,8 +273,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.GROUND_LOCK_REAL_TIME_DATA.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.GROUND_LOCK_REAL_TIME_DATA.getValue(), message); message.setSource(SendTagConstant.GROUND_LOCK_REAL_TIME_DATA); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.GROUND_LOCK_REAL_TIME_DATA, message); } /** @@ -285,8 +285,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA.getValue(), message); message.setSource(SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA, message); } /** @@ -297,8 +297,8 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.PLATFORM_RESTART_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.PLATFORM_RESTART_REPLY.getValue(), message); message.setSource(SendTagConstant.PLATFORM_RESTART_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_RESTART_REPLY, message); } /** @@ -309,7 +309,7 @@ // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagMenu.PLATFORM_REMOTE_UPDATE_REPLY.getValue()); return rocketMQEnhanceTemplate.send(TOPIC, SendTagMenu.PLATFORM_REMOTE_UPDATE_REPLY.getValue(), message); message.setSource(SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY); return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY, message); } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/FinancialSettlementController.java
@@ -7,29 +7,21 @@ import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient; import com.ruoyi.chargingPile.api.feignClient.ParkingLotClient; import com.ruoyi.chargingPile.api.feignClient.SiteClient; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.domain.AjaxResult; 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.order.api.model.TVipOrder; import com.ruoyi.order.api.query.VipShoppingOrderQuery; import com.ruoyi.order.vo.ChargingOrderListInfoVO; import com.ruoyi.order.api.vo.ChargingOrderTimeVO; import com.ruoyi.order.dto.ChargingListQuery; import com.ruoyi.order.dto.PayOrderDto; import com.ruoyi.order.dto.PayOrderQueryDto; import com.ruoyi.order.service.*; import com.ruoyi.payment.api.feignClient.AliPaymentClient; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Arrays; import java.util.List; /** * <p> @@ -93,5 +85,12 @@ ChargingOrderTimeVO res = chargingOrderService.chargingList(dto); return AjaxResult.success(res); } @ResponseBody @GetMapping(value = "/chargingInfo") @ApiOperation(value = "充电时段统计列表-查看详情", tags = {"管理后台-财务结算"}) public AjaxResult<ChargingOrderListInfoVO> chargingInfo(String uid) { ChargingOrderListInfoVO res = chargingOrderService.chargingInfo(uid); return AjaxResult.success(res); } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -30,6 +30,7 @@ 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; @@ -37,6 +38,7 @@ 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.ChargingOrderInfoVO; import com.ruoyi.order.api.vo.ChargingOrderVO; import com.ruoyi.order.api.vo.TCharingOrderVO; @@ -51,6 +53,7 @@ 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; @@ -102,6 +105,7 @@ private AliPaymentClient aliPaymentClient; @Resource private TShoppingOrderService shoppingOrderService; @Resource private AppUserClient appUserClient; @@ -332,6 +336,7 @@ return R.ok(count); } //订单详情 @PostMapping(value = "/detail") public R<TChargingOrder> detail(@RequestParam("orderId") Long orderId) { @@ -444,6 +449,27 @@ e.printStackTrace(); } } /** * 远程启动失败后退款回调 * @param request */ @ResponseBody @PostMapping(value = "/chargingOrderALICallback") public void chargingOrderStartupFailureWxRefund(HttpServletRequest request){ WxRefundNotifyResp data = wxPaymentClient.refundNotify(request).getData(); if(null != data){ String out_refund_no = data.getOut_refund_no(); String refund_id = data.getRefund_id(); String tradeState = data.getTradeState(); String success_time = data.getSuccess_time(); chargingOrderService.chargingOrderStartupFailureWxRefund(out_refund_no, refund_id, tradeState, success_time); } } @ResponseBody @@ -600,6 +626,19 @@ return AjaxResult.success(res); } /** * 处理充电订单实时监控数据相关的业务逻辑 * @param query */ @PostMapping("/chargeMonitoring") public void chargeMonitoring(@RequestBody UploadRealTimeMonitoringDataQuery query){ chargingOrderService.chargeMonitoring(query); } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/dto/PreChargeCheck.java
@@ -17,4 +17,8 @@ private Boolean insulationTesting; @ApiModelProperty("电子锁锁止") private Boolean electronicLockLock; @ApiModelProperty("启动成功(1=启动中,2=启动成功,3=启动失败,退款)") private Integer startupSuccess; @ApiModelProperty("失败原因(0:无,1:设备编号不匹配,2:枪已在充电,3:设备故障,4:设备离线,5:未插枪桩在收到启充命令后,检测到未插枪则发送 0x33 报文回复充电失败。若在 60 秒(以收到 0x34 时间开始计算)内检测到枪重新连接,则补送 0x33 成功报文;超时或者离线等其他异常,桩不启充、不补发 0x33 报文)") private Integer failureCause; } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/TChargingOrderService.java
@@ -10,10 +10,12 @@ import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.model.TChargingOrderRefund; import com.ruoyi.order.api.query.ChargingOrderQuery; import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; import com.ruoyi.order.api.vo.ChargingOrderTimeVO; import com.ruoyi.order.api.vo.ChargingOrderVO; import com.ruoyi.order.api.vo.TCharingOrderVO; import com.ruoyi.order.dto.*; import com.ruoyi.order.vo.ChargingOrderListInfoVO; import org.springframework.web.bind.annotation.RequestBody; import java.math.BigDecimal; @@ -76,6 +78,18 @@ /** * 充电启动失败后的退款回调处理 * @param out_refund_no * @param refund_id * @param tradeState * @param success_time * @return */ AjaxResult chargingOrderStartupFailureWxRefund(String out_refund_no, String refund_id, String tradeState, String success_time); /** * 获取充电中的详情 * @param id * @return @@ -115,4 +129,13 @@ List<Map<String, BigDecimal>> getYearData(List<Long> chargingOrderIds); ChargingOrderTimeVO chargingList(ChargingListQuery dto); ChargingOrderListInfoVO chargingInfo(String uid); /** * 处理充电订单实时监控数据相关的业务逻辑 * @param query */ void chargeMonitoring(UploadRealTimeMonitoringDataQuery query); } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -11,10 +11,12 @@ import com.ruoyi.account.api.model.TAppUserCar; import com.ruoyi.account.api.model.TAppUserVipDetail; import com.ruoyi.account.api.vo.GetAppUserVipDetail; import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyDetailClient; import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient; import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient; import com.ruoyi.chargingPile.api.feignClient.SiteClient; import com.ruoyi.chargingPile.api.model.Site; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.chargingPile.api.model.TChargingGun; import com.ruoyi.chargingPile.api.model.TChargingPile; import com.ruoyi.common.core.domain.R; @@ -26,16 +28,16 @@ import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.integration.api.feignClient.ChargingHandshakeClient; import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient; import com.ruoyi.integration.api.feignClient.SendMessageClient; import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; import com.ruoyi.integration.api.model.ChargingHandshake; import com.ruoyi.integration.api.model.PlatformStartCharging; import com.ruoyi.integration.api.model.PlatformStartChargingReply; 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.model.TChargingOrderRefund; import com.ruoyi.order.api.model.TOrderEvaluate; import com.ruoyi.order.api.model.*; import com.ruoyi.order.api.query.ChargingOrderQuery; import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; import com.ruoyi.order.api.vo.ChargingOrderListVO; import com.ruoyi.order.api.vo.ChargingOrderTimeVO; import com.ruoyi.order.api.vo.ChargingOrderVO; @@ -43,10 +45,17 @@ import com.ruoyi.order.dto.*; import com.ruoyi.order.mapper.TChargingOrderMapper; import com.ruoyi.order.service.TChargingOrderAccountingStrategyService; import com.ruoyi.order.service.TChargingOrderRefundService; import com.ruoyi.order.service.TChargingOrderService; import com.ruoyi.order.service.TOrderEvaluateService; import com.ruoyi.other.api.domain.TCoupon; import com.ruoyi.other.api.domain.TGoods; import com.ruoyi.order.vo.ChargingOrderListInfoVO; import com.ruoyi.payment.api.feignClient.AliPaymentClient; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import com.ruoyi.payment.api.model.RefundReq; import com.ruoyi.payment.api.model.RefundResp; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.api.vo.*; import io.seata.spring.annotation.GlobalTransactional; import io.swagger.annotations.ApiModelProperty; @@ -63,6 +72,7 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -104,7 +114,7 @@ private AliPaymentClient aliPaymentClient; @Resource private AppUserVipDetailClient appUserVipDetailClient; @@ -124,8 +134,21 @@ @Resource private TOrderEvaluateService orderEvaluateService; @Resource private AccountingStrategyDetailClient accountingStrategyDetailClient; @Resource private PlatformStartChargingReplyClient platformStartChargingReplyClient; @Resource private TChargingOrderRefundService chargingOrderRefundService; //计数器 private Map<String, Integer> counter_map = new HashMap<>(); /** * 获取小程序充电记录列表数据 @@ -425,6 +448,7 @@ * @return */ @Override @GlobalTransactional(rollbackFor = Exception.class) public AjaxResult chargingOrderCallback(Integer paymentType, String out_trade_no, String transaction_id, String attach) { TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, out_trade_no)); if(chargingOrder.getRechargePaymentStatus() == 2){ @@ -432,37 +456,191 @@ } chargingOrder.setRechargePaymentStatus(2); chargingOrder.setRechargeSerialNumber(transaction_id); chargingOrder.setStatus(2); this.updateById(chargingOrder); //添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据 PreChargeCheck preChargeCheck = new PreChargeCheck(); preChargeCheck.setElectronicLockLock(false); preChargeCheck.setInsulationTesting(false); preChargeCheck.setSecureConnectionDetection(false); preChargeCheck.setStartupSuccess(1); String key = "AQJC_" + chargingOrder.getChargingGunId(); redisService.setCacheObject(key, preChargeCheck); //根据当前充值的金额和计费模板算出充电的金额 BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); //计算充电金额,会员需要将折扣金额加入到充电总金额中 TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); TAccountingStrategyDetail strategyDetail = accountingStrategyDetailClient.getNowData(chargingGun.getAccountingStrategyId()).getData(); //总单价 BigDecimal totalUnitPrice = strategyDetail.getServiceCharge().add(strategyDetail.getElectrovalence()); //计算能充电的度数 BigDecimal degrees = rechargeAmount.divide(totalUnitPrice); //计算电费金额和服务费 BigDecimal serviceCharge = strategyDetail.getServiceCharge().multiply(degrees); BigDecimal electrovalence = strategyDetail.getElectrovalence().multiply(degrees); // TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); // if(){ // appUser.getVipId() // } // // // //调用远程启动充电消息 // PlatformStartCharging platformStartCharging = new PlatformStartCharging(); // platformStartCharging.setTransaction_serial_number(chargingOrder.getCode()); // platformStartCharging.setCharging_pile_code(); // platformStartCharging.setCharging_gun_code(); // platformStartCharging.setCard_number(); // platformStartCharging.setAccount_balance() // sendMessageClient.platformStartCharging(platformStartCharging); //再处理会员折扣 BigDecimal discount = BigDecimal.ZERO; TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); if(null != appUser.getVipId()){ GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); getAppUserVipDetail.setVipId(appUser.getVipId()); TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); if(data.getChargeNum() > 0){ discount = serviceCharge.multiply(data.getDiscount().divide(new BigDecimal(10))); data.setChargeNum(data.getChargeNum() - 1); appUserVipDetailClient.updateAppUserVipDetail(data); } } electrovalence = electrovalence.add(discount); TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData(); //调用远程启动充电消息 PlatformStartCharging platformStartCharging = new PlatformStartCharging(); platformStartCharging.setTransaction_serial_number(chargingOrder.getCode()); platformStartCharging.setCharging_pile_code(chargingPile.getCode()); platformStartCharging.setCharging_gun_code(chargingGun.getCode()); //使用订单id作为逻辑卡号 platformStartCharging.setCard_number(chargingOrder.getId().toString()); platformStartCharging.setAccount_balance(electrovalence); sendMessageClient.platformStartCharging(platformStartCharging); //异步线程检测远程启动的应答结果。如果失败,则需要全额退款 String code = chargingOrder.getCode(); //执行5分钟的定时任务检测 ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(()->{ List<PlatformStartChargingReply> data = platformStartChargingReplyClient.getPlatformStartChargingReply(code).getData(); if(data.size() != 0){ PlatformStartChargingReply platformStartChargingReply = data.get(1); Integer startup_result = platformStartChargingReply.getStartup_result(); Integer failure_cause = platformStartChargingReply.getFailure_cause(); Integer counter = counter_map.get(code); PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key); //状态为5的时候,硬件会间隔60秒后再次检测,依然未插枪,则不启动充电 //因这里是间隔5秒执行检测,所以累计次数在30次以上 if(failure_cause == 5 && null == counter || counter < 35){ counter++; counter_map.put(code, counter); //启动失败 preChargeCheck1.setStartupSuccess(3); preChargeCheck1.setFailureCause(failure_cause); redisService.setCacheObject(key, preChargeCheck1); return; } //清除计时器中的无效数据 counter_map.remove(code); //开始处理退款 TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); if(0 == startup_result){ //启动失败 preChargeCheck1.setStartupSuccess(3); preChargeCheck1.setFailureCause(failure_cause); //启动失败后取消订单,退款操作 refund(code); order.setStatus(5); order.setEndMode(0); }else{ preChargeCheck1.setStartupSuccess(2); order.setStatus(3); order.setStartTime(LocalDateTime.now()); } this.updateById(order); redisService.setCacheObject(key, preChargeCheck1); //提前结束定时任务 scheduler.shutdown(); } }, 5, 300, TimeUnit.SECONDS); return AjaxResult.success(); } /** * 启动失败后的退款,取消订单 * @param code */ public void refund(String code){ TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); if(chargingOrder.getStatus() == 2){ Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); //构建退款明细 TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); chargingOrderRefund.setChargingOrderId(chargingOrder.getId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Math.random() * 1000)); chargingOrderRefund.setRefundAmount(rechargeAmount); chargingOrderRefund.setRefundStatus(1); chargingOrderRefund.setPayType(rechargePaymentType); chargingOrderRefund.setRefundStatus(1); chargingOrderRefund.setCode(code); chargingOrderRefund.setRefundTitle("充电失败"); chargingOrderRefund.setRefundContent("充电失败"); chargingOrderRefund.setRefundReason("充电失败"); chargingOrderRefund.setRefundRemark("全额退款"); chargingOrderRefund.setRefundTotalAmount(rechargeAmount); chargingOrderRefund.setPayAmount(rechargeAmount); if(1 == rechargePaymentType){ WxPaymentRefundModel model = new WxPaymentRefundModel(); model.setOut_trade_no(chargingOrder.getCode()); model.setOut_refund_no(chargingOrderRefund.getRefundCode()); model.setReason("充电失败,取消充电订单"); model.setNotify_url("http://127.0.0.1:9000/order/t-charging-order/chargingOrderStartupFailureWxRefund"); WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); amount.setRefund(rechargeAmount.multiply(new BigDecimal(100)).intValue()); amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue()); amount.setCurrency("CNY"); model.setAmount(amount); R<String> orderR = wxPaymentClient.refundOrderR(model); if(200 == orderR.getCode()){ chargingOrderRefundService.save(chargingOrderRefund); } } if(2 == rechargePaymentType){ RefundReq dto = new RefundReq(); dto.setOutTradeNo(chargingOrder.getCode()); dto.setOutRequestNo(chargingOrderRefund.getCode()); dto.setRefundAmount(rechargeAmount.toString()); dto.setRefundReason("充电失败,取消充电订单"); RefundResp resp = aliPaymentClient.refund(dto).getData(); if(null != resp){ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); if(success.isSuccess()){ chargingOrderRefundService.save(chargingOrderRefund); } } } } } /** * 启动失败后微信退款的回调处理 * @param out_refund_no * @param refund_id * @param tradeState * @param success_time * @return */ public AjaxResult chargingOrderStartupFailureWxRefund(String out_refund_no, String refund_id, String tradeState, String success_time){ if("SUCCESS".equals(tradeState)){ TChargingOrderRefund one = chargingOrderRefundService.getOne(new LambdaQueryWrapper<TChargingOrderRefund>().eq(TChargingOrderRefund::getRefundCode, out_refund_no)); one.setRefundSerialNumber(refund_id); one.setRefundStatus(2); one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE"))); chargingOrderRefundService.updateById(one); } return AjaxResult.success(); } /** * 获取充电中的详情 * @param id @@ -484,6 +662,7 @@ chargingDetails.setName(site.getName() + "-" + chargingPile.getName()); chargingDetails.setCode(one.getCode()); chargingDetails.setStatus(one.getStatus()); chargingDetails.setChargingCost(one.getResidualAmount()); UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(one.getCode()).getData(); if(null != data){ chargingDetails.setChargeCurrent(data.getOutput_current()); @@ -494,7 +673,6 @@ chargingDetails.setRemainingChargeTime(data.getTime_remaining()); chargingDetails.setChargedDegrees(data.getCharging_degree()); chargingDetails.setChargedTime(data.getCumulative_charging_time()); chargingDetails.setChargingCost(data.getPaid_amount()); } ChargingHandshake chargingHandshake = chargingHandshakeClient.getDataByOrderCode(one.getCode()).getData(); if(null != chargingHandshake && null != data && null != one.getAppUserCarId()){ @@ -591,8 +769,8 @@ BigDecimal electronicMoney1 = new BigDecimal("0"); // 单个订单累计服务费 BigDecimal serviceMoney1 = new BigDecimal("0"); // todo 调用第三方获取充电时长 秒 UploadRealTimeMonitoringData data5 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrderVO.getCode()).getData(); chargingOrderVO.setChargingSecond(data5.getTime_remaining()*60L); // 总收入 if (chargingOrderVO.getRefundStatus() !=null && chargingOrderVO.getRefundStatus() == 2){ income = income.add(chargingOrderVO.getPaymentAmount().subtract(chargingOrderVO.getRefundAmount())); @@ -704,6 +882,7 @@ return this.baseMapper.getYearData(chargingOrderIds); } @Override public ChargingOrderTimeVO chargingList(ChargingListQuery dto) { String startTime1 = null; @@ -727,6 +906,7 @@ PageInfo<ChargingOrderListVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); List<ChargingOrderListVO> list = this.baseMapper.chargingList(pageInfo,dto,startTime1,startTime2,endTime1,endTime2); for (ChargingOrderListVO chargingOrderListVO : list) { chargingOrderListVO.setUid(chargingOrderListVO.getId()+""); List<Integer> integers = new ArrayList<>(); integers.add(chargingOrderListVO.getSiteId()); List<Site> data = siteClient.getSiteByIds(integers).getData(); @@ -738,7 +918,21 @@ if (data2 != null && data1 != null) { chargingOrderListVO.setTerminalName(data2.getName() + "-" + data1.getName()); } // todo 充电时长 调用第三方获取 // 获取充电时间 UploadRealTimeMonitoringData data5 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrderListVO.getCode()).getData(); if (data5!=null){ if (data5.getTime_remaining()!=null){ chargingOrderListVO.setChargingSecond(data5.getTime_remaining()*60L); } } // 获取开始SOC 结束soc List<UploadRealTimeMonitoringData> data6 = uploadRealTimeMonitoringDataClient.getDataByOrderCode(chargingOrderListVO.getCode()).getData(); if (!data6.isEmpty()){ // 第一条数据soc为开始 最后一条数据soc为结束soc chargingOrderListVO.setStartSoc(data6.get(0).getSoc().toString()); chargingOrderListVO.setEndSoc(data6.get(data6.size()-1).getSoc().toString()); } TAppUser data3 = appUserClient.getUserById(chargingOrderListVO.getAppUserId()).getData(); List<Long> carId = new ArrayList<>(); if (chargingOrderListVO.getAppUserCarId() != null) { @@ -865,4 +1059,59 @@ chargingOrderTimeVO.setList(pageInfo); return chargingOrderTimeVO; } @Override public ChargingOrderListInfoVO chargingInfo(String uid) { TChargingOrder chargingOrder= this.getById(uid); ChargingOrderListInfoVO chargingOrderListInfoVO = new ChargingOrderListInfoVO(); chargingOrderListInfoVO.setCode(chargingOrder.getCode()); List<Site> data = siteClient.getSiteByIds(Arrays.asList(chargingOrder.getSiteId())).getData(); if (!data.isEmpty()){ chargingOrderListInfoVO.setSiteName(data.get(0).getName()); chargingOrderListInfoVO.setSiteAddress(data.get(0).getAddress()); } TChargingGun data1 = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); TChargingPile data2 = chargingPileClient.getChargingPileById(data1.getChargingPileId()).getData(); if (data1!=null){ chargingOrderListInfoVO.setGunCode(data1.getCode()); chargingOrderListInfoVO.setTerminalName(data2.getName()+data1.getName()); } chargingOrderListInfoVO.setEndMode(chargingOrder.getEndMode()); // todo 周一完善 // chargingOrderListInfoVO.setStartSoc(); // chargingOrderListInfoVO.setEndSoc(); // chargingOrderListInfoVO.setChargingCapacity(); // chargingOrderListInfoVO.setSiteId(); // chargingOrderListInfoVO.setChargingPileId(); // chargingOrderListInfoVO.setAppUserId(); // chargingOrderListInfoVO.setAppUserCarId(); // chargingOrderListInfoVO.setChargingGunId(); // chargingOrderListInfoVO.setOrderType(); // chargingOrderListInfoVO.setChargingSecond(); // chargingOrderListInfoVO.setLicensePlate(); // chargingOrderListInfoVO.setPhone(); // chargingOrderListInfoVO.setPaymentAmount(); // chargingOrderListInfoVO.setElectrovalence(); // chargingOrderListInfoVO.setServiceCharge(); // chargingOrderListInfoVO.setStartTime(); // chargingOrderListInfoVO.setEndTime(); // chargingOrderListInfoVO.setId(); // chargingOrderListInfoVO.setUid(); // chargingOrderListInfoVO.setList(); return null; } /** * 处理充电订单实时监控数据相关的业务逻辑 * @param query */ @Override public void chargeMonitoring(UploadRealTimeMonitoringDataQuery query) { // todo 需完善 } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderAppealServiceImpl.java
@@ -57,13 +57,14 @@ if (item.getOrderType() == 1) { TChargingOrder tChargingOrder = chargingOrders.stream().filter(chargingOrder -> chargingOrder.getId().equals(item.getOrderId())).findFirst().orElse(null); if(Objects.nonNull(tChargingOrder)){ item.setChargingOrder(chargingOrders.stream().filter(chargingOrder -> chargingOrder.getId().equals(item.getOrderId())).findFirst().orElse(null)); item.setChargingOrder(tChargingOrder); SiteNameVO siteNameVO = chargingGunClient.getAllInfoById(tChargingOrder.getChargingGunId()).getData(); item.setGunName(siteNameVO.getGunName()); item.setGunNumber(siteNameVO.getGunNumber()); item.setPileName(siteNameVO.getPileName()); item.setPileNumber(siteNameVO.getPileNumber()); item.setSiteName(siteNameVO.getSiteName()); item.setEndMode(tChargingOrder.getEndMode()); } }else if (item.getOrderType() == 2) { TShoppingOrder tShoppingOrder = shoppingOrders.stream().filter(shoppingOrder -> shoppingOrder.getId().equals(item.getOrderId())).findFirst().orElse(null); @@ -82,7 +83,11 @@ BeanUtils.copyProperties(orderAppeal,orderAppealVO); // 查询申诉详情 if (orderAppeal.getOrderType() == 1) { orderAppealVO.setChargingOrder(chargingOrderMapper.selectById(orderAppeal.getOrderId())); TChargingOrder tChargingOrder = chargingOrderMapper.selectById(orderAppeal.getOrderId()); orderAppealVO.setChargingOrder(tChargingOrder); if(Objects.nonNull(tChargingOrder)){ orderAppealVO.setEndMode(tChargingOrder.getEndMode()); } }else if (orderAppeal.getOrderType() == 2) { TShoppingOrder tShoppingOrder = shoppingOrderMapper.selectById(orderAppeal.getOrderId()); setGoodsInfo(orderAppealVO,tShoppingOrder); ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TShoppingOrderServiceImpl.java
@@ -406,6 +406,7 @@ public AjaxResult cancelShoppingOrderWxRefund(String out_refund_no, String refund_id, String refund_status, String success_time) { if("SUCCESS".equals(refund_status)){ TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no)); one.setRefundStatus(2); one.setRefundSerialNumber(refund_id); one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE"))); shoppingOrderRefundService.updateById(one); ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/vo/ChargingOrderListInfoVO.java
New file @@ -0,0 +1,70 @@ package com.ruoyi.order.vo; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @Data @ApiModel(value = "ChargingOrderListInfoVO对象",description = "充电时段统计列表查看详情VO") public class ChargingOrderListInfoVO { @ApiModelProperty(value = "订单编号") private String code; @ApiModelProperty(value = "电站名称") private String siteName; @ApiModelProperty(value = "电站地址") private String siteAddress; @ApiModelProperty(value = "终端编号") private String gunCode; @ApiModelProperty(value = "充电终端名称 桩+枪") private String terminalName; @ApiModelProperty(value = "结束原因 (0=异常终止,1=主动终止,2=满电终止,3=费用不足终止)") private Integer endMode; @ApiModelProperty(value = "开始soc") private String startSoc; @ApiModelProperty(value = "结束soc") private String endSoc; @ApiModelProperty(value = "充电电流 度") private BigDecimal chargingCapacity; @ApiModelProperty(value = "电站id") private Integer siteId; @ApiModelProperty(value = "充电桩id") private Integer chargingPileId; @ApiModelProperty(value = "用户id") private Long appUserId; @ApiModelProperty(value = "用户车辆id") private Long appUserCarId; @ApiModelProperty(value = "充电枪id") private Integer chargingGunId; @ApiModelProperty(value = "订单类型(1=充电订单(小程序),2=充电订单(刷卡))") private String orderType; @ApiModelProperty(value = "充电时间 秒") private Long chargingSecond; @ApiModelProperty(value = "车牌号") private String licensePlate; @ApiModelProperty(value = "客户手机号") private String phone; @ApiModelProperty(value = "充电到账金额") private BigDecimal paymentAmount; @ApiModelProperty(value = "累计电费") private BigDecimal electrovalence; @ApiModelProperty(value = "累计服务费") private BigDecimal serviceCharge; @ApiModelProperty(value = "开始时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private LocalDateTime startTime; @ApiModelProperty(value = "结束时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private LocalDateTime endTime; @ApiModelProperty(value = "订单id") private Long id; @ApiModelProperty(value = "订单uid") private String uid; @ApiModelProperty(value = "充电信息") List<UploadRealTimeMonitoringData> list; } ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -24,6 +24,7 @@ <result column="recharge_payment_type" property="rechargePaymentType" /> <result column="recharge_payment_status" property="rechargePaymentStatus" /> <result column="recharge_serial_number" property="rechargeSerialNumber" /> <result column="residual_amount" property="residualAmount" /> <result column="order_amount" property="orderAmount" /> <result column="app_coupon_id" property="appCouponId" /> <result column="coupon_discount_amount" property="couponDiscountAmount" />