├── 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 sendValidateCode(@PathVariable String mobile, 54 | @PathVariable int type) { 55 | //发送验证码 56 | Map datas = userService.sendValidateCode(mobile, type); 57 | //发送成功 58 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.SUCCESS))) { 59 | return ResultBuilder.success(); 60 | } else { 61 | return ResultBuilder.fail(datas.get(CommonConstant.FAIL)); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/manager/impl/RedisTokenManager.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.manager.impl; 2 | 3 | import com.yiyexy.constant.TokenConstant; 4 | import com.yiyexy.manager.TokenManager; 5 | import com.yiyexy.model.common.TokenModel; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.UUID; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | /** 15 | * 通过Redis存储和验证token的实现类 16 | * @author ScienJus 17 | * @date 2015/7/31. 18 | */ 19 | @Component 20 | public class RedisTokenManager implements TokenManager { 21 | 22 | private RedisTemplate redisTemplate; 23 | 24 | @Autowired 25 | private void setRedisTemplate(RedisTemplate redisTemplate) { 26 | this.redisTemplate = redisTemplate; 27 | redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer()); 28 | } 29 | /** 30 | * 创建 token 31 | * @param userId 32 | * @return 33 | */ 34 | @Override 35 | public TokenModel createToken(Integer userId) { 36 | String token = UUID.randomUUID().toString().replace("-", ""); 37 | TokenModel model = new TokenModel(userId, token); 38 | redisTemplate.boundValueOps(userId).set(token, TokenConstant.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS); 39 | return model; 40 | } 41 | 42 | /** 43 | * 获取 token 44 | * @param authentication 加密后的字符串 45 | * @return 46 | */ 47 | @Override 48 | public TokenModel getToken(String authentication) { 49 | if (authentication == null || authentication.length() == 0) { 50 | return null; 51 | } 52 | String[] param = authentication.split("_"); 53 | if (param.length != 2) { 54 | return null; 55 | } 56 | //使用userId和源token简单拼接成的token,可以增加加密措施 57 | Integer userId = Integer.parseInt(param[0]); 58 | String token = param[1]; 59 | return new TokenModel(userId, token); 60 | } 61 | 62 | /** 63 | * 检查 token 的有效性 64 | * @param model token 65 | * @return 66 | */ 67 | @Override 68 | public boolean checkToken(TokenModel model) { 69 | if (model == null) { 70 | return false; 71 | } 72 | String token = redisTemplate.boundValueOps(model.getUid()).get(); 73 | if (token == null || !token.trim().equals(model.getToken().trim())) { 74 | return false; 75 | } 76 | //如果验证成功,说明此用户进行了一次有效操作,延长token的过期时间 77 | redisTemplate.boundValueOps(model.getUid()).expire(TokenConstant.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS); 78 | return true; 79 | } 80 | 81 | /** 82 | * 删除用户的 token 信息 83 | * @param userId 登录用户的id 84 | */ 85 | @Override 86 | public void deleteToken(Integer userId) { 87 | redisTemplate.delete(userId); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/com/yiyexy/dao/car/CarInformationDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.dao.car; 2 | 3 | import com.yiyexy.model.car.CarInformation; 4 | import com.yiyexy.util.NumUtil; 5 | import com.yiyexy.util.log.MyLogger; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.slf4j.Logger; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | import java.text.ParseException; 14 | import java.text.SimpleDateFormat; 15 | import java.util.Date; 16 | import java.util.List; 17 | 18 | /** 19 | *

Created on 2017/5/8.

20 | * 21 | * @author stormma 22 | * 23 | * @description: 拼车信息 dao 层测试 24 | */ 25 | @RunWith(SpringRunner.class) 26 | @SpringBootTest 27 | public class CarInformationDaoTest { 28 | 29 | @Autowired 30 | private CarInformationDao carInformationDao; 31 | 32 | private static Logger LOGGER = MyLogger.getLogger(CarInformationDaoTest.class); 33 | 34 | @Test 35 | public void testInsertCarInformation() { 36 | 37 | CarInformation carInformation = new CarInformation(); 38 | carInformation.setUid(55); 39 | carInformation.setStartDate(new Date()); 40 | carInformation.setStartPos("我爱你"); 41 | carInformation.setArrivePos("你爱我"); 42 | carInformation.setCurtMember(2); 43 | carInformation.setMaxMember(6); 44 | carInformation.setMessage("一辈子"); 45 | carInformation.setPubTime(new Date()); 46 | carInformation.setStartTimeMinHour(NumUtil.numToString(12)); 47 | carInformation.setStartTimeMinMin(NumUtil.numToString(12)); 48 | carInformation.setStartTimeMaxHour(NumUtil.numToString(18)); 49 | carInformation.setStartTimeMaxMin(NumUtil.numToString(23)); 50 | carInformationDao.insertCarInformation(carInformation); 51 | 52 | LOGGER.info("测试结果:{}", carInformation.getIid()); 53 | } 54 | 55 | @Test 56 | public void testGetCarInformation() { 57 | CarInformation carInformation = carInformationDao.getCarInformation(293); 58 | 59 | LOGGER.info("测试结果:{}", carInformation); 60 | } 61 | 62 | @Test 63 | public void testGetAllCarInformation() { 64 | 65 | List carInformations = carInformationDao.getAllCarInformation(); 66 | 67 | LOGGER.info("测试结果:{}", carInformations); 68 | } 69 | 70 | @Test 71 | public void testGetCarInformationsByPubTime() { 72 | 73 | List carInformations = carInformationDao.getCarInformationsByPubTime(new Date()); 74 | 75 | LOGGER.info("测试结果:{}", carInformations); 76 | } 77 | 78 | @Test 79 | public void testGetAllCarInformationByUser() { 80 | 81 | int uid = 55; 82 | 83 | List carInformations = carInformationDao.getAllCarInfomationByUser(uid); 84 | 85 | LOGGER.info("测试结果:{}", carInformations); 86 | } 87 | 88 | @Test 89 | public void testGetCarInformationsByStartDate() throws ParseException { 90 | 91 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 92 | List carInformations = carInformationDao.getCarInformationsByStartDate(simpleDateFormat.parse("2017-05-08")); 93 | LOGGER.info("测试结果:{}", carInformations); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/controller/car/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.controller.car; 2 | 3 | 4 | import com.yiyexy.annotation.*; 5 | import com.yiyexy.constant.CarInformationConstant; 6 | import com.yiyexy.constant.CommonConstant; 7 | import com.yiyexy.constant.IndexConstant; 8 | import com.yiyexy.constant.UserConstant; 9 | import com.yiyexy.controller.common.BaseController; 10 | import com.yiyexy.model.car.CarInformation; 11 | import com.yiyexy.model.common.User; 12 | import com.yiyexy.service.car.impl.CarInformationService; 13 | import com.yiyexy.util.ObjectUtil; 14 | import com.yiyexy.util.result.Result; 15 | import com.yiyexy.util.result.ResultBuilder; 16 | import io.swagger.annotations.*; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.web.bind.annotation.*; 19 | import springfox.documentation.annotations.ApiIgnore; 20 | 21 | import java.util.Date; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * _____ _ ___ ___ 27 | * / ___| | | \/ | 28 | * \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _ 29 | * `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` | 30 | * /\__/ / || (_) | | | | | | | | | | | (_| | 31 | * \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_| 我想念你,一如独自撸码的忧伤...., 重构代码就像是再婚,看到那个恶心的自己和恶心的对方,依旧是恶心的心情. 32 | *

Created on 2017/5/9.

33 | * 34 | * @author stormma 35 | * @description: 拼车主页控制器类 36 | */ 37 | @Api(value = "/api/index", description = IndexConstant.INDEX_CONTROLLER_DESC) 38 | @RequestMapping(value = "/api/index") 39 | @RestController 40 | public class IndexController extends BaseController { 41 | 42 | @Autowired 43 | private CarInformationService carInformationService; 44 | 45 | /** 46 | * 根据开始日期查询所有的拼车信息 47 | * @param startDate 48 | * @return 49 | */ 50 | @ApiOperation(value = IndexConstant.INDEX_METHOD_DESC, httpMethod = "GET") 51 | @ApiImplicitParams({@ApiImplicitParam(name = "startDate", value = CarInformationConstant.START_DATE_DESC, required = true, paramType = "path")}) 52 | @GetMapping("/{startDate}") 53 | public Result> handleIndexData(@PathVariable Date startDate) { 54 | 55 | List carInformations; 56 | carInformations = carInformationService.getCarInformationsByStartDate(startDate); 57 | return ResultBuilder.success(carInformations); 58 | } 59 | 60 | /** 61 | * 发起拼车 62 | * @param carInformation 63 | * @param loginUser 64 | * @return 65 | */ 66 | @com.yiyexy.annotation.Authorization 67 | @ApiOperation(value = CarInformationConstant.ADD_CAR_INFORMATION_METHOD_DESC, httpMethod = "POST") 68 | @ApiImplicitParams({@ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true, paramType = "header")}) 69 | @PostMapping(value = "/create/stroke") 70 | public Result createStroke(@RequestBody CarInformation carInformation, @ApiIgnore @CurrentUser User loginUser) { 71 | 72 | carInformation.setUid(loginUser.getUid()); 73 | Map datas = carInformationService.createStroke(carInformation); 74 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.SUCCESS))) { 75 | return ResultBuilder.success(datas.get(CommonConstant.SUCCESS)); 76 | } else { 77 | return ResultBuilder.fail(datas.get(CommonConstant.FAIL)); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.yiyexy 7 | yiyexy 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | yiyexy 12 | yiyexy 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-aop 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-data-redis 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 1.3.0 40 | 41 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-web 48 | 49 | 50 | 51 | mysql 52 | mysql-connector-java 53 | runtime 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-test 58 | test 59 | 60 | 61 | 62 | io.springfox 63 | springfox-swagger2 64 | 2.6.1 65 | 66 | 67 | io.springfox 68 | springfox-swagger-ui 69 | 2.6.1 70 | 71 | 72 | 73 | com.aliyun.oss 74 | aliyun-sdk-oss 75 | 2.5.0 76 | 77 | 78 | 79 | com.alibaba 80 | druid 81 | 1.0.5 82 | 83 | 84 | 85 | 86 | 87 | commons-httpclient 88 | commons-httpclient 89 | 3.1 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.springframework.boot 97 | spring-boot-maven-plugin 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/test/java/com/yiyexy/dao/car/UserDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.dao.car; 2 | 3 | import com.yiyexy.dao.common.UserDao; 4 | import com.yiyexy.model.common.User; 5 | import com.yiyexy.util.EncryptionUtil; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | *

Created on 2017/5/7.

18 | * 19 | * @author stormma 20 | * 21 | * @description:

用户dao层接口测试用例

22 | */ 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | public class UserDaoTest { 26 | 27 | @Autowired 28 | private UserDao userDao; 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(UserDaoTest.class); 31 | 32 | @Test 33 | public void testGetUser() { 34 | 35 | User user = new User(); 36 | 37 | user. setMobile("18292817803"); 38 | user.setPassword(EncryptionUtil.md5Encryption("StormMa")); 39 | 40 | User result = userDao.getUser(user); 41 | 42 | LOGGER.info("测试结果:{}", result); 43 | } 44 | 45 | @Test 46 | public void testInsertUser() { 47 | 48 | User user = new User(); 49 | 50 | user.setMobile("18292817801"); 51 | user.setPassword(EncryptionUtil.md5Encryption("woaini")); 52 | 53 | userDao.insertUser(user); 54 | LOGGER.info("插入用户的id:{}", user.getUid()); 55 | } 56 | 57 | @Test 58 | public void testIsExistUserName() { 59 | 60 | String userName = "StormMaybin"; 61 | 62 | int result = userDao.isExistUserName(userName); 63 | 64 | LOGGER.info("测试结果:{}", result); 65 | } 66 | 67 | @Test 68 | public void testIsExistMobile() { 69 | 70 | String mobile = "18292817803"; 71 | 72 | int result = userDao.isExistMobile(mobile); 73 | 74 | LOGGER.info("测试结果:{}", result); 75 | } 76 | 77 | @Test 78 | public void testUpdateUserName() { 79 | 80 | User user = new User(); 81 | user.setUserName("StormMa"); 82 | user.setMobile("18292817803"); 83 | 84 | userDao.updateUserName(user); 85 | 86 | LOGGER.info("测试成功"); 87 | } 88 | 89 | @Test 90 | public void testUpdatePassword() { 91 | 92 | User user = new User(); 93 | user.setMobile("18292817803"); 94 | user.setPassword(EncryptionUtil.md5Encryption("StormMa")); 95 | 96 | userDao.updatePassword(user); 97 | 98 | LOGGER.info("测试成功"); 99 | } 100 | 101 | @Test 102 | public void testUpdateQQ() { 103 | 104 | User user = new User(); 105 | 106 | user.setQq("1325338799"); 107 | user.setMobile("18292817803"); 108 | 109 | userDao.updateQQ(user); 110 | 111 | LOGGER.info("测试成功"); 112 | } 113 | 114 | @Test 115 | public void testGetUpdatePwdCount() { 116 | 117 | String mobile = "18292817803"; 118 | 119 | Integer result = userDao.getUpdatePwdCount(mobile); 120 | 121 | LOGGER.info("测试结果:{}", result); 122 | } 123 | 124 | @Test 125 | public void testGetUserByIid() { 126 | 127 | int iid = 293; 128 | 129 | List users = userDao.getUserByIid(iid); 130 | 131 | LOGGER.info("测试结果:{}", users); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/resources/mapper/car/MemberMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | UPDATE 19 | member 20 | SET 21 | id2 = #{member.uid2} 22 | WHERE 23 | main_id = #{member.iid}; 24 | 25 | 26 | UPDATE 27 | member 28 | SET 29 | id3 = #{member.uid3} 30 | WHERE 31 | main_id = #{member.iid}; 32 | 33 | 34 | UPDATE 35 | member 36 | SET 37 | id4 = #{member.uid4} 38 | WHERE 39 | main_id = #{member.iid}; 40 | 41 | 42 | UPDATE 43 | member 44 | SET 45 | id5 = #{member.uid5} 46 | WHERE 47 | main_id = #{member.iid}; 48 | 49 | 50 | UPDATE 51 | member 52 | SET 53 | id6 = #{member.uid6} 54 | WHERE 55 | main_id = #{member.iid}; 56 | 57 | 58 | 59 | 60 | 68 | 69 | 70 | 71 | 72 | DELETE 73 | FROM 74 | member 75 | WHERE 76 | main_id = #{member.iid}; 77 | 78 | 79 | UPDATE 80 | member 81 | SET 82 | id2 = 0 83 | WHERE 84 | main_id = #{member.iid}; 85 | 86 | 87 | UPDATE 88 | member 89 | SET 90 | id3 = 0 91 | WHERE 92 | main_id = #{member.iid}; 93 | 94 | 95 | UPDATE 96 | member 97 | SET 98 | id4 = 0 99 | WHERE 100 | main_id = #{member.iid}; 101 | 102 | 103 | UPDATE 104 | member 105 | SET 106 | id5 = 0 107 | WHERE 108 | main_id = #{member.iid}; 109 | 110 | 111 | UPDATE 112 | member 113 | SET 114 | id6 = 0 115 | WHERE 116 | main_id = #{member.iid}; 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/service/car/impl/CarInformationService.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.service.car.impl; 2 | 3 | import com.yiyexy.constant.CarInformationConstant; 4 | import com.yiyexy.constant.CommonConstant; 5 | import com.yiyexy.constant.MemberConstant; 6 | import com.yiyexy.dao.car.CarInformationDao; 7 | import com.yiyexy.model.car.CarInformation; 8 | import com.yiyexy.service.car.ICarInformationService; 9 | import com.yiyexy.util.DateUtils; 10 | import com.yiyexy.util.ObjectUtil; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.util.StringUtils; 14 | 15 | import java.util.Date; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | /** 21 | *

Created on 2017/5/9.

22 | * 23 | * @author stormma 24 | * 25 | * @description: 拼车信息的服务实现 26 | */ 27 | @Service 28 | public class CarInformationService implements ICarInformationService { 29 | 30 | @Autowired 31 | private CarInformationDao carInformationDao; 32 | 33 | /** 34 | * 添加一个行程信息 35 | * @param carInformation 36 | * @return 主键 37 | */ 38 | @Override 39 | public int addCarInformation(CarInformation carInformation) { 40 | carInformationDao.insertCarInformation(carInformation); 41 | return carInformation.getIid(); 42 | } 43 | 44 | /** 45 | * 根据发布日期查询拼车信息 46 | * @param pubTime 47 | * @return 发布日期为pubTime的所有行程信息 48 | */ 49 | @Override 50 | public List getCarInformationsByPubTime(Date pubTime) { 51 | return carInformationDao.getCarInformationsByPubTime(pubTime); 52 | } 53 | 54 | /** 55 | * 根据开始日期查询所有的行程信息 56 | * @param startDate 57 | * @return 58 | */ 59 | @Override 60 | public List getCarInformationsByStartDate(Date startDate) { 61 | return carInformationDao.getCarInformationsByStartDate(startDate); 62 | } 63 | 64 | /** 65 | * 根据用户查询用户所参加或者发起的拼车信息 66 | * 67 | * @param uid 68 | * @return 69 | */ 70 | @Override 71 | public List getUserSignedUpCarInformation(int uid) { 72 | return carInformationDao.getAllCarInfomationByUser(uid); 73 | } 74 | 75 | /** 76 | * 发布拼车信息 77 | * @param carInformation 78 | * @return 79 | */ 80 | @Override 81 | public Map createStroke(CarInformation carInformation) { 82 | Map datas = new HashMap<>(); 83 | carInformation.setPubTime(new Date()); 84 | //先查询已有的拼车信息 85 | List carInformations = carInformationDao.getAllCarInfomationByUser(carInformation.getUid()); 86 | Date startDate = carInformation.getStartDate(); 87 | String startPos = carInformation.getStartPos(); 88 | if (ObjectUtil.isEmpty(startDate) || StringUtils.isEmpty(startPos)) { 89 | datas.put(CommonConstant.FAIL, CommonConstant.PARAM_BIND_FAILED); 90 | } 91 | for (CarInformation information : carInformations) { 92 | //如果出发时间相同 93 | if (DateUtils.getDifferenceDays(information.getStartDate(), startDate) == 0) { 94 | //如果开始地点相同 95 | if (information.getStartPos().equals(startPos)) { 96 | datas.put(CommonConstant.FAIL, MemberConstant.INVAILD_SIGN_UP); 97 | return datas; 98 | } 99 | } 100 | } 101 | 102 | //可以发布拼车信息 103 | carInformationDao.insertCarInformation(carInformation); 104 | if (!ObjectUtil.isEmpty(carInformation.getIid())) { 105 | datas.put(CommonConstant.SUCCESS, CommonConstant.SUCCESS); 106 | return datas; 107 | } 108 | datas.put(CommonConstant.FAIL, CarInformationConstant.CREATE_STROKE_FAILED); 109 | return datas; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/model/common/User.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.model.common; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | 7 | /** 8 | *

Created on 2017/5/7.

9 | * 10 | * @author stormma 11 | * 12 | * @description:

user model of yiyexy

13 | */ 14 | public class User { 15 | 16 | /** 17 | * user id 18 | */ 19 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 20 | private Integer uid; 21 | 22 | /** 23 | * icon 24 | */ 25 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 26 | private String icon; 27 | 28 | /** 29 | * qq num 30 | */ 31 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 32 | private String qq; 33 | 34 | /** 35 | * user name 36 | */ 37 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 38 | private String userName; 39 | 40 | /** 41 | * password 42 | */ 43 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 44 | private String password; 45 | 46 | /** 47 | * mobile 48 | */ 49 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 50 | private String mobile; 51 | 52 | /** 53 | * good apprise 54 | */ 55 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 56 | private Integer goodApprise; 57 | 58 | /** 59 | * bad apprise 60 | */ 61 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 62 | private Integer badApprise; 63 | 64 | /** 65 | * update password count 66 | */ 67 | @JsonIgnore 68 | private Integer updatePwdCount; 69 | 70 | /** 71 | * type 72 | */ 73 | @JsonIgnore 74 | private Integer type; 75 | 76 | public User() { 77 | } 78 | 79 | public User(String password, String mobile) { 80 | this.password = password; 81 | this.mobile = mobile; 82 | } 83 | 84 | public Integer getUid() { 85 | return uid; 86 | } 87 | 88 | public void setUid(Integer uid) { 89 | this.uid = uid; 90 | } 91 | 92 | public String getIcon() { 93 | return icon; 94 | } 95 | 96 | public void setIcon(String icon) { 97 | this.icon = icon; 98 | } 99 | 100 | public String getQq() { 101 | return qq; 102 | } 103 | 104 | public void setQq(String qq) { 105 | this.qq = qq; 106 | } 107 | 108 | public String getUserName() { 109 | return userName; 110 | } 111 | 112 | public void setUserName(String userName) { 113 | this.userName = userName; 114 | } 115 | 116 | public String getPassword() { 117 | return password; 118 | } 119 | 120 | public void setPassword(String password) { 121 | this.password = password; 122 | } 123 | 124 | public String getMobile() { 125 | return mobile; 126 | } 127 | 128 | public void setMobile(String mobile) { 129 | this.mobile = mobile; 130 | } 131 | 132 | public Integer getGoodApprise() { 133 | return goodApprise; 134 | } 135 | 136 | public void setGoodApprise(Integer goodApprise) { 137 | this.goodApprise = goodApprise; 138 | } 139 | 140 | public Integer getBadApprise() { 141 | return badApprise; 142 | } 143 | 144 | public void setBadApprise(Integer badApprise) { 145 | this.badApprise = badApprise; 146 | } 147 | 148 | public Integer getUpdatePwdCount() { 149 | return updatePwdCount; 150 | } 151 | 152 | public void setUpdatePwdCount(Integer updatePwdCount) { 153 | this.updatePwdCount = updatePwdCount; 154 | } 155 | 156 | public Integer getType() { 157 | return type; 158 | } 159 | 160 | public void setType(Integer type) { 161 | this.type = type; 162 | } 163 | 164 | @Override 165 | public String toString() { 166 | return "User{" + 167 | "uid=" + uid + 168 | ", icon='" + icon + '\'' + 169 | ", qq='" + qq + '\'' + 170 | ", userName='" + userName + '\'' + 171 | ", password='" + password + '\'' + 172 | ", mobile='" + mobile + '\'' + 173 | ", goodApprise=" + goodApprise + 174 | ", badApprise=" + badApprise + 175 | ", updatePwdCount=" + updatePwdCount + 176 | ", type=" + type + 177 | '}'; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/main/resources/mapper/car/CarInformationMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | INSERT INTO car_information (uid, start_date, start_pos, arrive_pos, start_time_min_hour, start_time_min_min 28 | , start_time_max_hour, start_time_max_min, max_member, curt_member, message, pub_time) 29 | 30 | VALUES (#{carInfo.uid}, #{carInfo.startDate}, #{carInfo.startPos}, #{carInfo.arrivePos}, #{carInfo.startTimeMinHour} 31 | , #{carInfo.startTimeMinMin}, #{carInfo.startTimeMaxHour}, #{carInfo.startTimeMaxMin}, #{carInfo.maxMember} 32 | , #{carInfo.curtMember}, #{carInfo.message}, #{carInfo.pubTime}); 33 | 34 | 35 | 36 | 37 | 38 | DELETE 39 | FROM 40 | car_information 41 | WHERE 42 | id = #{iid}; 43 | 44 | 45 | 46 | 53 | 54 | 55 | 61 | 62 | 63 | 72 | 73 | 74 | 91 | 92 | 93 | 103 | 104 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/controller/car/MemberController.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.controller.car; 2 | 3 | import com.yiyexy.annotation.Authorization; 4 | import com.yiyexy.annotation.CurrentUser; 5 | import com.yiyexy.constant.CarInformationConstant; 6 | import com.yiyexy.constant.CommonConstant; 7 | import com.yiyexy.constant.MemberConstant; 8 | import com.yiyexy.constant.UserConstant; 9 | import com.yiyexy.controller.common.BaseController; 10 | import com.yiyexy.model.common.User; 11 | import com.yiyexy.service.car.IMemberService; 12 | import com.yiyexy.service.car.impl.CarInformationService; 13 | import com.yiyexy.util.ObjectUtil; 14 | import com.yiyexy.util.result.Result; 15 | import com.yiyexy.util.result.ResultBuilder; 16 | import io.swagger.annotations.Api; 17 | import io.swagger.annotations.ApiImplicitParam; 18 | import io.swagger.annotations.ApiImplicitParams; 19 | import io.swagger.annotations.ApiOperation; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.web.bind.annotation.*; 22 | import springfox.documentation.annotations.ApiIgnore; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * _____ _ ___ ___ 29 | * / ___| | | \/ | 30 | * \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _ 31 | * `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` | 32 | * /\__/ / || (_) | | | | | | | | | | | (_| | 33 | * \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_| 我想念你,一如独自撸码的忧伤.... 34 | * 凌晨12点43分,此刻我在异乡的床上,抱着电脑,写着自己的代码,我很享受这种感觉,但是我更想你。 35 | *

Created on 2017/5/10.

36 | * 37 | * @author stormma 38 | * @description: 成员信息控制器类 39 | */ 40 | @Api(value = "/api/member", description = MemberConstant.MEMBER_CONTROLLER_DESC) 41 | @RestController 42 | @RequestMapping("/api/member") 43 | public class MemberController extends BaseController { 44 | 45 | @Autowired 46 | private CarInformationService carInformationService; 47 | 48 | @Autowired 49 | private IMemberService memberService; 50 | 51 | /** 52 | * 获得加入拼车信息的成员信息(此处要登录) 53 | * 54 | * @param iid 55 | * @return 56 | */ 57 | @Authorization 58 | @ApiOperation(value = MemberConstant.GET_MEMBER_METHOD_DESC, httpMethod = "GET") 59 | @ApiImplicitParams({@ApiImplicitParam(name = "iid", value = CarInformationConstant.IID_FIELD_DESC, required = true, paramType = "path"), 60 | @ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true, paramType = "header")}) 61 | @GetMapping("/{iid}") 62 | public Result> getMember(@PathVariable int iid, @ApiIgnore @CurrentUser User loginUser) { 63 | 64 | List users = memberService.getMemberInfos(iid); 65 | 66 | return ResultBuilder.success(users); 67 | } 68 | 69 | 70 | /** 71 | * 加入拼车信息 72 | * @param loginUser 73 | * @param iid 74 | * @return 75 | */ 76 | @Authorization 77 | @ApiOperation(value = MemberConstant.SIGN_UP_CAR_INFORMATION_METHOD_DESC, httpMethod = "PUT") 78 | @ApiImplicitParams({@ApiImplicitParam(name = "iid", value = CarInformationConstant.IID_FIELD_DESC, required = true, paramType = "path"), 79 | @ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true, paramType = "header")}) 80 | @PutMapping(value = "/sign/{iid}") 81 | public Result signInformation(@ApiIgnore @CurrentUser User loginUser, 82 | @PathVariable int iid) { 83 | 84 | int uid = loginUser.getUid(); 85 | Map datas = memberService.addUserToStroke(iid, uid); 86 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.SUCCESS))) { 87 | return ResultBuilder.success(datas.get(CommonConstant.SUCCESS)); 88 | } else { 89 | return ResultBuilder.fail(datas.get(CommonConstant.FAIL)); 90 | } 91 | } 92 | 93 | /** 94 | * 取消拼车行程 95 | * @param loginUser 96 | * @param iid 97 | * @return 98 | */ 99 | @Authorization 100 | @ApiOperation(value = MemberConstant.CANCEL_CAR_INFORMATION_METHOD_DESC, httpMethod = "DELETE") 101 | @ApiImplicitParams({@ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true, paramType = "header"), 102 | @ApiImplicitParam(name = "iid", value = CarInformationConstant.IID_FIELD_DESC, required = true, paramType = "path")}) 103 | @DeleteMapping(value = "/cancel/{iid}") 104 | public Result cancelStroke(@ApiIgnore @CurrentUser User loginUser, 105 | @PathVariable int iid) { 106 | 107 | int uid = loginUser.getUid(); 108 | Map datas = memberService.cancelStroke(iid, uid); 109 | 110 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.SUCCESS))) { 111 | return ResultBuilder.success(datas.get(CommonConstant.SUCCESS)); 112 | } else { 113 | return ResultBuilder.fail(datas.get(CommonConstant.FAIL)); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/resources/mapper/common/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 31 | 32 | 33 | 34 | 35 | INSERT INTO 36 | user (mobile, password) 37 | VALUES (#{user.mobile}, #{user.password}); 38 | 39 | 40 | 41 | 42 | 51 | 52 | 53 | 62 | 63 | 64 | 65 | 66 | UPDATE 67 | user 68 | SET user_name = #{user.userName} 69 | WHERE mobile = #{user.mobile}; 70 | 71 | 72 | 73 | 74 | 75 | 76 | UPDATE 77 | user 78 | SET 79 | password = #{user.password} 80 | WHERE mobile = #{user.mobile}; 81 | 82 | 83 | 84 | 85 | 86 | 87 | UPDATE 88 | user 89 | SET 90 | qq = #{user.qq} 91 | WHERE mobile = #{user.mobile}; 92 | 93 | 94 | 95 | 96 | 105 | 106 | 107 | 116 | 117 | 118 | 127 | 128 | 129 | 143 | 144 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/model/car/CarInformation.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.model.car; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class CarInformation implements Comparable, Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | /** 11 | * 拼车信息 id 12 | */ 13 | private Integer iid; 14 | 15 | /** 16 | * 用户 id 17 | */ 18 | private Integer uid; 19 | 20 | /** 21 | * 开始日期 22 | */ 23 | private Date startDate; 24 | 25 | /** 26 | * 开始地点 27 | */ 28 | private String startPos; 29 | 30 | /** 31 | * 目的地 32 | */ 33 | private String arrivePos; 34 | 35 | /** 36 | * 拼车下限时间小时值ֵ 37 | */ 38 | private String startTimeMinHour; 39 | 40 | /** 41 | * 拼车下限时间分钟值ֵ 42 | */ 43 | private String startTimeMinMin; 44 | 45 | /** 46 | * 拼车上限时间小时值ֵ 47 | */ 48 | private String startTimeMaxHour; 49 | 50 | /** 51 | * 拼车上限时间分钟值ֵ 52 | */ 53 | private String startTimeMaxMin; 54 | 55 | /** 56 | * 拼车最大人数 57 | */ 58 | private int maxMember; 59 | 60 | /** 61 | * 拼车已有人数 62 | */ 63 | private int curtMember; 64 | 65 | /** 66 | * 拼车信息备注 67 | */ 68 | private String message; 69 | 70 | /** 71 | * 拼车发布日期 72 | */ 73 | private Date pubTime; 74 | 75 | public static long getSerialVersionUID() { 76 | return serialVersionUID; 77 | } 78 | 79 | public Integer getIid() { 80 | return iid; 81 | } 82 | 83 | public void setIid(Integer iid) { 84 | this.iid = iid; 85 | } 86 | 87 | public Integer getUid() { 88 | return uid; 89 | } 90 | 91 | public void setUid(Integer uid) { 92 | this.uid = uid; 93 | } 94 | 95 | public Date getStartDate() { 96 | return startDate; 97 | } 98 | 99 | public void setStartDate(Date startDate) { 100 | this.startDate = startDate; 101 | } 102 | 103 | public String getStartPos() { 104 | return startPos; 105 | } 106 | 107 | public void setStartPos(String startPos) { 108 | this.startPos = startPos; 109 | } 110 | 111 | public String getArrivePos() { 112 | return arrivePos; 113 | } 114 | 115 | public void setArrivePos(String arrivePos) { 116 | this.arrivePos = arrivePos; 117 | } 118 | 119 | public String getStartTimeMinHour() { 120 | return startTimeMinHour; 121 | } 122 | 123 | public void setStartTimeMinHour(String startTimeMinHour) { 124 | this.startTimeMinHour = startTimeMinHour; 125 | } 126 | 127 | public String getStartTimeMinMin() { 128 | return startTimeMinMin; 129 | } 130 | 131 | public void setStartTimeMinMin(String startTimeMinMin) { 132 | this.startTimeMinMin = startTimeMinMin; 133 | } 134 | 135 | public String getStartTimeMaxHour() { 136 | return startTimeMaxHour; 137 | } 138 | 139 | public void setStartTimeMaxHour(String startTimeMaxHour) { 140 | this.startTimeMaxHour = startTimeMaxHour; 141 | } 142 | 143 | public String getStartTimeMaxMin() { 144 | return startTimeMaxMin; 145 | } 146 | 147 | public void setStartTimeMaxMin(String startTimeMaxMin) { 148 | this.startTimeMaxMin = startTimeMaxMin; 149 | } 150 | 151 | public int getMaxMember() { 152 | return maxMember; 153 | } 154 | 155 | public void setMaxMember(int maxMember) { 156 | this.maxMember = maxMember; 157 | } 158 | 159 | public int getCurtMember() { 160 | return curtMember; 161 | } 162 | 163 | public void setCurtMember(int curtMember) { 164 | this.curtMember = curtMember; 165 | } 166 | 167 | public String getMessage() { 168 | return message; 169 | } 170 | 171 | public void setMessage(String message) { 172 | this.message = message; 173 | } 174 | 175 | public Date getPubTime() { 176 | return pubTime; 177 | } 178 | 179 | public void setPubTime(Date pubTime) { 180 | this.pubTime = pubTime; 181 | } 182 | 183 | @Override 184 | public String toString() { 185 | return "CarInformation{" + 186 | "iid=" + iid + 187 | ", uid=" + uid + 188 | ", startDate=" + startDate + 189 | ", startPos='" + startPos + '\'' + 190 | ", arrivePos='" + arrivePos + '\'' + 191 | ", startTimeMinHour='" + startTimeMinHour + '\'' + 192 | ", startTimeMinMin='" + startTimeMinMin + '\'' + 193 | ", startTimeMaxHour='" + startTimeMaxHour + '\'' + 194 | ", startTimeMaxMin='" + startTimeMaxMin + '\'' + 195 | ", maxMember=" + maxMember + 196 | ", curtMember=" + curtMember + 197 | ", message='" + message + '\'' + 198 | ", pubTime=" + pubTime + 199 | '}'; 200 | } 201 | 202 | @Override 203 | public int compareTo(CarInformation o) { 204 | if (this.getStartDate().getTime() > o.getStartDate().getTime()) { 205 | return -1; 206 | } else if (this.getStartDate().getTime() < o.getStartDate().getTime()) { 207 | return 1; 208 | } else { 209 | return 0; 210 | } 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/service/common/impl/MessageService.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.service.common.impl; 2 | 3 | import com.yiyexy.annotation.Authorization; 4 | import com.yiyexy.config.MessageConfig; 5 | import com.yiyexy.constant.CommonConstant; 6 | import com.yiyexy.constant.ValidateConstant; 7 | import com.yiyexy.sender.MessageSender; 8 | import com.yiyexy.service.common.IMessageService; 9 | import com.yiyexy.util.ObjectUtil; 10 | import com.yiyexy.util.StringRedisTempldateUtil; 11 | import com.yiyexy.util.ValidateCodeUtil; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.data.redis.core.RedisTemplate; 16 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.util.StringUtils; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | /** 25 | *

Created on 2017/5/8.

26 | * 27 | * @author stormma 28 | * 29 | * @description: 短信验证码服务 30 | */ 31 | @Service 32 | public class MessageService implements IMessageService { 33 | 34 | @Autowired 35 | private MessageConfig messageConfig; 36 | 37 | @Autowired 38 | private MessageSender messageSender; 39 | 40 | @Autowired 41 | private StringRedisTempldateUtil stringRedisTempldateUtil; 42 | 43 | private RedisTemplate redisTemplate; 44 | 45 | private static Logger LOGGER = LoggerFactory.getLogger(MessageService.class); 46 | 47 | @Autowired 48 | private void setRedisTemplate(RedisTemplate redisTemplate) { 49 | this.redisTemplate = redisTemplate; 50 | redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer()); 51 | } 52 | 53 | /** 54 | * 发送验证码服务,前提要判断是否具有权限 55 | * @param mobile 56 | * @return 57 | */ 58 | @Override 59 | public Map sendMessage(String mobile) { 60 | 61 | //发送的内容 62 | String msg = null; 63 | //生成验证码 64 | String validateCode = ValidateCodeUtil.getRandNum(messageConfig.getValidateCodeCount()); 65 | 66 | //格式化发送内容 67 | msg = String.format(CommonConstant.MESSAGE_TEMPLATE, validateCode); 68 | 69 | String returnResult; 70 | try { 71 | returnResult = messageSender.batchSend(messageConfig.getUrl() 72 | , messageConfig.getUsername() 73 | , messageConfig.getPassword() 74 | , mobile 75 | , msg 76 | , messageConfig.getRd() 77 | , null); 78 | 79 | LOGGER.info("返回字符串:{}", returnResult); 80 | Map datas = new HashMap<>(); 81 | //成功时候返回生成的验证码 82 | datas.put(CommonConstant.SUCCESS, validateCode); 83 | return datas; 84 | } catch (Exception e) { 85 | LOGGER.error("{}", e); 86 | Map datas = new HashMap<>(); 87 | datas.put(CommonConstant.FAIL, e.toString()); 88 | return datas; 89 | } 90 | } 91 | 92 | /** 93 | * 判断是否可以发送短信验证码 94 | * @param mobile 95 | * @return 96 | */ 97 | @Override 98 | public boolean isCanSendMessage(String mobile) { 99 | //获得该手机号码一周之内发送的验证码的数目 100 | Integer count = this.getSendValidateCodeCountOneWeek(mobile); 101 | if (ObjectUtil.isEmpty(count)) { 102 | return true; 103 | } else { 104 | return count < CommonConstant.SEND_MAX_VALIDATE_CODE_ONE_WEEK; 105 | } 106 | } 107 | 108 | /** 109 | * 增加发送短信验证码的数目 110 | * @param mobile 111 | */ 112 | @Override 113 | public void increaseSendValidateCodeCount(String mobile) { 114 | Integer count = this.getSendValidateCodeCountOneWeek(mobile); 115 | 116 | String key = this.getRedisKeyForSendValidateCodeCount(mobile); 117 | if (ObjectUtil.isEmpty(count)) { 118 | redisTemplate.boundValueOps(key).set(1, ValidateConstant.VALIDATE_CHECK_DAYS, TimeUnit.DAYS); 119 | } else { 120 | //增加1,继续设置上次的失效时间 121 | redisTemplate.boundValueOps(key).set(count + 1, redisTemplate.boundValueOps(key).getExpire(), TimeUnit.SECONDS); 122 | } 123 | } 124 | 125 | /** 126 | * 获得保存发送验证码数目的key 127 | * @param mobile 128 | * @return 129 | */ 130 | @Override 131 | public String getRedisKeyForSendValidateCodeCount(String mobile) { 132 | return mobile + ValidateConstant.VALIDATE_REDIS_SUFFIX; 133 | } 134 | 135 | /** 136 | * 获得该手机号码一周发送的数目 137 | * @param mobile 138 | * @return 139 | */ 140 | @Override 141 | public Integer getSendValidateCodeCountOneWeek(String mobile) { 142 | 143 | String key = this.getRedisKeyForSendValidateCodeCount(mobile); 144 | return redisTemplate.boundValueOps(key).get(); 145 | } 146 | 147 | /** 148 | * 判断该手机号提交的验证码是否正确 149 | * @param validateCode 150 | * @param mobile 151 | * @return 152 | */ 153 | @Override 154 | public boolean checkValidateIsValid(String validateCode, String mobile) { 155 | 156 | //redis 取出缓存 157 | String originValidateCode = stringRedisTempldateUtil.getStringRedisTempldate().boundValueOps(mobile).get(); 158 | 159 | //如果相等 160 | if (StringUtils.isEmpty(originValidateCode) || !originValidateCode.trim().equals(validateCode.trim())) { 161 | return false; 162 | } 163 | return true; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/service/common/impl/UserService.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.service.common.impl; 2 | 3 | import com.yiyexy.constant.CommonConstant; 4 | import com.yiyexy.constant.DBConstant; 5 | import com.yiyexy.constant.UserConstant; 6 | import com.yiyexy.constant.ValidateConstant; 7 | import com.yiyexy.dao.common.UserDao; 8 | import com.yiyexy.model.common.User; 9 | import com.yiyexy.service.common.IMessageService; 10 | import com.yiyexy.service.common.IUserService; 11 | import com.yiyexy.util.EncryptionUtil; 12 | import com.yiyexy.util.ObjectUtil; 13 | import com.yiyexy.util.RegexpUtil; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.data.redis.core.RedisTemplate; 16 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; 17 | import org.springframework.stereotype.Service; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | /** 24 | *

Created on 2017/5/7.

25 | * 26 | * @author stormma 27 | * 28 | * @description:

用户服务类实现

29 | */ 30 | @Service 31 | public class UserService implements IUserService { 32 | 33 | @Autowired 34 | private UserDao userDao; 35 | 36 | @Autowired 37 | private IMessageService messageService; 38 | 39 | @Autowired 40 | private RedisTemplate redisTemplate; 41 | 42 | @Autowired 43 | private void setRedisTemplate(RedisTemplate redisTemplate) { 44 | this.redisTemplate = redisTemplate; 45 | redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer()); 46 | } 47 | 48 | /** 49 | * 判断是否登录成功 50 | * @param mobile 51 | * @param password 52 | * @return 53 | */ 54 | @Override 55 | public Map isLoginSuccess(String mobile, String password) { 56 | User paramUser = new User(); 57 | paramUser.setMobile(mobile); 58 | paramUser.setPassword(EncryptionUtil.md5Encryption(password)); 59 | Integer uid = userDao.getUidByMobileAndPassword(paramUser); 60 | Map datas = new HashMap<>(); 61 | //登录失败 62 | if (ObjectUtil.isEmpty(uid)) { 63 | int status; 64 | //如果手机号未注册 65 | if (userDao.isExistMobile(mobile) == DBConstant.NO_THIS_RECORD) { 66 | status = UserConstant.NO_THIS_MOBILE; 67 | } else { 68 | status = UserConstant.ERROR_PASSWORD; 69 | } 70 | datas.put(CommonConstant.FAIL, status); 71 | } else { 72 | datas.put(CommonConstant.SUCCESS, uid); 73 | } 74 | return datas; 75 | } 76 | 77 | /** 78 | * 修改密码 79 | * @param mobile 80 | * @param password 81 | * @return 82 | */ 83 | @Override 84 | public boolean updatePassword(String mobile, String password) { 85 | 86 | User paramUser = new User(); 87 | paramUser.setMobile(mobile); 88 | //md5加密 89 | paramUser.setPassword(EncryptionUtil.md5Encryption(password)); 90 | userDao.updatePassword(paramUser); 91 | return true; 92 | } 93 | 94 | /** 95 | * 修改qq 96 | * @param mobile 97 | * @param qq 98 | * @return 99 | */ 100 | @Override 101 | public boolean updateQQNum(String mobile, String qq) { 102 | User paramUser = new User(); 103 | 104 | paramUser.setMobile(mobile); 105 | paramUser.setQq(qq); 106 | userDao.updateQQ(paramUser); 107 | 108 | return true; 109 | } 110 | 111 | /** 112 | * 修改用户名 113 | * @param mobile 114 | * @param userName 115 | * @return 116 | */ 117 | @Override 118 | public String updateUserName(String mobile, String userName) { 119 | User paramUser = new User(); 120 | 121 | paramUser.setMobile(mobile); 122 | paramUser.setUserName(userName); 123 | 124 | int count = userDao.getUpdatePwdCount(mobile); 125 | if (count >= 1) { 126 | return UserConstant.CAN_NOT_UPDATE_USER_NAME; 127 | } 128 | userDao.updateUserName(paramUser); 129 | return CommonConstant.SUCCESS; 130 | } 131 | 132 | /** 133 | * 注册时候发送验证码 134 | * @param moible 135 | * @return 136 | */ 137 | @Override 138 | public Map sendValidateCode(String moible, int type) { 139 | Map datas = new HashMap<>(); 140 | //正则匹配手机号码 141 | if (!RegexpUtil.isMobileNum(moible)) { 142 | datas.put(CommonConstant.FAIL, CommonConstant.INVALID_MOBILE_NUM); 143 | return datas; 144 | } 145 | //如果是注册时候发送验证码,先判断手机号码是否已经注册 146 | if (type == ValidateConstant.REGISTER_VALIDATE_CODE) { 147 | if (userDao.isExistMobile(moible) == DBConstant.HAVE_THIS_RECORD) { 148 | datas.put(CommonConstant.FAIL, ValidateConstant.THIS_MOBILE_ALERDY_REGISTER); 149 | return datas; 150 | } 151 | } 152 | //判断是否可以发送短信 153 | boolean isCanSend = messageService.isCanSendMessage(moible); 154 | if (isCanSend) { 155 | Map result = messageService.sendMessage(moible); 156 | if (!ObjectUtil.isEmpty(result.get(CommonConstant.SUCCESS))) { 157 | //发送成功,保存验证码到 redis 158 | redisTemplate.boundValueOps(moible).set(result.get(CommonConstant.SUCCESS), 159 | ValidateConstant.VALIDATE_CODE_VALID_TIME_MINUNTES, TimeUnit.MINUTES); 160 | datas.put(CommonConstant.SUCCESS, result.get(CommonConstant.SUCCESS)); 161 | //增加发送次数 162 | messageService.increaseSendValidateCodeCount(moible); 163 | } else { 164 | datas.put(CommonConstant.FAIL, ValidateConstant.VALIDATE_SEND_FAIL); 165 | } 166 | } else { 167 | datas.put(CommonConstant.FAIL, ValidateConstant.VALIDATE_SEND_MAX_COUNT_CODE); 168 | } 169 | return datas; 170 | } 171 | 172 | /** 173 | * 注册 174 | * @param mobile 175 | * @param password 176 | * @return 177 | */ 178 | @Override 179 | public Map register(String mobile, String password) { 180 | Map datas = new HashMap<>(); 181 | //判断手机号码是否已经注册 182 | if (userDao.isExistMobile(mobile) == DBConstant.HAVE_THIS_RECORD) { 183 | datas.put(CommonConstant.FAIL, ValidateConstant.THIS_MOBILE_ALERDY_REGISTER); 184 | return datas; 185 | } 186 | userDao.insertUser(new User(password, mobile)); 187 | datas.put(CommonConstant.SUCCESS, CommonConstant.SUCCESS); 188 | return datas; 189 | } 190 | 191 | /** 192 | * 获得用户信息 193 | * @param uid 194 | * @return 195 | */ 196 | @Override 197 | public User getUserInfo(Integer uid) { 198 | return userDao.getUserById(uid); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/service/car/impl/MemberService.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.service.car.impl; 2 | 3 | import com.yiyexy.constant.CarInformationConstant; 4 | import com.yiyexy.constant.CommonConstant; 5 | import com.yiyexy.constant.MemberConstant; 6 | import com.yiyexy.dao.car.CarInformationDao; 7 | import com.yiyexy.dao.car.MemberDao; 8 | import com.yiyexy.dao.common.UserDao; 9 | import com.yiyexy.model.car.CarInformation; 10 | import com.yiyexy.model.car.Member; 11 | import com.yiyexy.model.common.User; 12 | import com.yiyexy.service.car.ICarInformationService; 13 | import com.yiyexy.service.car.IMemberService; 14 | import com.yiyexy.util.DateUtils; 15 | import com.yiyexy.util.ObjectUtil; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.transaction.annotation.Transactional; 19 | import org.springframework.util.CollectionUtils; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | *

Created on 2017/5/9.

25 | * 26 | * @author stormma 27 | * 28 | * @description: 成员服务实现类 29 | */ 30 | @Service 31 | public class MemberService implements IMemberService { 32 | 33 | @Autowired 34 | private MemberDao memberDao; 35 | 36 | @Autowired 37 | private UserDao userDao; 38 | 39 | @Autowired 40 | private CarInformationDao carInformationDao; 41 | 42 | @Autowired 43 | private ICarInformationService carInformationService; 44 | 45 | /** 46 | * 取消用户uid在iid拼车的行程信息 47 | * @param iid 48 | * @param uid 49 | * @return 50 | */ 51 | @Override 52 | @Transactional 53 | public Map cancelStroke(int iid, int uid) { 54 | 55 | Map datas = new HashMap<>(); 56 | 57 | //首先判断要取消的这个用户是否加入了拼车该拼车信息如果是,继续操作,反之无权限 58 | if (!this.isSignedCarInformation(uid, iid)) { 59 | datas.put(CommonConstant.FAIL, MemberConstant.NO_SIGN_UP_THIS_CAR_INFORMATION); 60 | return datas; 61 | } 62 | //先查询iid这个拼车信息的成员 63 | Member member = memberDao.getMember(iid); 64 | Member param = this.conversionMember(member, uid); 65 | assert param != null; 66 | param.setIid(iid); 67 | memberDao.removeUserFromMember(param); 68 | if (param.getUid1() != null) { 69 | //删除拼车信息 70 | carInformationDao.removeCarInformation(iid); 71 | } 72 | datas.put(CommonConstant.SUCCESS, CommonConstant.SUCCESS); 73 | return datas; 74 | } 75 | 76 | /** 77 | * 根据拼车信息查询所有成员的信息 78 | * 79 | * @param iid 80 | * @return 81 | */ 82 | @Override 83 | public List getMemberInfos(int iid) { 84 | return userDao.getUserByIid(iid); 85 | } 86 | 87 | /** 88 | * 添加用户uid到行程中去 89 | * @param iid 90 | * @param uid 91 | */ 92 | @Override 93 | public Map addUserToStroke(int iid, int uid) { 94 | 95 | Map datas = new HashMap<>(); 96 | Member member = memberDao.getMember(iid); 97 | if (ObjectUtil.isEmpty(member)) { 98 | datas.put(CommonConstant.FAIL, CarInformationConstant.NO_THIS_IID_CAR_INFORMATION); 99 | return datas; 100 | } 101 | Member param = new Member(); 102 | //此处应该判断用户是否已经加入拼车信息 103 | if (this.isSignedCarInformation(uid, iid)) { 104 | datas.put(CommonConstant.FAIL, MemberConstant.ALERDY_SIGN_UP_CAR_INFORMATION); 105 | return datas; 106 | } 107 | //判断是否符合加入规则,同一天不能从同一地点出发两次 108 | if (!ObjectUtil.isEmpty(this.isCanSignUpCarInformation(uid, iid).get(CommonConstant.FAIL))) { 109 | datas.put(CommonConstant.FAIL, this.isCanSignUpCarInformation(uid, iid).get(CommonConstant.FAIL)); 110 | return datas; 111 | } 112 | param.setIid(iid); 113 | if (member.getUid2() == 0) { 114 | param.setUid2(uid); 115 | } else if (member.getUid3() == 0) { 116 | param.setUid3(uid); 117 | } else if (member.getUid4() == 0) { 118 | param.setUid4(uid); 119 | } else if (member.getUid5() == 0) { 120 | param.setUid5(uid); 121 | } else if (member.getUid6() == 0) { 122 | param.setUid6(uid); 123 | } else { 124 | datas.put(CommonConstant.FAIL, MemberConstant.MEMBER_IS_FULL); 125 | return datas; 126 | } 127 | memberDao.addUserToMember(param); 128 | datas.put(CommonConstant.SUCCESS, CommonConstant.SUCCESS); 129 | return datas; 130 | } 131 | 132 | /** 133 | * 判断用户是否已经加入拼车信息 134 | * 135 | * @param uid 136 | * @param iid 137 | * @return 138 | */ 139 | private boolean isSignedCarInformation(int uid, int iid) { 140 | Member member = memberDao.getMember(iid); 141 | if (Objects.equals(member.getUid1(), uid)) { 142 | return true; 143 | } else if (member.getUid2() == uid) { 144 | return true; 145 | } else if (member.getUid3() == uid) { 146 | return true; 147 | } else if (member.getUid4() == uid) { 148 | return true; 149 | } else if (member.getUid5() == uid) { 150 | return true; 151 | } else if (member.getUid6() == uid) { 152 | return true; 153 | } 154 | return false; 155 | } 156 | 157 | /** 158 | * 格式参数 159 | * 160 | * @param member 161 | * @param uid 162 | * @return 163 | */ 164 | private Member conversionMember(Member member, int uid) { 165 | Member param = new Member(); 166 | //判断此时的uid是第几个用户 167 | //下面这个代码写的也没谁了,宛如小学生写的代码.但是这个之前的设计就有问题,再加上没有什么好的解决办法,继续沿用之前的设计算了,不然盖起来麻烦, 168 | //比赛的代码马上就要提交了,我只能赶时间啊, QAQ..... 169 | if (member.getUid1() == uid) { 170 | param.setUid1(uid); 171 | } else if (member.getUid2() == uid) { 172 | param.setUid2(uid); 173 | } else if (member.getUid3() == uid) { 174 | param.setUid3(uid); 175 | } else if (member.getUid4() == uid) { 176 | param.setUid4(uid); 177 | } else if (member.getUid5() == uid) { 178 | param.setUid5(uid); 179 | } else if (member.getUid6() == uid) { 180 | param.setUid6(uid); 181 | } else { 182 | return null; 183 | } 184 | return param; 185 | } 186 | 187 | /** 188 | * 判断uid是否可以报名iid这个行程信息(同一天不能从同一地点出发两次) 189 | * @param uid 190 | * @param iid 191 | * @return 192 | */ 193 | @Override 194 | public Map isCanSignUpCarInformation(int uid, int iid) { 195 | Map datas = new HashMap<>(); 196 | 197 | //查询用户已经有的行程信息 198 | List carInformations = carInformationService.getUserSignedUpCarInformation(uid); 199 | //查询要报名的拼车信息 200 | CarInformation carInformation = carInformationDao.getCarInformation(iid); 201 | 202 | Date startDate = carInformation.getStartDate(); 203 | String startPos = carInformation.getStartPos(); 204 | 205 | if (!CollectionUtils.isEmpty(carInformations)) { 206 | for (CarInformation information : carInformations) { 207 | //如果出发日期是同一天并且出发地点还是相同的,那么不符合报名的规则 208 | if (DateUtils.getDifferenceDays(information.getStartDate(), startDate) == 0) { 209 | if (information.getStartPos().equals(startPos)) { 210 | datas.put(CommonConstant.FAIL, MemberConstant.INVAILD_SIGN_UP); 211 | return datas; 212 | } 213 | } 214 | } 215 | } 216 | datas.put(CommonConstant.SUCCESS, CommonConstant.SUCCESS); 217 | return datas; 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/com/yiyexy/controller/common/UserController.java: -------------------------------------------------------------------------------- 1 | package com.yiyexy.controller.common; 2 | 3 | import com.yiyexy.annotation.Authorization; 4 | import com.yiyexy.annotation.CurrentUser; 5 | import com.yiyexy.constant.CommonConstant; 6 | import com.yiyexy.constant.UserConstant; 7 | import com.yiyexy.constant.ValidateConstant; 8 | import com.yiyexy.manager.TokenManager; 9 | import com.yiyexy.model.common.TokenModel; 10 | import com.yiyexy.model.common.User; 11 | import com.yiyexy.service.common.IMessageService; 12 | import com.yiyexy.service.common.IUserService; 13 | import com.yiyexy.util.ObjectUtil; 14 | import com.yiyexy.util.result.Result; 15 | import com.yiyexy.util.result.ResultBuilder; 16 | import io.swagger.annotations.*; 17 | import org.omg.PortableInterceptor.USER_EXCEPTION; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.web.bind.annotation.*; 20 | import springfox.documentation.annotations.ApiIgnore; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * 26 | * _____ _ ___ ___ 27 | / ___| | | \/ | 28 | \ `--.| |_ ___ _ __ _ __ ___ | . . | __ _ 29 | `--. \ __/ _ \| '__| '_ ` _ \| |\/| |/ _` | 30 | /\__/ / || (_) | | | | | | | | | | | (_| | 31 | \____/ \__\___/|_| |_| |_| |_\_| |_/\__,_| 我想念你,一如独自撸码的忧伤.... 32 | * 33 | * 34 | *

Created on 2017/5/7.

35 | * 36 | * @author stormma 37 | * 38 | * @description:

用户控制器

39 | */ 40 | @Api(value = "/api/user", description = UserConstant.CONTROLLER_DESC) 41 | @RestController 42 | @RequestMapping(value = "/api/user") 43 | public class UserController extends BaseController { 44 | 45 | @Autowired 46 | private IUserService userService; 47 | 48 | @Autowired 49 | private TokenManager tokenManager; 50 | 51 | @Autowired 52 | private IMessageService messageService; 53 | 54 | 55 | /** 56 | * 用户登录 57 | * @param paramUser 58 | * @return 59 | */ 60 | @ApiOperation(value = UserConstant.LOGIN_DESC, httpMethod = "POST") 61 | @PostMapping(value = "/login") 62 | public Result login(@RequestBody User paramUser) { 63 | 64 | 65 | Map datas = userService.isLoginSuccess(paramUser.getMobile(), paramUser.getPassword()); 66 | 67 | //如果登录失败 68 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.FAIL))) { 69 | Integer status = datas.get(CommonConstant.FAIL); 70 | return ResultBuilder.fail(status + ""); 71 | } 72 | 73 | Integer uid = datas.get(CommonConstant.SUCCESS); 74 | TokenModel tokenModel = tokenManager.createToken(uid); 75 | return ResultBuilder.success(tokenModel); 76 | } 77 | 78 | 79 | /** 80 | * 修改密码 81 | * @param loginUser 82 | * @param paramUser 83 | * @return 84 | */ 85 | @Authorization 86 | @ApiOperation(value = UserConstant.UPDATE_PASSWORD, httpMethod = "POST") 87 | @ApiImplicitParams({@ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true 88 | , paramType = "header")}) 89 | @PostMapping(value = "/update/password") 90 | public Result updatePassword(@ApiIgnore @CurrentUser User loginUser, 91 | @RequestBody User paramUser) { 92 | 93 | String mobile = loginUser.getMobile(); 94 | 95 | boolean result = userService.updatePassword(mobile, paramUser.getPassword()); 96 | if (result) { 97 | return ResultBuilder.success(); 98 | } 99 | return ResultBuilder.fail(); 100 | } 101 | 102 | /** 103 | * 修改qq信息 104 | * @param loginUser 105 | * @param qq 106 | * @return 107 | */ 108 | @Authorization 109 | @ApiOperation(value = UserConstant.UPDATE_QQ_NUM, httpMethod = "PUT") 110 | @ApiImplicitParams({@ApiImplicitParam(name = "qq", value = UserConstant.USER_QQ_NUM, required = true 111 | , paramType = "path") 112 | , @ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true 113 | , paramType = "header")}) 114 | @PutMapping(value = "/update/qq/{qq}") 115 | public Result updateQQnum(@ApiIgnore @CurrentUser User loginUser, 116 | @PathVariable String qq) { 117 | 118 | String mobile = loginUser.getMobile(); 119 | 120 | boolean result = userService.updateQQNum(mobile, qq); 121 | 122 | if (result) { 123 | return ResultBuilder.success(); 124 | } 125 | return ResultBuilder.fail(); 126 | } 127 | 128 | /** 129 | *

修改用户名

130 | * @param loginUser 131 | * @param userName 132 | * @return 133 | */ 134 | @Authorization 135 | @ApiOperation(value = UserConstant.UPDATE_USER_NAME, httpMethod = "PUT") 136 | @ApiImplicitParams({@ApiImplicitParam(name = "userName", value = UserConstant.USER_NAME_DESC, required = true 137 | , paramType = "path") 138 | , @ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true 139 | , paramType = "header")}) 140 | @PutMapping(value = "/update/username/{userName}") 141 | public Result updateUserName(@ApiIgnore @CurrentUser User loginUser, 142 | @PathVariable String userName) { 143 | String mobile = loginUser.getMobile(); 144 | String result = userService.updateUserName(mobile, userName); 145 | 146 | //修改成功 147 | if (result.equals(CommonConstant.SUCCESS)) { 148 | return ResultBuilder.success(); 149 | } else { 150 | return ResultBuilder.fail(result); 151 | } 152 | } 153 | 154 | /** 155 | * 重置密码 156 | * @param validateCode 157 | * @param paramUser 158 | * @return 159 | */ 160 | @ApiOperation(value = UserConstant.RESET_PASSWORD_METHOD_DESC, httpMethod = "PUT") 161 | @ApiImplicitParams({@ApiImplicitParam(name = "validateCode", value = ValidateConstant.USER_COMMIT_VALIDATE_CODE, required = true, paramType = "path")}) 162 | @PutMapping("/reset/password/{validateCode}") 163 | public Result resetPassword(@PathVariable String validateCode, 164 | @RequestBody User paramUser) { 165 | 166 | //校验验证码 167 | if (!messageService.checkValidateIsValid(validateCode, paramUser.getMobile())) { 168 | return ResultBuilder.fail(ValidateConstant.VALIDATE_CODE_IS_INVALID); 169 | } 170 | //开始更新密码 171 | boolean result = userService.updatePassword(paramUser.getMobile(), paramUser.getPassword()); 172 | if (result) { 173 | return ResultBuilder.success(); 174 | } 175 | return ResultBuilder.fail(); 176 | } 177 | 178 | /** 179 | * 注册接口 180 | * @param validateCode 181 | * @param paramUser 182 | * @return 183 | */ 184 | @ApiOperation(value = UserConstant.USER_REGISTER_METHOD_DESC, httpMethod = "POST") 185 | @ApiImplicitParams({@ApiImplicitParam(name = "validateCode", value = ValidateConstant.USER_COMMIT_VALIDATE_CODE, required = true, paramType = "path")}) 186 | @PostMapping(value = "/register/{validateCode}") 187 | public Result register(@PathVariable String validateCode, 188 | @RequestBody User paramUser) { 189 | //校验验证码 190 | if (!messageService.checkValidateIsValid(validateCode, paramUser.getMobile())) { 191 | return ResultBuilder.fail(ValidateConstant.VALIDATE_CODE_IS_INVALID); 192 | } 193 | 194 | Map datas = userService.register(paramUser.getMobile(), paramUser.getPassword()); 195 | if (!ObjectUtil.isEmpty(datas.get(CommonConstant.SUCCESS))) { 196 | return ResultBuilder.success(datas.get(CommonConstant.SUCCESS)); 197 | } else { 198 | return ResultBuilder.fail(datas.get(CommonConstant.FAIL)); 199 | } 200 | } 201 | 202 | /** 203 | * 获得登录用户的个人信息 204 | * @param loginUser 205 | * @return 206 | */ 207 | @Authorization 208 | @ApiOperation(value = UserConstant.GET_USER_INFO_METHOD_DESC, httpMethod = "GET") 209 | @ApiImplicitParams({@ApiImplicitParam(name = "authorization", value = UserConstant.AUTHORIZATION_TOKEN, required = true 210 | , paramType = "header")}) 211 | @GetMapping("/info") 212 | public Result getUserInfo(@ApiIgnore @CurrentUser User loginUser) { 213 | return ResultBuilder.success(loginUser); 214 | } 215 | } --------------------------------------------------------------------------------