├── .DS_Store ├── src ├── .DS_Store ├── main │ ├── .DS_Store │ ├── java │ │ ├── .DS_Store │ │ └── com │ │ │ ├── .DS_Store │ │ │ └── njtech │ │ │ ├── .DS_Store │ │ │ └── smartuniversity │ │ │ ├── service │ │ │ ├── MailService.java │ │ │ ├── EmailInfoService.java │ │ │ ├── impl │ │ │ │ ├── MailServiceImpl.java │ │ │ │ ├── AuthorityServiceImpl.java │ │ │ │ ├── EmailInfoServiceImpl.java │ │ │ │ ├── GoodsServiceImpl.java │ │ │ │ ├── ShopInfoServiceImpl.java │ │ │ │ ├── CardServiceImpl.java │ │ │ │ ├── OrderServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ ├── AuthorityService.java │ │ │ ├── CardService.java │ │ │ ├── GoodsService.java │ │ │ ├── OrderService.java │ │ │ ├── ShopInfoService.java │ │ │ └── UserService.java │ │ │ ├── annotation │ │ │ └── ServiceAnnotation.java │ │ │ ├── exception │ │ │ └── GlobalExceptionHandler.java │ │ │ ├── bean │ │ │ ├── AuthTokenBean.java │ │ │ ├── CustomGoodsBean.java │ │ │ ├── AuthorityBean.java │ │ │ ├── SmsBean.java │ │ │ ├── LoginBean.java │ │ │ ├── OrderBean.java │ │ │ ├── EmailInfoBean.java │ │ │ ├── ShopInfoBean.java │ │ │ ├── CardBean.java │ │ │ ├── UserBean.java │ │ │ └── GoodsBean.java │ │ │ ├── SmartuniversityApplication.java │ │ │ ├── dao │ │ │ ├── CustomOrdersBeanMapper.java │ │ │ ├── CustomGoodsBeanMapper.java │ │ │ ├── CardBeanMapper.java │ │ │ ├── UserBeanMapper.java │ │ │ ├── GoodsBeanMapper.java │ │ │ ├── OrderBeanMapper.java │ │ │ ├── ShopInfoBeanMapper.java │ │ │ ├── AuthorityBeanMapper.java │ │ │ └── EmailInfoBeanMapper.java │ │ │ ├── config │ │ │ ├── TomcatConfig.java │ │ │ ├── security │ │ │ │ ├── JwtAuthenticationRequest.java │ │ │ │ ├── JwtUser.java │ │ │ │ ├── JwtAuthenticationEntryPoint.java │ │ │ │ ├── JwtUserDetailServiceImpl.java │ │ │ │ ├── JwtAuthenticationTokenFilter.java │ │ │ │ └── JwtTokenUtil.java │ │ │ ├── WebSecurityConfig.java │ │ │ └── SwaggerConfig.java │ │ │ ├── util │ │ │ ├── JwtConfig.java │ │ │ ├── MailUtil.java │ │ │ ├── JsonUtil.java │ │ │ ├── JsonResult.java │ │ │ ├── QiniuUtil.java │ │ │ └── Validator.java │ │ │ ├── controller │ │ │ ├── ImgController.java │ │ │ ├── AuthorityController.java │ │ │ └── AuthController.java │ │ │ └── aspect │ │ │ └── LogAspect.java │ └── resources │ │ ├── application.yml │ │ ├── generatorConfig.xml │ │ ├── mybatis-config.xml │ │ └── mapper │ │ ├── AuthorityBeanMapper.xml │ │ ├── OrderBeanMapper.xml │ │ ├── EmailInfoBeanMapper.xml │ │ ├── ShopInfoBeanMapper.xml │ │ └── CardBeanMapper.xml └── test │ └── java │ └── com │ └── njtech │ └── smartuniversity │ ├── SmartuniversityApplicationTests.java │ ├── MailServiceTest.java │ └── CustomGoodsMapperTest.java ├── screenshots ├── 登录.png ├── .DS_Store ├── 用户订单.png ├── 用户首页.png ├── 管理员主页.png ├── 商户-商品信息.png ├── 用户-商品列表.png ├── 用户具体信息.png ├── 商户-修改商品信息.png ├── 管理员-一卡通申请.png ├── 管理员-商品信息.png ├── 管理员-商品信息修改.png ├── 管理员-商品具体信息.png ├── 管理员-用户信息.png ├── Swagger-API文档-1.png ├── Swagger-API文档-2.png └── Swagger-API文档-3.png ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .gitignore ├── 功能需求.md ├── README.md ├── mvnw.cmd ├── pom.xml └── mvnw /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/.DS_Store -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/src/.DS_Store -------------------------------------------------------------------------------- /screenshots/登录.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/登录.png -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/src/main/.DS_Store -------------------------------------------------------------------------------- /screenshots/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/.DS_Store -------------------------------------------------------------------------------- /screenshots/用户订单.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/用户订单.png -------------------------------------------------------------------------------- /screenshots/用户首页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/用户首页.png -------------------------------------------------------------------------------- /screenshots/管理员主页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员主页.png -------------------------------------------------------------------------------- /screenshots/商户-商品信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/商户-商品信息.png -------------------------------------------------------------------------------- /screenshots/用户-商品列表.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/用户-商品列表.png -------------------------------------------------------------------------------- /screenshots/用户具体信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/用户具体信息.png -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/src/main/java/.DS_Store -------------------------------------------------------------------------------- /screenshots/商户-修改商品信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/商户-修改商品信息.png -------------------------------------------------------------------------------- /screenshots/管理员-一卡通申请.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员-一卡通申请.png -------------------------------------------------------------------------------- /screenshots/管理员-商品信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员-商品信息.png -------------------------------------------------------------------------------- /screenshots/管理员-商品信息修改.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员-商品信息修改.png -------------------------------------------------------------------------------- /screenshots/管理员-商品具体信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员-商品具体信息.png -------------------------------------------------------------------------------- /screenshots/管理员-用户信息.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/管理员-用户信息.png -------------------------------------------------------------------------------- /src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /screenshots/Swagger-API文档-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/Swagger-API文档-1.png -------------------------------------------------------------------------------- /screenshots/Swagger-API文档-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/Swagger-API文档-2.png -------------------------------------------------------------------------------- /screenshots/Swagger-API文档-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/screenshots/Swagger-API文档-3.png -------------------------------------------------------------------------------- /src/main/java/com/njtech/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RITCHIEHuang/smartuniversity-server/HEAD/src/main/java/com/njtech/.DS_Store -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/MailService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | /** 4 | * Created by ritchie on 7/2/18 5 | */ 6 | public interface MailService { 7 | 8 | void sendSimpleMail(String to, String subject, String content); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /.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 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/annotation/ServiceAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by ritchie on 6/29/18 7 | */ 8 | @Target({ElementType.METHOD, ElementType.PARAMETER}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Documented 11 | public @interface ServiceAnnotation { 12 | String description() default ""; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.exception; 2 | 3 | import org.springframework.web.bind.annotation.ControllerAdvice; 4 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 5 | 6 | /** 7 | * Created by ritchie on 6/30/18 8 | */ 9 | 10 | @ControllerAdvice 11 | public class GlobalExceptionHandler extends ResponseEntityExceptionHandler{ 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/njtech/smartuniversity/SmartuniversityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity; 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 SmartuniversityApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/AuthTokenBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | /** 4 | * Created by ritchie on 6/26/18 5 | */ 6 | public class AuthTokenBean { 7 | 8 | private String token; 9 | 10 | 11 | public AuthTokenBean() { 12 | } 13 | 14 | public AuthTokenBean(String token) { 15 | this.token = token; 16 | } 17 | 18 | public String getToken() { 19 | return token; 20 | } 21 | 22 | public void setToken(String token) { 23 | this.token = token; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/EmailInfoService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.njtech.smartuniversity.bean.EmailInfoBean; 4 | 5 | /** 6 | * Created by ritchie on 7/2/18 7 | */ 8 | public interface EmailInfoService { 9 | 10 | EmailInfoBean addEmailInfo(String email, String code); 11 | 12 | EmailInfoBean selectEmailInfo(String email, String code); 13 | 14 | EmailInfoBean selectEmailInfoByEmail(String email); 15 | 16 | EmailInfoBean updateEmailInfo(EmailInfoBean emailInfoBean); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/SmartuniversityApplication.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan(basePackages = "com.njtech.smartuniversity.dao") 9 | public class SmartuniversityApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SmartuniversityApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/CustomOrdersBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.GoodsBean; 4 | import org.apache.ibatis.annotations.ResultMap; 5 | import org.apache.ibatis.annotations.Select; 6 | 7 | import java.util.List; 8 | 9 | public interface CustomOrdersBeanMapper { 10 | 11 | 12 | @Select("select g.* from goods as g, orders as o where o.g_id=g.id group by g.id order by sum(o.num) desc") 13 | @ResultMap("com.njtech.smartuniversity.dao.GoodsBeanMapper.BaseResultMap") 14 | List getHotGoods(); 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/CustomGoodsBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | public class CustomGoodsBean implements Serializable { 6 | int rank; 7 | 8 | GoodsBean mGoodsBean; 9 | 10 | public GoodsBean getGoodsBean() { 11 | return mGoodsBean; 12 | } 13 | 14 | public void setGoodsBean(GoodsBean goodsBean) { 15 | mGoodsBean = goodsBean; 16 | } 17 | 18 | public int getRank() { 19 | return rank; 20 | } 21 | 22 | public void setRank(int rank) { 23 | this.rank = rank; 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/CustomGoodsBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.GoodsBean; 4 | import com.njtech.smartuniversity.bean.GoodsBeanExample; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.ResultMap; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | import java.util.List; 10 | 11 | public interface CustomGoodsBeanMapper { 12 | 13 | 14 | @Select("select * from goods where s_i_uuid in (select uuid from shop_info where user_uuid = #{userUUid})") 15 | @ResultMap("com.njtech.smartuniversity.dao.GoodsBeanMapper.BaseResultMap") 16 | List getMerchantGoods(@Param("userUUid") String userUUid); 17 | 18 | } -------------------------------------------------------------------------------- /src/test/java/com/njtech/smartuniversity/MailServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity; 2 | 3 | import com.njtech.smartuniversity.service.MailService; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class MailServiceTest { 13 | 14 | @Autowired 15 | private MailService mMailService; 16 | 17 | 18 | @Test 19 | public void testSimpleMail() throws Exception { 20 | mMailService.sendSimpleMail("1169532212@qq.com", "test simple mail", " hello this is simple mail"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/AuthorityBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | public class AuthorityBean { 4 | private Integer id; 5 | 6 | private String auName; 7 | 8 | private String auDetails; 9 | 10 | public Integer getId() { 11 | return id; 12 | } 13 | 14 | public void setId(Integer id) { 15 | this.id = id; 16 | } 17 | 18 | public String getAuName() { 19 | return auName; 20 | } 21 | 22 | public void setAuName(String auName) { 23 | this.auName = auName == null ? null : auName.trim(); 24 | } 25 | 26 | public String getAuDetails() { 27 | return auDetails; 28 | } 29 | 30 | public void setAuDetails(String auDetails) { 31 | this.auDetails = auDetails == null ? null : auDetails.trim(); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/SmsBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | /** 4 | * Created by ritchie on 7/2/18 5 | */ 6 | public class SmsBean { 7 | 8 | /** 9 | * code : 200 10 | * msg : 88 11 | * obj : 1908 12 | */ 13 | 14 | private int code; 15 | private String msg; 16 | private String obj; 17 | 18 | public int getCode() { 19 | return code; 20 | } 21 | 22 | public void setCode(int code) { 23 | this.code = code; 24 | } 25 | 26 | public String getMsg() { 27 | return msg; 28 | } 29 | 30 | public void setMsg(String msg) { 31 | this.msg = msg; 32 | } 33 | 34 | public String getObj() { 35 | return obj; 36 | } 37 | 38 | public void setObj(String obj) { 39 | this.obj = obj; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/LoginBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | /** 4 | * Created by ritchie on 7/3/18 5 | */ 6 | public class LoginBean extends AuthTokenBean { 7 | 8 | private int userType; 9 | 10 | private String userUUId; 11 | 12 | private String userID; 13 | 14 | public String getUserUUId() { 15 | return userUUId; 16 | } 17 | 18 | public void setUserUUId(String userUUId) { 19 | this.userUUId = userUUId; 20 | } 21 | 22 | public String getUserID() { 23 | return userID; 24 | } 25 | 26 | public void setUserID(String userID) { 27 | this.userID = userID; 28 | } 29 | 30 | public int getUserType() { 31 | return userType; 32 | } 33 | 34 | public void setUserType(int userType) { 35 | this.userType = userType; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /功能需求.md: -------------------------------------------------------------------------------- 1 | # 功能描述需求 2 | 3 | ## 1 功能描述 4 | ### 1.1 统角色:学生、老师和校园商户 5 | - 登录功能 6 | - 各种一卡通操作 7 | - 各种上架及购买操作 8 | - 每一笔买入、卖出的业务,商家都会记录在账 9 | - 实现防恶意登录及自动登录功能 10 | - 商店可以根据自己的实际情况选择可提供的服务项 11 | - 可选择提供送货服务或者自取两种方式 12 | 13 | ### 1.2 开发计划 14 | - 系统启动 15 | - 用户登录及权限识别 16 | - 用户购买商品及选择商品送货服务 17 | - 学生申请一卡通及老师审核 18 | - 一卡通管理及商品管理功能 19 | 20 | ## 2. 功能需求 21 | ### 2.1 项目启动 22 | #### 需求说明 23 | - 系统启动时,显示用户登录界面,未登录用户或未授权不能使用功能 24 | - 统启动后,显示商品列表 25 | ### 2.2 品列表展示 26 | #### 需求说明 27 | - 登陆成功后,展示商品列表,点击可查看商品详情 28 | - 如果登入失败,直接进入该页面会显示未登录提示 29 | - 提示未登录提示3秒后回到登录页面 30 | 31 | ### 2.3 订单管理及商品上架服务 32 | #### 需求说明 33 | - 用户成功登录后,可选择购买商品 34 | - 商家家登录成功后,可进行上架服务 35 | - 用户/上架登录成功后,可查询订单详情 36 | 37 | ### 2.4 一卡通申请与审核模块 38 | #### 需求说明 39 | - 生登录成功后,可申请一卡通 40 | - 师登录成功后,可审核学生提交的申请 41 | - 请成功后,发放学生一卡通账号 42 | - 次使用时,需修改初始密码 43 | 44 | ### 2.5 一卡通管理模块 45 | #### 需求说明 46 | - 学生身份显示当前一卡通使用信息 47 | - 可点击使用信息查看详情 48 | - 老师身份显示审核列表及已审核、未审核项 49 | - 未审核项给与提示信息 50 | - 老师身份可查看审核流程 51 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/OrderBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | public class OrderBean { 4 | private Integer id; 5 | 6 | private String userUuid; 7 | 8 | private Integer gId; 9 | 10 | private Integer num; 11 | 12 | public Integer getId() { 13 | return id; 14 | } 15 | 16 | public void setId(Integer id) { 17 | this.id = id; 18 | } 19 | 20 | public String getUserUuid() { 21 | return userUuid; 22 | } 23 | 24 | public void setUserUuid(String userUuid) { 25 | this.userUuid = userUuid == null ? null : userUuid.trim(); 26 | } 27 | 28 | public Integer getgId() { 29 | return gId; 30 | } 31 | 32 | public void setgId(Integer gId) { 33 | this.gId = gId; 34 | } 35 | 36 | public Integer getNum() { 37 | return num; 38 | } 39 | 40 | public void setNum(Integer num) { 41 | this.num = num; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/EmailInfoBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | import java.util.Date; 4 | 5 | public class EmailInfoBean { 6 | private Integer id; 7 | 8 | private String email; 9 | 10 | private String code; 11 | 12 | private Date createdTime; 13 | 14 | public Integer getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Integer id) { 19 | this.id = id; 20 | } 21 | 22 | public String getEmail() { 23 | return email; 24 | } 25 | 26 | public void setEmail(String email) { 27 | this.email = email == null ? null : email.trim(); 28 | } 29 | 30 | public String getCode() { 31 | return code; 32 | } 33 | 34 | public void setCode(String code) { 35 | this.code = code == null ? null : code.trim(); 36 | } 37 | 38 | public Date getCreatedTime() { 39 | return createdTime; 40 | } 41 | 42 | public void setCreatedTime(Date createdTime) { 43 | this.createdTime = createdTime; 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/CardBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.CardBean; 4 | import com.njtech.smartuniversity.bean.CardBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface CardBeanMapper { 9 | long countByExample(CardBeanExample example); 10 | 11 | int deleteByExample(CardBeanExample example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(CardBean record); 16 | 17 | int insertSelective(CardBean record); 18 | 19 | List selectByExample(CardBeanExample example); 20 | 21 | CardBean selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") CardBean record, @Param("example") CardBeanExample example); 24 | 25 | int updateByExample(@Param("record") CardBean record, @Param("example") CardBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(CardBean record); 28 | 29 | int updateByPrimaryKey(CardBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/UserBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.UserBean; 4 | import com.njtech.smartuniversity.bean.UserBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface UserBeanMapper { 9 | long countByExample(UserBeanExample example); 10 | 11 | int deleteByExample(UserBeanExample example); 12 | 13 | int deleteByPrimaryKey(String uuid); 14 | 15 | int insert(UserBean record); 16 | 17 | int insertSelective(UserBean record); 18 | 19 | List selectByExample(UserBeanExample example); 20 | 21 | UserBean selectByPrimaryKey(String uuid); 22 | 23 | int updateByExampleSelective(@Param("record") UserBean record, @Param("example") UserBeanExample example); 24 | 25 | int updateByExample(@Param("record") UserBean record, @Param("example") UserBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(UserBean record); 28 | 29 | int updateByPrimaryKey(UserBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/GoodsBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.GoodsBean; 4 | import com.njtech.smartuniversity.bean.GoodsBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface GoodsBeanMapper { 9 | long countByExample(GoodsBeanExample example); 10 | 11 | int deleteByExample(GoodsBeanExample example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(GoodsBean record); 16 | 17 | int insertSelective(GoodsBean record); 18 | 19 | List selectByExample(GoodsBeanExample example); 20 | 21 | GoodsBean selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") GoodsBean record, @Param("example") GoodsBeanExample example); 24 | 25 | int updateByExample(@Param("record") GoodsBean record, @Param("example") GoodsBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(GoodsBean record); 28 | 29 | int updateByPrimaryKey(GoodsBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/OrderBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.OrderBean; 4 | import com.njtech.smartuniversity.bean.OrderBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface OrderBeanMapper { 9 | long countByExample(OrderBeanExample example); 10 | 11 | int deleteByExample(OrderBeanExample example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(OrderBean record); 16 | 17 | int insertSelective(OrderBean record); 18 | 19 | List selectByExample(OrderBeanExample example); 20 | 21 | OrderBean selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") OrderBean record, @Param("example") OrderBeanExample example); 24 | 25 | int updateByExample(@Param("record") OrderBean record, @Param("example") OrderBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(OrderBean record); 28 | 29 | int updateByPrimaryKey(OrderBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/TomcatConfig.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.web.servlet.MultipartConfigFactory; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import javax.servlet.MultipartConfigElement; 9 | 10 | /** 11 | * Created by ritchie on 7/5/18 12 | */ 13 | @Configuration 14 | public class TomcatConfig { 15 | 16 | @Value("${tomcatserver.maxfilesize}") 17 | private String MaxFileSize; 18 | @Value("${tomcatserver.maxrequestsize}") 19 | private String MaxRequestSize; 20 | 21 | @Bean 22 | public MultipartConfigElement multipartConfigElement() { 23 | MultipartConfigFactory factory = new MultipartConfigFactory(); 24 | // 单个数据大小 25 | factory.setMaxFileSize(MaxFileSize); // KB,MB 26 | /// 总上传数据大小 27 | factory.setMaxRequestSize(MaxRequestSize); 28 | return factory.createMultipartConfig(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtAuthenticationRequest.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Yuicon on 2017/5/20. 7 | * https://segmentfault.com/u/yuicon 8 | */ 9 | public class JwtAuthenticationRequest implements Serializable { 10 | 11 | private static final long serialVersionUID = -8445943548965154778L; 12 | 13 | private String account; 14 | private String password; 15 | 16 | public JwtAuthenticationRequest() { 17 | super(); 18 | } 19 | 20 | public JwtAuthenticationRequest(String account, String password) { 21 | this.setAccount(account); 22 | this.setPassword(password); 23 | } 24 | 25 | public String getAccount() { 26 | return this.account; 27 | } 28 | 29 | public void setAccount(String account) { 30 | this.account = account; 31 | } 32 | 33 | public String getPassword() { 34 | return this.password; 35 | } 36 | 37 | private void setPassword(String password) { 38 | this.password = password; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/ShopInfoBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.ShopInfoBean; 4 | import com.njtech.smartuniversity.bean.ShopInfoBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface ShopInfoBeanMapper { 9 | long countByExample(ShopInfoBeanExample example); 10 | 11 | int deleteByExample(ShopInfoBeanExample example); 12 | 13 | int deleteByPrimaryKey(String uuid); 14 | 15 | int insert(ShopInfoBean record); 16 | 17 | int insertSelective(ShopInfoBean record); 18 | 19 | List selectByExample(ShopInfoBeanExample example); 20 | 21 | ShopInfoBean selectByPrimaryKey(String uuid); 22 | 23 | int updateByExampleSelective(@Param("record") ShopInfoBean record, @Param("example") ShopInfoBeanExample example); 24 | 25 | int updateByExample(@Param("record") ShopInfoBean record, @Param("example") ShopInfoBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(ShopInfoBean record); 28 | 29 | int updateByPrimaryKey(ShopInfoBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/AuthorityBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.AuthorityBean; 4 | import com.njtech.smartuniversity.bean.AuthorityBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface AuthorityBeanMapper { 9 | long countByExample(AuthorityBeanExample example); 10 | 11 | int deleteByExample(AuthorityBeanExample example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(AuthorityBean record); 16 | 17 | int insertSelective(AuthorityBean record); 18 | 19 | List selectByExample(AuthorityBeanExample example); 20 | 21 | AuthorityBean selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") AuthorityBean record, @Param("example") AuthorityBeanExample example); 24 | 25 | int updateByExample(@Param("record") AuthorityBean record, @Param("example") AuthorityBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(AuthorityBean record); 28 | 29 | int updateByPrimaryKey(AuthorityBean record); 30 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/dao/EmailInfoBeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.dao; 2 | 3 | import com.njtech.smartuniversity.bean.EmailInfoBean; 4 | import com.njtech.smartuniversity.bean.EmailInfoBeanExample; 5 | import java.util.List; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | public interface EmailInfoBeanMapper { 9 | long countByExample(EmailInfoBeanExample example); 10 | 11 | int deleteByExample(EmailInfoBeanExample example); 12 | 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(EmailInfoBean record); 16 | 17 | int insertSelective(EmailInfoBean record); 18 | 19 | List selectByExample(EmailInfoBeanExample example); 20 | 21 | EmailInfoBean selectByPrimaryKey(Integer id); 22 | 23 | int updateByExampleSelective(@Param("record") EmailInfoBean record, @Param("example") EmailInfoBeanExample example); 24 | 25 | int updateByExample(@Param("record") EmailInfoBean record, @Param("example") EmailInfoBeanExample example); 26 | 27 | int updateByPrimaryKeySelective(EmailInfoBean record); 28 | 29 | int updateByPrimaryKey(EmailInfoBean record); 30 | } -------------------------------------------------------------------------------- /src/test/java/com/njtech/smartuniversity/CustomGoodsMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity; 2 | 3 | import com.njtech.smartuniversity.bean.GoodsBean; 4 | import com.njtech.smartuniversity.dao.CustomGoodsBeanMapper; 5 | import com.njtech.smartuniversity.dao.CustomOrdersBeanMapper; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 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.List; 13 | 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest 16 | public class CustomGoodsMapperTest { 17 | 18 | @Autowired 19 | private CustomGoodsBeanMapper mCustomGoodsBeanMapper; 20 | 21 | @Autowired 22 | private CustomOrdersBeanMapper mCustomOrdersBeanMapper; 23 | 24 | @Test 25 | public void getMerchatGoods() throws Exception { 26 | mCustomGoodsBeanMapper.getMerchantGoods("afca81b91ceb493b969223ace6332627"); 27 | } 28 | 29 | 30 | @Test 31 | public void getHotGoods() throws Exception { 32 | mCustomOrdersBeanMapper.getHotGoods(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/MailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.njtech.smartuniversity.service.MailService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.mail.SimpleMailMessage; 7 | import org.springframework.mail.javamail.JavaMailSender; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * Created by ritchie on 7/2/18 12 | */ 13 | @Component 14 | public class MailServiceImpl implements MailService { 15 | 16 | @Autowired 17 | private JavaMailSender mJavaMailSender; 18 | 19 | @Value("${mail.fromMail.addr}") 20 | private String from; 21 | 22 | 23 | @Override 24 | public void sendSimpleMail(String to, String subject, String content) { 25 | SimpleMailMessage message = new SimpleMailMessage(); 26 | message.setFrom(from); 27 | message.setTo(to); 28 | message.setSubject(subject); 29 | message.setText(content); 30 | 31 | try { 32 | mJavaMailSender.send(message); 33 | } catch (Exception e) { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/JwtConfig.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by ritchie on 6/26/18 8 | */ 9 | @Component 10 | @ConfigurationProperties(prefix="jwt") 11 | public class JwtConfig { 12 | 13 | private String secret; 14 | 15 | private int expiration; 16 | 17 | private String header; 18 | 19 | private String tokenHead; 20 | 21 | public String getSecret() { 22 | return secret; 23 | } 24 | 25 | public void setSecret(String secret) { 26 | this.secret = secret; 27 | } 28 | 29 | public int getExpiration() { 30 | return expiration; 31 | } 32 | 33 | public void setExpiration(int expiration) { 34 | this.expiration = expiration; 35 | } 36 | 37 | public String getHeader() { 38 | return header; 39 | } 40 | 41 | public void setHeader(String header) { 42 | this.header = header; 43 | } 44 | 45 | public String getTokenHead() { 46 | return tokenHead; 47 | } 48 | 49 | public void setTokenHead(String tokenHead) { 50 | this.tokenHead = tokenHead; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # smartuniversity-server 2 | 智慧校园管理系统-服务端 3 | --- 4 | ### 1. 项目简介 5 | 项目基于Intellij Idea开发, JavaWeb实训项目,项目基于[Spring Boot][1]编写了后台接口, 使用[Swagger2][2]编写了简单的接口文档,数据库持久层用的是[MyBatis][3]. 6 | 7 | 功能及需求文档见[功能需求][5] 8 | 9 | ### 2. 项目导入 10 | 1. `git clone 本项目地址` 到本地, 用Intellij Idea打开 11 | 2. 打开项目根目录下的pom.xml依次下载项目依赖即可完成构建 12 | 3. 修改application.yml中的数据库及其他配置 13 | 4. 前端项目见[smartuniversity-web][4] 14 | 15 | ### 3. 项目截图 16 | ![Swagger-API文档-1](screenshots/Swagger-API文档-1.png) 17 | ![Swagger-API文档-2](screenshots/Swagger-API文档-2.png) 18 | ![Swagger-API文档-3](screenshots/Swagger-API文档-3.png) 19 | ![登录](screenshots/登录.png) 20 | ![管理员-主页](screenshots/管理员主页.png) 21 | ![管理员-用户信息](screenshots/管理员-用户信息.png) 22 | ![管理员-商品列表](screenshots/管理员-商品信息.png) 23 | ![管理员-商品信息修改](screenshots/管理员-商品信息修改.png) 24 | ![管理员-商品详细信息](screenshots/管理员-商品具体信息.png) 25 | ![管理员-一卡通审核](screenshots/管理员-一卡通申请.png) 26 | ![用户-首页](screenshots/用户首页.png) 27 | ![用户-订单信息](screenshots/用户订单.png) 28 | ![用户-个人信息](screenshots/用户具体信息.png) 29 | ![用户-商品列表](screenshots/用户-商品列表.png) 30 | ![商户-商品列表](screenshots/商户-商品信息.png) 31 | ![商户-商品修改](screenshots/商户-修改商品信息.png) 32 | 33 | 34 | 35 | [1]: https://spring.io/projects/spring-boot/ 36 | [2]: https://swagger.io/ 37 | [3]: https://blog.mybatis.org/ 38 | [4]: https://github.com/RITCHIEHuang/smartUniversity-web 39 | [5]: 功能需求.md 40 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/AuthorityService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.AuthorityBean; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by ritchie on 6/25/18 10 | */ 11 | public interface AuthorityService { 12 | /** 13 | * 根据权限ID查询权限 14 | * 15 | * @param id 权限ID 16 | * @return 17 | */ 18 | AuthorityBean selectByAuthorityId(int id); 19 | 20 | 21 | /** 22 | * 修改权限信息 23 | * 24 | * @param authorityBean 25 | * @return 26 | */ 27 | AuthorityBean update(AuthorityBean authorityBean); 28 | 29 | 30 | /** 31 | * 获取权限列表 32 | * 33 | * @return 34 | */ 35 | List getAllAuthorities(); 36 | 37 | /** 38 | * 获取分页的权限列表 39 | * 40 | * @param pageNum 页码 41 | * @param pageSize 每页数量 42 | * @return 43 | */ 44 | PageInfo getAuthorityByPage(int pageNum, int pageSize); 45 | 46 | /** 47 | * 删除权限 48 | * 49 | * @param id 50 | * @return 51 | */ 52 | boolean deleteById(int id); 53 | 54 | /** 55 | * 新增权限 56 | * 57 | * @param authorityBean 58 | * @return 59 | */ 60 | AuthorityBean addAuthority(AuthorityBean authorityBean); 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/ShopInfoBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | public class ShopInfoBean { 4 | private String uuid; 5 | 6 | private String shopName; 7 | 8 | private String shopAddr; 9 | 10 | private String state; 11 | 12 | private String userUuid; 13 | 14 | public String getUuid() { 15 | return uuid; 16 | } 17 | 18 | public void setUuid(String uuid) { 19 | this.uuid = uuid == null ? null : uuid.trim(); 20 | } 21 | 22 | public String getShopName() { 23 | return shopName; 24 | } 25 | 26 | public void setShopName(String shopName) { 27 | this.shopName = shopName == null ? null : shopName.trim(); 28 | } 29 | 30 | public String getShopAddr() { 31 | return shopAddr; 32 | } 33 | 34 | public void setShopAddr(String shopAddr) { 35 | this.shopAddr = shopAddr == null ? null : shopAddr.trim(); 36 | } 37 | 38 | public String getState() { 39 | return state; 40 | } 41 | 42 | public void setState(String state) { 43 | this.state = state == null ? null : state.trim(); 44 | } 45 | 46 | public String getUserUuid() { 47 | return userUuid; 48 | } 49 | 50 | public void setUserUuid(String userUuid) { 51 | this.userUuid = userUuid == null ? null : userUuid.trim(); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/MailUtil.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Created by ritchie on 7/2/18 7 | */ 8 | public class MailUtil { 9 | 10 | private static final int CODE_LENGTH = 6; 11 | public static final String SUBJECT_REGISTER = "smartUniversity邮箱注册"; 12 | 13 | private static final String MESSAGE = "欢迎注册SmartUniversity智能校园项目,您本次收到的验证码为: "; 14 | 15 | 16 | public static String generateCode() { 17 | char[] codeSequence = {'A', 'B', 'C', 'D', 'E', 'F', 'G', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; 18 | //动态字符串 19 | StringBuilder sb = new StringBuilder(); 20 | Random random = new Random(); 21 | int count = 0; 22 | while (true) { 23 | int index = random.nextInt(codeSequence.length); //定义随机数的范围并且产生一个随机的下标 24 | //随机的取出一个数 25 | char c = codeSequence[index]; 26 | if (sb.indexOf(c + "") == -1) { //不让字符重复,并且把一个字符变成字符串 27 | sb.append(c); 28 | count++; 29 | if (count == CODE_LENGTH) { 30 | break; 31 | } 32 | } 33 | } 34 | return sb.toString(); 35 | 36 | } 37 | 38 | 39 | public static String generateMessgae(String code) { 40 | return MESSAGE + code; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.CardBean; 5 | 6 | import java.util.List; 7 | 8 | public interface CardService { 9 | /** 10 | * 根据卡号id 查询一卡通信息 11 | * @param id 12 | * @return 13 | */ 14 | CardBean selectByCardId(int id); 15 | 16 | 17 | CardBean selectBySQId(String sqID); 18 | /** 19 | * 修改一卡通信息 20 | * @param cardBean 21 | * @return 22 | */ 23 | CardBean update(CardBean cardBean); 24 | 25 | /** 26 | * 获取一卡通列表 27 | * 28 | * @return 29 | */ 30 | List getAllCards(); 31 | 32 | 33 | 34 | List getAllUnpassCards(); 35 | 36 | 37 | 38 | long getUnpassCount(); 39 | 40 | long getTotalCount(); 41 | 42 | 43 | /** 44 | * 获取分页的一卡通信息列表 45 | * 46 | * @param pageNum 页码 47 | * @param pageSize 每页数量 48 | * @return 49 | */ 50 | PageInfo getCardsByPage(int pageNum, int pageSize); 51 | 52 | /** 53 | * 删除一卡通用户 54 | * @param id 55 | * @return 56 | */ 57 | boolean deleteById(int id); 58 | 59 | /** 60 | * 新增一卡通信息 61 | * @param cardBean 62 | * @return 63 | */ 64 | CardBean addCard(CardBean cardBean); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * Created by ritchie on 6/26/18 8 | */ 9 | public class JsonUtil implements Serializable{ 10 | 11 | public JsonResult wrongNoDataDefault() { 12 | return JsonResult.builder() 13 | .data("") 14 | .message("失败") 15 | .code(-1) 16 | .build(); 17 | } 18 | 19 | 20 | public JsonResult wrongNoDataWithMessage(String message) { 21 | return JsonResult.builder() 22 | .data("") 23 | .message(message) 24 | .code(-1) 25 | .build(); 26 | } 27 | 28 | 29 | public JsonResult successDataDefault(T data) { 30 | return JsonResult.builder() 31 | .data(data) 32 | .code(0) 33 | .message("成功").build(); 34 | } 35 | 36 | 37 | public JsonResult successEmptyDataDefault(String message) { 38 | return JsonResult.builder() 39 | .data("") 40 | .code(0) 41 | .message(message).build(); 42 | } 43 | 44 | public JsonResult successDataWithMessage(T data, String message) { 45 | return JsonResult.builder() 46 | .data(data) 47 | .code(0) 48 | .message(message).build(); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/GoodsService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.GoodsBean; 5 | 6 | import java.util.List; 7 | 8 | public interface GoodsService { 9 | /** 10 | * 根据商品id查询商品信息 11 | * 12 | * @param id 13 | * @return 14 | */ 15 | GoodsBean selectByGoodsID(int id); 16 | 17 | /** 18 | * 修改商品信息 19 | * 20 | * @param goodsBean 21 | * @return 22 | */ 23 | GoodsBean update(GoodsBean goodsBean); 24 | 25 | /** 26 | * 获取所有商品信息列表 27 | * 28 | * @return 29 | */ 30 | List getAllGoods(); 31 | 32 | 33 | List getAllAvaliableGoods(); 34 | 35 | 36 | List getShopGoods(String uuid); 37 | 38 | 39 | List getMerchantGoods(String user_uuid); 40 | 41 | 42 | /** 43 | * 获取分页的商品信息列表 44 | * 45 | * @param pageNum 页码 46 | * @param pageSize 每页数量 47 | * @return 48 | */ 49 | PageInfo getGoodsByPage(int pageNum, int pageSize); 50 | 51 | 52 | /** 53 | * 删除商品信息 54 | * 55 | * @param id 56 | * @return 57 | */ 58 | boolean deleteById(int id); 59 | 60 | /** 61 | * 增加商品信息 62 | * 63 | * @param goodsBean 64 | * @return 65 | */ 66 | GoodsBean addGoods(GoodsBean goodsBean); 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/CardBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | import java.util.Date; 4 | 5 | public class CardBean { 6 | private Integer id; 7 | 8 | private String cardVid; 9 | 10 | private String sqId; 11 | 12 | private Integer authId; 13 | 14 | private Date applicationTime; 15 | 16 | private String state; 17 | 18 | public Integer getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Integer id) { 23 | this.id = id; 24 | } 25 | 26 | public String getCardVid() { 27 | return cardVid; 28 | } 29 | 30 | public void setCardVid(String cardVid) { 31 | this.cardVid = cardVid == null ? null : cardVid.trim(); 32 | } 33 | 34 | public String getSqId() { 35 | return sqId; 36 | } 37 | 38 | public void setSqId(String sqId) { 39 | this.sqId = sqId == null ? null : sqId.trim(); 40 | } 41 | 42 | public Integer getAuthId() { 43 | return authId; 44 | } 45 | 46 | public void setAuthId(Integer authId) { 47 | this.authId = authId; 48 | } 49 | 50 | public Date getApplicationTime() { 51 | return applicationTime; 52 | } 53 | 54 | public void setApplicationTime(Date applicationTime) { 55 | this.applicationTime = applicationTime; 56 | } 57 | 58 | public String getState() { 59 | return state; 60 | } 61 | 62 | public void setState(String state) { 63 | this.state = state == null ? null : state.trim(); 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.CustomGoodsBean; 5 | import com.njtech.smartuniversity.bean.GoodsBean; 6 | import com.njtech.smartuniversity.bean.OrderBean; 7 | import org.springframework.core.annotation.Order; 8 | 9 | import java.util.List; 10 | 11 | public interface OrderService { 12 | /** 13 | * 根据id查询订单信息 14 | * 15 | * @param id 16 | * @return 17 | */ 18 | OrderBean selecteByOrderId(int id); 19 | 20 | /** 21 | * 修改订单信息 22 | * 23 | * @return 24 | */ 25 | OrderBean update(OrderBean orderBean); 26 | 27 | /** 28 | * 获取订单信息 29 | * 30 | * @return 31 | */ 32 | List getAllOrders(); 33 | 34 | 35 | List getUserOrders(String user_uuid); 36 | 37 | 38 | /** 39 | * 获取分页的订单信息列表 40 | * 41 | * @param pageNum 页码 42 | * @param pageSize 每页数量 43 | * @return 44 | */ 45 | PageInfo getOrdersByPage(int pageNum, int pageSize); 46 | 47 | PageInfo getHotOrdersByPage(int pageNum, int pageSize); 48 | 49 | /** 50 | * 删除订单信息 51 | * 52 | * @param id 53 | * @return 54 | */ 55 | boolean deleteById(int id); 56 | 57 | /** 58 | * 新增订单信息 59 | * 60 | * @param orderBean 61 | * @return 62 | */ 63 | OrderBean addOrderBean(OrderBean orderBean); 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/ShopInfoService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.ShopInfoBean; 5 | 6 | import java.util.List; 7 | 8 | public interface ShopInfoService { 9 | /** 10 | * 根据商家name查询商家信息 11 | * 12 | * @param name 13 | * @return 14 | */ 15 | ShopInfoBean selectByShopInfoName(String name); 16 | 17 | /** 18 | * 根据商家uuid查询商家信息 19 | * 20 | * @param uuid 21 | * @return 22 | */ 23 | ShopInfoBean selectByShopInfoUUID(String uuid); 24 | 25 | /** 26 | * 修改商家信息 27 | * 28 | * @param shopInfoBean 29 | * @return 30 | */ 31 | ShopInfoBean update(ShopInfoBean shopInfoBean); 32 | 33 | /** 34 | * 获取所有商家信息列表 35 | * 36 | * @return 37 | */ 38 | List getAllShopInfos(); 39 | 40 | 41 | /** 42 | * 获取分页的商家信息列表 43 | * 44 | * @param pageNum 页码 45 | * @param pageSize 每页数量 46 | * @return 47 | */ 48 | PageInfo getShopInfosByPage(int pageNum, int pageSize); 49 | 50 | 51 | /** 52 | * 删除商家信息 53 | * 54 | * @param uuid 55 | * @return 56 | */ 57 | boolean deleteByUUId(String uuid); 58 | 59 | /** 60 | * 新增商家信息 61 | * 62 | * @param shopInfoBean 63 | * @return 64 | */ 65 | ShopInfoBean addShopInfoBean(ShopInfoBean shopInfoBean); 66 | 67 | List selectbyUserUUid(String uuid); 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/controller/ImgController.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.controller; 2 | 3 | import com.njtech.smartuniversity.util.JsonResult; 4 | import com.njtech.smartuniversity.util.JsonUtil; 5 | import com.njtech.smartuniversity.util.QiniuUtil; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiImplicitParam; 8 | import io.swagger.annotations.ApiImplicitParams; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.security.access.prepost.PreAuthorize; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import java.io.FileInputStream; 16 | import java.io.IOException; 17 | import java.util.UUID; 18 | 19 | /** 20 | * Created by ritchie on 7/5/18 21 | */ 22 | @RestController 23 | @RequestMapping("/api/images") 24 | @Api(value = "/api/images", tags = {"图片"}, description = "图片相关") 25 | public class ImgController { 26 | 27 | @Autowired 28 | QiniuUtil mQiniuUtil; 29 | 30 | 31 | @PutMapping("/upload") 32 | @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_MERCHANT')") 33 | @ApiOperation(value = "图片上传接口", notes = "图片上传") 34 | @ApiImplicitParams({ 35 | @ApiImplicitParam(value = "图片", name = "image", dataType = "file", paramType = "form", required = true) 36 | }) 37 | public JsonResult uploadImgQiniu(@RequestParam("image") MultipartFile multipartFile) throws IOException { 38 | FileInputStream inputStream = (FileInputStream) multipartFile.getInputStream(); 39 | long time = System.currentTimeMillis(); 40 | String path = mQiniuUtil.uploadImg(inputStream, time + ""); 41 | return new JsonUtil().successDataWithMessage(path, "图片上传成功"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtUser.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | import com.njtech.smartuniversity.bean.UserBean; 4 | import org.springframework.security.core.GrantedAuthority; 5 | import org.springframework.security.core.userdetails.UserDetails; 6 | 7 | import java.util.Collection; 8 | 9 | public class JwtUser extends UserBean implements UserDetails { 10 | 11 | //角色集合 12 | private Collection authorities; 13 | 14 | JwtUser(UserBean userBean) { 15 | setAuthId(userBean.getAuthId()); 16 | setEmail(userBean.getEmail()); 17 | setId(userBean.getId()); 18 | setPassword(userBean.getPassword()); 19 | setPhone(userBean.getPhone()); 20 | setState(userBean.getState()); 21 | setLastPasswordResetTime(userBean.getLastPasswordResetTime()); 22 | setShopType(userBean.getShopType()); 23 | setUuid(userBean.getUuid()); 24 | setType(userBean.getType()); 25 | setAccount(userBean.getAccount()); 26 | } 27 | 28 | public void setAuthorities(Collection authorities) { 29 | this.authorities = authorities; 30 | } 31 | 32 | @Override 33 | public String getUsername() { 34 | return getId(); 35 | } 36 | 37 | @Override 38 | public boolean isAccountNonExpired() { 39 | return true; 40 | } 41 | 42 | @Override 43 | public boolean isAccountNonLocked() { 44 | return true; 45 | } 46 | 47 | @Override 48 | public boolean isCredentialsNonExpired() { 49 | return true; 50 | } 51 | 52 | @Override 53 | public boolean isEnabled() { 54 | return true; 55 | } 56 | 57 | public Collection getAuthorities() { 58 | return authorities; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | import com.google.gson.Gson; 4 | import com.njtech.smartuniversity.util.JsonUtil; 5 | import org.springframework.security.core.AuthenticationException; 6 | import org.springframework.security.web.AuthenticationEntryPoint; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.OutputStream; 13 | import java.io.PrintWriter; 14 | import java.io.Serializable; 15 | import java.util.Arrays; 16 | 17 | /** 18 | * Created by Yuicon on 2017/5/14. 19 | * https://segmentfault.com/u/yuicon 20 | */ 21 | @Component 22 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable { 23 | 24 | private static final long serialVersionUID = -8970718410437077606L; 25 | 26 | @Override 27 | public void commence(HttpServletRequest request, 28 | HttpServletResponse response, 29 | AuthenticationException authException) throws IOException { 30 | // This is invoked when user tries to access a secured REST resource without supplying any credentials 31 | // We should just send a 401 Unauthorized response because there is no 'login page' to redirect to 32 | // response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); 33 | response.setContentType("application/json;charset=UTF-8;"); 34 | response.setCharacterEncoding("UTF-8"); 35 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 36 | String res = new Gson().toJson(new JsonUtil().wrongNoDataWithMessage("操作未授权,请登录授权!")); 37 | OutputStream out = response.getOutputStream(); 38 | out.write(res.getBytes("UTF-8")); 39 | out.flush(); 40 | out.close(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # server 端口 2 | server: 3 | port: 8080 4 | # 数据库连接相关配置 5 | spring: 6 | datasource: 7 | druid: 8 | url: jdbc:mysql://localhost:3306/smartUniversitySystem?characterEncoding=utf8 9 | driver-class-name: com.mysql.jdbc.Driver 10 | username: root 11 | password: 445412 12 | initial-size: 5 13 | max-active: 30 14 | min-idle: 5 15 | max-wait: 60000 16 | time-between-eviction-runs-millis: 60000 17 | min-evictable-idle-time-millis: 300000 18 | validation-query: SELECT 1 FROM DUAL 19 | test-while-idle: true 20 | test-on-borrow: false 21 | test-on-return: false 22 | pool-prepared-statements: true 23 | max-pool-prepared-statement-per-connection-size: 50 24 | filters: stat,wall 25 | connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 26 | use-global-data-source-stat: true 27 | aop: 28 | auto: true 29 | mail: 30 | host: smtp.qq.com 31 | username: 1169532212@qq.com 32 | password: bqoogqxksotrigjh 33 | default-encoding: UTF-8 34 | 35 | 36 | mail: 37 | fromMail: 38 | addr: 1169532212@qq.com 39 | 40 | 41 | # mybatis 42 | mybatis: 43 | type-aliases-package: com.njtech.smartuniversity.bean 44 | config-location: classpath:mybatis-config.xml 45 | mapper-locations: classpath:mapper/*.xml 46 | 47 | # mapper 48 | mapper: 49 | mappers: 50 | - com.njtech.smartuniversity.dao 51 | not-empty: false 52 | identity: MYSQL 53 | 54 | pagehelper: 55 | helperDialect: mysql 56 | reasonable: true 57 | supportMethodsArguments: true 58 | params: count=countSql 59 | 60 | jwt: 61 | secret: ritchie 62 | expiration: 604800 63 | header: Authorization 64 | tokenHead: Bearer 65 | 66 | qiniu: 67 | accessKey: Sj7dGiSQ4RDu-m51FFMjAShrwBIMF9eijflZn1g5 68 | secretKey: njCzv1fNM9q_O-c59caIS853LX4t_JxWRRCjuKoz 69 | bucket: ritchie 70 | path: ohkd1whwt.bkt.clouddn.com 71 | 72 | tomcatserver: 73 | maxfilesize: 300MB 74 | maxrequestsize: 500MB 75 | # mail 76 | 77 | #logging: 78 | # config: classpath:logback-spring.groovy 79 | 80 | #sms: 81 | # send-url: https://api.netease.im/sms/sendcode.action 82 | # verify-url: 83 | # AppKey: 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/JsonResult.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | 5 | /** 6 | * Created by ritchie on 6/25/18 7 | */ 8 | public class JsonResult { 9 | 10 | @ApiModelProperty(value = "返回状态码", notes = "0成功 -1失败") 11 | private int code; 12 | 13 | @ApiModelProperty(value = "返回数据", notes = "\"\"为空") 14 | private T data; 15 | 16 | @ApiModelProperty(value = "返回信息", notes = "接口执行信息") 17 | private String message; 18 | 19 | 20 | private JsonResult(JsonResultBuilder builder) { 21 | this.code = builder.code; 22 | this.data = builder.data; 23 | this.message = builder.message; 24 | } 25 | 26 | public static JsonResult.JsonResultBuilder builder() { 27 | return new JsonResultBuilder<>(); 28 | } 29 | 30 | public int getCode() { 31 | return code; 32 | } 33 | 34 | public void setCode(int code) { 35 | this.code = code; 36 | } 37 | 38 | public T getData() { 39 | return data; 40 | } 41 | 42 | public void setData(T data) { 43 | this.data = data; 44 | } 45 | 46 | public String getMessage() { 47 | return message; 48 | } 49 | 50 | public void setMessage(String message) { 51 | this.message = message; 52 | } 53 | 54 | public static final class JsonResultBuilder { 55 | 56 | private int code; 57 | 58 | private T data; 59 | 60 | private String message; 61 | 62 | private JsonResultBuilder() { 63 | 64 | } 65 | 66 | public JsonResultBuilder message(String message) { 67 | this.message = message; 68 | return this; 69 | } 70 | 71 | public JsonResultBuilder data(T data) { 72 | this.data = data; 73 | return this; 74 | } 75 | 76 | public JsonResultBuilder code(int code) { 77 | this.code = code; 78 | return this; 79 | } 80 | 81 | public JsonResult build() { 82 | return new JsonResult<>(this); 83 | } 84 | } 85 | 86 | public static void main(String[] args) { 87 | System.out.print(JsonResult.builder().data("asd").build().toString()); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtUserDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | import com.njtech.smartuniversity.bean.AuthorityBean; 4 | import com.njtech.smartuniversity.bean.UserBean; 5 | import com.njtech.smartuniversity.bean.UserBeanExample; 6 | import com.njtech.smartuniversity.dao.UserBeanMapper; 7 | import com.njtech.smartuniversity.service.AuthorityService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | import org.springframework.security.core.userdetails.UserDetailsService; 12 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by ritchie on 6/25/18 20 | */ 21 | @Service 22 | public class JwtUserDetailServiceImpl implements UserDetailsService { 23 | 24 | @Autowired 25 | UserBeanMapper mUserBeanMapper; 26 | 27 | @Autowired 28 | AuthorityService mAuthorityService; 29 | 30 | 31 | @Override 32 | public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { 33 | UserBeanExample userBeanExample = new UserBeanExample(); 34 | UserBeanExample.Criteria userBeanExampleCriteria = userBeanExample.createCriteria(); 35 | userBeanExampleCriteria.andIdEqualTo(s); 36 | List userBeans = mUserBeanMapper.selectByExample(userBeanExample); 37 | 38 | if (userBeans == null || userBeans.size() <= 0) { 39 | throw new UsernameNotFoundException(String.format("没有该用户 '%s'.", s)); 40 | } 41 | 42 | UserBean userBean = userBeans.get(0); 43 | return create(userBean); 44 | } 45 | 46 | 47 | private JwtUser create(UserBean user) { 48 | int auth_id = user.getAuthId(); 49 | List authorities = new ArrayList<>(); 50 | AuthorityBean authorityBean = mAuthorityService.selectByAuthorityId(auth_id); 51 | authorities.add(new SimpleGrantedAuthority(authorityBean.getAuName())); 52 | JwtUser jwtUser = new JwtUser(user); 53 | jwtUser.setAuthorities(authorities); 54 | return jwtUser; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 | 43 |
44 | 45 |
46 | 47 |
48 | 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.LoginBean; 5 | import com.njtech.smartuniversity.bean.UserBean; 6 | import com.njtech.smartuniversity.util.JsonResult; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by ritchie on 6/25/18 12 | */ 13 | public interface UserService { 14 | 15 | /** 16 | * 根据用户ID查询用户 17 | * 18 | * @param id 用户ID(学号/教师工号) 19 | * @return 20 | */ 21 | UserBean selectByUserId(String id); 22 | 23 | /** 24 | * 根据账号、密码查找用户 25 | * 26 | * @param id 27 | * @param password 28 | * @return 29 | */ 30 | UserBean selectByIdAndPassword(String id, String password); 31 | 32 | 33 | /** 34 | * 根据邮箱密码查找用户 35 | * 36 | * @param email 37 | * @param password 38 | * @return 39 | */ 40 | LoginBean loginByEmailAndPassword(String email, String password); 41 | 42 | 43 | /** 44 | * 根据账户密码查找用户 45 | * 46 | * @param account 47 | * @param password 48 | * @return 49 | */ 50 | LoginBean loginByAccountAndPassword(String account, String password); 51 | 52 | /** 53 | * 根据账号、密码登录返回token 54 | * 55 | * @param id 56 | * @param password 57 | * @return 58 | */ 59 | LoginBean login(String id, String password); 60 | 61 | 62 | /** 63 | * 修改用户信息 64 | * 65 | * @param userBean 66 | * @return 67 | */ 68 | UserBean update(UserBean userBean); 69 | 70 | 71 | /** 72 | * 获取用户列表 73 | * 74 | * @return 75 | */ 76 | List getAllUsers(); 77 | 78 | 79 | /** 80 | * 获取分页的用户列表信息 81 | * 82 | * @param pageNum 页码 83 | * @param pageSize 每页的数量 84 | * @return 85 | */ 86 | PageInfo getUsersByPage(int pageNum, int pageSize); 87 | 88 | 89 | /** 90 | * 删除用户 91 | * 92 | * @param id 93 | * @return 94 | */ 95 | boolean deleteById(String id); 96 | 97 | /** 98 | * 新增用户 99 | * 100 | * @param userBean 101 | * @return 102 | */ 103 | UserBean addUser(UserBean userBean); 104 | 105 | /** 106 | * 注册 107 | * 108 | * @param userBean 109 | * @return 110 | */ 111 | UserBean register(UserBean userBean); 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/QiniuUtil.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import com.google.gson.Gson; 4 | import com.qiniu.common.QiniuException; 5 | import com.qiniu.common.Zone; 6 | import com.qiniu.http.Response; 7 | import com.qiniu.storage.Configuration; 8 | import com.qiniu.storage.UploadManager; 9 | import com.qiniu.storage.model.DefaultPutRet; 10 | import com.qiniu.util.Auth; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.stereotype.Component; 15 | 16 | import java.io.FileInputStream; 17 | 18 | /** 19 | * Created by ritchie on 7/5/18 20 | */ 21 | @Component 22 | public class QiniuUtil { 23 | 24 | private static final Logger logger = LoggerFactory.getLogger(QiniuUtil.class); 25 | 26 | @Value("${qiniu.accessKey}") 27 | private String accessKey; 28 | 29 | @Value("${qiniu.secretKey}") 30 | private String secretKey; 31 | 32 | @Value("${qiniu.bucket}") 33 | private String bucket; 34 | 35 | @Value("${qiniu.path}") 36 | private String path; 37 | 38 | /** 39 | * 将图片上传到七牛云 40 | * 41 | * @param file 42 | * @param key 保存在空间中的名字,如果为空会使用文件的hash值为文件名 43 | * @return 44 | */ 45 | public String uploadImg(FileInputStream file, String key) { 46 | //构造一个带指定Zone对象的配置类 47 | Configuration cfg = new Configuration(Zone.huadong()); 48 | //...其他参数参考类注释 49 | UploadManager uploadManager = new UploadManager(cfg); 50 | //...生成上传凭证,然后准备上传 51 | // String bucket = "oy09glbzm.bkt.clouddn.com"; 52 | //默认不指定key的情况下,以文件内容的hash值作为文件名 53 | try { 54 | Auth auth = Auth.create(accessKey, secretKey); 55 | String upToken = auth.uploadToken(bucket); 56 | try { 57 | Response response = uploadManager.put(file, key, upToken, null, null); 58 | //解析上传成功的结果 59 | 60 | DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); 61 | System.out.println(putRet.key); 62 | System.out.println(putRet.hash); 63 | String return_path = "http://" + path + "/" + putRet.key; 64 | logger.info("保存地址={}", return_path); 65 | return return_path; 66 | } catch (QiniuException ex) { 67 | Response r = ex.response; 68 | System.err.println(r.toString()); 69 | try { 70 | System.err.println(r.bodyString()); 71 | } catch (QiniuException ex2) { 72 | //ignore 73 | } 74 | } 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | return ""; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/AuthorityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.njtech.smartuniversity.bean.AuthorityBean; 6 | import com.njtech.smartuniversity.bean.AuthorityBeanExample; 7 | import com.njtech.smartuniversity.dao.AuthorityBeanMapper; 8 | import com.njtech.smartuniversity.service.AuthorityService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by ritchie on 6/26/18 16 | */ 17 | 18 | @Service 19 | public class AuthorityServiceImpl implements AuthorityService { 20 | 21 | @Autowired 22 | AuthorityBeanMapper mAuthorityBeanMapper; 23 | 24 | 25 | @Override 26 | public AuthorityBean selectByAuthorityId(int id) { 27 | 28 | return mAuthorityBeanMapper.selectByPrimaryKey(id); 29 | } 30 | 31 | @Override 32 | public AuthorityBean update(AuthorityBean authorityBean) { 33 | int id = authorityBean.getId(); 34 | mAuthorityBeanMapper.updateByPrimaryKey(authorityBean); 35 | return mAuthorityBeanMapper.selectByPrimaryKey(id); 36 | } 37 | 38 | @Override 39 | public List getAllAuthorities() { 40 | AuthorityBeanExample authorityBeanExample = new AuthorityBeanExample(); 41 | AuthorityBeanExample.Criteria criteria = authorityBeanExample.createCriteria(); 42 | criteria.andIdIsNotNull(); 43 | return mAuthorityBeanMapper.selectByExample(authorityBeanExample); 44 | } 45 | 46 | @Override 47 | public PageInfo getAuthorityByPage(int pageNum, int pageSize) { 48 | PageHelper.startPage(pageNum, pageSize); 49 | List list = getAllAuthorities(); 50 | return new PageInfo<>(list); 51 | } 52 | 53 | @Override 54 | public boolean deleteById(int id) { 55 | int result = mAuthorityBeanMapper.deleteByPrimaryKey(id); 56 | return result != 0; 57 | } 58 | 59 | @Override 60 | public AuthorityBean addAuthority(AuthorityBean authorityBean) { 61 | mAuthorityBeanMapper.insert(authorityBean); 62 | AuthorityBeanExample example = new AuthorityBeanExample(); 63 | AuthorityBeanExample.Criteria criteria = example.createCriteria(); 64 | criteria.andAuNameEqualTo(authorityBean.getAuName()); 65 | List authorityBeanList = mAuthorityBeanMapper.selectByExample(example); 66 | if (authorityBeanList != null && authorityBeanList.size() > 0) { 67 | authorityBean = authorityBeanList.get(0); 68 | return authorityBean; 69 | // return mAuthorityBeanMapper.selectByPrimaryKey(authorityBean.getId()); 70 | } 71 | return null; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/UserBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | import java.util.Date; 4 | 5 | public class UserBean { 6 | private String uuid; 7 | 8 | private String id; 9 | 10 | private String password; 11 | 12 | private String state; 13 | 14 | private String type; 15 | 16 | private String email; 17 | 18 | private String phone; 19 | 20 | private String account; 21 | 22 | private Integer authId; 23 | 24 | private String shopType; 25 | 26 | private Date lastPasswordResetTime; 27 | 28 | public String getUuid() { 29 | return uuid; 30 | } 31 | 32 | public void setUuid(String uuid) { 33 | this.uuid = uuid == null ? null : uuid.trim(); 34 | } 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id == null ? null : id.trim(); 42 | } 43 | 44 | public String getPassword() { 45 | return password; 46 | } 47 | 48 | public void setPassword(String password) { 49 | this.password = password == null ? null : password.trim(); 50 | } 51 | 52 | public String getState() { 53 | return state; 54 | } 55 | 56 | public void setState(String state) { 57 | this.state = state == null ? null : state.trim(); 58 | } 59 | 60 | public String getType() { 61 | return type; 62 | } 63 | 64 | public void setType(String type) { 65 | this.type = type == null ? null : type.trim(); 66 | } 67 | 68 | public String getEmail() { 69 | return email; 70 | } 71 | 72 | public void setEmail(String email) { 73 | this.email = email == null ? null : email.trim(); 74 | } 75 | 76 | public String getPhone() { 77 | return phone; 78 | } 79 | 80 | public void setPhone(String phone) { 81 | this.phone = phone == null ? null : phone.trim(); 82 | } 83 | 84 | public String getAccount() { 85 | return account; 86 | } 87 | 88 | public void setAccount(String account) { 89 | this.account = account == null ? null : account.trim(); 90 | } 91 | 92 | public Integer getAuthId() { 93 | return authId; 94 | } 95 | 96 | public void setAuthId(Integer authId) { 97 | this.authId = authId; 98 | } 99 | 100 | public String getShopType() { 101 | return shopType; 102 | } 103 | 104 | public void setShopType(String shopType) { 105 | this.shopType = shopType == null ? null : shopType.trim(); 106 | } 107 | 108 | public Date getLastPasswordResetTime() { 109 | return lastPasswordResetTime; 110 | } 111 | 112 | public void setLastPasswordResetTime(Date lastPasswordResetTime) { 113 | this.lastPasswordResetTime = lastPasswordResetTime; 114 | } 115 | } -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/bean/GoodsBean.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.bean; 2 | 3 | public class GoodsBean { 4 | private Integer id; 5 | 6 | private String gName; 7 | 8 | private String gPrice; 9 | 10 | private Integer gQuantity; 11 | 12 | private String gLy; 13 | 14 | private String gVid; 15 | 16 | private String gImg; 17 | 18 | private String gSimg; 19 | 20 | private String gLabel; 21 | 22 | private String gDetails; 23 | 24 | private String gState; 25 | 26 | private String sIUuid; 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getgName() { 37 | return gName; 38 | } 39 | 40 | public void setgName(String gName) { 41 | this.gName = gName == null ? null : gName.trim(); 42 | } 43 | 44 | public String getgPrice() { 45 | return gPrice; 46 | } 47 | 48 | public void setgPrice(String gPrice) { 49 | this.gPrice = gPrice == null ? null : gPrice.trim(); 50 | } 51 | 52 | public Integer getgQuantity() { 53 | return gQuantity; 54 | } 55 | 56 | public void setgQuantity(Integer gQuantity) { 57 | this.gQuantity = gQuantity; 58 | } 59 | 60 | public String getgLy() { 61 | return gLy; 62 | } 63 | 64 | public void setgLy(String gLy) { 65 | this.gLy = gLy == null ? null : gLy.trim(); 66 | } 67 | 68 | public String getgVid() { 69 | return gVid; 70 | } 71 | 72 | public void setgVid(String gVid) { 73 | this.gVid = gVid == null ? null : gVid.trim(); 74 | } 75 | 76 | public String getgImg() { 77 | return gImg; 78 | } 79 | 80 | public void setgImg(String gImg) { 81 | this.gImg = gImg == null ? null : gImg.trim(); 82 | } 83 | 84 | public String getgSimg() { 85 | return gSimg; 86 | } 87 | 88 | public void setgSimg(String gSimg) { 89 | this.gSimg = gSimg == null ? null : gSimg.trim(); 90 | } 91 | 92 | public String getgLabel() { 93 | return gLabel; 94 | } 95 | 96 | public void setgLabel(String gLabel) { 97 | this.gLabel = gLabel == null ? null : gLabel.trim(); 98 | } 99 | 100 | public String getgDetails() { 101 | return gDetails; 102 | } 103 | 104 | public void setgDetails(String gDetails) { 105 | this.gDetails = gDetails == null ? null : gDetails.trim(); 106 | } 107 | 108 | public String getgState() { 109 | return gState; 110 | } 111 | 112 | public void setgState(String gState) { 113 | this.gState = gState == null ? null : gState.trim(); 114 | } 115 | 116 | public String getsIUuid() { 117 | return sIUuid; 118 | } 119 | 120 | public void setsIUuid(String sIUuid) { 121 | this.sIUuid = sIUuid == null ? null : sIUuid.trim(); 122 | } 123 | } -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/EmailInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.njtech.smartuniversity.bean.EmailInfoBean; 4 | import com.njtech.smartuniversity.bean.EmailInfoBeanExample; 5 | import com.njtech.smartuniversity.dao.EmailInfoBeanMapper; 6 | import com.njtech.smartuniversity.service.EmailInfoService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by ritchie on 7/2/18 14 | */ 15 | @Service 16 | public class EmailInfoServiceImpl implements EmailInfoService { 17 | 18 | @Autowired 19 | EmailInfoBeanMapper mEmailInfoBeanMapper; 20 | 21 | @Override 22 | public EmailInfoBean addEmailInfo(String email, String code) { 23 | EmailInfoBean bean = new EmailInfoBean(); 24 | bean.setEmail(email); 25 | bean.setCode(code); 26 | 27 | mEmailInfoBeanMapper.insert(bean); 28 | EmailInfoBeanExample example = new EmailInfoBeanExample(); 29 | EmailInfoBeanExample.Criteria criteria = example.createCriteria(); 30 | criteria.andEmailEqualTo(email); 31 | criteria.andCodeEqualTo(code); 32 | List emailInfoBeanList = mEmailInfoBeanMapper.selectByExample(example); 33 | if (emailInfoBeanList != null && emailInfoBeanList.size() > 0) { 34 | bean = emailInfoBeanList.get(0); 35 | return bean; 36 | } 37 | return null; 38 | } 39 | 40 | @Override 41 | public EmailInfoBean selectEmailInfo(String email, String code) { 42 | EmailInfoBeanExample example = new EmailInfoBeanExample(); 43 | EmailInfoBeanExample.Criteria criteria = example.createCriteria(); 44 | criteria.andEmailEqualTo(email); 45 | criteria.andCodeEqualTo(code); 46 | List emailInfoBeanList = mEmailInfoBeanMapper.selectByExample(example); 47 | if (emailInfoBeanList != null && emailInfoBeanList.size() > 0) { 48 | EmailInfoBean bean = emailInfoBeanList.get(0); 49 | return bean; 50 | } 51 | return null; 52 | } 53 | 54 | @Override 55 | public EmailInfoBean selectEmailInfoByEmail(String email) { 56 | EmailInfoBeanExample example = new EmailInfoBeanExample(); 57 | EmailInfoBeanExample.Criteria criteria = example.createCriteria(); 58 | criteria.andEmailEqualTo(email); 59 | List emailInfoBeanList = mEmailInfoBeanMapper.selectByExample(example); 60 | if (emailInfoBeanList != null && emailInfoBeanList.size() > 0) { 61 | EmailInfoBean bean = emailInfoBeanList.get(0); 62 | return bean; 63 | } 64 | return null; 65 | } 66 | 67 | @Override 68 | public EmailInfoBean updateEmailInfo(EmailInfoBean emailInfoBean) { 69 | int id = emailInfoBean.getId(); 70 | mEmailInfoBeanMapper.updateByPrimaryKey(emailInfoBean); 71 | return mEmailInfoBeanMapper.selectByPrimaryKey(id); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtAuthenticationTokenFilter.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 7 | import org.springframework.security.core.context.SecurityContextHolder; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.filter.OncePerRequestFilter; 13 | 14 | import javax.servlet.FilterChain; 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | 20 | /** 21 | * Created by Yuicon on 2017/5/14. 22 | * https://segmentfault.com/u/yuicon 23 | */ 24 | @SuppressWarnings("SpringJavaAutowiringInspection") 25 | @Component 26 | public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { 27 | 28 | @Qualifier("jwtUserDetailServiceImpl") 29 | @Autowired 30 | private UserDetailsService userDetailsService; 31 | 32 | @Autowired 33 | private JwtTokenUtil jwtTokenUtil; 34 | 35 | @Value("${jwt.header}") 36 | private String tokenHeader; 37 | 38 | @Value("${jwt.tokenHead}") 39 | private String tokenHead; 40 | 41 | @Override 42 | protected void doFilterInternal( 43 | HttpServletRequest request, 44 | HttpServletResponse response, 45 | FilterChain chain) throws ServletException, IOException { 46 | 47 | String authHeader = request.getHeader(this.tokenHeader); 48 | if (authHeader != null && authHeader.startsWith(tokenHead)) { 49 | final String authToken = authHeader.substring(tokenHead.length()); // The part after "Bearer " 50 | String account = jwtTokenUtil.getUsernameFromToken(authToken); 51 | 52 | logger.info("checking authentication " + account); 53 | 54 | if (account != null && SecurityContextHolder.getContext().getAuthentication() == null) { 55 | 56 | // 如果我们足够相信token中的数据,也就是我们足够相信签名token的secret的机制足够好 57 | // 这种情况下,我们可以不用再查询数据库,而直接采用token中的数据 58 | // 本例中,我们还是通过Spring Security的 @UserDetailsService 进行了数据查询 59 | // 但简单验证的话,你可以采用直接验证token是否合法来避免昂贵的数据查询 60 | UserDetails userDetails = this.userDetailsService.loadUserByUsername(account); 61 | 62 | if (jwtTokenUtil.validateToken(authToken, userDetails)) { 63 | UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( 64 | userDetails, null, userDetails.getAuthorities()); 65 | authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails( 66 | request)); 67 | logger.info("authenticated user " + account + ", setting security context"); 68 | SecurityContextHolder.getContext().setAuthentication(authentication); 69 | } 70 | } 71 | } 72 | 73 | chain.doFilter(request, response); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/util/Validator.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.util; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | /** 6 | * Created by ritchie on 7/2/18 7 | */ 8 | public class Validator { 9 | /** 10 | * 正则表达式:验证用户名(不包含中文和特殊字符)如果用户名使用手机号码或邮箱 则结合手机号验证和邮箱验证 11 | */ 12 | public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,17}$"; 13 | 14 | /** 15 | * 正则表达式:验证密码(不包含特殊字符) 16 | */ 17 | public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,16}$"; 18 | 19 | /** 20 | * 说明:移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 21 | * 联通:130、131、132、152、155、156、185、186 22 | * 电信:133、153、180、189 23 | * 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9 24 | * 验证号码 手机号 固话均可 25 | * 正则表达式:验证手机号 26 | */ 27 | public static final String REGEX_MOBILE = "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-? \\d{7,8}-(\\d{1,4})$))"; 28 | 29 | /** 30 | * 正则表达式:验证邮箱 31 | */ 32 | public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; 33 | 34 | /** 35 | * 正则表达式:验证汉字(1-9个汉字) {1,9} 自定义区间 36 | */ 37 | public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5]{1,9}$"; 38 | 39 | /** 40 | * 正则表达式:验证身份证 41 | */ 42 | public static final String REGEX_ID_CARD = "(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])"; 43 | 44 | /** 45 | * 正则表达式:验证URL 46 | */ 47 | public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"; 48 | 49 | /** 50 | * 正则表达式:验证IP地址 51 | */ 52 | public static final String REGEX_IP_ADDR = "(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})"; 53 | 54 | /** 55 | * 校验用户名 56 | * 57 | * @param username 58 | * @return 校验通过返回true,否则返回false 59 | */ 60 | public static boolean isUserName(String username) { 61 | return Pattern.matches(REGEX_USERNAME, username); 62 | } 63 | 64 | /** 65 | * 校验密码 66 | * 67 | * @param password 68 | * @return 校验通过返回true,否则返回false 69 | */ 70 | public static boolean isPassword(String password) { 71 | return Pattern.matches(REGEX_PASSWORD, password); 72 | } 73 | 74 | /** 75 | * 校验手机号 76 | * 77 | * @param mobile 78 | * @return 校验通过返回true,否则返回false 79 | */ 80 | public static boolean isMobile(String mobile) { 81 | return Pattern.matches(REGEX_MOBILE, mobile); 82 | } 83 | 84 | /** 85 | * 校验邮箱 86 | * 87 | * @param email 88 | * @return 校验通过返回true,否则返回false 89 | */ 90 | public static boolean isEmail(String email) { 91 | return Pattern.matches(REGEX_EMAIL, email); 92 | } 93 | 94 | /** 95 | * 校验汉字 96 | * 97 | * @param chinese 98 | * @return 校验通过返回true,否则返回false 99 | */ 100 | public static boolean isChinese(String chinese) { 101 | return Pattern.matches(REGEX_CHINESE, chinese); 102 | } 103 | 104 | /** 105 | * 校验身份证 106 | * 107 | * @param idCard 108 | * @return 校验通过返回true,否则返回false 109 | */ 110 | public static boolean isIDCard(String idCard) { 111 | return Pattern.matches(REGEX_ID_CARD, idCard); 112 | } 113 | 114 | /** 115 | * 校验URL 116 | * 117 | * @param url 118 | * @return 校验通过返回true,否则返回false 119 | */ 120 | public static boolean isUrl(String url) { 121 | return Pattern.matches(REGEX_URL, url); 122 | } 123 | 124 | /** 125 | * 校验IP地址 126 | * 127 | * @param ipAddress 128 | * @return 129 | */ 130 | public static boolean isIPAddress(String ipAddress) { 131 | return Pattern.matches(REGEX_IP_ADDR, ipAddress); 132 | } 133 | 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/GoodsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.njtech.smartuniversity.bean.CardBean; 6 | import com.njtech.smartuniversity.bean.CardBeanExample; 7 | import com.njtech.smartuniversity.bean.GoodsBean; 8 | import com.njtech.smartuniversity.bean.GoodsBeanExample; 9 | import com.njtech.smartuniversity.dao.CustomGoodsBeanMapper; 10 | import com.njtech.smartuniversity.dao.GoodsBeanMapper; 11 | import com.njtech.smartuniversity.service.GoodsService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by Jimmy on 22:41 2018/6/29 19 | */ 20 | @Service 21 | public class GoodsServiceImpl implements GoodsService { 22 | 23 | @Autowired 24 | GoodsBeanMapper mGoodsBeanMapper; 25 | 26 | @Autowired 27 | CustomGoodsBeanMapper mCustomGoodsBeanMapper; 28 | 29 | 30 | /** 31 | * 根据商品id查询商品信息 32 | * 33 | * @param id 34 | * @return 35 | */ 36 | @Override 37 | public GoodsBean selectByGoodsID(int id) { 38 | return mGoodsBeanMapper.selectByPrimaryKey(id); 39 | } 40 | 41 | /** 42 | * 修改商品信息 43 | * 44 | * @param goodsBean 45 | * @return 46 | */ 47 | @Override 48 | public GoodsBean update(GoodsBean goodsBean) { 49 | int id = goodsBean.getId(); 50 | mGoodsBeanMapper.updateByPrimaryKey(goodsBean); 51 | return mGoodsBeanMapper.selectByPrimaryKey(id); 52 | } 53 | 54 | /** 55 | * 获取所有商品信息列表 56 | * 57 | * @return 58 | */ 59 | @Override 60 | public List getAllGoods() { 61 | GoodsBeanExample example = new GoodsBeanExample(); 62 | GoodsBeanExample.Criteria criteria = example.createCriteria(); 63 | criteria.andIdIsNotNull(); 64 | return mGoodsBeanMapper.selectByExample(example); 65 | } 66 | 67 | @Override 68 | public List getAllAvaliableGoods() { 69 | GoodsBeanExample example = new GoodsBeanExample(); 70 | GoodsBeanExample.Criteria criteria = example.createCriteria(); 71 | criteria.andIdIsNotNull(); 72 | criteria.andGStateEqualTo("1"); 73 | return mGoodsBeanMapper.selectByExample(example); 74 | } 75 | 76 | @Override 77 | public List getShopGoods(String uuid) { 78 | GoodsBeanExample example = new GoodsBeanExample(); 79 | GoodsBeanExample.Criteria criteria = example.createCriteria(); 80 | criteria.andSIUuidEqualTo(uuid); 81 | return mGoodsBeanMapper.selectByExample(example); 82 | } 83 | 84 | @Override 85 | public List getMerchantGoods(String user_uuid) { 86 | return mCustomGoodsBeanMapper.getMerchantGoods(user_uuid); 87 | } 88 | 89 | @Override 90 | public PageInfo getGoodsByPage(int pageNum, int pageSize) { 91 | PageHelper.startPage(pageNum, pageSize); 92 | List list = getAllGoods(); 93 | return new PageInfo<>(list); 94 | } 95 | 96 | /** 97 | * 删除商品信息 98 | * 99 | * @param id 100 | * @return 101 | */ 102 | @Override 103 | public boolean deleteById(int id) { 104 | int result = mGoodsBeanMapper.deleteByPrimaryKey(id); 105 | return result != 0; 106 | } 107 | 108 | /** 109 | * 增加商品信息 110 | * 111 | * @param goodsBean 112 | * @return 113 | */ 114 | @Override 115 | public GoodsBean addGoods(GoodsBean goodsBean) { 116 | mGoodsBeanMapper.insert(goodsBean); 117 | GoodsBeanExample example = new GoodsBeanExample(); 118 | GoodsBeanExample.Criteria criteria = example.createCriteria(); 119 | criteria.andGNameEqualTo(goodsBean.getgName()); 120 | List goodsBeanList = mGoodsBeanMapper.selectByExample(example); 121 | if (goodsBeanList != null && goodsBeanList.size() > 0) { 122 | goodsBean = goodsBeanList.get(0); 123 | return goodsBean; 124 | // return mCardBeanMapper.selectByPrimaryKey(cardBean.getId()); 125 | } 126 | return null; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/ShopInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.njtech.smartuniversity.bean.ShopInfoBean; 6 | import com.njtech.smartuniversity.bean.ShopInfoBeanExample; 7 | import com.njtech.smartuniversity.dao.ShopInfoBeanMapper; 8 | import com.njtech.smartuniversity.service.ShopInfoService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Jimmy on 22:42 2018/6/29 16 | */ 17 | @Service 18 | public class ShopInfoServiceImpl implements ShopInfoService { 19 | 20 | @Autowired 21 | ShopInfoBeanMapper mShopInfoBeanMapper; 22 | 23 | 24 | /** 25 | * 根据商家名查询商家信息 26 | * 27 | * @param 28 | * @return 29 | */ 30 | @Override 31 | public ShopInfoBean selectByShopInfoName(String name) { 32 | ShopInfoBeanExample userBeanExample = new ShopInfoBeanExample(); 33 | ShopInfoBeanExample.Criteria criteria = userBeanExample.createCriteria(); 34 | criteria.andShopNameEqualTo(name); 35 | List userBeanList = mShopInfoBeanMapper.selectByExample(userBeanExample); 36 | if (userBeanList.size() > 0) 37 | return userBeanList.get(0); 38 | return null; 39 | } 40 | 41 | @Override 42 | public ShopInfoBean selectByShopInfoUUID(String uuid) { 43 | return mShopInfoBeanMapper.selectByPrimaryKey(uuid); 44 | } 45 | 46 | /** 47 | * 修改商家信息 48 | * 49 | * @param shopInfoBean 50 | * @return 51 | */ 52 | @Override 53 | public ShopInfoBean update(ShopInfoBean shopInfoBean) { 54 | String uuid = shopInfoBean.getUuid(); 55 | mShopInfoBeanMapper.updateByPrimaryKey(shopInfoBean); 56 | return mShopInfoBeanMapper.selectByPrimaryKey(uuid); 57 | } 58 | 59 | /** 60 | * 获取商家信息 61 | * 62 | * @return 63 | */ 64 | @Override 65 | public List getAllShopInfos() { 66 | ShopInfoBeanExample userBeanExample = new ShopInfoBeanExample(); 67 | ShopInfoBeanExample.Criteria criteria = userBeanExample.createCriteria(); 68 | criteria.andUuidIsNotNull(); 69 | List shopInfoBeanList = mShopInfoBeanMapper.selectByExample(userBeanExample); 70 | return shopInfoBeanList; 71 | } 72 | 73 | @Override 74 | public PageInfo getShopInfosByPage(int pageNum, int pageSize) { 75 | PageHelper.startPage(pageNum, pageSize); 76 | List list = getAllShopInfos(); 77 | return new PageInfo<>(list); 78 | } 79 | 80 | /** 81 | * 删除商家信息 82 | * 83 | * @param uuid 84 | * @return 85 | */ 86 | @Override 87 | public boolean deleteByUUId(String uuid) { 88 | int result = mShopInfoBeanMapper.deleteByPrimaryKey(uuid); 89 | return result != 0; 90 | } 91 | 92 | /** 93 | * 新增商家信息 94 | * 95 | * @param shopInfoBean 96 | * @return 97 | */ 98 | @Override 99 | public ShopInfoBean addShopInfoBean(ShopInfoBean shopInfoBean) { 100 | mShopInfoBeanMapper.insert(shopInfoBean); 101 | ShopInfoBeanExample example = new ShopInfoBeanExample(); 102 | ShopInfoBeanExample.Criteria criteria = example.createCriteria(); 103 | criteria.andUuidEqualTo(shopInfoBean.getUuid()); 104 | List shopInfoBeanList = mShopInfoBeanMapper.selectByExample(example); 105 | if (shopInfoBeanList != null && shopInfoBeanList.size() > 0) { 106 | shopInfoBean = shopInfoBeanList.get(0); 107 | return shopInfoBean; 108 | // return mCardBeanMapper.selectByPrimaryKey(cardBean.getId()); 109 | } 110 | return null; 111 | } 112 | 113 | @Override 114 | public List selectbyUserUUid(String uuid) { 115 | ShopInfoBeanExample example = new ShopInfoBeanExample(); 116 | ShopInfoBeanExample.Criteria criteria = example.createCriteria(); 117 | criteria.andUserUuidEqualTo(uuid); 118 | List shopInfoBeanList = mShopInfoBeanMapper.selectByExample(example); 119 | return shopInfoBeanList; 120 | } 121 | 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/CardServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.njtech.smartuniversity.bean.CardBean; 6 | import com.njtech.smartuniversity.bean.CardBeanExample; 7 | import com.njtech.smartuniversity.dao.CardBeanMapper; 8 | import com.njtech.smartuniversity.service.CardService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Jimmy on 22:40 2018/6/29 16 | */ 17 | @Service 18 | public class CardServiceImpl implements CardService { 19 | 20 | @Autowired 21 | CardBeanMapper mCardBeanMapper; 22 | 23 | 24 | /** 25 | * 根据卡号id 查询一卡通信息 26 | * 27 | * @param id 28 | * @return 29 | */ 30 | @Override 31 | public CardBean selectByCardId(int id) { 32 | return mCardBeanMapper.selectByPrimaryKey(id); 33 | } 34 | 35 | @Override 36 | public CardBean selectBySQId(String sqID) { 37 | CardBeanExample cardBeanExample = new CardBeanExample(); 38 | CardBeanExample.Criteria criteria = cardBeanExample.createCriteria(); 39 | criteria.andSqIdEqualTo(sqID); 40 | List list = mCardBeanMapper.selectByExample(cardBeanExample); 41 | if (list != null && list.size() > 0) 42 | return list.get(0); 43 | return null; 44 | } 45 | 46 | /** 47 | * 修改一卡通信息 48 | * 49 | * @param cardBean 50 | * @return 51 | */ 52 | @Override 53 | public CardBean update(CardBean cardBean) { 54 | int id = cardBean.getId(); 55 | mCardBeanMapper.updateByPrimaryKey(cardBean); 56 | return mCardBeanMapper.selectByPrimaryKey(id); 57 | } 58 | 59 | 60 | /** 61 | * 获取一卡通列表 62 | * 63 | * @return 64 | */ 65 | @Override 66 | public List getAllCards() { 67 | CardBeanExample cardBeanExample = new CardBeanExample(); 68 | CardBeanExample.Criteria criteria = cardBeanExample.createCriteria(); 69 | criteria.andIdIsNotNull(); 70 | return mCardBeanMapper.selectByExample(cardBeanExample); 71 | } 72 | 73 | @Override 74 | public List getAllUnpassCards() { 75 | CardBeanExample cardBeanExample = new CardBeanExample(); 76 | CardBeanExample.Criteria criteria = cardBeanExample.createCriteria(); 77 | criteria.andStateEqualTo("0"); 78 | return mCardBeanMapper.selectByExample(cardBeanExample); 79 | } 80 | 81 | @Override 82 | public long getUnpassCount() { 83 | CardBeanExample cardBeanExample = new CardBeanExample(); 84 | CardBeanExample.Criteria criteria = cardBeanExample.createCriteria(); 85 | criteria.andStateEqualTo("0"); 86 | return mCardBeanMapper.countByExample(cardBeanExample); 87 | } 88 | 89 | @Override 90 | public long getTotalCount() { 91 | CardBeanExample cardBeanExample = new CardBeanExample(); 92 | CardBeanExample.Criteria criteria = cardBeanExample.createCriteria(); 93 | criteria.andIdIsNotNull(); 94 | return mCardBeanMapper.countByExample(cardBeanExample); 95 | } 96 | 97 | 98 | @Override 99 | public PageInfo getCardsByPage(int pageNum, int pageSize) { 100 | PageHelper.startPage(pageNum, pageSize); 101 | List list = getAllCards(); 102 | return new PageInfo<>(list); 103 | } 104 | 105 | /** 106 | * 删除一卡通用户 107 | * 108 | * @param id 109 | * @return 110 | */ 111 | @Override 112 | public boolean deleteById(int id) { 113 | int result = mCardBeanMapper.deleteByPrimaryKey(id); 114 | return result != 0; 115 | } 116 | 117 | /** 118 | * 新增一卡通信息 119 | * 120 | * @param cardBean 121 | * @return 122 | */ 123 | @Override 124 | public CardBean addCard(CardBean cardBean) { 125 | mCardBeanMapper.insert(cardBean); 126 | CardBeanExample example = new CardBeanExample(); 127 | CardBeanExample.Criteria criteria = example.createCriteria(); 128 | criteria.andCardVidEqualTo(cardBean.getCardVid()); 129 | List cardBeanList = mCardBeanMapper.selectByExample(example); 130 | if (cardBeanList != null && cardBeanList.size() > 0) { 131 | cardBean = cardBeanList.get(0); 132 | return cardBean; 133 | } 134 | return null; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config; 2 | 3 | import com.njtech.smartuniversity.config.security.JwtAuthenticationEntryPoint; 4 | import com.njtech.smartuniversity.config.security.JwtAuthenticationTokenFilter; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.http.HttpMethod; 10 | import org.springframework.security.authentication.AuthenticationManager; 11 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 12 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 14 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 15 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 16 | import org.springframework.security.config.http.SessionCreationPolicy; 17 | import org.springframework.security.core.userdetails.UserDetailsService; 18 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 19 | import org.springframework.security.crypto.password.PasswordEncoder; 20 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 21 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 22 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 23 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 24 | 25 | /** 26 | * Created by ritchie on 6/25/18 27 | */ 28 | @Configuration 29 | @EnableWebSecurity 30 | @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, jsr250Enabled = true) 31 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 32 | @Qualifier("jwtUserDetailServiceImpl") 33 | @Autowired 34 | UserDetailsService mUserDetailsService; 35 | 36 | @Autowired 37 | private JwtAuthenticationEntryPoint unauthorizedHandler; 38 | 39 | 40 | @Override 41 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 42 | auth.userDetailsService(mUserDetailsService).passwordEncoder(passwordEncoder()); 43 | } 44 | 45 | @Bean 46 | @Override 47 | public AuthenticationManager authenticationManagerBean() throws Exception { 48 | return super.authenticationManagerBean(); 49 | } 50 | 51 | // 装载BCrypt密码编码器 52 | @Bean 53 | public PasswordEncoder passwordEncoder() { 54 | return new BCryptPasswordEncoder(); 55 | } 56 | 57 | 58 | @Bean 59 | public JwtAuthenticationTokenFilter authenticationTokenFilterBean() throws Exception { 60 | return new JwtAuthenticationTokenFilter(); 61 | } 62 | 63 | @Bean 64 | public WebMvcConfigurer corsConfigurer() { 65 | return new WebMvcConfigurerAdapter() { 66 | @Override 67 | public void addCorsMappings(CorsRegistry registry) { 68 | registry.addMapping("/**").allowedOrigins("*") 69 | .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") 70 | .allowCredentials(false).maxAge(3600); 71 | } 72 | }; 73 | 74 | } 75 | 76 | @Override 77 | protected void configure(HttpSecurity httpSecurity) throws Exception { 78 | httpSecurity 79 | // 由于使用的是JWT,我们这里不需要csrf 80 | .csrf().disable() 81 | 82 | .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() 83 | 84 | // 基于token,所以不需要session 85 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 86 | 87 | .authorizeRequests() 88 | .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 89 | 90 | // 允许对于网站静态资源的无授权访问 91 | .antMatchers( 92 | HttpMethod.GET, 93 | "/", 94 | "/*.html", 95 | "/favicon.ico", 96 | "/**/*.html", 97 | "/**/*.css", 98 | "/**/*.js", 99 | "/webjars/**", 100 | "/swagger-resources/**", 101 | "/*/api-docs" 102 | ).permitAll() 103 | // 对于获取token的rest api要允许匿名访问 104 | .antMatchers("/api/auth/**").permitAll() 105 | .antMatchers("/druid/**").permitAll() 106 | // .antMatchers("/users/login**","/users/register**").permitAll() 107 | // .antMatchers(HttpMethod.GET, "/entries/**", "/articles/**").permitAll() 108 | // 除上面外的所有请求全部需要鉴权认证 109 | .anyRequest().authenticated(); 110 | 111 | // 添加JWT filter 112 | httpSecurity 113 | .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); 114 | 115 | // 禁用缓存 116 | httpSecurity.headers().cacheControl(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.njtech.smartuniversity.bean.CustomGoodsBean; 6 | import com.njtech.smartuniversity.bean.GoodsBean; 7 | import com.njtech.smartuniversity.bean.OrderBean; 8 | import com.njtech.smartuniversity.bean.OrderBeanExample; 9 | import com.njtech.smartuniversity.dao.CustomOrdersBeanMapper; 10 | import com.njtech.smartuniversity.dao.GoodsBeanMapper; 11 | import com.njtech.smartuniversity.dao.OrderBeanMapper; 12 | import com.njtech.smartuniversity.service.OrderService; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by Jimmy on 22:41 2018/6/29 21 | */ 22 | @Service 23 | public class OrderServiceImpl implements OrderService { 24 | 25 | @Autowired 26 | OrderBeanMapper mOrderBeanMapper; 27 | 28 | 29 | @Autowired 30 | GoodsBeanMapper mGoodsBeanMapper; 31 | 32 | @Autowired 33 | CustomOrdersBeanMapper mCustomOrdersBeanMapper; 34 | 35 | 36 | /** 37 | * 根据id查询订单信息 38 | * 39 | * @param id 40 | * @return 41 | */ 42 | @Override 43 | public OrderBean selecteByOrderId(int id) { 44 | return mOrderBeanMapper.selectByPrimaryKey(id); 45 | } 46 | 47 | /** 48 | * 修改订单信息 49 | * 50 | * @param orderBean 51 | * @return 52 | */ 53 | @Override 54 | public OrderBean update(OrderBean orderBean) { 55 | int id = orderBean.getgId(); 56 | mOrderBeanMapper.updateByPrimaryKey(orderBean); 57 | return mOrderBeanMapper.selectByPrimaryKey(id); 58 | } 59 | 60 | /** 61 | * 获取所有订单信息列表 62 | * 63 | * @return 64 | */ 65 | @Override 66 | public List getAllOrders() { 67 | OrderBeanExample example = new OrderBeanExample(); 68 | OrderBeanExample.Criteria criteria = example.createCriteria(); 69 | criteria.andIdIsNotNull(); 70 | List list = mOrderBeanMapper.selectByExample(example); 71 | return list; 72 | } 73 | 74 | @Override 75 | public List getUserOrders(String user_uuid) { 76 | OrderBeanExample example = new OrderBeanExample(); 77 | OrderBeanExample.Criteria criteria = example.createCriteria(); 78 | criteria.andUserUuidEqualTo(user_uuid); 79 | return mOrderBeanMapper.selectByExample(example); 80 | } 81 | 82 | @Override 83 | public PageInfo getOrdersByPage(int pageNum, int pageSize) { 84 | PageHelper.startPage(pageNum, pageSize); 85 | List list = getAllOrders(); 86 | return new PageInfo<>(list); 87 | } 88 | 89 | @Override 90 | public PageInfo getHotOrdersByPage(int pageNum, int pageSize) { 91 | PageHelper.startPage(pageNum, pageSize); 92 | List list = mCustomOrdersBeanMapper.getHotGoods(); 93 | List customGoodsBeanList = new ArrayList<>(list.size()); 94 | for (int i = 0; i < list.size(); i++) { 95 | CustomGoodsBean goodsBean = new CustomGoodsBean(); 96 | goodsBean.setGoodsBean(list.get(i)); 97 | goodsBean.setRank(i + 1); 98 | customGoodsBeanList.add(goodsBean); 99 | } 100 | return new PageInfo<>(customGoodsBeanList); 101 | } 102 | 103 | 104 | /** 105 | * 删除订单信息 106 | * 107 | * @param id 108 | * @return 109 | */ 110 | @Override 111 | public boolean deleteById(int id) { 112 | int result = mOrderBeanMapper.deleteByPrimaryKey(id); 113 | return result != 0; 114 | } 115 | 116 | /** 117 | * 新增订单 118 | * 119 | * @param orderBean 120 | * @return 121 | */ 122 | @Override 123 | public OrderBean addOrderBean(OrderBean orderBean) { 124 | mOrderBeanMapper.insert(orderBean); 125 | OrderBeanExample example = new OrderBeanExample(); 126 | OrderBeanExample.Criteria criteria = example.createCriteria(); 127 | criteria.andUserUuidEqualTo(orderBean.getUserUuid()); 128 | criteria.andGIdEqualTo(orderBean.getgId()); 129 | int good_id = orderBean.getgId(); 130 | GoodsBean goodsBean = mGoodsBeanMapper.selectByPrimaryKey(good_id); 131 | int num = goodsBean.getgQuantity(); 132 | int new_num = num - orderBean.getNum(); 133 | if (new_num < 0) { 134 | return null; 135 | } else if (new_num == 0) { 136 | //缺货 137 | goodsBean.setgState("-1"); 138 | } 139 | goodsBean.setgQuantity(new_num); 140 | mGoodsBeanMapper.updateByPrimaryKey(goodsBean); 141 | List orderBeanList = mOrderBeanMapper.selectByExample(example); 142 | if (orderBeanList != null && orderBeanList.size() > 0) { 143 | orderBean = orderBeanList.get(0); 144 | return orderBean; 145 | // return mCardBeanMapper.selectByPrimaryKey(cardBean.getId()); 146 | } 147 | return null; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/config/security/JwtTokenUtil.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config.security; 2 | 3 | 4 | import com.njtech.smartuniversity.config.security.JwtUser; 5 | import com.njtech.smartuniversity.util.JwtConfig; 6 | import io.jsonwebtoken.Claims; 7 | import io.jsonwebtoken.Jwts; 8 | import io.jsonwebtoken.SignatureAlgorithm; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.beans.factory.annotation.Value; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Date; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | 19 | /** 20 | * Created by ritchie on 6/26/18 21 | */ 22 | @Component 23 | public class JwtTokenUtil { 24 | 25 | @Autowired 26 | JwtConfig mJwtConfig; 27 | 28 | 29 | private static final long serialVersionUID = -3301605591108950415L; 30 | 31 | private static final String CLAIM_KEY_USERNAME = "sub"; 32 | private static final String CLAIM_KEY_CREATED = "created"; 33 | 34 | @Value("${jwt.secret}") 35 | private String secret; 36 | 37 | @Value("${jwt.expiration}") 38 | private Long expiration; 39 | 40 | public String getUsernameFromToken(String token) { 41 | String username; 42 | try { 43 | final Claims claims = getClaimsFromToken(token); 44 | username = claims.getSubject(); 45 | } catch (Exception e) { 46 | username = null; 47 | } 48 | return username; 49 | } 50 | 51 | private Date getCreatedDateFromToken(String token) { 52 | Date created; 53 | try { 54 | final Claims claims = getClaimsFromToken(token); 55 | created = new Date((Long) claims.get(CLAIM_KEY_CREATED)); 56 | } catch (Exception e) { 57 | created = null; 58 | } 59 | return created; 60 | } 61 | 62 | private Date getExpirationDateFromToken(String token) { 63 | Date expiration; 64 | try { 65 | final Claims claims = getClaimsFromToken(token); 66 | expiration = claims.getExpiration(); 67 | } catch (Exception e) { 68 | expiration = null; 69 | } 70 | return expiration; 71 | } 72 | 73 | private Claims getClaimsFromToken(String token) { 74 | Claims claims; 75 | try { 76 | claims = Jwts.parser() 77 | .setSigningKey(secret) 78 | .parseClaimsJws(token) 79 | .getBody(); 80 | } catch (Exception e) { 81 | claims = null; 82 | } 83 | return claims; 84 | } 85 | 86 | private Boolean ignoreTokenExpiration(String token) { 87 | // here you specify tokens, for that the expiration is ignored 88 | return false; 89 | } 90 | 91 | 92 | private Date generateExpirationDate() { 93 | return new Date(System.currentTimeMillis() + expiration * 1000); 94 | } 95 | 96 | private Boolean isTokenExpired(String token) { 97 | final Date expiration = getExpirationDateFromToken(token); 98 | return expiration.before(new Date()); 99 | } 100 | 101 | private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) { 102 | return (lastPasswordReset != null && created.before(lastPasswordReset)); 103 | } 104 | 105 | public String generateToken(UserDetails userDetails) { 106 | Map claims = new HashMap<>(); 107 | claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); 108 | claims.put(CLAIM_KEY_CREATED, new Date()); 109 | return generateToken(claims); 110 | } 111 | 112 | private String generateToken(Map claims) { 113 | return Jwts.builder() 114 | .setClaims(claims) 115 | .setExpiration(generateExpirationDate()) 116 | .signWith(SignatureAlgorithm.HS512, secret) 117 | .compact(); 118 | } 119 | 120 | public Boolean canTokenBeRefreshed(String token, Date lastPasswordReset) { 121 | final Date created = getCreatedDateFromToken(token); 122 | return !isCreatedBeforeLastPasswordReset(created, lastPasswordReset) 123 | && (!isTokenExpired(token)|| ignoreTokenExpiration(token)); 124 | } 125 | 126 | public String refreshToken(String token) { 127 | String refreshedToken; 128 | try { 129 | final Claims claims = getClaimsFromToken(token); 130 | claims.put(CLAIM_KEY_CREATED, new Date()); 131 | refreshedToken = generateToken(claims); 132 | } catch (Exception e) { 133 | refreshedToken = null; 134 | } 135 | return refreshedToken; 136 | } 137 | 138 | Boolean validateToken(String token, UserDetails userDetails) { 139 | JwtUser user = (JwtUser) userDetails; 140 | final String username = getUsernameFromToken(token); 141 | final Date created = getCreatedDateFromToken(token); 142 | //final Date expiration = getExpirationDateFromToken(token); 143 | return ( 144 | username.equals(user.getUsername()) 145 | && !isTokenExpired(token) 146 | && !isCreatedBeforeLastPasswordReset(created, user.getLastPasswordResetTime()) 147 | ); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /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/njtech/smartuniversity/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.context.request.async.DeferredResult; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.*; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spi.service.contexts.SecurityContext; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | import java.util.List; 16 | 17 | import static com.google.common.collect.Lists.newArrayList; 18 | 19 | @Configuration 20 | @EnableSwagger2 21 | public class SwaggerConfig { 22 | 23 | private static final String VERSION = "1.0"; 24 | private static final String TITLE = "智慧校园API接口文档"; 25 | private static final String DESCRIPTION = "智能校园API接口文档说明"; 26 | private static final String STUDENT_DESCRIPTION = "智能校园学生API接口文档说明"; 27 | private static final String TEACHER_DESCRIPTION = "智能校园教师API接口文档说明"; 28 | 29 | 30 | /** 31 | * 通用API 32 | * 33 | * @return 通用API 34 | */ 35 | @Bean(value = "generalAPI") 36 | public Docket createRestApi() { 37 | return new Docket(DocumentationType.SWAGGER_2) 38 | .apiInfo(apiInfo()) 39 | .select() 40 | .apis(RequestHandlerSelectors.basePackage("com.njtech.smartuniversity.controller")) 41 | .paths(PathSelectors.any()) 42 | .build() 43 | .securitySchemes(securitySchemes()) 44 | .securityContexts(securityContexts()); 45 | } 46 | 47 | 48 | // /** 49 | // * 学生API 50 | // * 51 | // * @return 学生API 52 | // */ 53 | // @Bean(value = "studentAPI") 54 | // public Docket studentAPI() { 55 | // return new Docket(DocumentationType.SWAGGER_2) 56 | // .apiInfo(studentApiInfo()) 57 | // .groupName("学生") 58 | // .select() 59 | // .apis(RequestHandlerSelectors.any()) 60 | // .paths(PathSelectors.any()) 61 | // .build() 62 | // .securitySchemes(securitySchemes()) 63 | // .securityContexts(securityContexts()); 64 | // } 65 | // 66 | // /** 67 | // * 教师API 68 | // * 69 | // * @return 教师API 70 | // */ 71 | // @Bean(value = "teacherAPI") 72 | // public Docket teacherAPI() { 73 | // return new Docket(DocumentationType.SWAGGER_2) 74 | // .apiInfo(apiInfo()) 75 | // .groupName("教师") 76 | // .select() 77 | // .apis(RequestHandlerSelectors.basePackage("com.njtech.smartuniversity.controller")) 78 | // .paths(PathSelectors.any()) 79 | // .build() 80 | // .securitySchemes(securitySchemes()) 81 | // .securityContexts(securityContexts()); 82 | // } 83 | 84 | /** 85 | * 配置认证模式 86 | */ 87 | private List securitySchemes() { 88 | return newArrayList(new ApiKey("Authorization", "Authorization", "header")); 89 | } 90 | 91 | /** 92 | * 配置认证上下文 93 | */ 94 | private List securityContexts() { 95 | return newArrayList(SecurityContext.builder() 96 | .securityReferences(defaultAuth()) 97 | .forPaths(PathSelectors.any()) 98 | .build()); 99 | } 100 | 101 | private List defaultAuth() { 102 | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); 103 | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; 104 | authorizationScopes[0] = authorizationScope; 105 | return newArrayList(new SecurityReference("Authorization", authorizationScopes)); 106 | } 107 | 108 | /** 109 | * 项目信息 110 | */ 111 | private ApiInfo apiInfo() { 112 | return new ApiInfoBuilder() 113 | .title(TITLE) 114 | .version(VERSION) 115 | .description(DESCRIPTION) 116 | // .contact(new Contact("ritchie", "https://github.com/RITCHIEHuang", 117 | // "ritchie445412@gmail.com")) 118 | .termsOfServiceUrl("http://localhost/") 119 | .build(); 120 | } 121 | 122 | /** 123 | * student信息 124 | */ 125 | private ApiInfo studentApiInfo() { 126 | return new ApiInfoBuilder() 127 | .title(TITLE) 128 | .version(VERSION) 129 | .description(STUDENT_DESCRIPTION) 130 | // .contact(new Contact("ritchie", "https://github.com/RITCHIEHuang", 131 | // "ritchie445412@gmail.com")) 132 | .termsOfServiceUrl("http://localhost/") 133 | .build(); 134 | } 135 | 136 | 137 | /** 138 | * teacher信息 139 | */ 140 | private ApiInfo teacherApiInfo() { 141 | return new ApiInfoBuilder() 142 | .title(TITLE) 143 | .version(VERSION) 144 | .description(TEACHER_DESCRIPTION) 145 | .contact(new Contact("ritchie", "https://github.com/RITCHIEHuang", 146 | "ritchie445412@gmail.com")) 147 | .termsOfServiceUrl("http://localhost/") 148 | .build(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.njtech 7 | smartuniversity 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | smartuniversity 12 | smartUniversity based on Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 2.7.0 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-security 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-thymeleaf 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | org.mybatis.spring.boot 43 | mybatis-spring-boot-starter 44 | 1.3.2 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-configuration-processor 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-aop 53 | 54 | 55 | mysql 56 | mysql-connector-java 57 | runtime 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | org.springframework.restdocs 66 | spring-restdocs-mockmvc 67 | test 68 | 69 | 70 | org.springframework.security 71 | spring-security-test 72 | test 73 | 74 | 75 | 76 | 77 | com.github.pagehelper 78 | pagehelper-spring-boot-starter 79 | 1.2.5 80 | 81 | 82 | 83 | tk.mybatis 84 | mapper-spring-boot-starter 85 | 1.2.4 86 | 87 | 88 | 89 | 90 | com.alibaba 91 | druid-spring-boot-starter 92 | 1.1.9 93 | 94 | 95 | 96 | io.springfox 97 | springfox-swagger2 98 | ${swagger.version} 99 | 100 | 101 | 102 | io.springfox 103 | springfox-swagger-ui 104 | ${swagger.version} 105 | 106 | 107 | com.github.ohcomeyes 108 | swagger-ui-layer 109 | 1.2 110 | 111 | 112 | com.github.xiaoymin 113 | swagger-bootstrap-ui 114 | 1.6 115 | 116 | 117 | 118 | 119 | 120 | io.jsonwebtoken 121 | jjwt 122 | 0.9.0 123 | 124 | 125 | 126 | 127 | com.google.code.gson 128 | gson 129 | 2.8.5 130 | 131 | 132 | 133 | org.springframework.boot 134 | spring-boot-starter-mail 135 | 136 | 137 | 138 | 139 | com.qiniu 140 | qiniu-java-sdk 141 | 7.2.14 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | org.springframework.boot 151 | spring-boot-maven-plugin 152 | 153 | 154 | 155 | 156 | 157 | org.mybatis.generator 158 | mybatis-generator-maven-plugin 159 | 1.3.6 160 | 161 | true 162 | true 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /src/main/resources/mapper/AuthorityBeanMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | and ${criterion.condition} 18 | 19 | 20 | and ${criterion.condition} #{criterion.value} 21 | 22 | 23 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 24 | 25 | 26 | and ${criterion.condition} 27 | 28 | #{listItem} 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | and ${criterion.condition} 47 | 48 | 49 | and ${criterion.condition} #{criterion.value} 50 | 51 | 52 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 53 | 54 | 55 | and ${criterion.condition} 56 | 57 | #{listItem} 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | id, au_name, au_details 69 | 70 | 84 | 90 | 91 | delete from authority 92 | where id = #{id,jdbcType=INTEGER} 93 | 94 | 95 | delete from authority 96 | 97 | 98 | 99 | 100 | 101 | insert into authority (id, au_name, au_details 102 | ) 103 | values (#{id,jdbcType=INTEGER}, #{auName,jdbcType=VARCHAR}, #{auDetails,jdbcType=VARCHAR} 104 | ) 105 | 106 | 107 | insert into authority 108 | 109 | 110 | id, 111 | 112 | 113 | au_name, 114 | 115 | 116 | au_details, 117 | 118 | 119 | 120 | 121 | #{id,jdbcType=INTEGER}, 122 | 123 | 124 | #{auName,jdbcType=VARCHAR}, 125 | 126 | 127 | #{auDetails,jdbcType=VARCHAR}, 128 | 129 | 130 | 131 | 137 | 138 | update authority 139 | 140 | 141 | id = #{record.id,jdbcType=INTEGER}, 142 | 143 | 144 | au_name = #{record.auName,jdbcType=VARCHAR}, 145 | 146 | 147 | au_details = #{record.auDetails,jdbcType=VARCHAR}, 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | update authority 156 | set id = #{record.id,jdbcType=INTEGER}, 157 | au_name = #{record.auName,jdbcType=VARCHAR}, 158 | au_details = #{record.auDetails,jdbcType=VARCHAR} 159 | 160 | 161 | 162 | 163 | 164 | update authority 165 | 166 | 167 | au_name = #{auName,jdbcType=VARCHAR}, 168 | 169 | 170 | au_details = #{auDetails,jdbcType=VARCHAR}, 171 | 172 | 173 | where id = #{id,jdbcType=INTEGER} 174 | 175 | 176 | update authority 177 | set au_name = #{auName,jdbcType=VARCHAR}, 178 | au_details = #{auDetails,jdbcType=VARCHAR} 179 | where id = #{id,jdbcType=INTEGER} 180 | 181 | -------------------------------------------------------------------------------- /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/resources/mapper/OrderBeanMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | and ${criterion.condition} 19 | 20 | 21 | and ${criterion.condition} #{criterion.value} 22 | 23 | 24 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 25 | 26 | 27 | and ${criterion.condition} 28 | 29 | #{listItem} 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | and ${criterion.condition} 48 | 49 | 50 | and ${criterion.condition} #{criterion.value} 51 | 52 | 53 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 54 | 55 | 56 | and ${criterion.condition} 57 | 58 | #{listItem} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | id, user_uuid, g_id, num 70 | 71 | 85 | 91 | 92 | delete from orders 93 | where id = #{id,jdbcType=INTEGER} 94 | 95 | 96 | delete from orders 97 | 98 | 99 | 100 | 101 | 102 | insert into orders (id, user_uuid, g_id, 103 | num) 104 | values (#{id,jdbcType=INTEGER}, #{userUuid,jdbcType=VARCHAR}, #{gId,jdbcType=INTEGER}, 105 | #{num,jdbcType=INTEGER}) 106 | 107 | 108 | insert into orders 109 | 110 | 111 | id, 112 | 113 | 114 | user_uuid, 115 | 116 | 117 | g_id, 118 | 119 | 120 | num, 121 | 122 | 123 | 124 | 125 | #{id,jdbcType=INTEGER}, 126 | 127 | 128 | #{userUuid,jdbcType=VARCHAR}, 129 | 130 | 131 | #{gId,jdbcType=INTEGER}, 132 | 133 | 134 | #{num,jdbcType=INTEGER}, 135 | 136 | 137 | 138 | 144 | 145 | update orders 146 | 147 | 148 | id = #{record.id,jdbcType=INTEGER}, 149 | 150 | 151 | user_uuid = #{record.userUuid,jdbcType=VARCHAR}, 152 | 153 | 154 | g_id = #{record.gId,jdbcType=INTEGER}, 155 | 156 | 157 | num = #{record.num,jdbcType=INTEGER}, 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | update orders 166 | set id = #{record.id,jdbcType=INTEGER}, 167 | user_uuid = #{record.userUuid,jdbcType=VARCHAR}, 168 | g_id = #{record.gId,jdbcType=INTEGER}, 169 | num = #{record.num,jdbcType=INTEGER} 170 | 171 | 172 | 173 | 174 | 175 | update orders 176 | 177 | 178 | user_uuid = #{userUuid,jdbcType=VARCHAR}, 179 | 180 | 181 | g_id = #{gId,jdbcType=INTEGER}, 182 | 183 | 184 | num = #{num,jdbcType=INTEGER}, 185 | 186 | 187 | where id = #{id,jdbcType=INTEGER} 188 | 189 | 190 | update orders 191 | set user_uuid = #{userUuid,jdbcType=VARCHAR}, 192 | g_id = #{gId,jdbcType=INTEGER}, 193 | num = #{num,jdbcType=INTEGER} 194 | where id = #{id,jdbcType=INTEGER} 195 | 196 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.service.impl; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.github.pagehelper.PageInfo; 6 | import com.njtech.smartuniversity.bean.AuthTokenBean; 7 | import com.njtech.smartuniversity.bean.LoginBean; 8 | import com.njtech.smartuniversity.bean.UserBean; 9 | import com.njtech.smartuniversity.bean.UserBeanExample; 10 | import com.njtech.smartuniversity.config.security.JwtTokenUtil; 11 | import com.njtech.smartuniversity.config.security.JwtUserDetailServiceImpl; 12 | import com.njtech.smartuniversity.dao.UserBeanMapper; 13 | import com.njtech.smartuniversity.service.UserService; 14 | import com.njtech.smartuniversity.util.JsonResult; 15 | import com.njtech.smartuniversity.util.JsonUtil; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.beans.factory.annotation.Qualifier; 18 | import org.springframework.security.authentication.AuthenticationManager; 19 | import org.springframework.security.authentication.BadCredentialsException; 20 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 21 | import org.springframework.security.core.Authentication; 22 | import org.springframework.security.core.context.SecurityContextHolder; 23 | import org.springframework.security.core.userdetails.UserDetails; 24 | import org.springframework.security.core.userdetails.UserDetailsService; 25 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 26 | import org.springframework.stereotype.Service; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | /** 32 | * Created by ritchie on 6/25/18 33 | */ 34 | @Service 35 | public class UserServiceImpl implements UserService { 36 | 37 | @Autowired 38 | UserBeanMapper mUserBeanMapper; 39 | 40 | private AuthenticationManager authenticationManager; 41 | private JwtTokenUtil jwtTokenUtil; 42 | private UserDetailsService userDetailsService; 43 | 44 | 45 | @Autowired 46 | public UserServiceImpl(AuthenticationManager authenticationManager, JwtTokenUtil jwtTokenUtil, @Qualifier("jwtUserDetailServiceImpl") UserDetailsService userDetailsService) { 47 | this.authenticationManager = authenticationManager; 48 | this.jwtTokenUtil = jwtTokenUtil; 49 | this.userDetailsService = userDetailsService; 50 | } 51 | 52 | @Override 53 | public UserBean selectByUserId(String id) { 54 | UserBeanExample userBeanExample = new UserBeanExample(); 55 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 56 | criteria.andIdEqualTo(id); 57 | List userBeanList = mUserBeanMapper.selectByExample(userBeanExample); 58 | if (userBeanList.size() > 0) 59 | return userBeanList.get(0); 60 | return null; 61 | } 62 | 63 | @Override 64 | public UserBean selectByIdAndPassword(String id, String password) { 65 | UserBeanExample userBeanExample = new UserBeanExample(); 66 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 67 | criteria.andIdEqualTo(id); 68 | criteria.andPasswordEqualTo(password); 69 | List userBeanList = mUserBeanMapper.selectByExample(userBeanExample); 70 | if (userBeanList.size() > 0) 71 | return userBeanList.get(0); 72 | return null; 73 | } 74 | 75 | @Override 76 | public LoginBean loginByEmailAndPassword(String email, String password) { 77 | UserBeanExample userBeanExample = new UserBeanExample(); 78 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 79 | criteria.andEmailEqualTo(email); 80 | List userBeanList = mUserBeanMapper.selectByExample(userBeanExample); 81 | if (userBeanList.size() > 0) { 82 | String id = userBeanList.get(0).getId(); 83 | return login(id, password); 84 | 85 | } 86 | return null; 87 | 88 | } 89 | 90 | @Override 91 | public LoginBean loginByAccountAndPassword(String account, String password) { 92 | UserBeanExample userBeanExample = new UserBeanExample(); 93 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 94 | criteria.andAccountEqualTo(account); 95 | List userBeanList = mUserBeanMapper.selectByExample(userBeanExample); 96 | if (userBeanList.size() > 0) { 97 | String id = userBeanList.get(0).getId(); 98 | return login(id, password); 99 | } 100 | return null; 101 | 102 | } 103 | 104 | 105 | @Override 106 | public UserBean update(UserBean userBean) { 107 | String uuid = userBean.getUuid(); 108 | mUserBeanMapper.updateByPrimaryKey(userBean); 109 | return mUserBeanMapper.selectByPrimaryKey(uuid); 110 | } 111 | 112 | @Override 113 | public List getAllUsers() { 114 | UserBeanExample userBeanExample = new UserBeanExample(); 115 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 116 | criteria.andUuidIsNotNull(); 117 | return mUserBeanMapper.selectByExample(userBeanExample); 118 | } 119 | 120 | @Override 121 | public PageInfo getUsersByPage(int pageNum, int pageSize) { 122 | PageHelper.startPage(pageNum, pageSize); 123 | List list = getAllUsers();//这个查询会分页 124 | return new PageInfo<>(list); 125 | } 126 | 127 | @Override 128 | public boolean deleteById(String id) { 129 | UserBeanExample userBeanExample = new UserBeanExample(); 130 | UserBeanExample.Criteria criteria = userBeanExample.createCriteria(); 131 | criteria.andIdEqualTo(id); 132 | int result = mUserBeanMapper.deleteByExample(userBeanExample); 133 | return result != 0; 134 | } 135 | 136 | @Override 137 | public UserBean addUser(UserBean userBean) { 138 | return getUserBean(userBean); 139 | } 140 | 141 | @Override 142 | public LoginBean login(String id, String password) { 143 | UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(id, password); 144 | try { 145 | final Authentication authentication = authenticationManager.authenticate(upToken); 146 | SecurityContextHolder.getContext().setAuthentication(authentication); 147 | final UserDetails userDetails = userDetailsService.loadUserByUsername(id); 148 | 149 | 150 | UserBeanExample userBeanExample = new UserBeanExample(); 151 | UserBeanExample.Criteria userBeanExampleCriteria = userBeanExample.createCriteria(); 152 | userBeanExampleCriteria.andIdEqualTo(id); 153 | List userBeans = mUserBeanMapper.selectByExample(userBeanExample); 154 | LoginBean loginBean = new LoginBean(); 155 | 156 | loginBean.setUserUUId(userBeans.get(0).getUuid()); 157 | loginBean.setUserID(userBeans.get(0).getId()); 158 | loginBean.setUserType((userBeans.get(0).getAuthId())); 159 | loginBean.setToken(jwtTokenUtil.generateToken(userDetails)); 160 | return loginBean; 161 | } catch (BadCredentialsException e) { 162 | return null; 163 | } 164 | } 165 | 166 | @Override 167 | public UserBean register(UserBean userBean) { 168 | return getUserBean(userBean); 169 | } 170 | 171 | private UserBean getUserBean(UserBean userBean) { 172 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 173 | String password = userBean.getPassword(); 174 | password = encoder.encode(password); 175 | userBean.setPassword(password); 176 | mUserBeanMapper.insert(userBean); 177 | return selectByUserId(userBean.getId()); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/main/resources/mapper/EmailInfoBeanMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | and ${criterion.condition} 19 | 20 | 21 | and ${criterion.condition} #{criterion.value} 22 | 23 | 24 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 25 | 26 | 27 | and ${criterion.condition} 28 | 29 | #{listItem} 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | and ${criterion.condition} 48 | 49 | 50 | and ${criterion.condition} #{criterion.value} 51 | 52 | 53 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 54 | 55 | 56 | and ${criterion.condition} 57 | 58 | #{listItem} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | id, email, code, created_time 70 | 71 | 85 | 91 | 92 | delete from email_info 93 | where id = #{id,jdbcType=INTEGER} 94 | 95 | 96 | delete from email_info 97 | 98 | 99 | 100 | 101 | 102 | insert into email_info (id, email, code, 103 | created_time) 104 | values (#{id,jdbcType=INTEGER}, #{email,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, 105 | #{createdTime,jdbcType=TIMESTAMP}) 106 | 107 | 108 | insert into email_info 109 | 110 | 111 | id, 112 | 113 | 114 | email, 115 | 116 | 117 | code, 118 | 119 | 120 | created_time, 121 | 122 | 123 | 124 | 125 | #{id,jdbcType=INTEGER}, 126 | 127 | 128 | #{email,jdbcType=VARCHAR}, 129 | 130 | 131 | #{code,jdbcType=VARCHAR}, 132 | 133 | 134 | #{createdTime,jdbcType=TIMESTAMP}, 135 | 136 | 137 | 138 | 144 | 145 | update email_info 146 | 147 | 148 | id = #{record.id,jdbcType=INTEGER}, 149 | 150 | 151 | email = #{record.email,jdbcType=VARCHAR}, 152 | 153 | 154 | code = #{record.code,jdbcType=VARCHAR}, 155 | 156 | 157 | created_time = #{record.createdTime,jdbcType=TIMESTAMP}, 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | update email_info 166 | set id = #{record.id,jdbcType=INTEGER}, 167 | email = #{record.email,jdbcType=VARCHAR}, 168 | code = #{record.code,jdbcType=VARCHAR}, 169 | created_time = #{record.createdTime,jdbcType=TIMESTAMP} 170 | 171 | 172 | 173 | 174 | 175 | update email_info 176 | 177 | 178 | email = #{email,jdbcType=VARCHAR}, 179 | 180 | 181 | code = #{code,jdbcType=VARCHAR}, 182 | 183 | 184 | created_time = #{createdTime,jdbcType=TIMESTAMP}, 185 | 186 | 187 | where id = #{id,jdbcType=INTEGER} 188 | 189 | 190 | update email_info 191 | set email = #{email,jdbcType=VARCHAR}, 192 | code = #{code,jdbcType=VARCHAR}, 193 | created_time = #{createdTime,jdbcType=TIMESTAMP} 194 | where id = #{id,jdbcType=INTEGER} 195 | 196 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/controller/AuthorityController.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.controller; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.njtech.smartuniversity.bean.AuthorityBean; 5 | import com.njtech.smartuniversity.bean.UserBean; 6 | import com.njtech.smartuniversity.service.AuthorityService; 7 | import com.njtech.smartuniversity.util.JsonResult; 8 | import com.njtech.smartuniversity.util.JsonUtil; 9 | import io.swagger.annotations.*; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.security.access.annotation.Secured; 12 | import org.springframework.security.access.prepost.PreAuthorize; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by ritchie on 6/25/18 19 | */ 20 | 21 | @RestController 22 | @Api(value = "/api/authorities", tags = {"权限"}, description = "权限相关") 23 | @RequestMapping("/api/authorities") 24 | public class AuthorityController { 25 | 26 | @Autowired 27 | AuthorityService mAuthorityService; 28 | 29 | 30 | @GetMapping("/{id}") 31 | @PreAuthorize("hasRole('ROLE_ADMIN')") 32 | @ApiOperation(value = "单个权限查询接口", notes = "使用ID查询权限") 33 | @ApiImplicitParams({ 34 | @ApiImplicitParam(value = "权限ID", name = "id", dataType = "int", paramType = "path", required = true) 35 | }) 36 | @ApiResponses({ 37 | @ApiResponse(code = 400, message = "请求参数有误"), 38 | @ApiResponse(code = 401, message = "未授权"), 39 | @ApiResponse(code = 403, message = "禁止访问"), 40 | @ApiResponse(code = 404, message = "请求路径不存在"), 41 | @ApiResponse(code = 500, message = "服务器内部错误") 42 | }) 43 | public JsonResult GetAuthority(@PathVariable("id") int id) { 44 | AuthorityBean authorityBean = mAuthorityService.selectByAuthorityId(id); 45 | if (authorityBean != null) { 46 | return new JsonUtil().successDataDefault(authorityBean); 47 | } 48 | 49 | return new JsonUtil().wrongNoDataWithMessage("不存在该权限"); 50 | } 51 | 52 | @GetMapping("/list") 53 | @PreAuthorize("hasRole('ROLE_ADMIN')") 54 | @ApiOperation(value = "权限列表接口", notes = "获取所有权限信息") 55 | @ApiResponses({ 56 | @ApiResponse(code = 400, message = "请求参数有误"), 57 | @ApiResponse(code = 401, message = "未授权"), 58 | @ApiResponse(code = 403, message = "禁止访问"), 59 | @ApiResponse(code = 404, message = "请求路径不存在"), 60 | @ApiResponse(code = 500, message = "服务器内部错误") 61 | }) 62 | public JsonResult ListAuthorities() { 63 | List authorityBeanList = mAuthorityService.getAllAuthorities(); 64 | if (authorityBeanList != null) { 65 | return new JsonUtil().successDataDefault(authorityBeanList); 66 | } 67 | return new JsonUtil().wrongNoDataWithMessage("不存在权限信息"); 68 | 69 | } 70 | 71 | @GetMapping() 72 | @PreAuthorize("hasRole('ROLE_ADMIN')") 73 | @ApiOperation(value = "权限列表分页接口", notes = "获取分页权限信息") 74 | @ApiImplicitParams({ 75 | @ApiImplicitParam(value = "页码", name = "page", dataType = "int", paramType = "form"), 76 | @ApiImplicitParam(value = "每页数量", name = "size", dataType = "int", paramType = "form") 77 | }) 78 | @ApiResponses({ 79 | @ApiResponse(code = 400, message = "请求参数有误"), 80 | @ApiResponse(code = 401, message = "未授权"), 81 | @ApiResponse(code = 403, message = "禁止访问"), 82 | @ApiResponse(code = 404, message = "请求路径不存在"), 83 | @ApiResponse(code = 500, message = "服务器内部错误") 84 | }) 85 | public JsonResult ListPageUsers(@RequestParam(value = "page", defaultValue = "1") int pageNum, 86 | @RequestParam(value = "size", defaultValue = "10") int pageSize) { 87 | PageInfo pageInfo = mAuthorityService.getAuthorityByPage(pageNum, pageSize); 88 | if (pageInfo != null) { 89 | return new JsonUtil().successDataDefault(pageInfo); 90 | } 91 | return new JsonUtil().wrongNoDataWithMessage("不存在权限信息"); 92 | } 93 | 94 | 95 | @DeleteMapping("/{id}") 96 | @PreAuthorize("hasRole('ROLE_ADMIN')") 97 | @ApiOperation(value = "权限删除接口", notes = "删除指定ID的权限") 98 | @ApiImplicitParam(value = "权限ID", name = "id", dataType = "int", paramType = "path", required = true) 99 | @ApiResponses({ 100 | @ApiResponse(code = 400, message = "请求参数有误"), 101 | @ApiResponse(code = 401, message = "未授权"), 102 | @ApiResponse(code = 403, message = "禁止访问"), 103 | @ApiResponse(code = 404, message = "请求路径不存在"), 104 | @ApiResponse(code = 500, message = "服务器内部错误") 105 | }) 106 | public JsonResult DeleteAuthority(@PathVariable("id") int id) { 107 | boolean result = mAuthorityService.deleteById(id); 108 | if (result) { 109 | return new JsonUtil().successEmptyDataDefault("删除该权限成功"); 110 | } 111 | 112 | return new JsonUtil().wrongNoDataWithMessage("不存在该权限"); 113 | } 114 | 115 | 116 | @PostMapping() 117 | @PreAuthorize("hasRole('ROLE_ADMIN')") 118 | @ApiOperation(value = "权限添加接口", notes = "权限添加") 119 | @ApiImplicitParams({ 120 | @ApiImplicitParam(value = "权限名称", name = "au_name", dataType = "String", paramType = "form", required = true), 121 | @ApiImplicitParam(value = "权限详情", name = "au_details", dataType = "String", paramType = "form", required = false) 122 | }) 123 | @ApiResponses({ 124 | @ApiResponse(code = 400, message = "请求参数有误"), 125 | @ApiResponse(code = 401, message = "未授权"), 126 | @ApiResponse(code = 403, message = "禁止访问"), 127 | @ApiResponse(code = 404, message = "请求路径不存在"), 128 | @ApiResponse(code = 500, message = "服务器内部错误") 129 | }) 130 | public JsonResult AddAuthority(@RequestParam("au_name") String name, 131 | @RequestParam("au_details") String details) { 132 | AuthorityBean authorityBean = new AuthorityBean(); 133 | 134 | if (details != null && !details.isEmpty()) { 135 | authorityBean.setAuDetails(details); 136 | } 137 | authorityBean.setAuName(name); 138 | 139 | AuthorityBean authorityBean1 = mAuthorityService.addAuthority(authorityBean); 140 | if (authorityBean1 != null) { 141 | return new JsonUtil().successDataWithMessage(authorityBean1, 142 | "权限添加成功"); 143 | 144 | } 145 | return new JsonUtil().wrongNoDataWithMessage("权限添加失败"); 146 | } 147 | 148 | 149 | @PatchMapping(value = "/{id}") 150 | @PreAuthorize("hasRole('ROLE_ADMIN')") 151 | @ApiOperation(value = "权限信息接口", notes = "修改指定ID的权限信息") 152 | @ApiImplicitParams({ 153 | @ApiImplicitParam(value = "权限ID", name = "id", dataType = "int", paramType = "path", required = true), 154 | @ApiImplicitParam(value = "权限名称", name = "au_name", dataType = "String", paramType = "form"), 155 | @ApiImplicitParam(value = "权限详情", name = "au_details", dataType = "String", paramType = "form") 156 | }) 157 | @ApiResponses({ 158 | @ApiResponse(code = 400, message = "请求参数有误"), 159 | @ApiResponse(code = 401, message = "未授权"), 160 | @ApiResponse(code = 403, message = "禁止访问"), 161 | @ApiResponse(code = 404, message = "请求路径不存在"), 162 | @ApiResponse(code = 500, message = "服务器内部错误") 163 | }) 164 | public JsonResult UpdateAuthority(@PathVariable("id") int id, 165 | @RequestParam(value = "au_name", required = false) String name, 166 | @RequestParam(value = "au_details", required = false) String details 167 | ) { 168 | 169 | AuthorityBean authorityBean = mAuthorityService.selectByAuthorityId(id); 170 | if (name != null && !name.isEmpty()) { 171 | authorityBean.setAuName(name); 172 | } 173 | if (details != null && !details.isEmpty()) { 174 | authorityBean.setAuDetails(details); 175 | } 176 | AuthorityBean authorityBean1 = mAuthorityService.update(authorityBean); 177 | return new JsonUtil().successDataWithMessage(authorityBean1, "修改用户信息成功"); 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/main/resources/mapper/ShopInfoBeanMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | and ${criterion.condition} 20 | 21 | 22 | and ${criterion.condition} #{criterion.value} 23 | 24 | 25 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 26 | 27 | 28 | and ${criterion.condition} 29 | 30 | #{listItem} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | and ${criterion.condition} 49 | 50 | 51 | and ${criterion.condition} #{criterion.value} 52 | 53 | 54 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 55 | 56 | 57 | and ${criterion.condition} 58 | 59 | #{listItem} 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | uuid, shop_name, shop_addr, state, user_uuid 71 | 72 | 86 | 92 | 93 | delete from shop_info 94 | where uuid = #{uuid,jdbcType=VARCHAR} 95 | 96 | 97 | delete from shop_info 98 | 99 | 100 | 101 | 102 | 103 | insert into shop_info (uuid, shop_name, shop_addr, 104 | state, user_uuid) 105 | values (#{uuid,jdbcType=VARCHAR}, #{shopName,jdbcType=VARCHAR}, #{shopAddr,jdbcType=VARCHAR}, 106 | #{state,jdbcType=CHAR}, #{userUuid,jdbcType=VARCHAR}) 107 | 108 | 109 | insert into shop_info 110 | 111 | 112 | uuid, 113 | 114 | 115 | shop_name, 116 | 117 | 118 | shop_addr, 119 | 120 | 121 | state, 122 | 123 | 124 | user_uuid, 125 | 126 | 127 | 128 | 129 | #{uuid,jdbcType=VARCHAR}, 130 | 131 | 132 | #{shopName,jdbcType=VARCHAR}, 133 | 134 | 135 | #{shopAddr,jdbcType=VARCHAR}, 136 | 137 | 138 | #{state,jdbcType=CHAR}, 139 | 140 | 141 | #{userUuid,jdbcType=VARCHAR}, 142 | 143 | 144 | 145 | 151 | 152 | update shop_info 153 | 154 | 155 | uuid = #{record.uuid,jdbcType=VARCHAR}, 156 | 157 | 158 | shop_name = #{record.shopName,jdbcType=VARCHAR}, 159 | 160 | 161 | shop_addr = #{record.shopAddr,jdbcType=VARCHAR}, 162 | 163 | 164 | state = #{record.state,jdbcType=CHAR}, 165 | 166 | 167 | user_uuid = #{record.userUuid,jdbcType=VARCHAR}, 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | update shop_info 176 | set uuid = #{record.uuid,jdbcType=VARCHAR}, 177 | shop_name = #{record.shopName,jdbcType=VARCHAR}, 178 | shop_addr = #{record.shopAddr,jdbcType=VARCHAR}, 179 | state = #{record.state,jdbcType=CHAR}, 180 | user_uuid = #{record.userUuid,jdbcType=VARCHAR} 181 | 182 | 183 | 184 | 185 | 186 | update shop_info 187 | 188 | 189 | shop_name = #{shopName,jdbcType=VARCHAR}, 190 | 191 | 192 | shop_addr = #{shopAddr,jdbcType=VARCHAR}, 193 | 194 | 195 | state = #{state,jdbcType=CHAR}, 196 | 197 | 198 | user_uuid = #{userUuid,jdbcType=VARCHAR}, 199 | 200 | 201 | where uuid = #{uuid,jdbcType=VARCHAR} 202 | 203 | 204 | update shop_info 205 | set shop_name = #{shopName,jdbcType=VARCHAR}, 206 | shop_addr = #{shopAddr,jdbcType=VARCHAR}, 207 | state = #{state,jdbcType=CHAR}, 208 | user_uuid = #{userUuid,jdbcType=VARCHAR} 209 | where uuid = #{uuid,jdbcType=VARCHAR} 210 | 211 | -------------------------------------------------------------------------------- /src/main/resources/mapper/CardBeanMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | and ${criterion.condition} 21 | 22 | 23 | and ${criterion.condition} #{criterion.value} 24 | 25 | 26 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 27 | 28 | 29 | and ${criterion.condition} 30 | 31 | #{listItem} 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | and ${criterion.condition} 50 | 51 | 52 | and ${criterion.condition} #{criterion.value} 53 | 54 | 55 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 56 | 57 | 58 | and ${criterion.condition} 59 | 60 | #{listItem} 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | id, card_vid, sq_id, auth_id, application_time, state 72 | 73 | 87 | 93 | 94 | delete from card 95 | where id = #{id,jdbcType=INTEGER} 96 | 97 | 98 | delete from card 99 | 100 | 101 | 102 | 103 | 104 | insert into card (id, card_vid, sq_id, 105 | auth_id, application_time, state 106 | ) 107 | values (#{id,jdbcType=INTEGER}, #{cardVid,jdbcType=VARCHAR}, #{sqId,jdbcType=VARCHAR}, 108 | #{authId,jdbcType=INTEGER}, #{applicationTime,jdbcType=TIMESTAMP}, #{state,jdbcType=VARCHAR} 109 | ) 110 | 111 | 112 | insert into card 113 | 114 | 115 | id, 116 | 117 | 118 | card_vid, 119 | 120 | 121 | sq_id, 122 | 123 | 124 | auth_id, 125 | 126 | 127 | application_time, 128 | 129 | 130 | state, 131 | 132 | 133 | 134 | 135 | #{id,jdbcType=INTEGER}, 136 | 137 | 138 | #{cardVid,jdbcType=VARCHAR}, 139 | 140 | 141 | #{sqId,jdbcType=VARCHAR}, 142 | 143 | 144 | #{authId,jdbcType=INTEGER}, 145 | 146 | 147 | #{applicationTime,jdbcType=TIMESTAMP}, 148 | 149 | 150 | #{state,jdbcType=VARCHAR}, 151 | 152 | 153 | 154 | 160 | 161 | update card 162 | 163 | 164 | id = #{record.id,jdbcType=INTEGER}, 165 | 166 | 167 | card_vid = #{record.cardVid,jdbcType=VARCHAR}, 168 | 169 | 170 | sq_id = #{record.sqId,jdbcType=VARCHAR}, 171 | 172 | 173 | auth_id = #{record.authId,jdbcType=INTEGER}, 174 | 175 | 176 | application_time = #{record.applicationTime,jdbcType=TIMESTAMP}, 177 | 178 | 179 | state = #{record.state,jdbcType=VARCHAR}, 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | update card 188 | set id = #{record.id,jdbcType=INTEGER}, 189 | card_vid = #{record.cardVid,jdbcType=VARCHAR}, 190 | sq_id = #{record.sqId,jdbcType=VARCHAR}, 191 | auth_id = #{record.authId,jdbcType=INTEGER}, 192 | application_time = #{record.applicationTime,jdbcType=TIMESTAMP}, 193 | state = #{record.state,jdbcType=VARCHAR} 194 | 195 | 196 | 197 | 198 | 199 | update card 200 | 201 | 202 | card_vid = #{cardVid,jdbcType=VARCHAR}, 203 | 204 | 205 | sq_id = #{sqId,jdbcType=VARCHAR}, 206 | 207 | 208 | auth_id = #{authId,jdbcType=INTEGER}, 209 | 210 | 211 | application_time = #{applicationTime,jdbcType=TIMESTAMP}, 212 | 213 | 214 | state = #{state,jdbcType=VARCHAR}, 215 | 216 | 217 | where id = #{id,jdbcType=INTEGER} 218 | 219 | 220 | update card 221 | set card_vid = #{cardVid,jdbcType=VARCHAR}, 222 | sq_id = #{sqId,jdbcType=VARCHAR}, 223 | auth_id = #{authId,jdbcType=INTEGER}, 224 | application_time = #{applicationTime,jdbcType=TIMESTAMP}, 225 | state = #{state,jdbcType=VARCHAR} 226 | where id = #{id,jdbcType=INTEGER} 227 | 228 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/aspect/LogAspect.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.aspect; 2 | 3 | import com.google.gson.Gson; 4 | import com.njtech.smartuniversity.annotation.ServiceAnnotation; 5 | import org.aspectj.lang.JoinPoint; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.*; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.boot.configurationprocessor.json.JSONObject; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.context.request.RequestContextHolder; 13 | import org.springframework.web.context.request.ServletRequestAttributes; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpSession; 17 | import java.lang.reflect.Method; 18 | import java.util.Arrays; 19 | 20 | /** 21 | * Created by ritchie on 6/27/18 22 | */ 23 | @Component 24 | @Aspect 25 | public class LogAspect { 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(LogAspect.class); 28 | 29 | private ThreadLocal startTime = new ThreadLocal<>(); 30 | 31 | 32 | /** 33 | * 监控com.njtech.smartuniversity.dao包及其子包的所有方法 34 | */ 35 | @Pointcut("execution(* com.njtech.smartuniversity.dao.*.*(..))") 36 | private void dao() { 37 | } 38 | 39 | /** 40 | * 监控com.njtech.smartuniversity.controller包及其子包的所有方法 41 | */ 42 | @Pointcut(value = "execution(* com.njtech.smartuniversity.controller.*.*(..))") 43 | public void controller() { 44 | } 45 | 46 | /** 47 | * 监控com.njtech.smartuniversity.service包及其子包的所有方法 48 | */ 49 | @Pointcut(value = "execution(* com.njtech.smartuniversity.service..*.*(..))") 50 | public void service() { 51 | } 52 | 53 | 54 | @Before("controller() || service() || dao()") 55 | public void doBefore(JoinPoint joinPoint) throws Throwable { 56 | 57 | startTime.set(System.currentTimeMillis()); 58 | Gson gson = new Gson(); 59 | //接收到请求,记录请求内容 60 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 61 | HttpServletRequest request = attributes.getRequest(); 62 | // 63 | // //记录下请求内容 64 | // logger.info("URL : " + request.getRequestURL().toString()); 65 | // logger.info("HTTP_METHOD : " + request.getMethod()); 66 | // logger.info("IP : " + request.getRemoteAddr()); 67 | // logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); 68 | // logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs())); 69 | 70 | //获取用户请求方法的参数并序列化为JSON格式字符串 71 | StringBuilder params = new StringBuilder(); 72 | if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) { 73 | for (int i = 0; i < joinPoint.getArgs().length; i++) { 74 | params.append(gson.toJson(joinPoint.getArgs()[i])).append(";"); 75 | } 76 | } 77 | HttpSession session = request.getSession(); 78 | //请求的IP 79 | String ip = request.getRemoteAddr(); 80 | try { 81 | logger.info("===== 前置通知开始====="); 82 | logger.info("URL : " + request.getRequestURL().toString()); 83 | logger.info("HTTP请求类型 : " + request.getMethod()); 84 | logger.info("请求方法:" + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()")); 85 | // logger.info("方法描述:" + getServiceMthodDescription(joinPoint)); 86 | // logger.info("请求人ID:" + user.getId()); 87 | // logger.info("请求人NAME:" + user.getName()); 88 | System.out.println("请求IP:" + ip); 89 | logger.info("请求参数:" + params); 90 | System.out.println("=====前置通知结束====="); 91 | } catch (Exception e) { 92 | //记录本地异常日志 93 | logger.error("==前置通知异常=="); 94 | logger.error("异常信息:{}", e.getMessage()); 95 | } 96 | } 97 | 98 | 99 | // /** 100 | // * 声明环绕通知 101 | // * 102 | // * @param pjp 103 | // * @return 104 | // * @throws Throwable 105 | // */ 106 | // @Around("dao() || controller() || service()") 107 | // public Object doAround(ProceedingJoinPoint pjp) throws Throwable { 108 | // long begin = System.nanoTime(); 109 | // Object obj = pjp.proceed(); 110 | // long end = System.nanoTime(); 111 | // 112 | // logger.info("调用方法:{},\n参数:{},\n执行耗时:{}纳秒,\r\n耗时:{}毫秒", 113 | // pjp.getSignature().toString(), Arrays.toString(pjp.getArgs()), 114 | // (end - begin), (end - begin) / 1000000); 115 | // return obj; 116 | // } 117 | 118 | 119 | @AfterReturning(returning = "result", pointcut = "dao() || controller() || service()") 120 | public void doAfter(JoinPoint joinPoint, Object result) { 121 | //处理完请求,返回内容 122 | Gson gson = new Gson(); 123 | String res = gson.toJson(result); 124 | //接收到请求,记录请求内容 125 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 126 | HttpServletRequest request = attributes.getRequest(); 127 | 128 | //获取请求ip 129 | String ip = request.getRemoteAddr(); 130 | //获取用户请求方法的参数并序列化为JSON格式字符串 131 | StringBuilder params = new StringBuilder(); 132 | if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) { 133 | for (int i = 0; i < joinPoint.getArgs().length; i++) { 134 | params.append(gson.toJson(joinPoint.getArgs()[i])).append(";"); 135 | } 136 | } 137 | try { 138 | logger.info("===== 后置通知开始====="); 139 | logger.info("请求方法:" + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()")); 140 | // logger.info("方法描述:" + getServiceMthodDescription(joinPoint)); 141 | // logger.info("请求人ID:" + user.getId()); 142 | // logger.info("请求人NAME:" + user.getName()); 143 | logger.info("请求IP:" + ip); 144 | logger.info("请求参数:" + params); 145 | logger.info("返回值为:" + res); 146 | logger.info("耗时 : {} 毫秒", (System.currentTimeMillis() - startTime.get())); 147 | 148 | 149 | } catch (Exception ex) { 150 | //记录本地异常日志 151 | logger.error("==异常通知异常=="); 152 | logger.error("异常信息:{}", ex.getMessage()); 153 | } 154 | } 155 | 156 | @AfterThrowing(pointcut = "dao() || controller() || service()", throwing = "e") 157 | public void doThrow(JoinPoint joinPoint, Throwable e) { 158 | 159 | Gson gson = new Gson(); 160 | //接收到请求,记录请求内容 161 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 162 | HttpServletRequest request = attributes.getRequest(); 163 | 164 | //请求IP address 165 | String ip = request.getRemoteAddr(); 166 | 167 | //获取用户请求方法的参数并序列化为JSON格式字符串 168 | StringBuilder params = new StringBuilder(); 169 | if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) { 170 | for (int i = 0; i < joinPoint.getArgs().length; i++) { 171 | params.append(gson.toJson(joinPoint.getArgs()[i])).append(";"); 172 | } 173 | } 174 | try { 175 | logger.error("=====异常通知开始====="); 176 | logger.error("异常代码:" + e.getClass().getName()); 177 | logger.error("异常信息:" + e.getMessage()); 178 | logger.error("异常方法:" + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()")); 179 | // logger.error("方法描述:" + getServiceMthodDescription(joinPoint)); 180 | logger.error("请求IP:" + ip); 181 | logger.error("请求参数:" + params.toString()); 182 | logger.error("=====异常通知结束====="); 183 | } catch (Exception ex) { 184 | //记录本地异常日志 185 | logger.error("==异常通知异常=="); 186 | logger.error("异常信息:{}", ex.getMessage()); 187 | } 188 | /*==========记录本地异常日志==========*/ 189 | logger.error("异常方法:{}异常代码:{}异常信息:{}参数:{}", joinPoint.getTarget().getClass().getName() + joinPoint.getSignature().getName(), e.getClass().getName(), e.getMessage(), params.toString()); 190 | } 191 | 192 | 193 | /** 194 | * 获取注解中对方法的描述信息 用于service层注解 195 | * 196 | * @param joinPoint 切点 197 | * @return 方法描述 198 | * @throws Exception 199 | */ 200 | private static String getServiceMthodDescription(JoinPoint joinPoint) 201 | throws Exception { 202 | String targetName = joinPoint.getTarget().getClass().getName(); 203 | String methodName = joinPoint.getSignature().getName(); 204 | Object[] arguments = joinPoint.getArgs(); 205 | Class targetClass = Class.forName(targetName); 206 | Method[] methods = targetClass.getMethods(); 207 | String description = ""; 208 | for (Method method : methods) { 209 | if (method.getName().equals(methodName)) { 210 | Class[] clazzs = method.getParameterTypes(); 211 | if (clazzs.length == arguments.length) { 212 | description = method.getAnnotation(ServiceAnnotation.class).description(); 213 | break; 214 | } 215 | } 216 | } 217 | return description; 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/com/njtech/smartuniversity/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.njtech.smartuniversity.controller; 2 | 3 | import com.google.gson.Gson; 4 | import com.njtech.smartuniversity.bean.AuthTokenBean; 5 | import com.njtech.smartuniversity.bean.EmailInfoBean; 6 | import com.njtech.smartuniversity.bean.LoginBean; 7 | import com.njtech.smartuniversity.bean.UserBean; 8 | import com.njtech.smartuniversity.config.security.JwtTokenUtil; 9 | import com.njtech.smartuniversity.config.security.JwtUser; 10 | import com.njtech.smartuniversity.service.EmailInfoService; 11 | import com.njtech.smartuniversity.service.MailService; 12 | import com.njtech.smartuniversity.service.UserService; 13 | import com.njtech.smartuniversity.util.JsonResult; 14 | import com.njtech.smartuniversity.util.JsonUtil; 15 | import com.njtech.smartuniversity.util.MailUtil; 16 | import com.njtech.smartuniversity.util.Validator; 17 | import io.swagger.annotations.*; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.beans.factory.annotation.Qualifier; 20 | import org.springframework.beans.factory.annotation.Value; 21 | import org.springframework.http.ResponseEntity; 22 | import org.springframework.security.access.prepost.PreAuthorize; 23 | import org.springframework.security.core.AuthenticationException; 24 | import org.springframework.security.core.userdetails.UserDetailsService; 25 | import org.springframework.web.bind.annotation.*; 26 | 27 | import javax.servlet.http.HttpServletRequest; 28 | import java.util.Date; 29 | import java.util.List; 30 | import java.util.UUID; 31 | 32 | /** 33 | * Created by ritchie on 6/25/18 34 | */ 35 | 36 | @RestController 37 | @Api(value = "/api/auth", tags = {"认证"}, description = "认证相关") 38 | @RequestMapping("/api/auth") 39 | public class AuthController { 40 | 41 | @Autowired 42 | UserService mUserService; 43 | 44 | @Autowired 45 | MailService mMailService; 46 | 47 | @Autowired 48 | EmailInfoService mEmailInfoService; 49 | 50 | @Autowired 51 | JwtTokenUtil mJwtTokenUtil; 52 | 53 | @Qualifier("jwtUserDetailServiceImpl") 54 | @Autowired 55 | UserDetailsService mUserDetailsService; 56 | 57 | @Value("${jwt.header}") 58 | private String tokenHeader; 59 | 60 | 61 | @PostMapping("/login") 62 | @ApiOperation(value = "登录接口", notes = "用户登录") 63 | @ApiImplicitParams({ 64 | @ApiImplicitParam(name = "id", value = "用户名(邮箱/账号/id)", required = true, dataType = "String", paramType = "form"), 65 | @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "form"), 66 | @ApiImplicitParam(name = "type", value = "用户登录类型 (0邮箱,1手机,2帐号)", dataType = "String", paramType = "form") 67 | }) 68 | public JsonResult login(@RequestParam("id") String id, 69 | @RequestParam("password") String password, 70 | @RequestParam(value = "type", required = false) String type) throws AuthenticationException { 71 | LoginBean loginBean; 72 | if (type == null) { 73 | //默认的登录类型 74 | loginBean = mUserService.login(id, password); 75 | if (loginBean != null) 76 | return new JsonUtil().successDataWithMessage(loginBean, 77 | "登录成功"); 78 | else 79 | loginBean = mUserService.loginByAccountAndPassword(id, password); 80 | if (loginBean != null) 81 | return new JsonUtil().successDataWithMessage(loginBean, 82 | "登录成功"); 83 | } else if (type.equals("0")) { 84 | //邮箱登录 85 | loginBean = mUserService.loginByEmailAndPassword(id, password); 86 | if (loginBean != null) 87 | return new JsonUtil().successDataWithMessage(loginBean, 88 | "登录成功"); 89 | return new JsonUtil().wrongNoDataWithMessage("邮箱或密码错误"); 90 | 91 | } else if (type.equals("1")) { 92 | return new JsonUtil().wrongNoDataWithMessage("不支持的登录方式"); 93 | //手机登录暂不支持 94 | } else if (type.equals("2")) { 95 | loginBean = mUserService.loginByAccountAndPassword(id, password); 96 | if (loginBean != null) 97 | return new JsonUtil().successDataWithMessage(loginBean, 98 | "登录成功"); 99 | return new JsonUtil().wrongNoDataWithMessage("帐号或密码错误"); 100 | } 101 | return new JsonUtil().wrongNoDataWithMessage("帐号或密码错误"); 102 | } 103 | 104 | 105 | @PostMapping("/sendEmail") 106 | @ApiOperation(value = "发送邮箱验证码接口", notes = "发送用户邮箱验证码") 107 | @ApiImplicitParams({ 108 | @ApiImplicitParam(value = "邮箱", name = "email", dataType = "String", paramType = "form", required = true) 109 | 110 | }) 111 | public JsonResult verifyCode(@RequestParam("email") String email) { 112 | String code = MailUtil.generateCode(); 113 | EmailInfoBean bean = mEmailInfoService.selectEmailInfoByEmail(email); 114 | 115 | mMailService.sendSimpleMail(email, MailUtil.SUBJECT_REGISTER, 116 | MailUtil.generateMessgae(code)); 117 | 118 | if (bean != null && bean.getEmail() != null) { 119 | bean.setCode(code); 120 | bean.setCreatedTime(new Date()); 121 | mEmailInfoService.updateEmailInfo(bean); 122 | } else { 123 | mEmailInfoService.addEmailInfo(email, code); 124 | } 125 | return new JsonUtil().successEmptyDataDefault("发送邮箱验证码成功!"); 126 | 127 | } 128 | 129 | @PostMapping("/register") 130 | @ApiOperation(value = "商家/用户注册接口", notes = "用户注册") 131 | @ApiImplicitParams({ 132 | @ApiImplicitParam(value = "用户注册类型(0邮箱,1手机,2帐号)", name = "type", dataType = "String", paramType = "form", required = true), 133 | @ApiImplicitParam(value = "用户类型(0普通用户 1商家)", name = "shop_type", dataType = "String", paramType = "form", required = true), 134 | @ApiImplicitParam(value = "用户名", name = "account", dataType = "String", paramType = "form"), 135 | @ApiImplicitParam(value = "邮箱", name = "email", dataType = "String", paramType = "form"), 136 | @ApiImplicitParam(value = "邮箱验证码", name = "verifyCode", dataType = "String", paramType = "form"), 137 | @ApiImplicitParam(value = "用户密码", name = "password", dataType = "String", paramType = "form") 138 | }) 139 | public JsonResult register( 140 | @RequestParam(value = "password", required = false) String password, 141 | @RequestParam(value = "account", required = false) String account, 142 | @RequestParam(value = "email", required = false) String email, 143 | @RequestParam(value = "verifyCode", required = false) String verifyCode, 144 | @RequestParam("type") String type, 145 | @RequestParam("shop_type") String shop_type) throws AuthenticationException { 146 | UserBean userBean = new UserBean(); 147 | 148 | //生成id 149 | String newId = String.valueOf(System.currentTimeMillis()).substring(1); 150 | userBean.setId(newId); 151 | 152 | //生成uuid 153 | String uuid = UUID.randomUUID().toString().replace("-", ""); 154 | userBean.setUuid(uuid); 155 | 156 | 157 | userBean.setState("1"); 158 | userBean.setType(type); 159 | 160 | //邮箱 161 | if (type.equals("0") && !email.isEmpty() && Validator.isEmail(email) && !verifyCode.isEmpty()) { 162 | //验证邮箱验证码 163 | EmailInfoBean emailInfoBean = mEmailInfoService.selectEmailInfo(email, verifyCode); 164 | if (emailInfoBean != null && !emailInfoBean.getEmail().isEmpty()) { 165 | userBean.setEmail(email); 166 | userBean.setPassword(password); 167 | } else if (emailInfoBean == null) { 168 | return new JsonUtil().wrongNoDataWithMessage("邮箱验证码错误"); 169 | } else { 170 | return new JsonUtil().wrongNoDataWithMessage("邮箱验证码出错"); 171 | 172 | } 173 | //验证 174 | } else if (type.equals("2") && !account.isEmpty() && Validator.isPassword(password)) { 175 | userBean.setAccount(account); 176 | userBean.setPassword(password); 177 | 178 | } 179 | //设置用户注册类型 180 | if (shop_type.equals("0")) { 181 | //普通用户 182 | userBean.setShopType(shop_type); 183 | userBean.setAuthId(2); 184 | 185 | } else if (shop_type.equals("1")) { 186 | //商人 187 | userBean.setShopType(shop_type); 188 | userBean.setAuthId(1); 189 | 190 | } else { 191 | return new JsonUtil().wrongNoDataWithMessage("用户类型不存在"); 192 | } 193 | 194 | 195 | UserBean userBean1 = mUserService.register(userBean); 196 | if (userBean1 != null) { 197 | return new JsonUtil().successDataWithMessage(userBean1, 198 | "用户注册成功"); 199 | 200 | } 201 | return new JsonUtil().wrongNoDataWithMessage("用户注册失败"); 202 | } 203 | 204 | 205 | @PostMapping("/refresh") 206 | @ApiOperation(value = "token刷新接口", notes = "刷新token") 207 | @ApiImplicitParams({ 208 | @ApiImplicitParam(value = "已授权token", name = "token", dataType = "String", paramType = "form", required = true) 209 | 210 | }) 211 | public JsonResult refresh(@RequestParam("token") String token) throws AuthenticationException { 212 | // String authToken = request.getHeader(tokenHeader); 213 | // final String token = authToken.substring(tokenHeader.length()); 214 | String username = mJwtTokenUtil.getUsernameFromToken(token); 215 | JwtUser user = (JwtUser) mUserDetailsService.loadUserByUsername(username); 216 | 217 | if (mJwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetTime())) { 218 | String refreshedToken = mJwtTokenUtil.refreshToken(token); 219 | AuthTokenBean tokenBean = new AuthTokenBean(refreshedToken); 220 | return new JsonUtil().successDataWithMessage(tokenBean, "token刷新成功"); 221 | } else { 222 | return new JsonUtil().wrongNoDataWithMessage("token刷新失败"); 223 | } 224 | 225 | } 226 | 227 | 228 | } 229 | --------------------------------------------------------------------------------