| | |
| | | package com.yeshi.fanli.service.impl.integral;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.integral.IntegralDetail;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTask;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
|
| | | 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.exception.integral.IntegralTaskRecordException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | |
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private IntegralDetailService integralDetailService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private IntegralTaskService integralTaskService;
|
| | | |
| | | |
| | |
|
| | | @Resource
|
| | | private IntegralTaskClassService integralTaskClassService;
|
| | |
|
| | | @Override
|
| | | public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
|
| | |
| | | }
|
| | |
|
| | | if (num > 7) {
|
| | | num = 1;
|
| | | num = 7;
|
| | | }
|
| | | return num;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Date> getSignDays(long uid, Long cid) {
|
| | | List<Date> listDate = new ArrayList<Date>();
|
| | | public List<IntegralTaskRecord> getSignDaysRecord(long uid, Long cid) {
|
| | | List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
|
| | | try {
|
| | | // 签到时间正序序查询近7天数据
|
| | | List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
|
| | |
| | | break; // 天数未连续
|
| | | }
|
| | | date = createTime;
|
| | | listDate.add(record.getCreateTime());
|
| | | listRecord.add(record);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | // 倒序
|
| | | Collections.reverse(listDate);
|
| | | return listDate;
|
| | | return listRecord;
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | if (userInfoExtra == null)
|
| | | throw new IntegralTaskRecordException(1, "用户信息不全");
|
| | |
|
| | | |
| | | List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
|
| | | if (list == null || list.size() == 0) |
| | | throw new IntegralTaskRecordException(1, "暂无可领取");
|
| | | |
| | | |
| | | Integer totalGoldCoin = 0;
|
| | | List<IntegralTaskRecord> list = integralTaskRecordMapper.listNotReceived(Integer.MAX_VALUE, uid);
|
| | | if (list == null || list.size() == 0)
|
| | | throw new IntegralTaskRecordException(1, "暂无可领取");
|
| | |
|
| | | Integer totalGoldCoin = 0;
|
| | | for (IntegralTaskRecord record : list) {
|
| | | Long uid2 = record.getUid();
|
| | | if (uid2 == null || uid.longValue() != uid2.longValue())
|
| | | continue; // 用户id不符合
|
| | |
|
| | | if (record.getState() != null && record.getState().intValue() == 1) {
|
| | | continue; // 已领取
|
| | | }
|
| | |
|
| | | 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) |
| | | continue;
|
| | | |
| | | |
| | | IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
|
| | | if (integralTask == null)
|
| | | continue;
|
| | | |
| | | // 加入明细
|
| | | IntegralDetail detail = new IntegralDetail();
|
| | | detail.setUid(uid);
|
| | | detail.setCreateTime(new Date());
|
| | | detail.setMoney(record.getGoldCoin());
|
| | | detail.setTitle(integralTask.getName());
|
| | | integralDetailService.insertSelective(detail);
|
| | | |
| | | totalGoldCoin += record.getGoldCoin();
|
| | | if (addDetail(uid, record))
|
| | | totalGoldCoin += record.getGoldCoin();
|
| | | }
|
| | |
|
| | | Integer goldCoin = userInfoExtra.getGoldCoin();
|
| | |
| | | if (record == null)
|
| | | continue;
|
| | |
|
| | | Long uid2 = record.getUid();
|
| | | if (uid2 == null || uid.longValue() != uid2.longValue())
|
| | | continue; // 用户id不符合
|
| | |
|
| | | if (record.getState() != null && record.getState().intValue() == 1) {
|
| | | continue; // 已领取
|
| | | }
|
| | |
|
| | | 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) |
| | | continue;
|
| | | |
| | | |
| | | IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
|
| | | if (integralTask == null)
|
| | | continue;
|
| | | |
| | | // 加入明细
|
| | | IntegralDetail detail = new IntegralDetail();
|
| | | detail.setUid(uid);
|
| | | detail.setCreateTime(new Date());
|
| | | detail.setMoney(record.getGoldCoin());
|
| | | detail.setTitle(integralTask.getName());
|
| | | integralDetailService.insertSelective(detail);
|
| | | |
| | | totalGoldCoin += record.getGoldCoin();
|
| | | if (addDetail(uid, record))
|
| | | totalGoldCoin += record.getGoldCoin();
|
| | | }
|
| | |
|
| | | Integer goldCoin = userInfoExtra.getGoldCoin();
|
| | |
| | | return extra.getGoldCoin();
|
| | | }
|
| | |
|
| | | public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
|
| | |
|
| | | Long uid2 = record.getUid();
|
| | | if (uid2 == null || uid.longValue() != uid2.longValue())
|
| | | return false; // 用户id不符合
|
| | |
|
| | | if (record.getState() != null && record.getState().intValue() == 1) {
|
| | | return false; // 已领取
|
| | | }
|
| | |
|
| | | IntegralTaskRecord taskRecord = new IntegralTaskRecord();
|
| | | taskRecord.setId(record.getId());
|
| | | taskRecord.setState(1); // 已领取
|
| | | taskRecord.setUpdateTime(new Date());
|
| | | integralTaskRecordMapper.updateByPrimaryKeySelective(taskRecord);
|
| | |
|
| | | Long cid = record.getCid();
|
| | | if (cid == null)
|
| | | return false;
|
| | |
|
| | | IntegralTaskClass taskClass = integralTaskClassService.selectByPrimaryKey(cid);
|
| | | if (taskClass == null)
|
| | | return false;
|
| | |
|
| | | Long taskId = record.getTaskId();
|
| | | if (taskId == null)
|
| | | return false;
|
| | |
|
| | | IntegralTask integralTask = integralTaskService.selectByPrimaryKey(taskId);
|
| | | if (integralTask == 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;
|
| | | }
|
| | |
|
| | | if (DateUtil.daysBetween2(tntegralTaskRecord.getCreateTime(), nextDate) != 1) {
|
| | | break; // 天数未连续
|
| | | }
|
| | | nextDate = tntegralTaskRecord.getCreateTime();
|
| | | num++;
|
| | | }
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | detail.setTitle(taskClass.getName() + "-第" + num + "天");
|
| | | } else {
|
| | | int num = 0;
|
| | | FrequencyEnum frequency = integralTask.getFrequency();
|
| | | if (frequency == FrequencyEnum.everyday) {
|
| | | num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
|
| | | TimeUtil.getWholeTime(record.getCreateTime().getTime()));
|
| | | } else if (frequency == FrequencyEnum.onlyOne) {
|
| | | num = 1;
|
| | | }
|
| | |
|
| | | if (num <= 0)
|
| | | num = 1;
|
| | | String title = taskClass.getName() + "-" + integralTask.getName() + "-" + num + "次";
|
| | | detail.setTitle(title);
|
| | | }
|
| | |
|
| | | detail.setUid(uid);
|
| | | detail.setMoney(record.getGoldCoin());
|
| | | detail.setCreateTime(record.getCreateTime());
|
| | | integralDetailService.insertSelective(detail);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Integer countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
|
| | | public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
|
| | | if (day == null)
|
| | | return null;
|
| | | return 0;
|
| | | Date minTime = new Date(
|
| | | TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
|
| | | Date maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
|
| | |
| | | integralTaskRecordMapper.insertSelective(record);
|
| | | return record;
|
| | | }
|
| | |
|
| | | @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);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
|
| | | return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
|
| | | }
|
| | | }
|