package com.fs.company.controller.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.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.qw.domain.QwContactBatch;
import com.fs.qw.service.IQwContactBatchService;
import com.fs.qw.vo.QwContactBatchListVO;
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-12
 */
@RestController
@RequestMapping("/qw/contactBatch")
public class QwContactBatchController extends BaseController
{
    @Autowired
    private IQwContactBatchService qwContactBatchService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询企微公海列表
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwContactBatch qwContactBatch)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        qwContactBatch.setCompanyId(companyId);
        List<QwContactBatchListVO> list = qwContactBatchService.selectQwContactBatchListVO(qwContactBatch);
        return getDataTable(list);
    }

    /**
     * 导出企微公海列表
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:export')")
    @Log(title = "企微公海", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwContactBatch qwContactBatch)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        qwContactBatch.setCompanyId(companyId);
        List<QwContactBatch> list = qwContactBatchService.selectQwContactBatchList(qwContactBatch);
        ExcelUtil<QwContactBatch> util = new ExcelUtil<QwContactBatch>(QwContactBatch.class);
        return util.exportExcel(list, "企微公海数据");
    }

    /**
     * 获取企微公海详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwContactBatchService.selectQwContactBatchByIdVO(id));
    }

    /**
     * 新增企微公海
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:add')")
    @Log(title = "企微公海", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwContactBatch qwContactBatch)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        qwContactBatch.setCompanyId(companyId);
        return toAjax(qwContactBatchService.insertQwContactBatch(qwContactBatch));
    }

    /**
     * 修改企微公海
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:edit')")
    @Log(title = "企微公海", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwContactBatch qwContactBatch)
    {
        return toAjax(qwContactBatchService.updateQwContactBatch(qwContactBatch));
    }

    /**
     * 删除企微公海
     */
    @PreAuthorize("@ss.hasPermi('qw:contactBatch:remove')")
    @Log(title = "企微公海", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwContactBatchService.deleteQwContactBatchByIds(ids));
    }
}
