From dbaab0484bfed855c6be65bb0f6452cadb99ae73 Mon Sep 17 00:00:00 2001 From: BrandWang Date: Mon, 8 May 2023 19:24:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=8F=AF=E5=9B=9E=E6=BA=AF):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加feign --- afis-recall-api/.gitignore | 38 +++++ afis-recall-api/pom.xml | 100 +++++++++++++ .../main/java/com/wabestway/recall/Main.java | 7 + .../wabestway/recall/api/dto/TraceUpDTO.java | 34 +++++ .../fallback/TraceFeignClientFallback.java | 19 +++ .../recall/api/feign/TraceFeignClient.java | 14 ++ .../trace/entity/RecallRecordEntity.java | 3 + .../recall/trace/handler/ListTypeHandler.java | 42 ++++++ .../recall/trace/vo/RecallOrderVO.java | 7 + afis-recall-web/pom.xml | 16 ++- .../impl/RecallOrderApiServiceImpl.java | 11 ++ .../impl/RecallRecordApiServiceImpl.java | 3 +- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-native.yml | 2 + .../src/main/resources/application.yml | 16 +++ .../src/main/resources/bootstrap-dev.yml | 17 +++ .../src/main/resources/bootstrap-native.yml | 51 +++++++ .../src/main/resources/bootstrap-prod.yml | 17 +++ .../src/main/resources/bootstrap-uat.yml | 16 +++ .../src/main/resources/bootstrap.yml | 3 + .../src/main/resources/logback-spring.xml | 135 ++++++++++++++++++ pom.xml | 1 + 22 files changed, 549 insertions(+), 4 deletions(-) create mode 100644 afis-recall-api/.gitignore create mode 100644 afis-recall-api/pom.xml create mode 100644 afis-recall-api/src/main/java/com/wabestway/recall/Main.java create mode 100644 afis-recall-api/src/main/java/com/wabestway/recall/api/dto/TraceUpDTO.java create mode 100644 afis-recall-api/src/main/java/com/wabestway/recall/api/fallback/TraceFeignClientFallback.java create mode 100644 afis-recall-api/src/main/java/com/wabestway/recall/api/feign/TraceFeignClient.java create mode 100644 afis-recall-service/src/main/java/com/wabestway/recall/trace/handler/ListTypeHandler.java create mode 100644 afis-recall-web/src/main/resources/application-dev.yml create mode 100644 afis-recall-web/src/main/resources/application-native.yml create mode 100644 afis-recall-web/src/main/resources/application.yml create mode 100644 afis-recall-web/src/main/resources/bootstrap-dev.yml create mode 100644 afis-recall-web/src/main/resources/bootstrap-native.yml create mode 100644 afis-recall-web/src/main/resources/bootstrap-prod.yml create mode 100644 afis-recall-web/src/main/resources/bootstrap-uat.yml create mode 100644 afis-recall-web/src/main/resources/bootstrap.yml create mode 100644 afis-recall-web/src/main/resources/logback-spring.xml diff --git a/afis-recall-api/.gitignore b/afis-recall-api/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/afis-recall-api/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/afis-recall-api/pom.xml b/afis-recall-api/pom.xml new file mode 100644 index 0000000..0c64c36 --- /dev/null +++ b/afis-recall-api/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + com.wabestway.recall + afis-recall-api + 1.0-SNAPSHOT + + + + 1.8 + 1.8 + UTF-8 + UTF-8 + + + + + com.wabestway.common + afis-web-common + 1.0 + + + org.springframework.cloud + spring-cloud-starter-openfeign + 2.2.3.RELEASE + provided + + + + com.google.code.gson + gson + 2.8.6 + + + + io.springfox + springfox-swagger2 + 3.0.0 + + + io.swagger + swagger-models + + + provided + + + + io.swagger + swagger-models + 1.5.22 + provided + + + + org.projectlombok + lombok + 1.18.6 + true + + + org.springframework.cloud + spring-cloud-openfeign-core + 2.2.3.RELEASE + compile + + + + + + release + Nexus Release Repository + http://dev.wabestway.com/nexus/repository/maven-releases/ + + + + snapshot + Nexus Snapshot Repository + http://dev.wabestway.com/nexus/repository/maven-snapshots/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + none + + + + + + + \ No newline at end of file diff --git a/afis-recall-api/src/main/java/com/wabestway/recall/Main.java b/afis-recall-api/src/main/java/com/wabestway/recall/Main.java new file mode 100644 index 0000000..f7b6cb1 --- /dev/null +++ b/afis-recall-api/src/main/java/com/wabestway/recall/Main.java @@ -0,0 +1,7 @@ +package com.wabestway.recall; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/afis-recall-api/src/main/java/com/wabestway/recall/api/dto/TraceUpDTO.java b/afis-recall-api/src/main/java/com/wabestway/recall/api/dto/TraceUpDTO.java new file mode 100644 index 0000000..5156a34 --- /dev/null +++ b/afis-recall-api/src/main/java/com/wabestway/recall/api/dto/TraceUpDTO.java @@ -0,0 +1,34 @@ +package com.wabestway.recall.api.dto; + +import lombok.Data; + +import java.util.List; + +@Data +public class TraceUpDTO { + private String batchId; + private long batchTime; + List records; +} + +@Data +class TraceRecord { + /** 业务订单ID */ + private String orderId; + /** 产品编码 */ + private String supplierProductCode; + /** 产品名称 */ + private String supplierProductName; + /** 保单号 */ + private String policyNo; + /** 投保人名称 */ + private String holderName; + /** 投保人手机号 */ + private String holderPhone; + /** 保险公司名称 */ + private String supplierName; + /** 保单起始日期 */ + private String startDate; + /** 保单结束日期 */ + private String endDate; +} diff --git a/afis-recall-api/src/main/java/com/wabestway/recall/api/fallback/TraceFeignClientFallback.java b/afis-recall-api/src/main/java/com/wabestway/recall/api/fallback/TraceFeignClientFallback.java new file mode 100644 index 0000000..6497d16 --- /dev/null +++ b/afis-recall-api/src/main/java/com/wabestway/recall/api/fallback/TraceFeignClientFallback.java @@ -0,0 +1,19 @@ +package com.wabestway.recall.api.fallback; + +import com.alibaba.fastjson.JSON; +import com.wabestway.commons.http.ResObj; +import com.wabestway.recall.api.dto.TraceUpDTO; +import com.wabestway.recall.api.feign.TraceFeignClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class TraceFeignClientFallback implements TraceFeignClient { + + @Override + public ResObj batchTraceUp(TraceUpDTO traceUpDTO) { + log.error("回溯业务数据更新:{}", JSON.toJSONString(traceUpDTO)); + return ResObj.fail("服务不可用"); + } +} diff --git a/afis-recall-api/src/main/java/com/wabestway/recall/api/feign/TraceFeignClient.java b/afis-recall-api/src/main/java/com/wabestway/recall/api/feign/TraceFeignClient.java new file mode 100644 index 0000000..fcc0a0b --- /dev/null +++ b/afis-recall-api/src/main/java/com/wabestway/recall/api/feign/TraceFeignClient.java @@ -0,0 +1,14 @@ +package com.wabestway.recall.api.feign; + +import com.wabestway.commons.http.ResObj; +import com.wabestway.recall.api.dto.TraceUpDTO; +import com.wabestway.recall.api.fallback.TraceFeignClientFallback; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; + +@FeignClient(value = "afis-recall", fallback = TraceFeignClientFallback.class) +public interface TraceFeignClient { + @PostMapping("/api/traceUp") + ResObj batchTraceUp(@RequestBody TraceUpDTO traceUpDTO); +} diff --git a/afis-recall-service/src/main/java/com/wabestway/recall/trace/entity/RecallRecordEntity.java b/afis-recall-service/src/main/java/com/wabestway/recall/trace/entity/RecallRecordEntity.java index 6ce26f0..6c630c0 100644 --- a/afis-recall-service/src/main/java/com/wabestway/recall/trace/entity/RecallRecordEntity.java +++ b/afis-recall-service/src/main/java/com/wabestway/recall/trace/entity/RecallRecordEntity.java @@ -1,8 +1,10 @@ package com.wabestway.recall.trace.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableId; +import com.wabestway.recall.trace.handler.ListTypeHandler; import lombok.Data; import java.util.List; @@ -29,6 +31,7 @@ public class RecallRecordEntity { /** 页面说明 */ private String content; /** 记录事件 */ + @TableField(typeHandler = ListTypeHandler.class) private List events; /** 回溯记录跟踪ID */ private String traceId; diff --git a/afis-recall-service/src/main/java/com/wabestway/recall/trace/handler/ListTypeHandler.java b/afis-recall-service/src/main/java/com/wabestway/recall/trace/handler/ListTypeHandler.java new file mode 100644 index 0000000..f18d010 --- /dev/null +++ b/afis-recall-service/src/main/java/com/wabestway/recall/trace/handler/ListTypeHandler.java @@ -0,0 +1,42 @@ +package com.wabestway.recall.trace.handler; + + +import com.wabestway.recall.trace.vo.RecallRecordVO; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; +import org.apache.ibatis.type.TypeHandler; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; + +@MappedTypes(value = {RecallRecordVO.class}) +@MappedJdbcTypes(value = {JdbcType.LONGNVARCHAR}) +public class ListTypeHandler implements TypeHandler> { + @Override + public void setParameter(PreparedStatement ps, int i, List strings, JdbcType jdbcType) throws SQLException { + ps.setString(i, String.join(",", strings)); + } + + @Override + public List getResult(ResultSet rs, String s) throws SQLException { + String str = rs.getString(s); + return Arrays.asList(str.split(",")); + } + + @Override + public List getResult(ResultSet rs, int i) throws SQLException { + String str = rs.getString(i); + return Arrays.asList(str.split(",")); + } + + @Override + public List getResult(CallableStatement cs, int i) throws SQLException { + String str = cs.getString(i); + return Arrays.asList(str.split(",")); + } +} diff --git a/afis-recall-service/src/main/java/com/wabestway/recall/trace/vo/RecallOrderVO.java b/afis-recall-service/src/main/java/com/wabestway/recall/trace/vo/RecallOrderVO.java index bda9bf9..06de931 100644 --- a/afis-recall-service/src/main/java/com/wabestway/recall/trace/vo/RecallOrderVO.java +++ b/afis-recall-service/src/main/java/com/wabestway/recall/trace/vo/RecallOrderVO.java @@ -1,6 +1,10 @@ package com.wabestway.recall.trace.vo; import java.io.Serializable; +import java.util.List; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -76,6 +80,7 @@ public class RecallOrderVO implements Serializable { private String createBy; /** 创建时间 */ @ApiModelProperty(value = "创建时间") + @JsonProperty(value = "createAt") private Long createTime; /** 更新人 */ @ApiModelProperty(value = "更新人") @@ -84,4 +89,6 @@ public class RecallOrderVO implements Serializable { @ApiModelProperty(value = "更新时间") private Long updateTime; + private List events; + } diff --git a/afis-recall-web/pom.xml b/afis-recall-web/pom.xml index b4d6198..be628d3 100644 --- a/afis-recall-web/pom.xml +++ b/afis-recall-web/pom.xml @@ -20,7 +20,8 @@ UTF-8 UTF-8 3.3.2 - 1.1.22 + 1.1.22 + @@ -40,7 +41,16 @@ - + + mysql + mysql-connector-java + runtime + + + com.alibaba + druid-spring-boot-starter + ${alibaba.boot.druid} + org.springframework.cloud spring-cloud-starter-openfeign @@ -74,7 +84,7 @@ org.springframework.boot - spring-boot-starter-webflux + spring-boot-starter-web org.projectlombok diff --git a/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallOrderApiServiceImpl.java b/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallOrderApiServiceImpl.java index 042c74c..c4cd0a7 100644 --- a/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallOrderApiServiceImpl.java +++ b/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallOrderApiServiceImpl.java @@ -56,6 +56,17 @@ public class RecallOrderApiServiceImpl implements RecallOrderApiService { @Override public ResObj getRecallOrderByOrderId(String orderId) { RecallOrderVO recallOrderVO = recallOrderService.queryRecallOrderById(orderId); + if (recallOrderVO != null) { + LambdaQueryWrapper recordQuery = Wrappers.lambdaQuery(); + recordQuery.eq(RecallRecordEntity::getTraceId, recallOrderVO.getTraceId()); + recordQuery.orderByAsc(RecallRecordEntity::getCreateTime); + List recordList = recallRecordService.getBaseMapper().selectList(recordQuery); + + List events = recordList.stream() + .flatMap(entity -> entity.getEvents().stream()) + .collect(Collectors.toList()); + recallOrderVO.setEvents(events); + } return ResObj.ok(recallOrderVO); } diff --git a/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallRecordApiServiceImpl.java b/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallRecordApiServiceImpl.java index 1a602e7..0d7ed1a 100644 --- a/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallRecordApiServiceImpl.java +++ b/afis-recall-web/src/main/java/com/wabestway/recall/trace/service/impl/RecallRecordApiServiceImpl.java @@ -38,7 +38,8 @@ public class RecallRecordApiServiceImpl implements RecallRecordApiService { .map(recallOrderService::queryRecallOrderByOrderId) .map(RecallOrderEntity::getTraceId) .orElse(UUID.randomUUID().toString().replace("-", "")); - + log.info(traceId); + record.setTraceId(traceId); boolean isLastEvent = record.isLast(); RecallOrderEntity order = Optional.ofNullable(orderId) diff --git a/afis-recall-web/src/main/resources/application-dev.yml b/afis-recall-web/src/main/resources/application-dev.yml new file mode 100644 index 0000000..ec8bad2 --- /dev/null +++ b/afis-recall-web/src/main/resources/application-dev.yml @@ -0,0 +1 @@ +# nacos \ No newline at end of file diff --git a/afis-recall-web/src/main/resources/application-native.yml b/afis-recall-web/src/main/resources/application-native.yml new file mode 100644 index 0000000..c222560 --- /dev/null +++ b/afis-recall-web/src/main/resources/application-native.yml @@ -0,0 +1,2 @@ +server: + port: 9235 diff --git a/afis-recall-web/src/main/resources/application.yml b/afis-recall-web/src/main/resources/application.yml new file mode 100644 index 0000000..59170e0 --- /dev/null +++ b/afis-recall-web/src/main/resources/application.yml @@ -0,0 +1,16 @@ + +#spring: +# jackson: +# date-format: yyyy-MM-dd HH:mm:ss +# time-zone: GMT+8 + +mybatis-plus: + #MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名 + configuration: + # 打印控制台 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +spring: + freemarker: + settings: + classic_compatible: true \ No newline at end of file diff --git a/afis-recall-web/src/main/resources/bootstrap-dev.yml b/afis-recall-web/src/main/resources/bootstrap-dev.yml new file mode 100644 index 0000000..4f674fa --- /dev/null +++ b/afis-recall-web/src/main/resources/bootstrap-dev.yml @@ -0,0 +1,17 @@ +spring: + profiles: dev + application: + name: afis-recall + cloud: + nacos: + config: + file-extension: yaml + server-addr: 192.168.0.141:8848 + namespace: ns-car-dev + discovery: + #Nacos服务注册中心地址 + server-addr: 192.168.0.141:8848 + namespace: ns-car-dev + + main: + allow-bean-definition-overriding: true diff --git a/afis-recall-web/src/main/resources/bootstrap-native.yml b/afis-recall-web/src/main/resources/bootstrap-native.yml new file mode 100644 index 0000000..7d7e351 --- /dev/null +++ b/afis-recall-web/src/main/resources/bootstrap-native.yml @@ -0,0 +1,51 @@ +spring: + profiles: native + application: + name: afis-recall + cloud: + nacos: + config: + file-extension: yaml + server-addr: 49.7.225.107:8848 + namespace: native-test + discovery: + #Nacos服务注册中心地址 + server-addr: 49.7.225.107:8848 + namespace: native-test + main: + allow-bean-definition-overriding: true + + datasource: + type: com.alibaba.druid.pool.DruidDataSource + url: jdbc:mysql://123.56.82.16:3306/afis-agency?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai + username: rocar + password: rocar + driver-class-name: com.mysql.cj.jdbc.Driver + platform: mysql + druid: + initial-size: 2 + max-active: 100 + time-between-eviction-runs-millis: 60000 + min-evictable-idle-time-millis: 300000 + validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 5 + filter: + stat: + log-slow-sql: true + slow-sql-millis: 2000 + enabled: true + config: + enabled: true + wall: + enabled: true + encoding: + enabled: true + stat-view-servlet: + enabled: true + url-pattern: /druid/* + login-username: admin + login-password: admin \ No newline at end of file diff --git a/afis-recall-web/src/main/resources/bootstrap-prod.yml b/afis-recall-web/src/main/resources/bootstrap-prod.yml new file mode 100644 index 0000000..53aaff9 --- /dev/null +++ b/afis-recall-web/src/main/resources/bootstrap-prod.yml @@ -0,0 +1,17 @@ + +spring: + profiles: prod + application: + name: afis-recall + cloud: + nacos: + config: + file-extension: yaml + server-addr: 192.168.208.47:18848,192.168.208.48:18848 + namespace: cs-prd + discovery: + #Nacos服务注册中心地址 + server-addr: 192.168.208.47:18848,192.168.208.48:18848 + namespace: cs-prd + main: + allow-bean-definition-overriding: true diff --git a/afis-recall-web/src/main/resources/bootstrap-uat.yml b/afis-recall-web/src/main/resources/bootstrap-uat.yml new file mode 100644 index 0000000..4222ea2 --- /dev/null +++ b/afis-recall-web/src/main/resources/bootstrap-uat.yml @@ -0,0 +1,16 @@ +spring: + profiles: uat + application: + name: afis-recall + cloud: + nacos: + config: + file-extension: yaml + server-addr: 192.168.220.31:8848 + namespace: tfs-cs-uat + discovery: + #Nacos服务注册中心地址 + server-addr: 192.168.220.31:8848 + namespace: tfs-cs-uat + main: + allow-bean-definition-overriding: true diff --git a/afis-recall-web/src/main/resources/bootstrap.yml b/afis-recall-web/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..54d7ddc --- /dev/null +++ b/afis-recall-web/src/main/resources/bootstrap.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: native diff --git a/afis-recall-web/src/main/resources/logback-spring.xml b/afis-recall-web/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..8060e20 --- /dev/null +++ b/afis-recall-web/src/main/resources/logback-spring.xml @@ -0,0 +1,135 @@ + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{trace_id}] %-5level %logger{36} - %msg%n + + + + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}.log.%d{yyyy-MM-dd}.log + + 181 + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} %X{trace_id} [%thread] %-5level %logger{50} - %msg%n + + + + 10MB + + + + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} %X{trace_id} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}-info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 181 + + + + info + ACCEPT + DENY + + + + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}-warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} %X{trace_id} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}-warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 181 + + + + warn + ACCEPT + DENY + + + + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}-error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} %X{trace_id} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${LOG_HOME}/${SERVICE_NAME}/${SERVICE_NAME}-error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 181 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 545ab26..b4c8dd5 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ afis-recall-web afis-recall-service + afis-recall-api