Skip to content

Feature: Lên danh sách khuyến mãi - #68

Merged
amadeusmz merged 7 commits into
masterfrom
planned-extras
Aug 12, 2025
Merged

Feature: Lên danh sách khuyến mãi#68
amadeusmz merged 7 commits into
masterfrom
planned-extras

Conversation

@amadeusmz

@amadeusmz amadeusmz commented Aug 3, 2025

Copy link
Copy Markdown
Member

https://git.minevn.net/kitchen/plan/-/issues/60

Tổng quan

Cho phép server admin lên danh sách khuyên mãi tại file khuyenmai.yml

Nội dung file mẫu (dùng năm 2024 làm ví dụ)

# Đặt lịch khuyến mãi
# Tại file này, bạn có thể lên kế hoạch cho các khuyến mãi trong tương lai
# Mỗi gạch đầu dòng là một kế hoạch khuyến mãi
#
# Các tùy chọn gồm có:
# * name: Tên khuyến mãi
# * rate: Tỉ lệ khuyến mãi, tính theo công thức sau:
#   * 0: Không có khuyến mãi
#   * 0.5: Khuyến mãi 50%, ví dụ: nạp 100k được 150k
#   * 1: Khuyến mãi 100%, ví dụ: nạp 100k được 200k
#   * 1.5: Khuyến mãi 150%, ví dụ: nạp 100k được 250k
# * from: Ngày bắt đầu khuyến mãi (định dạng dd/MM/yyyy HH:mm)
# * to: Ngày kết thúc khuyến mãi (định dạng dd/MM/yyyy HH:mm)
#
# Khuyến mãi ở file này sẽ được ưu tiên so với khuyến mãi được thiết lập ở file config.yml
#
# Trong trường hợp tại một thời điểm có nhiều khuyến mãi cùng lúc, khuyến mãi có tỉ lệ cao nhất sẽ được ưu tiên

- name: '&aNgày Giải Phóng Miền Nam và Quốc tế Lao Động'
  rate: 1.0
  from: 30/04/2024 00:00
  to: 01/05/2024 23:59

- name: '&aNgày Quốc khánh Việt Nam'
  rate: 1.0
  from: 02/09/2024 00:00
  to: 03/09/2024 23:59

Summary by CodeRabbit

  • New Features

    • Support for scheduled promotional campaigns with time ranges and bonus rates; system applies the highest active promotion.
    • Users receive messages naming the promotion and showing the bonus percentage when applicable.
  • Enhancements

    • Manual top-ups and card charges now prioritize active scheduled promotions over legacy settings.
  • Chores

    • Added configuration file for promotions and localization entry for planned-promotion messages.

@amadeusmz amadeusmz self-assigned this Aug 3, 2025
@coderabbitai

coderabbitai Bot commented Aug 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A scheduled promotional bonuses system ("planned extras") was added: new config file and PlannedExtras manager, the main plugin exposes it, and card-processing plus admin top-up flows now prefer planned promotions; localization and messages were extended for planned extras.

Changes

Cohort / File(s) Change Summary
Planned Extras Feature Implementation
dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt
Adds PlannedExtras to load, validate, and manage scheduled promotions from khuyenmai.yml; provides methods to get the current highest-rate active promotion and calculate extra amounts/percentages.
Plugin State Update
dotman-plugin/src/main/java/net/minevn/dotman/DotMan.kt
Adds lateinit var plannedExtras: PlannedExtras and initializes it during reload() so planned promotions are available globally.
Promotion Logic: Card Processing
dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt
Prioritizes plannedExtras.getCurrentExtra() when computing extra points; falls back to legacy extraRate/extraUntil; message selection now distinguishes planned vs legacy extras and includes name.
Promotion Logic: Admin Commands
dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt
Manual top-up uses planned extra if present (overrides legacy rate), records applied percentage and promotion name, and sends messages reporting the applied promotion and rate.
Planned Extras Configuration
dotman-plugin/src/main/resources/khuyenmai.yml
New YAML config file defining scheduled promotions (name, rate, from/to dates) with examples; planned extras take precedence over config-based legacy extras.
Localization Updates
dotman-plugin/src/main/java/net/minevn/dotman/config/Language.kt, dotman-plugin/src/main/resources/messages.yml
Adds cardChargedWithExtraPlanned language property and card-charged-with-extra-planned message key to include promotion name and rate in player messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Plugin as DotMan
    participant PlannedExtras
    participant CardProvider_Admin as CardProvider/AdminCmd
    participant Config

    User->>CardProvider_Admin: request award (card/manual)
    CardProvider_Admin->>Plugin: access plannedExtras
    Plugin->>PlannedExtras: getCurrentExtra()
    PlannedExtras-->>Plugin: active promotion or null
    alt Promotion found
        CardProvider_Admin->>CardProvider_Admin: apply planned promotion (amount, percent, name)
    else No promotion
        CardProvider_Admin->>Config: read legacy extraRate/extraUntil
        CardProvider_Admin->>CardProvider_Admin: apply legacy extra if applicable
    end
    CardProvider_Admin-->>User: award points and send messages (include promotion info if any)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested labels

