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.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.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwGroupMsgUser;
import com.fs.qw.service.IQwGroupMsgUserService;
import com.fs.qw.vo.QwGroupMsgDetailsVO;
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-06-20
 */
@RestController
@RequestMapping("/qw/groupMsgUser")
public class QwGroupMsgUserController extends BaseController
{
    @Autowired
    private IQwGroupMsgUserService qwGroupMsgUserService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询群发成员发送任务及执行结果反馈记录列表
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwGroupMsgUser qwGroupMsgUser)
    {
        startPage();
        List<QwGroupMsgUser> list = qwGroupMsgUserService.selectQwGroupMsgUserList(qwGroupMsgUser);
        return getDataTable(list);
    }

    /**
     * 导出群发成员发送任务及执行结果反馈记录列表
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:export')")
    @Log(title = "群发成员发送任务及执行结果反馈记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwGroupMsgUser qwGroupMsgUser)
    {
        List<QwGroupMsgUser> list = qwGroupMsgUserService.selectQwGroupMsgUserList(qwGroupMsgUser);
        ExcelUtil<QwGroupMsgUser> util = new ExcelUtil<QwGroupMsgUser>(QwGroupMsgUser.class);
        return util.exportExcel(list, "群发成员发送任务及执行结果反馈记录数据");
    }

    /**
     * 获取群发成员发送任务及执行结果反馈记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwGroupMsgUserService.selectQwGroupMsgUserById(id));
    }

    /**
     * 新增群发成员发送任务及执行结果反馈记录
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:add')")
    @Log(title = "群发成员发送任务及执行结果反馈记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwGroupMsgUser qwGroupMsgUser)
    {
        return toAjax(qwGroupMsgUserService.insertQwGroupMsgUser(qwGroupMsgUser));
    }

    /**
     * 修改群发成员发送任务及执行结果反馈记录
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:edit')")
    @Log(title = "群发成员发送任务及执行结果反馈记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwGroupMsgUser qwGroupMsgUser)
    {
        return toAjax(qwGroupMsgUserService.updateQwGroupMsgUser(qwGroupMsgUser));
    }

    /**
     * 删除群发成员发送任务及执行结果反馈记录
     */
    @PreAuthorize("@ss.hasPermi('qw:groupMsgUser:remove')")
    @Log(title = "群发成员发送任务及执行结果反馈记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwGroupMsgUserService.deleteQwGroupMsgUserByIds(ids));
    }

    /** 刷新/同步 客户群群发 结果 */
    @PostMapping("/refreshResultsGroupMsgUser")
    public R refreshResultsGroupMsgUser(@RequestBody List<QwGroupMsgDetailsVO> list){


        return  qwGroupMsgUserService.refreshResultsGroupMsgUser(list);
    }

    /** 刷新/同步 客户群发 结果 */
    @PostMapping("/refreshResultsMsgUser")
    public R refreshResultsMsgUser(@RequestBody List<QwGroupMsgDetailsVO> list,String corpId){
        QwGroupMsgDetailsVO qwGroupMsgDetailsVO = list.get(0);
        return  qwGroupMsgUserService.refreshResultsMsgUser(list,qwGroupMsgDetailsVO.getCorpId() );
    }
}
