Authored by zhaoyue

Add upsoftware features by zhaoyue

Showing 33 changed files with 1670 additions and 22 deletions
@@ -63,6 +63,12 @@ @@ -63,6 +63,12 @@
63 <artifactId>lombok</artifactId> 63 <artifactId>lombok</artifactId>
64 <version>1.16.8</version> 64 <version>1.16.8</version>
65 </dependency> 65 </dependency>
  66 + <!--json-->
  67 + <dependency>
  68 + <groupId>com.alibaba</groupId>
  69 + <artifactId>fastjson</artifactId>
  70 + <version>1.2.9</version>
  71 + </dependency>
66 </dependencies> 72 </dependencies>
67 73
68 <build> 74 <build>
  1 +git add --all src/*
  2 +git add push.sh
  3 +git add pom.xml
  4 +git commit -m "Add json jar."
  5 +git push origin zhaoyue-dev
  6 +git status
  1 +package com.xkl.authorization.annotation;
  2 +
  3 +import java.lang.annotation.ElementType;
  4 +import java.lang.annotation.Retention;
  5 +import java.lang.annotation.RetentionPolicy;
  6 +import java.lang.annotation.Target;
  7 +
  8 +/**
  9 + * 在Controller的方法参数中使用此注解,该方法在映射时会注入当前登录的Admin对象
  10 + * @see com.xkl.authorization.resolvers.CurrentUserMethodArgumentResolver
  11 + */
  12 +@Target(ElementType.PARAMETER)
  13 +@Retention(RetentionPolicy.RUNTIME)
  14 +public @interface CurrentAdmin {
  15 +}
  1 +package com.xkl.authorization.resolvers;
  2 +
  3 +import com.xkl.authorization.annotation.CurrentAdmin;
  4 +import com.xkl.config.Constants;
  5 +import com.xkl.domain.Admin;
  6 +import com.xkl.repository.AdminRepository;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.core.MethodParameter;
  9 +import org.springframework.stereotype.Component;
  10 +import org.springframework.web.bind.support.WebDataBinderFactory;
  11 +import org.springframework.web.context.request.NativeWebRequest;
  12 +import org.springframework.web.context.request.RequestAttributes;
  13 +import org.springframework.web.method.support.HandlerMethodArgumentResolver;
  14 +import org.springframework.web.method.support.ModelAndViewContainer;
  15 +import org.springframework.web.multipart.support.MissingServletRequestPartException;
  16 +
  17 +/**
  18 + * 增加方法注入,将含有CurrentAdmin注解的方法参数注入当前登录用户
  19 + * @see CurrentAdmin
  20 + */
  21 +@Component
  22 +public class CurrentAdminMethodArgumentResolver implements HandlerMethodArgumentResolver {
  23 +
  24 + @Autowired
  25 + private AdminRepository adminRepository;
  26 +
  27 + @Override
  28 + public boolean supportsParameter(MethodParameter parameter) {
  29 + //如果参数类型是Admin并且有CurrentAdmin注解则支持
  30 + if (parameter.getParameterType().isAssignableFrom(Admin.class) &&
  31 + parameter.hasParameterAnnotation(CurrentAdmin.class)) {
  32 + return true;
  33 + }
  34 + return false;
  35 + }
  36 +
  37 + @Override
  38 + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
  39 + //取出鉴权时存入的登录用户Id
  40 + Long currentAdminId = (Long) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
  41 + if (currentAdminId != null) {
  42 + //从数据库中查询并返回
  43 + return adminRepository.findOne(currentAdminId);
  44 + }
  45 + throw new MissingServletRequestPartException(Constants.CURRENT_USER_ID);
  46 + }
  47 +}
@@ -25,6 +25,7 @@ public interface Constants { @@ -25,6 +25,7 @@ public interface Constants {
25 */ 25 */
26 String AUTHORIZATION = "authorization"; 26 String AUTHORIZATION = "authorization";
27 27
  28 +
28 /** 29 /**
29 * 单项打分标准 30 * 单项打分标准
30 */ 31 */
@@ -55,4 +56,12 @@ public interface Constants { @@ -55,4 +56,12 @@ public interface Constants {
55 put(19,6); 56 put(19,6);
56 } 57 }
57 }; 58 };
  59 +
  60 + public static final int MALE = 0;
  61 + public static final int FEMALE = 1;
  62 +
  63 + public static final int NORMAL = 0;
  64 + public static final int LOWER = 1;
  65 + public static final int HIGHER = 2;
  66 +
58 } 67 }
1 package com.xkl.config; 1 package com.xkl.config;
2 2
3 import com.xkl.authorization.interceptor.AuthorizationInterceptor; 3 import com.xkl.authorization.interceptor.AuthorizationInterceptor;
  4 +import com.xkl.authorization.resolvers.CurrentAdminMethodArgumentResolver;
