Commit 22487c2e authored by liming's avatar liming

增加签到成就处理

parent 8f610d4f
package com.antai.sport.http.server.constants;
public class AchievementCondition {
public static final Integer SIGN_IN_DAYS = 10;
}
package com.antai.sport.http.server.constants;
public class GameCurrencySourceType {
//运动训练
public static final Integer SPORT = 10;
//成就
public static final Integer ACHIEVEMENT = 20;
}
...@@ -40,7 +40,7 @@ public class Achievement implements Serializable { ...@@ -40,7 +40,7 @@ public class Achievement implements Serializable {
/** /**
* 条件 10 登录天数 20 团练完成场数 30 日常赛完成场数 40 娱乐赛场数 50 里程 60 爬升高度 70 卡路里消耗 * 条件 10 登录天数 20 团练完成场数 30 日常赛完成场数 40 娱乐赛场数 50 里程 60 爬升高度 70 卡路里消耗
*/ */
private Integer condition; private Integer achievementCondition;
/** /**
* 成就名称 * 成就名称
......
...@@ -40,7 +40,7 @@ public class AchievementForSportUser implements Serializable { ...@@ -40,7 +40,7 @@ public class AchievementForSportUser implements Serializable {
/** /**
* 已读状态 * 已读状态
*/ */
private Boolean read; private Boolean markRead;
/** /**
* 创建时间 * 创建时间
......
...@@ -42,6 +42,11 @@ public class SportUserGameCurrencyLog implements Serializable { ...@@ -42,6 +42,11 @@ public class SportUserGameCurrencyLog implements Serializable {
*/ */
private Integer type; private Integer type;
/**
* 源头类型 10:训练 20:成就
*/
private Integer sourceType;
/** /**
* 源头id 漫游记录id 或消费订单id * 源头id 漫游记录id 或消费订单id
*/ */
......
package com.antai.sport.http.server.server.api.business.achievement.mapper;
import com.antai.sport.http.server.repository.achievement.entity.Achievement;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface AchievementBizMapper {
List<Achievement> getSignInAchievement(@Param("achievementCondition") Integer achievementCondition,
@Param("sportUserId") Long sportUserId);
}
package com.antai.sport.http.server.server.api.business.achievement.service; package com.antai.sport.http.server.server.api.business.achievement.service;
import com.antai.sport.http.server.constants.AchievementCondition;
import com.antai.sport.http.server.constants.GameCurrencySourceType;
import com.antai.sport.http.server.repository.achievement.entity.Achievement;
import com.antai.sport.http.server.repository.achievement.entity.AchievementForSportUser;
import com.antai.sport.http.server.repository.achievement.mapper.AchievementForSportUserMapper;
import com.antai.sport.http.server.server.api.business.achievement.mapper.AchievementBizMapper;
import com.antai.sport.http.server.server.api.business.sportusergamecurrency.service.SportUserGameCurrencyService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
@Service @Service
public class AchievementService { public class AchievementService {
@Resource
private AchievementForSportUserMapper achievementForSportUserMapper;
@Resource
private AchievementBizMapper achievementBizMapper;
@Resource
private SportUserGameCurrencyService sportUserGameCurrencyService;
/**
* 处理签到类成就
*
* @param sportUserId
*/
public void handleSignInAchievement(Long sportUserId, Integer continuousLoginDays) {
List<Achievement> achievementList =
achievementBizMapper.getSignInAchievement(AchievementCondition.SIGN_IN_DAYS, sportUserId);
for (Achievement achievement : achievementList) {
if (continuousLoginDays.compareTo(achievement.getConditionValue()) >= 0) {
AchievementForSportUser achievementForSportUser = new AchievementForSportUser();
achievementForSportUser.setSportUserId(sportUserId);
achievementForSportUser.setAchievementId(achievement.getId());
achievementForSportUser.setMarkRead(false);
achievementForSportUser.setCreateTime(LocalDateTime.now());
achievementForSportUserMapper.insert(achievementForSportUser);
sportUserGameCurrencyService.addCurrency(sportUserId, achievement.getCurrency(),
GameCurrencySourceType.ACHIEVEMENT, achievement.getId());
}
}
}
} }
package com.antai.sport.http.server.server.api.business.sportusergamecurrency.service;
import com.antai.sport.http.server.constants.GameCurrencyLogType;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrency;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyLog;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyLogMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
@Service
public class SportUserGameCurrencyService {
@Resource
private SportUserGameCurrencyMapper sportUserGameCurrencyMapper;
@Resource
private SportUserGameCurrencyLogMapper sportUserGameCurrencyLogMapper;
public void addCurrency(Long sportUserId, Integer currency, Integer sourceType, Long sourceId) {
SportUserGameCurrency userGameCurrency =
sportUserGameCurrencyMapper.selectOne(new QueryWrapper<SportUserGameCurrency>().lambda()
.eq(SportUserGameCurrency::getSportUserId, sportUserId));
if (userGameCurrency == null) {
userGameCurrency = new SportUserGameCurrency();
userGameCurrency.setSportUserId(sportUserId);
userGameCurrency.setAmmount(currency);
userGameCurrency.setCtDate(LocalDateTime.now());
sportUserGameCurrencyMapper.insert(userGameCurrency);
} else {
userGameCurrency.setAmmount(userGameCurrency.getAmmount() + currency);
sportUserGameCurrencyMapper.updateById(userGameCurrency);
}
SportUserGameCurrencyLog gameCurrencyLog = new SportUserGameCurrencyLog();
gameCurrencyLog.setSportUserId(sportUserId);
gameCurrencyLog.setAmmount(currency);
gameCurrencyLog.setSourceType(sourceType);
gameCurrencyLog.setSourceId(sourceId);
gameCurrencyLog.setCtDate(LocalDateTime.now());
gameCurrencyLog.setType(GameCurrencyLogType.ADD);
sportUserGameCurrencyLogMapper.insert(gameCurrencyLog);
}
}
...@@ -7,13 +7,9 @@ import com.antai.sport.http.server.repository.club.mapper.ClubMapper; ...@@ -7,13 +7,9 @@ import com.antai.sport.http.server.repository.club.mapper.ClubMapper;
import com.antai.sport.http.server.repository.club.mapper.ClubMemberMapper; import com.antai.sport.http.server.repository.club.mapper.ClubMemberMapper;
import com.antai.sport.http.server.repository.roommode.entity.RoomMode; import com.antai.sport.http.server.repository.roommode.entity.RoomMode;
import com.antai.sport.http.server.repository.roommode.mapper.RoomModeMapper; import com.antai.sport.http.server.repository.roommode.mapper.RoomModeMapper;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrency;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyBaseRule; import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyBaseRule;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyLog;
import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyMatchRule; import com.antai.sport.http.server.repository.shop.entity.SportUserGameCurrencyMatchRule;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyBaseRuleMapper; import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyBaseRuleMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyLogMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMapper;
import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMatchRuleMapper; import com.antai.sport.http.server.repository.shop.mapper.SportUserGameCurrencyMatchRuleMapper;
import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatch; import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatch;
import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchMapper; import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchMapper;
...@@ -23,6 +19,7 @@ import com.antai.sport.http.server.repository.teamtraining.entity.TeamTraining; ...@@ -23,6 +19,7 @@ import com.antai.sport.http.server.repository.teamtraining.entity.TeamTraining;
import com.antai.sport.http.server.repository.teamtraining.mapper.TeamTrainingMapper; import com.antai.sport.http.server.repository.teamtraining.mapper.TeamTrainingMapper;
import com.antai.sport.http.server.server.api.business.simplematch.dto.SimpleMatchUserScheduleVO; import com.antai.sport.http.server.server.api.business.simplematch.dto.SimpleMatchUserScheduleVO;
import com.antai.sport.http.server.server.api.business.simplematch.mapper.SimpleMatchBusinessMapper; import com.antai.sport.http.server.server.api.business.simplematch.mapper.SimpleMatchBusinessMapper;
import com.antai.sport.http.server.server.api.business.sportusergamecurrency.service.SportUserGameCurrencyService;
import com.antai.sport.http.server.server.api.business.teamtraining.dto.TeamTrainingUserScheduleVO; import com.antai.sport.http.server.server.api.business.teamtraining.dto.TeamTrainingUserScheduleVO;
import com.antai.sport.http.server.server.api.business.teamtraining.mapper.TeamTrainingBusinessMapper; import com.antai.sport.http.server.server.api.business.teamtraining.mapper.TeamTrainingBusinessMapper;
import com.antai.sport.http.server.server.api.business.traininglog.converter.SportUserTrainingLogConverter; import com.antai.sport.http.server.server.api.business.traininglog.converter.SportUserTrainingLogConverter;
...@@ -84,10 +81,6 @@ public class SportUserTrainingLogService { ...@@ -84,10 +81,6 @@ public class SportUserTrainingLogService {
@Resource @Resource
private SportUserGameCurrencyBaseRuleMapper sportUserGameCurrencyBaseRuleMapper; private SportUserGameCurrencyBaseRuleMapper sportUserGameCurrencyBaseRuleMapper;
@Resource @Resource
private SportUserGameCurrencyMapper sportUserGameCurrencyMapper;
@Resource
private SportUserGameCurrencyLogMapper sportUserGameCurrencyLogMapper;
@Resource
private SportUserGameCurrencyMatchRuleMapper sportUserGameCurrencyMatchRuleMapper; private SportUserGameCurrencyMatchRuleMapper sportUserGameCurrencyMatchRuleMapper;
@Resource @Resource
...@@ -95,6 +88,9 @@ public class SportUserTrainingLogService { ...@@ -95,6 +88,9 @@ public class SportUserTrainingLogService {
@Resource @Resource
private SportUserConverter sportUserConverter; private SportUserConverter sportUserConverter;
@Resource
private SportUserGameCurrencyService sportUserGameCurrencyService;
public void createBicycleTrainingLog(Long playerId, Integer gameMode, Long sourceId, String sourceName, public void createBicycleTrainingLog(Long playerId, Integer gameMode, Long sourceId, String sourceName,
String map, String path, Integer praiseNum, CyclingDataDTO sportData) { String map, String path, Integer praiseNum, CyclingDataDTO sportData) {
SportUserTrainingLog log = sportUserTrainingLogConverter.toSportUserTrainingLog(sportData); SportUserTrainingLog log = sportUserTrainingLogConverter.toSportUserTrainingLog(sportData);
...@@ -151,28 +147,7 @@ public class SportUserTrainingLogService { ...@@ -151,28 +147,7 @@ public class SportUserTrainingLogService {
if (matchRule != null && matchRule.getRate() != null) { if (matchRule != null && matchRule.getRate() != null) {
currency = matchRule.getRate().multiply(BigDecimal.valueOf(currency)).intValue(); currency = matchRule.getRate().multiply(BigDecimal.valueOf(currency)).intValue();
} }
sportUserGameCurrencyService.addCurrency(playerId, currency, GameCurrencySourceType.SPORT, logId);
SportUserGameCurrency userGameCurrency =
sportUserGameCurrencyMapper.selectOne(new QueryWrapper<SportUserGameCurrency>().lambda().eq(SportUserGameCurrency::getSportUserId, playerId));
if (userGameCurrency == null) {
userGameCurrency = new SportUserGameCurrency();
userGameCurrency.setSportUserId(playerId);
userGameCurrency.setAmmount(currency);
userGameCurrency.setCtDate(LocalDateTime.now());
sportUserGameCurrencyMapper.insert(userGameCurrency);
} else {
userGameCurrency.setAmmount(userGameCurrency.getAmmount() + currency);
sportUserGameCurrencyMapper.updateById(userGameCurrency);
}
SportUserGameCurrencyLog gameCurrencyLog = new SportUserGameCurrencyLog();
gameCurrencyLog.setSportUserId(playerId);
gameCurrencyLog.setAmmount(currency);
gameCurrencyLog.setSourceId(logId);
gameCurrencyLog.setCtDate(LocalDateTime.now());
gameCurrencyLog.setType(GameCurrencyLogType.ADD);
sportUserGameCurrencyLogMapper.insert(gameCurrencyLog);
} }
/** /**
......
...@@ -5,6 +5,7 @@ import com.antai.sport.http.server.repository.sport.entity.*; ...@@ -5,6 +5,7 @@ import com.antai.sport.http.server.repository.sport.entity.*;
import com.antai.sport.http.server.repository.sport.mapper.SportUserContinuousLoginDaysMapper; import com.antai.sport.http.server.repository.sport.mapper.SportUserContinuousLoginDaysMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserLoginLogMapper; import com.antai.sport.http.server.repository.sport.mapper.SportUserLoginLogMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserMapper; import com.antai.sport.http.server.repository.sport.mapper.SportUserMapper;
import com.antai.sport.http.server.server.api.business.achievement.service.AchievementService;
import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO; import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO;
import com.antai.sport.http.server.server.api.business.traininglog.service.SportUserTrainingLogService; import com.antai.sport.http.server.server.api.business.traininglog.service.SportUserTrainingLogService;
import com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo; import com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo;
...@@ -33,6 +34,8 @@ public class SportUserService { ...@@ -33,6 +34,8 @@ public class SportUserService {
@Resource @Resource
private SportUserTrainingLogService sportUserTrainingLogService; private SportUserTrainingLogService sportUserTrainingLogService;
@Resource
private AchievementService achievementService;
public RespUserHomeInfo getUserHomeInfo(Long userId) { public RespUserHomeInfo getUserHomeInfo(Long userId) {
RespUserHomeInfo resp = new RespUserHomeInfo(); RespUserHomeInfo resp = new RespUserHomeInfo();
...@@ -113,6 +116,7 @@ public class SportUserService { ...@@ -113,6 +116,7 @@ public class SportUserService {
continuousLoginDays.setDays(continuousLoginDays.getDays() + 1); continuousLoginDays.setDays(continuousLoginDays.getDays() + 1);
continuousLoginDays.setLastLoginDate(LocalDate.now()); continuousLoginDays.setLastLoginDate(LocalDate.now());
sportUserContinuousLoginDaysMapper.updateById(continuousLoginDays); sportUserContinuousLoginDaysMapper.updateById(continuousLoginDays);
achievementService.handleSignInAchievement(sportUserId, continuousLoginDays.getDays());
return; return;
} }
//其他情况重置连续登录天数 //其他情况重置连续登录天数
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.server.api.business.achievement.mapper.AchievementBizMapper">
<select id="getSignInAchievement" resultType="com.antai.sport.http.server.repository.achievement.entity.Achievement">
select *
from achievement t1
where t1.deleted = 0
and t1.achievement_condition = #{achievementCondition}
and t1.id not in (
select w1.achievement_id
from achievement_for_sport_user w1
where w1.sport_user_id = #{sportUserId}
)
order by level
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment