Эх сурвалжийг харах

feat: 众蚁云结算发起对接gig、结算回调

李学松 2 жил өмнө
parent
commit
4dd7918a52

+ 6 - 2
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/CacheConstants.java

@@ -126,10 +126,14 @@ public interface CacheConstants {
 	String HUI_QI_YUN_NOTIFY_KEY = "HUI:QI:YUN:NOTIFY:KEY:";
 
 	/**
-	 * 众蚁云异步结果回调key
+	 * 众蚁云签约异步结果回调key
 	 */
-	String ZHONG_YI_YUN_NOTIFY_KEY = "ZHONG:YI:YUN:NOTIFY:KEY:";
+	String ZHONG_YI_YUN_SIGN_NOTIFY_KEY = "ZHONG:YI:YUN:SIGN:NOTIFY:KEY:";
 
+	/**
+	 * 众蚁云结算异步结果回调key
+	 */
+	String ZHONG_YI_YUN_SETTLE_NOTIFY_KEY = "ZHONG:YI:YUN:SETTLE:NOTIFY:KEY:";
 
 	/**
 	 * 发起阿拉丁认证渠道记录key

+ 25 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/GigThirdApiController.java

@@ -86,6 +86,30 @@ public class GigThirdApiController {
 	public String zhongYiYunSettleNotifyRequest(@RequestBody String body, @RequestHeader HttpHeaders headers) {
 		log.info("众蚁云结算请求方法参数:body={}, headers={}", body, headers);
 
+		// 请求body json
+		JSONObject bodyJson = JSONUtil.parseObj(body);
+
+		// 请求序号
+		String reqId = bodyJson.getStr("reqId");
+
+		String redisKey = String.format("%s_%s", CacheConstants.ZHONG_YI_YUN_SETTLE_NOTIFY_KEY, reqId);
+		Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, reqId, 30, TimeUnit.MINUTES);
+		if (Boolean.FALSE.equals(absent)) {
+			log.warn("存在在途操作reqId={}", reqId);
+			return "fail";
+		}
+
+		// 请求记录到数据库
+		ZhongyiyunInputRecord inputRecord = new ZhongyiyunInputRecord();
+		inputRecord.setReqId(reqId);
+		inputRecord.setReqType(ZhongyiyunInputRecord.ReqType.SETTLE_NOTIFY.getType());
+		inputRecord.setReqBody(body);
+		inputRecord.setDecryptBody(body);
+		zhongyiyunInputRecordService.save(inputRecord);
+
+		// 业务处理
+		gigThirdApiService.zhongYiYunSettleNotify(bodyJson);
+
 		return "success";
 	}
 
@@ -108,7 +132,7 @@ public class GigThirdApiController {
 		// 请求序号
 		String reqId = bodyJson.getStr("reqId");
 
-		String redisKey = String.format("%s_%s", CacheConstants.ZHONG_YI_YUN_NOTIFY_KEY, reqId);
+		String redisKey = String.format("%s_%s", CacheConstants.ZHONG_YI_YUN_SIGN_NOTIFY_KEY, reqId);
 		Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, reqId, 30, TimeUnit.MINUTES);
 		if (Boolean.FALSE.equals(absent)) {
 			log.warn("存在在途操作reqId={}", reqId);

+ 2 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/ZhongyiyunInputRecord.java

@@ -54,7 +54,8 @@ public class ZhongyiyunInputRecord implements Serializable {
 	@Getter
 	@AllArgsConstructor
 	public enum ReqType {
-		SIGN_NOTIFY("SIGN_NOTIFY", "签约回调");
+		SIGN_NOTIFY("SIGN_NOTIFY", "签约回调"),
+		SETTLE_NOTIFY("SETTLE_NOTIFY", "结算回调");
 
 		/**
 		 * 请求类型

+ 10 - 2
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/gig/GigThirdApiService.java

@@ -2,7 +2,6 @@ package com.qunzhixinxi.hnqz.admin.service.gig;
 
 import cn.hutool.json.JSONObject;
 import com.qunzhixinxi.hnqz.admin.api.dto.OladingCommonRequest;
-import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageSettleNote;
 
 import java.util.List;
@@ -15,12 +14,21 @@ import java.util.List;
  */
 public interface GigThirdApiService {
 
+	/**
+	 * 众蚁云结算回调业务处理
+	 *
+	 * @param bodyJson
+	 * @return
+	 */
+	boolean zhongYiYunSettleNotify(JSONObject bodyJson);
+
 	/**
 	 * 众蚁云签约回调业务处理
 	 *
 	 * @param newBodyJson
+	 * @return
 	 */
-	void zhongYiYunSignNotify(JSONObject newBodyJson);
+	boolean zhongYiYunSignNotify(JSONObject newBodyJson);
 
 	/**
 	 * 汇企云回调业务处理

+ 76 - 3
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/gig/impl/GigThirdApiServiceImpl.java

@@ -87,13 +87,84 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 
 	private final HuiqiyunInputRecordService huiqiyunInputRecordService;
 
+	/**
+	 * 众蚁云结算回调业务处理
+	 *
+	 * @param bodyJson
+	 * @return
+	 */
+	@Override
+	public boolean zhongYiYunSettleNotify(JSONObject bodyJson) {
+		String reqId = bodyJson.getStr("reqId");
+		String state = bodyJson.getStr("state");
+
+		// 根据orderNo查询结算单
+		List<WmScorePackageSettleNote> settleNoteList = scorePackageSettleNoteService.list(Wrappers.<WmScorePackageSettleNote>lambdaQuery()
+				.eq(WmScorePackageSettleNote::getStreamId, reqId));
+		if (CollUtil.isEmpty(settleNoteList)) {
+			log.warn("订单reqId={}对应结算单不存在", reqId);
+			return false;
+		}
+
+		WmScorePackageSettleNote tmp = settleNoteList.get(0);
+
+		int yaoyiStatus = 0;
+		// 	state取值:
+		// 	SETSUCC结算成功;
+		//	SETFAIL:结算失败;
+		//	TICREF:已退票
+		if ("SETSUCC".equals(state)) {
+			// 对应要易结算成功状态
+			yaoyiStatus = 1;
+		} else if ("SETFAIL".equals(state)) {
+			yaoyiStatus = 2;
+		} else {
+			log.warn("当前结算state不处理");
+			redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + tmp.getId());
+			return false;
+		}
+
+		// 修改结算状态
+		final int finalYaoyiStatus = yaoyiStatus;
+		List<WmScorePackageSettleNote> updateList = settleNoteList.stream().map(note -> {
+			WmScorePackageSettleNote updateEntity = new WmScorePackageSettleNote();
+			updateEntity.setId(note.getId());
+			updateEntity.setSettleNoteStatus(finalYaoyiStatus);
+			if (finalYaoyiStatus == 1){
+				updateEntity.setNotifyTime(LocalDateTime.now());
+			}
+			updateEntity.setUpdateTime(LocalDateTime.now());
+			return updateEntity;
+		}).collect(Collectors.toList());
+
+		scorePackageSettleNoteService.updateBatchById(updateList);
+
+		WmScorePackage scorePackage = scorePackageService.getById(tmp.getPackageId());
+
+		// 遥领不修改
+		if (!"1611890566".equals(scorePackage.getSendPackageDeptId())) {
+			// 更新积分包状态
+			log.info("更新积分包状态:{}", tmp);
+			WmScorePackage wmScorePackage = new WmScorePackage();
+			wmScorePackage.setId(tmp.getPackageId());
+			wmScorePackage.setSettleStatus(yaoyiStatus);
+			wmScorePackage.setUpdateTime(LocalDateTime.now());
+			scorePackageService.updateById(wmScorePackage);
+		}
+
+		redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + tmp.getId());
+
+		return true;
+	}
+
 	/**
 	 * 众蚁云签约回调业务处理
 	 *
 	 * @param newBodyJson
+	 * @return
 	 */
 	@Override
-	public void zhongYiYunSignNotify(JSONObject newBodyJson) {
+	public boolean zhongYiYunSignNotify(JSONObject newBodyJson) {
 
 		String idCard = newBodyJson.getStr("idCard");
 		String mobile = newBodyJson.getStr("mobile");
@@ -109,7 +180,7 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 				.eq(SysUser::getDelFlag, DelEnum.NOT_DEL.val()));
 		if (sysUser == null) {
 			log.warn("用户不存在name={},idCard={},mobile={}", name, idCard, mobile);
-			return;
+			return false;
 		}
 
 		// 查询对应userSub数据
@@ -118,7 +189,7 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 				.eq(SysUserSub::getSubjectLocation, SubjectLocation.ZHONG_YI_YUN));
 		if (userSub == null) {
 			log.warn("没有查到对应userSub数据 userId={}", sysUser.getUserId());
-			return;
+			return false;
 		}
 
 		// 更新userSub
@@ -133,6 +204,8 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 		updateUserSub.setUpdateTime(LocalDateTime.now());
 		updateUserSub.setUpdateUser(0);
 		sysUserSubService.updateById(updateUserSub);
+
+		return true;
 	}
 
 	/**