package com.mvc.controller;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.ResultModel;
import com.mvc.model.TAireadDownloadRecordModel;
import com.mvc.service.TAireadDownloadRecordService;
import com.mvc.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Api(tags = "识别数据下载记录")
@RequestMapping("/TAireadDownloadRecordAction")
@Controller
public class TAireadDownloadRecordAction {

    @Resource
    private TAireadDownloadRecordService aireadDownloadRecordService;

    @ApiOperation("分页查询识别数据下载记录")
    @RequestMapping(value = "/findAllTAireadDownloadRecord", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel findAllTAireadDownloadRecord(@RequestBody TAireadDownloadRecordModel model) {
        ResultGeekerModel resultModel;
        try {
            ResPageModel res = aireadDownloadRecordService.findAllTAireadDownloadRecord(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增识别数据下载记录")
    @RequestMapping(value = "/saveTAireadDownloadRecord", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel saveTAireadDownloadRecord(@RequestBody TAireadDownloadRecordModel model) {
        ResultGeekerModel resultModel;
        try {
            TAireadDownloadRecordModel resModel = aireadDownloadRecordService.saveTAireadDownloadRecord(model);
            resultModel = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除识别数据下载记录")
    @RequestMapping(value = "/deleteTAireadDownloadRecord", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel deleteTAireadDownloadRecord(int id) {
        ResultGeekerModel resultModel;
        try {
            int res = aireadDownloadRecordService.deleteTAireadDownloadRecord(id);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("下载zip")
    @RequestMapping(value = "/downloadZipFile/{fileName}", method = RequestMethod.GET)
    @ResponseBody
    public void downloadZipFile(HttpServletResponse response, @PathVariable("fileName") String fileName) {
        try {
            aireadDownloadRecordService.downloadZipFile(response, fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation("测试-手动下载数据集(yyyyMMddHHmmss)")
    @RequestMapping(value = "/test/{startTime}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel test(@PathVariable("startTime") String startTime) {
        ResultModel resultModel;
        try {
            aireadDownloadRecordService.startFileGeneration2(startTime);
            resultModel = new ResultModel(1);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }
}
