package com.hys.app.controller.erp.goods;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dos.ProductStockDO;
import com.hys.app.model.erp.dto.GoodsSnDTO;
import com.hys.app.model.erp.dto.ProductStockDeleteReq;
import com.hys.app.model.erp.dto.ProductStockQueryParams;
import com.hys.app.model.erp.vo.*;
import com.hys.app.service.erp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品库存相关API
 *
 * @author 张崧
 * @since 2023-12-07 10:08:44
 */
@RestController
@RequestMapping("/admin/erp/productStock")
@Api(tags = "商品库存相关API")
@Validated
public class ProductStockManagerController {

    @Autowired
    private ProductStockManager productStockManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<ProductStockV1> list(ProductStockQueryParams queryParams) {
        List<ProductStockV1> productStockV1s= productStockManager.selectList(queryParams);
        Long recordCount= productStockManager.selectCount(queryParams);
        WebPage<ProductStockV1> voWebPage1=new WebPage<>();
        voWebPage1.setPageSize(queryParams.getPageSize());
        voWebPage1.setPageNo(queryParams.getPageNo());
        voWebPage1.setDataTotal(recordCount);
        voWebPage1.setData(productStockV1s);
        return voWebPage1;
    }


    @ApiOperation(value = "查询一条数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query")
    })
    @GetMapping("/getOne")
    public ProductStockDO getOne(@RequestParam String id){
        return productStockManager.getOne(id);
    }

    @ApiOperation(value = "删除库存记录")
    @PostMapping("/delete")
    public void delete(@RequestBody @Valid ProductStockDeleteReq request){
         productStockManager.deleteByIds(request.getIds());
    }


    @ApiOperation(value = "查询商品库存预警分页列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page_no", value = "分页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "page_size", value = "每页数量", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "warehouse_id", value = "仓库ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "dept_id", value = "部门ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query")
    })
    @GetMapping("/list-stock-warning")
    public WebPage<ProductStockWarningVO> listWarningStock(@ApiIgnore Long pageNo, @ApiIgnore Long pageSize,
                                                           @ApiIgnore Long warehouseId, @ApiIgnore Long deptId, @ApiIgnore String name) {
        return productStockManager.listWarningStock(pageNo, pageSize, warehouseId, deptId, name);
    }
}

