|
|
1
|
+package com.xkl.controller;
|
|
|
2
|
+
|
|
|
3
|
+import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
4
|
+import com.xkl.authorization.annotation.LogAnnotation;
|
|
|
5
|
+import com.xkl.config.Constants;
|
|
|
6
|
+import com.xkl.domain.*;
|
|
|
7
|
+import com.xkl.model.ReportDetailModel;
|
|
|
8
|
+import com.xkl.model.ReportModel;
|
|
|
9
|
+import com.xkl.model.ResultModel;
|
|
|
10
|
+import com.xkl.repository.*;
|
|
|
11
|
+import com.xkl.service.IScoreService;
|
|
|
12
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13
|
+import org.springframework.http.HttpStatus;
|
|
|
14
|
+import org.springframework.http.ResponseEntity;
|
|
|
15
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
18
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
19
|
+
|
|
|
20
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
21
|
+import java.util.ArrayList;
|
|
|
22
|
+import java.util.List;
|
|
|
23
|
+
|
|
|
24
|
+import static com.xkl.config.ResultStatus.*;
|
|
|
25
|
+
|
|
|
26
|
+/**
|
|
|
27
|
+ * Created by win7 on 2016/11/20.
|
|
|
28
|
+ */
|
|
|
29
|
+@RestController
|
|
|
30
|
+@RequestMapping("/dataShare")
|
|
|
31
|
+public class DataShareController {
|
|
|
32
|
+ @Autowired
|
|
|
33
|
+ private XklAmpReportRespository xklAmpReportRespository;
|
|
|
34
|
+ @Autowired
|
|
|
35
|
+ private XklAmpReportDetailRespository xklAmpReportDetailRespository;
|
|
|
36
|
+ @Autowired
|
|
|
37
|
+ private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;
|
|
|
38
|
+ @Autowired
|
|
|
39
|
+ private XklApiKeyRespository xklApiKeyRespository;
|
|
|
40
|
+ @Autowired
|
|
|
41
|
+ private XklCompanyRespository xklCompanyRespository;
|
|
|
42
|
+ @Autowired
|
|
|
43
|
+ private IScoreService scoreService;
|
|
|
44
|
+
|
|
|
45
|
+ @LogAnnotation
|
|
|
46
|
+ //@AntiXSS
|
|
|
47
|
+ //@Sign
|
|
|
48
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
49
|
+ @ApiOperation(value = "体检报告列表共享接口")
|
|
|
50
|
+ public ResponseEntity<ResultModel> getReportList(HttpServletRequest request,
|
|
|
51
|
+ @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
|
|
|
52
|
+ //if (!(boolean) request.getAttribute("signAspect"))
|
|
|
53
|
+ //return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
|
|
|
54
|
+ XklApiKeyEntity xklApiKey = xklApiKeyRespository.findOne((long)type);
|
|
|
55
|
+ List<XklAmpReportEntity> xklAmpReportResult = new ArrayList<>();
|
|
|
56
|
+ if(xklApiKey.getActiveStatus()!=1){
|
|
|
57
|
+ return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACTIVE), HttpStatus.OK);
|
|
|
58
|
+ }
|
|
|
59
|
+ if(xklApiKey.getAccessStatus()!=3){
|
|
|
60
|
+ return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACCESS), HttpStatus.OK);
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ long companyId = xklApiKey.getCompanyId();
|
|
|
64
|
+ XklCompanyEntity xklCompany = xklCompanyRespository.findOne(companyId);
|
|
|
65
|
+ if(xklCompany!= null){
|
|
|
66
|
+ int level = xklCompany.getLevel();//level:1-5
|
|
|
67
|
+ if(level == 1){//level-1对应所有的
|
|
|
68
|
+ xklAmpReportResult = xklAmpReportRespository.findByStatus(1);
|
|
|
69
|
+ }else{
|
|
|
70
|
+ int zeroLen = 8-(level-1)*2;
|
|
|
71
|
+ long companyCode = xklCompany.getCompanyCode();
|
|
|
72
|
+ long prefix = companyCode/((long)Math.pow(10,zeroLen));
|
|
|
73
|
+ List<XklCompanyEntity> childCompanyList = xklCompanyRespository.findByCompanyCodeStartingWith(String.valueOf(prefix));
|
|
|
74
|
+ if(childCompanyList!=null && childCompanyList.size()!=0){
|
|
|
75
|
+ List<Long> companyIdList = new ArrayList<>();
|
|
|
76
|
+ for(XklCompanyEntity company: childCompanyList){
|
|
|
77
|
+ companyIdList.add(company.getId());
|
|
|
78
|
+ }
|
|
|
79
|
+ xklAmpReportResult = xklAmpReportRespository.findByCompanyIdIn(companyIdList);
|
|
|
80
|
+ }
|
|
|
81
|
+ }
|
|
|
82
|
+ }else{
|
|
|
83
|
+ return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
|
86
|
+ return new ResponseEntity<>(ResultModel.ok(xklAmpReportResult), HttpStatus.OK);
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ @LogAnnotation
|
|
|
90
|
+ //@AntiXSS
|
|
|
91
|
+ //@Sign
|
|
|
92
|
+ @RequestMapping(value = "/detail", method = RequestMethod.GET)
|
|
|
93
|
+ @ApiOperation(value = "体检报告详情共享接口")
|
|
|
94
|
+ public ResponseEntity<ResultModel> getReportDetail(HttpServletRequest request, @RequestParam long report_id,
|
|
|
95
|
+ @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
|
|
|
96
|
+ //if (!(boolean) request.getAttribute("signAspect"))
|
|
|
97
|
+ // return new ResponseEntity<>(ResultModel.error(SIGN_ERROR), HttpStatus.OK);
|
|
|
98
|
+ XklAmpReportEntity report = xklAmpReportRespository.findOne(report_id);
|
|
|
99
|
+
|
|
|
100
|
+ XklApiKeyEntity xklApiKey = xklApiKeyRespository.findOne((long)type);
|
|
|
101
|
+ if(xklApiKey.getActiveStatus()!=1){
|
|
|
102
|
+ return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACTIVE), HttpStatus.OK);
|
|
|
103
|
+ }
|
|
|
104
|
+ if(xklApiKey.getAccessStatus()!=3){
|
|
|
105
|
+ return new ResponseEntity<>(ResultModel.error(SIGN_NO_ACCESS), HttpStatus.OK);
|
|
|
106
|
+ }
|
|
|
107
|
+
|
|
|
108
|
+ long companyId = xklApiKey.getCompanyId();
|
|
|
109
|
+ XklCompanyEntity company = xklCompanyRespository.findOne(companyId);
|
|
|
110
|
+ if(company!=null){
|
|
|
111
|
+ int level = company.getLevel();
|
|
|
112
|
+ int zeroLen = 8-(level-1)*2;
|
|
|
113
|
+ if(level!=1){
|
|
|
114
|
+ long reportCompanyId = report.getCompanyId();
|
|
|
115
|
+ XklCompanyEntity reportCompany = xklCompanyRespository.findOne(reportCompanyId);
|
|
|
116
|
+ if(reportCompany!=null){
|
|
|
117
|
+ long reportParentCompanyCode = reportCompany.getCompanyCode() - reportCompany.getCompanyCode()%((long)Math.pow(10,zeroLen));
|
|
|
118
|
+ if(reportParentCompanyCode != company.getCompanyCode()){//该报告必须属于密钥所属的公司或区域
|
|
|
119
|
+ return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
|
|
|
120
|
+ }
|
|
|
121
|
+ }else{
|
|
|
122
|
+ return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
|
|
|
123
|
+ }
|
|
|
124
|
+ }
|
|
|
125
|
+ }else{
|
|
|
126
|
+ return new ResponseEntity<>(ResultModel.error(COMPANY_ERROR), HttpStatus.OK);
|
|
|
127
|
+ }
|
|
|
128
|
+
|
|
|
129
|
+ List<ReportDetailModel> reportDetailModelList = new ArrayList<>();
|
|
|
130
|
+ if (report != null) {
|
|
|
131
|
+ if (report.getScore() - 0 < Constants.SMALL_DOUBLE || report.getScore() == null) {//首次调用接口,score为0
|
|
|
132
|
+ scoreService.getScore(report_id);
|
|
|
133
|
+ }
|
|
|
134
|
+ List<XklAmpReportDetailEntity> reportDetailEntityList = xklAmpReportDetailRespository.findAllByReportId(report_id);
|
|
|
135
|
+ for (XklAmpReportDetailEntity detail : reportDetailEntityList) {
|
|
|
136
|
+ int itemId = detail.getItemId();
|
|
|
137
|
+ ReportDetailModel reportDetail = new ReportDetailModel();
|
|
|
138
|
+ reportDetail.setItemId(itemId);
|
|
|
139
|
+ reportDetail.setItemValue(detail.getItemValue());
|
|
|
140
|
+ reportDetail.setStatus(detail.getStatus());
|
|
|
141
|
+
|
|
|
142
|
+ XklAmpReportMetaItemsEntity metaItems = Constants.itemMetaMap.get(itemId);
|
|
|
143
|
+ if (metaItems != null) {
|
|
|
144
|
+ reportDetail.setTitle(metaItems.getTitle());
|
|
|
145
|
+ if (report.getSex() == Constants.MALE) {
|
|
|
146
|
+ reportDetail.setNormalRange(metaItems.getStandardLowMale() + " - " + metaItems.getStandardHighMale());
|
|
|
147
|
+ } else {
|
|
|
148
|
+ reportDetail.setNormalRange(metaItems.getStandardLowFemale() + " - " + metaItems.getStandardHighFemale());
|
|
|
149
|
+ }
|
|
|
150
|
+ reportDetail.setType(metaItems.getType());
|
|
|
151
|
+ }
|
|
|
152
|
+
|
|
|
153
|
+ XklAmpReportHealthScoreEntity scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id, metaItems.getType());
|
|
|
154
|
+ if (scoreEntity != null)
|
|
|
155
|
+ reportDetail.setTypeHealthScore(scoreEntity.getTypeHealthScore());
|
|
|
156
|
+ reportDetailModelList.add(reportDetail);
|
|
|
157
|
+ }
|
|
|
158
|
+ }
|
|
|
159
|
+ ReportModel reportModel = new ReportModel(report, reportDetailModelList);
|
|
|
160
|
+ return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
|
|
|
161
|
+ }
|
|
|
162
|
+
|
|
|
163
|
+} |