package com.fs.company.controller.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.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.qw.domain.QwExternalContactTransferCompanyAudit;
import com.fs.qw.domain.QwExternalContactTransferCompanyAuditUser;
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditService;
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/qw/externalContactTransferCompanyAudit")
public class QwExternalContactTransferCompanyAuditController extends BaseController {

    @Autowired
    private IQwExternalContactTransferCompanyAuditService auditService;
    @Autowired
    private IQwExternalContactTransferCompanyAuditUserService auditUserService;
    @Autowired
    private TokenService tokenService;

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwExternalContactTransferCompanyAudit param) {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        param.setOperCompanyId(companyId);
        List<QwExternalContactTransferCompanyAudit> list = auditService.selectQwExternalContactTransferCompanyAuditList(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:sync')")
    @Log(title = "公司转接同步", businessType = BusinessType.INSERT)
    @PostMapping("/sync/{auditId}")
    public R sync(@PathVariable("auditId") Long auditId) {
        auditService.syncTransfer(auditId);
        return R.ok();
    }

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:detail')")
    @GetMapping("/detail/{auditId}")
    public TableDataInfo detail(@PathVariable Long auditId) {
        startPage();
        List<QwExternalContactTransferCompanyAuditUser> list = auditUserService.getListByAuditId(auditId);
        return getDataTable(list);
    }
}
