package com.fjhx.wms.controller.stock;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.wms.entity.stock.dto.StockSelectDto;
import com.fjhx.wms.entity.stock.po.Stock;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.wms.entity.stock.vo.StockVo;
import com.fjhx.wms.entity.stock.dto.StockDto;
import com.ruoyi.common.core.domain.BaseSelectDto;
import com.fjhx.wms.service.stock.StockService;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * <p>
 * 库存 前端控制器
 * </p>
 *
 * @author 
 * @since 2023-03-20
 */
@DS(SourceConstant.WMS)
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 库存查询
     */
    @PostMapping("/page")
    public Page<StockVo> page(@RequestBody StockSelectDto dto) {
        return stockService.getPage(dto);
    }

    /**
     * 维多利亚 按仓库查询
     */
    @PostMapping("/pageByWarehouse")
    public Page<StockVo> pageByWarehouse(@RequestBody StockSelectDto dto) {
        return stockService.pageByWarehouse(dto);
    }

    /**
     * 维多利亚 按产品查询
     */
    @PostMapping("/pageByProduct")
    public Page<StockVo> pageByProduct(@RequestBody StockSelectDto dto) {
        return stockService.pageByProduct(dto);
    }

    /**
     * 维多利亚 按产品spu查询
     */
    @PostMapping("/pageByProductSpu")
    public Page<StockVo> pageByProductSpu(@RequestBody StockSelectDto dto) {
        return stockService.pageByProductSpu(dto);
    }

    /**
     * 库存明细
     */
    @PostMapping("/detail")
    public Stock detail(@RequestBody StockDto dto) {
        return stockService.detail(dto);
    }

    /**
     * 手动入库
     */
    @PostMapping("/add")
    public void add(@RequestBody StockDto stockDto) {
        stockService.add(stockDto);
    }

    /**
     * 手动出库
     */
    @PostMapping("/edit")
    public void edit(@RequestBody StockDto stockDto) {
        stockService.edit(stockDto);
    }

    /**
     * 库存删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        stockService.delete(dto.getId());
    }

    /**
     * 次品转良品
     *
     * @return
     */
    @PostMapping("/defectiveToQualified")
    public void defectiveToQualified(@RequestBody Stock stock){
        stockService.defectiveToQualified(stock);
    }

    /**
     * 良品转次品
     *
     * @return
     */
    @PostMapping("/qualifiedToDefective")
    public void qualifiedToDefective(@RequestBody Stock stock){
        stockService.qualifiedToDefective(stock);
    }


}
