Pu Zhibing
2024-11-05 63f7a9310dd1649b7ae2bc680a37ac73536be64c
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
@@ -2,12 +2,15 @@
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.stereotype.Component;
@Slf4j
@Component
public class MessageUtil {
    @Autowired
@@ -43,6 +46,8 @@
    @Autowired
    private TimingSettingService timingSettingService;
    @Autowired
    private TimingSettingReplyService timingSettingReplyService;
    @Autowired
    private SetupBillingModelService setupBillingModelService;
    @Autowired
    private OpenOrCloseGroundLockService openOrCloseGroundLockService;
@@ -50,15 +55,18 @@
    private PlatformRestartService platformRestartService;
    @Autowired
    private PlatformRemoteUpdateService platformRemoteUpdateService;
    @Autowired
    private QrCodeDeliveryService qrCodeDeliveryService;
    /**
     * 登录认证应答
     * @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());
    }
    /**
@@ -66,9 +74,10 @@
     * @param pong 实体对象
     * @return
     */
    public String pong(Pong pong){
    public JSONObject pong(Pong pong){
        log.info("心跳包应答:{}", pong);
        pongService.create(pong);
        return getMessageJsonString(pong, ServiceIdConstant.PONG);
        return  getMessageJsonString(pong, ServiceIdMenu.PONG.getValue());
    }
    /**
@@ -76,9 +85,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());
    }
    /**
@@ -86,9 +96,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());
    }
    /**
@@ -96,9 +107,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());
    }
    /**
@@ -106,19 +118,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());
    }
    /**
@@ -126,9 +138,9 @@
     * @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());
    }
    /**
@@ -136,9 +148,9 @@
     * @param platformStopCharging 实体对象
     * @return
     */
    public String platformStopCharging(PlatformStopCharging platformStopCharging){
    public JSONObject platformStopCharging(PlatformStopCharging platformStopCharging){
        platformStopChargingService.create(platformStopCharging);
        return getMessageJsonString(platformStopCharging, ServiceIdConstant.PLATFORM_STOP_CHARGING);
        return  getMessageJsonString(platformStopCharging, ServiceIdMenu.PLATFORM_STOP_CHARGING.getValue());
    }
    /**
@@ -146,9 +158,9 @@
     * @param confirmTransactionRecord 实体对象
     * @return
     */
    public String confirmTransactionRecord(ConfirmTransactionRecord confirmTransactionRecord){
    public JSONObject confirmTransactionRecord(ConfirmTransactionRecord confirmTransactionRecord){
        confirmTransactionRecordService.create(confirmTransactionRecord);
        return getMessageJsonString(confirmTransactionRecord, ServiceIdConstant.CONFIRM_TRANSACTION_RECORD);
        return  getMessageJsonString(confirmTransactionRecord, ServiceIdMenu.CONFIRM_TRANSACTION_RECORD.getValue());
    }
    /**
@@ -156,9 +168,9 @@
     * @param updateBalance 实体对象
     * @return
     */
    public String updateBalance(UpdateBalance updateBalance){
    public JSONObject updateBalance(UpdateBalance updateBalance){
        updateBalanceService.create(updateBalance);
        return getMessageJsonString(updateBalance, ServiceIdConstant.UPDATE_BALANCE);
        return  getMessageJsonString(updateBalance, ServiceIdMenu.UPDATE_BALANCE.getValue());
    }
    /**
@@ -166,9 +178,9 @@
     * @param synchronizeOfflineCard 实体对象
     * @return
     */
    public String synchronizeOfflineCard(SynchronizeOfflineCard synchronizeOfflineCard){
    public JSONObject synchronizeOfflineCard(SynchronizeOfflineCard synchronizeOfflineCard){
        synchronizeOfflineCardService.create(synchronizeOfflineCard);
        return getMessageJsonString(synchronizeOfflineCard, ServiceIdConstant.SYNCHRONIZE_OFFLINE_CARD);
        return  getMessageJsonString(synchronizeOfflineCard, ServiceIdMenu.SYNCHRONIZE_OFFLINE_CARD.getValue());
    }
    /**
@@ -176,9 +188,9 @@
     * @param clearOfflineCard 实体对象
     * @return
     */
    public String clearOfflineCard(ClearOfflineCard clearOfflineCard){
    public JSONObject clearOfflineCard(ClearOfflineCard clearOfflineCard){
        clearOfflineCardService.create(clearOfflineCard);
        return getMessageJsonString(clearOfflineCard, ServiceIdConstant.CLEAR_OFFLINE_CARD);
        return  getMessageJsonString(clearOfflineCard, ServiceIdMenu.CLEAR_OFFLINE_CARD.getValue());
    }
    /**
@@ -186,9 +198,9 @@
     * @param queryOfflineCard 实体对象
     * @return
     */
    public String queryOfflineCard(QueryOfflineCard queryOfflineCard){
    public JSONObject queryOfflineCard(QueryOfflineCard queryOfflineCard){
        queryOfflineCardService.create(queryOfflineCard);
        return getMessageJsonString(queryOfflineCard, ServiceIdConstant.QUERY_OFFLINE_CARD);
        return  getMessageJsonString(queryOfflineCard, ServiceIdMenu.QUERY_OFFLINE_CARD.getValue());
    }
    /**
@@ -196,9 +208,9 @@
     * @param workingParameterSetting 实体对象
     * @return
     */
    public String workingParameterSetting(WorkingParameterSetting workingParameterSetting){
    public JSONObject workingParameterSetting(WorkingParameterSetting workingParameterSetting){
        workingParameterSettingService.create(workingParameterSetting);
        return getMessageJsonString(workingParameterSetting, ServiceIdConstant.WORKING_PARAMETER_SETTING);
        return  getMessageJsonString(workingParameterSetting, ServiceIdMenu.WORKING_PARAMETER_SETTING.getValue());
    }
    /**
@@ -206,9 +218,18 @@
     * @param timingSetting 实体对象
     * @return
     */
    public String timingSetting(TimingSetting timingSetting){
    public JSONObject timingSetting(TimingSetting timingSetting){
        timingSettingService.create(timingSetting);
        return getMessageJsonString(timingSetting, ServiceIdConstant.TIMING_SETTING);
        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());
    }
    /**
@@ -216,9 +237,9 @@
     * @param setupBillingModel 实体对象
     * @return
     */
    public String setupBillingModel(SetupBillingModel setupBillingModel){
    public JSONObject setupBillingModel(SetupBillingModel setupBillingModel){
        setupBillingModelService.create(setupBillingModel);
        return getMessageJsonString(setupBillingModel, ServiceIdConstant.SETUP_BILLING_MODEL);
        return  getMessageJsonString(setupBillingModel, ServiceIdMenu.SETUP_BILLING_MODEL.getValue());
    }
    /**
@@ -226,27 +247,37 @@
     * @param openOrCloseGroundLock 实体对象
     * @return
     */
    public String openOrCloseGroundLock(OpenOrCloseGroundLock openOrCloseGroundLock){
    public JSONObject openOrCloseGroundLock(OpenOrCloseGroundLock openOrCloseGroundLock){
        openOrCloseGroundLockService.create(openOrCloseGroundLock);
        return getMessageJsonString(openOrCloseGroundLock, ServiceIdConstant.OPEN_OR_CLOSE_GROUND_LOCK);
        return  getMessageJsonString(openOrCloseGroundLock, ServiceIdMenu.OPEN_OR_CLOSE_GROUND_LOCK.getValue());
    }
    /**
     * 远程重启
     * @param platformRestart 实体对象
     * @return
     */
    public String platformRestart(PlatformRestart platformRestart){
    public JSONObject platformRestart(PlatformRestart platformRestart){
        platformRestartService.create(platformRestart);
        return getMessageJsonString(platformRestart, ServiceIdConstant.PLATFORM_RESTART);
        return  getMessageJsonString(platformRestart, ServiceIdMenu.PLATFORM_RESTART.getValue());
    }
    /**
     * 远程更新
     * @param platformRemoteUpdate 实体对象
     * @return
     */
    public String platformRemoteUpdate(PlatformRemoteUpdate platformRemoteUpdate){
    public JSONObject platformRemoteUpdate(PlatformRemoteUpdate platformRemoteUpdate){
        platformRemoteUpdateService.create(platformRemoteUpdate);
        return getMessageJsonString(platformRemoteUpdate, ServiceIdConstant.PLATFORM_REMOTE_UPDATE);
        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());
    }
    /**
@@ -255,10 +286,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;
    }
}