package com.fs.company.controller.company;

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.CompanyUser;
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 companyWxAccountService;

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

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

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

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

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

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