Browse Source

修改Products表字段类型:将quantity字段改为String类型

master
Trae AI 2 months ago
parent
commit
778ce221f0
  1. 213
      init_deploy.sh
  2. 8
      src/main/java/com/example/web/entity/Products.java
  3. 2
      src/main/java/com/example/web/service/impl/CustomerServiceImpl.java
  4. 2
      src/main/resources/application.yaml
  5. 2
      src/main/resources/static/loginmm.html
  6. 2
      src/main/resources/static/sells.html
  7. 2
      src/main/resources/static/supply.html

213
init_deploy.sh

@ -0,0 +1,213 @@
#!/bin/bash
# 初始化部署脚本 - 在云端服务器上生成部署文件并拉取代码
# 部署目录
deploy_dir="/opt/project_root"
mkdir -p "$deploy_dir"
cd "$deploy_dir"
echo "开始在云端服务器初始化部署环境..."
# 1. 创建Dockerfile
echo "创建Dockerfile..."
cat > Dockerfile << 'EOF'
# 使用官方Tomcat 10.1作为基础镜像,兼容Spring Boot 3.x和Java 17
FROM tomcat:10.1-jdk17-openjdk
# 维护者信息
LABEL maintainer="your-email@example.com"
# 删除Tomcat默认的ROOT应用
RUN rm -rf /usr/local/tomcat/webapps/ROOT
# 将构建好的WAR文件复制到Tomcat的webapps目录下,并命名为backend.war,与配置文件中的上下文路径一致
COPY web.war /usr/local/tomcat/webapps/backend.war
# 暴露Tomcat默认端口
EXPOSE 8080
# 启动Tomcat服务
CMD ["catalina.sh", "run"]
EOF
# 2. 创建docker-compose.yml
echo "创建docker-compose.yml..."
cat > docker-compose.yml << 'EOF'
services:
tomcat-app:
image: web-application:latest
ports:
- "8080:8080"
environment:
- SPRING_DATASOURCE_PRIMARY_JDBC_URL=jdbc:mysql://1.95.162.61:3306/userlogin?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
- SPRING_DATASOURCE_PRIMARY_USERNAME=root
- SPRING_DATASOURCE_PRIMARY_PASSWORD=schl@2025
- SPRING_DATASOURCE_WECHAT_JDBC_URL=jdbc:mysql://1.95.162.61:3306/wechat_app?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
- SPRING_DATASOURCE_WECHAT_USERNAME=root
- SPRING_DATASOURCE_WECHAT_PASSWORD=schl@2025
- SERVER_SERVLET_CONTEXT_PATH=/backend
restart: always
container_name: web-application
EOF
# 3. 创建deploy.sh
echo "创建deploy.sh..."
cat > deploy.sh << 'EOF'
#!/bin/bash
# 修复后的部署脚本 - 解决Maven构建找不到pom.xml的问题
# 配置信息
GIT_REPO="http://8.137.125.67:4000/SwtTt29/Page--root.git"
BRANCH="master"
PROJECT_NAME="web"
DOCKER_IMAGE="web-application"
CONTAINER_NAME="web-application"
PORT="8080"
# 颜色定义
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
NC="\033[0m" # No Color
echo -e "${YELLOW}开始部署应用...${NC}"
# 1. 检查Git是否安装
if ! command -v git &> /dev/null; then
echo -e "${RED}错误: Git未安装,请先安装Git${NC}"
exit 1
fi
# 2. 检查Docker是否安装
if ! command -v docker &> /dev/null; then
echo -e "${RED}错误: Docker未安装,请先安装Docker${NC}"
exit 1
fi
# 3. 检查Docker Compose是否安装
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}错误: Docker Compose未安装,请先安装Docker Compose${NC}"
exit 1
fi
# 4. 拉取或更新代码
echo -e "${GREEN}1. 拉取/更新代码...${NC}"
if [ -d "$PROJECT_NAME" ]; then
cd "$PROJECT_NAME"
git pull origin "$BRANCH"
if [ $? -ne 0 ]; then
echo -e "${RED}错误: Git拉取失败${NC}"
exit 1
fi
else
git clone "$GIT_REPO" "$PROJECT_NAME"
if [ $? -ne 0 ]; then
echo -e "${RED}错误: Git克隆失败${NC}"
exit 1
fi
cd "$PROJECT_NAME"
fi
# 5. 查找pom.xml文件,确定正确的构建目录
echo -e "${GREEN}2. 查找pom.xml文件...${NC}"
pom_path=$(find . -name "pom.xml" -type f | head -1)
if [ -z "$pom_path" ]; then
echo -e "${RED}错误: 未找到pom.xml文件,请检查Git仓库结构${NC}"
exit 1
fi
# 获取pom.xml所在目录
maven_dir=$(dirname "$pom_path")
echo -e "${GREEN}3. 在目录 $maven_dir 中构建项目...${NC}"
# 6. 构建项目
cd "$maven_dir"
mvn clean package -DskipTests
if [ $? -ne 0 ]; then
echo -e "${RED}错误: Maven构建失败${NC}"
exit 1
fi
# 7. 查找生成的WAR文件(使用original版本,避免Spring Boot嵌入式Tomcat与外部Tomcat冲突)
war_path=$(find . -name "*.war.original" -type f | head -1)
# 如果没有找到original版本,使用普通WAR文件
if [ -z "$war_path" ]; then
war_path=$(find . -name "*.war" -type f | head -1)
fi
if [ -z "$war_path" ]; then
echo -e "${RED}错误: 未找到生成的WAR文件,请检查Maven构建结果${NC}"
exit 1
fi
# 8. 获取绝对路径的WAR文件路径
if [[ "$war_path" != /* ]]; then
war_path="$(pwd)/$war_path"
fi
# 9. 返回项目根目录(当前在maven_dir,需要返回到/opt/project_root目录)
cd /opt/project_root
# 9. 复制WAR文件到web子目录下,供Dockerfile使用
cp "$war_path" ./web/web.war
echo -e "${GREEN}4. 停止并移除旧容器...${NC}"
# 确保旧容器被完全移除,即使docker-compose down失败
old_container=$(docker ps -a -q -f name=web-application)
if [ ! -z "$old_container" ]; then
echo -e "${GREEN} 停止旧容器...${NC}"
docker stop "$old_container" > /dev/null 2>&1
echo -e "${GREEN} 移除旧容器...${NC}"
docker rm "$old_container" > /dev/null 2>&1
fi
# 使用docker-compose down确保所有相关资源都被清理
docker-compose down 2>/dev/null || true
# 10. 构建新的Docker镜像
echo -e "${GREEN}5. 构建Docker镜像...${NC}"
docker build -t web-application:latest ./web
if [ $? -ne 0 ]; then
echo -e "${RED}错误: Docker构建失败${NC}"
exit 1
fi
# 11. 启动新容器
echo -e "${GREEN}6. 启动新容器...${NC}"
docker-compose up -d
if [ $? -ne 0 ]; then
echo -e "${RED}错误: Docker容器启动失败${NC}"
exit 1
fi
# 12. 清理临时WAR文件
rm -f ./web/web.war
echo -e "${GREEN}部署完成!${NC}"
echo -e "${YELLOW}应用访问地址: http://8.137.125.67:${PORT}/backend${NC}"
echo -e "${YELLOW}容器名称: ${CONTAINER_NAME}${NC}"
echo -e "${YELLOW}查看日志命令: docker logs -f ${CONTAINER_NAME}${NC}"
EOF
# 4. 设置脚本执行权限
echo "设置脚本执行权限..."
chmod +x deploy.sh
# 5. 拉取Git代码
echo "拉取Git代码..."
git clone http://8.137.125.67:4000/SwtTt29/Page--root.git web
# 6. 将Dockerfile复制到web目录
cp Dockerfile web/
echo "初始化完成!"
echo "部署文件已生成在: $deploy_dir"
echo "Git代码已拉取到: $deploy_dir/web"
echo "可以通过以下命令执行部署:"
echo " cd $deploy_dir"
echo " ./deploy.sh"

8
src/main/java/com/example/web/entity/Products.java

@ -20,7 +20,7 @@ public class Products {
private String sellerId;//卖家id
private String productName;//产品名称
private String price;//单价 (数据库中为varchar类型)
private Integer quantity;//数量
private String quantity;//数量 (改为string类型)
private String variety;//品种
private String grossWeight;//毛重 (数据库中为varchar类型)
private String specification;//规格
@ -30,7 +30,7 @@ public class Products {
private String yolk;//蛋黄
private String rejectReason;//驳回原因
public Products(Integer id, String productId, String sellerId, String productName, String price, Integer quantity, String variety, String grossWeight, String specification, String status, LocalDateTime created_at, LocalDateTime updated_at, String yolk, String rejectReason) {
public Products(Integer id, String productId, String sellerId, String productName, String price, String quantity, String variety, String grossWeight, String specification, String status, LocalDateTime created_at, LocalDateTime updated_at, String yolk, String rejectReason) {
this.id = id;
this.productId = productId;
this.sellerId = sellerId;
@ -87,11 +87,11 @@ public class Products {
this.price = price;
}
public Integer getQuantity() {
public String getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
public void setQuantity(String quantity) {
this.quantity = quantity;
}

2
src/main/java/com/example/web/service/impl/CustomerServiceImpl.java

@ -1422,7 +1422,7 @@ public class CustomerServiceImpl implements CustomerService {
CustomerData.ProductFavorite productFavorite = new CustomerData.ProductFavorite();
productFavorite.setProductName(product.getProductName());
productFavorite.setPrice(product.getPrice());
productFavorite.setQuantity(String.valueOf(product.getQuantity()));
productFavorite.setQuantity(product.getQuantity());
productFavorite.setGrossWeight(product.getGrossWeight());
productFavorite.setYolk(product.getYolk());
productFavorite.setFavoriteDate(favorite.getDate());

2
src/main/resources/application.yaml

@ -63,7 +63,7 @@ management:
enabled: true
server:
port: 8080
port: 8081
servlet:
context-path: /DL
encoding:

2
src/main/resources/static/loginmm.html

@ -520,7 +520,7 @@
errorElement.classList.remove('show');
}
const API_BASE_URL = 'http://8.137.125.67:8080/DL'; // 服务器API地址
const API_BASE_URL = 'http://localhost:8081/DL'; // 服务器API地址
async function sendLoginRequest(projectName, userName, password) {
try {
// 使用URL编码的表单数据

2
src/main/resources/static/sells.html

@ -4727,7 +4727,7 @@
return currentPageRecords;
}
const API_BASE_URL = 'http://8.137.125.67:8080/DL'; // 后端API基础地址
const API_BASE_URL = 'http://localhost:8081/DL'; // 后端API基础地址
// 获取登录用户信息函数
function getLoginUserInfo() {

2
src/main/resources/static/supply.html

@ -4781,7 +4781,7 @@
return currentPageRecords;
}
const API_BASE_URL = 'http://8.137.125.67:8080/DL'; // 后端API基础地址
const API_BASE_URL = 'http://localhost:8081/DL'; // 后端API基础地址
// 获取登录用户信息函数
function getLoginInfo() {

Loading…
Cancel
Save