提交注冊登陸

This commit is contained in:
qiurunze 2019-01-23 19:38:28 +08:00
parent 3dc731e701
commit 26fdc15278
29 changed files with 856 additions and 231 deletions

View File

@ -78,7 +78,14 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId> <artifactId>spring-aspects</artifactId>
</dependency> </dependency>
<!-- xml freemarket 模板配置-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<!-- JSP相关 --> <!-- JSP相关 -->
<dependency> <dependency>
<groupId>jstl</groupId> <groupId>jstl</groupId>

View File

@ -0,0 +1,7 @@
package com.geekq.web.controller;
/**
* @author 邱润泽
*/
abstract public class BaseController {
}

View File

@ -0,0 +1,30 @@
package com.geekq.web.controller;
import com.geekq.common.utils.resultbean.ResultGeekQ;
import com.geekq.common.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
/**
* @author 邱润泽
* 登录模块
*/
@Controller
public class LoginController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(LoginController.class);
@RequestMapping("/login" )
@ResponseBody
public ResultGeekQ<Boolean> dologin(HttpServletResponse response, LoginVo loginVo) {
ResultGeekQ<Boolean> result = ResultGeekQ.build();
logger.info(loginVo.toString());
return result;
}
}

View File

@ -1,14 +1,9 @@
package com.geekq.web.controller; package com.geekq.web.controller;
import org.apache.commons.lang3.StringUtils; import com.geekq.web.service.CulsterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.geekq.common.utils.IMoocJSONResult;
import com.geekq.web.service.CulsterService;
/** /**
* @Description: 订购商品controller * @Description: 订购商品controller
@ -24,17 +19,5 @@ public class PayController {
return "login"; return "login";
} }
@GetMapping("/buy")
@ResponseBody
public IMoocJSONResult doGetlogin(String itemId) {
if (StringUtils.isNotBlank(itemId)) {
buyService.displayBuy(itemId);
} else {
return IMoocJSONResult.errorMsg("商品id不能为空");
}
return IMoocJSONResult.ok();
}
} }

View File

@ -0,0 +1,32 @@
package com.geekq.web.interceptor;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author 邱润泽
* 拦截器 拦截至主页面
*/
public class LoginInterceptor extends HandlerInterceptorAdapter {
// @Override
// public boolean preHandle(HttpServletRequest request,
// HttpServletResponse response, Object handler) throws Exception {
// if (handler instanceof HandlerMethod) {
// HandlerMethod hm = (HandlerMethod) handler;
// RequiredLogin rl = hm.getMethodAnnotation(RequiredLogin.class);
// if (rl != null) {
//// if (request.getSession().getAttribute(
//// UserContext.LOGIN_IN_SESSION) == null) {
// response.sendRedirect("/login.html");
// return false;
// }
//// }
// }
// return super.preHandle(request, response, handler);
// }
}

View File

@ -0,0 +1,12 @@
package com.geekq.web.interceptor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiredLogin {
}

View File

@ -18,15 +18,4 @@
<!-- 通知spring使用cglib而不是jdk的来生成代理方法 AOP可以拦截到Service --> <!-- 通知spring使用cglib而不是jdk的来生成代理方法 AOP可以拦截到Service -->
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy> <aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
<!-- 配置viewResolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<!-- 把session中的属性直接添加到freemarker的上下文中,我们就可以在页面上直接使用session中的属性 -->
<property name="exposeSessionAttributes" value="true" />
<!-- 配置模板文件的后缀 -->
<property name="suffix" value=".ftl" />
<!-- 配置输出文件的编码类型 -->
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
</beans> </beans>

View File

