From 88f6d2914d3956f4c476deeba4fa46ea48fe374d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6?= <吴æ武慧娟> Date: Wed, 25 Dec 2019 16:00:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ht/api/PatientReportController.java | 50 ++++--- .../ccsens/ht/bean/po/HtPatientReport.java | 11 ++ .../ht/bean/po/HtPatientReportExample.java | 70 ++++++++++ .../ccsens/ht/bean/vo/PatientReportVo.java | 127 ++++++++++++------ .../ht/service/IPatientReportService.java | 18 +++ .../ht/service/PatientReportService.java | 76 ++++++++++- .../mapper_raw/HtPatientReportMapper.xml | 27 +++- util/pom.xml | 12 +- .../main/java/com/ccsens/util/PdfUtil.java | 47 ++++--- .../main/java/com/ccsens/util/QrCodeUtil.java | 44 ++++++ .../java/com/ccsens/util/PdfUtilTest.java | 123 +++++++++++++++-- 11 files changed, 508 insertions(+), 97 deletions(-) create mode 100644 util/src/main/java/com/ccsens/util/QrCodeUtil.java diff --git a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java index 792344cd..ffec38c1 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java @@ -21,6 +21,9 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @program: ptpro @@ -112,20 +115,35 @@ public class PatientReportController { return JsonResponse.newInstance().ok(authority); } -// @ApiOperation(value = "导出报告单",notes = "导出报告单") -// @ApiImplicitParams({ -// @ApiImplicitParam(name = "json", value = "导出报告单", required = true) -// }) -// @RequestMapping(value="/exportReport", method = RequestMethod.POST) -// public JsonResponse exportReport(@RequestBody @ApiParam @Valid QueryDto param){ -// //查询报告单信息 -// log.info("查询报告单详情:{}", param); -// PatientReportVo.ReprotDetail detail = patientReportService.queryReportDetail(param.getParam(), param.getUserId()); -// if (detail == null) { -// return JsonResponse.newInstance().ok(CodeEnum.); -// } -// PdfUtil.credatePdf(PropUtil.path, detail.getPatient().getName(), detail.getPatient().toPdfRow(), ) -// log.info("查询报告单详情结果:{}", detail); -// return JsonResponse.newInstance().ok(detail); -// } + @ApiOperation(value = "导出报告单",notes = "导出报告单") + @ApiImplicitParams({ + @ApiImplicitParam(name = "json", value = "导出报告单", required = true) + }) + @RequestMapping(value="/exportReport", method = RequestMethod.POST) + public JsonResponse exportReport(@RequestBody @ApiParam @Valid QueryDto param){ + //查询报告单信息 + log.info("查询报告单详情:{}", param); + String path = patientReportService.exportReport(param.getParam(), param.getUserId()); + log.info("文件路径:{}", path); + PatientReportVo.Export export = new PatientReportVo.Export(); + export.setPath(path); + + return JsonResponse.newInstance().ok(export); + } + + @ApiOperation(value = "分享报告单",notes = "分享报告单") + @ApiImplicitParams({ + @ApiImplicitParam(name = "json", value = "分享报告单", required = true) + }) + @RequestMapping(value="/shareReport", method = RequestMethod.POST) + public JsonResponse shareReport(@RequestBody @ApiParam @Valid QueryDto param) throws IOException { + //查询报告单信息 + log.info("查询报告单详情:{}", param); + String path = patientReportService.generateQRCode(param.getParam(), param.getUserId()); + log.info("文件路径:{}", path); + PatientReportVo.Export export = new PatientReportVo.Export(); + export.setPath(path); + + return JsonResponse.newInstance().ok(export); + } } diff --git a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java index 1f695493..6d4f5287 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java +++ b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java @@ -36,6 +36,8 @@ public class HtPatientReport implements Serializable { private String url; + private String qrCodeUrl; + private String remark; private Date createTime; @@ -174,6 +176,14 @@ public class HtPatientReport implements Serializable { this.url = url == null ? null : url.trim(); } + public String getQrCodeUrl() { + return qrCodeUrl; + } + + public void setQrCodeUrl(String qrCodeUrl) { + this.qrCodeUrl = qrCodeUrl == null ? null : qrCodeUrl.trim(); + } + public String getRemark() { return remark; } @@ -228,6 +238,7 @@ public class HtPatientReport implements Serializable { sb.append(", checkTime=").append(checkTime); sb.append(", evaluationCode=").append(evaluationCode); sb.append(", url=").append(url); + sb.append(", qrCodeUrl=").append(qrCodeUrl); sb.append(", remark=").append(remark); sb.append(", createTime=").append(createTime); sb.append(", updateTime=").append(updateTime); diff --git a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java index 43d35c50..b46be1bb 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java +++ b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java @@ -1155,6 +1155,76 @@ public class HtPatientReportExample { return (Criteria) this; } + public Criteria andQrCodeUrlIsNull() { + addCriterion("qr_code_url is null"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlIsNotNull() { + addCriterion("qr_code_url is not null"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlEqualTo(String value) { + addCriterion("qr_code_url =", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotEqualTo(String value) { + addCriterion("qr_code_url <>", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlGreaterThan(String value) { + addCriterion("qr_code_url >", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlGreaterThanOrEqualTo(String value) { + addCriterion("qr_code_url >=", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLessThan(String value) { + addCriterion("qr_code_url <", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLessThanOrEqualTo(String value) { + addCriterion("qr_code_url <=", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLike(String value) { + addCriterion("qr_code_url like", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotLike(String value) { + addCriterion("qr_code_url not like", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlIn(List values) { + addCriterion("qr_code_url in", values, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotIn(List values) { + addCriterion("qr_code_url not in", values, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlBetween(String value1, String value2) { + addCriterion("qr_code_url between", value1, value2, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotBetween(String value1, String value2) { + addCriterion("qr_code_url not between", value1, value2, "qrCodeUrl"); + return (Criteria) this; + } + public Criteria andRemarkIsNull() { addCriterion("remark is null"); return (Criteria) this; diff --git a/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java b/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java index 5c88d090..a451cc00 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java +++ b/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java @@ -7,7 +7,6 @@ import com.ccsens.util.PdfUtil; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; import java.util.*; @@ -129,12 +128,17 @@ public class PatientReportVo { "病案号:" + this.hospitalNumber) ); //第四栏 - Date date = new Date(); - date.setTime(this.reportTime); + Date date = null; + if (this.reportTime > 0) { + date = new Date(); + date.setTime(this.reportTime); + } + rows.add( fillRow( "临床诊断:" + this.clinicalDiagnosis, - "检查日期:" + DateUtil.format(date, "yyyy-MM-dd")) + "", + "检查日期:" + (date == null ? "" : DateUtil.format(date, "yyyy-MM-dd"))) ); return rows; @@ -181,31 +185,39 @@ public class PatientReportVo { } public List toRow() { + int colNum = 8; + int headNum = 2; List rows = new ArrayList<>(); if (CollectionUtil.isEmpty(subReport)) { PdfUtil.Row row = new PdfUtil.Row(); PdfUtil.Cell cell1 = new PdfUtil.Cell(); - cell1.setContent(this.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); + cell1.setContent(this.code + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); + cell1.setColSpan(headNum); PdfUtil.Cell cell2 = new PdfUtil.Cell(); cell2.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + cell2.setColSpan(colNum - headNum); row.addCell(cell1); row.addCell(cell2); + rows.add(row); - return rows; } else { String mmse = "MMSE"; String npi = "NPI"; if (mmse.equalsIgnoreCase(this.code) || npi.equalsIgnoreCase(this.code)) { PdfUtil.Row row1 = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); - cell.setContent(this.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); + cell.setContent(this.code + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); cell.setRowSpan(2); + cell.setColSpan(npi.equalsIgnoreCase(this.code) ? headNum : 1); row1.addCell(cell); + //被合并cell PdfUtil.Row row2 = new PdfUtil.Row(); +// fillBlankCell(row2); + //子测评项 this.subReport.forEach(reportScore -> { - fillRow(row1,row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + fillRow(row1,row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : ""), npi.equalsIgnoreCase(this.code) ? new int[]{3,3} : null); }); - + // 总分 if (mmse.equalsIgnoreCase(this.code)) { fillRow(row1,row2, "总分", this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); } @@ -213,75 +225,110 @@ public class PatientReportVo { rows.add(row2); } else { //moca - int firstIndex = 6; + int firstIndex = 5; PdfUtil.Row row1 = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); cell.setContent(this.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); cell.setRowSpan(5); row1.addCell(cell); PdfUtil.Row row2 = new PdfUtil.Row(); +// fillBlankCell(row2); for (int i = 0; i < firstIndex; i++) { ReportScore reportScore = this.subReport.get(i); String jy = "JY"; if (jy.equalsIgnoreCase(reportScore.getCode())) { - fillRow(row1, row2, reportScore.getName(), ""); + fillRow(row1, row2, reportScore.getName(), "", i == 0 ? new int[]{2,2}: null); } else { - fillRow(row1, row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + fillRow(row1, row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : ""), i == 0 ? new int[]{2,2}: null); } } PdfUtil.Cell scoreNameCell = new PdfUtil.Cell(); scoreNameCell.setContent("总分"); row1.addCell(scoreNameCell); PdfUtil.Cell scoreCell = new PdfUtil.Cell(); - scoreNameCell.setContent("总分"); - row1.addCell(scoreNameCell); - - - for (ReportScore score: this.subReport) { - - - - if (firstIndex == 6) { - //设置总分 - PdfUtil.Cell scoreTitleCell = new PdfUtil.Cell(); - scoreTitleCell.setContent("总分"); - row1.addCell(scoreTitleCell); - PdfUtil.Cell scoreScoreCell = new PdfUtil.Cell(); - scoreScoreCell.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); - scoreScoreCell.setRowSpan(4); - row2.addCell(scoreScoreCell); - rows.add(row1); - rows.add(row2); - //换行 - row1 = new PdfUtil.Row(); - row2 = new PdfUtil.Row(); - } - firstIndex++; - } + scoreCell.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + scoreCell.setRowSpan(4); + row2.addCell(scoreCell); +// fillBlankCell(row1, row2); rows.add(row1); rows.add(row2); + //下一行 + PdfUtil.Row row3 = new PdfUtil.Row(); + PdfUtil.Row row4 = new PdfUtil.Row(); + PdfUtil.Row row5 = new PdfUtil.Row(); +// fillBlankCell(row3, row4, row5); + //延迟回忆特殊处理 + String ychy = "YCHY"; + for (int i = firstIndex; i < this.subReport.size(); i++) { + ReportScore reportScore = this.subReport.get(i); + //设置名字 + PdfUtil.Cell scoreTitleCell = new PdfUtil.Cell(); + scoreTitleCell.setContent(reportScore.getName()); + scoreTitleCell.setColSpan(ychy.equalsIgnoreCase(reportScore.getCode()) ? 2 : 1); + row3.addCell(scoreTitleCell); + //设置子类 + if (ychy.equalsIgnoreCase(reportScore.getCode())) { + for (int j = 0; j < reportScore.subReport.size(); j++) { + ReportScore subScore = reportScore.getSubReport().get(j); + PdfUtil.Cell subCell = new PdfUtil.Cell(); + subCell.setContent(subScore.name + (subScore.getScore() == null ? " " : subScore.getScore()) + subScore.getRemark()); + if (j == 0 ) { + row4.addCell(subCell); + } else { + row5.addCell(subCell); + } + } + } + PdfUtil.Cell scoreScoreCell = new PdfUtil.Cell(); + scoreScoreCell.setContent(reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + scoreScoreCell.setRowSpan(2); + row4.addCell(scoreScoreCell); +// fillBlankCell(row5); + + } +// fillBlankCell(row3); +// fillBlankCell(row3, row4, row5); + rows.add(row3); + rows.add(row4); + rows.add(row5); } } - PdfUtil.Row row = new PdfUtil.Row(); + PdfUtil.Row descRow = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); + cell.setColSpan(colNum); cell.setContent(this.description); - + descRow.addCell(cell); + rows.add(descRow); return rows; } - private void fillRow(PdfUtil.Row row1, PdfUtil.Row row2, String name, String score){ + /** + * 添加一个空格 + * @param rows + */ + private void fillBlankCell(PdfUtil.Row... rows) { + for (PdfUtil.Row row: rows) { + PdfUtil.Cell cell = new PdfUtil.Cell(); + row.addCell(cell); + } + } + + private void fillRow(PdfUtil.Row row1, PdfUtil.Row row2, String name, String score, int... colspan){ //名称 PdfUtil.Cell cell1 = new PdfUtil.Cell(); cell1.setContent(name); + cell1.setColSpan(colspan == null || colspan.length == 0 ? 1 : colspan[0]); row1.addCell(cell1); + //分数 PdfUtil.Cell cell2 = new PdfUtil.Cell(); cell2.setContent(score); + cell2.setColSpan(colspan == null || colspan.length <= 1 ? 1 : colspan[1]); row2.addCell(cell2); } } diff --git a/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java b/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java index b6620c3d..1f8fa78a 100644 --- a/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java +++ b/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java @@ -6,6 +6,8 @@ import com.ccsens.util.CodeEnum; import com.ccsens.util.JsonResponse; import com.github.pagehelper.PageInfo; +import java.io.IOException; + public interface IPatientReportService { @@ -56,4 +58,20 @@ public interface IPatientReportService { *@date: 2019/11/19 15:50 */ PatientReportVo.Authority queryReportAuthority(PatientReportDto.Authority authority, Long userId); + + /** + * 导出报告单 + * @param queryDetail + * @param userId + * @return + */ + String exportReport(PatientReportDto.QueryDetail queryDetail, Long userId); + + /** + * 生成二维码 + * @param queryDetail + * @param userId + * @return + */ + String generateQRCode(PatientReportDto.QueryDetail queryDetail, Long userId) throws IOException; } diff --git a/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java b/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java index 21f2f1ff..ba64c430 100644 --- a/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java +++ b/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java @@ -14,8 +14,7 @@ import com.ccsens.ht.persist.mapper.HtPatientFollowUpMapper; import com.ccsens.ht.persist.mapper.HtPatientMapper; import com.ccsens.ht.persist.mapper.HtPatientReportRecordMapper; import com.ccsens.ht.uitl.Constant; -import com.ccsens.util.CodeEnum; -import com.ccsens.util.JsonResponse; +import com.ccsens.util.*; import com.ccsens.util.exception.BaseException; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -27,6 +26,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.io.IOException; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -346,4 +346,76 @@ public class PatientReportService implements IPatientReportService { return sum.get(); } + + @Override + public String exportReport(PatientReportDto.QueryDetail queryDetail, Long userId) { + log.info("导出报告单:{}, 操作用户:{}", queryDetail, userId); + //查看是否已生成对应文件路径 + HtPatientReport report = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + if (report == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + if (StrUtil.isNotBlank(report.getUrl())) { + return report.getUrl(); + } + PatientReportVo.ReprotDetail detail = queryReportDetail(queryDetail, userId); + if (detail == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + List content = new ArrayList<>(); + detail.getScores().forEach(reportScore -> { + content.addAll(reportScore.toRow()); + }); + PdfUtil.Row row = new PdfUtil.Row(); + addCell(row,"初步印象",2,2); + addCell(row, detail.getPatient().getInitialImpression(), 6, 2); + content.add(row); + PdfUtil.Row row2 = new PdfUtil.Row(); + addCell(row2,"测评员:",4,1, 0); + addCell(row2,"报告日期:",4,1, 0); + content.add(row2); + + String path = PropUtil.imgDomain + "/" + PdfUtil.credatePdf(PropUtil.path, detail.getPatient().getName(), detail.getPatient().toPdfRow(), content); + report.setUrl(path); + htPatientReportDao.updateByPrimaryKeySelective(report); + log.info("生成文件路径:{}", path); + return path; + } + + private void addCell(PdfUtil.Row row, String content, int colSpan, int rowSpan, int... border) { + PdfUtil.Cell cell1 = new PdfUtil.Cell(); + cell1.setContent(content); + cell1.setColSpan(colSpan); + cell1.setRowSpan(rowSpan); + cell1.setBorder(border == null || border.length == 0 ? 1 : border[0]); + row.addCell(cell1); + } + + @Override + public String generateQRCode(PatientReportDto.QueryDetail queryDetail, Long userId) throws IOException { + log.info("报告单分享:{},用户ID:{}", queryDetail, userId); + HtPatientReport report = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + if (report == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + //有二维码直接返回 + if (StrUtil.isNotBlank(report.getQrCodeUrl())) { + log.info("直接返回二维码路径:{}", report.getQrCodeUrl()); + return report.getQrCodeUrl(); + } + + String pdfUrl = report.getUrl(); + if (StrUtil.isBlank(pdfUrl)) { + log.info("尚未生成pdf文件,生成文件"); + pdfUrl = exportReport(queryDetail, userId); + } + String qrCodePath = QrCodeUtil.urlToQRCode(pdfUrl, PropUtil.path); + String qrCodeUrl = PropUtil.imgDomain + "/" + qrCodePath; + log.info("生成的二维码路径:{}", qrCodeUrl); + HtPatientReport newReport = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + newReport.setQrCodeUrl(qrCodeUrl); + htPatientReportDao.updateByPrimaryKeySelective(newReport); + log.info("修改报告单二维码路径"); + return qrCodeUrl; + } } diff --git a/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml b/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml index b87e2524..1c75f972 100644 --- a/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml +++ b/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml @@ -18,6 +18,7 @@ + @@ -84,7 +85,7 @@ id, name, patient_id, patient_idcard, patient_age, doctor_id, serial_number, initial_impression, clinical_diagnosis, pasi, department, bed_number, report_time, check_time, evaluation_code, - url, remark, create_time, update_time, is_del + url, qr_code_url, remark, create_time, update_time, is_del - select t1.id, t1.type, t1.question_id, t1.name, t1.score, t1.display, if (t2.id is null, 0, 1) as choose , if(t2.type = 3, null, t2.answer) as answer - from t_ht_question_option t1 left join t_ht_patient_score t2 on t1.id = t2.option_id and (t2.id is null or t2.patient_report_id = #{patientReportId,jdbcType=BIGINT}) + select t1.id, t1.type, t1.question_id, t1.name, t1.score, t1.display, case when t1.type = 'hidden' then 0 when t2.id is null then 0 else 1 end as choose , if(t2.type = 3, null, t2.answer) as answer + from t_ht_question_option t1 left join t_ht_patient_score t2 on t1.id = t2.option_id and (t2.id is null or (t2.patient_report_id = #{patientReportId,jdbcType=BIGINT} and t2.is_del = 0)) where t1.question_id = #{questionId,jdbcType=BIGINT} and t1.is_del = 0 group by t1.id From 820ddb8b36de66e1c9e140175e1d0e3bfba845e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6?= <吴æ武慧娟> Date: Thu, 26 Dec 2019 16:09:24 +0800 Subject: [PATCH 3/4] client --- .../com/ccsens/game/api/ScreenController.java | 1 + .../com/ccsens/game/bean/dto/ClientDto.java | 18 ++++++++++++++++++ .../java/com/ccsens/game/bean/vo/ClientVo.java | 18 ++++++++++++++++++ .../com/ccsens/game/service/ClientService.java | 9 +++++++++ .../ccsens/game/service/IClientService.java | 11 +++++++++++ .../ht/intercept/MybatisInterceptor.java | 6 +++++- .../src/test/java/com/ccsens/util/KeyTest.java | 6 +++--- 7 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java create mode 100644 game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java create mode 100644 game/src/main/java/com/ccsens/game/service/ClientService.java create mode 100644 game/src/main/java/com/ccsens/game/service/IClientService.java diff --git a/game/src/main/java/com/ccsens/game/api/ScreenController.java b/game/src/main/java/com/ccsens/game/api/ScreenController.java index 09ba91a9..09d4bb57 100644 --- a/game/src/main/java/com/ccsens/game/api/ScreenController.java +++ b/game/src/main/java/com/ccsens/game/api/ScreenController.java @@ -36,6 +36,7 @@ public class ScreenController { @ApiOperation(value = "获取游戏基本信息", notes = "") @ApiImplicitParams({ + }) @RequestMapping(value = "", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JsonResponse getGameInfo(HttpServletRequest request, diff --git a/game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java b/game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java new file mode 100644 index 00000000..532dc13c --- /dev/null +++ b/game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java @@ -0,0 +1,18 @@ +package com.ccsens.game.bean.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; + +/** + * @description: + * @author: wuHuiJuan + * @create: 2019/12/26 15:03 + */ +public class ClientDto { + + @Data + @ApiModel("ClientDtoJoin") + public static class Join{ + + } +} diff --git a/game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java b/game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java new file mode 100644 index 00000000..839d363b --- /dev/null +++ b/game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java @@ -0,0 +1,18 @@ +package com.ccsens.game.bean.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @description: + * @author: wuHuiJuan + * @create: 2019/12/26 15:01 + */ +public class ClientVo { + @Data + @ApiModel("ClientVoJoin") + public static class Join{ + + } +} diff --git a/game/src/main/java/com/ccsens/game/service/ClientService.java b/game/src/main/java/com/ccsens/game/service/ClientService.java new file mode 100644 index 00000000..a13396be --- /dev/null +++ b/game/src/main/java/com/ccsens/game/service/ClientService.java @@ -0,0 +1,9 @@ +package com.ccsens.game.service; + +/** + * @description: + * @author: wuHuiJuan + * @create: 2019/12/26 15:01 + */ +public class ClientService implements IClientService { +} diff --git a/game/src/main/java/com/ccsens/game/service/IClientService.java b/game/src/main/java/com/ccsens/game/service/IClientService.java new file mode 100644 index 00000000..5d802316 --- /dev/null +++ b/game/src/main/java/com/ccsens/game/service/IClientService.java @@ -0,0 +1,11 @@ +package com.ccsens.game.service; + +/** + * @description: + * @author: wuHuiJuan + * @create: 2019/12/26 15:00 + */ +public interface IClientService { + + +} diff --git a/ht/src/main/java/com/ccsens/ht/intercept/MybatisInterceptor.java b/ht/src/main/java/com/ccsens/ht/intercept/MybatisInterceptor.java index 665572ed..89fed564 100644 --- a/ht/src/main/java/com/ccsens/ht/intercept/MybatisInterceptor.java +++ b/ht/src/main/java/com/ccsens/ht/intercept/MybatisInterceptor.java @@ -36,11 +36,15 @@ public class MybatisInterceptor implements Interceptor { String selectByExample = "selectByExample"; + String countByExample = "countByExample"; + String countByExample2 = "selectByExample_COUNT"; String selectByPrimaryKey = "selectByPrimaryKey"; Object[] args = invocation.getArgs(); MappedStatement statement = (MappedStatement) args[0]; - if (statement.getId().endsWith(selectByExample)) { + if (statement.getId().endsWith(selectByExample) + || statement.getId().endsWith(countByExample) + || statement.getId().endsWith(countByExample2)) { //XXXExample Object example = args[1]; diff --git a/util/src/test/java/com/ccsens/util/KeyTest.java b/util/src/test/java/com/ccsens/util/KeyTest.java index 104d3b35..99a0ec32 100644 --- a/util/src/test/java/com/ccsens/util/KeyTest.java +++ b/util/src/test/java/com/ccsens/util/KeyTest.java @@ -15,13 +15,13 @@ import org.junit.Test; */ public class KeyTest { /**生成密钥*/ - @Test +// @Test public void test33(){ byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded(); Console.log(Base64.encode(key)); } /**加密*/ - @Test +// @Test public void test3(){ String key = "a6RlI/GctLgENUvF6DOY7w=="; String string = "po3OynBO[M3579p6L7)o"; @@ -31,7 +31,7 @@ public class KeyTest { } /**解密*/ - @Test +// @Test public void test4(){ // String key = ""; String key = System.getenv("CCSENS_GAME"); From 5f557728e3839ce90e5294b664deefe54e2bdf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6?= <吴æ武慧娟> Date: Thu, 26 Dec 2019 16:58:15 +0800 Subject: [PATCH 4/4] login --- cloudutil/pom.xml | 5 +++ .../ccsens/cloudutil/annotation/Login.java | 14 +++++++++ .../cloudutil}/annotation/MustLogin.java | 2 +- .../cloudutil}/aspect/MustLoginAspect.java | 31 ++++++++++++++++--- ht/pom.xml | 6 +--- .../com/ccsens/ht/api/DoctorController.java | 5 ++- .../com/ccsens/ht/api/FileController.java | 6 ++-- .../com/ccsens/ht/api/PatientController.java | 4 +-- .../ht/api/PatientReportController.java | 8 ++--- .../com/ccsens/ht/api/PositionController.java | 4 +-- .../com/ccsens/ht/api/QuestionController.java | 4 +-- .../ccsens/ht/aspect/DoctorAuditAspect.java | 3 +- .../com/ccsens/util}/bean/dto/QueryDto.java | 2 +- 13 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 cloudutil/src/main/java/com/ccsens/cloudutil/annotation/Login.java rename {ht/src/main/java/com/ccsens/ht => cloudutil/src/main/java/com/ccsens/cloudutil}/annotation/MustLogin.java (88%) rename {ht/src/main/java/com/ccsens/ht => cloudutil/src/main/java/com/ccsens/cloudutil}/aspect/MustLoginAspect.java (63%) rename {ht/src/main/java/com/ccsens/ht => util/src/main/java/com/ccsens/util}/bean/dto/QueryDto.java (94%) diff --git a/cloudutil/pom.xml b/cloudutil/pom.xml index dc13ee98..7042df2c 100644 --- a/cloudutil/pom.xml +++ b/cloudutil/pom.xml @@ -44,6 +44,11 @@ org.springframework.cloud spring-cloud-sleuth-zipkin + + com.alibaba + fastjson + 1.2.62 + \ No newline at end of file diff --git a/cloudutil/src/main/java/com/ccsens/cloudutil/annotation/Login.java b/cloudutil/src/main/java/com/ccsens/cloudutil/annotation/Login.java new file mode 100644 index 00000000..41f28133 --- /dev/null +++ b/cloudutil/src/main/java/com/ccsens/cloudutil/annotation/Login.java @@ -0,0 +1,14 @@ +package com.ccsens.cloudutil.annotation; + +import java.lang.annotation.*; + +/** + * 有token,则根据token获取userId, 无则不获取 + * @author: wuHuiJuan + * @create: 2019/12/26 16:39 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Login { +} diff --git a/ht/src/main/java/com/ccsens/ht/annotation/MustLogin.java b/cloudutil/src/main/java/com/ccsens/cloudutil/annotation/MustLogin.java similarity index 88% rename from ht/src/main/java/com/ccsens/ht/annotation/MustLogin.java rename to cloudutil/src/main/java/com/ccsens/cloudutil/annotation/MustLogin.java index d4d6230d..1ea0dc9a 100644 --- a/ht/src/main/java/com/ccsens/ht/annotation/MustLogin.java +++ b/cloudutil/src/main/java/com/ccsens/cloudutil/annotation/MustLogin.java @@ -1,4 +1,4 @@ -package com.ccsens.ht.annotation; +package com.ccsens.cloudutil.annotation; import java.lang.annotation.*; diff --git a/ht/src/main/java/com/ccsens/ht/aspect/MustLoginAspect.java b/cloudutil/src/main/java/com/ccsens/cloudutil/aspect/MustLoginAspect.java similarity index 63% rename from ht/src/main/java/com/ccsens/ht/aspect/MustLoginAspect.java rename to cloudutil/src/main/java/com/ccsens/cloudutil/aspect/MustLoginAspect.java index 1dac90cb..1b9049c5 100644 --- a/ht/src/main/java/com/ccsens/ht/aspect/MustLoginAspect.java +++ b/cloudutil/src/main/java/com/ccsens/cloudutil/aspect/MustLoginAspect.java @@ -1,18 +1,20 @@ -package com.ccsens.ht.aspect; +package com.ccsens.cloudutil.aspect; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.cloudutil.feign.TallFeignClient; -import com.ccsens.ht.bean.dto.QueryDto; import com.ccsens.util.CodeEnum; import com.ccsens.util.JsonResponse; import com.ccsens.util.WebConstant; -import com.ccsens.util.exception.BaseException; +import com.ccsens.util.bean.dto.QueryDto; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -20,6 +22,7 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; /** * @description: @@ -34,7 +37,7 @@ public class MustLoginAspect { @Autowired private TallFeignClient tallFeignClient; - @Pointcut("@annotation(com.ccsens.ht.annotation.MustLogin)") + @Pointcut("@annotation(com.ccsens.cloudutil.annotation.MustLogin) || @annotation(com.ccsens.cloudutil.annotation.Login) ") public void loginAdvice(){} @Around("loginAdvice()") @@ -47,8 +50,28 @@ public class MustLoginAspect { Object[] args = pjp.getArgs(); QueryDto dto = args == null || args.length < 1 ? null : (QueryDto) args[0]; + //获取userId JsonResponse response = tallFeignClient.getUserIdByToken(authHeader); log.info("{}获取userId:{}", authHeader, response); + + Signature signature = pjp.getSignature(); + MethodSignature methodSignature = (MethodSignature) signature; + Method targetMethod = methodSignature.getMethod(); + MustLogin mustLoginAnnotation = targetMethod.getAnnotation(MustLogin.class); + + if (mustLoginAnnotation == null) { + log.info("不是必须登录,有token,则添加userId,没有则不添加"); + if (response.getCode().intValue() == CodeEnum.SUCCESS.getCode().intValue() && response.getData() != null) { + JSONObject json = JSONObject.parseObject(JSON.toJSONString(response.getData())); + Long userId = json.getLong("id"); + if (dto != null) { + dto.setUserId(userId); + } + } + Object result = pjp.proceed(); + return result; + } + //必须登录,未登录直接返回未登录相关信息 if (response.getCode().intValue() != CodeEnum.SUCCESS.getCode().intValue()) { return response; } diff --git a/ht/pom.xml b/ht/pom.xml index b382c508..121898bf 100644 --- a/ht/pom.xml +++ b/ht/pom.xml @@ -24,11 +24,7 @@ 1.0-SNAPSHOT - - com.alibaba - fastjson - 1.2.62 - + diff --git a/ht/src/main/java/com/ccsens/ht/api/DoctorController.java b/ht/src/main/java/com/ccsens/ht/api/DoctorController.java index 2f33d9d4..eb4f5c4b 100644 --- a/ht/src/main/java/com/ccsens/ht/api/DoctorController.java +++ b/ht/src/main/java/com/ccsens/ht/api/DoctorController.java @@ -1,10 +1,10 @@ package com.ccsens.ht.api; -import com.ccsens.ht.annotation.MustLogin; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.ht.annotation.DoctorAudit; import com.ccsens.ht.bean.dto.DoctorDto; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.vo.DoctorVo; import com.ccsens.ht.service.IDoctorService; import com.ccsens.util.CodeEnum; @@ -13,7 +13,6 @@ import com.github.pagehelper.PageInfo; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/ht/src/main/java/com/ccsens/ht/api/FileController.java b/ht/src/main/java/com/ccsens/ht/api/FileController.java index 1ffbaa2c..82e56af6 100644 --- a/ht/src/main/java/com/ccsens/ht/api/FileController.java +++ b/ht/src/main/java/com/ccsens/ht/api/FileController.java @@ -1,12 +1,10 @@ package com.ccsens.ht.api; import cn.hutool.core.date.DateUtil; -import com.ccsens.ht.annotation.MustLogin; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.ht.bean.dto.FileDto; -import com.ccsens.ht.bean.dto.QueryDto; -import com.ccsens.ht.bean.dto.QuestionDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.vo.FileVo; -import com.ccsens.ht.bean.vo.QuestionVo; import com.ccsens.util.Base64FileUtil; import com.ccsens.util.JsonResponse; import com.ccsens.util.PropUtil; diff --git a/ht/src/main/java/com/ccsens/ht/api/PatientController.java b/ht/src/main/java/com/ccsens/ht/api/PatientController.java index d01a3544..c9f720b5 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PatientController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PatientController.java @@ -2,9 +2,9 @@ package com.ccsens.ht.api; import cn.hutool.core.util.IdcardUtil; import com.ccsens.ht.annotation.DoctorAudit; -import com.ccsens.ht.annotation.MustLogin; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.ht.bean.dto.PatientDto; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.po.HtPatient; import com.ccsens.ht.bean.vo.PatientVo; import com.ccsens.ht.service.IPatientService; diff --git a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java index ffec38c1..8037e3e7 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java @@ -2,15 +2,13 @@ package com.ccsens.ht.api; import com.ccsens.ht.annotation.DoctorAudit; -import com.ccsens.ht.annotation.MustLogin; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.ht.bean.dto.PatientReportDto; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.vo.PatientReportVo; import com.ccsens.ht.service.IPatientReportService; import com.ccsens.util.CodeEnum; import com.ccsens.util.JsonResponse; -import com.ccsens.util.PdfUtil; -import com.ccsens.util.PropUtil; import com.github.pagehelper.PageInfo; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; @@ -22,8 +20,6 @@ import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; /** * @program: ptpro diff --git a/ht/src/main/java/com/ccsens/ht/api/PositionController.java b/ht/src/main/java/com/ccsens/ht/api/PositionController.java index 32dc310d..fca81e25 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PositionController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PositionController.java @@ -1,8 +1,8 @@ package com.ccsens.ht.api; -import com.ccsens.ht.annotation.MustLogin; +import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.ht.bean.dto.PositionDto; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.vo.PositionVo; import com.ccsens.ht.service.IPositionService; import com.ccsens.util.JsonResponse; diff --git a/ht/src/main/java/com/ccsens/ht/api/QuestionController.java b/ht/src/main/java/com/ccsens/ht/api/QuestionController.java index 325b30ca..91177a57 100644 --- a/ht/src/main/java/com/ccsens/ht/api/QuestionController.java +++ b/ht/src/main/java/com/ccsens/ht/api/QuestionController.java @@ -2,8 +2,8 @@ package com.ccsens.ht.api; import com.ccsens.ht.annotation.DoctorAudit; -import com.ccsens.ht.annotation.MustLogin; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.cloudutil.annotation.MustLogin; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.dto.QuestionDto; import com.ccsens.ht.bean.vo.QuestionVo; import com.ccsens.ht.service.IQuestionService; diff --git a/ht/src/main/java/com/ccsens/ht/aspect/DoctorAuditAspect.java b/ht/src/main/java/com/ccsens/ht/aspect/DoctorAuditAspect.java index 9be81cea..2516e003 100644 --- a/ht/src/main/java/com/ccsens/ht/aspect/DoctorAuditAspect.java +++ b/ht/src/main/java/com/ccsens/ht/aspect/DoctorAuditAspect.java @@ -1,13 +1,12 @@ package com.ccsens.ht.aspect; -import com.ccsens.ht.bean.dto.QueryDto; +import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.ht.bean.po.HtDoctor; import com.ccsens.ht.bean.po.HtDoctorExample; import com.ccsens.ht.persist.mapper.HtDoctorMapper; import com.ccsens.ht.uitl.Constant; import com.ccsens.util.CodeEnum; import com.ccsens.util.JsonResponse; -import com.ccsens.util.exception.BaseException; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; diff --git a/ht/src/main/java/com/ccsens/ht/bean/dto/QueryDto.java b/util/src/main/java/com/ccsens/util/bean/dto/QueryDto.java similarity index 94% rename from ht/src/main/java/com/ccsens/ht/bean/dto/QueryDto.java rename to util/src/main/java/com/ccsens/util/bean/dto/QueryDto.java index 3412122d..50cf2a80 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/dto/QueryDto.java +++ b/util/src/main/java/com/ccsens/util/bean/dto/QueryDto.java @@ -1,4 +1,4 @@ -package com.ccsens.ht.bean.dto; +package com.ccsens.util.bean.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty;