package com.huimv.receive.controller;


import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.entity.vo.GoodsVo;
import com.huimv.receive.service.IBillGoodsInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-08-22
 */
@RestController
@RequestMapping("/bill-goods-inventory")
@CrossOrigin
public class BillGoodsInventoryController {

    @Autowired
    private IBillGoodsInventoryService goodsInventoryService;

    @RequestMapping("/listAll")
    public Result listAll(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return goodsInventoryService.listAll(httpServletRequest, paramsMap);
    }

    @RequestMapping("/edit")
    public Result edit(HttpServletRequest httpServletRequest, @RequestParam("id") String id,
                       @RequestParam("goods") String goods,
                       @RequestParam("imgUrl1")MultipartFile imgUrl1,
                       @RequestParam(value = "imgUrl2",required = false) MultipartFile imgUrl2,
                       @RequestParam(value = "imgUrl3",required = false) MultipartFile imgUrl3,
                       @RequestParam(value = "imgUrl4",required = false) MultipartFile imgUrl4,
                       @RequestParam(value = "imgUrl5",required = false) MultipartFile imgUrl5,
                       @RequestParam(value = "imgUrl6",required = false) MultipartFile imgUrl6) throws IOException {
        return goodsInventoryService.edit(httpServletRequest, id,goods,imgUrl1,imgUrl2,imgUrl3,imgUrl4,imgUrl5,imgUrl6);
    }

    @RequestMapping("/list")
    public Result list(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return goodsInventoryService.list(httpServletRequest, paramsMap);
    }

    @RequestMapping("/listById")
    public Result listById(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return new Result(ResultCode.SUCCESS,goodsInventoryService.getById(id));
    }
}
