Browse Source

20220526高危筛查

bfyMa
zhangye 3 years ago
parent
commit
81ee79ef98
  1. 2
      src/main/java/com/ccsens/carbasics/bean/vo/QuestionnaireVo.java
  2. 12
      src/main/java/com/ccsens/carbasics/service/ScreeningService.java
  3. 87
      src/main/java/com/ccsens/carbasics/util/ScreeningQrCodeUtil.java
  4. 4
      src/main/resources/application.yml
  5. 17
      src/main/resources/mapper_dao/OrganizationPositionDao.xml
  6. BIN
      src/main/resources/templates/screeningQrCodeTemplates.png

2
src/main/java/com/ccsens/carbasics/bean/vo/QuestionnaireVo.java

@ -123,6 +123,8 @@ public class QuestionnaireVo {
private String doctorName;
@ApiModelProperty("二维码路径")
private String qrCode;
@JsonIgnore
private String positionCode;
}
@Data

12
src/main/java/com/ccsens/carbasics/service/ScreeningService.java

@ -10,6 +10,7 @@ import com.ccsens.carbasics.persist.dao.QuestionnaireDao;
import com.ccsens.carbasics.persist.dao.QuestionnaireDetailDao;
import com.ccsens.carbasics.util.Constant;
import com.ccsens.carbasics.util.DefaultCodeError;
import com.ccsens.carbasics.util.ScreeningQrCodeUtil;
import com.ccsens.util.PropUtil;
import com.ccsens.util.QrCodeUtil;
import com.ccsens.util.exception.BaseException;
@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -63,10 +65,16 @@ public class ScreeningService implements IScreeningService {
throw new BaseException(DefaultCodeError.NO_HOSPITAL);
}
if(param.getType() == 1){
String screeningQrCode = "";
String qrCode = screeningUrl + "?userId=" + userId;
String path = QrCodeUtil.getQrCodeWithUtf8(qrCode, PropUtil.path);
shareQuestionnaire.setQrCode(PropUtil.imgDomain + path);
if("WeiShengYuan".equals(shareQuestionnaire.getPositionCode())){
screeningQrCode = ScreeningQrCodeUtil.getScreeningQrCode(PropUtil.path, qrCode, shareQuestionnaire.getHospitalName(),"");
}else {
screeningQrCode = ScreeningQrCodeUtil.getScreeningQrCode(PropUtil.path, qrCode, shareQuestionnaire.getHospitalName(),shareQuestionnaire.getDoctorName());
}
shareQuestionnaire.setQrCode(PropUtil.imgDomain + screeningQrCode);
}
return shareQuestionnaire;
}

87
src/main/java/com/ccsens/carbasics/util/ScreeningQrCodeUtil.java

@ -0,0 +1,87 @@
package com.ccsens.carbasics.util;
import cn.hutool.core.date.DateUtil;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.javase.QRCode;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
public class ScreeningQrCodeUtil {
public static String getScreeningQrCode(String filePath, String qrCodeValue, String str1,String str2) throws IOException, WriterException {
//生成二维码
String fileName = "qrCode/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
HashMap<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.MARGIN, 1);
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix =qrCodeWriter.encode(qrCodeValue, BarcodeFormat.QR_CODE, 180, 180,hints);
File file = new File(filePath, fileName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
Path path = FileSystems.getDefault().getPath(filePath + fileName);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
//将二维码放在推按模板上
ResourceLoader resourceLoader = new DefaultResourceLoader();
InputStream is = resourceLoader.getResource("classpath:templates/screeningQrCodeTemplates.png").getInputStream();
BufferedImage bigImage = ImageIO.read(is);
BufferedImage smallImage = ImageIO.read(new FileInputStream(path.toFile()));
int x = (bigImage.getWidth() - smallImage.getWidth()) / 2;
int y = (bigImage.getHeight() - smallImage.getHeight()) / 2 + 20;
try {
Graphics2D g = bigImage.createGraphics();
//将二维码放在模板上
g.drawImage(smallImage, x, y, smallImage.getWidth(), smallImage.getHeight(), null);
Font font = new Font(null, Font.BOLD, 18);
g.setFont(font);
g.setColor(Color.black);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
FontMetrics fontMetrics = g.getFontMetrics(font);
// 计算出中心点 x 位置
int centerX = bigImage.getWidth() / 2;
// 文字宽度
int textWidth1 = fontMetrics.stringWidth(str1);
// 计算出中心点,并且绘制出文字
g.drawString(str1, centerX - textWidth1 / 2, y + smallImage.getHeight() + 30);
// 文字宽度
int textWidth2 = fontMetrics.stringWidth(str2);
// 计算出中心点,并且绘制出文字
g.drawString(str2, centerX - textWidth2 / 2, y + smallImage.getHeight() + 60);
g.dispose();
//往输出流中写数据
ImageIO.write(bigImage, "png", new File(filePath + fileName));
} catch (Exception e) {
e.printStackTrace();
}
return fileName;
}
}

4
src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: pre
include: common, util-pre
active: test
include: common, util-test

17
src/main/resources/mapper_dao/OrganizationPositionDao.xml

@ -79,7 +79,22 @@
<select id="getHospitalNameAndDoctorName"
resultType="com.ccsens.carbasics.bean.vo.QuestionnaireVo$ShareQuestionnaire">
SELECT
d.`name` as hospitalName,
d.`code` as positionCode,
if(d.`code` = 'WeiShengYuan',d.`name`,
(
SELECT
od.`name`
FROM
t_organization_department od,
t_organization_department_parent dp
WHERE
od.id = dp.parent_id
and od.rec_status = 0
and dp.rec_status = 0
and dp.department_id = d.id
limit 1
)
) as hospitalName,
m.`name` as doctorName
FROM
t_organization_position p,

BIN
src/main/resources/templates/screeningQrCodeTemplates.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Loading…
Cancel
Save