Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weasley-j/lejing-mall
乐璟商城
https://github.com/weasley-j/lejing-mall
mall microservices-architecture mybatis spring spring-boot spring-cloud spring-cloud-alibaba
Last synced: 5 days ago
JSON representation
乐璟商城
- Host: GitHub
- URL: https://github.com/weasley-j/lejing-mall
- Owner: Weasley-J
- License: apache-2.0
- Created: 2021-01-25T16:46:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-29T04:00:23.000Z (24 days ago)
- Last Synced: 2024-12-06T06:02:37.486Z (17 days ago)
- Topics: mall, microservices-architecture, mybatis, spring, spring-boot, spring-cloud, spring-cloud-alibaba
- Language: HTML
- Homepage:
- Size: 178 MB
- Stars: 52
- Watchers: 2
- Forks: 28
- Open Issues: 120
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![shanghao-idea](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/shanghao-idea.jpg)
# 乐璟商城
> **微服务架构图**
![](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210222191025177.png)
> 😄 😄 😄 😄😄 😄 😄 😄 😄 😄 `SonarQube`代码审查结果(不含前端代码)
![](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210929225124691.png)
![](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210929225220904.png)
# 1 技术架构选型
第二代微服务架构,`kubernetes`高可用集群,全自动`DevOps`,
🎉️ [springcloud与springboot对应版本](https://start.spring.io/actuator/info)
![image-20210126234300478](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210126234300478.png)
🎉️ [spring boot的历史版本](https://docs.spring.io/spring-boot/docs/)
![image-20210126234531221](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210126234531221.png)
🎉️ [spring cloud的历史版本](https://docs.spring.io/spring-cloud/docs/)
![image-20210224205205376](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210224205205376.png)
[spring-cloud-alibaba-dependencies版本说明](https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E)
技术架构:
- 🚀️ `JDK11`
- 🚀️ `MySQL-8.0.28`
- 🚀️ `apache-maven-3.8.4`
- 🚀️ `spring-boot 2.7.2`
- 🚀️ `spring-cloud-2021.0.0`
- 🚀️ `spring-cloud-alibaba 2021.1`
- 🚀️ `NACOS2.0.3`
- 🚀️ `Elasticsearch+Logstash+Kibana(7.17.0)`
- 🚀️ `mybatis-plus 3.5.1`
- 很多很多...# 2 IDEA环境`JVM`参数配置
> tips: 主要目的减少web服务的的内存占用
`JVM`参数: `-Xms256m -Xmx256m -Xmn100m -Xlog:gc*`
![image-20210207215344410](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210207215344410.png)
![image-20210207215556800](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210207215556800.png)
# 3 已完成清单
- [X] 已封装`BaseController`,用于Controller数据返回
![image-20210204005654609](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210204005654609.png)
- [X] 已封装`BaseResult`,返回结果封装 ,让接口的输入和输出更加明确
![image-20210204010657082](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210204010657082.png)
![image-20210204010822582](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210204010822582.png)
![image-20210204010952249](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210204010952249.png)
- [X] 重新改造代码生成, 所有接口都可以生成测试文档, 支持在线调试接口, 执行`mvn package`自动出api文档,访问地址改成自己的端口号:http://127.0.0.1:10000/index.html,
![image-20210205025359610](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210205025359610.png)
![image-20210205024651157](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210205024651157.png)
> 基于`Mybatis-Plus`自动生成,支持复杂分页查询, 数据库变动只需要修改实体类即可
![image-20210205025122573](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210205025122573.png)
![image-20210205025022332](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210205025022332.png)
**![image-20210205024941585](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210205024941585.png)**
- [X] 项目改造完成, 集成: 业务代码自动生成 -> 执行: `mvn package`, 自动输出可调式的高可读性`api`文档 -> 分层架构 ->
以最小的代价迎合业务的重大变更
- [X] 已接入`ELK`全家桶![image-20210307003402307](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210307003402307.png)
![image-20210307003417433](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210307003417433.png)
- [x] 集成全局埋`traceId`, 快速定位线上问题
# 4 待完成清单
- [X] 整合人人框架,提供:`domain`--> `dao` --> `service` --> `controller` --> 全自动`api`文档在线输出, 支持在线调试
目的:让今后因业务变动影响数据库的变动只需要码农修改数据库对应的领域模型即可,节省更多的时间
- [X] 微服务计划进行中......
- [X] 移除`spring-cloud-alibaba 2.2.5.RELEASE` 版本中微服务中通过`feign`远程调用时使用`ribbon`负载均衡的支持, 采用`spring-cloud 2020.0.1`的`spring cloud loadbalancer`代替
- [X] ......# 5 `Ubuntu`环境`Docker`基础软件安装指南
## 5.1 安装ELK全家桶
1. 下载本项目
```shell
git clone https://github.com/Weasley-J/lejing-mall
```2. 切换工作目录
```shell
cd shell
chmod 0777 -vR *.sh && ./run_elk_install.sh
```## 5.2 修改`logback-spring.xml`中`logstash`的参数
![image-20210303224138777](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210303224138777.png)
```xml
192.168.40.132:5044
```以上标签值改为你自己的 `Logstash` 能接受log的主机`ip:port`
## 5.3 `Logstash` 成功接受日志的效果
1. 终端
![image-20210303224508305](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210303224508305.png)
2. es中的索引数据
![image-20210303224559097](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210303224559097.png)
![image-20210303224642551](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210303224642551.png)
# 6 TIPS
> 本项目的`api`文档输出基于smart-doc和common工程里面我写的一些类完成的,不建议把common工程上传到maven私服上面,这会导致项目执行:
>
> `mvn package`的时候不能读取common里面的一些相关类的注释,因为`java`最终编译成字节码文件后会把所有注释都清理掉,也就是项目最终的class文件不包含任何注释## 6.1 `nacos MySQL`数据持久配置
文件相对路径:`nacos-server/nacos-server-1.4.1/nacos/conf/application.properties`
```properties
### If use MySQL as datasource:
spring.datasource.platform=mysql### Count of DB:
db.num=1### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.40.132:3306/nacos_config?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true&allowMultiQueries=true
db.user.0=root
db.password.0=123456
```## 6.2 各个服务启动顺序
- 启动`nacos`,进入终端:`nacos-server/nacos-server-1.4.1/nacos/run-nacos-standalone.bat`
- 启动授权服务
- 启动网关服务 `lejing-gateway`
- 再启动其他相关服务## 6.3 `Elasticsearch`索引库清理
使用`curl`命令模糊匹配删除,在`shell`终端上执行:
```shell
#!/usr/bin/env bash# 全局变量,自行修改
IP="192.168.40.132"
PORT="9200"
USER="elastic"
PWD="123456"# 删除乐景商城的日志索引库
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/lejing-*,renren-fast-*
# 删除kibana的日志索引库
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/.monitoring-kibana-*
# 删除logstash的日志索引库
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/.monitoring-logstash-*
# 删除es的日志索引库
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/.monitoring-es-*
# 其他
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/ilm-history-*
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/.kibana-event-*
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/*run_env*
curl -XDELETE -u ${USER}:${PWD} http://${IP}:${PORT}/.kibana_*
```## 6.4 前端项目启动
### 6.4.1 前端后台管理
```shell
#克隆项目,见lejing-web-frontend/lejing-manage/README.md文件
```### 6.4.2 前端门户网站
前端多页面`html`使用`live-server`运行:
```shell
#打开CMD终端
cd lejing-web-frontend/lejing-portal
# npm下载live-server启动门户网站, 指定门户网站的端口8002
npm install -g live-server --registry=https://registry.npm.taobao.org && live-server --port=8002
```## 6.5 集成`SonarQube`
- 项目父`pom.xml`添加maven插件
版本自行取中央仓库查找
```xml
org.sonarsource.scanner.maven
sonar-maven-plugin
${sonar-maven-plugin.version}
```- maven的`settings.xml`新加如下配置
```xml
org.sonarsource.scanner.maven
aliyunmaven
central
阿里云公共仓库
https://maven.aliyun.com/repository/public
sonar
true
UTF-8
UTF-8
http://192.168.40.132:9001
d65fc87408fd94ef8328b03a52d06bfec0fe388f
src/test/**/*,*.js,*.css,*.html,*.vue,*.bat,*.cmd,*.md,*.NET,*.cpp
sonar
```
- docker安装`SonarQube````shell
#!/bin/bashBASE_DIR_POSTGRES="/usr/local/postgres"
BASE_DIR_SONARQUBE="/usr/local/sonarqube"#主机ip
POSTGRESQL_HOST="192.168.40.132"clear && rm -rfv ${BASE_DIR_POSTGRES} && rm -rfv ${BASE_DIR_SONARQUBE}
mkdir -pv ${BASE_DIR_POSTGRES} && mkdir -pv ${BASE_DIR_SONARQUBE}/{data,extensions,logs}
chown -vR 0999 ${BASE_DIR_SONARQUBE}/docker stop postgres && docker rm -f postgres
docker run --name postgres \
-p 5432:5432 \
-v ${BASE_DIR_POSTGRES}:/var/lib/postgresql/data \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-e POSTGRES_USER=root \
-e POSTGRES_DB=postgres \
-e POSTGRES_PASSWORD=123456 \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-d postgres# 开启postgresql远程访问参考连接: https://www.cnblogs.com/chendongbky/p/14874794.html, 看5 -> 5.(1)
docker exec -it postgres psql -h ${POSTGRESQL_HOST} -U root
# 界面运行下面的SQL, 创建sonarqube的数据库
CREATE DATABASE "sonarqube" WITH OWNER = "root" TEMPLATE = "postgres" ENCODING = 'UTF8' TABLESPACE = "pg_default";
COMMENT ON DATABASE "sonarqube" IS 'SonarQube数据库';#退出容器
# 社区版本
docker stop sonarqube && docker rm -f sonarqube
docker run --name sonarqube \
-p 9001:9000 \
-p 9092:9092 \
-e SONAR_JDBC_USERNAME=root \
-e SONAR_JDBC_PASSWORD=123456 \
-e SONAR_JDBC_URL="jdbc:postgresql://${POSTGRESQL_HOST}:5432/sonarqube" \
-v ${BASE_DIR_SONARQUBE}/data:/opt/sonarqube/data \
-v ${BASE_DIR_SONARQUBE}/extensions:/opt/sonarqube/extensions \
-v ${BASE_DIR_SONARQUBE}/logs:/opt/sonarqube/logs \
-d sonarqube# 企业版本
#docker run -d -p 9001:9000 -p 9092:9092 --name sonarqube \
#-v ${BASE_DIR_SONARQUBE}/sonarqube_data:/opt/sonarqube/data \
#-v ${BASE_DIR_SONARQUBE}/sonarqube_extensions:/opt/sonarqube/extensions \
#-v ${BASE_DIR_SONARQUBE}/sonarqube_logs:/opt/sonarqube/logs \
#-e SONAR_JDBC_USERNAME=sonarqube \
#-e SONAR_JDBC_PASSWORD=sonarqube \
#-e SONAR_JDBC_URL="jdbc:postgresql://${POSTGRESQL_HOST}:5432/sonarqube" \
#sonarqube:enterprise#编辑这个文件, 再末尾追加(已经有就不用追加): vm.max_map_count=655360
vim /etc/sysctl.conf
sysctl -p# echo后边用单引号包围要添加的内容
echo 'vm.max_map_count=655360' >>/etc/sysctl.conf
sysctl -p# 浏览器访问sonarqube: http://192.168.40.132:9001, 默认用户名密码为:admin/admin , 进入界面后: Administration --> marketplace --> 搜索chinese, 安装中文语言
# token - > 99bfe61d5bba8bb2164d6679ee345c03ad30d5d7
```
- 看看国内的开源和国外的开源代码审查结果
> 阿里的[fastjson](https://github.com/alibaba/fastjson.git)
![img](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/RLAOVF@WRCQ_]512J_EK5.png)
国外的[Jackson](https://github.com/FasterXML/jackson-core.git)
![img](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/EX1`QE]8AV96S$_E90DHHW0-1626597142096.png)
从审查数据可以看到:
`fastjson`的bug级别为E, 共122个, `Jackson`为C级,共15个, `fastjson`的bug约为`jackson`的8倍还要多, 数据上看, `jackson`比`fastjson`可靠.
# 7 Question&Answer
## 7.1 为什么分页不用`mybatis-plus`自带的`IPage`?
`mybatis-plus`的`IPage`分页入参不利于项目的`API`文档输出,毕竟我们都不想手写接口文档,如果你喜欢手写接口文档,然后再填入什么`RAP`、`YApi`里面,我推荐你用回`Swagger`。
## 7.2 解决`github`提交代码`connection to github.com:443`
`fatal: unable to access ‘https://github.com/Weasley-J/lejing-mall’: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443`
在Git Bash终端中输入:
```bash
env GIT_SSL_NO_VERIFY=true#提交代码指定个人token, 格式: git push https://[email protected]
#如: git push https://[email protected]/Weasley-J/lejing-mall.git
```## 7.3 项目启动报错`Web server failed to start. Port 8000 was already in use.`
> windows
```bat
netstat -aon | findstr "10000"tasklist | findstr "1532"
taskkill /f /t /im "yundetectservice.exe"
```![image-20210611221759994](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210611221759994.png)
![image-20210611221811205](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210611221811205.png)
## 7.4 关于前端查询数据需要根据时间区间查询时`spring`全局`mvc`字符串日期转换配置
![image-20210623234349087](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210623234349087.png)
笔者亲身经历,土鳖公司当查询参数过多的时候就用POST,实在是很不习惯。所有就这个全局配置,当然不止这2种方式,有兴趣自行探索。
## 7.5 在`IDEA`中使用`smart-doc`辅助生成`api`文档的`java doc tag`
> 粘贴文本: download,ignore,required,mock,order,page,ignoreParams,response
见下图:
![链接图片](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210719155251017.png)
# 8 接入三方支付
## 8.1 支付宝支付-2021年6月20日
### 8.1.1 [个人开发者申请登录后台](https://open.alipay.com/platform/developerIndex.htm)
![image-20210620223425913](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210620223425913.png)
### 8.1.2 [新版`api`文档](https://opendocs.alipay.com/open/54/00y8k9)
![image-20210620223644859](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210620223644859.png)
### 8.1.3 `nginx`配置支付宝支付成功异步POST回调
```nginx
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;pid logs/nginx.pid;
events {
worker_connections 1024;
}http {
include mime.types;
default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;
#解决"nginx could not build the server_names_hash"的方法
server_names_hash_bucket_size 64;client_max_body_size 4G;
#乐璟商城
server {
listen 80;
server_name lejing.fgifast1.vipnps.vip;#内网穿透域名地址proxy_ssl_verify off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header cookie $http_cookie;
proxy_set_header Proxy-Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 接受支付宝支付成功异步回调
location /payed/ {
proxy_set_header Host order.lejing.com;#把内网穿透过来的请求改为order.lejing.com;
proxy_pass http://order.lejing.com/payed/;#接受支付宝异步通知的POST接口
}location / {
proxy_pass http://localhost:88/api;
}error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
```# 9 增加目前主流的web excel处理示例
详见:`lejing-order/doc/关于Excel导出示例说明.md`
![image-20210710221552613](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210710221552613.png)
## 9.1 大数据量excel文件导出,`5W~100W`数据量
## 9.2 excel文件预览
# 10 接入`Torna` `API`文档管理工具,完美融合`smart-doc`
> 全程无需手写文档,执行maven插件即可
>
> ![image-20210717232437120](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210717232437120.png)文档效果:
![image-20210717230458352](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210717230458352.png)
![image-20210717230515865](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20210717230515865.png)
## 10.1 `SQL`文件: `sql/torna.sql`
## 10.2 安装shell脚本: `shell/run_torna_install.sh`
# 11 `github`敏感配置文件提交解决办法
[参考链接](https://surest.cn/archives/169/)
`cd`到项目根路径执行`shell`脚本:
```shell
clear \
&& git filter-branch --force --index-filter "git rm -rf --cached --ignore-unmatch filename" --prune-empty --tag-name-filter cat -- --all \
&& rm -rfv .git/refs/original \
&& git reflog expire --expire=now --all \
&& git gc --prune=now \
&& git push --force
```