|
|
@@ -1,8 +1,10 @@
|
|
|
package com.etotem.cfc.controller.mind;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.FamilyFortune;
|
|
|
import com.etotem.cfc.entity.FamilyFortuneReport;
|
|
|
+import com.etotem.cfc.mapper.FamilyFortuneReportMapper;
|
|
|
import com.etotem.cfc.service.FortuneService;
|
|
|
import com.etotem.cfc.service.MembershipService;
|
|
|
import com.etotem.cfc.service.PdfReportService;
|
|
|
@@ -13,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@@ -28,6 +32,9 @@ public class MindFortuneController {
|
|
|
|
|
|
@Resource
|
|
|
private MembershipService membershipService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FamilyFortuneReportMapper familyFortuneReportMapper;
|
|
|
|
|
|
/**
|
|
|
* 获取今日家庭运势
|
|
|
@@ -147,4 +154,90 @@ public class MindFortuneController {
|
|
|
result.put("weeklyTip", fortune.getWeeklyTip());
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取本周运势数据(最近7天)
|
|
|
+ */
|
|
|
+ @PostMapping("/fortune/week")
|
|
|
+ public Result<List<Map<String, Object>>> getWeekFortune(@RequestAttribute("userId") Long userId) {
|
|
|
+ if (userId == null) return Result.error("请先登录");
|
|
|
+ Long familyId = membershipService.getOrCreateUserFamilyId(userId);
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ List<LocalDate> weekDates = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 7; i++) {
|
|
|
+ weekDates.add(today.minusDays(i));
|
|
|
+ }
|
|
|
+ List<FamilyFortune> fortunes = fortuneService.getFamilyFortuneBatch(familyId, weekDates);
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (FamilyFortune f : fortunes) {
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("date", f.getFortuneDate().toString());
|
|
|
+ item.put("fortuneLevel", f.getFortuneLevel());
|
|
|
+ item.put("fortuneLevelText", f.getFortuneLevelText());
|
|
|
+ item.put("fortuneScore", f.getMoodScore());
|
|
|
+ item.put("dominantElement", f.getDominantElement());
|
|
|
+ item.put("luckyDirection", f.getLuckyDirection() != null ? f.getLuckyDirection().replace("方", "") : "东");
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ result.sort((a, b) -> a.get("date").toString().compareTo(b.get("date").toString()));
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取本月运势数据
|
|
|
+ */
|
|
|
+ @PostMapping("/fortune/month")
|
|
|
+ public Result<List<Map<String, Object>>> getMonthFortune(@RequestAttribute("userId") Long userId) {
|
|
|
+ if (userId == null) return Result.error("请先登录");
|
|
|
+ Long familyId = membershipService.getOrCreateUserFamilyId(userId);
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
+ int daysInMonth = today.lengthOfMonth();
|
|
|
+ List<LocalDate> monthDates = new ArrayList<>();
|
|
|
+ for (int i = 0; i < daysInMonth; i++) {
|
|
|
+ monthDates.add(firstDayOfMonth.plusDays(i));
|
|
|
+ }
|
|
|
+ List<FamilyFortune> fortunes = fortuneService.getFamilyFortuneBatch(familyId, monthDates);
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (FamilyFortune f : fortunes) {
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("fortuneDate", f.getFortuneDate().toString());
|
|
|
+ item.put("fortuneLevel", f.getFortuneLevel());
|
|
|
+ item.put("fortuneLevelText", f.getFortuneLevelText());
|
|
|
+ item.put("luckyDirection", f.getLuckyDirection() != null ? f.getLuckyDirection().replace("方", "") : "东");
|
|
|
+ item.put("dominantElement", f.getDominantElement());
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ result.sort((a, b) -> a.get("fortuneDate").toString().compareTo(b.get("fortuneDate").toString()));
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取历史周报列表
|
|
|
+ */
|
|
|
+ @PostMapping("/fortune/reports")
|
|
|
+ public Result<List<Map<String, Object>>> getFortuneReports(@RequestAttribute("userId") Long userId) {
|
|
|
+ if (userId == null) return Result.error("请先登录");
|
|
|
+ Long familyId = membershipService.getUserFamilyId(userId);
|
|
|
+ if (familyId == null) return Result.noFamily("请先创建或加入家庭");
|
|
|
+ // 查询该家庭的历史周报
|
|
|
+ List<FamilyFortuneReport> reports = familyFortuneReportMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<FamilyFortuneReport>()
|
|
|
+ .eq(FamilyFortuneReport::getFamilyId, familyId.intValue())
|
|
|
+ .orderByAsc(FamilyFortuneReport::getCreatedAt));
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int weekNumber = 1;
|
|
|
+ for (FamilyFortuneReport r : reports) {
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("weekNumber", weekNumber++);
|
|
|
+ String dateStr = r.getCreatedAt() != null ? sdf.format(r.getCreatedAt()) : "";
|
|
|
+ item.put("startDate", dateStr);
|
|
|
+ item.put("endDate", dateStr);
|
|
|
+ item.put("content", r.getElement() != null ? "主导五行:" + r.getElement() + ",吉位:" + r.getLuckyDirection() : "");
|
|
|
+ item.put("pdfUrl", r.getPdfPath() != null ? "/storage/reports/" + r.getPdfPath() : "");
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
}
|