package com.ruoyi.project.business.controller;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.TcAccountContact;
import com.ruoyi.project.business.service.ITcAccountContactService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 联系人Controller
 * 
 * @author ruoyi
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/business/contact")
public class TcAccountContactController extends BaseController
{
    @Autowired
    private ITcAccountContactService tcAccountContactService;

    /**
     * 查询联系人列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TcAccountContact tcAccountContact)
    {
        startPage();
        List<TcAccountContact> list = tcAccountContactService.selectTcAccountContactList(tcAccountContact);
        return getDataTable(list);
    }

    /**
     * 查询相关联系人
     */
    @GetMapping("/contactlist")
    public TableDataInfo selectContactlistByAccountId(TcAccountContact tcAccountContact)
    {
        List<TcAccountContact> list = tcAccountContactService.selectContactlistByAccountId(tcAccountContact.getAccountId());
        return getDataTable(list);
    }

    /**
     * 导出联系人列表
     */
    @Log(title = "联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcAccountContact tcAccountContact)
    {
        List<TcAccountContact> list = tcAccountContactService.selectTcAccountContactList(tcAccountContact);
        ExcelUtil<TcAccountContact> util = new ExcelUtil<TcAccountContact>(TcAccountContact.class);
        util.exportExcel(response, list, "联系人数据");
    }

    /**
     * 获取联系人详细信息
     */
    @GetMapping(value = "/{contactId}")
    public AjaxResult getInfo(@PathVariable("contactId") Long contactId)
    {
        return success(tcAccountContactService.selectTcAccountContactByContactId(contactId));
    }

    /**
     * 新增联系人
     */
    @Log(title = "联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcAccountContact tcAccountContact)
    {
        return toAjax(tcAccountContactService.insertTcAccountContact(tcAccountContact));
    }

    /**
     * 修改联系人
     */
    @Log(title = "联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcAccountContact tcAccountContact)
    {
        return toAjax(tcAccountContactService.updateTcAccountContact(tcAccountContact));
    }

    /**
     * 删除联系人
     */
    @Log(title = "联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contactIds}")
    public AjaxResult remove(@PathVariable Long[] contactIds)
    {
        return toAjax(tcAccountContactService.deleteTcAccountContactByContactIds(contactIds));
    }

    /**
     * 查询相关联系人
     */
    @PostMapping("/getSameContactLib")
    public AjaxResult getSameContactLib(@RequestBody List<TcAccountContact> contactList) {
        return success(tcAccountContactService.getSameContactLib(contactList));
    }

}
