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.enums.purchase.PurchaseStatusEnum;
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("/stay/purchase/page")
    public R stayPurchasePage(@RequestBody Map<String, Object> condition) {
        Page<ApplyPurchase> result = purchaseService.stayPurchasePage(condition);
        return R.success(result);
    }

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

    /**
     * 取消
     *
     * @param entity
     * @return
     */
    @PostMapping("/cancel")
    public R cancel(@RequestBody Purchase entity) {
        purchaseService.cancelOrEnd(entity.getId(), PurchaseStatusEnum.STATUS_99.getKey());
        return R.success();
    }

    /**
     * 结束
     *
     * @param entity
     * @return
     */
    @PostMapping("/end")
    public R end(@RequestBody Purchase entity) {
        purchaseService.cancelOrEnd(entity.getId(), PurchaseStatusEnum.STATUS_50.getKey());
        return R.success();
    }

}

