| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
|
| | | 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.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;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | @Service
|
| | |
| | |
|
| | | @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 (userInfoExtra == null)
|
| | | throw new IntegralTaskRecordException(1, "用户信息不全");
|
| | |
|
| | | int totalGoldCoin = integralTaskRecordMapper.countTotalGoldCoin(uid);
|
| | | if (totalGoldCoin > 0) {
|
| | | integralTaskRecordMapper.updateReceived(uid);
|
| | | 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) {
|
| | | 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);
|
| | |
|
| | | 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;
|
| | |
|
| | | 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 + "次";
|
| | |
|
| | | // 加入明细
|
| | | IntegralDetail detail = new IntegralDetail();
|
| | | detail.setUid(uid);
|
| | | detail.setTitle(title);
|
| | | detail.setMoney(record.getGoldCoin());
|
| | | detail.setCreateTime(record.getCreateTime());
|
| | | integralDetailService.insertSelective(detail);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Integer countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
|
| | | if (day == null)
|