这是一个综合性的 B2B2C 平台,类似京东商城、天猫商城。网站采用商家入驻的模式,商家入驻平台提交申请,由平台进行资质审核,审核通过后,商家拥有独立的管理后台录入商品信息。商品经过平台审核后即可发布。
项目采用前后端分离方式
东易买网上商城主要分为网站前台(消费者)、运营商后台(平台管理员)、商家管理后台(商家)三个子系统。
技术架构:
数据库表结构:
| tb_brand | 品牌 |
| tb_specification | 规格 |
| tb_specification_option | 规格选项 |
| tb_type_template | 类型模板:用于关联品牌和规格 |
| tb_item_cat | 商品分类 |
| tb_seller | 商家 |
| tb_goods | 商品 |
| tb_goods_desc | 商品详情 |
| tb_item | 商品明细 |
| tb_content | 内容(广告) |
| tb_content_category | 内容(广告)类型 |
dongyimai-gateway :
- 网关模块,根据网站的规模和需要,可以将综合逻辑相关的服务用网关路由组合到一起。
在这里还可以做鉴权和限流相关操作
dongyimai-service :
- 微服务模块,该模块用于存放所有独立的微服务工程
dongyimai-service-api :
- 对应工程的JavaBean、Feign、以及Hystrix配置,该工程主要对外提供依赖。
dongyimai-transaction-fescar :
- 分布式事务模块,将分布式事务抽取到该工程中,任何工程如需要使用分布式事务,只需依赖该工程即可
dongyimai-web:
- web服务工程
父工程:
pom
org.springframework.boot
spring-boot-starter-parent
2.3.9.RELEASE
// gav坐标
com.offcn
dongyimai-parent
1.0
// 参数
UTF-8
UTF-8
1.8
Hoxton.RELEASE
2.9.2
1.2.51
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
com.alibaba
fastjson
${fastjson.version}
搭建Eureka注册中心
dongyimai-parent com.offcn 1.0 4.0.0 dongyimai-eurekaorg.springframework.cloud spring-cloud-starter-netflix-eureka-server
application.yml配置
server:
port: 8761
spring:
application:
name: eureka
eureka:
instance:
hostname: 127.0.0.1
client:
register-with-eureka: false #是否将自己注册到eureka中
fetch-registry: false #是否从eureka中获取信息
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
server:
enable-self-preservation: false # 关闭自我保护
eviction-interval-timer-in-ms: 5000 # 每隔5秒进行一次服务列表清理
注意:启动类加上@EnableEurekaServer
公共子模块 dongyimai-common:
dongyimai-parent com.offcn 1.0 4.0.0 dongyimai-commonorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-data-redisorg.springframework.cloud spring-cloud-starter-netflix-eureka-clientorg.springframework.cloud spring-cloud-starter-openfeignorg.apache.httpcomponents httpclient4.2.1 org.apache.httpcomponents httpcore4.2.1 commons-lang commons-lang2.6 org.eclipse.jetty jetty-util9.3.7.v20160115
创建返回状态码实体类
public class StatusCode {
public static final int OK = 20000;//成功
public static final int ERROR = 20001;//失败
public static final int LOGINERROR = 20002;//用户名或密码错误
public static final int ACCESSERROR = 20003;//权限不足
public static final int REMOTEERROR = 20004;//远程调用失败
public static final int REPERROR = 20005;//重复操作
public static final int NOTFOUNDERROR = 20006;//没有对应的抢购数据(秒杀)
}
建立类Result用于微服务返回结果给前端
public class Resultimplements Serializable { private boolean flag;//是否成功 private Integer code;//返回码(StatusCode) private String message;//返回消息 private T data;//返回数据 public Result(boolean flag, Integer code, String message, T data) { this.flag = flag; this.code = code; this.message = message; this.data = data; } public Result(boolean flag, Integer code, String message) { this.flag = flag; this.code = code; this.message = message; } public Result() { this.flag = true; this.code = StatusCode.OK; this.message = "操作成功!"; } // 添加 getter and setter..... }
分页结果实体类:
public class PageResultimplements Serializable{ private Long total;//总记录数 private List rows;//记录 public PageResult(Long total, List rows) { this.total = total; this.rows = rows; } public PageResult() { } //添加 getter and setter ...... }
创建公共模块 dongyimai-common-db:
随后依次创建个微服务过程子模块,并完成增删改查,再此就不做过多赘述。dongyimai-parent com.offcn 1.0 4.0.0 dongyimai-common-dbcom.offcn dongyimai-common1.0 mysql mysql-connector-java5.1.32 com.alibaba druid1.1.14 com.baomidou mybatis-plus-boot-starter3.4.2
接下来就是几个重要组件的搭建了
FastDFS搭建拉取镜像 :docker pull morunchang/fastdfs
运行tracker docker run -id --name tracker --net=host morunchang/fastdfs sh tracker.sh
运行storage docker run -id --name storage --net=host -e TRACKER_IP=192.168.188.129:22122 -e GROUP_NAME=group1
Docker容器中已经集成了Nginx,我们需要修改nginx的配置,进入storage的容器内部,修改nginx.conf
添加以下内容(如果已经存在了,就不需要再去加了)
location ~ /M00 {
root /data/fast_data/data;
ngx_fastdfs_module;
}
Elasticsearch 安装 docker镜像下载 docker pull elasticsearch:7.7.0dongyimai-service com.offcn 1.0 4.0.0 dongyimai-file-servicecn.bestwu fastdfs-client-java1.27 com.offcn dongyimai-common1.0
将elasticsearch容器内部的elasticsearch.yml配置文件拷贝到宿主机的root目录下
docker cp dym_es:/usr/share/elasticsearch/config/elasticsearch.yml /root/
cluster.name: "my-application"
cluster.name: "my-application"
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
进入容器安装ik分词器,注意是在plugins目录下进行安装



