RowKeyGenUtil 卡券生成
程序员文章站
2022-03-08 12:04:16
...
package com.njupt.passbook.utils; import com.njupt.passbook.vo.Feedback; import com.njupt.passbook.vo.GainPassTemplateRequest; import com.njupt.passbook.vo.PassTemplate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; /** * <h1>RowKey 生成器工具类</h1> * */ @Slf4j public class RowKeyGenUtil { /** * <h2>根据提供的 PassTemplate 对象生成 RowKey</h2> * @param passTemplate {@link PassTemplate} * @return String RowKey * */ public static String genPassTemplateRowKey(PassTemplate passTemplate){ String passInfo=String.valueOf(passTemplate.getId())+"_"+passTemplate.getTitle(); String rowKey= DigestUtils.md5Hex(passInfo); log.info("GenPassTemplateRowKey:{},{}",passInfo,rowKey); return rowKey; } /** * <h2>根据提供的领取优惠券请求生成 RowKey,只可以在领取优惠券的时候使用</h2> * Pass RowKey=reversed(userId)+inverse(timestamp)+PassTemplate RowKey * @param request {@link GainPassTemplateRequest} * @return String RowKey * */ public static String genPassRowKey(GainPassTemplateRequest request){ return new StringBuilder(String.valueOf(request.getUserId())).reverse().toString() + (Long.MAX_VALUE-System.currentTimeMillis()) + genPassTemplateRowKey(request.getPassTemplate()); } /** * <h2>根据 Feedback 构造 RowKey</h2> * @param feedback {@link Feedback} * @return String RowKey * */ public static String genFeedbackRowKey(Feedback feedback){ return new StringBuilder(String.valueOf(feedback.getUserId())).reverse().toString() + (Long.MAX_VALUE-System.currentTimeMillis()); } }
下一篇: js中运动框架封装的实例详解