Authored by zhaoyue

FIX some conflicts

@@ -25,7 +25,6 @@ public interface Constants { @@ -25,7 +25,6 @@ public interface Constants {
25 */ 25 */
26 String AUTHORIZATION = "authorization"; 26 String AUTHORIZATION = "authorization";
27 27
28 -  
29 /** 28 /**
30 * 单项打分标准 29 * 单项打分标准
31 */ 30 */
@@ -27,7 +27,7 @@ public class SwaggerConfig { @@ -27,7 +27,7 @@ public class SwaggerConfig {
27 @Bean 27 @Bean
28 public SwaggerSpringMvcPlugin customImplementation() { 28 public SwaggerSpringMvcPlugin customImplementation() {
29 return new SwaggerSpringMvcPlugin(this.springSwaggerConfig) 29 return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
30 - .apiInfo(new ApiInfo("Spring RESTful Authorization Demo Api", 30 + .apiInfo(new ApiInfo("xkl RESTful Api",
31 null, null, null, null, null)). 31 null, null, null, null, null)).
32 //将Timestamp类型全部转为Long类型 32 //将Timestamp类型全部转为Long类型
33 directModelSubstitute(Timestamp.class, Long.class); 33 directModelSubstitute(Timestamp.class, Long.class);
1 package com.xkl.controller.uploadsoft; 1 package com.xkl.controller.uploadsoft;
2 2
3 -import com.wordnik.swagger.annotations.ApiImplicitParam;  
4 -import com.wordnik.swagger.annotations.ApiImplicitParams;  
5 -import com.wordnik.swagger.annotations.ApiOperation; 3 +import com.wordnik.swagger.annotations.*;
6 import com.xkl.authorization.annotation.Authorization; 4 import com.xkl.authorization.annotation.Authorization;
7 import com.xkl.authorization.annotation.CurrentAdmin; 5 import com.xkl.authorization.annotation.CurrentAdmin;
8 import com.xkl.authorization.annotation.CurrentUser; 6 import com.xkl.authorization.annotation.CurrentUser;
9 import com.xkl.authorization.manager.ITokenManager; 7 import com.xkl.authorization.manager.ITokenManager;
10 import com.xkl.authorization.model.TokenModel; 8 import com.xkl.authorization.model.TokenModel;
  9 +import com.xkl.config.Constants;
11 import com.xkl.config.ResultStatus; 10 import com.xkl.config.ResultStatus;
12 import com.xkl.domain.AMPMachine; 11 import com.xkl.domain.AMPMachine;
13 import com.xkl.domain.Admin; 12 import com.xkl.domain.Admin;
14 import com.xkl.model.ResultModel; 13 import com.xkl.model.ResultModel;
15 import com.xkl.repository.AMPMachineRepository; 14 import com.xkl.repository.AMPMachineRepository;
16 import com.xkl.repository.AdminRepository; 15 import com.xkl.repository.AdminRepository;
  16 +import org.hibernate.validator.constraints.SafeHtml;
17 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.http.HttpStatus; 18 import org.springframework.http.HttpStatus;
19 import org.springframework.http.ResponseEntity; 19 import org.springframework.http.ResponseEntity;
@@ -28,7 +28,8 @@ import org.springframework.web.bind.annotation.RestController; @@ -28,7 +28,8 @@ import org.springframework.web.bind.annotation.RestController;
28 * 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射 28 * 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射
29 */ 29 */
30 @RestController 30 @RestController
31 -@RequestMapping("/upsoftaccount") 31 +@Api("AMP报告上传软件客户端登录及退出接口")
  32 +@RequestMapping("/upsoft/account")
32 public class UpSoftAccountController { 33 public class UpSoftAccountController {
33 34
34 @Autowired 35 @Autowired
@@ -41,7 +42,8 @@ public class UpSoftAccountController { @@ -41,7 +42,8 @@ public class UpSoftAccountController {
41 private static final String UPSOFT_TOKEN_PREFIX = "UPSOFT_TOKEN"; 42 private static final String UPSOFT_TOKEN_PREFIX = "UPSOFT_TOKEN";
42 43
43 @RequestMapping(method = RequestMethod.POST) 44 @RequestMapping(method = RequestMethod.POST)
44 - @ApiOperation(value = "报告上传软件登录") 45 + @ApiOperation(value = "报告上传软件登录", notes = "login")
  46 +
45 public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password 47 public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password
46 , @RequestParam String ampserial, @RequestParam String ampkey) { 48 , @RequestParam String ampserial, @RequestParam String ampkey) {
47 Assert.notNull(account, "account can not be empty"); 49 Assert.notNull(account, "account can not be empty");
@@ -72,7 +74,7 @@ public class UpSoftAccountController { @@ -72,7 +74,7 @@ public class UpSoftAccountController {
72 74
73 @RequestMapping(method = RequestMethod.DELETE) 75 @RequestMapping(method = RequestMethod.DELETE)
74 @Authorization 76 @Authorization
75 - @ApiOperation(value = "报告上传软件退出登录") 77 + @ApiOperation(value = "报告上传软件注销")
76 @ApiImplicitParams({ 78 @ApiImplicitParams({
77 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), 79 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
78 }) 80 })
@@ -81,9 +83,9 @@ public class UpSoftAccountController { @@ -81,9 +83,9 @@ public class UpSoftAccountController {
81 return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); 83 return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
82 } 84 }
83 85
84 - @RequestMapping(value = "/modpwd", method = RequestMethod.PUT) 86 + @RequestMapping(value = "/upsoft/modpwd", method = RequestMethod.PUT)
85 @Authorization 87 @Authorization
86 - @ApiOperation(value = "报告上传软件修改用户密码") 88 + @ApiOperation(value = "报告上传软件修改密码")
87 @ApiImplicitParams({ 89 @ApiImplicitParams({
88 @ApiImplicitParam(name = "authorization", value = "请以如下格式输入登录返回信息:adminId_tokens", required = true, dataType = "string", paramType = "header"), 90 @ApiImplicitParam(name = "authorization", value = "请以如下格式输入登录返回信息:adminId_tokens", required = true, dataType = "string", paramType = "header"),
89 }) 91 })
@@ -30,7 +30,7 @@ import java.util.List; @@ -30,7 +30,7 @@ import java.util.List;
30 * 上传报告及删除报告接口。 30 * 上传报告及删除报告接口。
31 */ 31 */
32 @RestController 32 @RestController
33 -@RequestMapping("/upsoftreport") 33 +@RequestMapping("/upsoft/report")
34 public class UpSoftReportController { 34 public class UpSoftReportController {
35 35
36 @Autowired 36 @Autowired
@@ -45,13 +45,6 @@ public class UpSoftReportController { @@ -45,13 +45,6 @@ public class UpSoftReportController {
45 @Autowired 45 @Autowired
46 private ReportDetailRepository reportDetailRepository; 46 private ReportDetailRepository reportDetailRepository;
47 47
48 - // 存储报告相关md5,防止重复上传已存在报告,防止重复上传错误报告。  
49 - private RedisTemplate<String, String> redis;  
50 -  
51 - @Autowired  
52 - public void setRedis(RedisTemplate redis) {  
53 - this.redis = redis;  
54 - }  
55 48
56 @Autowired 49 @Autowired
57 private UserRepository userRepository; 50 private UserRepository userRepository;
@@ -67,59 +60,8 @@ public class UpSoftReportController { @@ -67,59 +60,8 @@ public class UpSoftReportController {
67 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), 60 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
68 }) 61 })
69 public ResponseEntity<ResultModel> save(@CurrentAdmin Admin admin, @RequestParam String json_report) { 62 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 - } 63 + // 其中json_report格式为上传软件上传上来的原始report格式。
  64 + return reportService.save(admin, json_report);
123 } 65 }
124 66
125 @RequestMapping(method = RequestMethod.DELETE) 67 @RequestMapping(method = RequestMethod.DELETE)
@@ -130,24 +72,7 @@ public class UpSoftReportController { @@ -130,24 +72,7 @@ public class UpSoftReportController {
130 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), 72 @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
131 }) 73 })
132 public ResponseEntity<ResultModel> delete(@CurrentAdmin Admin admin, @RequestParam long report_id) { 74 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 - 75 + return reportService.delete(admin, report_id);
151 } 76 }
152 77
153 } 78 }
@@ -21,8 +21,8 @@ import java.util.List; @@ -21,8 +21,8 @@ import java.util.List;
21 * AMP报告上传软件客户端获取最新软件版本。 21 * AMP报告上传软件客户端获取最新软件版本。
22 */ 22 */
23 @RestController 23 @RestController
24 -@RequestMapping("/upsoftversion")  
25 -public class SoftVersionController { 24 +@RequestMapping("/upsoft/version")
  25 +public class UpSoftVerController {
26 26
27 @Autowired 27 @Autowired
28 private UpSoftVersionRepository upSoftVersionRepository; 28 private UpSoftVersionRepository upSoftVersionRepository;
@@ -3,12 +3,21 @@ package com.xkl.service; @@ -3,12 +3,21 @@ package com.xkl.service;
3 import com.xkl.domain.Admin; 3 import com.xkl.domain.Admin;
4 import com.xkl.domain.ReportData; 4 import com.xkl.domain.ReportData;
5 import com.xkl.domain.User; 5 import com.xkl.domain.User;
  6 +import com.xkl.model.ResultModel;
  7 +import org.springframework.http.ResponseEntity;
  8 +import org.springframework.web.bind.annotation.RequestParam;
6 9
7 /** 10 /**
8 * Created by zhao yue on 2016/11/26. 11 * Created by zhao yue on 2016/11/26.
9 */ 12 */
10 public interface IReportService { 13 public interface IReportService {
11 - public ReportData parseReport(String reportJson, String md5);  
12 - public int saveReport(ReportData report, Admin admin, User user); 14 +// public ReportData parseReport(String reportJson, String md5);
  15 +
  16 +// public int saveReport(ReportData report, Admin admin, User user);
  17 +
  18 + public ResponseEntity<ResultModel> delete(Admin admin, long report_id);
  19 + public ResponseEntity<ResultModel> save(Admin admin, String json_report);
  20 +
  21 +
13 22
14 } 23 }
@@ -2,11 +2,19 @@ package com.xkl.service; @@ -2,11 +2,19 @@ package com.xkl.service;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.xkl.config.Constants; 4 import com.xkl.config.Constants;
  5 +import com.xkl.config.ResultStatus;
5 import com.xkl.domain.*; 6 import com.xkl.domain.*;
  7 +import com.xkl.model.ReportIdModel;
  8 +import com.xkl.model.ResultModel;
6 import com.xkl.repository.ReportDetailRepository; 9 import com.xkl.repository.ReportDetailRepository;
7 import com.xkl.repository.ReportMetaItemsRepository; 10 import com.xkl.repository.ReportMetaItemsRepository;
8 import com.xkl.repository.ReportRepository; 11 import com.xkl.repository.ReportRepository;
  12 +import com.xkl.repository.UserRepository;
  13 +import com.xkl.security.SecurityTool;
9 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.data.redis.core.RedisTemplate;
  16 +import org.springframework.http.HttpStatus;
  17 +import org.springframework.http.ResponseEntity;
10 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
11 19
12 import java.sql.Timestamp; 20 import java.sql.Timestamp;
@@ -19,15 +27,109 @@ import java.util.*; @@ -19,15 +27,109 @@ import java.util.*;
19 public class ReportService implements IReportService { 27 public class ReportService implements IReportService {
20 @Autowired 28 @Autowired
21 private ReportMetaItemsRepository reportMetaItemsRepository; 29 private ReportMetaItemsRepository reportMetaItemsRepository;
  30 +
22 @Autowired 31 @Autowired
23 private ReportRepository reportRepository; 32 private ReportRepository reportRepository;
24 33
25 @Autowired 34 @Autowired
26 private ReportDetailRepository reportDetailRepository; 35 private ReportDetailRepository reportDetailRepository;
27 36
  37 + @Autowired
  38 + private UserRepository userRepository;
  39 +
  40 + // 存储报告相关md5,防止重复上传已存在报告,防止重复上传错误报告。
  41 + private RedisTemplate<String, String> redis;
  42 +
  43 + @Autowired
  44 + public void setRedis(RedisTemplate redis) {
  45 + this.redis = redis;
  46 + }
  47 +
28 private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>(); 48 private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>();
29 49
30 /* 50 /*
  51 + * 存储报告
  52 + */
  53 + public ResponseEntity<ResultModel> save(Admin admin, String json_report) {
  54 + // 验证存在性
  55 + String reportMd5 = SecurityTool.encode("MD5", json_report);
  56 + // 验证是否有对应的会员
  57 + String reportWithNoUser = reportMd5 + "Member";
  58 + // 验证报告格式是否有问题
  59 + String reportWrongFormat = reportMd5 + "Format";
  60 + /*
  61 + * 如果已经处理过的报告,不再进行处理。
  62 + */
  63 + AMPReport report = reportRepository.findByMd5(reportMd5);
  64 + if (report != null && report.getStatus() > 0) {
  65 + // 返回,报告已存在。
  66 + return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(report.getId())), HttpStatus.OK);
  67 + } else if (redis.hasKey(reportWithNoUser)) {
  68 + // 返回,报告对应会员不存在。
  69 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
  70 + } else if (redis.hasKey(reportWrongFormat)) {
  71 + // 返回,报告格式有问题。
  72 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
  73 + }
  74 + /*
  75 + * 解析报告数据
  76 + */
  77 + ReportData reportData = parseReport(json_report, reportMd5);
  78 + /*
  79 + * 检验报告格式
  80 + */
  81 + if (reportData == null) {
  82 + redis.boundValueOps(reportWrongFormat).set("");
  83 + // 返回,报告格式有问题。
  84 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_FORMAT_ERROR), HttpStatus.NOT_FOUND);
  85 + }
  86 + /*
  87 + * 检验会员存在性
  88 + */
  89 + User user = userRepository.findByLoginAccount(reportData.getAmpReport().getAccount_str());
  90 + if (user == null) {
  91 + redis.boundValueOps(reportWithNoUser).set("");
  92 + // 返回,报告对应会员不存在。
  93 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_USER_ERROR), HttpStatus.NOT_FOUND);
  94 + }
  95 +
  96 + /*
  97 + * 存储报告
  98 + */
  99 + int reportId = save2DB(reportData, admin, user);
  100 + if (reportId > 0) {
  101 + // 返回,报告存储成功,报告id
  102 + return new ResponseEntity<>(ResultModel.ok(new ReportIdModel(reportId)), HttpStatus.OK);
  103 + } else {
  104 + // 返回,服务器存储问题。
  105 + return new ResponseEntity<>(ResultModel.error(ResultStatus.DB_ERROR), HttpStatus.NOT_FOUND);
  106 + }
  107 + }
  108 +
  109 + /*
  110 + * 操作员删除报告,只能删除该操作员自己创建的报告。
  111 + */
  112 + public ResponseEntity<ResultModel> delete(Admin admin, long report_id) {
  113 + // 1. 得到report,验证报告存在性
  114 + AMPReport report = reportRepository.findById((int) report_id);
  115 + if (report == null) {
  116 + // 报告不存在,返回
  117 + return new ResponseEntity<>(ResultModel.error(ResultStatus.REPORT_INVALID__ERROR), HttpStatus.NOT_FOUND);
  118 + }
  119 +
  120 + // 2. 验证admin
  121 + if (report.getCreate_by() != admin.getId()) {
  122 + // 非此admin创建,不能删除,返回
  123 + return new ResponseEntity<>(ResultModel.error(ResultStatus.INVALID_ADMIN_RPDEL_ERROR), HttpStatus.NOT_FOUND);
  124 + }
  125 + // 3. 删除report和detail,返回ok
  126 + reportRepository.delete(report);
  127 + List<AMPReportDetail> detailList = reportDetailRepository.findByReportId(report.getId());
  128 + reportDetailRepository.delete(detailList);
  129 + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
  130 + }
  131 +
  132 + /*
31 验证md5 133 验证md5
32 获取report 134 获取report
33 获取detail 135 获取detail
@@ -37,7 +139,7 @@ public class ReportService implements IReportService { @@ -37,7 +139,7 @@ public class ReportService implements IReportService {
37 */ 139 */
38 // 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。 140 // 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。
39 // 125项目,改为float类型。 141 // 125项目,改为float类型。
40 - public ReportData parseReport(String reportJson, String md5) { 142 + private ReportData parseReport(String reportJson, String md5) {
41 ReportData reportData = new ReportData(); 143 ReportData reportData = new ReportData();
42 AMPReport ampReport = new AMPReport(); 144 AMPReport ampReport = new AMPReport();
43 List<AMPReportDetail> detailList = new ArrayList<>(); 145 List<AMPReportDetail> detailList = new ArrayList<>();
@@ -91,11 +193,11 @@ public class ReportService implements IReportService { @@ -91,11 +193,11 @@ public class ReportService implements IReportService {
91 /* 193 /*
92 * 存储报告 194 * 存储报告
93 */ 195 */
94 - public int saveReport(ReportData report, Admin admin, User user) { 196 + private int save2DB(ReportData report, Admin admin, User user) {
95 report.getAmpReport().setCreate_by((int) admin.getId()); 197 report.getAmpReport().setCreate_by((int) admin.getId());
96 report.getAmpReport().setCompany_id(admin.getCoid()); 198 report.getAmpReport().setCompany_id(admin.getCoid());
97 report.getAmpReport().setMember_id(user.getMemberId()); 199 report.getAmpReport().setMember_id(user.getMemberId());
98 - AMPReport ampReport = reportRepository.save(report.getAmpReport()); 200 + AMPReport ampReport = reportRepository.save(report.getAmpReport());
99 for (AMPReportDetail detail : report.getRpDetailList()) { 201 for (AMPReportDetail detail : report.getRpDetailList()) {
100 detail.setReportId(ampReport.getId()); 202 detail.setReportId(ampReport.getId());
101 } 203 }