Przeglądaj źródła

Merge remote-tracking branch 'origin/package' into package

zhangxianyu 10 miesięcy temu
rodzic
commit
eb91c7fca7
19 zmienionych plików z 440 dodań i 137 usunięć
  1. 10 4
      game-gs-data/game-gs-data-base/pom.xml
  2. 105 57
      game-gs-data/game-gs-data-serve/pom.xml
  3. 48 0
      game-gs-data/game-gs-data-serve/src/main/java/com/zanxiang/game/gs/data/serve/config/SwaggerConfig.java
  4. 4 60
      game-gs-data/pom.xml
  5. 1 1
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java
  6. 8 5
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpSendMsgLogServiceImpl.java
  7. 20 7
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java
  8. 0 1
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfRoomServiceImpl.java
  9. 3 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfSessionUserServiceImpl.java
  10. 5 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfAppletReply.java
  11. 2 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/RoleOperate.java
  12. 1 1
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java
  13. 31 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/config/AsyncConfig.java
  14. 36 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/listener/GameRoleCreateEvent.java
  15. 49 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/listener/GameRoleCreateListener.java
  16. 20 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IRoleOperateService.java
  17. 6 1
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/AgentServiceImpl.java
  18. 7 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameUserRoleServiceImpl.java
  19. 84 0
      game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/RoleOperateServiceImpl.java

+ 10 - 4
game-gs-data/game-gs-data-base/pom.xml

@@ -22,10 +22,16 @@
 
     <dependencies>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.11</version>
-            <scope>test</scope>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metadata-definition-protobuf</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zanxiang.module</groupId>
+            <artifactId>zx-web</artifactId>
         </dependency>
     </dependencies>
 

+ 105 - 57
game-gs-data/game-gs-data-serve/pom.xml

@@ -8,70 +8,118 @@
         <version>0.0.1-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
     <artifactId>game-gs-data-serve</artifactId>
 
-    <name>game-gs-data-serve</name>
-    <url>http://www.example.com</url>
-
-    <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.7</maven.compiler.source>
-        <maven.compiler.target>1.7</maven.compiler.target>
-    </properties>
-
     <dependencies>
+        <!-- game-gs-data-base -->
+        <dependency>
+            <artifactId>game-gs-data-base</artifactId>
+            <groupId>com.zanxiang.game</groupId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- spring-boot-starter -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <!-- spring-cloud -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter</artifactId>
+        </dependency>
+        <!-- spring boot默认不去扫描 bootstrap.yml文件了 -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-bootstrap</artifactId>
+        </dependency>
+        <!-- SpringBoot start -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <!-- nacos配置中心 默认的 nacos-client 2.0.3有 bug -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.alibaba.nacos</groupId>
+                    <artifactId>nacos-client</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <!-- nacos注册中心 -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.alibaba.nacos</groupId>
+                    <artifactId>nacos-client</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.nacos</groupId>
+            <artifactId>nacos-client</artifactId>
+        </dependency>
+        <!-- 解决validated不生效的依赖问题 -->
+        <dependency>
+            <groupId>org.hibernate.validator</groupId>
+            <artifactId>hibernate-validator</artifactId>
+            <version>6.0.17.Final</version>
+            <scope>compile</scope>
+        </dependency>
+        <!-- erp权限 -->
+        <dependency>
+            <groupId>com.zanxiang.erp</groupId>
+            <artifactId>erp-security</artifactId>
+        </dependency>
+        <!-- swagger2 -->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+            <version>${swagger2.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+            <version>${swagger2.ui.version}</version>
+        </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.11</version>
-            <scope>test</scope>
+            <groupId>com.mybatis-flex</groupId>
+            <artifactId>mybatis-flex-spring-boot-starter</artifactId>
+            <version>1.7.5</version>
         </dependency>
     </dependencies>
 
     <build>
-        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
-            <plugins>
-                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>3.1.0</version>
-                </plugin>
-                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-                <plugin>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-compiler-plugin</artifactId>
-                    <version>3.8.0</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.22.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-jar-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-install-plugin</artifactId>
-                    <version>2.5.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-deploy-plugin</artifactId>
-                    <version>2.8.2</version>
-                </plugin>
-                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-site-plugin</artifactId>
-                    <version>3.7.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-project-info-reports-plugin</artifactId>
-                    <version>3.0.0</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.5.14</version>
+                <configuration>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
     </build>
 </project>

+ 48 - 0
game-gs-data/game-gs-data-serve/src/main/java/com/zanxiang/game/gs/data/serve/config/SwaggerConfig.java

@@ -0,0 +1,48 @@
+package com.zanxiang.game.gs.data.serve.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+/**
+ * @author : lingfeng
+ * @time : 2022-3-31
+ * @description : Swagger2 配置
+ */
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig {
+
+    /**
+     * 包扫描
+     */
+    @Bean
+    public Docket createRestApi() {
+        return new Docket(DocumentationType.SWAGGER_2)
+                .useDefaultResponseMessages(false)
+                .apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors
+                        .basePackage("com.zanxiang.game.module.manage"))
+                .paths(PathSelectors.any())
+                .build();
+    }
+
+    /**
+     * api文档构造
+     *
+     * @return : 返回api模板
+     */
+    private ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title("游戏管理后台服务")
+                .version("1.0")
+                .build();
+    }
+}

