package com.mvc.controller.dic;

import com.mvc.entity.DicSequenceStation;
import com.mvc.model.ResultModel;
import com.mvc.service.dic.DicSequenceStationService;
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 java.util.Date;
import java.util.List;

@Api(tags = "站点编码队列字典")
@RequestMapping("/DicSequenceStationAction")
@Controller
public class DicSequenceStationAction {

    @Resource
    private DicSequenceStationService dicSequenceStationService;

    @ApiOperation("查询站点编码队列字典表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findAllDicSequenceStation() {
        ResultModel resultModel;
        try {
            List<DicSequenceStation> resList = dicSequenceStationService.findAllDicSequenceStation();
            resultModel = new ResultModel(resList);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增站点编码队列字典记录")
    @RequestMapping(value = "/saveDicSequenceStation", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel saveDicSequenceStation(@RequestBody DicSequenceStation model) {
        ResultModel resultModel;
        try {
            DicSequenceStation resModel = dicSequenceStationService.saveDicSequenceStation(model);
            resultModel = new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新站点编码队列字典记录")
    @RequestMapping(value = "/updateDicSequenceStation", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel updateDeviceAcc(@RequestBody DicSequenceStation model) {
        ResultModel resultModel;
        try {
            DicSequenceStation resModel = dicSequenceStationService.updateDicSequenceStation(model);
            resultModel = new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除站点编码队列字典记录")
    @RequestMapping(value = "/deleteDicSequenceStation/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel deleteDicSequenceStation(@PathVariable("id") Date id) {
        ResultModel resultModel;
        try {
            int res = dicSequenceStationService.deleteDicSequenceStation(id);
            resultModel = new ResultModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("测试生成编码")
    @RequestMapping(value = "/generatorNextCode", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel generatorNextCode() {
        ResultModel resultModel;
        try {
            String res = dicSequenceStationService.generatorNextCode();
            resultModel = new ResultModel(res, null);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultModel(e.getMessage());
        }
        return resultModel;
    }
}
