...
|
...
|
@@ -11,6 +11,7 @@ import com.xkl.repository.ReportMetaItemsRepository; |
|
|
import com.xkl.repository.ReportRepository;
|
|
|
import com.xkl.repository.UserRepository;
|
|
|
import com.xkl.security.SecurityTool;
|
|
|
import com.xkl.tools.UtilTools;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.http.HttpStatus;
|
...
|
...
|
@@ -45,22 +46,22 @@ public class ReportService implements IReportService { |
|
|
this.redis = redis;
|
|
|
}
|
|
|
|
|
|
private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>();
|
|
|
private static Map<Integer, XklAmpReportMetaItemsEntity> rpMetaItemMap = new HashMap<Integer, XklAmpReportMetaItemsEntity>();
|
|
|
|
|
|
/*
|
|
|
* 存储报告
|
|
|
*/
|
|
|
public ResponseEntity<ResultModel> save(Admin admin, String json_report) {
|
|
|
public ResponseEntity<ResultModel> save(XklAdminEntity admin, String json_report) {
|
|
|
// 验证存在性
|
|
|
String reportMd5 = SecurityTool.encode("MD5", json_report);
|
|
|
// 验证是否有对应的会员
|
|
|
// 验证是无对应的会员,rediskey
|
|
|
String reportWithNoUser = reportMd5 + "Member";
|
|
|
// 验证报告格式是否有问题
|
|
|
// 验证报告格式有问题,rediskey
|
|
|
String reportWrongFormat = reportMd5 + "Format";
|
|
|
/*
|
|
|
* 如果已经处理过的报告,不再进行处理。
|
|
|
*/
|
|
|
AMPReport report = reportRepository.findByMd5(reportMd5);
|
|
|
XklAmpReportEntity report = reportRepository.findByMd5AndStatus(reportMd5, Constants.STATUS_OK3);
|
|
|
if (report != null && report.getStatus() > 0) {
|
|
|
// 返回,报告已存在。
|
|
|
return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(report.getId())), HttpStatus.OK);
|
...
|
...
|
@@ -86,7 +87,7 @@ public class ReportService implements IReportService { |
|
|
/*
|
|
|
* 检验会员存在性
|
|
|
*/
|
|
|
User user = userRepository.findByLoginAccount(reportData.getAmpReport().getAccount_str());
|
|
|
User user = userRepository.findByLoginAccountAndStatus(reportData.getAmpReport().getAccountStr(), Constants.STATUS_OK2);
|
|
|
if (user == null) {
|
|
|
redis.boundValueOps(reportWithNoUser).set("");
|
|
|
// 返回,报告对应会员不存在。
|
...
|
...
|
@@ -96,7 +97,7 @@ public class ReportService implements IReportService { |
|
|
/*
|
|
|
* 存储报告
|
|
|
*/
|
|
|
int reportId = save2DB(reportData, admin, user);
|
|
|
long reportId = save2DB(reportData, admin, user);
|
|
|
if (reportId > 0) {
|
|
|
// 返回,报告存储成功,报告id
|
|
|
return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(reportId)), HttpStatus.OK);
|
...
|
...
|
@@ -109,22 +110,22 @@ public class ReportService implements IReportService { |
|
|
/*
|
|
|
* 操作员删除报告,只能删除该操作员自己创建的报告。
|
|
|
*/
|
|
|
public ResponseEntity<ResultModel> delete(Admin admin, long report_id) {
|
|
|
public ResponseEntity<ResultModel> delete(XklAdminEntity admin, long report_id) {
|
|
|
// 1. 得到report,验证报告存在性
|
|
|
AMPReport report = reportRepository.findById((int) report_id);
|
|
|
if (report == null) {
|
|
|
XklAmpReportEntity report = reportRepository.findById( report_id);
|
|
|
if (report == null || report.getStatus() == 0) {
|
|
|
// 报告不存在,返回
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_INVALID__ERROR), HttpStatus.NOT_FOUND);
|
|
|
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
// 2. 验证admin
|
|
|
if (report.getCreate_by() != admin.getId()) {
|
|
|
if (report.getCreateBy() != admin.getId()) {
|
|
|
// 非此admin创建,不能删除,返回
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_ADMIN_RPDEL_ERROR), HttpStatus.NOT_FOUND);
|
|
|
}
|
|
|
// 3. 删除report和detail,返回ok
|
|
|
reportRepository.delete(report);
|
|
|
List<AMPReportDetail> detailList = reportDetailRepository.findByReportId(report.getId());
|
|
|
List<XklAmpReportDetailEntity> detailList = reportDetailRepository.findByReportId(report.getId());
|
|
|
reportDetailRepository.delete(detailList);
|
|
|
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
|
|
|
}
|
...
|
...
|
@@ -137,12 +138,12 @@ public class ReportService implements IReportService { |
|
|
验证member
|
|
|
获取admin
|
|
|
*/
|
|
|
// 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。
|
|
|
// 125项目,改为float类型。
|
|
|
// 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。125项目,改为float类型。
|
|
|
//
|
|
|
private ReportData parseReport(String reportJson, String md5) {
|
|
|
ReportData reportData = new ReportData();
|
|
|
AMPReport ampReport = new AMPReport();
|
|
|
List<AMPReportDetail> detailList = new ArrayList<>();
|
|
|
XklAmpReportEntity ampReport = new XklAmpReportEntity();
|
|
|
List<XklAmpReportDetailEntity> detailList = new ArrayList<>();
|
|
|
int sex;
|
|
|
|
|
|
/*
|
...
|
...
|
@@ -156,18 +157,18 @@ public class ReportService implements IReportService { |
|
|
Timestamp.valueOf(rpJson.getString("report_date")),
|
|
|
new Timestamp(System.currentTimeMillis()),
|
|
|
rpJson.getString("account"),///
|
|
|
rpJson.getInteger("sex").intValue(),///
|
|
|
rpJson.getInteger("age").intValue(),
|
|
|
rpJson.getInteger("sex").byteValue(),///
|
|
|
rpJson.getInteger("age").byteValue(),
|
|
|
rpJson.getInteger("weight").intValue(),
|
|
|
rpJson.getInteger("pulse").intValue(),
|
|
|
rpJson.getInteger("respiratory_rate").intValue(),
|
|
|
rpJson.getFloat("atmospheric_pressure").floatValue(),
|
|
|
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.getDouble("atmospheric_pressure").doubleValue(),
|
|
|
rpJson.getDouble("LCA").doubleValue(),
|
|
|
rpJson.getDouble("RCA").doubleValue(),
|
|
|
rpJson.getDouble("LAC").doubleValue(),
|
|
|
rpJson.getDouble("RAC").doubleValue(),
|
|
|
rpJson.getDouble("ABD").doubleValue(),
|
|
|
rpJson.getDouble("total").doubleValue(),
|
|
|
rpJson.getInteger("stable").intValue(),
|
|
|
md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
|
|
|
/*
|
...
|
...
|
@@ -176,7 +177,7 @@ public class ReportService implements IReportService { |
|
|
JSONObject rpDetails = rpJson.getJSONObject("detail");
|
|
|
for (int item_id = 1; item_id <= 125; item_id++) {
|
|
|
float val = rpDetails.getFloat(String.valueOf(item_id)).floatValue();
|
|
|
AMPReportDetail detail = new AMPReportDetail();
|
|
|
XklAmpReportDetailEntity detail = new XklAmpReportDetailEntity();
|
|
|
detail.setItemValue(val);
|
|
|
detail.setItemId(item_id);
|
|
|
detailList.add(detail);
|
...
|
...
|
@@ -193,12 +194,12 @@ public class ReportService implements IReportService { |
|
|
/*
|
|
|
* 存储报告
|
|
|
*/
|
|
|
private int save2DB(ReportData report, Admin admin, User user) {
|
|
|
report.getAmpReport().setCreate_by((int) admin.getId());
|
|
|
report.getAmpReport().setCompany_id(admin.getCoid());
|
|
|
report.getAmpReport().setMember_id(user.getMemberId());
|
|
|
AMPReport ampReport = reportRepository.save(report.getAmpReport());
|
|
|
for (AMPReportDetail detail : report.getRpDetailList()) {
|
|
|
private long save2DB(ReportData report, XklAdminEntity admin, User user) {
|
|
|
report.getAmpReport().setCreateBy(admin.getId());
|
|
|
report.getAmpReport().setCompanyId((long)admin.getCoid());
|
|
|
report.getAmpReport().setMemberId((long)user.getMemberId());
|
|
|
XklAmpReportEntity ampReport = reportRepository.save(report.getAmpReport());
|
|
|
for (XklAmpReportDetailEntity detail : report.getRpDetailList()) {
|
|
|
detail.setReportId(ampReport.getId());
|
|
|
}
|
|
|
reportDetailRepository.save(report.getRpDetailList());
|
...
|
...
|
@@ -208,28 +209,28 @@ public class ReportService implements IReportService { |
|
|
/*
|
|
|
* 判断detail是正常,高于标准或低于标准。
|
|
|
*/
|
|
|
private void markItemStatus(int sex, List<AMPReportDetail> detailList) {
|
|
|
private void markItemStatus(int sex, List<XklAmpReportDetailEntity> detailList) {
|
|
|
// load ReportMetaItems into memory.
|
|
|
synchronized (this) {
|
|
|
if (rpMetaItemMap.size() == 0) {
|
|
|
Iterator<ReportMetaItem> rpMetaIter = reportMetaItemsRepository.findAll().iterator();
|
|
|
Iterator<XklAmpReportMetaItemsEntity> rpMetaIter = reportMetaItemsRepository.findAll().iterator();
|
|
|
while (rpMetaIter.hasNext()) {
|
|
|
ReportMetaItem rpMetaItem = rpMetaIter.next();
|
|
|
rpMetaItemMap.put(rpMetaItem.getItem_id(), rpMetaItem);
|
|
|
XklAmpReportMetaItemsEntity rpMetaItem = rpMetaIter.next();
|
|
|
rpMetaItemMap.put(rpMetaItem.getItemId(), rpMetaItem);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// mark status
|
|
|
for (AMPReportDetail detail : detailList) {
|
|
|
float lowSt;
|
|
|
float highSt;
|
|
|
for (XklAmpReportDetailEntity detail : detailList) {
|
|
|
double lowSt;
|
|
|
double highSt;
|
|
|
// get standard
|
|
|
if (sex == Constants.MALE) { // male
|
|
|
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_male();
|
|
|
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_male();
|
|
|
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandardLowMale();
|
|
|
highSt = rpMetaItemMap.get(detail.getItemId()).getStandardHighMale();
|
|
|
} else { // female
|
|
|
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_female();
|
|
|
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_female();
|
|
|
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandardLowFemale();
|
|
|
highSt = rpMetaItemMap.get(detail.getItemId()).getStandardHighFemale();
|
|
|
}
|
|
|
int status;
|
|
|
if (detail.getItemValue() < lowSt) {
|
...
|
...
|
|