package com.mvc.controller.upgrade;

import com.mvc.model.ResultGeekerModel;
import com.mvc.model.upgrade.TUpgradePlanDetailModel;
import com.mvc.service.upgrade.TUpgradePlanDetailService;
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("/TUpgradePlanDetailAction")
@Controller
public class TUpgradePlanDetailAction {

    @Resource
    private TUpgradePlanDetailService tUpgradePlanDetailService;

    @ApiOperation("查询所有升级计划明细")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel findAllTUpgradePlanDetail(){
        ResultGeekerModel resultModel;
        try {
            List<TUpgradePlanDetailModel> resList = tUpgradePlanDetailService.findAllTUpgradePlanDetail();
            resultModel=new ResultGeekerModel(resList);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增升级计划明细")
    @RequestMapping(value = "/saveTUpgradePlanDetail",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel saveTUpgradePlanDetail(@RequestBody TUpgradePlanDetailModel model){
        ResultGeekerModel resultModel;
        try {
            TUpgradePlanDetailModel resModel= tUpgradePlanDetailService.saveTUpgradePlanDetail(model);
            resultModel=new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新升级计划明细")
    @RequestMapping(value = "/updateTUpgradePlanDetail",method = RequestMethod.POST)
    @ResponseBody
    public ResultGeekerModel updateTUpgradePlanDetail(@RequestBody TUpgradePlanDetailModel model){
        ResultGeekerModel resultModel;
        try {
            TUpgradePlanDetailModel resModel= tUpgradePlanDetailService.updateTUpgradePlanDetail(model);
            resultModel=new ResultGeekerModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除升级计划明细")
    @RequestMapping(value = "/deleteTUpgradePlanDetail",method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel deleteTUpgradePlanDetail(int id){
        ResultGeekerModel resultModel;
        try {
            int res= tUpgradePlanDetailService.deleteTUpgradePlanDetail(id);
            resultModel=new ResultGeekerModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("根据计划ID获取明细列表")
    @RequestMapping(value = "/findTUpgradePlanDetailsByPlanId",method = RequestMethod.GET)
    @ResponseBody
    public ResultGeekerModel findTUpgradePlanDetailsByPlanId(int planId){
        ResultGeekerModel resultModel;
        try {
            List<TUpgradePlanDetailModel> resList = tUpgradePlanDetailService.findTUpgradePlanDetailsByPlanId(planId);
            resultModel=new ResultGeekerModel(resList);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultGeekerModel(e.getMessage());
        }
        return resultModel;
    }
}
