| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.common.webListener; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.util.IDLongGenerator; | 
|---|
|  |  |  | import com.dy.common.util.NumUtil; | 
|---|
|  |  |  | import jakarta.servlet.ServletContext; | 
|---|
|  |  |  | import jakarta.servlet.ServletContextEvent; | 
|---|
|  |  |  | import jakarta.servlet.ServletContextListener; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class GenerateIdSetSuffixListener implements ServletContextListener { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // | 
|---|
|  |  |  | public static final String IdSuffix = "idSuffix" ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void contextInitialized(ServletContextEvent event) { | 
|---|
|  |  |  | ServletContextListener.super.contextInitialized(event); | 
|---|
|  |  |  | ServletContext con = event.getServletContext(); | 
|---|
|  |  |  | this.init(con); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void contextDestroyed(ServletContextEvent event) { | 
|---|
|  |  |  | ServletContextListener.super.contextDestroyed(event); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 解析系统配置 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void init(ServletContext con){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String idSuffix = con.getInitParameter(IdSuffix); | 
|---|
|  |  |  | if(idSuffix == null || idSuffix.trim().equals("")){ | 
|---|
|  |  |  | throw new Exception("未配置ID后缀") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(!NumUtil.isPlusIntNumber(idSuffix)){ | 
|---|
|  |  |  | throw new Exception("配置ID后缀格式不正确") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | IDLongGenerator.setSuffix(Integer.parseInt(idSuffix)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("系统启动时,初始化ID后缀出错 !", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|