package com.fjhx.controller.stock;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.enums.stock.InTypeEnum;
import com.fjhx.params.stock.StockChangeVo;
import com.fjhx.service.apply.ApplyPurchaseService;
import com.fjhx.service.logistics.LogisticsDetailsService;
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;

import java.util.List;
import java.util.Map;

/**
 * 采购入库
 */
@RestController
@RequestMapping("/purchase/in/stock")
public class PurchaseInStockController {

    @Autowired
    private ApplyPurchaseService applyPurchaseService;

    @Autowired
    private LogisticsDetailsService logisticsDetailsService;

    @Autowired
    private StockService stockService;

    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = applyPurchaseService.applyInPage(condition);
        return R.success(result);
    }

    @PostMapping("getLogisticsDetailsByLogisticsId")
    public R getLogisticsDetailsByLogisticsId(@RequestBody Condition condition) {
        List<Map<String, Object>> result = logisticsDetailsService.getLogisticsDetailsByLogisticsId(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody StockChangeVo stockVo) {
        stockVo.setTypeEnum(InTypeEnum.PURCHASE);
        stockService.changeQuantity(stockVo);
        return R.success();
    }

}
