package com.mvc.controller;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.TDeviceOperationModel;
import com.mvc.service.TDeviceOperationService;
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("/TDeviceOperationAction")
@Controller
public class TDeviceOperationAction {

    @Resource
    private TDeviceOperationService deviceOperationService;

    @ApiOperation("分页查询数据")
    @RequestMapping(value = "/findAllTDeviceOperation", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel findAllTDeviceOperation(@RequestBody TDeviceOperationModel model){
        ResultGeekerModel resultModel;
        try {
            ResPageModel res = deviceOperationService.findAllTDeviceOperation(model);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增站点投运记录")
    @RequestMapping(value = "/saveTDeviceOperation", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel saveTDeviceOperation(@RequestBody TDeviceOperationModel model) {
        ResultGeekerModel resultModel;
        try {
            TDeviceOperationModel resModel = deviceOperationService.saveTDeviceOperation(model);
            resultModel = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新站点投运记录")
    @RequestMapping(value = "/updateTDeviceOperation", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel updateDeviceAcc(@RequestBody TDeviceOperationModel model) {
        ResultGeekerModel resultModel;
        try {
            TDeviceOperationModel resModel = deviceOperationService.updateTDeviceOperation(model);
            resultModel = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除站点投运记录")
    @RequestMapping(value = "/deleteTDeviceOperation", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel deleteTDeviceOperation(int id) {
        ResultGeekerModel resultModel;
        try {
            int res = deviceOperationService.deleteTDeviceOperation(id);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
