Browse Source

导出分享

master
6 years ago
parent
commit
88f6d2914d
  1. 50
      ht/src/main/java/com/ccsens/ht/api/PatientReportController.java
  2. 11
      ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java
  3. 70
      ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java
  4. 121
      ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java
  5. 18
      ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java
  6. 76
      ht/src/main/java/com/ccsens/ht/service/PatientReportService.java
  7. 27
      ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml
  8. 12
      util/pom.xml
  9. 37
      util/src/main/java/com/ccsens/util/PdfUtil.java
  10. 44
      util/src/main/java/com/ccsens/util/QrCodeUtil.java
  11. 123
      util/src/test/java/com/ccsens/util/PdfUtilTest.java

50
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<PatientReportVo.Export> exportReport(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.QueryDetail> 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<PatientReportVo.Export> exportReport(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.QueryDetail> 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<PatientReportVo.Export> shareReport(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.QueryDetail> 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);
}
}

11
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);

70
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<String> values) {
addCriterion("qr_code_url in", values, "qrCodeUrl");
return (Criteria) this;
}
public Criteria andQrCodeUrlNotIn(List<String> 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;

121
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 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<PdfUtil.Row> toRow() {
int colNum = 8;
int headNum = 2;
List<PdfUtil.Row> 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);
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);
//换行
row1 = new PdfUtil.Row();
row2 = new PdfUtil.Row();
//下一行
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);
}
firstIndex++;
}
rows.add(row1);
rows.add(row2);
}
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);
}
}

18
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;
}

76
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<PdfUtil.Row> 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;
}
}

27
ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml

@ -18,6 +18,7 @@
<result column="check_time" jdbcType="BIGINT" property="checkTime" />
<result column="evaluation_code" jdbcType="VARCHAR" property="evaluationCode" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="qr_code_url" jdbcType="VARCHAR" property="qrCodeUrl" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@ -84,7 +85,7 @@
<sql id="Base_Column_List">
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
</sql>
<select id="selectByExample" parameterType="com.ccsens.ht.bean.po.HtPatientReportExample" resultMap="BaseResultMap">
select
@ -122,15 +123,17 @@
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
)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{patientId,jdbcType=BIGINT},
#{patientIdcard,jdbcType=VARCHAR}, #{patientAge,jdbcType=TINYINT}, #{doctorId,jdbcType=BIGINT},
#{serialNumber,jdbcType=VARCHAR}, #{initialImpression,jdbcType=VARCHAR}, #{clinicalDiagnosis,jdbcType=VARCHAR},
#{pasi,jdbcType=TINYINT}, #{department,jdbcType=VARCHAR}, #{bedNumber,jdbcType=VARCHAR},
#{reportTime,jdbcType=BIGINT}, #{checkTime,jdbcType=BIGINT}, #{evaluationCode,jdbcType=VARCHAR},
#{url,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{isDel,jdbcType=TINYINT})
#{url,jdbcType=VARCHAR}, #{qrCodeUrl,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{isDel,jdbcType=TINYINT}
)
</insert>
<insert id="insertSelective" parameterType="com.ccsens.ht.bean.po.HtPatientReport">
insert into t_ht_patient_report
@ -183,6 +186,9 @@
<if test="url != null">
url,
</if>
<if test="qrCodeUrl != null">
qr_code_url,
</if>
<if test="remark != null">
remark,
</if>
@ -245,6 +251,9 @@
<if test="url != null">
#{url,jdbcType=VARCHAR},
</if>
<if test="qrCodeUrl != null">
#{qrCodeUrl,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
@ -316,6 +325,9 @@
<if test="record.url != null">
url = #{record.url,jdbcType=VARCHAR},
</if>
<if test="record.qrCodeUrl != null">
qr_code_url = #{record.qrCodeUrl,jdbcType=VARCHAR},
</if>
<if test="record.remark != null">
remark = #{record.remark,jdbcType=VARCHAR},
</if>
@ -351,6 +363,7 @@
check_time = #{record.checkTime,jdbcType=BIGINT},
evaluation_code = #{record.evaluationCode,jdbcType=VARCHAR},
url = #{record.url,jdbcType=VARCHAR},
qr_code_url = #{record.qrCodeUrl,jdbcType=VARCHAR},
remark = #{record.remark,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
@ -407,6 +420,9 @@
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
<if test="qrCodeUrl != null">
qr_code_url = #{qrCodeUrl,jdbcType=VARCHAR},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
@ -439,6 +455,7 @@
check_time = #{checkTime,jdbcType=BIGINT},
evaluation_code = #{evaluationCode,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
qr_code_url = #{qrCodeUrl,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},

