Merge remote-tracking branch 'origin/master'

# Conflicts:
#	readme.md
master
waynaqua 4 years ago
commit bf0704f59c

@ -50,6 +50,7 @@ threadPoolTaskExecutor.submit(bannerTask);
# 4. 最后可以在外部通过FutureTask的get方法异步获取执行结果 # 4. 最后可以在外部通过FutureTask的get方法异步获取执行结果
List<Banner> list = bannerTask.get() List<Banner> list = bannerTask.get()
``` ```
### 3. `ElasticSearch`查询操作,查询包含搜索关键字并且是上架中的商品,在根据指定字段进行排序,最后分页返回 ### 3. `ElasticSearch`查询操作,查询包含搜索关键字并且是上架中的商品,在根据指定字段进行排序,最后分页返回
```java ```java
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
@ -91,16 +92,55 @@ searchSourceBuilder.from((int) (page.getCurrent() - 1) * (int) page.getSize());
searchSourceBuilder.size((int) page.getSize()); searchSourceBuilder.size((int) page.getSize());
List<JSONObject> list = elasticDocument.search("goods", searchSourceBuilder, JSONObject.class); List<JSONObject> list = elasticDocument.search("goods", searchSourceBuilder, JSONObject.class);
``` ```
### 4. 订单编号生成规则:秒级时间戳 + 加密用户ID + 今日第几次下单 ### 4. 订单编号生成规则:秒级时间戳 + 加密用户ID + 今日第几次下单
1. 秒级时间戳:时间递增保证唯一性 1. 秒级时间戳:时间递增保证唯一性
2. 加密用户ID加密处理返回用户ID6位数字可以防并发访问同一秒用户不会产生2个订单 2. 加密用户ID加密处理返回用户ID6位数字可以防并发访问同一秒用户不会产生2个订单
3. 今日第几次下单:便于运营查询处理用户当日订单 3. 今日第几次下单:便于运营查询处理用户当日订单
```java
/**
* 返回订单编号,生成规则:秒级时间戳 + 加密用户ID + 今日第几次下单
*
* @param userId 用户ID
* @return 订单编号
*/
public static String generateOrderSn(Long userId) {
long now = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
return now + encryptUserId(String.valueOf(userId), 6) + countByOrderSn(userId);
}
/**
* 计算该用户今日内第几次下单
*
* @param userId 用户ID
* @return 该用户今日第几次下单
*/
public static int countByOrderSn(Long userId) {
IOrderService orderService = SpringContextUtil.getBean(IOrderService.class);
return orderService.count(new QueryWrapper<Order>().eq("user_id", userId)
.gt("create_time", LocalDate.now())
.lt("create_time", LocalDate.now().plusDays(1)));
}
/**
* 加密用户ID返回num位字符串
*
* @param userId 用户ID
* @param num 长度
* @return num位加密字符串
*/
private static String encryptUserId(String userId, int num) {
return String.format("%0" + num + "d", Integer.parseInt(userId) + 1);
}
```
### 5. 下单流程处理过程通过rabbitMQ异步生成订单提高系统下单处理能力 ### 5. 下单流程处理过程通过rabbitMQ异步生成订单提高系统下单处理能力
1. 用户点击提交订单按钮后台生成订单编号和订单金额跳转到订单支付页面并发送rabbitMQ消息包含订单编号等信息 1. 用户点击提交订单按钮,后台生成订单编号和订单金额跳转到订单支付页面,并将订单编号等信息发送rabbitMQ消息生产订单
2. 订单消费者接受到订单消息后生成订单记录(未支付) 2. 订单消费者接受到订单消息后,获取订单编号生成订单记录(用户待支付)
3. 用户点击支付按钮时,前端根据订单编号轮询订单信息查询接口,如果订单编号记录已经入库则进行后续支付操作,如果订单编号未入库则返回错误信息(订单异常) 3. 用户点击支付按钮时,前端根据订单编号轮询订单信息查询接口,如果订单编号记录已经入库则进行后续支付操作,如果订单编号未入库则返回错误信息(订单异常)
4. 用户支付完成后在回调通知里更新订单状态为已支付 4. 前端调用微信/支付宝完成支付操作
5. 用户支付完成后在回调通知里更新订单状态为已支付(已成功)
### 6. 金刚区跳转使用策略模式 ### 6. 金刚区跳转使用策略模式
```java ```java
@ -184,70 +224,7 @@ private DiamondJumpContext diamondJumpContext;
public void test(){ public void test(){
DiamondJumpType diamondJumpType = diamondJumpContext.getInstance(1); DiamondJumpType diamondJumpType = diamondJumpContext.getInstance(1);
} }
```
### 7. 使用google jib插件部署项目到阿里云容器服务
#### 1. 在waynboot-mobile-api子项目pom中添加如下配置
```javascript
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!--配置基本镜像可以在docker hub网站上寻找合适jdk11版本镜像-->
<from>
<image>adoptopenjdk:11-jre-openj9</image>
</from>
<!--配置最终推送的地址,仓库名,镜像名-->
<to>
<image>registry.cn-shanghai.aliyuncs.com/阿里云容器服务命名空间/你的项目名称
</image>
<tags>
<tag>你的版本号</tag>
<tag>latest</tag>
</tags>
<auth>
<username>你的阿里云镜像服务账号</username>
<password>你的阿里云镜像服务密码</password>
</auth>
</to>
<container>
<mainClass>com.waynboot.modile.ModileAppliction</mainClass>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
<jvmFlag>-Xmx512m</jvmFlag>
<jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
<jvmFlag>-XX:HeapDumpPath=./</jvmFlag>
</jvmFlags>
</container>
</configuration>
<!-- 绑定到maven lifecicle-->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
```
推送完成后就可以在阿里云容器服务管理控制台中看到自己推送得镜像
![image-20210610163326702](http://cdn.wayn.ltd/img/image-20210610163326702.png)
#### 2. 服务器获通过镜像启动java服务
##### 1.登录阿里云Docker Registry
```javascript
docker login --username=166973****@qq.com registry.cn-shanghai.aliyuncs.com
# 输入命令后会提示输入密码
```
##### 2.从Registry中拉取镜像
```javascript
docker pull registry.cn-shanghai.aliyuncs.com/wayn111/newbee-mall-plus:lastes
```
##### 3.启动java服务
```javascript
docker run -d -p 81:81 --name waynboot-mobile-api registry.cn-shanghai.aliyuncs.com/wayn111/newbee-mall-plus:lastes
# 自此大功能告成
``` ```
- todo - todo

