package com.mvc.controller;

import com.mvc.model.TMarkRecordModel;
import com.mvc.model.ResPageModel;
import com.mvc.model.ResultModel;
import com.mvc.service.TMarkRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "标记记录控制类")
@RequestMapping("/TMarkRecordAction")
@Controller
public class TMarkRecordAction {

    @Autowired
    private TMarkRecordService tMarkRecordService;

    @ApiOperation("查询标记记录表")
    @RequestMapping(value = "/findAllTMarkRecord",method = RequestMethod.POST)
    @ResponseBody
    public ResultModel findAllTMarkRecord(@RequestBody TMarkRecordModel model){
        ResultModel resultModel;
        try {
            ResPageModel pageModel = tMarkRecordService.findAllTMarkRecord(model);
            resultModel=new ResultModel(pageModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增标记记录")
    @RequestMapping(value = "/saveTMarkRecord",method = RequestMethod.POST)
    @ResponseBody
    public ResultModel saveTMarkRecord(@RequestBody TMarkRecordModel model){
        ResultModel resultModel;
        try {
            if(tMarkRecordService.findUntreatedModelByStationCode(model.getStationCode())!=null){
                return new ResultModel("当前站点已存在未处理的记录");
            }

            TMarkRecordModel resModel= tMarkRecordService.saveTMarkRecord(model);
            resultModel=new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新标记记录")
    @RequestMapping(value = "/updateTMarkRecord",method = RequestMethod.POST)
    @ResponseBody
    public ResultModel updateDeviceAcc(@RequestBody TMarkRecordModel model){
        ResultModel resultModel;
        try {
            TMarkRecordModel resModel= tMarkRecordService.updateTMarkRecord(model);
            resultModel=new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除标记记录")
    @RequestMapping(value = "/deleteTMarkRecord/{id}",method = RequestMethod.GET)
    @ResponseBody
    public ResultModel deleteTMarkRecord(@PathVariable("id") int id){
        ResultModel resultModel;
        try {
            int res= tMarkRecordService.deleteTMarkRecord(id);
            resultModel=new ResultModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }
}
