| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * éç¨è¯·æ±å¤ç |
| | |
| | | { |
| | | if (!FileUtils.checkAllowDownload(fileName)) |
| | | { |
| | | throw new Exception(StringUtils.format("æä»¶åç§°({})éæ³ï¼ä¸å
许ä¸è½½ã ", fileName)); |
| | | throw new Exception(StrUtil.format("æä»¶åç§°({})éæ³ï¼ä¸å
许ä¸è½½ã ", fileName)); |
| | | } |
| | | String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
| | | String filePath = RuoYiConfig.getDownloadPath() + fileName; |
| | |
| | | { |
| | | if (!FileUtils.checkAllowDownload(resource)) |
| | | { |
| | | throw new Exception(StringUtils.format("èµæºæä»¶({})éæ³ï¼ä¸å
许ä¸è½½ã ", resource)); |
| | | throw new Exception(StrUtil.format("èµæºæä»¶({})éæ³ï¼ä¸å
许ä¸è½½ã ", resource)); |
| | | } |
| | | // æ¬å°èµæºè·¯å¾ |
| | | String localPath = RuoYiConfig.getProfile(); |
| | | // æ°æ®åºèµæºå°å |
| | | String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); |
| | | String downloadPath = localPath + StrUtil.subAfter(resource, Constants.RESOURCE_PREFIX,false); |
| | | // ä¸è½½åç§° |
| | | String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); |
| | | String downloadName = StrUtil.subAfter(downloadPath, "/",true); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, downloadName); |
| | | FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
| | |
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Properties;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.data.redis.core.RedisCallback;
|
| | | import org.springframework.data.redis.core.RedisTemplate;
|
| | |
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | import java.util.*;
|
| | |
|
| | | /**
|
| | | * ç¼åçæ§
|
| | |
| | | commandStats.stringPropertyNames().forEach(key -> {
|
| | | Map<String, String> data = new HashMap<>(2);
|
| | | String property = commandStats.getProperty(key);
|
| | | data.put("name", StringUtils.removeStart(key, "cmdstat_"));
|
| | | data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
|
| | | data.put("name", StrUtil.removePrefix(key, "cmdstat_"));
|
| | | data.put("value", StrUtil.subBetween(property, "calls=", ",usec"));
|
| | | pieList.add(data);
|
| | | });
|
| | | result.put("commandStats", pieList);
|
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | | import com.ruoyi.system.service.ISysUserOnlineService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ·çæ§ |
| | |
| | | for (String key : keys) |
| | | { |
| | | LoginUser user = redisCache.getCacheObject(key); |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) |
| | | if (Validator.isNotEmpty(ipaddr) && Validator.isNotEmpty(userName)) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr()) && StrUtil.equals(userName, user.getUsername())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); |
| | | } |
| | | } |
| | | else if (StringUtils.isNotEmpty(ipaddr)) |
| | | else if (Validator.isNotEmpty(ipaddr)) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); |
| | | } |
| | | } |
| | | else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) |
| | | else if (Validator.isNotEmpty(userName) && Validator.isNotNull(user.getUser())) |
| | | { |
| | | if (StringUtils.equals(userName, user.getUsername())) |
| | | if (StrUtil.equals(userName, user.getUsername())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * é¨é¨ä¿¡æ¯ |
| | |
| | | { |
| | | SysDept d = (SysDept) it.next(); |
| | | if (d.getDeptId().intValue() == deptId |
| | | || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) |
| | | || ArrayUtils.contains(StrUtil.split(d.getAncestors(), ","), deptId + "")) |
| | | { |
| | | it.remove(); |
| | | } |
| | |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹é¨é¨'" + dept.getDeptName() + "'失败ï¼ä¸çº§é¨é¨ä¸è½æ¯èªå·±"); |
| | | } |
| | | else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
| | | else if (StrUtil.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
| | | && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0) |
| | | { |
| | | return AjaxResult.error("该é¨é¨å
嫿ªåç¨çåé¨é¨ï¼"); |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.system.service.ISysDictDataService; |
| | | import com.ruoyi.system.service.ISysDictTypeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°æ®åå
¸ä¿¡æ¯ |
| | |
| | | public AjaxResult dictType(@PathVariable String dictType) |
| | | { |
| | | List<SysDictData> data = dictTypeService.selectDictDataByType(dictType); |
| | | if (StringUtils.isNull(data)) |
| | | if (Validator.isNull(data)) |
| | | { |
| | | data = new ArrayList<SysDictData>(); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | |
| | | import com.ruoyi.framework.web.service.SysPermissionService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * ç»å½éªè¯ |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * èåä¿¡æ¯ |
| | |
| | | return AjaxResult.error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) |
| | | && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) |
| | | && !StrUtil.startWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) |
| | | { |
| | | return AjaxResult.error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | |
| | | return AjaxResult.error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) |
| | | && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) |
| | | && !StrUtil.startWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.service.SysPermissionService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è§è²ä¿¡æ¯ |
| | |
| | | { |
| | | // æ´æ°ç¼åç¨æ·æé |
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) |
| | | if (Validator.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) |
| | | { |
| | | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); |
| | | loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysPostService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * ç¨æ·ä¿¡æ¯ |
| | |
| | | List<SysRole> roles = roleService.selectRoleAll(); |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | ajax.put("posts", postService.selectPostAll()); |
| | | if (StringUtils.isNotNull(userId)) |
| | | if (Validator.isNotNull(userId)) |
| | | { |
| | | ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId)); |
| | | ajax.put("postIds", postService.selectPostListByUserId(userId)); |
| | |
| | | { |
| | | return AjaxResult.error("æ°å¢ç¨æ·'" + user.getUserName() + "'失败ï¼ç»å½è´¦å·å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | else if (Validator.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) |
| | | { |
| | | return AjaxResult.error("æ°å¢ç¨æ·'" + user.getUserName() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getEmail()) |
| | | else if (Validator.isNotEmpty(user.getEmail()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) |
| | | { |
| | | return AjaxResult.error("æ°å¢ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | | { |
| | | userService.checkUserAllowed(user); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | if (Validator.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getEmail()) |
| | | else if (Validator.isNotEmpty(user.getEmail()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | |
| | | package com.ruoyi.web.controller.tool; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import io.swagger.annotations.*; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | /** |
| | | * swagger ç¨æ·æµè¯æ¹æ³ |
| | |
| | | @PostMapping("/save") |
| | | public AjaxResult save(UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | if (Validator.isNull(user) || Validator.isNull(user.getUserId())) |
| | | { |
| | | return AjaxResult.error("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | |
| | | @PutMapping("/update") |
| | | public AjaxResult update(UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | if (Validator.isNull(user) || Validator.isNull(user.getUserId())) |
| | | { |
| | | return AjaxResult.error("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | |
| | | package com.ruoyi.common.core.controller; |
| | | |
| | | import java.beans.PropertyEditorSupport; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.web.bind.annotation.InitBinder; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.page.PageDomain; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.page.TableSupport; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.sql.SqlUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.web.bind.annotation.InitBinder; |
| | | |
| | | import java.beans.PropertyEditorSupport; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * webå±éç¨æ°æ®å¤ç |
| | |
| | | PageDomain pageDomain = TableSupport.buildPageRequest(); |
| | | Integer pageNum = pageDomain.getPageNum(); |
| | | Integer pageSize = pageDomain.getPageSize(); |
| | | if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) |
| | | if (Validator.isNotNull(pageNum) && Validator.isNotNull(pageSize)) |
| | | { |
| | | String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); |
| | | PageHelper.startPage(pageNum, pageSize, orderBy); |
| | |
| | | protected TableDataInfo getDataTable(List<?> list) |
| | | { |
| | | TableDataInfo rspData = new TableDataInfo(); |
| | | rspData.setCode(HttpStatus.SUCCESS); |
| | | rspData.setCode(HttpStatus.HTTP_OK); |
| | | rspData.setMsg("æ¥è¯¢æå"); |
| | | rspData.setRows(list); |
| | | rspData.setTotal(new PageInfo(list).getTotal()); |
| | |
| | | */ |
| | | public String redirect(String url) |
| | | { |
| | | return StringUtils.format("redirect:{}", url); |
| | | return StrUtil.format("redirect:{}", url); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.core.domain; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HttpStatus; |
| | | |
| | | import java.util.HashMap; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * æä½æ¶æ¯æé |
| | |
| | | { |
| | | super.put(CODE_TAG, code); |
| | | super.put(MSG_TAG, msg); |
| | | if (StringUtils.isNotNull(data)) |
| | | if (Validator.isNotNull(data)) |
| | | { |
| | | super.put(DATA_TAG, data); |
| | | } |
| | |
| | | */ |
| | | public static AjaxResult success(String msg, Object data) |
| | | { |
| | | return new AjaxResult(HttpStatus.SUCCESS, msg, data); |
| | | return new AjaxResult(HttpStatus.HTTP_OK, msg, data); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static AjaxResult error(String msg, Object data) |
| | | { |
| | | return new AjaxResult(HttpStatus.ERROR, msg, data); |
| | | return new AjaxResult(HttpStatus.HTTP_INTERNAL_ERROR, msg, data); |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.common.core.page; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | /** |
| | | * åé¡µæ°æ® |
| | |
| | | |
| | | public String getOrderBy() |
| | | { |
| | | if (StringUtils.isEmpty(orderByColumn)) |
| | | if (StrUtil.isEmpty(orderByColumn)) |
| | | { |
| | | return ""; |
| | | } |
| | | return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc; |
| | | return StrUtil.toUnderlineCase(orderByColumn) + " " + isAsc; |
| | | } |
| | | |
| | | public Integer getPageNum() |
| | |
| | | package com.ruoyi.common.exception; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * åºç¡å¼å¸¸ |
| | |
| | | public String getMessage() |
| | | { |
| | | String message = null; |
| | | if (!StringUtils.isEmpty(code)) |
| | | if (!Validator.isEmpty(code)) |
| | | { |
| | | message = MessageUtils.message(code, args); |
| | | } |
| | |
| | | package com.ruoyi.common.filter;
|
| | |
|
| | | import java.io.IOException;
|
| | | import javax.servlet.Filter;
|
| | | import javax.servlet.FilterChain;
|
| | | import javax.servlet.FilterConfig;
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.ServletRequest;
|
| | | import javax.servlet.ServletResponse;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import org.springframework.http.MediaType;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | import javax.servlet.*;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import java.io.IOException;
|
| | |
|
| | | /**
|
| | | * Repeatable è¿æ»¤å¨
|
| | |
| | | {
|
| | | ServletRequest requestWrapper = null;
|
| | | if (request instanceof HttpServletRequest
|
| | | && StringUtils.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE))
|
| | | && StrUtil.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE))
|
| | | {
|
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
|
| | | }
|
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import javax.servlet.Filter; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.FilterConfig; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * 鲿¢XSSæ»å»çè¿æ»¤å¨ |
| | |
| | | { |
| | | String tempExcludes = filterConfig.getInitParameter("excludes"); |
| | | String tempEnabled = filterConfig.getInitParameter("enabled"); |
| | | if (StringUtils.isNotEmpty(tempExcludes)) |
| | | if (StrUtil.isNotEmpty(tempExcludes)) |
| | | { |
| | | String[] url = tempExcludes.split(","); |
| | | for (int i = 0; url != null && i < url.length; i++) |
| | |
| | | excludes.add(url[i]); |
| | | } |
| | | } |
| | | if (StringUtils.isNotEmpty(tempEnabled)) |
| | | if (StrUtil.isNotEmpty(tempEnabled)) |
| | | { |
| | | enabled = Boolean.valueOf(tempEnabled); |
| | | } |
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | |
| | | import javax.servlet.ReadListener; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.html.EscapeUtil; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * XSSè¿æ»¤å¤ç |
| | |
| | | for (int i = 0; i < length; i++) |
| | | { |
| | | // é²xssæ»å»åè¿æ»¤ååç©ºæ ¼ |
| | | escapseValues[i] = EscapeUtil.clean(values[i]).trim(); |
| | | escapseValues[i] = HtmlUtil.cleanHtmlTag(values[i]).trim(); |
| | | } |
| | | return escapseValues; |
| | | } |
| | |
| | | |
| | | // 为空ï¼ç´æ¥è¿å |
| | | String json = IOUtils.toString(super.getInputStream(), "utf-8"); |
| | | if (StringUtils.isEmpty(json)) |
| | | if (Validator.isEmpty(json)) |
| | | { |
| | | return super.getInputStream(); |
| | | } |
| | | |
| | | // xssè¿æ»¤ |
| | | json = EscapeUtil.clean(json).trim(); |
| | | json = HtmlUtil.cleanHtmlTag(json).trim(); |
| | | final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); |
| | | return new ServletInputStream() |
| | | { |
| | |
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | |
| | | public static List<SysDictData> getDictCache(String key)
|
| | | {
|
| | | Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
| | | if (StringUtils.isNotNull(cacheObj))
|
| | | if (Validator.isNotNull(cacheObj))
|
| | | {
|
| | | List<SysDictData> dictDatas = StringUtils.cast(cacheObj);
|
| | | List<SysDictData> dictDatas = (List<SysDictData>)cacheObj;
|
| | | return dictDatas;
|
| | | }
|
| | | return null;
|
| | |
| | | StringBuilder propertyString = new StringBuilder();
|
| | | List<SysDictData> datas = getDictCache(dictType);
|
| | |
|
| | | if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
|
| | | if (StrUtil.containsAny(separator, dictValue) && Validator.isNotEmpty(datas))
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return StringUtils.stripEnd(propertyString.toString(), separator);
|
| | | return StrUtil.strip(propertyString.toString(), null, separator);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | StringBuilder propertyString = new StringBuilder();
|
| | | List<SysDictData> datas = getDictCache(dictType);
|
| | |
|
| | | if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
|
| | | if (StrUtil.containsAny(separator, dictLabel) && Validator.isNotEmpty(datas))
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return StringUtils.stripEnd(propertyString.toString(), separator);
|
| | | return StrUtil.strip(propertyString.toString(), null, separator);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.http.HttpStatus; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new CustomException("è·åç¨æ·è´¦æ·å¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | throw new CustomException("è·åç¨æ·è´¦æ·å¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new CustomException("è·åç¨æ·ä¿¡æ¯å¼å¸¸", HttpStatus.UNAUTHORIZED); |
| | | throw new CustomException("è·åç¨æ·ä¿¡æ¯å¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import org.springframework.web.context.request.RequestAttributes; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 客æ·ç«¯å·¥å
·ç±» |
| | |
| | | } |
| | | |
| | | String uri = request.getRequestURI(); |
| | | if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) |
| | | if (StrUtil.equalsAnyIgnoreCase(uri, ".json", ".xml")) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | String ajax = request.getParameter("__ajax"); |
| | | if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) |
| | | if (StrUtil.equalsAnyIgnoreCase(ajax, "json", "xml")) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException; |
| | | import com.ruoyi.common.exception.file.FileSizeLimitExceededException; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ å·¥å
·ç±» |
| | |
| | | private static final String getPathFileName(String uploadDir, String fileName) throws IOException |
| | | { |
| | | int dirLastIndex = RuoYiConfig.getProfile().length() + 1; |
| | | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
| | | String currentDir = StrUtil.subSuf(uploadDir, dirLastIndex); |
| | | String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| | | return pathFileName; |
| | | } |
| | |
| | | public static final String getExtension(MultipartFile file) |
| | | { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | if (StringUtils.isEmpty(extension)) |
| | | if (Validator.isEmpty(extension)) |
| | | { |
| | | extension = MimeTypeUtils.getExtension(file.getContentType()); |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * æä»¶å¤çå·¥å
·ç±» |
| | |
| | | public static boolean checkAllowDownload(String resource) |
| | | { |
| | | // ç¦æ¢ç®å½ä¸è·³çº§å« |
| | | if (StringUtils.contains(resource, "..")) |
| | | if (StrUtil.contains(resource, "..")) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // æ£æ¥å
许ä¸è½½çæä»¶è§å |
| | | if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) |
| | | if (ArrayUtil.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import org.apache.poi.util.IOUtils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.FileInputStream;
|
| | |
| | | import java.net.URL;
|
| | | import java.net.URLConnection;
|
| | | import java.util.Arrays;
|
| | | import org.apache.poi.util.IOUtils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | /**
|
| | | * å¾çå¤çå·¥å
·ç±»
|
| | |
| | | {
|
| | | // æ¬æºå°å
|
| | | String localPath = RuoYiConfig.getProfile();
|
| | | String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX);
|
| | | String downloadPath = localPath + StrUtil.subAfter(url, Constants.RESOURCE_PREFIX,false);
|
| | | in = new FileInputStream(downloadPath);
|
| | | }
|
| | | return IOUtils.toByteArray(in);
|
| | |
| | | package com.ruoyi.common.utils.http;
|
| | |
|
| | | import cn.hutool.core.exceptions.ExceptionUtil;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import javax.servlet.ServletRequest;
|
| | | import java.io.BufferedReader;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.nio.charset.Charset;
|
| | | import javax.servlet.ServletRequest;
|
| | | import org.apache.commons.lang3.exception.ExceptionUtils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | /**
|
| | | * éç¨httpå·¥å
·å°è£
|
| | |
| | | }
|
| | | catch (IOException e)
|
| | | {
|
| | | LOGGER.error(ExceptionUtils.getMessage(e));
|
| | | LOGGER.error(ExceptionUtil.getMessage(e));
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | package com.ruoyi.common.utils.ip; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * è·åå°åç±» |
| | |
| | | try |
| | | { |
| | | String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK); |
| | | if (StringUtils.isEmpty(rspStr)) |
| | | if (StrUtil.isEmpty(rspStr)) |
| | | { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | return UNKNOWN; |
| | |
| | | package com.ruoyi.common.utils.ip; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HtmlUtil; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.html.EscapeUtil; |
| | | |
| | | /** |
| | | * è·åIPæ¹æ³ |
| | |
| | | { |
| | | ip = request.getRemoteAddr(); |
| | | } |
| | | return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : EscapeUtil.clean(ip); |
| | | return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); |
| | | } |
| | | |
| | | public static boolean internalIp(String ip) |
| | |
| | | |
| | | private static boolean internalIp(byte[] addr) |
| | | { |
| | | if (StringUtils.isNull(addr) || addr.length < 2) |
| | | if (Validator.isNull(addr) || addr.length < 2) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.poi;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileOutputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.OutputStream;
|
| | | import java.lang.reflect.Field;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.DecimalFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.UUID;
|
| | | import java.util.stream.Collectors;
|
| | | import org.apache.poi.ss.usermodel.BorderStyle;
|
| | | import org.apache.poi.ss.usermodel.Cell;
|
| | | import org.apache.poi.ss.usermodel.CellStyle;
|
| | | import org.apache.poi.ss.usermodel.CellType;
|
| | | import org.apache.poi.ss.usermodel.ClientAnchor;
|
| | | import org.apache.poi.ss.usermodel.DataValidation;
|
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
| | | import org.apache.poi.ss.usermodel.DataValidationHelper;
|
| | | import org.apache.poi.ss.usermodel.DateUtil;
|
| | | import org.apache.poi.ss.usermodel.Drawing;
|
| | | import org.apache.poi.ss.usermodel.FillPatternType;
|
| | | import org.apache.poi.ss.usermodel.Font;
|
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
| | | import org.apache.poi.ss.usermodel.IndexedColors;
|
| | | import org.apache.poi.ss.usermodel.Row;
|
| | | import org.apache.poi.ss.usermodel.Sheet;
|
| | | import org.apache.poi.ss.usermodel.VerticalAlignment;
|
| | | import org.apache.poi.ss.usermodel.Workbook;
|
| | | import org.apache.poi.ss.usermodel.WorkbookFactory;
|
| | | import org.apache.poi.ss.util.CellRangeAddressList;
|
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import cn.hutool.core.convert.Convert;
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.annotation.Excel.Type;
|
| | | import com.ruoyi.common.annotation.Excels;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.DictUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.file.FileTypeUtils;
|
| | | import com.ruoyi.common.utils.file.ImageUtils;
|
| | | import com.ruoyi.common.utils.reflect.ReflectUtils;
|
| | | import org.apache.poi.ss.usermodel.*;
|
| | | import org.apache.poi.ss.util.CellRangeAddressList;
|
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import java.io.*;
|
| | | import java.lang.reflect.Field;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.DecimalFormat;
|
| | | import java.util.*;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | /**
|
| | | * Excelç¸å
³å¤ç
|
| | |
| | | */
|
| | | public List<T> importExcel(InputStream is) throws Exception
|
| | | {
|
| | | return importExcel(StringUtils.EMPTY, is);
|
| | | return importExcel(StrUtil.EMPTY, is);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | this.wb = WorkbookFactory.create(is);
|
| | | List<T> list = new ArrayList<T>();
|
| | | Sheet sheet = null;
|
| | | if (StringUtils.isNotEmpty(sheetName))
|
| | | if (Validator.isNotEmpty(sheetName))
|
| | | {
|
| | | // 妿æå®sheetå,ååæå®sheetä¸çå
容.
|
| | | sheet = wb.getSheet(sheetName);
|
| | |
| | | for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
|
| | | {
|
| | | Cell cell = heard.getCell(i);
|
| | | if (StringUtils.isNotNull(cell))
|
| | | if (Validator.isNotNull(cell))
|
| | | {
|
| | | String value = this.getCellValue(heard, i).toString();
|
| | | cellMap.put(value, i);
|
| | |
| | | if (String.class == fieldType)
|
| | | {
|
| | | String s = Convert.toStr(val);
|
| | | if (StringUtils.endsWith(s, ".0"))
|
| | | if (StrUtil.endWith(s, ".0"))
|
| | | {
|
| | | val = StringUtils.substringBefore(s, ".0");
|
| | | val = StrUtil.subBefore(s, ".0",false);
|
| | | }
|
| | | else
|
| | | {
|
| | | String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
| | | if (StringUtils.isNotEmpty(dateFormat))
|
| | | if (Validator.isNotEmpty(dateFormat))
|
| | | {
|
| | | val = DateUtils.parseDateToStr(dateFormat, (Date) val);
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
|
| | | else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && Validator.isNumber(Convert.toStr(val)))
|
| | | {
|
| | | val = Convert.toInt(val);
|
| | | }
|
| | |
| | | {
|
| | | val = Convert.toBool(val, false);
|
| | | }
|
| | | if (StringUtils.isNotNull(fieldType))
|
| | | if (Validator.isNotNull(fieldType))
|
| | | {
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | String propertyName = field.getName();
|
| | | if (StringUtils.isNotEmpty(attr.targetAttr()))
|
| | | if (Validator.isNotEmpty(attr.targetAttr()))
|
| | | {
|
| | | propertyName = field.getName() + "." + attr.targetAttr();
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
| | | else if (Validator.isNotEmpty(attr.readConverterExp()))
|
| | | {
|
| | | val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(attr.dictType()))
|
| | | else if (Validator.isNotEmpty(attr.dictType()))
|
| | | {
|
| | | val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
| | | }
|
| | |
| | | {
|
| | | if (ColumnType.STRING == attr.cellType())
|
| | | {
|
| | | cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
| | | cell.setCellValue(Validator.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
| | | }
|
| | | else if (ColumnType.NUMERIC == attr.cellType())
|
| | | {
|
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
|
| | | cell.setCellValue(StrUtil.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
|
| | | }
|
| | | else if (ColumnType.IMAGE == attr.cellType())
|
| | | {
|
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
|
| | | cell.getRow().getRowNum() + 1);
|
| | | String imagePath = Convert.toStr(value);
|
| | | if (StringUtils.isNotEmpty(imagePath))
|
| | | if (Validator.isNotEmpty(imagePath))
|
| | | {
|
| | | byte[] data = ImageUtils.getImage(imagePath);
|
| | | getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
|
| | |
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
| | | }
|
| | | // å¦æè®¾ç½®äºæç¤ºä¿¡æ¯åé¼ æ æ¾ä¸å»æç¤º.
|
| | | if (StringUtils.isNotEmpty(attr.prompt()))
|
| | | if (Validator.isNotEmpty(attr.prompt()))
|
| | | {
|
| | | // è¿éé»è®¤è®¾äº2-101åæç¤º.
|
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
|
| | |
| | | String readConverterExp = attr.readConverterExp();
|
| | | String separator = attr.separator();
|
| | | String dictType = attr.dictType();
|
| | | if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
| | | if (Validator.isNotEmpty(dateFormat) && Validator.isNotNull(value))
|
| | | {
|
| | | cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
| | | else if (Validator.isNotEmpty(readConverterExp) && Validator.isNotNull(value))
|
| | | {
|
| | | cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
| | | else if (Validator.isNotEmpty(dictType) && Validator.isNotNull(value))
|
| | | {
|
| | | cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
| | | }
|
| | |
| | | for (String item : convertSource)
|
| | | {
|
| | | String[] itemArray = item.split("=");
|
| | | if (StringUtils.containsAny(separator, propertyValue))
|
| | | if (StrUtil.containsAny(separator, propertyValue))
|
| | | {
|
| | | for (String value : propertyValue.split(separator))
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return StringUtils.stripEnd(propertyString.toString(), separator);
|
| | | return StrUtil.strip(propertyString.toString(), null,separator);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | for (String item : convertSource)
|
| | | {
|
| | | String[] itemArray = item.split("=");
|
| | | if (StringUtils.containsAny(separator, propertyValue))
|
| | | if (StrUtil.containsAny(separator, propertyValue))
|
| | | {
|
| | | for (String value : propertyValue.split(separator))
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return StringUtils.stripEnd(propertyString.toString(), separator);
|
| | | return StrUtil.strip(propertyString.toString(), null,separator);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
|
| | | {
|
| | | Object o = field.get(vo);
|
| | | if (StringUtils.isNotEmpty(excel.targetAttr()))
|
| | | if (Validator.isNotEmpty(excel.targetAttr()))
|
| | | {
|
| | | String target = excel.targetAttr();
|
| | | if (target.indexOf(".") > -1)
|
| | | if (target.contains("."))
|
| | | {
|
| | | String[] targets = target.split("[.]");
|
| | | for (String name : targets)
|
| | |
| | | */
|
| | | private Object getValue(Object o, String name) throws Exception
|
| | | {
|
| | | if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name))
|
| | | if (Validator.isNotNull(o) && Validator.isNotEmpty(name))
|
| | | {
|
| | | Class<?> clazz = o.getClass();
|
| | | Field field = clazz.getDeclaredField(name);
|
| | |
| | | try
|
| | | {
|
| | | Cell cell = row.getCell(column);
|
| | | if (StringUtils.isNotNull(cell))
|
| | | if (Validator.isNotNull(cell))
|
| | | {
|
| | | if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA)
|
| | | {
|
| | |
| | | package com.ruoyi.common.utils.reflect;
|
| | |
|
| | | import java.lang.reflect.Field;
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.lang.reflect.Modifier;
|
| | | import java.lang.reflect.ParameterizedType;
|
| | | import java.lang.reflect.Type;
|
| | | import java.util.Date;
|
| | | import cn.hutool.core.convert.Convert;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.commons.lang3.Validate;
|
| | | import org.apache.poi.ss.usermodel.DateUtil;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | |
|
| | | import java.lang.reflect.*;
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * åå°å·¥å
·ç±». æä¾è°ç¨getter/setteræ¹æ³, 访é®ç§æåé, è°ç¨ç§ææ¹æ³, è·åæ³åç±»åClass, 被AOPè¿ççå®ç±»çå·¥å
·å½æ°.
|
| | |
| | | package com.ruoyi.common.utils.spring; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import org.springframework.aop.framework.AopContext; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
| | |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * springå·¥å
·ç±» æ¹ä¾¿å¨éspring管çç¯å¢ä¸è·åbean |
| | |
| | | public static String getActiveProfile() |
| | | { |
| | | final String[] activeProfiles = getActiveProfiles(); |
| | | return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; |
| | | return Validator.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.utils.sql; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * sqlæä½å·¥å
·ç±» |
| | |
| | | */ |
| | | public static String escapeOrderBySql(String value) |
| | | { |
| | | if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) |
| | | if (Validator.isNotEmpty(value) && !isValidOrderBySql(value)) |
| | | { |
| | | throw new BaseException("åæ°ä¸ç¬¦åè§èï¼ä¸è½è¿è¡æ¥è¯¢"); |
| | | } |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.Signature; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | |
| | | import java.lang.reflect.Method; |
| | | |
| | | /** |
| | | * æ°æ®è¿æ»¤å¤ç |
| | |
| | | } |
| | | // è·åå½åçç¨æ· |
| | | LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | if (Validator.isNotNull(loginUser)) |
| | | { |
| | | SysUser currentUser = loginUser.getUser(); |
| | | // 妿æ¯è¶
级管çåï¼åä¸è¿æ»¤æ°æ® |
| | | if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) |
| | | if (Validator.isNotNull(currentUser) && !currentUser.isAdmin()) |
| | | { |
| | | dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), |
| | | controllerDataScope.userAlias()); |
| | |
| | | } |
| | | else if (DATA_SCOPE_CUSTOM.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format( |
| | | sqlString.append(StrUtil.format( |
| | | " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, |
| | | role.getRoleId())); |
| | | } |
| | | else if (DATA_SCOPE_DEPT.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); |
| | | sqlString.append(StrUtil.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); |
| | | } |
| | | else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) |
| | | { |
| | | sqlString.append(StringUtils.format( |
| | | sqlString.append(StrUtil.format( |
| | | " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
| | | deptAlias, user.getDeptId(), user.getDeptId())); |
| | | } |
| | | else if (DATA_SCOPE_SELF.equals(dataScope)) |
| | | { |
| | | if (StringUtils.isNotBlank(userAlias)) |
| | | if (StrUtil.isNotBlank(userAlias)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); |
| | | sqlString.append(StrUtil.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(sqlString.toString())) |
| | | if (StrUtil.isNotBlank(sqlString.toString())) |
| | | { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (StringUtils.isNotNull(params) && params instanceof BaseEntity) |
| | | if (Validator.isNotNull(params) && params instanceof BaseEntity) |
| | | { |
| | | BaseEntity baseEntity = (BaseEntity) params; |
| | | baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import java.util.Objects; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | |
| | | import org.springframework.core.annotation.AnnotationUtils; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 夿°æ®æºå¤ç |
| | |
| | | { |
| | | DataSource dataSource = getDataSource(point); |
| | | |
| | | if (StringUtils.isNotNull(dataSource)) |
| | | if (Validator.isNotNull(dataSource)) |
| | | { |
| | | DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); |
| | | } |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | | import com.ruoyi.common.enums.HttpMethod; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.Signature; |
| | | import org.aspectj.lang.annotation.AfterReturning; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.servlet.HandlerMapping; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | | import com.ruoyi.common.enums.HttpMethod; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.SysOperLog; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * æä½æ¥å¿è®°å½å¤ç |
| | |
| | | if (e != null) |
| | | { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | operLog.setErrorMsg(StrUtil.sub(e.getMessage(), 0, 2000)); |
| | | } |
| | | // è®¾ç½®æ¹æ³åç§° |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | |
| | | if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) |
| | | { |
| | | String params = argsArrayToString(joinPoint.getArgs()); |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000)); |
| | | operLog.setOperParam(StrUtil.sub(params, 0, 2000)); |
| | | } |
| | | else |
| | | { |
| | | Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); |
| | | operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); |
| | | operLog.setOperParam(StrUtil.sub(paramsMap.toString(), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.DispatcherType; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.filter.RepeatableFilter; |
| | | import com.ruoyi.common.filter.XssFilter; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import com.ruoyi.common.filter.RepeatableFilter; |
| | | import com.ruoyi.common.filter.XssFilter; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.servlet.DispatcherType; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Filteré
ç½® |
| | |
| | | FilterRegistrationBean registration = new FilterRegistrationBean(); |
| | | registration.setDispatcherTypes(DispatcherType.REQUEST); |
| | | registration.setFilter(new XssFilter()); |
| | | registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); |
| | | registration.addUrlPatterns(StrUtil.split(urlPatterns, ",")); |
| | | registration.setName("xssFilter"); |
| | | registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); |
| | | Map<String, String> initParameters = new HashMap<String, String>(); |
| | |
| | | package com.ruoyi.framework.interceptor.impl;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.TimeUnit;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.stereotype.Component;
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.http.HttpHelper;
|
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
|
| | | /**
|
| | | * å¤æè¯·æ±urlåæ°æ®æ¯å¦åä¸ä¸æ¬¡ç¸åï¼
|
| | |
| | | }
|
| | |
|
| | | // bodyåæ°ä¸ºç©ºï¼è·åParameterçæ°æ®
|
| | | if (StringUtils.isEmpty(nowParams))
|
| | | if (Validator.isEmpty(nowParams))
|
| | | {
|
| | | nowParams = JSONObject.toJSONString(request.getParameterMap());
|
| | | }
|
| | |
| | |
|
| | | // å¯ä¸å¼ï¼æ²¡ææ¶æ¯å¤´å使ç¨è¯·æ±å°åï¼
|
| | | String submitKey = request.getHeader(header);
|
| | | if (StringUtils.isEmpty(submitKey))
|
| | | if (Validator.isEmpty(submitKey))
|
| | | {
|
| | | submitKey = url;
|
| | | }
|
| | |
| | | package com.ruoyi.framework.manager.factory; |
| | | |
| | | import java.util.TimerTask; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.LogUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | |
| | | import com.ruoyi.system.service.ISysLogininforService; |
| | | import com.ruoyi.system.service.ISysOperLogService; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.TimerTask; |
| | | |
| | | /** |
| | | * 弿¥å·¥åï¼äº§çä»»å¡ç¨ï¼ |
| | |
| | | { |
| | | String address = AddressUtils.getRealAddressByIP(ip); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(LogUtils.getBlock(ip)); |
| | | s.append(getBlock(ip)); |
| | | s.append(address); |
| | | s.append(LogUtils.getBlock(username)); |
| | | s.append(LogUtils.getBlock(status)); |
| | | s.append(LogUtils.getBlock(message)); |
| | | s.append(getBlock(username)); |
| | | s.append(getBlock(status)); |
| | | s.append(getBlock(message)); |
| | | // æå°ä¿¡æ¯å°æ¥å¿ |
| | | sys_user_logger.info(s.toString(), args); |
| | | // è·å客æ·ç«¯æä½ç³»ç» |
| | |
| | | } |
| | | }; |
| | | } |
| | | |
| | | public static String getBlock(Object msg) |
| | | { |
| | | if (msg == null) |
| | | { |
| | | msg = ""; |
| | | } |
| | | return "[" + msg.toString() + "]"; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.security.filter; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.filter.OncePerRequestFilter; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * tokenè¿æ»¤å¨ éªè¯tokenæææ§ |
| | |
| | | throws ServletException, IOException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) |
| | | if (Validator.isNotNull(loginUser) && Validator.isNull(SecurityUtils.getAuthentication())) |
| | | { |
| | | tokenService.verifyToken(loginUser); |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); |
| | |
| | | package com.ruoyi.framework.security.handle; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import org.springframework.security.core.AuthenticationException; |
| | | import org.springframework.security.web.AuthenticationEntryPoint; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥å¤çç±» è¿åæªææ |
| | |
| | | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) |
| | | throws IOException |
| | | { |
| | | int code = HttpStatus.UNAUTHORIZED; |
| | | String msg = StringUtils.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | int code = HttpStatus.HTTP_UNAUTHORIZED; |
| | | String msg = StrUtil.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.security.handle; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * èªå®ä¹éåºå¤çç±» è¿åæå |
| | |
| | | throws IOException, ServletException |
| | | { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | if (Validator.isNotNull(loginUser)) |
| | | { |
| | | String userName = loginUser.getUsername(); |
| | | // å é¤ç¨æ·ç¼åè®°å½ |
| | |
| | | // è®°å½ç¨æ·éåºæ¥å¿ |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "éåºæå")); |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "éåºæå"))); |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.HTTP_OK, "éåºæå"))); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.web.exception; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.exception.DemoModeException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.security.access.AccessDeniedException; |
| | |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | import org.springframework.web.servlet.NoHandlerFoundException; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.exception.DemoModeException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.validation.ConstraintViolationException; |
| | | |
| | |
| | | @ExceptionHandler(CustomException.class) |
| | | public AjaxResult businessException(CustomException e) |
| | | { |
| | | if (StringUtils.isNull(e.getCode())) |
| | | if (Validator.isNull(e.getCode())) |
| | | { |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | |
| | | public AjaxResult handlerNoFoundException(Exception e) |
| | | { |
| | | log.error(e.getMessage(), e); |
| | | return AjaxResult.error(HttpStatus.NOT_FOUND, "è·¯å¾ä¸åå¨ï¼è¯·æ£æ¥è·¯å¾æ¯å¦æ£ç¡®"); |
| | | return AjaxResult.error(HttpStatus.HTTP_NOT_FOUND, "è·¯å¾ä¸åå¨ï¼è¯·æ£æ¥è·¯å¾æ¯å¦æ£ç¡®"); |
| | | } |
| | | |
| | | @ExceptionHandler(AccessDeniedException.class) |
| | | public AjaxResult handleAuthorizationException(AccessDeniedException e) |
| | | { |
| | | log.error(e.getMessage()); |
| | | return AjaxResult.error(HttpStatus.FORBIDDEN, "没ææéï¼è¯·è系管çåææ"); |
| | | return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "没ææéï¼è¯·è系管çåææ"); |
| | | } |
| | | |
| | | @ExceptionHandler(AccountExpiredException.class) |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import java.util.Set; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * RuoYié¦å èªå®ä¹æéå®ç°ï¼ssåèªSpringSecurityé¦åæ¯ |
| | |
| | | */ |
| | | public boolean hasPermi(String permission) |
| | | { |
| | | if (StringUtils.isEmpty(permission)) |
| | | if (Validator.isEmpty(permission)) |
| | | { |
| | | return false; |
| | | } |
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) |
| | | if (Validator.isNull(loginUser) || Validator.isEmpty(loginUser.getPermissions())) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | */ |
| | | public boolean hasAnyPermi(String permissions) |
| | | { |
| | | if (StringUtils.isEmpty(permissions)) |
| | | if (Validator.isEmpty(permissions)) |
| | | { |
| | | return false; |
| | | } |
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) |
| | | if (Validator.isNull(loginUser) || Validator.isEmpty(loginUser.getPermissions())) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | */ |
| | | public boolean hasRole(String role) |
| | | { |
| | | if (StringUtils.isEmpty(role)) |
| | | if (Validator.isEmpty(role)) |
| | | { |
| | | return false; |
| | | } |
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) |
| | | if (Validator.isNull(loginUser) || Validator.isEmpty(loginUser.getUser().getRoles())) |
| | | { |
| | | return false; |
| | | } |
| | | for (SysRole sysRole : loginUser.getUser().getRoles()) |
| | | { |
| | | String roleKey = sysRole.getRoleKey(); |
| | | if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StringUtils.trim(role))) |
| | | if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StrUtil.trim(role))) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | */ |
| | | public boolean hasAnyRoles(String roles) |
| | | { |
| | | if (StringUtils.isEmpty(roles)) |
| | | if (Validator.isEmpty(roles)) |
| | | { |
| | | return false; |
| | | } |
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); |
| | | if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) |
| | | if (Validator.isNull(loginUser) || Validator.isEmpty(loginUser.getUser().getRoles())) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | */ |
| | | private boolean hasPermissions(Set<String> permissions, String permission) |
| | | { |
| | | return permissions.contains(ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission)); |
| | | return permissions.contains(ALL_PERMISSION) || permissions.contains(StrUtil.trim(permission)); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import io.jsonwebtoken.Claims; |
| | | import io.jsonwebtoken.Jwts; |
| | | import io.jsonwebtoken.SignatureAlgorithm; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * tokenéªè¯å¤ç |
| | |
| | | { |
| | | // è·åè¯·æ±æºå¸¦ç令ç |
| | | String token = getToken(request); |
| | | if (StringUtils.isNotEmpty(token)) |
| | | if (Validator.isNotEmpty(token)) |
| | | { |
| | | Claims claims = parseToken(token); |
| | | // è§£æå¯¹åºçæé以åç¨æ·ä¿¡æ¯ |
| | |
| | | */ |
| | | public void setLoginUser(LoginUser loginUser) |
| | | { |
| | | if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) |
| | | if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken())) |
| | | { |
| | | refreshToken(loginUser); |
| | | } |
| | |
| | | */ |
| | | public void delLoginUser(String token) |
| | | { |
| | | if (StringUtils.isNotEmpty(token)) |
| | | if (Validator.isNotEmpty(token)) |
| | | { |
| | | String userKey = getTokenKey(token); |
| | | redisCache.deleteObject(userKey); |
| | |
| | | private String getToken(HttpServletRequest request) |
| | | { |
| | | String token = request.getHeader(header); |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) |
| | | if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) |
| | | { |
| | | token = token.replace(Constants.TOKEN_PREFIX, ""); |
| | | } |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.UserStatus; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.security.core.userdetails.UserDetailsService; |
| | | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.UserStatus; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * ç¨æ·éªè¯å¤ç |
| | |
| | | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException |
| | | { |
| | | SysUser user = userService.selectUserByUserName(username); |
| | | if (StringUtils.isNull(user)) |
| | | if (Validator.isNull(user)) |
| | | { |
| | | log.info("ç»å½ç¨æ·ï¼{} ä¸åå¨.", username); |
| | | throw new UsernameNotFoundException("ç»å½ç¨æ·ï¼" + username + " ä¸åå¨"); |
| | |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | |
| | | package com.ruoyi.generator.domain; |
| | | |
| | | import java.util.List; |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotBlank; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ä¸å¡è¡¨ gen_table |
| | |
| | | |
| | | public static boolean isSub(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_SUB, tplCategory); |
| | | } |
| | | |
| | | public boolean isTree() |
| | |
| | | |
| | | public static boolean isTree(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_TREE, tplCategory); |
| | | } |
| | | |
| | | public boolean isCrud() |
| | |
| | | |
| | | public static boolean isCrud(String tplCategory) |
| | | { |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | } |
| | | |
| | | public boolean isSuperColumn(String javaField) |
| | |
| | | { |
| | | if (isTree(tplCategory)) |
| | | { |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); |
| | | } |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.generator.domain; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | |
| | | /** |
| | | * 代ç çæä¸å¡å段表 gen_table_column |
| | |
| | | |
| | | public String getCapJavaField() |
| | | { |
| | | return StringUtils.capitalize(javaField); |
| | | return StrUtil.upperFirst(javaField); |
| | | } |
| | | |
| | | public void setIsPk(String isPk) |
| | |
| | | |
| | | public boolean isPk(String isPk) |
| | | { |
| | | return isPk != null && StringUtils.equals("1", isPk); |
| | | return isPk != null && StrUtil.equals("1", isPk); |
| | | } |
| | | |
| | | public String getIsIncrement() |
| | |
| | | |
| | | public boolean isIncrement(String isIncrement) |
| | | { |
| | | return isIncrement != null && StringUtils.equals("1", isIncrement); |
| | | return isIncrement != null && StrUtil.equals("1", isIncrement); |
| | | } |
| | | |
| | | public void setIsRequired(String isRequired) |
| | |
| | | |
| | | public boolean isRequired(String isRequired) |
| | | { |
| | | return isRequired != null && StringUtils.equals("1", isRequired); |
| | | return isRequired != null && StrUtil.equals("1", isRequired); |
| | | } |
| | | |
| | | public void setIsInsert(String isInsert) |
| | |
| | | |
| | | public boolean isInsert(String isInsert) |
| | | { |
| | | return isInsert != null && StringUtils.equals("1", isInsert); |
| | | return isInsert != null && StrUtil.equals("1", isInsert); |
| | | } |
| | | |
| | | public void setIsEdit(String isEdit) |
| | |
| | | |
| | | public boolean isEdit(String isEdit) |
| | | { |
| | | return isEdit != null && StringUtils.equals("1", isEdit); |
| | | return isEdit != null && StrUtil.equals("1", isEdit); |
| | | } |
| | | |
| | | public void setIsList(String isList) |
| | |
| | | |
| | | public boolean isList(String isList) |
| | | { |
| | | return isList != null && StringUtils.equals("1", isList); |
| | | return isList != null && StrUtil.equals("1", isList); |
| | | } |
| | | |
| | | public void setIsQuery(String isQuery) |
| | |
| | | |
| | | public boolean isQuery(String isQuery) |
| | | { |
| | | return isQuery != null && StringUtils.equals("1", isQuery); |
| | | return isQuery != null && StrUtil.equals("1", isQuery); |
| | | } |
| | | |
| | | public void setQueryType(String queryType) |
| | |
| | | |
| | | public static boolean isSuperColumn(String javaField) |
| | | { |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | // BaseEntity |
| | | "createBy", "createTime", "updateBy", "updateTime", "remark", |
| | | // TreeEntity |
| | |
| | | public static boolean isUsableColumn(String javaField) |
| | | { |
| | | // isSuperColumn()ä¸çååç¨äºé¿å
çæå¤ä½Domain屿§ï¼è¥æäºå±æ§å¨çæé¡µé¢æ¶éè¦ç¨å°ä¸è½å¿½ç¥ï¼åæ¾å¨æ¤å¤ç½åå |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | } |
| | | |
| | | public String readConverterExp() |
| | | { |
| | | String remarks = StringUtils.substringBetween(this.columnComment, "ï¼", "ï¼"); |
| | | String remarks = StrUtil.subBetween(this.columnComment, "ï¼", "ï¼"); |
| | | StringBuffer sb = new StringBuffer(); |
| | | if (StringUtils.isNotEmpty(remarks)) |
| | | if (StrUtil.isNotEmpty(remarks)) |
| | | { |
| | | for (String value : remarks.split(" ")) |
| | | { |
| | | if (StringUtils.isNotEmpty(value)) |
| | | if (StrUtil.isNotEmpty(value)) |
| | | { |
| | | Object startStr = value.subSequence(0, 1); |
| | | String endStr = value.substring(1); |
| | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper; |
| | | |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper; |
| | | import com.ruoyi.generator.mapper.GenTableMapper; |
| | | import com.ruoyi.generator.util.GenUtils; |
| | | import com.ruoyi.generator.util.VelocityInitializer; |
| | | import com.ruoyi.generator.util.VelocityUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.velocity.Template; |
| | | import org.apache.velocity.VelocityContext; |
| | | import org.apache.velocity.app.Velocity; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.velocity.Template; |
| | | import org.apache.velocity.VelocityContext; |
| | | import org.apache.velocity.app.Velocity; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.core.text.CharsetKit; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper; |
| | | import com.ruoyi.generator.mapper.GenTableMapper; |
| | | import com.ruoyi.generator.util.GenUtils; |
| | | import com.ruoyi.generator.util.VelocityInitializer; |
| | | import com.ruoyi.generator.util.VelocityUtils; |
| | | |
| | | /** |
| | | * ä¸å¡ æå¡å±å®ç° |
| | |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) |
| | | { |
| | | if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) |
| | | if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) |
| | | { |
| | | // æ¸²ææ¨¡æ¿ |
| | | StringWriter sw = new StringWriter(); |
| | |
| | | try |
| | | { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); |
| | | FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | |
| | | List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | | |
| | | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | if (StringUtils.isEmpty(dbTableColumns)) |
| | | if (Validator.isEmpty(dbTableColumns)) |
| | | { |
| | | throw new CustomException("åæ¥æ°æ®å¤±è´¥ï¼åè¡¨ç»æä¸åå¨"); |
| | | } |
| | |
| | | }); |
| | | |
| | | List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); |
| | | if (StringUtils.isNotEmpty(delColumns)) |
| | | if (Validator.isNotEmpty(delColumns)) |
| | | { |
| | | genTableColumnMapper.deleteGenTableColumns(delColumns); |
| | | } |
| | |
| | | { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) |
| | | if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) |
| | | { |
| | | throw new CustomException("æ ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) |
| | | else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) |
| | | { |
| | | throw new CustomException("æ ç¶ç¼ç åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) |
| | | else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) |
| | | { |
| | | throw new CustomException("æ åç§°åæ®µä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) |
| | | { |
| | | if (StringUtils.isEmpty(genTable.getSubTableName())) |
| | | if (Validator.isEmpty(genTable.getSubTableName())) |
| | | { |
| | | throw new CustomException("å
³èå表ç表åä¸è½ä¸ºç©º"); |
| | | } |
| | | else if (StringUtils.isEmpty(genTable.getSubTableFkName())) |
| | | else if (Validator.isEmpty(genTable.getSubTableFkName())) |
| | | { |
| | | throw new CustomException("å表å
³èçå¤é®åä¸è½ä¸ºç©º"); |
| | | } |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getPkColumn())) |
| | | if (Validator.isNull(table.getPkColumn())) |
| | | { |
| | | table.setPkColumn(table.getColumns().get(0)); |
| | | } |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getSubTable().getPkColumn())) |
| | | if (Validator.isNull(table.getSubTable().getPkColumn())) |
| | | { |
| | | table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); |
| | | } |
| | |
| | | public void setSubTable(GenTable table) |
| | | { |
| | | String subTableName = table.getSubTableName(); |
| | | if (StringUtils.isNotEmpty(subTableName)) |
| | | if (Validator.isNotEmpty(subTableName)) |
| | | { |
| | | table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); |
| | | } |
| | |
| | | public void setTableFromOptions(GenTable genTable) |
| | | { |
| | | JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); |
| | | if (StringUtils.isNotNull(paramsObj)) |
| | | if (Validator.isNotNull(paramsObj)) |
| | | { |
| | | String treeCode = paramsObj.getString(GenConstants.TREE_CODE); |
| | | String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); |
| | |
| | | public static String getGenPath(GenTable table, String template) |
| | | { |
| | | String genPath = table.getGenPath(); |
| | | if (StringUtils.equals(genPath, "/")) |
| | | if (StrUtil.equals(genPath, "/")) |
| | | { |
| | | return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | |
| | | package com.ruoyi.generator.util; |
| | | |
| | | import java.util.Arrays; |
| | | import org.apache.commons.lang3.RegExUtils; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.generator.config.GenConfig; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import org.apache.commons.lang3.RegExUtils; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * 代ç çæå¨ å·¥å
·ç±» |
| | |
| | | column.setTableId(table.getTableId()); |
| | | column.setCreateBy(table.getCreateBy()); |
| | | // 设置javaåæ®µå |
| | | column.setJavaField(StringUtils.toCamelCase(columnName)); |
| | | column.setJavaField(StrUtil.toCamelCase(columnName)); |
| | | // 设置é»è®¤ç±»å |
| | | column.setJavaType(GenConstants.TYPE_STRING); |
| | | |
| | |
| | | column.setHtmlType(GenConstants.HTML_INPUT); |
| | | |
| | | // å¦ææ¯æµ®ç¹å ç»ä¸ç¨BigDecimal |
| | | String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); |
| | | String[] str = StrUtil.split(StrUtil.subBetween(column.getColumnType(), "(", ")"), ","); |
| | | if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_BIGDECIMAL); |
| | |
| | | } |
| | | |
| | | // æ¥è¯¢å段类å |
| | | if (StringUtils.endsWithIgnoreCase(columnName, "name")) |
| | | if (StrUtil.endWithIgnoreCase(columnName, "name")) |
| | | { |
| | | column.setQueryType(GenConstants.QUERY_LIKE); |
| | | } |
| | | // ç¶æåæ®µè®¾ç½®åéæ¡ |
| | | if (StringUtils.endsWithIgnoreCase(columnName, "status")) |
| | | if (StrUtil.endWithIgnoreCase(columnName, "status")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_RADIO); |
| | | } |
| | | // ç±»å&æ§å«åæ®µè®¾ç½®ä¸ææ¡ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "type") |
| | | || StringUtils.endsWithIgnoreCase(columnName, "sex")) |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "type") |
| | | || StrUtil.endWithIgnoreCase(columnName, "sex")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_SELECT); |
| | | } |
| | | // å¾çåæ®µè®¾ç½®å¾çä¸ä¼ æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "image")) |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "image")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); |
| | | } |
| | | // æä»¶å段设置æä»¶ä¸ä¼ æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "file")) |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "file")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); |
| | | } |
| | | // å
容忮µè®¾ç½®å¯ææ¬æ§ä»¶ |
| | | else if (StringUtils.endsWithIgnoreCase(columnName, "content")) |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "content")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_EDITOR); |
| | | } |
| | |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | int nameLength = packageName.length(); |
| | | String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); |
| | | String moduleName = StrUtil.sub(packageName, lastIndex + 1, nameLength); |
| | | return moduleName; |
| | | } |
| | | |
| | |
| | | { |
| | | int lastIndex = tableName.lastIndexOf("_"); |
| | | int nameLength = tableName.length(); |
| | | String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); |
| | | String businessName = StrUtil.sub(tableName, lastIndex + 1, nameLength); |
| | | return businessName; |
| | | } |
| | | |
| | |
| | | { |
| | | boolean autoRemovePre = GenConfig.getAutoRemovePre(); |
| | | String tablePrefix = GenConfig.getTablePrefix(); |
| | | if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) |
| | | if (autoRemovePre && StrUtil.isNotEmpty(tablePrefix)) |
| | | { |
| | | String[] searchList = StringUtils.split(tablePrefix, ","); |
| | | String[] searchList = StrUtil.split(tablePrefix, ","); |
| | | tableName = replaceFirst(tableName, searchList); |
| | | } |
| | | return StringUtils.convertToCamelCase(tableName); |
| | | return StrUtil.toCamelCase(tableName); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getDbType(String columnType) |
| | | { |
| | | if (StringUtils.indexOf(columnType, "(") > 0) |
| | | if (StrUtil.indexOf(columnType, '(') > 0) |
| | | { |
| | | return StringUtils.substringBefore(columnType, "("); |
| | | return StrUtil.subBefore(columnType, "(",false); |
| | | } |
| | | else |
| | | { |
| | |
| | | */ |
| | | public static Integer getColumnLength(String columnType) |
| | | { |
| | | if (StringUtils.indexOf(columnType, "(") > 0) |
| | | if (StrUtil.indexOf(columnType, '(') > 0) |
| | | { |
| | | String length = StringUtils.substringBetween(columnType, "(", ")"); |
| | | String length = StrUtil.subBetween(columnType, "(", ")"); |
| | | return Integer.valueOf(length); |
| | | } |
| | | else |
| | |
| | | package com.ruoyi.generator.util; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import org.apache.velocity.VelocityContext; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import org.apache.velocity.VelocityContext; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 模æ¿å¤çå·¥å
·ç±» |
| | |
| | | VelocityContext velocityContext = new VelocityContext(); |
| | | velocityContext.put("tplCategory", genTable.getTplCategory()); |
| | | velocityContext.put("tableName", genTable.getTableName()); |
| | | velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "ã请填ååè½åç§°ã"); |
| | | velocityContext.put("functionName", StrUtil.isNotEmpty(functionName) ? functionName : "ã请填ååè½åç§°ã"); |
| | | velocityContext.put("ClassName", genTable.getClassName()); |
| | | velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); |
| | | velocityContext.put("className", StrUtil.lowerFirst(genTable.getClassName())); |
| | | velocityContext.put("moduleName", genTable.getModuleName()); |
| | | velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); |
| | | velocityContext.put("BusinessName", StrUtil.upperFirst(genTable.getBusinessName())); |
| | | velocityContext.put("businessName", genTable.getBusinessName()); |
| | | velocityContext.put("basePackage", getPackagePrefix(packageName)); |
| | | velocityContext.put("packageName", packageName); |
| | |
| | | String subTableName = genTable.getSubTableName(); |
| | | String subTableFkName = genTable.getSubTableFkName(); |
| | | String subClassName = genTable.getSubTable().getClassName(); |
| | | String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); |
| | | String subTableFkClassName = StrUtil.toCamelCase(subTableFkName); |
| | | |
| | | context.put("subTable", subTable); |
| | | context.put("subTableName", subTableName); |
| | | context.put("subTableFkName", subTableFkName); |
| | | context.put("subTableFkClassName", subTableFkClassName); |
| | | context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); |
| | | context.put("subTableFkclassName", StrUtil.lowerFirst(subTableFkClassName)); |
| | | context.put("subClassName", subClassName); |
| | | context.put("subclassName", StringUtils.uncapitalize(subClassName)); |
| | | context.put("subclassName", StrUtil.lowerFirst(subClassName)); |
| | | context.put("subImportList", getImportList(genTable.getSubTable())); |
| | | } |
| | | |
| | |
| | | // ä¸å¡åç§° |
| | | String businessName = genTable.getBusinessName(); |
| | | |
| | | String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); |
| | | String javaPath = PROJECT_PATH + "/" + StrUtil.replace(packageName, ".", "/"); |
| | | String mybatisPath = MYBATIS_PATH + "/" + moduleName; |
| | | String vuePath = "vue"; |
| | | |
| | | if (template.contains("domain.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); |
| | | fileName = StrUtil.format("{}/domain/{}.java", javaPath, className); |
| | | } |
| | | if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) |
| | | if (template.contains("sub-domain.java.vm") && StrUtil.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) |
| | | { |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); |
| | | fileName = StrUtil.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); |
| | | } |
| | | else if (template.contains("mapper.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); |
| | | fileName = StrUtil.format("{}/mapper/{}Mapper.java", javaPath, className); |
| | | } |
| | | else if (template.contains("service.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); |
| | | fileName = StrUtil.format("{}/service/I{}Service.java", javaPath, className); |
| | | } |
| | | else if (template.contains("serviceImpl.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); |
| | | fileName = StrUtil.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); |
| | | } |
| | | else if (template.contains("controller.java.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); |
| | | fileName = StrUtil.format("{}/controller/{}Controller.java", javaPath, className); |
| | | } |
| | | else if (template.contains("mapper.xml.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); |
| | | fileName = StrUtil.format("{}/{}Mapper.xml", mybatisPath, className); |
| | | } |
| | | else if (template.contains("sql.vm")) |
| | | { |
| | |
| | | } |
| | | else if (template.contains("api.js.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); |
| | | fileName = StrUtil.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index.vue.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | fileName = StrUtil.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index-tree.vue.vm")) |
| | | { |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | fileName = StrUtil.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | return fileName; |
| | | } |
| | |
| | | public static String getPackagePrefix(String packageName) |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | String basePackage = StringUtils.substring(packageName, 0, lastIndex); |
| | | String basePackage = StrUtil.sub(packageName, 0, lastIndex); |
| | | return basePackage; |
| | | } |
| | | |
| | |
| | | List<GenTableColumn> columns = genTable.getColumns(); |
| | | GenTable subGenTable = genTable.getSubTable(); |
| | | HashSet<String> importList = new HashSet<String>(); |
| | | if (StringUtils.isNotNull(subGenTable)) |
| | | if (Validator.isNotNull(subGenTable)) |
| | | { |
| | | importList.add("java.util.List"); |
| | | } |
| | |
| | | */ |
| | | public static String getPermissionPrefix(String moduleName, String businessName) |
| | | { |
| | | return StringUtils.format("{}:{}", moduleName, businessName); |
| | | return StrUtil.format("{}:{}", moduleName, businessName); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getParentMenuId(JSONObject paramsObj) |
| | | { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) |
| | | { |
| | | return paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | } |
| | |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_CODE)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | return StrUtil.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | return StrUtil.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | if (paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); |
| | | return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | return StrUtil.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.quartz.domain;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.Date;
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.fasterxml.jackson.annotation.JsonFormat;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import java.io.Serializable;
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦è¡¨ sys_job
|
| | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
| | | public Date getNextValidTime()
|
| | | {
|
| | | if (StringUtils.isNotEmpty(cronExpression))
|
| | | if (StrUtil.isNotEmpty(cronExpression))
|
| | | {
|
| | | return CronUtils.getNextExecution(cronExpression);
|
| | | }
|
| | |
| | | package com.ruoyi.quartz.task;
|
| | |
|
| | | import cn.hutool.core.lang.Console;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦æµè¯
|
| | |
| | | {
|
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
| | | {
|
| | | System.out.println(StringUtils.format("æ§è¡å¤åæ¹æ³ï¼ å符串类å{}ï¼å¸å°ç±»å{}ï¼é¿æ´å{}ï¼æµ®ç¹å{}ï¼æ´å½¢{}", s, b, l, d, i));
|
| | | Console.log(StrUtil.format("æ§è¡å¤åæ¹æ³ï¼ å符串类å{}ï¼å¸å°ç±»å{}ï¼é¿æ´å{}ï¼æµ®ç¹å{}ï¼æ´å½¢{}", s, b, l, d, i));
|
| | | }
|
| | |
|
| | | public void ryParams(String params)
|
| | | {
|
| | | System.out.println("æ§è¡æåæ¹æ³ï¼" + params);
|
| | | Console.log("æ§è¡æåæ¹æ³ï¼" + params);
|
| | | }
|
| | |
|
| | | public void ryNoParams()
|
| | | {
|
| | | System.out.println("æ§è¡æ åæ¹æ³");
|
| | | Console.log("æ§è¡æ åæ¹æ³");
|
| | | }
|
| | | }
|
| | |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import java.util.Date;
|
| | | import cn.hutool.core.bean.BeanUtil;
|
| | | import cn.hutool.core.exceptions.ExceptionUtil;
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | | import org.quartz.Job;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.quartz.JobExecutionException;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.utils.ExceptionUtil;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.bean.BeanUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * æ½è±¡quartzè°ç¨
|
| | |
| | | public void execute(JobExecutionContext context) throws JobExecutionException
|
| | | {
|
| | | SysJob sysJob = new SysJob();
|
| | | BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
| | | BeanUtil.copyProperties(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
| | | try
|
| | | {
|
| | | before(context, sysJob);
|
| | | if (sysJob != null)
|
| | | if (Validator.isNotNull(sysJob))
|
| | | {
|
| | | doExecute(context, sysJob);
|
| | | }
|
| | |
| | | if (e != null)
|
| | | {
|
| | | sysJobLog.setStatus(Constants.FAIL);
|
| | | String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
| | | String errorMsg = StrUtil.sub(ExceptionUtil.stacktraceToString(e), 0, 2000);
|
| | | sysJobLog.setExceptionInfo(errorMsg);
|
| | | }
|
| | | else
|
| | |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.LinkedList;
|
| | | import java.util.List;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 任塿§è¡å·¥å
·
|
| | |
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
| | | InvocationTargetException
|
| | | {
|
| | | if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | if (Validator.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
|
| | | method.invoke(bean, getMethodParamsValue(methodParams));
|
| | |
| | | */
|
| | | public static boolean isValidClassName(String invokeTarget)
|
| | | {
|
| | | return StringUtils.countMatches(invokeTarget, ".") > 1;
|
| | | return StrUtil.count(invokeTarget, ".") > 1;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static String getBeanName(String invokeTarget)
|
| | | {
|
| | | String beanName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringBeforeLast(beanName, ".");
|
| | | String beanName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subBefore(beanName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static String getMethodName(String invokeTarget)
|
| | | {
|
| | | String methodName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringAfterLast(methodName, ".");
|
| | | String methodName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subAfter(methodName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static List<Object[]> getMethodParams(String invokeTarget)
|
| | | {
|
| | | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
|
| | | if (StringUtils.isEmpty(methodStr))
|
| | | String methodStr = StrUtil.subBetween(invokeTarget, "(", ")");
|
| | | if (StrUtil.isEmpty(methodStr))
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
| | | List<Object[]> classs = new LinkedList<>();
|
| | | for (int i = 0; i < methodParams.length; i++)
|
| | | {
|
| | | String str = StringUtils.trimToEmpty(methodParams[i]);
|
| | | String str = StrUtil.trimToEmpty(methodParams[i]);
|
| | | // Stringå符串类åï¼å
å«'
|
| | | if (StringUtils.contains(str, "'"))
|
| | | if (StrUtil.contains(str, "'"))
|
| | | {
|
| | | classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class });
|
| | | classs.add(new Object[] { StrUtil.replace(str, "'", ""), String.class });
|
| | | }
|
| | | // booleanå¸å°ç±»åï¼çäºtrueæè
false
|
| | | else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false"))
|
| | | else if (StrUtil.equals(str, "true") || StrUtil.equalsIgnoreCase(str, "false"))
|
| | | {
|
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
|
| | | }
|
| | | // longé¿æ´å½¢ï¼å
å«L
|
| | | else if (StringUtils.containsIgnoreCase(str, "L"))
|
| | | else if (StrUtil.containsIgnoreCase(str, "L"))
|
| | | {
|
| | | classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | classs.add(new Object[] { Long.valueOf(StrUtil.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | }
|
| | | // doubleæµ®ç¹ç±»åï¼å
å«D
|
| | | else if (StringUtils.containsIgnoreCase(str, "D"))
|
| | | else if (StrUtil.containsIgnoreCase(str, "D"))
|
| | | {
|
| | | classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | classs.add(new Object[] { Double.valueOf(StrUtil.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | }
|
| | | // å
¶ä»ç±»åå½ç±»ä¸ºæ´å½¢
|
| | | else
|
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import javax.annotation.PostConstruct; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.enums.DataSourceType; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * åæ°é
ç½® æå¡å±å®ç° |
| | |
| | | public String selectConfigByKey(String configKey) |
| | | { |
| | | String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey))); |
| | | if (StringUtils.isNotEmpty(configValue)) |
| | | if (Validator.isNotEmpty(configValue)) |
| | | { |
| | | return configValue; |
| | | } |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey(configKey); |
| | | SysConfig retConfig = configMapper.selectConfig(config); |
| | | if (StringUtils.isNotNull(retConfig)) |
| | | if (Validator.isNotNull(retConfig)) |
| | | { |
| | | redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); |
| | | return retConfig.getConfigValue(); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | return StrUtil.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | for (Long configId : configIds) |
| | | { |
| | | SysConfig config = selectConfigById(configId); |
| | | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) |
| | | if (StrUtil.equals(UserConstants.YES, config.getConfigType())) |
| | | { |
| | | throw new CustomException(String.format("å
ç½®åæ°ã%1$sãä¸è½å é¤ ", config.getConfigKey())); |
| | | } |
| | |
| | | @Override |
| | | public String checkConfigKeyUnique(SysConfig config) |
| | | { |
| | | Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); |
| | | Long configId = Validator.isNull(config.getConfigId()) ? -1L : config.getConfigId(); |
| | | SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey()); |
| | | if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * é¨é¨ç®¡ç æå¡å®ç° |
| | |
| | | @Override |
| | | public String checkDeptNameUnique(SysDept dept) |
| | | { |
| | | Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); |
| | | Long deptId = Validator.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); |
| | | SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); |
| | | if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | { |
| | | SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); |
| | | SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); |
| | | if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) |
| | | if (Validator.isNotNull(newParentDept) && Validator.isNotNull(oldDept)) |
| | | { |
| | | String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); |
| | | String oldAncestors = oldDept.getAncestors(); |
| | |
| | | while (it.hasNext()) |
| | | { |
| | | SysDept n = (SysDept) it.next(); |
| | | if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) |
| | | if (Validator.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) |
| | | { |
| | | tlist.add(n); |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.PostConstruct; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.domain.entity.SysDictType; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.mapper.SysDictDataMapper; |
| | | import com.ruoyi.system.mapper.SysDictTypeMapper; |
| | | import com.ruoyi.system.service.ISysDictTypeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * åå
¸ ä¸å¡å±å¤ç |
| | |
| | | public List<SysDictData> selectDictDataByType(String dictType) |
| | | { |
| | | List<SysDictData> dictDatas = DictUtils.getDictCache(dictType); |
| | | if (StringUtils.isNotEmpty(dictDatas)) |
| | | if (Validator.isNotEmpty(dictDatas)) |
| | | { |
| | | return dictDatas; |
| | | } |
| | | dictDatas = dictDataMapper.selectDictDataByType(dictType); |
| | | if (StringUtils.isNotEmpty(dictDatas)) |
| | | if (Validator.isNotEmpty(dictDatas)) |
| | | { |
| | | DictUtils.setDictCache(dictType, dictDatas); |
| | | return dictDatas; |
| | |
| | | @Override |
| | | public String checkDictTypeUnique(SysDictType dict) |
| | | { |
| | | Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); |
| | | Long dictId = Validator.isNull(dict.getDictId()) ? -1L : dict.getDictId(); |
| | | SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); |
| | | if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) |
| | | if (Validator.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | | import com.ruoyi.system.mapper.SysMenuMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * èå ä¸å¡å±å¤ç |
| | |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) |
| | | { |
| | | if (StringUtils.isNotEmpty(perm)) |
| | | if (Validator.isNotEmpty(perm)) |
| | | { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | } |
| | |
| | | router.setName(getRouteName(menu)); |
| | | router.setPath(getRouterPath(menu)); |
| | | router.setComponent(getComponent(menu)); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()))); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()))); |
| | | List<SysMenu> cMenus = menu.getChildren(); |
| | | if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) |
| | | { |
| | |
| | | RouterVo children = new RouterVo(); |
| | | children.setPath(menu.getPath()); |
| | | children.setComponent(menu.getComponent()); |
| | | children.setName(StringUtils.capitalize(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()))); |
| | | children.setName(StrUtil.upperFirst(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()))); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | | } |
| | |
| | | @Override |
| | | public String checkMenuNameUnique(SysMenu menu) |
| | | { |
| | | Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); |
| | | Long menuId = Validator.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); |
| | | SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); |
| | | if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | */ |
| | | public String getRouteName(SysMenu menu) |
| | | { |
| | | String routerName = StringUtils.capitalize(menu.getPath()); |
| | | String routerName = StrUtil.upperFirst(menu.getPath()); |
| | | // éå¤é¾å¹¶ä¸æ¯ä¸çº§ç®å½ï¼ç±»å为ç®å½ï¼ |
| | | if (isMeunFrame(menu)) |
| | | { |
| | | routerName = StringUtils.EMPTY; |
| | | routerName = StrUtil.EMPTY; |
| | | } |
| | | return routerName; |
| | | } |
| | |
| | | public String getComponent(SysMenu menu) |
| | | { |
| | | String component = UserConstants.LAYOUT; |
| | | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) |
| | | if (StrUtil.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) |
| | | { |
| | | component = menu.getComponent(); |
| | | } |
| | | else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) |
| | | else if (StrUtil.isEmpty(menu.getComponent()) && isParentView(menu)) |
| | | { |
| | | component = UserConstants.PARENT_VIEW; |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysPost; |
| | | import com.ruoyi.system.mapper.SysPostMapper; |
| | | import com.ruoyi.system.mapper.SysUserPostMapper; |
| | | import com.ruoyi.system.service.ISysPostService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å²ä½ä¿¡æ¯ æå¡å±å¤ç |
| | |
| | | @Override |
| | | public String checkPostNameUnique(SysPost post) |
| | | { |
| | | Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = postMapper.checkPostNameUnique(post.getPostName()); |
| | | if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | @Override |
| | | public String checkPostCodeUnique(SysPost post) |
| | | { |
| | | Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); |
| | | if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.SysRoleDept; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | |
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper; |
| | | import com.ruoyi.system.mapper.SysUserRoleMapper; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * è§è² ä¸å¡å±å¤ç |
| | |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (SysRole perm : perms) |
| | | { |
| | | if (StringUtils.isNotNull(perm)) |
| | | if (Validator.isNotNull(perm)) |
| | | { |
| | | permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); |
| | | } |
| | |
| | | @Override |
| | | public String checkRoleNameUnique(SysRole role) |
| | | { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | @Override |
| | | public String checkRoleKeyUnique(SysRole role) |
| | | { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | @Override |
| | | public void checkRoleAllowed(SysRole role) |
| | | { |
| | | if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) |
| | | if (Validator.isNotNull(role.getRoleId()) && role.isAdmin()) |
| | | { |
| | | throw new CustomException("ä¸å
许æä½è¶
级管çåè§è²"); |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | | import com.ruoyi.system.service.ISysUserOnlineService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ· æå¡å±å¤ç |
| | |
| | | @Override |
| | | public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | |
| | | @Override |
| | | public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(userName, user.getUsername())) |
| | | if (StrUtil.equals(userName, user.getUsername())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | |
| | | @Override |
| | | public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) |
| | | { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr()) && StrUtil.equals(userName, user.getUsername())) |
| | | { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | |
| | | @Override |
| | | public SysUserOnline loginUserToUserOnline(LoginUser user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) |
| | | if (Validator.isNull(user) || Validator.isNull(user.getUser())) |
| | | { |
| | | return null; |
| | | } |
| | |
| | | sysUserOnline.setBrowser(user.getBrowser()); |
| | | sysUserOnline.setOs(user.getOs()); |
| | | sysUserOnline.setLoginTime(user.getLoginTime()); |
| | | if (StringUtils.isNotNull(user.getUser().getDept())) |
| | | if (Validator.isNotNull(user.getUser().getDept())) |
| | | { |
| | | sysUserOnline.setDeptName(user.getUser().getDept().getDeptName()); |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysPost; |
| | | import com.ruoyi.system.domain.SysUserPost; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.mapper.SysPostMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.mapper.SysUserPostMapper; |
| | | import com.ruoyi.system.mapper.SysUserRoleMapper; |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç¨æ· ä¸å¡å±å¤ç |
| | |
| | | { |
| | | idsStr.append(role.getRoleName()).append(","); |
| | | } |
| | | if (StringUtils.isNotEmpty(idsStr.toString())) |
| | | if (Validator.isNotEmpty(idsStr.toString())) |
| | | { |
| | | return idsStr.substring(0, idsStr.length() - 1); |
| | | } |
| | |
| | | { |
| | | idsStr.append(post.getPostName()).append(","); |
| | | } |
| | | if (StringUtils.isNotEmpty(idsStr.toString())) |
| | | if (Validator.isNotEmpty(idsStr.toString())) |
| | | { |
| | | return idsStr.substring(0, idsStr.length() - 1); |
| | | } |
| | |
| | | @Override |
| | | public String checkPhoneUnique(SysUser user) |
| | | { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | Long userId = Validator.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber()); |
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | @Override |
| | | public String checkEmailUnique(SysUser user) |
| | | { |
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | Long userId = Validator.isNull(user.getUserId()) ? -1L : user.getUserId(); |
| | | SysUser info = userMapper.checkEmailUnique(user.getEmail()); |
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | if (Validator.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) |
| | | { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | |
| | | @Override |
| | | public void checkUserAllowed(SysUser user) |
| | | { |
| | | if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) |
| | | if (Validator.isNotNull(user.getUserId()) && user.isAdmin()) |
| | | { |
| | | throw new CustomException("ä¸å
许æä½è¶
级管çåç¨æ·"); |
| | | } |
| | |
| | | public void insertUserRole(SysUser user) |
| | | { |
| | | Long[] roles = user.getRoleIds(); |
| | | if (StringUtils.isNotNull(roles)) |
| | | if (Validator.isNotNull(roles)) |
| | | { |
| | | // æ°å¢ç¨æ·ä¸è§è²ç®¡ç |
| | | List<SysUserRole> list = new ArrayList<SysUserRole>(); |
| | |
| | | public void insertUserPost(SysUser user) |
| | | { |
| | | Long[] posts = user.getPostIds(); |
| | | if (StringUtils.isNotNull(posts)) |
| | | if (Validator.isNotNull(posts)) |
| | | { |
| | | // æ°å¢ç¨æ·ä¸å²ä½ç®¡ç |
| | | List<SysUserPost> list = new ArrayList<SysUserPost>(); |
| | |
| | | @Override |
| | | public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) |
| | | { |
| | | if (StringUtils.isNull(userList) || userList.size() == 0) |
| | | if (Validator.isNull(userList) || userList.size() == 0) |
| | | { |
| | | throw new CustomException("导å
¥ç¨æ·æ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | } |
| | |
| | | { |
| | | // éªè¯æ¯å¦åå¨è¿ä¸ªç¨æ· |
| | | SysUser u = userMapper.selectUserByUserName(user.getUserName()); |
| | | if (StringUtils.isNull(u)) |
| | | if (Validator.isNull(u)) |
| | | { |
| | | user.setPassword(SecurityUtils.encryptPassword(password)); |
| | | user.setCreateBy(operName); |