From d88ce8f933df6a533eddb06f0f2e340a2c697001 Mon Sep 17 00:00:00 2001
From: zrj <646384940@qq.com>
Date: Fri, 30 Aug 2024 18:15:25 +0800
Subject: [PATCH] 修改生成环境数据库连接配置

---
 src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java |  144 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 126 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java b/src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java
index 3e05956..fd46f68 100644
--- a/src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java
+++ b/src/main/java/org/springblade/modules/architecture/controller/ArchitectureController.java
@@ -16,7 +16,10 @@
  */
 package org.springblade.modules.architecture.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;
@@ -26,15 +29,21 @@
 
 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.oss.model.OssFile;
 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.entity.Oss;
+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.*;
@@ -44,12 +53,12 @@
 import org.springblade.modules.architecture.service.IArchitectureService;
 import org.springblade.core.boot.ctrl.BladeController;
 import springfox.documentation.annotations.ApiIgnore;
-import sun.misc.BASE64Encoder;
+//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;
 
@@ -66,9 +75,16 @@
 @Api(value = "", tags = "接口")
 public class ArchitectureController extends BladeController {
 
+
+	private final IOssService ossService;
+
 	private final IArchitectureService architectureService;
 	private final IMechanismService mechanismService;
 	private final ILifeService lifeService;
+	/**
+	 * 对象存储构建类
+	 */
+	private final OssBuilder ossBuilder;
 
 	/**
 	 * 详情
@@ -110,22 +126,23 @@
 	@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");
 		architecture.setGd("0");
-		String url = "http://192.168.0.115:8080/#/mobileLayout/default";
-		//String url = "http://171.34.197.243:786/#/mobileLayout/default";
+		//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 addressName = URLEncoder.encode(architecture.getAddressName(), "UTF-8");
 		String mechanismname = URLEncoder.encode(architecture.getMechanismname(), "UTF-8");
 		String address = null;
 		if (architecture.getAddress() != null) {
 			address = URLEncoder.encode(architecture.getAddress(), "UTF-8");
 		}
-		String telephone=null;
+		String telephone = null;
 		if (architecture.getTelephone() != null) {
-			 telephone = URLEncoder.encode(architecture.getTelephone(), "UTF-8");
+			telephone = URLEncoder.encode(architecture.getTelephone(), "UTF-8");
 		}
 		String introduce = URLEncoder.encode(architecture.getIntroduce(), "UTF-8");
 		String jd = URLEncoder.encode(architecture.getJd(), "UTF-8");
@@ -140,6 +157,7 @@
 			websiteurl = URLEncoder.encode(architecture.getWebsiteurl(), "UTF-8");
 		}
 		String type = URLEncoder.encode(architecture.getType(), "UTF-8");
+		String x = URLEncoder.encode(architecture.getX(), "UTF-8");
 		String xtype = URLEncoder.encode(architecture.getCampus(), "UTF-8");
 		String heading = URLEncoder.encode(architecture.getHeading(), "UTF-8");
 		String pitch = URLEncoder.encode(architecture.getPitch(), "UTF-8");
@@ -156,6 +174,7 @@
 			"&telephone=" + telephone +
 			"&introduce=" + introduce +
 			"&jd=" + jd +
+			"&x=" + x +
 			"&wd=" + wd +
 			"&gd=" + gd +
 			"&tpurl=" + tpurl +
@@ -165,14 +184,18 @@
 			"&heading=" + heading +
 			"&pitch=" + pitch +
 			"&roll=" + roll +
-			"&panoramaurl=" + panoramaurl +
+			"&panoramaurl=" + panoramaurl + "&addressName=" + addressName +
 			"&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));
 	}
 
@@ -269,8 +292,8 @@
 	 * @return
 	 */
 	@GetMapping("/selectArchALL")
-	public R selectArchALL() {
-		return R.data(architectureService.selectArchALL());
+	public R selectArchALL(ArchitectureVO architecture) {
+		return R.data(architectureService.selectArchALL(architecture));
 	}
 
 	/**
@@ -386,12 +409,13 @@
 	 * 校园搜索
 	 *
 	 * @param mechanismName 名称模糊查询
+	 * @param campus 所属校区
 	 * @return
 	 */
 	@GetMapping("/selectLook")
-	public R selectLook(String mechanismName) {
+	public R selectLook(String mechanismName,String campus) {
 		List list = new ArrayList();
-		List<Map<Object, Object>> maps = architectureService.selectLook(mechanismName);
+		List<Map<Object, Object>> maps = architectureService.selectLook(mechanismName,campus);
 		//排除为null的数据
 		List<Map<Object, Object>> list2 = maps.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
 //		for (int i = 0; i < list2.size(); i++) {
@@ -402,4 +426,88 @@
 //		}
 		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(null);
+		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 {
+		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 = url + "/"+ bucket +"/" + newName;
+		//返回
+		return urls;
+	}
+
+
+	/**
+	 * 二维码重新生成 code url 转换
+	 */
+	@GetMapping("/refreshCode")
+	public void refreshCode() throws IOException, ServerException, InsufficientDataException, NoSuchAlgorithmException, InternalException, InvalidResponseException, XmlParserException, InvalidKeyException, ErrorResponseException {
+		List<Architecture> list = architectureService.selectArchALL(null);
+		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();
+		}
+	}
 }

--
Gitblit v1.9.3