diff --git a/pom.xml b/pom.xml index 500674f..c12e608 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,24 @@ httpclient 4.5.14 + + + + + com.google.zxing + core + 3.3.3 + + + + com.google.zxing + javase + 3.3.3 + diff --git a/src/main/java/com/hxgk/lowcode/controller/AssociatedFormsController.java b/src/main/java/com/hxgk/lowcode/controller/AssociatedFormsController.java index d5a5dff..a318585 100644 --- a/src/main/java/com/hxgk/lowcode/controller/AssociatedFormsController.java +++ b/src/main/java/com/hxgk/lowcode/controller/AssociatedFormsController.java @@ -1,7 +1,7 @@ package com.hxgk.lowcode.controller; import com.alibaba.fastjson2.JSON; -import com.hxgk.lowcode.mapper.CustomerFormViewMapper; + import com.hxgk.lowcode.model.entity.AsfTableFillResult; import com.hxgk.lowcode.model.entity.CustomerFormTableSingleFieldValue; import com.hxgk.lowcode.model.entity.Option; @@ -32,8 +32,7 @@ public class AssociatedFormsController { private AsfDataTitlesByIdsQueryParam asfDataTitlesByIdsQueryParam; @Autowired private HrService hrService; - @Autowired - private CustomerFormViewMapper customerFormViewMapper; + public AssociatedFormsController() { } diff --git a/src/main/java/com/hxgk/lowcode/controller/QrCodeController.java b/src/main/java/com/hxgk/lowcode/controller/QrCodeController.java new file mode 100644 index 0000000..f7a1095 --- /dev/null +++ b/src/main/java/com/hxgk/lowcode/controller/QrCodeController.java @@ -0,0 +1,63 @@ +package com.hxgk.lowcode.controller; + + +import com.hxgk.lowcode.model.entity.response.QrCodeDetailsResponseEntity; +import com.hxgk.lowcode.service.QrCodeService; +import com.hxgk.lowcode.utils.JsonData; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map; + +@RestController +@RequestMapping("/lowCode") +public class QrCodeController { + + @Autowired + QrCodeService qrCodeService; + + public QrCodeController(){ + + } + + /*获取用户有权限的启用状态的表单列表树形结构*/ + @RequestMapping(value = "/QrCode/getQrCodeImgInside") + public JsonData getCustomerFormList(@RequestHeader(value = "User-Key") String key, + @RequestHeader(value = "User-Token") String token, + @RequestBody Map requestBody) { + String cfid = requestBody.get("cfid"); + if(StringUtils.isBlank(key)||StringUtils.isBlank(token)||StringUtils.isBlank(cfid)){ + return JsonData.buildError("请重新登录"); + }else{ + String bufferedImage = qrCodeService.generateQrCodeByCfid(cfid); + return JsonData.buildSuccess(bufferedImage); + } + + } + + /*获取用户有权限的启用状态的表单列表树形结构*/ + @RequestMapping(value = "/QrCode/getDetailQrCodes") + public JsonData getDetailQrCodes(@RequestHeader(value = "User-Key") String key, + @RequestHeader(value = "User-Token") String token, + @RequestBody Map requestBody) { + String cfid = (String)requestBody.get("cfid"); + if(StringUtils.isBlank(key)||StringUtils.isBlank(token)||StringUtils.isBlank(cfid)){ + return JsonData.buildError("请重新登录"); + }else{ + ArrayList ids = (ArrayList) requestBody.get("idArray"); + LinkedHashMap settings = (LinkedHashMap) requestBody.get("settings"); + LinkedHashMap result = qrCodeService.getDetailQrCodes(cfid,ids,settings); + return JsonData.buildSuccess(result); + } + + } + + +} diff --git a/src/main/java/com/hxgk/lowcode/mapper/CustomerFormViewMapper.java b/src/main/java/com/hxgk/lowcode/mapper/CustomerFormViewMapper.java index 80caf66..259a3e7 100644 --- a/src/main/java/com/hxgk/lowcode/mapper/CustomerFormViewMapper.java +++ b/src/main/java/com/hxgk/lowcode/mapper/CustomerFormViewMapper.java @@ -19,4 +19,6 @@ public interface CustomerFormViewMapper { String getIdByCfid(String cfid); ArrayList getAppsByGroupId(@Param("groupid") String id); + + CustomerFormView getCustomerFormViewByCfid(String cfid); } diff --git a/src/main/java/com/hxgk/lowcode/mapper/FieldRecordMapper.java b/src/main/java/com/hxgk/lowcode/mapper/FieldRecordMapper.java index 21a2257..b96cafe 100644 --- a/src/main/java/com/hxgk/lowcode/mapper/FieldRecordMapper.java +++ b/src/main/java/com/hxgk/lowcode/mapper/FieldRecordMapper.java @@ -42,4 +42,8 @@ public interface FieldRecordMapper { ArrayList> queryAsfLeftMapListWithWhereCondition(@Param("leftTableName") String leftTableName, @Param("toSelectTableFeilds") ArrayList toSelectTableFeilds, @Param("currentMastersKey")String currentMastersKey, @Param("whereLeft") String whereLeft,@Param("whereOperator") String whereOperator,@Param("whereRight") String whereRight); + + List> getColumnComments(@Param("tableName") String dbFormName,@Param("stringArrayList")ArrayList stringArrayList); + + LinkedHashMap getQrCodeTableFields(@Param("asfFormName") String dbFormName,@Param("fields") ArrayList stringArrayList,@Param("id") String id); } diff --git a/src/main/java/com/hxgk/lowcode/model/entity/response/QrCodeDetailsResponseEntity.java b/src/main/java/com/hxgk/lowcode/model/entity/response/QrCodeDetailsResponseEntity.java new file mode 100644 index 0000000..a98f274 --- /dev/null +++ b/src/main/java/com/hxgk/lowcode/model/entity/response/QrCodeDetailsResponseEntity.java @@ -0,0 +1,29 @@ +package com.hxgk.lowcode.model.entity.response; + +import org.springframework.stereotype.Repository; + +import java.util.LinkedHashMap; +//单个二维码图片对象及其附属信息 +@Repository +public class QrCodeDetailsResponseEntity { + //二维码图片 + private String bufferedImage; + //要显示在表格中的字段map + private LinkedHashMap fieldsMap; + + public String getBufferedImage() { + return bufferedImage; + } + + public void setBufferedImage(String bufferedImage) { + this.bufferedImage = bufferedImage; + } + + public LinkedHashMap getFieldsMap() { + return fieldsMap; + } + + public void setFieldsMap(LinkedHashMap fieldsMap) { + this.fieldsMap = fieldsMap; + } +} diff --git a/src/main/java/com/hxgk/lowcode/service/CustomerFormViewService.java b/src/main/java/com/hxgk/lowcode/service/CustomerFormViewService.java index 69c5305..dc3c162 100644 --- a/src/main/java/com/hxgk/lowcode/service/CustomerFormViewService.java +++ b/src/main/java/com/hxgk/lowcode/service/CustomerFormViewService.java @@ -7,4 +7,6 @@ import java.util.ArrayList; public interface CustomerFormViewService { ArrayList getAppsByGroupId(CustomerFormGroup item); + + CustomerFormView getCustomerFormViewByCfid(String cfid); } diff --git a/src/main/java/com/hxgk/lowcode/service/QrCodeService.java b/src/main/java/com/hxgk/lowcode/service/QrCodeService.java new file mode 100644 index 0000000..5b80191 --- /dev/null +++ b/src/main/java/com/hxgk/lowcode/service/QrCodeService.java @@ -0,0 +1,13 @@ +package com.hxgk.lowcode.service; + +import com.hxgk.lowcode.model.entity.response.QrCodeDetailsResponseEntity; + +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +public interface QrCodeService { + String generateQrCodeByCfid(String cfid); + + LinkedHashMap getDetailQrCodes(String cfid, ArrayList ids, LinkedHashMap settings); +} diff --git a/src/main/java/com/hxgk/lowcode/service/impl/CustomerFormViewServiceImpl.java b/src/main/java/com/hxgk/lowcode/service/impl/CustomerFormViewServiceImpl.java index 1a081e8..16ccd83 100644 --- a/src/main/java/com/hxgk/lowcode/service/impl/CustomerFormViewServiceImpl.java +++ b/src/main/java/com/hxgk/lowcode/service/impl/CustomerFormViewServiceImpl.java @@ -20,4 +20,10 @@ public class CustomerFormViewServiceImpl implements CustomerFormViewService { public ArrayList getAppsByGroupId(CustomerFormGroup item) { return customerFormViewMapper.getAppsByGroupId(item.getId()); } + + @Override + public CustomerFormView getCustomerFormViewByCfid(String cfid) { + CustomerFormView customerFormView = customerFormViewMapper.getCustomerFormViewByCfid(cfid); + return customerFormView; + } } diff --git a/src/main/java/com/hxgk/lowcode/service/impl/QrCodeServiceImpl.java b/src/main/java/com/hxgk/lowcode/service/impl/QrCodeServiceImpl.java new file mode 100644 index 0000000..b5d566a --- /dev/null +++ b/src/main/java/com/hxgk/lowcode/service/impl/QrCodeServiceImpl.java @@ -0,0 +1,215 @@ +package com.hxgk.lowcode.service.impl; + +import com.hxgk.lowcode.mapper.FieldRecordMapper; +import com.hxgk.lowcode.model.entity.CustomerFormView; +import com.hxgk.lowcode.model.entity.response.QrCodeDetailsResponseEntity; +import com.hxgk.lowcode.service.CustomerFormViewService; +import com.hxgk.lowcode.service.QrCodeService; +import com.hxgk.lowcode.utils.QRCodeUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.awt.image.BufferedImage; +import java.util.*; +import java.util.stream.Collectors; + +@Service +public class QrCodeServiceImpl implements QrCodeService { + + @Autowired + CustomerFormViewService customerFormViewService; + @Autowired + FieldRecordMapper fieldRecordMapper; + + @Override + public String generateQrCodeByCfid(String cfid) { + + QRCodeUtil qrCodeUtil = new QRCodeUtil(); + String qrCodeStr = ""; + //String qrCodeStr = "https://wab.hxgk.group/#/form_table/taskListPage? id=112&key=287135214646333440&formid=116&formKey=287145907965661184&title=t2&state=1"; + String prefixLocal = "http://localhost:9998/form_table/taskListPage?"; + String prefixout = "https://wab.hxgk.group/#/form_table/taskListPage?"; + //获取参数 + /* + * + id cfid + key groupid + formid id + formKey signCode + title name + state states + * */ + CustomerFormView c = customerFormViewService.getCustomerFormViewByCfid(cfid); + //上线修改 + qrCodeStr = prefixout+"id="+c.getCfid()+"&key="+c.getGroupid()+"&formid="+c.getId()+"&formKey="+c.getSignCode()+"&title="+c.getName()+"&state="+c.getStates(); + System.out.println(qrCodeStr); + try { + BufferedImage bufferedImage = qrCodeUtil.getQRCodeImage(qrCodeStr, "生成的二维码"); + String base64 = qrCodeUtil.bufferedImageToBase64(bufferedImage); + return base64; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + } + + @Override + public LinkedHashMap getDetailQrCodes(String cfid, ArrayList ids, LinkedHashMap settings) { + LinkedHashMap result = new LinkedHashMap(); + QRCodeUtil qrCodeUtil = new QRCodeUtil(); + String basicQrCodeStr = ""; + //String basicQrCodeStr = "https://wab.hxgk.group/#/form_table/taskListPage? id=112&key=287135214646333440&formid=116&formKey=287145907965661184&title=t2&state=1"; + String prefixLocal = "http://localhost:9998/form_table/taskListPage?"; + String prefixout = "https://wab.hxgk.group/#/form_table/taskListPage?"; + CustomerFormView c = customerFormViewService.getCustomerFormViewByCfid(cfid); + //上线修改 + basicQrCodeStr = prefixout+"id="+c.getCfid()+"&key="+c.getGroupid()+"&formid="+c.getId()+"&formKey="+c.getSignCode()+"&title="+c.getName()+"&state="+c.getStates(); + //查询要展示在表格中的信息 + ArrayList qrCodeShowFields = new ArrayList<>(); + Object qrCodePrintStyle = settings.get("qrCodePrintStyle"); + String qrCodePrintStyleStr = ""; + if(qrCodePrintStyle==null){ + qrCodePrintStyle = (Object) "1"; + } + if(qrCodePrintStyle!=null&&!StringUtils.isBlank((String)qrCodePrintStyle)){ + qrCodePrintStyleStr = (String)qrCodePrintStyle; + if(qrCodePrintStyleStr.equals("2")){//需要根据已选择的字段拼装表格 + qrCodeShowFields = (ArrayList) settings.get("qrCodeShowFields"); + //表名 + String dbFormName = (String)settings.get("name"); + //字段List + ArrayList stringArrayList = keepLastPartAfterColon(qrCodeShowFields); + //根据list查询备注 + List> fieldsAndComments = fieldRecordMapper.getColumnComments(dbFormName,stringArrayList); + HashMap fieldsAndComments1 = convertListToHashMap(fieldsAndComments); + LinkedHashMap fieldsAndCommentsResult = sortMapByList(stringArrayList, fieldsAndComments1); + fieldsAndCommentsResult = updateEmptyValues(fieldsAndCommentsResult); + for (String id:ids) { + QrCodeDetailsResponseEntity qrCodeDetailsResponseEntity = new QrCodeDetailsResponseEntity(); + String currentQrCodeStr = basicQrCodeStr+"&qrDetailId="+id; + BufferedImage currentBufferedImage = null; + try { + currentBufferedImage = qrCodeUtil.getQRCodeImage(currentQrCodeStr, "生成的单条信息详情二维码"); + } catch (Exception e) { + e.printStackTrace(); + } + //当前id的二维码base64图片 + String currentBase64 = qrCodeUtil.bufferedImageToBase64(currentBufferedImage); + LinkedHashMap currentFieldsMap = new LinkedHashMap<>(); + if(qrCodeShowFields.size()>0){ + //用户要输出表格而且至少选择了一条要放在表格中的属性 + //需要根据已选择的字段拼装表格 + LinkedHashMap map = fieldRecordMapper.getQrCodeTableFields(dbFormName,stringArrayList,id); + map = convertMap(map); + currentFieldsMap = mergeMaps(fieldsAndCommentsResult, map); + System.out.println(1); + } + qrCodeDetailsResponseEntity.setBufferedImage(currentBase64); + qrCodeDetailsResponseEntity.setFieldsMap(currentFieldsMap); + result.put(id,qrCodeDetailsResponseEntity); + } + }else{ + for (String id:ids) { + QrCodeDetailsResponseEntity qrCodeDetailsResponseEntity = new QrCodeDetailsResponseEntity(); + String currentQrCodeStr = basicQrCodeStr+"&qrDetailId="+id; + BufferedImage currentBufferedImage = null; + try { + currentBufferedImage = qrCodeUtil.getQRCodeImage(currentQrCodeStr, "生成的单条信息详情二维码"); + } catch (Exception e) { + e.printStackTrace(); + } + //当前id的二维码base64图片 + String currentBase64 = qrCodeUtil.bufferedImageToBase64(currentBufferedImage); + //LinkedHashMap currentFieldsMap = new LinkedHashMap<>(); + + qrCodeDetailsResponseEntity.setBufferedImage(currentBase64); + //qrCodeDetailsResponseEntity.setFieldsMap(currentFieldsMap); + result.put(id,qrCodeDetailsResponseEntity); + } + } + } + + + + + + return result; + } + + public ArrayList keepLastPartAfterColon(ArrayList inputList) { + ArrayList resultList = new ArrayList<>(); + for (String str : inputList) { + int lastColonIndex = str.lastIndexOf(':'); + if (lastColonIndex!= -1) { + // 截取最后一个 : 后面的部分,包括 : 本身 + String lastPart = str.substring(lastColonIndex+1); + resultList.add(lastPart); + } else { + resultList.add(str); + } + } + return resultList; + } + + public HashMap convertListToHashMap(List> list) { + HashMap resultMap = new HashMap<>(); + for (Map map : list) { + String columnName = map.get("COLUMN_NAME"); + String columnComment = map.get("COLUMN_COMMENT"); + if (columnName!= null && columnComment!= null) { + resultMap.put(columnName, columnComment); + } + } + return resultMap; + } + + public LinkedHashMap sortMapByList(ArrayList a, Map b) { + LinkedHashMap c = new LinkedHashMap<>(); + for (String key : a) { + if (b.containsKey(key)) { + c.put(key, b.get(key)); + } + } + return c; + } + + public LinkedHashMap updateEmptyValues(LinkedHashMap inputMap) { + LinkedHashMap resultMap = new LinkedHashMap<>(); + for (Map.Entry entry : inputMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (value == null || value.isEmpty()) { + resultMap.put(key, key); + } else { + resultMap.put(key, value); + } + } + return resultMap; + } + public LinkedHashMap mergeMaps(LinkedHashMap a, LinkedHashMap b) { + LinkedHashMap c = new LinkedHashMap<>(); + for (String key : a.keySet()) { + if (b.containsKey(key)) { + String newValue = a.get(key) + "!@#@!" + b.get(key); + c.put(key, newValue); + } else { + // 可根据需求添加异常处理,此处暂时忽略不存在键的情况 + } + } + return c; + } + + public LinkedHashMap convertMap(LinkedHashMap a) { + LinkedHashMap b = new LinkedHashMap<>(); + for (Map.Entry entry : a.entrySet()) { + String key = entry.getKey(); + // 将值转换为字符串 + String value = String.valueOf(entry.getValue()); + b.put(key, value); + } + return b; + } + +} diff --git a/src/main/java/com/hxgk/lowcode/utils/QRCodeUtil.java b/src/main/java/com/hxgk/lowcode/utils/QRCodeUtil.java new file mode 100644 index 0000000..ee50c3a --- /dev/null +++ b/src/main/java/com/hxgk/lowcode/utils/QRCodeUtil.java @@ -0,0 +1,223 @@ +package com.hxgk.lowcode.utils; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +import org.apache.commons.codec.binary.Base64; +import org.springframework.core.io.ClassPathResource; +import org.springframework.util.StringUtils; +import sun.font.FontDesignMetrics; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; + +/** + * 二维码生成工具类 + * Created by chenzan on 2022/09/19 + */ +public class QRCodeUtil { + private static final int QRCODE_SIZE = 320; // 二维码尺寸,宽度和高度均是320 + private static final String FORMAT_TYPE = "PNG"; // 二维码图片类型 + + /** + * 默认需要logo,无底部文字 + * 返回 BufferedImage 可以使用ImageIO.write(BufferedImage, "png", outputStream);输出 + * + * @param dataStr + * @return 返回 BufferedImage 可以使用ImageIO.write(BufferedImage, "png", outputStream);输出 + */ + + public static BufferedImage getQRCodeImage(String dataStr) throws Exception { + BufferedImage bufferedImage = getQRCodeImage(dataStr, true, null); + return bufferedImage; + } + + /** + * 默认需要logo,无底部文字 + * + * @param dataStr + * @return 返回字节数组 + */ + + public static byte[] getQRCodeByte(String dataStr) throws Exception{ + BufferedImage bufferedImage = getQRCodeImage(dataStr, true, null); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, FORMAT_TYPE, outputStream); + byte[] byteData = outputStream.toByteArray(); + return byteData; + } + + /** + * 默认需要logo,包含底部文字 文字为空则不显示文字 + * 返回 BufferedImage 可以使用ImageIO.write(BufferedImage, "png", outputStream);输出 + * + * @param dataStr + * @return + */ + + public static BufferedImage getQRCodeImage(String dataStr, String bottomText) throws Exception { + BufferedImage bufferedImage = getQRCodeImage(dataStr, true, bottomText); + return bufferedImage; + } + + /** + * 默认需要logo,包含底部文字 文字为空则不显示文字 + * + * @param dataStr + * @return 返回字节数组 + */ + + public static byte[] getQRCodeByte(String dataStr, String bottomText) throws Exception { + BufferedImage bufferedImage = getQRCodeImage(dataStr, true, bottomText); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, FORMAT_TYPE, outputStream); + byte[] byteData = outputStream.toByteArray(); + return byteData; + } + + /** + * 获取二维码图片 + * + * @param dataStr 二维码内容 + * @param needLogo 是否需要添加logo + * @param bottomText 底部文字 为空则不显示 + * @return + */ + + public static BufferedImage getQRCodeImage(String dataStr, boolean needLogo, String bottomText) throws Exception { + needLogo = false; + if (dataStr == null) { + throw new RuntimeException("未包含任何信息"); + } + HashMap hints = new HashMap<>(); + hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); //定义内容字符集的编码 GB2312 GBK utf-8 + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); //定义纠错等级 + hints.put(EncodeHintType.MARGIN, 1); + QRCodeWriter qrCodeWriter = new QRCodeWriter(); + BitMatrix bitMatrix = qrCodeWriter.encode(dataStr, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); + + int width = bitMatrix.getWidth(); + int height = bitMatrix.getHeight(); + int tempHeight = height; + if (StringUtils.hasText(bottomText)) { + tempHeight = tempHeight + 12; + } + BufferedImage image = new BufferedImage(width, tempHeight, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); + } + } + // 判断是否添加logo + if (needLogo) { + insertLogoImage(image); + } + // 判断是否添加底部文字 + if (StringUtils.hasText(bottomText)) { + addFontImage(image, bottomText); + } + return image; + } + + /** + * 插入logo图片 + * + * @param source 二维码图片 + * @throws Exception + */ + private static void insertLogoImage(BufferedImage source) throws Exception { + // 默认logo放于resource/static/image目录下 + ClassPathResource classPathResource = new ClassPathResource("static/image/logo.png"); + InputStream inputStream = classPathResource.getInputStream(); + if (inputStream == null || inputStream.available() == 0) { + return; + } + Image src = ImageIO.read(inputStream); + int width = 30; + int height = 30; + + Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); + BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = tag.getGraphics(); + g.drawImage(image, 0, 0, null); // 绘制缩小后的图 + g.dispose(); + src = image; + + // 插入LOGO + Graphics2D graph = source.createGraphics(); + int x = (QRCODE_SIZE - width) / 2; + int y = (QRCODE_SIZE - height) / 2; + graph.drawImage(src, x, y, width, height, null); + Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); + graph.setStroke(new BasicStroke(3f)); + graph.draw(shape); + graph.dispose(); + } + + private static void addFontImage(BufferedImage source, String declareText) throws Exception{ + //生成image + int defineWidth = QRCODE_SIZE; + int defineHeight = 20; + BufferedImage textImage = new BufferedImage(defineWidth, defineHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = (Graphics2D) textImage.getGraphics(); + //开启文字抗锯齿 + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2.setBackground(Color.WHITE); + g2.clearRect(0, 0, defineWidth, defineHeight); + g2.setPaint(Color.BLACK); + FontRenderContext context = g2.getFontRenderContext(); + //部署linux需要注意 linux无此字体会显示方块 + Font font = new Font("宋体", Font.BOLD, 15); + g2.setFont(font); + LineMetrics lineMetrics = font.getLineMetrics(declareText, context); + FontMetrics fontMetrics = FontDesignMetrics.getMetrics(font); + float offset = (defineWidth - fontMetrics.stringWidth(declareText)) / 2; + float y = (defineHeight + lineMetrics.getAscent() - lineMetrics.getDescent() - lineMetrics.getLeading()) / 2; + g2.drawString(declareText, (int) offset, (int) y); + + Graphics2D graph = source.createGraphics(); + //开启文字抗锯齿 + graph.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + //添加image + int width = textImage.getWidth(null); + int height = textImage.getHeight(null); + + Image src = textImage; + graph.drawImage(src, 0, QRCODE_SIZE - 8, width, height, Color.WHITE, null); + graph.dispose(); + } + /* + + + * */ + + /** + * BufferedImage转base64 + * @param bufferedImage + * @return + */ + public String bufferedImageToBase64(BufferedImage bufferedImage) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + // 设置图片格式 + ImageIO.write(bufferedImage, "jpg", stream); + } catch (IOException e) { + e.printStackTrace(); + } + byte[] bytes = Base64.encodeBase64(stream.toByteArray()); + String base64 = new String(bytes); + return "data:image/jpeg;base64," + base64; + } + +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7b45093..750a6e2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,5 +2,4 @@ spring: profiles: active: dev server: - port: 8112 - #port: 39999 \ No newline at end of file + port: 8112 \ No newline at end of file diff --git a/src/main/resources/mapper/CustomerFormvViewMapper.xml b/src/main/resources/mapper/CustomerFormvViewMapper.xml index 8321c85..e1ba409 100644 --- a/src/main/resources/mapper/CustomerFormvViewMapper.xml +++ b/src/main/resources/mapper/CustomerFormvViewMapper.xml @@ -48,4 +48,13 @@ + + \ No newline at end of file diff --git a/src/main/resources/mapper/FieldRecordMapper.xml b/src/main/resources/mapper/FieldRecordMapper.xml index d663f3f..c6b7f26 100644 --- a/src/main/resources/mapper/FieldRecordMapper.xml +++ b/src/main/resources/mapper/FieldRecordMapper.xml @@ -176,4 +176,29 @@ + + + + + \ No newline at end of file