package com.ruoyi.web.v2.v1.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsInStock;
import com.ruoyi.web.v2.v1.service.IJsInStockService;
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-in-stock")
@Api("2.0物料入库")
public class JsInStockController {

    @Autowired
    private IJsInStockService inStockService;

    @ApiOperation("物料入库添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsInStock inStock) {
        return inStockService.add(inStock);
    }

    @ApiOperation("物料入库修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsInStock inStock) {
        return inStockService.edit(inStock);
    }

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

    @ApiOperation("物料入库列表")
    @PostMapping("/list")
    public AjaxResult listAll(@RequestBody Map<String, String> paramsMap) {
        String materialBatch = paramsMap.get("materialBatch");
        return inStockService.listAll(materialBatch);
    }

    @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 inStockService.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(inStockService.getById(id));
    }
}
