package com.fs.company.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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyWxAccount;
import com.fs.company.service.ICompanyWxAccountService;
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-12-09
 */
@RestController
@RequestMapping("/company/companyWx")
public class CompanyWxAccountController extends BaseController
{
    @Autowired
    private ICompanyWxAccountService companyWxEnterpriseAccountService;

    /**
     * 查询企微账号列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyWxAccount companyWxAccount)
    {
        startPage();
        List<CompanyWxAccount> list = companyWxEnterpriseAccountService.selectCompanyWxAccountList(companyWxAccount);
        return getDataTable(list);
    }
    /**
     * 查询企微账号列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:list')")
    @GetMapping("/listAll")
    public R listAll(CompanyWxAccount companyWxAccount){
        List<CompanyWxAccount> list = companyWxEnterpriseAccountService.selectCompanyWxAccountList(companyWxAccount);
        return R.ok().put("data", list);
    }

    /**
     * 导出企微账号列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:export')")
    @Log(title = "企微账号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyWxAccount companyWxAccount)
    {
        List<CompanyWxAccount> list = companyWxEnterpriseAccountService.selectCompanyWxAccountList(companyWxAccount);
        ExcelUtil<CompanyWxAccount> util = new ExcelUtil<CompanyWxAccount>(CompanyWxAccount.class);
        return util.exportExcel(list, "companyWx");
    }

    /**
     * 获取企微账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(companyWxEnterpriseAccountService.selectCompanyWxAccountById(id));
    }

    /**
     * 新增企微账号
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:add')")
    @Log(title = "企微账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyWxAccount companyWxAccount)
    {
        return toAjax(companyWxEnterpriseAccountService.insertCompanyWxAccount(companyWxAccount));
    }

    /**
     * 修改企微账号
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:edit')")
    @Log(title = "企微账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyWxAccount companyWxAccount)
    {
        return toAjax(companyWxEnterpriseAccountService.updateCompanyWxAccount(companyWxAccount));
    }

    /**
     * 删除企微账号
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:remove')")
    @Log(title = "企微账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyWxEnterpriseAccountService.deleteCompanyWxAccountByIds(ids));
    }
    /**
     * 删除企微账号
     */
    @PreAuthorize("@ss.hasPermi('company:companyWx:list')")
	@GetMapping("/companyListAll")
    public R companyListAll(){
        return R.ok().put("data", companyWxEnterpriseAccountService.companyListAll());
    }
}