@ -133,8 +133,9 @@
<container> <container>
<mainClass>${main-class}</mainClass> <mainClass>${main-class}</mainClass>
<jvmFlags> <jvmFlags>
<jvmFlag>-Xms512m</jvmFlag> <jvmFlag>-Xms812m</jvmFlag>
<jvmFlag>-Xmx512m</jvmFlag> <jvmFlag>-Xmx812m</jvmFlag>
<jvmFlag>-Xss512k</jvmFlag>
<jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag> <jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
<jvmFlag>-XX:HeapDumpPath=./</jvmFlag> <jvmFlag>-XX:HeapDumpPath=./</jvmFlag>
</jvmFlags> </jvmFlags>

@ -92,8 +92,9 @@
<container> <container>
<mainClass>${main-class}</mainClass> <mainClass>${main-class}</mainClass>
<jvmFlags> <jvmFlags>
<jvmFlag>-Xms512m</jvmFlag> <jvmFlag>-Xms1212m</jvmFlag>
<jvmFlag>-Xmx512m</jvmFlag> <jvmFlag>-Xmx1212m</jvmFlag>
<jvmFlag>-Xss512k</jvmFlag>
<jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag> <jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
<jvmFlag>-XX:HeapDumpPath=./</jvmFlag> <jvmFlag>-XX:HeapDumpPath=./</jvmFlag>
</jvmFlags> </jvmFlags>

@ -23,7 +23,7 @@ public class OrderSnGenUtil {
*/ */
public static String generateOrderSn(Long userId) { public static String generateOrderSn(Long userId) {
long now = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); long now = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
return now + encryptUserId(userId.toString()) + countByOrderSn(userId); return now + encryptUserId(String.valueOf(userId), 6) + countByOrderSn(userId);
} }
/** /**
@ -34,16 +34,19 @@ public class OrderSnGenUtil {
*/ */
public static int countByOrderSn(Long userId) { public static int countByOrderSn(Long userId) {
IOrderService orderService = SpringContextUtil.getBean(IOrderService.class); IOrderService orderService = SpringContextUtil.getBean(IOrderService.class);
return orderService.count(new QueryWrapper<Order>().eq("user_id", userId).gt("create_time", LocalDate.now()).lt("create_time", LocalDate.now().plusDays(1))); return orderService.count(new QueryWrapper<Order>().eq("user_id", userId)
.gt("create_time", LocalDate.now())
.lt("create_time", LocalDate.now().plusDays(1)));
} }
/** /**
* IDnum * IDnum
* *
* @param userId ID * @param userId ID
* @param num
* @return num * @return num
*/ */
private static String encryptUserId(String userId) { private static String encryptUserId(String userId, int num) {
return String.format("%0" + 6 + "d", Integer.parseInt(userId) + 1); return String.format("%0" + num + "d", Integer.parseInt(userId) + 1);
} }
} }

Loading…
Cancel
Save