package com.trade.admin.trade.purchasecontract.controller;

import com.trade.admin.trade.purchasecontract.dto.PurchaseContractSearchDto;
import com.trade.admin.system.controller.BaseController;
import com.trade.admin.trade.purchasecontract.service.PurchaseContractService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.purchasecontract.dto.PurchaseContractDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 采购合同接口
 *
 * @author hlb
 * @since 2024-09-07 16:30:38
 */
@RestController
@RequestMapping("/purchaseContract")
public class PurchaseContractController extends BaseController {

    /**
     * 服务对象
     */
    @Resource
    private PurchaseContractService purchaseContractService;

    /**
     * 分页查询采购合同基础信息
     *
     * @param search 查询实体
     * @return 所有数据
     */
    @GetMapping("/pages")
    @PreAuthorize("@ss.hasPermi('trade:purchaseContract:pages')")
    public ResponseResult<GridPage<PurchaseContractDto>> getPages(PurchaseContractSearchDto search) {
        return success(purchaseContractService.getPurchaseContractBySearch(search));
    }

    /**
     * 通过主键查询采购合同详细信息
     *
     * @param id 主键
     * @return 采购合同详细信息
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('trade:purchaseContract:query')")
    public ResponseResult<PurchaseContractDto> queryById(@PathVariable Long id) {
        return success(purchaseContractService.findPurchaseContractDetailById(id));
    }
}
