package com.example.zxweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.zxweb.common.api.vo.Result;
import com.example.zxweb.utils.RmsUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 访客机
 * @Author ZhouWenTao
 * @Date 2023/9/8 13:16
 */
@RestController
@RequestMapping("/rms")
@Slf4j
@Api(tags = "访客机")
public class RmsController {
    @ApiOperation(value = "访客查询")
    @PostMapping(value = "/fkterminal/findAccessRecord")
    public Result<?> fkterminalFindAccessRecord(@RequestBody JSONObject requestBody){
        JSONObject responseBody = RmsUtils.fkterminalFindAccessRecord(requestBody);
        if (responseBody.getInteger("code")!=0) {
            return Result.error(responseBody.getInteger("code"),StringUtils.isBlank(responseBody.getString("msg"))?responseBody.getString("message"):responseBody.getString("msg"));
        }
        responseBody.remove("msg");
        responseBody.remove("code");
        responseBody.remove("success");
        return Result.OK(responseBody);
    }

    @ApiOperation(value = "访客预约")
    @PostMapping(value = "/sync/orderrecord")
    public Result<?> syncOrderrecord(@RequestBody JSONObject requestBody){
        JSONObject responseBody = RmsUtils.syncOrderrecord(requestBody);
        if (responseBody.getInteger("code")!=0) {
            return Result.error(responseBody.getInteger("code"),StringUtils.isBlank(responseBody.getString("msg"))?responseBody.getString("message"):responseBody.getString("msg"));
        }
        responseBody.remove("msg");
        responseBody.remove("code");
        responseBody.remove("success");
        return Result.OK(responseBody);
    }
    @ApiOperation(value = "访客注销")
    @PostMapping(value = "/fkterminal/recoverCard")
    public Result<?> fkterminalRecoverCard(@RequestBody JSONObject requestBody){
        JSONObject responseBody = RmsUtils.fkterminalRecoverCard(requestBody);
        String msg=StringUtils.isBlank(responseBody.getString("msg"))?responseBody.getString("message"):responseBody.getString("msg");;
        if (responseBody.getInteger("code")!=0) {
            return Result.error(responseBody.getInteger("code"),StringUtils.isBlank(responseBody.getString("msg"))?responseBody.getString("message"):responseBody.getString("msg"));
        }
        /*responseBody.remove("msg");
        responseBody.remove("code");
        responseBody.remove("success");*/
        return Result.OK(msg);
    }

}
