|
@@ -1,7 +1,9 @@
|
|
package com.gis.cms.service.impl;
|
|
package com.gis.cms.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -10,6 +12,9 @@ import com.gis.admin.service.WxUserService;
|
|
import com.gis.cms.entity.dto.MyPageDto;
|
|
import com.gis.cms.entity.dto.MyPageDto;
|
|
import com.gis.cms.entity.dto.ScoreDto;
|
|
import com.gis.cms.entity.dto.ScoreDto;
|
|
import com.gis.cms.entity.po.GameLogEntity;
|
|
import com.gis.cms.entity.po.GameLogEntity;
|
|
|
|
+import com.gis.cms.entity.po.RoomEntity;
|
|
|
|
+import com.gis.cms.entity.vo.RoomRankingVo;
|
|
|
|
+import com.gis.cms.entity.vo.WxUserVo;
|
|
import com.gis.cms.mapper.GameLogMapper;
|
|
import com.gis.cms.mapper.GameLogMapper;
|
|
import com.gis.cms.service.GameLogService;
|
|
import com.gis.cms.service.GameLogService;
|
|
import com.gis.cms.service.RoomService;
|
|
import com.gis.cms.service.RoomService;
|
|
@@ -26,6 +31,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Optional;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,42 +51,58 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
|
|
@Autowired
|
|
@Autowired
|
|
RoomService roomService;
|
|
RoomService roomService;
|
|
|
|
|
|
-// @Override
|
|
|
|
-// public Result saveScore(ScoreDto param) {
|
|
|
|
-// Long roomId = param.getRoomId();
|
|
|
|
-// // 模式, 活动:activity , 普通:general
|
|
|
|
-// String type = "activity";
|
|
|
|
-// if (roomId == null){
|
|
|
|
-// type = "general";
|
|
|
|
-// }
|
|
|
|
-// GameLogEntity entity = new GameLogEntity();
|
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
|
-// entity.setType(type);
|
|
|
|
-// entity.setCreatorId(iBaseService.getUserId());
|
|
|
|
-// this.save(entity);
|
|
|
|
-// return Result.success();
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result saveScore(ScoreDto param) {
|
|
public Result saveScore(ScoreDto param) {
|
|
Long roomId = param.getRoomId();
|
|
Long roomId = param.getRoomId();
|
|
GameLogEntity entity;
|
|
GameLogEntity entity;
|
|
|
|
+ Long userId = iBaseService.getUserId();
|
|
// 模式, 活动:activity , 普通:general
|
|
// 模式, 活动:activity , 普通:general
|
|
if (roomId == null) {
|
|
if (roomId == null) {
|
|
String type = "general";
|
|
String type = "general";
|
|
entity = new GameLogEntity();
|
|
entity = new GameLogEntity();
|
|
BeanUtils.copyProperties(param, entity);
|
|
BeanUtils.copyProperties(param, entity);
|
|
entity.setType(type);
|
|
entity.setType(type);
|
|
- entity.setCreatorId(iBaseService.getUserId());
|
|
|
|
|
|
+
|
|
|
|
+ entity.setCreatorId(userId);
|
|
} else {
|
|
} else {
|
|
entity = this.getById(param.getGameLogId());
|
|
entity = this.getById(param.getGameLogId());
|
|
BeanUtils.copyProperties(param, entity);
|
|
BeanUtils.copyProperties(param, entity);
|
|
}
|
|
}
|
|
this.saveOrUpdate(entity);
|
|
this.saveOrUpdate(entity);
|
|
|
|
|
|
|
|
+ // 更新积分等级
|
|
|
|
+ updateUserLevel(userId, roomId);
|
|
|
|
+
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 更新积分等级
|
|
|
|
+ private void updateUserLevel(Long userId, Long roomId){
|
|
|
|
+ Integer totalScore = this.totalScore(userId, roomId);
|
|
|
|
+ int level = 0;
|
|
|
|
+ if (totalScore < 500){
|
|
|
|
+ level = 1;
|
|
|
|
+ } else if (totalScore < 1000) {
|
|
|
|
+ level = 2;
|
|
|
|
+ } else if (totalScore < 2000) {
|
|
|
|
+ level = 3;
|
|
|
|
+ } else if (totalScore < 5000) {
|
|
|
|
+ level = 4;
|
|
|
|
+ }
|
|
|
|
+ WxUserEntity entity = wxUserService.getById(userId);
|
|
|
|
+ // 更新等级
|
|
|
|
+ if (!entity.getLevel().equals(level)){
|
|
|
|
+ LambdaUpdateWrapper<WxUserEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ updateWrapper.set(WxUserEntity::getLevel, level);
|
|
|
|
+ wxUserService.update(updateWrapper);
|
|
|
|
+ log.info("更新等级完成:{}", level);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result list(MyPageDto param) {
|
|
public Result list(MyPageDto param) {
|
|
@@ -93,25 +116,54 @@ public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLogEntity
|
|
@Override
|
|
@Override
|
|
public Result detail(Long roomId) {
|
|
public Result detail(Long roomId) {
|
|
Long userId = iBaseService.getUserId();
|
|
Long userId = iBaseService.getUserId();
|
|
- HashMap<Object, Object> map = new HashMap<>();
|
|
|
|
- map.put("user", getWxUser(userId));
|
|
|
|
- map.put("ranking", roomService.ranking(roomId));
|
|
|
|
|
|
+ RoomEntity entity = roomService.getById(roomId);
|
|
|
|
+ BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
|
|
|
|
+ List<WxUserVo> rankings = roomService.ranking(roomId);
|
|
|
|
+ RoomRankingVo vo = new RoomRankingVo();
|
|
|
|
+ vo.setEndTime(entity.getEndTime());
|
|
|
|
+ vo.setRanking(rankings);
|
|
|
|
+ vo.setId(entity.getId());
|
|
|
|
+
|
|
|
|
+ //个人得分
|
|
|
|
+ List<WxUserVo> collect = rankings.stream().filter(p -> p.getId().equals(userId)).collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtil.isNotEmpty(collect)){
|
|
|
|
+ WxUserVo wxUserVo = collect.get(0);
|
|
|
|
+ vo.setScoreMy(wxUserVo.getScore());
|
|
|
|
+ }
|
|
|
|
|
|
- return Result.success(map);
|
|
|
|
|
|
+ //团队得分
|
|
|
|
+ Optional<Integer> reduce = rankings.stream().map(WxUserVo::getScore).reduce(Integer::sum);
|
|
|
|
+ Integer scoreTotal = reduce.orElse(null);
|
|
|
|
+ vo.setScoreTotal(scoreTotal);
|
|
|
|
+
|
|
|
|
+ return Result.success(vo);
|
|
}
|
|
}
|
|
|
|
|
|
private WxUserEntity getWxUser(Long userId) {
|
|
private WxUserEntity getWxUser(Long userId) {
|
|
WxUserEntity entity = wxUserService.getById(userId);
|
|
WxUserEntity entity = wxUserService.getById(userId);
|
|
BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
|
|
BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
|
|
// 统计得分
|
|
// 统计得分
|
|
- entity.setScore(countScore(userId));
|
|
|
|
|
|
+ entity.setScore(this.totalScore(userId, null));
|
|
return entity;
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
|
|
- // 统计得分
|
|
|
|
- private Integer countScore(Long userId) {
|
|
|
|
- String sqlStr = StrUtil.format("select sum(score) from tb_game_log where is_delete=0 and creator_id={}", userId);
|
|
|
|
- return getBaseMapper().sumSql(sqlStr);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 团队|个人总分
|
|
|
|
+ * @param userId 允许为空
|
|
|
|
+ * @param roomId 允许为空
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Integer totalScore(Long userId, Long roomId) {
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
+ sql.append("select sum(score) from tb_game_log where is_delete=0 ");
|
|
|
|
+ if (userId != null){
|
|
|
|
+ sql.append("and creator_id=").append(userId);
|
|
|
|
+ }
|
|
|
|
+ if (roomId != null){
|
|
|
|
+ sql.append("and room_id=").append(roomId);
|
|
|
|
+ }
|
|
|
|
+ return getBaseMapper().sumSql(sql.toString());
|
|
}
|
|
}
|
|
|
|
|
|
private IPage<GameLogEntity> getPage(MyPageDto param, Long userId) {
|
|
private IPage<GameLogEntity> getPage(MyPageDto param, Long userId) {
|