From dc5be7d38446f70e6ff86df311119c32b41fe7f8 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 28 十一月 2020 16:37:05 +0800
Subject: [PATCH] 大淘客搜索接口升级

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java |  786 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 403 insertions(+), 383 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 2722005..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
@@ -9,6 +9,8 @@
 
 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;
@@ -16,7 +18,6 @@
 import org.yeshi.utils.DateUtil;
 
 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;
@@ -24,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;
@@ -34,455 +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;
 
-	@Override
-	public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
-		return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType);
-	}
+    @Resource
+    private RocketMQManager rocketMQManager;
 
-	@Override
-	public Integer countFinished(long uid, Long cid, Integer dateType) {
-		return integralTaskRecordMapper.countFinished(uid, cid, dateType);
-	}
+    @Resource
+    private UserInfoService userInfoService;
 
-	@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(0);
-		taskRecord.setCreateTime(new Date());
-		taskRecord.setUpdateTime(new Date());
-		integralTaskRecordMapper.insertSelective(taskRecord);
-	}
+    @Override
+    public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
+        return integralTaskRecordMapper.getTotalGoldCoin(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 Integer countFinished(long uid, Long cid, Integer dateType) {
+        return integralTaskRecordMapper.countFinished(uid, cid, dateType);
+    }
 
-	@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 invalidGoldCoin() {
+        integralTaskRecordMapper.invalidGoldCoin();
+    }
 
-					if (DateUtil.daysBetween2(record.getCreateTime(), today) != 1) {
-						break; // 澶╂暟鏈繛缁�
-					}
-					today = record.getCreateTime();
-					num++;
-				}
-			}
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-		}
+    @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 (num > 7) {
-			num = 7;
-		}
-		return num;
-	}
+    @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 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 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> 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 (DateUtil.daysBetween2(record.getCreateTime(), today) != 1) {
+                        break; // 澶╂暟鏈繛缁�
+                    }
+                    today = record.getCreateTime();
+                    num++;
+                }
+            }
+        } catch (Exception e) {
+            LogHelper.errorDetailInfo(e);
+        }
 
-					if (listRecord.size() >= 7)
-						break;
-				}
-			}
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-		}
-		return listRecord;
-	}
+        if (num > 7) {
+            num = 7;
+        }
+        return num;
+    }
 
-	@Override
-	public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
-		return integralTaskRecordMapper.listNotReceived(count, uid);
-	}
+    @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> listNotReceivedExcludeId(int count, long uid, Set<Long> idList) {
-		if (idList != null && idList.size() == 0) {
-			idList = null;
-		}
-		return integralTaskRecordMapper.listNotReceivedExcludeId(count, uid, idList);
-	}
+    @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
-	@Transactional(rollbackFor = Exception.class)
-	public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
-		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
-		if (userInfoExtra == null)
-			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
+                    if (listRecord.size() >= 7)
+                        break;
+                }
+            }
+        } catch (Exception e) {
+            LogHelper.errorDetailInfo(e);
+        }
+        return listRecord;
+    }
 
-		List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
-		if (list == null || list.size() == 0)
-			throw new IntegralTaskRecordException(1, "鏆傛棤鍙鍙�");
+    @Override
+    public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
+        return integralTaskRecordMapper.listNotReceived(count, uid);
+    }
 
-		Integer totalGoldCoin = 0;
-		for (IntegralTaskRecord record : list) {
-			if (addDetail(uid, record))
-				totalGoldCoin += record.getGoldCoin();
-		}
+    @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);
+    }
 
-		// 鏇存柊閲戝竵
-		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
+        UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
+        if (userInfoExtra == null)
+            throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
 
-		return (userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()) + totalGoldCoin;
-	}
+        List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
+        if (list == null || list.size() == 0)
+            throw new IntegralTaskRecordException(1, "鏆傛棤鍙鍙�");
 
-	@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 totalGoldCoin = 0;
+        for (IntegralTaskRecord record : list) {
+            if (addDetail(uid, record))
+                totalGoldCoin += record.getGoldCoin();
+        }
 
-		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
-		if (userInfoExtra == null) {
-			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
-		}
+        // 鏇存柊閲戝竵
+        userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
 
