class FrontServices {

    public ResponseMessage userJoinv2(UserJoinRequest userJoinRequest) {

        log.info(userJoinRequest.toString());

        ThisLocalizedWeek thisLocalizedWeek = new ThisLocalizedWeek(Locale.CHINA);
        List<UserRecord> userRecords = runningRecordMapper.selectDailyUserRecord(thisLocalizedWeek.getFirstDay(), thisLocalizedWeek.getLastDay());

        UserJoinResponse userJoinResponse = new UserJoinResponse();



        /** 对 null 值处理 */
        userRecords = userRecords.stream()
                .map(e -> {
                    if (e.getDislikes() == null) {
                        e.setDislikes(0);
                    }
                    if (e.getLikes() == null) {
                        e.setLikes(0);
                    }
                    return e;
                }).collect(Collectors.toList());


        List<UserRecord> collectUserRecord = userRecords.stream().filter(e -> e.getUserOpenId().equals(userJoinRequest.getOpenId())).collect(Collectors.toList());


        if (collectUserRecord.size() > 0) {
            userJoinResponse.setUserRecord(collectUserRecord.get(0));
        } else {

            /** 如果我这周有打卡，那么就拿这个这周打开的数据*/
            UserRecord userRecord1 = runningRecordMapper.selectDailyUserRecordWithOpenId(thisLocalizedWeek.getFirstDay(), thisLocalizedWeek.getLastDay(), userJoinRequest.getOpenId());

            if (userRecord1 != null) {
                if (userRecord1.getDislikes() == null) {
                    userRecord1.setDislikes(0);
                }
                if (userRecord1.getLikes() == null) {
                    userRecord1.setLikes(0);
                }
                userJoinResponse.setUserRecord(userRecord1);
            } else {
                /** sql查询出没『我』的信息的时候 拼凑出0*/
                UserInfo userInfo = userInfoMapper.selectByOpenId(userJoinRequest.getOpenId());
                UserGroup userGroup = userGroupMapper.selectByGroupIdAndUserOpenId(1, userJoinRequest.getOpenId());
                TargetDistance targetDistance = targetDistanceMapper.selectByUserGroupIdAndTimeRange(userGroup.getUserGroupId(), thisLocalizedWeek.getFirstDay(), thisLocalizedWeek.getLastDay());
                UserRecord userRecord = new UserRecord();
                userRecord.setCoins(userInfo.getCoins());
                userRecord.setDislikes(0);
                userRecord.setLikes(0);
                userRecord.setCurrent((float) 0);
                userRecord.setDistanceValided((float) 0);
                userRecord.setTarget(targetDistance.getTargetDistance());
                userRecord.setUserGroupId(userGroup.getUserGroupId());
                userRecord.setIcon(userInfo.getIcon());
                userRecord.setNickName(userInfo.getUserName());
                userRecord.setUserOpenId(userInfo.getOpenId());
                userJoinResponse.setUserRecord(userRecord);
            }

        }

        List<UserRecord> collectOtherUserRecord = userRecords.stream().filter(e -> !e.getUserOpenId().equals(userJoinRequest.getOpenId())).collect(Collectors.toList());
        userJoinResponse.setOtherUsersRecord(collectOtherUserRecord);

        return ResultUtils.success(userJoinResponse);
    }

    @Autowired public  FrontServices(UserInfoMapper userInfoMapper,
                         UserGroupMapper userGroupMapper,
                         TargetDistanceMapper targetDistanceMapper,
                         RunningRecordMapper runningRecordMapper,
                         VoteRecordMapper voteRecordMapper);

}