| | |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRank;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskRankService;
|
| | | 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.vo.integral.DailySignVO;
|
| | | import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
|
| | | import com.yeshi.fanli.vo.integral.SignDateVO;
|
| | |
| | |
|
| | |
|
| | | @Override
|
| | | public IntegralTaskClass selectByPrimaryKey(Long id) {
|
| | | return integralTaskClassMapper.selectByPrimaryKey(id);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<IntegralTaskClassVO> getIntegralTaskClassVO(Long uid, long start, int count) {
|
| | | // 用户签到
|
| | | Integer baseGoldCoin = 5;
|
| | | boolean dailySign = false;
|
| | | if (start == 0) { // 第一页签到
|
| | | try { |
| | | baseGoldCoin = finishedDailySign(uid);
|
| | | dailySign = true;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | List<IntegralTaskClassVO> listVo = integralTaskClassMapper.getIntegralTaskClassVO(start, count);
|
| | | if (listVo == null || listVo.size() == 0) {
|
| | | return listVo;
|
| | | }
|
| | |
|
| | | for (IntegralTaskClassVO taskClassVO : listVo) {
|
| | | String progress = taskClassVO.getProgress();
|
| | | if (StringUtil.isNullOrEmpty(progress))
|
| | | continue;
|
| | | |
| | | Integer taskNum = taskClassVO.getTaskNum();
|
| | | if (taskNum == null)
|
| | | continue;
|
| | |
|
| | | // 目前只有签到变灰
|
| | | UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey();
|
| | | if (uniqueKey == UniqueKeyEnum.dailySign) {
|
| | | taskClassVO.setTotalCoin(baseGoldCoin);
|
| | | taskClassVO.setLightUp(dailySign);
|
| | | } else {
|
| | | taskClassVO.setLightUp(true);
|
| | | }
|
| | | |
| | | |
| | | Integer dateType = 1; // 查询当日
|
| | | if (uniqueKey == UniqueKeyEnum.orderReward)
|
| | | dateType = null; // 查询历史
|
| | |
|
| | | Long id = taskClassVO.getId();
|
| | | int countFinished = 0;
|
| | | Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, dateType);
|
| | | if (totalGoldCoin != null && totalGoldCoin > 0) {
|
| | | taskClassVO.setFinishedCoin("+" + totalGoldCoin);
|
| | | if (uniqueKey != UniqueKeyEnum.dailySign)
|
| | | countFinished = integralTaskRecordService.countFinished(uid, id, dateType);
|
| | | }
|
| | | progress = progress.replace("{已完成}", countFinished + "").replace("{总任务}", taskNum + "");
|
| | | |
| | | if (!dailySign && uniqueKey == UniqueKeyEnum.dailySign) {
|
| | | progress = "未签到";
|
| | | taskClassVO.setBtnName("签到");
|
| | | } |
| | | taskClassVO.setProgress(progress);
|
| | | }
|
| | | return listVo;
|
| | | return integralTaskClassMapper.getIntegralTaskClassVO(start, count);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | */
|
| | | @Transactional
|
| | | public Integer finishedDailySign(long uid) throws Exception{
|
| | | Integer baseGoldCoin = 5;
|
| | | |
| | | IntegralTaskClass taskClass = getByUniqueKey(UniqueKeyEnum.dailySign.name());
|
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1)
|
| | | return baseGoldCoin;
|
| | | throw new Exception("抛出异常:任务分类不存在");
|
| | |
|
| | | Long cid = taskClass.getId();
|
| | | |
| | | // 今日已签到完成
|
| | | if (integralTaskRecordService.isToDaySign(uid, cid))
|
| | | return baseGoldCoin;
|
| | | return 2;
|
| | |
|
| | | // 任务
|
| | | Integer num = integralTaskRecordService.getNowdaySignNum(uid, cid);
|
| | | String uniqueKey = UniqueKeyEnum.dailySign.name() + num;
|
| | | IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(cid, uniqueKey);
|
| | | if (integralTask == null)
|
| | | return baseGoldCoin;
|
| | | throw new Exception("抛出异常:任务不存在");
|
| | |
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null)
|
| | | return baseGoldCoin;
|
| | | throw new Exception("抛出异常:额外信息不存在");
|
| | |
|
| | | UserRank userRank = userInfoExtra.getUserRank();
|
| | | if (userRank == null)
|
| | | return baseGoldCoin;
|
| | | throw new Exception("抛出异常:等级信息不存在");
|
| | |
|
| | | Integer goldCoin = integralTask.getGoldCoin();
|
| | | Integer baseDoubleNum = integralTask.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | |
| | | baseGoldCoin = goldCoin;
|
| | |
|
| | | // 根据等级计算是否增加或加倍
|
| | | Long taskId = integralTask.getId();
|
| | |
| | | }
|
| | | // 加入记录
|
| | | integralTaskRecordService.finishedTask(uid, cid, taskId, goldCoin);
|
| | | return baseGoldCoin;
|
| | | |
| | | return 1;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public DailySignVO getDailySignList(Long uid, Long rankId) throws ParseException{
|
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd");
|
| | | List<SignDateVO> listSign = new ArrayList<SignDateVO>();
|
| | | IntegralTaskClass taskClass = integralTaskClassMapper.getByUniqueKey(UniqueKeyEnum.dailySign.name());
|
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1)
|
| | | return null;
|
| | |
|
| | | Long cid = taskClass.getId();
|
| | | List<IntegralTask> listTask = integralTaskService.listByCid(cid);
|
| | | if (listTask == null || listTask.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | |
| | | Date date = new Date();
|
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd");
|
| | | List<SignDateVO> listSign = new ArrayList<SignDateVO>();
|
| | | |
| | | List<Date> listDays = integralTaskRecordService.getSignDays(uid, cid);
|
| | | for (int i = 0; i < listDays.size(); i ++) {
|
| | | if(i == listDays.size() -1) {
|
| | | SignDateVO signDate = new SignDateVO();
|
| | | signDate.setDate("今日");
|
| | | signDate.setLightUp(true);
|
| | | listSign.add(signDate);
|
| | | break;
|
| | | }
|
| | | |
| | | String before = format.format(listDays.get(i));
|
| | | if (before.startsWith("0")) |
| | | before = before.substring(1, before.length());
|
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setDate(before);
|
| | | listSign.add(signDateVO);
|
| | | }
|
| | | |
| | | for (int i = 1; i <= 7- listDays.size(); i ++) {
|
| | | String after = format.format(DateUtil.reduceDay(i, date));
|
| | | if (after.startsWith("0")) |
| | | after = after.substring(1, after.length());
|
| | | |
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setDate(after);
|
| | | listSign.add(signDateVO);
|
| | | }
|
| | | |
| | | DailySignVO dailySignVO = new DailySignVO();
|
| | | for (int i = 0; i < listTask.size(); i++) {
|
| | | if (listSign.size() <= i) {
|
| | | break;
|
| | | }
|
| | | SignDateVO signDateVO = listSign.get(i);
|
| | | |
| | | IntegralTask task = listTask.get(i);
|
| | | Integer goldCoin = task.getGoldCoin();
|
| | | Integer baseDoubleNum = task.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | |
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(task.getId(), rankId);
|
| | | if (traskRank != null) {
|
| | | Integer addCoin = traskRank.getAddCoin();
|
| | | if (addCoin != null && addCoin > 0)
|
| | | goldCoin += addCoin;
|
| | |
|
| | | Integer doubleNum = traskRank.getDoubleNum();
|
| | | if (doubleNum != null && doubleNum > 0) {
|
| | | goldCoin = goldCoin * doubleNum;
|
| | | |
| | | Long cid = taskClass.getId();
|
| | | List<IntegralTaskRecord> listRecord = integralTaskRecordService.getSignDaysRecord(uid, cid);
|
| | | if (listRecord != null && listRecord.size() > 0) {
|
| | | for (int i = listRecord.size() - 1; i >= 0; i--) {
|
| | | IntegralTaskRecord taskRecord = listRecord.get(i);
|
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setLightUp(true);
|
| | | signDateVO.setGoldCoin("+" + taskRecord.getGoldCoin());
|
| | | if(i == 0) {
|
| | | signDateVO.setDate("今日");
|
| | | dailySignVO.setGoldCoin(taskRecord.getGoldCoin());
|
| | | } else {
|
| | | String before = format.format(taskRecord.getCreateTime());
|
| | | if (before.startsWith("0")) |
| | | before = before.substring(1, before.length());
|
| | | signDateVO.setDate(before);
|
| | | }
|
| | | listSign.add(signDateVO);
|
| | | }
|
| | | signDateVO.setGoldCoin("+" + goldCoin);
|
| | | |
| | | if("今日".equals(signDateVO.getDate()))
|
| | | dailySignVO.setGoldCoin(goldCoin);
|
| | | |
| | | }
|
| | |
|
| | | dailySignVO.setDays(listDays.size());
|
| | | |
| | | dailySignVO.setDays(listSign.size());
|
| | | |
| | | if (listSign.size() < 7) {
|
| | | List<IntegralTask> listTask = integralTaskService.listByCid(cid);
|
| | | if (listTask == null || listTask.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | |
| | | Date date = new Date();
|
| | | int j = 1;
|
| | | for (int i = listSign.size(); i < listTask.size(); i ++) {
|
| | | String after = format.format(DateUtil.plusDayDate(j, date));
|
| | | if (after.startsWith("0")) |
| | | after = after.substring(1, after.length());
|
| | | |
| | | IntegralTask task = listTask.get(i);
|
| | | Integer goldCoin = task.getGoldCoin();
|
| | | Integer baseDoubleNum = task.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | |
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(task.getId(), rankId);
|
| | | if (traskRank != null) {
|
| | | Integer addCoin = traskRank.getAddCoin();
|
| | | if (addCoin != null && addCoin > 0)
|
| | | goldCoin += addCoin;
|
| | |
|
| | | Integer doubleNum = traskRank.getDoubleNum();
|
| | | if (doubleNum != null && doubleNum > 0) {
|
| | | goldCoin = goldCoin * doubleNum;
|
| | | }
|
| | | }
|
| | | |
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setDate(after);
|
| | | signDateVO.setGoldCoin("+" + goldCoin);
|
| | | listSign.add(signDateVO);
|
| | | j++;
|
| | | }
|
| | | } |
| | | dailySignVO.setListDate(listSign);
|
| | | return dailySignVO;
|
| | | }
|