From 0e80995a7e26820c21c68ede4f8432ec59bfad20 Mon Sep 17 00:00:00 2001 From: x ronger Date: Sat, 16 Nov 2019 20:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C=E4=B8=8E?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 23 +++ .../vertical/config/HpeisShiroRealm.java | 7 +- .../rymcu/vertical/config/ShiroConfig.java | 8 + .../config/Swagger2Configuration.java | 37 ++++ .../vertical/config/WebMvcConfigurer.java | 4 +- .../core/result/GlobalResultMessage.java | 15 ++ .../java/com/rymcu/vertical/dto/RoleDTO.java | 8 +- .../java/com/rymcu/vertical/dto/TUser.java | 18 ++ .../com/rymcu/vertical/dto/UserExportDTO.java | 19 -- .../java/com/rymcu/vertical/entity/Menu.java | 8 +- .../java/com/rymcu/vertical/entity/Role.java | 22 +- .../java/com/rymcu/vertical/entity/User.java | 50 ++--- .../com/rymcu/vertical/mapper/MenuMapper.java | 12 +- .../com/rymcu/vertical/mapper/RoleMapper.java | 23 +-- .../com/rymcu/vertical/mapper/UserMapper.java | 28 +-- .../vertical/service/JavaMailService.java | 5 + .../rymcu/vertical/service/MenuService.java | 16 -- .../rymcu/vertical/service/RoleService.java | 23 --- .../rymcu/vertical/service/UserService.java | 32 +-- .../service/impl/JavaMailServiceImpl.java | 39 ++++ .../service/impl/MenuServiceImpl.java | 64 +----- .../service/impl/RoleServiceImpl.java | 119 +---------- .../service/impl/UserServiceImpl.java | 195 ++++++------------ .../java/com/rymcu/vertical/util/Utils.java | 5 + .../web/api/common/CommonApiController.java | 54 +++++ src/main/java/mapper/MenuMapper.xml | 87 +------- src/main/java/mapper/RoleMapper.xml | 148 ++----------- src/main/java/mapper/UserMapper.xml | 184 +++-------------- 28 files changed, 385 insertions(+), 868 deletions(-) create mode 100644 src/main/java/com/rymcu/vertical/config/Swagger2Configuration.java create mode 100644 src/main/java/com/rymcu/vertical/core/result/GlobalResultMessage.java create mode 100644 src/main/java/com/rymcu/vertical/dto/TUser.java delete mode 100644 src/main/java/com/rymcu/vertical/dto/UserExportDTO.java create mode 100644 src/main/java/com/rymcu/vertical/service/JavaMailService.java create mode 100644 src/main/java/com/rymcu/vertical/service/impl/JavaMailServiceImpl.java create mode 100644 src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java diff --git a/pom.xml b/pom.xml index ce2d8f4..c404dc9 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,10 @@ commons-text 1.8 + + commons-codec + commons-codec + io.jsonwebtoken jjwt @@ -135,6 +139,25 @@ spring-boot-configuration-processor true + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.8.0 + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + net.sourceforge.nekohtml + nekohtml + 1.9.22 + diff --git a/src/main/java/com/rymcu/vertical/config/HpeisShiroRealm.java b/src/main/java/com/rymcu/vertical/config/HpeisShiroRealm.java index 4da8858..ee3bc7a 100644 --- a/src/main/java/com/rymcu/vertical/config/HpeisShiroRealm.java +++ b/src/main/java/com/rymcu/vertical/config/HpeisShiroRealm.java @@ -12,6 +12,7 @@ import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.Encodes; import com.rymcu.vertical.util.Utils; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.exceptions.TooManyResultsException; import org.apache.shiro.authc.*; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; @@ -85,8 +86,8 @@ public class HpeisShiroRealm extends AuthorizingRealm { throw new CaptchaException(); } try { - user = userService.findByLoginName(username); - } catch (ServiceException e) { + user = userService.findByAccount(username); + } catch (TooManyResultsException e) { e.printStackTrace(); } if (user == null) { @@ -117,7 +118,7 @@ public class HpeisShiroRealm extends AuthorizingRealm { public Principal(User user, boolean mobileLogin) { this.id = user.getIdUser(); this.account = user.getAccount(); - this.name = user.getNickName(); + this.name = user.getNickname(); this.mobileLogin = mobileLogin; } diff --git a/src/main/java/com/rymcu/vertical/config/ShiroConfig.java b/src/main/java/com/rymcu/vertical/config/ShiroConfig.java index 8632a12..c5bbb76 100644 --- a/src/main/java/com/rymcu/vertical/config/ShiroConfig.java +++ b/src/main/java/com/rymcu/vertical/config/ShiroConfig.java @@ -49,6 +49,14 @@ public class ShiroConfig implements EnvironmentAware { filterChainDefinitionMap.put("/js/**", "anon"); filterChainDefinitionMap.put("/uploadFile/**", "anon"); filterChainDefinitionMap.put("/login", "anon"); + + filterChainDefinitionMap.put("/swagger-ui.html", "anon"); + filterChainDefinitionMap.put("/swagger-resources", "anon"); + filterChainDefinitionMap.put("/swagger-resources/configuration/security", "anon"); + filterChainDefinitionMap.put("/swagger-resources/configuration/ui", "anon"); + filterChainDefinitionMap.put("/v2/api-docs", "anon"); + filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon"); + filterChainDefinitionMap.put("/api/**", "anon"); // filterChainDefinitionMap.put("/**", "authc"); filterChainDefinitionMap.put("/**", "authc"); diff --git a/src/main/java/com/rymcu/vertical/config/Swagger2Configuration.java b/src/main/java/com/rymcu/vertical/config/Swagger2Configuration.java new file mode 100644 index 0000000..79e773e --- /dev/null +++ b/src/main/java/com/rymcu/vertical/config/Swagger2Configuration.java @@ -0,0 +1,37 @@ +package com.rymcu.vertical.config; + +import io.swagger.annotations.Api; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Configuration { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.rymcu.vertical.web.api"))//这是注意的代码 + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("Vertical项目接口文档") + .description("Vertical项目相关接口的文档") + .termsOfServiceUrl("http://www.rymcu.com") + .version("1.0") + .build(); + } + +} diff --git a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java index 11c0972..7aa8c41 100644 --- a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java +++ b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java @@ -71,9 +71,7 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { public void addInterceptors(InterceptorRegistry registry) { // TODO 先不拦截接口,进行测试 registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**") - .excludePathPatterns("/api/login/**", "/api/logout","/api/member/*", - "/api/home/*","/api/item/**","/api/searchHistory/**", "/api/pay/payNotify", - "/api/mall/oauth/**","/api/express/**","/api/person/**"); + .excludePathPatterns("/api/v1/**"); } diff --git a/src/main/java/com/rymcu/vertical/core/result/GlobalResultMessage.java b/src/main/java/com/rymcu/vertical/core/result/GlobalResultMessage.java new file mode 100644 index 0000000..55afdd8 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/core/result/GlobalResultMessage.java @@ -0,0 +1,15 @@ +package com.rymcu.vertical.core.result; + +public enum GlobalResultMessage { + + SUCCESS("操作成功!"), + FAIL("操作失败!"), + SEND_FAIL("发送失败,请稍后再试!"), + SEND_SUCCESS("发送成功!"); + + private String message; + + GlobalResultMessage(String message){ + this.message = message; + } +} diff --git a/src/main/java/com/rymcu/vertical/dto/RoleDTO.java b/src/main/java/com/rymcu/vertical/dto/RoleDTO.java index 13c261e..6c3a3c8 100644 --- a/src/main/java/com/rymcu/vertical/dto/RoleDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/RoleDTO.java @@ -12,14 +12,8 @@ public class RoleDTO { private String name; // 英文名称 - private String enname; - - // 用户类别 - private String roleType; + private String inputCode; // 角色授权菜单ids private String menuIds; - - // 备注 - private String remarks; } diff --git a/src/main/java/com/rymcu/vertical/dto/TUser.java b/src/main/java/com/rymcu/vertical/dto/TUser.java new file mode 100644 index 0000000..3f37530 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/TUser.java @@ -0,0 +1,18 @@ +package com.rymcu.vertical.dto; + +import lombok.Data; + +@Data +public class TUser { + + private String account; + + private String nickname; + + private String token; + + private String avatarType; + + private String avatarUrl; + +} diff --git a/src/main/java/com/rymcu/vertical/dto/UserExportDTO.java b/src/main/java/com/rymcu/vertical/dto/UserExportDTO.java deleted file mode 100644 index 2a0d5dd..0000000 --- a/src/main/java/com/rymcu/vertical/dto/UserExportDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.rymcu.vertical.dto; - -import lombok.Data; - -@Data -public class UserExportDTO { - - private String officeName; - - private String name; - - private String sex; - - private String loginName; - - private String storePerm; - - private String departPerm; -} diff --git a/src/main/java/com/rymcu/vertical/entity/Menu.java b/src/main/java/com/rymcu/vertical/entity/Menu.java index 68dcf39..edd0bdd 100644 --- a/src/main/java/com/rymcu/vertical/entity/Menu.java +++ b/src/main/java/com/rymcu/vertical/entity/Menu.java @@ -14,13 +14,13 @@ import java.util.Date; public class Menu { @Id - @Column(name = "ID_MENU") + @Column(name = "id") private Integer idMenu; /** * 上级菜单ID * */ - @Column(name = "PARENT_ID") + @Column(name = "parent_id") private String parentId; /** @@ -57,12 +57,12 @@ public class Menu { /** * 创建时间 * */ - @Column(name = "CREATED_TIME") + @Column(name = "created_time") private Date createdTime; /** * 状态 * */ - @Column(name = "STATUS") + @Column(name = "status") private String status; } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/entity/Role.java b/src/main/java/com/rymcu/vertical/entity/Role.java index 9c231f8..e7fbcef 100644 --- a/src/main/java/com/rymcu/vertical/entity/Role.java +++ b/src/main/java/com/rymcu/vertical/entity/Role.java @@ -8,33 +8,39 @@ import javax.persistence.Table; import java.util.Date; @Data -@Table(name = "SYS_ROLE") +@Table(name = "sys_role") public class Role { @Id - @Column(name = "ID_ROLE") - private String idRole; + @Column(name = "id") + private Integer idRole; /** * 角色名称 * */ - @Column(name = "NAME") + @Column(name = "name") private String name; /** * 拼音码 * */ - @Column(name = "INPUT_CODE") + @Column(name = "input_code") private String inputCode; /** * 状态 * */ - @Column(name = "STATUS") - private Integer status; + @Column(name = "status") + private String status; /** * 创建时间 * */ - @Column(name = "CREATED_TIME") + @Column(name = "created_time") private Date createdTime; + + /** + * 更新时间 + * */ + @Column(name = "updated_time") + private Date updatedTime; } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/entity/User.java b/src/main/java/com/rymcu/vertical/entity/User.java index 096c3c4..70464e9 100644 --- a/src/main/java/com/rymcu/vertical/entity/User.java +++ b/src/main/java/com/rymcu/vertical/entity/User.java @@ -9,97 +9,97 @@ import javax.persistence.Id; import javax.persistence.Table; import java.util.Date; -@Table(name = "SYS_USER") +@Table(name = "sys_user") @Data public class User { @Id - @Column(name = "ID_USER") + @Column(name = "id") private Integer idUser; - /** - * 应用ID - * */ - @Column(name = "APP_ID") - private String appId; - /** * 登录账号 * */ - @Column(name = "ACCOUNT") + @Column(name = "account") private String account; /** * 密码 * */ - @Column(name = "PASSWORD") + @Column(name = "password") private String password; /** * 昵称 * */ - @Column(name = "NICK_NAME") - private String nickName; + @Column(name = "nickname") + private String nickname; /** * 真实姓名 * */ - @Column(name = "REAL_NAME") + @Column(name = "real_name") private String realName; /** * 性别 1:男性 2:女性 * */ - @Column(name = "SEX") - private Integer sex; + @Column(name = "sex") + private String sex; /** * 头像文件类型 * */ - @Column(name = "AVATAR_TYPE") - private Integer avatarType; + @Column(name = "avatar_type") + private String avatarType; /** * 头像路径 * */ - @Column(name = "AVATAR_URL") + @Column(name = "avatar_url") private String avatarUrl; /** * 邮箱地址 * */ - @ColumnType(column = "EMAIL", + @ColumnType(column = "email", jdbcType = JdbcType.VARCHAR) private String email; /** * 手机号码 * */ - @ColumnType(column = "PHONE", + @ColumnType(column = "phone", jdbcType = JdbcType.VARCHAR) private String phone; /** * 签名 * */ - @ColumnType(column = "SIGNATURE", + @ColumnType(column = "signature", jdbcType = JdbcType.VARCHAR) private String signature; /** * 状态 * */ - @Column(name = "STATUS") - private Integer status; + @Column(name = "status") + private String status; /** * 最后登录时间 * */ - @Column(name = "LAST_LOGIN_TIME") + @Column(name = "last_login_time") private Date lastLoginTime; /** * 创建时间 * */ - @Column(name = "CREATED_TIME") + @Column(name = "created_time") private Date createdTime; + + /** + * 创建时间 + * */ + @Column(name = "updated_time") + private Date updatedTime; } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/mapper/MenuMapper.java b/src/main/java/com/rymcu/vertical/mapper/MenuMapper.java index ac8ea45..bcb4769 100644 --- a/src/main/java/com/rymcu/vertical/mapper/MenuMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/MenuMapper.java @@ -10,15 +10,5 @@ import java.util.List; public interface MenuMapper extends Mapper { - List selectMenuByRole(@Param("role") Role role); - - List findByParentId(@Param("parentId") String parentId); - - MenuDTO findMenuDTOById(@Param("id") String id); - - void deleteRoleMenu(@Param("menuId") String id); - - List findByParentIdAndUserId(@Param("parentId") String parentId, @Param("userId") String userId); - - void deleteMenu(@Param("id") String id); + List selectMenuByIdRole(@Param("role") Integer role); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/mapper/RoleMapper.java b/src/main/java/com/rymcu/vertical/mapper/RoleMapper.java index f15ac5a..4c2f4f3 100644 --- a/src/main/java/com/rymcu/vertical/mapper/RoleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/RoleMapper.java @@ -1,8 +1,6 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.User; import org.apache.ibatis.annotations.Param; @@ -10,25 +8,8 @@ import org.apache.ibatis.annotations.Param; import java.util.List; public interface RoleMapper extends Mapper { - List findAllDTO(@Param("role") RoleDTO roleDTO); - List selectRoleByUser(@Param("sysUser") User sysUser); + List selectRoleByIdUser(@Param("id") Integer id); - void insertRoleMenu(@Param("roleId") String id, @Param("menuId") String menuId); - - void deleteRoleMenuByRoleId(@Param("roleId") String roleId); - - void deleteUserRoleByRoleId(@Param("roleId") String roleId); - - RoleDTO findRoleDTOById(@Param("roleId") String roleId); - - String selectRoleIdsByUser(@Param("user") User user); - - List findUserOfRoleListData(@Param("user") UserDTO userDTO); - - void deleteUser(@Param("userId") String userId, @Param("roleId") String roleId); - - List findUnAddUserOfRole(@Param("userName") String userName, @Param("roleId") String roleId); - - void insertUserRole(@Param("userId") String userId, @Param("roleId") String roleId); + Role selectRoleByInputCode(@Param("inputCode") String inputCode); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java index 1a43f61..38dfdfb 100644 --- a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java @@ -1,35 +1,15 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; -import com.rymcu.vertical.dto.UserExportDTO; +import com.rymcu.vertical.dto.UserInfoDTO; import com.rymcu.vertical.entity.User; import org.apache.ibatis.annotations.Param; -import java.util.Date; -import java.util.List; - public interface UserMapper extends Mapper { - List findAllDTO(@Param("user") UserDTO userDTO); - UserDTO findUserDTOById(@Param("idUser") Integer idUser); + User findByAccount(@Param("account") String account); - void insertUserRole(@Param("idUser") Integer idUser, @Param("idRole") Integer idRole); + Integer insertUserRole(@Param("idUser") Integer idUser, @Param("idRole") Integer idRole); - void deleteUserRoleByUserId(@Param("idUser") Integer idUser); - - void deleteUserById(@Param("idUser") Integer idUser); - - void resetPassword(@Param("idUser") Integer idUser, @Param("password") String password); - - void updateLastLoginTime(@Param("idUser") Integer idUser, @Param("date") Date date); - - User findByLoginName(@Param("loginName") String loginName); - - List queryUserByInputCode(@Param("eName") String eName); - - List findUserExportData(@Param("user") UserDTO userDTO); - - List findRoleOfUser(@Param("idUser") Integer idUser); + UserInfoDTO findUserInfoByAccount(@Param("account") String account); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/service/JavaMailService.java b/src/main/java/com/rymcu/vertical/service/JavaMailService.java new file mode 100644 index 0000000..64651b8 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/JavaMailService.java @@ -0,0 +1,5 @@ +package com.rymcu.vertical.service; + +public interface JavaMailService { + Integer sendEmailCode(String email); +} diff --git a/src/main/java/com/rymcu/vertical/service/MenuService.java b/src/main/java/com/rymcu/vertical/service/MenuService.java index e91904f..fb6decf 100644 --- a/src/main/java/com/rymcu/vertical/service/MenuService.java +++ b/src/main/java/com/rymcu/vertical/service/MenuService.java @@ -14,20 +14,4 @@ import java.util.List; public interface MenuService extends Service { List selectMenuByUser(User sysUser); - - Menu getParent(Menu e); - - List findByParentId(String roleId); - - MenuDTO findMenuDTOById(String id); - - void saveMenu(MenuDTO menuDTO); - - void deleteMenuById(String id); - - void updateMenu(MenuDTO menuDTO); - - List findByParentIdAndUserId(String parentId, String userId); - - void updateUserStatus(String id, String flag); } diff --git a/src/main/java/com/rymcu/vertical/service/RoleService.java b/src/main/java/com/rymcu/vertical/service/RoleService.java index 683b4cf..3ef8e69 100644 --- a/src/main/java/com/rymcu/vertical/service/RoleService.java +++ b/src/main/java/com/rymcu/vertical/service/RoleService.java @@ -1,12 +1,9 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.User; -import javax.servlet.http.HttpServletRequest; import java.util.List; @@ -16,24 +13,4 @@ import java.util.List; public interface RoleService extends Service { List selectRoleByUser(User sysUser); - - List findAllDTO(HttpServletRequest request); - - void saveRole(RoleDTO roleDTO); - - void deleteAssociatedItemsForRole(String id); - - RoleDTO findRoleDTOById(String id); - - void updateRole(RoleDTO roleDTO); - - List findUserOfRoleListData(HttpServletRequest request); - - void deleteUser(String userId, String roleId); - - List findUnAddUserOfRole(HttpServletRequest request); - - String addUserOfRole(String roleId, String ids); - - void updateMenu(RoleDTO roleDTO); } diff --git a/src/main/java/com/rymcu/vertical/service/UserService.java b/src/main/java/com/rymcu/vertical/service/UserService.java index 369102a..3100e04 100644 --- a/src/main/java/com/rymcu/vertical/service/UserService.java +++ b/src/main/java/com/rymcu/vertical/service/UserService.java @@ -1,15 +1,10 @@ package com.rymcu.vertical.service; -import com.rymcu.vertical.core.exception.ServiceException; import com.rymcu.vertical.core.service.Service; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; -import com.rymcu.vertical.dto.UserExportDTO; import com.rymcu.vertical.entity.User; import org.apache.ibatis.exceptions.TooManyResultsException; -import javax.servlet.http.HttpServletRequest; -import java.util.List; +import java.util.Map; /** @@ -17,29 +12,10 @@ import java.util.List; */ public interface UserService extends Service { - List findAllDTO(HttpServletRequest request); - UserDTO findUserDTOById(Integer id); + User findByAccount(String account) throws TooManyResultsException; - void saveUser(UserDTO userDTO); + Map register(String email, String password, String code); - void updateUser(UserDTO userDTO); - - void deleteUserById(Integer id); - - Boolean checkLoginName(String loginName); - - void updateUserStatus(Integer id, Integer flag); - - void resetPassword(Integer userId, String password); - - User findByLoginName(String loginName) throws TooManyResultsException, ServiceException; - - List queryUserByInputCode(String eName); - - void updateLastLoginTime(Integer id); - - List exportExcel(HttpServletRequest request); - - List findRoleOfUser(HttpServletRequest request); + Map login(String account, String password); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/JavaMailServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/JavaMailServiceImpl.java new file mode 100644 index 0000000..4f93e6c --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/impl/JavaMailServiceImpl.java @@ -0,0 +1,39 @@ +package com.rymcu.vertical.service.impl; + +import com.rymcu.vertical.core.service.redis.RedisService; +import com.rymcu.vertical.service.JavaMailService; +import com.rymcu.vertical.util.Utils; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class JavaMailServiceImpl implements JavaMailService { + + @Resource + private JavaMailSenderImpl mailSender; + @Resource + private RedisService redisService; + + @Override + public Integer sendEmailCode(String email) { + return sendCode(email,0); + } + + private Integer sendCode(String to, Integer type) { + Integer code = Utils.genCode(); + redisService.set(to,code,5*60); + if(type == 0) { + SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); + simpleMailMessage.setFrom("service@rymcu.com"); + simpleMailMessage.setTo(to); + simpleMailMessage.setSubject("新用户注册邮箱验证"); + simpleMailMessage.setText("【RYMCU】您的校验码是 " + code + ",有效时间 5 分钟,请不要泄露验证码给其他人。如非本人操作,请忽略!"); + mailSender.send(simpleMailMessage); + return 1; + } + return 0; + } +} diff --git a/src/main/java/com/rymcu/vertical/service/impl/MenuServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/MenuServiceImpl.java index de390d2..1c3a15d 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/MenuServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/MenuServiceImpl.java @@ -36,72 +36,10 @@ public class MenuServiceImpl extends AbstractService implements MenuServic public List selectMenuByUser(User sysUser) { List list = new ArrayList(); List roles = roleService.selectRoleByUser(sysUser); - roles.forEach(role -> list.addAll(menuMapper.selectMenuByRole(role))); + roles.forEach(role -> list.addAll(menuMapper.selectMenuByIdRole(role.getIdRole()))); HashSet hashSet = new HashSet(list); list.clear(); list.addAll(hashSet); return list; } - - @Override - public Menu getParent(Menu e) { - String parentId = "0"; - if(e != null){ - if(StringUtils.isNotBlank(e.getParentId())){ - parentId = e.getParentId(); - } - } - return menuMapper.selectByPrimaryKey(parentId); - } - - @Override - public List findByParentId(String parentId) { - List list = menuMapper.findByParentId(parentId); - return list; - } - - @Override - public MenuDTO findMenuDTOById(String id) { - return menuMapper.findMenuDTOById(id); - } - - @Override - public void saveMenu(MenuDTO menuDTO) { - Menu menu = new Menu(); - BeanCopierUtil.copy(menuDTO,menu); - //Utils.createBase(menu); - menuMapper.insert(menu); - //Utils.removeAllMenu(); - } - - @Override - public void deleteMenuById(String id) { - menuMapper.deleteRoleMenu(id); - menuMapper.deleteMenu(id); - //Utils.removeAllMenu(); - } - - @Override - public void updateMenu(MenuDTO menuDTO) { - Menu menu = menuMapper.selectByPrimaryKey(menuDTO.getId()); - BeanCopierUtil.copy(menuDTO,menu); - //Utils.updateBase(menu); - menuMapper.updateByPrimaryKey(menu); - //Utils.removeAllMenu(); - //UserUtils.removeMenuList(); - } - - @Override - public List findByParentIdAndUserId(String parentId, String userId) { - return menuMapper.findByParentIdAndUserId(parentId, userId); - } - - @Override - public void updateUserStatus(String id, String flag) { - Menu menu = menuMapper.selectByPrimaryKey(id); - menu.setStatus(flag); - //Utils.updateBase(menu); - menuMapper.updateByPrimaryKey(menu); - //Utils.removeAllMenu(); - } } diff --git a/src/main/java/com/rymcu/vertical/service/impl/RoleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/RoleServiceImpl.java index 57665b6..32ee6c2 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/RoleServiceImpl.java @@ -1,21 +1,15 @@ package com.rymcu.vertical.service.impl; import com.rymcu.vertical.core.service.AbstractService; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.RoleMapper; import com.rymcu.vertical.service.RoleService; -import com.rymcu.vertical.util.BeanCopierUtil; -import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.List; -import java.util.UUID; /** @@ -29,119 +23,8 @@ public class RoleServiceImpl extends AbstractService implements RoleServic @Override public List selectRoleByUser(User sysUser) { - List roles = roleMapper.selectRoleByUser(sysUser); + List roles = roleMapper.selectRoleByIdUser(sysUser.getIdUser()); return roles; } - @Override - public List findAllDTO(HttpServletRequest request) { - RoleDTO roleDTO = new RoleDTO(); - roleDTO.setName(request.getParameter("name")); - roleDTO.setEnname(request.getParameter("enName")); - return roleMapper.findAllDTO(roleDTO); - } - - @Override - public void saveRole(RoleDTO roleDTO) { - Role role = new Role(); - BeanCopierUtil.copy(roleDTO,role); - //Utils.createBase(role); - roleMapper.insert(role); - - String menuIds = roleDTO.getMenuIds(); - String[] m = menuIds.split(","); - for (int i = 0,len = m.length; i < len; i++) { - roleMapper.insertRoleMenu(role.getIdRole(),m[i]); - } - } - - @Override - public void deleteAssociatedItemsForRole(String roleId) { - - roleMapper.deleteUserRoleByRoleId(roleId); - - roleMapper.deleteByPrimaryKey(roleId); - } - - @Override - public RoleDTO findRoleDTOById(String id) { - return roleMapper.findRoleDTOById(id); - } - - @Override - public void updateRole(RoleDTO roleDTO) { - String menuIds = ""; - Role role = roleMapper.selectByPrimaryKey(roleDTO.getId()); - - BeanCopierUtil.copy(roleDTO,role); - //Utils.updateBase(role); - roleMapper.updateByPrimaryKey(role); - - if("0".equals(roleDTO.getMenuIds())){ - menuIds = roleMapper.findRoleDTOById(roleDTO.getId()).getMenuIds(); - }else { - menuIds = roleDTO.getMenuIds(); - } - - roleMapper.deleteRoleMenuByRoleId(role.getIdRole()); - - String[] m = menuIds.split(","); - for (int i = 0,len = m.length; i < len; i++) { - roleMapper.insertRoleMenu(role.getIdRole(),m[i]); - } - - } - - @Override - public List findUserOfRoleListData(HttpServletRequest request) { - UserDTO userDTO = new UserDTO(); - userDTO.setLoginName(request.getParameter("loginName")); - userDTO.setInputCode(request.getParameter("inputCode")); - userDTO.setName(request.getParameter("name")); - userDTO.setStatus(request.getParameter("status")); - userDTO.setOfficeId(request.getParameter("officeId")); - userDTO.setRemarks(request.getParameter("roleId"));// 为不创建多余字段,此处使用 Remark 字段存放 roleId 数据 - return roleMapper.findUserOfRoleListData(userDTO); - } - - @Override - public void deleteUser(String userId, String roleId) { - roleMapper.deleteUser(userId,roleId); - } - - @Override - public List findUnAddUserOfRole(HttpServletRequest request) { - String roleId = request.getParameter("roleId"); - String userName = request.getParameter("userName"); - return roleMapper.findUnAddUserOfRole(userName,roleId); - } - - @Override - public String addUserOfRole(String roleId, String ids) { - String message = ""; - String[] userIds = ids.split(","); - for (String userId:userIds) { - if(!(",".equals(userId) || StringUtils.isBlank(userId))){ - roleMapper.insertUserRole(userId,roleId); - } - } - return message; - } - - @Override - public void updateMenu(RoleDTO roleDTO) { - String menuIds; - if("0".equals(roleDTO.getMenuIds())){ - menuIds = roleMapper.findRoleDTOById(roleDTO.getId()).getMenuIds(); - }else { - menuIds = roleDTO.getMenuIds(); - } - - roleMapper.deleteRoleMenuByRoleId(roleDTO.getId()); - - String[] m = menuIds.split(","); - for (int i = 0,len = m.length; i < len; i++) { - roleMapper.insertRoleMenu(roleDTO.getId(),m[i]); - } - } } diff --git a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java index 8c639d1..bf4d97e 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java @@ -1,11 +1,13 @@ package com.rymcu.vertical.service.impl; -import com.rymcu.vertical.core.exception.ServiceException; import com.rymcu.vertical.core.service.AbstractService; -import com.rymcu.vertical.dto.RoleDTO; -import com.rymcu.vertical.dto.UserDTO; -import com.rymcu.vertical.dto.UserExportDTO; +import com.rymcu.vertical.core.service.redis.RedisService; +import com.rymcu.vertical.dto.TUser; +import com.rymcu.vertical.dto.UserInfoDTO; +import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.jwt.service.TokenManager; +import com.rymcu.vertical.mapper.RoleMapper; import com.rymcu.vertical.mapper.UserMapper; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.BeanCopierUtil; @@ -14,12 +16,11 @@ import org.apache.commons.lang.StringUtils; import org.apache.ibatis.exceptions.TooManyResultsException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import tk.mybatis.mapper.entity.Condition; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.Date; -import java.util.List; +import java.util.HashMap; +import java.util.Map; /** @@ -29,139 +30,69 @@ import java.util.List; public class UserServiceImpl extends AbstractService implements UserService { @Resource private UserMapper userMapper; + @Resource + private RoleMapper roleMapper; + @Resource + private RedisService redisService; + @Resource + private TokenManager tokenManager; @Override - public List findAllDTO(HttpServletRequest request) { - UserDTO userDTO = new UserDTO(); - userDTO.setLoginName(request.getParameter("loginName")); - userDTO.setInputCode(request.getParameter("inputCode")); - userDTO.setName(request.getParameter("name")); - userDTO.setStatus(request.getParameter("status")); - userDTO.setOfficeId(request.getParameter("officeId"));// 为不创建多余字段,此处使用 Remark 字段存放 nodeId 数据 - return userMapper.findAllDTO(userDTO); - } - - @Override - public UserDTO findUserDTOById(Integer id) { - return userMapper.findUserDTOById(id); + public User findByAccount(String account) throws TooManyResultsException{ + return userMapper.findByAccount(account); } @Override @Transactional - public void saveUser(UserDTO userDTO) { + public Map register(String email, String password, String code) { + Map map = new HashMap(); + map.put("message","验证码无效!"); + String vcode = redisService.get(email); + if(StringUtils.isNotBlank(vcode)){ + if(vcode.equals(code)){ + User user = userMapper.findByAccount(email); + if(user != null){ + map.put("message","该邮箱已被注册!"); + } else { + user = new User(); + user.setAccount(email); + user.setNickname(email); + user.setEmail(email); + user.setPassword(Utils.entryptPassword(password)); + user.setCreatedTime(new Date()); + user.setUpdatedTime(user.getCreatedTime()); + userMapper.insertSelective(user); + user = userMapper.findByAccount(email); + Role role = roleMapper.selectRoleByInputCode("user"); + userMapper.insertUserRole(user.getIdUser(), role.getIdRole()); + map.put("message","注册成功!"); + redisService.delete(email); + } + } + } + return map; + } + + @Override + public Map login(String account, String password) { + Map map = new HashMap(); User user = new User(); - BeanCopierUtil.copy(userDTO, user); - //user.setPassword(Utils.entryptPassword("123456")); - //Utils.createBase(user); - //所有字符转为小写 - user.setAccount(user.getAccount().toLowerCase()); - userMapper.insertSelective(user); - - String roleIds = userDTO.getRoleIds(); - if(StringUtils.isNotBlank(roleIds)){ - String[] r = roleIds.split(","); - for(int i=0,len=r.length;i findRoleOfUser(HttpServletRequest request) { - String userId = request.getParameter("userId"); - return userMapper.findRoleOfUser(Integer.parseInt(userId)); + return map; } } diff --git a/src/main/java/com/rymcu/vertical/util/Utils.java b/src/main/java/com/rymcu/vertical/util/Utils.java index 4207483..97a4bcf 100644 --- a/src/main/java/com/rymcu/vertical/util/Utils.java +++ b/src/main/java/com/rymcu/vertical/util/Utils.java @@ -52,4 +52,9 @@ public class Utils { } return null; } + + public static Integer genCode() { + Integer code = (int)((Math.random()*9+1)*100000); + return code; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java new file mode 100644 index 0000000..1be2c82 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java @@ -0,0 +1,54 @@ +package com.rymcu.vertical.web.api.common; + +import com.rymcu.vertical.core.exception.ServiceException; +import com.rymcu.vertical.core.result.GlobalResult; +import com.rymcu.vertical.core.result.GlobalResultGenerator; +import com.rymcu.vertical.core.result.GlobalResultMessage; +import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.service.JavaMailService; +import com.rymcu.vertical.service.UserService; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping("/api/v1") +public class CommonApiController { + + @Resource + private JavaMailService javaMailService; + @Resource + private UserService userService; + + @ApiOperation(value = "获取邮件验证码") + @PostMapping("/get-email-code") + public GlobalResult getEmailCode(@RequestParam("email") String email) throws ServiceException { + Map map = new HashMap(); + map.put("message",GlobalResultMessage.SEND_SUCCESS); + User user = userService.findByAccount(email); + if (user != null) { + map.put("message","该邮箱已被注册!"); + } else { + Integer result = javaMailService.sendEmailCode(email); + if(result == 0){ + map.put("message",GlobalResultMessage.SEND_FAIL); + } + } + return GlobalResultGenerator.genSuccessResult(map); + } + + @PostMapping("/register") + public GlobalResult register(@RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("code") String code){ + Map map = userService.register(email,password,code); + return GlobalResultGenerator.genSuccessResult(map); + } + + @PostMapping("/login") + public GlobalResult login(@RequestParam("account") String account, @RequestParam("password") String password){ + Map map = userService.login(account,password); + return GlobalResultGenerator.genSuccessResult(map); + } +} diff --git a/src/main/java/mapper/MenuMapper.xml b/src/main/java/mapper/MenuMapper.xml index c2fa40e..84cfa1b 100644 --- a/src/main/java/mapper/MenuMapper.xml +++ b/src/main/java/mapper/MenuMapper.xml @@ -5,83 +5,18 @@ - - - - - - - - - + + + + + + + + + - - ID, - PARENT_ID parentId, - (select NAME - from SYS_MENU - where ID = #{parentId}) parentName, - NAME, - SORT, - HREF, - MENU_TYPE menuType, - PERMISSION, - REMARKS, - STATUS - - - - ID, - PARENT_ID parentId, - (select NAME - from SYS_MENU - where ID = m.PARENT_ID) parentName, - NAME, - SORT, - HREF, - MENU_TYPE menuType, - PERMISSION, - REMARKS, - STATUS - - - - delete SYS_ROLE_MENU - where MENU_ID = #{menuId} - - - update SYS_MENU set STATUS = '2' where ID = #{id} - - - + select * from sys_role_menu srm left join sys_menu sm on srm.id_menu = sm.id where status = '0' order by sort - - - - - - - \ No newline at end of file diff --git a/src/main/java/mapper/RoleMapper.xml b/src/main/java/mapper/RoleMapper.xml index ea97e22..e164e5d 100644 --- a/src/main/java/mapper/RoleMapper.xml +++ b/src/main/java/mapper/RoleMapper.xml @@ -5,143 +5,25 @@ - - - - - + + + + + + - - - - - - + + + + - - r.ID, - r.NAME, - r.ROLE_TYPE, - r.ENNAME, - r.REMARKS - - - - insert into SYS_ROLE_MENU (ROLE_ID, MENU_ID) VALUES (#{roleId}, #{menuId}) - - - insert into SYS_USER_ROLE (USER_ID, ROLE_ID) VALUES (#{userId}, #{roleId}) - - - - delete SYS_ROLE_MENU where ROLE_ID = #{roleId} - - - - delete SYS_USER_ROLE where ROLE_ID = #{roleId} - - - delete SYS_USER_ROLE where ROLE_ID = #{roleId} AND USER_ID = #{userId} - - - + select sr.* from sys_user_role sur left join sys_role sr on sur.id_role = sr.id where id_user = #{id} + + - - - - - \ No newline at end of file diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index f7c7103..4bd1fd7 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -5,165 +5,41 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + - insert into SYS_USER_ROLE (USER_ID, ROLE_ID) VALUES (#{userId}, #{roleId}) + insert into sys_user_role (id_user,id_role,created_time) values (#{idUser},#{idRole},sysdate()) - - delete SYS_USER_ROLE - where USER_ID = #{userId} - - - update SYS_USER set STATUS = 2 where ID = #{id} - - - UPDATE SYS_USER SET PASSWORD = #{password} WHERE ID = #{userId} - - - UPDATE SYS_USER SET LAST_LOGIN_TIME = #{date} WHERE ID = #{id} - - + select id, nickname, account, password, status from sys_user where account = #{account} AND status = 0 - - + select id, nickname, sex, avatar_type, avatar_url, email, phone, account, password, status, last_login_time from sus_user when account = #{account} - - - - \ No newline at end of file