后台完成修复,初始化项目

This commit is contained in:
2025-07-01 17:18:04 +08:00
commit 5916f076b7
74 changed files with 17444 additions and 0 deletions

View File

@@ -0,0 +1,215 @@
package com.org.flashsalesystem.util;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* JSP自定义函数工具类
* 提供在JSP页面中使用的格式化函数
*/
public class JSPFunctions {
private static final DecimalFormat PRICE_FORMAT = new DecimalFormat("#,##0.00");
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm");
/**
* 格式化价格
*
* @param price 价格
*
* @return 格式化后的价格字符串
*/
public static String formatPrice(Object price) {
if (price == null) {
return "0.00";
}
try {
if (price instanceof BigDecimal) {
return PRICE_FORMAT.format(price);
} else if (price instanceof Number) {
return PRICE_FORMAT.format(((Number) price).doubleValue());
} else {
double priceValue = Double.parseDouble(price.toString());
return PRICE_FORMAT.format(priceValue);
}
} catch (Exception e) {
return "0.00";
}
}
/**
* 格式化日期时间
*
* @param date 日期
*
* @return 格式化后的日期字符串
*/
public static String formatDateTime(Date date) {
if (date == null) {
return "";
}
return DATE_FORMAT.format(date);
}
/**
* 格式化短日期时间
*
* @param date 日期
*
* @return 格式化后的短日期字符串
*/
public static String formatShortDateTime(Date date) {
if (date == null) {
return "";
}
return SHORT_DATE_FORMAT.format(date);
}
/**
* 计算折扣百分比
*
* @param originalPrice 原价
* @param salePrice 售价
*
* @return 折扣百分比
*/
public static String calculateDiscount(Object originalPrice, Object salePrice) {
try {
double original = parsePrice(originalPrice);
double sale = parsePrice(salePrice);
if (original <= 0 || sale <= 0) {
return "0%";
}
double discount = (original - sale) / original * 100;
return String.format("%.0f%%", discount);
} catch (Exception e) {
return "0%";
}
}
/**
* 格式化库存数量
*
* @param stock 库存
*
* @return 格式化后的库存字符串
*/
public static String formatStock(Object stock) {
if (stock == null) {
return "0";
}
try {
int stockValue = Integer.parseInt(stock.toString());
if (stockValue <= 0) {
return "缺货";
} else if (stockValue < 10) {
return "仅剩" + stockValue + "";
} else {
return stockValue + "";
}
} catch (Exception e) {
return "0";
}
}
/**
* 截断文本
*
* @param text 文本
* @param maxLength 最大长度
*
* @return 截断后的文本
*/
public static String truncateText(String text, int maxLength) {
if (text == null || text.length() <= maxLength) {
return text;
}
return text.substring(0, maxLength) + "...";
}
/**
* 格式化订单状态
*
* @param status 状态码
*
* @return 状态描述
*/
public static String formatOrderStatus(Object status) {
if (status == null) {
return "未知";
}
try {
int statusCode = Integer.parseInt(status.toString());
switch (statusCode) {
case 1:
return "待支付";
case 2:
return "已支付";
case 3:
return "已发货";
case 4:
return "已完成";
case 5:
return "已取消";
default:
return "未知";
}
} catch (Exception e) {
return "未知";
}
}
/**
* 格式化秒杀状态
*
* @param status 状态码
*
* @return 状态描述
*/
public static String formatFlashSaleStatus(Object status) {
if (status == null) {
return "未知";
}
try {
int statusCode = Integer.parseInt(status.toString());
switch (statusCode) {
case 1:
return "未开始";
case 2:
return "进行中";
case 3:
return "已结束";
default:
return "未知";
}
} catch (Exception e) {
return "未知";
}
}
/**
* 解析价格
*/
private static double parsePrice(Object price) {
if (price == null) {
return 0.0;
}
if (price instanceof BigDecimal) {
return ((BigDecimal) price).doubleValue();
} else if (price instanceof Number) {
return ((Number) price).doubleValue();
} else {
return Double.parseDouble(price.toString());
}
}
}

View File

@@ -0,0 +1,35 @@
package com.org.flashsalesystem.util;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* 密码生成工具
* 用于生成BCrypt加密的密码
*/
public class PasswordGenerator {
public static void main(String[] args) {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
// 生成演示账号密码
String demo1Password = encoder.encode("123456");
String demo2Password = encoder.encode("123456");
String adminPassword = encoder.encode("admin123");
System.out.println("=== 演示账号密码哈希 ===");
System.out.println("demo1 (123456): " + demo1Password);
System.out.println("demo2 (123456): " + demo2Password);
System.out.println("admin (admin123): " + adminPassword);
System.out.println("\n=== SQL更新语句 ===");
System.out.println("UPDATE users SET password = '" + demo1Password + "' WHERE username = 'demo1';");
System.out.println("UPDATE users SET password = '" + demo2Password + "' WHERE username = 'demo2';");
System.out.println("UPDATE users SET password = '" + adminPassword + "' WHERE username = 'admin';");
// 验证密码
System.out.println("\n=== 密码验证 ===");
System.out.println("demo1密码验证: " + encoder.matches("123456", demo1Password));
System.out.println("demo2密码验证: " + encoder.matches("123456", demo2Password));
System.out.println("admin密码验证: " + encoder.matches("admin123", adminPassword));
}
}