1.用于存放当前用户的上下文UserContext
package com.xmg.p2p.base.util; import javax.servlet.http.HttpSession; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import com.xmg.p2p.base.domain.Logininfo; import com.xmg.p2p.base.vo.VerifyCodeVO; /** * 用于存放当前用户的上下文 * @author Administrator * */ public class UserContext { public static final String USER_IN_SESSION = "logininfo"; public static final String VERIFTCODE_IN_SESSION = "verifycode_in_session"; /** * 方向获取request * @return */ private static HttpSession getSesssion(){ return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getSession(); } public static void putCurrent(Logininfo current){ getSesssion().setAttribute(USER_IN_SESSION, current);; } public static Logininfo getCurrent(){ return (Logininfo) getSesssion().getAttribute(USER_IN_SESSION); } /** * 用来得到设置自的短信验证码 * @return */ public static void putVerifyCode(VerifyCodeVO vc){ getSesssion().setAttribute(VERIFTCODE_IN_SESSION, vc); } /** * 用来得到当前的短信验证码 * @return */ public static VerifyCodeVO getCurrentVerifyCode(){ return (VerifyCodeVO) getSesssion().getAttribute(VERIFTCODE_IN_SESSION); } }
2.返回结果类JSONResult
package com.xmg.p2p.base.util; public class JSONResult { private boolean success = true ; private String msg; public JSONResult(boolean success, String msg) { super(); this.success = success; this.msg = msg; } public JSONResult(String msg) { super(); this.msg = msg; } public JSONResult() { super(); } public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } }
3.时间工具类DateUtil
package com.xmg.p2p.base.util; import java.util.Calendar; import java.util.Date; import org.apache.commons.lang.time.DateUtils; public class DateUtil { /** * 用来计算发送两次验证码之间的间隔 () * @param d1 * @param d2 * @return */ public static long getBetweenSecond(Date d1 ,Date d2 ){ return Math.abs((d1.getTime() - d2.getTime())/1000) ; } /** * 得到一天的最后一秒钟 * */ public static Date endOfDay(Date d) { return DateUtils.addSeconds( DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), 1), -1); } public static long secondsBetween(Date d1 , Date d2){ return Math.abs(d1.getTime() - d2.getTime())/1000;//防止出现负数 用绝对值表示 } }
4.系统中的常量BidConst
package com.xmg.p2p.base.util; import java.math.BigDecimal; /** * 系统中的常量 * @author Administrator * */ public class BidConst { /** * 定义存储精度 */ public static final int STORE_SCALE = 4; /** * 定义运算精度 */ public static final int CAL_SCALE = 8; /** * 定义显示精度 */ public static final int DISPLAY_SCALE = 2; /** * 定义系统级别的0 */ public static final BigDecimal ZERO = new BigDecimal("0.0000"); /** * 定义初始授信额度 */ public static final BigDecimal INIT_BORROW_LIMIT = new BigDecimal("5000.0000"); /** * 默认管理员的用户名和密码 * */ public static final String DEFAULT_ADMIN_NAME = "admin"; public static final String DEFAULT_ADMIN_PASSWORD = "admin"; /** * 手机验证码的有效期 * */ public static final int VERIFYCODE_VAILDATE_SECOND = 300; }
5.用户状态类,记录用户在平台使用系统中所有的状态。BitStatesUtils
package com.xmg.p2p.base.util; /** * 用户状态类,记录用户在平台使用系统中所有的状态。 * * @author Administrator */ public class BitStatesUtils { public final static Long OP_BIND_PHONE = 1L << 0; // 用户绑定手机状态码 public final static Long OP_BIND_EMAIL = 1L << 1; // 用户绑定邮箱状态码 public final static Long OP_BASIC_INFO = 1L << 2; // 用户填写基本资料 public final static Long OP_REAL_AUTH = 1L << 3; // 用户是否已经实名认证 public final static Long OP_VEDIO_AUTH = 1L << 4; // 用户是否已经视频认证 public final static Long OP_HAS_BIDREQUEST_PROCESS = 1L << 5; // 用户是否已经有一个借款申请在申请流程中 public final static Long OP_HAS_BIND_BANK = 1L << 6; // 用户是否已经绑定了银行卡 public final static Long OP_HAS_WITHDRAW_PROCESS = 1L << 7; // 用户是否有提现在审核流程中 /** * @param states * 所有状态值 * @param value * 需要判断状态值 * @return 是否存在 */ public static boolean hasState(long states, long value) { return (states & value) != 0; } /** * @param states * 已有状态值 * @param value * 需要添加状态值 * @return 新的状态值 */ public static long addState(long states, long value) { if (hasState(states, value)) { return states; } return (states | value); } /** * @param states * 已有状态值 * @param value * 需要删除状态值 * @return 新的状态值 */ public static long removeState(long states, long value) { if (!hasState(states, value)) { return states; } return states ^ value; } }