package com.fjhx.controller.purchase;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.apply.ApplyPurchase;
import com.fjhx.entity.purchase.Purchase;
import com.fjhx.service.purchase.PurchaseService;
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.Map;

/**
 * <p>
 * 采购 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-01
 */
@RestController
@RequestMapping("/purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    /**
     * 待发货列表
     *
     * @param condition 查询条件
     * @return
     */
    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<Purchase> result = purchaseService.getPage(condition);
        return R.success(result);
    }

    /**
     * 待采购列表
     *
     * @param condition 查询条件
     * @return
     */
    @PostMapping("/stay/purchase/page")
    public R stayPurchasePage(@RequestBody Map<String, Object> condition) {
        Page<ApplyPurchase> result = purchaseService.stayPurchasePage(condition);
        return R.success(result);
    }

    /**
     * 完成
     *
     * @param entity
     * @return
     */
    @PostMapping("/complete")
    public R complete(@RequestBody Purchase entity) {
        purchaseService.complete(entity.getId());
        return R.success();
    }
}

