Commit 03fee680 authored by hezhen's avatar hezhen

Merge branch 'dev' of http://113.105.137.151:22280/youjj/cloud-platform into dev

parents 4d0f80a0 1ccd7073
...@@ -86,83 +86,86 @@ public class ActivityPopularizeBiz extends BaseBiz<ActivityPopularizeMapper, Act ...@@ -86,83 +86,86 @@ public class ActivityPopularizeBiz extends BaseBiz<ActivityPopularizeMapper, Act
}}); }});
log.info("活动邀请注册:activityPopularize = {}", activityPopularize.toString()); log.info("活动邀请注册:activityPopularize = {}", activityPopularize.toString());
if (activityPopularize != null) { if (activityPopularize != null) {
String lockKey = String.format("%s%d:%s:%d",registerQueueDTO.getInParamDTO().getActivityCode(), registerQueueDTO.getAppUserId(), registerQueueDTO.getInParamDTO().getUsername(), activityPopularize.getId()); String lockKey = String.format("%s%d%d", registerQueueDTO.getInParamDTO().getActivityCode(), appUserDTO.getInviterAccount(), activityPopularize.getId());
RLock rLock = redissonLock.getRLock(lockKey); RLock rLock = redissonLock.getRLock(lockKey);
try { try {
boolean isSuccess = rLock.tryLock(5, 5, TimeUnit.SECONDS); boolean isSuccess = rLock.tryLock(5, 5, TimeUnit.SECONDS);
if (isSuccess) { if (isSuccess) {
List<ActivityPopularizeItem> activityPopularizeItems = activityPopularizeItemBiz.selectByPopularizeId(activityPopularize.getId()); log.info("1, {}", System.currentTimeMillis());
ActivityPopularizeItem activityPopularizeItem = activityPopularizeItems.get(activityPopularizeItems.size() - 1); Thread.sleep(1000);
Date now = DateUtil.date(); log.info("2, {}", System.currentTimeMillis());
Date start = DateUtil.date(activityPopularize.getStartTime()); List<ActivityPopularizeItem> activityPopularizeItems = activityPopularizeItemBiz.selectByPopularizeId(activityPopularize.getId());
Date end = DateUtil.date(activityPopularize.getEndTime()); ActivityPopularizeItem activityPopularizeItem = activityPopularizeItems.get(activityPopularizeItems.size() - 1);
Date now = DateUtil.date();
//判断是否活动超时 Date start = DateUtil.date(activityPopularize.getStartTime());
if (now.before(start) || now.after(end)) { Date end = DateUtil.date(activityPopularize.getEndTime());
log.error("不在活动范围内 入参Json:" + JSONUtil.toJsonStr(registerQueueDTO));
return; //判断是否活动超时
} if (now.before(start) || now.after(end)) {
log.error("不在活动范围内 入参Json:" + JSONUtil.toJsonStr(registerQueueDTO));
return;
}
Integer majorUserId = Integer.valueOf(appUserDTO.getInviterAccount()); Integer majorUserId = Integer.valueOf(appUserDTO.getInviterAccount());
ActivityPopularizeRelation activityPopularizeRelation = new ActivityPopularizeRelation() {{ ActivityPopularizeRelation activityPopularizeRelation = new ActivityPopularizeRelation() {{
setMajorUserId(majorUserId); setMajorUserId(majorUserId);
setPopularizeId(activityPopularize.getId()); setPopularizeId(activityPopularize.getId());
}}; }};
//新增第几个邀请人和邀请金额字段 //新增第几个邀请人和邀请金额字段
Integer num = relationBiz.getByUserIdAndPopularizeId(activityPopularizeRelation); Integer num = relationBiz.getByUserIdAndPopularizeId(activityPopularizeRelation);
double amount = 0; double amount = 0;
JSONObject jsonObject = JSONObject.parseObject(activityPopularizeItem.getDetail()); JSONObject jsonObject = JSONObject.parseObject(activityPopularizeItem.getDetail());
if (jsonObject != null && StringUtils.isNotBlank(jsonObject.getString("detail"))) { if (jsonObject != null && StringUtils.isNotBlank(jsonObject.getString("detail"))) {
JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("detail")); JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("detail"));
if (jsonArray != null) { if (jsonArray != null) {
JSONObject jsonObject1 = jsonArray.getJSONObject(num - 1); JSONObject jsonObject1 = jsonArray.getJSONObject(num - 1);
if (jsonObject1 != null) { if (jsonObject1 != null) {
double amountString = jsonObject1.getDouble("amount"); double amountString = jsonObject1.getDouble("amount");
amount = amount + amountString; amount = amount + amountString;
}
}
}
double a = amount;
//添加活动关系
relationBiz.insertSelective(new ActivityPopularizeRelation() {{
setPopularizeId(activityPopularize.getId());
setMajorUserId(majorUserId);
setMinorUserId(appUserDTO.getUserid());
setNum(num);
setAmount(new BigDecimal(a));
}});
ApLogDTO apLogDTO = popularizeLogBiz.selectOneApLogDTO(new ActivityPopularizeLog() {{
setUserId(majorUserId);
setItemId(activityPopularizeItem.getId());
}});
//生成任务项
if (null == apLogDTO) {
popularizeLogBiz.insertSelectiveRe(new ActivityPopularizeLog() {{
setItemId(activityPopularizeItem.getId());
setUserId(majorUserId);
setStatus(SYS_FALSE);
setPopularizeId(activityPopularize.getId());
}});
} }
}
}
double a = amount;
//添加活动关系
relationBiz.insertSelective(new ActivityPopularizeRelation() {{
setPopularizeId(activityPopularize.getId());
setMajorUserId(majorUserId);
setMinorUserId(appUserDTO.getUserid());
setNum(num);
setAmount(new BigDecimal(a));
}});
ApLogDTO apLogDTO = popularizeLogBiz.selectOneApLogDTO(new ActivityPopularizeLog() {{
setUserId(majorUserId);
setItemId(activityPopularizeItem.getId());
}});
//生成任务项
if (null == apLogDTO) {
popularizeLogBiz.insertSelectiveRe(new ActivityPopularizeLog() {{
setItemId(activityPopularizeItem.getId());
setUserId(majorUserId);
setStatus(SYS_FALSE);
setPopularizeId(activityPopularize.getId());
}});
}
//查出majorUser参与活动信息 //查出majorUser参与活动信息
ActivityPopularizeUser activityPopularizeUser = popularizeUserBiz.selectOne(new ActivityPopularizeUser() {{ ActivityPopularizeUser activityPopularizeUser = popularizeUserBiz.selectOne(new ActivityPopularizeUser() {{
setUserId(majorUserId); setUserId(majorUserId);
setPopularizeId(activityPopularize.getId()); setPopularizeId(activityPopularize.getId());
}}); }});
double currentProgress = activityPopularizeUser.getCurrentProgress().doubleValue(); double currentProgress = activityPopularizeUser.getCurrentProgress().doubleValue();
log.info("用户原活动进度:currentProgress = {}", currentProgress); log.info("用户原活动进度:currentProgress = {}", currentProgress);
currentProgress += Double.parseDouble(a + ""); currentProgress += Double.parseDouble(a + "");
BigDecimal bigDecimal = new BigDecimal(currentProgress); BigDecimal bigDecimal = new BigDecimal(currentProgress);
log.info("用户现活动进度:newCurrentProgress = {}", currentProgress); log.info("用户现活动进度:newCurrentProgress = {}", currentProgress);
//修改当前进度 //修改当前进度
activityPopularizeUser.setCurrentProgress(bigDecimal); activityPopularizeUser.setCurrentProgress(bigDecimal);
popularizeUserBiz.updateSelectiveById(activityPopularizeUser); popularizeUserBiz.updateSelectiveById(activityPopularizeUser);
//任务没有完成 加锁 //任务没有完成 加锁
if (!SYS_TRUE.equals(activityPopularizeUser.getStatus())) { if (!SYS_TRUE.equals(activityPopularizeUser.getStatus())) {
// AwardDTO awardDTO = JSONUtil.toBean(activityPopularize.getValue(), AwardDTO.class); // AwardDTO awardDTO = JSONUtil.toBean(activityPopularize.getValue(), AwardDTO.class);
...@@ -196,6 +199,8 @@ public class ActivityPopularizeBiz extends BaseBiz<ActivityPopularizeMapper, Act ...@@ -196,6 +199,8 @@ public class ActivityPopularizeBiz extends BaseBiz<ActivityPopularizeMapper, Act
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("tryLock fail, key = [{}]", lockKey); log.error("tryLock fail, key = [{}]", lockKey);
} finally {
log.info("执行结束, {}", System.currentTimeMillis());
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment