package com.mvc.controller.extend;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.extend.TIdentEnquiriesModel;
import com.mvc.service.extend.TIdentEnquiriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = "识别情况查询接口")
@RequestMapping("/TIdentEnquiriesAction")
@Controller
public class TIdentEnquiriesAction {

    @Resource
    private TIdentEnquiriesService tIdentEnquiriesService;

    @ApiOperation("根据条件查询记录")
    @RequestMapping(value = "/findAllTIdentEnquiries", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel findAllTIdentEnquiries(@RequestBody TIdentEnquiriesModel model) {
        ResultGeekerModel resultModel;
        try {
            ResPageModel res = tIdentEnquiriesService.findAllTIdentEnquiries(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("生成识别查询数据")
    @RequestMapping(value = "/generateIdentEnquiriesData", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel generateIdentEnquiriesData() {
        ResultGeekerModel resultModel;
        try {
            if(!tIdentEnquiriesService.verifyGenerationInterval()){
                resultModel = new ResultGeekerModel("距离上次生成未超过1分钟，请稍后重试");
            }else {
                tIdentEnquiriesService.generateIdentEnquiriesData();
                resultModel = new ResultGeekerModel(1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