feat, free

Suggested reviewers

  • tranlong5252

Poem

"I nibble YAML by moonlight's hand,
Planned extras sprout across the land.
A hop, a patch, the bonuses cheer—
Rabbity code makes promos near.
Hooray for bunnies and points this year! 🐇✨"


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3909a9b and 8ea922c.

📒 Files selected for processing (2)
  • dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt (1 hunks)
  • dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt
  • dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch planned-extras

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
dotman-plugin/src/main/resources/khuyenmai.yml (1)

19-27: Update sample dates to avoid confusion.

The sample promotions use 2024 dates which are already expired. Consider updating these to future dates or adding a comment clarifying these are historical examples to avoid confusion when administrators copy this configuration.

-  from: 30/04/2024 00:00
-  to: 01/05/2024 23:59
+  from: 30/04/2025 00:00
+  to: 01/05/2025 23:59

-  from: 02/09/2024 00:00
-  to: 03/09/2024 23:59
+  from: 02/09/2025 00:00
+  to: 03/09/2025 23:59
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c324602 and 0e846b5.

📒 Files selected for processing (5)
  • dotman-plugin/src/main/java/net/minevn/dotman/DotMan.kt (2 hunks)
  • dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt (1 hunks)
  • dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt (1 hunks)
  • dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt (1 hunks)
  • dotman-plugin/src/main/resources/khuyenmai.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: the manual-point feature in `napthucong()` (admincmd.kt) now rejects non-positive values using `take...
Learnt from: amadeusmz
PR: minevn/dotman#62
File: dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt:0-0
Timestamp: 2025-01-06T14:09:58.896Z
Learning: The manual-point feature in `napThuCong()` (AdminCmd.kt) now rejects non-positive values using `takeIf { it > 0 }`. This ensures a user cannot enter zero or negative points.

Applied to files:

  • dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt
  • dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt
🧬 Code Graph Analysis (1)
dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt (1)
dotman-plugin/src/main/java/net/minevn/dotman/utils/Utils.kt (1)
  • info (27-27)
🔇 Additional comments (7)
dotman-plugin/src/main/java/net/minevn/dotman/DotMan.kt (1)

39-39: LGTM! Proper integration of the new PlannedExtras component.

The new plannedExtras property follows the established pattern used by other components like milestonesMaster and discord, with proper lateinit declaration and initialization in the reload() method.

Also applies to: 84-84

dotman-plugin/src/main/java/net/minevn/dotman/commands/AdminCmd.kt (1)

236-242: LGTM! Proper prioritization of planned extras over legacy configuration.

The logic correctly prioritizes planned promotions over legacy configuration with a proper fallback mechanism. The implementation maintains backward compatibility while enabling the new promotional system.

dotman-plugin/src/main/resources/khuyenmai.yml (1)

1-18: LGTM! Excellent documentation and configuration structure.

The comprehensive comments clearly explain all configuration options, including the rate calculation formula and date format. The structure is intuitive and well-organized.

dotman-plugin/src/main/java/net/minevn/dotman/providers/CardProvider.kt (1)

119-128: LGTM! Well-implemented prioritization of planned extras.

The refactoring correctly prioritizes planned promotions while maintaining backward compatibility. The use of plannedExtra.calculateAmount() and plannedExtra.getPercentage() methods provides good encapsulation and consistency with the new promotional system.

dotman-plugin/src/main/java/net/minevn/dotman/config/PlannedExtras.kt (3)

50-55: LGTM! Efficient logic for finding the highest rate active promotion.

The getCurrentExtra() method correctly filters active promotions and returns the one with the highest rate using maxByOrNull. This handles the requirement that overlapping promotions should prioritize the highest rate.


17-37: LGTM! Robust error handling and logging.

The loadComponents() method properly handles invalid entries with try-catch blocks, logs warnings for problematic promotions, and provides informative feedback about the number of loaded promotions.


74-75: Integer overflow in calculateAmount is not a concern with current ranges
After inspection, the largest baseAmount comes from CardPrice.CP_1000K, which maps to 1,000,000. Even at a 100% promotion (rate = 1.0), the result is 2,000,000; and to overflow an Int (max ≈2.1 billion) you’d need an implausibly high rate (>2,147). No changes are required.

@amadeusmz

Copy link
Copy Markdown
Member Author

Tests

  • Lệnh thủ công: OK
  • Nạp qua card: OK
image

@amadeusmz
amadeusmz merged commit 3852219 into master Aug 12, 2025
3 of 4 checks passed
@amadeusmz
amadeusmz deleted the planned-extras branch August 12, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants