INSERT INTO mall_event
(code, title, event_type, description, start_date, end_date, target_tiers, store_ids,
coupon_id, bonus_point_rate, gift_description, status, active, created_by)
VALUES
(#{code}, #{title}, COALESCE(#{eventType},'DISCOUNT'), #{description}, #{startDate}, #{endDate},
#{targetTiers}, #{storeIds}, #{couponId}, #{bonusPointRate}, #{giftDescription},
COALESCE(#{status},'DRAFT'), COALESCE(#{active},TRUE), #{createdBy})
UPDATE mall_event SET
title=#{title}, event_type=COALESCE(#{eventType},event_type), description=#{description},
start_date=#{startDate}, end_date=#{endDate}, target_tiers=#{targetTiers}, store_ids=#{storeIds},
coupon_id=#{couponId}, bonus_point_rate=#{bonusPointRate}, gift_description=#{giftDescription},
status=COALESCE(#{status},status), active=COALESCE(#{active},active), updated_at=NOW()
WHERE id=#{id}
UPDATE mall_event SET status=#{status}, updated_at=NOW() WHERE id=#{id}
DELETE FROM mall_event WHERE id=#{id}
INSERT INTO mall_event_banner (event_id, image_url, headline, subtext, link_url, sort_order, active)
VALUES (#{eventId}, #{imageUrl}, #{headline}, #{subtext}, #{linkUrl}, COALESCE(#{sortOrder},0), COALESCE(#{active},TRUE))
DELETE FROM mall_event_banner WHERE id=#{id}
DELETE FROM mall_event_banner WHERE event_id=#{eventId}
INSERT INTO mall_event_participation (event_id, owner, coupon_id, order_no, reward)
VALUES (#{eventId}, #{owner}, #{couponId}, #{orderNo}, #{reward})