@ -11,6 +11,8 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<!--<import resource="classpath:spring/applicationContext-service.xml" />-->
<context:component-scan base-package="com.geekq.web.controller" /> <context:component-scan base-package="com.geekq.web.controller" />
<!-- 自动创建代理 对@AspectJ注解的支持 --> <!-- 自动创建代理 对@AspectJ注解的支持 -->
@ -18,19 +20,52 @@
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy> <aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
<mvc:annotation-driven /> <mvc:annotation-driven />
<!-- 配置拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.geekq.web.interceptor.LoginInterceptor" />
</mvc:interceptor>
<!--<mvc:interceptor>-->
<!--<mvc:mapping path="/**" />-->
<!--<bean class="com.eloan.uiweb.interceptor.AddGlobalUtilInterceptor" />-->
<!--</mvc:interceptor>-->
</mvc:interceptors>
<!-- 开启aop对类代理 --> <!-- 开启aop对类代理 -->
<aop:config proxy-target-class="true"></aop:config> <aop:config proxy-target-class="true"></aop:config>
<!-- 静态资源映射 --> <!--&lt;!&ndash;处理上传 &ndash;&gt;-->
<!-- 缓存存在时间 cache-period 1年 修改--> <!--<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">-->
<mvc:resources mapping="/**/**" location="/**/" cache-period="31556926"/> <!--&lt;!&ndash; 在spring中,SpEL,#{}中的内容都是可以让spring来帮我们计算的内容 &ndash;&gt;-->
<!--<property name="maxUploadSize" value="#{1024*1024*100}" />-->
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
<!--<property name="prefix" value="/WEB-INF/jsp/" />-->
<!--<property name="suffix" value=".jsp" />-->
<!--</bean>--> <!--</bean>-->
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
<!--<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView" />-->
<!--<property name="prefix" value="/WEB-INF/" />-->
<!--<property name="suffix" value=".html" />-->
<!--<property name="order" value="1" />-->
<!--</bean>-->
<!-- 配置freemarker本身 -->
<bean
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<!-- freemarker模板的编码 -->
<property name="defaultEncoding" value="UTF-8" />
<!-- freemarker找模板的目录 -->
<property name="templateLoaderPath" value="/WEB-INF/views/" />
<!-- freemarker的一些基本输出设置 -->
<property name="freemarkerSettings">
<value>
number_format = 0.##
datetime_format = yyyy-MM-dd HH:mm:ss
</value>
</property>
</bean>
<!-- 配置viewResolver --> <!-- 配置viewResolver -->
@ -40,12 +75,13 @@
<property name="exposeSessionAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" />
<!-- 配置模板文件的后缀 --> <!-- 配置模板文件的后缀 -->
<property name="suffix" value=".ftl" /> <property name="suffix" value=".ftl" />
<property name="order" value="1" />
<!-- 配置输出文件的编码类型 --> <!-- 配置输出文件的编码类型 -->
<property name="contentType" value="text/html;charset=UTF-8" /> <property name="contentType" value="text/html;charset=UTF-8" />
</bean> </bean>
<!-- 属性文件不能跨容器要在controller中也能被访问到也需要配置 --> <!--&lt;!&ndash; 属性文件不能跨容器要在controller中也能被访问到也需要配置 &ndash;&gt;-->
<context:property-placeholder location="classpath:resource/*.properties" /> <!--<context:property-placeholder location="classpath:resource/*.properties" />-->
</beans> </beans>

View File

@ -33,7 +33,7 @@
<div class="container" style="position: relative;"> <div class="container" style="position: relative;">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="/">首页</a></li> <li><a href="/">首页</a></li>
<li><a href="/login.html">登录</a></li> <li><a href="/WEB-INF/login.html">登录</a></li>
<li><a href="#">帮助</a></li> <li><a href="#">帮助</a></li>
</ul> </ul>
</div> </div>

View File

@ -3,8 +3,8 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="/">首页</a></li> <li><a href="/">首页</a></li>
<#if !logininfo??> <#if !logininfo??>
<li><a href="/login.html">登录</a></li> <li><a href="/WEB-INF/login.html">登录</a></li>
<li><a href="/register.html">快速注册</a></li> <li><a href="/WEB-INF/register.html">快速注册</a></li>
<#else> <#else>
<li> <li>
<a class="el-current-user" href="/personal.do"> <a class="el-current-user" href="/personal.do">

View File

