Browse Source

fix 新增taihe-rpc模块

daiyihua 1 năm trước cách đây
mục cha
commit
e05010a8e1

+ 1 - 0
pom.xml

@@ -40,6 +40,7 @@
         <module>ywt-platform-outpatient-rpc</module>
         <module>ywt-platform-outpatient-rpc</module>
         <module>consumer</module>
         <module>consumer</module>
         <module>ywt-platform-outpatient-batch</module>
         <module>ywt-platform-outpatient-batch</module>
+        <module>ywt-platform-outpatient-taihe-rpc</module>
     </modules>
     </modules>
 
 
     <dependencyManagement>
     <dependencyManagement>

+ 142 - 0
ywt-platform-outpatient-taihe-rpc/pom.xml

@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>ywt-platform-outpatient-parent</artifactId>
+        <groupId>com.ywt</groupId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>ywt-platform-outpatient-taihe-rpc</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!-- xxl-job-core -->
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>jcl-over-slf4j</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>jul-to-slf4j</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jetty</artifactId>
+        </dependency>
+
+        <!-- 自动装配dubbo-->
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-spring-boot-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.nacos</groupId>
+            <artifactId>nacos-client</artifactId>
+        </dependency>
+
+        <!-- 注册中心 -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.ywt</groupId>
+            <artifactId>ywt-biz-common</artifactId>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>dev</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <properties>
+                <active.profile>dev</active.profile>
+            </properties>
+        </profile>
+        <profile>
+            <id>test</id>
+            <properties>
+                <active.profile>test</active.profile>
+            </properties>
+        </profile>
+        <profile>
+            <id>product</id>
+            <properties>
+                <active.profile>product</active.profile>
+            </properties>
+        </profile>
+
+    </profiles>
+    <build>
+        <filters>
+            <filter>../config_filters/filters-${active.profile}.properties</filter>
+        </filters>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.2</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>utf-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 15 - 0
ywt-platform-outpatient-taihe-rpc/src/main/java/com/ywt/OutpatientTaiheRpcServiceApplication.java

@@ -0,0 +1,15 @@
+package com.ywt;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableDubbo
+public class OutpatientTaiheRpcServiceApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(OutpatientTaiheRpcServiceApplication.class, args);
+    }
+
+}

+ 30 - 0
ywt-platform-outpatient-taihe-rpc/src/main/java/com/ywt/outpatient/taihe/rpc/config/db/Datasources.java

@@ -0,0 +1,30 @@
+package com.ywt.outpatient.taihe.rpc.config.db;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+
+/**
+ * Created by huangguoping.
+ */
+@Configuration
+public class Datasources {
+    @Bean(name = "ywtCenterDataSource")
+    @ConfigurationProperties(prefix="spring.datasource.ywtcenter")
+    @Primary
+    public DataSource ywtCenterDataSource(){
+        return new HikariDataSource();
+    }
+
+    @Bean(name = "ywtCenterJdbcTemplate")
+    public JdbcTemplate ywtCenterJdbcTemplate(
+            @Qualifier("ywtCenterDataSource") DataSource dataSource) {
+        return new JdbcTemplate(dataSource);
+    }
+}

+ 80 - 0
ywt-platform-outpatient-taihe-rpc/src/main/java/com/ywt/outpatient/taihe/rpc/config/db/Ywtcenter.java

@@ -0,0 +1,80 @@
+package com.ywt.outpatient.taihe.rpc.config.db;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
+import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
+import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Map;
+
+/**
+ * Created by huangguoping.
+ */
+@Configuration
+@EnableTransactionManagement
+@EnableJpaRepositories(
+        entityManagerFactoryRef = "entityManagerFactoryCenter",
+        transactionManagerRef = "transactionManagerCenter",
+        basePackages = {"com.ywt.outpatient.taihe.rpc.domain.entity.center"}
+)
+public class Ywtcenter {
+
+    private static final Logger log = LoggerFactory.getLogger(Ywtcenter.class);
+    @Autowired
+    @Qualifier("ywtCenterDataSource")
+    private DataSource ywtCenterDataSource;
+
+    @Autowired
+    private JpaProperties jpaProperties;
+
+    @Autowired
+    private HibernateProperties hibernateProperties;
+
+    /*
+     * 通过LocalContainerEntityManagerFactoryBean来获取EntityManagerFactory实例
+     */
+    @Bean(name = "entityManagerFactoryBeanCenter")
+    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(
+            EntityManagerFactoryBuilder builder) {
+        Map<String, Object> properties = hibernateProperties.determineHibernateProperties(
+                jpaProperties.getProperties(), new HibernateSettings());
+        return builder.dataSource(ywtCenterDataSource).properties(properties)
+                .packages("com.ywt.outpatient.taihe.rpc.domain.entity.center").build();
+    }
+
+    /*
+     * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory
+     * 总之,在执行操作之前,我们总要获取一个EntityManager,这就类似于Hibernate的Session,
+     * mybatis的sqlSession.
+     */
+    @Bean(name = "entityManagerFactoryCenter")
+    @Primary
+    public EntityManagerFactory entityManagerFactory(EntityManagerFactoryBuilder builder) {
+        log.info("创建ywt—center 的EntityManagerFactory");
+        return this.entityManagerFactoryBean(builder).getObject();
+    }
+
+    /*
+     * 配置事务管理器
+     */
+    @Bean(name = "transactionManagerCenter")
+    @Primary
+    public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
+        log.info("创建db1TransactionManager");
+        return new JpaTransactionManager(this.entityManagerFactory(builder));
+    }
+}

+ 37 - 0
ywt-platform-outpatient-taihe-rpc/src/main/java/com/ywt/proto/base.proto

@@ -0,0 +1,37 @@
+syntax = "proto3";
+
+
+package com.ywt.gapi;
+option java_multiple_files = true;
+option java_package = "com.ywt.gapi";
+option java_outer_classname = "BaseProto";
+
+enum ResultCode {
+    SUCCEED = 0;
+    PARAMETER_ERROR = 1;
+    OTHER_ERROR = 2;
+    APP_ERROR = 3;
+    APP_EXCEPTION = 4;
+}
+message Result {
+    ResultCode code = 1;
+    string info = 2;
+    string value = 3;
+}
+message ResultInt {
+    ResultCode code = 1;
+    string info = 2;
+    int32 value = 3;
+}
+message ResultInt64 {
+    ResultCode code = 1;
+    string info = 2;
+    int64 value = 3;
+}
+message ResultDouble {
+    ResultCode code = 1;
+    string info = 2;
+    double value = 3;
+}
+
+

+ 43 - 0
ywt-platform-outpatient-taihe-rpc/src/main/java/com/ywt/proto/system.proto

@@ -0,0 +1,43 @@
+// 开医疗设备检查的功能
+syntax = "proto3";
+
+import "base.proto";
+
+package com.ywt.gapi.system;
+
+option java_multiple_files = true;
+option java_package = "com.ywt.gapi.system";
+option java_outer_classname = "SystemProto";
+
+
+message Dept{
+    int32 deptId = 1;
+    string deptName = 2;
+    string deptCode = 3;
+    string yiDaCode = 4;	//医达科室code
+    int32 parentId = 5;
+    int32 subHospitalId = 6;
+}
+
+message HospitalDept{
+    int32 deptId = 1;
+    string deptName = 2;
+    repeated Dept deptList = 3;
+    string deptCode = 4;
+}
+
+message HospitalDeptListRequest{
+    int32 hospitalId = 1;
+    int32 subHospitalId = 2;
+    string name = 3;
+}
+
+message HospitalDeptListResponse{
+    Result result = 1;
+    repeated HospitalDept hospitalDeptList = 2;
+}
+// 对应 rpc 项目的 SystemServiceImpl 类
+service SystemService{
+    rpc getHospitalDeptList(HospitalDeptListRequest) returns (HospitalDeptListResponse);	//获取医院所有科室列表
+
+}

+ 67 - 0
ywt-platform-outpatient-taihe-rpc/src/main/resources/application.yml

@@ -0,0 +1,67 @@
+spring:
+  main:
+    allow-circular-references: true #允许循环依赖
+  application:
+    name: outpatient-batch
+    # redis 配置
+  redis:
+    enable: false # 开启redis
+    host: @redis.host@
+    port: @redis.port@
+  jpa:
+    hibernate:
+      ddl-auto: none
+      naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
+    show-sql: true
+    database-platform: org.hibernate.dialect.MySQL5Dialect
+  data:
+    jpa:
+      repositories:
+        enabled: true
+  # datasource 配置
+  datasource:
+    ywtcenter:
+      enable: true
+      jdbcUrl: @db.ywtcenter.url@
+      driver-class-name: com.mysql.jdbc.Driver
+      username: @db.ywtcenter.username@
+      password: @db.ywtcenter.password@
+      initialSize: 10
+      maxActive: 2000
+      minIdle: 1
+      maximumPoolSize: 200
+      autoCommit: true
+      poolName: HikariPool_center
+      maxLifetime: 1800000
+      connectionTestQuery: SELECT 1
+#dubbo 相关配置
+dubbo:
+  application:
+    logger: slf4j
+    qos-enable: false
+    register-mode: instance
+  registry:
+    address: nacos://@nacos.address@
+    parameters:
+      namespace: @nacos.namespace@
+  protocol:  #协议  消费者端可不配置
+    name: tri  #远triple协议
+    port: 20011  #端口
+  consumer:
+    #远程服务调用重试次数,不包括第一次调用,不需要重试请设为0
+    retries: 0
+    check: false
+#xxl 配置
+xxl:
+  job:
+    admin:
+      addresses: http://192.168.3.206:8081/xxl-job-admin/
+    executor:
+      appname: outpatient-batch
+      address:
+      ip:
+      port: 9999
+      logpath: /home/midware/xxl-job/jobhandler
+      logretentiondays: 30
+    accessToken: default_token
+

+ 31 - 0
ywt-platform-outpatient-taihe-rpc/src/main/resources/logback-spring.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false">
+    <appender name="FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--日志文件输出的文件名-->
+            <FileNamePattern>./logs/outpatient-taihe-rpc.%d{yyyy-MM-dd}.log</FileNamePattern>
+            <!--日志文件保留天数-->
+            <MaxHistory>30</MaxHistory>
+        </rollingPolicy>
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+        </encoder>
+        <!--日志文件最大的大小-->
+        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+            <MaxFileSize>100MB</MaxFileSize>
+        </triggeringPolicy>
+    </appender>
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <logger name="org.hibernate" level="ERROR" />
+    <!-- 日志输出级别 -->
+    <root level="@logging.level.root@">
+        <appender-ref ref="FILE" />
+        <appender-ref ref="console" />
+    </root>
+</configuration>