package com.dsk.cscec.controller;


import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.domain.R;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.utils.poi.ExcelUtil;
import com.dsk.cscec.domain.DCustomer;
import com.dsk.cscec.domain.bo.AdvisoryBodyBo;
import com.dsk.cscec.domain.bo.CustomerInfoBo;
import com.dsk.cscec.domain.vo.AdvisoryBodyVo;
import com.dsk.cscec.domain.vo.CustomerInfoVo;
import com.dsk.cscec.service.ICustomerInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 供应商相关
 *
 * @author
 * @since 2023-12-10
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/customerInfo")
public class CustomerInfoController extends BaseController {
    /**
     * 服务对象
     */
    private final ICustomerInfoService iCustomerInfoService;


    /**
     * 供应商分类列表
     */
    @PostMapping("/list")
    public TableDataInfo<CustomerInfoVo> list(@Validated @RequestBody CustomerInfoBo bo, @RequestBody PageQuery query) {
        return iCustomerInfoService.queryPageList(bo, query);
    }

    /**
     * 内部合作-咨询机构合作记录
     */
    @GetMapping("/advisoryList")
    public TableDataInfo<AdvisoryBodyVo> advisoryList(@Validated AdvisoryBodyBo bo, PageQuery query) {
        return iCustomerInfoService.queryAdvisoryList(bo, query);
    }

    /**
     * 内部合作-咨询机构合作记录导出
     */
    @GetMapping("/advisoryExport")
    public void advisoryExport(@Validated AdvisoryBodyBo bo, PageQuery query, HttpServletResponse response) {
        List<AdvisoryBodyVo> listVo = iCustomerInfoService.queryAdvisoryList(bo, query).getRows();
        ExcelUtil.exportExcel(listVo, "咨询机构合作记录", AdvisoryBodyVo.class, response);
    }

    /**
     * 合作记录-供应商准入情况
     */
    @GetMapping("/getByName/{name}")
    public R<DCustomer> list(@NotEmpty(message = "企业名称不能为空") @PathVariable String name) {
        return R.ok(iCustomerInfoService.queryByName(name));
    }

}

