Browse Source

20201210v2.0

recovery
zy_Java 5 years ago
parent
commit
9429af66f1
  1. 1
      cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/RibbonClientConfig.java
  2. 4
      cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/RibbonConfiguration.java
  3. 56
      cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/WpsBalanceRule.java
  4. 132
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  5. 3
      game/src/main/resources/application-dev.yml
  6. 3
      game/src/main/resources/application-prod.yml
  7. 3
      game/src/main/resources/application-prodsd.yml
  8. 4
      game/src/main/resources/application-test.yml
  9. 4
      game/src/main/resources/application.yml
  10. 2
      tall/src/main/java/com/ccsens/tall/TallApplication.java
  11. 6
      tall/src/main/java/com/ccsens/tall/web/DebugController.java
  12. 15
      util/src/main/java/com/ccsens/util/PropUtil.java

1
cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/RibbonClientConfig.java

@ -1,6 +1,7 @@
package com.ccsens.cloudutil.ribbon; package com.ccsens.cloudutil.ribbon;
import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**

4
cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/RibbonConfiguration.java

@ -14,10 +14,6 @@ import org.springframework.context.annotation.Configuration;
* @create: 2019/11/26 12:04 * @create: 2019/11/26 12:04
*/ */
@Configuration @Configuration
//@RibbonClients(value = {
// @RibbonClient(name = "tall",configuration = WpsBalanceRule.class)
//},defaultConfiguration = RibbonConfiguration.class)
@RibbonClient(name = "tall",configuration= WpsBalanceRule.class)
public class RibbonConfiguration { public class RibbonConfiguration {
/**根据响应时间加权,响应时间越长,权重越小,被选中的可能性越低*/ /**根据响应时间加权,响应时间越长,权重越小,被选中的可能性越低*/
// @Bean // @Bean

56
cloudutil/src/main/java/com/ccsens/cloudutil/ribbon/WpsBalanceRule.java

@ -1,28 +1,28 @@
package com.ccsens.cloudutil.ribbon; //package com.ccsens.cloudutil.ribbon;
//
import com.netflix.client.config.IClientConfig; //import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule; //import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.ILoadBalancer; //import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server; //import com.netflix.loadbalancer.Server;
import org.springframework.context.annotation.Primary; //import org.springframework.context.annotation.Primary;
//
@Primary ////@Primary
public class WpsBalanceRule extends AbstractLoadBalancerRule { //public class WpsBalanceRule extends AbstractLoadBalancerRule {
//
@Override // @Override
public void initWithNiwsConfig(IClientConfig clientConfig) { // public void initWithNiwsConfig(IClientConfig clientConfig) {
//
} // }
//
@Override // @Override
public Server choose(Object key) { // public Server choose(Object key) {
return choose(getLoadBalancer(), key); // return choose(getLoadBalancer(), key);
} // }
//
private Server choose(ILoadBalancer loadBalancer, Object key) { // private Server choose(ILoadBalancer loadBalancer, Object key) {
System.out.println(key); // System.out.println(key);
return null; // return null;
} // }
//
//
} //}

132
game/src/main/java/com/ccsens/game/service/ScreenService.java

@ -156,6 +156,10 @@ public class ScreenService implements IScreenService {
}else if( GameConstant.GAME_TYPE_BH.equalsIgnoreCase(memberGame.getGameType())){ }else if( GameConstant.GAME_TYPE_BH.equalsIgnoreCase(memberGame.getGameType())){
businessType = 10; businessType = 10;
} }
Map<String,Object> map = new HashMap<>();
map.put("businessId",memberGame.getTaskId());
map.put("businessType",businessType);
// String wpsFilePath = (String)RestTemplateUtil.getForEntity(PropUtil.gatewayUrl + PropUtil.getWpsFilePath, map, String.class);
String wpsFilePath = tallFeignClient.getWpsFilePath(memberGame.getTaskId(),businessType); String wpsFilePath = tallFeignClient.getWpsFilePath(memberGame.getTaskId(),businessType);
log.info("游戏配置表的路径:{}",wpsFilePath); log.info("游戏配置表的路径:{}",wpsFilePath);
if(StrUtil.isNotEmpty(wpsFilePath)){ if(StrUtil.isNotEmpty(wpsFilePath)){
@ -350,118 +354,6 @@ public class ScreenService implements IScreenService {
return gameUserPay; return gameUserPay;
} }
// @Override
// public ScreenVo.UrlVo getScreenUrl(QueryDto<ScreenDto.MemberGame> params) throws Exception {
// ScreenDto.MemberGame memberGame = params.getParam();
// //查找游戏
// GameType gameType = null;
// GameTypeExample gameTypeExample = new GameTypeExample();
// gameTypeExample.createCriteria().andCodeEqualTo(memberGame.getGameType());
// List<GameType> gameTypeList = gameTypeDao.selectByExample(gameTypeExample);
// if (CollectionUtil.isNotEmpty(gameTypeList)) {
// gameType = gameTypeList.get(0);
// }
// if (ObjectUtil.isNull(gameType)) {
// throw new BaseException(CodeEnum.NOT_GAME_TYPE);
// }
// //2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次
// GameUserPay gameUserPay = null;
// GameUserPayExample gameUserPayExample = new GameUserPayExample();
// gameUserPayExample.createCriteria().andUserIdEqualTo(params.getUserId()).andGameTypeIdEqualTo(gameType.getId());
// List<GameUserPay> gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample);
// if (CollectionUtil.isNotEmpty(gameUserPayList)) {
// gameUserPay = gameUserPayList.get(0);
// } else {
// gameUserPay = new GameUserPay();
// gameUserPay.setId(snowflake.nextId());
// gameUserPay.setUserId(params.getUserId());
// gameUserPay.setGameTypeId(gameType.getId());
// gameUserPay.setTotalCount(10);
// gameUserPay.setUsedCount(0);
// gameUserPay.setCreatedTime(System.currentTimeMillis());
// gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30));
// gameUserPayDao.insertSelective(gameUserPay);
// }
// //查询该任务下的游戏记录信息
// if (ObjectUtil.isNotNull(memberGame.getTaskId())) {
// GameRecordExample recordExample = new GameRecordExample();
// recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId());
// recordExample.setOrderByClause("created_at DESC");
// List<GameRecord> recordList = gameRecordDao.selectByExample(recordExample);
// if (CollectionUtil.isNotEmpty(recordList)) {
// GameRecord record = recordList.get(0);
// if(record.getGameStatus() == GameConstant.GAME_PREPARATION ||
// record.getGameStatus() == GameConstant.GAME_PROCESSING){
// throw new BaseException(CodeEnum.GAME_NO_END);
// }
// if(record.getGameStatus() == GameConstant.GAME_PENDING){
// record.setGameStatus(GameConstant.GAME_COMPLETED);
// gameRecordDao.updateByPrimaryKeySelective(record);
// }
// }
// }
//
// //3、根据用户购买的记录,添加一场新的游戏记录
// GameRecord gameRecord = new GameRecord();
// gameRecord.setId(snowflake.nextId());
// gameRecord.setUserPayId(gameUserPay.getId());
// gameRecord.setTaskId(memberGame.getTaskId());
// //添加路径
// String gameUrl = WebConstant.TEST_URL_GAME_SQ;
// switch (gameType.getCode()){
// case GameConstant.GAME_TYPE_SQ: break;
// case GameConstant.GAME_TYPE_SP: gameUrl = WebConstant.TEST_URL_GAME_SP; break;
// case GameConstant.GAME_TYPE_BH: gameUrl = WebConstant.TEST_URL_GAME_BH; break;
// default:break;
// }
// gameRecord.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecord.getId());
// gameRecord.setQrCodeUrl(gameUrl + gameRecord.getId() + File.separator + gameType.getClientUrl());
// gameRecordDao.insertSelective(gameRecord);
// //4、 判断是否有分组,如果是分组游戏,添加两条分组信息
// if (gameType.getIsGroup() == 1) {
// GameGroup gameGroupRed = new GameGroup();
// gameGroupRed.setId(snowflake.nextId());
// gameGroupRed.setRecordId(gameRecord.getId());
// gameGroupRed.setName(memberGame.getFirstTeam());
// gameGroupRed.setCode(GameConstant.FIRST_GROUP);
// gameGroupDao.insertSelective(gameGroupRed);
// GameGroup gameGroupBlue = new GameGroup();
// gameGroupBlue.setId(snowflake.nextId());
// gameGroupBlue.setRecordId(gameRecord.getId());
// gameGroupBlue.setName(memberGame.getSecondTeam());
// gameGroupBlue.setCode(GameConstant.SECOND_GROUP);
// gameGroupDao.insertSelective(gameGroupBlue);
// }
//
// //5、查询该游戏的规则
// List<String> ruleList = getGameActivityRule(gameType.getId());
// //6、返回
// ScreenVo.UrlVo urlVo = new ScreenVo.UrlVo();
// urlVo.setId(gameRecord.getId());
// urlVo.setUrl(gameRecord.getUrl());
// urlVo.setRuleList(ruleList);
//
// //路径(添加项目id)
// String url = gameRecord.getUrl() + "&projectId=" + memberGame.getProjectId();
// //给所有人发送消息发送消息
// ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberGame.getProjectId(),gameType.getCode());
// BaseMessageDto.MessageUser messageUser = null;
// List<BaseMessageDto.MessageUser> messageUserList = new ArrayList<>();
// //获取项目下所有成员
// List<Long> memberIdList = tallFeignClient.getMemberIdListByProject(memberGame.getProjectId());
// if (CollectionUtil.isNotEmpty(memberIdList)) {
// for (Long memberId : memberIdList) {
// messageUser = new BaseMessageDto.MessageUser();
// messageUser.setUserId(memberId);
// messageUserList.add(messageUser);
// }
// }
// chromeMessageDto.setReceivers(messageUserList);
// messageService.sendGameMessageWithGetUrl(chromeMessageDto);
//
// return urlVo;
// }
/** /**
* 获取游戏基本信息 * 获取游戏基本信息
* @return 返回游戏基本信息 * @return 返回游戏基本信息
@ -1384,11 +1276,19 @@ public class ScreenService implements IScreenService {
businessType = 10; businessType = 10;
} }
//查询该任务是否已有创建的游戏配置 //查询该任务是否已有创建的游戏配置
List<String> wpsPath; List<String> wpsPath = new ArrayList<>();
WpsDto.VisitWpsUrl visitWpsUrl = new WpsDto.VisitWpsUrl(); WpsDto.VisitWpsUrl visitWpsUrl = new WpsDto.VisitWpsUrl();
visitWpsUrl.setBusinessId(getConfig.getTaskId()); visitWpsUrl.setBusinessId(getConfig.getTaskId());
visitWpsUrl.setBusinessType(businessType); visitWpsUrl.setBusinessType(businessType);
visitWpsUrl.setUserId(params.getUserId()); visitWpsUrl.setUserId(params.getUserId());
// String result = RestTemplateUtil.postBody(PropUtil.gatewayUrl + PropUtil.queryVisitUrls, visitWpsUrl);
// log.info("调用tall查看游戏已有配置表:{}",result);
// if(StrUtil.isNotEmpty(result)){
// JSONObject json = JSONObject.parseObject(result);
// wpsPath.add(result);
//// wpsPath = (List<String>) json;
// }
wpsPath = tallFeignClient.queryVisitUrls(visitWpsUrl); wpsPath = tallFeignClient.queryVisitUrls(visitWpsUrl);
log.info("是否已有创建的游戏配置:{}",wpsPath); log.info("是否已有创建的游戏配置:{}",wpsPath);
//有配置直接返回 //有配置直接返回
@ -1434,7 +1334,13 @@ public class ScreenService implements IScreenService {
business.setFileSize(tmpFile.length()); business.setFileSize(tmpFile.length());
business.setOperation(WebConstant.Wps.USER_OPERATION_NEW); business.setOperation(WebConstant.Wps.USER_OPERATION_NEW);
business.setPrivilege(WebConstant.Wps.PROJECT_PRIVILEGE_WRITE); business.setPrivilege(WebConstant.Wps.PROJECT_PRIVILEGE_WRITE);
// RestTemplateUtil.postBody(PropUtil.gatewayUrl + PropUtil.saveWpsFile, business);
tallFeignClient.saveWpsFile(business); tallFeignClient.saveWpsFile(business);
// String s = RestTemplateUtil.postBody(PropUtil.gatewayUrl + PropUtil.queryVisitUrls, visitWpsUrl);
// if(StrUtil.isNotEmpty(s)){
// JSONObject json = JSONObject.parseObject(s);
// wpsPath = (List<String>) json;
// }
wpsPath = tallFeignClient.queryVisitUrls(visitWpsUrl); wpsPath = tallFeignClient.queryVisitUrls(visitWpsUrl);
return wpsPath; return wpsPath;
} }

3
game/src/main/resources/application-dev.yml

@ -30,6 +30,9 @@ swagger:
gatewayUrl: https://test.tall.wiki/gateway/ gatewayUrl: https://test.tall.wiki/gateway/
notGatewayUrl: https://test.tall.wiki/ notGatewayUrl: https://test.tall.wiki/
gameMqName: game_status_dev gameMqName: game_status_dev
saveWpsFile: tall/v1.0/wps/saveWps
queryVisitUrls: tall/v1.0/wps/visitUrls
getWpsFilePath: tall/v1.0/v1/3rd/getFilePath
file: file:
qrCode: https://test.tall.wiki/gateway/tall/uploads/ qrCode: https://test.tall.wiki/gateway/tall/uploads/
openWX: 0 openWX: 0

3
game/src/main/resources/application-prod.yml

@ -37,6 +37,9 @@ eureka:
gatewayUrl: https://www.tall.wiki/gateway/ gatewayUrl: https://www.tall.wiki/gateway/
notGatewayUrl: https://www.tall.wiki/ notGatewayUrl: https://www.tall.wiki/
gameMqName: game_status_www gameMqName: game_status_www
saveWpsFile: tall/v1.0/wps/saveWps
queryVisitUrls: tall/v1.0/wps/visitUrls
getWpsFilePath: tall/v1.0/v1/3rd/getFilePath
file: file:
qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/ qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/
openWX: 1 openWX: 1

3
game/src/main/resources/application-prodsd.yml

@ -36,6 +36,9 @@ eureka:
gatewayUrl: https://www.tall.wiki/gateway/ gatewayUrl: https://www.tall.wiki/gateway/
notGatewayUrl: https://www.tall.wiki/ notGatewayUrl: https://www.tall.wiki/
gameMqName: game_status_sd gameMqName: game_status_sd
saveWpsFile: tall/v1.0/wps/saveWps
queryVisitUrls: tall/v1.0/wps/visitUrls
getWpsFilePath: tall/v1.0/v1/3rd/getFilePath
file: file:
qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/ qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/
openWX: 1 openWX: 1

4
game/src/main/resources/application-test.yml

@ -32,6 +32,10 @@ eureka:
gatewayUrl: https://test.tall.wiki/gateway/ gatewayUrl: https://test.tall.wiki/gateway/
notGatewayUrl: https://test.tall.wiki/ notGatewayUrl: https://test.tall.wiki/
gameMqName: game_status_sd
saveWpsFile: tall/v1.0/wps/saveWps
queryVisitUrls: tall/v1.0/wps/visitUrls
getWpsFilePath: tall/v1.0/v1/3rd/getFilePath
file: file:
qrCode: https://test.tall.wiki/gateway/tall/v1.0/uploads/ qrCode: https://test.tall.wiki/gateway/tall/v1.0/uploads/
openWX: 0 openWX: 0

4
game/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring: spring:
profiles: profiles:
active: dev active: prod
include: common, util-dev include: common, util-prod

2
tall/src/main/java/com/ccsens/tall/TallApplication.java

@ -1,6 +1,5 @@
package com.ccsens.tall; package com.ccsens.tall;
import com.ccsens.cloudutil.ribbon.WpsBalanceRule;
import com.ccsens.util.WebConstant; import com.ccsens.util.WebConstant;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
@ -8,7 +7,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;

6
tall/src/main/java/com/ccsens/tall/web/DebugController.java

@ -43,10 +43,10 @@ public class DebugController {
}) })
@RequestMapping(value="",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) @RequestMapping(value="",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse getSmsCode(HttpServletRequest request) throws Exception { public JsonResponse getSmsCode(HttpServletRequest request) throws Exception {
redisUtil.set("wps_tall_appId","d12722a7d28e430c889309fa4754aaba"); // redisUtil.set("wps_tall_appId","d12722a7d28e430c889309fa4754aaba");
redisUtil.set("wps_tall_appKey","f273e717247947ba8942a2373b6896c7"); // redisUtil.set("wps_tall_appKey","f273e717247947ba8942a2373b6896c7");
return JsonResponse.newInstance().ok(redisUtil.get("wps_tall_appId")); return JsonResponse.newInstance().ok("测试");
} }

15
util/src/main/java/com/ccsens/util/PropUtil.java

@ -24,7 +24,22 @@ public class PropUtil {
public static String openWx; public static String openWx;
public static String signUpUrl; public static String signUpUrl;
public static String gameMqName; public static String gameMqName;
public static String saveWpsFile;
public static String queryVisitUrls;
public static String getWpsFilePath;
@Value("${saveWpsFile:}")
public void setSaveWpsFile(String saveWpsFile) {
PropUtil.saveWpsFile = saveWpsFile;
}
@Value("${queryVisitUrls:}")
public void setQueryVisitUrls(String queryVisitUrls) {
PropUtil.queryVisitUrls = queryVisitUrls;
}
@Value("${getWpsFilePath:}")
public void setGetWpsFilePath(String getWpsFilePath) {
PropUtil.getWpsFilePath = getWpsFilePath;
}
@Value("${gameMqName:}") @Value("${gameMqName:}")
public void setGameMqName(String gameMqName) { public void setGameMqName(String gameMqName) {
PropUtil.gameMqName = gameMqName; PropUtil.gameMqName = gameMqName;

Loading…
Cancel
Save