Authored by zhaoyue

Add report parse

git add --all src/*
git add push.sh
git commit -m "Bug fix"
git commit -m "Add report parse"
git push origin zhaoyue-dev
git status
\ No newline at end of file
... ...
... ... @@ -19,5 +19,4 @@ public class Constants {
* 存放Authorization的header字段
*/
public static final String AUTHORIZATION = "authorization";
}
... ...
... ... @@ -13,7 +13,8 @@ public enum ResultStatus {
USER_LOGOUT(101,"修改密码成功,退出登录"),
// 111开头的都是与amp报告上传软件相关的
AMP_KEY_ERROR(-11100, "AMP密钥不匹配");
AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
REPORT_FORMAT_ERROR(-11140,"报告格式错误");
/**
* 返回码
... ...
package com.xkl.controller.uploadsoft;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentAdmin;
import com.xkl.domain.Admin;
import com.xkl.model.ResultModel;
import com.xkl.repository.UpSoftVersionRepository;
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 com.alibaba.fastjson.*;
import java.util.List;
/**
* 上传报告及删除报告接口。
*/
@RestController
@RequestMapping("/report")
public class ReportController {
@Autowired
private UpSoftVersionRepository upSoftVersionRepository;
@RequestMapping(method = RequestMethod.POST)
@Authorization
@ApiOperation(value = "上传报告")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> save(@CurrentAdmin Admin admin, @RequestParam String json_report) {
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.DELETE)
@Authorization
@ApiOperation(value = "删除报告")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> delete(@CurrentAdmin Admin admin, @RequestParam int report_id) {
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}
... ...
... ... @@ -54,7 +54,7 @@ public class AMPReport {
private int breath_rate;
// 大气压力
@Column(name = "atmos_pressure")
private int atmos_pressure;
private float atmos_pressure;
@Column(name = "LCA")
private float LCA;
... ... @@ -113,6 +113,33 @@ public class AMPReport {
@Column(name = "status")
private int status;
public void setReport(String name, String title, Timestamp check_time,
Timestamp uptime, String account_str, int sex, int age,
int weight, int pulse, int breath_rate, float atmos_pressure,
float LCA, float RCA, float LAC, float RAC, float ABD, float temp_sum,
int stable, String md5, String conclusion) {
this.name = name;
this.title = title;
this.check_time = check_time;
this.uptime = uptime;
this.account_str = account_str;
this.sex = sex;
this.age = age;
this.weight = weight;
this.pulse = pulse;
this.breath_rate = breath_rate;
this.atmos_pressure = atmos_pressure;
this.LCA = LCA;
this.RCA = RCA;
this.LAC = LAC;
this.RAC = RAC;
this.ABD = ABD;
this.temp_sum = temp_sum;
this.stable = stable;
this.md5 = md5;
this.conclusion = conclusion;
}
public int getId() {
return id;
}
... ... @@ -209,11 +236,11 @@ public class AMPReport {
this.breath_rate = breath_rate;
}
public int getAtmos_pressure() {
public float getAtmos_pressure() {
return atmos_pressure;
}
public void setAtmos_pressure(int atmos_pressure) {
public void setAtmos_pressure(float atmos_pressure) {
this.atmos_pressure = atmos_pressure;
}
... ...
package com.xkl.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 用户数据的domain类
*/
@Entity
@Table(name = "xkl_amp_report_detail")
public class AMPReportDetail {
//自增id
@Id
@Column(name = "id")
private long id;
// 报告id
@Column(name = "report_id")
private int report_id;
// 指标id
@Column(name = "item_id")
private int item_id;
// 指标值
@Column(name = "item_value")
private float item_value;
// 0, normal; 1, lower; 2, higher.
@Column(name = "status")
private int status;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getReport_id() {
return report_id;
}
public void setReport_id(int report_id) {
this.report_id = report_id;
}
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
public float getItem_value() {
return item_value;
}
public void setItem_value(float item_value) {
this.item_value = item_value;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
... ...
package com.xkl.domain;
import java.util.List;
import com.xkl.config.ResultStatus;
/**
* 用于报告处理的中间数据类。
* Created by zhao yue on 2016/11/13.
*/
public class ReportData {
private AMPReport ampReport;
private List<AMPReportDetail> rpDetailList;
// ResultStatus resStatus;
// public ReportData(ResultStatus resStatus) {
// this.resStatus = resStatus;
// }
public AMPReport getAmpReport() {
return ampReport;
}
public void setAmpReport(AMPReport ampReport) {
this.ampReport = ampReport;
}
public List<AMPReportDetail> getRpDetailList() {
return rpDetailList;
}
public void setRpDetailList(List<AMPReportDetail> rpDetailList) {
this.rpDetailList = rpDetailList;
}
// public ResultStatus getResStatus() {
// return resStatus;
// }
//
// public void setResStatus(ResultStatus resStatus) {
// this.resStatus = resStatus;
// }
}
... ...
package com.xkl.service;
import com.alibaba.fastjson.JSONObject;
import com.xkl.domain.AMPReport;
import com.xkl.domain.AMPReportDetail;
import com.xkl.domain.ReportData;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
/**
* Created by zhao yue on 2016/11/13.
*/
@Service
public class ReportService {
/*
1. 验证md5
3. 获取report
4. 获取detail
5. 评判detail
1. 验证member
2. 获取admin
*/
// 需要程喆增加 title,account字段,String,修改set字段为int,0男,1女。
public ReportData parseReport(String reportJson, String md5) {
ReportData reportData = new ReportData();
AMPReport ampReport = new AMPReport();
List<AMPReportDetail> detailList = new ArrayList<>();
/*
* 获取report基础信息
*/
try {
JSONObject rpJson = JSONObject.parseObject(reportJson);
ampReport.setReport(rpJson.getString("name"),
rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
rpJson.getTimestamp("report_date"),
new Timestamp(System.currentTimeMillis()),
rpJson.getString("account"),///
rpJson.getInteger("sex").intValue(),///
rpJson.getInteger("age").intValue(),
rpJson.getInteger("weight").intValue(),
rpJson.getInteger("pulse").intValue(),
rpJson.getInteger("respiratory_rate").intValue(),
rpJson.getInteger("atmospheric_pressure").intValue(),
rpJson.getFloat("LCA").floatValue(),
rpJson.getFloat("RCA").floatValue(),
rpJson.getFloat("LAC").floatValue(),
rpJson.getFloat("RAC").floatValue(),
rpJson.getFloat("ABD").floatValue(),
rpJson.getFloat("total").floatValue(),
rpJson.getInteger("stable").intValue(),
md5, rpJson.getString("basic_result"));
/*
* 获取detail信息
*/
JSONObject rpDetails = rpJson.getJSONObject("detail");
for (int item_id = 1; item_id <= 125; item_id++) {
String val = rpDetails.getString(String.valueOf(item_id));
if (val == null || val.equals("")) {
continue;
}
val = val.trim().replace(" ", "").replace("``", "").replace("`", ".");
float valFloat = Float.parseFloat(val);
AMPReportDetail detail = new AMPReportDetail();
detail.setItem_value(valFloat);
detail.setItem_id(item_id);
detailList.add(detail);
}
} catch (Exception e) {
return null;
}
reportData.setAmpReport(ampReport);
reportData.setRpDetailList(detailList);
return reportData;
}
}
... ...
... ... @@ -5,14 +5,15 @@ server.port=8090
#server.ssl.key-password = xkl2016
#MySQL
spring.datasource.url=jdbc:mysql://localhost:3306/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=fyqmysql
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
#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
spring.redis.port=6379
\ No newline at end of file
spring.redis.port=6379
... ...
... ... @@ -5,15 +5,14 @@ server.port=8090
#server.ssl.key-password = xkl2016
#MySQL
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
spring.datasource.url=jdbc:mysql://localhost:3306/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=fyqmysql
#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
spring.redis.port=6379
spring.redis.port=6379
\ No newline at end of file
... ...