From fb9e286342938f63af535eb2a363f783a63213db Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 28 五月 2025 11:13:57 +0800
Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile into dev

---
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java |  303 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 282 insertions(+), 21 deletions(-)

diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
index bd5dc8f..caab60d 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/MessageUtil.java
@@ -2,41 +2,302 @@
 
 
 import com.alibaba.fastjson2.JSONObject;
-import com.ruoyi.integration.iotda.constant.ServiceIdConstant;
+import com.ruoyi.integration.api.model.*;
+import com.ruoyi.integration.iotda.enums.ServiceIdMenu;
+import com.ruoyi.integration.mongodb.service.*;
+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 java.util.HashMap;
-import java.util.Map;
+import javax.annotation.Resource;
+import java.util.concurrent.TimeUnit;
 
+@Slf4j
+@Component
 public class MessageUtil {
+
+    @Autowired
+    private OnlineReplyService onlineReplyService;
+    @Autowired
+    private PongService pongService;
+    @Autowired
+    private BillingModeVerifyReplyService billingModeVerifyReplyService;
+    @Autowired
+    private AcquisitionBillingModeReplyService acquisitionBillingModeReplyService;
+    @Autowired
+    private ReadRealTimeMonitoringDataService readRealTimeMonitoringDataService;
+    @Autowired
+    private EndChargeService endChargeService;
+    @Autowired
+    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 charging_pile_code  桩编码
-     * @param online_result 登录结果(0:成功,1:失败)
+     * @param onlineReply  实体对象
      * @return
      */
-    public static String onlineReply(String charging_pile_code,Integer online_result){
-        Map<String,Object> map = new HashMap<>(3);
-        map.put("service_id", ServiceIdConstant.ONLINE_REPLY);
-        map.put("charging_pile_code",charging_pile_code);
-        map.put("online_result",online_result);
-        return JSONObject.toJSONString(map);
+    public JSONObject onlineReply(OnlineReply onlineReply){
+        log.info("登录认证应答:{}", onlineReply);
+        onlineReplyService.create(onlineReply);
+        return  getMessageJsonString(onlineReply, ServiceIdMenu.ONLINE_REPLY.getValue());
     }
 
     /**
      * 心跳包应答
-     * @param charging_pile_code 桩编码
-     * @param charging_gun_code 枪号
-     * @param charging_gun_status 心跳应答(0)
+     * @param pong 实体对象
      * @return
      */
-    public static String pong(String charging_pile_code,String charging_gun_code,Integer charging_gun_status){
-        Map<String,Object> map = new HashMap<>(3);
-        map.put("service_id", ServiceIdConstant.ONLINE_REPLY);
-        map.put("charging_pile_code",charging_pile_code);
-        map.put("charging_gun_code",charging_gun_code);
-        map.put("charging_gun_status",charging_gun_status);
-        return JSONObject.toJSONString(map);
+    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());
     }
 
+    /**
+     * 计费模型验证请求应答
+     * @param billingModeVerifyReply 实体对象
+     * @return
+     */
+    public JSONObject billingModeVerifyReply(BillingModeVerifyReply billingModeVerifyReply){
+        log.info("计费模型验证请求应答:{}", billingModeVerifyReply);
+        billingModeVerifyReplyService.create(billingModeVerifyReply);
+        return  getMessageJsonString(billingModeVerifyReply, ServiceIdMenu.BILLING_MODE_VERIFY_REPLY.getValue());
+    }
+
+    /**
+     * 计费模型验证请求应答
+     * @param acquisitionBillingModeReply 实体对象
+     * @return
+     */
+    public JSONObject acquisitionBillingModeReply(AcquisitionBillingModeReply acquisitionBillingModeReply){
+        log.info("计费模型验证请求应答:{}", acquisitionBillingModeReply);
+        acquisitionBillingModeReplyService.create(acquisitionBillingModeReply);
+        return  getMessageJsonString(acquisitionBillingModeReply, ServiceIdMenu.ACQUISITION_BILLING_MODE_REPLY.getValue());
+    }
+
+    /**
+     * 读取实时监测数据
+     * @param readRealTimeMonitoringData 实体对象
+     * @return
+     */
+    public JSONObject readRealTimeMonitoringData(ReadRealTimeMonitoringData readRealTimeMonitoringData){
+        log.info("读取实时监测数据:{}", readRealTimeMonitoringData);
+        readRealTimeMonitoringDataService.create(readRealTimeMonitoringData);
+        return  getMessageJsonString(readRealTimeMonitoringData, ServiceIdMenu.READ_REAL_TIME_MONITORING_DATA.getValue());
+    }
+
+    /**
+     * 充电结束
+     * @param endCharge 实体对象
+     * @return
+     */
+//    public String endCharge(EndCharge endCharge){
+//        endChargeService.create(endCharge);
+//        return  getMessageJsonString(endCharge, ServiceIdMenu.END_CHARGE.getValue());
+//    }
+
+    /**
+     * 运营平台确认启动充电
+     * @param platformConfirmationCharging 实体对象
+     * @return
+     */
+    public JSONObject platformConfirmationCharging(PlatformConfirmationCharging platformConfirmationCharging){
+        platformConfirmationChargingService.create(platformConfirmationCharging);
+        return  getMessageJsonString(platformConfirmationCharging, ServiceIdMenu.PLATFORM_CONFIRMATION_CHARGING.getValue());
+    }
+
+    /**
+     * 运营平台远程控制启机
+     * @param platformStartCharging 实体对象
+     * @return
+     */
+    public JSONObject platformStartCharging(PlatformStartCharging platformStartCharging){
+        platformStartChargingService.create(platformStartCharging);
+        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());
+    }
+
+    /**
+     * 统一封装消息
+     * @param object 实体对象
+     * @param serviceId 服务ID
+     * @return
+     */
+    public JSONObject getMessageJsonString(Object object, String serviceId){
+        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(object));
+        jsonObject.put("service_id", serviceId);
+        log.info("发送数据service_id:{},发送内容:{}",serviceId,jsonObject);
+        return jsonObject;
+    }
 }

--
Gitblit v1.7.1