{"id":404206,"date":"2024-06-29T17:34:07","date_gmt":"2024-06-29T17:34:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=404206"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T17:34:07","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=404206","title":{"rendered":"<span>\u041d\u0430\u0433\u0440\u0430\u0434\u044b \u0432 \u0438\u0433\u0440\u0430\u0445. \u0412\u0430\u0440\u0438\u0430\u043d\u0442 backend \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 \u0441\u0443\u043d\u0434\u0443\u043a\u043e\u0432 \u0438 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0433\u0435\u0439\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0445 \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c. <a href=\"https:\/\/habr.com\/en\/post\/568220\/\" rel=\"noopener noreferrer nofollow\">\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0438\u0434\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0438 \u0441\u0443\u043d\u0434\u0443\u043a\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0430\u0433\u0440\u0430\u0434 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443<\/a>. \u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u0443 \u0438\u0433\u0440\u044b \u0438 \u0442\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0443\u043d\u0434\u0443\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u043c\u0438 \u0438 \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0442\u044c \u0438 \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0442\u044c \u0438\u0445. \u00a0<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/35d\/c38\/8c0\/35dc388c092f66be6a04d95c7ece88de.jpeg\" width=\"500\" height=\"375\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35d\/c38\/8c0\/35dc388c092f66be6a04d95c7ece88de.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u0443\u0436\u0435 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f &#8212; \u043e\u0442 \u0437\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0433\u0435\u0439\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u043e\u043c, \u0434\u043e \u0432\u044b\u0434\u0430\u0447\u0438 \u044d\u0442\u043e\u0439 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0432 \u0438\u0433\u0440\u0435. \u0411\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0430, \u0438 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0438\u0434\u0431\u044d\u043a \u043e\u0442 \u0442\u0435\u0445 \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. <a href=\"https:\/\/github.com\/deft1991\/petproject\/tree\/master\/reward\" rel=\"noopener noreferrer nofollow\">\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0432 GitHub.<\/a><\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u201c\u041d\u0430\u0433\u0440\u0430\u0434\u0430\u201d \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u042d\u0442\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0418 \u043d\u0430\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u201c\u044d\u043d\u0442\u0438\u0442\u0438\u201d \u043a \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u0434 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.\u00a0<\/p>\n<pre><code>@Getter @Setter @Entity(name = \"reward\") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = \"type\", \u00a0 \u00a0 \u00a0 \u00a0 discriminatorType = DiscriminatorType.STRING) @DynamicUpdate @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = \"non-lazy\") public abstract class Reward implements GameItem {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 @Id     @GeneratedValue( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strategy = GenerationType.SEQUENCE, \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 generator = \"seq_reward\" \u00a0 \u00a0 ) \u00a0 \u00a0 @SequenceGenerator( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 name = \"seq_reward\", \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 allocationSize = 1 \u00a0 \u00a0 ) \u00a0 \u00a0 @Column(name = \"id\", nullable = false, length = 36, unique = true) \u00a0 \u00a0 private Long id;  \u00a0 \u00a0 @Column(name = \"alias\", length = 255) \u00a0 \u00a0 private String alias; \/\/ short description  \u00a0 \u00a0 @Column(name = \"min_count\") \u00a0 \u00a0 private Integer minCount = 0; \/\/ it is diff card count for card reward, can be null for some rewards  \u00a0 \u00a0 @Column(name = \"max_count\") \u00a0 \u00a0 private Integer maxCount = 0; \/\/ it is diff card count for card reward, can be null for some rewards<\/code><\/pre>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/cee\/cd7\/267\/ceecd7267376724b5e915acd4d8a941c.jpeg\" width=\"400\" height=\"300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cee\/cd7\/267\/ceecd7267376724b5e915acd4d8a941c.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>   \u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 &#171;\u0437\u043e\u043b\u043e\u0442\u043e&#187; (&#171;GOLD&#187;).<\/p>\n<pre><code>@Entity @DiscriminatorValue(\"GOLD\") @NoArgsConstructor public class GoldReward extends Reward {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Generate gold currency for profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 @Override \u00a0 \u00a0 public List&lt;?> rewardFor(Profile profile, ContentGenerator contentGenerator) { \u00a0 \u00a0 \u00a0 \u00a0 int count = contentGenerator.generateCount(this.getMinCount(), this.getMaxCount(), this.getCount()); \u00a0 \u00a0 \u00a0 \u00a0 return List.of(new GoldCurrency(profile, count));  \u00a0 \u00a0 }  \u00a0 \u00a0 @Override \u00a0 \u00a0 public RewardType getType() { \u00a0 \u00a0 \u00a0 \u00a0 return RewardType.GOLD; \u00a0 \u00a0 }  <\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e GoldReward \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f RewardType.GOLD. \u042d\u0442\u043e enum \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430\u0433\u0440\u0430\u0434. \u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043d\u0435\u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u00a0<\/p>\n<pre><code>public interface GameItem { \u00a0 \u00a0 List&lt;?> rewardFor(Profile profile, ContentGenerator contentGenerator); }<\/code><\/pre>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/fde\/be9\/3c1\/fdebe93c157a3375d934dc7d41fbedd8.jpeg\" width=\"700\" height=\"376\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fde\/be9\/3c1\/fdebe93c157a3375d934dc7d41fbedd8.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<pre><code>INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (1, '\u0417\u043e\u043b\u043e\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e', 'GOLD', 30, 60);  INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (2, '\u0417\u043e\u043b\u043e\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435', 'GOLD', 100, 200);  INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (3, '\u0417\u043e\u043b\u043e\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435', 'GOLD', 500, 700);<\/code><\/pre>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Spring Data \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. <\/p>\n<pre><code>public interface RewardRepository&lt;T extends Reward> extends JpaRepository&lt;T, Long> { }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043b\u0438\u0448\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f ContentGenerator. \u042d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0433\u0440\u0430\u0434\u044b, \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0441 \u0448\u0430\u043d\u0441\u043e\u043c \u0432\u044b\u043f\u0430\u0434\u0435\u043d\u0438\u044f, \u0442\u043e ContentGenerator \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u043d\u0430\u0433\u0440\u0430\u0434\u0430 \u0438\u043b\u0438 \u043d\u0435\u0442, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0433\u0440\u0430\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.\u00a0<\/p>\n<pre><code>public interface ContentGenerator {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Should drop reward \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 boolean shouldDropReward(int chance);  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Generate random count in interval \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 int generateCount(Integer from, Integer to, Integer count); }<\/code><\/pre>\n<p>\u042f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0432\u0437\u044f\u0442\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u041c\u044b \u043f\u043e\u043a\u0430 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u043f\u043e \u0435\u0435 id.\u00a0<\/p>\n<pre><code>public class RewardServiceImpl implements RewardService {  \u00a0\u00a0 \u00a0@Override \u00a0 \u00a0 @SneakyThrows \u00a0 \u00a0 public List&lt;Object> claimReward(long rewardId) { \u00a0 \u00a0 \u00a0 \u00a0 Profile currentProfile = profileService.getCurrentProfile(); \u00a0 \u00a0 \u00a0 \u00a0 Reward reward = (Reward) rewardRepository.findById(rewardId).orElseThrow(() -> new RuntimeException(\"Reward not found\")); \u00a0 \u00a0 \u00a0 \u00a0 return claimReward(currentProfile, reward); \u00a0 \u00a0 }  \u00a0 \u00a0 @Override \u00a0 \u00a0 @SneakyThrows \u00a0 \u00a0 public List&lt;Object> claimReward(Profile profile, Reward reward) { \u00a0\u00a0 \u00a0 \u00a0 \u00a0 List&lt;?> rewards = reward.rewardFor(profile, contentGenerator); \u00a0 \u00a0 \u00a0 \u00a0 Map&lt;Class, GameContentService> mapContentServices = gameContentServices \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .stream() \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .collect(Collectors.toMap(GameContentService::getSupportedType, gameContentService -> gameContentService)); \u00a0 \u00a0 \u00a0 \u00a0 List&lt;Object> resultList = new ArrayList&lt;>();  \u00a0 \u00a0 \u00a0 \u00a0 \/* \u00a0\u00a0 \u00a0 \u00a0 \u00a0 * Save and apply reward for profile \u00a0\u00a0 \u00a0 \u00a0 \u00a0 *\/ \u00a0 \u00a0 \u00a0 \u00a0 processReward(rewards, mapContentServices, resultList); \u00a0 \u00a0 \u00a0 \u00a0 return resultList; \u00a0 \u00a0 } }  <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u043d\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 GameContentService.\u00a0<\/p>\n<pre><code>public interface GameContentService&lt;T> {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Save or update content to profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 T saveOrUpdate(T content);  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Get supported type of Service, for add reward to profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 Class&lt;T> getSupportedType();  }  <\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435.\u00a0<\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u041d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0430\u0433\u0440\u0430\u0434 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0434\u043b\u044f \u043d\u0438\u0445. \u041c\u044b \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434 (\u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e enum, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f). \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f open-close.\u00a0<\/p>\n<p>\u0427\u0442\u043e \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f? \u041a\u0430\u043a \u0443 \u0432\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043d\u0430 backend? <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/569500\/\"> https:\/\/habr.com\/ru\/articles\/569500\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 \u0441\u0443\u043d\u0434\u0443\u043a\u043e\u0432 \u0438 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0433\u0435\u0439\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0445 \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c. <a href=\"https:\/\/habr.com\/en\/post\/568220\/\" rel=\"noopener noreferrer nofollow\">\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0438\u0434\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0438 \u0441\u0443\u043d\u0434\u0443\u043a\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0430\u0433\u0440\u0430\u0434 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443<\/a>. \u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0430 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u0443 \u0438\u0433\u0440\u044b \u0438 \u0442\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0443\u043d\u0434\u0443\u043a\u0438 \u043f\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u043c\u0438 \u0438 \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0442\u044c \u0438 \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0442\u044c \u0438\u0445. \u00a0<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u0443\u0436\u0435 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f &#8212; \u043e\u0442 \u0437\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0433\u0435\u0439\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u043e\u043c, \u0434\u043e \u0432\u044b\u0434\u0430\u0447\u0438 \u044d\u0442\u043e\u0439 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0432 \u0438\u0433\u0440\u0435. \u0411\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0430, \u0438 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0438\u0434\u0431\u044d\u043a \u043e\u0442 \u0442\u0435\u0445 \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. <a href=\"https:\/\/github.com\/deft1991\/petproject\/tree\/master\/reward\" rel=\"noopener noreferrer nofollow\">\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0432 GitHub.<\/a><\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u201c\u041d\u0430\u0433\u0440\u0430\u0434\u0430\u201d \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u042d\u0442\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0418 \u043d\u0430\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u201c\u044d\u043d\u0442\u0438\u0442\u0438\u201d \u043a \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u0434 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.\u00a0<\/p>\n<pre><code>@Getter @Setter @Entity(name = \"reward\") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = \"type\", \u00a0 \u00a0 \u00a0 \u00a0 discriminatorType = DiscriminatorType.STRING) @DynamicUpdate @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = \"non-lazy\") public abstract class Reward implements GameItem {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 @Id     @GeneratedValue( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strategy = GenerationType.SEQUENCE, \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 generator = \"seq_reward\" \u00a0 \u00a0 ) \u00a0 \u00a0 @SequenceGenerator( \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 name = \"seq_reward\", \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 allocationSize = 1 \u00a0 \u00a0 ) \u00a0 \u00a0 @Column(name = \"id\", nullable = false, length = 36, unique = true) \u00a0 \u00a0 private Long id;  \u00a0 \u00a0 @Column(name = \"alias\", length = 255) \u00a0 \u00a0 private String alias; \/\/ short description  \u00a0 \u00a0 @Column(name = \"min_count\") \u00a0 \u00a0 private Integer minCount = 0; \/\/ it is diff card count for card reward, can be null for some rewards  \u00a0 \u00a0 @Column(name = \"max_count\") \u00a0 \u00a0 private Integer maxCount = 0; \/\/ it is diff card count for card reward, can be null for some rewards<\/code><\/pre>\n<figure class=\"float\"><figcaption><\/figcaption><\/figure>\n<p>   \u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 &#171;\u0437\u043e\u043b\u043e\u0442\u043e&#187; (&#171;GOLD&#187;).<\/p>\n<pre><code>@Entity @DiscriminatorValue(\"GOLD\") @NoArgsConstructor public class GoldReward extends Reward {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Generate gold currency for profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 @Override \u00a0 \u00a0 public List&lt;?> rewardFor(Profile profile, ContentGenerator contentGenerator) { \u00a0 \u00a0 \u00a0 \u00a0 int count = contentGenerator.generateCount(this.getMinCount(), this.getMaxCount(), this.getCount()); \u00a0 \u00a0 \u00a0 \u00a0 return List.of(new GoldCurrency(profile, count));  \u00a0 \u00a0 }  \u00a0 \u00a0 @Override \u00a0 \u00a0 public RewardType getType() { \u00a0 \u00a0 \u00a0 \u00a0 return RewardType.GOLD; \u00a0 \u00a0 }  <\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e GoldReward \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f RewardType.GOLD. \u042d\u0442\u043e enum \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430\u0433\u0440\u0430\u0434. \u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043d\u0435\u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u00a0<\/p>\n<pre><code>public interface GameItem { \u00a0 \u00a0 List&lt;?> rewardFor(Profile profile, ContentGenerator contentGenerator); }<\/code><\/pre>\n<figure class=\"float full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code>INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (1, '\u0417\u043e\u043b\u043e\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e', 'GOLD', 30, 60);  INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (2, '\u0417\u043e\u043b\u043e\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435', 'GOLD', 100, 200);  INSERT INTO reward (id, alias, type, min_count, max_count) VALUES (3, '\u0417\u043e\u043b\u043e\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435', 'GOLD', 500, 700);<\/code><\/pre>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Spring Data \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. <\/p>\n<pre><code>public interface RewardRepository&lt;T extends Reward> extends JpaRepository&lt;T, Long> { }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043b\u0438\u0448\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f ContentGenerator. \u042d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0433\u0440\u0430\u0434\u044b, \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0441 \u0448\u0430\u043d\u0441\u043e\u043c \u0432\u044b\u043f\u0430\u0434\u0435\u043d\u0438\u044f, \u0442\u043e ContentGenerator \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u043d\u0430\u0433\u0440\u0430\u0434\u0430 \u0438\u043b\u0438 \u043d\u0435\u0442, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0433\u0440\u0430\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.\u00a0<\/p>\n<pre><code>public interface ContentGenerator {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Should drop reward \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 boolean shouldDropReward(int chance);  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Generate random count in interval \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 int generateCount(Integer from, Integer to, Integer count); }<\/code><\/pre>\n<p>\u042f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0432\u0437\u044f\u0442\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u041c\u044b \u043f\u043e\u043a\u0430 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u043f\u043e \u0435\u0435 id.\u00a0<\/p>\n<pre><code>public class RewardServiceImpl implements RewardService {  \u00a0\u00a0 \u00a0@Override \u00a0 \u00a0 @SneakyThrows \u00a0 \u00a0 public List&lt;Object> claimReward(long rewardId) { \u00a0 \u00a0 \u00a0 \u00a0 Profile currentProfile = profileService.getCurrentProfile(); \u00a0 \u00a0 \u00a0 \u00a0 Reward reward = (Reward) rewardRepository.findById(rewardId).orElseThrow(() -> new RuntimeException(\"Reward not found\")); \u00a0 \u00a0 \u00a0 \u00a0 return claimReward(currentProfile, reward); \u00a0 \u00a0 }  \u00a0 \u00a0 @Override \u00a0 \u00a0 @SneakyThrows \u00a0 \u00a0 public List&lt;Object> claimReward(Profile profile, Reward reward) { \u00a0\u00a0 \u00a0 \u00a0 \u00a0 List&lt;?> rewards = reward.rewardFor(profile, contentGenerator); \u00a0 \u00a0 \u00a0 \u00a0 Map&lt;Class, GameContentService> mapContentServices = gameContentServices \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .stream() \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .collect(Collectors.toMap(GameContentService::getSupportedType, gameContentService -> gameContentService)); \u00a0 \u00a0 \u00a0 \u00a0 List&lt;Object> resultList = new ArrayList&lt;>();  \u00a0 \u00a0 \u00a0 \u00a0 \/* \u00a0\u00a0 \u00a0 \u00a0 \u00a0 * Save and apply reward for profile \u00a0\u00a0 \u00a0 \u00a0 \u00a0 *\/ \u00a0 \u00a0 \u00a0 \u00a0 processReward(rewards, mapContentServices, resultList); \u00a0 \u00a0 \u00a0 \u00a0 return resultList; \u00a0 \u00a0 } }  <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u043d\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 GameContentService.\u00a0<\/p>\n<pre><code>public interface GameContentService&lt;T> {  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Save or update content to profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 T saveOrUpdate(T content);  \u00a0 \u00a0 \/** \u00a0\u00a0 \u00a0 * Get supported type of Service, for add reward to profile \u00a0\u00a0 \u00a0 *\/ \u00a0 \u00a0 Class&lt;T> getSupportedType();  }  <\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u043d\u0430\u0433\u0440\u0430\u0434\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u043f\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435.\u00a0<\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b. \u041d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0430\u0433\u0440\u0430\u0434 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0434\u043b\u044f \u043d\u0438\u0445. \u041c\u044b \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434 (\u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e enum, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f). \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f open-close.\u00a0<\/p>\n<p>\u0427\u0442\u043e \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f? \u041a\u0430\u043a \u0443 \u0432\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043d\u0430 backend? <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/569500\/\"> https:\/\/habr.com\/ru\/articles\/569500\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-404206","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=404206"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404206\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}