道具券道具天数处理

This commit is contained in:
tianfeng 2025-11-20 18:37:40 +08:00
parent 4d7abe240c
commit 4bb1da87e4
6 changed files with 40 additions and 13 deletions

View File

@ -38,8 +38,13 @@ public class PropCouponGrantCmd extends Command {
/** /**
* 有效天数 * 有效天数
*/ */
@NotNull(message = "有效天数不能为空") private Integer validDays = 30;
private Integer validDays;
/**
* 道具天数
*/
@NotNull(message = "道具天数不能为空")
private Integer propDays;
/** /**
* 接收用户ID列表 * 接收用户ID列表

View File

@ -4,6 +4,8 @@ import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient;
import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateCustomizeCmd; import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateCustomizeCmd;
import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum;
import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.inner.model.cmd.material.PropCouponGrantCmd; import com.red.circle.other.inner.model.cmd.material.PropCouponGrantCmd;
import com.red.circle.other.domain.gateway.PropCouponGateway; import com.red.circle.other.domain.gateway.PropCouponGateway;
import com.red.circle.other.domain.propcoupon.PropCoupon; import com.red.circle.other.domain.propcoupon.PropCoupon;
@ -37,9 +39,9 @@ import java.util.stream.Collectors;
public class PropCouponGrantCmdExe { public class PropCouponGrantCmdExe {
private final PropCouponGateway propCouponGateway; private final PropCouponGateway propCouponGateway;
private final UserProfileClient userProfileClient;
private final OfficialNoticeClient officialNoticeClient; private final OfficialNoticeClient officialNoticeClient;
private final PropsSourceClient propsSourceClient; private final PropsSourceClient propsSourceClient;
private final UserProfileGateway userProfileGateway;
/** /**
* 执行后台赠送道具券 * 执行后台赠送道具券
@ -52,7 +54,7 @@ public class PropCouponGrantCmdExe {
// 2. 校验用户是否存在 // 2. 校验用户是否存在
Set<Long> userIds = cmd.getUserIds().stream().map(Long::parseLong).collect(Collectors.toSet()); Set<Long> userIds = cmd.getUserIds().stream().map(Long::parseLong).collect(Collectors.toSet());
Map<Long, UserProfileDTO> userMap = validateUsers(userIds); Map<Long, UserProfile> userMap = validateUsers(userIds);
PropsResourcesDTO propsResourcesDTO = ResponseAssert.requiredSuccess( PropsResourcesDTO propsResourcesDTO = ResponseAssert.requiredSuccess(
propsSourceClient.getById(Long.parseLong(cmd.getPropId()))); propsSourceClient.getById(Long.parseLong(cmd.getPropId())));
@ -93,10 +95,20 @@ public class PropCouponGrantCmdExe {
/** /**
* 校验用户是否存在 * 校验用户是否存在
*/ */
private Map<Long, UserProfileDTO> validateUsers(Set<Long> userIds) { private Map<Long, UserProfile> validateUsers(Set<Long> userIds) {
Map<Long, UserProfileDTO> userMap = ResponseAssert.requiredSuccess( Map<Long, UserProfile> userMap = userProfileGateway.mapByUserIds(userIds);
userProfileClient.mapByUserIds(userIds)
); if (userMap.isEmpty()) {
Map<Long, UserProfile> map = new HashMap<>();
userIds.forEach(userId -> {
List<UserProfile> userProfiles = userProfileGateway.getByAccount(String.valueOf(userId));
if (!userProfiles.isEmpty()) {
UserProfile userProfile = userProfiles.get(0);
map.put(userProfile.getId(), userProfile);
}
});
return map;
}
// 校验所有用户都存在 // 校验所有用户都存在
ResponseAssert.isTrue(OtherErrorCode.PROP_COUPON_RECEIVER_NOT_FOUND, ResponseAssert.isTrue(OtherErrorCode.PROP_COUPON_RECEIVER_NOT_FOUND,
@ -124,6 +136,7 @@ public class PropCouponGrantCmdExe {
propCoupon.setPropIcon(cmd.getPropIcon()); propCoupon.setPropIcon(cmd.getPropIcon());
propCoupon.setPropName(displayPropName); propCoupon.setPropName(displayPropName);
propCoupon.setValidDays(cmd.getValidDays()); propCoupon.setValidDays(cmd.getValidDays());
propCoupon.setPropDays(cmd.getPropDays());
propCoupon.setStatus(PropCouponStatus.UNUSED); propCoupon.setStatus(PropCouponStatus.UNUSED);
propCoupon.setSource(PropCouponSource.ADMIN_GRANT); propCoupon.setSource(PropCouponSource.ADMIN_GRANT);
propCoupon.setExpireTime(expireTime); propCoupon.setExpireTime(expireTime);
@ -178,10 +191,10 @@ public class PropCouponGrantCmdExe {
/** /**
* 发送系统消息通知用户 * 发送系统消息通知用户
*/ */
private void sendNotifications(List<PropCoupon> propCoupons, Map<Long, UserProfileDTO> userMap, PropCouponType couponType) { private void sendNotifications(List<PropCoupon> propCoupons, Map<Long, UserProfile> userMap, PropCouponType couponType) {
for (PropCoupon propCoupon : propCoupons) { for (PropCoupon propCoupon : propCoupons) {
try { try {
UserProfileDTO user = userMap.get(propCoupon.getUserId()); UserProfile user = userMap.get(propCoupon.getUserId());
if (user != null) { if (user != null) {
sendNotification(propCoupon, user, couponType); sendNotification(propCoupon, user, couponType);
} }
@ -195,7 +208,7 @@ public class PropCouponGrantCmdExe {
/** /**
* 发送单个通知 * 发送单个通知
*/ */
private void sendNotification(PropCoupon propCoupon, UserProfileDTO user, PropCouponType couponType) { private void sendNotification(PropCoupon propCoupon, UserProfile user, PropCouponType couponType) {
officialNoticeClient.send( officialNoticeClient.send(
NoticeExtTemplateCustomizeCmd.builder() NoticeExtTemplateCustomizeCmd.builder()
.toAccount(user.getId()) .toAccount(user.getId())

View File

@ -110,7 +110,7 @@ public class PropCouponUseCmdExe {
private void givePropsToUser(PropCoupon propCoupon, Long userId) { private void givePropsToUser(PropCoupon propCoupon, Long userId) {
PropCouponType couponType = propCoupon.getCouponType(); PropCouponType couponType = propCoupon.getCouponType();
Long propId = propCoupon.getPropId(); Long propId = propCoupon.getPropId();
Integer validDays = propCoupon.getValidDays(); Integer validDays = propCoupon.getPropDays();
switch (couponType) { switch (couponType) {
case AVATAR_FRAME: case AVATAR_FRAME:

View File

@ -189,7 +189,8 @@ public class PropsSendCommon {
grantCmd.setPropIcon(propsSourceRecord.getCover()); grantCmd.setPropIcon(propsSourceRecord.getCover());
grantCmd.setPropName(propsSourceRecord.getName()); grantCmd.setPropName(propsSourceRecord.getName());
grantCmd.setCouponType(couponType.getCode()); grantCmd.setCouponType(couponType.getCode());
grantCmd.setValidDays(prizeDescribe.getQuantity()); grantCmd.setValidDays(30);
grantCmd.setPropDays(prizeDescribe.getQuantity());
List<PropCoupon> propCoupons = generateCoupons(grantCmd, source, couponType, Collections.singleton(acceptUserId)); List<PropCoupon> propCoupons = generateCoupons(grantCmd, source, couponType, Collections.singleton(acceptUserId));
// 5. 批量插入券记录 // 5. 批量插入券记录
@ -490,6 +491,7 @@ public class PropsSendCommon {
propCoupon.setPropIcon(cmd.getPropIcon()); propCoupon.setPropIcon(cmd.getPropIcon());
propCoupon.setPropName(displayPropName); propCoupon.setPropName(displayPropName);
propCoupon.setValidDays(cmd.getValidDays()); propCoupon.setValidDays(cmd.getValidDays());
propCoupon.setPropDays(cmd.getPropDays());
propCoupon.setStatus(PropCouponStatus.UNUSED); propCoupon.setStatus(PropCouponStatus.UNUSED);
propCoupon.setSource(source); propCoupon.setSource(source);
propCoupon.setExpireTime(expireTime); propCoupon.setExpireTime(expireTime);

View File

@ -58,6 +58,11 @@ public class PropCouponDO {
*/ */
private Integer validDays; private Integer validDays;
/**
* 道具天数
*/
private Integer propDays;
/** /**
* 券状态0未使用 1已使用 2已过期 3已赠送 * 券状态0未使用 1已使用 2已过期 3已赠送
*/ */

View File

@ -139,6 +139,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway {
propCoupon.setPropIcon(propCouponDO.getPropIcon()); propCoupon.setPropIcon(propCouponDO.getPropIcon());
propCoupon.setPropName(propCouponDO.getPropName()); propCoupon.setPropName(propCouponDO.getPropName());
propCoupon.setValidDays(propCouponDO.getValidDays()); propCoupon.setValidDays(propCouponDO.getValidDays());
propCoupon.setPropDays(propCouponDO.getPropDays());
propCoupon.setStatus(PropCouponStatus.getByCode(propCouponDO.getStatus())); propCoupon.setStatus(PropCouponStatus.getByCode(propCouponDO.getStatus()));
propCoupon.setSource(PropCouponSource.getByCode(propCouponDO.getSource())); propCoupon.setSource(PropCouponSource.getByCode(propCouponDO.getSource()));
propCoupon.setExpireTime(propCouponDO.getExpireTime()); propCoupon.setExpireTime(propCouponDO.getExpireTime());
@ -164,6 +165,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway {
propCouponDO.setPropIcon(propCoupon.getPropIcon()); propCouponDO.setPropIcon(propCoupon.getPropIcon());
propCouponDO.setPropName(propCoupon.getPropName()); propCouponDO.setPropName(propCoupon.getPropName());
propCouponDO.setValidDays(propCoupon.getValidDays()); propCouponDO.setValidDays(propCoupon.getValidDays());
propCouponDO.setPropDays(propCoupon.getPropDays());
propCouponDO.setStatus(propCoupon.getStatus() != null ? propCoupon.getStatus().getCode() : null); propCouponDO.setStatus(propCoupon.getStatus() != null ? propCoupon.getStatus().getCode() : null);
propCouponDO.setSource(propCoupon.getSource() != null ? propCoupon.getSource().getCode() : null); propCouponDO.setSource(propCoupon.getSource() != null ? propCoupon.getSource().getCode() : null);
propCouponDO.setExpireTime(propCoupon.getExpireTime()); propCouponDO.setExpireTime(propCoupon.getExpireTime());