12
util/pom.xml

@ -15,24 +15,30 @@
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-pdf -->
<!--PDF生成-->
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.1.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<!--生成二维码-->
<dependency>
<groupId>net.glxn.qrgen</groupId>
<artifactId>javase</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

37
util/src/main/java/com/ccsens/util/PdfUtil.java

@ -34,7 +34,7 @@ public class PdfUtil {
* @return
*/
public static String credatePdf(String parentPath, String title, List<Row> intros, List<Row> content) {
String fileName = "pdf/" + DateUtil.today() + "/" + title + System.currentTimeMillis() + ".pdf";
String fileName = "pdf/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".pdf";
log.info("pdf文件名:{}", fileName );
File file = new File(parentPath, fileName);
if (!file.getParentFile().exists()) {
@ -61,9 +61,8 @@ public class PdfUtil {
//设置介绍内容
if (CollectionUtil.isNotEmpty(intros)) {
fillRow(intros, document);
fillBlankRow(document, titleChinese);
}
if (CollectionUtil.isEmpty(content)) {
if (CollectionUtil.isNotEmpty(content)) {
fillRow(content, document);
}
@ -106,30 +105,36 @@ public class PdfUtil {
*/
private static void fillRow(List<Row> rows, Document document) throws IOException, DocumentException {
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
rows.forEach(row -> {
int size = 0;
for (Cell cell :rows.get(0).getCells()) {
size += cell.getColSpan();
}
PdfPTable table = new PdfPTable(row.getCells().size());
PdfPTable table = new PdfPTable(size);
table.setSpacingBefore(0);
table.setWidthPercentage(100);
table.setSpacingBefore(10);
for (int j = 0; j < rows.size(); j++) {
Row row = rows.get(j);
table.setHorizontalAlignment(row.align);
Font font = new Font(bfChinese, row.fontSize, row.fontStyle);
row.cells.forEach(cell -> {
PdfPCell pdfpCell = new PdfPCell(new Paragraph(cell.content,font));
pdfpCell.setBorder(cell.border);
for (int i = 0; i < row.cells.size(); i++) {
Cell cell = row.cells.get(i);
PdfPCell pdfpCell = new PdfPCell(new Phrase(cell.content,font));
pdfpCell.setBorderWidthTop(j == 0 ? cell.border : 0);
pdfpCell.setBorderWidthLeft(cell.border);
pdfpCell.setBorderWidthRight(i == row.cells.size() - 1 ? cell.border : 0);
pdfpCell.setBorderWidthBottom(cell.border);
pdfpCell.setColspan(cell.colSpan);
pdfpCell.setRowspan(cell.rowSpan);
table.addCell(pdfpCell);
});
}
}
try {
table.setWidthPercentage(90);
table.setHorizontalAlignment(row.align);
document.add(table);
} catch (DocumentException e) {
e.printStackTrace();
}
});
}
/**

44
util/src/main/java/com/ccsens/util/QrCodeUtil.java

@ -0,0 +1,44 @@
package com.ccsens.util;
import cn.hutool.core.date.DateUtil;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.javase.QRCode;
import java.io.*;
/**
* 二维码工具类
* @author: wuHuiJuan
* @create: 2019/12/25 10:36
*/
public class QrCodeUtil {
/**
* 根据文件路径生成二维码
* @param url
* @param parentPath
* @return
* @throws IOException
*/
public static String urlToQRCode(String url, String parentPath) throws IOException {
String fileName = "qrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
ByteArrayOutputStream stream = QRCode.from(url).to(ImageType.BMP).stream();
byte[] codeByte = stream.toByteArray();
File file = new File(parentPath, fileName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
OutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(codeByte);
out.flush();
} finally {
if ( out!= null) {
out.close();
}
}
return fileName;
}
}

123
util/src/test/java/com/ccsens/util/PdfUtilTest.java

@ -1,9 +1,17 @@
package com.ccsens.util;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import org.junit.Test;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* @description:
@ -14,22 +22,26 @@ public class PdfUtilTest {
@Test
public void test(){
List<PdfUtil.Row> rows = new ArrayList<>();
for (int i = 0; i < 3; i++) {
PdfUtil.Cell cell = new PdfUtil.Cell();
cell.setContent("cell" + i);
PdfUtil.Row row = new PdfUtil.Row();
row.addCell(cell);
PdfUtil.Cell cell2 = new PdfUtil.Cell();
cell2.setContent("cell--" + i);
row.addCell(cell2);
rows.add(row);
}
// for (int i = 0; i < 3; i++) {
// PdfUtil.Cell cell = new PdfUtil.Cell();
// cell.setContent("cell" + i);
// PdfUtil.Row row = new PdfUtil.Row();
// row.addCell(cell);
// PdfUtil.Cell cell2 = new PdfUtil.Cell();
// cell2.setContent("cell--" + i);
// row.addCell(cell2);
// rows.add(row);
// }
List<PdfUtil.Row> contents = new ArrayList<>();
for (int i = 0; i < 3; i++) {
PdfUtil.Cell cell = new PdfUtil.Cell();
cell.setRowSpan(2);
cell.setContent("*******" + i);
PdfUtil.Cell cell1 = new PdfUtil.Cell();
cell1.setContent("*******==========" + i);
PdfUtil.Row row = new PdfUtil.Row();
row.addCell(cell);
row.addCell(cell1);
PdfUtil.Cell cell2 = new PdfUtil.Cell();
cell2.setContent("+++++++" + i);
PdfUtil.Row row2 = new PdfUtil.Row();
@ -39,4 +51,95 @@ public class PdfUtilTest {
}
PdfUtil.credatePdf("/home/", "评测", rows, contents);
}
public static void main(String[] args) throws IOException, DocumentException {
String fileDesc = "";
FileOutputStream outr = null;// 创建输出流
// 生成随机数
Random random = new Random();
int x = random.nextInt();
fileDesc = "d:\\home\\" + "_" + x + ".pdf";// 路径下一定要有此文件
BaseFont baseFontChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(baseFontChinese, 12, Font.NORMAL);
// step 1
Document document = new Document();
// step 2
try {
outr = new FileOutputStream(fileDesc);
PdfWriter.getInstance(document, outr);
// step 3
document.open();
// step 4
PdfPTable table = new PdfPTable(3);
// the cell object
PdfPCell cell;
// we add a cell with colspan3
cell = new PdfPCell(new Phrase("Cell with colspan 3"));
cell.setColspan(3);
table.addCell(cell);
// now we add a cell with rowspan2
cell = new PdfPCell(new Phrase("Cell with rowspan 2 跨行", fontChinese));
cell.setRowspan(2);
// cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
// we add the four remaining cells with addCell()
table.addCell("row 1-1; cell 1");
table.addCell("row 1-2; cell 2");
cell = new PdfPCell(new Phrase("Cell with rowspan 2 跨行", fontChinese));
table.addCell("row 2-1; cell 1");
table.addCell("row 2-2; cell 2");
table.addCell("row 3-1; cell 1");
table.addCell("row 3-2; cell 2");
table.addCell("row 3-3; cell 3");
table.addCell("row 4-1; cell 1");
table.addCell("row 4-2; cell 2");
table.addCell("row 4-3; cell 3");
table.addCell("row 5-1; cell 1");
table.addCell("row 5-2; cell 2");
table.addCell("row 5-3; cell 3");
table.addCell("row 6-1; cell 1");
table.addCell("row 6-2; cell 2");
table.addCell("row 6-3; cell 3");
table.addCell("row 7-1; cell 1");
table.addCell("row 7-2; cell 2");
table.addCell("row 7-3; cell 3");
table.addCell("row 8-1; cell 1");
table.addCell("row 8-2; cell 2");
table.addCell("row 8-3; cell 3");
table.addCell("row 9-1; cell 1");
table.addCell("row 9-2; cell 2");
table.addCell("row 9-3; cell 3");
//加入隔行换色事件
// PdfPTableEvent event = new AlternatingBackground();
// table.setTableEvent(event);
//end
document.add(table);
document.close();
} catch (DocumentException e1) {
e1.printStackTrace();
} finally {
if (outr != null) {
outr.close();
}
}
}
}

Loading…
Cancel
Save