Pārlūkot izejas kodu

新增短信服务

lijun 1 gadu atpakaļ
vecāks
revīzija
8241588917

+ 15 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteSmsService.java

@@ -0,0 +1,15 @@
+package com.xunmei.system.api;
+
+import com.xunmei.common.core.constant.ServiceNameConstants;
+import com.xunmei.system.api.factory.RemoteUserFallbackFactory;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@FeignClient(contextId = "remoteSmsService", value = ServiceNameConstants.SMS, fallbackFactory = RemoteUserFallbackFactory.class)
+public interface RemoteSmsService {
+
+    @GetMapping("/test/send")
+    String testSms(@RequestParam(value = "orgId") Long orgId);
+
+}

+ 27 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteSmsFallbackFactory.java

@@ -0,0 +1,27 @@
+package com.xunmei.system.api.factory;
+
+import com.xunmei.system.api.RemoteSmsService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cloud.openfeign.FallbackFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * @description:
+ * @author: lj
+ * @Date: 2024/2/22 17:23
+ */
+@Component
+public class RemoteSmsFallbackFactory implements FallbackFactory<RemoteSmsService> {
+    private static final Logger log = LoggerFactory.getLogger(RemoteSmsFallbackFactory.class);
+    @Override
+    public RemoteSmsService create(Throwable throwable) {
+        log.error("用户服务调用失败:{}", throwable.getMessage());
+        return new RemoteSmsService() {
+            @Override
+            public String testSms(Long orgId) {
+                return "error";
+            }
+        };
+    }
+}

+ 1 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/ServiceNameConstants.java

@@ -26,4 +26,5 @@ public class ServiceNameConstants
     public static final String SYNC_SERVICE = "soc-sync";
     public static final String JOB_SERVICE="soc-job";
     public static final String MEDIATOR_SERVICE="soc-mediator";
+    public static final String SMS="soc-sms";
 }

+ 1 - 0
soc-modules/pom.xml

@@ -24,6 +24,7 @@
         <module>soc-modules-gen</module>
         <module>soc-modules-mediator</module>
         <module>soc-modules-iot</module>
+        <module>soc-modules-sms</module>
     </modules>
 
 </project>

+ 117 - 0
soc-modules/soc-modules-sms/pom.xml

@@ -0,0 +1,117 @@
+<?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>soc-modules</artifactId>
+        <groupId>com.xunmei</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>soc-modules-sms</artifactId>
+    <description>
+        soc-modules-sms短信模块
+    </description>
+
+    <dependencies>
+        <!-- SpringCloud Alibaba Nacos -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+        </dependency>
+
+        <!-- SpringCloud Alibaba Nacos Config -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+        </dependency>
+
+        <!-- SpringCloud Alibaba Sentinel -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
+        </dependency>
+
+        <!-- SpringBoot Actuator -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+
+        <!-- Swagger UI -->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+            <version>${swagger.fox.version}</version>
+        </dependency>
+
+        <!-- Mysql Connector -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+
+
+        <!--soc datascope 数据权限-->
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-common-datascope</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-common-datasource</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-common-log</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.8</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-common-swagger</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-common-core</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.xunmei</groupId>
+            <artifactId>soc-api-system</artifactId>
+            <version>${soc.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+        <plugins>
+            <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>

+ 28 - 0
soc-modules/soc-modules-sms/src/main/java/com/xunmei/sms/SocSmsApplication.java

@@ -0,0 +1,28 @@
+package com.xunmei.sms;
+
+import com.xunmei.common.security.annotation.EnableCustomConfig;
+import com.xunmei.common.security.annotation.EnableSocFeignClients;
+import com.xunmei.common.swagger.annotation.EnableCustomSwagger2;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+
+/**
+ * @description:
+ * @author: lj
+ * @Date: 2024/2/21 17:37
+ */
+@EnableCustomConfig
+@EnableCustomSwagger2
+@EnableSocFeignClients
+@ComponentScan({"com.xunmei.*"})
+@SpringBootApplication
+@Slf4j
+public class SocSmsApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(SocSmsApplication.class, args);
+        System.out.println("(♥◠‿◠)ノ゙  短信模块启动成功   ლ(´ڡ`ლ)゙  ");
+        log.info("(♥◠‿◠)ノ゙  短信模块启动成功   ლ(´ڡ`ლ)゙  ");
+    }
+}

