liurunyu
2024-04-26 9b6a841844210ceb76084c9ebcb51e4650cef934
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/qrCode/MarkQrCodeCtrl.java
File was renamed from pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/code/MarkCodeCtrl.java
@@ -1,4 +1,4 @@
package com.dy.pmsBase.code;
package com.dy.pmsBase.qrCode;
import cn.hutool.core.codec.Base64;
@@ -7,6 +7,8 @@
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pmsGlobal.util.QrCodeConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -22,9 +24,9 @@
 */
@Slf4j
@RestController
@RequestMapping(path = "markCode")
@RequestMapping(path = "markQrCode")
@SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked")
public class MarkCodeCtrl {
public class MarkQrCodeCtrl {
    /**
     * 客户端请求得到默认密码
@@ -34,18 +36,21 @@
    public BaseResponse<List<ResultVo>> show() {
        try{
            List<ResultVo> list = new ArrayList<>() ;
            URL logoUrl = MarkCodeCtrl.class.getResource("/images/logo.png") ;
            Resource resource = new ClassPathResource("/images/logo.png");
            File logoPngFile = resource.getFile() ;
            String[][] marks = QrCodeConstant.Marks() ;
            for(String[] mark : marks){
                ResultVo vo = new ResultVo() ;
                vo.code = mark[0] ;
                vo.name = mark[1] ;
                BufferedImage bufferedImage = QrCodeGenerator.toBufferedImage(QrCodeGenerator.createBitMatrix(mark[0], QrCodeConstant.MarkQrCodeWidth, QrCodeConstant.MarkQrCodeHeight));
                if(logoUrl != null){
                    bufferedImage = QrCodeGenerator.addQrCodeLogo(bufferedImage, new File(logoUrl.getFile()));
                //vo.code = "1234567890123456789012" ;
                //BufferedImage bufferedImage = QrCodeGenerator.toBufferedImage(QrCodeGenerator.createBitMatrix(vo.code, 30, 30));
                BufferedImage bufferedImage = QrCodeGenerator.toBufferedImage(QrCodeGenerator.createBitMatrix(vo.code, QrCodeConstant.MarkQrCodeWidth, QrCodeConstant.MarkQrCodeHeight));
                if(logoPngFile != null && logoPngFile.exists()){
                    bufferedImage = QrCodeGenerator.addQrCodeLogo(bufferedImage, logoPngFile);
                }
                byte[] codes = QrCodeGenerator.bufferedImageToByteArray(bufferedImage, "JPG");
                vo.imgBase64 = Base64.encode(codes);
                vo.imgBase64 = "data:image/jpeg;base64," + Base64.encode(codes);
                list.add(vo) ;
            }
            return BaseResponseUtils.buildSuccess(list);