NoticeController.java 1.84 KB
package cn.com.glsx.consumer.controller;

import cn.com.glsx.consumer.common.Contants;
import cn.com.glsx.consumer.entity.AqaraEvent;
import cn.com.glsx.consumer.service.DeviceEventService;
import cn.com.glsx.consumer.service.InfoService;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zhouhaibao
 * @date 2021/4/18 10:39
 */
@Controller
@RequestMapping("/notice")
@Slf4j
public class NoticeController {

    @Autowired
    private DeviceEventService deviceEventService;

    @RequestMapping(value = "/deviceInfo",method = RequestMethod.POST)
    @ResponseBody
    public String deviceInfo(@RequestBody String requestBody){
        // 解密请求体信息
        try {
            log.info("消息内容{}",requestBody);
            // 解密传过来的状态值
            AqaraEvent aqaraEvent = JSONObject.parseObject(requestBody, AqaraEvent.class);
            if(Contants.MSG_TYPE_RESOURCE.equals(aqaraEvent.getMsgType())){
                deviceEventService.processResMessage(aqaraEvent);
            }else if(Contants.MSG_TYPE_DEIVCE.equals(aqaraEvent.getMsgType())){
                deviceEventService.processDevMessage(aqaraEvent);
            }
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("code",0);
            jsonObject.put("result","glsxtest");
            return jsonObject.toJSONString();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

}