多语言-修改后台赠送逻辑

This commit is contained in:
liaozetao
2024-04-19 16:18:45 +08:00
parent 754af62844
commit 3ca581b058
5 changed files with 61 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ import com.accompany.admin.dto.NameplateDto;
import com.accompany.admin.model.AdminUser;
import com.accompany.admin.service.base.BaseService;
import com.accompany.admin.service.system.AdminUserService;
import com.accompany.core.enumeration.I18nAlertEnum;
import com.accompany.core.util.I18NMessageSourceUtil;
import com.accompany.admin.vo.dress.NameplateAdminVo;
import com.accompany.business.constant.nameplate.NameplateStyleTypeEnum;
@@ -241,8 +242,11 @@ public class NameplateAdminService extends BaseService {
userNameplateService.officialSendNameplateSingle(nameplateId, targetUid, days, remark, updateBy, null, null);
if (isSendMsg) {
// 赠送铭牌时需要发送小助手通知
this.sendNameplateSecretaryMessage(targetUid, "小秘書贈送給你銘牌 - [" + nameplate.getName() + "] 有效期" + days
+ "天,已經幫你放進裝扮里啦,快點移步查看吧~~");
String nameplateName = nameplate.getName();
String i18nId = Nameplate.class.getSimpleName() + StrUtil.DOT + nameplateName;
String name = I18NMessageSourceUtil.getMessage(i18nId, nameplateName, targetUid);
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.NAMEPLATE_FOR_SEND, new Object[]{name, days}, targetUid);
this.sendNameplateSecretaryMessage(targetUid, message);
}
} catch (Exception e) {//吞掉异常,保证其他用户礼物能正常增送
logger.error("赠送铭牌失败nameplateId={}, erbanNo={}", nameplateId, erbanNo);
@@ -272,7 +276,8 @@ public class NameplateAdminService extends BaseService {
attach.setSecond(Constant.DefineProtocol.CUSTOM_MESS_SUB_SECRETARY_INTRACTION);
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", "[銘牌消息]");
String title = I18NMessageSourceUtil.getMessage(I18nAlertEnum.NAMEPLATE_FOR_TITLE, receiverUid);
jsonObject.put("title", title);
jsonObject.put("msg", message);
jsonObject.put("routerType", Constant.SecretarySkipType.NAMEPLATE);
// 0跳转商城1跳转我的头饰
@@ -316,7 +321,7 @@ public class NameplateAdminService extends BaseService {
*/
public void recallUserNameplate(Long id) {
NameplateRecord record = nameplateRecordMapper.selectById(id);
if (null == record || record.getStatus() == PrivilegeConstant.NameplateRecordStatus.RECALL) {
if (null == record || Objects.equals(record.getStatus(), PrivilegeConstant.NameplateRecordStatus.RECALL)) {
return;
}
Long uid = record.getUid();
@@ -446,7 +451,7 @@ public class NameplateAdminService extends BaseService {
upadteNameplate.setId(userNameplate.getId());
upadteNameplate.setUpdateTime(date);
upadteNameplate.setNameplateImage(mpPicUrl);
if (NameplateTypeEnum.CUSTOMIZE.getValue().toString().equals(nameplate.getNameplateType())) {
if (NameplateTypeEnum.CUSTOMIZE.getValue().equals(nameplate.getNameplateType())) {
upadteNameplate.setWord(nameplate.getFixedWord());
}
updateUserNameplates.add(upadteNameplate);

View File

@@ -55,6 +55,20 @@ public class I18NMessageSourceUtil {
}
public static String getMessage(I18nAlertEnum msgEnum, Object[] params, Locale locale) {
return getMessage(msgEnum.getI18nId(), params, msgEnum.getDefaultStr(), locale);
}
public static String getMessage(String i18nId, String defaultValue, Long uid) {
Users user = SpringContextHolder.getBean(UsersBaseService.class).getUsersByUid(uid);
if (null == user) {
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
Integer partitionId = user.getPartitionId();
Locale locale = SpringContextHolder.getBean(PartitionInfoService.class).getDefaultLang(partitionId);
return getMessage(i18nId, null, defaultValue, locale);
}
public static String getMessage(String i18nId, Object[] params, String defaultValue, Locale locale) {
String[] parameters = null;
if (params != null && params.length > 0) {
parameters = new String[params.length];
@@ -62,7 +76,7 @@ public class I18NMessageSourceUtil {
parameters[i] = params[i].toString();
}
}
String message = SpringContextHolder.getBean(MessageSource.class).getMessage(msgEnum.getI18nId(), null, msgEnum.getDefaultStr(), locale);
String message = SpringContextHolder.getBean(MessageSource.class).getMessage(i18nId, null, defaultValue, locale);
return String.format(message, parameters);
}

View File

@@ -10,6 +10,7 @@
*/
package com.accompany.business.service.dress;
import cn.hutool.core.util.StrUtil;
import com.accompany.business.model.UserPurse;
import com.accompany.business.model.dress.ChatBubble;
import com.accompany.business.model.dress.UserChatBubble;
@@ -135,7 +136,7 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
}
try {
UserChatBubble bubbleForSend = getByBubbleIdAndUid(uid, bubbleId);
sendUserChatBubble(uid,null, bubbleId, comeFrom, expireTime, desc, needSendMsg,null,bubbleForSend);
sendUserChatBubble(uid, null, bubbleId, comeFrom, expireTime, desc, needSendMsg, null, bubbleForSend);
} catch (Exception e) {
log.error("赠送用户资料卡出现异常。uid :" + uid + ", bubbleId : " + bubbleId, e);
throw e;
@@ -160,7 +161,7 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
}
try {
UserChatBubble bubbleForSend = getByBubbleIdAndUid(uid, bubbleId);
sendUserChatBubble(uid,null, bubbleId, comeFrom, day, desc, needSendMsg,null,bubbleForSend);
sendUserChatBubble(uid, null, bubbleId, comeFrom, day, desc, needSendMsg, null, bubbleForSend);
} catch (Exception e) {
log.error("赠送用户资料卡出现异常。uid :" + uid + ", bubbleId : " + bubbleId, e);
throw e;
@@ -215,9 +216,9 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
}
try {
UserChatBubble bubbleForSend;
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)) {
bubbleForSend = getByBubbleIdAndUid(targetUid, bubbleId);
}else{
} else {
bubbleForSend = getByBubbleIdAndUid(uid, bubbleId);
}
Date expireTime;
@@ -226,14 +227,14 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
} else {
Date now = new Date();
if (now.getTime() > bubbleForSend.getExpireTime().getTime()) {
expireTime = DateTimeUtil.addDays(now , addDay);
expireTime = DateTimeUtil.addDays(now, addDay);
} else {
expireTime = DateTimeUtil.addDays(bubbleForSend.getExpireTime() , addDay);
expireTime = DateTimeUtil.addDays(bubbleForSend.getExpireTime(), addDay);
}
}
// 先判断是购买还是赠送聊天气泡
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom) || Constant.UserInfoCardComeFrom.BUY.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom) || Constant.UserInfoCardComeFrom.BUY.equals(comeFrom)) {
BillObjTypeEnum billObjTypeEnum = Constant.UserInfoCardComeFrom.BUY.equals(comeFrom) ? BillObjTypeEnum.PURCHASE_CHAT_BUBBLE : BillObjTypeEnum.GIVE_CHAT_BUBBLE;
// 扣除用户金币
this.userPurseService.subDiamond(uid, price.doubleValue(), billObjTypeEnum.getDesc());
@@ -244,7 +245,7 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
billRecordService.insertGeneralBillRecord(uid, targetUid, null, billObjTypeEnum, Double.valueOf(price));
}
sendUserChatBubble(uid,targetUid, bubbleId, comeFrom, expireTime, desc, needSendMsg,price,bubbleForSend);
sendUserChatBubble(uid, targetUid, bubbleId, comeFrom, expireTime, desc, needSendMsg, price, bubbleForSend);
} catch (Exception e) {
log.error("赠送用户资料卡出现异常。uid :" + uid + ", bubbleId : " + bubbleId, e);
throw e;
@@ -254,7 +255,7 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
}
private void sendUserChatBubble(Long uid, Long targetUid,Long bubbleId, Byte comeFrom, Date expireTime, String desc, Boolean needSendMsg, Long price, UserChatBubble userChatBubble){
private void sendUserChatBubble(Long uid, Long targetUid, Long bubbleId, Byte comeFrom, Date expireTime, String desc, Boolean needSendMsg, Long price, UserChatBubble userChatBubble) {
ChatBubble chatBubbleById = chatBubbleService.getChatBubbleById(bubbleId);
Date now = new Date();
if (null == chatBubbleById) {
@@ -273,9 +274,9 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
.used(Constant.UserInfoCardUsed.NOT_USING)
.comeFrom(comeFrom).createTime(now).updateTime(now)
.build();
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)) {
userChatBubble.setUid(targetUid);
}else{
} else {
userChatBubble.setUid(uid);
}
save(userChatBubble);
@@ -298,18 +299,21 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
}
// 增加记录
int days = DateTimeUtil.diffDayByDateV2(startTime, expireTime);
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)) {
saveRecord(targetUid, bubbleId, comeFrom, days, desc, now, targetUid, price);
}else{
} else {
saveRecord(uid, bubbleId, comeFrom, days, desc, now, targetUid, price);
}
if (needSendMsg) {
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.CHAT_BUBBLE_FOR_SEND, new Object[]{chatBubbleById.getName(), days}, uid);
String chatBubbleName = chatBubbleById.getName();
String i18nId = ChatBubble.class.getSimpleName() + StrUtil.DOT + chatBubbleName;
String name = I18NMessageSourceUtil.getMessage(i18nId, chatBubbleName, uid);
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.CHAT_BUBBLE_FOR_SEND, new Object[]{name, days}, uid);
sendChatBubbleSecretaryMessage(uid, message);
}
}
private void sendUserChatBubble(Long uid, Long targetUid,Long bubbleId, Byte comeFrom, Integer days, String desc, Boolean needSendMsg, Long price, UserChatBubble userChatBubble) {
private void sendUserChatBubble(Long uid, Long targetUid, Long bubbleId, Byte comeFrom, Integer days, String desc, Boolean needSendMsg, Long price, UserChatBubble userChatBubble) {
ChatBubble chatBubbleById = chatBubbleService.getChatBubbleById(bubbleId);
Date now = new Date();
if (null == chatBubbleById) {
@@ -327,16 +331,16 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
.used(Constant.UserInfoCardUsed.NOT_USING)
.comeFrom(comeFrom).createTime(now).updateTime(now)
.build();
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)) {
userChatBubble.setUid(targetUid);
}else{
} else {
userChatBubble.setUid(uid);
}
save(userChatBubble);
} else {
Byte status;
//是否已经过期
if (userChatBubble.getExpireTime().getTime() < System.currentTimeMillis()){
if (userChatBubble.getExpireTime().getTime() < System.currentTimeMillis()) {
startTime = now;
expireTime = DateTimeUtil.addDays(now, days);
status = Constant.UserInfoCardUsed.NOT_USING;
@@ -354,9 +358,9 @@ public class UserChatBubbleService extends ServiceImpl<UserChatBubbleMapper, Use
updateById(userChatBubble);
}
if(Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)){
if (Constant.UserInfoCardComeFrom.USER_DONATE.equals(comeFrom)) {
saveRecord(targetUid, bubbleId, comeFrom, days, desc, now, targetUid, price);
}else{
} else {
saveRecord(uid, bubbleId, comeFrom, days, desc, now, targetUid, price);
}

View File

@@ -10,6 +10,7 @@
*/
package com.accompany.business.service.dress;
import cn.hutool.core.util.StrUtil;
import com.accompany.business.model.UserPurse;
import com.accompany.business.model.dress.InfoCard;
import com.accompany.business.model.dress.UserInfoCard;
@@ -322,7 +323,10 @@ public class UserInfoCardService extends ServiceImpl<UserInfoCardMapper, UserInf
saveRecord(uid, cardId, comeFrom, days, desc, now,null, price);
}
if (needSendMsg) {
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.INFO_CARD_FOR_SEND, new Object[]{infoCard.getName(), days}, uid);
String infoCardName = infoCard.getName();
String i18nId = InfoCard.class.getSimpleName() + StrUtil.DOT + infoCardName;
String name = I18NMessageSourceUtil.getMessage(i18nId, infoCardName, targetUid);
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.INFO_CARD_FOR_SEND, new Object[]{name, days}, uid);
sendInfoCardSecretaryMessage(uid, message);
}
}