+ 4 - 60
game-gs-data/pom.xml

@@ -11,72 +11,16 @@
 
     <artifactId>game-gs-data</artifactId>
     <packaging>pom</packaging>
-
-    <name>game-gs-data</name>
-    <url>http://www.example.com</url>
     <modules>
         <module>game-gs-data-base</module>
         <module>game-gs-data-serve</module>
     </modules>
 
     <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.7</maven.compiler.source>
-        <maven.compiler.target>1.7</maven.compiler.target>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <swagger2.version>2.9.2</swagger2.version>
+        <swagger2.ui.version>2.9.2</swagger2.ui.version>
     </properties>
 
-    <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.11</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
-            <plugins>
-                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>3.1.0</version>
-                </plugin>
-                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-                <plugin>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-compiler-plugin</artifactId>
-                    <version>3.8.0</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.22.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-jar-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-install-plugin</artifactId>
-                    <version>2.5.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-deploy-plugin</artifactId>
-                    <version>2.8.2</version>
-                </plugin>
-                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-site-plugin</artifactId>
-                    <version>3.7.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-project-info-reports-plugin</artifactId>
-                    <version>3.0.0</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
-    </build>
 </project>

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (消息推送补发以及游戏区服信息下载・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (虚拟游戏更改为可接待03・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 8 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpSendMsgLogServiceImpl.java

@@ -74,8 +74,8 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
                 CpSendMsgResultDTO result = this.cpSendMsgApi(gameSupper, cpSendMsgLog.getMsgId(), serverId, text, serverRoleIdList);
                 this.reResultHandle(cpSendMsgLog, result, sendResultList);
             } catch (Exception e) {
-                log.error("CP消息发送API调用异常, cpSendMsgLog : {}, sendMsgResultList : {}",
-                        JsonUtil.toString(cpSendMsgLog), JsonUtil.toString(sendResultList));
+                log.error("CP消息发送API调用异常, cpSendMsgLog : {}, sendMsgResultList : {}, e : {}",
+                        JsonUtil.toString(cpSendMsgLog), JsonUtil.toString(sendResultList), e.getMessage(), e);
             }
         });
     }
