Authored by zhaoyue

Add report pase, save and delete. Add upsoft version, account.

git add --all src/*
git add push.sh
git commit -m "Add report parse"
git commit -m "Add report pase, save and delete. Add upsoft version, account."
git push origin zhaoyue-dev
git status
\ No newline at end of file
... ...
... ... @@ -19,4 +19,13 @@ public class Constants {
* 存放Authorization的header字段
*/
public static final String AUTHORIZATION = "authorization";
public static final int MALE = 0;
public static final int FEMALE = 1;
public static final int NORMAL = 0;
public static final int LOWER = 1;
public static final int HIGHER = 2;
}
... ...
... ... @@ -14,7 +14,16 @@ public enum ResultStatus {
// 111开头的都是与amp报告上传软件相关的
AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
REPORT_FORMAT_ERROR(-11140,"报告格式错误");
REPORT_FORMAT_ERROR(-11140,"报告格式错误"),
REPORT_EXISTED_ERROR(-11141,"报告重复上传"),
REPORT_INVALID__ERROR(-11142,"报告在数据库中不存在"),
INVALID_USER_ERROR(-11150,"报告所属用户未注册"),
INVALID_ADMIN_RPDEL_ERROR(-11151,"报告非此操作员创建,无权删除!"),
DB_ERROR(-11160,"服务器错误,无法写入数据库");
/**
* 返回码
... ...
... ... @@ -40,15 +40,17 @@ public class TokenController {
Assert.notNull(username, "username can not be empty");
Assert.notNull(password, "password can not be empty");
User user = userRepository.findByUsername(username);
User user = userRepository.findByLoginAccount(username);
if (user == null){ //用户不存在
if (user == null) { //用户不存在
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
}else{
} else {
String salt = user.getSalt();
String pass_in_db= user.getPassword();
String pass=SecurityTool.getPassword(username,password,salt);
if(!pass.equals(pass_in_db))
String pass_in_db = user.getLoginPwd();
String pass = SecurityTool.getPassword(username, password, salt);
if (!pass.equals(pass_in_db))
// TODO: 2016/11/26 use pwd with salt
// if(!password.equals(pass_in_db)) // for test
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
}
//生成一个token,保存用户登录状态
... ...
... ... @@ -39,18 +39,18 @@ public class UserInfoController {
Assert.notNull(username, "username can not be empty");
Assert.notNull(password, "password can not be empty");
User user = userRepository.findByUsername(username);
User user = userRepository.findByLoginAccount(username);
if (user != null ) { //用户已注册
return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.NOT_FOUND);
}else{
String salt= SecurityTool.genSalt();
String pass=SecurityTool.getPassword(username,password,salt);
user = new User();
user.setMember_id("aaa");
user.setUsername(username);
user.setPassword(pass);
user.setMemberId(2);
user.setLoginAccount(username);
user.setLoginPwd(pass);
user.setSalt(salt);
user.setState(true);
user.setStatus(true);
userRepository.save(user);
}
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
... ... @@ -66,8 +66,8 @@ public class UserInfoController {
public ResponseEntity<ResultModel> modPassword(@CurrentUser User user,@RequestParam String password) {
Assert.notNull(password, "password can not be empty");
String salt= SecurityTool.genSalt();
String pass=SecurityTool.getPassword(user.getUsername(),password,salt);
user.setPassword(pass);
String pass=SecurityTool.getPassword(user.getLoginAccount(),password,salt);
user.setLoginPwd(pass);
user.setSalt(salt);
userRepository.save(user);
tokenManager.deleteToken(user.getId());//退出登录
... ... @@ -81,7 +81,7 @@ public class UserInfoController {
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getUserNickName(@CurrentUser User user) {
String dickName=user.getMember_id();
String dickName=user.getLoginAccount();
return new ResponseEntity<>(ResultModel.ok(dickName), HttpStatus.OK);
}
... ...
... ... @@ -5,19 +5,27 @@ 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.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.*;
import com.xkl.model.ReportIdModel;
import com.xkl.model.ResultModel;
import com.xkl.repository.UpSoftVersionRepository;
import com.xkl.repository.*;
import com.xkl.security.AntiXSS;
import com.xkl.security.SecurityTool;
import com.xkl.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
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;
/**
* 上传报告及删除报告接口。
*/
... ... @@ -28,26 +36,118 @@ public class ReportController {
@Autowired
private UpSoftVersionRepository upSoftVersionRepository;
@Autowired
private IReportService reportService;
@Autowired
private ReportRepository reportRepository;
@Autowired
private ReportDetailRepository reportDetailRepository;
// 存储报告相关md5,防止重复上传已存在报告,防止重复上传错误报告。
private RedisTemplate<String, String> redis;
@Autowired
public void setRedis(RedisTemplate redis) {
this.redis = redis;
}
@Autowired
private UserRepository userRepository;
@Autowired
private AdminRepository adminRepository;
@RequestMapping(method = RequestMethod.POST)
@AntiXSS
@Authorization
@ApiOperation(value = "上传报告")
@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) {
// 验证存在性
String reportMd5 = SecurityTool.encode("MD5", json_report);
// 验证是否有对应的会员
String reportWithNoUser = reportMd5 + "Member";
// 验证报告格式是否有问题
String reportWrongFormat = reportMd5 + "Format";
/*
* 如果已经处理过的报告,不再进行处理。
*/
AMPReport report = reportRepository.findByMd5(reportMd5);
if (report != null && report.getStatus() > 0) {
// 返回,报告已存在。
return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(report.getId())), HttpStatus.OK);
} else if (redis.hasKey(reportWithNoUser)) {
// 返回,报告对应会员不存在。
return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
} else if (redis.hasKey(reportWrongFormat)) {
// 返回,报告格式有问题。
return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
}
/*
* 解析报告数据
*/
ReportData reportData = reportService.parseReport(json_report, reportMd5);
/*
* 检验报告格式
*/
if (reportData == null) {
redis.boundValueOps(reportWrongFormat).set("");
// 返回,报告格式有问题。
return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
}
/*
* 检验会员存在性
*/
User user = userRepository.findByLoginAccount(reportData.getAmpReport().getAccount_str());
if (user == null) {
redis.boundValueOps(reportWithNoUser).set("");
// 返回,报告对应会员不存在。
return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
/*
* 存储报告
*/
int reportId = reportService.saveReport(reportData, admin, user);
if (reportId > 0) {
// 返回,报告存储成功,报告id
return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(reportId)), HttpStatus.OK);
} else {
// 返回,服务器存储问题。
return new ResponseEntity<>(ResultModel.error(ResultStatus.DB_ERROR), HttpStatus.NOT_FOUND);
}
}
@RequestMapping(method = RequestMethod.DELETE)
@AntiXSS
@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) {
public ResponseEntity<ResultModel> delete(@CurrentAdmin Admin admin, @RequestParam long report_id) {
// 1. 得到report,验证报告存在性
AMPReport report = reportRepository.findById((int) report_id);
if (report == null) {
// 报告不存在,返回
return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_INVALID__ERROR), HttpStatus.NOT_FOUND);
}
// 2. 验证admin
if (report.getCreate_by() != 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());
reportDetailRepository.delete(detailList);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}
... ...
... ... @@ -21,7 +21,7 @@ import java.util.List;
* AMP报告上传软件客户端获取最新软件版本。
*/
@RestController
@RequestMapping("/version")
@RequestMapping("/upsoftversion")
public class SoftVersionController {
@Autowired
... ... @@ -29,7 +29,7 @@ public class SoftVersionController {
@RequestMapping(method = RequestMethod.GET)
@ApiOperation(value = "获取最新软件版本信息")
@ApiOperation(value = "获取最新软件版本信息,返回值中,version_num为版本号")
public ResponseEntity<ResultModel> getVersionInfo() {
List<UpSoftVersion> versionList = upSoftVersionRepository.findAllVersion();
UpSoftVersion version = versionList.get(versionList.size() - 1);
... ...
... ... @@ -28,8 +28,8 @@ import org.springframework.web.bind.annotation.RestController;
* 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射
*/
@RestController
@RequestMapping("/uploadsoftwareaccount")
public class UploadSoftwareAccountController {
@RequestMapping("/upsoftaccount")
public class UpSoftAccountController {
@Autowired
private AdminRepository adminRepository;
... ...
... ... @@ -2,10 +2,7 @@ package com.xkl.domain;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import java.sql.Timestamp;
/**
... ... @@ -18,6 +15,7 @@ public class AMPReport {
//用户id
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "member_id")
... ... @@ -108,7 +106,7 @@ public class AMPReport {
private float score;
// 所属公司id
@Column(name = "company_id")
private String company_id;
private int company_id;
// 报告状态 0,失效;1有效。
@Column(name = "status")
private int status;
... ... @@ -117,7 +115,7 @@ public class AMPReport {
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) {
int stable, String md5,String machine_num, String conclusion) {
this.name = name;
this.title = title;
this.check_time = check_time;
... ... @@ -137,7 +135,9 @@ public class AMPReport {
this.temp_sum = temp_sum;
this.stable = stable;
this.md5 = md5;
this.machine_num = machine_num;
this.conclusion = conclusion;
this.status = 1; //默认为有效。
}
public int getId() {
... ... @@ -380,11 +380,12 @@ public class AMPReport {
this.score = score;
}
public String getCompany_id() {
public int getCompany_id() {
return company_id;
}
public void setCompany_id(String company_id) {
public void setCompany_id(int company_id) {
this.company_id = company_id;
}
... ...
package com.xkl.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
/**
* 用户数据的domain类
... ... @@ -15,19 +14,20 @@ public class AMPReportDetail {
//自增id
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
// 报告id
@Column(name = "report_id")
private int report_id;
private int reportId;
// 指标id
@Column(name = "item_id")
private int item_id;
private int itemId;
// 指标值
@Column(name = "item_value")
private float item_value;
private float itemValue;
// 0, normal; 1, lower; 2, higher.
... ... @@ -42,28 +42,28 @@ public class AMPReportDetail {
this.id = id;
}
public int getReport_id() {
return report_id;
public int getReportId() {
return reportId;
}
public void setReport_id(int report_id) {
this.report_id = report_id;
public void setReportId(int reportId) {
this.reportId = reportId;
}
public int getItem_id() {
return item_id;
public int getItemId() {
return itemId;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
public void setItemId(int itemId) {
this.itemId = itemId;
}
public float getItem_value() {
return item_value;
public float getItemValue() {
return itemValue;
}
public void setItem_value(float item_value) {
this.item_value = item_value;
public void setItemValue(float itemValue) {
this.itemValue = itemValue;
}
public int getStatus() {
... ...
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_meta_items")
public class ReportMetaItem {
// id
@Id
@Column(name = "id")
private long id;
// item_id
@Column(name = "item_id")
private int item_id;
// type
@Column(name = "type")
private String type;
// title
@Column(name = "title")
private String title;
// standard_low_male
@Column(name = "standard_low_male")
private float standard_low_male;
// standard_high_male
@Column(name = "standard_high_male")
private float standard_high_male;
// standard_low_female
@Column(name = "standard_low_female")
private float standard_low_female;
// standard_high_female
@Column(name = "standard_high_female")
private float standard_high_female;
// explain_low
@Column(name = "explain_low")
private String explain_low;
// explain_high
@Column(name = "explain_high")
private String explain_high;
// explain_normal
@Column(name = "explain_normal")
private String explain_normal;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public float getStandard_low_male() {
return standard_low_male;
}
public void setStandard_low_male(float standard_low_male) {
this.standard_low_male = standard_low_male;
}
public float getStandard_high_male() {
return standard_high_male;
}
public void setStandard_high_male(float standard_high_male) {
this.standard_high_male = standard_high_male;
}
public float getStandard_low_female() {
return standard_low_female;
}
public void setStandard_low_female(float standard_low_female) {
this.standard_low_female = standard_low_female;
}
public float getStandard_high_female() {
return standard_high_female;
}
public void setStandard_high_female(float standard_high_female) {
this.standard_high_female = standard_high_female;
}
public String getExplain_low() {
return explain_low;
}
public void setExplain_low(String explain_low) {
this.explain_low = explain_low;
}
public String getExplain_high() {
return explain_high;
}
public void setExplain_high(String explain_high) {
this.explain_high = explain_high;
}
public String getExplain_normal() {
return explain_normal;
}
public void setExplain_normal(String explain_normal) {
this.explain_normal = explain_normal;
}
}
... ...
... ... @@ -16,11 +16,11 @@ import javax.persistence.Table;
public class User {
//用户名
@Column(name = "login_account")
private String username;
private String loginAccount;
//密码
@Column(name = "login_pwd")
private String password;
private String loginPwd;
//用户id
@Id
... ... @@ -30,26 +30,26 @@ public class User {
@Column(name = "salt")
private String salt;
@Column(name = "state")
private boolean state;
@Column(name = "status")
private boolean status;
@Column(name = "member_id")
private String member_id;
private int memberId;
public String getUsername() {
return username;
public String getLoginAccount() {
return loginAccount;
}
public void setUsername(String username) {
this.username = username;
public void setLoginAccount(String loginAccount) {
this.loginAccount = loginAccount;
}
public String getPassword() {
return password;
public String getLoginPwd() {
return loginPwd;
}
public void setPassword(String password) {
this.password = password;
public void setLoginPwd(String loginPwd) {
this.loginPwd = loginPwd;
}
public long getId() {
... ... @@ -68,19 +68,19 @@ public class User {
this.salt = salt;
}
public boolean isState() {
return state;
public boolean isStatus() {
return status;
}
public void setState(boolean state) {
this.state = state;
public void setStatus(boolean status) {
this.status = status;
}
public String getMember_id() {
return member_id;
public int getMemberId() {
return memberId;
}
public void setMember_id(String member_id) {
this.member_id = member_id;
public void setMemberId(int memberId) {
this.memberId = memberId;
}
}
... ...
package com.xkl.model;
public class ReportIdModel {
// Report Id
private int reportId;
public ReportIdModel(int reportId) {
this.reportId = reportId;
}
public int getReportId() {
return reportId;
}
public void setReportId(int reportId) {
this.reportId = reportId;
}
}
... ...
package com.xkl.repository;
import com.xkl.domain.AMPReport;
import com.xkl.domain.AMPReportDetail;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* AMPReportDetail类的CRUD操作
*
* @see AMPReportDetail
*/
public interface ReportDetailRepository extends CrudRepository<AMPReportDetail, Long> {
public List<AMPReportDetail> findByReportId(int reportId);
}
... ...
package com.xkl.repository;
import com.xkl.domain.ReportMetaItem;
import com.xkl.domain.User;
import org.springframework.data.repository.CrudRepository;
/**
* ReportMetaItems类的CRUD操作
* @see User
*/
public interface ReportMetaItemsRepository extends CrudRepository<ReportMetaItem, Long> {
}
... ...
package com.xkl.repository;
import com.xkl.domain.AMPReport;
import com.xkl.domain.Admin;
import org.springframework.data.repository.CrudRepository;
/**
* AMPReport类的CRUD操作
*
* @see AMPReport
*/
public interface ReportRepository extends CrudRepository<AMPReport, Long> {
public AMPReport findByMd5(String md5);
public AMPReport findById(int id);
}
... ...
... ... @@ -9,5 +9,5 @@ import org.springframework.data.repository.CrudRepository;
*/
public interface UserRepository extends CrudRepository<User, Long> {
public User findByUsername(String username);
public User findByLoginAccount(String username);
}
... ...
package com.xkl.service;
import com.xkl.domain.Admin;
import com.xkl.domain.ReportData;
import com.xkl.domain.User;
/**
* Created by zhao yue on 2016/11/26.
*/
public interface IReportService {
public ReportData parseReport(String reportJson, String md5);
public int saveReport(ReportData report, Admin admin, User user);
}
... ...
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 com.xkl.config.Constants;
import com.xkl.domain.*;
import com.xkl.repository.ReportDetailRepository;
import com.xkl.repository.ReportMetaItemsRepository;
import com.xkl.repository.ReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* Created by zhao yue on 2016/11/13.
*/
@Service
public class ReportService {
public class ReportService implements IReportService {
@Autowired
private ReportMetaItemsRepository reportMetaItemsRepository;
@Autowired
private ReportRepository reportRepository;
@Autowired
private ReportDetailRepository reportDetailRepository;
private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>();
/*
1. 验证md5
3. 获取report
4. 获取detail
5. 评判detail
1. 验证member
2. 获取admin
验证md5
获取report
获取detail
评判detail
验证member
获取admin
*/
// 需要程喆增加 title,account字段,String,修改set字段为int,0男,1女。
// 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。
// 125项目,改为float类型。
public ReportData parseReport(String reportJson, String md5) {
ReportData reportData = new ReportData();
AMPReport ampReport = new AMPReport();
List<AMPReportDetail> detailList = new ArrayList<>();
int sex;
/*
* 获取report基础信息
* 2. 获取report基础信息
*/
try {
JSONObject rpJson = JSONObject.parseObject(reportJson);
sex = rpJson.getInteger("sex").intValue();
ampReport.setReport(rpJson.getString("name"),
rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
rpJson.getTimestamp("report_date"),
Timestamp.valueOf(rpJson.getString("report_date")),
new Timestamp(System.currentTimeMillis()),
rpJson.getString("account"),///
rpJson.getInteger("sex").intValue(),///
... ... @@ -43,7 +59,7 @@ public class ReportService {
rpJson.getInteger("weight").intValue(),
rpJson.getInteger("pulse").intValue(),
rpJson.getInteger("respiratory_rate").intValue(),
rpJson.getInteger("atmospheric_pressure").intValue(),
rpJson.getFloat("atmospheric_pressure").floatValue(),
rpJson.getFloat("LCA").floatValue(),
rpJson.getFloat("RCA").floatValue(),
rpJson.getFloat("LAC").floatValue(),
... ... @@ -51,28 +67,77 @@ public class ReportService {
rpJson.getFloat("ABD").floatValue(),
rpJson.getFloat("total").floatValue(),
rpJson.getInteger("stable").intValue(),
md5, rpJson.getString("basic_result"));
md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
/*
* 获取detail信息
* 3. 获取detail信息,id,float类型
*/
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);
float val = rpDetails.getFloat(String.valueOf(item_id)).floatValue();
AMPReportDetail detail = new AMPReportDetail();
detail.setItem_value(valFloat);
detail.setItem_id(item_id);
detail.setItemValue(val);
detail.setItemId(item_id);
detailList.add(detail);
}
} catch (Exception e) {
return null;
}
markItemStatus(sex, detailList);
reportData.setAmpReport(ampReport);
reportData.setRpDetailList(detailList);
return reportData;
}
/*
* 存储报告
*/
public int saveReport(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()) {
detail.setReportId(ampReport.getId());
}
reportDetailRepository.save(report.getRpDetailList());
return ampReport.getId();
}
/*
* 判断detail是正常,高于标准或低于标准。
*/
private void markItemStatus(int sex, List<AMPReportDetail> detailList) {
// load ReportMetaItems into memory.
synchronized (this) {
if (rpMetaItemMap.size() == 0) {
Iterator<ReportMetaItem> rpMetaIter = reportMetaItemsRepository.findAll().iterator();
while (rpMetaIter.hasNext()) {
ReportMetaItem rpMetaItem = rpMetaIter.next();
rpMetaItemMap.put(rpMetaItem.getItem_id(), rpMetaItem);
}
}
}
// mark status
for (AMPReportDetail detail : detailList) {
float lowSt;
float highSt;
// get standard
if (sex == Constants.MALE) { // male
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_male();
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_male();
} else { // female
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_female();
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_female();
}
int status;
if (detail.getItemValue() < lowSt) {
status = Constants.LOWER;
} else if (detail.getItemValue() > highSt) {
status = Constants.HIGHER;
} else {
status = Constants.NORMAL;
}
detail.setStatus(status);
}
}
}
... ...