Authored by zhaoyue

Add upsoftware features by zhaoyue

Showing 33 changed files with 1670 additions and 22 deletions
... ... @@ -63,6 +63,12 @@
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
<!--json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.9</version>
</dependency>
</dependencies>
<build>
... ...
git add --all src/*
git add push.sh
git add pom.xml
git commit -m "Add json jar."
git push origin zhaoyue-dev
git status
\ No newline at end of file
... ...
package com.xkl.authorization.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 在Controller的方法参数中使用此注解,该方法在映射时会注入当前登录的Admin对象
* @see com.xkl.authorization.resolvers.CurrentUserMethodArgumentResolver
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface CurrentAdmin {
}
... ...
package com.xkl.authorization.resolvers;
import com.xkl.authorization.annotation.CurrentAdmin;
import com.xkl.config.Constants;
import com.xkl.domain.Admin;
import com.xkl.repository.AdminRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
/**
* 增加方法注入,将含有CurrentAdmin注解的方法参数注入当前登录用户
* @see CurrentAdmin
*/
@Component
public class CurrentAdminMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Autowired
private AdminRepository adminRepository;
@Override
public boolean supportsParameter(MethodParameter parameter) {
//如果参数类型是Admin并且有CurrentAdmin注解则支持
if (parameter.getParameterType().isAssignableFrom(Admin.class) &&
parameter.hasParameterAnnotation(CurrentAdmin.class)) {
return true;
}
return false;
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出鉴权时存入的登录用户Id
Long currentAdminId = (Long) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
if (currentAdminId != null) {
//从数据库中查询并返回
return adminRepository.findOne(currentAdminId);
}
throw new MissingServletRequestPartException(Constants.CURRENT_USER_ID);
}
}
... ...
... ... @@ -25,6 +25,7 @@ public interface Constants {
*/
String AUTHORIZATION = "authorization";
/**
* 单项打分标准
*/
... ... @@ -55,4 +56,12 @@ public interface Constants {
put(19,6);
}
};
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;
}
... ...
package com.xkl.config;
import com.xkl.authorization.interceptor.AuthorizationInterceptor;
import com.xkl.authorization.resolvers.CurrentAdminMethodArgumentResolver;
import com.xkl.authorization.resolvers.CurrentUserMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
... ... @@ -24,6 +25,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver;
@Autowired
private CurrentAdminMethodArgumentResolver currentAdminMethodArgumentResolver;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authorizationInterceptor);
... ... @@ -32,5 +35,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(currentUserMethodArgumentResolver);
argumentResolvers.add(currentAdminMethodArgumentResolver);
}
}
... ...
... ... @@ -9,7 +9,21 @@ public enum ResultStatus {
USER_NOT_FOUND(-1002, "用户不存在"),
USER_NOT_LOGIN(-1004, "用户未登录"),
USER_IS_EXIT(-1005, "用户已注册"),
USER_LOGOUT(101,"修改密码成功,退出登录");
USER_LOGOUT(101,"修改密码成功,退出登录"),
// 111开头的都是与amp报告上传软件相关的
AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
REPORT_FORMAT_ERROR(-11140,"报告格式错误"),
REPORT_EXISTED_ERROR(-11141,"报告重复上传"),
REPORT_INVALID__ERROR(-11142,"报告在数据库中不存在"),
INVALID_USER_ERROR(-11150,"报告所属用户未注册"),
INVALID_ADMIN_RPDEL_ERROR(-11151,"报告非此操作员创建,无权删除!"),
DB_ERROR(-11160,"服务器错误,无法写入数据库");
/**
* 返回码
... ...
... ... @@ -44,15 +44,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,保存用户登录状态
... ...
... ... @@ -49,7 +49,7 @@ 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{
... ... @@ -61,9 +61,10 @@ public class UserInfoController {
* 1. sign检测注解@Sign先注释掉 ,便于测试
* 2. 暂时把所有注册的用户的member表member_id都设置为1
*/
user.setMember_id(1);
user.setUsername(username);
user.setPassword(pass);
user.setMemberId(1);
user.setLoginAccount(username);
user.setLoginPwd(pass);
user.setSalt(salt);
user.setStatus(true);
userRepository.save(user);
... ... @@ -84,8 +85,8 @@ public class UserInfoController {
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
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(String.valueOf(user.getId()));//退出登录
... ... @@ -99,11 +100,17 @@ public class UserInfoController {
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
<<<<<<< HEAD
public ResponseEntity<ResultModel> getUserInfo(HttpServletRequest request,@CurrentUser User user,
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
long member_id=user.getMember_id();
XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id);
return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK);
=======
public ResponseEntity<ResultModel> getUserNickName(@CurrentUser User user) {
String dickName=user.getLoginAccount();
return new ResponseEntity<>(ResultModel.ok(dickName), HttpStatus.OK);
>>>>>>> zhaoyue-dev
}
}
... ...
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.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.*;
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 java.util.List;
/**
* 上传报告及删除报告接口。
*/
@RestController
@RequestMapping("/report")
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 = "上传并存储报告")
@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);
}
/*
* 存储报告
*/
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 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);
}
}
... ...
package com.xkl.controller.uploadsoft;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.domain.UpSoftVersion;
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.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* AMP报告上传软件客户端获取最新软件版本。
*/
@RestController
@RequestMapping("/upsoftversion")
public class SoftVersionController {
@Autowired
private UpSoftVersionRepository upSoftVersionRepository;
@RequestMapping(method = RequestMethod.GET)
@ApiOperation(value = "获取最新软件版本信息,返回值中,version_num为版本号")
public ResponseEntity<ResultModel> getVersionInfo() {
List<UpSoftVersion> versionList = upSoftVersionRepository.findAllVersion();
UpSoftVersion version = versionList.get(versionList.size() - 1);
return new ResponseEntity<>(ResultModel.ok(version), HttpStatus.OK);
}
}
... ...
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.authorization.annotation.CurrentUser;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
import com.xkl.config.ResultStatus;
import com.xkl.domain.AMPMachine;
import com.xkl.domain.Admin;
import com.xkl.model.ResultModel;
import com.xkl.repository.AMPMachineRepository;
import com.xkl.repository.AdminRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
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;
/**
* AMP报告上传软件客户端登录及退出接口。
* 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射
*/
@RestController
@RequestMapping("/upsoftaccount")
public class UpSoftAccountController {
@Autowired
private AdminRepository adminRepository;
@Autowired
private AMPMachineRepository ampMachineRepository;
@Autowired
private ITokenManager tokenManager;
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "报告上传软件登录")
public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password
, @RequestParam String ampserial, @RequestParam String ampkey) {
Assert.notNull(account, "account can not be empty");
Assert.notNull(password, "password can not be empty");
Assert.notNull(ampserial, "ampserial can not be empty");
Assert.notNull(ampkey, "ampkey can not be empty");
AMPMachine ampMachine = ampMachineRepository.findBySecretKey(ampkey.trim());
if (ampMachine == null ||// 未找到密钥所对应的机器
!ampMachine.getAMPSerial().equals(ampserial) ||//amp序号不符合
ampMachine.getStatus() != 1) {//用户无效
return new ResponseEntity<>(ResultModel.error(ResultStatus.AMP_KEY_ERROR), HttpStatus.NOT_FOUND);
}
Admin admin = adminRepository.findByAccount(account);
if (admin == null || //未注册
!admin.getPwd().equals(password) ||//密码错误
admin.getStatus() != 1) {//用户无效
//提示用户名或密码错误
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
}
//生成一个token,保存用户登录状态
TokenModel model = tokenManager.createToken(admin.getId());
return new ResponseEntity<>(ResultModel.ok(model), 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> logout(@CurrentAdmin Admin admin) {
tokenManager.deleteToken(admin.getId());
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
@RequestMapping(value = "/modpwd", method = RequestMethod.PUT)
@Authorization
@ApiOperation(value = "报告上传软件修改用户密码")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请以如下格式输入登录返回信息:adminId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> modpwd(@CurrentAdmin Admin admin, @RequestParam String newpwd) {
admin = adminRepository.findById(admin.getId());
admin.setPwd(newpwd);
adminRepository.save(admin);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}
... ...
package com.xkl.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;
/**
* 用户数据的domain类
*/
@Entity
@Table(name = "xkl_amp_machine")
public class AMPMachine {
//machine id
@Id
@Column(name = "id")
private long id;
//AMP序列号或机器硬件码
@Column(name = "AMPSerial")
private String AMPSerial;
//上传软件密钥(明文存储)
@Column(name = "secret_key")
private String secretKey;
//所属公司id
@Column(name = "company_id")
private int companyId;
//创建时间
@Column(name = "create_time")
private Timestamp createTime;
//状态(0,不可用;1可用)
@Column(name = "status")
private int status;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAMPSerial() {
return AMPSerial;
}
public void setAMPSerial(String AMPSerial) {
this.AMPSerial = AMPSerial;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public int getCompanyId() {
return companyId;
}
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public Timestamp getCreateTime() {
return createTime;
}
public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
... ...
package com.xkl.domain;
import lombok.Data;
import javax.persistence.*;
import java.sql.Timestamp;
/**
* 用户数据的domain类
*/
@Entity
@Table(name = "xkl_amp_report")
@Data
public class AMPReport {
//用户id
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "member_id")
private int member_id;
// 姓名
@Column(name = "name")
private String name;
// 报告标题
@Column(name = "title")
private String title;
// 体检时间
@Column(name = "check_time")
private Timestamp check_time;
// 上传时间
@Column(name = "uptime")
private Timestamp uptime;
//用户账号
@Column(name = "account_str")
private String account_str;
// 0, 男; 1,女
@Column(name = "sex")
private int sex;
@Column(name = "age")
private int age;
@Column(name = "weight")
private int weight;
// 脉搏
@Column(name = "pulse")
private int pulse;
// 呼吸频率
@Column(name = "breath_rate")
private int breath_rate;
// 大气压力
@Column(name = "atmos_pressure")
private float atmos_pressure;
@Column(name = "LCA")
private float LCA;
@Column(name = "RCA")
private float RCA;
@Column(name = "LAC")
private float LAC;
@Column(name = "RAC")
private float RAC;
@Column(name = "ABD")
private float ABD;
// 温度和
@Column(name = "temp_sum")
private float temp_sum;
// 稳定值
@Column(name = "stable")
private int stable;
// 报告md5值
@Column(name = "md5")
private String md5;
// 创建者id
@Column(name = "create_by")
private int create_by;
// 机器号码
@Column(name = "machine_num")
private String machine_num;
@Column(name = "T0")
private String T0;
@Column(name = "T1")
private String T1;
@Column(name = "T2")
private String T2;
@Column(name = "T3")
private String T3;
@Column(name = "T4")
private String T4;
// 体检结论
@Column(name = "conclusion")
private String conclusion;
// 健康评分
@Column(name = "score")
private float score;
// 所属公司id
@Column(name = "company_id")
private int company_id;
// 报告状态 0,失效;1有效。
@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 machine_num, 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.machine_num = machine_num;
this.conclusion = conclusion;
this.status = 1; //默认为有效。
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getMember_id() {
return member_id;
}
public void setMember_id(int member_id) {
this.member_id = member_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Timestamp getCheck_time() {
return check_time;
}
public void setCheck_time(Timestamp check_time) {
this.check_time = check_time;
}
public Timestamp getUptime() {
return uptime;
}
public void setUptime(Timestamp uptime) {
this.uptime = uptime;
}
public String getAccount_str() {
return account_str;
}
public void setAccount_str(String account_str) {
this.account_str = account_str;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getPulse() {
return pulse;
}
public void setPulse(int pulse) {
this.pulse = pulse;
}
public int getBreath_rate() {
return breath_rate;
}
public void setBreath_rate(int breath_rate) {
this.breath_rate = breath_rate;
}
public float getAtmos_pressure() {
return atmos_pressure;
}
public void setAtmos_pressure(float atmos_pressure) {
this.atmos_pressure = atmos_pressure;
}
public float getLCA() {
return LCA;
}
public void setLCA(float LCA) {
this.LCA = LCA;
}
public float getRCA() {
return RCA;
}
public void setRCA(float RCA) {
this.RCA = RCA;
}
public float getLAC() {
return LAC;
}
public void setLAC(float LAC) {
this.LAC = LAC;
}
public float getRAC() {
return RAC;
}
public void setRAC(float RAC) {
this.RAC = RAC;
}
public float getABD() {
return ABD;
}
public void setABD(float ABD) {
this.ABD = ABD;
}
public float getTemp_sum() {
return temp_sum;
}
public void setTemp_sum(float temp_sum) {
this.temp_sum = temp_sum;
}
public int getStable() {
return stable;
}
public void setStable(int stable) {
this.stable = stable;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public int getCreate_by() {
return create_by;
}
public void setCreate_by(int create_by) {
this.create_by = create_by;
}
public String getMachine_num() {
return machine_num;
}
public void setMachine_num(String machine_num) {
this.machine_num = machine_num;
}
public String getT0() {
return T0;
}
public void setT0(String t0) {
T0 = t0;
}
public String getT1() {
return T1;
}
public void setT1(String t1) {
T1 = t1;
}
public String getT2() {
return T2;
}
public void setT2(String t2) {
T2 = t2;
}
public String getT3() {
return T3;
}
public void setT3(String t3) {
T3 = t3;
}
public String getT4() {
return T4;
}
public void setT4(String t4) {
T4 = t4;
}
public String getConclusion() {
return conclusion;
}
public void setConclusion(String conclusion) {
this.conclusion = conclusion;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public int getCompany_id() {
return company_id;
}
public void setCompany_id(int company_id) {
this.company_id = company_id;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
... ...
package com.xkl.domain;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
/**
* 用户数据的domain类
*/
@Entity
@Table(name = "xkl_amp_report_detail")
public class AMPReportDetail {
//自增id
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
// 报告id
@Column(name = "report_id")
private int reportId;
// 指标id
@Column(name = "item_id")
private int itemId;
// 指标值
@Column(name = "item_value")
private float itemValue;
// 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 getReportId() {
return reportId;
}
public void setReportId(int reportId) {
this.reportId = reportId;
}
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
public float getItemValue() {
return itemValue;
}
public void setItemValue(float itemValue) {
this.itemValue = itemValue;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
... ...
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_admin")
public class Admin {
//用户id
@Id
@Column(name = "id")
private long id;
//账号
@Column(name = "account")
private String account;
//密码
@Column(name = "pwd")
private String pwd;
//账号类型
@Column(name = "type")
private int type;
//公司id
@Column(name = "coid")
private int coid;
//备注
@Column(name = "note")
private String note;
//状态
@Column(name = "status")
private int status;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getCoid() {
return coid;
}
public void setCoid(int coid) {
this.coid = coid;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
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.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;
}
}
... ...
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_upsoft_version")
public class UpSoftVersion {
//用户id
@Id
@Column(name = "id")
private long id;
//版本号
@Column(name = "version_num")
private int version_num;
//版本名称
@Column(name = "name")
private String name;
//版本详情
@Column(name = "note")
private String note;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getVersion_num() {
return version_num;
}
public void setVersion_num(int version_num) {
this.version_num = version_num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
... ...
... ... @@ -13,11 +13,11 @@ import javax.persistence.*;
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
... ... @@ -32,5 +32,54 @@ public class User {
private boolean status;
@Column(name = "member_id")
private long member_id;
private int memberId;
public String getLoginAccount() {
return loginAccount;
}
public void setLoginAccount(String loginAccount) {
this.loginAccount = loginAccount;
}
public String getLoginPwd() {
return loginPwd;
}
public void setLoginPwd(String loginPwd) {
this.loginPwd = loginPwd;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public int getMemberId() {
return memberId;
}
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.AMPMachine;
import org.springframework.data.repository.CrudRepository;
/**
* AMPMachine 类的CRUD操作
*
* @see AMPMachine
*/
public interface AMPMachineRepository extends CrudRepository<AMPMachine, Long> {
public AMPMachine findBySecretKey(String secretKey);
}
... ...
package com.xkl.repository;
import com.xkl.domain.Admin;
import org.springframework.data.repository.CrudRepository;
/**
* Admin类的CRUD操作
* @see Admin
*/
public interface AdminRepository extends CrudRepository<Admin, Long> {
public Admin findByAccount(String account);
public Admin findById(long id);
}
... ...
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);
}
... ...
package com.xkl.repository;
import com.xkl.domain.UpSoftVersion;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* User类的CRUD操作
*
* @see UpSoftVersion
*/
public interface UpSoftVersionRepository extends CrudRepository<UpSoftVersion, Long> {
@Query("select upsoft from UpSoftVersion upsoft")
public List<UpSoftVersion> findAllVersion();
}
... ...
... ... @@ -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.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.*;
/**
* Created by zhao yue on 2016/11/13.
*/
@Service
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>();
/*
验证md5
获取report
获取detail
评判detail
验证member
获取admin
*/
// 需要程喆增加 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;
/*
* 2. 获取report基础信息
*/
try {
JSONObject rpJson = JSONObject.parseObject(reportJson);
sex = rpJson.getInteger("sex").intValue();
ampReport.setReport(rpJson.getString("name"),
rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
Timestamp.valueOf(rpJson.getString("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.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.getInteger("stable").intValue(),
md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
/*
* 3. 获取detail信息,id,float类型
*/
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();
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);
}
}
}
... ...
... ... @@ -5,13 +5,14 @@ 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
... ...
server.port=8090
#server.ssl.key-store = ${user.home}/.keystore
#server.ssl.key-store-password = xkl2016
#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
#Redis
spring.redis.host=127.0.0.1
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
... ...
... ... @@ -27,7 +27,7 @@
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "http://localhost:8090/api-docs";
url = "http://127.0.0.1:8090/api-docs";
}
window.swaggerUi = new SwaggerUi({
url: url,
... ...