#!/bin/bash

echo "=== 验证ExpirationTime设置修复 ==="
echo

echo "1. 检查是否还有setExpirationTime使用DateUtil的问题..."

echo "  查找 setExpirationTime(DateUtil.xxx) 模式："
find src/main/java -name "*.java" -exec grep -Hn "setExpirationTime(DateUtil\." {} \;

echo
echo "2. 检查已修复的文件..."

files=(
    "src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java"
    "src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java"
    "src/main/java/com/gxwebsoft/project/controller/ProjectRenewController.java"
    "src/main/java/com/gxwebsoft/project/service/impl/ProjectServiceImpl.java"
    "src/main/java/com/gxwebsoft/bszx/controller/BszxPayController.java"
)

for file in "${files[@]}"; do
    echo "  检查文件: $file"
    if grep -q "LocalDateTime\.now()" "$file" && ! grep -q "setExpirationTime(DateUtil\." "$file"; then
        echo "    ✅ 已正确修复"
    else
        echo "    ❌ 需要检查"
    fi
done

echo
echo "3. 检查修复方案..."

echo "  ✅ CmsWebsiteServiceImpl.java:"
if grep -q "setExpirationTime(LocalDateTime.now().plusMonths(1))" src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java; then
    echo "    使用 LocalDateTime.now().plusMonths(1)"
else
    echo "    ❌ 修复方案不正确"
fi

echo "  ✅ ShopOrderController.java:"
if grep -q "setExpirationTime(LocalDateTime.now().plusYears(10))" src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java; then
    echo "    使用 LocalDateTime.now().plusYears(10)"
else
    echo "    ❌ 修复方案不正确"
fi

echo "  ✅ ProjectRenewController.java:"
if grep -q "minusDays\|minusMonths" src/main/java/com/gxwebsoft/project/controller/ProjectRenewController.java; then
    echo "    使用 minusDays/minusMonths 方法"
else
    echo "    ❌ 修复方案不正确"
fi

echo "  ✅ ProjectServiceImpl.java:"
if grep -q "plusDays\|plusMonths" src/main/java/com/gxwebsoft/project/service/impl/ProjectServiceImpl.java; then
    echo "    使用 plusDays/plusMonths 方法"
else
    echo "    ❌ 修复方案不正确"
fi

echo "  ✅ BszxPayController.java:"
if grep -q "setExpirationTime(LocalDateTime.now().plusYears(10))" src/main/java/com/gxwebsoft/bszx/controller/BszxPayController.java; then
    echo "    使用 LocalDateTime.now().plusYears(10)"
else
    echo "    ❌ 修复方案不正确"
fi

echo
echo "4. 统计修复情况..."

total_expiration_calls=$(find src/main/java -name "*.java" -exec grep -c "setExpirationTime" {} \; | awk '{sum += $1} END {print sum}')
dateutil_expiration_calls=$(find src/main/java -name "*.java" -exec grep -c "setExpirationTime(DateUtil\." {} \; | awk '{sum += $1} END {print sum}')

echo "  总setExpirationTime调用数: $total_expiration_calls"
echo "  仍使用DateUtil的调用数: $dateutil_expiration_calls"

if [ "$dateutil_expiration_calls" -eq 0 ]; then
    echo "  ✅ 所有setExpirationTime调用已修复"
else
    echo "  ❌ 还有 $dateutil_expiration_calls 个调用需要修复"
fi

echo
echo "=== 验证完成 ==="
