package com.fs.qw;

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.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwContactWayGroup;
import com.fs.qw.service.IQwContactWayGroupService;
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-07-19
 */
@RestController
@RequestMapping("/qw/contactWayGroup")
public class QwContactWayGroupController extends BaseController
{
    @Autowired
    private IQwContactWayGroupService qwContactWayGroupService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询联系我分组列表
     */
//    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwContactWayGroup qwContactWayGroup)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwContactWayGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        List<QwContactWayGroup> list = qwContactWayGroupService.selectQwContactWayGroupList(qwContactWayGroup);
        return getDataTable(list);
    }

    /**
     * 导出联系我分组列表
     */
    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:export')")
    @Log(title = "联系我分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwContactWayGroup qwContactWayGroup)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwContactWayGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        List<QwContactWayGroup> list = qwContactWayGroupService.selectQwContactWayGroupList(qwContactWayGroup);
        ExcelUtil<QwContactWayGroup> util = new ExcelUtil<QwContactWayGroup>(QwContactWayGroup.class);
        return util.exportExcel(list, "联系我分组数据");
    }

    /**
     * 获取联系我分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwContactWayGroupService.selectQwContactWayGroupById(id));
    }

    /**
     * 新增联系我分组
     */
    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:add')")
    @Log(title = "联系我分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwContactWayGroup qwContactWayGroup)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwContactWayGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        return toAjax(qwContactWayGroupService.insertQwContactWayGroup(qwContactWayGroup));
    }

    /**
     * 修改联系我分组
     */
    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:edit')")
    @Log(title = "联系我分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwContactWayGroup qwContactWayGroup)
    {
        return toAjax(qwContactWayGroupService.updateQwContactWayGroup(qwContactWayGroup));
    }

    /**
     * 删除联系我分组
     */
    @PreAuthorize("@ss.hasPermi('qw:contactWayGroup:remove')")
    @Log(title = "联系我分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwContactWayGroupService.deleteQwContactWayGroupByIds(ids));
    }
}