4 import com.xkl.authorization.resolvers.CurrentUserMethodArgumentResolver; 5 import com.xkl.authorization.resolvers.CurrentUserMethodArgumentResolver;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.context.annotation.Configuration; 7 import org.springframework.context.annotation.Configuration;
@@ -24,6 +25,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter { @@ -24,6 +25,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
24 @Autowired 25 @Autowired
25 private CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver; 26 private CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver;
26 27
  28 + @Autowired
  29 + private CurrentAdminMethodArgumentResolver currentAdminMethodArgumentResolver;
27 @Override 30 @Override
28 public void addInterceptors(InterceptorRegistry registry) { 31 public void addInterceptors(InterceptorRegistry registry) {
29 registry.addInterceptor(authorizationInterceptor); 32 registry.addInterceptor(authorizationInterceptor);
@@ -32,5 +35,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter { @@ -32,5 +35,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
32 @Override 35 @Override
33 public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { 36 public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
34 argumentResolvers.add(currentUserMethodArgumentResolver); 37 argumentResolvers.add(currentUserMethodArgumentResolver);
  38 + argumentResolvers.add(currentAdminMethodArgumentResolver);
35 } 39 }
36 } 40 }
@@ -9,7 +9,21 @@ public enum ResultStatus { @@ -9,7 +9,21 @@ public enum ResultStatus {
9 USER_NOT_FOUND(-1002, "用户不存在"), 9 USER_NOT_FOUND(-1002, "用户不存在"),
10 USER_NOT_LOGIN(-1004, "用户未登录"), 10 USER_NOT_LOGIN(-1004, "用户未登录"),
11 USER_IS_EXIT(-1005, "用户已注册"), 11 USER_IS_EXIT(-1005, "用户已注册"),
12 - USER_LOGOUT(101,"修改密码成功,退出登录"); 12 +
  13 + USER_LOGOUT(101,"修改密码成功,退出登录"),
  14 +
  15 + // 111开头的都是与amp报告上传软件相关的
  16 + AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
  17 + REPORT_FORMAT_ERROR(-11140,"报告格式错误"),
  18 + REPORT_EXISTED_ERROR(-11141,"报告重复上传"),
  19 + REPORT_INVALID__ERROR(-11142,"报告在数据库中不存在"),
  20 +
  21 + INVALID_USER_ERROR(-11150,"报告所属用户未注册"),
  22 + INVALID_ADMIN_RPDEL_ERROR(-11151,"报告非此操作员创建,无权删除!"),
  23 +
  24 + DB_ERROR(-11160,"服务器错误,无法写入数据库");
  25 +
  26 +
13 27
14 /** 28 /**
15 * 返回码 29 * 返回码
@@ -44,15 +44,17 @@ public class TokenController { @@ -44,15 +44,17 @@ public class TokenController {
44 Assert.notNull(username, "username can not be empty"); 44 Assert.notNull(username, "username can not be empty");
45 Assert.notNull(password, "password can not be empty"); 45 Assert.notNull(password, "password can not be empty");
46 46
47 - User user = userRepository.findByUsername(username); 47 + User user = userRepository.findByLoginAccount(username);
48 48
49 - if (user == null){ //用户不存在 49 + if (user == null) { //用户不存在
50 return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND); 50 return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
51 - }else{ 51 + } else {
52 String salt = user.getSalt(); 52 String salt = user.getSalt();
53 - String pass_in_db= user.getPassword();  
54 - String pass=SecurityTool.getPassword(username,password,salt);  
55 - if(!pass.equals(pass_in_db)) 53 + String pass_in_db = user.getLoginPwd();
  54 + String pass = SecurityTool.getPassword(username, password, salt);
  55 + if (!pass.equals(pass_in_db))
  56 + // TODO: 2016/11/26 use pwd with salt
  57 + // if(!password.equals(pass_in_db)) // for test
56 return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND); 58 return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
57 } 59 }
58 //生成一个token,保存用户登录状态 60 //生成一个token,保存用户登录状态
@@ -49,7 +49,7 @@ public class UserInfoController { @@ -49,7 +49,7 @@ public class UserInfoController {
49 Assert.notNull(username, "username can not be empty"); 49 Assert.notNull(username, "username can not be empty");
50 Assert.notNull(password, "password can not be empty"); 50 Assert.notNull(password, "password can not be empty");
51 51
52 - User user = userRepository.findByUsername(username); 52 + User user = userRepository.findByLoginAccount(username);
53 if (user != null ) { //用户已注册 53 if (user != null ) { //用户已注册
54 return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.NOT_FOUND); 54 return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.NOT_FOUND);
55 }else{ 55 }else{
@@ -61,9 +61,10 @@ public class UserInfoController { @@ -61,9 +61,10 @@ public class UserInfoController {
61 * 1. sign检测注解@Sign先注释掉 ,便于测试 61 * 1. sign检测注解@Sign先注释掉 ,便于测试
62 * 2. 暂时把所有注册的用户的member表member_id都设置为1 62 * 2. 暂时把所有注册的用户的member表member_id都设置为1
63 */ 63 */
64 - user.setMember_id(1);  
65 - user.setUsername(username);  
66 - user.setPassword(pass); 64 +
  65 + user.setMemberId(1);
  66 + user.setLoginAccount(username);
  67 + user.setLoginPwd(pass);
67 user.setSalt(salt); 68 user.setSalt(salt);
68 user.setStatus(true); 69 user.setStatus(true);
69 userRepository.save(user); 70 userRepository.save(user);
@@ -84,8 +85,8 @@ public class UserInfoController { @@ -84,8 +85,8 @@ public class UserInfoController {
84 @RequestParam String sign,@RequestParam long t,@RequestParam int type) { 85 @RequestParam String sign,@RequestParam long t,@RequestParam int type) {
85 Assert.notNull(password, "password can not be empty"); 86 Assert.notNull(password, "password can not be empty");
86 String salt= SecurityTool.genSalt(); 87 String salt= SecurityTool.genSalt();
87 - String pass=SecurityTool.getPassword(user.getUsername(),password,salt);  
88 - user.setPassword(pass); 88 + String pass=SecurityTool.getPassword(user.getLoginAccount(),password,salt);
  89 + user.setLoginPwd(pass);
89 user.setSalt(salt); 90 user.setSalt(salt);
90 userRepository.save(user); 91 userRepository.save(user);
91 tokenManager.deleteToken(String.valueOf(user.getId()));//退出登录 92 tokenManager.deleteToken(String.valueOf(user.getId()));//退出登录
@@ -99,11 +100,17 @@ public class UserInfoController { @@ -99,11 +100,17 @@ public class UserInfoController {
99 @ApiImplicitParams({ 100 @ApiImplicitParams({
100 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), 101 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
101 }) 102 })
  103 +<<<<<<< HEAD
102 public ResponseEntity<ResultModel> getUserInfo(HttpServletRequest request,@CurrentUser User user, 104 public ResponseEntity<ResultModel> getUserInfo(HttpServletRequest request,@CurrentUser User user,
103 @RequestParam String sign,@RequestParam long t,@RequestParam int type) { 105 @RequestParam String sign,@RequestParam long t,@RequestParam int type) {
104 long member_id=user.getMember_id(); 106 long member_id=user.getMember_id();
105 XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id); 107 XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id);
106 return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK); 108 return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK);
  109 +=======
  110 + public ResponseEntity<ResultModel> getUserNickName(@CurrentUser User user) {
  111 + String dickName=user.getLoginAccount();
  112 + return new ResponseEntity<>(ResultModel.ok(dickName), HttpStatus.OK);
  113 +>>>>>>> zhaoyue-dev
107 } 114 }
108 115
109 } 116 }
  1 +package com.xkl.controller.uploadsoft;
  2 +
  3 +import com.wordnik.swagger.annotations.ApiImplicitParam;
  4 +import com.wordnik.swagger.annotations.ApiImplicitParams;
  5 +import com.wordnik.swagger.annotations.ApiOperation;
  6 +import com.xkl.authorization.annotation.Authorization;
  7 +import com.xkl.authorization.annotation.CurrentAdmin;
  8 +import com.xkl.config.Constants;
  9 +import com.xkl.config.ResultStatus;
  10 +import com.xkl.domain.*;
  11 +import com.xkl.model.ReportIdModel;
  12 +import com.xkl.model.ResultModel;
  13 +import com.xkl.repository.*;
  14 +import com.xkl.security.AntiXSS;
  15 +import com.xkl.security.SecurityTool;
  16 +import com.xkl.service.IReportService;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.data.redis.core.RedisTemplate;
  19 +import org.springframework.http.HttpStatus;
  20 +import org.springframework.http.ResponseEntity;
  21 +import org.springframework.web.bind.annotation.RequestMapping;
  22 +import org.springframework.web.bind.annotation.RequestMethod;
  23 +import org.springframework.web.bind.annotation.RequestParam;
  24 +import org.springframework.web.bind.annotation.RestController;
  25 +
  26 +import java.util.List;
  27 +
  28 +
  29 +/**
  30 + * 上传报告及删除报告接口。
  31 + */
  32 +@RestController
  33 +@RequestMapping("/report")
  34 +public class ReportController {
  35 +
  36 + @Autowired
  37 + private UpSoftVersionRepository upSoftVersionRepository;
  38 +
  39 + @Autowired
  40 + private IReportService reportService;
  41 +
  42 + @Autowired
  43 + private ReportRepository reportRepository;
  44 +
  45 + @Autowired
  46 + private ReportDetailRepository reportDetailRepository;
  47 +
  48 + // 存储报告相关md5,防止重复上传已存在报告,防止重复上传错误报告。
  49 + private RedisTemplate<String, String> redis;
  50 +
  51 + @Autowired
  52 + public void setRedis(RedisTemplate redis) {
  53 + this.redis = redis;
  54 + }
  55 +
  56 + @Autowired
  57 + private UserRepository userRepository;
  58 +
  59 + @Autowired
  60 + private AdminRepository adminRepository;
  61 +
  62 + @RequestMapping(method = RequestMethod.POST)
  63 + @AntiXSS
  64 + @Authorization
  65 + @ApiOperation(value = "上传并存储报告")
  66 + @ApiImplicitParams({
  67 + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
  68 + })
  69 + public ResponseEntity<ResultModel> save(@CurrentAdmin Admin admin, @RequestParam String json_report) {
  70 + // 验证存在性
  71 + String reportMd5 = SecurityTool.encode("MD5", json_report);
  72 + // 验证是否有对应的会员
  73 + String reportWithNoUser = reportMd5 + "Member";
  74 + // 验证报告格式是否有问题
  75 + String reportWrongFormat = reportMd5 + "Format";
  76 + /*
  77 + * 如果已经处理过的报告,不再进行处理。
  78 + */
  79 + AMPReport report = reportRepository.findByMd5(reportMd5);
  80 + if (report != null && report.getStatus() > 0) {
  81 + // 返回,报告已存在。
  82 + return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(report.getId())), HttpStatus.OK);
  83 + } else if (redis.hasKey(reportWithNoUser)) {
  84 + // 返回,报告对应会员不存在。
  85 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
  86 + } else if (redis.hasKey(reportWrongFormat)) {
  87 + // 返回,报告格式有问题。
  88 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
  89 + }
  90 + /*
  91 + * 解析报告数据
  92 + */
  93 + ReportData reportData = reportService.parseReport(json_report, reportMd5);
  94 + /*
  95 + * 检验报告格式
  96 + */
  97 + if (reportData == null) {
  98 + redis.boundValueOps(reportWrongFormat).set("");
  99 + // 返回,报告格式有问题。
  100 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
  101 + }
  102 + /*
  103 + * 检验会员存在性
  104 + */
  105 + User user = userRepository.findByLoginAccount(reportData.getAmpReport().getAccount_str());
  106 + if (user == null) {
  107 + redis.boundValueOps(reportWithNoUser).set("");
  108 + // 返回,报告对应会员不存在。
  109 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
  110 + }
  111 +
  112 + /*
  113 + * 存储报告
  114 + */
  115 + int reportId = reportService.saveReport(reportData, admin, user);
  116 + if (reportId > 0) {
  117 + // 返回,报告存储成功,报告id
  118 + return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(reportId)), HttpStatus.OK);
  119 + } else {
  120 + // 返回,服务器存储问题。
  121 + return new ResponseEntity<>(ResultModel.error(ResultStatus.DB_ERROR), HttpStatus.NOT_FOUND);
  122 + }
  123 + }
  124 +
  125 + @RequestMapping(method = RequestMethod.DELETE)
  126 + @AntiXSS
  127 + @Authorization
  128 + @ApiOperation(value = "删除报告")
  129 + @ApiImplicitParams({
  130 + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
  131 + })
  132 + public ResponseEntity<ResultModel> delete(@CurrentAdmin Admin admin, @RequestParam long report_id) {
  133 + // 1. 得到report,验证报告存在性
  134 + AMPReport report = reportRepository.findById((int) report_id);
  135 + if (report == null) {
  136 + // 报告不存在,返回
  137 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_INVALID__ERROR), HttpStatus.NOT_FOUND);
  138 + }
  139 +
  140 + // 2. 验证admin
  141 + if (report.getCreate_by() != admin.getId()) {
  142 + // 非此admin创建,不能删除,返回
  143 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_ADMIN_RPDEL_ERROR), HttpStatus.NOT_FOUND);
  144 + }
  145 + // 3. 删除report和detail,返回ok
  146 + reportRepository.delete(report);
  147 + List<AMPReportDetail> detailList = reportDetailRepository.findByReportId(report.getId());
  148 + reportDetailRepository.delete(detailList);
  149 + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
  150 +
  151 + }
  152 +
  153 +}
  1 +package com.xkl.controller.uploadsoft;
  2 +
  3 +import com.wordnik.swagger.annotations.ApiOperation;
  4 +
  5 +import com.xkl.domain.UpSoftVersion;
  6 +import com.xkl.model.ResultModel;
  7 +
  8 +import com.xkl.repository.UpSoftVersionRepository;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.http.HttpStatus;
  11 +import org.springframework.http.ResponseEntity;
  12 +
  13 +import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RequestMethod;
  15 +import org.springframework.web.bind.annotation.RestController;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * AMP报告上传软件客户端获取最新软件版本。
  22 + */
  23 +@RestController
  24 +@RequestMapping("/upsoftversion")
  25 +public class SoftVersionController {
  26 +
  27 + @Autowired
  28 + private UpSoftVersionRepository upSoftVersionRepository;
  29 +
  30 +
  31 + @RequestMapping(method = RequestMethod.GET)
  32 + @ApiOperation(value = "获取最新软件版本信息,返回值中,version_num为版本号")
  33 + public ResponseEntity<ResultModel> getVersionInfo() {
  34 + List<UpSoftVersion> versionList = upSoftVersionRepository.findAllVersion();
  35 + UpSoftVersion version = versionList.get(versionList.size() - 1);
  36 + return new ResponseEntity<>(ResultModel.ok(version), HttpStatus.OK);
  37 + }
  38 +
  39 +}
  1 +package com.xkl.controller.uploadsoft;
  2 +
  3 +import com.wordnik.swagger.annotations.ApiImplicitParam;
  4 +import com.wordnik.swagger.annotations.ApiImplicitParams;
  5 +import com.wordnik.swagger.annotations.ApiOperation;
  6 +import com.xkl.authorization.annotation.Authorization;
  7 +import com.xkl.authorization.annotation.CurrentAdmin;
  8 +import com.xkl.authorization.annotation.CurrentUser;
  9 +import com.xkl.authorization.manager.ITokenManager;
  10 +import com.xkl.authorization.model.TokenModel;
  11 +import com.xkl.config.ResultStatus;
  12 +import com.xkl.domain.AMPMachine;
  13 +import com.xkl.domain.Admin;
  14 +import com.xkl.model.ResultModel;
  15 +import com.xkl.repository.AMPMachineRepository;
  16 +import com.xkl.repository.AdminRepository;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.http.HttpStatus;
  19 +import org.springframework.http.ResponseEntity;
  20 +import org.springframework.util.Assert;
  21 +import org.springframework.web.bind.annotation.RequestMapping;
  22 +import org.springframework.web.bind.annotation.RequestMethod;
  23 +import org.springframework.web.bind.annotation.RequestParam;
  24 +import org.springframework.web.bind.annotation.RestController;
  25 +
  26 +/**
  27 + * AMP报告上传软件客户端登录及退出接口。
  28 + * 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射
  29 + */
  30 +@RestController
  31 +@RequestMapping("/upsoftaccount")
  32 +public class UpSoftAccountController {
  33 +
  34 + @Autowired
  35 + private AdminRepository adminRepository;
  36 + @Autowired
  37 + private AMPMachineRepository ampMachineRepository;
  38 + @Autowired
  39 + private ITokenManager tokenManager;
  40 +
  41 + @RequestMapping(method = RequestMethod.POST)
  42 + @ApiOperation(value = "报告上传软件登录")
  43 + public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password
  44 + , @RequestParam String ampserial, @RequestParam String ampkey) {
  45 + Assert.notNull(account, "account can not be empty");
  46 + Assert.notNull(password, "password can not be empty");
  47 + Assert.notNull(ampserial, "ampserial can not be empty");
  48 + Assert.notNull(ampkey, "ampkey can not be empty");
  49 +
  50 + AMPMachine ampMachine = ampMachineRepository.findBySecretKey(ampkey.trim());
  51 + if (ampMachine == null ||// 未找到密钥所对应的机器
  52 + !ampMachine.getAMPSerial().equals(ampserial) ||//amp序号不符合
  53 + ampMachine.getStatus() != 1) {//用户无效
  54 + return new ResponseEntity<>(ResultModel.error(ResultStatus.AMP_KEY_ERROR), HttpStatus.NOT_FOUND);
  55 +
  56 + }
  57 +
  58 + Admin admin = adminRepository.findByAccount(account);
  59 + if (admin == null || //未注册
  60 + !admin.getPwd().equals(password) ||//密码错误
  61 + admin.getStatus() != 1) {//用户无效
  62 + //提示用户名或密码错误
  63 + return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
  64 + }
  65 +
  66 + //生成一个token,保存用户登录状态
  67 + TokenModel model = tokenManager.createToken(admin.getId());
  68 + return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
  69 + }
  70 +
  71 + @RequestMapping(method = RequestMethod.DELETE)
  72 + @Authorization
  73 + @ApiOperation(value = "报告上传软件退出登录")
  74 + @ApiImplicitParams({
  75 + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
  76 + })
  77 + public ResponseEntity<ResultModel> logout(@CurrentAdmin Admin admin) {
  78 + tokenManager.deleteToken(admin.getId());
  79 + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
  80 + }
  81 +
  82 + @RequestMapping(value = "/modpwd", method = RequestMethod.PUT)
  83 + @Authorization
  84 + @ApiOperation(value = "报告上传软件修改用户密码")
  85 + @ApiImplicitParams({
  86 + @ApiImplicitParam(name = "authorization", value = "请以如下格式输入登录返回信息:adminId_tokens", required = true, dataType = "string", paramType = "header"),
  87 + })
  88 + public ResponseEntity<ResultModel> modpwd(@CurrentAdmin Admin admin, @RequestParam String newpwd) {
  89 +
  90 + admin = adminRepository.findById(admin.getId());
  91 + admin.setPwd(newpwd);
  92 + adminRepository.save(admin);
  93 + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
  94 + }
  95 +}
  1 +package com.xkl.domain;
  2 +
  3 +import javax.persistence.Column;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.Id;
  6 +import javax.persistence.Table;
  7 +import java.sql.Timestamp;
  8 +
  9 +/**
  10 + * 用户数据的domain类
  11 + */
  12 +@Entity
  13 +@Table(name = "xkl_amp_machine")
  14 +public class AMPMachine {
  15 +
  16 + //machine id
  17 + @Id
  18 + @Column(name = "id")
  19 + private long id;
  20 +
  21 + //AMP序列号或机器硬件码
  22 + @Column(name = "AMPSerial")
  23 + private String AMPSerial;
  24 +
  25 + //上传软件密钥(明文存储)
  26 + @Column(name = "secret_key")
  27 + private String secretKey;
  28 +
  29 + //所属公司id
  30 + @Column(name = "company_id")
  31 + private int companyId;
  32 +
  33 +
  34 + //创建时间
  35 + @Column(name = "create_time")
  36 + private Timestamp createTime;
  37 +
  38 + //状态(0,不可用;1可用)
  39 + @Column(name = "status")
  40 + private int status;
  41 +
  42 + public long getId() {
  43 + return id;
  44 + }
  45 +
  46 + public void setId(long id) {
  47 + this.id = id;
  48 + }
  49 +
  50 + public String getAMPSerial() {
  51 + return AMPSerial;
  52 + }
  53 +
  54 + public void setAMPSerial(String AMPSerial) {
  55 + this.AMPSerial = AMPSerial;
  56 + }
  57 +
  58 + public String getSecretKey() {
  59 + return secretKey;
  60 + }
  61 +
  62 + public void setSecretKey(String secretKey) {
  63 + this.secretKey = secretKey;
  64 + }
  65 +
  66 + public int getCompanyId() {
  67 + return companyId;
  68 + }
  69 +
  70 + public void setCompanyId(int companyId) {
  71 + this.companyId = companyId;
  72 + }
  73 +
  74 + public Timestamp getCreateTime() {
  75 + return createTime;
  76 + }
  77 +
  78 + public void setCreateTime(Timestamp createTime) {
  79 + this.createTime = createTime;
  80 + }
  81 +
  82 + public int getStatus() {
  83 + return status;
  84 + }
  85 +
  86 + public void setStatus(int status) {
  87 + this.status = status;
  88 + }
  89 +}
  1 +package com.xkl.domain;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.persistence.*;
  6 +import java.sql.Timestamp;
  7 +
  8 +/**
  9 + * 用户数据的domain类
  10 + */
  11 +@Entity
  12 +@Table(name = "xkl_amp_report")
  13 +@Data
  14 +public class AMPReport {
  15 + //用户id
  16 + @Id
  17 + @Column(name = "id")
  18 + @GeneratedValue(strategy = GenerationType.IDENTITY)
  19 + private int id;
  20 +
  21 + @Column(name = "member_id")
  22 + private int member_id;
  23 + // 姓名
  24 + @Column(name = "name")
  25 + private String name;
  26 + // 报告标题
  27 + @Column(name = "title")
  28 + private String title;
  29 + // 体检时间
  30 + @Column(name = "check_time")
  31 + private Timestamp check_time;
  32 + // 上传时间
  33 + @Column(name = "uptime")
  34 + private Timestamp uptime;
  35 + //用户账号
  36 + @Column(name = "account_str")
  37 + private String account_str;
  38 + // 0, 男; 1,女
  39 + @Column(name = "sex")
  40 + private int sex;
  41 +
  42 + @Column(name = "age")
  43 + private int age;
  44 +
  45 + @Column(name = "weight")
  46 + private int weight;
  47 + // 脉搏
  48 + @Column(name = "pulse")
  49 + private int pulse;
  50 + // 呼吸频率
  51 + @Column(name = "breath_rate")
  52 + private int breath_rate;
  53 + // 大气压力
  54 + @Column(name = "atmos_pressure")
  55 + private float atmos_pressure;
  56 +
  57 + @Column(name = "LCA")
  58 + private float LCA;
  59 +
  60 + @Column(name = "RCA")
  61 + private float RCA;
  62 +
  63 + @Column(name = "LAC")
  64 + private float LAC;
  65 +
  66 + @Column(name = "RAC")
  67 + private float RAC;
  68 +
  69 + @Column(name = "ABD")
  70 + private float ABD;
  71 + // 温度和
  72 + @Column(name = "temp_sum")
  73 + private float temp_sum;
  74 + // 稳定值
  75 + @Column(name = "stable")
  76 + private int stable;
  77 + // 报告md5值
  78 + @Column(name = "md5")
  79 + private String md5;
  80 + // 创建者id
  81 + @Column(name = "create_by")
  82 + private int create_by;
  83 + // 机器号码
  84 + @Column(name = "machine_num")
  85 + private String machine_num;
  86 +
  87 + @Column(name = "T0")
  88 + private String T0;
  89 +
  90 + @Column(name = "T1")
  91 + private String T1;
  92 +
  93 + @Column(name = "T2")
  94 + private String T2;
  95 +
  96 + @Column(name = "T3")
  97 + private String T3;
  98 +
  99 + @Column(name = "T4")
  100 + private String T4;
  101 + // 体检结论
  102 + @Column(name = "conclusion")
  103 + private String conclusion;
  104 + // 健康评分
  105 + @Column(name = "score")
  106 + private float score;
  107 + // 所属公司id
  108 + @Column(name = "company_id")
  109 + private int company_id;
  110 + // 报告状态 0,失效;1有效。
  111 + @Column(name = "status")
  112 + private int status;
  113 +
  114 + public void setReport(String name, String title, Timestamp check_time,
  115 + Timestamp uptime, String account_str, int sex, int age,
  116 + int weight, int pulse, int breath_rate, float atmos_pressure,
  117 + float LCA, float RCA, float LAC, float RAC, float ABD, float temp_sum,
  118 + int stable, String md5,String machine_num, String conclusion) {
  119 + this.name = name;
  120 + this.title = title;
  121 + this.check_time = check_time;
  122 + this.uptime = uptime;
  123 + this.account_str = account_str;
  124 + this.sex = sex;
  125 + this.age = age;
  126 + this.weight = weight;
  127 + this.pulse = pulse;
  128 + this.breath_rate = breath_rate;
  129 + this.atmos_pressure = atmos_pressure;
  130 + this.LCA = LCA;
  131 + this.RCA = RCA;
  132 + this.LAC = LAC;
  133 + this.RAC = RAC;
  134 + this.ABD = ABD;
  135 + this.temp_sum = temp_sum;
  136 + this.stable = stable;
  137 + this.md5 = md5;
  138 + this.machine_num = machine_num;
  139 + this.conclusion = conclusion;
  140 + this.status = 1; //默认为有效。
  141 + }
  142 +
  143 + public int getId() {
  144 + return id;
  145 + }
  146 +
  147 + public void setId(int id) {
  148 + this.id = id;
  149 + }
  150 +
  151 + public int getMember_id() {
  152 + return member_id;
  153 + }
  154 +
  155 + public void setMember_id(int member_id) {
  156 + this.member_id = member_id;
  157 + }
  158 +
  159 + public String getName() {
  160 + return name;
  161 + }
  162 +
  163 + public void setName(String name) {
  164 + this.name = name;
  165 + }
  166 +
  167 + public String getTitle() {
  168 + return title;
  169 + }
  170 +
  171 + public void setTitle(String title) {
  172 + this.title = title;
  173 + }
  174 +
  175 + public Timestamp getCheck_time() {
  176 + return check_time;
  177 + }
  178 +
  179 + public void setCheck_time(Timestamp check_time) {
  180 + this.check_time = check_time;
  181 + }
  182 +
  183 + public Timestamp getUptime() {
  184 + return uptime;
  185 + }
  186 +
  187 + public void setUptime(Timestamp uptime) {
  188 + this.uptime = uptime;
  189 + }
  190 +
  191 + public String getAccount_str() {
  192 + return account_str;
  193 + }
  194 +
  195 + public void setAccount_str(String account_str) {
  196 + this.account_str = account_str;
  197 + }
  198 +
  199 + public int getSex() {
  200 + return sex;
  201 + }
  202 +
  203 + public void setSex(int sex) {
  204 + this.sex = sex;
  205 + }
  206 +
  207 + public int getAge() {
  208 + return age;
  209 + }
  210 +
  211 + public void setAge(int age) {
  212 + this.age = age;
  213 + }
  214 +
  215 + public int getWeight() {
  216 + return weight;
  217 + }
  218 +
  219 + public void setWeight(int weight) {
  220 + this.weight = weight;
  221 + }
  222 +
  223 + public int getPulse() {
  224 + return pulse;
  225 + }
  226 +
  227 + public void setPulse(int pulse) {
  228 + this.pulse = pulse;
  229 + }
  230 +
  231 + public int getBreath_rate() {
  232 + return breath_rate;
  233 + }
  234 +
  235 + public void setBreath_rate(int breath_rate) {
  236 + this.breath_rate = breath_rate;
  237 + }
  238 +
  239 + public float getAtmos_pressure() {
  240 + return atmos_pressure;
  241 + }
  242 +
  243 + public void setAtmos_pressure(float atmos_pressure) {
  244 + this.atmos_pressure = atmos_pressure;
  245 + }
  246 +
  247 + public float getLCA() {
  248 + return LCA;
  249 + }
  250 +
  251 + public void setLCA(float LCA) {
  252 + this.LCA = LCA;
  253 + }
  254 +
  255 + public float getRCA() {
  256 + return RCA;
  257 + }
  258 +
  259 + public void setRCA(float RCA) {
  260 + this.RCA = RCA;
  261 + }
  262 +
  263 + public float getLAC() {
  264 + return LAC;
  265 + }
  266 +
  267 + public void setLAC(float LAC) {
  268 + this.LAC = LAC;
  269 + }
  270 +
  271 + public float getRAC() {
  272 + return RAC;
  273 + }
  274 +
  275 + public void setRAC(float RAC) {
  276 + this.RAC = RAC;
  277 + }
  278 +
  279 + public float getABD() {
  280 + return ABD;
  281 + }
  282 +
  283 + public void setABD(float ABD) {
  284 + this.ABD = ABD;
  285 + }
  286 +
  287 + public float getTemp_sum() {
  288 + return temp_sum;
  289 + }
  290 +
  291 + public void setTemp_sum(float temp_sum) {
  292 + this.temp_sum = temp_sum;
  293 + }
  294 +
  295 + public int getStable() {
  296 + return stable;
  297 + }
  298 +
  299 + public void setStable(int stable) {
  300 + this.stable = stable;
  301 + }
  302 +
  303 + public String getMd5() {
  304 + return md5;
  305 + }
  306 +
  307 + public void setMd5(String md5) {
  308 + this.md5 = md5;
  309 + }
  310 +
  311 + public int getCreate_by() {
  312 + return create_by;
  313 + }
  314 +
  315 + public void setCreate_by(int create_by) {
  316 + this.create_by = create_by;
  317 + }
  318 +
  319 + public String getMachine_num() {
  320 + return machine_num;
  321 + }
  322 +
  323 + public void setMachine_num(String machine_num) {
  324 + this.machine_num = machine_num;
  325 + }
  326 +
  327 + public String getT0() {
  328 + return T0;
  329 + }
  330 +
  331 + public void setT0(String t0) {
  332 + T0 = t0;
  333 + }
  334 +
  335 + public String getT1() {
  336 + return T1;
  337 + }
  338 +
  339 + public void setT1(String t1) {
  340 + T1 = t1;
  341 + }
  342 +
  343 + public String getT2() {
  344 + return T2;
  345 + }
  346 +
  347 + public void setT2(String t2) {
  348 + T2 = t2;
  349 + }
  350 +
  351 + public String getT3() {
  352 + return T3;
  353 + }
  354 +
  355 + public void setT3(String t3) {
  356 + T3 = t3;
  357 + }
  358 +
  359 + public String getT4() {
  360 + return T4;
  361 + }
  362 +
  363 + public void setT4(String t4) {
  364 + T4 = t4;
  365 + }
  366 +
  367 + public String getConclusion() {
  368 + return conclusion;
  369 + }
  370 +
  371 + public void setConclusion(String conclusion) {
  372 + this.conclusion = conclusion;
  373 + }
  374 +
  375 + public float getScore() {
  376 + return score;
  377 + }
  378 +
  379 + public void setScore(float score) {
  380 + this.score = score;
  381 + }
  382 +
  383 +
  384 + public int getCompany_id() {
  385 + return company_id;
  386 + }
  387 +
  388 + public void setCompany_id(int company_id) {
  389 + this.company_id = company_id;
  390 + }
  391 +
  392 + public int getStatus() {
  393 + return status;
  394 + }
  395 +
  396 + public void setStatus(int status) {
  397 + this.status = status;
  398 + }
  399 +}
  1 +package com.xkl.domain;
  2 +
  3 +import org.hibernate.annotations.Cascade;
  4 +
  5 +import javax.persistence.*;
  6 +
  7 +/**
  8 + * 用户数据的domain类
  9 + */
  10 +@Entity
  11 +@Table(name = "xkl_amp_report_detail")
  12 +public class AMPReportDetail {
  13 +
  14 + //自增id
  15 + @Id
  16 + @Column(name = "id")
  17 + @GeneratedValue(strategy = GenerationType.IDENTITY)
  18 + private long id;
  19 +
  20 + // 报告id
  21 + @Column(name = "report_id")
  22 + private int reportId;
  23 +
  24 + // 指标id
  25 + @Column(name = "item_id")
  26 + private int itemId;
  27 +
  28 + // 指标值
  29 + @Column(name = "item_value")
  30 + private float itemValue;
  31 +
  32 +
  33 + // 0, normal; 1, lower; 2, higher.
  34 + @Column(name = "status")
  35 + private int status;
  36 +
  37 + public long getId() {
  38 + return id;
  39 + }
  40 +
  41 + public void setId(long id) {
  42 + this.id = id;
  43 + }
  44 +
  45 + public int getReportId() {
  46 + return reportId;
  47 + }
  48 +
  49 + public void setReportId(int reportId) {
  50 + this.reportId = reportId;
  51 + }
  52 +
  53 + public int getItemId() {
  54 + return itemId;
  55 + }
  56 +
  57 + public void setItemId(int itemId) {
  58 + this.itemId = itemId;
  59 + }
  60 +
  61 + public float getItemValue() {
  62 + return itemValue;
  63 + }
  64 +
  65 + public void setItemValue(float itemValue) {
  66 + this.itemValue = itemValue;
  67 + }
  68 +
  69 + public int getStatus() {
  70 + return status;
  71 + }
  72 +
  73 + public void setStatus(int status) {
  74 + this.status = status;
  75 + }
  76 +}
  1 +package com.xkl.domain;
  2 +
  3 +import javax.persistence.Column;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.Id;
  6 +import javax.persistence.Table;
  7 +
  8 +/**
  9 + * 用户数据的domain类
  10 + */
  11 +@Entity
  12 +@Table(name = "xkl_admin")
  13 +public class Admin {
  14 + //用户id
  15 + @Id
  16 + @Column(name = "id")
  17 + private long id;
  18 +
  19 + //账号
  20 + @Column(name = "account")
  21 + private String account;
  22 +
  23 + //密码
  24 + @Column(name = "pwd")
  25 + private String pwd;
  26 +
  27 + //账号类型
  28 + @Column(name = "type")
  29 + private int type;
  30 +
  31 +
  32 + //公司id
  33 + @Column(name = "coid")
  34 + private int coid;
  35 +
  36 + //备注
  37 + @Column(name = "note")
  38 + private String note;
  39 +
  40 +
  41 + //状态
  42 + @Column(name = "status")
  43 + private int status;
  44 +
  45 + public long getId() {
  46 + return id;
  47 + }
  48 +
  49 + public void setId(long id) {
  50 + this.id = id;
  51 + }
  52 +
  53 + public String getAccount() {
  54 + return account;
  55 + }
  56 +
  57 + public void setAccount(String account) {
  58 + this.account = account;
  59 + }
  60 +
  61 + public String getPwd() {
  62 + return pwd;
  63 + }
  64 +
  65 + public void setPwd(String pwd) {
  66 + this.pwd = pwd;
  67 + }
  68 +
  69 + public int getType() {
  70 + return type;
  71 + }
  72 +
  73 + public void setType(int type) {
  74 + this.type = type;
  75 + }
  76 +
  77 + public int getCoid() {
  78 + return coid;
  79 + }
  80 +
  81 + public void setCoid(int coid) {
  82 + this.coid = coid;
  83 + }
  84 +
  85 + public String getNote() {
  86 + return note;
  87 + }
  88 +
  89 + public void setNote(String note) {
  90 + this.note = note;
  91 + }
  92 +
  93 + public int getStatus() {
  94 + return status;
  95 + }
  96 +
  97 + public void setStatus(int status) {
  98 + this.status = status;
  99 + }
  100 +}
  1 +package com.xkl.domain;
  2 +
  3 +import java.util.List;
  4 +import com.xkl.config.ResultStatus;
  5 +
  6 +/**
  7 + * 用于报告处理的中间数据类。
  8 + * Created by zhao yue on 2016/11/13.
  9 + */
  10 +public class ReportData {
  11 + private AMPReport ampReport;
  12 + private List<AMPReportDetail> rpDetailList;
  13 +// ResultStatus resStatus;
  14 +
  15 +// public ReportData(ResultStatus resStatus) {
  16 +// this.resStatus = resStatus;
  17 +// }
  18 +
  19 + public AMPReport getAmpReport() {
  20 + return ampReport;
  21 + }
  22 +
  23 + public void setAmpReport(AMPReport ampReport) {
  24 + this.ampReport = ampReport;
  25 + }
  26 +
  27 + public List<AMPReportDetail> getRpDetailList() {
  28 + return rpDetailList;
  29 + }
  30 +
  31 + public void setRpDetailList(List<AMPReportDetail> rpDetailList) {
  32 + this.rpDetailList = rpDetailList;
  33 + }
  34 +
  35 +// public ResultStatus getResStatus() {
  36 +// return resStatus;
  37 +// }
  38 +//
  39 +// public void setResStatus(ResultStatus resStatus) {
  40 +// this.resStatus = resStatus;
  41 +// }
  42 +}
  1 +package com.xkl.domain;
  2 +
  3 +import javax.persistence.Column;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.Id;
  6 +import javax.persistence.Table;
  7 +
  8 +/**
  9 + * 指标数据标准的domain类
  10 + */
  11 +@Entity
  12 +@Table(name = "xkl_amp_report_meta_items")
  13 +public class ReportMetaItem {
  14 + // id
  15 + @Id
  16 + @Column(name = "id")
  17 + private long id;
  18 +
  19 + // item_id
  20 + @Column(name = "item_id")
  21 + private int item_id;
  22 +
  23 + // type
  24 + @Column(name = "type")
  25 + private String type;
  26 +
  27 + // title
  28 + @Column(name = "title")
  29 + private String title;
  30 +
  31 + // standard_low_male
  32 + @Column(name = "standard_low_male")
  33 + private float standard_low_male;
  34 +
  35 + // standard_high_male
  36 + @Column(name = "standard_high_male")
  37 + private float standard_high_male;
  38 +
  39 + // standard_low_female
  40 + @Column(name = "standard_low_female")
  41 + private float standard_low_female;
  42 +
  43 + // standard_high_female
  44 + @Column(name = "standard_high_female")
  45 + private float standard_high_female;
  46 +
  47 + // explain_low
  48 + @Column(name = "explain_low")
  49 + private String explain_low;
  50 +
  51 + // explain_high
  52 + @Column(name = "explain_high")
  53 + private String explain_high;
  54 +
  55 + // explain_normal
  56 + @Column(name = "explain_normal")
  57 + private String explain_normal;
  58 +
  59 + public long getId() {
  60 + return id;
  61 + }
  62 +
  63 + public void setId(long id) {
  64 + this.id = id;
  65 + }
  66 +
  67 + public int getItem_id() {
  68 + return item_id;
  69 + }
  70 +
  71 + public void setItem_id(int item_id) {
  72 + this.item_id = item_id;
  73 + }
  74 +
  75 + public String getType() {
  76 + return type;
  77 + }
  78 +
  79 + public void setType(String type) {
  80 + this.type = type;
  81 + }
  82 +
  83 + public String getTitle() {
  84 + return title;
  85 + }
  86 +
  87 + public void setTitle(String title) {
  88 + this.title = title;
  89 + }
  90 +
  91 + public float getStandard_low_male() {
  92 + return standard_low_male;
  93 + }
  94 +
  95 + public void setStandard_low_male(float standard_low_male) {
  96 + this.standard_low_male = standard_low_male;
  97 + }
  98 +
  99 + public float getStandard_high_male() {
  100 + return standard_high_male;
  101 + }
  102 +
  103 + public void setStandard_high_male(float standard_high_male) {
  104 + this.standard_high_male = standard_high_male;
  105 + }
  106 +
  107 + public float getStandard_low_female() {
  108 + return standard_low_female;
  109 + }
  110 +
  111 + public void setStandard_low_female(float standard_low_female) {
  112 + this.standard_low_female = standard_low_female;
  113 + }
  114 +
  115 + public float getStandard_high_female() {
  116 + return standard_high_female;
  117 + }
  118 +
  119 + public void setStandard_high_female(float standard_high_female) {
  120 + this.standard_high_female = standard_high_female;
  121 + }
  122 +
  123 + public String getExplain_low() {
  124 + return explain_low;
  125 + }
  126 +
  127 + public void setExplain_low(String explain_low) {
  128 + this.explain_low = explain_low;
  129 + }
  130 +
  131 + public String getExplain_high() {
  132 + return explain_high;
  133 + }
  134 +
  135 + public void setExplain_high(String explain_high) {
  136 + this.explain_high = explain_high;
  137 + }
  138 +
  139 + public String getExplain_normal() {
  140 + return explain_normal;
  141 + }
  142 +
  143 + public void setExplain_normal(String explain_normal) {
  144 + this.explain_normal = explain_normal;
  145 + }
  146 +}
  1 +package com.xkl.domain;
  2 +
  3 +import javax.persistence.Column;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.Id;
  6 +import javax.persistence.Table;
  7 +
  8 +/**
  9 + * 用户数据的domain类
  10 + */
  11 +@Entity
  12 +@Table(name = "xkl_upsoft_version")
  13 +public class UpSoftVersion {
  14 + //用户id
  15 + @Id
  16 + @Column(name = "id")
  17 + private long id;
  18 +
  19 + //版本号
  20 + @Column(name = "version_num")
  21 + private int version_num;
  22 +
  23 + //版本名称
  24 + @Column(name = "name")
  25 + private String name;
  26 +
  27 + //版本详情
  28 + @Column(name = "note")
  29 + private String note;
  30 +
  31 + public long getId() {
  32 + return id;
  33 + }
  34 +
  35 + public void setId(long id) {
  36 + this.id = id;
  37 + }
  38 +
  39 + public int getVersion_num() {
  40 + return version_num;
  41 + }
  42 +
  43 + public void setVersion_num(int version_num) {
  44 + this.version_num = version_num;
  45 + }
  46 +
  47 + public String getName() {
  48 + return name;
  49 + }
  50 +
  51 + public void setName(String name) {
  52 + this.name = name;
  53 + }
  54 +
  55 + public String getNote() {
  56 + return note;
  57 + }
  58 +
  59 + public void setNote(String note) {
  60 + this.note = note;
  61 + }
  62 +}