-		Integer totalGoldCoin = 0;
-		for (Long id : idList) {
-			IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
-			if (record == null)
-				continue;
+        return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
+    }
 
-			// 宸查鍙�
-			Integer state = record.getState();
-			if (state != null && state == 1)
-				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涓虹┖");
+        }
 
-			if (addDetail(uid, record))
-				totalGoldCoin += record.getGoldCoin();
-		}
+        UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
+        if (userInfoExtra == null) {
+            throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
+        }
 
-		// 鏇存柊閲戝竵
-		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
+        Integer totalGoldCoin = 0;
+        for (Long id : idList) {
+            IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
+            if (record == null)
+                continue;
 
-		return totalGoldCoin+(userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin());
-	}
+            // 宸查鍙�
+            Integer state = record.getState();
+            if (state != null && state != 0)
+                continue;
 
-	@Transactional
-	public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
-		Long uid2 = record.getUid();
-		if (uid2 == null || uid.longValue() != uid2.longValue())
-			return false; // 鐢ㄦ埛id涓嶇鍚�
+            if (addDetail(uid, record))
+                totalGoldCoin += record.getGoldCoin();
+        }
 
-		if (record.getState() != null && record.getState().intValue() == 1) {
-			return false; // 宸查鍙�
-		}
+        // 鏇存柊閲戝竵
+        userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
 
-		IntegralTaskRecord taskRecord = new IntegralTaskRecord();
-		taskRecord.setId(record.getId());
-		taskRecord.setState(1); // 宸查鍙�
-		taskRecord.setUpdateTime(new Date());
-		integralTaskRecordMapper.updateByPrimaryKeySelective(taskRecord);
+        return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
+    }
 
-		Long cid = record.getCid();
-		if (cid == null)
-			return false;
+    @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涓嶇鍚�
 
-		IntegralTaskClass taskClass = integralTaskClassService.selectByPrimaryKey(cid);
-		if (taskClass == null)
-			return false;
+        if (record.getState() != null && record.getState().intValue() == 1) {
+            return false; // 宸查鍙�
+        }
 
-		Long taskId = record.getTaskId();
-		if (taskId == null)
-			return false;
+        IntegralTaskRecord taskRecord = new IntegralTaskRecord();
+        taskRecord.setId(record.getId());
+        taskRecord.setState(1); // 宸查鍙�
+        taskRecord.setUpdateTime(new Date());
+        integralTaskRecordMapper.updateByPrimaryKeySelective(taskRecord);
 
-		IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
-		if (integralTask == null)
-			return false;
+        Long cid = record.getCid();
+        if (cid == 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;
-						}
+        IntegralTaskClass taskClass = integralTaskClassService.selectByPrimaryKey(cid);
+        if (taskClass == 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()));
-				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);
-			}
-		}
+        Long taskId = record.getTaskId();
+        if (taskId == null)
+            return false;
 
-		detail.setUid(uid);
-		detail.setMoney(record.getGoldCoin());
-		detail.setCreateTime(record.getCreateTime());
-		integralDetailService.insertSelective(detail);
+        IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
+        if (integralTask == null)
+            return false;
 
-		return true;
-	}
+        // 鍔犲叆鏄庣粏
+        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;
+                        }
 
-	@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);
-	}
+                        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);
+            }
+        }
 
-	@Override
-	public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
-		if (record == null)
-			throw new IntegralTaskRecordException(1, "璁板綍涓虹┖");
+        detail.setUid(uid);
+        detail.setMoney(record.getGoldCoin());
+        detail.setCreateTime(record.getCreateTime());
+        integralDetailService.insertSelective(detail);
 
-		if (record.getCid() == null || record.getTaskId() == null || record.getGoldCoin() == null
-				|| record.getState() == null || record.getUid() == null)
-			throw new IntegralTaskRecordException(2, "鏁版嵁涓嶅畬鎴�");
+        return true;
+    }
 
-		if (record.getCreateTime() == null)
-			record.setCreateTime(new Date());
+    @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);
+    }
 
-		if (record.getUpdateTime() == null)
-			record.setUpdateTime(new Date());
-		integralTaskRecordMapper.insertSelective(record);
-		return record;
-	}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
+        if (record == null)
+            throw new IntegralTaskRecordException(1, "璁板綍涓虹┖");
 
-	@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);
-	}
+        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);
 
-	@Override
-	public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
-		return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
-	}
+        if (record.getUpdateTime() == null)
+            record.setUpdateTime(date);
 
-	@Override
-	public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
-		return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
-	}
+        // 璁剧疆鏈夋晥鏈�
+        record.setEndTime(DateUtil.plusDayDate(Constant.GOLD_COIN_VALID_DAYS, date));
+        integralTaskRecordMapper.insertSelective(record);
+        return record;
+    }
 
-	@Async()
-	@Override
-	public void firstRebateOrderRewardBoss(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");
-		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 firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
-		if (uid == null || originUid == 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_order_reward_boss_super");
-		if (StringUtil.isNullOrEmpty(reward))
-			return;
-		firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
-	}
 
-	@Async()
-	@Override
-	public void firstShareOrderReward(Long uid, String beizu) {
-		if (uid == 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");
-		if (StringUtil.isNullOrEmpty(reward))
-			return;
-		firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
-	}
+        SystemEnum system = userInfoService.getUserSystem(uid);
 
-	@Async()
-	@Override
-	public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
-		if (uid == null || originUid == null)
-			return;
+        String reward = configService.getValue(ConfigKeyEnum.firstOrderRewardBoss.getKey(), system);
+        if (StringUtil.isNullOrEmpty(reward))
+            return;
+        firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+    }
 
-		String reward = configService.get("first_share_order_reward_boss");
-		if (StringUtil.isNullOrEmpty(reward))
-			return;
-		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
-	}
+    @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);
+    }
 
-	/**
-	 * 闃熷憳棣栧崟濂栧姳閲戝竵
-	 * 
-	 * @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;
+    @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);
+    }
 
-		// 鍒ゆ柇鏄惁宸查鍙�
-		IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
-		if (detailRecord != null)
-			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);
+    }
 
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-		if (userInfoExtra == null)
-			return;
+    /**
+     * 闃熷憳棣栧崟濂栧姳閲戝竵
+     *
+     * @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;
 
-		Integer goldCoin = userInfoExtra.getGoldCoin();
-		if (goldCoin == null)
-			goldCoin = 0;
-		goldCoin = goldCoin + addGoldCoin;
+        // 鍒ゆ柇鏄惁宸查鍙�
+        IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
+        if (detailRecord != null)
+            return;
 
-		try {
-			UserInfoExtra extra = new UserInfoExtra();
-			extra.setId(userInfoExtra.getId());
-			extra.setGoldCoin(goldCoin);
-			userInfoExtraService.saveUserInfoExtra(extra);
-		} catch (UserInfoExtraException e) {
-			LogHelper.errorDetailInfo(e);
-			return;
-		}
+        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+        if (userInfoExtra == null)
+            return;
 
-		// 閲戝竵璇︽儏
-		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);
+        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;
+        }
 
-		// 娑堟伅
-		MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
-		msgOther.setTitle("閲戝竵濂栧姳");
-		msgOther.setNum(addGoldCoin + "閲戝竵");
-		msgOther.setTotal(goldCoin + "閲戝竵");
-		if (StringUtil.isNullOrEmpty(level)) {
-			msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� ");
-			msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 ");
-		} else {
-			msgOther.setSource(level + "绾ч槦鍛橀娆′笅鍗曪紝绯荤粺濂栧姳閲戝竵 ");
-			msgOther.setExplain("浠呮柊閭�璇烽槦鍛橀涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 ");
-		}
-		userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
-	}
+        // 閲戝竵璇︽儏
+        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);
+
+        // 娑堟伅
+        if (level.equalsIgnoreCase("涓�") || level.equalsIgnoreCase("1")) {
+            // 鐩存帴绮変笣
+            userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, true);
+        } else {
+            // 闂存帴绮変笣
+            userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, false);
+        }
+
+    }
+
 }

--
Gitblit v1.8.0