package com.mvc.controller.taizhang;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.TStkoutModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Api(tags = "设备出库表接口")
@RequestMapping("/TStkoutAction")
@Controller
public class TStkoutAction {

    @Autowired
    private com.mvc.service.taizhang.TStkoutService tStkoutService;

    @ApiOperation("设备出库表分页查询")
    @RequestMapping(value = "/findlistByCon",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllTStkout(@RequestBody TStkoutModel model){

        try {
            Map<String,Object> res= tStkoutService.findAllTStkout(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("新增设备出库表")
    @RequestMapping(value = "/saveTStkout",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTStkout(@RequestBody TStkoutModel model){
        try {
            String msg = tStkoutService.checkDataLegitimacy(model);
            if(StringUtils.isNotEmpty(msg)){
                Map<String, Object> resMap = new ErrorMap();
                resMap.put("error", msg);
                return resMap;
            }

            TStkoutModel resModel= tStkoutService.saveTStkout(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("更新设备出库表")
    @RequestMapping(value = "/updateTStkout",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateTStkout(@RequestBody TStkoutModel model){
        try {
            String msg = tStkoutService.checkDataLegitimacy(model);
            if(StringUtils.isNotEmpty(msg)){
                Map<String, Object> resMap = new ErrorMap();
                resMap.put("error", msg);
                return resMap;
            }

            TStkoutModel resModel= tStkoutService.updateTStkout(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("删除设备出库表")
    @RequestMapping(value = "/deleteTStkout",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteTStkout(@RequestBody TStkoutModel model){
        try {
            int  res= tStkoutService.deleteTStkout(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }
}
