package com.mvc.controller.taizhang;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.TStkoutDetailModel;
import com.mvc.service.taizhang.TStkoutDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Api(tags = "出库明细表接口")
@RequestMapping("/TStkoutDetailAction")
@Controller
public class TStkoutDetailAction {
    @Autowired
    private TStkoutDetailService TStkoutDetailService;

    @ApiOperation("根据出库单据标号查询出库明细")
    @RequestMapping(value = "/findBybillCode/{billCode}/{page}/{rows}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findBybillCode(@PathVariable("billCode") String billCode,@PathVariable("page")  Integer page,@PathVariable("rows")  Integer rows){

        try {
            Map<String, Object> res= TStkoutDetailService.findBybillCodeByPage(billCode,page,rows);
            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 = "/saveTStkoutDetail/{billCode}/{devsns}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> saveTStkoutDetail(@PathVariable("billCode") String billCode,@PathVariable("devsns") String devsns){

        try {
            List<TStkoutDetailModel> resList= TStkoutDetailService.saveTStkoutDetail(billCode,devsns);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }


    @ApiOperation("删除出库明细表")
    @RequestMapping(value = "/deleteTStkoutDetail/{ids}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTStkoutDetail(@PathVariable("ids") String  ids){
        try {
            int  res= TStkoutDetailService.deleteTStkoutDetail(ids);
            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;
        }
    }
}
