Explorar el Código

feat: 浪潮结算回调,接收参数适配浪潮的传参格式

lixuesong hace 2 años
padre
commit
764b0872c0

+ 35 - 46
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/GigThirdApiController.java

@@ -76,60 +76,49 @@ public class GigThirdApiController {
 	/**
 	 * 浪潮(灵才接好活)结算回调
 	 *
-	 * @param body
+	 * @param request
 	 * @return
 	 */
 	@Inner(value = false)
 	@SysLog("浪潮异步通知回调")
 	@PostMapping("/lingcaiai")
 	public String lingcaiaiNotify(HttpServletRequest request) {
-		Enumeration<String> attributeNames = request.getAttributeNames();
-		log.info("attributeNames={}", attributeNames);
 		Map<String, String[]> parameterMap = request.getParameterMap();
-		log.info("parameterMap={}", parameterMap);
+		log.info("浪潮结算回调请求方法参数:parameterMap={}", JSONUtil.toJsonStr(parameterMap));
+
+		// 签名
+		String verify = parameterMap.get("verify")[0];
+		// 通知类型
+		String channel = parameterMap.get("channel")[0];
+		// 项目单号
+		String batchNo = parameterMap.get("batch_no")[0];
+		// 订单状态
+		String orderStatus = parameterMap.get("status")[0];
+		// project_accounts
+		String projectAccounts = parameterMap.get("project_accounts")[0];
+		// 账号单号
+		if (StrUtil.isBlank(projectAccounts)) {
+			log.warn("project_accounts为空");
+			return "fail";
+		}
 
-//		log.info("浪潮结算回调请求方法参数:body={}", body);
-//
-//		// 请求body json
-//		JSONObject bodyJson = JSONUtil.parseObj(body);
-//
-//		// 签名
-//		String verify = bodyJson.getStr("verify");
-//		// 通知类型
-//		String channel = bodyJson.getStr("channel");
-//		// 项目单号
-//		String batchNo = bodyJson.getStr("batch_no");
-//		// 订单状态
-//		Integer orderStatus = bodyJson.getInt("status");
-//		// project_accounts
-//		JSONArray projectAccounts = bodyJson.getJSONArray("project_accounts");
-//		// 账号单号
-//		if (projectAccounts == null) {
-//			log.warn("project_accounts为空");
-//			return "fail";
-//		}
-//		JSONObject projectAccountObj = (JSONObject) projectAccounts.get(0);
-//		String accountNo = projectAccountObj.getStr("account_no");
-//		String status = projectAccountObj.getStr("status");// TODO 项目status和详情的status ???
-//
-//		String redisKey = String.format("%s_%s_%s", CacheConstants.ZHEGN_QI_ZHI_XING_NOTIFY_KEY, channel, accountNo);
-//		Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, accountNo, 30, TimeUnit.MINUTES);
-//		if (!absent) {
-//			return "success";
-//		}
-//
-//		// 请求存入数据库
-//		LingcaiaiInputRecord record = new LingcaiaiInputRecord();
-//		record.setVerify(verify);
-//		record.setChannel(channel);
-//		record.setReqBody(body);
-//		record.setBatchNo(batchNo);
-//		record.setAccountNo(accountNo);
-//		record.setOrderStatus(orderStatus);
-//		record.setCreateTime(LocalDateTime.now());
-//		lingcaiaiInputRecordService.save(record);
-//
-//		gigThirdApiService.lingcaiaiNotify(channel, accountNo, orderStatus);
+		String redisKey = String.format("%s_%s_%s", CacheConstants.ZHEGN_QI_ZHI_XING_NOTIFY_KEY, channel, batchNo);
+		Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, batchNo, 30, TimeUnit.MINUTES);
+		if (!absent) {
+			return "success";
+		}
+
+		// 请求存入数据库
+		LingcaiaiInputRecord record = new LingcaiaiInputRecord();
+		record.setVerify(verify);
+		record.setChannel(channel);
+		record.setReqBody(JSONUtil.toJsonStr(parameterMap));
+		record.setBatchNo(batchNo);
+		record.setOrderStatus(Integer.valueOf(orderStatus));
+		record.setCreateTime(LocalDateTime.now());
+		lingcaiaiInputRecordService.save(record);
+
+		gigThirdApiService.lingcaiaiNotify(channel, batchNo, Integer.valueOf(orderStatus));
 
 		return "success";
 	}