package com.fkzy.warn.controller;

import com.alibaba.fastjson.JSONObject;
import com.fkzy.warn.common.constants.ResponseMsgConstants;
import com.fkzy.warn.common.request.RequestParameter;
import com.fkzy.warn.common.response.ApiResponse;
import com.fkzy.warn.service.AuditRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhangjing
 * @date 2024/05/21 11:22
 * @description
 */
@Api(tags = "授权历史")
@RestController
@RequestMapping("auditRecords/")
@Slf4j
public class AuditRecordsController {
    @Resource
    private AuditRecordsService auditRecordsService ;


    @RequestMapping(value = "queryPage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页查询")
    public ApiResponse queryPage(@ApiParam() @RequestBody RequestParameter parameter) {
        ApiResponse apiResponse = new ApiResponse();
            try {
                apiResponse.setData(auditRecordsService.queryPage(parameter));
            } catch (Exception e) {
                apiResponse.recordError(ResponseMsgConstants.OPERATE_FAIL);
            }
        return apiResponse;
    }
    @RequestMapping(value = "record", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "授权审批记录")
    public ApiResponse record(@ApiParam() @RequestBody  JSONObject jsonObject) {
        ApiResponse apiResponse = new ApiResponse();
        try {
            apiResponse.setData(auditRecordsService.record(jsonObject.getInteger("id")));
        } catch (Exception e) {
            apiResponse.recordError(ResponseMsgConstants.OPERATE_FAIL);
        }
        return apiResponse;
    }

}
