Newer
Older
br-data-forwarding / src / main / java / com / casic / api / DeviceInfoController.java
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<String, Object> map) {
        log.info(JSONObject.toJSONString(map));
        Map<String, Object> 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;
    }
}