@ -1,28 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
version="2.5">
<display-name>miaosha-admin-web</display-name> <servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list> <filter>
<welcome-file>index.html</welcome-file> <filter-name>characterEncoding</filter-name>
<welcome-file>index.htm</welcome-file> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<welcome-file>index.jsp</welcome-file> <init-param>
<welcome-file>default.html</welcome-file> <param-name>encoding</param-name>
<welcome-file>default.htm</welcome-file> <param-value>utf-8</param-value>
<welcome-file>default.jsp</welcome-file> </init-param>
</welcome-file-list> </filter>
<filter-mapping>
<!-- 加载log4j --> <filter-name>characterEncoding</filter-name>
<context-param> <url-pattern>*.do</url-pattern>
<param-name>log4jConfigLocation</param-name> </filter-mapping>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 加载spring容器 --> <!-- 加载spring容器 -->
<context-param> <context-param>
@ -32,35 +38,10 @@
<listener> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </listener>
<!-- 解决post乱码 --> <!-- 必须配置这个listener,才能在spring中使用RequestContextHolder -->
<filter> <listener>
<filter-name>CharacterEncodingFilter</filter-name> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> </listener>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- springmvc的前端控制器 -->
<servlet>
<servlet-name>miaosha-admin-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>miaosha-admin-web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app> </web-app>

View File

@ -15,8 +15,8 @@
<div class="container" style="position: relative;"> <div class="container" style="position: relative;">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="/">首页</a></li> <li><a href="/">首页</a></li>
<li><a href="/login.html">登录</a></li> <li><a href="/WEB-INF/login.htmlgin.html">登录</a></li>
<li><a href="/register.html">快速注册</a></li> <li><a href="/WEB-INF/register.htmlter.html">快速注册</a></li>
<li><a href="#">帮助</a></li> <li><a href="#">帮助</a></li>
</ul> </ul>
</div> </div>
@ -59,7 +59,7 @@
<li>材料认证分数达到30分</li> <li>材料认证分数达到30分</li>
<li>视频认证</li> <li>视频认证</li>
</ul> </ul>
<a href="/login.html" class="el-borrow-apply"> <a href="/WEB-INF/login.htmlgin.html" class="el-borrow-apply">
登陆后申请 登陆后申请
</a> </a>
</div> </div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>蓝源Eloan-P2P平台->用户登录</title> <title>秒杀平台->用户登录</title>
<link rel="stylesheet" href="/js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css" /> <link rel="stylesheet" href="/js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/css/core.css" type="text/css" /> <link rel="stylesheet" href="/css/core.css" type="text/css" />
<script type="text/javascript" src="/js/jquery/jquery-2.1.3.js"></script> <script type="text/javascript" src="/js/jquery/jquery-2.1.3.js"></script>
@ -52,7 +52,7 @@
}); });
}, },
rules:{ rules:{
username:"required", mobile:"required",
password:"required" password:"required"
} }
}); });
@ -78,7 +78,7 @@
<div class="navbar navbar-default el-navbar"> <div class="navbar navbar-default el-navbar">
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<a href=""><img alt="Brand" src="/images/logo.png"></a> <!--<a href=""><img alt="Brand" src="/images/miaoshaxitong.png"></a>-->
<span class="el-page-title">用户登录</span> <span class="el-page-title">用户登录</span>
</div> </div>
</div> </div>
@ -89,9 +89,9 @@
<form id="loginForm" class="form-horizontal el-login-form" action="/login.do" method="post" > <form id="loginForm" class="form-horizontal el-login-form" action="/login.do" method="post" >
<p class="h4" style="margin: 10px 10px 20px 110px;color:#999;">请输入用户名和密码</p> <p class="h4" style="margin: 10px 10px 20px 110px;color:#999;">请输入用户名和密码</p>
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2">用户名</label> <label class="control-label col-sm-2">手机号码</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" autocomplete="off" name="username" class="form-control" value="stef"/> <input type="text" autocomplete="off" name="mobile" class="form-control" value="stef"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -117,22 +117,15 @@
<div class="container-foot-2"> <div class="container-foot-2">
<div class="context"> <div class="context">
<div class="left"> <div class="left">
<p>专注于高级Java开发工程师的培养</p> <p>we -- hello -- world </p>
<p>版权所有:&emsp;2015广州小码哥教育科技有限公司</p> <p>版权所有:&emsp;GeekQ</p>
<p>&emsp;&emsp;址:&emsp;广州市天河区棠下荷光三横路盛达商务园D座5楼</p> <p>&emsp;&emsp;址:&emsp;北京市</p>
<p>&emsp;&emsp;话: 020-29007520&emsp;&emsp; <p>Q&emsp;&emsp;Q 3341386488&emsp;&emsp;</p>
邮箱:&emsp;service@520it.com</p> <p>邮 箱:&emsp;QiuRunZe_key@163.com</p>
<p>
<a href="http://www.miitbeian.gov.cn" style="color: #ffffff">ICP备案
粤ICP备字1504547</a>
</p>
<p>
<a href="http://www.gzjd.gov.cn/wlaqjc/open/validateSite.do" style="color: #ffffff">穗公网安备44010650010086</a>
</p>
</div> </div>
<div class="right"> <div class="right">
<a target="_blank" href="http://weibo.com/ITxiaomage"><img <a target="_blank" href="https://github.com/qiurunze123/miaosha"><img
src="/images/sina.png"></a> src="/images/geekq.png"></a>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>

