From 6f3d5c3affdd6b9c3eb65d73ffaad917934b63cd Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Sun, 3 Sep 2023 15:46:35 +0800 Subject: [PATCH 1/2] =?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 --- .../com/api/controller/v1/AuthController.java | 14 +++++ .../api/controller/v1/TradeController.java | 50 ++++++++++-------- .../src/main/resources/dev/application.yml | 2 +- .../main/resources/prod-9606/application.yml | 4 +- .../src/main/resources/prod/application.yml | 4 +- .../com/hfkj/common/utils/HttpsUtils.java | 18 ++++--- .../main/java/com/hfkj/obs/HuaWeiYunObs.java | 14 +++++ .../hfkj/openapi/v1/utils/SignatureUtil.java | 51 +++++++++++++++++-- 8 files changed, 121 insertions(+), 36 deletions(-) diff --git a/open-api/src/main/java/com/api/controller/v1/AuthController.java b/open-api/src/main/java/com/api/controller/v1/AuthController.java index 4e86c24..bda6ac0 100644 --- a/open-api/src/main/java/com/api/controller/v1/AuthController.java +++ b/open-api/src/main/java/com/api/controller/v1/AuthController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.HttpsUtils; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.model.ResponseData; import com.hfkj.openapi.v1.model.TokenGrantType; @@ -109,4 +110,17 @@ public class AuthController { } } + @RequestMapping(value="/getHttpStats",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "getHttpStats") + public ResponseData getHttpStats() { + try { + + return ResponseMsgUtil.success(HttpsUtils.getHttpStats()); + + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index 815557e..236ce37 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.java @@ -5,14 +5,13 @@ import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; -import com.hfkj.common.utils.DateUtil; -import com.hfkj.common.utils.RequestUtils; -import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.common.utils.*; import com.hfkj.config.CommonSysConst; import com.hfkj.entity.BsMer; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderRefund; import com.hfkj.model.ResponseData; +import com.hfkj.obs.HuaWeiYunObs; import com.hfkj.openapi.v1.model.*; import com.hfkj.openapi.v1.model.request.*; import com.hfkj.openapi.v1.model.response.ResponseQueryTradeModel; @@ -22,11 +21,13 @@ import com.hfkj.openapi.v1.utils.SignatureUtil; import com.hfkj.service.BsMerKeyService; import com.hfkj.service.BsMerService; import com.hfkj.sysenum.*; +import com.obs.services.model.PutObjectResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.util.ResourceUtils; import org.springframework.validation.annotation.Validated; @@ -35,11 +36,9 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.validation.constraints.NotBlank; +import java.io.File; import java.math.BigDecimal; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; @Controller @Api(value = "交易订单") @@ -50,12 +49,12 @@ public class TradeController { @Resource private BsMerKeyService merKeyService; - @Resource private OpenApiTradeOrderService openApiTradeOrderService; - @Resource private BsMerService merService; + @Resource + private RedisTemplate redisTemplate; @RequestMapping(value="/preorder",method = RequestMethod.POST) @ResponseBody @@ -267,15 +266,18 @@ public class TradeController { } List tradeBills = openApiTradeOrderService.tradeBills(body.getMerchantNo(), body.getBillDateS(), body.getBillDateE()); - String fileName = "/temporary/" + System.currentTimeMillis() + ".xlsx"; - EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + fileName, TradeBillsModel.class) + String childPath = "temporary/"; + String fileName = System.currentTimeMillis() + "" + Math.abs(new Random().nextInt() % 1000) + ".xlsx"; + EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, TradeBillsModel.class) .sheet(body.getMerchantNo()) .doWrite(tradeBills); - String fileUrl = CommonSysConst.getSysConfig().getDomainName() + "/filesystem" + fileName; + // 上传华为云 OBS + HuaWeiYunObs.obsUtilPutObject(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, HuaWeiYunObs.bucketName, childPath + fileName); + + String fileUrl = CommonSysConst.getSysConfig().getObs_url() + "/"+ childPath + fileName; log.info("返回参数:" + fileUrl); return ResponseMsgUtil.success(fileUrl); - } catch (Exception e) { log.info("出现异常:", e); return ResponseMsgUtil.exception(e); @@ -305,12 +307,16 @@ public class TradeController { } List tradeBills = openApiTradeOrderService.tradeRefundBills(body.getMerchantNo(), body.getBillDateS(), body.getBillDateE()); - String fileName = "/temporary/" + System.currentTimeMillis() + ".xlsx"; - EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + fileName, TradeRefundBillsModel.class) + String childPath = "temporary/"; + String fileName = System.currentTimeMillis() + "" + Math.abs(new Random().nextInt() % 1000) + ".xlsx"; + EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, TradeRefundBillsModel.class) .sheet(body.getMerchantNo()) .doWrite(tradeBills); - String fileUrl = CommonSysConst.getSysConfig().getDomainName() + "/filesystem" + fileName; + // 上传华为云 OBS + HuaWeiYunObs.obsUtilPutObject(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, HuaWeiYunObs.bucketName, childPath + fileName); + + String fileUrl = CommonSysConst.getSysConfig().getObs_url() + "/"+ childPath + fileName; log.info("返回参数:" + fileUrl); return ResponseMsgUtil.success(fileUrl); @@ -356,12 +362,16 @@ public class TradeController { } List tradeBills = openApiTradeOrderService.tradeSettleBills(body.getMerchantNo(), body.getBillDateS(), body.getBillDateE()); - String fileName = "/temporary/" + System.currentTimeMillis() + ".xlsx"; - EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + fileName, TradeDetailBillsModel.class) - .sheet("交易结算账单") + String childPath = "temporary/"; + String fileName = System.currentTimeMillis() + "" + Math.abs(new Random().nextInt() % 1000) + ".xlsx"; + EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, TradeDetailBillsModel.class) + .sheet(body.getMerchantNo()) .doWrite(tradeBills); - String fileUrl = CommonSysConst.getSysConfig().getDomainName() + "/filesystem" + fileName; + // 上传华为云 OBS + HuaWeiYunObs.obsUtilPutObject(CommonSysConst.getSysConfig().getFilesystem() + "/" + childPath + fileName, HuaWeiYunObs.bucketName, childPath + fileName); + + String fileUrl = CommonSysConst.getSysConfig().getObs_url() + "/"+ childPath + fileName; log.info("返回参数:" + fileUrl); return ResponseMsgUtil.success(fileUrl); diff --git a/open-api/src/main/resources/dev/application.yml b/open-api/src/main/resources/dev/application.yml index ed2f5e7..2963541 100644 --- a/open-api/src/main/resources/dev/application.yml +++ b/open-api/src/main/resources/dev/application.yml @@ -9,7 +9,7 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://139.9.154.68:3306/gratia_pay?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + url: jdbc:mysql://139.9.154.68:3306/gratia_pay_prod?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: HF123456. type: com.alibaba.druid.pool.DruidDataSource diff --git a/open-api/src/main/resources/prod-9606/application.yml b/open-api/src/main/resources/prod-9606/application.yml index c665fba..b6fe02f 100644 --- a/open-api/src/main/resources/prod-9606/application.yml +++ b/open-api/src/main/resources/prod-9606/application.yml @@ -30,7 +30,7 @@ spring: redis: database: 2 - host: 127.0.0.1 + host: 140.210.192.36 port: 36379 password: HF123456.Redis timeout: 1000 @@ -69,7 +69,7 @@ jetcache: remote: default: type: redis - host: 127.0.0.1 + host: 140.210.192.36 port: 36379 password: HF123456.Redis database: 2 diff --git a/open-api/src/main/resources/prod/application.yml b/open-api/src/main/resources/prod/application.yml index 2aa3c58..8d30e7a 100644 --- a/open-api/src/main/resources/prod/application.yml +++ b/open-api/src/main/resources/prod/application.yml @@ -30,7 +30,7 @@ spring: redis: database: 2 - host: 127.0.0.1 + host: 140.210.192.36 port: 36379 password: HF123456.Redis timeout: 1000 @@ -69,7 +69,7 @@ jetcache: remote: default: type: redis - host: 127.0.0.1 + host: 140.210.192.36 port: 36379 password: HF123456.Redis database: 2 diff --git a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java index a6e4956..4e50c41 100644 --- a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java +++ b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java @@ -42,10 +42,7 @@ import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class HttpsUtils { @@ -59,8 +56,8 @@ public class HttpsUtils { // 设置连接池 connMgr = new PoolingHttpClientConnectionManager(); // 设置连接池大小 - connMgr.setMaxTotal(1000); - connMgr.setDefaultMaxPerRoute(connMgr.getMaxTotal()); + connMgr.setMaxTotal(5000); + connMgr.setDefaultMaxPerRoute(2000); // Validate connections after 1 sec of inactivity connMgr.setValidateAfterInactivity(1000); RequestConfig.Builder configBuilder = RequestConfig.custom(); @@ -73,7 +70,14 @@ public class HttpsUtils { requestConfig = configBuilder.build(); } - + + public static Object getHttpStats() { + Map param = new LinkedHashMap<>(); + param.put("totalStats", connMgr.getTotalStats()); + param.put("routes", connMgr.getRoutes()); + return param; + } + /** * 发送 GET 请求(HTTP),不带输入数据 * diff --git a/service/src/main/java/com/hfkj/obs/HuaWeiYunObs.java b/service/src/main/java/com/hfkj/obs/HuaWeiYunObs.java index 31c3d8c..bfa22d4 100644 --- a/service/src/main/java/com/hfkj/obs/HuaWeiYunObs.java +++ b/service/src/main/java/com/hfkj/obs/HuaWeiYunObs.java @@ -6,6 +6,7 @@ import com.obs.services.ObsClient; import com.obs.services.model.*; import java.io.File; +import java.io.IOException; /** * 华为云obs 对象存储 @@ -17,6 +18,7 @@ public class HuaWeiYunObs { private static String endPoint = CommonSysConst.getSysConfig().getObs_end_point(); private static String accessKey = "CZVO7VAT8UV2RPYJUBD2"; private static String secretKey = "gyjrR8rYq9w2maPq9VmpRqoMqCJzQMH8vMctg7eE"; + public static String bucketName = "gratia-pay"; /** * 创建请求 @@ -59,6 +61,18 @@ public class HuaWeiYunObs { 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 桶名称 diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index c2277a2..d7196d1 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -8,6 +8,8 @@ import java.security.MessageDigest; import java.util.Arrays; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * 签名工具类 @@ -82,11 +84,52 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + - " \"merchantNo\": \"2023051910562136809\",\n" + - " \"billDateS\": 1688140800000,\n" + - " \"billDateE\": 1690732800000,\n" + + " \"merchantNo\": \"2023041916292112804\",\n" + + " \"outTradeNo\": \"ZF1130202305051459532538970028\",\n" + + " \"payMode\": \"ALIPAY\",\n" + + " \"totalAmount\": 0.01,\n" + + " \"transType\": \"NATIVE\",\n" + + " \"profitSharing\": 0,\n" + + " \"specialField\": \"测试\"" + "}"; - String sign = createSign(JSONObject.parseObject(paramStr), "NGixVhkzVYFFMj8tjj4zOkYQtUiU3bd4"); + String sign = createSign(JSONObject.parseObject(paramStr), "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"); System.out.println(sign); + + /*// 创建一个线程池,设置最大线程数为10 + ExecutorService executor = Executors.newFixedThreadPool(10); + + // 提交10个查询任务 + for (int i = 0; i < 10; i++) { + executor.submit(new QueryTask(i)); + } + + // 关闭线程池 + executor.shutdown();*/ + } + + static class QueryTask implements Runnable { + private int taskId; + + public QueryTask(int taskId) { + this.taskId = taskId; + } + + @Override + public void run() { + // 执行查询任务 + String result = queryData(taskId); + System.out.println("Task " + taskId + " result: " + result); + } + + private String queryData(int taskId) { + // 模拟查询数据的过程 + /*try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + }*/ + + return "data " + taskId; + } } } From a471c7654ff6d9e926e98f5a5b1d31a40c7ff940 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 4 Sep 2023 14:33:35 +0800 Subject: [PATCH 2/2] =?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 --- open-api/src/main/resources/prod-9606/application.yml | 6 +++--- open-api/src/main/resources/prod/application.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/open-api/src/main/resources/prod-9606/application.yml b/open-api/src/main/resources/prod-9606/application.yml index b6fe02f..92880a1 100644 --- a/open-api/src/main/resources/prod-9606/application.yml +++ b/open-api/src/main/resources/prod-9606/application.yml @@ -15,10 +15,10 @@ spring: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat - maxActive: 10 - initialSize: 5 + maxActive: 200 + initialSize: 20 maxWait: 60000 - minIdle: 5 + minIdle: 20 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' diff --git a/open-api/src/main/resources/prod/application.yml b/open-api/src/main/resources/prod/application.yml index 8d30e7a..a62b076 100644 --- a/open-api/src/main/resources/prod/application.yml +++ b/open-api/src/main/resources/prod/application.yml @@ -15,10 +15,10 @@ spring: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat - maxActive: 10 - initialSize: 5 + maxActive: 200 + initialSize: 20 maxWait: 60000 - minIdle: 5 + minIdle: 20 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x'