game-api/ff-game/src/main/java/com/ff/agent/controller/AgentController.java

143 lines
5.1 KiB
Java
Raw Normal View History

package com.ff.agent.controller;
import
com.ff.agent.dto.AgentTenantSecretKeyDTO;
import com.ff.agent.dto.AgentCreateTenantDTO;
import com.ff.base.constant.Constants;
import com.ff.base.core.controller.BaseController;
import com.ff.base.core.domain.AjaxResult;
import com.ff.base.core.page.TableDataInfo;
import com.ff.base.enums.OperationType;
import com.ff.base.enums.QuotaType;
import com.ff.base.system.domain.TenantPlatform;
import com.ff.base.system.dto.CreateTenantDTO;
import com.ff.base.system.dto.TenantSecretKeyDTO;
import com.ff.base.system.service.ISysDeptService;
import com.ff.base.system.service.ISysRoleService;
import com.ff.base.system.service.ISysUserService;
import com.ff.base.utils.DateUtils;
import com.ff.base.utils.bean.BeanUtils;
import com.ff.base.utils.ip.IpUtils;
import com.ff.base.system.domain.TenantSecretKey;
import com.ff.common.domain.TenantAgentPlatform;
import com.ff.common.dto.BalanceChangesDTO;
import com.ff.common.service.ITenantGameQuotaService;
import com.ff.base.system.service.ITenantSecretKeyService;
import com.ff.base.system.service.ITenantPlatformService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* api
*
* @author shi
* @date 2025/02/10
*/
@RestController
@RequestMapping("/agent/tenant")
@Slf4j
public class AgentController extends BaseController {
@Resource
private ITenantSecretKeyService tenantSecretKeyService;
@Resource
private ITenantGameQuotaService tenantGameQuotaService;
@Resource
private ITenantPlatformService tenantPlatformService;
/**
*
*
* @param tenantSecretKeyDTO
* @return {@link TableDataInfo }
*/
@GetMapping("/list")
@Transactional
@PreAuthorize("@ss.hasPermi('agent:tenant:list')")
public TableDataInfo list(TenantSecretKeyDTO tenantSecretKeyDTO) {
startPage();
tenantSecretKeyDTO.setAgentId(getUserId());
List<TenantSecretKey> tenantSecretKeys = tenantSecretKeyService.selectTenantSecretKeyDTOList(tenantSecretKeyDTO);
TableDataInfo dataTable = getDataTable(tenantSecretKeys);
List<AgentTenantSecretKeyDTO> list = new ArrayList<>();
for (TenantSecretKey row : (List<TenantSecretKey>) dataTable.getRows()) {
AgentTenantSecretKeyDTO agentTenantSecretKeyDTO = new AgentTenantSecretKeyDTO();
BeanUtils.copyProperties(row, agentTenantSecretKeyDTO);
agentTenantSecretKeyDTO.setTenantPlatforms(tenantPlatformService.selectTenantPlatformList(TenantPlatform.builder()
.tenantId(row.getId())
.build()));
list.add(agentTenantSecretKeyDTO);
}
dataTable.setRows(list);
return dataTable;
}
/**
*
*
* @return {@link AjaxResult }
*/
@PostMapping("/create")
@Transactional
@PreAuthorize("@ss.hasPermi('agent:tenant:create')")
public AjaxResult createTenant(@Validated @RequestBody AgentCreateTenantDTO agentCreateTenantDTO) {
//构造租户的充值信息
List<TenantPlatform> tenantPlatforms = new ArrayList<>();
for (TenantAgentPlatform tenantAgentPlatform : agentCreateTenantDTO.getTenantAgentPlatforms()) {
TenantPlatform tenantPlatform = new TenantPlatform();
BeanUtils.copyProperties(tenantAgentPlatform, tenantPlatform);
tenantPlatforms.add(tenantPlatform);
}
//创建租户
Integer tenant = tenantSecretKeyService.createTenant(CreateTenantDTO.builder()
.registerTime(DateUtils.getNowDate())
.registerIp(IpUtils.getIpAddr())
.agentId(getUserId())
.account(agentCreateTenantDTO.getAccount())
.password(agentCreateTenantDTO.getPassword())
.scoreRatio(agentCreateTenantDTO.getScoreRatio())
.tenantType(agentCreateTenantDTO.getTenantType())
.depositRatio(agentCreateTenantDTO.getDepositRatio())
.tenantPlatforms(tenantPlatforms)
.build());
if (tenant > 0) {
//信誉额度
if (!ObjectUtils.isEmpty(agentCreateTenantDTO.getRealBalance())) {
tenantGameQuotaService.balanceChanges(BalanceChangesDTO.builder()
.isOut(Boolean.TRUE)
.currencyCode(Constants.USDT)
.tenantKey(agentCreateTenantDTO.getAccount())
.balance(agentCreateTenantDTO.getRealBalance())
.operationType(OperationType.TENANT_RECHARGE.getCode())
.quotaType(QuotaType.REPUTATION.getCode())
.remark(OperationType.TENANT_RECHARGE.getDescription())
.build());
}
}
return toAjax(tenant);
}
}