Explorar o código

feat: 浪潮回调接口, 定义浪潮相关枚举类

lixuesong %!s(int64=2) %!d(string=hai) anos
pai
achega
a3d6f6b5b9

+ 48 - 14
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/GigThirdApiController.java

@@ -1,12 +1,15 @@
 package com.qunzhixinxi.hnqz.admin.controller;
 package com.qunzhixinxi.hnqz.admin.controller;
 
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
 import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.dto.OladingCommonRequest;
 import com.qunzhixinxi.hnqz.admin.api.dto.OladingCommonRequest;
+import com.qunzhixinxi.hnqz.admin.entity.LingcaiaiInputRecord;
 import com.qunzhixinxi.hnqz.admin.entity.OladingInputRecord;
 import com.qunzhixinxi.hnqz.admin.entity.OladingInputRecord;
 import com.qunzhixinxi.hnqz.admin.entity.XinbadaInputRecord;
 import com.qunzhixinxi.hnqz.admin.entity.XinbadaInputRecord;
+import com.qunzhixinxi.hnqz.admin.service.LingcaiaiInputRecordService;
 import com.qunzhixinxi.hnqz.admin.service.XinbadaInputRecordService;
 import com.qunzhixinxi.hnqz.admin.service.XinbadaInputRecordService;
 import com.qunzhixinxi.hnqz.admin.service.gig.GigThirdApiService;
 import com.qunzhixinxi.hnqz.admin.service.gig.GigThirdApiService;
 import com.qunzhixinxi.hnqz.admin.service.gig.OladingInputRecordService;
 import com.qunzhixinxi.hnqz.admin.service.gig.OladingInputRecordService;
@@ -51,20 +54,23 @@ public class GigThirdApiController {
 
 
 	private final XinbadaInputRecordService xinbadaInputRecordService;
 	private final XinbadaInputRecordService xinbadaInputRecordService;
 
 
+	private final LingcaiaiInputRecordService lingcaiaiInputRecordService;
 
 
-	private final RedisTemplate redisTemplate;
-
-	private static final HMACSignProvider hMACSignProvide = new HMACSignProvider();
 
 
-	/**
-	 * 公钥 TODO 暂时没有
-	 */
-	private static final String PUBLIC_KEY = "123123123";
+	private final RedisTemplate redisTemplate;
 
 
-	/**
-	 * 算法类型
-	 */
-	private static final String ALGORITHM_TYPE = "HmacSHA256";
+// 阿拉钉签名验签
+//	private static final HMACSignProvider hMACSignProvide = new HMACSignProvider();
+//
+//	/**
+//	 * 公钥
+//	 */
+//	private static final String PUBLIC_KEY = "123123123";
+//
+//	/**
+//	 * 算法类型
+//	 */
+//	private static final String ALGORITHM_TYPE = "HmacSHA256";
 
 
 	/**
 	/**
 	 * 浪潮(灵才接好活)结算回调
 	 * 浪潮(灵才接好活)结算回调
@@ -81,14 +87,42 @@ public class GigThirdApiController {
 		// 请求body json
 		// 请求body json
 		JSONObject bodyJson = JSONUtil.parseObj(body);
 		JSONObject bodyJson = JSONUtil.parseObj(body);
 
 
-		// 代理商编号
-		String aid = bodyJson.getStr("aid");
 		// 签名
 		// 签名
 		String verify = bodyJson.getStr("verify");
 		String verify = bodyJson.getStr("verify");
 		// 通知类型
 		// 通知类型
 		String channel = bodyJson.getStr("channel");
 		String channel = bodyJson.getStr("channel");
+		// 项目单号
+		String batchNo = bodyJson.getStr("batch_no");
+		// 订单状态
+		Integer orderStatus = bodyJson.getInt("order_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 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";
+		}
 
 
-		// TODO
+		// 请求存入数据库
+		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);
 
 
 		return "success";
 		return "success";
 	}
 	}

+ 62 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/LingcaiaiInputRecord.java

@@ -0,0 +1,62 @@
+package com.qunzhixinxi.hnqz.admin.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author: lixuesong
+ * @createTime: 2022/10/27 11:20
+ * @description: 浪潮(灵才接好活)结算回调记录
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName(value = "lingcaiai_input_record")
+public class LingcaiaiInputRecord extends Model<LingcaiaiInputRecord> {
+
+	/**
+	 * 主键id
+	 */
+	@TableId(type = IdType.AUTO)
+	private Integer id;
+
+	/**
+	 * 签名
+	 */
+	private String verify;
+
+	/**
+	 * 通知类型
+	 */
+	private String channel;
+
+	/**
+	 * 请求body内容
+	 */
+	private String reqBody;
+
+	/**
+	 * 项目单号
+	 */
+	private String batchNo;
+
+	/**
+	 * 账号单号
+	 */
+	private String accountNo;
+
+	/**
+	 * 订单状态(0未支付,1已支付,2已取消)
+	 */
+	private Integer orderStatus;
+
+	/**
+	 * 创建时间
+	 */
+	private LocalDateTime createTime;
+}