@@ -129,11 +129,13 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
                 .collect(Collectors.groupingBy(GameUserRole::getServerId));
         serverIdRoleMap.forEach((serverId, roleList) -> {
             List<String> serverRoleIdList = roleList.stream().map(GameUserRole::getRoleId).collect(Collectors.toList());
+            CpSendMsgResultDTO result = null;
             try {
-                CpSendMsgResultDTO result = this.cpSendMsgApi(gameSupper, msgId, serverId, text, serverRoleIdList);
+                result = this.cpSendMsgApi(gameSupper, msgId, serverId, text, serverRoleIdList);
                 this.resultHandle(cpSendMsgLog, result, serverId, serverRoleIdList);
             } catch (Exception e) {
-                log.error("CP消息发送API调用异常, serverId : {}, roleList : {}", serverId, roleList);
+                log.error("CP消息发送API调用异常, serverId : {}, roleList : {}, result : {}, e : {}",
+                        serverId, roleList, JsonUtil.toString(result), e.getMessage(), e);
             }
         });
     }
@@ -210,8 +212,9 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
         String result;
         try {
             result = restTemplate.postForObject(gameSupper.getCpSendMsgUrl(), request, String.class);
+            log.error("CP推送消息结果, result : {}", result);
         } catch (Exception e) {
-            System.out.println(e.getMessage());
+            log.error("CP推送消息异常, e : {}", e.getMessage(), e);
             throw new BaseException("消息发送失败");
         }
         return JsonUtil.toObj(result, CpSendMsgResultDTO.class);

+ 20 - 7
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -147,9 +147,15 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         //虚拟游戏小程序, 单独逻辑
         if (Objects.equals(gameApplet.getType(), 3)) {
             //小程序自动回复
-            this.appletReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom, gameApplet.getAppId());
-            //保存房间消息
-            kfRoomMsgService.save(kfRoomMsg);
+            Boolean customerSwitch = this.appletReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(),
+                    kfRoom, gameApplet.getAppId());
+            if (Objects.equals(Boolean.TRUE, customerSwitch)) {
+                //保存消息, 玩家转入接待状态
+                this.saveMsgAndChangeWait(kfRoom, kfRoomMsg, gameApplet, kfAppletMsgDTO, msgContent);
+            } else {
+                //保存房间消息
+                kfRoomMsgService.save(kfRoomMsg);
+            }
             //直接结束
             return;
         }
@@ -169,6 +175,12 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         this.systemReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom);
         //消息报警监测
         this.monitorWordHandle(gameApplet, kfAppletMsgDTO);
+        //保存消息, 玩家转入接待状态
+        this.saveMsgAndChangeWait(kfRoom, kfRoomMsg, gameApplet, kfAppletMsgDTO, msgContent);
+    }
+
+    private void saveMsgAndChangeWait(KfRoom kfRoom, KfRoomMsg kfRoomMsg, GameApplet gameApplet, KfAppletMsgDTO kfAppletMsgDTO,
+                                      KfWebSocketMsgDTO.MsgContentBean msgContent) {
         //保存房间消息
         kfRoomMsgService.save(kfRoomMsg);
         //玩家状态更新为待接入状态
@@ -184,13 +196,13 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoomMsg, msgContent));
     }
 
-    private void appletReplyHandle(Long gameId, String openId, KfRoom kfRoom, String appId) {
+    private Boolean appletReplyHandle(Long gameId, String openId, KfRoom kfRoom, String appId) {
         //玩家信息
         KfSessionUser kfSessionUser = kfSessionUserService.getById(openId, gameId);
         //来源类型
         KfSessionFromEnum kfSessionFrom = KfSessionFromEnum.getKfSessionFrom(kfSessionUser.getSessionFrom());
         if (kfSessionFrom == null) {
-            return;
+            return Boolean.TRUE;
         }
         //查询玩家访问信息
         UserApplet userApplet = userAppletService.getOne(new LambdaQueryWrapper<UserApplet>()
@@ -200,7 +212,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
                 .last("limit 1"));
         //不存在访问信息, 不处理
         if (userApplet == null) {
-            return;
+            return Boolean.TRUE;
         }
         Map<String, String> channelMap = JsonUtil.toMap(userApplet.getChannel(), Map.class, String.class);
         String pageSign = channelMap.get(KfAppletReply.PAGE_SIGN);
@@ -212,7 +224,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
                 .orderByDesc(KfAppletReply::getCreateTime)
                 .last("limit 1"));
         if (kfAppletReply == null) {
-            return;
+            return Boolean.TRUE;
         }
         //存在文本消息发送
         if (Strings.isNotBlank(kfAppletReply.getReplyText())) {
@@ -233,6 +245,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             }
             this.sysLinkMsgSend(gameId, openId, kfRoom, linkMap);
         }
