package com.ruoyi.web.controller.warehouse.basicData;

import com.ruoyi.basicData.domain.TCustomerContact;
import com.ruoyi.basicData.service.ITCustomerContactService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户联系人Controller
 *
 * @author ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/basicdata/contact")
public class TCustomerContactController extends BaseController {
    @Autowired
    private ITCustomerContactService tCustomerContactService;

    /**
     * 查询客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCustomerContact tCustomerContact) {
        startPage();
        List<TCustomerContact> list = tCustomerContactService.selectTCustomerContactList(tCustomerContact);
        return getDataTable(list);
    }

    /**
     * 导出客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:export')")
    @Log(title = "客户联系人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TCustomerContact tCustomerContact) {
        List<TCustomerContact> list = tCustomerContactService.selectTCustomerContactList(tCustomerContact);
        ExcelUtil<TCustomerContact> util = new ExcelUtil<TCustomerContact>(TCustomerContact.class);
        return util.exportExcel(list, "contact");
    }

    /**
     * 获取客户联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:query')")
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId) {
        return AjaxResult.success(tCustomerContactService.selectTCustomerContactById(tId));
    }

    /**
     * 新增客户联系人
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:add')")
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCustomerContact tCustomerContact) {
        return toAjax(tCustomerContactService.insertTCustomerContact(tCustomerContact));
    }

    /**
     * 修改客户联系人
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:edit')")
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCustomerContact tCustomerContact) {
        return toAjax(tCustomerContactService.updateTCustomerContact(tCustomerContact));
    }

    /**
     * 删除客户联系人
     */
    @PreAuthorize("@ss.hasPermi('basicdata:contact:remove')")
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tIds}")
    public AjaxResult remove(@PathVariable Long[] tIds) {
        return toAjax(tCustomerContactService.deleteTCustomerContactByIds(tIds));
    }
}
