Pu Zhibing
9 天以前 7a4f9541331bef779a506b38a27ed5c3373c0bec
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
@@ -2,12 +2,19 @@
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.integration.iotda.constant.ServiceIdConstant;
import com.ruoyi.integration.mongodb.model.*;
import com.ruoyi.integration.api.model.*;
import com.ruoyi.integration.iotda.enums.ServiceIdMenu;
import com.ruoyi.integration.mongodb.service.*;
import org.apache.poi.ss.formula.functions.T;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class MessageUtil {
    @Autowired
@@ -26,15 +33,46 @@
    private PlatformConfirmationChargingService platformConfirmationChargingService;
    @Autowired
    private PlatformStartChargingService platformStartChargingService;
    @Autowired
    private PlatformStopChargingService platformStopChargingService;
    @Autowired
    private ConfirmTransactionRecordService confirmTransactionRecordService;
    @Autowired
    private UpdateBalanceService updateBalanceService;
    @Autowired
    private SynchronizeOfflineCardService synchronizeOfflineCardService;
    @Autowired
    private ClearOfflineCardService clearOfflineCardService;
    @Autowired
    private QueryOfflineCardService queryOfflineCardService;
    @Autowired
    private WorkingParameterSettingService workingParameterSettingService;
    @Autowired
    private TimingSettingService timingSettingService;
    @Autowired
    private TimingSettingReplyService timingSettingReplyService;
    @Autowired
    private SetupBillingModelService setupBillingModelService;
    @Autowired
    private OpenOrCloseGroundLockService openOrCloseGroundLockService;
    @Autowired
    private PlatformRestartService platformRestartService;
    @Autowired
    private PlatformRemoteUpdateService platformRemoteUpdateService;
    @Autowired
    private QrCodeDeliveryService qrCodeDeliveryService;
    @Resource
    private RedisTemplate redisTemplate;
    /**
     * 登录认证应答
     * @param onlineReply  实体对象
     * @return
     */
    public String onlineReply(OnlineReply onlineReply){
    public JSONObject onlineReply(OnlineReply onlineReply){
        log.info("登录认证应答:{}", onlineReply);
        onlineReplyService.create(onlineReply);
        return getMessageJsonString(onlineReply, ServiceIdConstant.ONLINE_REPLY);
        return  getMessageJsonString(onlineReply, ServiceIdMenu.ONLINE_REPLY.getValue());
    }
    /**
@@ -42,9 +80,12 @@
     * @param pong 实体对象
     * @return
     */
    public String pong(Pong pong){
        pongService.create(pong);
        return getMessageJsonString(pong, ServiceIdConstant.PONG);
    public JSONObject pong(Pong pong){
        log.info("心跳包应答:{}", pong);
//        pongService.create(pong);
        //存储缓存中,5分钟有效
        redisTemplate.opsForValue().set("pong:" + pong.getCharging_pile_code() + pong.getCharging_gun_code(), pong, 5, TimeUnit.MINUTES);
        return  getMessageJsonString(pong, ServiceIdMenu.PONG.getValue());
    }
    /**
@@ -52,9 +93,10 @@
     * @param billingModeVerifyReply 实体对象
     * @return
     */
    public String billingModeVerifyReply(BillingModeVerifyReply billingModeVerifyReply){
    public JSONObject billingModeVerifyReply(BillingModeVerifyReply billingModeVerifyReply){
        log.info("计费模型验证请求应答:{}", billingModeVerifyReply);
        billingModeVerifyReplyService.create(billingModeVerifyReply);
        return getMessageJsonString(billingModeVerifyReply, ServiceIdConstant.BILLING_MODE_VERIFY_REPLY);
        return  getMessageJsonString(billingModeVerifyReply, ServiceIdMenu.BILLING_MODE_VERIFY_REPLY.getValue());
    }
    /**
@@ -62,9 +104,10 @@
     * @param acquisitionBillingModeReply 实体对象
     * @return
     */
    public String acquisitionBillingModeReply(AcquisitionBillingModeReply acquisitionBillingModeReply){
    public JSONObject acquisitionBillingModeReply(AcquisitionBillingModeReply acquisitionBillingModeReply){
        log.info("计费模型验证请求应答:{}", acquisitionBillingModeReply);
        acquisitionBillingModeReplyService.create(acquisitionBillingModeReply);
        return getMessageJsonString(acquisitionBillingModeReply, ServiceIdConstant.ACQUISITION_BILLING_MODE_REPLY);
        return  getMessageJsonString(acquisitionBillingModeReply, ServiceIdMenu.ACQUISITION_BILLING_MODE_REPLY.getValue());
    }
    /**
@@ -72,9 +115,10 @@
     * @param readRealTimeMonitoringData 实体对象
     * @return
     */
    public String readRealTimeMonitoringData(ReadRealTimeMonitoringData readRealTimeMonitoringData){
    public JSONObject readRealTimeMonitoringData(ReadRealTimeMonitoringData readRealTimeMonitoringData){
        log.info("读取实时监测数据:{}", readRealTimeMonitoringData);
        readRealTimeMonitoringDataService.create(readRealTimeMonitoringData);
        return getMessageJsonString(readRealTimeMonitoringData, ServiceIdConstant.READ_REAL_TIME_MONITORING_DATA);
        return  getMessageJsonString(readRealTimeMonitoringData, ServiceIdMenu.READ_REAL_TIME_MONITORING_DATA.getValue());
    }
    /**
@@ -82,19 +126,19 @@
     * @param endCharge 实体对象
     * @return
     */
    public String endCharge(EndCharge endCharge){
        endChargeService.create(endCharge);
        return getMessageJsonString(endCharge, ServiceIdConstant.END_CHARGE);
    }
//    public String endCharge(EndCharge endCharge){
//        endChargeService.create(endCharge);
//        return  getMessageJsonString(endCharge, ServiceIdMenu.END_CHARGE.getValue());
//    }
    /**
     * 运营平台确认启动充电
     * @param platformConfirmationCharging 实体对象
     * @return
     */
    public String platformConfirmationCharging(PlatformConfirmationCharging platformConfirmationCharging){
    public JSONObject platformConfirmationCharging(PlatformConfirmationCharging platformConfirmationCharging){
        platformConfirmationChargingService.create(platformConfirmationCharging);
        return getMessageJsonString(platformConfirmationCharging, ServiceIdConstant.PLATFORM_CONFIRMATION_CHARGING);
        return  getMessageJsonString(platformConfirmationCharging, ServiceIdMenu.PLATFORM_CONFIRMATION_CHARGING.getValue());
    }
    /**
@@ -102,12 +146,147 @@
     * @param platformStartCharging 实体对象
     * @return
     */
    public String platformConfirmationCharging(PlatformStartCharging platformStartCharging){
    public JSONObject platformStartCharging(PlatformStartCharging platformStartCharging){
        platformStartChargingService.create(platformStartCharging);
        return getMessageJsonString(platformStartCharging, ServiceIdConstant.PLATFORM_START_CHARGING);
        return  getMessageJsonString(platformStartCharging, ServiceIdMenu.PLATFORM_START_CHARGING.getValue());
    }
    /**
     * 运营平台远程停机
     * @param platformStopCharging 实体对象
     * @return
     */
    public JSONObject platformStopCharging(PlatformStopCharging platformStopCharging){
        platformStopChargingService.create(platformStopCharging);
        return  getMessageJsonString(platformStopCharging, ServiceIdMenu.PLATFORM_STOP_CHARGING.getValue());
    }
    /**
     * 交易记录确认
     * @param confirmTransactionRecord 实体对象
     * @return
     */
    public JSONObject confirmTransactionRecord(ConfirmTransactionRecord confirmTransactionRecord){
        confirmTransactionRecordService.create(confirmTransactionRecord);
        return  getMessageJsonString(confirmTransactionRecord, ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getValue());
    }
    /**
     * 远程账户余额更新
     * @param updateBalance 实体对象
     * @return
     */
    public JSONObject updateBalance(UpdateBalance updateBalance){
        updateBalanceService.create(updateBalance);
        return  getMessageJsonString(updateBalance, ServiceIdMenu.UPDATE_BALANCE.getValue());
    }
    /**
     * 离线卡数据同步
     * @param synchronizeOfflineCard 实体对象
     * @return
     */
    public JSONObject synchronizeOfflineCard(SynchronizeOfflineCard synchronizeOfflineCard){
        synchronizeOfflineCardService.create(synchronizeOfflineCard);
        return  getMessageJsonString(synchronizeOfflineCard, ServiceIdMenu.SYNCHRONIZE_OFFLINE_CARD.getValue());
    }
    /**
     * 离线卡数据清除
     * @param clearOfflineCard 实体对象
     * @return
     */
    public JSONObject clearOfflineCard(ClearOfflineCard clearOfflineCard){
        clearOfflineCardService.create(clearOfflineCard);
        return  getMessageJsonString(clearOfflineCard, ServiceIdMenu.CLEAR_OFFLINE_CARD.getValue());
    }
    /**
     * 离线卡数据查询
     * @param queryOfflineCard 实体对象
     * @return
     */
    public JSONObject queryOfflineCard(QueryOfflineCard queryOfflineCard){
        queryOfflineCardService.create(queryOfflineCard);
        return  getMessageJsonString(queryOfflineCard, ServiceIdMenu.QUERY_OFFLINE_CARD.getValue());
    }
    /**
     * 充电桩工作参数设置
     * @param workingParameterSetting 实体对象
     * @return
     */
    public JSONObject workingParameterSetting(WorkingParameterSetting workingParameterSetting){
        workingParameterSettingService.create(workingParameterSetting);
        return  getMessageJsonString(workingParameterSetting, ServiceIdMenu.WORKING_PARAMETER_SETTING.getValue());
    }
    /**
     * 对时设置
     * @param timingSetting 实体对象
     * @return
     */
    public JSONObject timingSetting(TimingSetting timingSetting){
        timingSettingService.create(timingSetting);
        return  getMessageJsonString(timingSetting, ServiceIdMenu.TIMING_SETTING.getValue());
    }
    /**
     * 对时设置应答
     * @param timingSettingReply 实体对象
     * @return
     */
    public JSONObject timingSettingReply(TimingSettingReply timingSettingReply){
        timingSettingReplyService.create(timingSettingReply);
        return  getMessageJsonString(timingSettingReply, ServiceIdMenu.TIMING_SETTING_REPLY.getValue());
    }
    /**
     * 计费模型设置
     * @param setupBillingModel 实体对象
     * @return
     */
    public JSONObject setupBillingModel(SetupBillingModel setupBillingModel){
        setupBillingModelService.create(setupBillingModel);
        return  getMessageJsonString(setupBillingModel, ServiceIdMenu.SETUP_BILLING_MODEL.getValue());
    }
    /**
     * 遥控地锁升锁与降锁命令 (下行)
     * @param openOrCloseGroundLock 实体对象
     * @return
     */
    public JSONObject openOrCloseGroundLock(OpenOrCloseGroundLock openOrCloseGroundLock){
        openOrCloseGroundLockService.create(openOrCloseGroundLock);
        return  getMessageJsonString(openOrCloseGroundLock, ServiceIdMenu.OPEN_OR_CLOSE_GROUND_LOCK.getValue());
    }
    /**
     * 远程重启
     * @param platformRestart 实体对象
     * @return
     */
    public JSONObject platformRestart(PlatformRestart platformRestart){
        platformRestartService.create(platformRestart);
        return  getMessageJsonString(platformRestart, ServiceIdMenu.PLATFORM_RESTART.getValue());
    }
    /**
     * 远程更新
     * @param platformRemoteUpdate 实体对象
     * @return
     */
    public JSONObject platformRemoteUpdate(PlatformRemoteUpdate platformRemoteUpdate){
        platformRemoteUpdateService.create(platformRemoteUpdate);
        return  getMessageJsonString(platformRemoteUpdate, ServiceIdMenu.PLATFORM_REMOTE_UPDATE.getValue());
    }
    /**
     * 二维码下发
     * @param qrCodeDelivery 实体对象
     * @return
     */
    public JSONObject qrCodeDelivery(QrCodeDelivery qrCodeDelivery){
        qrCodeDeliveryService.create(qrCodeDelivery);
        return  getMessageJsonString(qrCodeDelivery, ServiceIdMenu.QR_CODE_DELIVERY.getValue());
    }
    /**
     * 统一封装消息
@@ -115,10 +294,10 @@
     * @param serviceId 服务ID
     * @return
     */
    private String getMessageJsonString(Object object, String serviceId){
    public JSONObject getMessageJsonString(Object object, String serviceId){
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(object));
        jsonObject.put("service_id", serviceId);
        return jsonObject.toJSONString();
        log.info("发送数据service_id:{},发送内容:{}",serviceId,jsonObject);
        return jsonObject;
    }
}