package com.fjhx.controller.stock;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.entity.stock.StockJournal;
import com.fjhx.enums.stock.InTypeEnum;
import com.fjhx.params.stock.ManualInDto;
import com.fjhx.params.stock.StockChangeDto;
import com.fjhx.service.stock.StockJournalService;
import com.fjhx.service.stock.StockService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 手动入库
 */
@RestController
@RequestMapping("/manual/in/stock")
public class ManualInStockController {

    @Autowired
    private StockJournalService stockJournalService;

    @Autowired
    private StockService stockService;

    /**
     * 列表
     *
     * @param condition 查询条件
     * @return
     */
    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<StockJournal> result = stockJournalService.getManualInStockPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody ManualInDto manualInDto) {
        StockChangeDto stockChangeDto = new StockChangeDto();
        stockChangeDto.setDefaultBusinessId(IdWorker.getId());
        stockChangeDto.setDefaultWarehouseId(manualInDto.getWarehouseId());
        stockChangeDto.setDefaultRemarks(manualInDto.getRemarks());
        stockChangeDto.setTypeEnum(InTypeEnum.MANUAL);
        stockChangeDto.setChangeDetailsList(manualInDto.getChangeProductList());

        stockService.changeQuantity(stockChangeDto);
        return R.success();
    }

}
