连续7天打卡记录

原创
2019/05/28 14:40
阅读数 9
    /**
     * 查询用户任务列表分享跑步
     *
     * @param userId
     * @param businessId
     * @return
     */
    public DynamicRuleDO selectUserTask(Long userId, Integer businessId) {
        DynamicRuleDO rule = new DynamicRuleDO();
        Date dd = DateUtils.minusDay(new Date(), 1);
        String endDate = DateUtils.formatYYYYMMDDForDate(dd);
        String startDate = DateUtils.minusDay(endDate, -7);
        //7天记录数据
        List<TaskIncomeDO> list = taskIncomeMapper.selectUserTask(userId, businessId, startDate, endDate);
        if (list == null || list.size() == 0) {
            rule.setFinishnum(0);
            rule.setIsfinish(0);
            return rule;
        }
//排序按添加数据顺序倒序
        list.stream().sorted(Comparator.comparing(TaskIncomeDO::getId).reversed()).collect(Collectors.toList());
        List<TaskIncomeDO> nlist = list.stream().filter(o -> o.getType() == 1).collect(Collectors.toList());
        TaskIncomeDO first = list.get(0);
//符合7条数据普通数据6条第七天1条并且最后一条是第七天额外
        if (list.size() == 7 && nlist.size() == 6 && first.getType() == 2) {
            rule.setFinishnum(7);
            rule.setIsfinish(1);
            return rule;
        }
        int num = 0;
//是否是今天日期
        boolean isToday = true;
        boolean result = true;
//两个日期比较结果采用今天比较还是昨天比较
        for (int i = 0; i < list.size(); i++) {
            Date date = DateUtils.minusDateForDay(new Date(), (0 - i));
            TaskIncomeDO income = list.get(i);
            if (income.getType() == 2) {
                break;
            }
            if (isToday) {
                boolean isSame = DateUtils.isSameDate(date, income.getCreatedat());
                if (!isSame) {
                    isToday = false;
                }
                result = isSame;
            }
            if (!result && i != 0) {
                break;
            }
            if (!isToday) {
                result = DateUtils.isSameDate(DateUtils.minusDateForDay(new Date(), (-1 - i)), income.getCreatedat());
            }
            if (!result) {
                break;
            }
            num++;
        }
        rule.setFinishnum(num);//连续几天
        rule.setIsfinish(0);//
        return rule;
    }

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部