package com.yanzhu.jh.publics;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.yanzhu.jh.video.domain.DevAiProjectDataVO;
import com.yanzhu.jh.video.service.IDevAiProjectDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * AIBoxController
 * 智能盒子
 * @author JiangYuQi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/publics/aiBox")
public class AIBoxController extends BaseController {

    @Autowired
    private IDevAiProjectDataService devAiProjectDataService;

    private static final Logger logger = LoggerFactory.getLogger("AIBoxController");

    /**
     * aibox推送预警数据
     */
    @PostMapping("/v1/push")
    public void push(@RequestBody Map<String,Object> dataMap)
    {
        try{
            List<Map<String,Object>> list = (List<Map<String,Object>>)dataMap.get("BehaviorResults");
            DevAiProjectDataVO devAiProjectDataVO = JSON.parseObject(JSONObject.toJSONString(list.get(0)), DevAiProjectDataVO.class);
            devAiProjectDataService.insertHttpDevAiProjectData(devAiProjectDataVO);
        }catch (Exception e){
            logger.info("AiBox解析参数失败！！！");
            logger.info(dataMap.toString());
            e.printStackTrace();
        }

    }

}
