|
|
@@ -0,0 +1,118 @@
|
|
|
+package com.etotem.cfc.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.FamilyMember;
|
|
|
+import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
+import com.etotem.cfc.service.IndicatorCorrelationService;
|
|
|
+import com.etotem.cfc.service.IndicatorTrendService;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/indicator")
|
|
|
+public class IndicatorController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IndicatorTrendService indicatorTrendService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IndicatorCorrelationService indicatorCorrelationService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FamilyMemberMapper familyMemberMapper;
|
|
|
+
|
|
|
+ /** 校验 subjectId 属于当前用户家庭(familyId 由 JwtInterceptor 注入,必存在) */
|
|
|
+ private Result<Void> checkSubjectBelongs(Long subjectId, Long familyId) {
|
|
|
+ if (subjectId == null) {
|
|
|
+ return Result.error("subjectId不能为空");
|
|
|
+ }
|
|
|
+ FamilyMember member = familyMemberMapper.selectOne(new LambdaQueryWrapper<FamilyMember>()
|
|
|
+ .eq(FamilyMember::getId, subjectId)
|
|
|
+ .eq(FamilyMember::getFamilyId, familyId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (member == null) {
|
|
|
+ return Result.error("成员不属于当前家庭");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 指标曲线(设计 6.1) */
|
|
|
+ @PostMapping("/trend")
|
|
|
+ public Result<?> trend(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("familyId") Long familyId) {
|
|
|
+ Long subjectId = com.etotem.cfc.util.ParamUtils.getLong(params.get("subjectId"));
|
|
|
+ Result<Void> check = checkSubjectBelongs(subjectId, familyId);
|
|
|
+ if (check != null) {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Object> rawIds = (List<Object>) params.get("definitionIds");
|
|
|
+ List<Long> definitionIds = new ArrayList<>();
|
|
|
+ if (rawIds != null) {
|
|
|
+ for (Object o : rawIds) {
|
|
|
+ if (o instanceof Number) {
|
|
|
+ definitionIds.add(((Number) o).longValue());
|
|
|
+ } else if (o != null) {
|
|
|
+ definitionIds.add(Long.valueOf(o.toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success(indicatorTrendService.trend(subjectId, definitionIds, familyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 变化幅度排名(设计 6.2) */
|
|
|
+ @PostMapping("/change-ranking")
|
|
|
+ public Result<?> changeRanking(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("familyId") Long familyId) {
|
|
|
+ Long subjectId = com.etotem.cfc.util.ParamUtils.getLong(params.get("subjectId"));
|
|
|
+ Result<Void> check = checkSubjectBelongs(subjectId, familyId);
|
|
|
+ if (check != null) {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ String reportType = params.get("reportType") != null ? params.get("reportType").toString() : null;
|
|
|
+ String category = params.get("category") != null ? params.get("category").toString() : null;
|
|
|
+ String scope = params.get("scope") != null ? params.get("scope").toString() : "adjacent";
|
|
|
+ String orderBy = params.get("orderBy") != null ? params.get("orderBy").toString() : "magnitude";
|
|
|
+ Integer limit = params.get("limit") != null
|
|
|
+ ? Integer.valueOf(params.get("limit").toString()) : 50;
|
|
|
+ return Result.success(indicatorTrendService.changeRanking(
|
|
|
+ subjectId, reportType, category, scope, orderBy, limit, familyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 指标速查(设计 6.3) */
|
|
|
+ @PostMapping("/quick-lookup")
|
|
|
+ public Result<?> quickLookup(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("familyId") Long familyId) {
|
|
|
+ Long subjectId = com.etotem.cfc.util.ParamUtils.getLong(params.get("subjectId"));
|
|
|
+ Result<Void> check = checkSubjectBelongs(subjectId, familyId);
|
|
|
+ if (check != null) {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ String category = params.get("category") != null ? params.get("category").toString() : null;
|
|
|
+ Integer page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) : 1;
|
|
|
+ Integer pageSize = params.get("pageSize") != null ? Integer.valueOf(params.get("pageSize").toString()) : 30;
|
|
|
+ return Result.success(indicatorTrendService.quickLookup(subjectId, category, page, pageSize, familyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 指标关联查询(设计 6.4) */
|
|
|
+ @PostMapping("/correlation/list")
|
|
|
+ public Result<?> correlationList(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("familyId") Long familyId) {
|
|
|
+ Long subjectId = com.etotem.cfc.util.ParamUtils.getLong(params.get("subjectId"));
|
|
|
+ Long definitionId = com.etotem.cfc.util.ParamUtils.getLong(params.get("definitionId"));
|
|
|
+ Result<Void> check = checkSubjectBelongs(subjectId, familyId);
|
|
|
+ if (check != null) {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ return Result.success(indicatorCorrelationService.listRelations(subjectId, definitionId));
|
|
|
+ }
|
|
|
+}
|