View File

@ -111,7 +111,7 @@
<div class="container" style="position: relative;"> <div class="container" style="position: relative;">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="/">首页</a></li> <li><a href="/">首页</a></li>
<li><a href="/login.html">登录</a></li> <li><a href="/WEB-INF/login.html">登录</a></li>
<li><a href="#">帮助</a></li> <li><a href="#">帮助</a></li>
</ul> </ul>
</div> </div>

View File

@ -28,6 +28,29 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<!-- 校验处理工具包 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!--lombook引用-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.5.Final</version>
</dependency>
<!-- httpclient --> <!-- httpclient -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>

View File

@ -0,0 +1,67 @@
package com.geekq.common.enums;
public class MessageStatus {
public static final Integer ZORE = 0;
/**
* 消息类型
*/
public enum messageType {
maiosha_message("秒杀消息"),
buy_message("购买消息"),
system_message("系统消息");
private String message;
private messageType(String message){
this.message = message;
}
public String getMessage() {
return message;
}
}
/**
* 消息内容
*/
public enum ContentEnum {
system_message_register(7000,"尊敬的用户你好,你已经成功注册!"),
system_message_register_head(7001,"注册成功");
private int code;
private String message;
private ContentEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}
/**
* 消息类型
*/
public enum sendType {
// maiosha_message("秒杀消息"),
// buy_message("购买消息"),
// system_message("系统消息");
// private String message;
//
// private messageType(String message){
// this.message = message;
// }
//
// public String getMessage() {
// return message;
// }
}
}

View File