@@ -13,11 +13,11 @@ import javax.persistence.*; @@ -13,11 +13,11 @@ import javax.persistence.*;
13 public class User { 13 public class User {
14 //用户名 14 //用户名
15 @Column(name = "login_account") 15 @Column(name = "login_account")
16 - private String username; 16 + private String loginAccount;
17 17
18 //密码 18 //密码
19 @Column(name = "login_pwd") 19 @Column(name = "login_pwd")
20 - private String password; 20 + private String loginPwd;
21 21
22 //用户id 22 //用户id
23 @Id 23 @Id
@@ -32,5 +32,54 @@ public class User { @@ -32,5 +32,54 @@ public class User {
32 private boolean status; 32 private boolean status;
33 33
34 @Column(name = "member_id") 34 @Column(name = "member_id")
35 - private long member_id; 35 +
  36 + private int memberId;
  37 +
  38 + public String getLoginAccount() {
  39 + return loginAccount;
  40 + }
  41 +
  42 + public void setLoginAccount(String loginAccount) {
  43 + this.loginAccount = loginAccount;
  44 + }
  45 +
  46 + public String getLoginPwd() {
  47 + return loginPwd;
  48 + }
  49 +
  50 + public void setLoginPwd(String loginPwd) {
  51 + this.loginPwd = loginPwd;
  52 + }
  53 +
  54 + public long getId() {
  55 + return id;
  56 + }
  57 +
  58 + public void setId(long id) {
  59 + this.id = id;
  60 + }
  61 +
  62 + public String getSalt() {
  63 + return salt;
  64 + }
  65 +
  66 + public void setSalt(String salt) {
  67 + this.salt = salt;
  68 + }
  69 +
  70 + public boolean isStatus() {
  71 + return status;
  72 + }
  73 +
  74 + public void setStatus(boolean status) {
  75 + this.status = status;
  76 + }
  77 +
  78 + public int getMemberId() {
  79 + return memberId;
  80 + }
  81 +
  82 + public void setMemberId(int memberId) {
  83 + this.memberId = memberId;
  84 + }
36 } 85 }
  1 +package com.xkl.model;
  2 +
  3 +
  4 +public class ReportIdModel {
  5 +
  6 + // Report Id
  7 + private int reportId;
  8 +
  9 +
  10 + public ReportIdModel(int reportId) {
  11 + this.reportId = reportId;
  12 + }
  13 +
  14 + public int getReportId() {
  15 + return reportId;
  16 + }
  17 +
  18 + public void setReportId(int reportId) {
  19 + this.reportId = reportId;
  20 + }
  21 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.AMPMachine;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +
  6 +/**
  7 + * AMPMachine 类的CRUD操作
  8 + *
  9 + * @see AMPMachine
  10 + */
  11 +public interface AMPMachineRepository extends CrudRepository<AMPMachine, Long> {
  12 +
  13 + public AMPMachine findBySecretKey(String secretKey);
  14 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.Admin;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +
  6 +/**
  7 + * Admin类的CRUD操作
  8 + * @see Admin
  9 + */
  10 +public interface AdminRepository extends CrudRepository<Admin, Long> {
  11 +
  12 + public Admin findByAccount(String account);
  13 + public Admin findById(long id);
  14 +
  15 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.AMPReport;
  4 +import com.xkl.domain.AMPReportDetail;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * AMPReportDetail类的CRUD操作
  11 + *
  12 + * @see AMPReportDetail
  13 + */
  14 +public interface ReportDetailRepository extends CrudRepository<AMPReportDetail, Long> {
  15 + public List<AMPReportDetail> findByReportId(int reportId);
  16 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.ReportMetaItem;
  4 +import com.xkl.domain.User;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +
  7 +/**
  8 + * ReportMetaItems类的CRUD操作
  9 + * @see User
  10 + */
  11 +public interface ReportMetaItemsRepository extends CrudRepository<ReportMetaItem, Long> {
  12 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.AMPReport;
  4 +import com.xkl.domain.Admin;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +
  7 +/**
  8 + * AMPReport类的CRUD操作
  9 + *
  10 + * @see AMPReport
  11 + */
  12 +public interface ReportRepository extends CrudRepository<AMPReport, Long> {
  13 + public AMPReport findByMd5(String md5);
  14 +
  15 + public AMPReport findById(int id);
  16 +
  17 +}
  1 +package com.xkl.repository;
  2 +
  3 +import com.xkl.domain.UpSoftVersion;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * User类的CRUD操作
  11 + *
  12 + * @see UpSoftVersion
  13 + */
  14 +public interface UpSoftVersionRepository extends CrudRepository<UpSoftVersion, Long> {
  15 + @Query("select upsoft from UpSoftVersion upsoft")
  16 + public List<UpSoftVersion> findAllVersion();
  17 +}
@@ -9,5 +9,5 @@ import org.springframework.data.repository.CrudRepository; @@ -9,5 +9,5 @@ import org.springframework.data.repository.CrudRepository;
9 */ 9 */
10 public interface UserRepository extends CrudRepository<User, Long> { 10 public interface UserRepository extends CrudRepository<User, Long> {
11 11
12 - public User findByUsername(String username); 12 + public User findByLoginAccount(String username);
13 } 13 }
  1 +package com.xkl.service;
  2 +
  3 +import com.xkl.domain.Admin;
  4 +import com.xkl.domain.ReportData;
  5 +import com.xkl.domain.User;
  6 +
  7 +/**
  8 + * Created by zhao yue on 2016/11/26.
  9 + */
  10 +public interface IReportService {
  11 + public ReportData parseReport(String reportJson, String md5);
  12 + public int saveReport(ReportData report, Admin admin, User user);
  13 +
  14 +}
  1 +package com.xkl.service;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.xkl.config.Constants;
  5 +import com.xkl.domain.*;
  6 +import com.xkl.repository.ReportDetailRepository;
  7 +import com.xkl.repository.ReportMetaItemsRepository;
  8 +import com.xkl.repository.ReportRepository;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.sql.Timestamp;
  13 +import java.util.*;
  14 +
  15 +/**
  16 + * Created by zhao yue on 2016/11/13.
  17 + */
  18 +@Service
  19 +public class ReportService implements IReportService {
  20 + @Autowired
  21 + private ReportMetaItemsRepository reportMetaItemsRepository;
  22 + @Autowired
  23 + private ReportRepository reportRepository;
  24 +
  25 + @Autowired
  26 + private ReportDetailRepository reportDetailRepository;
  27 +
  28 + private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>();
  29 +
  30 + /*
  31 + 验证md5
  32 + 获取report
  33 + 获取detail
  34 + 评判detail
  35 + 验证member
  36 + 获取admin
  37 + */
  38 + // 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。
  39 + // 125项目,改为float类型。
  40 + public ReportData parseReport(String reportJson, String md5) {
  41 + ReportData reportData = new ReportData();
  42 + AMPReport ampReport = new AMPReport();
  43 + List<AMPReportDetail> detailList = new ArrayList<>();
  44 + int sex;
  45 +
  46 + /*
  47 + * 2. 获取report基础信息
  48 + */
  49 + try {
  50 + JSONObject rpJson = JSONObject.parseObject(reportJson);
  51 + sex = rpJson.getInteger("sex").intValue();
  52 + ampReport.setReport(rpJson.getString("name"),
  53 + rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
  54 + Timestamp.valueOf(rpJson.getString("report_date")),
  55 + new Timestamp(System.currentTimeMillis()),
  56 + rpJson.getString("account"),///
  57 + rpJson.getInteger("sex").intValue(),///
  58 + rpJson.getInteger("age").intValue(),
  59 + rpJson.getInteger("weight").intValue(),
  60 + rpJson.getInteger("pulse").intValue(),
  61 + rpJson.getInteger("respiratory_rate").intValue(),
  62 + rpJson.getFloat("atmospheric_pressure").floatValue(),
  63 + rpJson.getFloat("LCA").floatValue(),
  64 + rpJson.getFloat("RCA").floatValue(),
  65 + rpJson.getFloat("LAC").floatValue(),
  66 + rpJson.getFloat("RAC").floatValue(),
  67 + rpJson.getFloat("ABD").floatValue(),
  68 + rpJson.getFloat("total").floatValue(),
  69 + rpJson.getInteger("stable").intValue(),
  70 + md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
  71 + /*
  72 + * 3. 获取detail信息,id,float类型
  73 + */
  74 + JSONObject rpDetails = rpJson.getJSONObject("detail");
  75 + for (int item_id = 1; item_id <= 125; item_id++) {
  76 + float val = rpDetails.getFloat(String.valueOf(item_id)).floatValue();
  77 + AMPReportDetail detail = new AMPReportDetail();
  78 + detail.setItemValue(val);
  79 + detail.setItemId(item_id);
  80 + detailList.add(detail);
  81 + }
  82 + } catch (Exception e) {
  83 + return null;
  84 + }
  85 + markItemStatus(sex, detailList);
  86 + reportData.setAmpReport(ampReport);
  87 + reportData.setRpDetailList(detailList);
  88 + return reportData;
  89 + }
  90 +
  91 + /*
  92 + * 存储报告
  93 + */
  94 + public int saveReport(ReportData report, Admin admin, User user) {
  95 + report.getAmpReport().setCreate_by((int) admin.getId());
  96 + report.getAmpReport().setCompany_id(admin.getCoid());
  97 + report.getAmpReport().setMember_id(user.getMemberId());
  98 + AMPReport ampReport = reportRepository.save(report.getAmpReport());
  99 + for (AMPReportDetail detail : report.getRpDetailList()) {
  100 + detail.setReportId(ampReport.getId());
  101 + }
  102 + reportDetailRepository.save(report.getRpDetailList());
  103 + return ampReport.getId();
  104 + }
  105 +
  106 + /*
  107 + * 判断detail是正常,高于标准或低于标准。
  108 + */
  109 + private void markItemStatus(int sex, List<AMPReportDetail> detailList) {
  110 + // load ReportMetaItems into memory.
  111 + synchronized (this) {
  112 + if (rpMetaItemMap.size() == 0) {
  113 + Iterator<ReportMetaItem> rpMetaIter = reportMetaItemsRepository.findAll().iterator();
  114 + while (rpMetaIter.hasNext()) {
  115 + ReportMetaItem rpMetaItem = rpMetaIter.next();
  116 + rpMetaItemMap.put(rpMetaItem.getItem_id(), rpMetaItem);
  117 + }
  118 + }
  119 + }
  120 + // mark status
  121 + for (AMPReportDetail detail : detailList) {
  122 + float lowSt;
  123 + float highSt;
  124 + // get standard
  125 + if (sex == Constants.MALE) { // male
  126 + lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_male();
  127 + highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_male();
  128 + } else { // female
  129 + lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_female();
  130 + highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_female();
  131 + }
  132 + int status;
  133 + if (detail.getItemValue() < lowSt) {
  134 + status = Constants.LOWER;
  135 + } else if (detail.getItemValue() > highSt) {
  136 + status = Constants.HIGHER;
  137 + } else {
  138 + status = Constants.NORMAL;
  139 + }
  140 + detail.setStatus(status);
  141 + }
  142 + }
  143 +}
@@ -5,13 +5,14 @@ server.port=8090 @@ -5,13 +5,14 @@ server.port=8090
5 #server.ssl.key-password = xkl2016 5 #server.ssl.key-password = xkl2016
6 6
7 #MySQL 7 #MySQL
8 -spring.datasource.url=jdbc:mysql://localhost:3306/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true  
9 -spring.datasource.username=root  
10 -spring.datasource.password=fyqmysql 8 +spring.datasource.url=jdbc:mysql://db.hanhezy.com:4096/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true
  9 +spring.datasource.username=hanhe
  10 +spring.datasource.password=HANhetest2016
  11 +
11 12
12 #Redis 13 #Redis
13 spring.redis.host=127.0.0.1 14 spring.redis.host=127.0.0.1
14 -spring.redis.password=foobared 15 +#spring.redis.password=foobared
15 #spring.redis.host=r-m5e7cedd3124afd4.redis.rds.aliyuncs.com 16 #spring.redis.host=r-m5e7cedd3124afd4.redis.rds.aliyuncs.com
16 #spring.redis.password=r-m5e7cedd3124afd4:XIkaiLURedis2016 17 #spring.redis.password=r-m5e7cedd3124afd4:XIkaiLURedis2016
17 18
  1 +server.port=8090
  2 +
  3 +#server.ssl.key-store = ${user.home}/.keystore
  4 +#server.ssl.key-store-password = xkl2016
  5 +#server.ssl.key-password = xkl2016
  6 +
  7 +#MySQL
  8 +spring.datasource.url=jdbc:mysql://localhost:3306/hanhe_test?useUnicode=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=round&autoReconnect=true
  9 +spring.datasource.username=root
  10 +spring.datasource.password=fyqmysql
  11 +
  12 +#Redis
  13 +spring.redis.host=127.0.0.1
  14 +spring.redis.password=foobared
  15 +#spring.redis.host=r-m5e7cedd3124afd4.redis.rds.aliyuncs.com
  16 +#spring.redis.password=r-m5e7cedd3124afd4:XIkaiLURedis2016
  17 +
  18 +spring.redis.port=6379
@@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
27 if (url && url.length > 1) { 27 if (url && url.length > 1) {
28 url = decodeURIComponent(url[1]); 28 url = decodeURIComponent(url[1]);
29 } else { 29 } else {
30 - url = "http://localhost:8090/api-docs"; 30 + url = "http://127.0.0.1:8090/api-docs";
31 } 31 }
32 window.swaggerUi = new SwaggerUi({ 32 window.swaggerUi = new SwaggerUi({
33 url: url, 33 url: url,