后台-赠送钻石水晶-按用户角色每月限制赠送金币数

This commit is contained in:
khalil
2025-07-16 18:41:32 +08:00
parent 788c0b7601
commit 89b3dc953e
7 changed files with 123 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import com.accompany.admin.vo.OfficialGoldRecordVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -50,4 +51,9 @@ public interface OfficialGoldRecordMapperExpand {
int getOfficialGoldRecordCount(@Param("record") Map record); int getOfficialGoldRecordCount(@Param("record") Map record);
long getTotalNum(@Param("record") Map record); long getTotalNum(@Param("record") Map record);
BigDecimal getTotalAmountByAdminId(@Param("`type`") Byte type,
@Param("adminId") Integer adminId,
@Param("startTime") Date startTime,
@Param("endTime") Date endTime);
} }

View File

@@ -84,6 +84,8 @@ public class OfficialGoldRecordService extends BaseService {
private EnterpriseWeChatPushAdminService enterpriseWeChatPushAdminService; private EnterpriseWeChatPushAdminService enterpriseWeChatPushAdminService;
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired
private OfficialGoldRoleLimitService officialGoldRoleLimitService;
/** /**
* 后台赠送金币、萝卜 * 后台赠送金币、萝卜
@@ -91,31 +93,31 @@ public class OfficialGoldRecordService extends BaseService {
* @param ernos * @param ernos
* @param type * @param type
* @param num * @param num
* @param optId * @param adminId
* @param actualAmount * @param actualAmount
* @param remark * @param remark
* @return * @return
* @throws Exception * @throws Exception
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void handle(String ernos, OfficalSendTypeEnum type, BigDecimal num, int optId, public void handle(String ernos, OfficalSendTypeEnum type, BigDecimal num, int adminId,
BigDecimal actualAmount, String remark, Integer busType) throws Exception { BigDecimal actualAmount, String remark, Integer busType) throws Exception {
if (type == null) { if (type == null) {
throw new AdminServiceException(BusiStatus.REQUEST_PARAM_ERROR); throw new AdminServiceException(BusiStatus.REQUEST_PARAM_ERROR);
} }
switch (type){ switch (type){
case OFFICAL_GOLD: case OFFICAL_GOLD:
giveGold(ernos, type.getValue(), num, optId, remark, busType); giveGold(ernos, type.getValue(), num, adminId, remark, busType);
break; break;
case OFFICAL_DIAMOND: case OFFICAL_DIAMOND:
case COMPANY_ACCOUNT_DIAMOND: case COMPANY_ACCOUNT_DIAMOND:
giveDiamond(ernos, type.getValue(), num, optId, actualAmount, remark, busType); giveDiamond(ernos, type.getValue(), num, adminId, actualAmount, remark, busType);
break; break;
//case OFFICAL_RADISH: //case OFFICAL_RADISH:
// giveCrystal(ernos, type.getValue(), num, optId, remark, busType); // giveCrystal(ernos, type.getValue(), num, adminId, remark, busType);
// return BusiResult.success(); // return BusiResult.success();
case OFFICAL_REDUCE_DIAMONDS: case OFFICAL_REDUCE_DIAMONDS:
reduceDiamondNum(ernos, type.getValue(), num, optId, remark, busType); reduceDiamondNum(ernos, type.getValue(), num, adminId, remark, busType);
break; break;
default: default:
throw new AdminServiceException(BusiStatus.REQUEST_PARAM_ERROR); throw new AdminServiceException(BusiStatus.REQUEST_PARAM_ERROR);
@@ -156,7 +158,7 @@ public class OfficialGoldRecordService extends BaseService {
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void giveDiamond(String ernos, byte type, BigDecimal num, int optId, BigDecimal actualAmount, String remark, Integer busType) { public void giveDiamond(String ernos, byte type, BigDecimal num, int adminId, BigDecimal actualAmount, String remark, Integer busType) {
String lockval = null; String lockval = null;
try { try {
lockval = this.jedisLockService.lock(RedisKey.lock_official_gold_send.getKey(), 3000); lockval = this.jedisLockService.lock(RedisKey.lock_official_gold_send.getKey(), 3000);
@@ -166,6 +168,11 @@ public class OfficialGoldRecordService extends BaseService {
OfficalSendTypeEnum typeEnum = OfficalSendTypeEnum.get(type); OfficalSendTypeEnum typeEnum = OfficalSendTypeEnum.get(type);
if (OfficalSendTypeEnum.OFFICAL_DIAMOND.equals(typeEnum)
&& officialGoldRoleLimitService.overLimit(adminId)){
throw new AdminServiceException("本月的金币打款已经封顶");
}
// 根据配置,发送微信提示消息 // 根据配置,发送微信提示消息
List<String> erbanNos = Arrays.asList(ernos.trim().split("\n")); List<String> erbanNos = Arrays.asList(ernos.trim().split("\n"));
Map<Long, Users> usersMap = erbanNos.parallelStream().map(Long::parseLong).distinct() Map<Long, Users> usersMap = erbanNos.parallelStream().map(Long::parseLong).distinct()
@@ -177,13 +184,13 @@ public class OfficialGoldRecordService extends BaseService {
return u; return u;
}) })
.collect(Collectors.toMap(Users::getErbanNo, u->u)); .collect(Collectors.toMap(Users::getErbanNo, u->u));
List<Integer> partitionIds = usersMap.values().stream().map(Users::getPartitionId).distinct().collect(Collectors.toList()); List<Integer> partitionIds = usersMap.values().stream().map(Users::getPartitionId).distinct().toList();
if (partitionIds.size() > 1){ if (partitionIds.size() > 1){
throw new ServiceException(BusiStatus.PARTITION_ERROR, "分区不一致"); throw new ServiceException(BusiStatus.PARTITION_ERROR, "分区不一致");
} }
Integer partitionId = partitionIds.get(0); Integer partitionId = partitionIds.get(0);
enterpriseWeChatPushAdminService.pushMessage(usersMap, partitionId, null == typeEnum? "官方赠送金币": typeEnum.getDesc(), optId, num, remark); enterpriseWeChatPushAdminService.pushMessage(usersMap, partitionId, typeEnum.getDesc(), adminId, num, remark);
// officialGoldSendMsg(ernos,num,optId,remark); // officialGoldSendMsg(ernos,num,optId,remark);
// AdminDict adminDict = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_time"); // AdminDict adminDict = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_time");
@@ -202,7 +209,7 @@ public class OfficialGoldRecordService extends BaseService {
long recordId = DefaultIdentifierGenerator.getInstance().nextId(null); long recordId = DefaultIdentifierGenerator.getInstance().nextId(null);
String recordIdStr = String.valueOf(recordId); String recordIdStr = String.valueOf(recordId);
addGoldRecord(recordId, users, type, Constant.WalletCurrencyType.diamonds, num, optId, remark, busType, actualAmount); addGoldRecord(recordId, users, type, Constant.WalletCurrencyType.diamonds, num, adminId, remark, busType, actualAmount);
BillObjTypeEnum billObjTypeEnum = Constant.BillType.chargeByCompanyAccount.byteValue() == type? BillObjTypeEnum.CHARGE_BY_COMPANY_ACCOUNT: BillObjTypeEnum.OFFICIAL_GOLD_ADD; BillObjTypeEnum billObjTypeEnum = Constant.BillType.chargeByCompanyAccount.byteValue() == type? BillObjTypeEnum.CHARGE_BY_COMPANY_ACCOUNT: BillObjTypeEnum.OFFICIAL_GOLD_ADD;

View File

@@ -0,0 +1,74 @@
package com.accompany.admin.service.record;
import com.accompany.admin.mapper.OfficialGoldRecordMapperExpand;
import com.accompany.admin.model.AdminRefUserRoleKey;
import com.accompany.admin.service.system.AdminRoleService;
import com.accompany.business.dto.OfficialGoldRoleLimitServiceConfigDto;
import com.accompany.common.constant.Constant;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.exception.AdminServiceException;
import com.accompany.core.service.SysConfService;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class OfficialGoldRoleLimitService {
@Autowired
private SysConfService sysConfService;
@Autowired
private AdminRoleService adminRoleService;
@Autowired
private OfficialGoldRecordMapperExpand recordMapperExpand;
public boolean overLimit(int adminId){
OfficialGoldRoleLimitServiceConfigDto config = getConfig();
List<AdminRefUserRoleKey> roleKeyList = adminRoleService.getRoleByAdminId(adminId);
if (CollectionUtils.isEmpty(roleKeyList)){
throw new AdminServiceException("找不到用户角色");
}
List<Integer> roleIdList = roleKeyList.stream().map(AdminRefUserRoleKey::getRoleId).toList();
if (config.getRoleMonthlyLimitMap().keySet().stream().noneMatch(roleIdList::contains)){
return false;
}
BigDecimal minLimit = roleIdList.stream().filter(config.getRoleMonthlyLimitMap()::containsKey)
.map(config.getRoleMonthlyLimitMap()::get).min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
if (minLimit.equals(BigDecimal.ZERO)){
return false;
}
Date now = new Date();
Date monthStartTime = DateTimeUtil.getBeginTimeOfMonth(now);
Date monthEndTime = DateTimeUtil.getEndTimeOfMonth(now);
BigDecimal totalAmount = recordMapperExpand.getTotalAmountByAdminId(Constant.BillType.interSendDiamond.byteValue(), adminId, monthStartTime, monthEndTime);
if (null == totalAmount || totalAmount.compareTo(minLimit) < 0){
return false;
}
log.info("用户{} 的 {} 月打金币金额 {} 高于限制", adminId, totalAmount, minLimit);
return true;
}
private OfficialGoldRoleLimitServiceConfigDto getConfig(){
String configStr = sysConfService.getSysConfValueById(Constant.SysConfId.OFFICIAL_GOLD_ROLE_LIMIT_CONFIG);
if (!StringUtils.hasText(configStr)){
throw new AdminServiceException(BusiStatus.ALREADY_NOTEXISTS_CONFIG);
}
return JSON.parseObject(configStr, OfficialGoldRoleLimitServiceConfigDto.class);
}
}

View File

@@ -213,4 +213,12 @@
</where> </where>
</select> </select>
<select id="getTotalAmountByAdminId" resultType="java.math.BigDecimal">
select sum(gold_num) from official_gold_record r
where 1=1
and r.create_time between #{startTime} and #{endTime}
and r.type = #{type}
and r.operator_id = #{adminId}
</select>
</mapper> </mapper>

View File

@@ -70,8 +70,9 @@ public class GoldCoinController extends BaseController {
if (BlankUtil.isBlank(ernos) || num.compareTo(BigDecimal.ZERO) <= 0) { if (BlankUtil.isBlank(ernos) || num.compareTo(BigDecimal.ZERO) <= 0) {
throw new ServiceException(BusiStatus.PARAMETERILLEGAL); throw new ServiceException(BusiStatus.PARAMETERILLEGAL);
} }
officialGoldRecordService.handle(ernos, type, num, getAdminId(), actualAmount, remark, busType); int adminId = getAdminId();
adminLogService.insertLog(getAdminId(), getClass().getCanonicalName(), "giveGoldCoin" officialGoldRecordService.handle(ernos, type, num, adminId, actualAmount, remark, busType);
adminLogService.insertLog(adminId, getClass().getCanonicalName(), "giveGoldCoin"
, "params===>>ernos:" + ernos + ", type:" + type + ", num:" + num + ", actualAmount:" + actualAmount , "params===>>ernos:" + ernos + ", type:" + type + ", num:" + num + ", actualAmount:" + actualAmount
+ ", remark:" + remark); + ", remark:" + remark);
return BusiResult.success(); return BusiResult.success();

View File

@@ -1449,6 +1449,8 @@ public class Constant {
public static final String FIRST_CHARGE_BANNER_CONFIG = "first_charge_banner_config"; public static final String FIRST_CHARGE_BANNER_CONFIG = "first_charge_banner_config";
public static final String GUILD_USD_TO_RECHARGE_USER_LIMIT_CONFIG = "guild_usd_to_recharge_user_limit_config"; public static final String GUILD_USD_TO_RECHARGE_USER_LIMIT_CONFIG = "guild_usd_to_recharge_user_limit_config";
public static final String OFFICIAL_GOLD_ROLE_LIMIT_CONFIG = "official_gold_role_limit_config";
} }
public static class WithDrawStatus { public static class WithDrawStatus {

View File

@@ -0,0 +1,13 @@
package com.accompany.business.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Map;
@Data
public class OfficialGoldRoleLimitServiceConfigDto {
private Map<Integer, BigDecimal> roleMonthlyLimitMap;
}