+ 3 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/GigTypeEnum.java

@@ -20,7 +20,9 @@ public enum GigTypeEnum {
 	TAX_HELPOR(1, "税邦云", "税邦云", TaxHelperCertStatus.class),
 	TAX_HELPOR(1, "税邦云", "税邦云", TaxHelperCertStatus.class),
 	OLADING(2, "钉灵工", "钉灵工-海南飞亿", OladingCertStatus.class),
 	OLADING(2, "钉灵工", "钉灵工-海南飞亿", OladingCertStatus.class),
 	YEE(3, "易联数科", "易联数科", YeeCertStatus.class),
 	YEE(3, "易联数科", "易联数科", YeeCertStatus.class),
-	ZHENG_QI_ZHI_XING(4, "正启之星", "正启之星", ZhengQiZhiXingCertStatus.class);
+	ZHENG_QI_ZHI_XING(4, "正启之星", "正启之星", ZhengQiZhiXingCertStatus.class),
+
+	LANG_CHAO(5, "浪潮", "浪潮", null);// TODO
 
 
 	@EnumValue
 	@EnumValue
 	private int code;
 	private int code;

+ 4 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/SubjectLocation.java

@@ -30,7 +30,10 @@ public enum SubjectLocation {
 	YI_LIAN("YI_LIAN", GigTypeEnum.YEE, "易联数科", 6),
 	YI_LIAN("YI_LIAN", GigTypeEnum.YEE, "易联数科", 6),
 
 
 	// 正启之星
 	// 正启之星
-	ZHENG_QI_ZHI_XING("ZHENG_QI_ZHI_XING",  GigTypeEnum.ZHENG_QI_ZHI_XING, "正启之星", 7);
+	ZHENG_QI_ZHI_XING("ZHENG_QI_ZHI_XING",  GigTypeEnum.ZHENG_QI_ZHI_XING, "正启之星", 7),
+
+	// 浪潮
+	LANG_CHAO("LANG_CHAO", GigTypeEnum.LANG_CHAO, "浪潮", 8);
 
 
 	@EnumValue
 	@EnumValue
 	private final String type;
 	private final String type;

+ 14 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/LingcaiaiInputRecordMapper.java

@@ -0,0 +1,14 @@
+package com.qunzhixinxi.hnqz.admin.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qunzhixinxi.hnqz.admin.entity.LingcaiaiInputRecord;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author: lixuesong
+ * @createTime: 2022/10/27 13:39
+ * @description: 浪潮(灵才接好活)结算回调记录mapper
+ */
+@Mapper
+public interface LingcaiaiInputRecordMapper extends BaseMapper<LingcaiaiInputRecord> {
+}

+ 12 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/LingcaiaiInputRecordService.java

@@ -0,0 +1,12 @@
+package com.qunzhixinxi.hnqz.admin.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qunzhixinxi.hnqz.admin.entity.LingcaiaiInputRecord;
+
+/**
+ * @author: lixuesong
+ * @createTime: 2022/10/27 13:40
+ * @description: 浪潮(灵才接好活)结算回调记录service
+ */
+public interface LingcaiaiInputRecordService extends IService<LingcaiaiInputRecord> {
+}

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

@@ -14,6 +14,15 @@ import java.util.List;
  */
  */
 public interface GigThirdApiService {
 public interface GigThirdApiService {
 
 
+	/**
+	 * 浪潮(灵才接好活)结算回调
+	 *
+	 * @param channel 通知类型(recharge 充值,batchQuery 批量结果,refund  退款)
+	 * @param batchNo 项目单号
+	 * @param orderStatus 项目订单状态(0未支付,1已支付,2已取消)
+	 */
+	void lingcaiaiNotify(String channel, String batchNo, Integer orderStatus);
+
 	/**
 	/**
 	 * 正启之星回调业务处理
 	 * 正启之星回调业务处理
 	 *
 	 *

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

@@ -78,6 +78,78 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 
 
 	private final ApplicationEventPublisher applicationEventPublisher;
 	private final ApplicationEventPublisher applicationEventPublisher;
 
 
+	/**
+	 * 浪潮(灵才接好活)结算回调
+	 *
+	 * @param channel 通知类型(recharge 充值,batchQuery 批量结果,refund  退款)
+	 * @param batchNo 项目单号
+	 * @param orderStatus 项目订单状态(0未支付,1已支付,2已取消)
+	 */
+	@Override
+	public void lingcaiaiNotify(String channel, String batchNo, Integer orderStatus) {
+		switch (channel) {
+			case "recharge":
+				// 充值 暂不实现~
+				break;
+			case "refund":
+				// 退款 暂不实现~
+				break;
+			case "batchQuery":
+				// 订单状态转换为
+				int yaoyiStatus;
+				switch (orderStatus){
+					case 1:
+						yaoyiStatus = 1;
+						break;
+					default:
+						yaoyiStatus = 2;
+						break;
+				}
+
+				// 批量结果
+				// 根据orderNo查询结算单
+				List<WmScorePackageSettleNote> settleNoteList = scorePackageSettleNoteService.list(Wrappers.<WmScorePackageSettleNote>lambdaQuery()
+						.eq(WmScorePackageSettleNote::getStreamId, batchNo));
+				if (CollUtil.isEmpty(settleNoteList)) {
+					log.warn("订单streamId={}对应结算单不存在", batchNo);
+					return;
+				}
+
+				// 修改结算状态
+				List<WmScorePackageSettleNote> updateList = settleNoteList.stream().map(note -> {
+					WmScorePackageSettleNote updateEntity = new WmScorePackageSettleNote();
+					updateEntity.setId(note.getId());
+					updateEntity.setSettleNoteStatus(yaoyiStatus);
+					if (yaoyiStatus == 1){
+						updateEntity.setNotifyTime(LocalDateTime.now());
+					}
+					updateEntity.setUpdateTime(LocalDateTime.now());
+					return updateEntity;
+				}).collect(Collectors.toList());
+
+				scorePackageSettleNoteService.updateBatchById(updateList);
+
+				WmScorePackageSettleNote tmp = settleNoteList.get(0);
+				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());
+
+				break;
+			default:
+		}
+	}
+
 	/**
 	/**
 	 * 正启之星回调业务处理
 	 * 正启之星回调业务处理
 	 *
 	 *

+ 2 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/gig/impl/SysUserSignCertServiceImpl.java

@@ -495,6 +495,8 @@ public class SysUserSignCertServiceImpl implements SysUserSignCertService {
 					return true;
 					return true;
 				} else if (GigTypeEnum.ZHENG_QI_ZHI_XING.equals(sysUserSub.getGigType())) {
 				} else if (GigTypeEnum.ZHENG_QI_ZHI_XING.equals(sysUserSub.getGigType())) {
 					return true;
 					return true;
+				} else if (GigTypeEnum.LANG_CHAO.equals(sysUserSub.getGigType())) {
+					return true;
 				}
 				}
 				return false;
 				return false;
 			}).forEach(userSub -> {
 			}).forEach(userSub -> {

+ 17 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/LingcaiaiInputRecordServiceImpl.java

@@ -0,0 +1,17 @@
+package com.qunzhixinxi.hnqz.admin.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qunzhixinxi.hnqz.admin.entity.LingcaiaiInputRecord;
+import com.qunzhixinxi.hnqz.admin.mapper.LingcaiaiInputRecordMapper;
+import com.qunzhixinxi.hnqz.admin.service.LingcaiaiInputRecordService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: lixuesong
+ * @createTime: 2022/10/27 13:40
+ * @description: 浪潮(灵才接好活)结算回调记录service
+ */
+@Service
+public class LingcaiaiInputRecordServiceImpl
+		extends ServiceImpl<LingcaiaiInputRecordMapper, LingcaiaiInputRecord> implements LingcaiaiInputRecordService {
+}

+ 179 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/util/Md5Utils.java

@@ -0,0 +1,179 @@
+package com.qunzhixinxi.hnqz.admin.util;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+@Slf4j
+public class Md5Utils {
+
+    public static String MD5(String s) {
+        try {
+            byte[] btInput = s.getBytes("utf-8");
+            // 获得MD5摘要算法的 MessageDigest 对象
+            MessageDigest mdInst = MessageDigest.getInstance("MD5");
+            // 使用指定的字节更新摘要
+            mdInst.update(btInput);
+            // 获得密文
+            byte[] md = mdInst.digest();
+            // 把密文转换成十六进制的字符串形式
+            return byteArrayToHex(md);
+        } catch (Exception e) {
+            //e.printStackTrace();
+            log.error("秘闻转换异常",e);
+            return null;
+        }
+    }
+
+    public static String getMd5ByFileProperty(String fileProperty) {
+        try {
+            // 拿到一个MD5转换器(如果想要SHA1参数换成”SHA1”)
+            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
+            // 输入的字符串转换成字节数组
+            byte[] inputByteArray = fileProperty.getBytes();
+            // inputByteArray是输入字符串转换得到的字节数组
+            messageDigest.update(inputByteArray);
+            // 转换并返回结果,也是字节数组,包含16个元素
+            byte[] resultByteArray = messageDigest.digest();
+            // 字符数组转换成字符串返回
+            return byteArrayToHex(resultByteArray);
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static String byteArrayToHex(byte[] byteArray) {
+        // 首先初始化一个字符数组,用来存放每个16进制字符
+        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+                'A', 'B', 'C', 'D', 'E', 'F' };
+        // new一个字符数组,这个就是用来组成结果字符串的(解释一下:一个byte是八位二进制,也就是2位十六进制字符(2的8次方等于16的2次方))
+        char[] resultCharArray = new char[byteArray.length * 2];
+        // 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
+        int index = 0;
+        for (byte b : byteArray) {
+            resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
+            resultCharArray[index++] = hexDigits[b & 0xf];
+        }
+        // 字符数组组合成字符串返回
+        return new String(resultCharArray);
+
+    }
+
+    public static String getMd5ByFile(File file) {
+        String value = null;
+        FileInputStream in = null;
+        FileChannel ch = null;
+        try {
+            in = new FileInputStream(file);
+            ch = in.getChannel();
+            MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            md5.update(byteBuffer);
+            BigInteger bi = new BigInteger(1, md5.digest());
+            value = bi.toString(16);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (null != ch) {
+                try {
+                    ch.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != in) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return value.toUpperCase();
+    }
+
+    /**
+     * MD5校验
+     * @param request
+     * @param key
+     * @param strMd5
+     * @return
+     */
+    public static boolean check(List<String> listSort, HashMap<String, String> hm, String key, String strMd5, HashMap<String, String> remove, StringBuffer log) {
+        String str = "";
+        for (String mkey : listSort) {
+            if(null != remove.get(mkey) && !"".equals(remove.get(mkey))) continue;
+            if (null == hm.get(mkey)) continue;
+            str+=hm.get(mkey);
+        }
+        str+=key;
+        String tempMd5 = MD5(str);
+
+        if (tempMd5.equals(strMd5.toUpperCase())) {
+            return true;
+        }
+
+        log.append("MD5(").append(str).append(") = ").append(tempMd5.toLowerCase()).append("\r\n");
+        return false;
+    }
+
+    public static String getSign(List<String> listSort, HashMap<String, String> hm, String key) {
+        Collections.sort(listSort, new Comparator<String>() {
+            public int compare(String arg0, String arg1) {
+                return arg0.compareTo(arg1);
+            }
+        });
+        String str = "";
+        for (String mkey : listSort) {
+            if (null == hm.get(mkey)) continue;
+            str+=hm.get(mkey);
+        }
+        str+=key;
+        String tempMd5 = MD5(str);
+
+        return tempMd5;
+    }
+    private static String byteArrayToHexString(byte b[]) {
+        StringBuffer resultSb = new StringBuffer();
+        for (int i = 0; i < b.length; i++)
+            resultSb.append(byteToHexString(b[i]));
+
+        return resultSb.toString();
+    }
+
+    private static String byteToHexString(byte b) {
+        int n = b;
+        if (n < 0)
+            n += 256;
+        int d1 = n / 16;
+        int d2 = n % 16;
+        return hexDigits[d1] + hexDigits[d2];
+    }
+    public static String MD5Encode(String origin, String charsetname) {
+        String resultString = null;
+        try {
+            resultString = new String(origin);
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            if (charsetname == null || "".equals(charsetname))
+                resultString = byteArrayToHexString(md.digest(resultString
+                        .getBytes()));
+            else
+                resultString = byteArrayToHexString(md.digest(resultString
+                        .getBytes(charsetname)));
+        } catch (Exception exception) {
+        }
+        return resultString;
+    }
+    private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
+            "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
+}