package cn.ezhizao.project.business.companyContactor.controller;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.companyContactor.domain.BizCompanyContactor;
import cn.ezhizao.project.business.companyContactor.service.IBizCompanyContactorService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户联系人Controller
 *
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/business/companyContactor")
public class BizCompanyContactorController extends BaseController
{
    @Resource
    private IBizCompanyContactorService bizCompanyContactorService;

    /**
     * 查询客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCompanyContactor bizCompanyContactor) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyContactor);
        startPage();
        List<BizCompanyContactor> list = bizCompanyContactorService.getList(bizCompanyContactor);
        return getDataTable(list);
    }

    /**
     * 导出客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:export')")
    @Log(title = "客户联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompanyContactor bizCompanyContactor) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyContactor);
        List<BizCompanyContactor> list = bizCompanyContactorService.getList(bizCompanyContactor);
        ExcelUtil<BizCompanyContactor> util = new ExcelUtil<BizCompanyContactor>(BizCompanyContactor.class);
        util.exportExcel(response, list, "客户联系人数据");
    }

    /**
     * 获取客户联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCompanyContactorService.getById(id));
    }

    /**
     * 新增客户联系人
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:add')")
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompanyContactor bizCompanyContactor) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyContactor);
        return toAjax(bizCompanyContactorService.save(bizCompanyContactor));
    }

    /**
     * 修改客户联系人
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:edit')")
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompanyContactor bizCompanyContactor) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyContactor);
        return toAjax(bizCompanyContactorService.updateById(bizCompanyContactor));
    }

    /**
     * 删除客户联系人
     */
    @PreAuthorize("@ss.hasPermi('business:companyContactor:remove')")
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCompanyContactorService.removeBatchByIds(ids));
    }
}
