package com.zanxiang.game.data.serve.controller;

import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.data.serve.pojo.dto.*;
import com.zanxiang.game.data.serve.service.IRoleManageService;
import com.zanxiang.game.data.serve.utils.Page;
import com.zanxiang.game.module.base.ServerInfo;
import com.zanxiang.game.module.base.pojo.vo.SendMsgResultVO;
import com.zanxiang.game.module.base.pojo.vo.SendMsgVO;
import com.zanxiang.game.module.base.rpc.ICPSendMsgRpc;
import com.zanxiang.module.util.pojo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author tianhua
 * @time 2023/9/8
 * @Description  角色运营管理控制层接口
 **/
@Api(tags = "角色运营管理")
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleManageController {

    @Autowired
    private IRoleManageService roleManageService;
    @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
    private ICPSendMsgRpc sendMsgRpc;


    @ApiOperation(value = "角色充值排行榜")
    @PreAuthorize(permissionKey = "roleManage:recharge:role")
    @PostMapping("/rechargeRanking")
    public ResultVO<Page<Map>> getRoleRechargeRanking(@RequestBody RoleRechargeRankingDTO dto) {
        return ResultVO.ok(roleManageService.getRoleRechargeRanking(dto));
    }

    @ApiOperation(value = "角色战力排行榜")
    @PreAuthorize(permissionKey = "roleManage:combat:role")
    @PostMapping("/combatRanking")
    public ResultVO<Page<Map>> getRoleCombatRanking(@RequestBody RoleCombatRankingDTO dto) {
        return ResultVO.ok(roleManageService.getRoleCombatRanking(dto));
    }

    @ApiOperation(value = "创建发送消息任务")
    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:create")
    @PostMapping("/sendMsgTask")
    public ResultVO createSendMsgTask(@RequestBody @Valid SendMsgTaskDTO dto) {
        roleManageService.createSendMsgTask(dto);
        return ResultVO.ok("操作成功", true);
    }

    @ApiOperation(value = "查询发送消息任务列表")
    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:list")
    @PostMapping("/sendMsgTask/list")
    public ResultVO<Page<SendMsgVO>> getSendMsgTaskList(@RequestBody MsgTaskDTO dto) {
        return ResultVO.ok(roleManageService.getSendMsgTaskList(dto));
    }


    @ApiOperation(value = "查询发送消息任务结果")
    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:resultList")
    @PostMapping("/sendMsgTask/resultList")
    public ResultVO<Page<SendMsgResultVO>> getSendMsgResultList(@RequestBody @Valid MsgTaskResultDTO msgTaskResultDto) {
        return ResultVO.ok(roleManageService.getSendMsgResultList(msgTaskResultDto));
    }

    @ApiOperation(value = "根据任务id重发消息")
    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:reSendMsgByTaskId")
    @PostMapping("/reSendMsgByTaskId")
    public ResultVO<Boolean> reSendMsgByTaskId(@RequestParam("gameId") Long gameId,@RequestParam("taskId") Long taskId) {
        return sendMsgRpc.reSendMsgByTaskId(gameId, taskId);
    }

    @ApiOperation(value = "根据发送结果id重发消息")
    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:reSendMsgByResultId")
    @PostMapping("/reSendMsgByResultId")
    public ResultVO<Boolean> reSendMsgByResultId(@RequestParam("resultId") Long resultId) {
        return sendMsgRpc.reSendMsgByResultId(resultId);
    }





}
