package com.mvc.controller.produce;

import com.mvc.model.ResPageModel;
import com.mvc.model.ResultGeekerModel;
import com.mvc.model.produce.FilterDataModel;
import com.mvc.model.produce.ProductionPlanPdfModel;
import com.mvc.model.produce.TProductionPlanModel;
import com.mvc.service.produce.TProductionPlanService;
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.List;

@Api(tags = "生产计划表")
@RequestMapping("/TProductionPlanAction")
@Controller
public class TProductionPlanAction {

    @Resource
    private TProductionPlanService productionPlanService;

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


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

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

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

    @ApiOperation("查询前台PDF格式的数据")
    @RequestMapping(value = "/findProductionPlanForPdf/{planId}", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel findProductionPlanForPdf(@PathVariable("planId") Integer planId) {
        ResultGeekerModel resultModel;
        try {
            ProductionPlanPdfModel res = productionPlanService.findProductionPlanForPdf(planId);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("根据设备SN查询前台PDF格式的数据")
    @RequestMapping(value = "/findProductionPlanPdfDataByDeviceSn/{deviceSn}", method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel findProductionPlanPdfDataByDeviceSn(@PathVariable("deviceSn") String deviceSn) {
        ResultGeekerModel resultModel;
        try {
            ProductionPlanPdfModel res = productionPlanService.findProductionPlanPdfDataByDeviceSn(deviceSn);
            resultModel = new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel = new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
