package com.mvc.controller.taizhang;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.TStkinModel;
import com.mvc.service.taizhang.TStkinService;
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.*;

import java.util.Map;

@Api(tags = "设备入库表接口")
@RequestMapping("/TStkinAction")
@Controller
public class TStkinAction {
    @Autowired
    private TStkinService tStkinService;

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

        try {
            Map<String,Object> res= tStkinService.findAllTStkin(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 = "/saveTStkin",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTStkin(@RequestBody TStkinModel model){
        try {
            String msg = tStkinService.checkDataLegitimacy(model);
            if(StringUtils.isNotEmpty(msg)){
                Map<String, Object> resMap = new ErrorMap();
                resMap.put("error", msg);
                return resMap;
            }

            TStkinModel resModel= tStkinService.saveTStkin(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 = "/updateTStkin",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateTStkin(@RequestBody TStkinModel model){
        try {
            String msg = tStkinService.checkDataLegitimacy(model);
            if(StringUtils.isNotEmpty(msg)){
                Map<String, Object> resMap = new ErrorMap();
                resMap.put("error", msg);
                return resMap;
            }

            TStkinModel resModel= tStkinService.updateTStkin(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 = "/deleteTStkin",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteTStkin(@RequestBody TStkinModel model){
        try {
            int  res= tStkinService.deleteTStkin(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;
        }
    }
}
