├── src
├── main
│ ├── resources
│ │ ├── api
│ │ │ ├── validate.md
│ │ │ └── user.md
│ │ ├── banner.txt
│ │ └── mapper
│ │ │ ├── car
│ │ │ ├── MemberMapper.xml
│ │ │ └── CarInformationMapper.xml
│ │ │ └── common
│ │ │ └── UserMapper.xml
│ └── java
│ │ └── com
│ │ └── yiyexy
│ │ ├── util
│ │ ├── NumUtil.java
│ │ ├── ObjectUtil.java
│ │ ├── log
│ │ │ └── MyLogger.java
│ │ ├── RegexpUtil.java
│ │ ├── ValidateCodeUtil.java
│ │ ├── StringRedisTempldateUtil.java
│ │ ├── DateUtils.java
│ │ ├── EncryptionUtil.java
│ │ └── result
│ │ │ ├── Result.java
│ │ │ └── ResultBuilder.java
│ │ ├── constant
│ │ ├── DBConstant.java
│ │ ├── IndexConstant.java
│ │ ├── TokenConstant.java
│ │ ├── CarInformationConstant.java
│ │ ├── CommonConstant.java
│ │ ├── MemberConstant.java
│ │ ├── ValidateConstant.java
│ │ └── UserConstant.java
│ │ ├── annotation
│ │ ├── Authorization.java
│ │ └── CurrentUser.java
│ │ ├── YiyexyApplication.java
│ │ ├── task
│ │ └── Task.java
│ │ ├── dao
│ │ ├── car
│ │ │ ├── MemberDao.java
│ │ │ └── CarInformationDao.java
│ │ └── common
│ │ │ └── UserDao.java
│ │ ├── exception
│ │ └── MemberUserIsFullException.java
│ │ ├── manager
│ │ ├── TokenManager.java
│ │ └── impl
│ │ │ └── RedisTokenManager.java
│ │ ├── config
│ │ ├── MyBatisMapperScannerConfig.java
│ │ ├── CorsConfig.java
│ │ ├── WebConfigBeans.java
│ │ ├── Swagger2Configuration.java
│ │ ├── MyWebAppConfigurer.java
│ │ ├── MessageConfig.java
│ │ └── MyBatisConfig.java
│ │ ├── handle
│ │ └── ExceptionHandle.java
│ │ ├── controller
│ │ ├── common
│ │ │ ├── BaseController.java
│ │ │ ├── ValidateController.java
│ │ │ └── UserController.java
│ │ └── car
│ │ │ ├── IndexController.java
│ │ │ └── MemberController.java
│ │ ├── service
│ │ ├── car
│ │ │ ├── IMemberService.java
│ │ │ ├── ICarInformationService.java
│ │ │ └── impl
│ │ │ │ ├── CarInformationService.java
│ │ │ │ └── MemberService.java
│ │ └── common
│ │ │ ├── IMessageService.java
│ │ │ ├── IUserService.java
│ │ │ └── impl
│ │ │ ├── MessageService.java
│ │ │ └── UserService.java
│ │ ├── model
│ │ ├── common
│ │ │ ├── TokenModel.java
│ │ │ └── User.java
│ │ └── car
│ │ │ ├── CarRetroaction.java
│ │ │ ├── Member.java
│ │ │ ├── BusTicketInfo.java
│ │ │ └── CarInformation.java
│ │ ├── converter
│ │ └── DateConverter.java
│ │ ├── interceptor
│ │ └── AuthorizationInterceptor.java
│ │ ├── resolvers
│ │ └── CurrentUserMethodArgumentResolver.java
│ │ └── sender
│ │ └── MessageSender.java
└── test
│ └── java
│ └── com
│ └── yiyexy
│ ├── YiyexyApplicationTests.java
│ ├── util
│ ├── ValidateCodeUtilTest.java
│ └── RedisTemplateTest.java
│ ├── service
│ ├── car
│ │ └── MemberServiceTest.java
│ └── common
│ │ └── MessageServiceTest.java
│ └── dao
│ └── car
│ ├── MemberDaoTest.java
│ ├── CarInformationDaoTest.java
│ └── UserDaoTest.java
├── .mvn
└── wrapper
│ └── maven-wrapper.jar
├── java.sh
├── .gitignore
├── pom.xml
├── mvnw.cmd
└── mvnw
/src/main/resources/api/validate.md:
--------------------------------------------------------------------------------
1 | ##### 验证码相关 api
2 |
3 | ----
4 |
5 |
6 | > url
7 | ```text
8 | /
9 | ```
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/archervanderwaal/yiyexy/HEAD/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/java.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -i count
4 | #统计java代码行数
5 | a=`find ./src -name "*.java"|xargs cat|wc -l`
6 | b=`find ./src -name "*.xml"|xargs cat|wc -l`
7 | c=`find ./src -name "*.sql"|xargs cat|wc -l`
8 | count=${a}+${b}+${c}
9 | echo "total java: ${count} line."
--------------------------------------------------------------------------------
/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | _____ _ ___ ___
2 | / ___| | | \/ |
3 | \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _
4 | `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` |
5 | /\__/ / || (_) | | | | | | | | | | | (_| |
6 | \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_|
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/NumUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | /**
4 | *
Created on 2017/5/8.
5 | *
6 | * @author stormma
7 | *
8 | * @description
9 | */
10 | public class NumUtil {
11 |
12 | public static String numToString(int num) {
13 | return num + "";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/ObjectUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | /**
4 | * Created on 2017/5/7.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 对象工具类
9 | */
10 | public class ObjectUtil {
11 |
12 | public static boolean isEmpty(Object object) {
13 | return object == null;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/DBConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/7.
5 | *
6 | * @author stormma
7 | *
8 | * @description:
9 | */
10 | public class DBConstant {
11 |
12 | public static final int NO_THIS_RECORD = 0;
13 |
14 | public static final int HAVE_THIS_RECORD = 1;
15 | }
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | ###properties
12 | *.properties
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | nbproject/private/
22 | build/
23 | nbbuild/
24 | dist/
25 | nbdist/
26 | .nb-gradle/
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/YiyexyApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class YiyexyApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/IndexConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/10.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 主页常量池
9 | *
10 | * 我一直以为在代码里面写汉字是非常非常恶心的一件事情,但是这不得不避免,谁叫咱英语四级还没过呢
11 | * 我能做的就是把这些汉字描述全部用常量池来定义,这样看着逼格就不一样...
12 | */
13 | public class IndexConstant {
14 |
15 | public static final String INDEX_CONTROLLER_DESC = "主页控制器";
16 |
17 | public static final String INDEX_METHOD_DESC = "根据日期返回今日拼车信息";
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/annotation/Authorization.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Create on 20175/7
10 | *
11 | * @author stormma
12 | *
13 | * @description: 权限控制注解
14 | */
15 | @Target(ElementType.METHOD)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | public @interface Authorization {
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/log/MyLogger.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util.log;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | /**
7 | * Created on 2017/5/8.
8 | *
9 | * @author stormma
10 | *
11 | * @descritpion: 日志记录器
12 | */
13 | public class MyLogger {
14 |
15 | /**
16 | * 获得日志记录器
17 | * @param clazz
18 | * @return
19 | */
20 | public static Logger getLogger(Class clazz) {
21 |
22 | return LoggerFactory.getLogger(clazz);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/annotation/CurrentUser.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 |
9 | /**
10 | * Create on 2017/5/7
11 | *
12 | * @author stormma
13 | *
14 | * @description: Controller的方法参数中使用此注解,该方法在映射时会注入当前登录的User对象
15 | */
16 | @Target(ElementType.PARAMETER)
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface CurrentUser {
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/YiyexyApplication.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.scheduling.annotation.EnableScheduling;
6 | import org.springframework.transaction.annotation.EnableTransactionManagement;
7 |
8 | @SpringBootApplication
9 | @EnableScheduling
10 | @EnableTransactionManagement
11 | public class YiyexyApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(YiyexyApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/api/user.md:
--------------------------------------------------------------------------------
1 | #### 用户相关 api 文档
2 |
3 |
4 | ----
5 |
6 | ##### 登录
7 |
8 | ```text
9 | url: /api/user/login
10 | method: POST
11 | param: mobile(手机号), password(密码)
12 | example: /api/user/login?mobile=xxxx&password=xxxx
13 | return:
14 | ```
15 | > 成功
16 | ```json
17 |
18 | {
19 | "code": 0,
20 | "data": {
21 | "uid": 55,
22 | "token": "75b2e801f3be48d1a4a61700fdd516b8"
23 | },
24 | "msg": "success"
25 | }
26 | ```
27 | > 失败
28 |
29 | ```json
30 | {
31 | "code": 1,
32 | "data": null,
33 | "msg": "0"
34 | }
35 | ```
36 | > 补充
37 | ```text
38 | 继续延伸上个版本的逻辑,如果登录失败,并且 msg=0表示密码错误, msg=1表示手机号未注册
39 | ```
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/TokenConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/7.
5 | *
6 | * @author stormma
7 | *
8 | * @description: Created on 2017/5/7.
9 | */
10 | public class TokenConstant {
11 |
12 | /**
13 | * 存储当前登录用户id的字段名
14 | */
15 | public static final String CURRENT_USER_ID = "CURRENT_USER_ID";
16 |
17 | /**
18 | * token有效期(小时)
19 | */
20 | public static final int TOKEN_EXPIRES_HOUR = 72;
21 |
22 | /**
23 | * 存放Authorization的header字段
24 | */
25 | public static final String AUTHORIZATION = "authorization";
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/CarInformationConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/10.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 拼车信息的常量池
9 | */
10 | public class CarInformationConstant {
11 |
12 | public static final String START_DATE_DESC = "拼车信息开始日期";
13 |
14 | public static final String IID_FIELD_DESC = "拼车信息id";
15 |
16 | public static final String NO_THIS_IID_CAR_INFORMATION = "没有此id的拼车信息";
17 |
18 | public static final String ADD_CAR_INFORMATION_METHOD_DESC = "发起拼车接口";
19 |
20 | public static final String CREATE_STROKE_FAILED = "发布拼车信息失败";
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/task/Task.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.task;
2 |
3 | import com.yiyexy.util.log.MyLogger;
4 | import org.slf4j.Logger;
5 | import org.springframework.scheduling.annotation.EnableScheduling;
6 | import org.springframework.scheduling.annotation.Scheduled;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * Created by stormma on 2017/5/8.
11 | */
12 | @Component
13 | @EnableScheduling
14 | public class Task {
15 |
16 |
17 | private static final Logger LOGGER = MyLogger.getLogger(Task.class);
18 |
19 | @Scheduled(cron = "0 49 20 ? * MON")
20 | public void task() {
21 | LOGGER.info("听说今天是周日");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/RegexpUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * Created on 2017/5/9.
8 | *
9 | * @author stormma
10 | *
11 | * @description: 正则匹配工具类
12 | */
13 | public class RegexpUtil {
14 |
15 | /**
16 | * 判断是不是手机号码
17 | * @param mobile
18 | * @return
19 | */
20 | public static boolean isMobileNum(String mobile) {
21 |
22 | String regexp = "^1[3,4,5,7,8]\\d{9}$";
23 |
24 | Pattern pattern = Pattern.compile(regexp);
25 |
26 | Matcher matcher = pattern.matcher(mobile);
27 | return matcher.matches();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/CommonConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/7.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 共有的常量池
9 | */
10 | public class CommonConstant {
11 |
12 | public static final String SUCCESS = "success";
13 |
14 | public static final String FAIL = "fail";
15 |
16 | public static final String MESSAGE_TEMPLATE = "【一页校园】您的验证码为 %s。青衿不解参差,一页便知校园。";
17 |
18 | public static final int SEND_MAX_VALIDATE_CODE_ONE_WEEK = 10;
19 |
20 | public static final String INVALID_MOBILE_NUM = "无效的手机号码";
21 |
22 | public static final String VALIDATE_TYPE_DESC = "请求发送验证码的类型, 1表示重置密码的验证码,0表示注册时候的验证码";
23 |
24 | public static final String PARAM_BIND_FAILED = "参数绑定失败";
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/dao/car/MemberDao.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.dao.car;
2 |
3 | import com.yiyexy.model.car.Member;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * Created on 2017/5/8.
9 | *
10 | * @author stormma
11 | *
12 | * @description: 成员 dao 层接口
13 | */
14 | @Mapper
15 | public interface MemberDao {
16 |
17 |
18 | /**
19 | * 增加用户到行程中
20 | * @param member
21 | */
22 | void addUserToMember(@Param("member") Member member);
23 |
24 | /**
25 | * 查询拼车信息的成员
26 | * @param iid
27 | * @return
28 | */
29 | Member getMember(@Param("iid") int iid);
30 |
31 | /**
32 | * 删除成员中的某个用户
33 | * @param member
34 | */
35 | void removeUserFromMember(@Param("member") Member member);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/ValidateCodeUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import java.util.Random;
4 |
5 | /**
6 | * Created on 2017/5/8.
7 | *
8 | * @author stormma
9 | * @description: 验证码工具类
10 | */
11 | public class ValidateCodeUtil {
12 |
13 | /**
14 | * 获得几位数的验证码
15 | * @param charCount
16 | * @return
17 | */
18 | public static String getRandNum(int charCount) {
19 | String charValue = "";
20 | for (int i = 0; i < charCount; i++) {
21 | char c = (char) (randomInt(0, 10) + 48);
22 | charValue = charValue + String.valueOf(c);
23 | }
24 | return charValue;
25 | }
26 |
27 | public static int randomInt(int from, int to) {
28 | Random r = new Random();
29 | return from + r.nextInt(to - from);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/exception/MemberUserIsFullException.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.exception;
2 |
3 | /**
4 | * Created on 2017/5/9.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 成员已满异常
9 | */
10 | public class MemberUserIsFullException extends Exception {
11 |
12 | public MemberUserIsFullException() {
13 | }
14 |
15 | public MemberUserIsFullException(String message) {
16 | super(message);
17 | }
18 |
19 | public MemberUserIsFullException(String message, Throwable cause) {
20 | super(message, cause);
21 | }
22 |
23 | public MemberUserIsFullException(Throwable cause) {
24 | super(cause);
25 | }
26 |
27 | public MemberUserIsFullException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
28 | super(message, cause, enableSuppression, writableStackTrace);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/MemberConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/10.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 成员信息常量池
9 | */
10 | public class MemberConstant {
11 |
12 | public static final String MEMBER_CONTROLLER_DESC = "拼车信息的成员控制器类";
13 |
14 | public static final String GET_MEMBER_METHOD_DESC = "根据拼车信息id获得加入拼车成员的信息(登录授权)";
15 |
16 | public static final String SIGN_UP_CAR_INFORMATION_METHOD_DESC = "加入拼车信息(参数iid和uid)";
17 |
18 | public static final String ALERDY_SIGN_UP_CAR_INFORMATION = "已加入拼车信息";
19 |
20 | public static final String MEMBER_IS_FULL = "成员已满";
21 |
22 | public static final String CANCEL_CAR_INFORMATION_METHOD_DESC = "取消行程信息";
23 |
24 | public static final String NO_SIGN_UP_THIS_CAR_INFORMATION = "没有加入此拼车信息,所以你没有权限取消该行程";
25 |
26 | public static final String INVAILD_SIGN_UP = "请检查您现有的拼车信息,您当前的操作和已有拼车冲突";
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/manager/TokenManager.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.manager;
2 |
3 |
4 | import com.yiyexy.model.common.TokenModel;
5 |
6 | /**
7 | * Create on 2017/5/7
8 | *
9 | * @author stormma
10 | *
11 | * @description: 对Token进行操作的接口
12 | */
13 | public interface TokenManager {
14 |
15 | /**
16 | * 创建一个token关联上指定用户
17 | * @param userId
18 | * @return 生成的token
19 | */
20 | TokenModel createToken(Integer userId);
21 |
22 | /**
23 | * 检查token是否有效
24 | * @param model token
25 | * @return 是否有效
26 | */
27 | boolean checkToken(TokenModel model);
28 |
29 | /**
30 | * 从字符串中解析token
31 | * @param authentication 加密后的字符串
32 | * @return
33 | */
34 | TokenModel getToken(String authentication);
35 |
36 | /**
37 | * 清除token
38 | * @param userId 登录用户的id
39 | */
40 | void deleteToken(Integer userId);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/StringRedisTempldateUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.redis.core.RedisTemplate;
5 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * Created on 2017/5/10.
10 | *
11 | * @author stormma
12 | *
13 | * @description: reids 工具类
14 | */
15 | @Component
16 | public class StringRedisTempldateUtil {
17 |
18 | private RedisTemplate redisTemplate;
19 |
20 | @Autowired
21 | private void setRedisTemplate(RedisTemplate redisTemplate) {
22 | this.redisTemplate = redisTemplate;
23 | redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer());
24 | }
25 |
26 | public RedisTemplate getStringRedisTempldate() {
27 | return redisTemplate;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/MyBatisMapperScannerConfig.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import org.mybatis.spring.mapper.MapperScannerConfigurer;
4 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * Created on 2017/3/13.
10 | *
11 | * @author StormMa
12 | *
13 | * @Description: Mybaitis 自动扫描的配置类
14 | */
15 | @Configuration
16 | @AutoConfigureAfter(MyBatisConfig.class)
17 | public class MyBatisMapperScannerConfig {
18 |
19 | @Bean
20 | public MapperScannerConfigurer mapperScannerConfigurer() {
21 | MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
22 | mapperScannerConfigurer.setBasePackage("com.yiyexy.dao");
23 | mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
24 | return mapperScannerConfigurer;
25 | }
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/DateUtils.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import java.util.Calendar;
4 | import java.util.Date;
5 | /**
6 | * Created on 2017/5/10.
7 | *
8 | * @author StormMa
9 | *
10 | * @Description: 日期相关工具类
11 | */
12 | public class DateUtils {
13 |
14 | /**
15 | * 判断两个日期像个多少天
16 | * @param date1
17 | * @param date2
18 | * @return
19 | */
20 | public static int getDifferenceDays(Date date1, Date date2) {
21 | return (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
22 | }
23 |
24 | /**
25 | * 获得指定日期之前几天的日期
26 | * @param date
27 | * @param day
28 | * @return
29 | */
30 | public static Date getBeforeDate(Date date, int day) {
31 | Calendar calendar = Calendar.getInstance();
32 | calendar.setTime(date);
33 | int days = calendar.get(Calendar.DATE);
34 | calendar.set(Calendar.DATE, days - day);
35 | return calendar.getTime();
36 | }
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/EncryptionUtil.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import sun.misc.BASE64Encoder;
6 |
7 | import java.security.MessageDigest;
8 | import java.security.NoSuchAlgorithmException;
9 |
10 | /**
11 | * Created on 2017/5/7.
12 | *
13 | * @author stormma
14 | *
15 | * @description: 加密工具类
16 | */
17 | public class EncryptionUtil {
18 |
19 | private static final Logger LOGGER = LoggerFactory.getLogger(EncryptionUtil.class);
20 |
21 | public static String md5Encryption(String source) {
22 |
23 | MessageDigest md = null;
24 | try {
25 | md = MessageDigest.getInstance("md5");
26 | } catch (NoSuchAlgorithmException e) {
27 | LOGGER.error("加密出错:{}", e);
28 | }
29 | byte [] md5 = md.digest(source.getBytes());
30 |
31 | BASE64Encoder encode = new BASE64Encoder();
32 |
33 | return encode.encode(md5);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/handle/ExceptionHandle.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.handle;
2 |
3 | import com.yiyexy.util.result.Result;
4 | import com.yiyexy.util.result.ResultBuilder;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.web.bind.annotation.ExceptionHandler;
8 | import org.springframework.web.bind.annotation.RestControllerAdvice;
9 |
10 | /**
11 | * Created on 2017/3/15.
12 | *
13 | * @author StormMa
14 | *
15 | * @Description: 统一异常处理
16 | */
17 | @RestControllerAdvice
18 | public class ExceptionHandle {
19 |
20 | private static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
21 | @ExceptionHandler(value = Exception.class)
22 | public Result exceptionHandle(Exception e) {
23 | if (e instanceof RuntimeException) {
24 | logger.error("服务器发生错误:{}", e);
25 | return ResultBuilder.fail("服务器内部错误");
26 | }
27 |
28 | logger.error("错误信息:{}", e);
29 | return ResultBuilder.fail();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/controller/common/BaseController.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.controller.common;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import javax.servlet.http.HttpSession;
9 |
10 | /**
11 | * * _____ _ ___ ___
12 | / ___| | | \/ |
13 | \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _
14 | `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` |
15 | /\__/ / || (_) | | | | | | | | | | | (_| |
16 | \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_| 我想念你,一如独自撸码的忧伤....
17 |
18 | * Create On 20175/9
19 | *
20 | * @author stormma
21 | *
22 | * 控制器基类
23 | */
24 | @RestController
25 | public class BaseController {
26 |
27 | @Autowired
28 | protected HttpServletRequest request;
29 |
30 | @Autowired
31 | private HttpSession session;
32 |
33 | @Autowired
34 | private HttpServletResponse response;
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/service/car/IMemberService.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.car;
2 |
3 | import com.yiyexy.model.common.User;
4 |
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Created on 2017/5/9.
10 | *
11 | * @author stormma
12 | *
13 | * @description: 成员服务接口
14 | */
15 | public interface IMemberService {
16 |
17 | /**
18 | * 取消用户uid在iid拼车的行程信息
19 | * @param iid
20 | * @param uid
21 | * @return
22 | */
23 | Map cancelStroke (int iid, int uid);
24 |
25 | /**
26 | * 根据拼车信息查询所有成员的信息
27 | * @param iid
28 | * @return
29 | */
30 | List getMemberInfos(int iid);
31 |
32 | /**
33 | * 添加用户uid到行程中去
34 | * @param iid
35 | * @param uid
36 | * @return
37 | */
38 | Map addUserToStroke(int iid, int uid);
39 |
40 | /**
41 | * 判断uid是否可以报名iid这个行程信息
42 | * @param uid
43 | * @param iid
44 | * @return
45 | */
46 | Map isCanSignUpCarInformation(int uid, int iid);
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/util/ValidateCodeUtilTest.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import com.yiyexy.config.MessageConfig;
4 | import com.yiyexy.util.log.MyLogger;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | /**
13 | * Created on 2017/5/8.
14 | *
15 | * @author stormma
16 | *
17 | * @description: 验证码生成器测试用例
18 | */
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | public class ValidateCodeUtilTest {
22 |
23 | @Autowired
24 | private MessageConfig messageConfig;
25 |
26 | private static final Logger LOGGER = MyLogger.getLogger(ValidateCodeUtilTest.class);
27 |
28 | @Test
29 | public void testGetCode() {
30 | String validateCode = ValidateCodeUtil.getRandNum(messageConfig.getValidateCodeCount());
31 |
32 | LOGGER.info("测试结果:{}", validateCode);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/CorsConfig.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.cors.CorsConfiguration;
6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
7 | import org.springframework.web.filter.CorsFilter;
8 |
9 | @Configuration
10 | public class CorsConfig {
11 | private CorsConfiguration buildConfig() {
12 | CorsConfiguration corsConfiguration = new CorsConfiguration();
13 | corsConfiguration.addAllowedOrigin("*"); // 1
14 | corsConfiguration.addAllowedHeader("*"); // 2
15 | corsConfiguration.addAllowedMethod("*"); // 3
16 | corsConfiguration.setAllowCredentials(true);
17 | return corsConfiguration;
18 | }
19 |
20 | @Bean
21 | public CorsFilter corsFilter() {
22 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
23 | source.registerCorsConfiguration("/**", buildConfig()); // 4
24 | return new CorsFilter(source);
25 | }
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/model/common/TokenModel.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.model.common;
2 |
3 | /**
4 | * Create on 2017/5/7
5 | *
6 | * @author stormma
7 | *
8 | * @description: token 的 model 类
9 | */
10 | public class TokenModel {
11 |
12 | /**
13 | * 用户 id
14 | */
15 | private Integer uid;
16 |
17 | /**
18 | * 随机生成 token
19 | */
20 | private String token;
21 |
22 | public TokenModel() {
23 | }
24 |
25 | public TokenModel(Integer uid, String token) {
26 | this.uid = uid;
27 | this.token = token;
28 | }
29 |
30 | public Integer getUid() {
31 | return uid;
32 | }
33 |
34 | public void setUid(Integer uid) {
35 | this.uid = uid;
36 | }
37 |
38 | public String getToken() {
39 | return token;
40 | }
41 |
42 | public void setToken(String token) {
43 | this.token = token;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "TokenModel{" +
49 | "uid=" + uid +
50 | ", token='" + token + '\'' +
51 | '}';
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/service/car/MemberServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.car;
2 |
3 | import com.yiyexy.util.RegexpUtil;
4 | import com.yiyexy.util.log.MyLogger;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | /**
13 | * Created on 2017/5/9.
14 | *
15 | * @author stormma
16 | *
17 | * @description 测试用例
18 | */
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | public class MemberServiceTest {
22 |
23 | @Autowired
24 | private IMemberService memberService;
25 |
26 | private static final Logger LOGGER = MyLogger.getLogger(MemberServiceTest.class);
27 |
28 | @Test
29 | public void testCancelStroke() {
30 |
31 | /*int iid = 293;
32 |
33 | int uid = 55;
34 |
35 | boolean result = memberService.cancelStroke(iid, uid);
36 |
37 | LOGGER.info("测试结果:{}", result);*/
38 |
39 | LOGGER.info("{}", RegexpUtil.isMobileNum("18292817803"));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/ValidateConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/9.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 验证码常量池
9 | */
10 | public class ValidateConstant {
11 |
12 | public static final String VALIDATE_CONTROLLER_DESC = "验证码控制器类";
13 |
14 | public static final String VALIDATE_SEND_METHOD_DESC = "发送验证码";
15 |
16 | public static final String VALIDATE_SEND_FAIL = "验证码发送失败";
17 |
18 | public static final String VALIDATE_SEND_MAX_COUNT_CODE = "一周发送验证码已达上限";
19 |
20 | public static final long VALIDATE_CODE_VALID_TIME_MINUNTES = 30L;
21 |
22 | public static final String USER_COMMIT_VALIDATE_CODE = "用户提交的验证码";
23 |
24 | //设置多少天之内发送验证码数目有限
25 | public static final long VALIDATE_CHECK_DAYS = 7L;
26 |
27 | public static final String VALIDATE_REDIS_SUFFIX = "_count";
28 |
29 | public static final int RESET_PASSWORD_VALIDATE_CODE = 1;
30 |
31 | public static final int REGISTER_VALIDATE_CODE = 0;
32 |
33 | public static final String THIS_MOBILE_ALERDY_REGISTER = "该手机号码已经注册";
34 |
35 | public static final String VALIDATE_CODE_IS_INVALID = "验证码校验不通过,无法继续这次操作,请重试";
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/result/Result.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util.result;
2 |
3 | /**
4 | * Created on 2017/3/15.
5 | *
6 | * @author StormMa
7 | *
8 | * @Description: 对请求结果进行封装
9 | */
10 | public class Result {
11 |
12 | /**
13 | * error code :错误是1、成功是0
14 | */
15 | private Integer code;
16 |
17 | /**
18 | * 要返回的数据
19 | */
20 | private T data;
21 |
22 | /**
23 | * 本次请求的说明信息
24 | */
25 | private String msg;
26 |
27 | public Integer getCode() {
28 | return code;
29 | }
30 |
31 | public void setCode(Integer code) {
32 | this.code = code;
33 | }
34 |
35 | public T getData() {
36 | return data;
37 | }
38 |
39 | public void setData(T data) {
40 | this.data = data;
41 | }
42 |
43 | public String getMsg() {
44 | return msg;
45 | }
46 |
47 | public void setMsg(String msg) {
48 | this.msg = msg;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "RequestResult{" +
54 | "code=" + code +
55 | ", data=" + data +
56 | ", msg='" + msg + '\'' +
57 | '}';
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/service/common/MessageServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.common;
2 |
3 | import com.yiyexy.constant.CommonConstant;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | import java.util.Map;
13 |
14 | /**
15 | * Created on 2017/5/8.
16 | *
17 | * @author stormma
18 | *
19 | * @description: 验证码测试接口
20 | */
21 | @RunWith(SpringRunner.class)
22 | @SpringBootTest
23 | public class MessageServiceTest {
24 |
25 | @Autowired
26 | private IMessageService messageService;
27 |
28 | private static final Logger LOGGER = LoggerFactory.getLogger(MessageServiceTest.class);
29 |
30 | @Test
31 | public void testSendMessage() {
32 | String mobile = "18292817803";
33 |
34 | Map datas = messageService.sendMessage(mobile);
35 |
36 | if (datas.get(CommonConstant.SUCCESS) != null) {
37 | LOGGER.info("验证码为:{}", datas.get(CommonConstant.SUCCESS));
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/dao/car/MemberDaoTest.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.dao.car;
2 |
3 | import com.yiyexy.model.car.Member;
4 | import com.yiyexy.util.log.MyLogger;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | /**
13 | * Created on 2017/5/9.
14 | *
15 | * @author stormma
16 | *
17 | * @description: 成员测试
18 | */
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | public class MemberDaoTest {
22 |
23 | @Autowired
24 | private MemberDao memberDao;
25 |
26 | private static final Logger LOGGER = MyLogger.getLogger(MemberDaoTest.class);
27 |
28 | @Test
29 | public void testGetMember() {
30 | int iid = 293;
31 |
32 | Member member = memberDao.getMember(iid);
33 |
34 | LOGGER.info("测试结果:{}", member);
35 | }
36 |
37 | @Test
38 | public void testAddUserToMember() {
39 | Member member = new Member();
40 | member.setIid(293);
41 | member.setUid3(56);
42 |
43 | memberDao.addUserToMember(member);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/service/common/IMessageService.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.common;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created on 2017/5/8.
7 | *
8 | * @author stormma
9 | *
10 | * @description: 短信验证码服务
11 | */
12 | public interface IMessageService {
13 |
14 | /**
15 | * 发送验证码服务,前提要判断是否具有权限
16 | * @param mobile
17 | * @return
18 | */
19 | Map sendMessage(String mobile);
20 |
21 | /**
22 | * 判断是否可以发送短信验证码
23 | * @param mobile
24 | * @return
25 | */
26 | boolean isCanSendMessage(String mobile);
27 |
28 | /**
29 | * 增加发送短信验证码的数目
30 | * @param mobile
31 | */
32 | void increaseSendValidateCodeCount(String mobile);
33 |
34 | /**
35 | * 获得保存发送验证码数目的key
36 | * @param mobile
37 | * @return
38 | */
39 | String getRedisKeyForSendValidateCodeCount(String mobile);
40 |
41 | /**
42 | * 获得该手机号码一周发送的数目
43 | * @param mobile
44 | * @return
45 | */
46 | Integer getSendValidateCodeCountOneWeek(String mobile);
47 |
48 | /**
49 | * 判断该手机号提交的验证码是否正确
50 | * @param validateCode
51 | * @param mobile
52 | * @return
53 | */
54 | boolean checkValidateIsValid(String validateCode, String mobile);
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/service/car/ICarInformationService.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.car;
2 |
3 | import com.yiyexy.model.car.CarInformation;
4 |
5 | import java.util.Date;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | /**
10 | * Created on 2017/5/9.
11 | *
12 | * @author stormma
13 | *
14 | * @description: 维护拼车信息的服务接口
15 | */
16 | public interface ICarInformationService {
17 |
18 | /**
19 | * 添加一个行程信息
20 | * @param carInformation
21 | * @return 主键
22 | */
23 | int addCarInformation(CarInformation carInformation);
24 |
25 | /**
26 | * 根据发布日期查询拼车信息
27 | * @param pubTime
28 | * @return 发布日期为pubTime的所有行程信息
29 | */
30 | List getCarInformationsByPubTime(Date pubTime);
31 |
32 | /**
33 | * 根据开始日期查询所有的行程信息
34 | * @param startDate
35 | * @return
36 | */
37 | List getCarInformationsByStartDate(Date startDate);
38 |
39 | /**
40 | * 根据用户查询用户所参加或者发起的拼车信息
41 | * @param uid
42 | * @return
43 | */
44 | List getUserSignedUpCarInformation(int uid);
45 |
46 | /**
47 | * 发布拼车信息
48 | * @param carInformation
49 | * @return
50 | */
51 | Map createStroke(CarInformation carInformation);
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/converter/DateConverter.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.converter;
2 |
3 | import org.apache.commons.lang.StringUtils;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.core.convert.converter.Converter;
7 |
8 | import java.text.ParseException;
9 | import java.text.SimpleDateFormat;
10 | import java.util.Date;
11 |
12 | /**
13 | * Create on 2017/5/7.
14 | *
15 | * @author stormma
16 | *
17 | * @description: 日期转换器
18 | */
19 | public class DateConverter implements Converter {
20 | private Logger logger = LoggerFactory.getLogger(DateConverter.class);
21 |
22 | @Override
23 | public Date convert(String source) {
24 | if (StringUtils.isEmpty(source)) {
25 | return null;
26 | }
27 | try {
28 | long milltime = Long.valueOf(source);
29 | return new Date(milltime);
30 | } catch (Exception e){
31 | logger.warn("传入的时间参数不是Long类型, 按String类型处理");
32 | }
33 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
34 | try {
35 | return simpleDateFormat.parse(source);
36 | } catch (ParseException e) {
37 | logger.error("Date转换错误: str=" + source + ", errorMsg=" + e.getMessage());
38 | }
39 | return null;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/WebConfigBeans.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import com.yiyexy.converter.DateConverter;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.core.convert.support.GenericConversionService;
7 | import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
8 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
9 |
10 | import javax.annotation.PostConstruct;
11 |
12 | /**
13 | * Created on 2017/5/7.
14 | *
15 | * @author stormma
16 | *
17 | * @description: 配置
18 | */
19 | @Configuration
20 | public class WebConfigBeans {
21 |
22 | @Autowired
23 | private RequestMappingHandlerAdapter handlerAdapter;
24 |
25 |
26 | @PostConstruct
27 | public void initEditableValidation() {
28 | ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter
29 | .getWebBindingInitializer();
30 | if (initializer.getConversionService() != null) {
31 | GenericConversionService genericConversionService = (GenericConversionService) initializer
32 | .getConversionService();
33 | genericConversionService.addConverter(new DateConverter());
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/Swagger2Configuration.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.ApiInfoBuilder;
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.service.ApiInfo;
9 | import springfox.documentation.spi.DocumentationType;
10 | import springfox.documentation.spring.web.plugins.Docket;
11 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
12 |
13 | /**
14 | * Created on 2017/4/10.
15 | *
16 | * @author StormMa
17 | *
18 | * @Description: 配置类
19 | */
20 | @Configuration
21 | @EnableSwagger2
22 | public class Swagger2Configuration {
23 | @Bean
24 | public Docket buildDocket() {
25 | return new Docket(DocumentationType.SWAGGER_2)
26 | .apiInfo(buildApiInf())
27 | .select()
28 | .apis(RequestHandlerSelectors.basePackage("com.yiyexy.controller"))
29 | .paths(PathSelectors.any())
30 | .build();
31 | }
32 | private ApiInfo buildApiInf() {
33 | return new ApiInfoBuilder()
34 | .title("一页校园api文档")
35 | .contact("StormMa")
36 | .version(" v1.0")
37 | .build();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/util/result/ResultBuilder.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util.result;
2 |
3 | /**
4 | * Created on 2017/3/15.
5 | *
6 | * @author StormMa
7 | *
8 | * @Description: 封装请求结果的工具类
9 | */
10 | public class ResultBuilder {
11 |
12 | /**
13 | * 成功请求的结果封装
14 | * @param t
15 | * @param
16 | * @return
17 | */
18 | public static Result success(T t) {
19 | Result result = new Result<>();
20 | result.setCode(0);
21 | result.setMsg("success");
22 | result.setData(t);
23 | return result;
24 | }
25 |
26 | /**
27 | * 成功请求的结果封装
28 | * @param
29 | * @return
30 | */
31 | public static Result success() {
32 | return success(null);
33 | }
34 |
35 | /**
36 | * 失败请求的结果封装
37 | * @param
38 | * @return
39 | */
40 | public static Result fail() {
41 | Result result = new Result<>();
42 | result.setCode(1);
43 | result.setData(null);
44 | result.setMsg("fail");
45 | return result;
46 | }
47 |
48 | /**
49 | * 失败请求的结果封装
50 | * @param msg
51 | * @param
52 | * @return
53 | */
54 | public static Result fail(String msg) {
55 | Result result = new Result<>();
56 | result.setCode(1);
57 | result.setData(null);
58 | result.setMsg(msg);
59 | return result;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/model/car/CarRetroaction.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.model.car;
2 |
3 | /**
4 | * Created on 2017/5/10.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 拼车反馈
9 | */
10 | public class CarRetroaction {
11 |
12 | /**
13 | * uid
14 | */
15 | private Integer uid;
16 |
17 | /**
18 | * 拼车信息 id
19 | */
20 | private Integer iid;
21 |
22 | /**
23 | * 反馈内容
24 | */
25 | private String content;
26 |
27 | /**
28 | * 是否成功(成功或者失败)
29 | */
30 | private String status;
31 |
32 | public Integer getUid() {
33 | return uid;
34 | }
35 |
36 | public void setUid(Integer uid) {
37 | this.uid = uid;
38 | }
39 |
40 | public Integer getIid() {
41 | return iid;
42 | }
43 |
44 | public void setIid(Integer iid) {
45 | this.iid = iid;
46 | }
47 |
48 | public String getContent() {
49 | return content;
50 | }
51 |
52 | public void setContent(String content) {
53 | this.content = content;
54 | }
55 |
56 | public String getStatus() {
57 | return status;
58 | }
59 |
60 | public void setStatus(String status) {
61 | this.status = status;
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "CarRetroaction{" +
67 | "uid=" + uid +
68 | ", iid=" + iid +
69 | ", content='" + content + '\'' +
70 | ", status='" + status + '\'' +
71 | '}';
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/service/common/IUserService.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.service.common;
2 |
3 | import com.yiyexy.model.common.User;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created on 2017/5/7.
9 | *
10 | * @author stormma
11 | *
12 | * @description: 用户服务类接口
13 | */
14 | public interface IUserService {
15 |
16 | /**
17 | * 判断是否登录成功
18 | * @param mobile
19 | * @param password
20 | * @return
21 | */
22 | Map isLoginSuccess(String mobile, String password);
23 |
24 | /**
25 | * 修改密码
26 | * @param mobile
27 | * @param password
28 | * @return
29 | */
30 | boolean updatePassword(String mobile, String password);
31 |
32 | /**
33 | * 修改qq
34 | * @param mobile
35 | * @param qq
36 | * @return
37 | */
38 | boolean updateQQNum(String mobile, String qq);
39 |
40 | /**
41 | * 修改用户名
42 | * @param mobile
43 | * @param userName
44 | * @return
45 | */
46 | String updateUserName(String mobile, String userName);
47 |
48 |
49 | /**
50 | * 注册时候发送验证码
51 | * @param moible
52 | * @return
53 | */
54 | Map sendValidateCode(String moible, int type);
55 |
56 | /**
57 | * 注册
58 | * @param mobile
59 | * @param password
60 | * @return
61 | */
62 | Map register(String mobile, String password);
63 |
64 | /**
65 | * 获得用户信息
66 | * @param uid
67 | * @return
68 | */
69 | User getUserInfo(Integer uid);
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/MyWebAppConfigurer.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 |
4 | import com.yiyexy.interceptor.AuthorizationInterceptor;
5 | import com.yiyexy.resolvers.CurrentUserMethodArgumentResolver;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
10 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
11 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
12 |
13 | import java.util.List;
14 |
15 | @Configuration
16 | public class MyWebAppConfigurer
17 | extends WebMvcConfigurerAdapter {
18 |
19 | @Autowired
20 | private AuthorizationInterceptor authorizationInterceptor;
21 |
22 | @Autowired
23 | private CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver;
24 |
25 | @Override
26 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
27 | registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
28 | super.addResourceHandlers(registry);
29 | }
30 |
31 | @Override
32 | public void addInterceptors(InterceptorRegistry registry) {
33 | registry.addInterceptor(authorizationInterceptor);
34 | }
35 |
36 | @Override
37 | public void addArgumentResolvers(List argumentResolvers) {
38 | argumentResolvers.add(currentUserMethodArgumentResolver);
39 | }
40 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/dao/car/CarInformationDao.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.dao.car;
2 |
3 | import com.yiyexy.model.car.CarInformation;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.Date;
8 | import java.util.List;
9 |
10 | /**
11 | * Created on 2017/5/8.
12 | *
13 | * @author stormma
14 | *
15 | * @description: 拼车信息 dao 层接口
16 | */
17 | @Mapper
18 | public interface CarInformationDao {
19 |
20 | /**
21 | * 添加形成dao层接口
22 | * @param carInformation
23 | */
24 | void insertCarInformation(@Param("carInfo") CarInformation carInformation);
25 |
26 | /**
27 | * 删除制定id的拼车信息
28 | * @param iid
29 | */
30 | void removeCarInformation(@Param("iid") int iid);
31 |
32 | /**
33 | * 根据 iid 查询拼车信息
34 | * @param iid
35 | * @return
36 | */
37 | CarInformation getCarInformation(@Param("iid") int iid);
38 |
39 |
40 | /**
41 | * 查询所有的拼车行程
42 | * @return
43 | */
44 | List getAllCarInformation();
45 |
46 |
47 | /**
48 | * 根据发布时间查询行程信息
49 | * @param pubTime
50 | * @return
51 | */
52 | List getCarInformationsByPubTime(@Param("pubTime") Date pubTime);
53 |
54 | /**
55 | * 根据用户 id 查询用户自己的行程(既包括自己发起的,还包括参与的 )
56 | * @param uid
57 | * @return
58 | */
59 | List getAllCarInfomationByUser(@Param("uid") Integer uid);
60 |
61 | /**
62 | * 根据开始日期查询所有的行程
63 | * @param startDate
64 | * @return
65 | */
66 | List getCarInformationsByStartDate(@Param("startDate") Date startDate);
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/constant/UserConstant.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.constant;
2 |
3 | /**
4 | * Created on 2017/5/7.
5 | *
6 | * @author stormma
7 | *
8 | * @description: 用户常量池
9 | */
10 | public class UserConstant {
11 |
12 | public static final String USER_ENTITY_DESC = "用户实体类";
13 |
14 | public static final String USER_ID_DESC = "用户id";
15 |
16 | public static final String USER_QQ_NUM = "用户qq号码";
17 |
18 | public static final String USER_NAME_DESC = "用户名";
19 |
20 | public static final String USER_PASSWORD_DESC = "用户密码";
21 |
22 | public static final String LOGIN_DESC = "用户登录(参数: mobile、password)";
23 |
24 | public static final String CONTROLLER_DESC = "处理用户数据的请求";
25 |
26 | public static final String UPDATE_PASSWORD = "修改用户密码(password传到user对象中, 授权码头参数)";
27 |
28 | public static final String UPDATE_USER_NAME = "修改用户名";
29 |
30 | public static final String CAN_NOT_UPDATE_USER_NAME = "不能修改用户名";
31 |
32 | public static final String UPDATE_QQ_NUM = "更新qq号码";
33 |
34 | public static final String MOBILE_DESC = "用户手机号码";
35 |
36 | public static final String AUTHORIZATION_TOKEN = "授权码(格式: uid_token)";
37 |
38 | public static final String RESET_PASSWORD_METHOD_DESC = "重置密码接口(参数: mobile, password body参数, validateCode 路径参数)";
39 |
40 | public static final int NO_THIS_MOBILE = -1;
41 |
42 | public static final int ERROR_PASSWORD = 0;
43 |
44 | public static final int LOGIN_SUCCESS = 1;
45 |
46 | public static final String USER_REGISTER_METHOD_DESC = "用户注册(参数:mobile, password body参数, validateCode:路径参数)";
47 |
48 | public static final String GET_USER_INFO_METHOD_DESC = "获得用户个人信息接口";
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/com/yiyexy/util/RedisTemplateTest.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.util;
2 |
3 | import com.yiyexy.constant.ValidateConstant;
4 | import com.yiyexy.util.log.MyLogger;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.data.redis.core.RedisTemplate;
11 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | import java.util.concurrent.TimeUnit;
15 |
16 | /**
17 | * Created on 2017/5/9.
18 | *
19 | * @author stormma
20 | *
21 | * @description: 判断
22 | */
23 | @RunWith(SpringRunner.class)
24 | @SpringBootTest
25 | public class RedisTemplateTest {
26 |
27 | private RedisTemplate redisTemplate;
28 |
29 | private static final Logger LOGGER = MyLogger.getLogger(RedisTemplateTest.class);
30 | @Autowired
31 | private void setRedisTemplate(RedisTemplate redisTemplate) {
32 | this.redisTemplate = redisTemplate;
33 | redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer());
34 | }
35 |
36 | @Test
37 | public void testGetSendValidareCodeCount() {
38 |
39 | String mobile = "18292817803";
40 | String key = mobile + ValidateConstant.VALIDATE_REDIS_SUFFIX;
41 |
42 | redisTemplate.boundValueOps(key).set(10, redisTemplate.boundValueOps(key).getExpire(), TimeUnit.SECONDS);
43 | long day = redisTemplate.boundValueOps(key).getExpire();
44 |
45 | LOGGER.info("{}", day);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/interceptor/AuthorizationInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.interceptor;
2 |
3 | import com.yiyexy.annotation.Authorization;
4 | import com.yiyexy.constant.TokenConstant;
5 | import com.yiyexy.manager.TokenManager;
6 | import com.yiyexy.model.common.TokenModel;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 | import org.springframework.web.method.HandlerMethod;
10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.lang.reflect.Method;
15 |
16 | /**
17 | * 自定义拦截器,判断此次请求是否有权限
18 | * @author ScienJus
19 | * @date 2015/7/30.
20 | */
21 | @Component
22 | public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
23 |
24 | @Autowired
25 | private TokenManager manager;
26 |
27 | public boolean preHandle(HttpServletRequest request,
28 | HttpServletResponse response, Object handler) throws Exception {
29 | //如果不是映射到方法直接通过
30 | if (!(handler instanceof HandlerMethod)) {
31 | return true;
32 | }
33 | HandlerMethod handlerMethod = (HandlerMethod) handler;
34 | Method method = handlerMethod.getMethod();
35 | //从header中得到token
36 | String authorization = request.getHeader(TokenConstant.AUTHORIZATION);
37 | //验证token
38 | TokenModel model = manager.getToken(authorization);
39 | if (manager.checkToken(model)) {
40 | //如果token验证成功,将token对应的用户id存在request中,便于之后注入
41 | request.setAttribute(TokenConstant.CURRENT_USER_ID, model.getUid());
42 | return true;
43 | }
44 | //如果验证token失败,并且方法注明了Authorization,返回401错误
45 | if (method.getAnnotation(Authorization.class) != null) {
46 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
47 | return false;
48 | }
49 | return true;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/model/car/Member.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.model.car;
2 |
3 | /**
4 | * Crete on 2017/05/07
5 | *
6 | * @author stormma
7 | *
8 | * @description: 拼车信息的成员 model
9 | */
10 | public class Member {
11 |
12 | /**
13 | * 拼车信息 id
14 | */
15 | private Integer iid;
16 |
17 | /**
18 | * 成员1id
19 | */
20 | private Integer uid1;
21 |
22 | /**
23 | * 成员2id
24 | */
25 | private Integer uid2;
26 |
27 | /**
28 | * 成员3id
29 | */
30 | private Integer uid3;
31 |
32 | /**
33 | * 成员4id
34 | */
35 | private Integer uid4;
36 |
37 | /**
38 | * 成员5id
39 | */
40 | private Integer uid5;
41 |
42 | /**
43 | * 成员6id
44 | */
45 | private Integer uid6;
46 |
47 | public Integer getIid() {
48 | return iid;
49 | }
50 |
51 | public void setIid(Integer iid) {
52 | this.iid = iid;
53 | }
54 |
55 | public Integer getUid1() {
56 | return uid1;
57 | }
58 |
59 | public void setUid1(Integer uid1) {
60 | this.uid1 = uid1;
61 | }
62 |
63 | public Integer getUid2() {
64 | return uid2;
65 | }
66 |
67 | public void setUid2(Integer uid2) {
68 | this.uid2 = uid2;
69 | }
70 |
71 | public Integer getUid3() {
72 | return uid3;
73 | }
74 |
75 | public void setUid3(Integer uid3) {
76 | this.uid3 = uid3;
77 | }
78 |
79 | public Integer getUid4() {
80 | return uid4;
81 | }
82 |
83 | public void setUid4(Integer uid4) {
84 | this.uid4 = uid4;
85 | }
86 |
87 | public Integer getUid5() {
88 | return uid5;
89 | }
90 |
91 | public void setUid5(Integer uid5) {
92 | this.uid5 = uid5;
93 | }
94 |
95 | public Integer getUid6() {
96 | return uid6;
97 | }
98 |
99 | public void setUid6(Integer uid6) {
100 | this.uid6 = uid6;
101 | }
102 |
103 | @Override
104 | public String toString() {
105 | return "Member{" +
106 | "iid=" + iid +
107 | ", uid1=" + uid1 +
108 | ", uid2=" + uid2 +
109 | ", uid3=" + uid3 +
110 | ", uid4=" + uid4 +
111 | ", uid5=" + uid5 +
112 | ", uid6=" + uid6 +
113 | '}';
114 | }
115 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/dao/common/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.dao.common;
2 |
3 | import com.yiyexy.model.common.User;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created on 2017/5/7.
11 | *
12 | * @author stormma
13 | *
14 | * @description: 用户 dao 层接口
15 | */
16 | @Mapper
17 | public interface UserDao {
18 |
19 |
20 | /**
21 | * 根据手机号和密码查询用户
22 | * @param user
23 | * @return
24 | */
25 | User getUser(@Param("user") User user);
26 |
27 | /**
28 | * 插入新用户
29 | * @param user
30 | */
31 | void insertUser(@Param("user") User user);
32 |
33 | /**
34 | * 判断用户名是否存在
35 | * @param userName
36 | * @return
37 | */
38 | int isExistUserName(@Param("userName") String userName);
39 |
40 | /**
41 | * 判断手机号码是否存在
42 | * @param mobile
43 | * @return
44 | */
45 | int isExistMobile(@Param("mobile") String mobile);
46 |
47 | /**
48 | * 根据手机号码修改用户名
49 | * @param user
50 | */
51 | void updateUserName(@Param("user") User user);
52 |
53 | /**
54 | * 根据手机号码修改用户密码
55 | * @param user
56 | */
57 | void updatePassword(@Param("user") User user);
58 |
59 | /**
60 | * 根据手机号码修改用户qq信息
61 | * @param user
62 | */
63 | void updateQQ(@Param("user") User user);
64 |
65 | /**
66 | * 根据用户的手机号码查询用户的修改密码次数
67 | * @param mobile
68 | * @return
69 | */
70 | Integer getUpdatePwdCount(@Param("mobile") String mobile);
71 |
72 | /**
73 | * 根据用户id获得用户信息
74 | * @param uid
75 | * @return
76 | */
77 | User getUserById(@Param("uid") Integer uid);
78 |
79 | /**
80 | * 根据 mobile 和 password 获得 uid
81 | * @param user
82 | * @return
83 | */
84 | Integer getUidByMobileAndPassword(@Param(("user"))User user);
85 |
86 | /**
87 | * 根据拼车信息 id 查询已加入用户的信息
88 | * @param iid
89 | * @return
90 | */
91 | List getUserByIid(@Param("iid") int iid);
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/resolvers/CurrentUserMethodArgumentResolver.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.resolvers;
2 |
3 | import com.yiyexy.annotation.CurrentUser;
4 | import com.yiyexy.constant.TokenConstant;
5 | import com.yiyexy.dao.common.UserDao;
6 | import com.yiyexy.model.common.User;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.core.MethodParameter;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.web.bind.support.WebDataBinderFactory;
11 | import org.springframework.web.context.request.NativeWebRequest;
12 | import org.springframework.web.context.request.RequestAttributes;
13 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
14 | import org.springframework.web.method.support.ModelAndViewContainer;
15 | import org.springframework.web.multipart.support.MissingServletRequestPartException;
16 |
17 | /**
18 | * Create on 2017/5/7
19 | *
20 | * @author stormma
21 | *
22 | * @description: 增加方法注入,将含有CurrentUser注解的方法参数注入当前登录用户
23 | */
24 | @Component
25 | public class CurrentUserMethodArgumentResolver implements HandlerMethodArgumentResolver {
26 |
27 | @Autowired
28 | private UserDao userDao;
29 |
30 | @Override
31 | public boolean supportsParameter(MethodParameter parameter) {
32 | //如果参数类型是User并且有CurrentUser注解则支持
33 | if (parameter.getParameterType().isAssignableFrom(User.class) &&
34 | parameter.hasParameterAnnotation(CurrentUser.class)) {
35 | return true;
36 | }
37 | return false;
38 | }
39 |
40 | @Override
41 | public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
42 | //取出鉴权时存入的登录用户Id
43 | Integer currentUserId = (Integer) webRequest.getAttribute(TokenConstant.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
44 | if (currentUserId != null) {
45 | //从数据库中查询并返回
46 | return userDao.getUserById(currentUserId);
47 | }
48 | throw new MissingServletRequestPartException(TokenConstant.CURRENT_USER_ID);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/MessageConfig.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * Created on 2017/5/8.
8 | *
9 | * @author stormma
10 | *
11 | * @description: 短信验证码配置类
12 | */
13 | @Component
14 | @ConfigurationProperties(locations = {"classpath:config/message.properties"}, prefix = "message")
15 | public class MessageConfig {
16 |
17 | /**
18 | * url
19 | */
20 | private String url;
21 |
22 | /**
23 | * userName
24 | */
25 | private String username;
26 |
27 | /**
28 | * password
29 | */
30 | private String password;
31 |
32 | /**
33 | * 是否返回结果码
34 | */
35 | private String rd;
36 |
37 | /**
38 | * 验证码位数
39 | */
40 | private int validateCodeCount;
41 |
42 | public String getUrl() {
43 | return url;
44 | }
45 |
46 | public void setUrl(String url) {
47 | this.url = url;
48 | }
49 |
50 | public String getUsername() {
51 | return username;
52 | }
53 |
54 | public void setUsername(String username) {
55 | this.username = username;
56 | }
57 |
58 | public String getPassword() {
59 | return password;
60 | }
61 |
62 | public void setPassword(String password) {
63 | this.password = password;
64 | }
65 |
66 | public String getRd() {
67 | return rd;
68 | }
69 |
70 | public void setRd(String rd) {
71 | this.rd = rd;
72 | }
73 |
74 | public int getValidateCodeCount() {
75 | return validateCodeCount;
76 | }
77 |
78 | public void setValidateCodeCount(int validateCodeCount) {
79 | this.validateCodeCount = validateCodeCount;
80 | }
81 |
82 | @Override
83 | public String toString() {
84 | return "MessageConfig{" +
85 | "url='" + url + '\'' +
86 | ", username='" + username + '\'' +
87 | ", password='" + password + '\'' +
88 | ", rd='" + rd + '\'' +
89 | ", VALIDATE_CODE_COUNT=" + validateCodeCount +
90 | '}';
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/sender/MessageSender.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.sender;
2 |
3 | import org.apache.commons.httpclient.*;
4 | import org.apache.commons.httpclient.methods.GetMethod;
5 | import org.apache.commons.httpclient.params.HttpClientParams;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.io.ByteArrayOutputStream;
9 | import java.io.InputStream;
10 | import java.net.URLDecoder;
11 |
12 | /**
13 | * Created on 2017/5/8.
14 | *
15 | * @author stormma
16 | * @description: 短信验证码发送器
17 | */
18 | @Component
19 | public class MessageSender {
20 |
21 | public static String batchSend(String url, String un, String pw, String phone, String msg,
22 | String rd, String ex) throws Exception {
23 | HttpClient client = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
24 | GetMethod method = new GetMethod();
25 | try {
26 | URI base = new URI(url, false);
27 | method.setURI(new URI(base, "send", false));
28 | method.setQueryString(new NameValuePair[]{
29 | new NameValuePair("un", un),
30 | new NameValuePair("pw", pw),
31 | new NameValuePair("phone", phone),
32 | new NameValuePair("rd", rd),
33 | new NameValuePair("msg", msg),
34 | new NameValuePair("ex", ex),
35 | });
36 | int result = client.executeMethod(method);
37 | if (result == HttpStatus.SC_OK) {
38 | InputStream in = method.getResponseBodyAsStream();
39 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
40 | byte[] buffer = new byte[1024];
41 | int len = 0;
42 | while ((len = in.read(buffer)) != -1) {
43 | baos.write(buffer, 0, len);
44 | }
45 | return URLDecoder.decode(baos.toString(), "UTF-8");
46 | } else {
47 | throw new Exception("HTTP ERROR Status: " + method.getStatusCode() + ":" + method.getStatusText());
48 | }
49 | } finally {
50 | method.releaseConnection();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/model/car/BusTicketInfo.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.model.car;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Create on 2017/05/07
7 | *
8 | * @author stormma
9 | *
10 | * @description: 用户购买大巴模板类
11 | */
12 | public class BusTicketInfo {
13 |
14 | /**
15 | * uid
16 | */
17 | private int uid;
18 |
19 | /**
20 | * 姓名
21 | */
22 | private String name;
23 |
24 | /**
25 | * 地址
26 | */
27 | private String address;
28 |
29 | /**
30 | * 购票数目
31 | */
32 | private int amount;
33 |
34 | /**
35 | * 出发日期
36 | */
37 | private Date startDate;
38 |
39 | /**
40 | * 出发时间
41 | */
42 | private String startTime;
43 |
44 | /**
45 | * 目的地
46 | */
47 | private String arrive;
48 |
49 | public int getUid() {
50 | return uid;
51 | }
52 |
53 | public void setUid(int uid) {
54 | this.uid = uid;
55 | }
56 |
57 | public String getName() {
58 | return name;
59 | }
60 |
61 | public void setName(String name) {
62 | this.name = name;
63 | }
64 |
65 | public String getAddress() {
66 | return address;
67 | }
68 |
69 | public void setAddress(String address) {
70 | this.address = address;
71 | }
72 |
73 | public int getAmount() {
74 | return amount;
75 | }
76 |
77 | public void setAmount(int amount) {
78 | this.amount = amount;
79 | }
80 |
81 | public Date getStartDate() {
82 | return startDate;
83 | }
84 |
85 | public void setStartDate(Date startDate) {
86 | this.startDate = startDate;
87 | }
88 |
89 | public String getStartTime() {
90 | return startTime;
91 | }
92 |
93 | public void setStartTime(String startTime) {
94 | this.startTime = startTime;
95 | }
96 |
97 | public String getArrive() {
98 | return arrive;
99 | }
100 |
101 | public void setArrive(String arrive) {
102 | this.arrive = arrive;
103 | }
104 |
105 | @Override
106 | public String toString() {
107 | return "BusTicketInfo{" +
108 | "uid=" + uid +
109 | ", name='" + name + '\'' +
110 | ", address='" + address + '\'' +
111 | ", amount=" + amount +
112 | ", startDate=" + startDate +
113 | ", startTime='" + startTime + '\'' +
114 | ", arrive='" + arrive + '\'' +
115 | '}';
116 | }
117 | }
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/config/MyBatisConfig.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.config;
2 |
3 | import org.apache.ibatis.session.SqlSessionFactory;
4 | import org.mybatis.spring.SqlSessionFactoryBean;
5 | import org.mybatis.spring.SqlSessionTemplate;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
12 | import org.springframework.core.io.support.ResourcePatternResolver;
13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
14 | import org.springframework.transaction.PlatformTransactionManager;
15 | import org.springframework.transaction.annotation.EnableTransactionManagement;
16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer;
17 |
18 | import javax.sql.DataSource;
19 |
20 |
21 | /**
22 | * Created on 2017/5/7
23 | *
24 | * @author stormma
25 | *
26 | * @Description: Mybatis的配置类
27 | */
28 | @Configuration
29 | @EnableTransactionManagement
30 | public class MyBatisConfig implements TransactionManagementConfigurer {
31 |
32 | @Autowired
33 | private DataSource dataSource;
34 |
35 | private static final Logger logger = LoggerFactory.getLogger(MyBatisConfig.class);
36 | @Bean(name = "sqlSessionFactory")
37 | public SqlSessionFactory sqlSessionFactoryBean() {
38 | SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
39 | sqlSessionFactory.setDataSource(dataSource);
40 | try {
41 | ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
42 | sqlSessionFactory.setMapperLocations(resolver.getResources("classpath*:mapper/**/*Mapper.xml"));
43 | return sqlSessionFactory.getObject();
44 | } catch (Exception e) {
45 | logger.error("初始化sqlSessionFactory失败,失败信息{}", e);
46 | throw new RuntimeException(e);
47 | }
48 | }
49 |
50 | @Bean
51 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
52 | return new SqlSessionTemplate(sqlSessionFactory);
53 | }
54 |
55 | @Bean
56 | @Override
57 | public PlatformTransactionManager annotationDrivenTransactionManager() {
58 | return new DataSourceTransactionManager(dataSource);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/yiyexy/controller/common/ValidateController.java:
--------------------------------------------------------------------------------
1 | package com.yiyexy.controller.common;
2 |
3 | import com.yiyexy.constant.CommonConstant;
4 | import com.yiyexy.constant.UserConstant;
5 | import com.yiyexy.constant.ValidateConstant;
6 | import com.yiyexy.service.common.IUserService;
7 | import com.yiyexy.util.ObjectUtil;
8 | import com.yiyexy.util.result.Result;
9 | import com.yiyexy.util.result.ResultBuilder;
10 | import io.swagger.annotations.Api;
11 | import io.swagger.annotations.ApiImplicitParam;
12 | import io.swagger.annotations.ApiImplicitParams;
13 | import io.swagger.annotations.ApiOperation;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.web.bind.annotation.GetMapping;
16 | import org.springframework.web.bind.annotation.PathVariable;
17 | import org.springframework.web.bind.annotation.RequestMapping;
18 | import org.springframework.web.bind.annotation.RestController;
19 |
20 | import java.util.Map;
21 |
22 | /**
23 | * _____ _ ___ ___
24 | * / ___| | | \/ |
25 | * \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _
26 | * `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` |
27 | * /\__/ / || (_) | | | | | | | | | | | (_| |
28 | * \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_| 我想念你,一如独自撸码的忧伤...
29 | *
30 | *
Created on 2017/5/9.
31 | *
32 | * @author stormma
33 | * @description: 验证码服务类
34 | */
35 | @Api(value = "/api/validate", description = ValidateConstant.VALIDATE_CONTROLLER_DESC)
36 | @RestController
37 | @RequestMapping("/api/validate")
38 | public class ValidateController extends BaseController {
39 |
40 | @Autowired
41 | private IUserService userService;
42 |
43 | /**
44 | * 发送验证码
45 | *
46 | * @param mobile
47 | * @return
48 | */
49 | @ApiOperation(value = ValidateConstant.VALIDATE_SEND_METHOD_DESC, httpMethod = "GET")
50 | @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = UserConstant.MOBILE_DESC, paramType = "path", required = true),
51 | @ApiImplicitParam(name = "type", value = CommonConstant.VALIDATE_TYPE_DESC, paramType = "path", required = true)})
52 | @GetMapping(value = "/code/{type}/{mobile}")
53 | public Result