From b6853bf0a1411e39360f184b3bee5836010dbd22 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 27 十月 2020 17:35:18 +0800
Subject: [PATCH] CMQ接口优化
---
fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java | 852 ++++++++++++++++++++++++++------------------------------
1 files changed, 399 insertions(+), 453 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java
index c56924e..8f8dfe7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.service.impl.user.integral;
-import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -10,15 +9,15 @@
import javax.annotation.Resource;
+import com.yeshi.fanli.entity.SystemEnum;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
-import com.aliyun.openservices.ons.api.Producer;
import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
-import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.integral.IntegralDetail;
import com.yeshi.fanli.entity.integral.IntegralTask;
@@ -26,6 +25,7 @@
import com.yeshi.fanli.entity.integral.IntegralTaskClass;
import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
@@ -36,527 +36,473 @@
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
+import com.yeshi.fanli.service.manger.msg.RocketMQManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TimeUtil;
+import org.yeshi.utils.TimeUtil;
@Service
public class IntegralTaskRecordServiceImpl implements IntegralTaskRecordService {
- @Resource
- private IntegralTaskRecordMapper integralTaskRecordMapper;
+ @Resource
+ private IntegralTaskRecordMapper integralTaskRecordMapper;
- @Resource
- private UserInfoExtraService userInfoExtraService;
+ @Resource
+ private UserInfoExtraService userInfoExtraService;
- @Resource
- private IntegralDetailService integralDetailService;
+ @Resource
+ private IntegralDetailService integralDetailService;
- @Resource
- private IntegralTaskService integralTaskService;
+ @Resource
+ private IntegralTaskService integralTaskService;
- @Lazy
- @Resource
- private IntegralTaskClassService integralTaskClassService;
+ @Lazy
+ @Resource
+ private IntegralTaskClassService integralTaskClassService;
- @Resource
- private UserOtherMsgNotificationService userOtherMsgNotificationService;
+ @Resource
+ private UserOtherMsgNotificationService userOtherMsgNotificationService;
- @Resource
- private ConfigService configService;
+ @Resource
+ private ConfigService configService;
- @Resource(name = "producer")
- private Producer producer;
+ @Resource
+ private RocketMQManager rocketMQManager;
- @Override
- public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
- return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType);
- }
+ @Resource
+ private UserInfoService userInfoService;
- @Override
- public Integer countFinished(long uid, Long cid, Integer dateType) {
- return integralTaskRecordMapper.countFinished(uid, cid, dateType);
- }
+ @Override
+ public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
+ return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType);
+ }
- @Override
- public void invalidGoldCoin() {
- integralTaskRecordMapper.invalidGoldCoin();
- }
-
- @Override
- public void finishedTask(long uid, long cid, long taskId, int goldCoin) {
- IntegralTaskRecord taskRecord = new IntegralTaskRecord();
- taskRecord.setUid(uid);
- taskRecord.setCid(cid);
- taskRecord.setTaskId(taskId);
- taskRecord.setGoldCoin(goldCoin);
- taskRecord.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
- taskRecord.setCreateTime(new Date());
- taskRecord.setUpdateTime(new Date());
- integralTaskRecordMapper.insertSelective(taskRecord);
- }
+ @Override
+ public Integer countFinished(long uid, Long cid, Integer dateType) {
+ return integralTaskRecordMapper.countFinished(uid, cid, dateType);
+ }
- @Override
- public boolean isToDaySign(long uid, Long cid) {
- Integer countFinished = integralTaskRecordMapper.countFinished(uid, cid, 1);
- if (countFinished != null && countFinished > 0) {
- return true;
- }
- return false;
- }
+ @Override
+ public void invalidGoldCoin() {
+ integralTaskRecordMapper.invalidGoldCoin();
+ }
- @Override
- public Integer getNowdaySignNum(long uid, Long cid) {
- int num = 1;
- try {
- // 绛惧埌鏃堕棿鍊掑簭鏌ヨ杩�7澶╂暟鎹�
- List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
- if (list != null && list.size() > 0) {
- Date today = new Date();
- for (IntegralTaskRecord record : list) {
- if (DateUtil.daysBetween2(record.getCreateTime(), today) == 0) {
- continue;
- }
+ @Override
+ public void finishedTask(long uid, long cid, long taskId, int goldCoin) {
+ IntegralTaskRecord taskRecord = new IntegralTaskRecord();
+ taskRecord.setUid(uid);
+ taskRecord.setCid(cid);
+ taskRecord.setTaskId(taskId);
+ taskRecord.setGoldCoin(goldCoin);
+ taskRecord.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
+ taskRecord.setCreateTime(new Date());
+ taskRecord.setUpdateTime(new Date());
+ integralTaskRecordMapper.insertSelective(taskRecord);
+ }
- if (DateUtil.daysBetween2(record.getCreateTime(), today) != 1) {
- break; // 澶╂暟鏈繛缁�
- }
- today = record.getCreateTime();
- num++;
- }
- }
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- }
+ @Override
+ public boolean isToDaySign(long uid, Long cid) {
+ Integer countFinished = integralTaskRecordMapper.countFinished(uid, cid, 1);
+ if (countFinished != null && countFinished > 0) {
+ return true;
+ }
+ return false;
+ }
- if (num > 7) {
- num = 7;
- }
- return num;
- }
+ @Override
+ public Integer getNowdaySignNum(long uid, Long cid) {
+ int num = 1;
+ try {
+ // 绛惧埌鏃堕棿鍊掑簭鏌ヨ杩�7澶╂暟鎹�
+ List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
+ if (list != null && list.size() > 0) {
+ Date today = new Date();
+ for (IntegralTaskRecord record : list) {
+ if (DateUtil.daysBetween2(record.getCreateTime(), today) == 0) {
+ continue;
+ }
- @Override
- public List<IntegralTaskRecord> getSignDaysRecord(long uid, Long cid) {
- List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
- try {
- // 绛惧埌鏃堕棿姝e簭搴忔煡璇㈣繎7澶╂暟鎹�
- List<IntegralTaskRecord> list = integralTaskRecordMapper.listDateSignRecord(uid, cid);
- if (list != null && list.size() > 0) {
- Date date = new Date();
- for (IntegralTaskRecord record : list) {
- Date createTime = record.getCreateTime();
- if (DateUtil.daysBetween2(createTime, date) > 1) {
- break; // 澶╂暟鏈繛缁�
- }
- date = createTime;
- listRecord.add(record);
- }
- }
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- }
- return listRecord;
- }
+ if (DateUtil.daysBetween2(record.getCreateTime(), today) != 1) {
+ break; // 澶╂暟鏈繛缁�
+ }
+ today = record.getCreateTime();
+ num++;
+ }
+ }
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
+ }
- @Override
- public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
- List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
- try {
- // 绛惧埌鏃堕棿姝e簭搴忔煡璇㈣繎7澶╂暟鎹�
- List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
- if (list != null && list.size() > 0) {
- Date date = new Date();
- for (IntegralTaskRecord record : list) {
- Date createTime = record.getCreateTime();
- if (DateUtil.daysBetween2(createTime, date) > 1) {
- break; // 澶╂暟鏈繛缁�
- }
- date = createTime;
- listRecord.add(record);
+ if (num > 7) {
+ num = 7;
+ }
+ return num;
+ }
- if (listRecord.size() >= 7)
- break;
- }
- }
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- }
- return listRecord;
- }
+ @Override
+ public List<IntegralTaskRecord> getSignDaysRecord(long uid, Long cid) {
+ List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
+ try {
+ // 绛惧埌鏃堕棿姝e簭搴忔煡璇㈣繎7澶╂暟鎹�
+ List<IntegralTaskRecord> list = integralTaskRecordMapper.listDateSignRecord(uid, cid);
+ if (list != null && list.size() > 0) {
+ Date date = new Date();
+ for (IntegralTaskRecord record : list) {
+ Date createTime = record.getCreateTime();
+ if (DateUtil.daysBetween2(createTime, date) > 1) {
+ break; // 澶╂暟鏈繛缁�
+ }
+ date = createTime;
+ listRecord.add(record);
+ }
+ }
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
+ }
+ return listRecord;
+ }
- @Override
- public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
- return integralTaskRecordMapper.listNotReceived(count, uid);
- }
+ @Override
+ public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
+ List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
+ try {
+ // 绛惧埌鏃堕棿姝e簭搴忔煡璇㈣繎7澶╂暟鎹�
+ List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
+ if (list != null && list.size() > 0) {
+ Date date = new Date();
+ for (IntegralTaskRecord record : list) {
+ Date createTime = record.getCreateTime();
+ if (DateUtil.daysBetween2(createTime, date) > 1) {
+ break; // 澶╂暟鏈繛缁�
+ }
+ date = createTime;
+ listRecord.add(record);
- @Override
- public List<IntegralTaskRecord> listNotReceivedExcludeId(int count, long uid, Set<Long> idList) {
- if (idList != null && idList.size() == 0) {
- idList = null;
- }
- return integralTaskRecordMapper.listNotReceivedExcludeId(count, uid, idList);
- }
+ if (listRecord.size() >= 7)
+ break;
+ }
+ }
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
+ }
+ return listRecord;
+ }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
- UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
- if (userInfoExtra == null)
- throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
+ @Override
+ public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
+ return integralTaskRecordMapper.listNotReceived(count, uid);
+ }
- List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
- if (list == null || list.size() == 0)
- throw new IntegralTaskRecordException(1, "鏆傛棤鍙鍙�");
+ @Override
+ public List<IntegralTaskRecord> listNotReceivedExcludeId(int count, long uid, Set<Long> idList) {
+ if (idList != null && idList.size() == 0) {
+ idList = null;
+ }
+ return integralTaskRecordMapper.listNotReceivedExcludeId(count, uid, idList);
+ }
- Integer totalGoldCoin = 0;
- for (IntegralTaskRecord record : list) {
- if (addDetail(uid, record))
- totalGoldCoin += record.getGoldCoin();
- }
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
+ UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
+ if (userInfoExtra == null)
+ throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
- // 鏇存柊閲戝竵
- userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
+ List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
+ if (list == null || list.size() == 0)
+ throw new IntegralTaskRecordException(1, "鏆傛棤鍙鍙�");
- return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
- }
+ Integer totalGoldCoin = 0;
+ for (IntegralTaskRecord record : list) {
+ if (addDetail(uid, record))
+ totalGoldCoin += record.getGoldCoin();
+ }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Integer receiveGoldCoin(Long uid, Set<Long> idList) throws IntegralTaskRecordException {
- if (idList == null || idList.size() == 0) {
- throw new IntegralTaskRecordException(1, "id涓虹┖");
- }
+ // 鏇存柊閲戝竵
+ userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
- UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
- if (userInfoExtra == null) {
- throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
- }
+ return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
+ }
- Integer totalGoldCoin = 0;
- for (Long id : idList) {
- IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
- if (record == null)
- continue;
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Integer receiveGoldCoin(Long uid, Set<Long> idList) throws IntegralTaskRecordException {
+ if (idList == null || idList.size() == 0) {
+ throw new IntegralTaskRecordException(1, "id涓虹┖");
+ }
- // 宸查鍙�
- Integer state = record.getState();
- if (state != null && state != 0)
- continue;
+ UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
+ if (userInfoExtra == null) {
+ throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
+ }
- if (addDetail(uid, record))
- totalGoldCoin += record.getGoldCoin();
- }
+ Integer totalGoldCoin = 0;
+ for (Long id : idList) {
+ IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
+ if (record == null)
+ continue;
- // 鏇存柊閲戝竵
- userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
+ // 宸查鍙�
+ Integer state = record.getState();
+ if (state != null && state != 0)
+ continue;
- return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
- }
+ if (addDetail(uid, record))
+ totalGoldCoin += record.getGoldCoin();
+ }
- @Transactional(rollbackFor = Exception.class)
- public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
- Long uid2 = record.getUid();
- if (uid2 == null || uid.longValue() != uid2.longValue())
- return false; // 鐢ㄦ埛id涓嶇鍚�
+ // 鏇存柊閲戝竵
+ userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
- if (record.getState() != null && record.getState().intValue() == 1) {
- return false; // 宸查鍙�
- }
+ return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
+ }
- IntegralTaskRecord taskRecord = new IntegralTaskRecord();
- taskRecord.setId(record.getId());
- taskRecord.setState(1); // 宸查鍙�
- taskRecord.setUpdateTime(new Date());
- integralTaskRecordMapper.updateByPrimaryKeySelective(taskRecord);
+ @Transactional(rollbackFor = Exception.class)
+ public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
+ Long uid2 = record.getUid();
+ if (uid2 == null || uid.longValue() != uid2.longValue())
+ return false; // 鐢ㄦ埛id涓嶇鍚�
- Long cid = record.getCid();
- if (cid == null)
- return false;
+ if (record.getState() != null && record.getState().intValue() == 1) {
+ return false; // 宸查鍙�
+ }
- IntegralTaskClass taskClass = integralTaskClassService.selectByPrimaryKey(cid);
- if (taskClass == null)
- return false;
+ IntegralTaskRecord taskRecord = new IntegralTaskRecord();
+ taskRecord.setId(record.getId());
+ taskRecord.setState(1); // 宸查鍙�
+ taskRecord.setUpdateTime(new Date());
+ integralTaskRecordMapper.updateByPrimaryKeySelective(taskRecord);
- Long taskId = record.getTaskId();
- if (taskId == null)
- return false;
+ Long cid = record.getCid();
+ if (cid == null)
+ return false;
- IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
- if (integralTask == null)
- return false;
+ IntegralTaskClass taskClass = integralTaskClassService.selectByPrimaryKey(cid);
+ if (taskClass == null)
+ return false;
- // 鍔犲叆鏄庣粏
- IntegralDetail detail = new IntegralDetail();
- if (UniqueKeyEnum.dailySign == taskClass.getUniqueKey()) {
- SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
- Date recordTime = record.getCreateTime();
- List<IntegralTaskRecord> list = integralTaskRecordMapper.listSignRecordByDateTime(uid, cid,
- format.format(recordTime));
- int num = 1;
- if (list != null && list.size() > 0) {
- try {
- Date nextDate = null;
- for (IntegralTaskRecord tntegralTaskRecord : list) {
- if (nextDate == null) {
- nextDate = tntegralTaskRecord.getCreateTime();
- continue;
- }
+ Long taskId = record.getTaskId();
+ if (taskId == null)
+ return false;
- if (DateUtil.daysBetween2(tntegralTaskRecord.getCreateTime(), nextDate) != 1) {
- break; // 澶╂暟鏈繛缁�
- }
- nextDate = tntegralTaskRecord.getCreateTime();
- num++;
- }
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- detail.setTitle(taskClass.getName() + "-绗�" + num + "澶�");
- } else {
- FrequencyEnum frequency = integralTask.getFrequency();
- if (frequency == FrequencyEnum.everyday) {
- int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
- TimeUtil.getWholeTime(record.getCreateTime().getTime()), record.getId());
- if (num <= 0)
- num = 1;
- String title = taskClass.getName() + "-" + integralTask.getName() + "-绗�" + num + "娆�";
- detail.setTitle(title);
- } else if (frequency == FrequencyEnum.onlyOne) {
- String title = taskClass.getName() + "-" + integralTask.getName();
- detail.setTitle(title);
- }
- }
-
- detail.setUid(uid);
- detail.setMoney(record.getGoldCoin());
- detail.setCreateTime(record.getCreateTime());
- integralDetailService.insertSelective(detail);
-
- return true;
- }
-
- @Override
- public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
- Date minTime = null;
- Date maxTime = null;
- if (day == null) {
- minTime = new Date(TimeUtil.convertToTimeTemp("1970-01-01", "yyyy-MM-dd"));
- maxTime = new Date(TimeUtil.convertToTimeTemp("2100-01-01", "yyyy-MM-dd"));
- } else {
- minTime = new Date(
- TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
- maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
- }
- return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
- }
+ IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
+ if (integralTask == null)
+ return false;
- @Transactional(rollbackFor = Exception.class)
- @Override
- public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
- if (record == null)
- throw new IntegralTaskRecordException(1, "璁板綍涓虹┖");
+ // 鍔犲叆鏄庣粏
+ IntegralDetail detail = new IntegralDetail();
+ if (UniqueKeyEnum.dailySign == taskClass.getUniqueKey()) {
+ SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
+ Date recordTime = record.getCreateTime();
+ List<IntegralTaskRecord> list = integralTaskRecordMapper.listSignRecordByDateTime(uid, cid,
+ format.format(recordTime));
+ int num = 1;
+ if (list != null && list.size() > 0) {
+ try {
+ Date nextDate = null;
+ for (IntegralTaskRecord tntegralTaskRecord : list) {
+ if (nextDate == null) {
+ nextDate = tntegralTaskRecord.getCreateTime();
+ continue;
+ }
- if (record.getCid() == null || record.getTaskId() == null || record.getGoldCoin() == null
- || record.getState() == null || record.getUid() == null)
- throw new IntegralTaskRecordException(2, "鏁版嵁涓嶅畬鎴�");
- Date date = new Date();
- if (record.getCreateTime() == null)
- record.setCreateTime(date);
+ if (DateUtil.daysBetween2(tntegralTaskRecord.getCreateTime(), nextDate) != 1) {
+ break; // 澶╂暟鏈繛缁�
+ }
+ nextDate = tntegralTaskRecord.getCreateTime();
+ num++;
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ detail.setTitle(taskClass.getName() + "-绗�" + num + "澶�");
+ } else {
+ FrequencyEnum frequency = integralTask.getFrequency();
+ if (frequency == FrequencyEnum.everyday) {
+ int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
+ TimeUtil.getWholeTime(record.getCreateTime().getTime()), record.getId());
+ if (num <= 0)
+ num = 1;
+ String title = taskClass.getName() + "-" + integralTask.getName() + "-绗�" + num + "娆�";
+ detail.setTitle(title);
+ } else if (frequency == FrequencyEnum.onlyOne) {
+ String title = taskClass.getName() + "-" + integralTask.getName();
+ detail.setTitle(title);
+ }
+ }
- if (record.getUpdateTime() == null)
- record.setUpdateTime(date);
-
- // 璁剧疆鏈夋晥鏈�
- record.setEndTime(DateUtil.plusDayDate(Constant.GOLD_COIN_VALID_DAYS, date));
- integralTaskRecordMapper.insertSelective(record);
- return record;
- }
+ detail.setUid(uid);
+ detail.setMoney(record.getGoldCoin());
+ detail.setCreateTime(record.getCreateTime());
+ integralDetailService.insertSelective(detail);
- @Override
- public List<IntegralTaskRecord> listByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime,
- int page, int count) {
- return integralTaskRecordMapper.listByCidAndUidAndCreateTime(cid, uid, minTime, maxTime, (page - 1) * count,
- count);
- }
+ return true;
+ }
- @Override
- public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
- return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
- }
+ @Override
+ public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
+ Date minTime = null;
+ Date maxTime = null;
+ if (day == null) {
+ minTime = new Date(TimeUtil.convertToTimeTemp("1970-01-01", "yyyy-MM-dd"));
+ maxTime = new Date(TimeUtil.convertToTimeTemp("2100-01-01", "yyyy-MM-dd"));
+ } else {
+ minTime = new Date(
+ TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
+ maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
+ }
+ return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
+ }
- @Override
- public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
- return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
- }
+ @Transactional(rollbackFor = Exception.class)
+ @Override
+ public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
+ if (record == null)
+ throw new IntegralTaskRecordException(1, "璁板綍涓虹┖");
+ if (record.getCid() == null || record.getTaskId() == null || record.getGoldCoin() == null
+ || record.getState() == null || record.getUid() == null)
+ throw new IntegralTaskRecordException(2, "鏁版嵁涓嶅畬鎴�");
+ Date date = new Date();
+ if (record.getCreateTime() == null)
+ record.setCreateTime(date);
- @Async()
- @Override
- public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
- if (uid == null || originUid == null)
- return;
+ if (record.getUpdateTime() == null)
+ record.setUpdateTime(date);
- String reward = configService.get("first_order_reward_boss");
- if (StringUtil.isNullOrEmpty(reward))
- return;
- firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
- }
+ // 璁剧疆鏈夋晥鏈�
+ record.setEndTime(DateUtil.plusDayDate(Constant.GOLD_COIN_VALID_DAYS, date));
+ integralTaskRecordMapper.insertSelective(record);
+ return record;
+ }
- @Async()
- @Override
- public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
- if (uid == null || originUid == null)
- return;
+ @Override
+ public List<IntegralTaskRecord> listByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime,
+ int page, int count) {
+ return integralTaskRecordMapper.listByCidAndUidAndCreateTime(cid, uid, minTime, maxTime, (page - 1) * count,
+ count);
+ }
- String reward = configService.get("first_order_reward_boss_super");
- if (StringUtil.isNullOrEmpty(reward))
- return;
- firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
- }
+ @Override
+ public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
+ return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
+ }
- @Async()
- @Override
- public void firstShareOrderReward(Long uid, String beizu) {
- if (uid == null)
- return;
+ @Override
+ public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
+ return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
+ }
- String reward = configService.get("first_share_order_reward");
- if (StringUtil.isNullOrEmpty(reward))
- return;
- firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
- }
- @Async()
- @Override
- public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
- if (uid == null || originUid == null)
- return;
+ @Async()
+ @Override
+ public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
+ if (uid == null || originUid == null)
+ return;
- String reward = configService.get("first_share_order_reward_boss");
- if (StringUtil.isNullOrEmpty(reward))
- return;
- firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
- }
+ SystemEnum system = userInfoService.getUserSystem(uid);
- /**
- * 闃熷憳棣栧崟濂栧姳閲戝竵
- *
- * @param uid
- * @param addGoldCoin
- * @param level
- * 鎵�灞炲摢绾ч槦鍛�
- * @param beizu
- */
- private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
- String uniqueKey = "firstOrder-" + uid.toString();
- if (originUid != null)
- uniqueKey = uniqueKey + "-" + originUid;
+ String reward = configService.getValue(ConfigKeyEnum.firstOrderRewardBoss.getKey(), system);
+ if (StringUtil.isNullOrEmpty(reward))
+ return;
+ firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+ }
- // 鍒ゆ柇鏄惁宸查鍙�
- IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
- if (detailRecord != null)
- return;
+ @Async()
+ @Override
+ public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
+ if (uid == null || originUid == null)
+ return;
+ SystemEnum system = userInfoService.getUserSystem(uid);
+ String reward = configService.getValue(ConfigKeyEnum.firstOrderRewardBossSuper.getKey(),system);
+ if (StringUtil.isNullOrEmpty(reward))
+ return;
+ firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
+ }
- UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
- if (userInfoExtra == null)
- return;
+ @Async()
+ @Override
+ public void firstShareOrderReward(Long uid, String beizu) {
+ if (uid == null)
+ return;
+ SystemEnum system = userInfoService.getUserSystem(uid);
+ String reward = configService.getValue(ConfigKeyEnum.firstShareOrderReward.getKey(),system);
+ if (StringUtil.isNullOrEmpty(reward))
+ return;
+ //firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
+ }
- int totalGoldCoin = 0;
- try {
- UserInfoExtra extra = new UserInfoExtra();
- extra.setId(userInfoExtra.getId());
- Integer goldCoin = userInfoExtra.getGoldCoin();
- if (goldCoin == null) {
- extra.setGoldCoin(addGoldCoin);
- } else {
- extra.setGoldCoin(goldCoin + addGoldCoin);
- }
- userInfoExtraService.saveUserInfoExtra(extra);
- totalGoldCoin = extra.getGoldCoin();
- } catch (UserInfoExtraException e) {
- LogHelper.errorDetailInfo(e);
- return;
- }
+ @Async()
+ @Override
+ public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
+ if (uid == null || originUid == null)
+ return;
+ SystemEnum system = userInfoService.getUserSystem(uid);
+ String reward = configService.getValue(ConfigKeyEnum.firstShareOrderRewardBoss.getKey(),system);
+ if (StringUtil.isNullOrEmpty(reward))
+ return;
+ firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+ }
- // 閲戝竵璇︽儏
- IntegralDetail detail = new IntegralDetail();
- detail.setTitle("閲戝竵濂栧姳");
- detail.setUid(uid);
- detail.setMoney(addGoldCoin);
- detail.setRemark(beizu);
- detail.setUniqueKey(uniqueKey);
- detail.setCreateTime(new Date());
- integralDetailService.insertSelective(detail);
+ /**
+ * 闃熷憳棣栧崟濂栧姳閲戝竵
+ *
+ * @param uid
+ * @param addGoldCoin
+ * @param level 鎵�灞炲摢绾ч槦鍛�
+ * @param beizu
+ */
+ private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
+ String uniqueKey = "firstOrder-" + uid.toString();
+ if (originUid != null)
+ uniqueKey = uniqueKey + "-" + originUid;
- // 娑堟伅
- MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
- msgOther.setTitle("閲戝竵濂栧姳");
- msgOther.setNum(addGoldCoin + "閲戝竵");
- msgOther.setTotal(totalGoldCoin + "閲戝竵");
- if (StringUtil.isNullOrEmpty(level)) {
- msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� ");
- msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 ");
- } else {
- if (level.equalsIgnoreCase("涓�") || level.equalsIgnoreCase("1"))
- msgOther.setSource("鐩存帴绮変笣棣栨涓嬪崟锛岀郴缁熷鍔遍噾甯� ");
- else
- msgOther.setSource("闂存帴绮変笣棣栨涓嬪崟锛岀郴缁熷鍔遍噾甯� ");
- msgOther.setExplain("浠呮柊閭�璇风矇涓濋涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 ");
- }
- userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
- }
+ // 鍒ゆ柇鏄惁宸查鍙�
+ IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
+ if (detailRecord != null)
+ return;
- /**
- * 鎺ㄥ箍绾㈠寘鎶樼畻閲戝竵
- *
- * @param uid
- * @param addGoldCoin
- * @param tlj
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void taoLiJinExchange(Long uid, Integer addGoldCoin, BigDecimal tlj) {
- String uniqueKey = "taoLiJinExchange-" + uid.toString();
- IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
- if (detailRecord != null)
- return;
+ UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+ if (userInfoExtra == null)
+ return;
- UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
- if (userInfoExtra == null)
- return;
+ int totalGoldCoin = 0;
+ try {
+ UserInfoExtra extra = new UserInfoExtra();
+ extra.setId(userInfoExtra.getId());
+ Integer goldCoin = userInfoExtra.getGoldCoin();
+ if (goldCoin == null) {
+ extra.setGoldCoin(addGoldCoin);
+ } else {
+ extra.setGoldCoin(goldCoin + addGoldCoin);
+ }
+ userInfoExtraService.saveUserInfoExtra(extra);
+ totalGoldCoin = extra.getGoldCoin();
+ } catch (UserInfoExtraException e) {
+ LogHelper.errorDetailInfo(e);
+ return;
+ }
- Integer goldCoin = userInfoExtra.getGoldCoin();
- if (goldCoin == null)
- goldCoin = 0;
- goldCoin = goldCoin + addGoldCoin;
+ // 閲戝竵璇︽儏
+ IntegralDetail detail = new IntegralDetail();
+ detail.setTitle("閲戝竵濂栧姳");
+ detail.setUid(uid);
+ detail.setMoney(addGoldCoin);
+ detail.setRemark(beizu);
+ detail.setUniqueKey(uniqueKey);
+ detail.setCreateTime(new Date());
+ integralDetailService.insertSelective(detail);
- try {
- UserInfoExtra extra = new UserInfoExtra();
- extra.setId(userInfoExtra.getId());
- extra.setGoldCoin(goldCoin);
- userInfoExtraService.saveUserInfoExtra(extra);
- } catch (UserInfoExtraException e) {
- LogHelper.errorDetailInfo(e);
- return;
- }
+ // 娑堟伅
+ if (level.equalsIgnoreCase("涓�") || level.equalsIgnoreCase("1")) {
+ // 鐩存帴绮変笣
+ userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, true);
+ } else {
+ // 闂存帴绮変笣
+ userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, false);
+ }
- // 閲戝竵璇︽儏
- IntegralDetail detail = new IntegralDetail();
- detail.setTitle("鎺ㄥ箍绾㈠寘涓嬬嚎-绯荤粺鎶樼畻鎴愰噾甯�");
- detail.setUid(uid);
- detail.setMoney(addGoldCoin);
- detail.setUniqueKey(uniqueKey);
- detail.setCreateTime(new Date());
- integralDetailService.insertSelective(detail);
+ }
- // 娑堟伅
- MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
- msgOther.setTitle("鎺ㄥ箍绾㈠寘");
- msgOther.setTotal("鎺ㄥ箍绾㈠寘楼" + tlj.setScale(2));
- msgOther.setNum(addGoldCoin + "鏋�");
- msgOther.setSource("宸茶繘鍏ュ埌鍙敤閲戝竵涓�");
- msgOther.setExplain("鍘熸帹骞跨孩鍖呭姛鑳戒笅绾匡紝鍓╀綑鎺ㄥ箍绾㈠寘鎸夌収10:1鎶樼畻涓洪噾甯� ");
- userOtherMsgNotificationService.taoLiJinExchangeMsg(uid, "鏈姌绠楁湁涓斾粎鏈変竴娆�", msgOther);
- }
}
--
Gitblit v1.8.0