# zmm_edu **Repository Path**: my-code-havent-bug/zmm_edu ## Basic Information - **Project Name**: zmm_edu - **Description**: 无Bug良品项目仓库 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 1 - **Created**: 2021-06-21 - **Last Updated**: 2022-11-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 物流的挑战与蓝胖智汇“装满满” ### 一、介绍 “装满满”SaaS教学版项目仓库,实现一个完整的产品设计、开发、部署、运维流程 ### 二、软件架构 “装满满”软件架构说明 ![“装满满”软件架构说明](https://images.gitee.com/uploads/images/2021/0621/222753_e0010568_6515873.png "“装满满”软件架构说明.png") ### 三、系统设计 ##### 1. RBAC 模型设计 ![RBAC模型设计](https://images.gitee.com/uploads/images/2021/0622/102705_193044c3_6515873.png "RBAC.png") ##### 2. 数据库结构设计 ![数据库结构设计](https://images.gitee.com/uploads/images/2021/0623/112406_e4a2c980_6515873.png "数据库设计.png") ##### 3. 注册功能时序图 ![注册功能时序图](https://images.gitee.com/uploads/images/2021/0623/111858_047adee5_6515873.png "注册功能时序图.png") ##### 4. 用户上传功能时序图 ![用户上传功能时序图](https://images.gitee.com/uploads/images/2021/0623/113952_315d31ba_6515873.png "用户上传功能时序图.png") ### 四、安装教程 ##### 1. [安装 Ubuntu20.04 桌面版](https://blog.csdn.net/u012257982/article/details/106888455) ##### 2. 安装 Python3.x 环境命令: - sudo apt update - sudo apt-get python3 - sudo apt-get python3-pip **配置默认 python 为 python3 命令:** - sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150 ##### 3. [安装 Git 版本控制软件](https://www.bootcss.com/p/git-guide/) ##### 4. 本地目录安装 python 环境包: ```shell pip install -r requirements.txt ``` ##### 5. 使用apt安装docker ```shell # 更新数据源 sudo apt-get update # 安装所需依赖 sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common # 安装GPG证书 sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # 新增数据源 sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" # 更新并安装docker sudo apt-get update && sudo apt-get install -y docker-ce # 验证安装 sudo docker version ``` ### 五、使用说明 ##### 1. Git 操作 HTTPS URL: ``` https://gitee.com/my-code-havent-bug/my-web.git ``` Git 克隆命令: ```shell git clone https://gitee.com/my-code-havent-bug/my-web.git ``` Git 上传命令: ```shell git add . git commit -m "new_info" git pull git push ``` ##### 2. 常用的 Docker 操作命令 拉取 busybox 镜像命令: ```shell sudo docker pull busybox ``` 查看镜像命令: ```shell sudo docker images ``` 启动 busybox 镜像命令: ```shell sudo docker run busybox ``` 进入 busybox 镜像命令: ```shell sudo docker run -it busybox sh ``` 查看运行容器命令: ```shell sudo docker ps -a ``` 建立 my_nginx 容器: ```shell sudo docker build --tag my_nginx -f ./Dockerfile . ``` 运行 8080 -> 80 容器命令: ```shell sudo docker run -p 8080:80 my_nginx ``` 删除容器命令: ```shell sudo docker rm id ``` 删除镜像命令: ```shell sudo docker rmi id ``` ![nginx部署网站](https://images.gitee.com/uploads/images/2021/0623/161634_1a2c26ff_6515873.png "nginx部署网站.png") Docker 改源命令: ```shell sudo vim /etc/docker/daemon.json ``` ```json { "registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"] } ``` ##### 3. 搭建容器化的 Django 开发环境 ###### 步骤[1]:创建装满满 Django 项目: ```shell django-admin startproject zmm ``` ###### 步骤[2]:创建两个 Django 应用: “common”应用将实现通用的SaaS功能,如用户管理、租户管理以及租户数据隔离 ```shell cd zmm python manage.py startapp common ``` “load_planner”应用将实现装箱业务相关功能,包含集装箱运柜数据管理、装箱任务管理 ``` python manage.py startapp load_planner ``` ###### 步骤[3]:编写 Dockerfile: ```shell # 设置基础镜像 FROM python:3.8 # 创建/code文件夹,作为放应用代码的地方 RUN mkdir /code # 将主机的应用代码 搬运到 镜像内部 COPY . /code # WORKDIR => work directory 工作目录,进入容器后所在的默认位置 WORKDIR /code # 将 Django,DRF及Ipython装到镜像中 RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \ pip config set global.trusted-host mirrors.aliyun.com && \ pip install Django djangorestframework IPython psycopg2-binary ``` **安装容器测试命令** ```shell sudo docker build -t zmm . ``` **文件下载并放入 scripts 文件夹中(附加权限 775)** Requirements.txt: [https://gitlab.com/-/snippets/2137538](https://gitlab.com/-/snippets/2137538) 数据库就绪检查脚本: [https://gitlab.com/-/snippets/2134785](https://gitlab.com/-/snippets/2134785) 启动装满满脚本: [https://gitlab.com/-/snippets/2139035](https://gitlab.com/-/snippets/2139035) 启动装满满脚本: [https://gitlab.com/-/snippets/2134786](https://gitlab.com/-/snippets/2134786) 进入容器测试命令 ```shell sudo docker run -it zmm:latest bash ``` ###### 步骤[4]:**编写 docker-compose.yml**: ```yaml version: '3.5' services: postgres: image: postgres:11.1 container_name: "psql_db" volumes: - postgres_data:/var/lib/postgresql/data/ env_file: - .env networks: - zmm expose: - "5432" zmm: build: context: . container_name: "zmm_app" command: bash -c "./scripts/run.sh" volumes: - .:/code env_file: - .env depends_on: - postgres networks: - zmm ports: - "8080:8080" volumes: postgres_data: networks: zmm: ``` ```shell sudo apt install docker-compose sudo docker-compose up ``` ###### 步骤[5]:**创建环境变量文件**: ```shell # docker-compose 创建并启动 sudo docker-compose up --build ``` ```shell # docker-compose 启动 sudo docker-compose up ``` ```django # 替换 Django 中的 DATABASES 环境 DATABASES = { 'default': { # 从环境变量中读取数据库的各项配置参数 # 并使用PostgreSQL数据库引擎 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ['POSTGRES_DB'], 'USER': os.environ['POSTGRES_USER'], 'PASSWORD': os.environ['POSTGRES_PASSWORD'], 'HOST': os.environ['POSTGRES_HOST'], 'PORT': os.environ['POSTGRES_PORT'] } } ``` ```shell # 停止容器 sudo docker-compose down ``` ```shell # 找到尾缀 postgres_data sudo docker volume ls ``` ```shell # 删除容器 sudo docker volume rm django-docker_postgres_data ``` ```shell # 启动容器 sudo docker-compose up ``` ![启动django](https://images.gitee.com/uploads/images/2021/0624/134641_187cd2be_6515873.png "启动django.png") ##### 4. PostgreSQL 操作命令 \# docker 进入 数据库: ```shell sudo docker exec -it psql_db bash ``` \# 用户 admin 进入 zmm 数据库: ```shell psql -U admin --dbname zmm ``` \# 查看架构模式列表: ```plsql \dn ``` \# 查看表命令: ```plsql \dt ``` ##### 5. Postman 请求测试 **\* 终端启动输出** ![终端启动输出](https://images.gitee.com/uploads/images/2021/0701/100402_11fd6c2d_6515873.png "终端启动输出.png") ###### i.用户注册请求 ``` http://localhost:8080/api/register # method: POST ``` \* 输入 Json 信息 \* ```json { "email": "abc12345678@qq.com", "password": "12345678", "first_name": "MyFirstName", "last_name": "MyLastName" } ``` \* 结果输出 \* ```json { "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjI1NzA5ODk4LCJqdGkiOiI0ODM3MGFhMDM5NzY0OTZmODI3MTQ5Y2RiNTFhNjQwNSIsInVzZXJfaWQiOjF9.nCmHd2HUuBqTgg18D56GUjUwb1Nd8imibSuxoud5mOk", "user": { "id": 1, "email": "abc12345678@qq.com", "first_name": "MyFirstName", "last_name": "MyLastName", "tenant": "Tenant object (1)", "roles": [ "Role object (1)" ], "created": "2021-07-01T02:04:58.914077Z" } } ``` ###### ii.用户登录请求 ``` http://localhost:8080/api/login/ # method: POST ``` \* 输入 Json 信息 \* ```json { "email": "abc12345678@qq.com", "password": "12345678" } ``` \* 结果输出 \* ```json { "tokens": { "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTYyNTE5MTU1MiwianRpIjoiODE4NzkyMmE0MWE1NGZkM2ExODJmM2FlN2I4NDA5NzMiLCJ1c2VyX2lkIjoxfQ.t-MUICNpPRikY7PN_5V_GBQT7ly4zerIjemQOvLQxUU", "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjI1NzA5OTUyLCJqdGkiOiJhYjIwMTQwYmVhMWI0ZmQ4OTA3NzMxOWI5NTQ0NWVhYSIsInVzZXJfaWQiOjF9.Dc9-LWGKu1VnMk9EJ45MA9ldTM52_t81rMqDgbtqNsQ" }, "user": { "id": 1, "email": "abc12345678@qq.com", "first_name": "MyFirstName", "last_name": "MyLastName", "tenant": "Tenant object (1)", "roles": [ "Role object (1)" ], "created": "2021-07-01T02:04:58.914077Z" } } ``` ###### iii.查看用户请求 ``` http://localhost:8080/api/users/ # method: GET ``` \* 输入 Token 信息 \* ``` eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjI1NTQwNDUzLCJqdGkiOiIxNjkzYjQ2MWJmYjU0MTdlODZkMGIxZThiOTAzYmFlNCIsInVzZXJfaWQiOjF9.CL9wyjZkfHz6_SXQ0psFzsok48-q91_EimcpwOcTvM4 ``` \* 结果输出 \* ```json { "id": 1, "email": "abc12345678@qq.com", "first_name": "MyFirstName", "last_name": "MyLastName", "tenant": "Tenant object (1)", "roles": [ "Role object (1)" ], "created": "2021-07-01T02:04:58.914077Z" } ``` ###### iv.创建任务请求 ``` http://localhost:8080/api/tasks/ # method: POST ``` \* 输入 Json 信息 \* ```json { "name": "测试任务-new", "creator": 1 } ``` \* 结果输出 \* ```json { "id": 3, "name": "测试任务-new", "status": "idle", "config": null, "input_dataset": null, "result_dataset": null, "created_at": "2021-07-01T02:08:40.704184Z", "submitted_at": null, "finished_at": null, "creator": 1 } ``` ###### v.提交任务请求 ``` http://localhost:8080/api/tasks/{id}/ # method: PATCH ``` \* 输入 Json 信息 \* ```json { "submit": true, "input_dataset": [{ "name": "cargo1" }] } ``` \* 结果输出 \* ```json { "id": 1, "name": "测试任务-new", "status": "submitted", "config": null, "input_dataset": [ { "name": "cargo1" } ], "result_dataset": { "config": null, "task_id": 1, "tenant_id": 1, "input_dataset": [ { "name": "cargo1" } ] }, "created_at": "2021-07-01T02:07:32.451273Z", "submitted_at": "2021-07-01T02:08:53.182446Z", "finished_at": "2021-07-01T02:08:58.217456Z", "creator": 1 } ``` ###### vi.查看任务请求 ``` http://localhost:8080/api/tasks/{id}/ # method: GET ``` \* 结果输出 \* ```json { "id": 1, "name": "测试任务-new", "status": "finished", "config": null, "input_dataset": [ { "name": "cargo1" } ], "result_dataset": { "config": null, "task_id": 1, "tenant_id": 1, "input_dataset": [ { "name": "cargo1" } ] }, "created_at": "2021-07-01T02:07:32.451273Z", "submitted_at": "2021-07-01T02:08:53.182446Z", "finished_at": "2021-07-01T02:08:58.217456Z", "creator": 1 } ``` ### 六、页面效果展示 ##### 1.注册页面 ![注册页面](https://images.gitee.com/uploads/images/2021/0701/161010_da1cf47d_6515873.png "注册页面.png") ##### 2.登录页面 ![登录页面](https://images.gitee.com/uploads/images/2021/0701/161043_e9f435fb_6515873.png "登录页面.png") ##### 3.用户详情页面 ![用户详情页面](https://images.gitee.com/uploads/images/2021/0701/161136_d40bc79a_6515873.png "用户详情页面.png") ##### 4.主页面 ![主页面](https://images.gitee.com/uploads/images/2021/0701/161115_9fcaae41_6515873.png "主页面.png") ##### 5.任务页面 ![任务页面](https://images.gitee.com/uploads/images/2021/0701/161202_07894dd7_6515873.png "任务页面.png") ### 参与贡献 本项目由 **无Bug良品** 贡献,版本将定期更新 ![无Bug良品](https://images.gitee.com/uploads/images/2021/0622/182910_0e5751c3_6515873.png "logo")