ReportController.java
9.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.Sign;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.*;
import com.xkl.model.ReportDetailModel;
import com.xkl.model.ReportItemGraphModel;
import com.xkl.model.ReportModel;
import com.xkl.model.ResultModel;
import com.xkl.repository.XklAmpReportDetailRespository;
import com.xkl.repository.XklAmpReportHealthScoreRespository;
import com.xkl.repository.XklAmpReportRespository;
import com.xkl.service.IScoreService;
import com.xkl.tools.UtilTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.function.DoubleToIntFunction;
/**
* Created by win7 on 2016/11/20.
*/
@RestController
@RequestMapping("/report")
public class ReportController {
@Autowired
private XklAmpReportRespository xklAmpReportRespository;
@Autowired
private XklAmpReportDetailRespository xklAmpReportDetailRespository;
@Autowired
private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;
@Autowired
private IScoreService scoreService;
@RequestMapping(value="/list",method = RequestMethod.GET)
@Authorization
@Sign
@ApiOperation(value = "体检报告列表查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportList(HttpServletRequest request, @CurrentUser User user,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
long member_id=user.getMemberId();
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberId(member_id);
return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK);
}
@RequestMapping(value="/detail",method = RequestMethod.GET)
@Authorization
@Sign
@ApiOperation(value = "体检报告详情查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportDetail(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
XklAmpReportEntity report=xklAmpReportRespository.findOne(report_id);
List<ReportDetailModel> reportDetailModelList = new ArrayList<>();
if(report != null ){
if(report.getScore()==0){//首次调用接口,score为0
//TODO:可以在上传时直接打分?
scoreService.getScore(report_id);
}
List<XklAmpReportDetailEntity> reportDetailEntityList=xklAmpReportDetailRespository.findAllByReportId(report_id);
for(XklAmpReportDetailEntity detail:reportDetailEntityList){
int itemId=detail.getItemId();
ReportDetailModel reportDetail = new ReportDetailModel();
reportDetail.setItemId(itemId);
reportDetail.setItemValue(detail.getItemValue());
reportDetail.setStatus(detail.getStatus());
XklAmpReportMetaItemsEntity metaItems=Constants.itemMetaMap.get(itemId);
if(metaItems!=null){
reportDetail.setTitle(metaItems.getTitle());
reportDetail.setNormal(metaItems.getStandardLowMale()+" - "+metaItems.getStandardHighMale());
reportDetail.setNormalNv(metaItems.getStandardLowFemale()+ " - "+metaItems.getStandardHighFemale());
reportDetail.setType(metaItems.getType());
}
XklAmpReportHealthScoreEntity scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id,metaItems.getType());
if(scoreEntity!=null)
reportDetail.setTypeHealthScore(scoreEntity.getTypeHealthScore());
reportDetailModelList.add(reportDetail);
}
}
ReportModel reportModel = new ReportModel(report,reportDetailModelList);
return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
}
/*@RequestMapping(value="/score",method = RequestMethod.GET)
@Authorization
@Sign
@ApiOperation(value = "健康评分接口(测试service用,后续可以注释掉)")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportScore(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
//单独测试需要删除xkl_amp_report_health_scroe表中数据
scoreService.getScore(report_id);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}*/
@RequestMapping(value="/itemInfo",method = RequestMethod.GET)
@Authorization
@Sign
@ApiOperation(value = "指标解释查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportItemInfo(HttpServletRequest request, @CurrentUser User user,@RequestParam int itemId,@RequestParam int status,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
XklAmpReportMetaItemsEntity metaItems = Constants.itemMetaMap.get(itemId);
String result="";
if(metaItems!= null){
//0, normal,1, lower,2, higher
if(status == 0){
result = metaItems.getExplainNormal();
}else if(status == 1){
result = metaItems.getExplainLow();
}else if(status == 2){
result = metaItems.getExplainHigh();
}else{
result = "没有此status相关信息";
}
}else{
result = "没有此itemId相关信息";
}
return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK);
}
@RequestMapping(value="/itemGraph",method = RequestMethod.GET)
@Authorization
@Sign
@ApiOperation(value = "指标曲线查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportItemGraph(HttpServletRequest request, @CurrentUser User user,@RequestParam int itemId,@RequestParam String stime,@RequestParam String etime,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
long member_id=user.getMemberId();
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberId(member_id);
List<ReportItemGraphModel> reportItemGraphModelList =new ArrayList<>();
if(xklAmpReportEntity!=null && xklAmpReportEntity.size()>0){
for(XklAmpReportEntity report:xklAmpReportEntity){
long reportTime= report.getUptime().getTime();
long stimeLong= UtilTools.getLongTime(stime);
long etimeLong= UtilTools.getLongTime(etime);
long reportId= report.getId();
if(reportTime>=stimeLong&&reportTime<=etimeLong){//在时间范围内
XklAmpReportDetailEntity reportDetail = xklAmpReportDetailRespository.findByReportIdAndItemId(reportId,itemId);
if(reportDetail!=null){
ReportItemGraphModel reportItemGraphModel= new ReportItemGraphModel(reportTime,reportDetail.getItemValue());
reportItemGraphModelList.add(reportItemGraphModel);
}
}
}
}
return new ResponseEntity<>(ResultModel.ok(reportItemGraphModelList), HttpStatus.OK);
}
}