fanli/src/main/java/com/yeshi/fanli/controller/CallBackController.java
@@ -3,6 +3,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.math.BigDecimal; import java.security.SignatureException; import java.util.Date; import java.util.HashMap; @@ -188,7 +189,8 @@ if (!StringUtil.isNullOrEmpty(orderNo)) { BanLiShopOrder order = banLiShopOrderService.selectByOrderNo(orderNo); if (order != null) {// 支付成功消息推送 BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid()); BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid(), new BigDecimal(map.get("total_fee")).multiply(new BigDecimal("0.01"))); Message message = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.banLiShopOrderPaid.name(), new Gson().toJson(msg).getBytes()); producer.send(message); fanli/src/main/java/com/yeshi/fanli/controller/admin/.gitignore
New file @@ -0,0 +1 @@ /OrderAdminController.java fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/BanLiShopOrderMQMsg.java
@@ -1,10 +1,21 @@ package com.yeshi.fanli.dto.mq.order.body; import java.math.BigDecimal; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; public class BanLiShopOrderMQMsg extends BaseMQMsgBody { private Long orderId;// 订单ID private Long uid;// 用户ID private BigDecimal money;// 付款金额 public BigDecimal getMoney() { return money; } public void setMoney(BigDecimal money) { this.money = money; } public BanLiShopOrderMQMsg(Long orderId, Long uid) { super(); @@ -12,6 +23,12 @@ this.uid = uid; } public BanLiShopOrderMQMsg(Long orderId, Long uid, BigDecimal money) { this.money = money; this.orderId = orderId; this.uid = uid; } public BanLiShopOrderMQMsg() { super(); } fanli/src/main/java/com/yeshi/fanli/dto/mq/user/UserTopicTagEnum.java
@@ -1,13 +1,20 @@ package com.yeshi.fanli.dto.mq.user; import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserRegisterMQMsg; import com.yeshi.fanli.util.annotation.UserActive; public enum UserTopicTagEnum { userAccountBinding(UserActive.class), // 用户账号绑定 userAccountBinding(UserAccountBindingMQMsg.class), // 用户账号绑定 userActve(UserActive.class), // 用户活跃 useSystemCoupon(UserActive.class), // 系统券使用 inviteSuccess(UserActive.class), // 邀请成功 integralTaskFinish(UserActive.class);// 完成金币任务 inviteSuccess(UserInviteMQMsg.class), // 邀请成功 integralTaskFinish(IntegralTaskMQMsg.class), // 完成金币任务 userRegister(UserRegisterMQMsg.class);// 用户注册 private final Class<?> clazz; fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/IntegralTaskMQMsg.java
New file @@ -0,0 +1,53 @@ package com.yeshi.fanli.dto.mq.user.body; import java.util.Date; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; /** * 金币任务 * * @author Administrator * */ public class IntegralTaskMQMsg extends BaseMQMsgBody { public IntegralTaskMQMsg(Long uid, long longegralCount, Date createTime) { super(); this.uid = uid; this.longegralCount = longegralCount; this.createTime = createTime; } public IntegralTaskMQMsg() { super(); } private Long uid;// 用户ID private long longegralCount;// 金币数量 private Date createTime;// 创建时间 public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Long getUid() { return uid; } public void setUid(Long uid) { this.uid = uid; } public long getIntegralCount() { return longegralCount; } public void setIntegralCount(long longegralCount) { this.longegralCount = longegralCount; } } fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/UserAccountBindingMQMsg.java
New file @@ -0,0 +1,67 @@ package com.yeshi.fanli.dto.mq.user.body; import java.util.Date; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; /** * 账号绑定 * * @author Administrator * */ public class UserAccountBindingMQMsg extends BaseMQMsgBody { public static int TYPE_PHONE = 3; public static int TYPE_WX = 2; public static int TYPE_TAOBAO = 1; public static int TYPE_ALIPAY = 4; private Long uid;// 用户ID private Integer type;// 绑定类型 private String value;// 绑定的值 private Date bindingTime;// 绑定时间 public UserAccountBindingMQMsg(Long uid, Integer type, String value, Date bindingTime) { super(); this.uid = uid; this.type = type; this.value = value; this.bindingTime = bindingTime; } public UserAccountBindingMQMsg() { super(); } public Long getUid() { return uid; } public void setUid(Long uid) { this.uid = uid; } public Integer getType() { return type; } public void setType(Integer type) { this.type = type; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public Date getBindingTime() { return bindingTime; } public void setBindingTime(Date bindingTime) { this.bindingTime = bindingTime; } } fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/UserInviteMQMsg.java
New file @@ -0,0 +1,75 @@ package com.yeshi.fanli.dto.mq.user.body; import java.util.Date; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; /** * 邀请信息 * * @author Administrator * */ public class UserInviteMQMsg extends BaseMQMsgBody { public static int STATE_NOT_SUCCESS = 0; public static int STATE_SUCCESS = 1; private Long bossId;// 上级ID private Long workerId;// 下级ID private Date inviteTime;// 邀请时间 private Date successTime;// 成功时间 private int state;// 邀请状态 public UserInviteMQMsg(Long bossId, Long workerId, Date inviteTime, Date successTime, int state) { super(); this.bossId = bossId; this.workerId = workerId; this.inviteTime = inviteTime; this.successTime = successTime; this.state = state; } public UserInviteMQMsg() { super(); } public Long getBossId() { return bossId; } public void setBossId(Long bossId) { this.bossId = bossId; } public Long getWorkerId() { return workerId; } public void setWorkerId(Long workerId) { this.workerId = workerId; } public Date getInviteTime() { return inviteTime; } public void setInviteTime(Date inviteTime) { this.inviteTime = inviteTime; } public Date getSuccessTime() { return successTime; } public void setSuccessTime(Date successTime) { this.successTime = successTime; } public int getState() { return state; } public void setState(int state) { this.state = state; } } fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/UserRegisterMQMsg.java
New file @@ -0,0 +1,50 @@ package com.yeshi.fanli.dto.mq.user.body; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; /** * 用户注册信息 * * @author Administrator * */ public class UserRegisterMQMsg extends BaseMQMsgBody { private Long uid;// 注册的用户ID private String wxUnionId;// 注册的微信unionId private String phone;// 注册的电话号码 public UserRegisterMQMsg(Long uid, String wxUnionId, String phone) { super(); this.uid = uid; this.wxUnionId = wxUnionId; this.phone = phone; } public UserRegisterMQMsg() { super(); } public Long getUid() { return uid; } public void setUid(Long uid) { this.uid = uid; } public String getWxUnionId() { return wxUnionId; } public void setWxUnionId(String wxUnionId) { this.wxUnionId = wxUnionId; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } } fanli/src/main/java/com/yeshi/fanli/entity/bus/user/ThreeSale.java
@@ -1,12 +1,8 @@ package com.yeshi.fanli.entity.bus.user; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Transient; fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -121,8 +121,7 @@ @Lazy @Resource private UserInfoModifyRecordService userInfoModifyRecordService; @Transactional @Override public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId, @@ -223,7 +222,7 @@ updateUserInfo.setLastLoginTime(System.currentTimeMillis()); updateUserInfo.setLoginType(loginType); updateUserInfo.setLastLoginIp(request.getRemoteHost()); //更新openId // 更新openId updateUserInfo.setOpenid(weiXinUser.getOpenid()); userInfoMapper.updateByPrimaryKeySelective(updateUserInfo); @@ -694,6 +693,7 @@ addUser(userInfo); } @Transactional @Override public void addUser(UserInfo user) { @@ -726,12 +726,12 @@ e.printStackTrace(); } // 添加账号绑定历史 if (!StringUtil.isNullOrEmpty(user.getPhone())) userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, user.getPhone()); if (!StringUtil.isNullOrEmpty(user.getWxUnionId())) userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId()); } @Override @@ -1087,8 +1087,7 @@ // 通过Code换取信息 WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(1, "微信帐号授权失败"); } @@ -1125,23 +1124,24 @@ spreadUserImgService.deleteImgUrl(userInfo.getId()); } else { LogHelper.test("微信unionID不存在:" + weiXinUser.getUnionid()); String portrait = null; if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) { InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()); if (asInputStream != null) { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) portrait = result.getUrl(); } else { portrait = weiXinUser.getHeadimgurl(); } } if (StringUtil.isNullOrEmpty(portrait)) portrait = Constant.systemCommonConfig.getDefaultPortrait(); // 创建新账户 userInfo = new UserInfo(); userInfo.setPortrait(portrait); @@ -1179,10 +1179,10 @@ throw new UserAccountException(10, "请稍后再试"); } @Transactional @Override public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode, String appId) throws UserAccountException { public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode, String appId) throws UserAccountException { // 日志信息 JSONObject logInfo = new JSONObject(); logInfo.put("appId", appId); @@ -1192,8 +1192,7 @@ // 通过Code换取信息 WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), wxAccount.getAppSecret()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(1, "微信帐号授权失败"); } @@ -1206,7 +1205,6 @@ throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); } UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid()); if (userInfo == null) { String longinKey = StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()); @@ -1225,8 +1223,6 @@ return userInfo; } /** * 更新账户登录信息 * @@ -1291,8 +1287,7 @@ throw new UserAccountException(1, "用户不存在"); } WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(2, "微信帐号授权失败"); } @@ -1338,14 +1333,14 @@ String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { LogHelper.test("微信头像下载失败: " +weiXinUser.getUnionid()+ " " + headimgurl); LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl); } else { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { LogHelper.test("微信头像上传失败: " +weiXinUser.getUnionid()+ " " + headimgurl); LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); @@ -1369,49 +1364,49 @@ userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, wxUnionId); } @Override public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request) throws UserAccountException { public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request) throws UserAccountException { UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone); if (phoneUser != null) if (phoneUser != null) throw new UserAccountException(1, "号码已经被占用"); // 判断手机号码是否被封禁 ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone); if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); String value = redisManager.getCommonString(key); if (StringUtil.isNullOrEmpty(value)) throw new UserAccountException(1, "微信授权失效,请使用微信重新登录"); WeiXinUser weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class); if (weiXinUser == null) throw new UserAccountException(1, "微信授权失效,请使用微信重新登录"); UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid()); // 直接用的微信登录 if (userInfo != null) if (userInfo != null) throw new UserAccountException(10, "该微信号已被占用"); String portrait = null; if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) { InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()); if (asInputStream != null) { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) portrait = result.getUrl(); } else { portrait = weiXinUser.getHeadimgurl(); } } if (StringUtil.isNullOrEmpty(portrait)) portrait = Constant.systemCommonConfig.getDefaultPortrait(); // 创建新账户 userInfo = new UserInfo(); userInfo.setPhone(phone); @@ -1427,7 +1422,7 @@ userInfo.setLastLoginIp(request.getRemoteHost()); userInfo.setState(UserInfo.STATE_NORMAL); addUser(userInfo); Long uid = userInfo.getId(); ThreadUtil.run(new Runnable() { public void run() { @@ -1437,7 +1432,7 @@ } catch (Exception e) { e.printStackTrace(); } // 加入绑定记录 UserAccountBindingHistory history = new UserAccountBindingHistory(); history.setContent(phone); @@ -1447,16 +1442,14 @@ userAccountBindingHistoryService.addUserAccountBindingHistory(history); userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone); userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid()); userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid()); } }); // 删除缓存 redisManager.removeCommonString(key); return userInfo; } @Override public void forbiddenUserAll(Long uid, String reason) { fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoModifyRecordServiceImpl.java
@@ -6,8 +6,14 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.aliyun.openservices.ons.api.Message; import com.aliyun.openservices.ons.api.Producer; import com.google.gson.Gson; import com.yeshi.fanli.dao.mybatis.user.UserInfoModifyRecordMapper; import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg; import com.yeshi.fanli.entity.bus.user.BindingAccount; import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; @@ -23,6 +29,7 @@ import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.rocketmq.MQTopicName; @Service public class UserInfoModifyRecordServiceImpl implements UserInfoModifyRecordService { @@ -45,7 +52,11 @@ @Resource private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; @Resource(name = "producer") private Producer producer; @Async() @Transactional @Override public void addModifyRecord(Long uid, ModifyTypeEnum type, String value) { try { @@ -81,6 +92,25 @@ record.setValue(value); record.setCreateTime(new Date()); userInfoModifyRecordMapper.insertSelective(record); if (oldRecord == null) {// 新建 // 发送账号修改消息 UserAccountBindingMQMsg mqMsg = null; if (type == ModifyTypeEnum.bindPhone) { mqMsg = new UserAccountBindingMQMsg(uid, UserAccountBindingMQMsg.TYPE_PHONE, value, new Date()); } else if (type == ModifyTypeEnum.bindTaoBao) { mqMsg = new UserAccountBindingMQMsg(uid, UserAccountBindingMQMsg.TYPE_TAOBAO, value, new Date()); } else if (type == ModifyTypeEnum.bindWeiXin) { mqMsg = new UserAccountBindingMQMsg(uid, UserAccountBindingMQMsg.TYPE_WX, value, new Date()); } else if (type == ModifyTypeEnum.bindAlipay) { mqMsg = new UserAccountBindingMQMsg(uid, UserAccountBindingMQMsg.TYPE_ALIPAY, value, new Date()); } Message message = new Message(MQTopicName.TOPIC_USER.name(), UserTopicTagEnum.userAccountBinding.name(), new Gson().toJson(mqMsg).getBytes()); producer.send(message); } } } catch (Exception e) { e.printStackTrace(); @@ -113,7 +143,8 @@ addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId()); } if (user.getNickName() != null && !user.getNickName().startsWith("返利券")&&!user.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName())) { if (user.getNickName() != null && !user.getNickName().startsWith("返利券") && !user.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName())) { addModifyRecord(uid, ModifyTypeEnum.nickName, user.getNickName() + ""); } fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java
@@ -16,7 +16,12 @@ import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.DateUtil; import com.aliyun.openservices.ons.api.Message; import com.aliyun.openservices.ons.api.Producer; import com.google.gson.Gson; import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper; import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg; import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO; import com.yeshi.fanli.entity.bus.user.UserInfoExtra; import com.yeshi.fanli.entity.integral.IntegralDetail; @@ -37,6 +42,7 @@ import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.rocketmq.MQTopicName; @Service public class IntegralTaskRecordServiceImpl implements IntegralTaskRecordService { @@ -63,6 +69,9 @@ @Resource private ConfigService configService; @Resource(name = "producer") private Producer producer; @Override public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) { return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType); @@ -80,7 +89,7 @@ taskRecord.setCid(cid); taskRecord.setTaskId(taskId); taskRecord.setGoldCoin(goldCoin); taskRecord.setState(0); taskRecord.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE); taskRecord.setCreateTime(new Date()); taskRecord.setUpdateTime(new Date()); integralTaskRecordMapper.insertSelective(taskRecord); @@ -207,7 +216,7 @@ // 更新金币 userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin); return (userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()) + totalGoldCoin; return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin; } @Override @@ -240,7 +249,7 @@ // 更新金币 userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin); return totalGoldCoin+(userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()); return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()); } @Transactional @@ -341,6 +350,7 @@ return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime); } @Transactional @Override public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException { if (record == null) @@ -356,6 +366,14 @@ if (record.getUpdateTime() == null) record.setUpdateTime(new Date()); integralTaskRecordMapper.insertSelective(record); long count = integralTaskRecordMapper.getTotalGoldCoinByUid(record.getUid()); if (count >= 200) {// 大于200发送消息 IntegralTaskMQMsg msg = new IntegralTaskMQMsg(record.getUid(), count, new Date()); Message message = new Message(MQTopicName.TOPIC_USER.name(), UserTopicTagEnum.integralTaskFinish.name(), new Gson().toJson(msg).getBytes()); producer.send(message); } return record; } @@ -376,14 +394,11 @@ return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count); } @Override public long getTotalGoldCoinByUid(Long uid) { return integralTaskRecordMapper.getTotalGoldCoinByUid(uid); } @Async() @Override public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) { @@ -494,10 +509,10 @@ } userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther); } /** * 推广红包折算金币 * * @param uid * @param addGoldCoin * @param tlj fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java
@@ -13,8 +13,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.aliyun.openservices.ons.api.Message; import com.aliyun.openservices.ons.api.Producer; import com.google.gson.Gson; import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper; import com.yeshi.fanli.dao.mybatis.UserInfoMapper; import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg; import com.yeshi.fanli.entity.bus.user.ThreeSale; import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; @@ -30,7 +35,7 @@ import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.cmq.ThreeSaleCMQManager; import com.yeshi.fanli.util.rocketmq.MQTopicName; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -71,6 +76,9 @@ @Resource(name = "taskExecutor") private TaskExecutor executor; @Resource(name = "producer") private Producer producer; public UserInfo getBoss(final long uid) { return threeSaleMapper.selectBoss(uid); @@ -185,8 +193,7 @@ ts.setSucceedTime(System.currentTimeMillis()); ts.setWorker(worker); threeSaleMapper.insertSelective(ts); ThreeSaleCMQManager.getInstance().addThreeSaleMsg(ts); userInviteMsgNotificationService.inviteSuccess(inviter.getId(), ts); inviteSuccess(inviter.getId(), worker.getId(), ts); } else { if (!list.get(0).getState() && list.get(0).getExpire() == ThreeSale.EXPIRE_NORMAL && list.get(0).getBoss().getId() == inviter.getId().longValue()) {// 未生效的上级和现在上级一样就生效 @@ -194,8 +201,7 @@ update.setState(true); update.setSucceedTime(System.currentTimeMillis()); threeSaleMapper.updateByPrimaryKeySelective(update); ThreeSaleCMQManager.getInstance().addThreeSaleMsg(list.get(0));// 添加通知 userInviteMsgNotificationService.inviteSuccess(inviter.getId(), list.get(0)); inviteSuccess(list.get(0).getBoss().getId(), list.get(0).getWorker().getId(), list.get(0)); } } } @@ -226,14 +232,11 @@ oldSale.setState(update.getState()); oldSale.setSucceedTime(update.getSucceedTime()); UserInfo inviter = list.get(0).getBoss(); // 不以邀请人数计算等级 // if (inviter != null) // reComputeUserRank(inviter.getId()); // 添加到队列 ThreeSaleCMQManager.getInstance().addThreeSaleMsg(oldSale); // 通知 userInviteMsgNotificationService.inviteSuccess(inviter.getId(), oldSale); inviteSuccess(oldSale.getBoss().getId(), oldSale.getWorker().getId(), oldSale); } } @@ -536,20 +539,7 @@ threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId()); } // 添加到队列 ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale); // 邀请消息 userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale); executor.execute(new Runnable() { @Override public void run() { // 邀请金币 integralGetService.addInviteLevelOne(inviter.getId(), invitee.getId()); } }); inviteSuccess(inviter.getId(), invitee.getId(), threeSale); } @Override @@ -600,19 +590,28 @@ threeSale.setBoss(boss); threeSale.setWorker(invitee); // 添加到队列 ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale); inviteSuccess(boss.getId(), invitee.getId(), threeSale); } /** * 邀请成功 */ @Transactional private void inviteSuccess(Long bossId, Long workerId, ThreeSale threeSale) { // 邀请消息 userInviteMsgNotificationService.inviteSuccess(threeSale.getBoss().getId(), threeSale); executor.execute(new Runnable() { @Override public void run() { // 邀请金币 integralGetService.addInviteLevelOne(boss.getId(), invitee.getId()); integralGetService.addInviteLevelOne(bossId, workerId); } }); UserInviteMQMsg msg = new UserInviteMQMsg(bossId, workerId, null, new Date(), UserInviteMQMsg.STATE_SUCCESS); Message message = new Message(MQTopicName.TOPIC_USER.name(), UserTopicTagEnum.inviteSuccess.name(), new Gson().toJson(msg).getBytes()); producer.send(message); } /** fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -63,7 +63,6 @@ import com.yeshi.fanli.util.cmq.JDOrderCMQManager; import com.yeshi.fanli.util.cmq.PDDOrderCMQManager; import com.yeshi.fanli.util.cmq.PlaceOrderCMQManager; import com.yeshi.fanli.util.cmq.ThreeSaleCMQManager; import com.yeshi.fanli.util.cmq.UserMoneyChangeCMQManager; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; @@ -166,7 +165,6 @@ doOrderTiChengFanLi();// 处理订单提成返利 doWeiQuanOrder();// 处理维权订单 doPushIOS();// 处理发送IOS消息 doThreeSaleUserCouponJob();// 处理邀请队列 doUserMoneyDebtJob();// 债务偿还 initScheduler();// 启动商品更新定时任务 doUpdateGoodsJob(); // 更新商品队列 @@ -516,66 +514,6 @@ } /** * 邀请关系变化后券的更新 */ public void doThreeSaleUserCouponJob() { // 采用2个线程做更新 for (int i = 0; i < 2; i++) executor.execute(new Runnable() { @Override public void run() { while (true) { try { Map<String, ThreeSale> map = ThreeSaleCMQManager.getInstance() .consumeQueueMsg(ThreeSaleCMQManager.QUEUE_USER_COUPON, 16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { ThreeSale threeSale = map.get(key); if (threeSale != null) threeSale = threeSaleSerivce.selectByPrimaryKey(threeSale.getId()); if (threeSale != null) { if (threeSale.getState() != null && threeSale.getState() == true) { // 邀请成功 - 券激活生效 LogHelper.test("doThreeSaleUserCouponJob-" + threeSale.getId()); Long bossId = threeSale.getBoss().getId(); // 下级昵称 String workerNickName = userInfoService .selectByPKey(threeSale.getWorker().getId()).getNickName(); userSystemCouponService.activatedWelfareFreeCoupon(bossId, workerNickName); } } ThreeSaleCMQManager.getInstance() .deleteQueueMsg(ThreeSaleCMQManager.QUEUE_USER_COUPON, key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.error("更新商品出错:" + e.getMessage()); } } } }); } /** * 用户借贷处理 */ public void doUserMoneyDebtJob() { @@ -747,8 +685,8 @@ fanliGetIntegral(hongBaoV2); HongBaoRecieveCMQManager.getInstance() .deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key); //返利不足0.01元送金币 // 返利不足0.01元送金币 if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购 // 判断是否为该用户的首笔红包 List<Integer> typeList = new ArrayList<>(); fanli/src/main/java/com/yeshi/fanli/util/cmq/ThreeSaleCMQManager.java
File was deleted fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/redpack/RedPackMessageListener.java
New file @@ -0,0 +1,69 @@ package com.yeshi.fanli.util.rocketmq.consumer.redpack; import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.aliyun.openservices.ons.api.Action; import com.aliyun.openservices.ons.api.ConsumeContext; import com.aliyun.openservices.ons.api.Message; import com.aliyun.openservices.ons.api.MessageListener; import com.google.gson.Gson; import com.yeshi.fanli.dto.mq.BaseMQMsgBody; import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserRegisterMQMsg; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.rocketmq.MQTopicName; /** * 红包消费 * * @author Administrator * */ @Component public class RedPackMessageListener implements MessageListener { @Resource private UserSystemCouponService userSystemCouponService; @Override public Action consume(Message message, ConsumeContext context) { LogHelper.mqInfo("consumer-RedPackMessageListener", message.getTopic(), message.getTag(), new String(message.getBody())); String tag = message.getTag(); if (tag == null) tag = ""; BaseMQMsgBody baseBody = new Gson().fromJson(new String(message.getBody()), BaseMQMsgBody.class); if (baseBody.isTest() != Constant.IS_TEST) return Action.ReconsumeLater; if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) { if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {// 返利到账 } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 订单统计 } } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) { if (tag.equalsIgnoreCase(UserTopicTagEnum.userAccountBinding.name())) {// 账号绑定 UserAccountBindingMQMsg userAccountBindingMQMsg = new Gson().fromJson(new String(message.getBody()), UserAccountBindingMQMsg.class); } else if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteSuccess.name())) {// 邀请成功 UserInviteMQMsg userInviteMQMsg = new Gson().fromJson(new String(message.getBody()), UserInviteMQMsg.class); } else if (tag.equalsIgnoreCase(UserTopicTagEnum.integralTaskFinish.name())) {// 金币任务完成 IntegralTaskMQMsg integralTaskMQMsg = new Gson().fromJson(new String(message.getBody()), IntegralTaskMQMsg.class); } } return Action.CommitMessage; } } fanli/src/main/resource/env-dev/rocket/consumer.xml
@@ -68,7 +68,8 @@ <key> <bean class="com.aliyun.openservices.ons.api.bean.Subscription"> <property name="topic" value="TOPIC_ORDER" /> <property name="expression" value="banLiShopOrderDelay||banLiShopOrderPaid||banLiShopOrderRefund" /><!--expression <property name="expression" value="banLiShopOrderDelay||banLiShopOrderPaid||banLiShopOrderRefund" /><!--expression 即 Tag,可以设置成具体的 Tag,如 taga||tagb||tagc,也可设置成 *。 * 仅代表订阅所有 Tag,不支持通配 --> </bean> </key> @@ -77,5 +78,47 @@ </property> </bean> <!-- 红包消息订阅 --> <bean id="redPackMessageListener" class="com.yeshi.fanli.util.rocketmq.consumer.redpack.RedPackMessageListener"></bean> <!-- Group ID 订阅同一个 Topic,可以创建多个 ConsumerBean --> <bean id="redPackConsumer" class="com.aliyun.openservices.ons.api.bean.ConsumerBean" init-method="start" destroy-method="shutdown"> <property name="properties"> <!--消费者配置信息 --> <props> <prop key="AccessKey">LTAI4FwmTxVCuzTaoZtDiV8z</prop> <prop key="SecretKey">ixWg90QbYFKP6ae5xpAo2P1qwIyll5</prop> <prop key="GROUP_ID">GID_RED_PACK</prop> <prop key="NAMESRV_ADDR">http://MQ_INST_1205444665315884_BbaMbxF4.mq-internet-access.mq-internet.aliyuncs.com:80 </prop> <prop key="ConsumeThreadNums">50</prop> </props> </property> <property name="subscriptionTable"> <map> <!-- 产生订单,订单到账 --> <entry value-ref="redPackMessageListener"> <key> <bean class="com.aliyun.openservices.ons.api.bean.Subscription"> <property name="topic" value="TOPIC_ORDER" /> <property name="expression" value="orderStatistic||orderFanLiActual" /> </bean> </key> </entry> <!-- 用户注册,账号绑定,邀请好友 ,完成金币任务 --> <entry value-ref="redPackMessageListener"> <key> <bean class="com.aliyun.openservices.ons.api.bean.Subscription"> <property name="topic" value="TOPIC_USER" /> <property name="expression" value="inviteSuccess||userAccountBinding||integralTaskFinish" /> </bean> </key> </entry> </map> </property> </bean> </beans>