package com.mvc.controller.produce;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.produce.TDeviceSnManagementModel;
import com.mvc.service.produce.TDeviceSnManagementService;
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;

@Api(tags = "设备编码管理")
@RequestMapping("/TDeviceSnManagementAction")
@Controller
public class TDeviceSnManagementAction {

    @Resource
    private TDeviceSnManagementService deviceSnManagementService;

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


    @ApiOperation("新增生产计划记录")
    @RequestMapping(value = "/saveTDeviceSnManagement", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel saveTDeviceSnManagement(@RequestBody TDeviceSnManagementModel model) {
        ResultGeekerModel resultModel;
        try {
            TDeviceSnManagementModel resModel = deviceSnManagementService.saveTDeviceSnManagement(model);
            resultModel = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新生产计划记录")
    @RequestMapping(value = "/updateTDeviceSnManagement", method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel updateDeviceAcc(@RequestBody TDeviceSnManagementModel model) {
        ResultGeekerModel resultModel;
        try {
            TDeviceSnManagementModel resModel = deviceSnManagementService.updateTDeviceSnManagement(model);
            resultModel = new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除生产计划记录")
    @RequestMapping(value = "/deleteTDeviceSnManagement", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel deleteTDeviceSnManagement(int id) {
        ResultGeekerModel resultModel;
        try {
            int res = deviceSnManagementService.deleteTDeviceSnManagement(id);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("下载设备编码PDF文件")
    @RequestMapping(value = "/downloadDevicesnPdf/{planId}", method = RequestMethod.GET)
    @ResponseBody
    public void downloadDevicesnPdf(HttpServletResponse response, @PathVariable("planId") Integer planId) {
        deviceSnManagementService.downloadDevicesnPdf(response,planId);
    }
}
