package com.trade.admin.enterprise.customer.controller;

import com.trade.service.enterprise.customer.dto.EnterpriseDictVO;
import com.trade.admin.enterprise.customer.service.EnterpriseService;
import com.trade.admin.enterprise.customer.dto.EnterpriseDetailDto;
import com.trade.service.enterprise.customer.dto.EnterpriseBaseInfoDto;
import com.trade.service.enterprise.customer.dto.EnterpriseSearchDto;
import com.trade.admin.system.controller.BaseController;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业信息接口
 *
 * @author hlb
 * @since 2024-05-29 15:02:09
 */
@RestController
@RequestMapping("/customer/enterprise")
public class EnterpriseController extends BaseController {

    @Resource
    private EnterpriseService enterpriseService;

    /**
     * 分页查询企业信息
     *
     * @param search 查询实体
     * @return 所有数据
     */
    @GetMapping("/pages")
    @PreAuthorize("@ss.hasPermi('customer:enterprise:list')")
    public ResponseResult<GridPage<EnterpriseBaseInfoDto>> getPages(EnterpriseSearchDto search) {
        GridPage<EnterpriseBaseInfoDto> pages = enterpriseService.getPages(search);
        return success(pages);
    }

    /**
     * 通过主键查询企业信息
     *
     * @param id 主键
     * @return 企业信息
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('customer:enterprise:detail')")
    public ResponseResult<EnterpriseDetailDto> queryById(@PathVariable Long id) {
        EnterpriseDetailDto enterprise = enterpriseService.queryDetailById(id);
        return success(enterprise);
    }

    /**
     * 查询所有客户字典数据
     */
    @RequestMapping("/queryAllEnterprise4Dict")
    public ResponseResult<List<EnterpriseDictVO>> queryAllEnterprise4Dict() {
        return ResponseResult.success(enterpriseService.queryAllEnterprise4Dict());
    }
}
