DataShareController.java
10.4 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
196
197
198
199
200
201
202
203
package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.config.Constants;
import com.xkl.domain.*;
import com.xkl.model.ReportDetailModel;
import com.xkl.model.ReportModel;
import com.xkl.model.ReportTypeModel;
import com.xkl.model.ResultModel;
import com.xkl.repository.*;
import com.xkl.security.AntiXSS;
import com.xkl.service.IScoreService;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.xkl.config.ResultStatus.*;
/**
* Created by win7 on 2016/11/20.
*/
@RestController
@RequestMapping("/dataShare")
public class DataShareController {
@Autowired
private XklAmpReportRespository xklAmpReportRespository;
@Autowired
private XklAmpReportDetailRespository xklAmpReportDetailRespository;
@Autowired
private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;
@Autowired
private XklApiKeyRespository xklApiKeyRespository;
@Autowired
private XklCompanyRespository xklCompanyRespository;
@Autowired
private IScoreService scoreService;
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ApiOperation(value = "体检报告列表共享接口")
public ResponseEntity<ResultModel> getReportList(HttpServletRequest request,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if (!(boolean) request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
XklApiKeyEntity xklApiKey = xklApiKeyRespository.findOne((long)type);
List<XklAmpReportEntity> xklAmpReportResult = new ArrayList<>();
if(xklApiKey.getActiveStatus()!=1){
return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACTIVE), HttpStatus.OK);
}
long companyId = xklApiKey.getCompanyId();
XklCompanyEntity xklCompany = xklCompanyRespository.findOne(companyId);
if(xklCompany!= null){
int level = xklCompany.getLevel();//level:1-5
if(level == 1){//level-1对应所有的
xklAmpReportResult = xklAmpReportRespository.findByStatus(1);
}else{
int zeroLen = 8-(level-1)*2;
long companyCode = xklCompany.getCompanyCode();
long prefix = companyCode/((long)Math.pow(10,zeroLen));
List<XklCompanyEntity> childCompanyList = xklCompanyRespository.findByCompanyCodeStartingWith(String.valueOf(prefix));
if(childCompanyList!=null && childCompanyList.size()!=0){
List<Long> companyIdList = new ArrayList<>();
for(XklCompanyEntity company: childCompanyList){
companyIdList.add(company.getId());
}
xklAmpReportResult = xklAmpReportRespository.findByCompanyIdIn(companyIdList);
}
}
}else{
return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
}
return new ResponseEntity<>(ResultModel.ok(xklAmpReportResult), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@ApiOperation(value = "体检报告详情共享接口")
public ResponseEntity<ResultModel> getReportDetail(HttpServletRequest request, @RequestParam long report_id,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if (!(boolean) request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
XklAmpReportEntity report = xklAmpReportRespository.findOne(report_id);
XklApiKeyEntity xklApiKey = xklApiKeyRespository.findOne((long)type);
if(xklApiKey.getActiveStatus()!=1){
return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACTIVE), HttpStatus.OK);
}
long companyId = xklApiKey.getCompanyId();
XklCompanyEntity company = xklCompanyRespository.findOne(companyId);
if(company!=null){
int level = company.getLevel();
int zeroLen = 8-(level-1)*2;
if(level!=1){
long reportCompanyId = report.getCompanyId();
XklCompanyEntity reportCompany = xklCompanyRespository.findOne(reportCompanyId);
if(reportCompany!=null){
long reportParentCompanyCode = reportCompany.getCompanyCode() - reportCompany.getCompanyCode()%((long)Math.pow(10,zeroLen));
if(reportParentCompanyCode != company.getCompanyCode()){//该报告必须属于密钥所属的公司或区域
return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
}
}else{
return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
}
}
}else{
return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
}
Map<Integer,ReportTypeModel> reportTypeMap = new HashMap<>();
if (report != null) {
if (report.getScore() - 0 < Constants.SMALL_DOUBLE || report.getScore() == null) {//首次调用接口,score为0
scoreService.getScore(report_id);
}
List<XklAmpReportDetailEntity> reportDetailEntityList = xklAmpReportDetailRespository.findAllByReportId(report_id);
for (XklAmpReportDetailEntity detail : reportDetailEntityList) {
int itemId = detail.getItemId();
XklAmpReportMetaItemsEntity metaItems = Constants.itemMetaMap.get(itemId);
if (metaItems != null) {
int item_type = metaItems.getType();
boolean testFlag = false;//是否是测试项目,测试项目要存两份
if(Constants.testItemSet.contains(itemId)){
testFlag = true;
}
ReportDetailModel reportDetail = new ReportDetailModel();
reportDetail.setItemId(itemId);
reportDetail.setItemValue(detail.getItemValue());
reportDetail.setStatus(detail.getStatus());
reportDetail.setTitle(metaItems.getTitle());
if(Constants.itemIdSpSet.contains(itemId)){//特殊项
reportDetail.setNormalRange(Constants.itemRangeSpString);
}else if (report.getSex() == Constants.MALE) {//男
reportDetail.setNormalRange(metaItems.getStandardLowMale() + " - " + metaItems.getStandardHighMale());
}else {//女
reportDetail.setNormalRange(metaItems.getStandardLowFemale() + " - " + metaItems.getStandardHighFemale());
}
//正常的一份
if(!reportTypeMap.containsKey(item_type)){
ReportTypeModel reportTypeModel = new ReportTypeModel();
reportTypeModel.setType(item_type);
XklAmpReportHealthScoreEntity scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id, item_type);
if (scoreEntity != null) {
reportTypeModel.setTypeHealthScore(scoreEntity.getTypeHealthScore());
}
List<ReportDetailModel> reportDetailModelList = new ArrayList<>();
reportDetailModelList.add(reportDetail);
reportTypeModel.setReportDetailModelList(reportDetailModelList);
reportTypeMap.put(item_type,reportTypeModel);
}else{
ReportTypeModel reportTypeModel = reportTypeMap.get(item_type);
List<ReportDetailModel> reportDetailModelList = reportTypeModel.getReportDetailModelList();
reportDetailModelList.add(reportDetail);
reportTypeModel.setReportDetailModelList(reportDetailModelList);
reportTypeMap.put(item_type,reportTypeModel);
}
//测试项目另存一份
if(testFlag){
if(!reportTypeMap.containsKey(Constants.testItemType)){
//test项目一份
ReportTypeModel reportTypeModel_test = new ReportTypeModel();
reportTypeModel_test.setTypeHealthScore(0);//测试项目没有打分
reportTypeModel_test.setType(Constants.testItemType);
List<ReportDetailModel> reportDetailModelList_test = new ArrayList<>();
reportDetailModelList_test.add(reportDetail);
reportTypeModel_test.setReportDetailModelList(reportDetailModelList_test);
reportTypeMap.put(Constants.testItemType,reportTypeModel_test);
}else{
ReportTypeModel reportTypeModel_test = reportTypeMap.get(Constants.testItemType);
List<ReportDetailModel> reportDetailModelList_test = reportTypeModel_test.getReportDetailModelList();
reportDetailModelList_test.add(reportDetail);
reportTypeModel_test.setReportDetailModelList(reportDetailModelList_test);
reportTypeMap.put(Constants.testItemType,reportTypeModel_test);
}
}
}
}
}
ReportModel reportModel = new ReportModel(report, reportTypeMap);
return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
}
}