xuhy
2024-09-03 ffd6a8ed2f7c052f9ef7e2450a26fa9df868b670
充电结束接口更换,计费模版修改
10个文件已修改
2个文件已添加
188 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/IntegrationFallbackFactory.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/IntegrationClient.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/resources/mapper/chargingPile/TAccountingStrategyMapper.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/constant/SendTagConstant.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/enums/ServiceIdMenu.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/listener/EndChargeMessageListener.java 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/model/EndChargeMessage.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/IntegrationFallbackFactory.java
@@ -48,10 +48,10 @@
                return R.fail("读取实时监测数据调用失败:" + throwable.getMessage());
            }
            @Override
            public R<String> endCharge(EndCharge endCharge) {
                return R.fail("充电结束调用失败:" + throwable.getMessage());
            }
//            @Override
//            public R<String> endCharge(EndCharge endCharge) {
//                return R.fail("充电结束调用失败:" + throwable.getMessage());
//            }
            @Override
            public R<String> platformConfirmationCharging(PlatformConfirmationCharging platformConfirmationCharging) {
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/IntegrationClient.java
@@ -61,8 +61,8 @@
     * @param endCharge 实体对象
     * @return
     */
    @PostMapping("/sendMessage/sendMessageendCharge")
    public R<String> endCharge(@RequestBody EndCharge endCharge);
//    @PostMapping("/sendMessage/sendMessageendCharge")
//    public R<String> endCharge(@RequestBody EndCharge endCharge);
    /**
     * 运营平台确认启动充电
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.chargingPile.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.chargingPile.api.model.TAccountingStrategy;
import com.ruoyi.chargingPile.api.query.TAccountingStrategyQuery;
@@ -12,9 +13,13 @@
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
@@ -33,6 +38,10 @@
    public PageInfo<TAccountingStrategyVO> pageList(TAccountingStrategyQuery query) {
        PageInfo<TAccountingStrategyVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        List<TAccountingStrategyVO> list = this.baseMapper.pageList(query,pageInfo);
        List<Integer> parentIds = list.stream().map(TAccountingStrategyVO::getId).collect(Collectors.toList());
        List<TAccountingStrategy> list1 = this.list(Wrappers.lambdaQuery(TAccountingStrategy.class)
                .in(TAccountingStrategy::getParentId, parentIds)
                .in(TAccountingStrategy::getAuditStatus, Arrays.asList(1,2)));
        for (TAccountingStrategyVO tAccountingStrategyVO : list) {
            SysUser data = sysUserClient.getSysUser(tAccountingStrategyVO.getUserId()).getData();
            tAccountingStrategyVO.setUserName(data.getNickName());
@@ -44,6 +53,13 @@
                SysUser two = sysUserClient.getSysUser(tAccountingStrategyVO.getUserId()).getData();
                tAccountingStrategyVO.setTwoUserName(two==null?null:two.getNickName());
            }
            // 匹配编辑后的未审核的
            List<TAccountingStrategy> accountingStrategies = list1.stream().filter(e -> e.getParentId().equals(tAccountingStrategyVO.getId()))
                    .sorted(Comparator.comparing(TAccountingStrategy::getCreateTime).reversed()).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(accountingStrategies)){
                TAccountingStrategy tAccountingStrategy = accountingStrategies.get(0);
                tAccountingStrategyVO.setAuditStatus(tAccountingStrategy.getAuditStatus());
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
ruoyi-service/ruoyi-chargingPile/src/main/resources/mapper/chargingPile/TAccountingStrategyMapper.xml
@@ -37,6 +37,7 @@
                AND audit_status = #{query.auditStatus}
            </if>
            AND site_id IS NULL
            AND (parent_id IS NULL OR audit_status = 3 OR audit_status = 4)
            AND del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </where>
        ORDER BY create_time DESC
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/constant/SendTagConstant.java
@@ -15,6 +15,10 @@
     */
    public static final String PING ="ping";
    /**
     * 充电结束
     */
    public static final String END_CHARGE = "end_charge";
    /**
     * 计费模型验证请求
     */
    public static final String BILLING_MODE_VERIFY ="billing_mode_verify";
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/controller/SendMessageController.java
@@ -76,10 +76,10 @@
     * @param endCharge 实体对象
     * @return
     */
    @PostMapping("/endCharge")
    public String endCharge(@RequestBody EndCharge endCharge){
        return  iotMessageProduce.sendMessage(endCharge.getCharging_pile_code(), ServiceIdMenu.END_CHARGE.getKey(),messageUtil.endCharge(endCharge));
    }
//    @PostMapping("/endCharge")
//    public String endCharge(@RequestBody EndCharge endCharge){
//        return  iotMessageProduce.sendMessage(endCharge.getCharging_pile_code(), ServiceIdMenu.END_CHARGE.getKey(),messageUtil.endCharge(endCharge));
//    }
    /**
     * 运营平台确认启动充电
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/enums/ServiceIdMenu.java
@@ -26,10 +26,10 @@
     * 读取实时监测数据
     */
     READ_REAL_TIME_MONITORING_DATA ("读取实时监测数据","read_real_time_monitoring_data"),
    /**
     * 充电结束
     */
     END_CHARGE ("充电结束","end_charge"),
//    /**
//     * 充电结束
//     */
//     END_CHARGE ("充电结束","end_charge"),
    /**
     * 运营平台确认启动充电
     */
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
@@ -44,6 +44,9 @@
            case SendTagConstant.PING:
                sendResult = enhanceProduce.pingMessage(content);
                break;
            case SendTagConstant.END_CHARGE:
                sendResult = enhanceProduce.endChargeMessage(content);
                break;
            case SendTagConstant.BILLING_MODE_VERIFY:
                sendResult = enhanceProduce.billingModeVerifyMessage(content);
                break;
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
@@ -109,10 +109,10 @@
     * @param endCharge 实体对象
     * @return
     */
    public String endCharge(EndCharge endCharge){
        endChargeService.create(endCharge);
        return  getMessageJsonString(endCharge, ServiceIdMenu.END_CHARGE.getValue());
    }
//    public String endCharge(EndCharge endCharge){
//        endChargeService.create(endCharge);
//        return  getMessageJsonString(endCharge, ServiceIdMenu.END_CHARGE.getValue());
//    }
    /**
     * 运营平台确认启动充电
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/listener/EndChargeMessageListener.java
New file
@@ -0,0 +1,88 @@
package com.ruoyi.integration.rocket.listener;
import com.ruoyi.integration.api.model.EndCharge;
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.EndChargeService;
import com.ruoyi.integration.mongodb.service.PingService;
import com.ruoyi.integration.rocket.model.EndChargeMessage;
import com.ruoyi.integration.rocket.model.PingMessage;
import com.ruoyi.integration.rocket.util.EnhanceMessageHandler;
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;
@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "enhance_consumer_group",
        topic = "rocket_enhance",
        selectorExpression = "*",
        consumeThreadMax = 5 //默认是64个线程并发消息,配置 consumeThreadMax 参数指定并发消费线程数,避免太大导致资源不够
)
public class EndChargeMessageListener extends EnhanceMessageHandler<EndChargeMessage> implements RocketMQListener<EndChargeMessage> {
    @Autowired
    private EndChargeService endChargeService;
    @Autowired
    private MessageUtil messageUtil;
    @Autowired
    private IotMessageProduce iotMessageProduce;
    @Override
    protected void handleMessage(EndChargeMessage message) throws Exception {
        // 此时这里才是最终的业务处理,代码只需要处理资源类关闭异常,其他的可以交给父类重试
        log.info("充电结束-业务消息处理:{}",message);
        // 持久化消息
        EndCharge endCharge = new EndCharge();
        BeanUtils.copyProperties(message,endCharge);
        endChargeService.create(endCharge);
        // 业务处理
    }
    @Override
    protected void handleMaxRetriesExceeded(EndChargeMessage message) {
        // 当超过指定重试次数消息时此处方法会被调用
        // 生产中可以进行回退或其他业务操作
        log.error("消息消费失败,请执行后续处理");
    }
    /**
     * 是否执行重试机制
     */
    @Override
    protected boolean isRetry() {
        return true;
    }
    @Override
    protected boolean throwException() {
        // 是否抛出异常,false搭配retry自行处理异常
        return false;
    }
    /**
     * 若需要处理消息过滤,在父级中进行统一处理,或者在此处实现之后,自行处理
     * @param message 待处理消息
     * @return true: 本次消息被过滤,false:不过滤
     */
    @Override
    protected boolean filter(EndChargeMessage message) {
        // 此处可做消息过滤
        return false;
    }
    /**
     * 监听消费消息,不需要执行业务处理,委派给父类做基础操作,父类做完基础操作后会调用子类的实际处理类型
     */
    @Override
    public void onMessage(EndChargeMessage message) {
        super.dispatchMessage(message);
    }
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/model/EndChargeMessage.java
New file
@@ -0,0 +1,29 @@
package com.ruoyi.integration.rocket.model;
import com.ruoyi.integration.rocket.base.BaseMessage;
import lombok.Data;
import java.math.BigDecimal;
/**
 * 充电结束
 **/
@Data
public class EndChargeMessage extends BaseMessage {
    private String transaction_serial_number; // 交易流水号
    private String charging_pile_code; // 桩编码
    private String charging_gun_code; // 抢号
    private BigDecimal bms_battery_charging_status; // BMS 中止荷电状态 SOC
    private BigDecimal bms_minimum_battery_voltage; // BMS 动力蓄电池单体最低电压
    private BigDecimal bms_maximum_battery_voltage; // BMS 动力蓄电池单体最高电压
    private Integer bms_minimum_battery_temperature; // BMS 动力蓄电池最低温度
    private Integer bms_maximum_battery_temperature; // BMS 动力蓄电池最高温度
    private BigDecimal cumulative_charging_time; // 电桩累计充电时间
    private BigDecimal output_energy; // 电桩输出能量
    private String charger_code; // 电桩充电机编号
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java
@@ -48,6 +48,17 @@
        message.setSource(SendTagConstant.PING);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PING, message);
    }
    /**
     * 充电结束
     */
    public SendResult endChargeMessage(JSONObject jsonObject) {
        PingMessage message = JSON.parseObject(jsonObject.toJSONString(),PingMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.END_CHARGE);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.END_CHARGE, message);
    }
    /**
     * 计费模型验证请求