2025-02-27 16:26:02 +08:00
|
|
|
package com.ff.agent.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.ff.agent.dto.AgentCreateTenantDTO;
|
2025-04-11 14:39:54 +08:00
|
|
|
import com.ff.agent.dto.AgentTenantSecretKeyDTO;
|
2025-02-27 16:26:02 +08:00
|
|
|
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;
|
2025-03-24 17:52:01 +08:00
|
|
|
import com.ff.base.exception.base.BaseException;
|
2025-02-27 16:26:02 +08:00
|
|
|
import com.ff.base.system.domain.TenantPlatform;
|
2025-04-11 14:39:54 +08:00
|
|
|
import com.ff.base.system.domain.TenantSecretKey;
|
2025-02-27 16:26:02 +08:00
|
|
|
import com.ff.base.system.dto.CreateTenantDTO;
|
|
|
|
import com.ff.base.system.dto.TenantSecretKeyDTO;
|
2025-04-11 14:39:54 +08:00
|
|
|
import com.ff.base.system.service.ITenantPlatformService;
|
|
|
|
import com.ff.base.system.service.ITenantSecretKeyService;
|
2025-02-27 16:26:02 +08:00
|
|
|
import com.ff.base.utils.DateUtils;
|
|
|
|
import com.ff.base.utils.bean.BeanUtils;
|
|
|
|
import com.ff.base.utils.ip.IpUtils;
|
|
|
|
import com.ff.common.domain.TenantAgentPlatform;
|
|
|
|
import com.ff.common.dto.BalanceChangesDTO;
|
2025-04-12 14:35:41 +08:00
|
|
|
import com.ff.tenant.service.ITenantAgentPlatformService;
|
|
|
|
import com.ff.tenant.service.ITenantGameQuotaBiz;
|
|
|
|
import com.ff.tenant.service.ITenantGameQuotaService;
|
2025-02-27 16:26:02 +08:00
|
|
|
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;
|
2025-04-12 14:35:41 +08:00
|
|
|
|
|
|
|
@Resource
|
|
|
|
private ITenantGameQuotaBiz tenantGameQuotaBiz;
|
2025-03-24 17:36:42 +08:00
|
|
|
@Resource
|
|
|
|
private ITenantPlatformService tenantPlatformService;
|
2025-02-27 16:26:02 +08:00
|
|
|
|
2025-03-24 17:52:01 +08:00
|
|
|
@Resource
|
|
|
|
private ITenantAgentPlatformService tenantAgentPlatformService;
|
2025-04-11 14:39:54 +08:00
|
|
|
|
2025-02-27 16:26:02 +08:00
|
|
|
/**
|
|
|
|
* 列表
|
|
|
|
*
|
|
|
|
* @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);
|
2025-03-24 17:36:42 +08:00
|
|
|
agentTenantSecretKeyDTO.setTenantPlatforms(tenantPlatformService.selectTenantPlatformList(TenantPlatform.builder()
|
2025-04-11 14:39:54 +08:00
|
|
|
.tenantId(row.getId())
|
2025-03-24 17:36:42 +08:00
|
|
|
.build()));
|
2025-02-27 16:26:02 +08:00
|
|
|
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()) {
|
2025-03-24 17:52:01 +08:00
|
|
|
TenantAgentPlatform agentPlatform = tenantAgentPlatformService.selectTenantAgentPlatformById(tenantAgentPlatform.getId());
|
|
|
|
// 成本比平台成本大
|
2025-04-11 14:39:54 +08:00
|
|
|
if (agentPlatform.getCost().compareTo(tenantAgentPlatform.getCost()) > 0) {
|
2025-03-24 17:52:01 +08:00
|
|
|
throw new BaseException("成本比例不允许比最低比例小");
|
|
|
|
}
|
2025-02-27 16:26:02 +08:00
|
|
|
TenantPlatform tenantPlatform = new TenantPlatform();
|
|
|
|
BeanUtils.copyProperties(tenantAgentPlatform, tenantPlatform);
|
|
|
|
tenantPlatforms.add(tenantPlatform);
|
2025-03-24 17:36:42 +08:00
|
|
|
|
2025-02-27 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//创建租户
|
|
|
|
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())) {
|
2025-04-12 14:35:41 +08:00
|
|
|
tenantGameQuotaBiz.balanceChanges(BalanceChangesDTO.builder()
|
2025-02-27 16:26:02 +08:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|