|
@@ -0,0 +1,123 @@
|
|
|
|
|
+package com.mangoo.rating.recommend.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.mangoo.rating.recommend.AjaxResult;
|
|
|
|
|
+import com.mangoo.rating.recommend.manager.ActiveBatchManager;
|
|
|
|
|
+import com.mangoo.rating.recommend.manager.CardPopManager;
|
|
|
|
|
+import com.mangoo.rating.recommend.manager.CardValueHistoryManager;
|
|
|
|
|
+import com.mangoo.rating.recommend.manager.RatingRecommendRuleManager;
|
|
|
|
|
+import com.mangoo.rating.recommend.po.CardPopPO;
|
|
|
|
|
+import com.mangoo.rating.recommend.po.CardValueHistoryPO;
|
|
|
|
|
+import com.mangoo.rating.recommend.po.RatingRecommendRulePO;
|
|
|
|
|
+import com.mangoo.rating.recommend.response.recommend.CardDetailVO;
|
|
|
|
|
+import com.mangoo.rating.recommend.response.recommend.CardPopVO;
|
|
|
|
|
+import com.mangoo.rating.recommend.response.recommend.CardValueVO;
|
|
|
|
|
+import com.mangoo.rating.recommend.response.recommend.TrendPointVO;
|
|
|
|
|
+import com.mangoo.rating.recommend.service.CardDetailService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 卡片详情/趋势查询服务实现
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author gengjintao
|
|
|
|
|
+ * @date 2026/06/25
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class CardDetailServiceImpl implements CardDetailService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RatingRecommendRuleManager ratingRecommendRuleManager;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private CardPopManager cardPopManager;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private CardValueHistoryManager cardValueHistoryManager;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ActiveBatchManager activeBatchManager;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public AjaxResult getDetail(String cardId, String period) {
|
|
|
|
|
+ if (cardId == null || cardId.trim().isEmpty()) {
|
|
|
|
|
+ return AjaxResult.error("cardId 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String activeBatchNo = activeBatchManager.selectActiveBatchNo();
|
|
|
|
|
+ if (activeBatchNo == null) {
|
|
|
|
|
+ return AjaxResult.error("暂无生效规则数据");
|
|
|
|
|
+ }
|
|
|
|
|
+ RatingRecommendRulePO rule = ratingRecommendRuleManager.selectByCardId(cardId, activeBatchNo);
|
|
|
|
|
+ if (rule == null) {
|
|
|
|
|
+ return AjaxResult.error("卡片不存在或已失效");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CardDetailVO vo = new CardDetailVO();
|
|
|
|
|
+ vo.setCardId(rule.getCardId());
|
|
|
|
|
+ vo.setCardNo(rule.getCardNo());
|
|
|
|
|
+ vo.setName(rule.getPlayer());
|
|
|
|
|
+ vo.setYear(rule.getYear());
|
|
|
|
|
+ vo.setSeries(rule.getSeries());
|
|
|
|
|
+ vo.setCardSet(rule.getCardSet());
|
|
|
|
|
+ vo.setImageUrl(null); // 本期规则表未存卡图,留 null
|
|
|
|
|
+
|
|
|
|
|
+ // 行情
|
|
|
|
|
+ CardValueVO value = new CardValueVO();
|
|
|
|
|
+ value.setCurrent(rule.getCurrentValue());
|
|
|
|
|
+ value.setChangePct(rule.getValueChangePct());
|
|
|
|
|
+ value.setMin(rule.getValueMin());
|
|
|
|
|
+ value.setMax(rule.getValueMax());
|
|
|
|
|
+ vo.setValue(value);
|
|
|
|
|
+
|
|
|
|
|
+ // POP 明细
|
|
|
|
|
+ List<CardPopPO> pops = cardPopManager.selectByCardId(cardId, activeBatchNo);
|
|
|
|
|
+ List<CardPopVO> popVOs = new ArrayList<>();
|
|
|
|
|
+ for (CardPopPO p : pops) {
|
|
|
|
|
+ CardPopVO pv = new CardPopVO();
|
|
|
|
|
+ pv.setAgency(p.getAgency());
|
|
|
|
|
+ pv.setAll(p.getGradeAll());
|
|
|
|
|
+ pv.setG10(p.getGrade10());
|
|
|
|
|
+ pv.setG9(p.getGrade9());
|
|
|
|
|
+ pv.setG8(p.getGrade8());
|
|
|
|
|
+ pv.setG7(p.getGrade7());
|
|
|
|
|
+ popVOs.add(pv);
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setPops(popVOs);
|
|
|
|
|
+
|
|
|
|
|
+ // 价格趋势(period → 起始日期)
|
|
|
|
|
+ LocalDate startDate = resolveStartDate(period);
|
|
|
|
|
+ List<CardValueHistoryPO> history = cardValueHistoryManager.selectTrend(cardId, startDate);
|
|
|
|
|
+ List<TrendPointVO> trend = new ArrayList<>();
|
|
|
|
|
+ for (CardValueHistoryPO h : history) {
|
|
|
|
|
+ TrendPointVO tp = new TrendPointVO();
|
|
|
|
|
+ tp.setDate(h.getRecordDate());
|
|
|
|
|
+ tp.setPrice(h.getPrice());
|
|
|
|
|
+ trend.add(tp);
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setTrend(trend);
|
|
|
|
|
+
|
|
|
|
|
+ return AjaxResult.success("查询成功", vo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析时间窗为起始日期;all 或非法值返回 null(查全部),默认 30d
|
|
|
|
|
+ */
|
|
|
|
|
+ private LocalDate resolveStartDate(String period) {
|
|
|
|
|
+ if (period == null) {
|
|
|
|
|
+ return LocalDate.now().minusDays(30);
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (period.trim()) {
|
|
|
|
|
+ case "7d":
|
|
|
|
|
+ return LocalDate.now().minusDays(7);
|
|
|
|
|
+ case "90d":
|
|
|
|
|
+ return LocalDate.now().minusDays(90);
|
|
|
|
|
+ case "all":
|
|
|
|
|
+ return null;
|
|
|
|
|
+ case "30d":
|
|
|
|
|
+ default:
|
|
|
|
|
+ return LocalDate.now().minusDays(30);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|