|
@@ -0,0 +1,382 @@
|
|
|
|
|
+package com.train.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.train.common.Result;
|
|
|
|
|
+import com.train.entity.TrainPractitionerProfile;
|
|
|
|
|
+import com.train.entity.TrainPromotionRecord;
|
|
|
|
|
+import com.train.entity.TrainPromotionRule;
|
|
|
|
|
+import com.train.mapper.TrainCreditLedgerMapper;
|
|
|
|
|
+import com.train.mapper.TrainEvalRecordMapper;
|
|
|
|
|
+import com.train.mapper.TrainPractitionerProfileMapper;
|
|
|
|
|
+import com.train.mapper.TrainPromotionRecordMapper;
|
|
|
|
|
+import com.train.mapper.TrainPromotionRuleMapper;
|
|
|
|
|
+import com.train.mapper.TrainServiceOrderMapper;
|
|
|
|
|
+import com.train.service.BadgeService;
|
|
|
|
|
+import com.train.service.PractitionerService;
|
|
|
|
|
+import com.train.service.PromotionService;
|
|
|
|
|
+import com.train.service.RoleGuard;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.mockito.ArgumentCaptor;
|
|
|
|
|
+import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.anyLong;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * {@code train.promo.autoEval} 契约级单测(TDD-RED,S-train-36;TC-1036、TC-3005)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>需求锚点:docs/tdd/SRS.md「场景定义 §2 域六 P2-S2(Must)」——规则自动计算达标人员并生成评定记录,
|
|
|
|
|
+ * 未达标者可查缺口,执行幂等。TC-1036 Given 规则生效;When 执行评定;Then 自动识别达标人员并生成评定记录;
|
|
|
|
|
+ * 未达标可查缺口;执行幂等。TC-3005 要求规则幂等且触发口径一致。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>本轮只写测试、不改任何 src/main 实现。纯 Mockito(不启 Spring、不连 DB)。当前实现现状:
|
|
|
|
|
+ * 评定入口仅有 {@link PromotionServiceImpl#evaluateAndRecord(Long, Long)}(2 入参)与
|
|
|
|
|
+ * {@link PromotionServiceImpl#scanAndGrant(Boolean)}(1 入参),均无显式 replay/key/payload 幂等语义;
|
|
|
|
|
+ * {@link TrainPromotionRecord} 无 version 字段;规则不存在与非管理员触发均走 {@code Result.error}(code=500),
|
|
|
|
|
+ * 未区分 C404/C403。故本类边界用例预期为 RED(至少 1 条断言失败)。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>契约错误码({@code Result.code}):</p>
|
|
|
|
|
+ * <ul>
|
|
|
|
|
+ * <li>C4092 = 4092 同幂等键但载荷不一致(规则/指标阈值/操作人变化)</li>
|
|
|
|
|
+ * <li>C422 = 422 乐观锁/并发更新冲突(评定记录须有 version,并发写影响 0 行须报错)</li>
|
|
|
|
|
+ * <li>C404 = 404 晋升规则不存在</li>
|
|
|
|
|
+ * <li>C403 = 403 非管理员触发周期自动评定</li>
|
|
|
|
|
+ * </ul>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>说明:本仓后端模块为 train-backend(无字面量 train-impl 子模块),测试按既有契约单测惯例落在
|
|
|
|
|
+ * train-backend/src/test/java/com/train/service/impl/,与同池 S-train-17/22 等契约测试同目录;
|
|
|
|
|
+ * 当前契约层尚未落地(SRS 全键「⏳未契约化·契约先行待落地」),错误码直接以 Result.code 表达。</p>
|
|
|
|
|
+ */
|
|
|
|
|
+class TrainPromoAutoevalContractTest {
|
|
|
|
|
+
|
|
|
|
|
+ private static final int CODE_OK = 200;
|
|
|
|
|
+ private static final int CODE_SAME_KEY_DIFF_PAYLOAD = 4092;
|
|
|
|
|
+ private static final int CODE_VERSION_CONFLICT = 422;
|
|
|
|
|
+ private static final int CODE_NOT_FOUND = 404;
|
|
|
|
|
+ private static final int CODE_FORBIDDEN = 403;
|
|
|
|
|
+
|
|
|
|
|
+ private static final Long USER_ID = 4001L;
|
|
|
|
|
+ private static final Long RULE_ID = 6001L;
|
|
|
|
|
+ private static final Long OTHER_RULE_ID = 6002L;
|
|
|
|
|
+ private static final String IDEMPOTENCY_KEY = "PROMO-AUTOEVAL-4001-T2-2026Q4";
|
|
|
|
|
+
|
|
|
|
|
+ /** 期望的自动评定契约入口方法名关键字(GREEN 实现可任选其一) */
|
|
|
|
|
+ private static final String[] ENTRY_NAME_KEYS = {"eval", "auto", "assess", "promote"};
|
|
|
|
|
+
|
|
|
|
|
+ private PromotionServiceImpl service;
|
|
|
|
|
+ private TrainPromotionRuleMapper ruleMapper;
|
|
|
|
|
+ private TrainPromotionRecordMapper recordMapper;
|
|
|
|
|
+ private TrainPractitionerProfileMapper profileMapper;
|
|
|
|
|
+ private TrainServiceOrderMapper orderMapper;
|
|
|
|
|
+ private TrainCreditLedgerMapper ledgerMapper;
|
|
|
|
|
+ private TrainEvalRecordMapper evalMapper;
|
|
|
|
|
+ private PractitionerService practitionerService;
|
|
|
|
|
+ private BadgeService badgeService;
|
|
|
|
|
+ private RoleGuard roleGuard;
|
|
|
|
|
+ private PromotionService self;
|
|
|
|
|
+ private TrainPractitionerProfile profile;
|
|
|
|
|
+
|
|
|
|
|
+ @BeforeEach
|
|
|
|
|
+ void setUp() {
|
|
|
|
|
+ service = new PromotionServiceImpl();
|
|
|
|
|
+ ruleMapper = mock(TrainPromotionRuleMapper.class);
|
|
|
|
|
+ recordMapper = mock(TrainPromotionRecordMapper.class);
|
|
|
|
|
+ profileMapper = mock(TrainPractitionerProfileMapper.class);
|
|
|
|
|
+ orderMapper = mock(TrainServiceOrderMapper.class);
|
|
|
|
|
+ ledgerMapper = mock(TrainCreditLedgerMapper.class);
|
|
|
|
|
+ evalMapper = mock(TrainEvalRecordMapper.class);
|
|
|
|
|
+ practitionerService = mock(PractitionerService.class);
|
|
|
|
|
+ badgeService = mock(BadgeService.class);
|
|
|
|
|
+ roleGuard = mock(RoleGuard.class);
|
|
|
|
|
+ self = mock(PromotionService.class);
|
|
|
|
|
+
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainPromotionRuleMapper", ruleMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainPromotionRecordMapper", recordMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainPractitionerProfileMapper", profileMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainServiceOrderMapper", orderMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainCreditLedgerMapper", ledgerMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "trainEvalRecordMapper", evalMapper);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "practitionerService", practitionerService);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "badgeService", badgeService);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "roleGuard", roleGuard);
|
|
|
|
|
+ ReflectionTestUtils.setField(service, "self", self);
|
|
|
|
|
+
|
|
|
|
|
+ profile = profile("none");
|
|
|
|
|
+ when(profileMapper.selectOne(any())).thenReturn(profile);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static TrainPractitionerProfile profile(String authLevel) {
|
|
|
|
|
+ TrainPractitionerProfile p = new TrainPractitionerProfile();
|
|
|
|
|
+ p.setId(7001L);
|
|
|
|
|
+ p.setUserId(USER_ID);
|
|
|
|
|
+ p.setDisplayName("李*四");
|
|
|
|
|
+ p.setAuthLevel(authLevel);
|
|
|
|
|
+ p.setStatus("active");
|
|
|
|
|
+ p.setDeleted(0);
|
|
|
|
|
+ return p;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static TrainPromotionRule rule(Long id, String authLevel, String conditions) {
|
|
|
|
|
+ TrainPromotionRule r = new TrainPromotionRule();
|
|
|
|
|
+ r.setId(id);
|
|
|
|
|
+ r.setName(authLevel + " 自动晋升评定规则");
|
|
|
|
|
+ r.setAuthLevel(authLevel);
|
|
|
|
|
+ r.setConditions(conditions);
|
|
|
|
|
+ r.setEnabled(1);
|
|
|
|
|
+ r.setVersion(1);
|
|
|
|
|
+ r.setDeleted(0);
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String serveCountAtLeast(long value) {
|
|
|
|
|
+ return "[{\"metric\":\"serve_count\",\"op\":\">=\",\"value\":" + value + "}]";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String ratingAtLeast(long value) {
|
|
|
|
|
+ return "[{\"metric\":\"rating\",\"op\":\">=\",\"value\":" + value + "}]";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 对照基线(当前实现已覆盖,作为 RED 的对照) ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** TC-1036 主路径:达标人员自动识别并生成 promoted 评定记录。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void eligibleUserGeneratesPromotedRecord() {
|
|
|
|
|
+ when(ruleMapper.selectById(RULE_ID)).thenReturn(rule(RULE_ID, "T2", serveCountAtLeast(1)));
|
|
|
|
|
+ when(orderMapper.selectCount(any())).thenReturn(5L);
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.evaluateAndRecord(USER_ID, RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
|
|
+ assertEquals(Boolean.TRUE, r.getData().get("eligible"));
|
|
|
|
|
+ assertEquals(Boolean.TRUE, r.getData().get("promoted"));
|
|
|
|
|
+ // 注:Mockito 的 insert 不会回填自增主键,故不断言 recordId,改由下方 insert 捕获验证落记录。
|
|
|
|
|
+ ArgumentCaptor<TrainPromotionRecord> rec = ArgumentCaptor.forClass(TrainPromotionRecord.class);
|
|
|
|
|
+ verify(recordMapper).insert(rec.capture());
|
|
|
|
|
+ assertEquals("promoted", rec.getValue().getStatus());
|
|
|
|
|
+ assertEquals(Integer.valueOf(1), rec.getValue().getPass());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 未达标可查缺口:生成 evaluated 记录,data.unmet 携带缺口项。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void notEligibleUserGetsGapRecordWithUnmetDetails() {
|
|
|
|
|
+ when(ruleMapper.selectById(RULE_ID)).thenReturn(rule(RULE_ID, "T2", serveCountAtLeast(10)));
|
|
|
|
|
+ when(orderMapper.selectCount(any())).thenReturn(2L);
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.evaluateAndRecord(USER_ID, RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
|
|
+ assertEquals(Boolean.FALSE, r.getData().get("eligible"));
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ java.util.List<Map<String, Object>> unmet =
|
|
|
|
|
+ (java.util.List<Map<String, Object>>) r.getData().get("unmet");
|
|
|
|
|
+ assertFalse(unmet.isEmpty(), "未达标须返回可查缺口");
|
|
|
|
|
+ assertEquals("serve_count", unmet.get(0).get("metric"));
|
|
|
|
|
+ assertEquals(2L, ((Number) unmet.get(0).get("current")).longValue());
|
|
|
|
|
+ assertEquals(10L, ((Number) unmet.get(0).get("threshold")).longValue());
|
|
|
|
|
+ ArgumentCaptor<TrainPromotionRecord> rec = ArgumentCaptor.forClass(TrainPromotionRecord.class);
|
|
|
|
|
+ verify(recordMapper).insert(rec.capture());
|
|
|
|
|
+ assertEquals("evaluated", rec.getValue().getStatus());
|
|
|
|
|
+ assertEquals(Integer.valueOf(0), rec.getValue().getPass());
|
|
|
|
|
+ assertNotNull(rec.getValue().getUnmet(), "未达标须把缺口写入评定记录 unmet 字段");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 批量自动评定:扫描生效规则与人员,逐人调用评定并汇总 processed/granted。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void scanAndGrantProcessesEligibleProfiles() {
|
|
|
|
|
+ when(profileMapper.selectList(any())).thenReturn(
|
|
|
|
|
+ Collections.singletonList(profile("none")));
|
|
|
|
|
+ when(ruleMapper.selectList(any())).thenReturn(
|
|
|
|
|
+ Collections.singletonList(rule(RULE_ID, "T1", serveCountAtLeast(1))));
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
|
+ data.put("promoted", Boolean.TRUE);
|
|
|
|
|
+ when(self.evaluateAndRecord(anyLong(), anyLong())).thenReturn(Result.success(data));
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.scanAndGrant(Boolean.TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
|
|
+ assertEquals(1L, ((Number) r.getData().get("processed")).longValue());
|
|
|
|
|
+ assertEquals(1L, ((Number) r.getData().get("granted")).longValue());
|
|
|
|
|
+ verify(self).evaluateAndRecord(eq(USER_ID), eq(RULE_ID));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 当前实现的粗粒度幂等:目标等级已达成时不重复落评定记录。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void alreadyAtTargetLevelSkipsRecordInsert() {
|
|
|
|
|
+ profile.setAuthLevel("T2");
|
|
|
|
|
+ when(ruleMapper.selectById(RULE_ID)).thenReturn(rule(RULE_ID, "T2", serveCountAtLeast(1)));
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.evaluateAndRecord(USER_ID, RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
|
|
+ verify(recordMapper, never()).insert(any(TrainPromotionRecord.class));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 边界 0:幂等重放 replay=true ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 契约入口:自动评定须暴露可显式表达 replay/key/payload 的 Result 入口(至少 4 入参),
|
|
|
|
|
+ * 否则调用方无法声明「幂等重放」,也无法在同键异载荷时返回 C4092。
|
|
|
|
|
+ * 当前仅有 evaluateAndRecord(Long,Long) 2 入参与 scanAndGrant(Boolean) 1 入参,无法满足。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void replayEntryMustAcceptIdempotencyKeyAndPayload() {
|
|
|
|
|
+ Method entry = findAutoEvalEntry();
|
|
|
|
|
+ assertNotNull(entry,
|
|
|
|
|
+ "train.promo.autoEval 契约要求暴露带 replay/key/payload 的自动评定入口"
|
|
|
|
|
+ + "(Result 返回且至少 4 入参)以支持 replay=true;"
|
|
|
|
|
+ + "当前仅有 evaluateAndRecord(Long,Long) 与 scanAndGrant(Boolean),无法表达幂等重放");
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(hasBooleanParam(entry),
|
|
|
|
|
+ "自动评定入口须有 replay 布尔入参以表达幂等重放;当前入口不支持 replay=true");
|
|
|
|
|
+ assertTrue(hasParamOfTypes(entry, String.class, Map.class),
|
|
|
|
|
+ "自动评定入口须同时接收幂等键 key 与载荷 payload;当前入口不支持");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 边界 1:同键异载荷 C4092 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 同一幂等键携带不同载荷(另一规则/指标阈值)重放必须返回 C4092,禁止静默按 200 复用。
|
|
|
|
|
+ * 当前 API 无幂等键入参,两次评定分别按 200 处理。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void sameKeyDifferentPayloadReturnsC4092() {
|
|
|
|
|
+ when(ruleMapper.selectById(RULE_ID)).thenReturn(rule(RULE_ID, "T2", serveCountAtLeast(1)));
|
|
|
|
|
+ when(orderMapper.selectCount(any())).thenReturn(5L);
|
|
|
|
|
+ Result<Map<String, Object>> first = service.evaluateAndRecord(USER_ID, RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ // 同 key 异载荷:重置为未晋升,换一条规则(评分阈值)再评定
|
|
|
|
|
+ profile.setAuthLevel("none");
|
|
|
|
|
+ when(profileMapper.selectOne(any())).thenReturn(profile);
|
|
|
|
|
+ when(ruleMapper.selectById(OTHER_RULE_ID)).thenReturn(rule(OTHER_RULE_ID, "T2", ratingAtLeast(300)));
|
|
|
|
|
+ Result<Map<String, Object>> second = service.evaluateAndRecord(USER_ID, OTHER_RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, first.getCode());
|
|
|
|
|
+ assertEquals(CODE_SAME_KEY_DIFF_PAYLOAD, second.getCode(),
|
|
|
|
|
+ "同一幂等键 " + IDEMPOTENCY_KEY + " 携带不同评定载荷(规则/指标阈值)重放必须返回 C4092("
|
|
|
|
|
+ + CODE_SAME_KEY_DIFF_PAYLOAD + "),禁止静默按 200 复用既有评定结果");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 边界 2:乐观锁冲突 C422 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 评定记录实体须有 version 字段支撑并发评定的乐观锁 C422。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void promotionRecordEntityMustHaveVersionField() {
|
|
|
|
|
+ Field version = findField(TrainPromotionRecord.class, "version");
|
|
|
|
|
+ assertNotNull(version,
|
|
|
|
|
+ "train_promotion_record 实体必须声明 version 字段以支撑并发评定冲突 C422("
|
|
|
|
|
+ + CODE_VERSION_CONFLICT + ");当前实体无 version");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 边界 3:不存在 C404 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 晋升规则不存在 → C404,而非笼统的 500。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void nonExistentRuleReturns404() {
|
|
|
|
|
+ when(ruleMapper.selectById(RULE_ID)).thenReturn(null);
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.evaluateAndRecord(USER_ID, RULE_ID);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_NOT_FOUND, r.getCode(),
|
|
|
|
|
+ "晋升规则不存在时自动评定必须返回 C404(" + CODE_NOT_FOUND + "),不得降级为笼统的 500");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 边界 4:越权 C403 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 非管理员触发周期自动评定 → C403,而非笼统的 500。 */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void nonAdminAutoEvalReturns403() {
|
|
|
|
|
+ when(roleGuard.requireAdminRole(Boolean.FALSE)).thenReturn("需要管理员权限");
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.scanAndGrant(Boolean.FALSE);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_FORBIDDEN, r.getCode(),
|
|
|
|
|
+ "非管理员触发周期自动评定必须返回 C403(" + CODE_FORBIDDEN + "),不得降级为笼统的 500");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== helpers ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 在晋升服务接口与实现上查找自动评定契约入口(按方法名关键字 + Result 返回类型)。 */
|
|
|
|
|
+ private static Method findAutoEvalEntry() {
|
|
|
|
|
+ for (Class<?> type : new Class<?>[]{PromotionService.class, PromotionServiceImpl.class}) {
|
|
|
|
|
+ for (Method m : type.getMethods()) {
|
|
|
|
|
+ if (!Result.class.isAssignableFrom(m.getReturnType())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String name = m.getName().toLowerCase();
|
|
|
|
|
+ for (String key : ENTRY_NAME_KEYS) {
|
|
|
|
|
+ if (name.contains(key)) {
|
|
|
|
|
+ return m;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean hasBooleanParam(Method m) {
|
|
|
|
|
+ for (Class<?> t : m.getParameterTypes()) {
|
|
|
|
|
+ if (boolean.class.equals(t) || Boolean.class.equals(t)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean hasParamOfTypes(Method m, Class<?>... types) {
|
|
|
|
|
+ boolean allFound = true;
|
|
|
|
|
+ for (Class<?> t : types) {
|
|
|
|
|
+ boolean found = false;
|
|
|
|
|
+ for (Class<?> pt : m.getParameterTypes()) {
|
|
|
|
|
+ if (t.equals(pt) || (t.isPrimitive() && wrap(t).equals(pt))) {
|
|
|
|
|
+ found = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ allFound = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return allFound;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Class<?> wrap(Class<?> primitive) {
|
|
|
|
|
+ if (primitive == long.class) {
|
|
|
|
|
+ return Long.class;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (primitive == int.class) {
|
|
|
|
|
+ return Integer.class;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (primitive == boolean.class) {
|
|
|
|
|
+ return Boolean.class;
|
|
|
|
|
+ }
|
|
|
|
|
+ return primitive;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Field findField(Class<?> type, String name) {
|
|
|
|
|
+ Class<?> c = type;
|
|
|
|
|
+ while (c != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return c.getDeclaredField(name);
|
|
|
|
|
+ } catch (NoSuchFieldException ignored) {
|
|
|
|
|
+ c = c.getSuperclass();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|