package com.cm.smartgate.controller.app;

import com.alibaba.fastjson.JSONObject;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.smartgate.pojo.dtos.check.SmartGateCheckResultDTO;
import com.cm.smartgate.pojo.vos.check.SmartGateCheckVO;
import com.cm.smartgate.service.ISmartGateService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: SmartGateController
 * @Description: 智慧闸机
 * @Author: WangGeng
 * @Date: 2020/8/27 9:38
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "智慧闸机接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/smartgate")
public class SmartGateAppController extends AbstractController {

    @Autowired
    private ISmartGateService smartGateService;

    @ApiOperation(value = "闸机心跳检测", notes = "闸机心跳检测接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serialNo", value = "设备编号", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @RequestMapping("heartbeat" + ISystemConstant.APP_RELEASE_SUFFIX)
    public SuccessResult heartbeat(@RequestParam("SerialNo") String serialNo) {
        smartGateService.heartbeat(serialNo);
        return null;
    }

    @ApiOperation(value = "通过校验闸机身份证获取开门状态", notes = "通过校验闸机身份证获取开门状态接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "json", value = "提交数据", paramType = "query"),
            @ApiImplicitParam(name = "picture", value = "图片信息", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("getopendoorstatecheckbyidcard" + ISystemConstant.APP_RELEASE_SUFFIX)
    public JSONObject getOpenDoorStateCheckByIdCard(@RequestParam("json") String json, @RequestParam(name = "picture", required = false) MultipartFile picture) {
        LOG.debug("json：" + json);
        SmartGateCheckVO smartGateCheckVO = JSONObject.parseObject(json, SmartGateCheckVO.class);
        // SmartGateCheckResultDTO openDoorStateCheckByIdCard = smartGateService.getOpenDoorStateCheckByIdCard(smartGateCheckVO, picture);
        JSONObject result = smartGateService.getOpenDoorStateCheckByIdCard(smartGateCheckVO, picture);
        LOG.debug("result: " + result);
        return result;
    }

}
