package com.fs.qw.controller;

import java.util.List;

import com.fs.common.core.domain.R;
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.qw.domain.QwWorkUser;
import com.fs.qw.service.IQwWorkUserService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 企微获客添加的用户Controller
 * 
 * @author fs
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/qw/workUser")
public class QwWorkUserController extends BaseController
{
    @Autowired
    private IQwWorkUserService qwWorkUserService;

    /**
     * 查询企微获客添加的用户列表
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwWorkUser qwWorkUser)
    {
        startPage();
        List<QwWorkUser> list = qwWorkUserService.selectQwWorkUserList(qwWorkUser);
        return getDataTable(list);
    }

    /**
     * 导出企微获客添加的用户列表
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:export')")
    @Log(title = "企微获客添加的用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwWorkUser qwWorkUser)
    {
        List<QwWorkUser> list = qwWorkUserService.selectQwWorkUserList(qwWorkUser);
        ExcelUtil<QwWorkUser> util = new ExcelUtil<QwWorkUser>(QwWorkUser.class);
        return util.exportExcel(list, "企微获客添加的用户数据");
    }

    /**
     * 获取企微获客添加的用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwWorkUserService.selectQwWorkUserById(id));
    }

    /**
     * 新增企微获客添加的用户
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:add')")
    @Log(title = "企微获客添加的用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwWorkUser qwWorkUser)
    {
        return toAjax(qwWorkUserService.insertQwWorkUser(qwWorkUser));
    }

    /**
     * 修改企微获客添加的用户
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:edit')")
    @Log(title = "企微获客添加的用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwWorkUser qwWorkUser)
    {
        return toAjax(qwWorkUserService.updateQwWorkUser(qwWorkUser));
    }

    /**
     * 删除企微获客添加的用户
     */
    @PreAuthorize("@ss.hasPermi('qw:workUser:remove')")
    @Log(title = "企微获客添加的用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwWorkUserService.deleteQwWorkUserByIds(ids));
    }


//    @GetMapping("/syncUsers")
    public R syncUsers(){
        qwWorkUserService.syncUsers();
        return R.ok();
    }
//    @GetMapping("/uploadBd")
    public R uploadBd(){
        qwWorkUserService.uploadBd();
        return R.ok();
    }
}
