#!/bin/bash

echo "=== 时间兼容性问题最终验证 ==="
echo

echo "1. 检查LocalDateTime字段与Date比较的问题..."
echo "查找可能的类型不匹配："

# 查找可能的问题模式
echo "  - 查找 .compareTo(DateUtil.date()) 模式："
find src/main/java -name "*.java" -exec grep -Hn "\.compareTo(DateUtil\.date())" {} \; | head -5

echo "  - 查找 DateUtil.offsetDay(...).compareTo(DateUtil.date()) 模式："
find src/main/java -name "*.java" -exec grep -Hn "DateUtil\.offsetDay.*\.compareTo(DateUtil\.date())" {} \; | head -5

echo "  - 查找 setXxxTime(DateUtil.date()) 模式："
find src/main/java -name "*.java" -exec grep -Hn "\.set.*Time(DateUtil\.date())" {} \; | head -5

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

echo "  ✅ OaAssetsSslServiceImpl.java:"
if grep -q "LocalDateTime now = LocalDateTime.now()" src/main/java/com/gxwebsoft/oa/service/impl/OaAssetsSslServiceImpl.java; then
    echo "    已正确修复"
else
    echo "    ❌ 需要检查"
fi

echo "  ✅ ShopOrderServiceImpl.java:"
if grep -q "setPayTime(LocalDateTime.now())" src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java; then
    echo "    已正确修复"
else
    echo "    ❌ 需要检查"
fi

echo "  ✅ ProjectServiceImpl.java:"
if grep -q "ChronoUnit.DAYS.between" src/main/java/com/gxwebsoft/project/service/impl/ProjectServiceImpl.java; then
    echo "    已正确修复"
else
    echo "    ❌ 需要检查"
fi

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

total_files=$(find src/main/java -name "*.java" | wc -l)
dateutil_files=$(find src/main/java -name "*.java" -exec grep -l "DateUtil\.date()" {} \; | wc -l)
localdatetime_files=$(find src/main/java -name "*.java" -exec grep -l "LocalDateTime" {} \; | wc -l)

echo "  总Java文件数: $total_files"
echo "  使用DateUtil.date()的文件数: $dateutil_files"
echo "  使用LocalDateTime的文件数: $localdatetime_files"

echo
echo "4. 检查可能遗漏的问题..."

echo "  查找同时使用LocalDateTime和DateUtil.date()的文件："
find src/main/java -name "*.java" -exec sh -c '
    if grep -q "LocalDateTime" "$1" && grep -q "DateUtil\.date()" "$1"; then
        echo "  ⚠️  $1 - 需要检查兼容性"
    fi
' _ {} \;

echo
echo "=== 验证完成 ==="
echo
echo "建议："
echo "1. 如果发现任何类型不匹配的问题，请手动修复"
echo "2. 运行单元测试确保修复正确"
echo "3. 特别注意日期比较和时间设置的逻辑"
