zhongrj
2022-10-24 0cc95376f2af6fa5dfbe63ff79cbaf94674531e0
新增接口替换二维码地址,数据新增时修改二维码(保存地址)
11 files modified
1 files added
298 ■■■■■ changed files
src/main/java/org/springblade/common/utils/Base64Util.java 83 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java 86 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/architecture/mapper/ArchitectureMapper.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/architecture/mapper/ArchitectureMapper.xml 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/architecture/service/IArchitectureService.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/architecture/service/impl/ArchitectureServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/mechanism/controller/MechanismController.java 85 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/mechanism/mapper/MechanismMapper.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/mechanism/mapper/MechanismMapper.xml 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/mechanism/service/IMechanismService.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/mechanism/service/impl/MechanismServiceImpl.java 10 ●●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/Base64Util.java
New file
@@ -0,0 +1,83 @@
package org.springblade.common.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.imageio.stream.FileImageInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Base64Util {
    /**
     * 字符串转图片
     * @param base64Str
     * @return
     */
    public static byte[] decode(String base64Str){
        byte[] b = null;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            b = decoder.decodeBuffer(replaceEnter(base64Str));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return b;
    }
    /**
     * 图片转字符串
     * @param image
     * @return
     */
    public static String encode(byte[] image){
        BASE64Encoder decoder = new BASE64Encoder();
        return replaceEnter(decoder.encode(image));
    }
    public static String encode(String uri){
        BASE64Encoder encoder = new BASE64Encoder();
        return replaceEnter(encoder.encode(uri.getBytes()));
    }
    /**
     *
     * @path    图片路径
     * @return
     */
    public static byte[] imageTobyte(String path){
        byte[] data = null;
        FileImageInputStream input = null;
        try {
            input = new FileImageInputStream(new File(path));
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int numBytesRead = 0;
            while((numBytesRead = input.read(buf)) != -1){
                output.write(buf, 0, numBytesRead);
            }
            data = output.toByteArray();
            output.close();
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }
    public static String replaceEnter(String str){
        String reg ="[\n-\r]";
        Pattern p = Pattern.compile(reg);
        Matcher m = p.matcher(str);
        return m.replaceAll("");
    }
}
src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java
@@ -17,6 +17,8 @@
package org.springblade.modules.architecture.controller;
import com.google.zxing.WriterException;
import io.minio.*;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -26,15 +28,19 @@
import javax.validation.Valid;
import org.springblade.common.utils.Base64Util;
import org.springblade.common.utils.QRCodeUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.life.entity.Life;
import org.springblade.modules.life.service.ILifeService;
import org.springblade.modules.mechanism.entity.Mechanism;
import org.springblade.modules.mechanism.service.IMechanismService;
import org.springblade.modules.resource.builder.oss.OssBuilder;
import org.springblade.modules.resource.service.IOssService;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -46,10 +52,10 @@
import springfox.documentation.annotations.ApiIgnore;
import sun.misc.BASE64Encoder;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;
@@ -69,6 +75,10 @@
    private final IArchitectureService architectureService;
    private final IMechanismService mechanismService;
    private final ILifeService lifeService;
    /**
     * 对象存储构建类
     */
    private final OssBuilder ossBuilder;
    /**
     * 详情
@@ -110,7 +120,7 @@
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入architecture")
    public R save(@Valid @RequestBody Architecture architecture) throws IOException, WriterException {
    public R save(@Valid @RequestBody Architecture architecture) throws IOException, WriterException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
        architecture.setPitch("-90");
        architecture.setHeading("0");
        architecture.setRoll("0");
@@ -172,10 +182,14 @@
            "&videourl=" + videourl;
        //生成标注二维码
        byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
        String encode = new BASE64Encoder().encode(qrCodeImage);
        //设置二维码
        String a = "data:image/png;base64," + encode;
        architecture.setCodeurl(a);
//        String encode = new BASE64Encoder().encode(qrCodeImage);
//        //设置二维码
//        String a = "data:image/png;base64," + encode;
        ByteArrayInputStream stream = new ByteArrayInputStream(qrCodeImage);
        String upload = upload(stream);
        stream.close();
        //设置二维码地址
        architecture.setCodeurl(upload);
        return R.status(architectureService.save(architecture));
    }
@@ -405,4 +419,60 @@
//        }
        return R.data(list2);
    }
    /**
     * code url 转换
     */
    @GetMapping("/url")
    public void url() throws IOException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
        List<Architecture> list = architectureService.selectArchALL();
        for (Architecture architecture : list) {
            int index = architecture.getCodeurl().lastIndexOf(",") +1;
            String substring = architecture.getCodeurl().substring(index);
            byte[] qrCodeImage = Base64Util.decode(substring);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(qrCodeImage);
            String url = upload(inputStream);
            architecture.setCodeurl(url);
            architectureService.updateById(architecture);
            //关闭流
            inputStream.close();
        }
    }
    private String upload(ByteArrayInputStream in) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
        //填写你文件上传的地址以及相应信息
        String url = "http://106.225.193.35:2081";
        String access = "zhbaadmin";
        String secret = "zhbapassword";
        String bucket = "zhxy";
        MinioClient minioClient =
            MinioClient.builder()
                .endpoint(url)
                .credentials(access, secret)
                .build();
        // 检查存储桶是否已经存在
        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (!isExist) {
            // 创建一个名为zip的存储桶,用于zip文件。
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
        }
        String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + ".png";
        //创建头部信息
        Map<String, String> headers = new HashMap<>(1 << 2);
        //添加自定义内容类型
        headers.put("Content-Type", "application/octet-stream");
        //上传
        minioClient.putObject(
            PutObjectArgs.builder().bucket(bucket).object(newName).stream(
                in, in.available(), -1)
                .headers(headers)
                .build());
        //文件推送
        String urls = "https://dev.jxpskj.com:8023/zhxy/"+newName;
        //返回
        return urls;
    }
}
src/main/java/org/springblade/modules/architecture/mapper/ArchitectureMapper.java
@@ -55,7 +55,7 @@
    Map<Object,Object> selectInArchite(String id);
    List selectArch();
    List selectArchALL();
    List<Architecture> selectArchALL();
    String selectIns(String id);
    List<Map<Object,Object>> selectAll(String mechanismName);
    List<Map<Object,Object>> selectLook(String mechanismName);
