Authored by fangyeqing

Merge branch 'addDataShare' into 'master'

ADD:add dataShare

添加数据共享

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