package com.fjhx.controller.stock;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.entity.logistics.LogisticsInfo;
import com.fjhx.params.stock.GetLogisticsDetailsDto;
import com.fjhx.params.stock.GetLogisticsDetailsVo;
import com.fjhx.params.stock.InStockAdd;
import com.fjhx.service.logistics.LogisticsDetailsService;
import com.fjhx.service.logistics.LogisticsInfoService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

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

    @Autowired
    private LogisticsInfoService logisticsInfoService;

    @Autowired
    private LogisticsDetailsService logisticsDetailsService;

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

    // /**
    //  * 物流单明细
    //  *
    //  * @param entity 查询条件
    //  * @return
    //  */
    // @PostMapping("/logistics/details")
    // public R logisticsDetails(@RequestBody LogisticsDetails entity) {
    //     List<LogisticsDetails> result = logisticsDetailsService.getByLogisticsInfoId(entity.getLogisticsInfoId());
    //     return R.success(result);
    // }

    /**
     * 物流单明细
     */
    @PostMapping("/getLogisticsDetails")
    public R getLogisticsDetails(@RequestBody GetLogisticsDetailsDto getLogisticsDetailsDto) {
        List<GetLogisticsDetailsVo> result = logisticsDetailsService.getByLogisticsInfoId(getLogisticsDetailsDto);
        return R.success(result);
    }

    /**
     * 入库
     */
    @PostMapping("/add")
    public R add(@Validated @RequestBody InStockAdd inStockAdd) {
        logisticsInfoService.inStock(inStockAdd);
        return R.success();
    }

}
