Authored by fangyeqing

ADD:add reportdetail interface and itemInfo interface

1 package com.xkl.config; 1 package com.xkl.config;
2 2
  3 +import com.xkl.domain.XklAmpReportMetaItemsEntity;
3 import com.xkl.domain.XklAmpReportMetaScoreStandardEntity; 4 import com.xkl.domain.XklAmpReportMetaScoreStandardEntity;
4 5
5 import java.util.HashMap; 6 import java.util.HashMap;
@@ -56,6 +57,8 @@ public interface Constants { @@ -56,6 +57,8 @@ public interface Constants {
56 } 57 }
57 }; 58 };
58 59
  60 + Map<Integer,XklAmpReportMetaItemsEntity> itemMetaMap = new HashMap<Integer, XklAmpReportMetaItemsEntity>();
  61 +
59 public static final int MALE = 0; 62 public static final int MALE = 0;
60 public static final int FEMALE = 1; 63 public static final int FEMALE = 1;
61 64
1 package com.xkl.config; 1 package com.xkl.config;
2 2
  3 +import com.xkl.domain.XklAmpReportMetaItemsEntity;
3 import com.xkl.domain.XklAmpReportMetaScoreStandardEntity; 4 import com.xkl.domain.XklAmpReportMetaScoreStandardEntity;
  5 +import com.xkl.repository.XklAmpReportMetaItemsRespository;
