正在显示
36 个修改的文件
包含
1113 行增加
和
190 行删除
| @@ -4,7 +4,7 @@ import com.ruoyi.common.annotation.Log; | @@ -4,7 +4,7 @@ import com.ruoyi.common.annotation.Log; | ||
| 4 | import com.ruoyi.common.constant.Constants; | 4 | import com.ruoyi.common.constant.Constants; |
| 5 | import com.ruoyi.common.core.controller.BaseController; | 5 | import com.ruoyi.common.core.controller.BaseController; |
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | -import com.zhonglai.luhui.admin.model.LoginUser; | 7 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 8 | import com.ruoyi.common.core.page.TableDataInfo; | 8 | import com.ruoyi.common.core.page.TableDataInfo; |
| 9 | import com.ruoyi.common.core.redis.RedisCache; | 9 | import com.ruoyi.common.core.redis.RedisCache; |
| 10 | import com.ruoyi.common.enums.BusinessType; | 10 | import com.ruoyi.common.enums.BusinessType; |
| @@ -53,7 +53,7 @@ public class SysUserOnlineController extends BaseController | @@ -53,7 +53,7 @@ public class SysUserOnlineController extends BaseController | ||
| 53 | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); | 53 | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| 54 | for (String key : keys) | 54 | for (String key : keys) |
| 55 | { | 55 | { |
| 56 | - LoginUser user = redisCache.getCacheObject(key); | 56 | + SysLoginUser user = redisCache.getCacheObject(key); |
| 57 | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) | 57 | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) |
| 58 | { | 58 | { |
| 59 | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) | 59 | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) |
| @@ -5,6 +5,7 @@ import com.ruoyi.common.core.controller.BaseController; | @@ -5,6 +5,7 @@ import com.ruoyi.common.core.controller.BaseController; | ||
| 5 | import com.ruoyi.common.core.domain.AjaxResult; | 5 | import com.ruoyi.common.core.domain.AjaxResult; |
| 6 | import com.ruoyi.system.domain.entity.SysMenu; | 6 | import com.ruoyi.system.domain.entity.SysMenu; |
| 7 | import com.ruoyi.system.domain.entity.SysUser; | 7 | import com.ruoyi.system.domain.entity.SysUser; |
| 8 | +import com.ruoyi.system.login.service.LoginService; | ||
| 8 | import com.zhonglai.luhui.admin.model.LoginBody; | 9 | import com.zhonglai.luhui.admin.model.LoginBody; |
| 9 | import com.ruoyi.common.utils.SecurityUtils; | 10 | import com.ruoyi.common.utils.SecurityUtils; |
| 10 | import com.zhonglai.luhui.admin.service.SysLoginService; | 11 | import com.zhonglai.luhui.admin.service.SysLoginService; |
| @@ -31,7 +32,7 @@ import java.util.Set; | @@ -31,7 +32,7 @@ import java.util.Set; | ||
| 31 | public class SysLoginController extends BaseController | 32 | public class SysLoginController extends BaseController |
| 32 | { | 33 | { |
| 33 | @Autowired | 34 | @Autowired |
| 34 | - private SysLoginService loginService; | 35 | + private LoginService loginService; |
| 35 | 36 | ||
| 36 | @Autowired | 37 | @Autowired |
| 37 | private ISysMenuService menuService; | 38 | private ISysMenuService menuService; |
| @@ -45,7 +46,7 @@ public class SysLoginController extends BaseController | @@ -45,7 +46,7 @@ public class SysLoginController extends BaseController | ||
| 45 | { | 46 | { |
| 46 | AjaxResult ajax = AjaxResult.success(); | 47 | AjaxResult ajax = AjaxResult.success(); |
| 47 | // 生成令牌 | 48 | // 生成令牌 |
| 48 | - String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), | 49 | + String token = loginService.sysUserLogin(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), |
| 49 | loginBody.getUuid()); | 50 | loginBody.getUuid()); |
| 50 | ajax.put(Constants.TOKEN, token); | 51 | ajax.put(Constants.TOKEN, token); |
| 51 | return ajax; | 52 | return ajax; |
| @@ -60,7 +61,7 @@ public class SysLoginController extends BaseController | @@ -60,7 +61,7 @@ public class SysLoginController extends BaseController | ||
| 60 | @GetMapping("getInfo") | 61 | @GetMapping("getInfo") |
| 61 | public AjaxResult getInfo() | 62 | public AjaxResult getInfo() |
| 62 | { | 63 | { |
| 63 | - SysUser user = SecurityUtils.getLoginUser().getUser(); | 64 | + SysUser user = (SysUser) SecurityUtils.getLoginUser().getUser(); |
| 64 | // 角色集合 | 65 | // 角色集合 |
| 65 | Set<String> roles = permissionService.getRolePermission(user); | 66 | Set<String> roles = permissionService.getRolePermission(user); |
| 66 | // 权限集合 | 67 | // 权限集合 |
| @@ -6,12 +6,12 @@ import com.ruoyi.system.domain.entity.UserConstants; | @@ -6,12 +6,12 @@ import com.ruoyi.system.domain.entity.UserConstants; | ||
| 6 | import com.ruoyi.common.core.controller.BaseController; | 6 | import com.ruoyi.common.core.controller.BaseController; |
| 7 | import com.ruoyi.common.core.domain.AjaxResult; | 7 | import com.ruoyi.common.core.domain.AjaxResult; |
| 8 | import com.ruoyi.system.domain.entity.SysUser; | 8 | import com.ruoyi.system.domain.entity.SysUser; |
| 9 | -import com.zhonglai.luhui.admin.model.LoginUser; | 9 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 10 | import com.ruoyi.common.enums.BusinessType; | 10 | import com.ruoyi.common.enums.BusinessType; |
| 11 | import com.ruoyi.common.utils.SecurityUtils; | 11 | import com.ruoyi.common.utils.SecurityUtils; |
| 12 | import com.ruoyi.common.utils.StringUtils; | 12 | import com.ruoyi.common.utils.StringUtils; |
| 13 | import com.ruoyi.common.utils.file.FileUploadUtils; | 13 | import com.ruoyi.common.utils.file.FileUploadUtils; |
| 14 | -import com.ruoyi.framework.web.service.TokenService; | 14 | +import com.ruoyi.system.login.service.TokenService; |
| 15 | import com.ruoyi.system.service.ISysUserService; | 15 | import com.ruoyi.system.service.ISysUserService; |
| 16 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 17 | import io.swagger.annotations.ApiOperation; | 17 | import io.swagger.annotations.ApiOperation; |
| @@ -44,7 +44,7 @@ public class SysProfileController extends BaseController | @@ -44,7 +44,7 @@ public class SysProfileController extends BaseController | ||
| 44 | @GetMapping | 44 | @GetMapping |
| 45 | public AjaxResult profile() | 45 | public AjaxResult profile() |
| 46 | { | 46 | { |
| 47 | - LoginUser loginUser = getLoginUser(); | 47 | + SysLoginUser loginUser = getLoginUser(); |
| 48 | SysUser user = loginUser.getUser(); | 48 | SysUser user = loginUser.getUser(); |
| 49 | AjaxResult ajax = AjaxResult.success(user); | 49 | AjaxResult ajax = AjaxResult.success(user); |
| 50 | ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); | 50 | ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); |
| @@ -60,7 +60,7 @@ public class SysProfileController extends BaseController | @@ -60,7 +60,7 @@ public class SysProfileController extends BaseController | ||
| 60 | @PutMapping | 60 | @PutMapping |
| 61 | public AjaxResult updateProfile(@RequestBody SysUser user) | 61 | public AjaxResult updateProfile(@RequestBody SysUser user) |
| 62 | { | 62 | { |
| 63 | - LoginUser loginUser = getLoginUser(); | 63 | + SysLoginUser loginUser = getLoginUser(); |
| 64 | SysUser sysUser = loginUser.getUser(); | 64 | SysUser sysUser = loginUser.getUser(); |
| 65 | user.setUserName(sysUser.getUserName()); | 65 | user.setUserName(sysUser.getUserName()); |
| 66 | if (StringUtils.isNotEmpty(user.getPhonenumber()) | 66 | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| @@ -96,7 +96,7 @@ public class SysProfileController extends BaseController | @@ -96,7 +96,7 @@ public class SysProfileController extends BaseController | ||
| 96 | @PutMapping("/updatePwd") | 96 | @PutMapping("/updatePwd") |
| 97 | public AjaxResult updatePwd(String oldPassword, String newPassword) | 97 | public AjaxResult updatePwd(String oldPassword, String newPassword) |
| 98 | { | 98 | { |
| 99 | - LoginUser loginUser = getLoginUser(); | 99 | + SysLoginUser loginUser = getLoginUser(); |
| 100 | String userName = loginUser.getUsername(); | 100 | String userName = loginUser.getUsername(); |
| 101 | String password = loginUser.getPassword(); | 101 | String password = loginUser.getPassword(); |
| 102 | if (!SecurityUtils.matchesPassword(oldPassword, password)) | 102 | if (!SecurityUtils.matchesPassword(oldPassword, password)) |
| @@ -127,7 +127,7 @@ public class SysProfileController extends BaseController | @@ -127,7 +127,7 @@ public class SysProfileController extends BaseController | ||
| 127 | { | 127 | { |
| 128 | if (!file.isEmpty()) | 128 | if (!file.isEmpty()) |
| 129 | { | 129 | { |
| 130 | - LoginUser loginUser = getLoginUser(); | 130 | + SysLoginUser loginUser = getLoginUser(); |
| 131 | String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); | 131 | String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); |
| 132 | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) | 132 | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) |
| 133 | { | 133 | { |
| @@ -6,13 +6,13 @@ import com.ruoyi.common.core.controller.BaseController; | @@ -6,13 +6,13 @@ import com.ruoyi.common.core.controller.BaseController; | ||
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | import com.ruoyi.system.domain.entity.SysRole; | 7 | import com.ruoyi.system.domain.entity.SysRole; |
| 8 | import com.ruoyi.system.domain.entity.SysUser; | 8 | import com.ruoyi.system.domain.entity.SysUser; |
| 9 | -import com.zhonglai.luhui.admin.model.LoginUser; | 9 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 10 | import com.ruoyi.common.core.page.TableDataInfo; | 10 | import com.ruoyi.common.core.page.TableDataInfo; |
| 11 | import com.ruoyi.common.enums.BusinessType; | 11 | import com.ruoyi.common.enums.BusinessType; |
| 12 | import com.ruoyi.common.utils.StringUtils; | 12 | import com.ruoyi.common.utils.StringUtils; |
| 13 | import com.ruoyi.common.utils.poi.ExcelUtil; | 13 | import com.ruoyi.common.utils.poi.ExcelUtil; |
| 14 | import com.zhonglai.luhui.admin.service.SysPermissionService; | 14 | import com.zhonglai.luhui.admin.service.SysPermissionService; |
| 15 | -import com.ruoyi.framework.web.service.TokenService; | 15 | +import com.ruoyi.system.login.service.TokenService; |
| 16 | import com.ruoyi.system.domain.SysUserRole; | 16 | import com.ruoyi.system.domain.SysUserRole; |
| 17 | import com.ruoyi.system.service.ISysRoleService; | 17 | import com.ruoyi.system.service.ISysRoleService; |
| 18 | import com.ruoyi.system.service.ISysUserService; | 18 | import com.ruoyi.system.service.ISysUserService; |
| @@ -127,7 +127,7 @@ public class SysRoleController extends BaseController | @@ -127,7 +127,7 @@ public class SysRoleController extends BaseController | ||
| 127 | if (roleService.updateRole(role) > 0) | 127 | if (roleService.updateRole(role) > 0) |
| 128 | { | 128 | { |
| 129 | // 更新缓存用户权限 | 129 | // 更新缓存用户权限 |
| 130 | - LoginUser loginUser = getLoginUser(); | 130 | + SysLoginUser loginUser = getLoginUser(); |
| 131 | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) | 131 | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) |
| 132 | { | 132 | { |
| 133 | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); | 133 | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); |
| 1 | package com.zhonglai.luhui.admin.service; | 1 | package com.zhonglai.luhui.admin.service; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | import com.ruoyi.system.domain.entity.SysRole; | 3 | import com.ruoyi.system.domain.entity.SysRole; |
| 5 | -import com.zhonglai.luhui.admin.model.LoginUser; | 4 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 6 | import com.ruoyi.common.utils.SecurityUtils; | 5 | import com.ruoyi.common.utils.SecurityUtils; |
| 7 | import com.ruoyi.common.utils.StringUtils; | 6 | import com.ruoyi.common.utils.StringUtils; |
| 8 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| @@ -40,7 +39,7 @@ public class PermissionService | @@ -40,7 +39,7 @@ public class PermissionService | ||
| 40 | { | 39 | { |
| 41 | return false; | 40 | return false; |
| 42 | } | 41 | } |
| 43 | - LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser(); | 42 | + SysLoginUser loginUser = (SysLoginUser) SecurityUtils.getLoginUser(); |
| 44 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) | 43 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) |
| 45 | { | 44 | { |
| 46 | return false; | 45 | return false; |
| @@ -71,7 +70,7 @@ public class PermissionService | @@ -71,7 +70,7 @@ public class PermissionService | ||
| 71 | { | 70 | { |
| 72 | return false; | 71 | return false; |
| 73 | } | 72 | } |
| 74 | - LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser(); | 73 | + SysLoginUser loginUser = (SysLoginUser) SecurityUtils.getLoginUser(); |
| 75 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) | 74 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) |
| 76 | { | 75 | { |
| 77 | return false; | 76 | return false; |
| @@ -99,7 +98,7 @@ public class PermissionService | @@ -99,7 +98,7 @@ public class PermissionService | ||
| 99 | { | 98 | { |
| 100 | return false; | 99 | return false; |
| 101 | } | 100 | } |
| 102 | - LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser(); | 101 | + SysLoginUser loginUser = (SysLoginUser) SecurityUtils.getLoginUser(); |
| 103 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) | 102 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) |
| 104 | { | 103 | { |
| 105 | return false; | 104 | return false; |
| @@ -138,7 +137,7 @@ public class PermissionService | @@ -138,7 +137,7 @@ public class PermissionService | ||
| 138 | { | 137 | { |
| 139 | return false; | 138 | return false; |
| 140 | } | 139 | } |
| 141 | - LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser(); | 140 | + SysLoginUser loginUser = (SysLoginUser) SecurityUtils.getLoginUser(); |
| 142 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) | 141 | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) |
| 143 | { | 142 | { |
| 144 | return false; | 143 | return false; |
| 1 | package com.zhonglai.luhui.admin.service; | 1 | package com.zhonglai.luhui.admin.service; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.constant.Constants; | ||
| 4 | -import com.ruoyi.system.domain.entity.SysUser; | ||
| 5 | -import com.zhonglai.luhui.admin.model.LoginUser; | ||
| 6 | -import com.ruoyi.common.core.redis.RedisCache; | ||
| 7 | -import com.ruoyi.common.exception.ServiceException; | ||
| 8 | -import com.ruoyi.common.exception.user.CaptchaException; | ||
| 9 | -import com.ruoyi.common.exception.user.CaptchaExpireException; | ||
| 10 | -import com.ruoyi.common.exception.user.UserPasswordNotMatchException; | ||
| 11 | -import com.ruoyi.common.utils.DateUtils; | ||
| 12 | -import com.ruoyi.common.utils.MessageUtils; | ||
| 13 | -import com.ruoyi.common.utils.ServletUtils; | ||
| 14 | -import com.ruoyi.common.utils.StringUtils; | ||
| 15 | -import com.ruoyi.common.utils.ip.IpUtils; | ||
| 16 | -import com.ruoyi.framework.manager.AsyncManager; | ||
| 17 | -import com.ruoyi.framework.manager.factory.AsyncFactory; | ||
| 18 | -import com.ruoyi.framework.web.service.TokenService; | 3 | +import com.ruoyi.system.login.service.TokenService; |
| 19 | import com.ruoyi.system.service.ISysConfigService; | 4 | import com.ruoyi.system.service.ISysConfigService; |
| 20 | -import com.ruoyi.system.service.ISysUserService; | ||
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.security.authentication.AuthenticationManager; | 6 | import org.springframework.security.authentication.AuthenticationManager; |
| 23 | -import org.springframework.security.authentication.BadCredentialsException; | ||
| 24 | -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| 25 | -import org.springframework.security.core.Authentication; | ||
| 26 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 27 | 8 | ||
| 28 | import javax.annotation.Resource; | 9 | import javax.annotation.Resource; |
| @@ -41,96 +22,9 @@ public class SysLoginService | @@ -41,96 +22,9 @@ public class SysLoginService | ||
| 41 | @Resource | 22 | @Resource |
| 42 | private AuthenticationManager authenticationManager; | 23 | private AuthenticationManager authenticationManager; |
| 43 | 24 | ||
| 44 | - @Autowired | ||
| 45 | - private RedisCache redisCache; | ||
| 46 | - | ||
| 47 | - @Autowired | ||
| 48 | - private ISysUserService userService; | ||
| 49 | 25 | ||
| 50 | @Autowired | 26 | @Autowired |
| 51 | private ISysConfigService configService; | 27 | private ISysConfigService configService; |
| 52 | 28 | ||
| 53 | - /** | ||
| 54 | - * 登录验证 | ||
| 55 | - * | ||
| 56 | - * @param username 用户名 | ||
| 57 | - * @param password 密码 | ||
| 58 | - * @param code 验证码 | ||
| 59 | - * @param uuid 唯一标识 | ||
| 60 | - * @return 结果 | ||
| 61 | - */ | ||
| 62 | - public String login(String username, String password, String code, String uuid) | ||
| 63 | - { | ||
| 64 | -// boolean captchaOnOff = configService.selectCaptchaOnOff(); | ||
| 65 | -// // 验证码开关 | ||
| 66 | -// if (captchaOnOff) | ||
| 67 | -// { | ||
| 68 | -// validateCaptcha(username, code, uuid); | ||
| 69 | -// } | ||
| 70 | - // 用户验证 | ||
| 71 | - Authentication authentication = null; | ||
| 72 | - try | ||
| 73 | - { | ||
| 74 | - // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername | ||
| 75 | - authentication = authenticationManager | ||
| 76 | - .authenticate(new UsernamePasswordAuthenticationToken(username, password)); | ||
| 77 | - } | ||
| 78 | - catch (Exception e) | ||
| 79 | - { | ||
| 80 | - if (e instanceof BadCredentialsException) | ||
| 81 | - { | ||
| 82 | - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); | ||
| 83 | - throw new UserPasswordNotMatchException(); | ||
| 84 | - } | ||
| 85 | - else | ||
| 86 | - { | ||
| 87 | - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); | ||
| 88 | - throw new ServiceException(e.getMessage()); | ||
| 89 | - } | ||
| 90 | - } | ||
| 91 | - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); | ||
| 92 | - LoginUser loginUser = (LoginUser) authentication.getPrincipal(); | ||
| 93 | - recordLoginInfo(loginUser.getUserId()); | ||
| 94 | - // 生成token | ||
| 95 | - return tokenService.createToken(loginUser); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - /** | ||
| 99 | - * 校验验证码 | ||
| 100 | - * | ||
| 101 | - * @param username 用户名 | ||
| 102 | - * @param code 验证码 | ||
| 103 | - * @param uuid 唯一标识 | ||
| 104 | - * @return 结果 | ||
| 105 | - */ | ||
| 106 | - public void validateCaptcha(String username, String code, String uuid) | ||
| 107 | - { | ||
| 108 | - String verifyKey = Constants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); | ||
| 109 | - String captcha = redisCache.getCacheObject(verifyKey); | ||
| 110 | - redisCache.deleteObject(verifyKey); | ||
| 111 | - if (captcha == null) | ||
| 112 | - { | ||
| 113 | - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); | ||
| 114 | - throw new CaptchaExpireException(); | ||
| 115 | - } | ||
| 116 | - if (!code.equalsIgnoreCase(captcha)) | ||
| 117 | - { | ||
| 118 | - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); | ||
| 119 | - throw new CaptchaException(); | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | 29 | ||
| 123 | - /** | ||
| 124 | - * 记录登录信息 | ||
| 125 | - * | ||
| 126 | - * @param userId 用户ID | ||
| 127 | - */ | ||
| 128 | - public void recordLoginInfo(Long userId) | ||
| 129 | - { | ||
| 130 | - SysUser sysUser = new SysUser(); | ||
| 131 | - sysUser.setUserId(userId); | ||
| 132 | - sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); | ||
| 133 | - sysUser.setLoginDate(DateUtils.getNowDate()); | ||
| 134 | - userService.updateUserProfile(sysUser); | ||
| 135 | - } | ||
| 136 | } | 30 | } |
| @@ -10,8 +10,8 @@ import com.ruoyi.common.exception.user.CaptchaExpireException; | @@ -10,8 +10,8 @@ import com.ruoyi.common.exception.user.CaptchaExpireException; | ||
| 10 | import com.ruoyi.common.utils.MessageUtils; | 10 | import com.ruoyi.common.utils.MessageUtils; |
| 11 | import com.ruoyi.common.utils.SecurityUtils; | 11 | import com.ruoyi.common.utils.SecurityUtils; |
| 12 | import com.ruoyi.common.utils.StringUtils; | 12 | import com.ruoyi.common.utils.StringUtils; |
| 13 | -import com.ruoyi.framework.manager.AsyncManager; | ||
| 14 | -import com.ruoyi.framework.manager.factory.AsyncFactory; | 13 | +import com.ruoyi.system.login.manager.AsyncManager; |
| 14 | +import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 15 | import com.ruoyi.system.service.ISysConfigService; | 15 | import com.ruoyi.system.service.ISysConfigService; |
| 16 | import com.ruoyi.system.service.ISysUserService; | 16 | import com.ruoyi.system.service.ISysUserService; |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 1 | package com.zhonglai.luhui.admin.service; | 1 | package com.zhonglai.luhui.admin.service; |
| 2 | 2 | ||
| 3 | import com.ruoyi.system.domain.entity.SysUser; | 3 | import com.ruoyi.system.domain.entity.SysUser; |
| 4 | -import com.zhonglai.luhui.admin.model.LoginUser; | 4 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 5 | import com.ruoyi.common.enums.UserStatus; | 5 | import com.ruoyi.common.enums.UserStatus; |
| 6 | import com.ruoyi.common.exception.ServiceException; | 6 | import com.ruoyi.common.exception.ServiceException; |
| 7 | import com.ruoyi.common.utils.StringUtils; | 7 | import com.ruoyi.common.utils.StringUtils; |
| @@ -20,9 +20,9 @@ import org.springframework.stereotype.Service; | @@ -20,9 +20,9 @@ import org.springframework.stereotype.Service; | ||
| 20 | * @author ruoyi | 20 | * @author ruoyi |
| 21 | */ | 21 | */ |
| 22 | @Service | 22 | @Service |
| 23 | -public class UserDetailsServiceImpl implements UserDetailsService | 23 | +public class SysUserDetailsServiceImpl implements UserDetailsService |
| 24 | { | 24 | { |
| 25 | - private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class); | 25 | + private static final Logger log = LoggerFactory.getLogger(SysUserDetailsServiceImpl.class); |
| 26 | 26 | ||
| 27 | @Autowired | 27 | @Autowired |
| 28 | private ISysUserService userService; | 28 | private ISysUserService userService; |
| @@ -55,6 +55,6 @@ public class UserDetailsServiceImpl implements UserDetailsService | @@ -55,6 +55,6 @@ public class UserDetailsServiceImpl implements UserDetailsService | ||
| 55 | 55 | ||
| 56 | public UserDetails createLoginUser(SysUser user) | 56 | public UserDetails createLoginUser(SysUser user) |
| 57 | { | 57 | { |
| 58 | - return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); | 58 | + return new SysLoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| @@ -2,7 +2,7 @@ package com.zhonglai.luhui.admin.service; | @@ -2,7 +2,7 @@ package com.zhonglai.luhui.admin.service; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.core.domain.BaseLoginUser; | 3 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| 4 | import com.ruoyi.framework.web.service.ISysUserOnlineService; | 4 | import com.ruoyi.framework.web.service.ISysUserOnlineService; |
| 5 | -import com.zhonglai.luhui.admin.model.LoginUser; | 5 | +import com.ruoyi.system.login.dto.SysLoginUser; |
| 6 | import com.ruoyi.common.utils.StringUtils; | 6 | import com.ruoyi.common.utils.StringUtils; |
| 7 | import com.ruoyi.system.domain.SysUserOnline; | 7 | import com.ruoyi.system.domain.SysUserOnline; |
| 8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| @@ -73,7 +73,7 @@ public class SysUserOnlineServiceImpl implements ISysUserOnlineService | @@ -73,7 +73,7 @@ public class SysUserOnlineServiceImpl implements ISysUserOnlineService | ||
| 73 | { | 73 | { |
| 74 | return null; | 74 | return null; |
| 75 | } | 75 | } |
| 76 | - LoginUser user = (LoginUser) baseLoginUser; | 76 | + SysLoginUser user = (SysLoginUser) baseLoginUser; |
| 77 | SysUserOnline sysUserOnline = new SysUserOnline(); | 77 | SysUserOnline sysUserOnline = new SysUserOnline(); |
| 78 | sysUserOnline.setTokenId(user.getToken()); | 78 | sysUserOnline.setTokenId(user.getToken()); |
| 79 | sysUserOnline.setUserName(user.getUsername()); | 79 | sysUserOnline.setUserName(user.getUsername()); |
| @@ -10,6 +10,7 @@ import org.springframework.context.annotation.ComponentScan; | @@ -10,6 +10,7 @@ import org.springframework.context.annotation.ComponentScan; | ||
| 10 | "com.ruoyi.system", | 10 | "com.ruoyi.system", |
| 11 | "com.ruoyi.framework", | 11 | "com.ruoyi.framework", |
| 12 | "com.zhonglai.luhui.api.config", | 12 | "com.zhonglai.luhui.api.config", |
| 13 | + "com.zhonglai.luhui.api.service", | ||
| 13 | "com.zhonglai.luhui.api.controller", | 14 | "com.zhonglai.luhui.api.controller", |
| 14 | }) | 15 | }) |
| 15 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | 16 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) |
| 1 | -package com.zhonglai.luhui.api.config; | ||
| 2 | - | ||
| 3 | -import com.zhonglai.luhui.api.dto.ApiLoginUser; | ||
| 4 | -import org.springframework.security.core.userdetails.UserDetails; | ||
| 5 | -import org.springframework.security.core.userdetails.UserDetailsService; | ||
| 6 | -import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 7 | -import org.springframework.stereotype.Service; | ||
| 8 | - | ||
| 9 | -@Service | ||
| 10 | -public class ApiUserDetailsServiceImpl implements UserDetailsService { | ||
| 11 | - @Override | ||
| 12 | - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
| 13 | - | ||
| 14 | - return new ApiLoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); | ||
| 15 | - } | ||
| 16 | -} |
| 1 | +package com.zhonglai.luhui.api.controller.login; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.constant.Constants; | ||
| 4 | +import com.ruoyi.common.core.controller.BaseController; | ||
| 5 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 6 | +import com.ruoyi.common.utils.StringUtils; | ||
| 7 | +import com.ruoyi.system.login.service.LoginService; | ||
| 8 | +import io.swagger.annotations.Api; | ||
| 9 | +import io.swagger.annotations.ApiOperation; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RestController; | ||
| 14 | + | ||
| 15 | +import javax.servlet.http.HttpServletRequest; | ||
| 16 | + | ||
| 17 | +@Api(tags = "登陆") | ||
| 18 | +@RestController | ||
| 19 | +@RequestMapping("/login/ApiLogin") | ||
| 20 | +public class ApiLoginController extends BaseController { | ||
| 21 | + public static String YU2LE_LOGIN_TOKEN_KEY = "loginToken"; //登录令牌键值 | ||
| 22 | + @Autowired | ||
| 23 | + private LoginService loginService; | ||
| 24 | + | ||
| 25 | + @ApiOperation("账号密码登陆") | ||
| 26 | + @PostMapping("/userpassLogin") | ||
| 27 | + public AjaxResult userpassLogin(String user,String pass) | ||
| 28 | + { | ||
| 29 | + AjaxResult ajax = AjaxResult.success(); | ||
| 30 | + //生成令牌 | ||
| 31 | + String token = loginService.apiLoginByPass(user,pass); | ||
| 32 | + ajax.put(Constants.TOKEN, token); | ||
| 33 | + return ajax; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @ApiOperation("鱼儿乐token登陆") | ||
| 37 | + @PostMapping("/yu2leTokenLogin") | ||
| 38 | + public AjaxResult yu2leTokenLogin(HttpServletRequest request) | ||
| 39 | + { | ||
| 40 | + String loginToken = request.getHeader(YU2LE_LOGIN_TOKEN_KEY); | ||
| 41 | + if(StringUtils.isEmpty(loginToken)) | ||
| 42 | + { | ||
| 43 | + return AjaxResult.error("请输入鱼儿乐令牌"); | ||
| 44 | + } | ||
| 45 | + AjaxResult ajax = AjaxResult.success(); | ||
| 46 | + //生成令牌 | ||
| 47 | + String token = loginService.yu2leTokenLogin(loginToken); | ||
| 48 | + ajax.put(Constants.TOKEN, token); | ||
| 49 | + return ajax; | ||
| 50 | + } | ||
| 51 | +} |
| @@ -2,17 +2,24 @@ package com.zhonglai.luhui.api.dto; | @@ -2,17 +2,24 @@ package com.zhonglai.luhui.api.dto; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.annotation.JSONField; | 3 | import com.alibaba.fastjson.annotation.JSONField; |
| 4 | import com.ruoyi.common.core.domain.BaseLoginUser; | 4 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| 5 | +import com.ruoyi.system.login.dto.Yu2leUserInfo; | ||
| 6 | +import com.ruoyi.system.login.dto.Yu2leUserLogin; | ||
| 5 | import org.springframework.security.core.GrantedAuthority; | 7 | import org.springframework.security.core.GrantedAuthority; |
| 6 | 8 | ||
| 7 | import java.util.Collection; | 9 | import java.util.Collection; |
| 8 | 10 | ||
| 9 | public class ApiLoginUser extends BaseLoginUser { | 11 | public class ApiLoginUser extends BaseLoginUser { |
| 10 | - private UserInfo userInfo; | 12 | + private Yu2leUserInfo userInfo; |
| 11 | 13 | ||
| 12 | - private UserLogin userLogin; | 14 | + private Yu2leUserLogin userLogin; |
| 15 | + | ||
| 16 | + public ApiLoginUser(Yu2leUserInfo userInfo, Yu2leUserLogin userLogin) { | ||
| 17 | + this.userInfo = userInfo; | ||
| 18 | + this.userLogin = userLogin; | ||
| 19 | + } | ||
| 13 | 20 | ||
| 14 | @Override | 21 | @Override |
| 15 | - public UserInfo getUser() { | 22 | + public Yu2leUserInfo getUser() { |
| 16 | return userInfo; | 23 | return userInfo; |
| 17 | } | 24 | } |
| 18 | 25 | ||
| @@ -73,15 +80,15 @@ public class ApiLoginUser extends BaseLoginUser { | @@ -73,15 +80,15 @@ public class ApiLoginUser extends BaseLoginUser { | ||
| 73 | return false; | 80 | return false; |
| 74 | } | 81 | } |
| 75 | 82 | ||
| 76 | - public void setUserInfo(UserInfo userInfo) { | 83 | + public void setUserInfo(Yu2leUserInfo userInfo) { |
| 77 | this.userInfo = userInfo; | 84 | this.userInfo = userInfo; |
| 78 | } | 85 | } |
| 79 | 86 | ||
| 80 | - public UserLogin getUserLogin() { | 87 | + public Yu2leUserLogin getUserLogin() { |
| 81 | return userLogin; | 88 | return userLogin; |
| 82 | } | 89 | } |
| 83 | 90 | ||
| 84 | - public void setUserLogin(UserLogin userLogin) { | 91 | + public void setUserLogin(Yu2leUserLogin userLogin) { |
| 85 | this.userLogin = userLogin; | 92 | this.userLogin = userLogin; |
| 86 | } | 93 | } |
| 87 | } | 94 | } |
| 1 | +package com.zhonglai.luhui.api.service; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.enums.UserStatus; | ||
| 4 | +import com.ruoyi.common.exception.ServiceException; | ||
| 5 | +import com.ruoyi.common.utils.StringUtils; | ||
| 6 | +import com.ruoyi.system.login.dto.Yu2leUserInfo; | ||
| 7 | +import com.ruoyi.system.login.dto.Yu2leUserLogin; | ||
| 8 | +import com.ruoyi.system.service.PublicService; | ||
| 9 | +import com.zhonglai.luhui.api.dto.ApiLoginUser; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 14 | +import org.springframework.security.core.userdetails.UserDetailsService; | ||
| 15 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | + | ||
| 18 | +@Service | ||
| 19 | +public class ApiUserDetailsServiceImpl implements UserDetailsService { | ||
| 20 | + private static final Logger log = LoggerFactory.getLogger(ApiUserDetailsServiceImpl.class); | ||
| 21 | + @Autowired | ||
| 22 | + private PublicService publicService; | ||
| 23 | + @Override | ||
| 24 | + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
| 25 | + Yu2leUserLogin yu2leUserLogin = publicService.getObjectForTableName(Yu2leUserLogin.class,"loginName",username,"`liu_yu_le`.`user_login`"); | ||
| 26 | + Yu2leUserInfo yu2leUserInfo = null; | ||
| 27 | + if (StringUtils.isNull(yu2leUserLogin) || StringUtils.isNull(yu2leUserInfo)) | ||
| 28 | + { | ||
| 29 | + log.info("登录用户:{} 不存在.", username); | ||
| 30 | + throw new ServiceException("登录用户:" + username + " 不存在"); | ||
| 31 | + } | ||
| 32 | + else if (1==yu2leUserInfo.getIsInvalid()) | ||
| 33 | + { | ||
| 34 | + log.info("登录用户:{} 已被停用.", username); | ||
| 35 | + throw new ServiceException("对不起,您的账号:" + username + " 已停用"); | ||
| 36 | + } | ||
| 37 | + return new ApiLoginUser(yu2leUserInfo, yu2leUserLogin); | ||
| 38 | + } | ||
| 39 | +} |
| 1 | -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb | ||
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/* |
| 1 | +package com.ruoyi.common.utils; | ||
| 2 | + | ||
| 3 | +import org.apache.commons.lang3.StringUtils; | ||
| 4 | + | ||
| 5 | +import javax.crypto.Cipher; | ||
| 6 | +import javax.crypto.SecretKey; | ||
| 7 | +import javax.crypto.SecretKeyFactory; | ||
| 8 | +import javax.crypto.spec.DESKeySpec; | ||
| 9 | +import java.security.SecureRandom; | ||
| 10 | +import java.util.Random; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 采用MD5加密解密 | ||
| 14 | + * @author tfq | ||
| 15 | + * @datetime 2011-10-13 | ||
| 16 | + */ | ||
| 17 | +public class DESUtil { | ||
| 18 | + | ||
| 19 | + private static final String KEY = "kimwaynet";// 密钥 | ||
| 20 | + private final static String DES = "DES";// DES算法名称 | ||
| 21 | + | ||
| 22 | + //加密 | ||
| 23 | + private static byte[] encrypt(byte[] src, byte[] key) throws Exception { | ||
| 24 | + SecureRandom sr = new SecureRandom(); | ||
| 25 | + DESKeySpec dks = new DESKeySpec(key); | ||
| 26 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES); | ||
| 27 | + SecretKey securekey = keyFactory.generateSecret(dks); | ||
| 28 | + Cipher cipher = Cipher.getInstance(DES); | ||
| 29 | + cipher.init(Cipher.ENCRYPT_MODE, securekey, sr); | ||
| 30 | + return cipher.doFinal(src); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + //解密 | ||
| 34 | + private static byte[] decrypt(byte[] src, byte[] key) throws Exception { | ||
| 35 | + SecureRandom sr = new SecureRandom(); | ||
| 36 | + DESKeySpec dks = new DESKeySpec(key); | ||
| 37 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES); | ||
| 38 | + SecretKey securekey = keyFactory.generateSecret(dks); | ||
| 39 | + Cipher cipher = Cipher.getInstance(DES); | ||
| 40 | + cipher.init(Cipher.DECRYPT_MODE, securekey, sr); | ||
| 41 | + return cipher.doFinal(src); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + private static String byte2hex(byte[] b) { | ||
| 45 | + String hs = ""; | ||
| 46 | + String stmp = ""; | ||
| 47 | + for (int n = 0; n < b.length; n++) { | ||
| 48 | + stmp = (Integer.toHexString(b[n] & 0XFF)); | ||
| 49 | + if (stmp.length() == 1) | ||
| 50 | + hs = hs + "0" + stmp; | ||
| 51 | + else | ||
| 52 | + hs = hs + stmp; | ||
| 53 | + } | ||
| 54 | + return hs.toUpperCase(); | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + private static byte[] hex2byte(byte[] b) { | ||
| 58 | + if ((b.length % 2) != 0) | ||
| 59 | + throw new IllegalArgumentException("length not even"); | ||
| 60 | + byte[] b2 = new byte[b.length / 2]; | ||
| 61 | + for (int n = 0; n < b.length; n += 2) { | ||
| 62 | + String item = new String(b, n, 2); | ||
| 63 | + b2[n / 2] = (byte) Integer.parseInt(item, 16); | ||
| 64 | + } | ||
| 65 | + return b2; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + //解密 | ||
| 69 | + public static String decode(String src,String key) { | ||
| 70 | + if(StringUtils.isEmpty(key)) | ||
| 71 | + { | ||
| 72 | + key = KEY; | ||
| 73 | + } | ||
| 74 | + String decryptStr = ""; | ||
| 75 | + try { | ||
| 76 | + decryptStr = new String(decrypt(hex2byte(src.getBytes()),key.getBytes())); | ||
| 77 | + } catch (Exception ex) { | ||
| 78 | + ex.printStackTrace(); | ||
| 79 | + } | ||
| 80 | + return decryptStr; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + //加密 | ||
| 84 | + public static String encode(String src,String key){ | ||
| 85 | + if(StringUtils.isEmpty(key)) | ||
| 86 | + { | ||
| 87 | + key = KEY; | ||
| 88 | + } | ||
| 89 | + byte[] bytes = null; | ||
| 90 | + String encryptStr = ""; | ||
| 91 | + try { | ||
| 92 | + bytes = encrypt(src.getBytes(), key.getBytes()); | ||
| 93 | + } catch (Exception ex) { | ||
| 94 | + ex.printStackTrace(); | ||
| 95 | + } | ||
| 96 | + if (bytes != null) | ||
| 97 | + encryptStr = byte2hex(bytes); | ||
| 98 | + return encryptStr; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public static String getDecodeMAC(String decryptStr){ | ||
| 102 | + String mac = ""; | ||
| 103 | + String[] strs = decryptStr.split(":"); | ||
| 104 | + if (strs.length == 5) { | ||
| 105 | + mac = strs[0]; | ||
| 106 | + } | ||
| 107 | + return mac; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 生成指定长度的随机字符串 | ||
| 112 | + * @param args | ||
| 113 | + */ | ||
| 114 | + /** | ||
| 115 | + * 产生随机字符串 | ||
| 116 | + * */ | ||
| 117 | + private static Random randGen = null; | ||
| 118 | + private static char[] numbersAndLetters = null; | ||
| 119 | + | ||
| 120 | + public static final String randomString(int length) { | ||
| 121 | + if (length < 1) { | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + if (randGen == null) { | ||
| 125 | + randGen = new Random(); | ||
| 126 | + numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" + | ||
| 127 | + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray(); | ||
| 128 | + //numbersAndLetters = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray(); | ||
| 129 | + } | ||
| 130 | + char [] randBuffer = new char[length]; | ||
| 131 | + for (int i=0; i<randBuffer.length; i++) { | ||
| 132 | + randBuffer[i] = numbersAndLetters[randGen.nextInt(71)]; | ||
| 133 | + //randBuffer[i] = numbersAndLetters[randGen.nextInt(35)]; | ||
| 134 | + } | ||
| 135 | + return new String(randBuffer); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + // 测试主函数 | ||
| 139 | + public static void main(String args[]) { | ||
| 140 | +// String s = new String("F:/yu2le-service-log"); | ||
| 141 | +// System.out.println("原始:" + s); | ||
| 142 | +// s = encode(s,"LINUXYU2LE"); | ||
| 143 | +// System.out.println("加密的:" + s); | ||
| 144 | + System.out.println("解密的:" + decode("498CFDA0AA8A2E9A","kimwaynet")); | ||
| 145 | + | ||
| 146 | +// System.out.println(encode("13912927204","LS6GzB")); | ||
| 147 | + } | ||
| 148 | +} |
| @@ -9,8 +9,8 @@ import com.ruoyi.common.utils.SecurityUtils; | @@ -9,8 +9,8 @@ import com.ruoyi.common.utils.SecurityUtils; | ||
| 9 | import com.ruoyi.common.utils.ServletUtils; | 9 | import com.ruoyi.common.utils.ServletUtils; |
| 10 | import com.ruoyi.common.utils.StringUtils; | 10 | import com.ruoyi.common.utils.StringUtils; |
| 11 | import com.ruoyi.common.utils.ip.IpUtils; | 11 | import com.ruoyi.common.utils.ip.IpUtils; |
| 12 | -import com.ruoyi.framework.manager.AsyncManager; | ||
| 13 | -import com.ruoyi.framework.manager.factory.AsyncFactory; | 12 | +import com.ruoyi.system.login.manager.AsyncManager; |
| 13 | +import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 14 | import com.ruoyi.system.domain.SysOperLog; | 14 | import com.ruoyi.system.domain.SysOperLog; |
| 15 | import org.aspectj.lang.JoinPoint; | 15 | import org.aspectj.lang.JoinPoint; |
| 16 | import org.aspectj.lang.annotation.AfterReturning; | 16 | import org.aspectj.lang.annotation.AfterReturning; |
| @@ -3,7 +3,7 @@ package com.ruoyi.framework.security.filter; | @@ -3,7 +3,7 @@ package com.ruoyi.framework.security.filter; | ||
| 3 | import com.ruoyi.common.core.domain.BaseLoginUser; | 3 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| 4 | import com.ruoyi.common.utils.SecurityUtils; | 4 | import com.ruoyi.common.utils.SecurityUtils; |
| 5 | import com.ruoyi.common.utils.StringUtils; | 5 | import com.ruoyi.common.utils.StringUtils; |
| 6 | -import com.ruoyi.framework.web.service.TokenService; | 6 | +import com.ruoyi.system.login.service.TokenService; |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| 9 | import org.springframework.security.core.context.SecurityContextHolder; | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
| @@ -7,9 +7,9 @@ import com.ruoyi.common.core.domain.AjaxResult; | @@ -7,9 +7,9 @@ import com.ruoyi.common.core.domain.AjaxResult; | ||
| 7 | import com.ruoyi.common.core.domain.BaseLoginUser; | 7 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| 8 | import com.ruoyi.common.utils.ServletUtils; | 8 | import com.ruoyi.common.utils.ServletUtils; |
| 9 | import com.ruoyi.common.utils.StringUtils; | 9 | import com.ruoyi.common.utils.StringUtils; |
| 10 | -import com.ruoyi.framework.manager.AsyncManager; | ||
| 11 | -import com.ruoyi.framework.manager.factory.AsyncFactory; | ||
| 12 | -import com.ruoyi.framework.web.service.TokenService; | 10 | +import com.ruoyi.system.login.manager.AsyncManager; |
| 11 | +import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 12 | +import com.ruoyi.system.login.service.TokenService; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.context.annotation.Configuration; | 14 | import org.springframework.context.annotation.Configuration; |
| 15 | import org.springframework.security.core.Authentication; | 15 | import org.springframework.security.core.Authentication; |
| @@ -281,10 +281,12 @@ public class PublicSQL { | @@ -281,10 +281,12 @@ public class PublicSQL { | ||
| 281 | tableName = (String) para.get("tableName"); | 281 | tableName = (String) para.get("tableName"); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | - String select = "*"; | 284 | + String select = ""; |
| 285 | if(para.containsKey("select") && null != para.get("select")) | 285 | if(para.containsKey("select") && null != para.get("select")) |
| 286 | { | 286 | { |
| 287 | select = (String) para.get("select"); | 287 | select = (String) para.get("select"); |
| 288 | + }else{ | ||
| 289 | + select = getSelect(clas); | ||
| 288 | } | 290 | } |
| 289 | 291 | ||
| 290 | if(StringUtils.isBlank(tableName)) | 292 | if(StringUtils.isBlank(tableName)) |
| @@ -469,6 +471,8 @@ public class PublicSQL { | @@ -469,6 +471,8 @@ public class PublicSQL { | ||
| 469 | if(para.containsKey("selectStr") && null != para.get("selectStr")) | 471 | if(para.containsKey("selectStr") && null != para.get("selectStr")) |
| 470 | { | 472 | { |
| 471 | selectStr = para.get("selectStr")+""; | 473 | selectStr = para.get("selectStr")+""; |
| 474 | + }else{ | ||
| 475 | + selectStr = getSelect(object.getClass()); | ||
| 472 | } | 476 | } |
| 473 | String tableName = changTableNameFromObject(object); | 477 | String tableName = changTableNameFromObject(object); |
| 474 | 478 | ||
| @@ -702,4 +706,29 @@ public class PublicSQL { | @@ -702,4 +706,29 @@ public class PublicSQL { | ||
| 702 | public static String escapeSql(String str) { | 706 | public static String escapeSql(String str) { |
| 703 | return str == null ? null : StringUtils.replace(str, "'", "''"); | 707 | return str == null ? null : StringUtils.replace(str, "'", "''"); |
| 704 | } | 708 | } |
| 709 | + | ||
| 710 | + private String getSelect(Class<?> clas) | ||
| 711 | + { | ||
| 712 | + String select = ""; | ||
| 713 | + Field[] fields = clas.getDeclaredFields(); | ||
| 714 | + for(Field field:fields) | ||
| 715 | + { | ||
| 716 | + PublicSQLConfig publicSQLConfig = field.getAnnotation(PublicSQLConfig.class); | ||
| 717 | + if(null != publicSQLConfig && !publicSQLConfig.isSelect()) | ||
| 718 | + { | ||
| 719 | + continue; | ||
| 720 | + } | ||
| 721 | + if(!"".equals(select)) | ||
| 722 | + { | ||
| 723 | + select += ","; | ||
| 724 | + } | ||
| 725 | + String fieldName = field.getName(); | ||
| 726 | + select +="`"+ com.ruoyi.common.utils.StringUtils.toUnderScoreCase(fieldName) +"` "+fieldName; | ||
| 727 | + } | ||
| 728 | + if("".equals(select)) | ||
| 729 | + { | ||
| 730 | + select = "*"; | ||
| 731 | + } | ||
| 732 | + return select; | ||
| 733 | + } | ||
| 705 | } | 734 | } |
| 1 | +package com.ruoyi.system.dto; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import java.lang.annotation.ElementType; | ||
| 5 | +import java.lang.annotation.Retention; | ||
| 6 | +import java.lang.annotation.RetentionPolicy; | ||
| 7 | +import java.lang.annotation.Target; | ||
| 8 | + | ||
| 9 | +@Target(ElementType.FIELD) | ||
| 10 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 11 | +public @interface PublicSQLConfig { | ||
| 12 | + boolean isSelect() default true; | ||
| 13 | +} |
| 1 | +package com.ruoyi.system.login.dto; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | +import org.springframework.security.core.GrantedAuthority; | ||
| 5 | + | ||
| 6 | +import java.util.Collection; | ||
| 7 | + | ||
| 8 | +public class ApiLoginUser extends BaseLoginUser { | ||
| 9 | + private static final long serialVersionUID = -2519976444812946707L; | ||
| 10 | + | ||
| 11 | + private Yu2leUserLogin yu2leUserLogin; | ||
| 12 | + | ||
| 13 | + public ApiLoginUser(Yu2leUserLogin yu2leUserLogin) { | ||
| 14 | + this.yu2leUserLogin = yu2leUserLogin; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public Object getUser() { | ||
| 19 | + return yu2leUserLogin; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public Collection<? extends GrantedAuthority> getAuthorities() { | ||
| 24 | + return null; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public String getPassword() { | ||
| 29 | + return yu2leUserLogin.getLoginPass(); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public String getUsername() { | ||
| 34 | + return yu2leUserLogin.getLoginName(); | ||
| 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 Yu2leUserLogin getYu2leUserLogin() { | ||
| 58 | + return yu2leUserLogin; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setYu2leUserLogin(Yu2leUserLogin yu2leUserLogin) { | ||
| 62 | + this.yu2leUserLogin = yu2leUserLogin; | ||
| 63 | + } | ||
| 64 | +} |
| 1 | -package com.zhonglai.luhui.admin.model; | 1 | +package com.ruoyi.system.login.dto; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.annotation.JSONField; | 3 | import com.alibaba.fastjson.annotation.JSONField; |
| 4 | import com.ruoyi.common.core.domain.BaseLoginUser; | 4 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| @@ -13,7 +13,7 @@ import java.util.Set; | @@ -13,7 +13,7 @@ import java.util.Set; | ||
| 13 | * | 13 | * |
| 14 | * @author ruoyi | 14 | * @author ruoyi |
| 15 | */ | 15 | */ |
| 16 | -public class LoginUser extends BaseLoginUser | 16 | +public class SysLoginUser extends BaseLoginUser |
| 17 | { | 17 | { |
| 18 | private static final long serialVersionUID = 1L; | 18 | private static final long serialVersionUID = 1L; |
| 19 | 19 | ||
| @@ -44,17 +44,17 @@ public class LoginUser extends BaseLoginUser | @@ -44,17 +44,17 @@ public class LoginUser extends BaseLoginUser | ||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | - public LoginUser() | 47 | + public SysLoginUser() |
| 48 | { | 48 | { |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | - public LoginUser(SysUser user, Set<String> permissions) | 51 | + public SysLoginUser(SysUser user, Set<String> permissions) |
| 52 | { | 52 | { |
| 53 | this.user = user; | 53 | this.user = user; |
| 54 | this.permissions = permissions; | 54 | this.permissions = permissions; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | - public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions) | 57 | + public SysLoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions) |
| 58 | { | 58 | { |
| 59 | setUserId(userId); | 59 | setUserId(userId); |
| 60 | this.deptId = deptId; | 60 | this.deptId = deptId; |
| 1 | +package com.ruoyi.system.login.dto; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.ruoyi.common.utils.DESUtil; | ||
| 5 | +import com.ruoyi.common.utils.DateUtils; | ||
| 6 | + | ||
| 7 | +import java.io.Serializable; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 登录令牌 | ||
| 11 | + */ | ||
| 12 | +public class Yu2leLoginToken implements Serializable { | ||
| 13 | + private static final long serialVersionUID = -8696564127500370479L; | ||
| 14 | + private Integer userId; //当前用户id | ||
| 15 | + private String userLoginName; //当前用户登录名 | ||
| 16 | + private String userNickName; //当前用户昵称 | ||
| 17 | + private Integer parentUserId; //上级用户id,没有就是顶级 | ||
| 18 | + private String parentUserLoginName; //上级用户登录名 | ||
| 19 | + private String parentUserNickName; //上级用户昵称 | ||
| 20 | + private JSONObject date; //数据 | ||
| 21 | + private Integer createTime; //生成时间 | ||
| 22 | + private String key = "LiuYuLeXX"; //密钥 | ||
| 23 | + private Integer userType; //用户类型(0普通用户,1管理员) | ||
| 24 | + private Integer isOperation = 1; //有无操作权限 (0无,1有) | ||
| 25 | + | ||
| 26 | + public Integer getIsOperation() { | ||
| 27 | + return isOperation; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public void setIsOperation(Integer isOperation) { | ||
| 31 | + this.isOperation = isOperation; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public Yu2leLoginToken() | ||
| 35 | + { | ||
| 36 | + | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public Yu2leLoginToken(Integer userId, String userLoginName, String userNickName, Integer userType) | ||
| 40 | + { | ||
| 41 | + this.userId = userId; | ||
| 42 | + this.userLoginName = userLoginName; | ||
| 43 | + this.userNickName = userNickName; | ||
| 44 | + this.createTime = DateUtils.getNowTimeMilly(); | ||
| 45 | + this.userType = userType; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public Yu2leLoginToken(Integer userId, String userLoginName, String userNickName, Integer userType, Integer parentUserId) | ||
| 49 | + { | ||
| 50 | + this.userId = userId; | ||
| 51 | + this.userLoginName = userLoginName; | ||
| 52 | + this.userNickName = userNickName; | ||
| 53 | + this.parentUserId = parentUserId; | ||
| 54 | + this.userType = userType; | ||
| 55 | + this.createTime = DateUtils.getNowTimeMilly(); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public Yu2leLoginToken(Integer userId, String userLoginName, String userNickName, Integer userType, Integer parentUserId, JSONObject date) | ||
| 59 | + { | ||
| 60 | + this.userId = userId; | ||
| 61 | + this.userLoginName = userLoginName; | ||
| 62 | + this.userNickName = userNickName; | ||
| 63 | + this.parentUserId = parentUserId; | ||
| 64 | + this.userType = userType; | ||
| 65 | + this.date = date; | ||
| 66 | + this.createTime = DateUtils.getNowTimeMilly(); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 解密token | ||
| 71 | + * @param deLoginToken | ||
| 72 | + */ | ||
| 73 | + public Yu2leLoginToken(String deLoginToken) | ||
| 74 | + { | ||
| 75 | + String loginTokenString = DESUtil.decode(deLoginToken,key); | ||
| 76 | + JSONObject jsonObject = JSONObject.parseObject(loginTokenString, JSONObject.class); | ||
| 77 | + if(jsonObject.containsKey("userId")) | ||
| 78 | + { | ||
| 79 | + userId = jsonObject.getInteger("userId"); | ||
| 80 | + } | ||
| 81 | + if(jsonObject.containsKey("userLoginName")) | ||
| 82 | + { | ||
| 83 | + userLoginName = jsonObject.getString("userLoginName"); | ||
| 84 | + } | ||
| 85 | + if(jsonObject.containsKey("userNickName")) | ||
| 86 | + { | ||
| 87 | + userNickName = jsonObject.getString("userNickName"); | ||
| 88 | + } | ||
| 89 | + if(jsonObject.containsKey("parentUserId")) | ||
| 90 | + { | ||
| 91 | + parentUserId = jsonObject.getInteger("parentUserId"); | ||
| 92 | + } | ||
| 93 | + if(jsonObject.containsKey("date")) | ||
| 94 | + { | ||
| 95 | + date = jsonObject.getJSONObject("date"); | ||
| 96 | + } | ||
| 97 | + if(jsonObject.containsKey("createTime")) | ||
| 98 | + { | ||
| 99 | + createTime = jsonObject.getInteger("createTime"); | ||
| 100 | + } | ||
| 101 | + if(jsonObject.containsKey("userType")) | ||
| 102 | + { | ||
| 103 | + userType = jsonObject.getInteger("userType"); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 生成加密loginToken | ||
| 109 | + * @return | ||
| 110 | + */ | ||
| 111 | + public String get() | ||
| 112 | + { | ||
| 113 | + return DESUtil.encode(JSONObject.toJSONString(this),key); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public Integer getUserId() { | ||
| 117 | + return userId; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public void setUserId(Integer userId) { | ||
| 121 | + this.userId = userId; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public String getUserLoginName() { | ||
| 125 | + return userLoginName; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setUserLoginName(String userLoginName) { | ||
| 129 | + this.userLoginName = userLoginName; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public String getUserNickName() { | ||
| 133 | + return userNickName; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public void setUserNickName(String userNickName) { | ||
| 137 | + this.userNickName = userNickName; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public Integer getParentUserId() { | ||
| 141 | + return parentUserId; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setParentUserId(Integer parentUserId) { | ||
| 145 | + this.parentUserId = parentUserId; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public JSONObject getDate() { | ||
| 149 | + return date; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setDate(JSONObject date) { | ||
| 153 | + this.date = date; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public Integer getCreateTime() { | ||
| 157 | + return createTime; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public void setCreateTime(Integer createTime) { | ||
| 161 | + this.createTime = createTime; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public String getKey() { | ||
| 165 | + return key; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public void setKey(String key) { | ||
| 169 | + this.key = key; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public Integer getUserType() { | ||
| 173 | + return userType; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public void setUserType(Integer userType) { | ||
| 177 | + this.userType = userType; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public String getParentUserLoginName() { | ||
| 181 | + return parentUserLoginName; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public void setParentUserLoginName(String parentUserLoginName) { | ||
| 185 | + this.parentUserLoginName = parentUserLoginName; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public String getParentUserNickName() { | ||
| 189 | + return parentUserNickName; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public void setParentUserNickName(String parentUserNickName) { | ||
| 193 | + this.parentUserNickName = parentUserNickName; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | +} |
| 1 | -package com.zhonglai.luhui.api.dto; | 1 | +package com.ruoyi.system.login.dto; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.ruoyi.system.dto.PublicSQLConfig; | ||
| 5 | + | ||
| 4 | import java.io.Serializable; | 6 | import java.io.Serializable; |
| 5 | 7 | ||
| 6 | /** | 8 | /** |
| 7 | * 用户信息 | 9 | * 用户信息 |
| 8 | */ | 10 | */ |
| 9 | -public class UserInfo implements Serializable { | 11 | +public class Yu2leUserInfo implements Serializable { |
| 12 | + @PublicSQLConfig(isSelect = false) | ||
| 10 | private static final long serialVersionUID = 2442852637823064570L; | 13 | private static final long serialVersionUID = 2442852637823064570L; |
| 11 | - | ||
| 12 | private Integer id; // int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', | 14 | private Integer id; // int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', |
| 13 | private String loginName; // varchar(50) NOT NULL COMMENT '登录名', | 15 | private String loginName; // varchar(50) NOT NULL COMMENT '登录名', |
| 14 | private String name; // varchar(50) DEFAULT NULL COMMENT '真实姓名', | 16 | private String name; // varchar(50) DEFAULT NULL COMMENT '真实姓名', |
| 1 | -package com.zhonglai.luhui.api.dto; | 1 | +package com.ruoyi.system.login.dto; |
| 2 | + | ||
| 3 | +import com.ruoyi.system.dto.PublicSQLConfig; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 2 | 6 | ||
| 3 | /** | 7 | /** |
| 4 | * 用户登录 | 8 | * 用户登录 |
| 5 | */ | 9 | */ |
| 6 | -public class UserLogin { | 10 | +public class Yu2leUserLogin implements Serializable { |
| 11 | + @PublicSQLConfig(isSelect = false) | ||
| 12 | + private static final long serialVersionUID = -3205855629462027722L; | ||
| 7 | private Integer id; // int(11) NOT NULL AUTO_INCREMENT COMMENT '用户登录主键主键', | 13 | private Integer id; // int(11) NOT NULL AUTO_INCREMENT COMMENT '用户登录主键主键', |
| 8 | private Integer userId; // int(11) NOT NULL COMMENT '用户主键id', | 14 | private Integer userId; // int(11) NOT NULL COMMENT '用户主键id', |
| 9 | private String loginName; // varchar(50) NOT NULL COMMENT '用户登录名', | 15 | private String loginName; // varchar(50) NOT NULL COMMENT '用户登录名', |
| 1 | -package com.ruoyi.framework.manager; | 1 | +package com.ruoyi.system.login.manager; |
| 2 | 2 | ||
| 3 | import org.slf4j.Logger; | 3 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 4 | import org.slf4j.LoggerFactory; |
| @@ -14,7 +14,7 @@ import javax.annotation.PreDestroy; | @@ -14,7 +14,7 @@ import javax.annotation.PreDestroy; | ||
| 14 | @Component | 14 | @Component |
| 15 | public class ShutdownManager | 15 | public class ShutdownManager |
| 16 | { | 16 | { |
| 17 | - private static final Logger logger = LoggerFactory.getLogger("sys-user"); | 17 | + private static final Logger logger = LoggerFactory.getLogger(ShutdownManager.class); |
| 18 | 18 | ||
| 19 | @PreDestroy | 19 | @PreDestroy |
| 20 | public void destroy() | 20 | public void destroy() |
| 1 | +package com.ruoyi.system.login.service; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.constant.Constants; | ||
| 4 | +import com.ruoyi.common.core.redis.RedisCache; | ||
| 5 | +import com.ruoyi.common.exception.ServiceException; | ||
| 6 | +import com.ruoyi.common.exception.user.CaptchaException; | ||
| 7 | +import com.ruoyi.common.exception.user.CaptchaExpireException; | ||
| 8 | +import com.ruoyi.common.exception.user.UserPasswordNotMatchException; | ||
| 9 | +import com.ruoyi.common.utils.DateUtils; | ||
| 10 | +import com.ruoyi.common.utils.MessageUtils; | ||
| 11 | +import com.ruoyi.common.utils.ServletUtils; | ||
| 12 | +import com.ruoyi.common.utils.StringUtils; | ||
| 13 | +import com.ruoyi.common.utils.ip.IpUtils; | ||
| 14 | +import com.ruoyi.system.domain.entity.SysUser; | ||
| 15 | +import com.ruoyi.system.login.dto.ApiLoginUser; | ||
| 16 | +import com.ruoyi.system.login.dto.SysLoginUser; | ||
| 17 | +import com.ruoyi.system.login.dto.Yu2leUserLogin; | ||
| 18 | +import com.ruoyi.system.login.dto.Yu2leLoginToken; | ||
| 19 | +import com.ruoyi.system.login.manager.AsyncManager; | ||
| 20 | +import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 21 | +import com.ruoyi.system.service.ISysUserService; | ||
| 22 | +import com.ruoyi.system.service.PublicService; | ||
| 23 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 24 | +import org.springframework.security.authentication.AuthenticationManager; | ||
| 25 | +import org.springframework.security.authentication.BadCredentialsException; | ||
| 26 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| 27 | +import org.springframework.security.core.Authentication; | ||
| 28 | +import org.springframework.stereotype.Service; | ||
| 29 | + | ||
| 30 | +import javax.annotation.Resource; | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * 登陆业务 | ||
| 34 | + */ | ||
| 35 | +@Service | ||
| 36 | +public class LoginService { | ||
| 37 | + @Autowired | ||
| 38 | + private PublicService publicService; | ||
| 39 | + | ||
| 40 | + @Autowired | ||
| 41 | + private RedisCache redisCache; | ||
| 42 | + | ||
| 43 | + @Resource | ||
| 44 | + private AuthenticationManager authenticationManager; | ||
| 45 | + | ||
| 46 | + @Autowired | ||
| 47 | + private ISysUserService userService; | ||
| 48 | + | ||
| 49 | + @Autowired | ||
| 50 | + private TokenService tokenService; | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 管理员用户名密码登录验证 | ||
| 54 | + * | ||
| 55 | + * @param username 用户名 | ||
| 56 | + * @param password 密码 | ||
| 57 | + * @param code 验证码 | ||
| 58 | + * @param uuid 唯一标识 | ||
| 59 | + * @return 结果 | ||
| 60 | + */ | ||
| 61 | + public String sysUserLogin(String username, String password, String code, String uuid) | ||
| 62 | + { | ||
| 63 | +// boolean captchaOnOff = configService.selectCaptchaOnOff(); | ||
| 64 | +// // 验证码开关 | ||
| 65 | +// if (captchaOnOff) | ||
| 66 | +// { | ||
| 67 | +// validateCaptcha(username, code, uuid); | ||
| 68 | +// } | ||
| 69 | + // 用户验证 | ||
| 70 | + Authentication authentication = userPasswordVerification(username,password); | ||
| 71 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("sysuser.login.success"))); | ||
| 72 | + SysLoginUser loginUser = (SysLoginUser) authentication.getPrincipal(); | ||
| 73 | + recordLoginInfo(loginUser.getUserId()); | ||
| 74 | + // 生成token | ||
| 75 | + return tokenService.createToken(loginUser); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * api用户名密码登陆验证 | ||
| 80 | + * @param user | ||
| 81 | + * @param pass | ||
| 82 | + * @return | ||
| 83 | + */ | ||
| 84 | + public String apiLoginByPass(String user,String pass) { | ||
| 85 | + // 用户验证 | ||
| 86 | + Authentication authentication = userPasswordVerification(user,pass); | ||
| 87 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(user, Constants.LOGIN_SUCCESS, MessageUtils.message("apiuser.login.success"))); | ||
| 88 | + ApiLoginUser loginUser = (ApiLoginUser) authentication.getPrincipal(); | ||
| 89 | + recordLoginInfo(loginUser.getUserId()); | ||
| 90 | + return tokenService.createToken(loginUser); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 刷新api端token | ||
| 95 | + * @param token | ||
| 96 | + * @return | ||
| 97 | + */ | ||
| 98 | + public String refreshApiToken(String token) { | ||
| 99 | + return null; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 鱼儿乐token登陆 | ||
| 104 | + * @param token | ||
| 105 | + * @return | ||
| 106 | + */ | ||
| 107 | + public String yu2leTokenLogin(String token) { | ||
| 108 | + Yu2leLoginToken loginToken = new Yu2leLoginToken(token); | ||
| 109 | + Yu2leUserLogin userInfo = publicService.getObjectForTableName(Yu2leUserLogin.class,"id",loginToken.getUserId()+"","`liu_yu_le`.`user_login`"); | ||
| 110 | + return apiLoginByPass(userInfo.getLoginName(),userInfo.getLoginPass()); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * 记录登录信息 | ||
| 115 | + * | ||
| 116 | + * @param userId 用户ID | ||
| 117 | + */ | ||
| 118 | + private void recordLoginInfo(Long userId) | ||
| 119 | + { | ||
| 120 | + SysUser sysUser = new SysUser(); | ||
| 121 | + sysUser.setUserId(userId); | ||
| 122 | + sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); | ||
| 123 | + sysUser.setLoginDate(DateUtils.getNowDate()); | ||
| 124 | + userService.updateUserProfile(sysUser); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 校验验证码 | ||
| 129 | + * | ||
| 130 | + * @param username 用户名 | ||
| 131 | + * @param code 验证码 | ||
| 132 | + * @param uuid 唯一标识 | ||
| 133 | + * @return 结果 | ||
| 134 | + */ | ||
| 135 | + private void validateCaptcha(String username, String code, String uuid) | ||
| 136 | + { | ||
| 137 | + String verifyKey = Constants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); | ||
| 138 | + String captcha = redisCache.getCacheObject(verifyKey); | ||
| 139 | + redisCache.deleteObject(verifyKey); | ||
| 140 | + if (captcha == null) | ||
| 141 | + { | ||
| 142 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); | ||
| 143 | + throw new CaptchaExpireException(); | ||
| 144 | + } | ||
| 145 | + if (!code.equalsIgnoreCase(captcha)) | ||
| 146 | + { | ||
| 147 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); | ||
| 148 | + throw new CaptchaException(); | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + private Authentication userPasswordVerification(String username,String password) | ||
| 153 | + { | ||
| 154 | + Authentication authentication = null; | ||
| 155 | + try | ||
| 156 | + { | ||
| 157 | + // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername | ||
| 158 | + authentication = authenticationManager | ||
| 159 | + .authenticate(new UsernamePasswordAuthenticationToken(username, password)); | ||
| 160 | + } | ||
| 161 | + catch (Exception e) | ||
| 162 | + { | ||
| 163 | + if (e instanceof BadCredentialsException) | ||
| 164 | + { | ||
| 165 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); | ||
| 166 | + throw new UserPasswordNotMatchException(); | ||
| 167 | + } | ||
| 168 | + else | ||
| 169 | + { | ||
| 170 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); | ||
| 171 | + throw new ServiceException(e.getMessage()); | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + return authentication; | ||
| 175 | + } | ||
| 176 | +} |
| @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; | @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.system.dto.PublicSQL; | 3 | import com.ruoyi.system.dto.PublicSQL; |
| 4 | import org.apache.ibatis.annotations.*; | 4 | import org.apache.ibatis.annotations.*; |
| 5 | +import org.springframework.stereotype.Component; | ||
| 5 | 6 | ||
| 6 | import java.util.List; | 7 | import java.util.List; |
| 7 | import java.util.Map; | 8 | import java.util.Map; |
| @@ -9,6 +10,7 @@ import java.util.Map; | @@ -9,6 +10,7 @@ import java.util.Map; | ||
| 9 | /** | 10 | /** |
| 10 | * 公用mapper | 11 | * 公用mapper |
| 11 | */ | 12 | */ |
| 13 | +@Component | ||
| 12 | public interface PublicMapper { | 14 | public interface PublicMapper { |
| 13 | /** | 15 | /** |
| 14 | * 添加对象 | 16 | * 添加对象 |
| @@ -40,14 +42,14 @@ public interface PublicMapper { | @@ -40,14 +42,14 @@ public interface PublicMapper { | ||
| 40 | * @param whereFieldNames | 42 | * @param whereFieldNames |
| 41 | */ | 43 | */ |
| 42 | @UpdateProvider(type = PublicSQL.class, method = "updateObject") | 44 | @UpdateProvider(type = PublicSQL.class, method = "updateObject") |
| 43 | - void updateObject(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames); | 45 | + int updateObject(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames); |
| 44 | 46 | ||
| 45 | /** | 47 | /** |
| 46 | * 自定义sql更新 | 48 | * 自定义sql更新 |
| 47 | * @param sql | 49 | * @param sql |
| 48 | */ | 50 | */ |
| 49 | @UpdateProvider(type = PublicSQL.class, method = "updateBySql") | 51 | @UpdateProvider(type = PublicSQL.class, method = "updateBySql") |
| 50 | - void updateBySql(String sql); | 52 | + int updateBySql(String sql); |
| 51 | 53 | ||
| 52 | /** | 54 | /** |
| 53 | * 查询 通过条件查询 | 55 | * 查询 通过条件查询 |
| @@ -67,7 +69,7 @@ public interface PublicMapper { | @@ -67,7 +69,7 @@ public interface PublicMapper { | ||
| 67 | * @return | 69 | * @return |
| 68 | */ | 70 | */ |
| 69 | @SelectProvider(type = PublicSQL.class, method = "getObject") | 71 | @SelectProvider(type = PublicSQL.class, method = "getObject") |
| 70 | - Map<String,Object> getObjectForTableName(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName); | 72 | + <T> T getObjectForTableName(@Param("class") Class<T> clas, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName); |
| 71 | 73 | ||
| 72 | /** | 74 | /** |
| 73 | * 查询 通过条件查询单个指定项目 | 75 | * 查询 通过条件查询单个指定项目 |
| @@ -107,7 +109,7 @@ public interface PublicMapper { | @@ -107,7 +109,7 @@ public interface PublicMapper { | ||
| 107 | * @param map | 109 | * @param map |
| 108 | */ | 110 | */ |
| 109 | @UpdateProvider(type = PublicSQL.class, method = "deleteObjectByContent") | 111 | @UpdateProvider(type = PublicSQL.class, method = "deleteObjectByContent") |
| 110 | - void deleteObjectByContent(@Param("objectCalss") Class<?> oClass, @Param("map") Map<String, String> map); | 112 | + int deleteObjectByContent(@Param("objectCalss") Class<?> oClass, @Param("map") Map<String, String> map); |
| 111 | 113 | ||
| 112 | /** | 114 | /** |
| 113 | * 自定义sql语句查询list | 115 | * 自定义sql语句查询list |
| @@ -123,7 +125,7 @@ public interface PublicMapper { | @@ -123,7 +125,7 @@ public interface PublicMapper { | ||
| 123 | * @return | 125 | * @return |
| 124 | */ | 126 | */ |
| 125 | @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObjectList") | 127 | @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObjectList") |
| 126 | - void saveOrUpdateObjectList(List<Object> objectlist); | 128 | + int saveOrUpdateObjectList(List<Object> objectlist); |
| 127 | 129 | ||
| 128 | /** | 130 | /** |
| 129 | * 添加或更新对象 | 131 | * 添加或更新对象 |
| @@ -132,16 +134,16 @@ public interface PublicMapper { | @@ -132,16 +134,16 @@ public interface PublicMapper { | ||
| 132 | * @return | 134 | * @return |
| 133 | */ | 135 | */ |
| 134 | @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObject") | 136 | @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObject") |
| 135 | - void saveOrUpdateObject(Object object); | 137 | + int saveOrUpdateObject(Object object); |
| 136 | 138 | ||
| 137 | /** | 139 | /** |
| 138 | * 通过id删除数据 | 140 | * 通过id删除数据 |
| 139 | * @return | 141 | * @return |
| 140 | */ | 142 | */ |
| 141 | @UpdateProvider(type = PublicSQL.class, method = "deleteObjectById") | 143 | @UpdateProvider(type = PublicSQL.class, method = "deleteObjectById") |
| 142 | - void deleteObjectById(@Param("objectCalss") Class<?> oClass, @Param("id") String id); | 144 | + int deleteObjectById(@Param("objectCalss") Class<?> oClass, @Param("id") String id); |
| 143 | 145 | ||
| 144 | @Options(useGeneratedKeys = false) | 146 | @Options(useGeneratedKeys = false) |
| 145 | @InsertProvider(type = PublicSQL.class, method = "updateBySql") | 147 | @InsertProvider(type = PublicSQL.class, method = "updateBySql") |
| 146 | - void insertIntoBySql(@Param("sql") String sql); | 148 | + int insertIntoBySql(@Param("sql") String sql); |
| 147 | } | 149 | } |
| 1 | +package com.ruoyi.system.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 公用mapper | ||
| 8 | + */ | ||
| 9 | +public interface PublicService { | ||
| 10 | + /** | ||
| 11 | + * 添加对象 | ||
| 12 | + */ | ||
| 13 | + int insert(Object object); | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 指定表名添加 | ||
| 17 | + */ | ||
| 18 | + int insertToTable(Object object, String tableName); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 添加对象集合 | ||
| 22 | + */ | ||
| 23 | + int insertAll(List<?> list); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 指定表名添加对象集合 | ||
| 27 | + */ | ||
| 28 | + int insertAllToTable(List<?> list, String tableName); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 更新对象不为空的属性 | ||
| 32 | + * @param object | ||
| 33 | + * @param whereFieldNames | ||
| 34 | + */ | ||
| 35 | + int updateObject( Object object, String whereFieldNames); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 自定义sql更新 | ||
| 39 | + * @param sql | ||
| 40 | + */ | ||
| 41 | + int updateBySql(String sql); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 查询 通过条件查询 | ||
| 45 | + * @param clas | ||
| 46 | + * @param idName | ||
| 47 | + * @param values | ||
| 48 | + * @return | ||
| 49 | + */ | ||
| 50 | + <T> T getObject( Class<?> clas, String idName, String values); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 查询 通过条件查询 | ||
| 54 | + * @param clas | ||
| 55 | + * @param idName | ||
| 56 | + * @param values | ||
| 57 | + * @return | ||
| 58 | + */ | ||
| 59 | + <T> T getObjectForTableName(Class<T> clas, String idName, String values, String tableName); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 查询 通过条件查询单个指定项目 | ||
| 63 | + * @param clas 類型 | ||
| 64 | + * @param select 查詢結果 | ||
| 65 | + * @param idName 主鍵名稱 | ||
| 66 | + * @param values 主鍵值 | ||
| 67 | + * @return | ||
| 68 | + */ | ||
| 69 | + Map<String,Object> getObjectSelectTableName(Class<?> clas, String select, String idName, String values, String tableName); | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 查询list | ||
| 73 | + * @param object | ||
| 74 | + * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间 | ||
| 75 | + * @param order | ||
| 76 | + * @param pagetSize | ||
| 77 | + * @param pageNo | ||
| 78 | + * @return | ||
| 79 | + */ | ||
| 80 | + List<Map<String,Object>> getObjectList(Object object,String selectStr,Map<String, String> whereMap, String order, Integer pagetSize,Integer pageNo); | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 查詢totle | ||
| 84 | + * @param object | ||
| 85 | + * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间 | ||
| 86 | + * @return | ||
| 87 | + */ | ||
| 88 | + Long getObjectListTotle(Object object, Map<String, String> whereMap); | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 通过条件删除对象 | ||
| 92 | + * @param oClass | ||
| 93 | + * @param map | ||
| 94 | + */ | ||
| 95 | + int deleteObjectByContent(Class<?> oClass, Map<String, String> map); | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 自定义sql语句查询list | ||
| 99 | + * @param sql | ||
| 100 | + * @return | ||
| 101 | + */ | ||
| 102 | + List<Map<String,Object>> getObjectListBySQL(String sql); | ||
| 103 | + /** | ||
| 104 | + * 添加或更新对象列表 | ||
| 105 | + * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`); | ||
| 106 | + * @param objectlist 对象列表 | ||
| 107 | + * @return | ||
| 108 | + */ | ||
| 109 | + int saveOrUpdateObjectList(List<Object> objectlist); | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * 添加或更新对象 | ||
| 113 | + * INSERT INTO test(`in1`,`str1`) VALUES ('1','1'); | ||
| 114 | + * @param object 对象 | ||
| 115 | + * @return | ||
| 116 | + */ | ||
| 117 | + int saveOrUpdateObject(Object object); | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 通过id删除数据 | ||
| 121 | + * @return | ||
| 122 | + */ | ||
| 123 | + int deleteObjectById( Class<?> oClass, String id); | ||
| 124 | + | ||
| 125 | + int insertIntoBySql(String sql); | ||
| 126 | +} |
| 1 | +package com.ruoyi.system.service.impl; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.system.mapper.PublicMapper; | ||
| 4 | +import com.ruoyi.system.service.PublicService; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.Map; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 公用mapper | ||
| 13 | + */ | ||
| 14 | +@Service | ||
| 15 | +public class PublicServiceImpl implements PublicService { | ||
| 16 | + @Autowired | ||
| 17 | + private PublicMapper publicMapper; | ||
| 18 | + /** | ||
| 19 | + * 添加对象 | ||
| 20 | + */ | ||
| 21 | + public int insert(Object object) | ||
| 22 | + { | ||
| 23 | + return publicMapper.insert(object); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 指定表名添加 | ||
| 28 | + */ | ||
| 29 | + public int insertToTable(Object object, String tableName) | ||
| 30 | + { | ||
| 31 | + return publicMapper.insertToTable(object,tableName); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 添加对象集合 | ||
| 36 | + */ | ||
| 37 | + public int insertAll(List<?> list) | ||
| 38 | + { | ||
| 39 | + return publicMapper.insertAll(list); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 指定表名添加对象集合 | ||
| 44 | + */ | ||
| 45 | + public int insertAllToTable(List<?> list, String tableName) | ||
| 46 | + { | ||
| 47 | + return publicMapper.insertAllToTable(list, tableName); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 更新对象不为空的属性 | ||
| 52 | + * @param object | ||
| 53 | + * @param whereFieldNames | ||
| 54 | + */ | ||
| 55 | + public int updateObject(Object object, String whereFieldNames) | ||
| 56 | + { | ||
| 57 | + return publicMapper.updateObject(object,whereFieldNames); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 自定义sql更新 | ||
| 62 | + * @param sql | ||
| 63 | + */ | ||
| 64 | + public int updateBySql(String sql) | ||
| 65 | + { | ||
| 66 | + return publicMapper.updateBySql(sql); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 查询 通过条件查询 | ||
| 71 | + * @param clas | ||
| 72 | + * @param idName | ||
| 73 | + * @param values | ||
| 74 | + * @return | ||
| 75 | + */ | ||
| 76 | + public <T> T getObject(Class<?> clas, String idName, String values) | ||
| 77 | + { | ||
| 78 | + return publicMapper.getObject(clas,idName,values); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 查询 通过条件查询 | ||
| 83 | + * @param clas | ||
| 84 | + * @param idName | ||
| 85 | + * @param values | ||
| 86 | + * @return | ||
| 87 | + */ | ||
| 88 | + public <T> T getObjectForTableName(Class<T> clas, String idName, String values, String tableName) | ||
| 89 | + { | ||
| 90 | + return publicMapper.getObjectForTableName(clas,idName,values,tableName); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 查询 通过条件查询单个指定项目 | ||
| 95 | + * @param clas 類型 | ||
| 96 | + * @param select 查詢結果 | ||
| 97 | + * @param idName 主鍵名稱 | ||
| 98 | + * @param values 主鍵值 | ||
| 99 | + * @return | ||
| 100 | + */ | ||
| 101 | + public Map<String,Object> getObjectSelectTableName(Class<?> clas, String select, String idName, String values, String tableName) | ||
| 102 | + { | ||
| 103 | + return publicMapper.getObjectSelectTableName(clas,select,idName,values,tableName); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * 查询list | ||
| 108 | + * @param object | ||
| 109 | + * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间 | ||
| 110 | + * @param order | ||
| 111 | + * @param pagetSize | ||
| 112 | + * @param pageNo | ||
| 113 | + * @return | ||
| 114 | + */ | ||
| 115 | + public List<Map<String,Object>> getObjectList(Object object, String selectStr, Map<String, String> whereMap, String order, Integer pagetSize, Integer pageNo) | ||
| 116 | + { | ||
| 117 | + return publicMapper.getObjectList(object,selectStr,whereMap,order,pagetSize,pageNo); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 查詢totle | ||
| 122 | + * @param object | ||
| 123 | + * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间 | ||
| 124 | + * @return | ||
| 125 | + */ | ||
| 126 | + public Long getObjectListTotle(Object object, Map<String, String> whereMap) | ||
| 127 | + { | ||
| 128 | + return publicMapper.getObjectListTotle(object,whereMap); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 通过条件删除对象 | ||
| 133 | + * @param oClass | ||
| 134 | + * @param map | ||
| 135 | + */ | ||
| 136 | + public int deleteObjectByContent(Class<?> oClass, Map<String, String> map) | ||
| 137 | + { | ||
| 138 | + return publicMapper.deleteObjectByContent(oClass,map); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * 自定义sql语句查询list | ||
| 143 | + * @param sql | ||
| 144 | + * @return | ||
| 145 | + */ | ||
| 146 | + public List<Map<String,Object>> getObjectListBySQL(String sql) | ||
| 147 | + { | ||
| 148 | + return publicMapper.getObjectListBySQL(sql); | ||
| 149 | + } | ||
| 150 | + /** | ||
| 151 | + * 添加或更新对象列表 | ||
| 152 | + * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`); | ||
| 153 | + * @param objectlist 对象列表 | ||
| 154 | + * @return | ||
| 155 | + */ | ||
| 156 | + public int saveOrUpdateObjectList(List<Object> objectlist) | ||
| 157 | + { | ||
| 158 | + return publicMapper.saveOrUpdateObjectList(objectlist); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + /** | ||
| 162 | + * 添加或更新对象 | ||
| 163 | + * INSERT INTO test(`in1`,`str1`) VALUES ('1','1'); | ||
| 164 | + * @param object 对象 | ||
| 165 | + * @return | ||
| 166 | + */ | ||
| 167 | + public int saveOrUpdateObject(Object object) | ||
| 168 | + { | ||
| 169 | + return publicMapper.saveOrUpdateObject(object); | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * 通过id删除数据 | ||
| 174 | + * @return | ||
| 175 | + */ | ||
| 176 | + public int deleteObjectById(Class<?> oClass, String id) | ||
| 177 | + { | ||
| 178 | + return publicMapper.deleteObjectById(oClass, id); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public int insertIntoBySql(String sql) | ||
| 182 | + { | ||
| 183 | + return publicMapper.insertIntoBySql(sql); | ||
| 184 | + } | ||
| 185 | +} |
-
请 注册 或 登录 后发表评论