feat:正元第三方调用记录

This commit is contained in:
dzc committed 2025-03-04 10:30:05 +08:00
1 parent bc2c228d06
commit 8af79fb451
16 files changed
+533 -20

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
create database `pjcloudx_thirdparty` default character set utf8mb4 collate utf8mb4_general_ci;
-- ----------------------------
-- Table structure for third_zy_log
-- ----------------------------
DROP TABLE IF EXISTS `third_zy_log`;
CREATE TABLE `third_zy_log`
(
`id` bigint NOT NULL COMMENT '主键',
`biz_type` tinytext NOT NULL COMMENT '同步类型',
`biz_id` varchar(2048) NOT NULL COMMENT '同步类型id',
`api_url` text DEFAULT NULL COMMENT 'api url',
`org_res` text DEFAULT NULL COMMENT '原始res',
`encipher_res` text DEFAULT NULL COMMENT '加密res',
`org_req` text DEFAULT NULL COMMENT '原始req',
`encipher_req` text DEFAULT NULL COMMENT '加密req',
`error` text DEFAULT NULL COMMENT '调用错误',
`version` char(64) DEFAULT NULL COMMENT '同步版本格式化为14位字符串,如果是数字不足14位的,前面补0',
`time_consuming` char(64) DEFAULT NULL COMMENT '同步版本格式化为14位字符串,如果是数字不足14位的,前面补0',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`create_by` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '创建人',
`update_by` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新人',
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '删除时间',
`tenant_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci
ROW_FORMAT = DYNAMIC COMMENT ='正元日志表';
@@ -0,0 +1,44 @@
package com.bsd.pjcloud.thirdparty.constant;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 打印状态
*/
@AllArgsConstructor
@Getter
public enum ThirdZyBizEnumType {
// 数据同步
SYNC_DEALER_INFO("10", "商户信息同步"),
SYNC_ENTERPRISE_INFO("20", "已打印"),
SYNC_ACCOUNT_INFO("30", "账户信息同步"),
SYNC_ACC_CLASS_INFO("40", "身份信息同步"),
// 跨单位交易
AUTHENTICATION("50", "统一身份验证功能"),
CONSUMPTION("60", "智慧园区通刷平台提供消费接口"),
CORRECT("70", "智慧园区通刷平台提供冲正接口"),
// 本地一卡通交易数据同步
SYNC_NATIVE_CARD_INFO("80", "本地一卡通交易数据同步"),
GET_REGION_ID_BY_TOKEN("90", "获取区域编码"),
// 第三方需提供的接口
SELF_CHECK_SYSTEM_STATUS("100", "第三方url健康探测"),
SELF_CORRECT("110", "第三方一卡通系统提供冲正接口"),
SELF_PAY("120", "第三方一卡通系统提供扣费接口"),
SELF_GET_TOKEN("130", "第三方提供获取token"),
;
private final String type;
private final String description;
public static ThirdZyBizEnumType valueOfByType(String type) {
if (ObjectUtil.isEmpty(type)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
}
}
@@ -0,0 +1,134 @@
package com.bsd.pjcloud.thirdparty.entity.zy;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
* 正元日志表
*
* @author dzc
* @date 2025-03-04 09:05:56
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TenantTable
@TableName("third_zy_log")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "正元日志表")
public class ThirdZyLogEntity extends Model<ThirdZyLogEntity> {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private Long id;
/**
* 同步类型
*/
@Schema(description = "同步类型")
private String bizType;
/**
* api url
*/
@Schema(description = "apiUrl")
private String apiUrl;
/**
* 同步类型id
*/
@Schema(description = "同步类型id")
private String bizId;
/**
* 原始res
*/
@Schema(description = "原始res")
private String orgRes;
/**
* 加密res
*/
@Schema(description = "加密res")
private String encipherRes;
/**
* 原始req
*/
@Schema(description = "原始req")
private String orgReq;
/**
* 加密req
*/
@Schema(description = "加密req")
private String encipherReq;
/**
* 调用错误
*/
@Schema(description = "调用错误")
private String error;
/**
* 同步版本格式化为14位字符串,如果是数字不足14位的,前面补0
*/
@Schema(description = "同步版本格式化为14位字符串,如果是数字不足14位的,前面补0")
private String version;
/**
* 同步版本格式化为14位字符串,如果是数字不足14位的,前面补0
*/
@Schema(description = "同步版本格式化为14位字符串,如果是数字不足14位的,前面补0")
private String timeConsuming;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 更新人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新人")
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新时间")
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除时间")
private String delFlag;
/**
* tenantId
*/
@Schema(description = "tenantId")
private Long tenantId;
}
+4
View File
@@ -115,6 +115,10 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.bsd</groupId>
<artifactId>pjcloud-common-idempotent</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
@@ -0,0 +1,84 @@
package com.bsd.pjcloud.thirdparty.controller.zy;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.service.ThirdZyLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 正元日志表
*
* @author dzc
* @date 2025-03-04 09:05:56
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/third-zy-log")
@Tag(description = "thirdZyLog", name = "正元日志表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ThirdZyLogController {
private final ThirdZyLogService thirdZyLogService;
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_view')")
public R getThirdZyLogPage(@ParameterObject Page page, @ParameterObject ThirdZyLogEntity thirdZyLog) {
LambdaQueryWrapper<ThirdZyLogEntity> wrapper = Wrappers.lambdaQuery();
return R.ok(thirdZyLogService.page(page, wrapper));
}
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(thirdZyLogService.getById(id));
}
@Operation(summary = "新增正元日志表", description = "新增正元日志表")
@SysLog("新增正元日志表")
@PostMapping
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_add')")
public R save(@RequestBody ThirdZyLogEntity thirdZyLog) {
return R.ok(thirdZyLogService.save(thirdZyLog));
}
@Operation(summary = "修改正元日志表", description = "修改正元日志表")
@SysLog("修改正元日志表")
@PutMapping
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_edit')")
public R updateById(@RequestBody ThirdZyLogEntity thirdZyLog) {
return R.ok(thirdZyLogService.updateById(thirdZyLog));
}
@Operation(summary = "通过id删除正元日志表", description = "通过id删除正元日志表")
@SysLog("通过id删除正元日志表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(thirdZyLogService.removeBatchByIds(CollUtil.toList(ids)));
}
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_export')")
public List<ThirdZyLogEntity> export(ThirdZyLogEntity thirdZyLog, Long[] ids) {
return thirdZyLogService.list(Wrappers.lambdaQuery(thirdZyLog).in(ArrayUtil.isNotEmpty(ids), ThirdZyLogEntity::getId, ids));
}
}
@@ -1,5 +1,6 @@
package com.bsd.pjcloud.thirdparty.controller.zy;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfCorrectDto;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfGetTokenDto;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfPayDto;
@@ -14,7 +15,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Map;
@RestController
@@ -28,6 +28,7 @@ public class ZySelfController {
@GetMapping("/checkSystemStatus")
@Operation(summary = "第三方url健康探测", description = "第三方url健康探测")
@Idempotent(expireTime = 10, info = "请勿重复调用")
public Map<String, Object> checkSystemStatus() {
return zySelfService.checkSystemStatus();
}
@@ -47,6 +48,7 @@ public class ZySelfController {
@PostMapping("/getToken")
@Operation(summary = "第三方一卡通系统提供扣费接口", description = "第三方一卡通系统提供扣费接口")
@Idempotent(expireTime = 10, info = "请勿重复调用")
public ZySelfPayVo pay(@RequestBody ZySelfPayDto params, @RequestParam(value = "access_token", required = false) String accessToken) {
return zySelfService.pay(params, accessToken);
}
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.thirdparty.mapper.zy;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ThirdZyLogMapper extends PjcloudBaseMapper<ThirdZyLogEntity> {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.thirdparty.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
public interface ThirdZyLogService extends IService<ThirdZyLogEntity> {
}
@@ -0,0 +1,16 @@
package com.bsd.pjcloud.thirdparty.service.impl.zy;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.mapper.zy.ThirdZyLogMapper;
import com.bsd.pjcloud.thirdparty.service.ThirdZyLogService;
import org.springframework.stereotype.Service;
/**
* 正元日志表
*
* @author dzc
* @date 2025-03-04 09:05:56
*/
@Service
public class ThirdZyLogServiceImpl extends ServiceImpl<ThirdZyLogMapper, ThirdZyLogEntity> implements ThirdZyLogService {
}
@@ -5,8 +5,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.bsd.pjcloud.thirdparty.config.ZyConfig;
import com.bsd.pjcloud.thirdparty.dto.zy.foreign.ZyForeignGetRegionIdByTokenDto;
import com.bsd.pjcloud.thirdparty.dto.zy.foreign.ZyForeignSyncNativeCardTradeInfoDto;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.service.impl.ZyForeignService;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApi;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApiTool;
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -33,17 +34,24 @@ public class ZyForeignServiceImpl implements ZyForeignService {
private final ZyApiTool zyApiTool;
private final ThirdZyLogServiceImpl thirdZyLogService;
/**
* 本地一卡通交易数据同步
*/
@Override
public ZyForeignSyncNativeCardTradeInfoVo syncNativeCardTradeInfoApi(ZyForeignSyncNativeCardTradeInfoDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Foreign.SYNC_NATIVE_CARD_TRADE_INFO;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("regionCode", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -51,13 +59,21 @@ public class ZyForeignServiceImpl implements ZyForeignService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyForeignSyncNativeCardTradeInfoVo vo = JSONUtil.toBean(res, ZyForeignSyncNativeCardTradeInfoVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||syncNativeCardTradeInfoApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncNativeCardTradeInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -67,13 +83,17 @@ public class ZyForeignServiceImpl implements ZyForeignService {
*/
@Override
public ZyForeignGetRegionIdByTokenVo.VoData getRegionIdByToken() {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Foreign.GET_REGION_ID_BY_TOKEN;
try {
url = String.format(url, zyApiTool.getToken());
entity.setApiUrl(url);
String res = HttpRequest.get(url).execute().body();
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyBaseEncryptVo baseEncryptVo = JSONUtil.toBean(res, ZyBaseEncryptVo.class);
if (ObjectUtil.isEmpty(baseEncryptVo)) {
throw new RuntimeException(String.format("解密错误res|%s|url|%s|res|%s|", res, url, baseEncryptVo));
@@ -83,9 +103,16 @@ public class ZyForeignServiceImpl implements ZyForeignService {
}
String json = Base64.decodeStr(baseEncryptVo.getData());
ZyForeignGetRegionIdByTokenVo.VoData vo = JSONUtil.toBean(json, ZyForeignGetRegionIdByTokenVo.VoData.class);
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||getRegionIdByToken|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||getRegionIdByToken|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -9,6 +9,7 @@ import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncAccClassInfoDto;
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncAccountInfoDto;
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncDealerInfoDto;
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncEnterpriseInfoDto;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.service.impl.ZyMerService;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApi;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApiTool;
@@ -18,10 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Validated
@@ -35,11 +33,15 @@ public class ZyMerServiceImpl implements ZyMerService {
private final ZyApiTool zyApiTool;
private final ThirdZyLogServiceImpl thirdZyLogService;
/**
* 商户信息同步
*/
@Override
public ZyMerSyncDealerInfoVo syncDealerInfoApi(List<ZyMerSyncDealerInfoDto> dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
if (ObjectUtil.isEmpty(dto)) {
return null;
}
@@ -53,7 +55,10 @@ public class ZyMerServiceImpl implements ZyMerService {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("dealers", listMap);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.contentType("application/x-www-form-urlencoded")
.body(body)
@@ -62,13 +67,20 @@ public class ZyMerServiceImpl implements ZyMerService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyMerSyncDealerInfoVo vo = JSONUtil.toBean(res, ZyMerSyncDealerInfoVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||syncDealerInfoApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncNativeCardTradeInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -78,12 +90,17 @@ public class ZyMerServiceImpl implements ZyMerService {
*/
@Override
public ZyMerSyncEnterpriseInfoVo syncEnterpriseInfoApi(ZyMerSyncEnterpriseInfoDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Mer.SYNC_ENTERPRISE_INFO;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("enterprises", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -91,13 +108,21 @@ public class ZyMerServiceImpl implements ZyMerService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyMerSyncEnterpriseInfoVo vo = JSONUtil.toBean(res, ZyMerSyncEnterpriseInfoVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||syncEnterpriseInfoApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncEnterpriseInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -107,12 +132,17 @@ public class ZyMerServiceImpl implements ZyMerService {
*/
@Override
public ZyMerSyncAccountInfoVo syncAccountInfoApi(ZyMerSyncAccountInfoDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Mer.SYNC_ACCOUNT_INFO;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("accounts", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -120,13 +150,21 @@ public class ZyMerServiceImpl implements ZyMerService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyMerSyncAccountInfoVo vo = JSONUtil.toBean(res, ZyMerSyncAccountInfoVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||syncAccountInfoApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncAccountInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
}finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -136,12 +174,17 @@ public class ZyMerServiceImpl implements ZyMerService {
*/
@Override
public ZyMerSyncAccClassInfoVo syncAccClassInfoApi(ZyMerSyncAccClassInfoDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Mer.SYNC_ACC_CLASS_INFO;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("accClasses", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -149,13 +192,21 @@ public class ZyMerServiceImpl implements ZyMerService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyMerSyncAccClassInfoVo vo = JSONUtil.toBean(res, ZyMerSyncAccClassInfoVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||syncAccClassInfoApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncAccClassInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
}finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -10,7 +10,9 @@ import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfCorrectDto;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfGetTokenDto;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfPayDto;
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfTokenDto;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.service.impl.ZySelfService;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApi;
import com.bsd.pjcloud.thirdparty.vo.zy.ZyBaseVo;
import com.bsd.pjcloud.thirdparty.vo.zy.self.ZySelfCorrectVo;
import com.bsd.pjcloud.thirdparty.vo.zy.self.ZySelfGetTokenVo;
@@ -24,6 +26,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -41,15 +44,31 @@ public class ZySelfServiceImpl implements ZySelfService {
private final StringRedisTemplate redisTemplate;
private final ThirdZyLogServiceImpl thirdZyLogService;
/**
* 第三方url健康探测
*/
@Override
public Map<String, Object> checkSystemStatus() {
String systemTime = DateUtil.formatDateTime(new Date());
Map<String, Object> result = Map.of("systemTime", systemTime);
log.info("|{}|checkSystemStatus res|{}|", TAG, JSONUtil.toJsonStr(result));
return result;
ThirdZyLogEntity entity = new ThirdZyLogEntity();
entity.setApiUrl(ZyApi.Self.CHECK_SYSTEM_STATUS);
long startTime = System.currentTimeMillis();
try {
String systemTime = DateUtil.formatDateTime(new Date());
Map<String, Object> result = Map.of("systemTime", systemTime);
log.info("|{}|checkSystemStatus res|{}|", TAG, JSONUtil.toJsonStr(result));
return result;
} catch (Exception e) {
String error = String.format("|%s||checkSystemStatus|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
return null;
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
}
/**
@@ -90,6 +109,9 @@ public class ZySelfServiceImpl implements ZySelfService {
*/
@Override
public ZySelfGetTokenVo getToken(ZySelfGetTokenDto params) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
entity.setApiUrl(ZyApi.Self.GET_TOKEN);
long startTime = System.currentTimeMillis();
ZySelfGetTokenVo result = new ZySelfGetTokenVo();
result.setCode(ZyBaseVo.errorCode);
if (ObjectUtil.isEmpty(params.getAppid()) || ObjectUtil.equals(params.getAppid(), zyConfig.getSelfAppId())) {
@@ -110,9 +132,15 @@ public class ZySelfServiceImpl implements ZySelfService {
result.setExpires_in(zyConfig.getSelfExpiresIn().toString());
return result;
} catch (Exception e) {
log.error("|{}|getToken意外的错误dto|{}|error|{}|stack|{}|", TAG, JSONUtil.toJsonStr(params), e.getMessage(), e.getStackTrace());
String error = String.format("|%s||getToken|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
result.setMsg(ZyBaseVo.defaultErrorMsg);
return result;
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
}
@@ -7,6 +7,7 @@ import com.bsd.pjcloud.thirdparty.config.ZyConfig;
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideAuthenticationDto;
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideConsumptionDto;
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideCorrectDto;
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity;
import com.bsd.pjcloud.thirdparty.service.impl.ZyStrideService;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApi;
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApiTool;
@@ -19,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -34,17 +36,24 @@ public class ZyStrideServiceImpl implements ZyStrideService {
private final ZyApiTool zyApiTool;
private final ThirdZyLogServiceImpl thirdZyLogService;
/**
* 统一身份验证功能
*/
@Override
public ZyStrideAuthenticationVo authenticationApi(ZyStrideAuthenticationDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Stride.AUTHENTICATION;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("dealers", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -52,13 +61,21 @@ public class ZyStrideServiceImpl implements ZyStrideService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyStrideAuthenticationVo vo = JSONUtil.toBean(res, ZyStrideAuthenticationVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||authenticationApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||authenticationApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -68,12 +85,17 @@ public class ZyStrideServiceImpl implements ZyStrideService {
*/
@Override
public ZyStrideConsumptionVo consumptionApi(ZyStrideConsumptionDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Stride.CONSUMPTION;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("dealers", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -81,13 +103,21 @@ public class ZyStrideServiceImpl implements ZyStrideService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyStrideConsumptionVo vo = JSONUtil.toBean(res, ZyStrideConsumptionVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||consumptionApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||syncNativeCardTradeInfoApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -97,12 +127,17 @@ public class ZyStrideServiceImpl implements ZyStrideService {
*/
@Override
public ZyStrideCorrectVo correctApi(ZyStrideCorrectDto dto) {
ThirdZyLogEntity entity = new ThirdZyLogEntity();
long startTime = System.currentTimeMillis();
String url = zyConfig.getBaseUrl() + ZyApi.Stride.CORRECT;
try {
url = String.format(url, zyApiTool.getToken());
Map<String, Object> encryptionBody = new HashMap<>();
encryptionBody.put("dealers", dto);
entity.setApiUrl(url);
entity.setOrgReq(JSONUtil.toJsonStr(encryptionBody));
String body = zyApiTool.getEncryptionDto(encryptionBody);
entity.setEncipherReq(body);
String res = HttpRequest.post(url)
.body(body)
.execute()
@@ -110,13 +145,21 @@ public class ZyStrideServiceImpl implements ZyStrideService {
if (ObjectUtil.isEmpty(res)) {
throw new RuntimeException("response is empty");
}
entity.setEncipherRes(res);
ZyStrideCorrectVo vo = JSONUtil.toBean(res, ZyStrideCorrectVo.class);
if (!vo.isSuccess()) {
throw new RuntimeException(String.format("请求错误res|%s|url|%s|body|%s|", res, url, body));
}
entity.setOrgRes(JSONUtil.toJsonStr(vo));
return vo;
} catch (Exception e) {
log.error("|{}||correctApi|意外的错误error|{}|", TAG, e.getMessage());
String error = String.format("|%s||correctApi|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
entity.setError(error);
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
entity.setTimeConsuming(Long.toString(elapsedTime));
thirdZyLogService.save(entity);
}
return null;
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.zy.ThirdZyLogMapper">
<resultMap id="thirdZyLogMap" type="com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyLogEntity">
<id property="id" column="id"/>
<result property="bizType" column="biz_type"/>
<result property="bizId" column="biz_id"/>
<result property="orgRes" column="org_res"/>
<result property="encipherRes" column="encipher_res"/>
<result property="orgReq" column="org_req"/>
<result property="encipherReq" column="encipher_req"/>
<result property="version" column="version"/>
<result property="timeConsuming" column="time_consuming"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>
@@ -0,0 +1,4 @@
package com.bsd.pjcloud.admin.service;
public interface SysThirdZyService {
}
@@ -0,0 +1,4 @@
package com.bsd.pjcloud.admin.service.impl.third;
public class SysThirdZyServiceImpl {
}