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

-- ============================================
-- 第一步：查询今天补录的数据（请先执行此查询确认数据）
-- ============================================

-- 查询今天创建的申请记录（推荐使用此查询）
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime as CurrentReceiveTime,
    F_IsReceived,
    F_ApprovalStatus,
    F_UpdateTime
FROM lq_inventory_usage_application
WHERE DATE(F_ApplicationTime) = '2026-01-16'
    AND F_IsEffective = 1
ORDER BY F_ApplicationTime DESC;

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

-- 查询今天更新的记录
SELECT 
    F_Id,
    F_UsageBatchId,
    F_ApplicationStoreId,
    F_ApplicationTime,
    F_ReceiveTime as CurrentReceiveTime,
    F_IsReceived,
    F_ApprovalStatus,
    F_UpdateTime
FROM lq_inventory_usage_application
WHERE DATE(F_UpdateTime) = '2026-01-16'
    AND F_IsEffective = 1
ORDER BY F_UpdateTime DESC;

-- ============================================
-- 第二步：根据查询结果，选择对应的更新语句执行
-- ============================================

-- 方案A：更新今天创建的申请记录的领取时间（如果已领取）
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;

-- 方案B：更新今天标记为已领取的记录的领取时间
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;

-- 方案C：更新今天更新的记录的领取时间（如果已领取）
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;

-- ============================================
-- 第三步：验证更新结果
-- ============================================

-- 验证：查询更新后的数据
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' 
    OR DATE(F_ReceiveTime) = '2026-01-16'
    OR DATE(F_UpdateTime) = '2026-01-16')
    AND F_IsEffective = 1
    AND F_IsReceived = 1
    AND DATE(F_ReceiveTime) = '2025-11-16'
ORDER BY F_UpdateTime DESC;

-- ============================================
-- 第四步：更新后需要重新计算的数据
-- ============================================

-- 注意：更新领取时间后，需要重新计算以下数据：
-- 1. 2025年11月的工资（如果使用11月数据）
--    - 店长工资：POST /api/Extend/lqstoremanagersalary/calculate/store-manager?year=2025&month=11
--    - 主任工资：POST /api/Extend/lqdirectorsalary/calculate/director?year=2025&month=11
--    - 事业部总经理/经理工资：POST /api/Extend/lqbusinessunitmanagersalary/calculate/business-unit-manager?year=2025&month=11
-- 2. 2025年12月的工资（如果使用11月数据）
--    - 店长工资：POST /api/Extend/lqstoremanagersalary/calculate/store-manager?year=2025&month=12
--    - 主任工资：POST /api/Extend/lqdirectorsalary/calculate/director?year=2025&month=12
--    - 事业部总经理/经理工资：POST /api/Extend/lqbusinessunitmanagersalary/calculate/business-unit-manager?year=2025&month=12
-- 3. 2025年11月的股份统计
--    - POST /api/Extend/lqsharestatisticsstore/generate (body: {"statisticsMonth":"202511"})

-- ============================================
-- 执行说明：
-- 1. 先执行第一步的查询语句，确认要更新的数据
-- 2. 根据查询结果，选择对应的更新方案（方案A/B/C）
-- 3. 执行更新语句
-- 4. 执行第三步的验证查询，确认更新成功
-- 5. 根据实际情况，重新计算相关的工资和股份统计数据
-- ============================================