View File

@@ -1,5 +1,6 @@
package com.accompany.business.service.headwear;
import cn.hutool.core.util.StrUtil;
import com.accompany.business.model.*;
import com.accompany.business.mybatismapper.*;
import com.accompany.business.param.neteasepush.NeteaseSendMsgParam;
@@ -29,7 +30,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -588,7 +588,6 @@ public class HeadwearService extends BaseService {
}
/**
* 更新到期头饰
*/
@@ -677,7 +676,7 @@ public class HeadwearService extends BaseService {
* @param deviceInfo
*/
public Long insertHeadwearRecord(Long uid, Headwear headwear, Long price, Byte optType, DeviceInfo deviceInfo, Integer days,
Long giverUid, Byte comeFrom, Byte currencyType) {
Long giverUid, Byte comeFrom, Byte currencyType) {
HeadwearRecord record = new HeadwearRecord();
record.setUid(uid);
record.setHeadwearId(headwear.getHeadwearId());
@@ -731,8 +730,11 @@ public class HeadwearService extends BaseService {
this.officialSendHeadWearSingle(headwearId, targetUid, days);
if (isSendMsg) {
// 贈送頭飾時需要發送小助手通知
this.sendHeadwearSecretaryMessage(targetUid, "小秘書贈送給你頭飾 - [" + headwear.getName() + "] 有效期" + days
+ "天,已經幫你放進裝扮里啦,快點移步查看吧~~");
String headWearName = headwear.getName();
String i18nId = Headwear.class.getSimpleName() + StrUtil.DOT + headWearName;
String name = I18NMessageSourceUtil.getMessage(i18nId, headWearName, targetUid);
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.HEAD_WEAR_FOR_SEND, new Object[]{name, days}, targetUid);
this.sendHeadwearSecretaryMessage(targetUid, message);
}
} catch (Exception e) {//吞掉异常,保证其他用户礼物能正常增送
logger.error("赠送头饰失败headwearId={}, erbanNo={}", headwearId, erbanNo);