+ 28 - 0
soc-modules/soc-modules-sms/src/main/java/com/xunmei/sms/controller/TestController.java

@@ -0,0 +1,28 @@
+package com.xunmei.sms.controller;
+
+import com.xunmei.common.core.web.controller.BaseController;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: lj
+ * @Date: 2024/2/22 16:26
+ */
+@Api(tags = {"SmsTest"})
+@RestController
+@RequestMapping("/test")
+public class TestController extends BaseController {
+
+    @ApiOperation(value = "根据机构获取区域")
+    @GetMapping("/send")
+    public String getAreaByOrg(@RequestParam(value = "orgId") Long orgId) {
+        return "Ok"+ " " + orgId;
+    }
+}

+ 20 - 0
soc-modules/soc-modules-sms/src/main/java/com/xunmei/sms/controller/VersionController.java

@@ -0,0 +1,20 @@
+package com.xunmei.sms.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author gaoxiong
+ * @Title: 获取当前服务是否在线
+ * @Package
+ * @Description:
+ * @date 2023/11/2217:55
+ */
+@RestController
+public class VersionController {
+
+    @RequestMapping("/version")
+    public String getVersion(){
+        return "未设置";
+    }
+}

+ 14 - 0
soc-modules/soc-modules-sms/src/main/resources/banner.txt

@@ -0,0 +1,14 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+
+ _______  _______  _______      _______  _______  _______
+(  ____ \(  ___  )(  ____ \    (  ____ \(       )(  ____ \
+| (    \/| (   ) || (    \/    | (    \/| () () || (    \/
+| (_____ | |   | || |          | (_____ | || || || (_____
+(_____  )| |   | || |          (_____  )| |(_)| |(_____  )
+      ) || |   | || |                ) || |   | |      ) |
+/\____) || (___) || (____/\    /\____) || )   ( |/\____) |
+\_______)(_______)(_______/    \_______)|/     \|\_______)
+
+
+

+ 74 - 0
soc-modules/soc-modules-sms/src/main/resources/logback.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+    <!-- 日志存放路径 -->
+	<property name="log.path" value="logs/soc-sms" />
+   <!-- 日志输出格式 -->
+	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
+
+    <!-- 控制台输出 -->
+	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+		<encoder>
+			<pattern>${log.pattern}</pattern>
+		</encoder>
+	</appender>
+
+    <!-- 系统日志输出 -->
+	<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
+	    <file>${log.path}/info.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+			<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
+			<!-- 日志最大的历史 30天 -->
+			<maxHistory>30</maxHistory>
+		</rollingPolicy>
+		<encoder>
+			<pattern>${log.pattern}</pattern>
+		</encoder>
+		<filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>INFO</level>
+            <!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+            <!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+	</appender>
+
+    <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
+	    <file>${log.path}/error.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+            <fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
+			<!-- 日志最大的历史 30天 -->
+			<maxHistory>30</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>ERROR</level>
+			<!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+			<!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+    <!-- 系统模块日志级别控制  -->
+	<logger name="com.xunmei" level="info" />
+	<!-- Spring日志级别控制  -->
+	<logger name="org.springframework" level="warn" />
+
+	<root level="info">
+		<appender-ref ref="console" />
+	</root>
+	
+	<!--系统操作日志-->
+    <root level="info">
+        <appender-ref ref="file_info" />
+        <appender-ref ref="file_error" />
+    </root>
+</configuration>