+        return kfAppletReply.getCustomerSwitch();
     }
 
     private void sysLinkMsgSend(Long gameId, String openId, KfRoom kfRoom, Map<String, String> linkMap) {

+ 0 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfRoomServiceImpl.java

@@ -117,7 +117,6 @@ public class KfRoomServiceImpl extends ServiceImpl<KfRoomMapper, KfRoom> impleme
         return gameAppletService.list(new LambdaQueryWrapper<GameApplet>()
                 .in(!SecurityUtil.isAdmin(), GameApplet::getGameId,
                         gameAuthList.stream().map(GameAuth::getGameId).collect(Collectors.toSet()))
-                .eq(GameApplet::getType, 1)
                 .eq(GameApplet::getKfNew, Boolean.TRUE)
         ).stream().map(gameApplet -> this.transform(gameApplet, kfUserId)).collect(Collectors.toList());
     }

+ 3 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfSessionUserServiceImpl.java

@@ -51,6 +51,8 @@ public class KfSessionUserServiceImpl extends ServiceImpl<KfSessionUserMapper, K
         return super.list(new LambdaQueryWrapper<KfSessionUser>()
                 .eq(KfSessionUser::getGameId, gameId)
                 .eq(KfSessionUser::getIsWait, Boolean.TRUE)
+                .orderByDesc(KfSessionUser::getWaitStartTime)
+                .last("limit 16")
         ).stream().map(this::transform).collect(Collectors.toList());
     }
 
