package com.fs.qw.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.model.LoginUser;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.utils.SecurityUtils;
import com.fs.qw.domain.QwExternalContactTransferCompanyAudit;
import com.fs.qw.domain.QwExternalContactTransferCompanyAuditUser;
import com.fs.qw.dto.CompanyTransferAuditDTO;
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 javax.validation.Valid;
import java.util.List;

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

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

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwExternalContactTransferCompanyAudit param) {
        startPage();
        List<QwExternalContactTransferCompanyAudit> list = auditService.selectQwExternalContactTransferCompanyAuditList(param);
        return getDataTable(list);
    }

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

    @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:audit')")
    @PostMapping("/audit")
    public AjaxResult audit(@Valid @RequestBody CompanyTransferAuditDTO param) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        auditService.audit(param, loginUser.getUser().getUserName());
        return AjaxResult.success();
    }

}
