package com.mortals.xhx.busiz.web;

import com.alibaba.fastjson.JSON;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.common.utils.ComsumerSnapTask;
import com.mortals.xhx.module.hik.event.model.req.callback.EventReq;
import com.mortals.xhx.module.hik.event.service.IHikEventService;
import lombok.extern.slf4j.Slf4j;
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;

@RestController
@Slf4j
@RequestMapping("hik")
public class HikCallbackController {

    @Autowired
    private IHikEventService hikEventService;

    @PostMapping("eventRcv")
    @UnAuth
    public Rest<String> receivePlanMessage(@RequestBody EventReq req) {
        //log.info("【接收人脸计划事件数据】【请求体】--> {}", JSON.toJSONString(req));
        //    EventReq eventReq = JSON.parseObject(req, EventReq.class);
        try {
            //单独线程处理
           // Rest<String> rest = hikEventService.handleEvent(req);
            ComsumerSnapTask comsumerSnapTask = new ComsumerSnapTask(hikEventService,req);
            ThreadPool.getInstance().execute(comsumerSnapTask);
            return Rest.ok();
        } catch (Exception e) {
            log.error("接收数据失败", e);
            return Rest.fail();
        }
    }

}