@@ -61,6 +63,7 @@ public class KfSessionUserServiceImpl extends ServiceImpl<KfSessionUserMapper, K
         KfWebSocketMsgDTO.WaitUserBean waitUserBean = BeanUtil.copy(kfSessionUser, KfWebSocketMsgDTO.WaitUserBean.class);
         Page<KfRoomMsg> kfRoomMsgPage = kfRoomMsgService.page(new Page<>(1, 10),
                 new QueryWrapper<KfRoomMsg>().lambda()
+                        .eq(KfRoomMsg::getGameId, kfSessionUser.getGameId())
                         .eq(KfRoomMsg::getOpenId, kfSessionUser.getOpenId())
                         .eq(KfRoomMsg::getReadStatus, Boolean.FALSE)
                         .isNull(KfRoomMsg::getRoomId)

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfAppletReply.java

@@ -58,6 +58,11 @@ public class KfAppletReply implements Serializable {
      */
     private String replyLink;
 
+    /**
+     * 客服接待开关
+     */
+    private Boolean customerSwitch;
+
     /**
      * 创建时间
      */

+ 2 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/RoleOperate.java

@@ -24,6 +24,8 @@ public class RoleOperate implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    public static final Long SYSTEM_OPERATE = 0L;
+
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <session检测弹窗换行, 识别开发工具os> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <创角取消使用事件通知> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 31 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/config/AsyncConfig.java

@@ -0,0 +1,31 @@
+package com.zanxiang.game.module.sdk.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-27
+ * @description : 异步线程池配置
+ */
+@Configuration
+@EnableAsync
+public class AsyncConfig implements AsyncConfigurer {
+
+    @Override
+    public Executor getAsyncExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //设置核心线程数
+        executor.setCorePoolSize(30);
+        //设置最大线程数
+        executor.setMaxPoolSize(50);
+        //设置队列容量
+        executor.setQueueCapacity(50);
+        executor.initialize();
+        return executor;
+    }
+}

+ 36 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/listener/GameRoleCreateEvent.java

@@ -0,0 +1,36 @@
+package com.zanxiang.game.module.sdk.listener;
+
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-06-05
+ * @description : 游戏角色创建事件
+ */
+@Getter
+public class GameRoleCreateEvent extends ApplicationEvent {
+
+    /**
+     * 玩家id
+     */
+    private Long userId;
+
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+
+    /**
+     * 角色id
+     */
+    private String roleId;
+
+    public GameRoleCreateEvent(Object source, GameUserRole userRole) {
+        super(source);
+        this.userId = userRole.getUserId();
+        this.gameId = userRole.getGameId();
+        this.roleId = userRole.getRoleId();
+    }
+}

+ 49 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/listener/GameRoleCreateListener.java

@@ -0,0 +1,49 @@
+package com.zanxiang.game.module.sdk.listener;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
+import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
+import com.zanxiang.game.module.sdk.service.IRoleOperateService;
+import com.zanxiang.module.util.JsonUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-06-05
+ * @description : 游戏角色创建监听
+ */
+@Slf4j
+@Component
+public class GameRoleCreateListener {
+
+    @Autowired
+    private IRoleOperateService roleOperateService;
+
+    @Autowired
+    private IGameUserRoleService gameUserRoleService;
+
+    @Async
+    @EventListener
+    public void onApplicationEvent(GameRoleCreateEvent event) {
+        try {
+            //查询角色信息
+            GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
+                    .eq(GameUserRole::getGameId, event.getGameId())
+                    .eq(GameUserRole::getRoleId, event.getRoleId())
+                    .eq(GameUserRole::getUserId, event.getUserId()));
+            if (gameUserRole == null) {
+                log.error("角色创建事 : 查询角色信息为空, event : {}", JsonUtil.toString(event));
+                return;
+            }
+            log.error("创角事件消费 gameId : {}, roleId : {}", gameUserRole.getGameId(), gameUserRole.getRoleId());
+            //创角成功, 添加角色操作记录
+            roleOperateService.systemRoleOperate(gameUserRole);
+        } catch (Exception e) {
+            log.error("创角事件消费异常, event : {}, e : {}", JsonUtil.toString(event), e.getMessage(), e);
+        }
+    }
+}

+ 20 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IRoleOperateService.java

@@ -0,0 +1,20 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
+import com.zanxiang.game.module.mybatis.entity.RoleOperate;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-09-09
+ * @description : 角色操作表
+ */
+public interface IRoleOperateService extends IService<RoleOperate> {
+
+    /**
+     * 系统角色操作
+     *
+     * @param gameUserRole : 玩家角色信息
+     */
+    void systemRoleOperate(GameUserRole gameUserRole);
+}

+ 6 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/AgentServiceImpl.java

@@ -139,7 +139,12 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
         }
         //数据解析
         Map<String, String> urlParamMap = this.channelTransform(channel);
