|
@@ -0,0 +1,188 @@
|
|
|
+package com.rf.psychological.rest;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.rf.psychological.base.rest.BaseController;
|
|
|
+import com.rf.psychological.plan.dao.model.HisTestPlanEntry;
|
|
|
+import com.rf.psychological.plan.dao.model.TestPlanContendEntity;
|
|
|
+import com.rf.psychological.plan.dao.model.TestPlanEntity;
|
|
|
+import com.rf.psychological.plan.service.HisTestPlanService;
|
|
|
+import com.rf.psychological.plan.service.TestPlanContendService;
|
|
|
+import com.rf.psychological.plan.service.TestPlanService;
|
|
|
+import com.rf.psychological.plan.service.TestPlanUserService;
|
|
|
+import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
|
+import com.rf.psychological.scale.service.ScaleMarksService;
|
|
|
+import com.rf.psychological.scale.service.UserRecordService;
|
|
|
+import com.rf.psychological.security.SafetyProcess;
|
|
|
+import com.rf.psychological.structure.dao.model.StructureEntity;
|
|
|
+import com.rf.psychological.structure.service.StructureService;
|
|
|
+import com.rf.psychological.user.service.UserService;
|
|
|
+import com.rf.psychological.utils.Constant;
|
|
|
+import com.rf.psychological.utils.Result;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.repository.query.Param;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:报告分析接口
|
|
|
+ * @Author: mimang
|
|
|
+ * @Date: 2024/1/25
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/report/analysis")
|
|
|
+@Api(tags = "报告分析")
|
|
|
+public class ReportAnalysisController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HisTestPlanService hisTestPlanService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TestPlanContendService planContendService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ScaleMarksService scaleMarksService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserRecordService userRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TestPlanUserService planUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StructureService structureService;
|
|
|
+
|
|
|
+ @GetMapping("/getReportResult")
|
|
|
+ @ApiOperation(value = "获取到该计划下量表及量表评分规则和各规则下人数")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result getReportResult(@Param(value = "planId") String planId,@Param(value = "structureNo") String structureNo){
|
|
|
+ try {
|
|
|
+ List<JSONObject> subjectList = new ArrayList<>();
|
|
|
+ //获取到计划详情
|
|
|
+ HisTestPlanEntry plan = hisTestPlanService.findById(planId);
|
|
|
+ if (plan== null){
|
|
|
+ return fail("计划不存在请确认,请联系管理员");
|
|
|
+ }
|
|
|
+ if (Constant.TEST_PLAN_STATUS_UNSTART == plan.getStatus() || Constant.TEST_PLAN_STATUS_RUNNING== plan.getStatus() ){
|
|
|
+ return fail("计划未结束,暂不支持统计分析");
|
|
|
+ }
|
|
|
+ //获取到计划下关联量表
|
|
|
+ List<TestPlanContendEntity> planContendEntities = planContendService.findAllByTestPlanId(planId);
|
|
|
+ if (CollectionUtils.isEmpty(planContendEntities)){
|
|
|
+ return fail("该计划下无测试内容,请联系管理员");
|
|
|
+ }
|
|
|
+ planContendEntities.forEach(item ->{
|
|
|
+ //循环获取到量表
|
|
|
+ JSONObject subject = new JSONObject();
|
|
|
+ subject.put("name",item.getName());
|
|
|
+ //获取到该量表规则
|
|
|
+ List<ScaleMarksEntity> marksEntities = scaleMarksService.getScaleMarksByFlag(item.getFlag());
|
|
|
+ if (CollectionUtils.isEmpty(marksEntities)){
|
|
|
+ subject.put("value",null);
|
|
|
+ }
|
|
|
+ List<JSONObject> markList = new ArrayList<>();
|
|
|
+ marksEntities.forEach(mark->{
|
|
|
+ JSONObject markJson = new JSONObject();
|
|
|
+ markJson.put("name",mark.getSymptom());
|
|
|
+ //TODO 获取到结果中该结论数
|
|
|
+ int value = userRecordService.countByInstitutionNoAndFlagAndConclusion(plan.getInstitutionNo(), mark.getFlag(), mark.getSymptom(),structureNo==null?"%":structureNo+"%");
|
|
|
+ markJson.put("value",value);
|
|
|
+ markList.add(markJson);
|
|
|
+ });
|
|
|
+ subject.put("value",markList);
|
|
|
+ subjectList.add(subject);
|
|
|
+ });
|
|
|
+
|
|
|
+ return success(subjectList);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getUserNum")
|
|
|
+ @ApiOperation(value = "获取到组织下总人数和参与计划测试人数数")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result getUserNum(@Param(value = "planId") String planId,@Param(value = "structureNo") String structureNo){
|
|
|
+ try {
|
|
|
+ HisTestPlanEntry plan = hisTestPlanService.findById(planId);
|
|
|
+ if (plan== null){
|
|
|
+ return fail("计划不存在请确认,请联系管理员");
|
|
|
+ }
|
|
|
+ //首先获取到计划下参与总人数
|
|
|
+ if (StringUtils.isEmpty(structureNo)){
|
|
|
+ structureNo = "%";
|
|
|
+ }
|
|
|
+ int planUsers = planUserService.countByTestPlanIdAndStructureNo(planId,structureNo,plan.getInstitutionNo());
|
|
|
+ int structureUsers = userService.countByStructureNo(plan.getInstitutionNo(),structureNo);
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("planUsers",planUsers);
|
|
|
+ map.put("structureUsers",structureUsers);
|
|
|
+ return success(map);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getVisResult")
|
|
|
+ @ApiOperation(value = "获取到同级数据")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result getVisResult(@Param(value = "planId") String planId,@Param(value = "structureNo") String structureNo,@Param(value = "flag") String flag){
|
|
|
+ try {
|
|
|
+ List<JSONObject> orgList = new ArrayList<>();
|
|
|
+ HisTestPlanEntry plan = hisTestPlanService.findById(planId);
|
|
|
+ if (plan== null){
|
|
|
+ return fail("计划不存在请确认,请联系管理员");
|
|
|
+ }
|
|
|
+ //首先获取到计划下参与总人数
|
|
|
+ if (StringUtils.isEmpty(structureNo)){
|
|
|
+ return fail("组织编号不能为空");
|
|
|
+ }
|
|
|
+ //获取到子节点
|
|
|
+ List<StructureEntity> child = structureService.getChildByParent(structureNo,plan.getInstitutionNo());
|
|
|
+ if (CollectionUtils.isEmpty(child)){
|
|
|
+ return fail("不存在子节点,请重新选择");
|
|
|
+ }
|
|
|
+ child.forEach(item->{
|
|
|
+ JSONObject org = new JSONObject();
|
|
|
+ org.put("name",item.getStructureName());
|
|
|
+ //获取到该量表规则
|
|
|
+ List<ScaleMarksEntity> marksEntities = scaleMarksService.getScaleMarksByFlag(flag);
|
|
|
+ if (CollectionUtils.isEmpty(marksEntities)){
|
|
|
+ org.put("value",null);
|
|
|
+ }
|
|
|
+ List<JSONObject> markList = new ArrayList<>();
|
|
|
+ marksEntities.forEach(mark->{
|
|
|
+ JSONObject markJson = new JSONObject();
|
|
|
+ markJson.put("name",mark.getSymptom());
|
|
|
+ //TODO 获取到结果中该结论数
|
|
|
+ int value = userRecordService.countByInstitutionNoAndFlagAndConclusion(plan.getInstitutionNo(), mark.getFlag(), mark.getSymptom(),item.getStructureNo()+"%");
|
|
|
+ markJson.put("value",value);
|
|
|
+ markList.add(markJson);
|
|
|
+ });
|
|
|
+ org.put("value",markList);
|
|
|
+ orgList.add(org);
|
|
|
+ });
|
|
|
+ return success(orgList);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|