4 import com.xkl.repository.XklAmpReportMetaScoreStandardRespository; 6 import com.xkl.repository.XklAmpReportMetaScoreStandardRespository;
5 import lombok.extern.apachecommons.CommonsLog; 7 import lombok.extern.apachecommons.CommonsLog;
6 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,9 +18,11 @@ import java.util.Iterator; @@ -16,9 +18,11 @@ import java.util.Iterator;
16 */ 18 */
17 @Component 19 @Component
18 @CommonsLog 20 @CommonsLog
19 -public class ScheduledTask { 21 +public class ScheduledTask implements Constants{
20 @Autowired 22 @Autowired
21 private XklAmpReportMetaScoreStandardRespository scoreStandardRespository; 23 private XklAmpReportMetaScoreStandardRespository scoreStandardRespository;
  24 + @Autowired
  25 + private XklAmpReportMetaItemsRespository metaItemsRespository;
22 26
23 @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000) 27 @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
24 public void getTableMap(){ 28 public void getTableMap(){
@@ -26,7 +30,17 @@ public class ScheduledTask { @@ -26,7 +30,17 @@ public class ScheduledTask {
26 Iterator<XklAmpReportMetaScoreStandardEntity> it=scoreStandardRespository.findAll().iterator(); 30 Iterator<XklAmpReportMetaScoreStandardEntity> it=scoreStandardRespository.findAll().iterator();
27 while(it.hasNext()){ 31 while(it.hasNext()){
28 XklAmpReportMetaScoreStandardEntity scoreStandard=it.next(); 32 XklAmpReportMetaScoreStandardEntity scoreStandard=it.next();
29 - Constants.scoreMap.put(scoreStandard.getItemId(),scoreStandard); 33 + scoreMap.put(scoreStandard.getItemId(),scoreStandard);
  34 + }
  35 + }
  36 +
  37 + @Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
  38 + public void getItemMetaMap(){
  39 + log.info("Load ItemMeta Table");
  40 + Iterator<XklAmpReportMetaItemsEntity> it = metaItemsRespository.findAll().iterator();
  41 + while(it.hasNext()){
  42 + XklAmpReportMetaItemsEntity reportMetaItems = it.next();
  43 + itemMetaMap.put(reportMetaItems.getItemId(),reportMetaItems);
30 } 44 }
31 } 45 }
32 } 46 }
@@ -7,6 +7,8 @@ import com.xkl.authorization.annotation.Authorization; @@ -7,6 +7,8 @@ import com.xkl.authorization.annotation.Authorization;
7 import com.xkl.authorization.annotation.CurrentUser; 7 import com.xkl.authorization.annotation.CurrentUser;
8 import com.xkl.config.Constants; 8 import com.xkl.config.Constants;
9 import com.xkl.domain.*; 9 import com.xkl.domain.*;
  10 +import com.xkl.model.ReportDetailModel;
  11 +import com.xkl.model.ReportModel;
10 import com.xkl.model.ResultModel; 12 import com.xkl.model.ResultModel;
11 import com.xkl.repository.XklAmpReportDetailRespository; 13 import com.xkl.repository.XklAmpReportDetailRespository;
12 import com.xkl.repository.XklAmpReportHealthScoreRespository; 14 import com.xkl.repository.XklAmpReportHealthScoreRespository;
@@ -34,14 +36,14 @@ public class ReportController { @@ -34,14 +36,14 @@ public class ReportController {
34 private XklAmpReportRespository xklAmpReportRespository; 36 private XklAmpReportRespository xklAmpReportRespository;
35 @Autowired 37 @Autowired
36 private XklAmpReportDetailRespository xklAmpReportDetailRespository; 38 private XklAmpReportDetailRespository xklAmpReportDetailRespository;
37 - 39 + @Autowired
38 private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository; 40 private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;
39 41
40 @Autowired 42 @Autowired
41 private IScoreService scoreService; 43 private IScoreService scoreService;
42 44
43 @RequestMapping(value="/list",method = RequestMethod.GET) 45 @RequestMapping(value="/list",method = RequestMethod.GET)
44 - //@Authorization 46 + @Authorization
45 //@Sign 47 //@Sign
46 @ApiOperation(value = "体检报告列表查询接口") 48 @ApiOperation(value = "体检报告列表查询接口")
47 @ApiImplicitParams({ 49 @ApiImplicitParams({
@@ -54,19 +56,83 @@ public class ReportController { @@ -54,19 +56,83 @@ public class ReportController {
54 return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK); 56 return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK);
55 } 57 }
56 58
  59 + @RequestMapping(value="/detail",method = RequestMethod.GET)
  60 + @Authorization
  61 + //@Sign
  62 + @ApiOperation(value = "体检报告详情查询接口")
  63 + @ApiImplicitParams({
  64 + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
  65 + })
  66 + public ResponseEntity<ResultModel> getReportDetail(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id,
  67 + @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
  68 + XklAmpReportEntity report=xklAmpReportRespository.findOne(report_id);
  69 + List<ReportDetailModel> reportDetailModelList = new ArrayList<>();
  70 + if(report != null ){
  71 + if(report.getScore()==0){//首次调用接口,score为0
  72 + //TODO:可以在上传时直接打分?
  73 + scoreService.getScore(report_id);
  74 + }
  75 + List<XklAmpReportDetailEntity> reportDetailEntityList=xklAmpReportDetailRespository.findAllByReportId(report_id);
  76 + for(XklAmpReportDetailEntity detail:reportDetailEntityList){
  77 + int itemId=detail.getItemId();
  78 + ReportDetailModel reportDetail = new ReportDetailModel();
  79 + reportDetail.setItemId(itemId);
  80 + reportDetail.setItemValue(detail.getItemValue());
  81 + reportDetail.setStatus(detail.getStatus());
  82 +
  83 + XklAmpReportMetaItemsEntity metaItems=Constants.itemMetaMap.get(itemId);
  84 + reportDetail.setTitle(metaItems.getTitle());
  85 + reportDetail.setNormal(metaItems.getStandardLowMale()+" - "+metaItems.getStandardHighMale());
  86 + reportDetail.setNormalNv(metaItems.getStandardLowFemale()+ " - "+metaItems.getStandardHighFemale());
  87 + reportDetail.setType(metaItems.getType());
  88 +
  89 + XklAmpReportHealthScoreEntity scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id,metaItems.getType());
  90 + if(scoreEntity!=null)
  91 + reportDetail.setTypeHealthScore(scoreEntity.getTypeHealthScore());
  92 + reportDetailModelList.add(reportDetail);
  93 + }
  94 + }
  95 + ReportModel reportModel = new ReportModel(report,reportDetailModelList);
  96 + return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
  97 + }
  98 +
57 @RequestMapping(value="/score",method = RequestMethod.GET) 99 @RequestMapping(value="/score",method = RequestMethod.GET)
58 @Authorization 100 @Authorization
59 //@Sign 101 //@Sign
60 - @ApiOperation(value = "健康评分接口") 102 + @ApiOperation(value = "健康评分接口(测试service用,后续可以注释掉)")
61 @ApiImplicitParams({ 103 @ApiImplicitParams({
62 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), 104 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
63 }) 105 })
64 public ResponseEntity<ResultModel> getReportScore(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id, 106 public ResponseEntity<ResultModel> getReportScore(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id,
65 @RequestParam String sign, @RequestParam long t, @RequestParam int type) { 107 @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
  108 + //单独测试需要删除xkl_amp_report_health_scroe表中数据
66 scoreService.getScore(report_id); 109 scoreService.getScore(report_id);
67 return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); 110 return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
68 } 111 }
69 112
  113 + @RequestMapping(value="/itemInfo",method = RequestMethod.GET)
  114 + @Authorization
  115 + //@Sign
  116 + @ApiOperation(value = "指标解释查询接口")
  117 + @ApiImplicitParams({
  118 + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
  119 + })
  120 + public ResponseEntity<ResultModel> getReportItemInfo(HttpServletRequest request, @CurrentUser User user,@RequestParam int itemId,@RequestParam int status,
  121 + @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
  122 + XklAmpReportMetaItemsEntity metaItems = Constants.itemMetaMap.get(itemId);
  123 + String result="";
  124 + //0, normal,1, lower,2, higher
  125 + if(status == 0){
  126 + result = metaItems.getExplainNormal();
  127 + }else if(status == 1){
  128 + result = metaItems.getExplainLow();
  129 + }else if(status == 2){
  130 + result = metaItems.getExplainHigh();
  131 + }else{
  132 + result = "没有此status相关信息";
  133 + }
  134 + return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK);
  135 + }
70 136
71 137
72 } 138 }
@@ -22,7 +22,7 @@ public class ReportMetaItem { @@ -22,7 +22,7 @@ public class ReportMetaItem {
22 22
23 // type 23 // type
24 @Column(name = "type") 24 @Column(name = "type")
25 - private String type; 25 + private int type;
26 26
27 // title 27 // title
28 @Column(name = "title") 28 @Column(name = "title")
@@ -72,11 +72,11 @@ public class ReportMetaItem { @@ -72,11 +72,11 @@ public class ReportMetaItem {
72 this.item_id = item_id; 72 this.item_id = item_id;
73 } 73 }
74 74
75 - public String getType() { 75 + public int getType() {
76 return type; 76 return type;
77 } 77 }
78 78
79 - public void setType(String type) { 79 + public void setType(int type) {
80 this.type = type; 80 this.type = type;
81 } 81 }
82 82
@@ -12,170 +12,37 @@ import javax.persistence.*; @@ -12,170 +12,37 @@ import javax.persistence.*;
12 @Entity 12 @Entity
13 @Table(name = "xkl_amp_report_meta_items", schema = "hanhe_test", catalog = "") 13 @Table(name = "xkl_amp_report_meta_items", schema = "hanhe_test", catalog = "")
14 public class XklAmpReportMetaItemsEntity { 14 public class XklAmpReportMetaItemsEntity {
15 - private int id;  
16 - private int itmeId;  
17 - private String type;  
18 - private String title;  
19 - private double standardLowMale;  
20 - private double standardHighMale;  
21 - private double standardLowFemale;  
22 - private double standardHighFemale;  
23 - private String explainLow;  
24 - private String explainHigh;  
25 - private String explainNormal;  
26 -  
27 @Id 15 @Id
28 @Column(name = "id") 16 @Column(name = "id")
29 - public int getId() {  
30 - return id;  
31 - }  
32 -  
33 - public void setId(int id) {  
34 - this.id = id;  
35 - }  
36 - 17 + private int id;
37 @Basic 18 @Basic
38 - @Column(name = "itme_id")  
39 - public int getItmeId() {  
40 - return itmeId;  
41 - }  
42 -  
43 - public void setItmeId(int itmeId) {  
44 - this.itmeId = itmeId;  
45 - }  
46 - 19 + @Column(name = "item_id")
  20 + private int itemId;
47 @Basic 21 @Basic
48 @Column(name = "type") 22 @Column(name = "type")
49 - public String getType() {  
50 - return type;  
51 - }  
52 -  
53 - public void setType(String type) {  
54 - this.type = type;  
55 - }  
56 - 23 + private int type;
57 @Basic 24 @Basic
58 @Column(name = "title") 25 @Column(name = "title")
59 - public String getTitle() {  
60 - return title;  
61 - }  
62 -  
63 - public void setTitle(String title) {  
64 - this.title = title;  
65 - }  
66 - 26 + private String title;
67 @Basic 27 @Basic
68 @Column(name = "standard_low_male") 28 @Column(name = "standard_low_male")
69 - public double getStandardLowMale() {  
70 - return standardLowMale;  
71 - }  
72 -  
73 - public void setStandardLowMale(double standardLowMale) {  
74 - this.standardLowMale = standardLowMale;  
75 - }  
76 - 29 + private double standardLowMale;
77 @Basic 30 @Basic
78 @Column(name = "standard_high_male") 31 @Column(name = "standard_high_male")
79 - public double getStandardHighMale() {  
80 - return standardHighMale;  
81 - }  
82 -  
83 - public void setStandardHighMale(double standardHighMale) {  
84 - this.standardHighMale = standardHighMale;  
85 - }  
86 - 32 + private double standardHighMale;
87 @Basic 33 @Basic
88 @Column(name = "standard_low_female") 34 @Column(name = "standard_low_female")
89 - public double getStandardLowFemale() {  
90 - return standardLowFemale;  
91 - }  
92 -  
93 - public void setStandardLowFemale(double standardLowFemale) {  
94 - this.standardLowFemale = standardLowFemale;  
95 - }  
96 - 35 + private double standardLowFemale;
97 @Basic 36 @Basic
98 @Column(name = "standard_high_female") 37 @Column(name = "standard_high_female")
99 - public double getStandardHighFemale() {  
100 - return standardHighFemale;  
101 - }  
102 -  
103 - public void setStandardHighFemale(double standardHighFemale) {  
104 - this.standardHighFemale = standardHighFemale;  
105 - }  
106 - 38 + private double standardHighFemale;
107 @Basic 39 @Basic
108 @Column(name = "explain_low") 40 @Column(name = "explain_low")
109 - public String getExplainLow() {  
110 - return explainLow;  
111 - }  
112 -  
113 - public void setExplainLow(String explainLow) {  
114 - this.explainLow = explainLow;  
115 - }  
116 - 41 + private String explainLow;
117 @Basic 42 @Basic
118 @Column(name = "explain_high") 43 @Column(name = "explain_high")
119 - public String getExplainHigh() {  
120 - return explainHigh;  
121 - }  
122 -  
123 - public void setExplainHigh(String explainHigh) {  
124 - this.explainHigh = explainHigh;  
125 - }  
126 - 44 + private String explainHigh;
127 @Basic 45 @Basic
128 @Column(name = "explain_normal") 46 @Column(name = "explain_normal")
129 - public String getExplainNormal() {  
130 - return explainNormal;  
131 - }  
132 -  
133 - public void setExplainNormal(String explainNormal) {  
134 - this.explainNormal = explainNormal;  
135 - }  
136 -  
137 - @Override  
138 - public boolean equals(Object o) {  
139 - if (this == o) return true;  
140 - if (o == null || getClass() != o.getClass()) return false;  
141 -  
142 - XklAmpReportMetaItemsEntity that = (XklAmpReportMetaItemsEntity) o;  
143 -  
144 - if (id != that.id) return false;  
145 - if (itmeId != that.itmeId) return false;  
146 - if (Double.compare(that.standardLowMale, standardLowMale) != 0) return false;  
147 - if (Double.compare(that.standardHighMale, standardHighMale) != 0) return false;  
148 - if (Double.compare(that.standardLowFemale, standardLowFemale) != 0) return false;  
149 - if (Double.compare(that.standardHighFemale, standardHighFemale) != 0) return false;  
150 - if (type != null ? !type.equals(that.type) : that.type != null) return false;  
151 - if (title != null ? !title.equals(that.title) : that.title != null) return false;  
152 - if (explainLow != null ? !explainLow.equals(that.explainLow) : that.explainLow != null) return false;  
153 - if (explainHigh != null ? !explainHigh.equals(that.explainHigh) : that.explainHigh != null) return false;  
154 - if (explainNormal != null ? !explainNormal.equals(that.explainNormal) : that.explainNormal != null)  
155 - return false;  
156 -  
157 - return true;  
158 - }  
159 -  
160 - @Override  
161 - public int hashCode() {  
162 - int result;  
163 - long temp;  
164 - result = id;  
165 - result = 31 * result + itmeId;  
166 - result = 31 * result + (type != null ? type.hashCode() : 0);  
167 - result = 31 * result + (title != null ? title.hashCode() : 0);  
168 - temp = Double.doubleToLongBits(standardLowMale);  
169 - result = 31 * result + (int) (temp ^ (temp >>> 32));  
170 - temp = Double.doubleToLongBits(standardHighMale);  
171 - result = 31 * result + (int) (temp ^ (temp >>> 32));  
172 - temp = Double.doubleToLongBits(standardLowFemale);  
173 - result = 31 * result + (int) (temp ^ (temp >>> 32));  
174 - temp = Double.doubleToLongBits(standardHighFemale);  
175 - result = 31 * result + (int) (temp ^ (temp >>> 32));  
176 - result = 31 * result + (explainLow != null ? explainLow.hashCode() : 0);  
177 - result = 31 * result + (explainHigh != null ? explainHigh.hashCode() : 0);  
178 - result = 31 * result + (explainNormal != null ? explainNormal.hashCode() : 0);  
179 - return result;  
180 - } 47 + private String explainNormal;
181 } 48 }
  1 +package com.xkl.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Created by win7 on 2016/12/12.
  7 + */
  8 +@Data
  9 +public class ReportDetailModel {
  10 + /**
  11 + * XklAmpReportDetailEntity
  12 + */
  13 + private int itemId;//对应itemId
  14 + private double itemValue;
  15 + private int status;
  16 + /**
  17 + * XklAmpReportMetaItemsEntity
  18 + */
  19 + private String title;
  20 + private String normalNv;
  21 + private String normal;
  22 + /**
  23 + * XklAmpReportHealthScoreEntity
  24 + */
  25 + private int type;
  26 + private double typeHealthScore;
  27 +}
  1 +package com.xkl.model;
  2 +
  3 +import com.xkl.domain.XklAmpReportDetailEntity;
  4 +import com.xkl.domain.XklAmpReportEntity;
  5 +import lombok.AllArgsConstructor;
  6 +import lombok.Data;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * Created by win7 on 2016/11/21.
  12 + */
  13 +@Data
  14 +@AllArgsConstructor
  15 +public class ReportModel {
  16 + //
  17 + private XklAmpReportEntity Report;
  18 +
  19 + private List<ReportDetailModel> ReportDetailList;
  20 +}
@@ -11,7 +11,7 @@ import java.util.List; @@ -11,7 +11,7 @@ import java.util.List;
11 */ 11 */
12 public interface XklAmpReportHealthScoreRespository extends CrudRepository<XklAmpReportHealthScoreEntity, Long> { 12 public interface XklAmpReportHealthScoreRespository extends CrudRepository<XklAmpReportHealthScoreEntity, Long> {
13 //item_id 13 //item_id
14 - public List<XklAmpReportHealthScoreEntity> findByReportIdAndType(long report_id,int type); 14 + public XklAmpReportHealthScoreEntity findByReportIdAndType(long report_id,int type);
15 15
16 //public boolean existsByReportId(long report_id); 16 //public boolean existsByReportId(long report_id);
17 17
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.XklAmpReportDetailEntity;
  4 +import com.xkl.domain.XklAmpReportMetaItemsEntity;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * Created by win7 on 2016/11/20.
  11 + */
  12 +public interface XklAmpReportMetaItemsRespository extends CrudRepository<XklAmpReportMetaItemsEntity, Long> {
  13 +
  14 +}
@@ -31,6 +31,9 @@ public class ScoreServiceImpl implements IScoreService,Constants{ @@ -31,6 +31,9 @@ public class ScoreServiceImpl implements IScoreService,Constants{
31 public void getScore(long report_id) { 31 public void getScore(long report_id) {
32 Map<Integer,Double> typeScoreMap=new HashMap<>();//记录各大项打分的Map 32 Map<Integer,Double> typeScoreMap=new HashMap<>();//记录各大项打分的Map
33 33
  34 + /**
  35 + * report_detail表中获取每项体检的值,按大类存入typeScoreMap
  36 + */
34 List<XklAmpReportDetailEntity> reportDetailList=xklAmpReportDetailRespository.findAllByReportId(report_id); 37 List<XklAmpReportDetailEntity> reportDetailList=xklAmpReportDetailRespository.findAllByReportId(report_id);
35 38
36 for(XklAmpReportDetailEntity detail:reportDetailList){ 39 for(XklAmpReportDetailEntity detail:reportDetailList){
1 -server.port=8090  
2 -  
3 -#server.ssl.key-store = ${user.home}/.keystore  
4 -#server.ssl.key-store-password = xkl2016  
5 -#server.ssl.key-password = xkl2016  
6 -  
7 -#MySQL  
8 -spring.datasource.url=jdbc:mysql://db.hanhezy.com:4096/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true  
9 -spring.datasource.username=hanhe  
10 -spring.datasource.password=HANhetest2016  
11 -  
12 -  
13 -#Redis  
14 -spring.redis.host=127.0.0.1  
15 -#spring.redis.password=foobared  
16 -#spring.redis.host=r-m5e7cedd3124afd4.redis.rds.aliyuncs.com  
17 -#spring.redis.password=r-m5e7cedd3124afd4:XIkaiLURedis2016  
18 -  
19 -spring.redis.port=6379