package com.fs.qw.controller;

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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyUser;
import com.fs.company.service.ICompanyUserService;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwAccount;
import com.fs.qw.domain.QwAccountAudit;
import com.fs.qw.param.QwAccountParam;
import com.fs.qw.service.IQwAccountService;
import com.fs.qw.vo.QwAccountListVO;
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 2023-08-23
 */
@RestController
@RequestMapping("/qw/account")
public class QwAccountController extends BaseController
{
    @Autowired
    private IQwAccountService qwAccountService;

    /**
     * 查询企微功能账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('qw:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwAccountParam param)
    {
        startPage();
        List<QwAccountListVO> list = qwAccountService.selectAllQwAccounts(param);
        return getDataTable(list);
    }


    /**
     * 获取企微功能账号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwAccountService.selectQwAccountById(id));
    }

    @PreAuthorize("@ss.hasPermi('qw:account:export')")
    @Log(title = "企微功能账号管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwAccountParam param)
    {
        List<QwAccountListVO> list = qwAccountService.selectAllQwAccounts(param);
        ExcelUtil<QwAccountListVO> util = new ExcelUtil<QwAccountListVO>(QwAccountListVO.class);
        return util.exportExcel(list, "企微账号");
    }

    /**
     * 审核企微功能账号管理
     */
    @PreAuthorize("@ss.hasPermi('qw:account:audit')")
    @Log(title = "企微功能账号管理", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody QwAccountAudit audit)
    {
        return toAjax(qwAccountService.auditQwAccount(audit));
    }

    /**
     * 删除企微功能账号管理
     */
    @PreAuthorize("@ss.hasPermi('qw:account:remove')")
    @Log(title = "企微功能账号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwAccountService.deleteQwAccountByIds(ids));
    }


}
