|
@@ -1,23 +1,67 @@
|
|
|
package com.hy.modules.bz.webapi.service.impl;
|
|
package com.hy.modules.bz.webapi.service.impl;
|
|
|
|
|
|
|
|
-import com.hy.modules.bz.webapi.dto.LoginInfoDto;
|
|
|
|
|
-import com.hy.modules.bz.webapi.dto.LoginResultDto;
|
|
|
|
|
-import com.hy.modules.bz.webapi.dto.RankingDto;
|
|
|
|
|
-import com.hy.modules.bz.webapi.dto.RankingFetchDto;
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.hy.common.tools.EncodeUtils;
|
|
|
|
|
+import com.hy.modules.bz.domain.BzPlayer;
|
|
|
|
|
+import com.hy.modules.bz.service.IBzPlayerService;
|
|
|
|
|
+import com.hy.modules.bz.webapi.dto.*;
|
|
|
import com.hy.modules.bz.webapi.service.WebApiService;
|
|
import com.hy.modules.bz.webapi.service.WebApiService;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class WebApiServiceImpl implements WebApiService {
|
|
public class WebApiServiceImpl implements WebApiService {
|
|
|
|
|
|
|
|
|
|
+ private static final String TOKEN_PRIFIX = "user:";
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IBzPlayerService playerService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private StringRedisTemplate redisTemplate;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public LoginResultDto login(LoginInfoDto loginInfo) {
|
|
public LoginResultDto login(LoginInfoDto loginInfo) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ QueryWrapper<BzPlayer> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("card_no",loginInfo.getCardNo())
|
|
|
|
|
+ .eq("card_password",loginInfo.getCardPwd())
|
|
|
|
|
+ .eq("status","normal");
|
|
|
|
|
+ BzPlayer player = playerService.getOne(queryWrapper,false);
|
|
|
|
|
+ Assert.notNull(player,"No player found");
|
|
|
|
|
+
|
|
|
|
|
+ String toEncode = UUID.randomUUID().toString().concat(String.valueOf(loginInfo.getTimestamp()));
|
|
|
|
|
+ String token = EncodeUtils.customBase64Encode(toEncode);
|
|
|
|
|
+ redisTemplate.opsForValue().set(TOKEN_PRIFIX.concat(loginInfo.getCardNo()),token);
|
|
|
|
|
+ LoginResultDto loginResultDto = new LoginResultDto();
|
|
|
|
|
+ loginResultDto.setToken(token);
|
|
|
|
|
+ loginResultDto.setCardNo(loginResultDto.getCardNo());
|
|
|
|
|
+ return loginResultDto;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void logout(LogoutDto logoutDto) {
|
|
|
|
|
+ QueryWrapper<BzPlayer> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("card_no",logoutDto.getCardNo())
|
|
|
|
|
+ .eq("status","normal");
|
|
|
|
|
+ BzPlayer player = playerService.getOne(queryWrapper,false);
|
|
|
|
|
+ Assert.notNull(player,"No player found");
|
|
|
|
|
+
|
|
|
|
|
+ String token = redisTemplate.opsForValue().get(TOKEN_PRIFIX.concat(logoutDto.getCardNo()));
|
|
|
|
|
+ if(null!=token){
|
|
|
|
|
+ if(!token.equals(logoutDto.getToken())){
|
|
|
|
|
+ throw new RuntimeException("Illegal request for user: " + logoutDto.getCardNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ redisTemplate.delete(TOKEN_PRIFIX.concat(logoutDto.getCardNo()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<RankingDto> rankingList(RankingFetchDto fetchDto) {
|
|
public List<RankingDto> rankingList(RankingFetchDto fetchDto) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|