Authored by fangyeqing

Fix some bugs

Showing 27 changed files with 321 additions and 157 deletions
... ... @@ -40,11 +40,7 @@ public class SignAspect {
* @return
*/
private String getKeyByType(int type){
long id = 0;
if(type == 1)
id = 1;
else
id = 2;
long id = (long)type;
return (xklInterKeyRespository.findOne(id) == null)?"":xklInterKeyRespository.findOne(id).getKey();
}
/**
... ... @@ -80,6 +76,7 @@ public class SignAspect {
}
String key = getKeyByType(type);
if(key != null){
long t1= UtilTools.getNow10Second();
String sign1= SecurityTool.encode("MD5",str+t+key);
/**
... ... @@ -90,5 +87,8 @@ public class SignAspect {
}else{
request.setAttribute("signAspect",false);
}
}else{
request.setAttribute("signAspect",false);
}
}
}
... ...
package com.xkl.config;
import com.xkl.domain.XklAmpReportCategoryEntity;
import com.xkl.domain.XklAmpReportMetaItemsEntity;
import com.xkl.domain.XklAmpReportMetaScoreStandardEntity;
... ... @@ -32,32 +33,15 @@ public interface Constants {
Map<Integer,XklAmpReportMetaScoreStandardEntity> scoreMap=new HashMap<>();
/**
* 综合加权标准
* 大项综合加权标准
*/
Map<Integer,Integer> weightedScoreMap=new HashMap<Integer,Integer>(){
{
put(2,10);
put(3,6);
put(4,4);
put(5,7);
put(6,3);
put(7,10);
put(8,10);
put(9,6);
put(10,4);
put(11,2);
put(12,4);
put(13,5);
put(14,5);
put(15,6);
put(16,4);
put(17,6);
put(18,2);
put(19,6);
}
};
Map<Integer,XklAmpReportCategoryEntity> weightedScoreMap=new HashMap<>();
Map<Integer,XklAmpReportMetaItemsEntity> itemMetaMap = new HashMap<Integer, XklAmpReportMetaItemsEntity>();
/**
* 分年龄段平均得分
*/
Map<String,Double> aveScoreMap = new HashMap<>();
public static final int MALE = 0;
public static final int FEMALE = 1;
... ...
package com.xkl.config;
import com.xkl.domain.XklAmpReportAverageScoreEntity;
import com.xkl.domain.XklAmpReportCategoryEntity;
import com.xkl.domain.XklAmpReportMetaItemsEntity;
import com.xkl.domain.XklAmpReportMetaScoreStandardEntity;
import com.xkl.repository.XklAmpReportAveScoreRespository;
import com.xkl.repository.XklAmpReportCategoryRespository;
import com.xkl.repository.XklAmpReportMetaItemsRespository;
import com.xkl.repository.XklAmpReportMetaScoreStandardRespository;
import lombok.extern.apachecommons.CommonsLog;
... ... @@ -23,10 +27,14 @@ public class ScheduledTask implements Constants{
private XklAmpReportMetaScoreStandardRespository scoreStandardRespository;
@Autowired
private XklAmpReportMetaItemsRespository metaItemsRespository;
@Autowired
private XklAmpReportCategoryRespository reportCategoryRespository;
@Autowired
private XklAmpReportAveScoreRespository reportAveScoreRespository;
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getTableMap(){
log.info("Load ScoreStandard Table");
log.info("Load ScoreStandard and reportCategory Table");
Iterator<XklAmpReportMetaScoreStandardEntity> it=scoreStandardRespository.findAll().iterator();
while(it.hasNext()){
XklAmpReportMetaScoreStandardEntity scoreStandard=it.next();
... ... @@ -35,6 +43,16 @@ public class ScheduledTask implements Constants{
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getWeightedScoreMap(){
log.info("Load WeightedScore Table");
Iterator<XklAmpReportCategoryEntity> iterator = reportCategoryRespository.findAll().iterator();
while (iterator.hasNext()){
XklAmpReportCategoryEntity reportCategory = iterator.next();
weightedScoreMap.put(reportCategory.getId(),reportCategory);
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getItemMetaMap(){
log.info("Load ItemMeta Table");
Iterator<XklAmpReportMetaItemsEntity> it = metaItemsRespository.findAll().iterator();
... ... @@ -43,4 +61,15 @@ public class ScheduledTask implements Constants{
itemMetaMap.put(reportMetaItems.getItemId(),reportMetaItems);
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getAveScoreMap(){
log.info("Load AveScore Table");
Iterator<XklAmpReportAverageScoreEntity> iterator = reportAveScoreRespository.findAll().iterator();
while (iterator.hasNext()){
XklAmpReportAverageScoreEntity reportCategory = iterator.next();
String ageAndType = reportCategory.getAgeId()+"-"+reportCategory.getScoreType();
aveScoreMap.put(ageAndType,reportCategory.getAverageScore());
}
}
}
... ...
package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.Sign;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklMemberOpenidEntity;
import com.xkl.domain.*;
import com.xkl.model.ReportDetailModel;
import com.xkl.model.ResultModel;
import com.xkl.repository.XklAmpReportDetailRespository;
import com.xkl.repository.XklAmpReportHealthScoreRespository;
import com.xkl.repository.XklAmpReportRespository;
import com.xkl.repository.XklMemberOpenidRespository;
import com.xkl.security.AntiXSS;
import com.xkl.service.ILoginService;
... ... @@ -21,6 +27,8 @@ 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;
/**
* Created by win7 on 2016/10/19.
... ... @@ -109,13 +117,10 @@ public class OpenIdController {
if(xklMemberOpenid == null){
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
}
long accountId = xklMemberOpenid.getId();
long accountId = xklMemberOpenid.getAccountId();
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
}
... ...
... ... @@ -9,14 +9,13 @@ import com.xkl.authorization.annotation.Sign;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.*;
import com.xkl.model.ReportDetailModel;
import com.xkl.model.ReportItemGraphModel;
import com.xkl.model.ReportModel;
import com.xkl.model.ResultModel;
import com.xkl.model.*;
import com.xkl.repository.XklAmpReportDetailRespository;
import com.xkl.repository.XklAmpReportHealthScoreRespository;
import com.xkl.repository.XklAmpReportRespository;
import com.xkl.security.AntiXSS;
import com.xkl.service.IScoreService;
import com.xkl.tools.HtmlTools;
import com.xkl.tools.UtilTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
... ... @@ -28,7 +27,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.function.DoubleToIntFunction;
/**
* Created by win7 on 2016/11/20.
... ... @@ -46,9 +44,10 @@ public class ReportController {
@Autowired
private IScoreService scoreService;
@RequestMapping(value="/list",method = RequestMethod.GET)
@AntiXSS
@Authorization
@Sign
@RequestMapping(value="/list",method = RequestMethod.GET)
@ApiOperation(value = "体检报告列表查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
... ... @@ -59,13 +58,14 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
long member_id=user.getMemberId();
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberId(member_id);
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberIdAndStatus(member_id,1);
return new ResponseEntity<>(ResultModel.ok(xklAmpReportEntity), HttpStatus.OK);
}
@RequestMapping(value="/detail",method = RequestMethod.GET)
@AntiXSS
@Authorization
@Sign
@RequestMapping(value="/detail",method = RequestMethod.GET)
@ApiOperation(value = "体检报告详情查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
... ... @@ -93,8 +93,11 @@ public class ReportController {
XklAmpReportMetaItemsEntity metaItems=Constants.itemMetaMap.get(itemId);
if(metaItems!=null){
reportDetail.setTitle(metaItems.getTitle());
reportDetail.setNormal(metaItems.getStandardLowMale()+" - "+metaItems.getStandardHighMale());
reportDetail.setNormalNv(metaItems.getStandardLowFemale()+ " - "+metaItems.getStandardHighFemale());
if(report.getSex()==Constants.MALE){
reportDetail.setNormalRange(metaItems.getStandardLowMale()+" - "+metaItems.getStandardHighMale());
}else{
reportDetail.setNormalRange(metaItems.getStandardLowFemale()+ " - "+metaItems.getStandardHighFemale());
}
reportDetail.setType(metaItems.getType());
}
... ... @@ -108,31 +111,37 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.ok(reportModel), HttpStatus.OK);
}
/*@RequestMapping(value="/score",method = RequestMethod.GET)
@Authorization
@AntiXSS
@Sign
@ApiOperation(value = "健康评分接口(测试service用,后续可以注释掉)")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportScore(HttpServletRequest request, @CurrentUser User user,@RequestParam long report_id,
@RequestMapping(value="/score",method = RequestMethod.GET)
@ApiOperation(value = "健康评分接口")
public ResponseEntity<ResultModel> getReportScore(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(ResultStatus.SIGN_ERROR), HttpStatus.OK);
double score = 0;
XklAmpReportEntity report=xklAmpReportRespository.findOne(report_id);
if(report != null ){
if(report.getScore()==0){//首次调用接口,score为0
//TODO:可以在上传时直接打分?
//单独测试需要删除xkl_amp_report_health_scroe表中数据
scoreService.getScore(report_id);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}*/
score = scoreService.getScore(report_id);
}else{
score = report.getScore();
}
}
return new ResponseEntity<>(ResultModel.ok(score), HttpStatus.OK);
}
@RequestMapping(value="/itemInfo",method = RequestMethod.GET)
@AntiXSS
@Authorization
@Sign
@RequestMapping(value="/itemInfo",method = RequestMethod.GET)
@ApiOperation(value = "指标解释查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getReportItemInfo(HttpServletRequest request, @CurrentUser User user,@RequestParam int itemId,@RequestParam int status,
public ResponseEntity<ResultModel> getReportItemInfo(HttpServletRequest request, @CurrentUser User user,@RequestParam int itemId,@RequestParam int status,@RequestParam boolean isPureHtml,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
... ... @@ -141,11 +150,11 @@ public class ReportController {
String result="";
if(metaItems!= null){
//0, normal,1, lower,2, higher
if(status == 0){
if(status == Constants.NORMAL){
result = metaItems.getExplainNormal();
}else if(status == 1){
}else if(status == Constants.LOWER){
result = metaItems.getExplainLow();
}else if(status == 2){
}else if(status == Constants.HIGHER){
result = metaItems.getExplainHigh();
}else{
result = "没有此status相关信息";
... ... @@ -153,13 +162,16 @@ public class ReportController {
}else{
result = "没有此itemId相关信息";
}
if(isPureHtml){
result = HtmlTools.stripHtml(result);
}
return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK);
}
@RequestMapping(value="/itemGraph",method = RequestMethod.GET)
@AntiXSS
@Authorization
@Sign
@RequestMapping(value="/itemGraph",method = RequestMethod.GET)
@ApiOperation(value = "指标曲线查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
... ... @@ -170,7 +182,7 @@ public class ReportController {
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
long member_id=user.getMemberId();
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberId(member_id);
List<XklAmpReportEntity> xklAmpReportEntity=xklAmpReportRespository.findByMemberIdAndStatus(member_id,1);
List<ReportItemGraphModel> reportItemGraphModelList =new ArrayList<>();
if(xklAmpReportEntity!=null && xklAmpReportEntity.size()>0){
... ... @@ -192,4 +204,47 @@ public class ReportController {
}
@AntiXSS
@Authorization
@Sign
@RequestMapping(value="/compare",method = RequestMethod.POST)
@ApiOperation(value = "微信端体检报告分年龄比较接口")
public ResponseEntity<ResultModel> openIdCompare(HttpServletRequest request, @CurrentUser User user,@RequestParam Long report_id,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if(!(boolean)request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
List<CompareModel> result = new ArrayList<>();
XklAmpReportEntity report=xklAmpReportRespository.findOne(report_id);
double score = 0;
if(report != null ) {
if (report.getScore() == 0) {//首次调用接口,score为0
score = scoreService.getScore(report_id);
} else {
score = report.getScore();
}
int age = report.getAge();
String ageId = String.valueOf((age - age % 5) / 5);
for (Map.Entry<Integer, XklAmpReportCategoryEntity> entry : Constants.weightedScoreMap.entrySet()) {
//List<XklAmpReportHealthScoreEntity> scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id);
int typeId = entry.getKey();
XklAmpReportCategoryEntity value = entry.getValue();
String key = ageId +"-"+ typeId;
double aveScore = Constants.aveScoreMap.get(key);
double typeScore = 0;
XklAmpReportHealthScoreEntity scoreEntity = xklAmpReportHealthScoreRespository.findByReportIdAndType(report_id, typeId);
if (scoreEntity != null) {
typeScore = scoreEntity.getTypeHealthScore();
}else{
if(typeId==1){//第一项为测试项目
typeScore = score;
}
}
CompareModel cm = new CompareModel(typeId, value.getName(), typeScore, aveScore);
result.add(cm);
}
}
return new ResponseEntity<>(ResultModel.ok(result), HttpStatus.OK);
}
}
... ...
... ... @@ -11,6 +11,7 @@ import com.xkl.authorization.model.TokenModel;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.model.ResultModel;
import com.xkl.security.AntiXSS;
import com.xkl.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
... ... @@ -34,6 +35,7 @@ public class TokenController {
@Autowired
private ITokenManager tokenManager;
@AntiXSS
@Sign
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "用户登录接口")
... ... @@ -54,7 +56,7 @@ public class TokenController {
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
@AntiXSS
@Authorization
@Sign
@RequestMapping(method = RequestMethod.DELETE)
... ...
... ... @@ -77,9 +77,8 @@ public class UserInfoController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK);
}
@Authorization
@AntiXSS
@Authorization
@Sign
@RequestMapping(method = RequestMethod.PUT)
@ApiOperation(value = "用户密码修改接口")
... ... @@ -101,7 +100,7 @@ public class UserInfoController {
return new ResponseEntity<>(new ResultModel(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK);
}
@AntiXSS
@Authorization
@Sign
@RequestMapping(method = RequestMethod.GET)
... ...
package com.xkl.domain;
import lombok.Data;
import javax.persistence.*;
/**
* Created by win7 on 2017/1/15.
*/
@Data
@Entity
@Table(name = "xkl_amp_report_average_score")
public class XklAmpReportAverageScoreEntity {
@Id
@Column(name = "id")
private int id;
@Basic
@Column(name = "age_id")
private int ageId;
@Basic
@Column(name = "score_type")
private int scoreType;
@Basic
@Column(name = "average_score")
private double averageScore;
}
... ...
package com.xkl.domain;
import lombok.Data;
import javax.persistence.*;
/**
* Created by win7 on 2017/1/15.
*/
@Data
@Entity
@Table(name = "xkl_amp_report_category")
public class XklAmpReportCategoryEntity {
@Id
@Column(name = "id")
private int id;
@Basic
@Column(name = "name")
private String name;
@Basic
@Column(name = "picture")
private String picture;
@Basic
@Column(name = "score_weight")
private Double scoreWeight;
}
... ...
... ... @@ -10,7 +10,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_amp_report_detail", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_amp_report_detail")
public class XklAmpReportDetailEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
... ...
... ... @@ -11,7 +11,7 @@ import java.sql.Timestamp;
*/
@Data
@Entity
@Table(name = "xkl_amp_report", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_amp_report")
public class XklAmpReportEntity {
@Id
@Column(name = "id")
... ... @@ -109,7 +109,7 @@ public class XklAmpReportEntity {
private long companyId;
@Basic
@Column(name = "status")
private Byte status;
private int status;
public long getId() {
return id;
... ... @@ -388,12 +388,4 @@ public class XklAmpReportEntity {
public void setCompanyId(long companyId) {
this.companyId = companyId;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
}
... ...
... ... @@ -10,7 +10,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_amp_report_health_scroe", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_amp_report_health_scroe")
public class XklAmpReportHealthScoreEntity {
@Id
@GeneratedValue
... ...
... ... @@ -10,7 +10,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_amp_report_meta_items", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_amp_report_meta_items")
public class XklAmpReportMetaItemsEntity {
@Id
@Column(name = "id")
... ...
... ... @@ -10,7 +10,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_amp_report_meta_score_standard", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_amp_report_meta_score_standard")
public class XklAmpReportMetaScoreStandardEntity {
@Id
@GeneratedValue
... ...
... ... @@ -10,7 +10,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_inter_key", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_inter_key")
public class XklInterKeyEntity {
@Id
@Column(name = "id")
... ...
... ... @@ -12,7 +12,7 @@ import java.sql.Date;
*/
@Data
@Entity
@Table(name = "xkl_member", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_member")
public class XklMemberEntity {
@Id
@GeneratedValue
... ...
... ... @@ -9,7 +9,7 @@ import javax.persistence.*;
*/
@Data
@Entity
@Table(name = "xkl_member_openid", schema = "hanhe_test", catalog = "")
@Table(name = "xkl_member_openid")
public class XklMemberOpenidEntity {
@Id
@GeneratedValue
... ...
package com.xkl.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Created by win7 on 2017/1/15.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CompareModel {
long typeId;
String typeName;
double typeScore;
double typeScoreAVG;
}
... ...
... ... @@ -17,75 +17,10 @@ public class ReportDetailModel {
* XklAmpReportMetaItemsEntity
*/
private String title;
private String normalNv;
private String normal;
private String normalRange;
/**
* XklAmpReportHealthScoreEntity
*/
private int type;
private double typeHealthScore;
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
public double getItemValue() {
return itemValue;
}
public void setItemValue(double itemValue) {
this.itemValue = itemValue;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNormalNv() {
return normalNv;
}
public void setNormalNv(String normalNv) {
this.normalNv = normalNv;
}
public String getNormal() {
return normal;
}
public void setNormal(String normal) {
this.normal = normal;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getTypeHealthScore() {
return typeHealthScore;
}
public void setTypeHealthScore(double typeHealthScore) {
this.typeHealthScore = typeHealthScore;
}
}
... ...
package com.xkl.repository;
import com.xkl.domain.XklAmpReportAverageScoreEntity;
import com.xkl.domain.XklAmpReportCategoryEntity;
import org.springframework.data.repository.CrudRepository;
/**
* Created by win7 on 2016/11/20.
*/
public interface XklAmpReportAveScoreRespository extends CrudRepository<XklAmpReportAverageScoreEntity, Integer> {
}
... ...
package com.xkl.repository;
import com.xkl.domain.XklAmpReportCategoryEntity;
import com.xkl.domain.XklMemberEntity;
import org.springframework.data.repository.CrudRepository;
import javax.persistence.criteria.CriteriaBuilder;
/**
* Created by win7 on 2016/11/20.
*/
public interface XklAmpReportCategoryRespository extends CrudRepository<XklAmpReportCategoryEntity, Integer> {
}
... ...
... ... @@ -13,6 +13,7 @@ public interface XklAmpReportHealthScoreRespository extends CrudRepository<XklAm
//item_id
public XklAmpReportHealthScoreEntity findByReportIdAndType(long report_id,int type);
public List<XklAmpReportHealthScoreEntity> findByReportId(long report_id);
//public boolean existsByReportId(long report_id);
//public void saveByReportId(List<XklAmpReportHealthScoreEntity> list,long report_id);
... ...
... ... @@ -12,5 +12,5 @@ import java.util.List;
*/
public interface XklAmpReportRespository extends CrudRepository<XklAmpReportEntity, Long> {
//member_id
public List<XklAmpReportEntity> findByMemberId(long member_id);
public List<XklAmpReportEntity> findByMemberIdAndStatus(long member_id,int status);
}
... ...
... ... @@ -4,5 +4,5 @@ package com.xkl.service;
* Created by win7 on 2016/11/21.
*/
public interface IScoreService {
public void getScore(long report_id);
public double getScore(long report_id);
}
... ...
... ... @@ -28,7 +28,7 @@ public class ScoreServiceImpl implements IScoreService,Constants{
private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;
@Override
public void getScore(long report_id) {
public double getScore(long report_id) {
Map<Integer,Double> typeScoreMap=new HashMap<>();//记录各大项打分的Map
/**
... ... @@ -72,8 +72,8 @@ public class ScoreServiceImpl implements IScoreService,Constants{
scoreEntity.setTypeHealthScore(score);
saveScoreList.add(scoreEntity);
double weightedScore=weightedScoreMap.get(item_type);
finalScore += weightedScore*(score/100);
double weightedScore=weightedScoreMap.get(item_type).getScoreWeight();
finalScore += weightedScore*score;
}
/**
* 每类得分存入xkl_amp_report_health_scroe
... ... @@ -87,5 +87,6 @@ public class ScoreServiceImpl implements IScoreService,Constants{
report.setScore(finalScore);
xklAmpReportRespository.save(report);
}
return finalScore;
}
}
... ...
package com.xkl.tools;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by win7 on 2017/1/15.
*/
public class HtmlTools {
private static final String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
private static final String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
private static final String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
private static final String regEx_space = "\\s*|\t|\r|\n";//定义空格回车换行符
/**
* @param htmlStr
* @return 删除html, style, javascript标签 ,剩余纯文本
*/
public static String getTextFromHtml(String htmlStr) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
htmlStr = htmlStr.replaceAll(" ", ""); //过滤
return htmlStr.trim(); // 返回文本字符串
}
/**
* @param content
* @return 删除纯html标签,保留换行与空格
*/
public static String stripHtml(String content) {
// <p>段落替换为换行
content = content.replaceAll("<p .*?>", "\r\n");
// <br><br/>替换为换行
content = content.replaceAll("<br\\s*/?>", "\r\n");
// 去掉其它的<>之间的东西
content = content.replaceAll("\\<.*?>", "");
// 替换空格转义符
content = content.replaceAll("&nbsp;", " ");
return content;
}
public static void main(String[] args) {
String test1= "<p> <span style=\"font-size:16px;\"><strong><b style=\"line-height:20px;text-indent:-29.266666412353516px;white-space:normal;background-color:#FFFFFF;\"><b><span style=\"font-size:18px;font-family:宋体;\">血红蛋白:</span></b></b><span style=\"line-height:20px;text-indent:-29.266666412353516px;white-space:normal;background-color:#FFFFFF;font-size:18px;font-family:宋体;\"></span></strong><span style=\"font-size:18px;font-family:宋体;\"></span><span style=\"line-height:20px;text-indent:-29.266666412353516px;white-space:normal;background-color:#FFFFFF;font-size:18px;font-family:宋体;\"></span><span style=\"line-height:20px;text-indent:-29.266666412353516px;white-space:normal;background-color:#FFFFFF;font-size:18px;font-family:宋体;color:#000000;\">是一种含铁的蛋白质,其功能是运输氧和二氧化碳,维持血液酸碱平衡。</span></span> </p> <p> <span style=\"font-size:16px;\"></span><span style=\"font-size:16px;\"></span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <b style=\"text-indent:45pt;\"><span style=\"font-size:18px;font-family:宋体;\">成年男性:</span></b><span style=\"font-size:18px;font-family:宋体;\"></span><span style=\"font-size:18px;\">120g</span><span style=\"font-size:18px;font-family:宋体;\">~</span><span style=\"font-size:18px;\">160 g/L</span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <b style=\"text-indent:45pt;\"><span style=\"font-size:18px;font-family:宋体;\">成年女性:</span></b><span style=\"font-size:18px;font-family:宋体;\"></span><span style=\"font-size:18px;\">110g</span><span style=\"font-size:18px;font-family:宋体;\">~</span><span style=\"font-size:18px;\">150 g/L</span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <b style=\"text-indent:45pt;\"><span style=\"font-size:18px;font-family:宋体;\">儿 &nbsp; &nbsp;童:</span></b><span style=\"font-size:18px;font-family:宋体;\"></span><span style=\"font-size:18px;\">110g</span><span style=\"font-size:18px;font-family:宋体;\">~</span><span style=\"font-size:18px;\">160 g/L</span><span style=\"font-size:18px;\">&nbsp; &nbsp;&nbsp;</span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <b style=\"text-indent:45pt;\"><span style=\"font-size:18px;font-family:宋体;\">新 生 儿:</span></b><span style=\"font-size:18px;font-family:宋体;\"></span><span style=\"font-size:18px;\">170g</span><span style=\"font-size:18px;font-family:宋体;\">~</span><span style=\"font-size:18px;\">200 g/L</span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <span style=\"font-size:18px;color:#E53333;\"><span style=\"white-space:nowrap;color:#E53333;\"><strong><br /> </strong></span></span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <span style=\"font-size:18px;color:#E53333;\"><span style=\"white-space:nowrap;color:#E53333;\"><strong>升高:缺氧、吸烟、剧烈运动后,慢性肺源性心脏病或先天性心脏病及高原病。</strong></span></span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <span style=\"font-size:18px;\"><span style=\"white-space:nowrap;color:#009900;\"><strong><br /> </strong></span></span> </p> <p style=\"margin-left:21.95pt;line-height:20px;white-space:normal;text-indent:-21.95pt;\"> <span style=\"font-size:18px;\"><span style=\"white-space:nowrap;color:#009900;\"><strong>建议:戒烟,到负氧离子浓度高的环境中调养,如公园、森林等。</strong></span><span style=\"color:#009900;\"><strong></strong></span><br /> </span> </p> <p> <span style=\"font-size:16px;\"><strong><span style=\"color:#e53333;\"> </span></strong></span> </p> <p style=\"text-indent:18.05pt;\"> <strong><b><span style=\"font-size:16px;font-family:宋体;color:red;\"><br /> </span></b> </strong> </p> <p style=\"text-indent:18.05pt;\"> <strong><br /> </strong> </p> <span style=\"font-size:16px;\"><strong></strong></span> <p> <br /> </p> <p> &nbsp; </p>";
String test2= "<span style=\"font-size:16px;\"><strong>总胆固醇:</strong>指血液中所有脂蛋白所含胆固醇之总和,人群总胆固醇水平主要取决于遗传因素和生活方式。</span><br />";
System.out.println(stripHtml(test1));
System.out.println(stripHtml(test2));
}
}
\ No newline at end of file
... ...
... ... @@ -15,7 +15,7 @@ spring.datasource.password=HANhetest2016
#Redis
spring.redis.host=127.0.0.1
#spring.redis.password=foobared
spring.redis.password=foobared
#spring.redis.host=r-m5e7cedd3124afd4.redis.rds.aliyuncs.com
#spring.redis.password=r-m5e7cedd3124afd4:XIkaiLURedis2016
... ...