package com.fs.qw;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwExternalContactTransferLog;
import com.fs.qw.param.QwExternalContactTransferLogParam;
import com.fs.qw.service.IQwExternalContactTransferLogService;
import com.fs.qw.vo.QwExternalContactTransferLogListVO;
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 fs
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/qw/externalContactTransferLog")
public class QwExternalContactTransferLogController extends BaseController
{
    @Autowired
    private IQwExternalContactTransferLogService qwExternalContactTransferLogService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询转接记录列表
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwExternalContactTransferLogParam qwExternalContactTransferLog)
    {
        startPage();
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        Long companyId = loginUser.getCompany().getCompanyId();
//        qwExternalContactTransferLog.setCompanyId(companyId);

        List<QwExternalContactTransferLogListVO> list = qwExternalContactTransferLogService.selectQwExternalContactTransferLogListVO(qwExternalContactTransferLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:myList')")
    @GetMapping("/myList")
    public TableDataInfo myList(QwExternalContactTransferLogParam qwExternalContactTransferLog)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        qwExternalContactTransferLog.setCompanyId(companyId);
        qwExternalContactTransferLog.setCompanyUserId(loginUser.getUser().getUserId());
        List<QwExternalContactTransferLogListVO> list = qwExternalContactTransferLogService.selectQwExternalContactTransferLogListVO(qwExternalContactTransferLog);
        return getDataTable(list);
    }

    /**
     * 导出转接记录列表 阿
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:export')")
    @Log(title = "转接记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwExternalContactTransferLog qwExternalContactTransferLog)
    {
        List<QwExternalContactTransferLog> list = qwExternalContactTransferLogService.selectQwExternalContactTransferLogList(qwExternalContactTransferLog);
        ExcelUtil<QwExternalContactTransferLog> util = new ExcelUtil<QwExternalContactTransferLog>(QwExternalContactTransferLog.class);
        return util.exportExcel(list, "转接记录数据");
    }

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:sync')")
    @Log(title = "同步", businessType = BusinessType.INSERT)
    @GetMapping("/sync/{corpId}")
    public R syncTag(@PathVariable("corpId") String corpId)
    {

        return qwExternalContactTransferLogService.syncQwExternalContactTransferLog(corpId);
    }
    /**
     * 获取转接记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwExternalContactTransferLogService.selectQwExternalContactTransferLogById(id));
    }

    /**
     * 新增转接记录
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:add')")
    @Log(title = "转接记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwExternalContactTransferLog qwExternalContactTransferLog)
    {
        return toAjax(qwExternalContactTransferLogService.insertQwExternalContactTransferLog(qwExternalContactTransferLog));
    }

    /**
     * 修改转接记录
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:edit')")
    @Log(title = "转接记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwExternalContactTransferLog qwExternalContactTransferLog)
    {
        return toAjax(qwExternalContactTransferLogService.updateQwExternalContactTransferLog(qwExternalContactTransferLog));
    }

    /**
     * 删除转接记录
     */
    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferLog:remove')")
    @Log(title = "转接记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwExternalContactTransferLogService.deleteQwExternalContactTransferLogByIds(ids));
    }
}