@ -0,0 +1,103 @@
package com.geekq.common.enums;
/**
* 普通返回类
* 1打头 系统系列错误
* 2 注册登录系列错误
* 3 check 系列错误
* 4 秒杀错误
* 5 商品错误
* 6 订单错误
* @author qiurunze
*/
public enum ResultStatus {
SUCCESS(0, "成功"),
FAILD(-1, "失败"),
EXCEPTION(-1, "系统异常"),
PARAM_ERROR(10000, "参数错误"),
SYSTEM_ERROR(10001, "系统错误"),
FILE_NOT_EXIST(10002, "文件不存在"),
FILE_NOT_DOWNLOAD(10003, "文件没有下载"),
FILE_NOT_GENERATE(10004, "文件没有生成"),
FILE_NOT_STORAGE(10005, "文件没有入库"),
SYSTEM_DB_ERROR(10006, "数据库系统错误"),
FILE_ALREADY_DOWNLOAD(10007, "文件已经下载"),
DATA_ALREADY_PEXISTS(10008, "数据已经存在"),
/**
* 注册登录
*/
RESIGETR_SUCCESS(20000,"注册成功!"),
RESIGETER_FAIL(200001,"注册失败!"),
CODE_FAIL(200002,"验证码不一致!"),
/**
* check
*/
BIND_ERROR (30001,"参数校验异常:%s"),
ACCESS_LIMIT_REACHED (30002,"请求非法!"),
REQUEST_ILLEGAL (30004,"访问太频繁!"),
SESSION_ERROR (30005,"Session不存在或者已经失效!"),
PASSWORD_EMPTY (30006,"登录密码不能为空!"),
MOBILE_EMPTY (30007,"手机号不能为空!"),
MOBILE_ERROR (30008,"手机号格式错误!"),
MOBILE_NOT_EXIST (30009,"手机号不存在!"),
PASSWORD_ERROR (30010,"密码错误!"),
USER_NOT_EXIST(30011,"用户不存在!"),
/**
* 订单模块
*/
ORDER_NOT_EXIST(60001,"订单不存在"),
/**
* 秒杀模块
*/
MIAO_SHA_OVER(40001,"商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002,"不能重复秒杀"),
MIAOSHA_FAIL(40003,"秒杀失败");
/**
* 商品模块
*/
private int code;
private String message;
private ResultStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return this.code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public String getName() {
return this.name();
}
public String getOutputName() {
return this.name();
}
public String toString() {
return this.getName();
}
private ResultStatus(Object... args) {
this.message = String.format(this.message, args);
}
}

View File

@ -0,0 +1,26 @@
package com.geekq.common.utils;
public class Constanst {
public static String CLOSE_ORDER_INFO_TASK_LOCK = "CLOSE_ORDER_INFO_KEY";
public static String COUNTLOGIN = "count:login";
public enum orderStaus{
ORDER_NOT_PAY("新建未支付");
orderStaus(String name){
this.name=name;
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -1,112 +0,0 @@
package com.geekq.common.utils;
/**
*
* @Description: 自定义响应数据结构
* 这个类是提供给门户ios安卓微信商城用的
* 门户接受此类数据后需要使用本类的方法转换成对于的数据类型格式或者list
* 其他自行处理
* 200表示成功
* 500表示错误错误信息在msg字段中
* 501bean验证错误不管多少个错误都以map形式返回
* 502拦截器拦截到用户token出错
* 555异常抛出信息
*/
public class IMoocJSONResult {
// 响应业务状态
private Integer status;
// 响应消息
private String msg;
// 响应中的数据
private Object data;
private String ok; // 不使用
public static IMoocJSONResult build(Integer status, String msg, Object data) {
return new IMoocJSONResult(status, msg, data);
}
public static IMoocJSONResult ok(Object data) {
return new IMoocJSONResult(data);
}
public static IMoocJSONResult ok() {
return new IMoocJSONResult(null);
}
public static IMoocJSONResult errorMsg(String msg) {
return new IMoocJSONResult(500, msg, null);
}
public static IMoocJSONResult errorMap(Object data) {
return new IMoocJSONResult(501, "error", data);
}
public static IMoocJSONResult errorTokenMsg(String msg) {
return new IMoocJSONResult(502, msg, null);
}
public static IMoocJSONResult errorException(String msg) {
return new IMoocJSONResult(555, msg, null);
}
public IMoocJSONResult() {
}
// public static LeeJSONResult build(Integer status, String msg) {
// return new LeeJSONResult(status, msg, null);
// }
public IMoocJSONResult(Integer status, String msg, Object data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public IMoocJSONResult(Object data) {
this.status = 200;
this.msg = "OK";
this.data = data;
}
public Boolean isOK() {
return this.status == 200;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getOk() {
return ok;
}
public void setOk(String ok) {
this.ok = ok;
}
}

View File

@ -0,0 +1,65 @@
package com.geekq.common.utils.MD5;
import org.apache.commons.codec.digest.DigestUtils;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;
/**
* @author 邱润泽
*/
public class MD5Utils {
private static final String getSaltT (){
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[15];
random.nextBytes(bytes);
String salt = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes);
return salt;
}
private static String getSalt = getSaltT();
public static String MD5( String keyName ){
/**
* 返回16
*/
return DigestUtils.md5Hex(keyName);
}
/**
* 测试使用
* @param inputPass
* @return
*/
public static String inputPassFormPass ( String inputPass ){
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) + inputPass + getSalt.charAt(4) + getSalt.charAt(6) ;
return MD5(str);
}
/**
* 盐值salt 随机 二次加密
* @param inputPass
* @return
*/
public static String formPassFormPass ( String inputPass ){
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) +inputPass + getSalt.charAt(4) + getSalt.charAt(6) ;
return MD5(str);
}
/**
* 第二次md5--反解密 用户登录验证 --- salt 可随机 
* @param formPass
* @param salt
* @return
*/
public static String formPassToDBPass ( String formPass ,String salt ) {
String str = "" + salt.charAt(0) + salt.charAt(2)+ formPass + salt.charAt(4) + salt.charAt(6) ;
return MD5(str);
}
}

View File

@ -0,0 +1,163 @@
package com.geekq.common.utils;
/**
* Twitter_Snowflake<br>
* SnowFlake的结构如下(每部分用-分开):<br>
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
* 1位标识由于long基本类型在Java中是带符号的最高位是符号位正数是0负数是1所以id一般是正数最高位是0<br>
* 41位时间截(毫秒级)注意41位时间截不是存储当前时间的时间截而是存储时间截的差值当前时间截 - 开始时间截)
* 得到的值这里的的开始时间截一般是我们的id生成器开始使用的时间由我们程序来指定的如下下面程序IdWorker类的startTime属性41位的时间截可以使用69年年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
* 10位的数据机器位可以部署在1024个节点包括5位datacenterId和5位workerId<br>
* 12位序列毫秒内的计数12位的计数顺序号支持每个节点每毫秒(同一机器同一时间截)产生4096个ID序号<br>
* 加起来刚好64位为一个Long型<br>
* SnowFlake的优点是整体上按照时间自增排序并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分)并且效率较高经测试SnowFlake每秒能够产生26万ID左右
*/
public class SnowflakeIdWorker {
// ==============================Fields===========================================
/** 开始时间截 (2015-01-01) */
private final long twepoch = 1420041600000L;
/** 机器id所占的位数 */
private final long workerIdBits = 5L;
/** 数据标识id所占的位数 */
private final long datacenterIdBits = 5L;
/** 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/** 支持的最大数据标识id结果是31 */
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/** 序列在id中占的位数 */
private final long sequenceBits = 12L;
/** 机器ID向左移12位 */
private final long workerIdShift = sequenceBits;
/** 数据标识id向左移17位(12+5) */
private final long datacenterIdShift = sequenceBits + workerIdBits;
/** 时间截向左移22位(5+5+12) */
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/** 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095) */
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/** 工作机器ID(0~31) */
private long workerId;
/** 数据中心ID(0~31) */
private long datacenterId;
/** 毫秒内序列(0~4095) */
private long sequence = 0L;
/** 上次生成ID的时间截 */
private long lastTimestamp = -1L;
//==============================Constructors=====================================
/**
* 构造函数
* @param workerId 工作ID (0~31)
* @param datacenterId 数据中心ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 生成订单唯一ID
* @param workerId
* @param datacenterId
* @return
*/
public static long getOrderId(long workerId, long datacenterId){
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
return idWorker.nextId();
}
// ==============================Methods==========================================
/**
* 获得下一个ID (该方法是线程安全的)
* @return SnowflakeId
*/
public synchronized long nextId() {
long timestamp = timeGen();
//如果当前时间小于上一次ID生成的时间戳说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {
throw new RuntimeException(
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
//如果是同一时间生成的则进行毫秒内序列
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
//毫秒内序列溢出
if (sequence == 0) {
//阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
}
//时间戳改变毫秒内序列重置
else {
sequence = 0L;
}
//上次生成ID的时间截
lastTimestamp = timestamp;
//移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
| sequence;
}
/**
* 阻塞到下一个毫秒直到获得新的时间戳
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
* 返回以毫秒为单位的当前时间
* @return 当前时间(毫秒)
*/
protected long timeGen() {
return System.currentTimeMillis();
}
//==============================Test=============================================
/** 测试 */
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
}

View File

@ -0,0 +1,21 @@
package com.geekq.common.utils;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ValidatorUtil {
private static final Pattern mobile_pattern = Pattern.compile("1\\d{10}");
public static boolean isMobile(String src) {
if(StringUtils.isEmpty(src)) {
return false;
}
Matcher m = mobile_pattern.matcher(src);
return m.matches();
}
}

View File

@ -0,0 +1,63 @@
package com.geekq.common.utils.resultbean;
import com.geekq.common.enums.ResultStatus;
public class AbstractResult {
private ResultStatus status;
private int code;
private String message;
protected AbstractResult(ResultStatus status, String message) {
this.code = status.getCode();
this.status = status;
this.message = message;
}
protected AbstractResult(ResultStatus status) {
this.code = status.getCode();
this.message = status.getMessage();
this.status = status;
}
public static boolean isSuccess(AbstractResult result) {
return result != null && result.status == ResultStatus.SUCCESS && result.getCode() == ResultStatus.SUCCESS.getCode();
}
public AbstractResult withError(ResultStatus status) {
this.status = status;
return this;
}
public AbstractResult withError(String message) {
this.status = ResultStatus.SYSTEM_ERROR;
this.message = message;
return this;
}
public AbstractResult withError(int code, String message) {
this.code = code;
this.message = message;
return this;
}
public AbstractResult success() {
this.status = ResultStatus.SUCCESS;
return this;
}
public ResultStatus getStatus() {
return this.status;
}
public String getMessage() {
return this.message == null ? this.status.getMessage() : this.message;
}
public int getCode() {
return this.code;
}
public void setCode(int code) {
this.code = code;
}
}

View File

@ -0,0 +1,52 @@
package com.geekq.common.utils.resultbean;
import com.geekq.common.enums.ResultStatus;
import java.io.Serializable;
public class ResultGeekQ<T> extends AbstractResult implements Serializable {
private static final long serialVersionUID = 867933019328199779L;
private T data;
private Integer count;
protected ResultGeekQ(ResultStatus status, String message) {
super(status, message);
}
protected ResultGeekQ(ResultStatus status) {
super(status);
}
public static <T> ResultGeekQ<T> build() {
return new ResultGeekQ(ResultStatus.SUCCESS, (String)null);
}
public static <T> ResultGeekQ<T> build(String message) {
return new ResultGeekQ(ResultStatus.SUCCESS, message);
}
public static <T> ResultGeekQ<T> error(ResultStatus status) {
return new ResultGeekQ<T>(status);
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Integer getCount() {
return this.count;
}
public void setCount(Integer count) {
this.count = count;
}
public void success(T value) {
this.success();
this.data = value;
this.count = 0;
}
}

View File

@ -0,0 +1,19 @@
package com.geekq.common.validator;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = {MobileValidator.class})
public @interface MobileCheck {
boolean required() default true ;
String message() default "手机号码格式有误!";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

View File

@ -0,0 +1,30 @@
package com.geekq.common.validator;
import com.geekq.common.utils.ValidatorUtil;
import org.apache.commons.lang3.StringUtils;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
public class MobileValidator implements ConstraintValidator<MobileCheck, String> {
private boolean require = false ;
@Override
public void initialize(MobileCheck isMobile) {
require = isMobile.required() ;
}
@Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
if(require){
return ValidatorUtil.isMobile(value) ;
}else{
if(StringUtils.isEmpty(value)){
return true ;
}else {
return ValidatorUtil.isMobile(value) ;
}
}
}
}

View File

@ -0,0 +1,35 @@
package com.geekq.common.vo;
import com.geekq.common.validator.MobileCheck;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
/**
* @author 邱润泽
*/
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class LoginVo {
@NotNull
@MobileCheck
private String mobile ;
@NotNull
@Length(min=32)
private String password;
@Override
public String toString() {
return "LoginVo{" +
"mobile='" + mobile + '\'' +
", password='" + password + '\'' +
'}';
}
}