package com.mvc.controller.biz;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.biz.TMaintenanceRecordsModel;
import com.mvc.service.biz.TMaintenanceRecordsService;
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;

@Api(tags = "维护记录接口")
@RequestMapping("/TMaintenanceRecordsAction")
@Controller
public class TMaintenanceRecordsAction {

    @Resource
    private TMaintenanceRecordsService tMaintenanceRecordsService;
    
    @ApiOperation("查询所有维护记录")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel findAllTMaintenanceRecords(@RequestBody TMaintenanceRecordsModel model){
        ResultGeekerModel resultModel;
        try {
            ResPageModel res = tMaintenanceRecordsService.findAllTMaintenanceRecords(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增维护记录")
    @RequestMapping(value = "/saveTMaintenanceRecords",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel saveTMaintenanceRecords(@RequestBody TMaintenanceRecordsModel model){
        ResultGeekerModel resultModel;
        try {
            TMaintenanceRecordsModel res= tMaintenanceRecordsService.saveTMaintenanceRecords(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新维护记录")
    @RequestMapping(value = "/updateTMaintenanceRecords",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel updateTMaintenanceRecords(@RequestBody TMaintenanceRecordsModel model){
        ResultGeekerModel resultModel;
        try {
            TMaintenanceRecordsModel res= tMaintenanceRecordsService.updateTMaintenanceRecords(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除维护记录")
    @RequestMapping(value = "/deleteTMaintenanceRecords",method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel deleteTMaintenanceRecords(int id){
        ResultGeekerModel resultModel;
        try {
            int res= tMaintenanceRecordsService.deleteTMaintenanceRecords(id);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("根据读数列表生成维护记录")
    @RequestMapping(value = "/generateRecordByTAiReads",method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel generateRecordByTAiReads(){
        ResultGeekerModel resultModel;
        try {
            int res = tMaintenanceRecordsService.generateRecordByTAiReads();
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
