package com.ruoyi.group.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.group.domain.dto.CustGroupMemberQueryDTO;
import com.ruoyi.group.domain.vo.CustGroupMemberVO;
import com.ruoyi.group.service.ICustGroupMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客群客户Controller
 *
 * @author ruoyi
 */
@Api(tags = "客群客户接口")
@RestController
@RequestMapping("/group/member")
public class CustGroupMemberController extends BaseController {

    @Resource
    private ICustGroupMemberService custGroupMemberService;

    /**
     * 分页查询客群客户列表
     */
    @ApiOperation("分页查询客群客户列表")
    @Log(title = "客群客户-查询客户列表")
    @GetMapping("/list/{groupId}")
    public TableDataInfo listCustGroupMembers(@PathVariable Long groupId,
                                              CustGroupMemberQueryDTO dto) {
        // 注意：startPage()在Service内部调用，因为权限检查会先执行SQL导致分页失效
        List<CustGroupMemberVO> list = custGroupMemberService.listCustGroupMembers(groupId, dto);
        return getDataTable(list);
    }

    /**
     * 手动移除客群客户
     */
    @ApiOperation("手动移除客群客户")
    @Log(title = "客群客户-手动移除客户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult removeMembers(@RequestParam Long groupId, @RequestBody List<Long> memberIds) {
        String result = custGroupMemberService.removeMembers(groupId, memberIds);
        return AjaxResult.success(result);
    }
}
