Authored by zhaoyue

Merge branch 'zhaoyue-dev' into 'master'

Zhaoyue dev



See merge request !9
git add --all src/*
git add push.sh
git add pom.xml
git commit -m "ADD code for uspih"
git push origin zhaoyue-dev4
git commit -m "ADD code for uspih "
git push origin zhaoyue-dev
git status
... ...
... ... @@ -3,6 +3,7 @@ package com.xkl.authorization.resolvers;
import com.xkl.authorization.annotation.CurrentAdmin;
import com.xkl.config.Constants;
import com.xkl.controller.uploadsoft.UpSoftAccountController;
import com.xkl.controller.uspih.AdminAccountController;
import com.xkl.domain.XklAdminEntity;
import com.xkl.repository.AdminRepository;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -39,7 +40,8 @@ public class CurrentAdminMethodArgumentResolver implements HandlerMethodArgument
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出鉴权时存入的登录用户Id
String currentAdminId = ((String) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST)).replace(UpSoftAccountController.UPSOFT_TOKEN_PREFIX, "");
String currentAdminId = ((String) webRequest.getAttribute(Constants.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST)).
replace(UpSoftAccountController.UPSOFT_TOKEN_PREFIX, "").replace(AdminAccountController.USPIH_TOKEN_PREFIX, "");
if (currentAdminId != null) {
//从数据库中查询并返回
XklAdminEntity admin = adminRepository.findByIdAndStatus(Long.parseLong(currentAdminId), Constants.STATUS_OK);
... ...
... ... @@ -23,12 +23,12 @@ public enum ResultStatus {
// 111开头的都是与amp报告上传软件相关的
AMP_KEY_ERROR(-11100, "AMP密钥不匹配"),
REPORT_FORMAT_ERROR(-11140,"报告格式错误"),
REPORT_FORMAT_ERROR(-11140,"报告格式错误/Report json format error"),
REPORT_EXISTED_ERROR(-11141,"报告重复上传"),
REPORT_INVALID__ERROR(-11142,"报告在数据库中不存在"),
REPORT_INVALID__ERROR(-11142,"报告在数据库中不存在/Report is not exist in the DB"),
INVALID_USER_ERROR(-11150,"报告所属用户未注册"),
INVALID_ADMIN_RPDEL_ERROR(-11151,"报告非此操作员创建,无权删除!"),
INVALID_USER_ERROR(-11150,"报告所属用户未注册/Report user's account is not exist"),
INVALID_ADMIN_RPDEL_ERROR(-11151,"报告非此操作员创建,无权删除!/Operator can not delete this report"),
DB_ERROR(-11160,"服务器错误,无法写入数据库");
... ...
... ... @@ -10,6 +10,8 @@ import com.xkl.config.ResultStatus;
public class ReportData {
private XklAmpReportEntity ampReport;
private List<XklAmpReportDetailEntity> rpDetailList;
private List<XklAmpReportResultEntity> basicResList;
// ResultStatus resStatus;
// public ReportData(ResultStatus resStatus) {
... ... @@ -32,7 +34,15 @@ public class ReportData {
this.rpDetailList = rpDetailList;
}
// public ResultStatus getResStatus() {
public List<XklAmpReportResultEntity> getBasicResList() {
return basicResList;
}
public void setBasicResList(List<XklAmpReportResultEntity> basicResList) {
this.basicResList = basicResList;
}
// public ResultStatus getResStatus() {
// return resStatus;
// }
//
... ...
package com.xkl.domain;
import lombok.Data;
import javax.persistence.*;
/**
* @author zhaoyue
* report诊断结果id列表
*/
@Data
@Entity
@Table(name = "xkl_amp_report_result")
public class XklAmpReportResultEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Basic
@Column(name = "report_id")
private long reportId;
@Basic
@Column(name = "result_item_id")
private int resultItemId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getReportId() {
return reportId;
}
public void setReportId(long reportId) {
this.reportId = reportId;
}
public int getResultItemId() {
return resultItemId;
}
public void setResultItemId(int resultItemId) {
this.resultItemId = resultItemId;
}
}
... ...
package com.xkl.repository;
import org.springframework.data.repository.CrudRepository;
import com.xkl.domain.XklAmpReportResultEntity;
import java.util.List;
/**
* XklAmpReportResultEntity类的CRUD操作
*
* @see XklAmpReportResultEntity
*/
public interface ReportResultRepository extends CrudRepository<XklAmpReportResultEntity, Long> {
public List<XklAmpReportResultEntity> findByReportId(long reportId);
}
... ...
package com.xkl.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.ReportDetailRepository;
import com.xkl.repository.ReportMetaItemsRepository;
import com.xkl.repository.ReportRepository;
import com.xkl.repository.UserRepository;
import com.xkl.repository.*;
import com.xkl.security.SecurityTool;
import com.xkl.tools.UtilTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
... ... @@ -36,6 +33,9 @@ public class ReportService implements IReportService {
private ReportDetailRepository reportDetailRepository;
@Autowired
private ReportResultRepository reportResultRepository;
@Autowired
private UserRepository userRepository;
// 存储报告相关md5,防止重复上传已存在报告,防止重复上传错误报告。
... ... @@ -112,7 +112,7 @@ public class ReportService implements IReportService {
*/
public ResponseEntity<ResultModel> delete(XklAdminEntity admin, long report_id) {
// 1. 得到report,验证报告存在性
XklAmpReportEntity report = reportRepository.findById( report_id);
XklAmpReportEntity report = reportRepository.findById(report_id);
if (report == null || report.getStatus() == 0) {
// 报告不存在,返回
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
... ... @@ -127,6 +127,8 @@ public class ReportService implements IReportService {
reportRepository.delete(report);
List<XklAmpReportDetailEntity> detailList = reportDetailRepository.findByReportId(report.getId());
reportDetailRepository.delete(detailList);
List<XklAmpReportResultEntity> rpResList = reportResultRepository.findByReportId(report.getId());
reportResultRepository.delete(rpResList);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
... ... @@ -144,6 +146,7 @@ public class ReportService implements IReportService {
ReportData reportData = new ReportData();
XklAmpReportEntity ampReport = new XklAmpReportEntity();
List<XklAmpReportDetailEntity> detailList = new ArrayList<>();
List<XklAmpReportResultEntity> basicResList = new ArrayList<>();
int sex;
/*
... ... @@ -182,12 +185,24 @@ public class ReportService implements IReportService {
detail.setItemId(item_id);
detailList.add(detail);
}
/*
* 4. 获取诊断结论编号
*/
JSONArray basicResIdsArr = rpJson.getJSONArray("basic_result_ids");
if (basicResIdsArr != null && basicResIdsArr.size() > 0) {
for (int resId = 0; resId < basicResIdsArr.size(); resId++) {
XklAmpReportResultEntity rpRes = new XklAmpReportResultEntity();
rpRes.setResultItemId(basicResIdsArr.getInteger(resId));
basicResList.add(rpRes);
}
}
} catch (Exception e) {
return null;
}
markItemStatus(sex, detailList);
reportData.setAmpReport(ampReport);
reportData.setRpDetailList(detailList);
reportData.setBasicResList(basicResList);
return reportData;
}
... ... @@ -196,13 +211,17 @@ public class ReportService implements IReportService {
*/
private long save2DB(ReportData report, XklAdminEntity admin, User user) {
report.getAmpReport().setCreateBy(admin.getId());
report.getAmpReport().setCompanyId((long)admin.getCoid());
report.getAmpReport().setMemberId((long)user.getMemberId());
report.getAmpReport().setCompanyId((long) admin.getCoid());
report.getAmpReport().setMemberId((long) user.getMemberId());
XklAmpReportEntity ampReport = reportRepository.save(report.getAmpReport());
for (XklAmpReportDetailEntity detail : report.getRpDetailList()) {
detail.setReportId(ampReport.getId());
}
for (XklAmpReportResultEntity rpRes : report.getBasicResList()){
rpRes.setReportId(ampReport.getId());
}
reportDetailRepository.save(report.getRpDetailList());
reportResultRepository.save(report.getBasicResList());
return ampReport.getId();
}
... ...