道具券道具天数处理

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;
private Integer validDays = 30;
/**
* 道具天数
*/
@NotNull(message = "道具天数不能为空")
private Integer propDays;
/**
* 接收用户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.enums.message.OfficialNoticeTypeEnum;
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.domain.gateway.PropCouponGateway;
import com.red.circle.other.domain.propcoupon.PropCoupon;
@ -37,9 +39,9 @@ import java.util.stream.Collectors;
public class PropCouponGrantCmdExe {
private final PropCouponGateway propCouponGateway;
private final UserProfileClient userProfileClient;
private final OfficialNoticeClient officialNoticeClient;
private final PropsSourceClient propsSourceClient;
private final UserProfileGateway userProfileGateway;
/**
* 执行后台赠送道具券
@ -52,7 +54,7 @@ public class PropCouponGrantCmdExe {
// 2. 校验用户是否存在
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(
propsSourceClient.getById(Long.parseLong(cmd.getPropId())));
@ -93,10 +95,20 @@ public class PropCouponGrantCmdExe {
/**
* 校验用户是否存在
*/
private Map<Long, UserProfileDTO> validateUsers(Set<Long> userIds) {
Map<Long, UserProfileDTO> userMap = ResponseAssert.requiredSuccess(
userProfileClient.mapByUserIds(userIds)
);
private Map<Long, UserProfile> validateUsers(Set<Long> userIds) {
Map<Long, UserProfile> userMap = userProfileGateway.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,
@ -124,6 +136,7 @@ public class PropCouponGrantCmdExe {
propCoupon.setPropIcon(cmd.getPropIcon());
propCoupon.setPropName(displayPropName);
propCoupon.setValidDays(cmd.getValidDays());
propCoupon.setPropDays(cmd.getPropDays());
propCoupon.setStatus(PropCouponStatus.UNUSED);
propCoupon.setSource(PropCouponSource.ADMIN_GRANT);
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) {
try {
UserProfileDTO user = userMap.get(propCoupon.getUserId());
UserProfile user = userMap.get(propCoupon.getUserId());
if (user != null) {
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(
NoticeExtTemplateCustomizeCmd.builder()
.toAccount(user.getId())

View File

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

View File

@ -189,7 +189,8 @@ public class PropsSendCommon {
grantCmd.setPropIcon(propsSourceRecord.getCover());
grantCmd.setPropName(propsSourceRecord.getName());
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));
// 5. 批量插入券记录
@ -490,6 +491,7 @@ public class PropsSendCommon {
propCoupon.setPropIcon(cmd.getPropIcon());
propCoupon.setPropName(displayPropName);
propCoupon.setValidDays(cmd.getValidDays());
propCoupon.setPropDays(cmd.getPropDays());
propCoupon.setStatus(PropCouponStatus.UNUSED);
propCoupon.setSource(source);
propCoupon.setExpireTime(expireTime);

View File

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

View File

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