Authored by Yeqing Fang

ADD:add dataShare

@@ -82,7 +82,7 @@ public class SignAspect { @@ -82,7 +82,7 @@ public class SignAspect {
82 /** 82 /**
83 * 比较sign和过期时间 83 * 比较sign和过期时间
84 */ 84 */
85 - if(sign1.equals(sign)&&Math.abs(t1-t)<300){ 85 + if(sign1.equals(sign)&&Math.abs(t1-t)<60*60*24){
86 request.setAttribute("signAspect",true); 86 request.setAttribute("signAspect",true);
87 }else{ 87 }else{
88 request.setAttribute("signAspect",false); 88 request.setAttribute("signAspect",false);
@@ -6,6 +6,8 @@ package com.xkl.config; @@ -6,6 +6,8 @@ package com.xkl.config;
6 public enum ResultStatus { 6 public enum ResultStatus {
7 SUCCESS(100, "成功/Success"), 7 SUCCESS(100, "成功/Success"),
8 SIGN_ERROR(-100, "签名错误或者客户端时间有误"), 8 SIGN_ERROR(-100, "签名错误或者客户端时间有误"),
  9 + SIGN_NO_ACCESS(-101, "签名未授权"),
  10 + SIGN_NO_ACTIVE(-102, "签名未激活"),
9 11
10 USER_REGISTER(1000,"用户注册成功"), 12 USER_REGISTER(1000,"用户注册成功"),
11 USER_LOGOUT(1001,"退出登录成功"), 13 USER_LOGOUT(1001,"退出登录成功"),
@@ -20,7 +22,6 @@ public enum ResultStatus { @@ -20,7 +22,6 @@ public enum ResultStatus {
20 OPENID_UNBIND_SUCESS(2002,"OPENID解除绑定成功"), 22 OPENID_UNBIND_SUCESS(2002,"OPENID解除绑定成功"),
21 OPENID_ERROR(-2001,"OPENID错误"), 23 OPENID_ERROR(-2001,"OPENID错误"),
22 24
23 -  
24 // 111开头的都是与amp报告上传软件相关的 25 // 111开头的都是与amp报告上传软件相关的
25 AMP_KEY_ERROR(-11100, "AMP密钥不匹配"), 26 AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
26 REPORT_FORMAT_ERROR(-11140,"报告格式错误/Report json format error"), 27 REPORT_FORMAT_ERROR(-11140,"报告格式错误/Report json format error"),
  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 +}
@@ -78,15 +78,15 @@ public class XklAmpReportMetaScoreStandardEntity { @@ -78,15 +78,15 @@ public class XklAmpReportMetaScoreStandardEntity {
78 */ 78 */
79 public double getScore(double score){ 79 public double getScore(double score){
80 double result = 0; 80 double result = 0;
81 - if(score>interval1Min && score<interval1Max) 81 + if(score>=interval1Min && score<interval1Max)
82 result = interval1Score; 82 result = interval1Score;
83 - else if(score>interval2Min && score<interval2Max) 83 + else if(score>=interval2Min && score<interval2Max)
84 result = interval2Score; 84 result = interval2Score;
85 - else if(score>interval3Min && score<interval3Max) 85 + else if(score>=interval3Min && score<interval3Max)
86 result = interval3Score; 86 result = interval3Score;
87 - else if(score>interval4Min && score<interval4Max) 87 + else if(score>=interval4Min && score<=interval4Max)
88 result = interval4Score; 88 result = interval4Score;
89 - else if(score>interval5Min && score<interval5Max) 89 + else if(score>=interval5Min && score<=interval5Max)
90 result = interval5Score; 90 result = interval5Score;
91 return result; 91 return result;
92 } 92 }
  1 +package com.xkl.domain;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.persistence.*;
  6 +
  7 +/**
  8 + * Created by fangyeqing on 2017/3/13.
  9 + */
  10 +@Data
  11 +@Entity
  12 +@Table(name = "xkl_api_key")
  13 +public class XklApiKeyEntity {
  14 + @Id
  15 + @Column(name = "id")
  16 + private long id;
  17 + @Basic
  18 + @Column(name = "api_key")
  19 + private String apiKey;
  20 + @Basic
  21 + @Column(name = "company_id")
  22 + private long companyId;
  23 + @Basic
  24 + @Column(name = "access_status")
  25 + private byte accessStatus;
  26 + @Basic
  27 + @Column(name = "active_status")
  28 + private byte activeStatus;
  29 + @Basic
  30 + @Column(name = "remark")
  31 + private String remark;
  32 + @Basic
  33 + @Column(name = "status")
  34 + private byte status;
  35 +}
1 package com.xkl.repository; 1 package com.xkl.repository;
2 2
3 -import com.xkl.domain.User;  
4 import com.xkl.domain.XklAmpReportEntity; 3 import com.xkl.domain.XklAmpReportEntity;
5 -import com.xkl.domain.XklMemberEntity;  
6 import org.springframework.data.repository.CrudRepository; 4 import org.springframework.data.repository.CrudRepository;
7 5
8 import java.util.List; 6 import java.util.List;
@@ -13,4 +11,6 @@ import java.util.List; @@ -13,4 +11,6 @@ import java.util.List;
13 public interface XklAmpReportRespository extends CrudRepository<XklAmpReportEntity, Long> { 11 public interface XklAmpReportRespository extends CrudRepository<XklAmpReportEntity, Long> {
14 //member_id 12 //member_id
15 public List<XklAmpReportEntity> findByMemberIdAndStatus(long member_id,int status); 13 public List<XklAmpReportEntity> findByMemberIdAndStatus(long member_id,int status);
  14 + public List<XklAmpReportEntity> findByStatus(int status);
  15 + public List<XklAmpReportEntity> findByCompanyIdIn(List<Long> companyIdList);
16 } 16 }
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.XklApiKeyEntity;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +
  6 +/**
  7 + * Created by win7 on 2016/11/20.
  8 + */
  9 +public interface XklApiKeyRespository extends CrudRepository<XklApiKeyEntity, Long> {
  10 +
  11 +
  12 +}
1 package com.xkl.repository; 1 package com.xkl.repository;
2 2
3 -import com.xkl.domain.XklCityEntity;  
4 import com.xkl.domain.XklCompanyEntity; 3 import com.xkl.domain.XklCompanyEntity;
  4 +import org.springframework.data.jpa.repository.Query;
5 import org.springframework.data.repository.CrudRepository; 5 import org.springframework.data.repository.CrudRepository;
6 6
  7 +import java.util.List;
  8 +
7 /** 9 /**
8 * Created by win7 on 2016/11/20. 10 * Created by win7 on 2016/11/20.
9 */ 11 */
10 public interface XklCompanyRespository extends CrudRepository<XklCompanyEntity, Long> { 12 public interface XklCompanyRespository extends CrudRepository<XklCompanyEntity, Long> {
11 13
  14 + @Query(value = "select * from xkl_company where company_code like ?1%", nativeQuery = true)
  15 + public List<XklCompanyEntity> findByCompanyCodeStartingWith(String prefix);
  16 +
12 } 17 }
@@ -5,6 +5,15 @@ server.port=8090 @@ -5,6 +5,15 @@ server.port=8090
5 #spring.datasource.username=root 5 #spring.datasource.username=root
6 #spring.datasource.password=fyqmysql 6 #spring.datasource.password=fyqmysql
7 7
  8 +# debug sql
  9 +logging.level.org.hibernate.SQL=DEBUG
  10 +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
  11 +spring.jpa.properties.hibernate.show_sql=true
  12 +spring.jpa.properties.hibernate.use_sql_comments=true
  13 +spring.jpa.properties.hibernate.format_sql=true
  14 +spring.jpa.properties.hibernate.type=trace
  15 +
  16 +# datasource
8 spring.datasource.url=jdbc:mysql://db.hanhezy.com:4096/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true 17 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 18 spring.datasource.username=hanhe
10 spring.datasource.password=HANhetest2016 19 spring.datasource.password=HANhetest2016