diff --git a/src/main/java/com/casic/api/DeviceInfoController.java b/src/main/java/com/casic/api/DeviceInfoController.java new file mode 100644 index 0000000..1450c26 --- /dev/null +++ b/src/main/java/com/casic/api/DeviceInfoController.java @@ -0,0 +1,56 @@ +package com.casic.api; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.casic.dao.model.BusDevice; +import com.casic.dao.service.IBusDeviceService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@RestController +@RequestMapping("/api/device") +public class DeviceInfoController { + + @Resource + private IBusDeviceService deviceService; + + @RequestMapping("aepExt") + public Object aepExt(@RequestBody Map map) { + log.info(JSONObject.toJSONString(map)); + Map retObj = new HashMap<>(); + if (map.containsKey("DEVCODE")) { + String devCode = StrUtil.toString(map.get("DEVCODE")); + BusDevice device = deviceService.getDeviceByCode(devCode); + if (ObjectUtil.isNotNull(device)) { + device.setNbAppKey(StrUtil.toString(map.getOrDefault("NB_APP_KEY", ""))); + device.setNbAppSecret(StrUtil.toString(map.getOrDefault("NB_APP_SECRET", ""))); + device.setMasterApiKey(StrUtil.toString(map.getOrDefault("MASTER_API_KEY", ""))); + device.setNbDeviceId(StrUtil.toString(map.getOrDefault("NB_DEVICE_ID", ""))); + device.setNbProductId(StrUtil.toString(map.getOrDefault("NB_PRODUCT_ID", ""))); + + deviceService.updateById(device); + + retObj.put("code", 200); + retObj.put("success", true); + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode[" + devCode + "]的设备未找到"); + } + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode必传,不能为空"); + } + + return retObj; + } +} diff --git a/src/main/java/com/casic/api/DeviceInfoController.java b/src/main/java/com/casic/api/DeviceInfoController.java new file mode 100644 index 0000000..1450c26 --- /dev/null +++ b/src/main/java/com/casic/api/DeviceInfoController.java @@ -0,0 +1,56 @@ +package com.casic.api; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.casic.dao.model.BusDevice; +import com.casic.dao.service.IBusDeviceService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@RestController +@RequestMapping("/api/device") +public class DeviceInfoController { + + @Resource + private IBusDeviceService deviceService; + + @RequestMapping("aepExt") + public Object aepExt(@RequestBody Map map) { + log.info(JSONObject.toJSONString(map)); + Map retObj = new HashMap<>(); + if (map.containsKey("DEVCODE")) { + String devCode = StrUtil.toString(map.get("DEVCODE")); + BusDevice device = deviceService.getDeviceByCode(devCode); + if (ObjectUtil.isNotNull(device)) { + device.setNbAppKey(StrUtil.toString(map.getOrDefault("NB_APP_KEY", ""))); + device.setNbAppSecret(StrUtil.toString(map.getOrDefault("NB_APP_SECRET", ""))); + device.setMasterApiKey(StrUtil.toString(map.getOrDefault("MASTER_API_KEY", ""))); + device.setNbDeviceId(StrUtil.toString(map.getOrDefault("NB_DEVICE_ID", ""))); + device.setNbProductId(StrUtil.toString(map.getOrDefault("NB_PRODUCT_ID", ""))); + + deviceService.updateById(device); + + retObj.put("code", 200); + retObj.put("success", true); + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode[" + devCode + "]的设备未找到"); + } + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode必传,不能为空"); + } + + return retObj; + } +} diff --git a/src/main/java/com/casic/dao/model/BusDevice.java b/src/main/java/com/casic/dao/model/BusDevice.java index edf9264..cbf8f16 100644 --- a/src/main/java/com/casic/dao/model/BusDevice.java +++ b/src/main/java/com/casic/dao/model/BusDevice.java @@ -58,6 +58,18 @@ private String secretKey; /** + * 电信AEP平台的DEVICE_ID + */ + @TableField("NB_DEVICE_ID") + private String nbDeviceId; + + /** + * 电信AEP平台的PRODUCT_ID + */ + @TableField("NB_PRODUCT_ID") + private String nbProductId; + + /** * 电信AEP平台的AppKey */ @TableField("NB_APP_KEY") diff --git a/src/main/java/com/casic/api/DeviceInfoController.java b/src/main/java/com/casic/api/DeviceInfoController.java new file mode 100644 index 0000000..1450c26 --- /dev/null +++ b/src/main/java/com/casic/api/DeviceInfoController.java @@ -0,0 +1,56 @@ +package com.casic.api; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.casic.dao.model.BusDevice; +import com.casic.dao.service.IBusDeviceService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@RestController +@RequestMapping("/api/device") +public class DeviceInfoController { + + @Resource + private IBusDeviceService deviceService; + + @RequestMapping("aepExt") + public Object aepExt(@RequestBody Map map) { + log.info(JSONObject.toJSONString(map)); + Map retObj = new HashMap<>(); + if (map.containsKey("DEVCODE")) { + String devCode = StrUtil.toString(map.get("DEVCODE")); + BusDevice device = deviceService.getDeviceByCode(devCode); + if (ObjectUtil.isNotNull(device)) { + device.setNbAppKey(StrUtil.toString(map.getOrDefault("NB_APP_KEY", ""))); + device.setNbAppSecret(StrUtil.toString(map.getOrDefault("NB_APP_SECRET", ""))); + device.setMasterApiKey(StrUtil.toString(map.getOrDefault("MASTER_API_KEY", ""))); + device.setNbDeviceId(StrUtil.toString(map.getOrDefault("NB_DEVICE_ID", ""))); + device.setNbProductId(StrUtil.toString(map.getOrDefault("NB_PRODUCT_ID", ""))); + + deviceService.updateById(device); + + retObj.put("code", 200); + retObj.put("success", true); + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode[" + devCode + "]的设备未找到"); + } + } else { + retObj.put("code", 201); + retObj.put("success", false); + retObj.put("message", "devCode必传,不能为空"); + } + + return retObj; + } +} diff --git a/src/main/java/com/casic/dao/model/BusDevice.java b/src/main/java/com/casic/dao/model/BusDevice.java index edf9264..cbf8f16 100644 --- a/src/main/java/com/casic/dao/model/BusDevice.java +++ b/src/main/java/com/casic/dao/model/BusDevice.java @@ -58,6 +58,18 @@ private String secretKey; /** + * 电信AEP平台的DEVICE_ID + */ + @TableField("NB_DEVICE_ID") + private String nbDeviceId; + + /** + * 电信AEP平台的PRODUCT_ID + */ + @TableField("NB_PRODUCT_ID") + private String nbProductId; + + /** * 电信AEP平台的AppKey */ @TableField("NB_APP_KEY") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d396714..3a0eeb1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,7 +33,8 @@ base-url: https://ag-api.ctwing.cn push: - url: http://10.30.7.26:20705/device/receiveData + # url: http://10.30.7.26:20705/device/receiveData + url: http://111.198.10.15:11643/device/receiveData # type 可燃气体的设备类型 # minutes: 燃气外协设备上传数据的分钟数 \ No newline at end of file