-        String shareUserId = urlParamMap.get("shareUserId");
+        String shareUserId = null;
+        String shareUserInfo = urlParamMap.get("shareUserId");
+        if (Strings.isNotBlank(shareUserInfo)) {
+            int questionMarkIndex = shareUserInfo.indexOf('?');
+            shareUserId = questionMarkIndex == -1 ? shareUserInfo : shareUserInfo.substring(0, questionMarkIndex);
+        }
         //查询渠道
         Agent agent = null;
         if (Strings.isNotBlank(shareUserId)) {

+ 7 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameUserRoleServiceImpl.java

@@ -22,6 +22,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
@@ -72,6 +74,9 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
     @Autowired
     private IGameExtService gameExtService;
 
+    @Autowired
+    private IRoleOperateService roleOperateService;
+
     @Override
     public Boolean updateUserGameRole(GameUserRoleSubmitParam param) {
         //查询游戏信息
@@ -265,6 +270,8 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
         kafkaService.eventTrack(KafkaEventTrackEnum.KAFKA_EVENT_TRACK_ROLE_CREATE, JsonUtil.toString(userRole));
         //创建角色通知监听服务
         this.callListenIn(param, userData);
+        //角色操作记录添加
+        roleOperateService.systemRoleOperate(userRole);
     }
 
     private GameUserRole transform(GameUserRoleUpdateParam param, UserData userData, GameUser gameUser, User user) {

+ 84 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/RoleOperateServiceImpl.java

@@ -0,0 +1,84 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
+import com.zanxiang.game.module.mybatis.entity.RoleOperate;
+import com.zanxiang.game.module.mybatis.entity.User;
+import com.zanxiang.game.module.mybatis.mapper.RoleOperateMapper;
+import com.zanxiang.game.module.sdk.service.IAgentService;
+import com.zanxiang.game.module.sdk.service.IRoleOperateService;
+import com.zanxiang.game.module.sdk.service.IUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.Map;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-09-09
+ * @description : 角色操作表
+ */
+@Slf4j
+@Service
+public class RoleOperateServiceImpl extends ServiceImpl<RoleOperateMapper, RoleOperate> implements IRoleOperateService {
+
+    @Autowired
+    private IUserService userService;
+
+    @Autowired
+    private IAgentService agentService;
+
+    @Override
+    public void systemRoleOperate(GameUserRole gameUserRole) {
+        try {
+            //查询玩家信息
+            User user = userService.getById(gameUserRole.getUserId());
+            //解析玩家渠道信息
+            Map<String, String> channelMap = agentService.channelTransform(user.getChannel());
+            if (!channelMap.containsKey("corpId") || !channelMap.containsKey("corpUserId")
+                    || !channelMap.containsKey("externalUserId")) {
+                log.error("创角非企微链路, 不做操作! gameId : {}, roleId : {}", gameUserRole.getGameId(), gameUserRole.getRoleId());
+                return;
+            }
+            //查询操作记录
+            RoleOperate roleOperate = super.getOne(new LambdaQueryWrapper<RoleOperate>()
+                    .eq(RoleOperate::getGameId, gameUserRole.getGameId())
+                    .eq(RoleOperate::getServerId, gameUserRole.getServerId())
+                    .eq(RoleOperate::getUserId, gameUserRole.getUserId())
+                    .eq(RoleOperate::getRoleId, gameUserRole.getRoleId()));
+            if (roleOperate == null) {
+                roleOperate = this.transform(gameUserRole, channelMap);
+            } else {
+                roleOperate.setCorpId(channelMap.get("corpId"));
+                roleOperate.setExternalUserId(channelMap.get("externalUserId"));
+                roleOperate.setAddCorpUserId(channelMap.get("corpUserId"));
+                roleOperate.setIsAddCorpWechat(1);
+                roleOperate.setUpdateBy(RoleOperate.SYSTEM_OPERATE);
+                roleOperate.setUpdateTime(LocalDateTime.now());
+            }
+            super.saveOrUpdate(roleOperate);
+        } catch (Exception e) {
+            log.error("创角添加记录异常! gameId : {}, roleId : {}", gameUserRole.getGameId(), gameUserRole.getRoleId());
+        }
+    }
+
+    private RoleOperate transform(GameUserRole gameUserRole, Map<String, String> channelMap) {
+        return RoleOperate.builder()
+                .gameId(gameUserRole.getGameId())
+                .serverId(gameUserRole.getServerId())
+                .userId(gameUserRole.getUserId())
+                .roleId(gameUserRole.getRoleId())
+                .corpId(channelMap.get("corpId"))
+                .externalUserId(channelMap.get("externalUserId"))
+                .addCorpUserId(channelMap.get("corpUserId"))
+                .isAddCorpWechat(1)
+                .createBy(RoleOperate.SYSTEM_OPERATE)
+                .createTime(LocalDateTime.now())
+                .updateBy(RoleOperate.SYSTEM_OPERATE)
+                .updateTime(LocalDateTime.now())
+                .build();
+    }
+}