好玩儿的枚举:
public interface RabbitMQTypeEnums { String SYSTEM_PREFIX = "tx"; String SEPARATOR = "_"; String ROUTING_KEY = "routingKey"; String QUEUE_NAME = "queueName"; /** * 子系统 * * @return */ String getSubSystem(); /** * 业务key * @return */ String getBusinessKey(); /** * 获取routingkey * @return */ default String getRoutingKey() { return SYSTEM_PREFIX + SEPARATOR + this.getSubSystem() + SEPARATOR + this.getBusinessKey()+ROUTING_KEY; } /** * 获取队列名字 * @return */ default String getQueueName() { return SYSTEM_PREFIX + SEPARATOR + this.getSubSystem() + SEPARATOR + this.getBusinessKey()+QUEUE_NAME; } @Getter @AllArgsConstructor enum COMMON implements RabbitMQTypeEnums { /** * 短链接 redis key */ FILE_EXPORT_ROUTING_KEY("fileExport", "文件导出"); private String businessKey; private String desc; @Override public String getSubSystem() { return SubSystemEnum.COMMON.getValue(); } } @Getter enum SubSystemEnum { USER("user"), COURSE("course"), COMMON("common"), MARKET("market"), TASK("task"), ; private String value; SubSystemEnum(String value) { this.value = value; } } }
interface+常量+default方法+enums
好玩的 假饿汉模式
@Data @Slf4j public class OrgPushCallInfoDto { private String statusStr; private String startTime; private String connectedTime; private String hangUpTime; private String duringTime; private String customerNumber; private String extention; private String connectedNumber; private String uniqueId; private String recordFile; public static OrgPushCallInfoDto of(HttpServletRequest request) { String statusStr = request.getParameter("status"); String startTime = request.getParameter("call_start"); String connectedTime = request.getParameter("connected_time"); String hangUpTime = request.getParameter("hang_up_time"); String duringTime = request.getParameter("during_time"); String customerNumber = request.getParameter("customer_number"); String extention = request.getParameter("extention"); String connectedNumber = request.getParameter("connected_number"); String uniqueId = request.getParameter("unique_id"); String recordFile = request.getParameter("record_file"); OrgPushCallInfoDto dto = new OrgPushCallInfoDto(); dto.statusStr = statusStr; dto.startTime = startTime; dto.connectedTime = connectedTime; dto.hangUpTime = hangUpTime; dto.duringTime = duringTime; dto.customerNumber = customerNumber; dto.extention = extention; dto.connectedNumber = connectedNumber; dto.uniqueId = uniqueId; dto.recordFile = recordFile; log.info("receive record info:{}", dto); return dto; } }