package com.yuchen.saas.park.service.controller.face;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.message.api.dto.WebSocketMessagDTO;
import com.yuchen.saas.message.api.feign.ws.WebSocketFeignServer;
import com.yuchen.saas.park.api.dto.park.ImportantFaceMatchDTO;
import com.yuchen.saas.park.api.request.PeopleCaptureQueryRequest;
import com.yuchen.saas.park.api.response.PeopleCaptureResponse;
import com.yuchen.saas.park.api.vo.park.FaceMatchVo;
import com.yuchen.saas.park.service.service.FaceMatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 林立超
 * @date 2022/6/16 16:25
 * @Description
 */
@RestController
@RequestMapping("/face/match")
@Api(value = "人脸比对", tags = "人脸比对")
public class FaceMatchController {

    @Autowired
    private FaceMatchService faceMatchService;
    @Resource
    //SimpMessagingTemplate simpMessagingTemplate;
    private WebSocketFeignServer webSocketClient;

    @GetMapping("/latestDataAllQuery/{parkId}")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "中间人脸抓拍数据汇总查询", notes = "中间人脸抓拍数据汇总查询")
    public R<List<FaceMatchVo>> latestDataAllQuery(@PathVariable("parkId") Long parkId) {

        return R.data(faceMatchService.latestDataQuery(parkId));
    }

    @GetMapping("/latestDataImportantQuery/{parkId}")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "登记人员数据查询", notes = "登记人员数据查询")
    public R<List<FaceMatchVo>> latestDataImportantQuery(@PathVariable("parkId") Long parkId) {

        return R.data(faceMatchService.latestDataQuery2(parkId,"0","8"));
    }

    @GetMapping("/latestDataStrangerQuery/{parkId}")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "陌生人数据查询", notes = "陌生人数据查询")
    public R<List<FaceMatchVo>> latestDataStrangerQuery(@PathVariable("parkId") Long parkId) {

        return R.data(faceMatchService.latestDataQuery2(parkId,"1","8"));
    }

  /*  @GetMapping("/pageQuery")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "防疫数据分页查询", notes = "防疫数据分页查询")
    public R<IPage<TemperaturePreventionVO>> pageQuery(FaceMatchDTO faceMatchDTO, Query query) {

        return R.data(faceMatchService.pageQuery(faceMatchDTO, query));
    }*/

    @PostMapping("/add")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增数据", notes = "新增数据")
    public R<Boolean> add(@RequestBody ImportantFaceMatchDTO importantFaceMatchDTO) {


        return R.data(faceMatchService.add(importantFaceMatchDTO));
    }

    @PostMapping("/sendWebSocket")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增数据", notes = "新增数据")
    public R<Boolean> sendWebSocket(@RequestBody WebSocketMessagDTO messagDTO) {
        /*simpMessagingTemplate.convertAndSendToUser(String.valueOf(messagDTO.getUserId()),
                messagDTO.getDestinationPath(), messagDTO.getEntity());*/

        WebSocketMessagDTO dto0 = new WebSocketMessagDTO(String.valueOf(messagDTO.getUserId()),
                messagDTO.getDestinationPath(), BeanUtil.beanToMap(messagDTO.getEntity()));
        webSocketClient.convertAndSendToUser(dto0);
        return R.data(true);
    }

    @GetMapping("/list/page")
    @ApiOperation(value = "抓拍数据分页查询", notes = "抓拍数据分页查询")
    public R<IPage<PeopleCaptureResponse>> listPage(PeopleCaptureQueryRequest peopleCaptureQueryRequest, Query query) {
        return R.data(faceMatchService.listPage(peopleCaptureQueryRequest,query));
    }
}
