| | |
| | | */ |
| | | package org.springblade.modules.mechanism.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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; |
| | |
| | | |
| | | 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.springblade.modules.resource.entity.Oss; |
| | | import org.springblade.modules.resource.service.IOssService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springblade.modules.mechanism.entity.Mechanism; |
| | |
| | | import org.springblade.modules.mechanism.service.IMechanismService; |
| | | import org.springblade.core.boot.ctrl.BladeController; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | import sun.misc.BASE64Encoder; |
| | | //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; |
| | | |
| | | /** |
| | | * 控制器 |
| | |
| | | public class MechanismController extends BladeController { |
| | | |
| | | private final IMechanismService mechanismService; |
| | | |
| | | private final IOssService ossService; |
| | | |
| | | /** |
| | | * 对象存储构建类 |
| | | */ |
| | | private final OssBuilder ossBuilder; |
| | | |
| | | /** |
| | | * 详情 |
| | |
| | | @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"); |
| | | mechanism.setGd("0"); |
| | | String url = "http://192.168.0.115:8080/#/mobileLayout/default"; |
| | | //String url = "http://171.34.197.243:786/#/mobileLayout/default"; |
| | | String addressName = URLEncoder.encode(mechanism.getAddressName(), "UTF-8"); |
| | | //String url = "http://192.168.0.115:8080/#/mobileLayout/default"; |
| | | String url = "https://dev.jxpskj.com:8023/zhjg/#/mobileLayout/default"; |
| | | String gotos = URLEncoder.encode("arc", "UTF-8"); |
| | | String mechanismname = URLEncoder.encode(mechanism.getMechanismname(), "UTF-8"); |
| | | String address = URLEncoder.encode(mechanism.getAddress(), "UTF-8"); |
| | | String telephone = URLEncoder.encode(mechanism.getTelephone(), "UTF-8"); |
| | | String introduce = URLEncoder.encode(mechanism.getIntroduce(), "UTF-8"); |
| | | String jd = URLEncoder.encode(mechanism.getJd(), "UTF-8"); |
| | | String x = URLEncoder.encode(mechanism.getX(), "UTF-8"); |
| | | String wd = URLEncoder.encode(mechanism.getWd(), "UTF-8"); |
| | | String gd = URLEncoder.encode(mechanism.getGd(), "UTF-8"); |
| | | String tpurl = URLEncoder.encode(mechanism.getTpurl(), "UTF-8"); |
| | |
| | | String type = URLEncoder.encode(mechanism.getType(), "UTF-8"); |
| | | String mtype = URLEncoder.encode(mechanism.getMtype(), "UTF-8"); |
| | | String loutype = URLEncoder.encode(mechanism.getLoutype(), "UTF-8"); |
| | | String xtype = URLEncoder.encode(mechanism.getXtype(), "UTF-8"); |
| | | String campus = URLEncoder.encode(mechanism.getCampus(), "UTF-8"); |
| | | String heading = URLEncoder.encode(mechanism.getHeading(), "UTF-8"); |
| | | String pitch = URLEncoder.encode(mechanism.getPitch(), "UTF-8"); |
| | | String roll = URLEncoder.encode(mechanism.getRoll(), "UTF-8"); |
| | |
| | | "&telephone=" + telephone + |
| | | "&introduce=" + introduce + |
| | | "&jd=" + jd + |
| | | "&x=" + x + |
| | | "&wd=" + wd + |
| | | "&gd=" + gd + |
| | | "&tpurl=" + tpurl + |
| | |
| | | "&type=" + type + |
| | | "&mtype=" + mtype + |
| | | "&loutype=" + loutype + |
| | | "&xtype=" + xtype + |
| | | "&campus=" + campus + |
| | | "&heading=" + heading + |
| | | "&pitch=" + pitch + |
| | | "&roll=" + roll + |
| | | "&addressName=" + addressName + |
| | | "&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)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 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 { |
| | | QueryWrapper<Oss> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0); |
| | | Oss one = ossService.getOne(wrapper); |
| | | //填写你文件上传的地址以及相应信息 |
| | | // String url = "http://106.225.193.35:2081"; |
| | | // String access = "zhbaadmin"; |
| | | // String secret = "zhbapassword"; |
| | | // String bucket = "zhxy"; |
| | | String url = one.getEndpoint(); |
| | | String access = one.getAccessKey(); |
| | | String secret = one.getSecretKey(); |
| | | String bucket = one.getBucketName(); |
| | | 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; |
| | | String urls = url + "/"+ bucket + "/" + newName; |
| | | //返回 |
| | | return urls; |
| | | } |
| | | |
| | | } |