### Start and Enable Nginx Service Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/nginx安装与跨域配置.md Starts the Nginx service and configures it to launch automatically on system boot. Use these commands after installing Nginx. ```shell systemctl start nginx.service systemctl enable nginx.service ``` -------------------------------- ### Pip Installation Success Output Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Example output indicating a successful installation of docker-compose via pip. ```text Collecting docker-compose Downloading docker-compose-1.17.1.tar.gz (149kB): 149kB downloaded ... Successfully installed docker-compose cached-property requests texttable websocket-client docker-py dockerpty six enum34 backports.ssl-match-hostname ipaddress ``` -------------------------------- ### Start Project with Docker Compose Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/使用docker部署商城.md Execute this command in the project root directory to start the application using Docker Compose. Ensure Docker Compose is installed. ```bash docker-compose up ``` -------------------------------- ### Install Necessary System Tools Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Install essential system utilities required for Docker installation and operation. ```bash sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` -------------------------------- ### Configure and Install Maven using Yum Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/通过yum安装maven.md Use these commands to add the EPEL repository for Maven, enable it, and then install the apache-maven package. Verify the installation and check the yum repository list afterwards. ```bash yum-config-manager --add-repo http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo ``` ```bash yum-config-manager --enable epel-apache-maven ``` ```bash yum install -y apache-maven ``` ```bash mvn -version ``` ```bash yum repolist ``` -------------------------------- ### Install Tcl and Redis Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Download and compile Tcl, then download and compile Redis from source. Ensure Tcl is installed before compiling Redis. ```bash #安装tcl redis需要 wget http://downloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz tar xzvf tcl8.6.8-src.tar.gz -C /usr/local/ cd /usr/local/tcl8.6.8/unix/ ./configure make && make install #安装redis wget http://download.redis.io/releases/redis-4.0.11.tar.gz tar xzvf redis-4.0.11.tar.gz -C /usr/local/ cd /usr/local/redis-4.0.11/ make && make test && make install ``` -------------------------------- ### Start and Verify Redis Process Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Make the init script executable, start the Redis service, and verify the process is running using ps. ```bash cd /etc/init.d, chmod 777 redis_6379, ./redis_6379 start ps -ef | grep redis ``` -------------------------------- ### Start Docker Service Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Start the Docker daemon service. ```bash sudo systemctl start docker ``` -------------------------------- ### Start MySQL Service Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Start the MySQL daemon service. ```shell systemctl start mysqld ``` -------------------------------- ### Install Dependencies with pnpm Source: https://github.com/gz-yami/mall4j/blob/master/front-end/mall4v/README.md Use this command to install project dependencies. Ensure pnpm is installed globally. ```bash pnpm install ``` -------------------------------- ### Enable Docker on Boot Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Configure Docker to start automatically when the system boots. ```bash systemctl enable docker ``` -------------------------------- ### Install JDK on CentOS Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/centos jdk安装.md Use this command to install OpenJDK 17 and its development tools, which includes the 'javac' compiler. This is necessary if the 'java-17-openjdk-devel' package is not already installed. ```bash yum install java-17-openjdk java-17-openjdk-devel ``` -------------------------------- ### Install MySQL Community Server Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Install the MySQL community server package using yum. ```shell yum install mysql-community-server ``` -------------------------------- ### Run Development Server Source: https://github.com/gz-yami/mall4j/blob/master/front-end/mall4v/README.md Starts the development server for the mall4j frontend. Hot-reloading is typically enabled. ```bash pnpm run dev ``` -------------------------------- ### Install Docker Compose via Binary (Linux 64-bit) Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Download and install the Docker Compose binary directly on a 64-bit Linux system. Ensure the binary is executable. ```bash $ sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose ``` -------------------------------- ### Install MySQL 5.7 YUM Repository Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Install the downloaded MySQL YUM repository package to enable MySQL package installation via yum. ```shell yum localinstall mysql57-community-release-el7-8.noarch.rpm ``` -------------------------------- ### Install Nginx Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/nginx安装与跨域配置.md Installs the Nginx web server using yum. This command should be run on a CentOS 7 64-bit system. ```shell yum install -y nginx ``` -------------------------------- ### Enable Redis Auto-Start Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Use chkconfig to enable Redis to start automatically on system boot. ```bash chkconfig redis_6379 on ``` -------------------------------- ### Install JDK Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/教你如何部署.md Installs the necessary JDK package if not already present. This ensures the 'javac' command is available for compilation. ```bash yum install java-17-openjdk java-17-openjdk-devel ``` -------------------------------- ### Install Docker Compose via Container Script Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Download and install a script to run Docker Compose from a container. This method avoids polluting the host system. ```bash $ curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose ``` -------------------------------- ### Install Docker CE Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Install the Docker Community Edition package using yum. ```bash sudo yum -y install docker-ce ``` -------------------------------- ### Install Python Pip Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Install the Python package installer (pip) on Linux systems using yum. This is a prerequisite for installing Docker Compose via pip. ```bash yum -y install epel-release yum -y install python-pip ``` -------------------------------- ### Run Vue Development Environment Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Starts the Vue development server for the main application. ```bash npm run dev ``` -------------------------------- ### Run Development Server (H5) Source: https://github.com/gz-yami/mall4j/blob/master/front-end/mall4uni/README.md Start the development server for the H5 platform. This command is used to preview changes during development. ```bash pnpm run dev:h5 ``` -------------------------------- ### Enable MySQL on Boot and Reload Daemon Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Configure MySQL to start automatically on system boot and reload the systemd daemon to recognize the changes. ```shell systemctl enable mysqld systemctl daemon-reload ``` -------------------------------- ### Check Docker Version Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Verify the installed Docker version. ```bash docker version ``` -------------------------------- ### Bash Completion for Docker Compose Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Download and install bash completion script for Docker Compose. Replace the version number with your installed version. ```bash $ curl -L https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose ``` -------------------------------- ### Package Project with Maven Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/使用docker部署商城.md Use this command to package the Mall4j project, skipping tests. Ensure Maven is installed. ```bash mvn clean package -DskipTests ``` -------------------------------- ### Install Project Dependencies with pnpm Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Installs project dependencies using the pnpm package manager. If you prefer not to use pnpm, remove the 'preinstall' script from package.json before running. ```bash pnpm i ``` -------------------------------- ### Check Docker Compose Version Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Verify the installed Docker Compose version. This command is useful after installation to confirm success. ```bash $ docker-compose --version docker-compose version 1.17.1, build 6d101fb ``` -------------------------------- ### Run Java Application in Production Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/教你如何部署.md Starts the packaged JAR file in the production environment. Ensure to replace placeholders with actual paths and names. The '-Dspring.profiles.active=prod' flag activates production configurations. ```bash nohup java -jar -Dspring.profiles.active=prod "${jarPath}/${jarName}" > "${jarPath}/log/${moduleName}-console.log" & ``` ```bash nohup java -jar -Dspring.profiles.active=prod "${jarPath}/${jarName}" > "${jarPath}/log/${moduleName}-console.log" & ``` -------------------------------- ### Install Docker Compose via Pip Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Install or upgrade Docker Compose using pip. This method is recommended for ARM architectures like Raspberry Pi. ```bash pip install -U docker-compose ``` -------------------------------- ### Run Vue Development Environment for H5 Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Starts the Vue development server specifically for the H5 version of the application. ```bash npm run dev:h5 ``` -------------------------------- ### Verify MySQL YUM Repository Installation Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Check if the MySQL community repository has been successfully enabled and is available for use. ```shell yum repolist enabled | grep "mysql.*-community.*" ``` -------------------------------- ### Remove pnpm Preinstall Script Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Example of the 'preinstall' script in package.json that enforces pnpm usage. Remove this line if you wish to use other package managers like npm or yarn. ```json { "scripts" : { "preinstall": "npx only-allow pnpm" // 使用其他包管理工具(npm、yarn、cnpm等)请删除此命令 } } ``` -------------------------------- ### Vue Production Environment Configuration Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/教你如何部署.md Example of a `.env.production` file for the Vue frontend. `VUE_APP_BASE_API` points to the backend API, and `VUE_APP_RESOURCES_URL` specifies the URL for static resources. ```javascript # just a flag ENV = 'production' // api接口请求地址 VUE_APP_BASE_API = 'https://mini-admin.mall4j.com/apis' // 静态资源文件url VUE_APP_RESOURCES_URL = 'https://img.mall4j.com/' ``` -------------------------------- ### Uninstall Docker Compose (Pip) Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Uninstall Docker Compose if it was installed using pip. ```bash pip uninstall docker-compose ``` -------------------------------- ### SysUser Model with Validation Annotations Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/统一验证.md Example of a SysUser model class demonstrating various validation annotations like @NotBlank, @Size, @Email, and @Pattern. ```java public class SysUser implements Serializable { private static final long serialVersionUID = 1L; /** * 用户ID * */ @TableId private Long userId; /** * 用户名 */ @NotBlank(message="用户名不能为空") @Size(min = 2,max = 20,message = "用户名长度要在2-20之间") private String username; /** * 密码 */ @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private String password; /** * 邮箱 */ @NotBlank(message="邮箱不能为空") @Email(message="邮箱格式不正确") private String email; /** * 手机号 */ @Pattern(regexp="0?1[0-9]{10}",message = "请输入正确的手机号") private String mobile; /** * 状态 0:禁用 1:正常 */ private Integer status; /** * 用户所在店铺id */ private Long shopId; /** * 角色ID列表 */ @TableField(exist=false) private List roleIdList; /** * 创建时间 */ private Date createTime; } ``` -------------------------------- ### Uninstall Docker Compose (Binary) Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/Docker Compose 安装与卸载.md Remove the Docker Compose binary file if it was installed using the binary download method. ```bash rm /usr/local/bin/docker-compose ``` -------------------------------- ### Configure Redis for System Startup Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Add chkconfig and description comments to the redis_init_script for automatic system startup. ```bash # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database ``` -------------------------------- ### Remove Old Docker Versions Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Execute this command to remove any previously installed Docker packages to ensure a clean installation. ```bash sudo yum remove \ docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine ``` -------------------------------- ### Configure Docker Image Acceleration Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Configure a registry mirror in `/etc/docker/daemon.json` to speed up Docker image pulls from Chinese networks. Create the file if it does not exist. ```json { "registry-mirrors": ["https://registry.docker-cn.com"] } ``` -------------------------------- ### Initiate Payment Source: https://github.com/gz-yami/mall4j/blob/master/doc/接口设计/4. 订单设计-支付.md Initiates the payment process for a given user and payment parameters. This is the entry point for payment operations. ```java PayInfoDto payInfo = payService.pay(userId, payParam); ``` -------------------------------- ### Enter Redis CLI Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Connect to the Redis server using the default host and port to enter the interactive command-line interface. ```bash redis-cli ``` -------------------------------- ### Build for Production (H5) Source: https://github.com/gz-yami/mall4j/blob/master/front-end/mall4uni/README.md Build the project for production deployment on the H5 platform. This command generates optimized static assets. ```bash pnpm run build:h5 ``` -------------------------------- ### Qiniu Cloud Configuration (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/文件上传下载.md Configuration class for setting up Qiniu Cloud Storage beans, including the Qiniu configuration, upload manager, authentication, and bucket manager. ```java @Configuration public class FileUploadConfig { @Autowired private Qiniu qiniu; /** * 华南机房 */ @Bean public com.qiniu.storage.Configuration qiniuConfig() { return new com.qiniu.storage.Configuration(Zone.zone2()); } /** * 构建一个七牛上传工具实例 */ @Bean public UploadManager uploadManager() { return new UploadManager(qiniuConfig()); } /** * 认证信息实例 * @return */ @Bean public Auth auth() { return Auth.create(qiniu.getAccessKey(), qiniu.getSecretKey()); } /** * 构建七牛空间管理实例 */ @Bean public BucketManager bucketManager() { return new BucketManager(auth(), qiniuConfig()); } } ``` -------------------------------- ### Build for Production Source: https://github.com/gz-yami/mall4j/blob/master/front-end/mall4v/README.md Generates a production-ready build of the mall4j frontend. This command optimizes assets for deployment. ```bash pnpm run build ``` -------------------------------- ### Retrieve MySQL Root Temporary Password Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Find the temporary password for the root user generated during MySQL installation by searching the mysqld.log file. ```shell grep 'temporary password' /var/log/mysqld.log ``` -------------------------------- ### Create Database and Remote Access User Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Create a new database named 'yamidb' with utf8 character set and collation, and grant all privileges on this database to a new user 'yami' that can connect from any host ('%'). ```mysql create database yamidb CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON yamidb.* TO 'yami'@'%' IDENTIFIED BY 'Yami@2019'; ``` -------------------------------- ### Get User Shopping Cart Information Source: https://github.com/gz-yami/mall4j/blob/master/doc/接口设计/1. 购物车的设计.md Retrieves user shopping cart information. It allows for updating cart details based on selected promotional items and returns a structured list of carts, shops, and items, including discount information. ```APIDOC ## POST /info ### Description Retrieves user shopping cart information. It allows for updating cart details based on selected promotional items and returns a structured list of carts, shops, and items, including discount information. ### Method POST ### Endpoint /info ### Parameters #### Request Body - **basketIdShopCartParamMap** (Map) - Required - A map where keys are cart IDs and values are `ShopCartParam` objects, used to update promotional item selections and recalculate prices. ### Request Example ```json { "1": { "shopId": 1, "shopCartItemParams": [ { "skuId": 101, "productId": 10, "num": 1, "chooseDiscountItemDto": { "discountId": 1001, "type": "FULL_REDUCTION" } } ] } } ``` ### Response #### Success Response (200) - **data** (List) - A list of `ShopCartDto` objects, each representing a shop with its items and applicable discounts. #### Response Example ```json { "code": "00000", "msg": "success", "data": [ { "shopId": 1, "shopName": "Example Shop", "shopCartItemDiscounts": [ { "chooseDiscountItemDto": { "discountId": 1001, "type": "FULL_REDUCTION" }, "shopCartItems": [ { "productId": 10, "skuId": 101, "productName": "Example Product", "skuName": "Example SKU", "pic": "http://example.com/pic.jpg", "price": 100.00, "num": 1, "totalAmount": 100.00, "discounts": [ { "discountId": 1001, "type": "FULL_REDUCTION", "discountAmount": 10.00 } ] } ] } ] } ] } ``` ``` -------------------------------- ### Login to MySQL Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Log in to the MySQL server as the root user using the retrieved temporary password. ```shell mysql -uroot -p ``` -------------------------------- ### List Downloaded Docker Images Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker 镜像的基本操作.md View a list of all images downloaded to your system using `docker images` or `docker image ls`. The output includes repository, tag, image ID, creation date, and size. ```bash [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE anapsix/alpine-java 8_server-jre_unlimited 49d744fbb526 5 months ago 126MB ``` -------------------------------- ### Nginx Configuration for API and Admin Domains Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/nginx安装与跨域配置.md Configures Nginx server blocks for handling API requests (HTTPS) and admin panel requests (HTTP). This includes SSL certificate setup, proxying to backend applications, and cross-domain configuration for '/apis' path. ```nginx #小程序接口的域名配置,小程序规定要https,填写对应域名,并把https证书上传至服务器 server { listen 443; server_name mall4j-api.gz-yami.com; ssl on; ssl_certificate /usr/share/nginx/cert/xxxxxxxxxxxxxxxx.pem; ssl_certificate_key /usr/share/nginx/cert/xxxxxxxxxxxxxxxx.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; location / { proxy_pass http://127.0.0.1:8112; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } #后台域名配置,后台vue页面代码上传至 /usr/share/nginx/admin server { listen 80; server_name mall4j-admin.gz-yami.com; root /usr/share/nginx/admin; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } # 跨域配置 location /apis { rewrite ^/apis/(.*)$ /$1 break; proxy_pass http://127.0.0.1:8111; } } ``` -------------------------------- ### PageAdapter for Pagination Transformation Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/一对多、多对多分页.md Transforms Mybatis Plus Page parameters (current page, page size) into start and end row indices for manual SQL queries. This is useful when Mybatis Plus's automatic count SQL is inaccurate for complex relationships. ```java import lombok.Data; @Data public class PageAdapter{ private int begin; private int end; public PageAdapter(Page page) { int[] startEnd = PageUtil.transToStartEnd((int) page.getCurrent(), (int) page.getSize()); this.begin = startEnd[0]; this.end = startEnd[1]; } } ``` -------------------------------- ### Verify Accelerator Configuration Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Check if the Docker image accelerator configuration is effective by running `docker info`. Look for the 'Registry Mirrors' section in the output. ```bash docker info ``` -------------------------------- ### Get User Shopping Cart Information API Source: https://github.com/gz-yami/mall4j/blob/master/doc/接口设计/1. 购物车的设计.md This endpoint retrieves user shopping cart information. It accepts a map of selected discount items to recalculate prices. It first updates the cart with any provided discount changes and then fetches all cart items to be processed by the `getShopCarts` method, which handles complex discount and shop logic. ```java @PostMapping("/info") @Operation(summary = "获取用户购物车信息" , description = "获取用户购物车信息,参数为用户选中的活动项数组,以购物车id为key") public ServerResponseEntity> info(@RequestBody Map basketIdShopCartParamMap) { String userId = SecurityUtils.getUser().getUserId(); // 更新购物车信息, if (MapUtil.isNotEmpty(basketIdShopCartParamMap)) { basketService.updateBasketByShopCartParam(userId, basketIdShopCartParamMap); } // 拿到购物车的所有item List shopCartItems = basketService.getShopCartItems(userId); return ServerResponseEntity.success(basketService.getShopCarts(shopCartItems)); } ``` -------------------------------- ### Configure npm Registry Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/教你如何部署.md Sets the npm package registry to the淘宝 mirror. Avoid using 'cnpm' to prevent potential issues. ```bash npm config set registry https://registry.npmmirror.com ``` -------------------------------- ### List Downloaded Docker Images Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker 容器的基本操作.md Displays a list of all Docker images that have been downloaded to your system. This includes repository, tag, and image ID. ```bash docker images ``` ```bash docker image ls ``` ```bash [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE anapsix/alpine-java 8_server-jre_unlimited 49d744fbb526 5 months ago 126MB ``` -------------------------------- ### Dynamic Menu and Permission Loading in Router Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/权限管理.md This code snippet demonstrates how to load navigation menu and permission data from the backend upon user login. It uses `router.beforeEach` to intercept route changes, fetch data via HTTP, and dynamically add menu routes. Permissions are stored in sessionStorage. ```javascript router.beforeEach((to, from, next) => { // 添加动态(菜单)路由 if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') { next() } else { http({ url: http.adornUrl('/sys/menu/nav'), method: 'get', params: http.adornParams() }).then(({ data }) => { sessionStorage.setItem('authorities', JSON.stringify(data.authorities || '[]')) fnAddDynamicMenuRoutes(data.menuList) router.options.isAddDynamicMenuRoutes = true sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]')) next({ ...to, replace: true }) }).catch((e) => { console.log(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue') router.push({ name: 'login' }) }) } }) ``` -------------------------------- ### Monitor Application Logs Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/教你如何部署.md Streams the log output for the backend and frontend services. Replace `${PROJECT_PATH}` with the actual log directory path defined in `logback-prod.xml`. ```bash # 后台日志 tail -f ${PROJECT_PATH}/log/admin.log ``` ```bash # 前端接口日志 tail -f ${PROJECT_PATH}/log/api.log ``` -------------------------------- ### Add Spring Boot AOP Starter Dependency Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/统一的系统日志.md Include this dependency in your project's pom.xml to enable Aspect-Oriented Programming features. ```xml org.springframework.boot spring-boot-starter-aop ``` -------------------------------- ### Add Spring Boot Starter Validation Dependency Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/统一验证.md Include this dependency in your pom.xml to enable validation features. ```xml org.springframework.boot spring-boot-starter-validation ``` -------------------------------- ### 商品 SKU 表结构 (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/商城表设计/商品表设计.md 定义了商品 SKU 的详细信息,包括 ID、商品 ID、销售属性组合、价格、库存、图片、名称等。该实体类用于数据库映射。 ```java import lombok.Data; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import java.util.Date; @Data @TableName("tz_sku") public class Sku implements Serializable { /** * 单品ID */ @TableId private Long skuId; /** * 商品ID */ private Long prodId; /** * 销售属性组合字符串,格式是p1:v1;p2:v2 */ private String properties; /** * 原价 */ private Double oriPrice; /** * 价格 */ private Double price; /** * 库存 */ private Integer stocks; /** * 实际库存 */ private Integer actualStocks; /** * 修改时间 */ private Date updateTime; /** * 记录时间 */ private Date recTime; /** * 商家编码 */ private String partyCode; /** * 商品条形码 */ private String modelId; /** * sku图片 */ private String pic; /** * sku名称 */ private String skuName; /** * 商品名称 */ private String prodName; /** *重量 */ private Double weight; /** * 体积 */ private Double volume; /** * 状态:0禁用 1 启用 */ private Integer status; /** * 0 正常 1 已被删除 */ private Integer isDelete; } ``` -------------------------------- ### Pull Docker Image Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker 容器的基本操作.md Fetches a Docker image from a registry. Specify the image name and optionally a tag or digest. ```bash # docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] docker pull [OPTIONS] NAME[:TAG|@DIGEST] ``` ```bash # 向docker拉取,最小化的jre 1.8的运行环境(anapsix/alpine-java 项目名称name,8_server-jre_unlimited为标签tag) docker pull anapsix/alpine-java:8_server-jre_unlimited ``` -------------------------------- ### Qiniu File Upload Service (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/文件上传下载.md Implementation of the file upload service using Qiniu Cloud Storage. Handles file naming, database insertion, and uploading to Qiniu. ```java @Service public class AttachFileServiceImpl extends ServiceImpl implements AttachFileService { @Autowired private AttachFileMapper attachFileMapper; @Autowired private UploadManager uploadManager; @Autowired private BucketManager bucketManager; @Autowired private Qiniu qiniu; @Autowired private Auth auth; public final static String NORM_MONTH_PATTERN = "yyyy/MM/"; @Override public String uploadFile(byte[] bytes,String originalName) throws QiniuException { String extName = FileUtil.extName(originalName); String fileName =DateUtil.format(new Date(), NORM_MONTH_PATTERN)+ IdUtil.simpleUUID() + "." + extName; AttachFile attachFile = new AttachFile(); attachFile.setFilePath(fileName); attachFile.setFileSize(bytes.length); attachFile.setFileType(extName); attachFile.setUploadTime(new Date()); attachFileMapper.insert(attachFile); String upToken = auth.uploadToken(qiniu.getBucket(),fileName); Response response = uploadManager.put(bytes, fileName, upToken); Json.parseObject(response.bodyString(), DefaultPutRet.class); return fileName; } } ``` -------------------------------- ### 商品 SKU 规格属性值表结构 (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/商城表设计/商品表设计.md 定义了商品 SKU 规格属性的值,包括属性值 ID、属性值名称和关联的属性 ID。该实体类用于数据库映射。 ```java public class ProdProp implements Serializable { /** * 属性值ID */ @TableId private Long valueId; /** * 属性值名称 */ private String propValue; /** * 属性ID */ private Long propId; } ``` -------------------------------- ### 商品 SKU 规格属性表结构 (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/商城表设计/商品表设计.md 定义了商品 SKU 的规格属性名称,用于关联属性 ID 和属性名称。该实体类用于数据库映射。 ```java public class ProdProp implements Serializable { /** * 属性id */ @TableId private Long propId; /** * 属性名称 */ private String propName; private Long shopId; } ``` -------------------------------- ### Configure Redis for Production Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装redis.md Modify the redis.conf file for production use, enabling daemon mode, setting PID file location, port, and data directory. ```ini daemonize yes 让redis以daemon进程运行 pidfile /var/run/redis_6379.pid 设置redis的pid文件位置 port 6379 设置redis的监听端口号 dir /var/redis/6379 设置持久化文件的存储位置 ``` -------------------------------- ### Rendering Navigation Menu from Local Storage Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/权限管理.md This code shows how to retrieve menu data from `sessionStorage` and render it dynamically in the navigation sidebar. It uses a `sub-menu` component to recursively build the menu structure. ```javascript created () { this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]') this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]') this.routeHandle(this.$route) } ``` ```html ``` -------------------------------- ### 商品价格和库存字段定义 Source: https://github.com/gz-yami/mall4j/blob/master/doc/商城表设计/商品表设计.md 定义了商品的总库存量(所有SKU库存累加)、原价以及现价。注意Java中使用Double存储价格,需使用Arith工具类进行运算。 ```java /** * 库存量 * 基于 sku 的库存数量累加 */ private Integer totalStocks; /** * 原价 */ private Double oriPrice; /** * 现价 */ private Double price; ``` -------------------------------- ### Download MySQL 5.7 YUM Repository Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Download the YUM repository RPM package for MySQL 5.7 from the official website. ```shell wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm ``` -------------------------------- ### Add Docker CE Repository Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/docker/docker centos 安装.md Configure the yum package manager to use the official Docker CE repository for CentOS. ```bash sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ``` -------------------------------- ### Configure MySQL Character Set and Case Sensitivity Source: https://github.com/gz-yami/mall4j/blob/master/doc/生产环境/安装mysql.md Modify the my.cnf configuration file to set the default server character set to utf8, initialize connections with utf8, and configure table names to be case-insensitive. ```mysql [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' lower_case_table_names=1 ``` -------------------------------- ### Configure API Endpoint in Mini Program Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Sets the API interface request address for the mall4m mini-program. Verify this matches the backend service port (default 8086). ```javascript domain: 'http://127.0.0.1:8086' ``` -------------------------------- ### File Upload Endpoint (Java) Source: https://github.com/gz-yami/mall4j/blob/master/doc/基本框架设计/文件上传下载.md Backend controller for handling file uploads. It processes a single multipart file and returns a success response with the file name. ```java @RestController @RequestMapping("/admin/file") public class FileController { @Autowired private AttachFileService attachFileService; @PostMapping("/upload/element") public ServerResponseEntity uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{ if(file.isEmpty()){ return ServerResponseEntity.success(); } String fileName = attachFileService.uploadFile(file.getBytes(),file.getOriginalFilename()); return ServerResponseEntity.success(fileName); } } ``` -------------------------------- ### Configure API and Resource URLs in Vue Source: https://github.com/gz-yami/mall4j/blob/master/doc/README.md Sets the base API endpoint and static resource URL for the Vue frontend. Ensure these match your backend service ports (e.g., 8085 for admin, 8086 for uni/mini). ```json // api接口请求地址 VITE_APP_BASE_API = 'http://127.0.0.1:8085' // 静态资源文件url VITE_APP_RESOURCES_URL = 'https://img.mall4j.com/' ``` -------------------------------- ### Core Order Submission Logic Source: https://github.com/gz-yami/mall4j/blob/master/doc/接口设计/3. 订单设计-提交订单.md This is the central method for submitting the order, processing the merger order details. ```java List orders = orderService.submit(userId,mergerOrder); ```