package com.ruoyi.web.v2.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.model.JsOutStock;
import com.ruoyi.web.v2.service.IJsOutStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0物料领用 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-23
 */
@RestController
@RequestMapping("/js-out-stock")
@Api("2.0物料领用")
public class JsOutStockController {

    @Autowired
    private IJsOutStockService outStockService;

    @ApiOperation("物料领用添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsOutStock outStock) {
        return outStockService.add(outStock);
    }

    @ApiOperation("物料领用修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsOutStock outStock) {
        return outStockService.edit(outStock);
    }

//    @ApiOperation("物料领用删除")
//    @PostMapping("/delete")
//    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
//        String ids = paramsMap.get("ids");
//        return outStockService.delete(ids);
//    }

    @ApiOperation("物料领用列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return outStockService.listAll();
    }

    @ApiOperation("物料领用分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "materialBatch", required = false) String materialBatch
            , @RequestParam(value = "materialName", required = false) String materialName
            , @RequestParam(value = "materialType", required = false) Integer materialType
            , @RequestParam(value = "needAllFlag", required = false) Boolean needAllFlag) {

        return outStockService.page(pageNum, pageSize, startTime, endTime, materialBatch,materialName,materialType,needAllFlag);
    }

    @ApiOperation("物料领用详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(outStockService.getById(id));
    }
}
