package com.sckw.goods.controller;

import com.sckw.goods.entity.req.InventoryInsertParam;
import com.sckw.goods.entity.req.InventoryPageListParam;
import com.sckw.goods.entity.req.InventoryUpdateParam;
import com.sckw.goods.service.InventoryService;
import com.sckw.core.web.response.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 清单控制器
 * @author: Lt
 * @date: 2024-04-26
 */
@RestController
@RequestMapping("/goods/inventory")
public class InventoryController {

    @Autowired
    InventoryService inventoryService;

    /**
    * @Description: 新增清单
    * @Author: Lt
    * @Date: 2024/4/26 17:09
    */
    @PostMapping("/insert")
    public HttpResult insert(@RequestBody @Validated InventoryInsertParam inventoryParam)
    {
        return HttpResult.ok(inventoryService.insert(inventoryParam));
    }

    /**
     * @Description: 新增清单
     * @Author: Lt
     * @Date: 2024/4/26 17:09
     */
    @PostMapping("/update")
    public HttpResult update(@RequestBody @Validated InventoryUpdateParam IinventoryUpdateParam)
    {
        return HttpResult.ok(inventoryService.update(IinventoryUpdateParam));
    }

    /**
    * @Description: 清单List列表
    * @Author: Lt
    * @Date: 2024/4/27 13:54
    */
    @GetMapping("/findList")
    public HttpResult findList(@RequestParam(value = "name", required = false) String name)
    {
        return HttpResult.ok(inventoryService.findList(name));
    }

    /**
     * 清单分页查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findPage")
    public HttpResult findPage(@RequestBody InventoryPageListParam params) {
        return HttpResult.ok(inventoryService.findPage(params));
    }



    /**
     * 删除
     *
     * @return
     */
    @PostMapping("/delete")
    public HttpResult delete(@RequestParam(value = "ids") List<Long> ids) {
        int result = inventoryService.delete(ids);
        return HttpResult.ok(result);
    }

    /**
    * @Description: 根据清单ids查询所有清单
    * @Author: Lt
    * @Date: 2024/4/27 0027 13:59
    */
    @PostMapping("/inventoryAllByInventoryIds")
    public HttpResult inventoryAllByInventoryIds(@RequestParam(value = "ids") List<Long> ids) {

        return HttpResult.ok(inventoryService.inventoryAllByInventoryIds(ids));
    }
}
