From 26928992e9a2d3e83e6cfc138d827d2e83d4570a Mon Sep 17 00:00:00 2001
From: hurui <177768073@qq.com>
Date: Thu, 16 May 2024 17:08:59 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../bweb/controller/FileUploadController.java | 9 ++
.../com/order/controller/OrderController.java | 4 +-
service/pom.xml | 5 +
.../com/hfkj/common/obs/HuaWeiYunObs.java | 100 ++++++++++++++++++
.../java/com/hfkj/config/CommonSysConfig.java | 7 ++
.../hfkj/service/order/BsOrderService.java | 7 ++
.../order/impl/BsOrderServiceImpl.java | 19 ++++
.../resources/dev/commonConfig.properties | 4 +
8 files changed, 154 insertions(+), 1 deletion(-)
create mode 100644 service/src/main/java/com/hfkj/common/obs/HuaWeiYunObs.java
diff --git a/bweb/src/main/java/com/bweb/controller/FileUploadController.java b/bweb/src/main/java/com/bweb/controller/FileUploadController.java
index 7343d82..251a9b1 100644
--- a/bweb/src/main/java/com/bweb/controller/FileUploadController.java
+++ b/bweb/src/main/java/com/bweb/controller/FileUploadController.java
@@ -1,10 +1,13 @@
package com.bweb.controller;
+import com.hfkj.common.obs.HuaWeiYunObs;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.bweb.config.SysConfig;
+import com.hfkj.config.CommonSysConst;
import com.hfkj.model.ResponseData;
import com.hfkj.service.FileUploadService;
+import com.obs.services.model.PutObjectResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.coobird.thumbnailator.Thumbnails;
@@ -72,6 +75,9 @@ public class FileUploadController {
out.write(file.getBytes());
out.flush();
fileNames.add(childPath + "/" + fileName);
+
+ PutObjectResult putObjectResult = HuaWeiYunObs.putObject(CommonSysConst.getSysConfig().getObsBucketName(),
+ childPath + "/" + fileName, new File(destDirName + "/" + fileName));
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
@@ -132,6 +138,9 @@ public class FileUploadController {
if (fis.available() > 500000) {
Thumbnails.of(new FileInputStream(destDirName + File.separator + fileName)).scale(0.5).toFile(new File(destDirName + File.separator + fileName));
}
+ PutObjectResult putObjectResult = HuaWeiYunObs.putObject(CommonSysConst.getSysConfig().getObsBucketName(),
+ childPath + "/" + fileName, new File(destDirName + "/" + fileName));
+
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
diff --git a/order/src/main/java/com/order/controller/OrderController.java b/order/src/main/java/com/order/controller/OrderController.java
index 220de97..a62de41 100644
--- a/order/src/main/java/com/order/controller/OrderController.java
+++ b/order/src/main/java/com/order/controller/OrderController.java
@@ -8,6 +8,7 @@ import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
+import com.hfkj.entity.BsOrder;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.model.order.OrderChildModel;
@@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -138,7 +140,7 @@ public class OrderController {
param.put("orderNo", orderNo);
PageHelper.startPage(pageNum, pageSize);
- return ResponseMsgUtil.success(null);
+ return ResponseMsgUtil.success(new PageInfo<>(orderService.getOrderList(param)));
} catch (Exception e) {
log.error("error!",e);
diff --git a/service/pom.xml b/service/pom.xml
index 8b7eb85..153f99a 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -238,6 +238,11 @@
org.projectlombok
lombok
+
+ com.huaweicloud
+ esdk-obs-java-bundle
+ [3.21.8,)
+
diff --git a/service/src/main/java/com/hfkj/common/obs/HuaWeiYunObs.java b/service/src/main/java/com/hfkj/common/obs/HuaWeiYunObs.java
new file mode 100644
index 0000000..da74f62
--- /dev/null
+++ b/service/src/main/java/com/hfkj/common/obs/HuaWeiYunObs.java
@@ -0,0 +1,100 @@
+package com.hfkj.common.obs;
+
+import com.hfkj.config.CommonSysConst;
+import com.obs.services.ObsClient;
+import com.obs.services.model.*;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * 华为云obs 对象存储
+ * @author hurui
+ */
+public class HuaWeiYunObs {
+
+ public static String url = CommonSysConst.getSysConfig().getObsUrl();
+ private static String endPoint = CommonSysConst.getSysConfig().getObsEndPoint();
+ private static String accessKey = "CZVO7VAT8UV2RPYJUBD2";
+ private static String secretKey = "gyjrR8rYq9w2maPq9VmpRqoMqCJzQMH8vMctg7eE";
+ public static String bucketName = CommonSysConst.getSysConfig().getObsUrl();
+
+ /**
+ * 创建请求
+ * @return
+ */
+ private static ObsClient createClient() {
+ return new ObsClient(accessKey, secretKey, endPoint);
+ }
+
+ /**
+ * 关闭请求
+ * @param obsClient
+ */
+ private static void closeClient(ObsClient obsClient) {
+ try {
+ if (obsClient != null) {
+ obsClient.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 上传文件
+ * @param bucketName 桶名称
+ * @param objectName 对象名称 例如:1.jpg
+ * @param file 文件路径
+ * @return
+ */
+ public static PutObjectResult putObject(String bucketName,String objectName, File file) {
+ ObsClient client = createClient();
+ try {
+ return client.putObject(bucketName, objectName, file);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeClient(client);
+ }
+ return null;
+ }
+
+ /**
+ * 上传文件
+ * @param fileUrl 文件路径
+ * @param bucketName 桶名称
+ * @param objectName 对象路径名称 例如:temporary/1.jpg
+ * @return
+ */
+ public static void obsUtilPutObject(String fileUrl,String bucketName,String objectName) throws IOException {
+ // 执行上传命令
+ new ProcessBuilder("/bin/bash", "-c", "obsutil cp "+ fileUrl + " obs://"+bucketName +"/"+ objectName).start();
+ }
+
+ /**
+ * 获取图片临时路径
+ * @param bucketName 桶名称
+ * @param objectName 对象名称 例如:1.jpg
+ * @return
+ */
+ public static String getImgSignedUrl(String bucketName,String objectName) {
+ ObsClient client = createClient();
+ try {
+ TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, 1800L);
+ request.setBucketName(bucketName);
+ request.setObjectKey(objectName);
+
+ TemporarySignatureResponse response = client.createTemporarySignature(request);
+ return response.getSignedUrl();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeClient(client);
+ }
+ return null;
+ }
+
+
+}
diff --git a/service/src/main/java/com/hfkj/config/CommonSysConfig.java b/service/src/main/java/com/hfkj/config/CommonSysConfig.java
index 463e848..2d791f1 100644
--- a/service/src/main/java/com/hfkj/config/CommonSysConfig.java
+++ b/service/src/main/java/com/hfkj/config/CommonSysConfig.java
@@ -66,6 +66,13 @@ public class CommonSysConfig {
*/
private String blxPostUrl;
+ /**
+ * 对象存储
+ */
+ private String obsUrl;
+ private String obsBucketName;
+ private String obsEndPoint;
+
/**
* 汇联通卡券请求地址
*/
diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderService.java b/service/src/main/java/com/hfkj/service/order/BsOrderService.java
index a36cc59..8e84e24 100644
--- a/service/src/main/java/com/hfkj/service/order/BsOrderService.java
+++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java
@@ -68,4 +68,11 @@ public interface BsOrderService {
*/
List getOrderList(Map param);
+ /**
+ * 查询用户订单列表
+ * @param param
+ * @return
+ */
+ List getUserOrderList(Map param);
+
}
diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java
index 171e0d1..325fbf3 100644
--- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java
+++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java
@@ -34,6 +34,7 @@ import org.thymeleaf.util.DateUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -301,4 +302,22 @@ public class BsOrderServiceImpl implements BsOrderService {
example.setOrderByClause("create_time desc");
return orderMapper.selectByExample(example);
}
+
+ @Override
+ public List getUserOrderList(Map param) {
+ BsOrderExample example = new BsOrderExample();
+ BsOrderExample.Criteria criteria = example.createCriteria();
+
+ if (StringUtils.isNotBlank(MapUtils.getString(param, "order"))) {
+ criteria.andOrderNoLike("%"+MapUtils.getString(param, "order")+"%");
+ }
+
+ example.setOrderByClause("create_time desc");
+ List orderModelList = new ArrayList<>();
+ List orderList = orderMapper.selectByExample(example);
+ for (BsOrder order : orderList) {
+ orderModelList.add(getDetail(order.getOrderNo()));
+ }
+ return orderModelList;
+ }
}
diff --git a/service/src/main/resources/dev/commonConfig.properties b/service/src/main/resources/dev/commonConfig.properties
index a3e4b16..2ff9cc0 100644
--- a/service/src/main/resources/dev/commonConfig.properties
+++ b/service/src/main/resources/dev/commonConfig.properties
@@ -3,6 +3,10 @@ wechatMaSecret=
wechatMpAppid=
wechatMpSecret=
+obsBucketName=phg-test
+obsEndPoint=https://obs.cn-southwest-2.myhuaweicloud.com
+obsUrl=https://phg-test.obs.cn-southwest-2.myhuaweicloud.com
+
huiPayPreorderNotifyUrl=https://phgcs.dctpay.com/order/notify/huipay
# ChongQingCNPC configuration parameters