瀏覽代碼

读取洗车机主板配置

skyline 1 年之前
父節點
當前提交
ba4d02505d

+ 14 - 4
car-wash-admin/src/main/java/com/kym/admin/controller/DeviceConfigController.java

@@ -8,10 +8,7 @@ import com.kym.entity.DeviceConfig;
 import com.kym.entity.queryParams.DeviceConfigParams;
 import com.kym.service.DeviceConfigService;
 import jakarta.validation.Valid;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * <p>
@@ -44,6 +41,19 @@ public class DeviceConfigController extends IController {
         return resp((t) -> deviceConfigService.add(deviceConfig));
     }
 
+    /**
+     * 读取设备配置
+     *
+     * @param shortId
+     * @return Res
+     */
+//    @SaCheckPermission(value = "deviceConfig.list")
+    @PostMapping("/{shortId}")
+    @SysLog(value = "读取设备配置")
+    public R<?> readDeviceConfig(@PathVariable("shortId") String shortId) {
+        return resp(() -> deviceConfigService.readDeviceConfig(shortId));
+    }
+
     /**
      * 更新设备配置
      *

+ 3 - 0
car-wash-service/src/main/java/com/kym/service/DeviceConfigService.java

@@ -15,7 +15,10 @@ import com.kym.service.mybatisplus.MyBaseService;
 public interface DeviceConfigService extends MyBaseService<DeviceConfig> {
 
     void add(DeviceConfig deviceConfig);
+
     void modify(DeviceConfig deviceConfig);
 
     void batchModify(DeviceConfigParams params);
+
+    Object readDeviceConfig(String shortId);
 }

+ 4 - 42
car-wash-service/src/main/java/com/kym/service/awoara/AwoaraServiceImpl.java

@@ -1,5 +1,6 @@
 package com.kym.service.awoara;
 
+import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.TypeReference;
 import com.google.gson.FieldNamingPolicy;
@@ -39,6 +40,7 @@ public class AwoaraServiceImpl implements AwoaraService {
             .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter())
             .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
             .create();
+
     /**
      * BASE64解码器
      */
@@ -238,56 +240,16 @@ public class AwoaraServiceImpl implements AwoaraService {
                     "params": []
                 }
                 """;
-        return doRequest(productKey, deviceName, params, new TypeReference<AwoaraResponse<DeviceConfig>>() {
-        });
+        var res = doRequest(productKey, deviceName, params, null);
+        return gson.fromJson(JSON.toJSONString(res).replaceAll("\\.", ""), DeviceConfig.class);
     }
 
     @Override
     public void writeConfig(String productKey, String deviceName, DeviceConfig deviceConfig) {
-        var params = """
-                {
-                    "version": "2.0",
-                    "method": "write_config",
-                    "params": {
-                        "version":2,
-                        "maintenance_mode": 0,
-                        "user_message.1": "超级进化车生活2",
-                        "user_message.2": "客服电话:13018061579",
-                        "sensor_water": 0,
-                        "price_space": 0,
-                        "price_water": 150,
-                        "price_foam": 250,
-                        "price_tap": 100,
-                        "price_cleaner": 120,
-                        "price_user_ext": 100,
-                        "idle_timeout": 1200,
-                        "operation_timeout": 3600,
-                        "quick_open_money": 2000,
-                        "work_mode": 1,
-                        "work_time_period.1": "00:00 - 00:00",
-                        "work_time_period.2": "00:00 - 00:00",
-                        "light_mode": 2,
-                        "light_time_period.1": "00:00 - 05:30",
-                        "light_time_period.2": "18:30 - 00:00",
-                        "sound_volume": 70,
-                        "screen_type": 0,
-                        "video_source": 0,
-                        "video_play_delay": 20,
-                        "work_light_delay": 30,
-                        "bill_delay": 60,
-                        "notice_throshold_idle": 300,
-                        "notice_throshold_operation": 600,
-                        "motor_mode": 0
-                     }
-                }
-                """;
-
         var json = new JSONObject();
         json.put("version", "2.0");
         json.put("method", "write_config");
         json.put("params", deviceConfig);
-
-//        doRequest(productKey, deviceName, params, null);
         doRequest(productKey, deviceName, gson.toJson(json).replaceAll("1\"", ".1\"").replaceAll("2\"", ".2\""), null);
     }
 }

+ 8 - 0
car-wash-service/src/main/java/com/kym/service/impl/DeviceConfigServiceImpl.java

@@ -8,6 +8,7 @@ import com.kym.mapper.DeviceConfigMapper;
 import com.kym.service.DeviceConfigService;
 import com.kym.service.WashDeviceService;
 import com.kym.service.awoara.AwoaraService;
+import com.kym.service.cache.KymCache;
 import com.kym.service.mybatisplus.MyBaseServiceImpl;
 import org.springframework.stereotype.Service;
 
@@ -51,4 +52,11 @@ public class DeviceConfigServiceImpl extends MyBaseServiceImpl<DeviceConfigMappe
         CommUtil.asserts(CommUtil.isNotEmptyAndNull(deviceConfig), "设备参数不存在");
         deviceList.forEach(device -> awoaraService.writeConfig(device.getProductKey(), device.getDeviceName(), deviceConfig));
     }
+
+    @Override
+    public Object readDeviceConfig(String shortId) {
+        return awoaraService.readConfig(KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId)[0], KymCache.INSTANCE.getProductKeyAndDeviceNameByWashShortId(shortId)[1]);
+    }
+
+
 }