package com.mvc.controller.taizhang;


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

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

@Api(tags = "入库明细表接口")
@RequestMapping("/TStkinDetailAction")
@Controller
public class TStkinDetailAction {

    @Autowired
    private TStkinDetailService tStkinDetailService;

    @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= tStkinDetailService.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 = "/saveTStkinDetail/{billCode}/{devsns}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> saveTStkinDetail(@PathVariable("billCode") String billCode,@PathVariable("devsns") String devsns){

        try {
            List<TStkinDetailModel> resList= tStkinDetailService.saveTStkinDetail(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 = "/deleteTStkinDetail/{ids}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTStkinDetail(@PathVariable("ids") String  ids){
        try {
            int  res= tStkinDetailService.deleteTStkinDetail(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;
        }
    }
}
