@@ -1,12 +1,10 @@
package com.accompany.admin.service.record ;
import cn.hutool.core.util.StrUtil ;
import com.accompany.admin.common.AdminConstants ;
import com.accompany.admin.mapper.OfficialGoldRecordMapper ;
import com.accompany.admin.mapper.OfficialGoldRecordMapperExpand ;
import com.accompany.admin.model.AdminUser ;
import com.accompany.admin.model.OfficialGoldRecord ;
import com.accompany.admin.service.push.EnterpriseWeChatPushAdminService ;
import com.accompany.admin.model.AdminUser ;
import com.accompany.admin.service.system.AdminUserService ;
import com.accompany.admin.vo.OfficialGoldAllRecordVo ;
import com.accompany.admin.vo.OfficialGoldRecordVo ;
@@ -15,20 +13,22 @@ import com.accompany.business.constant.guild.GuildUsdOperateTypeEnum;
import com.accompany.business.model.OfficialGoldBusType ;
import com.accompany.business.model.UserPurse ;
import com.accompany.business.model.guild.GuildMember ;
import com.accompany.business.service.WebConfigService ;
import com.accompany.business.service.guild.GuildMemberService ;
import com.accompany.business.service.guild.GuildUsdBillRecordService ;
import com.accompany.business.service.purse.UserPurseService ;
import com.accompany.business.service.record.BillRecordService ;
import com.accompany.business.service.user.UsersService ;
import com.accompany.business.vo.charge.CommonRecharge4ActVo ;
import com.accompany.common.config.WebSecurityConfig ;
import com.accompany.common.constant.AppEnum ;
import com.accompany.common.constant.Constant ;
import com.accompany.common.push.MarkdownMessage ;
import com.accompany.common.redis.RedisKey ;
import com.accompany.common.result.BusiResult ;
import com.accompany.common.result.PageResult ;
import com.accompany.common.status.BusiStatus ;
import com.accompany.common.utils.BlankUtil ;
import com.accompany.common.utils.DateTimeUtil ;
import com.accompany.common.utils.EnvComponent ;
import com.accompany.common.utils.StringUtils ;
import com.accompany.common.utils.UUIDUtil ;
import com.accompany.core.enumeration.BillObjTypeEnum ;
@@ -37,7 +37,7 @@ import com.accompany.core.exception.AdminServiceException;
import com.accompany.core.exception.ServiceException ;
import com.accompany.core.model.Users ;
import com.accompany.core.service.base.BaseService ;
import com.accompany.core.service.common.Jedis Service ;
import com.accompany.core.service.message.MessageRobotPush Service ;
import com.accompany.core.service.user.UsersBaseService ;
import com.accompany.payment.event.ChargeSuccessEvent ;
import com.accompany.payment.event.CommonRecharge4ActEvent ;
@@ -53,14 +53,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.Assert ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.stream.Collectors ;
import static com.accompany.common.status.BusiStatus.NOT_ENOUGH_GUILD_USD ;
@Service
public class OfficialGoldRecordService extends BaseService {
@@ -79,16 +77,8 @@ public class OfficialGoldRecordService extends BaseService {
@Autowired
private OfficialGoldRecordMapperExpand officialGoldRecordMapperExpand ;
@Autowired
private WebConfigService webConfigService ;
@Autowired
private AdminUserService adminUserService ;
@Autowired
private JedisService jedisService ;
@Autowired
private OfficialGoldBusTypeAdminService officialGoldBusTypeAdminService ;
@Autowired
private EnterpriseWeChatPushAdminService enterpriseWeChatPushAdminService ;
@Autowired
private ApplicationContext applicationContext ;
@Autowired
private OfficialGoldRoleLimitService officialGoldRoleLimitService ;
@@ -96,6 +86,14 @@ public class OfficialGoldRecordService extends BaseService {
private GuildMemberService guildMemberService ;
@Autowired
private GuildUsdBillRecordService guildUsdBillRecordService ;
@Autowired
private AdminUserService adminUserService ;
@Autowired
private WebSecurityConfig webSecurityConfig ;
@Autowired
private EnvComponent envComponent ;
@Autowired
private MessageRobotPushService messageRobotPushService ;
public List < Map < String , Object > > listType ( int adminId ) {
boolean hasLimit = officialGoldRoleLimitService . hasLimit ( adminId ) ;
@@ -117,60 +115,179 @@ public class OfficialGoldRecordService extends BaseService {
* 后台赠送金币、萝卜
*
* @param ernos
* @param type
* @param typeEnum
* @param num
* @param adminId
* @param actualAmount
* @param remark
* @return
* @throws Exception
*/
@Transactional ( rollbackFor = Exception . class )
public void handle ( String ernos , OfficalSendTypeEnum type , BigDecimal num , int adminId ,
BigDecimal actualAmount , String remark , Integer busType ) throws Exception {
if ( type = = null ) {
public void handle ( String ernos , OfficalSendTypeEnum typeEnum , BigDecimal num , int adminId ,
String remark , Integer busType ) {
if ( typeEnum = = null ) {
throw new AdminServiceException ( BusiStatus . REQUEST_PARAM_ERROR ) ;
}
if ( ! OfficalSendTypeEnum . OFFICAL_DIAMOND . equals ( type ) & & officialGoldRoleLimitService . hasLimit ( adminId ) ) {
if ( ! OfficalSendTypeEnum . OFFICAL_DIAMOND . equals ( typeEnum ) & & officialGoldRoleLimitService . hasLimit ( adminId ) ) {
throw new AdminServiceException ( BusiStatus . PARAMETERILLEGAL ) ;
}
switch ( type ) {
case OFFICAL_GOLD :
giveGold ( ernos , type . getValue ( ) , num , adminId , remark , busType ) ;
break ;
case OFFICAL_DIAMOND :
case COMPANY_ACCOUNT_DIAMOND :
giveDiamond ( ernos , type . getValue ( ) , num , adminId , actualAmount , remark , busType ) ;
break ;
//case OFFICAL_RADISH:
// giveCrystal(ernos, type.getValue(), num, adminId, remark, busType) ;
// return BusiResult.success();
case OFFICAL_REDUCE_DIAMONDS :
reduceDiamondNum ( ernos , type . getValue ( ) , num , adminId , remark , busType ) ;
b reak ;
case OFFICAL_MINUS_GUILD_USD :
adjustUsd ( ernos , type . getValue ( ) , num , adminId , remark , busType , Boolean . FALSE ) ;
break ;
case OFFICAL_PLUS_GUILD_USD :
adjustUsd ( ernos , type . getValue ( ) , num , adminId , remark , busType , Boolean . TRUE ) ;
break ;
case OFFICAL_PLUS_GUILD_CRYSTAL :
adjustGuildCrystal ( ernos , type . getValue ( ) , num , adminId , remark , busType , Boolean . TRUE ) ;
break ;
case OFFICAL_MINUS_GUILD_CRYSTAL :
adjustGuildCrystal ( ernos , type . getValue ( ) , num , adminId , remark , busType , Boolean . FALSE ) ;
break ;
default :
throw new AdminServiceException ( BusiStatus . REQUEST_PARAM_ERROR ) ;
if ( OfficalSendTypeEnum . OFFICAL_DIAMOND . equals ( typeEnum )
& & officialGoldRoleLimitService . overLimit ( adminId , num ) ) {
throw new AdminServiceException ( " 本月的金币打款已经封顶 " ) ;
}
// 提取用户查询和分区检查逻辑到统一位置
List < String > erbanNos = Arrays . asList ( ernos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , Users > usersMap = erbanNos . parallelStream ( ) . map ( Long : : parseLong ) . distinct ( )
. map ( erbanNo - > {
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
return u ;
} )
. collect ( Collectors . toMap ( Users : : getErbanNo , u - > u ) ) ;
List < Integer > partitionIds = usersMap . values ( ) . stream ( ) . map ( Users : : getPartitionId ) . distinct ( ) . toList ( ) ;
if ( partitionIds . size ( ) > 1 ) {
throw new ServiceException ( BusiStatus . PARTITION_ERROR , " 分区不一致 " ) ;
}
Integer partitionId = partitionIds . get ( 0 ) ;
BigDecimal actualAmount = num . divide ( typeEnum . getCurrencyType ( ) . getExchangeRate ( ) , 2 , RoundingMode . HALF_UP ) ;
// 统一获取锁
String lockval = null ;
try {
lockval = this . jedisLockService . lock ( RedisKey . lock_official_gold_send . getKey ( ) , 3000 ) ;
if ( StringUtils . isEmpty ( lockval ) ) {
throw new AdminServiceException ( BusiStatus . SERVERBUSY ) ;
}
// 统一发送微信提示消息
pushEnterpriseWeChatMessage ( usersMap , partitionId , typeEnum . getDesc ( ) , adminId , num , remark ) ;
switch ( typeEnum ) {
case OFFICAL_GOLD :
giveGold ( usersMap , typeEnum , num , adminId , remark , busType , actualAmount ) ;
break ;
case OFFICAL_DIAMOND :
case COMPANY_ACCOUNT_DIAMOND :
giveDiamond ( usersMap , typeEnum , num , adminId , remark , busType , actualAmount ) ;
break ;
case OFFICAL_REDUCE_DIAMONDS :
reduceDiamondNum ( usersMap , typeEnum , num , adminId , remark , busType , actualAmount ) ;
break ;
case OFFICAL_MINUS_GUILD_USD :
adjustUsd ( usersMap , typeEnum , num , adminId , remark , busType , Boolean . FALSE , actualAmount ) ;
break ;
case OFFICAL_PLUS_GUILD_USD :
adjustUsd ( usersMap , typeEnum , num , adminId , remark , busType , Boolean . TRUE , actualAmount ) ;
break ;
case OFFICAL_PLUS_GUILD_CRYSTAL :
adjustGuildCrystal ( usersMap , typeEnum , num , adminId , remark , busType , Boolean . TRUE , actualAmount ) ;
break ;
case OFFICAL_MINUS_GUILD_CRYSTAL :
adjustGuildCrystal ( usersMap , typeEnum , num , adminId , remark , busType , Boolean . FALSE , actualAmount ) ;
break ;
case CLEAR_USER_GOLD :
clearUserGold ( usersMap , num , adminId , actualAmount ) ;
break ;
default :
throw new AdminServiceException ( BusiStatus . REQUEST_PARAM_ERROR ) ;
}
} finally {
// 统一释放锁
if ( StringUtils . isNotEmpty ( lockval ) ) {
this . jedisLockService . unlock ( RedisKey . lock_official_gold_send . getKey ( ) , lockval ) ;
}
}
}
/**
* 赠送钻石
*
* @param usersMap 用户映射
* @param type 赠送类型
* @param num 赠送数量
* @return
*/
public void giveDiamond ( Map < Long , Users > usersMap , OfficalSendTypeEnum type , BigDecimal num , int adminId , String remark , Integer busType ,
BigDecimal actualAmount ) {
// AdminDict adminDict = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_time");
// AdminDict adminDict2 = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_count");
// int limitTime = Integer.valueOf(adminDict.getDictval());
// int limitCount = Integer.valueOf(adminDict2.getDictval());
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
// if (!isCanGiveGold(users, type, num, limitTime, limitCount)) {
// busiResult.setCode(-1);
// busiResult.setMessage("兔兔号为" + erNo + "的用户被赠送的次数大于" + limitTime + "或者金币余额大于" + limitCount);
// return busiResult;
// }
// 增加官方赠送活动记录
long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
addGoldRecord ( recordId , users , type . getValue ( ) , Constant . WalletCurrencyType . diamonds , num , adminId , remark , busType , actualAmount ) ;
BillObjTypeEnum billObjTypeEnum = Constant . OfficialType . chargeByCompanyAccount . byteValue ( ) = = type . getValue ( ) ? BillObjTypeEnum . CHARGE_BY_COMPANY_ACCOUNT : BillObjTypeEnum . OFFICIAL_GOLD_ADD ;
UserPurse after = userPurseService . addDiamond ( users . getUid ( ) , num . doubleValue ( ) , billObjTypeEnum ,
( userPurse ) - > billRecordService . insertGeneralBillRecord ( users . getUid ( ) , recordIdStr , billObjTypeEnum , num . doubleValue ( ) , userPurse ) ) ;
// 增加充值记录
if ( Constant . OfficialType . chargeByCompanyAccount . byteValue ( ) = = type . getValue ( ) ) {
BigDecimal amount = actualAmount . multiply ( Constant . HUNDRED ) ;
String chargeRecordId = UUIDUtil . get ( ) ;
addChargeRecord ( chargeRecordId , users . getUid ( ) , num . longValue ( ) , amount . longValue ( ) ) ;
this . applicationContext . publishEvent ( new CommonRecharge4ActEvent (
CommonRecharge4ActVo . builder ( )
. uid ( users . getUid ( ) )
. channel ( Constant . ChargeChannel . company )
. chargeStatus ( Constant . ChargeRecordStatus . finish )
. totalGoldNum ( num . longValue ( ) )
. createTime ( new Date ( ) ) . build ( ) ) ) ;
}
try {
userPurseService . sendSysMsgByModifyGold ( after ) ;
} catch ( Exception e ) {
logger . error ( " sendSysMsgByModifyGold error, uid: " + users . getUid ( ) , e ) ;
}
logger . info ( " giveGold success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type . getValue ( ) , num , recordId ) ;
}
}
/**
* 赠送金币
*
* @param usersMap 用户映射
* @param num 赠送数量
* @return
*/
@Transactional ( rollbackFor = Exception . class )
public void giveGold ( Map < Long , Users > usersMap , OfficalSendTypeEnum typeEnum , BigDecimal num , int optId , String remark , Integer busType ,
BigDecimal actualAmount ) {
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , typeEnum . getValue ( ) , Constant . WalletCurrencyType . gold , num , optId , remark , busType , actualAmount ) ;
// 更新账户钻石数量
userPurseService . addGold ( users . getUid ( ) , num . doubleValue ( ) , BillObjTypeEnum . INTER_SEND_DIAMOND ) ;
logger . info ( " giveGold success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , typeEnum . getValue ( ) , num , recordId ) ;
}
}
/**
* 官方消钻
*
* @param ernos
* @param usersMap 用户映射
* @param type
* @param num
* @param optId
@@ -180,166 +297,19 @@ public class OfficialGoldRecordService extends BaseService {
* @throws Exception
*/
@Transactional ( rollbackFor = Exception . class )
public void reduceDiamondNum ( String ernos , byte type , BigDecimal num , int optId , String remark , Integer busType ) {
Users user = usersBaseService . getUsersByErBanNo ( Long . valueOf ( ernos . trim ( ) ) ) ;
if ( user = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
public void reduceDiamondNum ( Map < Long , Users > usersMap , OfficalSendTypeEnum type , BigDecimal num , int optId , String remark , Integer busType , BigDecimal actualAmount ) {
for ( Users user : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
userPurseService . subDiamond ( user . getUid ( ) , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_GOLD_REDUCE ,
( userPurse ) - > billRecordService . insertGeneralBillRecord ( user . getUid ( ) , recordIdStr , BillObjTypeEnum . OFFICIAL_GOLD_REDUCE , num . doubleValue ( ) , userPurse ) ) ;
addGoldRecord ( recordId , user , type . getValue ( ) , Constant . WalletCurrencyType . diamonds , num , optId , remark , busType , actualAmount ) ;
}
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
userPurseService . subDiamond ( user . getUid ( ) , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_GOLD_REDUCE ,
( userPurse ) - > billRecordService . insertGeneralBillRecord ( user . getUid ( ) , recordIdStr , BillObjTypeEnum . OFFICIAL_GOLD_REDUCE , num . doubleValue ( ) , userPurse ) ) ;
addGoldRecord ( recordId , user , type , Constant . WalletCurrencyType . diamonds , num , optId , remark , busType , null ) ;
}
/**
* 赠送钻石
*
* @param ernos 耳伴号,多个耳伴号用换行符分隔
* @param type 赠送类型
* @param num 赠送数量
* @return
*/
public void giveDiamond ( String ernos , byte type , BigDecimal num , int adminId , BigDecimal actualAmount , String remark , Integer busType ) {
String lockval = null ;
try {
lockval = this . jedisLockService . lock ( RedisKey . lock_official_gold_send . getKey ( ) , 3000 ) ;
if ( StringUtils . isEmpty ( lockval ) ) {
throw new AdminServiceException ( BusiStatus . SERVERBUSY ) ;
}
OfficalSendTypeEnum typeEnum = OfficalSendTypeEnum . get ( type ) ;
if ( OfficalSendTypeEnum . OFFICAL_DIAMOND . equals ( typeEnum )
& & officialGoldRoleLimitService . overLimit ( adminId , num ) ) {
throw new AdminServiceException ( " 本月的金币打款已经封顶 " ) ;
}
// 根据配置,发送微信提示消息
List < String > erbanNos = Arrays . asList ( ernos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , Users > usersMap = erbanNos . parallelStream ( ) . map ( Long : : parseLong ) . distinct ( )
. map ( erbanNo - > {
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
return u ;
} )
. collect ( Collectors . toMap ( Users : : getErbanNo , u - > u ) ) ;
List < Integer > partitionIds = usersMap . values ( ) . stream ( ) . map ( Users : : getPartitionId ) . distinct ( ) . toList ( ) ;
if ( partitionIds . size ( ) > 1 ) {
throw new ServiceException ( BusiStatus . PARTITION_ERROR , " 分区不一致 " ) ;
}
Integer partitionId = partitionIds . get ( 0 ) ;
enterpriseWeChatPushAdminService . pushMessage ( usersMap , partitionId , typeEnum . getDesc ( ) , adminId , num , remark ) ;
// officialGoldSendMsg(ernos,num,optId,remark);
// AdminDict adminDict = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_time");
// AdminDict adminDict2 = adminDictService.getOneAdminDict("official_gold_limit_" + type, "limit_count");
// int limitTime = Integer.valueOf(adminDict.getDictval());
// int limitCount = Integer.valueOf(adminDict2.getDictval());
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
// if (!isCanGiveGold(users, type, num, limitTime, limitCount)) {
// busiResult.setCode(-1);
// busiResult.setMessage("兔兔号为" + erNo + "的用户被赠送的次数大于" + limitTime + "或者金币余额大于" + limitCount);
// return busiResult;
// }
// 增加官方赠送活动记录
long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
addGoldRecord ( recordId , users , type , Constant . WalletCurrencyType . diamonds , num , adminId , remark , busType , actualAmount ) ;
BillObjTypeEnum billObjTypeEnum = Constant . OfficialType . chargeByCompanyAccount . byteValue ( ) = = type ? BillObjTypeEnum . CHARGE_BY_COMPANY_ACCOUNT : BillObjTypeEnum . OFFICIAL_GOLD_ADD ;
UserPurse after = userPurseService . addDiamond ( users . getUid ( ) , num . doubleValue ( ) , billObjTypeEnum ,
( userPurse ) - > billRecordService . insertGeneralBillRecord ( users . getUid ( ) , recordIdStr , billObjTypeEnum , num . doubleValue ( ) , userPurse ) ) ;
// 增加充值记录
if ( Constant . OfficialType . chargeByCompanyAccount . byteValue ( ) = = type ) {
BigDecimal amount = actualAmount . multiply ( Constant . HUNDRED ) ;
String chargeRecordId = UUIDUtil . get ( ) ;
addChargeRecord ( chargeRecordId , users . getUid ( ) , num . longValue ( ) , amount . longValue ( ) ) ;
this . applicationContext . publishEvent ( new CommonRecharge4ActEvent (
CommonRecharge4ActVo . builder ( )
. uid ( users . getUid ( ) )
. channel ( Constant . ChargeChannel . company )
. chargeStatus ( Constant . ChargeRecordStatus . finish )
. totalGoldNum ( num . longValue ( ) )
. createTime ( new Date ( ) ) . build ( ) ) ) ;
}
try {
userPurseService . sendSysMsgByModifyGold ( after ) ;
} catch ( Exception e ) {
logger . error ( " sendSysMsgByModifyGold error, uid: " + users . getUid ( ) , e ) ;
}
logger . info ( " giveGold success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
}
} finally {
this . jedisLockService . unlock ( RedisKey . lock_official_gold_send . getKey ( ) , lockval ) ;
}
}
/**
* 赠送钻石
*
* @param ernos 耳伴号,多个耳伴号用换行符分隔
* @param type 赠送类型
* @param num 赠送数量
* @return
*/
@Transactional ( rollbackFor = Exception . class )
public void giveGold ( String ernos , byte type , BigDecimal num , int optId , String remark , Integer busType ) {
String lockval = null ;
try {
lockval = this . jedisLockService . lock ( RedisKey . lock_official_gold_send . getKey ( ) , 3000 ) ;
if ( StringUtils . isEmpty ( lockval ) ) {
throw new AdminServiceException ( BusiStatus . SERVERBUSY ) ;
}
// 根据配置,发送微信提示消息
List < String > erbanNos = Arrays . asList ( ernos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , Users > usersMap = erbanNos . parallelStream ( ) . map ( Long : : parseLong ) . distinct ( )
. map ( erbanNo - > {
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
return u ;
} )
. collect ( Collectors . toMap ( Users : : getErbanNo , u - > u ) ) ;
List < Integer > partitionIds = usersMap . values ( ) . stream ( ) . map ( Users : : getPartitionId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( partitionIds . size ( ) > 1 ) {
throw new ServiceException ( BusiStatus . PARTITION_ERROR , " 分区不一致 " ) ;
}
Integer partitionId = partitionIds . get ( 0 ) ;
enterpriseWeChatPushAdminService . pushMessage ( usersMap , partitionId , " 后台赠送金币 " , optId , num , remark ) ;
// officialGoldSendMsg(ernos,num,optId,remark);
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , type , Constant . WalletCurrencyType . gold , num , optId , remark , busType , null ) ;
// 更新账户钻石数量
userPurseService . addGold ( users . getUid ( ) , num . doubleValue ( ) , BillObjTypeEnum . INTER_SEND_DIAMOND ) ;
logger . info ( " giveGold success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
}
} finally {
this . jedisLockService . unlock ( RedisKey . lock_official_gold_send . getKey ( ) , lockval ) ;
}
}
/**
* 官方调整薪资(增加或减少)
* @param ernos 用户耳伴号列表,多个用换行分隔
* @param usersMap 用户映射
* @param type 操作类型
* @param num 调整数量
* @param optId 操作人ID
@@ -349,70 +319,47 @@ public class OfficialGoldRecordService extends BaseService {
* @throws Exception
*/
@Transactional ( rollbackFor = Exception . class )
public void adjustUsd ( String ernos , byte type , BigDecimal num , int optId , String remark , Integer busType , boolean isPlus ) {
String lockval = null ;
try {
lockval = this . jedisLockService . lock ( RedisKey . lock_official_gold_send . getKey ( ) , 3000 ) ;
if ( StringUtils . isEmpty ( lockval ) ) {
throw new AdminServiceException ( BusiStatus . SERVERBUSY ) ;
public void adjustUsd ( Map < Long , Users > usersMap , OfficalSendTypeEnum type , BigDecimal num , int optId , String remark , Integer busType , boolean isPlus , BigDecimal actualAmount ) {
Map < Long , GuildMember > guildMemberMap = new HashMap < > ( ) ;
for ( Users u : usersMap . values ( ) ) {
Long uid = u . getUid ( ) ;
GuildMember guildMemberByUid = guildMemberService . getVaildGuildMemberByUid ( uid ) ;
if ( guildMemberByUid = = null ) {
throw new AdminServiceException ( " ID: " + u . getErbanNo ( ) + " but not in guild, not allow operate " ) ;
}
guildMemberMap . put ( uid , guildMemberByUid ) ;
}
List < String > erbanNos = Arrays . asList ( ernos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , GuildMember > guildMemberMap = new HashMap < > ( ) ;
Map < Long, Users > usersMap = new HashMap < > ( ) ;
for ( String erbanNoStr : erbanNos ) {
Long erbanNo = Long . parseLong ( erbanNoStr . trim ( ) ) ;
if ( usersMap . containsKey ( erbanNo ) ) {
continue ;
}
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
Long uid = u . getUid ( ) ;
G uildMember guildMemberByUid = guildMemberService . getVaildGuildMemberByUid ( uid ) ;
if ( g uildMemberByUid = = null ) {
throw new AdminServiceException ( " ID: " + erbanNoStr + " but not in guild, not allow operate " ) ;
}
guildMemberMap . put ( uid , guildMemberByUid ) ;
usersMap . put ( uid , u ) ;
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
Long uid = users . getUid ( ) ;
GuildMember guildMember = guildMemberMap . get ( uid ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , type . getValue ( ) , Constant . WalletCurrencyType . guildUsd , num , optId , remark , busType , actualAmount ) ;
if ( isPlus ) {
// 增加账户usd数量
UserPurse userPurse = userPurseService . addGuildUsd ( uid , num . doubleValue ( ) , BillObjTypeEnum . PLUS_GUILD_USD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , uid , BillObjTypeEnum . PLUS_GUILD_USD , num . doubleValue ( ) , up ) ) ;
g uildUsdBillRecordService . insert ( UUIDUtil . get ( ) , guildMember . getPartitionId ( ) , guildMember . getId ( ) , guildMember . getGuildId ( ) , uid ,
guildMember . getId ( ) , uid , G uildUsdOperateTypeEnum . SYSTEM_PLUS_USD , null , userPurse , num , null , recordId , remark ) ;
logger . info ( " plusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type . getValue ( ) , num , recordId ) ;
} else {
// 减少账户usd数量
UserPurse userPurse = userPurseService . subGuildUsd ( uid , num , BillObjTypeEnum . MIUNS_GUILD_USD , BusiStatus . NOT_ENOUGH_GUILD_USD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , uid , BillObjTypeEnum . MIUNS_GUILD_USD , num . doubleValue ( ) , up ) ) ;
guildUsdBillRecordService . insert ( UUIDUtil . get ( ) , guildMember . getPartitionId ( ) , guildMember . getId ( ) , guildMember . getGuildId ( ) , uid ,
guildMember . getId ( ) , uid , GuildUsdOperateTypeEnum . SYSTEM_MIUNS_USD , userPurse , null , num , null , recordId , remark ) ;
logger . info ( " minusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type . getValue ( ) , num , recordId ) ;
}
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
Long uid = users . getUid ( ) ;
GuildMember guildMember = guildMemberMap . get ( uid ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , type , Constant . WalletCurrencyType . guildUsd , num , optId , remark , busType , null ) ;
if ( isPlus ) {
// 增加账户usd数量
UserPurse userPurse = userPurseService . addGuildUsd ( uid , num . doubleValue ( ) , BillObjTypeEnum . PLUS_GUILD_USD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , uid , BillObjTypeEnum . PLUS_GUILD_USD , num . doubleValue ( ) , up ) ) ;
guildUsdBillRecordService . insert ( UUIDUtil . get ( ) , guildMember . getPartitionId ( ) , guildMember . getId ( ) , guildMember . getGuildId ( ) , uid ,
guildMember . getId ( ) , uid , GuildUsdOperateTypeEnum . SYSTEM_PLUS_USD , null , userPurse , num , null , recordId , remark ) ;
logger . info ( " plusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
} else {
// 减少账户usd数量
UserPurse userPurse = userPurseService . subGuildUsd ( uid , num , BillObjTypeEnum . MIUNS_GUILD_USD , NOT_ENOUGH_GUILD_USD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , uid , BillObjTypeEnum . MIUNS_GUILD_USD , num . doubleValue ( ) , up ) ) ;
guildUsdBillRecordService . insert ( UUIDUtil . get ( ) , guildMember . getPartitionId ( ) , guildMember . getId ( ) , guildMember . getGuildId ( ) , uid ,
guildMember . getId ( ) , uid , GuildUsdOperateTypeEnum . SYSTEM_MIUNS_USD , userPurse , null , num , null , recordId , remark ) ;
logger . info ( " minusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
}
}
} finally {
this . jedisLockService . unlock ( RedisKey . lock_official_gold_send . getKey ( ) , lockval ) ;
}
}
/**
* 官方调整薪资 (增加或减少)
* @param ernos 用户耳伴号列表,多个用换行分隔
* 官方调整水晶 (增加或减少)
* @param usersMap 用户映射
* @param type 操作类型
* @param num 调整数量
* @param optId 操作人ID
@@ -422,53 +369,46 @@ public class OfficialGoldRecordService extends BaseService {
* @throws Exception
*/
@Transactional ( rollbackFor = Exception . class )
public void adjustGuildCrystal ( String ernos , byte type , BigDecimal num , int optId , String remark , Integer busType , boolean isPlus ) {
String lockval = null ;
try {
lockval = this . jedisLockService . lock ( RedisKey . lock_official_gold_send . getKey ( ) , 3000 ) ;
if ( StringUtils . isEmpty ( lockval ) ) {
throw new AdminServiceException ( BusiStatus . SERVERBUSY ) ;
public void adjustGuildCrystal ( Map < Long , Users > usersMap , OfficalSendTypeEnum type , BigDecimal num , int optId , String remark , Integer busType , boolean isPlus , BigDecimal actualAmount ) {
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
Long uid = users . getUid ( ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , type . getValue ( ) , Constant . WalletCurrencyType . guildCrystal , num , optId , remark , busType , actualAmount ) ;
if ( isPlus ) {
// 增加账户usd数量
userPurseService . addGuildCrystal ( uid , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_PLUS_GUILD_CRYSTAL ) ;
logger . info ( " plusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type . getValue ( ) , num , recordId ) ;
} else {
// 减少账户usd数量
userPurseService . subGuildCrystal ( uid , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_MIUNS_GUILD_CRYSTAL ) ;
logger . info ( " minusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type . getValue ( ) , num , recordId ) ;
}
}
}
List < String > erbanNos = Arrays . asList ( ernos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , Users > usersMap = new HashMap < > ( ) ;
for ( String erbanNoStr : erbanNos ) {
Long erbanNo = Long . parseLong ( erbanNoStr . trim ( ) ) ;
if ( usersMap . containsKey ( erbanNo ) ) {
continue ;
}
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
Long uid = u . getUid ( ) ;
usersMap . put ( uid , u ) ;
@Transactional ( rollbackFor = Exception . class )
public void clearUserGold ( Map < Long , Users > usersMap , BigDecimal num , Integer adminId , BigDecimal actualAmount ) {
for ( Users users: usersMap . values ( ) ) {
Long uid = users . getUid ( ) ;
UserPurse userPurse = userPurseService . queryUserPurse ( uid ) ;
BigDecimal golds = BigDecimal . valueOf ( userPurse . getGolds ( ) ) ;
if ( golds . compareTo ( num ) < 0 ) {
throw new AdminServiceException ( " [ " + users . getErbanNo ( ) + " ]的用户金币金额低于 " + num ) ;
}
// 分隔耳伴号,多个耳伴号用换行分隔
for ( Users users : usersMap . values ( ) ) {
Long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
Long uid = users . getUid ( ) ;
// 增加官方赠送活动记录
addGoldRecord ( recordId , users , type , Constant . WalletCurrencyType . guildCrystal , num , optId , remark , busType , null ) ;
if ( isPlus ) {
// 增加账户usd数量
userPurseService . addGuildCrystal ( uid , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_PLUS_GUILD_CRYSTAL ) ;
logger . info ( " plusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
} else {
// 减少账户usd数量
userPurseService . subGuildCrystal ( uid , num . doubleValue ( ) , BillObjTypeEnum . OFFICIAL_MIUNS_GUILD_CRYSTAL ) ;
logger . info ( " minusUsd success, erpan_no: {}, type: {}, num: {}, recordId: {} " , users . getErbanNo ( ) , type , num , recordId ) ;
}
}
} finally {
this . jedisLockService . unlock ( RedisKey . lock_official_gold_send . getKey ( ) , lockval ) ;
long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
//扣减金币
userPurse = userPurseService . subGold ( uid , num . doubleValue ( ) , BillObjTypeEnum . CLEAR_USER_GOLD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , recordIdStr , BillObjTypeEnum . CLEAR_USER_GOLD , num . doubleValue ( ) , up ) ) ;
//获取更新后的金额
BigDecimal currentGoldNum = BigDecimal . valueOf ( userPurse . getGolds ( ) ) ;
//增加官方操作记录
addOfficialGoldRecord ( recordId , uid , null , num , currentGoldNum , OfficalSendTypeEnum . CLEAR_USER_GOLD . getValue ( ) ,
Constant . WalletCurrencyType . gold , BillObjTypeEnum . CLEAR_USER_GOLD . getValue ( ) , adminId , BillObjTypeEnum . CLEAR_USER_GOLD . getDesc ( ) , actualAmount ) ;
}
}
@@ -652,110 +592,6 @@ public class OfficialGoldRecordService extends BaseService {
return data ;
}
/**
* 后台金币充值根据配置,发送微信消息
*
* @param ernos
* @param num
* @param optId
* @param remark
*/
public void officialGoldSendMsg ( String ernos , long num , int optId , String remark ) {
boolean flag = true ; //true为金额提示消息,false为笔数提示消息
String cusDate = DateTimeUtil . getTodayStr ( ) ;
Integer limitTime = Integer . valueOf ( webConfigService . getSingleConf ( AdminConstants . OFFICIAL_GOLD_LIMIT_TIME ) ) ;
Integer limitGold = Integer . valueOf ( webConfigService . getSingleConf ( AdminConstants . OFFICIAL_GOLD_LIMIT_GOLD ) ) ;
String openIds = webConfigService . getSingleConf ( AdminConstants . OFFICIAL_GOLD_NOTIFY_MEMBER ) ;
Assert . notNull ( openIds , " 通知的openIds不能为空 " ) ;
List < String > openIdList = Arrays . asList ( openIds . split ( " , " ) ) ;
//获取操作人名字
AdminUser user = adminUserService . getAdminUserById ( optId ) ;
Assert . notNull ( user , " 该操作人不存在! " ) ;
//当日累计一次
Double rechargeTime = jedisService . zincrby ( RedisKey . official_gold_limit_time . getKey ( ) , 1 . 0 , cusDate ) ;
//判断后台充值金额是否需要发送消息
if ( rechargeTime > = limitTime ) {
flag = false ;
}
//根据openId发送微信消息
boolean finalFlag = flag ;
if ( rechargeTime > = limitTime | | num > = limitGold ) {
openIdList . forEach ( ( openID ) - > {
sendMsg ( ernos , num , user . getUsername ( ) , remark , rechargeTime . intValue ( ) , finalFlag , openID ) ;
} ) ;
}
}
/**
* 发送微信消息
*
* @param ernos
* @param num
* @param optName
* @param remark
* @param countTime
* @param flag
* @param openId
*/
public void sendMsg ( String ernos , long num , String optName , String remark , int countTime , boolean flag , String openId ) {
String first = " 耳伴管理系统 " ;
String keyword1 = " 后台管理系统金币充值提醒 " ;
String keyword2 = " 充值人: " + optName + " ,充值: " + num + " 元,被充值人: " + ernos + " ,原因: " + remark + " ,当日累计笔数: " + countTime ;
String keyword3 = " 提醒类型: " ;
if ( flag ) {
keyword3 + = " 金额 " ;
} else {
keyword3 + = " 笔数 " ;
}
String keyword4 = " 充值时间: " + DateTimeUtil . convertDate ( new Date ( ) , " yyyy-MM-dd hh:mm " ) ;
//wxPubService.sendAlertMsg(openId,first,keyword1,keyword2,keyword3,keyword4,"");
}
@Transactional ( rollbackFor = Exception . class )
public void clearUserGold ( String erBanNos , BigDecimal num , Integer adminId ) {
if ( StrUtil . isEmpty ( erBanNos ) ) {
throw new AdminServiceException ( " ID不能为空 " ) ;
}
// 根据配置,发送微信提示消息
List < String > erbanNos = Arrays . asList ( erBanNos . trim ( ) . split ( " \ n " ) ) ;
Map < Long , Users > usersMap = erbanNos . parallelStream ( ) . map ( Long : : parseLong ) . distinct ( )
. map ( erbanNo - > {
Users u = usersService . getUserByErbanNo ( erbanNo ) ;
if ( u = = null ) {
throw new AdminServiceException ( BusiStatus . USERNOTEXISTS ) ;
}
return u ;
} )
. collect ( Collectors . toMap ( Users : : getErbanNo , u - > u ) ) ;
List < Integer > partitionIds = usersMap . values ( ) . stream ( ) . map ( Users : : getPartitionId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( partitionIds . size ( ) > 1 ) {
throw new ServiceException ( BusiStatus . PARTITION_ERROR , " 分区不一致 " ) ;
}
for ( Users users : usersMap . values ( ) ) {
Long uid = users . getUid ( ) ;
UserPurse userPurse = userPurseService . queryUserPurse ( uid ) ;
BigDecimal golds = BigDecimal . valueOf ( userPurse . getGolds ( ) ) ;
if ( golds . compareTo ( num ) < 0 ) {
throw new AdminServiceException ( " [ " + users . getErbanNo ( ) + " ]的用户金币金额低于 " + num ) ;
}
long recordId = DefaultIdentifierGenerator . getInstance ( ) . nextId ( null ) ;
String recordIdStr = String . valueOf ( recordId ) ;
//扣减金币
userPurse = userPurseService . subGold ( uid , num . doubleValue ( ) , BillObjTypeEnum . CLEAR_USER_GOLD ,
( up ) - > billRecordService . insertGeneralBillRecord ( uid , recordIdStr , BillObjTypeEnum . CLEAR_USER_GOLD , num . doubleValue ( ) , up ) ) ;
//获取更新后的金额
BigDecimal currentGoldNum = BigDecimal . valueOf ( userPurse . getGolds ( ) ) ;
//增加官方操作记录
addOfficialGoldRecord ( recordId , uid , null , num , currentGoldNum , OfficalSendTypeEnum . CLEAR_USER_GOLD . getValue ( ) ,
Constant . WalletCurrencyType . gold , BillObjTypeEnum . CLEAR_USER_GOLD . getValue ( ) , adminId , BillObjTypeEnum . CLEAR_USER_GOLD . getDesc ( ) , null ) ;
}
}
public BusiResult < PageResult < OfficialGoldAllRecordVo > > allRecord ( Integer partitionId , Long erbanNo , OfficalSendTypeEnum type ,
Date beginDate , Date endDate , Integer pageNo , Integer pageSize ) {
Page < OfficialGoldRecordVo > p = new Page < > ( pageNo , pageSize ) ;
@@ -820,4 +656,36 @@ public class OfficialGoldRecordService extends BaseService {
return BusiResult . success ( pageResult ) ;
}
}
/**
* 推送企业微信消息
* @param usersMap 用户映射
* @param partitionId 分区ID
* @param title 标题
* @param adminId 管理员ID
* @param amount 数量
* @param remark 备注
*/
private void pushEnterpriseWeChatMessage ( Map < Long , Users > usersMap , Integer partitionId , String title , int adminId , BigDecimal amount , String remark ) {
if ( envComponent . getDevOrNativeEnv ( ) ) {
return ;
}
String userDescList = usersMap . values ( ) . stream ( ) . map ( u - > String . format ( " %s(%d) " , u . getNick ( ) , u . getErbanNo ( ) ) ) . collect ( Collectors . joining ( " , " ) ) ;
PartitionEnum partitionEnum = PartitionEnum . getByPartitionId ( partitionId ) ;
AdminUser adminUser = adminUserService . getAdminUserById ( adminId ) ;
MarkdownMessage msg = new MarkdownMessage ( ) ;
msg . addTitle ( MarkdownMessage . getHeaderText ( 3 , adminUser . getUsername ( ) + title ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( title ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " APP应用: " ) + AppEnum . getCurApp ( ) . getValue ( ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 赠送数量: " + amount . toPlainString ( ) ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 赠送分区: " + partitionEnum . getDesc ( ) ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 赠送人数: " + usersMap . size ( ) ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 赠送用户: " + userDescList ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 操作者: " + adminUser . getUsername ( ) ) ) ;
msg . add ( MarkdownMessage . getReferenceText ( " 备注: " + remark ) ) ;
// 发送消息
messageRobotPushService . pushMessageByKey ( webSecurityConfig . getOfficialDingPushKey ( ) , msg , false ) ;
}
}