src/main/java/org/springblade/modules/architecture/mapper/ArchitectureMapper.xml
@@ -82,8 +82,9 @@
        WHERE panoramaurl IS NOT NULL
          AND panoramaurl!='' and is_deleted = 0
    </select>
    <select id="selectArchALL" resultType="java.util.HashMap">
        SELECT jd, wd, mechanismName AS mechanismname, tpUrl AS tpurl, codeUrl AS codeurl, introduce, panoramaurl,x
    <select id="selectArchALL" resultType="org.springblade.modules.architecture.entity.Architecture">
        SELECT id,jd, wd, mechanismName AS mechanismname, tpUrl AS tpurl, codeUrl AS codeurl, introduce, panoramaurl,x
        FROM sys_architecture
        WHERE is_deleted = 0
        --         UNION
src/main/java/org/springblade/modules/architecture/service/IArchitectureService.java
@@ -54,7 +54,7 @@
     */
    Map<Object,Object> selectInArchite(String id);
    List selectArch();
    List selectArchALL();
    List<Architecture> selectArchALL();
    String selectIns(String id);
    List<Map<Object,Object>> selectAll(String mechanismName);
    List<Map<Object,Object>> selectLook(String mechanismName);
src/main/java/org/springblade/modules/architecture/service/impl/ArchitectureServiceImpl.java
@@ -62,7 +62,7 @@
    }
    @Override
    public List selectArchALL() {
    public List<Architecture> selectArchALL() {
        return baseMapper.selectArchALL();
    }
src/main/java/org/springblade/modules/mechanism/controller/MechanismController.java
@@ -17,6 +17,8 @@
package org.springblade.modules.mechanism.controller;
import com.google.zxing.WriterException;
import io.minio.*;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -25,11 +27,14 @@
import javax.validation.Valid;
import org.springblade.common.utils.Base64Util;
import org.springblade.common.utils.QRCodeUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.resource.builder.oss.OssBuilder;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.mechanism.entity.Mechanism;
@@ -39,10 +44,16 @@
import springfox.documentation.annotations.ApiIgnore;
import sun.misc.BASE64Encoder;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * 控制器
@@ -57,6 +68,11 @@
public class MechanismController extends BladeController {
    private final IMechanismService mechanismService;
    /**
     * 对象存储构建类
     */
    private final OssBuilder ossBuilder;
    /**
     * 详情
@@ -97,7 +113,7 @@
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入mechanism")
    public R save(@Valid @RequestBody Mechanism mechanism) throws IOException, WriterException {
    public R save(@Valid @RequestBody Mechanism mechanism) throws IOException, WriterException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
        mechanism.setPitch("-90");
        mechanism.setHeading("0");
        mechanism.setRoll("0");
@@ -144,10 +160,14 @@
            "&videourl=" + videourl;
        //生成标注二维码
        byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
        String encode = new BASE64Encoder().encode(qrCodeImage);
        //设置二维码
        String a = "data:image/png;base64," + encode;
        mechanism.setCodeurl(a);
//        String encode = new BASE64Encoder().encode(qrCodeImage);
//        //设置二维码
//        String a = "data:image/png;base64," + encode;
        ByteArrayInputStream stream = new ByteArrayInputStream(qrCodeImage);
        String upload = upload(stream);//关闭流
        stream.close();
        //设置二维码地址
        mechanism.setCodeurl(upload);
        return R.status(mechanismService.save(mechanism));
    }
@@ -183,4 +203,59 @@
    }
    /**
     * code url 转换
     */
    @GetMapping("/url")
    public void url() throws IOException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
        List<Mechanism> list = mechanismService.selectAllList();
        for (Mechanism mechanism : list) {
            int index = mechanism.getCodeurl().lastIndexOf(",") +1;
            String substring = mechanism.getCodeurl().substring(index);
            byte[] qrCodeImage = Base64Util.decode(substring);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(qrCodeImage);
            String url = upload(inputStream);
            mechanism.setCodeurl(url);
            mechanismService.updateById(mechanism);
            //关闭流
            inputStream.close();
        }
    }
    private String upload(ByteArrayInputStream in) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
        //填写你文件上传的地址以及相应信息
        String url = "http://106.225.193.35:2081";
        String access = "zhbaadmin";
        String secret = "zhbapassword";
        String bucket = "zhxy";
        MinioClient minioClient =
            MinioClient.builder()
                .endpoint(url)
                .credentials(access, secret)
                .build();
        // 检查存储桶是否已经存在
        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (!isExist) {
            // 创建一个名为zip的存储桶,用于zip文件。
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
        }
        String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + ".png";
        //创建头部信息
        Map<String, String> headers = new HashMap<>(1 << 2);
        //添加自定义内容类型
        headers.put("Content-Type", "application/octet-stream");
        //上传
        minioClient.putObject(
            PutObjectArgs.builder().bucket(bucket).object(newName).stream(
                in, in.available(), -1)
                .headers(headers)
                .build());
        //文件推送
        String urls = "https://dev.jxpskj.com:8023/zhxy/"+newName;
        //返回
        return urls;
    }
}
src/main/java/org/springblade/modules/mechanism/mapper/MechanismMapper.java
@@ -46,4 +46,9 @@
     */
    String selectIn(String id);
    /**
     * 查询所有
     * @return
     */
    List<Mechanism> selectAllList();
}
src/main/java/org/springblade/modules/mechanism/mapper/MechanismMapper.xml
@@ -30,4 +30,10 @@
        SELECT GROUP_CONCAT(mechanismName) as mechanismname  FROM `sys_mechanism` WHERE loutype=#{id} and is_deleted = 0
    </select>
    <select id="selectAllList" resultType="org.springblade.modules.mechanism.entity.Mechanism">
        select id,codeUrl AS codeurl
         from sys_mechanism where is_deleted = 0
    </select>
</mapper>
src/main/java/org/springblade/modules/mechanism/service/IMechanismService.java
@@ -21,6 +21,8 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
 *  服务类
 *
@@ -43,4 +45,10 @@
     * @return
     */
    String selectIn(String id);
    /**
     * 查询所有
     * @return
     */
    List<Mechanism> selectAllList();
}
src/main/java/org/springblade/modules/mechanism/service/impl/MechanismServiceImpl.java
@@ -24,6 +24,8 @@
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
 *  服务实现类
 *
@@ -43,4 +45,12 @@
        return baseMapper.selectIn(id);
    }
    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Mechanism> selectAllList() {
        return baseMapper.selectAllList();
    }
}
src/main/resources/application-test.yml
@@ -17,9 +17,9 @@
#    url: jdbc:mysql://localhost:3306/bladex_boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
#    username: root
#    password: root
    url: jdbc:mysql://localhost:3306/zhxyys?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    url: jdbc:mysql://192.168.0.126:3306/zhxyys?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: 245436
    password: NCzhba@2022
#第三方登陆
social: