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.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.qw.domain.QwCompany;
import com.fs.qw.service.IQwCompanyService;
import com.fs.qw.vo.QwOptionsVO;
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-10-09
 */
@RestController
@RequestMapping("/qw/qwCompany")
public class QwCompanyController extends BaseController
{
    @Autowired
    private IQwCompanyService qwCompanyService;

    /**
     * 查询企微主体列表
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwCompany qwCompany)
    {
        startPage();
        List<QwCompany> list = qwCompanyService.selectQwCompanyList(qwCompany);
        return getDataTable(list);
    }


    @GetMapping("/all")
    public R all()
    {
        List<QwOptionsVO> list = qwCompanyService.selectQwCompanyListOptionsVO();
        return R.ok().put("data", list);
    }
    /**
     * 导出企微主体列表
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:export')")
    @Log(title = "企微主体", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwCompany qwCompany)
    {
        List<QwCompany> list = qwCompanyService.selectQwCompanyList(qwCompany);
        ExcelUtil<QwCompany> util = new ExcelUtil<QwCompany>(QwCompany.class);
        return util.exportExcel(list, "企微主体数据");
    }

    /**
     * 获取企微主体详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwCompanyService.selectQwCompanyById(id));
    }

    /**
     * 新增企微主体
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:add')")
    @Log(title = "企微主体", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwCompany qwCompany)
    {
        return toAjax(qwCompanyService.insertQwCompany(qwCompany));
    }

    /**
     * 修改企微主体
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:edit')")
    @Log(title = "企微主体", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwCompany qwCompany)
    {
        return toAjax(qwCompanyService.updateQwCompany(qwCompany));
    }

    /**
     * 删除企微主体
     */
    @PreAuthorize("@ss.hasPermi('qw:qwCompany:remove')")
    @Log(title = "企微主体", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwCompanyService.deleteQwCompanyByIds(ids));
    }
}
