package com.fs.qywx.controller;

import java.util.ArrayList;
import java.util.List;

import com.fs.qywx.vo.QywxCompanyListVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.qywx.domain.QywxCompany;
import com.fs.qywx.service.IQywxCompanyService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 企业微信三方应用授权公司Controller
 *
 * @author fs
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/qywx/company")
public class QywxCompanyController extends BaseController
{
    @Autowired
    private IQywxCompanyService qywxCompanyService;

    /**
     * 查询企业微信三方应用授权公司列表
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(QywxCompany qywxCompany)
    {
        startPage();
        List<QywxCompanyListVO> list = qywxCompanyService.selectQywxCompanyListVO(qywxCompany);
        return getDataTable(list);
    }

    /**
     * 导出企业微信三方应用授权公司列表
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:export')")
    @Log(title = "企业微信三方应用授权公司", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QywxCompany qywxCompany)
    {
        List<QywxCompany> list = qywxCompanyService.selectQywxCompanyList(qywxCompany);
        ExcelUtil<QywxCompany> util = new ExcelUtil<QywxCompany>(QywxCompany.class);
        return util.exportExcel(list, "company");
    }

    /**
     * 获取企业微信三方应用授权公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qywxCompanyService.selectQywxCompanyById(Math.toIntExact(id)));
    }

    /**
     * 新增企业微信三方应用授权公司
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:add')")
    @Log(title = "企业微信三方应用授权公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QywxCompany qywxCompany)
    {
        return toAjax(qywxCompanyService.insertQywxCompany(qywxCompany));
    }

    /**
     * 修改企业微信三方应用授权公司
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:edit')")
    @Log(title = "企业微信三方应用授权公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QywxCompany qywxCompany)
    {

        return toAjax(qywxCompanyService.updateQywxCompany(qywxCompany));
    }

    /**
     * 删除企业微信三方应用授权公司
     */
    @PreAuthorize("@ss.hasPermi('qywx:company:remove')")
    @Log(title = "企业微信三方应用授权公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        Integer[] ints3 = new Integer[ids.length];
        for (int i = 0; i < ids.length; i++) {
            ints3[i] =Math.toIntExact(ids[i]);
        }
        return toAjax(qywxCompanyService.deleteQywxCompanyByIds(ints3));
    }
}
