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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.wxUser.domain.CompanyWxUserGroup;
import com.fs.wxUser.service.ICompanyWxUserGroupService;
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-25
 */
@RestController
@RequestMapping("/company/wxUserGroup")
public class CompanyWxUserGroupController extends BaseController
{
    @Autowired
    private ICompanyWxUserGroupService companyWxUserGroupService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询个微 分组列表
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyWxUserGroup companyWxUserGroup)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        companyWxUserGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        List<CompanyWxUserGroup> list = companyWxUserGroupService.selectCompanyWxUserGroupList(companyWxUserGroup);
        return getDataTable(list);
    }

    //查询个微分组-添加sop任务-个微-选择的分组（不要权限版）
    @GetMapping("/sopList")
    public TableDataInfo sopList(CompanyWxUserGroup companyWxUserGroup)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        companyWxUserGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        List<CompanyWxUserGroup> list = companyWxUserGroupService.selectCompanyWxUserGroupList(companyWxUserGroup);
        return getDataTable(list);
    }

    /**
     * 导出个微 分组列表
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:export')")
    @Log(title = "个微 分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyWxUserGroup companyWxUserGroup)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        companyWxUserGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        List<CompanyWxUserGroup> list = companyWxUserGroupService.selectCompanyWxUserGroupList(companyWxUserGroup);
        ExcelUtil<CompanyWxUserGroup> util = new ExcelUtil<CompanyWxUserGroup>(CompanyWxUserGroup.class);
        return util.exportExcel(list, "个微 分组数据");
    }

    /**
     * 获取个微 分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return AjaxResult.success(companyWxUserGroupService.selectCompanyWxUserGroupByGroupId(groupId));
    }

    /**
     * 新增个微 分组
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:add')")
    @Log(title = "个微 分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyWxUserGroup companyWxUserGroup)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        companyWxUserGroup.setCompanyId(loginUser.getCompany().getCompanyId());
        return toAjax(companyWxUserGroupService.insertCompanyWxUserGroup(companyWxUserGroup));
    }

    /**
     * 修改个微 分组
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:edit')")
    @Log(title = "个微 分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyWxUserGroup companyWxUserGroup)
    {
        return toAjax(companyWxUserGroupService.updateCompanyWxUserGroup(companyWxUserGroup));
    }

    /**
     * 删除个微 分组
     */
    @PreAuthorize("@ss.hasPermi('company:wxUserGroup:remove')")
    @Log(title = "个微 分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(companyWxUserGroupService.deleteCompanyWxUserGroupByGroupIds(groupIds));
    }


}
