-- ============================================
-- 更新2026-01-16补录数据的领取时间为2025-11-16
-- 执行时间：2026-01-16
-- 说明：将今天补录的数据的领取时间改为2025年11月16日
-- ============================================

-- 方案1：更新今天创建的申请记录（如果今天有创建申请）
-- UPDATE lq_inventory_usage_application
-- SET F_ReceiveTime = '2025-11-16 00:00:00',
--     F_UpdateTime = NOW(),
--     F_UpdateUser = 'admin'
-- WHERE DATE(F_ApplicationTime) = '2026-01-16'
--     AND F_IsEffective = 1
--     AND F_IsReceived = 1
--     AND F_ReceiveTime IS NOT NULL;

-- 方案2：更新今天标记为已领取的记录（如果今天有标记领取）
-- UPDATE lq_inventory_usage_application
-- SET F_ReceiveTime = '2025-11-16 00:00:00',
--     F_UpdateTime = NOW(),
--     F_UpdateUser = 'admin'
-- WHERE DATE(F_ReceiveTime) = '2026-01-16'
--     AND F_IsEffective = 1
--     AND F_IsReceived = 1;

-- 方案3：更新今天更新的记录（如果今天有更新）
-- UPDATE lq_inventory_usage_application
-- SET F_ReceiveTime = '2025-11-16 00:00:00',
--     F_UpdateTime = NOW(),
--     F_UpdateUser = 'admin'
-- WHERE DATE(F_UpdateTime) = '2026-01-16'
--     AND F_IsEffective = 1
--     AND F_IsReceived = 1
--     AND F_ReceiveTime IS NOT NULL;

-- ============================================
-- 推荐方案：先查询确认，再执行更新
-- ============================================

-- 步骤1：查询今天补录的数据（根据实际情况选择查询条件）
-- 查询今天创建的申请记录
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime as CurrentReceiveTime,
    '2025-11-16 00:00:00' as NewReceiveTime,
    F_IsReceived,
    F_ApprovalStatus
FROM lq_inventory_usage_application
WHERE DATE(F_ApplicationTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1
    AND F_ReceiveTime IS NOT NULL;

-- 查询今天标记为已领取的记录
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime as CurrentReceiveTime,
    '2025-11-16 00:00:00' as NewReceiveTime,
    F_IsReceived,
    F_ApprovalStatus
FROM lq_inventory_usage_application
WHERE DATE(F_ReceiveTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1;

-- 查询今天更新的记录
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime as CurrentReceiveTime,
    '2025-11-16 00:00:00' as NewReceiveTime,
    F_IsReceived,
    F_ApprovalStatus,
    F_UpdateTime
FROM lq_inventory_usage_application
WHERE DATE(F_UpdateTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1
    AND F_ReceiveTime IS NOT NULL;

-- ============================================
-- 步骤2：确认数据后，执行更新（请根据实际情况选择对应的方案）
-- ============================================

-- 更新今天创建的申请记录的领取时间
UPDATE lq_inventory_usage_application
SET F_ReceiveTime = '2025-11-16 00:00:00',
    F_UpdateTime = NOW(),
    F_UpdateUser = 'admin'
WHERE DATE(F_ApplicationTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1
    AND F_ReceiveTime IS NOT NULL;

-- 或者：更新今天标记为已领取的记录的领取时间
UPDATE lq_inventory_usage_application
SET F_ReceiveTime = '2025-11-16 00:00:00',
    F_UpdateTime = NOW(),
    F_UpdateUser = 'admin'
WHERE DATE(F_ReceiveTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1;

-- 或者：更新今天更新的记录的领取时间
-- UPDATE lq_inventory_usage_application
-- SET F_ReceiveTime = '2025-11-16 00:00:00',
--     F_UpdateTime = NOW(),
--     F_UpdateUser = 'admin'
-- WHERE DATE(F_UpdateTime) = '2026-01-16'
--     AND F_IsEffective = 1
--     AND F_IsReceived = 1
--     AND F_ReceiveTime IS NOT NULL;

-- ============================================
-- 步骤3：验证更新结果
-- ============================================

-- 验证：查询更新后的数据
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime,
    F_IsReceived,
    F_ApprovalStatus,
    F_UpdateTime
FROM lq_inventory_usage_application
WHERE DATE(F_ApplicationTime) = '2026-01-16'
    AND F_IsEffective = 1
    AND F_IsReceived = 1
    AND DATE(F_ReceiveTime) = '2025-11-16';

-- ============================================
-- 注意事项：
-- 1. 执行前请先运行查询语句确认要更新的数据
-- 2. 建议在测试环境先验证
-- 3. 更新后需要重新计算相关工资和股份统计数据
-- 4. 如果更新了领取时间，可能需要重新计算：
--    - 2025年11月的工资（如果使用11月数据）
--    - 2025年12月的工资（如果使用11月数据）
--    - 2025年11月的股份统计
-- ============================================
