正在显示
99 个修改的文件
包含
4266 行增加
和
97 行删除
lh-common/lh-public-dao/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>lh-public-dao</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | + <dependencies> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 23 | + <artifactId>ruoyi-common</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + <dependency> | ||
| 26 | + <groupId>tk.mybatis</groupId> | ||
| 27 | + <artifactId>mapper</artifactId> | ||
| 28 | + <!-- 建议使用最新版本,最新版本请从项目首页查找 --> | ||
| 29 | + </dependency> | ||
| 30 | + <dependency> | ||
| 31 | + <groupId>tk.mybatis</groupId> | ||
| 32 | + <artifactId>mapper-spring-boot-starter</artifactId> | ||
| 33 | + </dependency> | ||
| 34 | + </dependencies> | ||
| 35 | + | ||
| 36 | +</project> |
| 1 | -package com.ruoyi.system.dto; | 1 | +package com.zhonglai.luhui.dao.dto; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.system.domain.tool.PublicSQLConfig; | 3 | +import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import org.apache.commons.lang3.StringUtils; | 4 | import org.apache.commons.lang3.StringUtils; |
| 5 | 5 | ||
| 6 | import java.lang.reflect.Field; | 6 | import java.lang.reflect.Field; |
| 1 | -package com.ruoyi.system.mapper; | 1 | +package com.zhonglai.luhui.dao.mapper; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.system.dto.PublicSQL; | 3 | +import com.zhonglai.luhui.dao.dto.PublicSQL; |
| 4 | import org.apache.ibatis.annotations.*; | 4 | import org.apache.ibatis.annotations.*; |
| 5 | import org.springframework.stereotype.Component; | 5 | import org.springframework.stereotype.Component; |
| 6 | 6 |
| 1 | -package com.ruoyi.system.service.impl; | 1 | +package com.zhonglai.luhui.dao.service.impl; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.system.mapper.MapMapper; | ||
| 4 | -import com.ruoyi.system.service.MapService; | 3 | +import com.zhonglai.luhui.dao.mapper.MapMapper; |
| 4 | +import com.zhonglai.luhui.dao.service.MapService; | ||
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.stereotype.Service; | 6 | import org.springframework.stereotype.Service; |
| 7 | 7 |
| 1 | -package com.ruoyi.system.service.impl; | 1 | +package com.zhonglai.luhui.dao.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | -import com.ruoyi.system.mapper.PublicMapper; | ||
| 5 | -import com.ruoyi.system.service.PublicService; | ||
| 6 | -import org.apache.ibatis.annotations.Param; | 4 | +import com.zhonglai.luhui.dao.mapper.PublicMapper; |
| 5 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 9 | 8 |
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 5 | <parent> | 5 | <parent> |
| 6 | <groupId>com.zhonglai.luhui</groupId> | 6 | <groupId>com.zhonglai.luhui</groupId> |
| 7 | - <artifactId>Luhui</artifactId> | 7 | + <artifactId>lh-common</artifactId> |
| 8 | <version>1.0-SNAPSHOT</version> | 8 | <version>1.0-SNAPSHOT</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| @@ -32,7 +32,11 @@ | @@ -32,7 +32,11 @@ | ||
| 32 | <!-- 通用工具--> | 32 | <!-- 通用工具--> |
| 33 | <dependency> | 33 | <dependency> |
| 34 | <groupId>com.zhonglai.luhui</groupId> | 34 | <groupId>com.zhonglai.luhui</groupId> |
| 35 | - <artifactId>ruoyi-common</artifactId> | 35 | + <artifactId>ruoyi-common-security</artifactId> |
| 36 | + </dependency> | ||
| 37 | + <dependency> | ||
| 38 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 39 | + <artifactId>lh-jar-action</artifactId> | ||
| 36 | </dependency> | 40 | </dependency> |
| 37 | 41 | ||
| 38 | </dependencies> | 42 | </dependencies> |
| @@ -3,6 +3,9 @@ package com.ruoyi.quartz.controller; | @@ -3,6 +3,9 @@ package com.ruoyi.quartz.controller; | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import javax.servlet.http.HttpServletResponse; | 4 | import javax.servlet.http.HttpServletResponse; |
| 5 | 5 | ||
| 6 | +import com.zhonglai.luhui.action.BaseController; | ||
| 7 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 8 | +import com.zhonglai.luhui.sys.utils.ExcelUtil; | ||
| 6 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
| 7 | import io.swagger.annotations.ApiOperation; | 10 | import io.swagger.annotations.ApiOperation; |
| 8 | import org.quartz.SchedulerException; | 11 | import org.quartz.SchedulerException; |
| @@ -18,13 +21,11 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -18,13 +21,11 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
| 18 | import org.springframework.web.bind.annotation.RestController; | 21 | import org.springframework.web.bind.annotation.RestController; |
| 19 | import com.ruoyi.common.annotation.Log; | 22 | import com.ruoyi.common.annotation.Log; |
| 20 | import com.ruoyi.common.constant.Constants; | 23 | import com.ruoyi.common.constant.Constants; |
| 21 | -import com.ruoyi.common.core.controller.BaseController; | ||
| 22 | import com.ruoyi.common.core.domain.AjaxResult; | 24 | import com.ruoyi.common.core.domain.AjaxResult; |
| 23 | import com.ruoyi.common.core.page.TableDataInfo; | 25 | import com.ruoyi.common.core.page.TableDataInfo; |
| 24 | import com.ruoyi.common.enums.BusinessType; | 26 | import com.ruoyi.common.enums.BusinessType; |
| 25 | import com.ruoyi.common.exception.job.TaskException; | 27 | import com.ruoyi.common.exception.job.TaskException; |
| 26 | import com.ruoyi.common.utils.StringUtils; | 28 | import com.ruoyi.common.utils.StringUtils; |
| 27 | -import com.ruoyi.common.utils.poi.ExcelUtil; | ||
| 28 | import com.ruoyi.quartz.domain.SysJob; | 29 | import com.ruoyi.quartz.domain.SysJob; |
| 29 | import com.ruoyi.quartz.service.ISysJobService; | 30 | import com.ruoyi.quartz.service.ISysJobService; |
| 30 | import com.ruoyi.quartz.util.CronUtils; | 31 | import com.ruoyi.quartz.util.CronUtils; |
| @@ -109,7 +110,7 @@ public class SysJobController extends BaseController | @@ -109,7 +110,7 @@ public class SysJobController extends BaseController | ||
| 109 | { | 110 | { |
| 110 | return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规"); | 111 | return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规"); |
| 111 | } | 112 | } |
| 112 | - job.setCreateBy(getUsername()); | 113 | + job.setCreateBy(SecurityUtils.getUsername()); |
| 113 | return toAjax(jobService.insertJob(job)); | 114 | return toAjax(jobService.insertJob(job)); |
| 114 | } | 115 | } |
| 115 | 116 | ||
| @@ -142,7 +143,7 @@ public class SysJobController extends BaseController | @@ -142,7 +143,7 @@ public class SysJobController extends BaseController | ||
| 142 | { | 143 | { |
| 143 | return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规"); | 144 | return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规"); |
| 144 | } | 145 | } |
| 145 | - job.setUpdateBy(getUsername()); | 146 | + job.setUpdateBy(SecurityUtils.getUsername()); |
| 146 | return toAjax(jobService.updateJob(job)); | 147 | return toAjax(jobService.updateJob(job)); |
| 147 | } | 148 | } |
| 148 | 149 |
| @@ -3,6 +3,8 @@ package com.ruoyi.quartz.controller; | @@ -3,6 +3,8 @@ package com.ruoyi.quartz.controller; | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import javax.servlet.http.HttpServletResponse; | 4 | import javax.servlet.http.HttpServletResponse; |
| 5 | 5 | ||
| 6 | +import com.zhonglai.luhui.action.BaseController; | ||
| 7 | +import com.zhonglai.luhui.sys.utils.ExcelUtil; | ||
| 6 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
| 7 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -14,11 +16,9 @@ import org.springframework.web.bind.annotation.PostMapping; | @@ -14,11 +16,9 @@ import org.springframework.web.bind.annotation.PostMapping; | ||
| 14 | import org.springframework.web.bind.annotation.RequestMapping; | 16 | import org.springframework.web.bind.annotation.RequestMapping; |
| 15 | import org.springframework.web.bind.annotation.RestController; | 17 | import org.springframework.web.bind.annotation.RestController; |
| 16 | import com.ruoyi.common.annotation.Log; | 18 | import com.ruoyi.common.annotation.Log; |
| 17 | -import com.ruoyi.common.core.controller.BaseController; | ||
| 18 | import com.ruoyi.common.core.domain.AjaxResult; | 19 | import com.ruoyi.common.core.domain.AjaxResult; |
| 19 | import com.ruoyi.common.core.page.TableDataInfo; | 20 | import com.ruoyi.common.core.page.TableDataInfo; |
| 20 | import com.ruoyi.common.enums.BusinessType; | 21 | import com.ruoyi.common.enums.BusinessType; |
| 21 | -import com.ruoyi.common.utils.poi.ExcelUtil; | ||
| 22 | import com.ruoyi.quartz.domain.SysJobLog; | 22 | import com.ruoyi.quartz.domain.SysJobLog; |
| 23 | import com.ruoyi.quartz.service.ISysJobLogService; | 23 | import com.ruoyi.quartz.service.ISysJobLogService; |
| 24 | 24 |
| @@ -4,7 +4,7 @@ import java.util.Date; | @@ -4,7 +4,7 @@ import java.util.Date; | ||
| 4 | import javax.validation.constraints.NotBlank; | 4 | import javax.validation.constraints.NotBlank; |
| 5 | import javax.validation.constraints.Size; | 5 | import javax.validation.constraints.Size; |
| 6 | 6 | ||
| 7 | -import com.ruoyi.system.domain.tool.BaseEntity; | 7 | +import com.ruoyi.common.tool.BaseEntity; |
| 8 | import org.apache.commons.lang3.builder.ToStringBuilder; | 8 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 9 | import org.apache.commons.lang3.builder.ToStringStyle; | 9 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 10 | import com.fasterxml.jackson.annotation.JsonFormat; | 10 | import com.fasterxml.jackson.annotation.JsonFormat; |
| @@ -2,10 +2,10 @@ package com.ruoyi.quartz.domain; | @@ -2,10 +2,10 @@ package com.ruoyi.quartz.domain; | ||
| 2 | 2 | ||
| 3 | import java.util.Date; | 3 | import java.util.Date; |
| 4 | 4 | ||
| 5 | -import com.ruoyi.system.domain.tool.BaseEntity; | 5 | +import com.ruoyi.common.annotation.Excel; |
| 6 | +import com.ruoyi.common.tool.BaseEntity; | ||
| 6 | import org.apache.commons.lang3.builder.ToStringBuilder; | 7 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 7 | import org.apache.commons.lang3.builder.ToStringStyle; | 8 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 8 | -import com.ruoyi.common.annotation.Excel; | ||
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * 定时任务调度日志表 sys_job_log | 11 | * 定时任务调度日志表 sys_job_log |
lh-common/ruoyi-auth/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>ruoyi-auth</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | +</project> |
lh-common/ruoyi-common-core/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>ruoyi-common-core</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | +</project> |
lh-common/ruoyi-common-redis/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>ruoyi-common-redis</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | + <dependencies> | ||
| 21 | + <!-- redis 缓存操作 --> | ||
| 22 | + <dependency> | ||
| 23 | + <groupId>org.springframework.boot</groupId> | ||
| 24 | + <artifactId>spring-boot-starter-data-redis</artifactId> | ||
| 25 | + <exclusions> | ||
| 26 | + <exclusion> | ||
| 27 | + <groupId>io.lettuce</groupId> | ||
| 28 | + <artifactId>lettuce-core</artifactId> | ||
| 29 | + </exclusion> | ||
| 30 | + </exclusions> | ||
| 31 | + </dependency> | ||
| 32 | + <dependency> | ||
| 33 | + <groupId>redis.clients</groupId> | ||
| 34 | + <artifactId>jedis</artifactId> | ||
| 35 | + </dependency> | ||
| 36 | + | ||
| 37 | + <!-- RuoYi Common Core--> | ||
| 38 | + <dependency> | ||
| 39 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 40 | + <artifactId>ruoyi-common</artifactId> | ||
| 41 | + </dependency> | ||
| 42 | + </dependencies> | ||
| 43 | +</project> |
| 1 | -package com.ruoyi.framework.config; | 1 | +package com.zhonglai.luhui.redis.configure; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.parser.ParserConfig; | 3 | import com.alibaba.fastjson.parser.ParserConfig; |
| 4 | import com.fasterxml.jackson.annotation.JsonAutoDetect; | 4 | import com.fasterxml.jackson.annotation.JsonAutoDetect; |
lh-common/ruoyi-common-redis/src/main/java/com/zhonglai/luhui/redis/service/RedisCache.java
0 → 100644
| 1 | +package com.zhonglai.luhui.redis.service; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.data.redis.core.BoundSetOperations; | ||
| 6 | +import org.springframework.data.redis.core.HashOperations; | ||
| 7 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 8 | +import org.springframework.data.redis.core.ValueOperations; | ||
| 9 | +import org.springframework.data.redis.core.script.DefaultRedisScript; | ||
| 10 | +import org.springframework.data.redis.core.script.RedisScript; | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | + | ||
| 13 | +import java.time.Duration; | ||
| 14 | +import java.util.*; | ||
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * spring redis 工具类 | ||
| 19 | + * | ||
| 20 | + * @author ruoyi | ||
| 21 | + **/ | ||
| 22 | +@SuppressWarnings(value = { "unchecked", "rawtypes" }) | ||
| 23 | +@Component | ||
| 24 | +public class RedisCache | ||
| 25 | +{ | ||
| 26 | + @Autowired | ||
| 27 | + public RedisTemplate redisTemplate; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 缓存基本的对象,Integer、String、实体类等 | ||
| 31 | + * | ||
| 32 | + * @param key 缓存的键值 | ||
| 33 | + * @param value 缓存的值 | ||
| 34 | + */ | ||
| 35 | + public <T> void setCacheObject(final String key, final T value) | ||
| 36 | + { | ||
| 37 | + redisTemplate.opsForValue().set(key, value); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 缓存基本的对象,Integer、String、实体类等 | ||
| 42 | + * | ||
| 43 | + * @param key 缓存的键值 | ||
| 44 | + * @param value 缓存的值 | ||
| 45 | + * @param timeout 时间 | ||
| 46 | + * @param timeUnit 时间颗粒度 | ||
| 47 | + */ | ||
| 48 | + public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) | ||
| 49 | + { | ||
| 50 | + redisTemplate.opsForValue().set(key, value, timeout, timeUnit); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 设置有效时间 | ||
| 55 | + * | ||
| 56 | + * @param key Redis键 | ||
| 57 | + * @param timeout 超时时间 | ||
| 58 | + * @return true=设置成功;false=设置失败 | ||
| 59 | + */ | ||
| 60 | + public boolean expire(final String key, final long timeout) | ||
| 61 | + { | ||
| 62 | + return expire(key, timeout, TimeUnit.SECONDS); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 设置有效时间 | ||
| 67 | + * | ||
| 68 | + * @param key Redis键 | ||
| 69 | + * @param timeout 超时时间 | ||
| 70 | + * @param unit 时间单位 | ||
| 71 | + * @return true=设置成功;false=设置失败 | ||
| 72 | + */ | ||
| 73 | + public boolean expire(final String key, final long timeout, final TimeUnit unit) | ||
| 74 | + { | ||
| 75 | + return redisTemplate.expire(key, timeout, unit); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 获得缓存的基本对象。 | ||
| 80 | + * | ||
| 81 | + * @param key 缓存键值 | ||
| 82 | + * @return 缓存键值对应的数据 | ||
| 83 | + */ | ||
| 84 | + public <T> T getCacheObject(final String key) | ||
| 85 | + { | ||
| 86 | + ValueOperations<String, T> operation = redisTemplate.opsForValue(); | ||
| 87 | + return operation.get(key); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 删除单个对象 | ||
| 92 | + * | ||
| 93 | + * @param key | ||
| 94 | + */ | ||
| 95 | + public boolean deleteObject(final String key) | ||
| 96 | + { | ||
| 97 | + return redisTemplate.delete(key); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 删除集合对象 | ||
| 102 | + * | ||
| 103 | + * @param collection 多个对象 | ||
| 104 | + * @return | ||
| 105 | + */ | ||
| 106 | + public long deleteObject(final Collection collection) | ||
| 107 | + { | ||
| 108 | + return redisTemplate.delete(collection); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * 缓存List数据 | ||
| 113 | + * | ||
| 114 | + * @param key 缓存的键值 | ||
| 115 | + * @param dataList 待缓存的List数据 | ||
| 116 | + * @return 缓存的对象 | ||
| 117 | + */ | ||
| 118 | + public <T> long setCacheList(final String key, final List<T> dataList) | ||
| 119 | + { | ||
| 120 | + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); | ||
| 121 | + return count == null ? 0 : count; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * 获得缓存的list对象 | ||
| 126 | + * | ||
| 127 | + * @param key 缓存的键值 | ||
| 128 | + * @return 缓存键值对应的数据 | ||
| 129 | + */ | ||
| 130 | + public <T> List<T> getCacheList(final String key) | ||
| 131 | + { | ||
| 132 | + return redisTemplate.opsForList().range(key, 0, -1); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 缓存Set | ||
| 137 | + * | ||
| 138 | + * @param key 缓存键值 | ||
| 139 | + * @param dataSet 缓存的数据 | ||
| 140 | + * @return 缓存数据的对象 | ||
| 141 | + */ | ||
| 142 | + public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) | ||
| 143 | + { | ||
| 144 | + BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key); | ||
| 145 | + Iterator<T> it = dataSet.iterator(); | ||
| 146 | + while (it.hasNext()) | ||
| 147 | + { | ||
| 148 | + setOperation.add(it.next()); | ||
| 149 | + } | ||
| 150 | + return setOperation; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + /** | ||
| 154 | + * 获得缓存的set | ||
| 155 | + * | ||
| 156 | + * @param key | ||
| 157 | + * @return | ||
| 158 | + */ | ||
| 159 | + public <T> Set<T> getCacheSet(final String key) | ||
| 160 | + { | ||
| 161 | + return redisTemplate.opsForSet().members(key); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 缓存Map | ||
| 166 | + * | ||
| 167 | + * @param key | ||
| 168 | + * @param dataMap | ||
| 169 | + */ | ||
| 170 | + public <T> void setCacheMap(final String key, final Map<String, T> dataMap) | ||
| 171 | + { | ||
| 172 | + if (dataMap != null) { | ||
| 173 | + redisTemplate.opsForHash().putAll(key, dataMap); | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + /** | ||
| 178 | + * 获得缓存的Map | ||
| 179 | + * | ||
| 180 | + * @param key | ||
| 181 | + * @return | ||
| 182 | + */ | ||
| 183 | + public <T> Map<String, T> getCacheMap(final String key) | ||
| 184 | + { | ||
| 185 | + return redisTemplate.opsForHash().entries(key); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /** | ||
| 189 | + * 往Hash中存入数据 | ||
| 190 | + * | ||
| 191 | + * @param key Redis键 | ||
| 192 | + * @param hKey Hash键 | ||
| 193 | + * @param value 值 | ||
| 194 | + */ | ||
| 195 | + public <T> void setCacheMapValue(final String key, final String hKey, final T value) | ||
| 196 | + { | ||
| 197 | + redisTemplate.opsForHash().put(key, hKey, value); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + /** | ||
| 201 | + * 获取Hash中的数据 | ||
| 202 | + * | ||
| 203 | + * @param key Redis键 | ||
| 204 | + * @param hKey Hash键 | ||
| 205 | + * @return Hash中的对象 | ||
| 206 | + */ | ||
| 207 | + public <T> T getCacheMapValue(final String key, final String hKey) | ||
| 208 | + { | ||
| 209 | + HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash(); | ||
| 210 | + return opsForHash.get(key, hKey); | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * 删除Hash中的数据 | ||
| 215 | + * | ||
| 216 | + * @param key | ||
| 217 | + * @param hKey | ||
| 218 | + */ | ||
| 219 | + public void delCacheMapValue(final String key, final String... hKey) | ||
| 220 | + { | ||
| 221 | + HashOperations hashOperations = redisTemplate.opsForHash(); | ||
| 222 | + hashOperations.delete(key, hKey); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 获取多个Hash中的数据 | ||
| 227 | + * | ||
| 228 | + * @param key Redis键 | ||
| 229 | + * @param hKeys Hash键集合 | ||
| 230 | + * @return Hash对象集合 | ||
| 231 | + */ | ||
| 232 | + public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) | ||
| 233 | + { | ||
| 234 | + return redisTemplate.opsForHash().multiGet(key, hKeys); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + /** | ||
| 238 | + * 获得缓存的基本对象列表 | ||
| 239 | + * | ||
| 240 | + * @param pattern 字符串前缀 | ||
| 241 | + * @return 对象列表 | ||
| 242 | + */ | ||
| 243 | + public Collection<String> keys(final String pattern) | ||
| 244 | + { | ||
| 245 | + return redisTemplate.keys(pattern); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * | ||
| 250 | + * @param key | ||
| 251 | + * @return 判断key是否存在 | ||
| 252 | + */ | ||
| 253 | + public boolean hasKey(String key){ | ||
| 254 | + return redisTemplate.hasKey(key); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + public void hmset(String key,Object object){ | ||
| 258 | + String s = JSONObject.toJSONString(object); | ||
| 259 | + Map<String, String> map = JSONObject.parseObject(s,HashMap.class); | ||
| 260 | + setCacheMap(key, map); | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + //分布式锁过期时间 s 可以根据业务自己调节 | ||
| 264 | + private static final Long LOCK_REDIS_TIMEOUT = 10L; | ||
| 265 | + //分布式锁休眠 至 再次尝试获取 的等待时间 ms 可以根据业务自己调节 | ||
| 266 | + public static final Long LOCK_REDIS_WAIT = 500L; | ||
| 267 | + | ||
| 268 | + /** | ||
| 269 | + * 加锁 | ||
| 270 | + **/ | ||
| 271 | + public Boolean getLock(String key,String value){ | ||
| 272 | + Boolean lockStatus = this.redisTemplate.opsForValue().setIfAbsent(key,value, Duration.ofSeconds(LOCK_REDIS_TIMEOUT)); | ||
| 273 | + return lockStatus; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + /** | ||
| 277 | + * 释放锁 | ||
| 278 | + **/ | ||
| 279 | + public Long releaseLock(String key,String value){ | ||
| 280 | + String luaScript = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; | ||
| 281 | + RedisScript<Long> redisScript = new DefaultRedisScript<>(luaScript,Long.class); | ||
| 282 | + Long releaseStatus = (Long)this.redisTemplate.execute(redisScript, Collections.singletonList(key),value); | ||
| 283 | + return releaseStatus; | ||
| 284 | + } | ||
| 285 | +} |
lh-common/ruoyi-common-security/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>ruoyi-common-security</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | + <dependencies> | ||
| 21 | + | ||
| 22 | + <!-- spring security 安全认证 --> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.springframework.boot</groupId> | ||
| 25 | + <artifactId>spring-boot-starter-security</artifactId> | ||
| 26 | + </dependency> | ||
| 27 | + <dependency> | ||
| 28 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 29 | + <artifactId>ruoyi-common-redis</artifactId> | ||
| 30 | + </dependency> | ||
| 31 | + <dependency> | ||
| 32 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 33 | + <artifactId>lh-jar-sys-service</artifactId> | ||
| 34 | + </dependency> | ||
| 35 | + <!-- spring security 安全认证 --> | ||
| 36 | + <dependency> | ||
| 37 | + <groupId>org.springframework.boot</groupId> | ||
| 38 | + <artifactId>spring-boot-starter-security</artifactId> | ||
| 39 | + </dependency> | ||
| 40 | + </dependencies> | ||
| 41 | +</project> |
| 1 | -package com.ruoyi.framework.config; | 1 | +package com.zhonglai.luhui.security.config; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter; | ||
| 4 | -import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl; | ||
| 5 | -import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; | 3 | +import com.zhonglai.luhui.security.filter.JwtAuthenticationTokenFilter; |
| 4 | +import com.zhonglai.luhui.security.handle.AuthenticationEntryPointImpl; | ||
| 5 | +import com.zhonglai.luhui.security.handle.LogoutSuccessHandlerImpl; | ||
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.beans.factory.annotation.Value; | 7 | import org.springframework.beans.factory.annotation.Value; |
| 8 | import org.springframework.context.annotation.Bean; | 8 | import org.springframework.context.annotation.Bean; |
| 1 | +package com.zhonglai.luhui.security.config; | ||
| 2 | + | ||
| 3 | +import org.slf4j.Logger; | ||
| 4 | +import org.slf4j.LoggerFactory; | ||
| 5 | +import org.springframework.security.access.AccessDeniedException; | ||
| 6 | +import com.ruoyi.common.constant.HttpStatus; | ||
| 7 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 8 | +import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| 9 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| 10 | + | ||
| 11 | +import javax.servlet.http.HttpServletRequest; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 异常处理器 | ||
| 15 | + */ | ||
| 16 | +@RestControllerAdvice | ||
| 17 | +public class SecurityExceptionHandler { | ||
| 18 | + private static final Logger log = LoggerFactory.getLogger(SecurityExceptionHandler.class); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 权限校验异常 | ||
| 22 | + */ | ||
| 23 | + @ExceptionHandler(AccessDeniedException.class) | ||
| 24 | + public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) | ||
| 25 | + { | ||
| 26 | + String requestURI = request.getRequestURI(); | ||
| 27 | + log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage()); | ||
| 28 | + return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权"); | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package com.zhonglai.luhui.security.controller; | ||
| 2 | + | ||
| 3 | +import org.slf4j.Logger; | ||
| 4 | +import org.slf4j.LoggerFactory; | ||
| 5 | + | ||
| 6 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; | ||
| 7 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 8 | + | ||
| 9 | +public class LoginBaseController { | ||
| 10 | + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 11 | + /** | ||
| 12 | + * 获取用户缓存信息 | ||
| 13 | + */ | ||
| 14 | + public static BaseLoginUser getLoginUser() | ||
| 15 | + { | ||
| 16 | + return SecurityUtils.getLoginUser(); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 获取登录用户id | ||
| 21 | + */ | ||
| 22 | + public static Long getUserId() | ||
| 23 | + { | ||
| 24 | + return getLoginUser().getUserId(); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 获取登录用户名 | ||
| 30 | + */ | ||
| 31 | + public static String getUsername() | ||
| 32 | + { | ||
| 33 | + return getLoginUser().getUsername(); | ||
| 34 | + } | ||
| 35 | +} |
lh-common/ruoyi-common-security/src/main/java/com/zhonglai/luhui/security/domain/TreeEntity.java
0 → 100644
| 1 | +package com.zhonglai.luhui.security.domain; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.ruoyi.common.tool.BaseEntity; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Tree基类 | ||
| 11 | + * | ||
| 12 | + * @author ruoyi | ||
| 13 | + */ | ||
| 14 | +public class TreeEntity extends BaseEntity | ||
| 15 | +{ | ||
| 16 | + private static final long serialVersionUID = 1L; | ||
| 17 | + | ||
| 18 | + /** 父菜单名称 */ | ||
| 19 | + private String parentName; | ||
| 20 | + | ||
| 21 | + /** 父菜单ID */ | ||
| 22 | + private Long parentId; | ||
| 23 | + | ||
| 24 | + /** 显示顺序 */ | ||
| 25 | + private Integer orderNum; | ||
| 26 | + | ||
| 27 | + /** 祖级列表 */ | ||
| 28 | + private String ancestors; | ||
| 29 | + | ||
| 30 | + /** 子部门 */ | ||
| 31 | + private List<?> children = new ArrayList<>(); | ||
| 32 | + | ||
| 33 | + public String getParentName() | ||
| 34 | + { | ||
| 35 | + return parentName; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public void setParentName(String parentName) | ||
| 39 | + { | ||
| 40 | + this.parentName = parentName; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public Long getParentId() | ||
| 44 | + { | ||
| 45 | + return parentId; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setParentId(Long parentId) | ||
| 49 | + { | ||
| 50 | + this.parentId = parentId; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public Integer getOrderNum() | ||
| 54 | + { | ||
| 55 | + return orderNum; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void setOrderNum(Integer orderNum) | ||
| 59 | + { | ||
| 60 | + this.orderNum = orderNum; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getAncestors() | ||
| 64 | + { | ||
| 65 | + return ancestors; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setAncestors(String ancestors) | ||
| 69 | + { | ||
| 70 | + this.ancestors = ancestors; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public List<?> getChildren() | ||
| 74 | + { | ||
| 75 | + return children; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void setChildren(List<?> children) | ||
| 79 | + { | ||
| 80 | + this.children = children; | ||
| 81 | + } | ||
| 82 | +} |
lh-common/ruoyi-common-security/src/main/java/com/zhonglai/luhui/security/domain/TreeSelect.java
0 → 100644
| 1 | +package com.zhonglai.luhui.security.domain; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import com.ruoyi.system.domain.entity.SysDept; | ||
| 5 | +import com.ruoyi.system.domain.entity.SysMenu; | ||
| 6 | + | ||
| 7 | +import java.io.Serializable; | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.stream.Collectors; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Treeselect树结构实体类 | ||
| 13 | + * | ||
| 14 | + * @author ruoyi | ||
| 15 | + */ | ||
| 16 | +public class TreeSelect implements Serializable | ||
| 17 | +{ | ||
| 18 | + private static final long serialVersionUID = 1L; | ||
| 19 | + | ||
| 20 | + /** 节点ID */ | ||
| 21 | + private Long id; | ||
| 22 | + | ||
| 23 | + /** 节点名称 */ | ||
| 24 | + private String label; | ||
| 25 | + | ||
| 26 | + /** 子节点 */ | ||
| 27 | + @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| 28 | + private List<TreeSelect> children; | ||
| 29 | + | ||
| 30 | + public TreeSelect() | ||
| 31 | + { | ||
| 32 | + | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public TreeSelect(SysDept dept) | ||
| 36 | + { | ||
| 37 | + this.id = dept.getDeptId(); | ||
| 38 | + this.label = dept.getDeptName(); | ||
| 39 | + this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public TreeSelect(SysMenu menu) | ||
| 43 | + { | ||
| 44 | + this.id = menu.getMenuId(); | ||
| 45 | + this.label = menu.getMenuName(); | ||
| 46 | + this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public Long getId() | ||
| 50 | + { | ||
| 51 | + return id; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setId(Long id) | ||
| 55 | + { | ||
| 56 | + this.id = id; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public String getLabel() | ||
| 60 | + { | ||
| 61 | + return label; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setLabel(String label) | ||
| 65 | + { | ||
| 66 | + this.label = label; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public List<TreeSelect> getChildren() | ||
| 70 | + { | ||
| 71 | + return children; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setChildren(List<TreeSelect> children) | ||
| 75 | + { | ||
| 76 | + this.children = children; | ||
| 77 | + } | ||
| 78 | +} |
| 1 | -package com.ruoyi.system.login.dto; | 1 | +package com.zhonglai.luhui.security.dto; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | import com.ruoyi.common.utils.DESUtil; | 3 | import com.ruoyi.common.utils.DESUtil; |
| 5 | -import com.ruoyi.common.utils.SecurityUtils; | ||
| 6 | -import com.ruoyi.system.domain.tool.SysLogininforType; | 4 | +import com.ruoyi.common.tool.SysLogininforType; |
| 5 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 7 | import org.springframework.security.core.GrantedAuthority; | 6 | import org.springframework.security.core.GrantedAuthority; |
| 8 | 7 | ||
| 9 | import java.util.Collection; | 8 | import java.util.Collection; |
lh-common/ruoyi-common-security/src/main/java/com/zhonglai/luhui/security/dto/BaseLoginUser.java
0 → 100644
| 1 | +package com.zhonglai.luhui.security.dto; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.tool.SysLogininforType; | ||
| 4 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +public abstract class BaseLoginUser implements UserDetails { | ||
| 8 | + /** | ||
| 9 | + * 用户ID | ||
| 10 | + */ | ||
| 11 | + private Long userId; | ||
| 12 | + /** | ||
| 13 | + * 用户唯一标识 | ||
| 14 | + */ | ||
| 15 | + private String token; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 登录时间 | ||
| 19 | + */ | ||
| 20 | + private Long loginTime; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 过期时间 | ||
| 24 | + */ | ||
| 25 | + private Long expireTime; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 登录IP地址 | ||
| 29 | + */ | ||
| 30 | + private String ipaddr; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 登录地点 | ||
| 34 | + */ | ||
| 35 | + private String loginLocation; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 浏览器类型 | ||
| 39 | + */ | ||
| 40 | + private String browser; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 操作系统 | ||
| 44 | + */ | ||
| 45 | + private String os; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 浏览器类型 | ||
| 49 | + */ | ||
| 50 | + private SysLogininforType sysLogininforType; | ||
| 51 | + | ||
| 52 | + public Long getUserId() { | ||
| 53 | + return userId; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setUserId(Long userId) { | ||
| 57 | + this.userId = userId; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public String getToken() { | ||
| 61 | + return token; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setToken(String token) { | ||
| 65 | + this.token = token; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public Long getLoginTime() { | ||
| 69 | + return loginTime; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setLoginTime(Long loginTime) { | ||
| 73 | + this.loginTime = loginTime; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public Long getExpireTime() { | ||
| 77 | + return expireTime; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setExpireTime(Long expireTime) { | ||
| 81 | + this.expireTime = expireTime; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public String getIpaddr() { | ||
| 85 | + return ipaddr; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setIpaddr(String ipaddr) { | ||
| 89 | + this.ipaddr = ipaddr; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public String getLoginLocation() { | ||
| 93 | + return loginLocation; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setLoginLocation(String loginLocation) { | ||
| 97 | + this.loginLocation = loginLocation; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public String getBrowser() { | ||
| 101 | + return browser; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setBrowser(String browser) { | ||
| 105 | + this.browser = browser; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public String getOs() { | ||
| 109 | + return os; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setOs(String os) { | ||
| 113 | + this.os = os; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public abstract Object getUser(); | ||
| 117 | + | ||
| 118 | + public SysLogininforType getSysLogininforType() { | ||
| 119 | + return sysLogininforType; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public void setSysLogininforType(SysLogininforType sysLogininforType) { | ||
| 123 | + this.sysLogininforType = sysLogininforType; | ||
| 124 | + } | ||
| 125 | +} |
| 1 | -package com.ruoyi.system.login.dto; | 1 | +package com.zhonglai.luhui.security.dto; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | -import com.ruoyi.common.utils.SecurityUtils; | ||
| 5 | -import com.ruoyi.system.domain.tool.PublicSQLConfig; | ||
| 6 | -import com.ruoyi.system.domain.tool.SysLogininforType; | 3 | +import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | +import com.ruoyi.common.tool.SysLogininforType; | ||
| 5 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 7 | import org.springframework.security.core.GrantedAuthority; | 6 | import org.springframework.security.core.GrantedAuthority; |
| 8 | 7 | ||
| 9 | import java.util.Collection; | 8 | import java.util.Collection; |
| @@ -48,7 +47,7 @@ public class OpenAiLoginUser extends BaseLoginUser { | @@ -48,7 +47,7 @@ public class OpenAiLoginUser extends BaseLoginUser { | ||
| 48 | 47 | ||
| 49 | @Override | 48 | @Override |
| 50 | public String getPassword() { | 49 | public String getPassword() { |
| 51 | - return SecurityUtils.encryptPassword("123456"); | 50 | + return SecurityUtils.encryptPassword(openAiUserInfo.getPass()); |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | @Override | 53 | @Override |
| 1 | -package com.ruoyi.system.login.dto; | 1 | +package com.zhonglai.luhui.security.dto; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import com.ruoyi.system.domain.tool.PublicSQLConfig; | 4 | +import com.ruoyi.common.annotation.PublicSQLConfig; |
| 5 | 5 | ||
| 6 | import java.io.Serializable; | 6 | import java.io.Serializable; |
| 7 | import java.math.BigDecimal; | 7 | import java.math.BigDecimal; |
| @@ -28,10 +28,31 @@ public class OpenAiUserInfo implements Serializable { | @@ -28,10 +28,31 @@ public class OpenAiUserInfo implements Serializable { | ||
| 28 | private BigDecimal default_below_unitprice; //默认下级流量单价 | 28 | private BigDecimal default_below_unitprice; //默认下级流量单价 |
| 29 | private String promo_code; //推广码 | 29 | private String promo_code; //推广码 |
| 30 | 30 | ||
| 31 | + private String pass; | ||
| 32 | + | ||
| 33 | + private String token; | ||
| 34 | + private Integer token_endtime; | ||
| 35 | + | ||
| 31 | public String getPromo_code() { | 36 | public String getPromo_code() { |
| 32 | return promo_code; | 37 | return promo_code; |
| 33 | } | 38 | } |
| 34 | 39 | ||
| 40 | + public String getToken() { | ||
| 41 | + return token; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public void setToken(String token) { | ||
| 45 | + this.token = token; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public Integer getToken_endtime() { | ||
| 49 | + return token_endtime; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setToken_endtime(Integer token_endtime) { | ||
| 53 | + this.token_endtime = token_endtime; | ||
| 54 | + } | ||
| 55 | + | ||
| 35 | public void setPromo_code(String promo_code) { | 56 | public void setPromo_code(String promo_code) { |
| 36 | this.promo_code = promo_code; | 57 | this.promo_code = promo_code; |
| 37 | } | 58 | } |
| @@ -147,4 +168,12 @@ public class OpenAiUserInfo implements Serializable { | @@ -147,4 +168,12 @@ public class OpenAiUserInfo implements Serializable { | ||
| 147 | public void setFlow_packet_total(Integer flow_packet_total) { | 168 | public void setFlow_packet_total(Integer flow_packet_total) { |
| 148 | this.flow_packet_total = flow_packet_total; | 169 | this.flow_packet_total = flow_packet_total; |
| 149 | } | 170 | } |
| 171 | + | ||
| 172 | + public String getPass() { | ||
| 173 | + return pass; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public void setPass(String pass) { | ||
| 177 | + this.pass = pass; | ||
| 178 | + } | ||
| 150 | } | 179 | } |
| 1 | -package com.ruoyi.system.login.dto; | 1 | +package com.zhonglai.luhui.security.dto; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.annotation.JSONField; | 3 | import com.alibaba.fastjson.annotation.JSONField; |
| 4 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 5 | import com.ruoyi.system.domain.entity.SysUser; | 4 | import com.ruoyi.system.domain.entity.SysUser; |
| 6 | -import com.ruoyi.system.domain.tool.PublicSQLConfig; | ||
| 7 | -import com.ruoyi.system.domain.tool.SysLogininforType; | 5 | +import com.ruoyi.common.annotation.PublicSQLConfig; |
| 6 | +import com.ruoyi.common.tool.SysLogininforType; | ||
| 8 | import org.springframework.security.core.GrantedAuthority; | 7 | import org.springframework.security.core.GrantedAuthority; |
| 9 | 8 | ||
| 10 | import java.util.Collection; | 9 | import java.util.Collection; |
| 1 | -package com.ruoyi.framework.security.filter; | 1 | +package com.zhonglai.luhui.security.filter; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | -import com.ruoyi.common.utils.SecurityUtils; | ||
| 5 | import com.ruoyi.common.utils.StringUtils; | 3 | import com.ruoyi.common.utils.StringUtils; |
| 6 | -import com.ruoyi.system.login.service.TokenService; | 4 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; |
| 5 | +import com.zhonglai.luhui.security.service.TokenService; | ||
| 6 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| 9 | import org.springframework.security.core.context.SecurityContextHolder; | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
| 1 | -package com.ruoyi.framework.security.handle; | 1 | +package com.zhonglai.luhui.security.handle; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.ruoyi.common.constant.Constants; | 4 | import com.ruoyi.common.constant.Constants; |
| 5 | import com.ruoyi.common.constant.HttpStatus; | 5 | import com.ruoyi.common.constant.HttpStatus; |
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 8 | import com.ruoyi.common.utils.ServletUtils; | 7 | import com.ruoyi.common.utils.ServletUtils; |
| 9 | import com.ruoyi.common.utils.StringUtils; | 8 | import com.ruoyi.common.utils.StringUtils; |
| 10 | -import com.ruoyi.system.login.manager.AsyncManager; | ||
| 11 | -import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 12 | -import com.ruoyi.system.login.service.TokenService; | 9 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; |
| 10 | +import com.zhonglai.luhui.security.manager.AsyncManager; | ||
| 11 | +import com.zhonglai.luhui.security.manager.factory.AsyncFactory; | ||
| 12 | +import com.zhonglai.luhui.security.service.TokenService; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.context.annotation.Configuration; | 14 | import org.springframework.context.annotation.Configuration; |
| 15 | import org.springframework.security.core.Authentication; | 15 | import org.springframework.security.core.Authentication; |
| 1 | -package com.ruoyi.system.login.manager.factory; | 1 | +package com.zhonglai.luhui.security.manager.factory; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.constant.Constants; | 3 | import com.ruoyi.common.constant.Constants; |
| 4 | import com.ruoyi.common.utils.LogUtils; | 4 | import com.ruoyi.common.utils.LogUtils; |
| @@ -7,11 +7,11 @@ import com.ruoyi.common.utils.StringUtils; | @@ -7,11 +7,11 @@ import com.ruoyi.common.utils.StringUtils; | ||
| 7 | import com.ruoyi.common.utils.ip.AddressUtils; | 7 | import com.ruoyi.common.utils.ip.AddressUtils; |
| 8 | import com.ruoyi.common.utils.ip.IpUtils; | 8 | import com.ruoyi.common.utils.ip.IpUtils; |
| 9 | import com.ruoyi.common.utils.spring.SpringUtils; | 9 | import com.ruoyi.common.utils.spring.SpringUtils; |
| 10 | -import com.ruoyi.system.domain.SysLogininfor; | ||
| 11 | -import com.ruoyi.system.domain.SysOperLog; | ||
| 12 | -import com.ruoyi.system.domain.tool.SysLogininforType; | ||
| 13 | -import com.ruoyi.system.service.ISysLogininforService; | ||
| 14 | -import com.ruoyi.system.service.ISysOperLogService; | 10 | +import com.ruoyi.system.domain.sys.SysLogininfor; |
| 11 | +import com.ruoyi.system.domain.sys.SysOperLog; | ||
| 12 | +import com.ruoyi.common.tool.SysLogininforType; | ||
| 13 | +import com.zhonglai.luhui.sys.service.ISysLogininforService; | ||
| 14 | +import com.zhonglai.luhui.sys.service.ISysOperLogService; | ||
| 15 | import eu.bitwalker.useragentutils.UserAgent; | 15 | import eu.bitwalker.useragentutils.UserAgent; |
| 16 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 17 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 1 | -package com.ruoyi.framework.web.service; | 1 | +package com.zhonglai.luhui.security.service; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 4 | -import com.ruoyi.system.domain.SysUserOnline; | 3 | +import com.ruoyi.system.domain.sys.SysUserOnline; |
| 4 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; | ||
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | * 在线用户 服务层 | 7 | * 在线用户 服务层 |
| 1 | -package com.ruoyi.system.login.service; | 1 | +package com.zhonglai.luhui.security.service; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.constant.Constants; | 3 | import com.ruoyi.common.constant.Constants; |
| 4 | -import com.ruoyi.common.core.redis.RedisCache; | ||
| 5 | import com.ruoyi.common.exception.ServiceException; | 4 | import com.ruoyi.common.exception.ServiceException; |
| 6 | import com.ruoyi.common.exception.user.CaptchaException; | 5 | import com.ruoyi.common.exception.user.CaptchaException; |
| 7 | import com.ruoyi.common.exception.user.CaptchaExpireException; | 6 | import com.ruoyi.common.exception.user.CaptchaExpireException; |
| @@ -9,12 +8,12 @@ import com.ruoyi.common.exception.user.UserPasswordNotMatchException; | @@ -9,12 +8,12 @@ import com.ruoyi.common.exception.user.UserPasswordNotMatchException; | ||
| 9 | import com.ruoyi.common.utils.*; | 8 | import com.ruoyi.common.utils.*; |
| 10 | import com.ruoyi.common.utils.ip.IpUtils; | 9 | import com.ruoyi.common.utils.ip.IpUtils; |
| 11 | import com.ruoyi.system.domain.entity.SysUser; | 10 | import com.ruoyi.system.domain.entity.SysUser; |
| 12 | -import com.ruoyi.system.domain.tool.SysLogininforType; | ||
| 13 | -import com.ruoyi.system.login.dto.*; | ||
| 14 | -import com.ruoyi.system.login.manager.AsyncManager; | ||
| 15 | -import com.ruoyi.system.login.manager.factory.AsyncFactory; | ||
| 16 | -import com.ruoyi.system.service.ISysUserService; | ||
| 17 | -import com.ruoyi.system.service.PublicService; | 11 | +import com.ruoyi.common.tool.SysLogininforType; |
| 12 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 13 | +import com.zhonglai.luhui.redis.service.RedisCache; | ||
| 14 | +import com.zhonglai.luhui.security.dto.*; | ||
| 15 | +import com.zhonglai.luhui.security.manager.AsyncManager; | ||
| 16 | +import com.zhonglai.luhui.security.manager.factory.AsyncFactory; | ||
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.security.authentication.AuthenticationManager; | 18 | import org.springframework.security.authentication.AuthenticationManager; |
| 20 | import org.springframework.security.authentication.BadCredentialsException; | 19 | import org.springframework.security.authentication.BadCredentialsException; |
| @@ -39,9 +38,6 @@ public class LoginService { | @@ -39,9 +38,6 @@ public class LoginService { | ||
| 39 | private AuthenticationManager authenticationManager; | 38 | private AuthenticationManager authenticationManager; |
| 40 | 39 | ||
| 41 | @Autowired | 40 | @Autowired |
| 42 | - private ISysUserService userService; | ||
| 43 | - | ||
| 44 | - @Autowired | ||
| 45 | private TokenService tokenService; | 41 | private TokenService tokenService; |
| 46 | 42 | ||
| 47 | /** | 43 | /** |
| @@ -131,7 +127,7 @@ public class LoginService { | @@ -131,7 +127,7 @@ public class LoginService { | ||
| 131 | sysUser.setUserId(userId); | 127 | sysUser.setUserId(userId); |
| 132 | sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); | 128 | sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); |
| 133 | sysUser.setLoginDate(DateUtils.getNowDate()); | 129 | sysUser.setLoginDate(DateUtils.getNowDate()); |
| 134 | - userService.updateUserProfile(sysUser); | 130 | + publicService.updateObject(sysUser,"user_id"); |
| 135 | } | 131 | } |
| 136 | 132 | ||
| 137 | /** | 133 | /** |
| 1 | +package com.zhonglai.luhui.security.service; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.exception.ServiceException; | ||
| 4 | +import com.ruoyi.common.utils.StringUtils; | ||
| 5 | +import com.ruoyi.common.utils.bean.BeanValidators; | ||
| 6 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 7 | +import com.ruoyi.system.domain.entity.SysDept; | ||
| 8 | +import com.ruoyi.system.domain.entity.SysMenu; | ||
| 9 | +import com.ruoyi.system.domain.entity.SysRole; | ||
| 10 | +import com.ruoyi.system.domain.entity.SysUser; | ||
| 11 | +import com.zhonglai.luhui.security.domain.TreeSelect; | ||
| 12 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 13 | +import com.zhonglai.luhui.sys.mapper.*; | ||
| 14 | +import com.zhonglai.luhui.sys.service.*; | ||
| 15 | +import com.zhonglai.luhui.sys.service.impl.SysUserServiceImpl; | ||
| 16 | +import org.slf4j.Logger; | ||
| 17 | +import org.slf4j.LoggerFactory; | ||
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | +import org.springframework.stereotype.Service; | ||
| 20 | +import org.springframework.transaction.annotation.Transactional; | ||
| 21 | + | ||
| 22 | +import javax.validation.Validator; | ||
| 23 | +import java.util.List; | ||
| 24 | +import java.util.stream.Collectors; | ||
| 25 | + | ||
| 26 | +@Service | ||
| 27 | +public class SecurityService { | ||
| 28 | + private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); | ||
| 29 | + | ||
| 30 | + @Autowired | ||
| 31 | + private ISysRoleService sysRoleService; | ||
| 32 | + | ||
| 33 | + @Autowired | ||
| 34 | + private SysRoleMenuMapper roleMenuMapper; | ||
| 35 | + | ||
| 36 | + @Autowired | ||
| 37 | + private SysRoleDeptMapper roleDeptMapper; | ||
| 38 | + | ||
| 39 | + @Autowired | ||
| 40 | + private SysRoleMapper roleMapper; | ||
| 41 | + | ||
| 42 | + @Autowired | ||
| 43 | + private ISysDeptService sysDeptService; | ||
| 44 | + | ||
| 45 | + @Autowired | ||
| 46 | + private ISysMenuService sysMenuService; | ||
| 47 | + | ||
| 48 | + @Autowired | ||
| 49 | + private SysMenuMapper menuMapper; | ||
| 50 | + | ||
| 51 | + @Autowired | ||
| 52 | + private ISysUserService sysUserService; | ||
| 53 | + | ||
| 54 | + @Autowired | ||
| 55 | + private ISysConfigService configService; | ||
| 56 | + | ||
| 57 | + @Autowired | ||
| 58 | + private SysUserMapper userMapper; | ||
| 59 | + | ||
| 60 | + @Autowired | ||
| 61 | + protected Validator validator; | ||
| 62 | + | ||
| 63 | + @Autowired | ||
| 64 | + private SysUserRoleMapper userRoleMapper; | ||
| 65 | + | ||
| 66 | + @Autowired | ||
| 67 | + private SysUserPostMapper userPostMapper; | ||
| 68 | + /** | ||
| 69 | + * 校验角色是否有数据权限 | ||
| 70 | + * | ||
| 71 | + * @param roleId 角色id | ||
| 72 | + */ | ||
| 73 | + public void checkRoleDataScope(Long roleId) | ||
| 74 | + { | ||
| 75 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 76 | + { | ||
| 77 | + SysRole role = new SysRole(); | ||
| 78 | + role.setRoleId(roleId); | ||
| 79 | + List<SysRole> roles = SpringUtils.getAopProxy(sysRoleService).selectRoleList(role); | ||
| 80 | + if (StringUtils.isEmpty(roles)) | ||
| 81 | + { | ||
| 82 | + throw new ServiceException("没有权限访问角色数据!"); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 批量删除角色信息 | ||
| 89 | + * | ||
| 90 | + * @param roleIds 需要删除的角色ID | ||
| 91 | + * @return 结果 | ||
| 92 | + */ | ||
| 93 | + @Transactional | ||
| 94 | + public int deleteRoleByIds(Long[] roleIds) | ||
| 95 | + { | ||
| 96 | + for (Long roleId : roleIds) | ||
| 97 | + { | ||
| 98 | + sysRoleService.checkRoleAllowed(new SysRole(roleId)); | ||
| 99 | + checkRoleDataScope(roleId); | ||
| 100 | + SysRole role = sysRoleService.selectRoleById(roleId); | ||
| 101 | + if (sysRoleService.countUserRoleByRoleId(roleId) > 0) | ||
| 102 | + { | ||
| 103 | + throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + // 删除角色与菜单关联 | ||
| 107 | + roleMenuMapper.deleteRoleMenu(roleIds); | ||
| 108 | + // 删除角色与部门关联 | ||
| 109 | + roleDeptMapper.deleteRoleDept(roleIds); | ||
| 110 | + return roleMapper.deleteRoleByIds(roleIds); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * 构建前端所需要下拉树结构 | ||
| 115 | + * | ||
| 116 | + * @param depts 部门列表 | ||
| 117 | + * @return 下拉树结构列表 | ||
| 118 | + */ | ||
| 119 | + public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts) | ||
| 120 | + { | ||
| 121 | + List<SysDept> deptTrees = sysDeptService.buildDeptTree(depts); | ||
| 122 | + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * 校验部门是否有数据权限 | ||
| 127 | + * | ||
| 128 | + * @param deptId 部门id | ||
| 129 | + */ | ||
| 130 | + public void checkDeptDataScope(Long deptId) | ||
| 131 | + { | ||
| 132 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 133 | + { | ||
| 134 | + SysDept dept = new SysDept(); | ||
| 135 | + dept.setDeptId(deptId); | ||
| 136 | + List<SysDept> depts = SpringUtils.getAopProxy(sysDeptService).selectDeptList(dept); | ||
| 137 | + if (StringUtils.isEmpty(depts)) | ||
| 138 | + { | ||
| 139 | + throw new ServiceException("没有权限访问部门数据!"); | ||
| 140 | + } | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * 构建前端所需要下拉树结构 | ||
| 146 | + * | ||
| 147 | + * @param menus 菜单列表 | ||
| 148 | + * @return 下拉树结构列表 | ||
| 149 | + */ | ||
| 150 | + public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) | ||
| 151 | + { | ||
| 152 | + List<SysMenu> menuTrees = sysMenuService.buildMenuTree(menus); | ||
| 153 | + return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 根据用户ID查询菜单 | ||
| 158 | + * | ||
| 159 | + * @param userId 用户名称 | ||
| 160 | + * @return 菜单列表 | ||
| 161 | + */ | ||
| 162 | + public List<SysMenu> selectMenuTreeByUserId(Long userId) | ||
| 163 | + { | ||
| 164 | + List<SysMenu> menus = null; | ||
| 165 | + if (SecurityUtils.isAdmin(userId)) | ||
| 166 | + { | ||
| 167 | + menus = menuMapper.selectMenuTreeAll(); | ||
| 168 | + } | ||
| 169 | + else | ||
| 170 | + { | ||
| 171 | + menus = menuMapper.selectMenuTreeByUserId(userId); | ||
| 172 | + } | ||
| 173 | + return sysMenuService.getChildPerms(menus, 0); | ||
| 174 | + } | ||
| 175 | + /** | ||
| 176 | + * 校验用户是否有数据权限 | ||
| 177 | + * | ||
| 178 | + * @param userId 用户id | ||
| 179 | + */ | ||
| 180 | + public void checkUserDataScope(Long userId) | ||
| 181 | + { | ||
| 182 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 183 | + { | ||
| 184 | + SysUser user = new SysUser(); | ||
| 185 | + user.setUserId(userId); | ||
| 186 | + List<SysUser> users = SpringUtils.getAopProxy(sysUserService).selectUserList(user); | ||
| 187 | + if (StringUtils.isEmpty(users)) | ||
| 188 | + { | ||
| 189 | + throw new ServiceException("没有权限访问用户数据!"); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * 批量删除用户信息 | ||
| 196 | + * | ||
| 197 | + * @param userIds 需要删除的用户ID | ||
| 198 | + * @return 结果 | ||
| 199 | + */ | ||
| 200 | + @Transactional | ||
| 201 | + public int deleteUserByIds(Long[] userIds) | ||
| 202 | + { | ||
| 203 | + for (Long userId : userIds) | ||
| 204 | + { | ||
| 205 | + sysUserService.checkUserAllowed(new SysUser(userId)); | ||
| 206 | + checkUserDataScope(userId); | ||
| 207 | + } | ||
| 208 | + // 删除用户与角色关联 | ||
| 209 | + userRoleMapper.deleteUserRole(userIds); | ||
| 210 | + // 删除用户与岗位关联 | ||
| 211 | + userPostMapper.deleteUserPost(userIds); | ||
| 212 | + return userMapper.deleteUserByIds(userIds); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + | ||
| 216 | + /** | ||
| 217 | + * 导入用户数据 | ||
| 218 | + * | ||
| 219 | + * @param userList 用户数据列表 | ||
| 220 | + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 | ||
| 221 | + * @param operName 操作用户 | ||
| 222 | + * @return 结果 | ||
| 223 | + */ | ||
| 224 | + public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) | ||
| 225 | + { | ||
| 226 | + if (StringUtils.isNull(userList) || userList.size() == 0) | ||
| 227 | + { | ||
| 228 | + throw new ServiceException("导入用户数据不能为空!"); | ||
| 229 | + } | ||
| 230 | + int successNum = 0; | ||
| 231 | + int failureNum = 0; | ||
| 232 | + StringBuilder successMsg = new StringBuilder(); | ||
| 233 | + StringBuilder failureMsg = new StringBuilder(); | ||
| 234 | + String password = configService.selectConfigByKey("sys.user.initPassword"); | ||
| 235 | + for (SysUser user : userList) | ||
| 236 | + { | ||
| 237 | + try | ||
| 238 | + { | ||
| 239 | + // 验证是否存在这个用户 | ||
| 240 | + SysUser u = userMapper.selectUserByUserName(user.getUserName()); | ||
| 241 | + if (StringUtils.isNull(u)) | ||
| 242 | + { | ||
| 243 | + BeanValidators.validateWithException(validator, user); | ||
| 244 | + user.setPassword(SecurityUtils.encryptPassword(password)); | ||
| 245 | + user.setCreateBy(operName); | ||
| 246 | + sysUserService.insertUser(user); | ||
| 247 | + successNum++; | ||
| 248 | + successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功"); | ||
| 249 | + } | ||
| 250 | + else if (isUpdateSupport) | ||
| 251 | + { | ||
| 252 | + BeanValidators.validateWithException(validator, user); | ||
| 253 | + user.setUpdateBy(operName); | ||
| 254 | + sysUserService.updateUser(user); | ||
| 255 | + successNum++; | ||
| 256 | + successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功"); | ||
| 257 | + } | ||
| 258 | + else | ||
| 259 | + { | ||
| 260 | + failureNum++; | ||
| 261 | + failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在"); | ||
| 262 | + } | ||
| 263 | + } | ||
| 264 | + catch (Exception e) | ||
| 265 | + { | ||
| 266 | + failureNum++; | ||
| 267 | + String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:"; | ||
| 268 | + failureMsg.append(msg + e.getMessage()); | ||
| 269 | + log.error(msg, e); | ||
| 270 | + } | ||
| 271 | + } | ||
| 272 | + if (failureNum > 0) | ||
| 273 | + { | ||
| 274 | + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); | ||
| 275 | + throw new ServiceException(failureMsg.toString()); | ||
| 276 | + } | ||
| 277 | + else | ||
| 278 | + { | ||
| 279 | + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); | ||
| 280 | + } | ||
| 281 | + return successMsg.toString(); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | +} |
| 1 | -package com.ruoyi.system.login.service; | 1 | +package com.zhonglai.luhui.security.service; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.constant.Constants; | 3 | import com.ruoyi.common.constant.Constants; |
| 4 | -import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 5 | -import com.ruoyi.common.core.redis.RedisCache; | ||
| 6 | import com.ruoyi.common.utils.ServletUtils; | 4 | import com.ruoyi.common.utils.ServletUtils; |
| 7 | import com.ruoyi.common.utils.StringUtils; | 5 | import com.ruoyi.common.utils.StringUtils; |
| 8 | import com.ruoyi.common.utils.ip.AddressUtils; | 6 | import com.ruoyi.common.utils.ip.AddressUtils; |
| 9 | import com.ruoyi.common.utils.ip.IpUtils; | 7 | import com.ruoyi.common.utils.ip.IpUtils; |
| 10 | import com.ruoyi.common.utils.uuid.IdUtils; | 8 | import com.ruoyi.common.utils.uuid.IdUtils; |
| 9 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; | ||
| 10 | +import com.zhonglai.luhui.redis.service.RedisCache; | ||
| 11 | import eu.bitwalker.useragentutils.UserAgent; | 11 | import eu.bitwalker.useragentutils.UserAgent; |
| 12 | import io.jsonwebtoken.Claims; | 12 | import io.jsonwebtoken.Claims; |
| 13 | import io.jsonwebtoken.Jwts; | 13 | import io.jsonwebtoken.Jwts; |
lh-common/ruoyi-common-security/src/main/java/com/zhonglai/luhui/security/utils/SecurityUtils.java
0 → 100644
| 1 | +package com.zhonglai.luhui.security.utils; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.constant.HttpStatus; | ||
| 4 | +import com.ruoyi.common.exception.ServiceException; | ||
| 5 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; | ||
| 6 | +import org.springframework.security.core.Authentication; | ||
| 7 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 8 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 安全服务工具类 | ||
| 12 | + * | ||
| 13 | + * @author ruoyi | ||
| 14 | + */ | ||
| 15 | +public class SecurityUtils | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * 用户ID | ||
| 19 | + **/ | ||
| 20 | + public static Long getUserId() | ||
| 21 | + { | ||
| 22 | + try | ||
| 23 | + { | ||
| 24 | + return getLoginUser().getUserId(); | ||
| 25 | + } | ||
| 26 | + catch (Exception e) | ||
| 27 | + { | ||
| 28 | + throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED); | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 获取用户账户 | ||
| 34 | + **/ | ||
| 35 | + public static String getUsername() | ||
| 36 | + { | ||
| 37 | + try | ||
| 38 | + { | ||
| 39 | + return getLoginUser().getUsername(); | ||
| 40 | + } | ||
| 41 | + catch (Exception e) | ||
| 42 | + { | ||
| 43 | + throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 获取用户 | ||
| 49 | + **/ | ||
| 50 | + public static BaseLoginUser getLoginUser() | ||
| 51 | + { | ||
| 52 | + try | ||
| 53 | + { | ||
| 54 | + return (BaseLoginUser) getAuthentication().getPrincipal(); | ||
| 55 | + } | ||
| 56 | + catch (Exception e) | ||
| 57 | + { | ||
| 58 | + throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 获取Authentication | ||
| 64 | + */ | ||
| 65 | + public static Authentication getAuthentication() | ||
| 66 | + { | ||
| 67 | + return SecurityContextHolder.getContext().getAuthentication(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 生成BCryptPasswordEncoder密码 | ||
| 72 | + * | ||
| 73 | + * @param password 密码 | ||
| 74 | + * @return 加密字符串 | ||
| 75 | + */ | ||
| 76 | + public static String encryptPassword(String password) | ||
| 77 | + { | ||
| 78 | + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); | ||
| 79 | + return passwordEncoder.encode(password); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 判断密码是否相同 | ||
| 84 | + * | ||
| 85 | + * @param rawPassword 真实密码 | ||
| 86 | + * @param encodedPassword 加密后字符 | ||
| 87 | + * @return 结果 | ||
| 88 | + */ | ||
| 89 | + public static boolean matchesPassword(String rawPassword, String encodedPassword) | ||
| 90 | + { | ||
| 91 | + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); | ||
| 92 | + return passwordEncoder.matches(rawPassword, encodedPassword); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 是否为管理员 | ||
| 97 | + * | ||
| 98 | + * @param userId 用户ID | ||
| 99 | + * @return 结果 | ||
| 100 | + */ | ||
| 101 | + public static boolean isAdmin(Long userId) | ||
| 102 | + { | ||
| 103 | + return userId != null && 1L == userId; | ||
| 104 | + } | ||
| 105 | +} |
lh-common/ruoyi-common/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <parent> | ||
| 6 | + <artifactId>lh-common</artifactId> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <version>1.0-SNAPSHOT</version> | ||
| 9 | + </parent> | ||
| 10 | + <modelVersion>4.0.0</modelVersion> | ||
| 11 | + | ||
| 12 | + <artifactId>ruoyi-common</artifactId> | ||
| 13 | + | ||
| 14 | + <description> | ||
| 15 | + common通用工具 | ||
| 16 | + </description> | ||
| 17 | + | ||
| 18 | + <dependencies> | ||
| 19 | + | ||
| 20 | + <!-- Spring框架基本的核心工具 --> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>org.springframework</groupId> | ||
| 23 | + <artifactId>spring-context-support</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + | ||
| 26 | + <!-- SpringWeb模块 --> | ||
| 27 | + <dependency> | ||
| 28 | + <groupId>org.springframework</groupId> | ||
| 29 | + <artifactId>spring-web</artifactId> | ||
| 30 | + </dependency> | ||
| 31 | + | ||
| 32 | + <!-- pagehelper 分页插件 --> | ||
| 33 | + <dependency> | ||
| 34 | + <groupId>com.github.pagehelper</groupId> | ||
| 35 | + <artifactId>pagehelper-spring-boot-starter</artifactId> | ||
| 36 | + </dependency> | ||
| 37 | + | ||
| 38 | + <!-- 自定义验证注解 --> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.springframework.boot</groupId> | ||
| 41 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + | ||
| 44 | + <!--常用工具类 --> | ||
| 45 | + <dependency> | ||
| 46 | + <groupId>org.apache.commons</groupId> | ||
| 47 | + <artifactId>commons-lang3</artifactId> | ||
| 48 | + </dependency> | ||
| 49 | + | ||
| 50 | + <!-- JSON工具类 --> | ||
| 51 | + <dependency> | ||
| 52 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
| 53 | + <artifactId>jackson-databind</artifactId> | ||
| 54 | + </dependency> | ||
| 55 | + | ||
| 56 | + <!-- 阿里JSON解析器 --> | ||
| 57 | + <dependency> | ||
| 58 | + <groupId>com.alibaba</groupId> | ||
| 59 | + <artifactId>fastjson</artifactId> | ||
| 60 | + </dependency> | ||
| 61 | + | ||
| 62 | + <!-- io常用工具类 --> | ||
| 63 | + <dependency> | ||
| 64 | + <groupId>commons-io</groupId> | ||
| 65 | + <artifactId>commons-io</artifactId> | ||
| 66 | + </dependency> | ||
| 67 | + | ||
| 68 | + <!-- 文件上传工具类 --> | ||
| 69 | + <dependency> | ||
| 70 | + <groupId>commons-fileupload</groupId> | ||
| 71 | + <artifactId>commons-fileupload</artifactId> | ||
| 72 | + </dependency> | ||
| 73 | + | ||
| 74 | + <!-- excel工具 --> | ||
| 75 | + <dependency> | ||
| 76 | + <groupId>org.apache.poi</groupId> | ||
| 77 | + <artifactId>poi-ooxml</artifactId> | ||
| 78 | + </dependency> | ||
| 79 | + | ||
| 80 | + <!-- yml解析器 --> | ||
| 81 | + <dependency> | ||
| 82 | + <groupId>org.yaml</groupId> | ||
| 83 | + <artifactId>snakeyaml</artifactId> | ||
| 84 | + </dependency> | ||
| 85 | + | ||
| 86 | + <!-- Token生成与解析--> | ||
| 87 | + <dependency> | ||
| 88 | + <groupId>io.jsonwebtoken</groupId> | ||
| 89 | + <artifactId>jjwt</artifactId> | ||
| 90 | + </dependency> | ||
| 91 | + | ||
| 92 | + <!-- Jaxb --> | ||
| 93 | + <dependency> | ||
| 94 | + <groupId>javax.xml.bind</groupId> | ||
| 95 | + <artifactId>jaxb-api</artifactId> | ||
| 96 | + </dependency> | ||
| 97 | + | ||
| 98 | + <!-- pool 对象池 --> | ||
| 99 | + <dependency> | ||
| 100 | + <groupId>org.apache.commons</groupId> | ||
| 101 | + <artifactId>commons-pool2</artifactId> | ||
| 102 | + </dependency> | ||
| 103 | + | ||
| 104 | + <!-- 解析客户端操作系统、浏览器等 --> | ||
| 105 | + <dependency> | ||
| 106 | + <groupId>eu.bitwalker</groupId> | ||
| 107 | + <artifactId>UserAgentUtils</artifactId> | ||
| 108 | + </dependency> | ||
| 109 | + | ||
| 110 | + <!-- servlet包 --> | ||
| 111 | + <dependency> | ||
| 112 | + <groupId>javax.servlet</groupId> | ||
| 113 | + <artifactId>javax.servlet-api</artifactId> | ||
| 114 | + </dependency> | ||
| 115 | + | ||
| 116 | + <dependency> | ||
| 117 | + <groupId>com.google.guava</groupId> | ||
| 118 | + <artifactId>guava</artifactId> | ||
| 119 | + <version>20.0</version> | ||
| 120 | + </dependency> | ||
| 121 | + | ||
| 122 | + <!-- 支持data --> | ||
| 123 | + <dependency> | ||
| 124 | + <groupId>org.projectlombok</groupId> | ||
| 125 | + <artifactId>lombok</artifactId> | ||
| 126 | + </dependency> | ||
| 127 | + | ||
| 128 | + <dependency> | ||
| 129 | + <groupId>org.apache.commons</groupId> | ||
| 130 | + <artifactId>commons-text</artifactId> | ||
| 131 | + </dependency> | ||
| 132 | + | ||
| 133 | + <dependency> | ||
| 134 | + <groupId>com.google.zxing</groupId> | ||
| 135 | + <artifactId>javase</artifactId> | ||
| 136 | + </dependency> | ||
| 137 | + <dependency> | ||
| 138 | + <groupId>com.google.zxing</groupId> | ||
| 139 | + <artifactId>core</artifactId> | ||
| 140 | + </dependency> | ||
| 141 | + | ||
| 142 | + <dependency> | ||
| 143 | + <groupId>com.squareup.okhttp3</groupId> | ||
| 144 | + <artifactId>okhttp</artifactId> | ||
| 145 | + </dependency> | ||
| 146 | + | ||
| 147 | + <!-- 自定义验证注解 --> | ||
| 148 | + <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation --> | ||
| 149 | + <dependency> | ||
| 150 | + <groupId>org.springframework.boot</groupId> | ||
| 151 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 152 | + </dependency> | ||
| 153 | + | ||
| 154 | + <dependency> | ||
| 155 | + <groupId>org.jboss.logging</groupId> | ||
| 156 | + <artifactId>jboss-logging</artifactId> | ||
| 157 | + <version>3.4.3.Final</version> | ||
| 158 | + </dependency> | ||
| 159 | + <dependency> | ||
| 160 | + <groupId>jakarta.validation</groupId> | ||
| 161 | + <artifactId>jakarta.validation-api</artifactId> | ||
| 162 | + <version>2.0.2</version> | ||
| 163 | + </dependency> | ||
| 164 | + | ||
| 165 | + <dependency> | ||
| 166 | + <groupId>com.google.code.gson</groupId> | ||
| 167 | + <artifactId>gson</artifactId> | ||
| 168 | + </dependency> | ||
| 169 | + | ||
| 170 | + <dependency> | ||
| 171 | + <groupId>org.springframework.data</groupId> | ||
| 172 | + <artifactId>spring-data-commons</artifactId> | ||
| 173 | + </dependency> | ||
| 174 | + </dependencies> | ||
| 175 | +</project> |
| 1 | +package com.ruoyi.common.annotation; | ||
| 2 | + | ||
| 3 | +import java.lang.annotation.*; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 数据权限过滤注解 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +@Target(ElementType.METHOD) | ||
| 11 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 12 | +@Documented | ||
| 13 | +public @interface DataScope | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * 部门表的别名 | ||
| 17 | + */ | ||
| 18 | + public String deptAlias() default ""; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 用户表的别名 | ||
| 22 | + */ | ||
| 23 | + public String userAlias() default ""; | ||
| 24 | +} |
| 1 | -package com.ruoyi.system.domain.tool; | 1 | +package com.ruoyi.common.annotation; |
| 2 | + | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +import com.ruoyi.common.utils.poi.ExcelHandlerAdapter; | ||
| 2 | 6 | ||
| 3 | import java.lang.annotation.ElementType; | 7 | import java.lang.annotation.ElementType; |
| 4 | import java.lang.annotation.Retention; | 8 | import java.lang.annotation.Retention; |
| 1 | -package com.ruoyi.system.domain.tool; | ||
| 2 | - | ||
| 3 | -import com.ruoyi.system.domain.tool.Excel; | 1 | +package com.ruoyi.common.annotation; |
| 4 | 2 | ||
| 5 | import java.lang.annotation.ElementType; | 3 | import java.lang.annotation.ElementType; |
| 6 | import java.lang.annotation.Retention; | 4 | import java.lang.annotation.Retention; |
| 1 | +package com.ruoyi.common.annotation; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.enums.BusinessType; | ||
| 4 | +import com.ruoyi.common.enums.OperatorType; | ||
| 5 | + | ||
| 6 | +import java.lang.annotation.*; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 自定义操作日志记录注解 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + * | ||
| 13 | + */ | ||
| 14 | +@Target({ ElementType.PARAMETER, ElementType.METHOD }) | ||
| 15 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 16 | +@Documented | ||
| 17 | +public @interface Log | ||
| 18 | +{ | ||
| 19 | + /** | ||
| 20 | + * 模块 | ||
| 21 | + */ | ||
| 22 | + public String title() default ""; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 功能 | ||
| 26 | + */ | ||
| 27 | + public BusinessType businessType() default BusinessType.OTHER; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 操作人类别 | ||
| 31 | + */ | ||
| 32 | + public OperatorType operatorType() default OperatorType.MANAGE; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 是否保存请求的参数 | ||
| 36 | + */ | ||
| 37 | + public boolean isSaveRequestData() default true; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 是否保存响应的参数 | ||
| 41 | + */ | ||
| 42 | + public boolean isSaveResponseData() default true; | ||
| 43 | +} |
| 1 | +package com.ruoyi.common.annotation; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.constant.Constants; | ||
| 4 | +import com.ruoyi.common.enums.LimitType; | ||
| 5 | + | ||
| 6 | +import java.lang.annotation.*; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 限流注解 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + */ | ||
| 13 | +@Target(ElementType.METHOD) | ||
| 14 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 15 | +@Documented | ||
| 16 | +public @interface RateLimiter | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * 限流key | ||
| 20 | + */ | ||
| 21 | + public String key() default Constants.RATE_LIMIT_KEY; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 限流时间,单位秒 | ||
| 25 | + */ | ||
| 26 | + public int time() default 60; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 限流次数 | ||
| 30 | + */ | ||
| 31 | + public int count() default 100; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 限流类型 | ||
| 35 | + */ | ||
| 36 | + public LimitType limitType() default LimitType.DEFAULT; | ||
| 37 | +} |
| 1 | +package com.ruoyi.common.annotation; | ||
| 2 | + | ||
| 3 | +import java.lang.annotation.*; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 自定义注解防止表单重复提交 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +@Inherited | ||
| 12 | +@Target(ElementType.METHOD) | ||
| 13 | +@Retention(RetentionPolicy.RUNTIME) | ||
| 14 | +@Documented | ||
| 15 | +public @interface RepeatSubmit | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * 间隔时间(ms),小于此时间视为重复提交 | ||
| 19 | + */ | ||
| 20 | + public int interval() default 5000; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 提示消息 | ||
| 24 | + */ | ||
| 25 | + public String message() default "不允许重复提交,请稍候再试"; | ||
| 26 | +} |
| 1 | +package com.ruoyi.common.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 4 | +import org.springframework.stereotype.Component; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 读取项目相关配置 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +@Component | ||
| 12 | +@ConfigurationProperties(prefix = "jhlt") | ||
| 13 | +public class RuoYiConfig | ||
| 14 | +{ | ||
| 15 | + /** 项目名称 */ | ||
| 16 | + private String name; | ||
| 17 | + | ||
| 18 | + /** 版本 */ | ||
| 19 | + private String version; | ||
| 20 | + | ||
| 21 | + /** 版权年份 */ | ||
| 22 | + private String copyrightYear; | ||
| 23 | + | ||
| 24 | + /** 实例演示开关 */ | ||
| 25 | + private boolean demoEnabled; | ||
| 26 | + | ||
| 27 | + /** 上传路径 */ | ||
| 28 | + private static String profile; | ||
| 29 | + | ||
| 30 | + /** 获取地址开关 */ | ||
| 31 | + private static boolean addressEnabled; | ||
| 32 | + | ||
| 33 | + /** 验证码类型 */ | ||
| 34 | + private static String captchaType; | ||
| 35 | + | ||
| 36 | + /** root */ | ||
| 37 | + private static String root; | ||
| 38 | + | ||
| 39 | + public static String getRoot() { | ||
| 40 | + return root; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static void setRoot(String root) { | ||
| 44 | + RuoYiConfig.root = root; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getName() | ||
| 48 | + { | ||
| 49 | + return name; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setName(String name) | ||
| 53 | + { | ||
| 54 | + this.name = name; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public String getVersion() | ||
| 58 | + { | ||
| 59 | + return version; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setVersion(String version) | ||
| 63 | + { | ||
| 64 | + this.version = version; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getCopyrightYear() | ||
| 68 | + { | ||
| 69 | + return copyrightYear; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setCopyrightYear(String copyrightYear) | ||
| 73 | + { | ||
| 74 | + this.copyrightYear = copyrightYear; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public boolean isDemoEnabled() | ||
| 78 | + { | ||
| 79 | + return demoEnabled; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public void setDemoEnabled(boolean demoEnabled) | ||
| 83 | + { | ||
| 84 | + this.demoEnabled = demoEnabled; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public static String getProfile() | ||
| 88 | + { | ||
| 89 | + return profile; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setProfile(String profile) | ||
| 93 | + { | ||
| 94 | + RuoYiConfig.profile = profile; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public static boolean isAddressEnabled() | ||
| 98 | + { | ||
| 99 | + return addressEnabled; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public void setAddressEnabled(boolean addressEnabled) | ||
| 103 | + { | ||
| 104 | + RuoYiConfig.addressEnabled = addressEnabled; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public static String getCaptchaType() { | ||
| 108 | + return captchaType; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setCaptchaType(String captchaType) { | ||
| 112 | + RuoYiConfig.captchaType = captchaType; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 获取导入上传路径 | ||
| 117 | + */ | ||
| 118 | + public static String getImportPath() | ||
| 119 | + { | ||
| 120 | + return getProfile() + "/import"; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * 获取头像上传路径 | ||
| 125 | + */ | ||
| 126 | + public static String getAvatarPath() | ||
| 127 | + { | ||
| 128 | + return getProfile() + "/avatar"; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 获取下载路径 | ||
| 133 | + */ | ||
| 134 | + public static String getDownloadPath() | ||
| 135 | + { | ||
| 136 | + return getProfile() + "/download/"; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 获取上传路径 | ||
| 141 | + */ | ||
| 142 | + public static String getUploadPath() | ||
| 143 | + { | ||
| 144 | + return getProfile() + "/upload"; | ||
| 145 | + } | ||
| 146 | +} |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +import io.jsonwebtoken.Claims; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 通用常量信息 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +public class Constants | ||
| 11 | +{ | ||
| 12 | + /** | ||
| 13 | + * UTF-8 字符集 | ||
| 14 | + */ | ||
| 15 | + public static final String UTF8 = "UTF-8"; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * GBK 字符集 | ||
| 19 | + */ | ||
| 20 | + public static final String GBK = "GBK"; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * http请求 | ||
| 24 | + */ | ||
| 25 | + public static final String HTTP = "http://"; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * https请求 | ||
| 29 | + */ | ||
| 30 | + public static final String HTTPS = "https://"; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 通用成功标识 | ||
| 34 | + */ | ||
| 35 | + public static final String SUCCESS = "0"; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 通用失败标识 | ||
| 39 | + */ | ||
| 40 | + public static final String FAIL = "1"; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 登录成功 | ||
| 44 | + */ | ||
| 45 | + public static final String LOGIN_SUCCESS = "Success"; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 注销 | ||
| 49 | + */ | ||
| 50 | + public static final String LOGOUT = "Logout"; | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 注册 | ||
| 54 | + */ | ||
| 55 | + public static final String REGISTER = "Register"; | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 登录失败 | ||
| 59 | + */ | ||
| 60 | + public static final String LOGIN_FAIL = "Error"; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 验证码 redis key | ||
| 64 | + */ | ||
| 65 | + public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 登录用户 redis key | ||
| 69 | + */ | ||
| 70 | + public static final String LOGIN_TOKEN_KEY = "login_tokens:"; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 防重提交 redis key | ||
| 74 | + */ | ||
| 75 | + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 限流 redis key | ||
| 79 | + */ | ||
| 80 | + public static final String RATE_LIMIT_KEY = "rate_limit:"; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 验证码有效期(分钟) | ||
| 84 | + */ | ||
| 85 | + public static final Integer CAPTCHA_EXPIRATION = 2; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 令牌 | ||
| 89 | + */ | ||
| 90 | + public static final String TOKEN = "token"; | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 令牌前缀 | ||
| 94 | + */ | ||
| 95 | + public static final String TOKEN_PREFIX = "Bearer "; | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 令牌前缀 | ||
| 99 | + */ | ||
| 100 | + public static final String LOGIN_USER_KEY = "login_user_key"; | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 用户ID | ||
| 104 | + */ | ||
| 105 | + public static final String JWT_USERID = "userid"; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 用户名称 | ||
| 109 | + */ | ||
| 110 | + public static final String JWT_USERNAME = Claims.SUBJECT; | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * 用户头像 | ||
| 114 | + */ | ||
| 115 | + public static final String JWT_AVATAR = "avatar"; | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * 创建时间 | ||
| 119 | + */ | ||
| 120 | + public static final String JWT_CREATED = "created"; | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 用户权限 | ||
| 124 | + */ | ||
| 125 | + public static final String JWT_AUTHORITIES = "authorities"; | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 参数管理 cache key | ||
| 129 | + */ | ||
| 130 | + public static final String SYS_CONFIG_KEY = "sys_config:"; | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 字典管理 cache key | ||
| 134 | + */ | ||
| 135 | + public static final String SYS_DICT_KEY = "sys_dict:"; | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * 资源映射路径 前缀 | ||
| 139 | + */ | ||
| 140 | + public static final String RESOURCE_PREFIX = "/profile"; | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 资源映射路径 前缀 | ||
| 144 | + */ | ||
| 145 | + public static final String ROOT = "/**"; | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * RMI 远程方法调用 | ||
| 149 | + */ | ||
| 150 | + public static final String LOOKUP_RMI = "rmi:"; | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * LDAP 远程方法调用 | ||
| 154 | + */ | ||
| 155 | + public static final String LOOKUP_LDAP = "ldap:"; | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * LDAPS 远程方法调用 | ||
| 159 | + */ | ||
| 160 | + public static final String LOOKUP_LDAPS = "ldaps:"; | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) | ||
| 164 | + */ | ||
| 165 | + public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * 定时任务违规的字符 | ||
| 169 | + */ | ||
| 170 | + public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", | ||
| 171 | + "org.springframework", "org.apache", "com.ruoyi.common.utils.file" }; | ||
| 172 | +} |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 代码生成通用常量 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class GenConstants | ||
| 9 | +{ | ||
| 10 | + /** 单表(增删改查) */ | ||
| 11 | + public static final String TPL_CRUD = "crud"; | ||
| 12 | + | ||
| 13 | + /** 树表(增删改查) */ | ||
| 14 | + public static final String TPL_TREE = "tree"; | ||
| 15 | + | ||
| 16 | + /** 主子表(增删改查) */ | ||
| 17 | + public static final String TPL_SUB = "sub"; | ||
| 18 | + | ||
| 19 | + /** 树编码字段 */ | ||
| 20 | + public static final String TREE_CODE = "treeCode"; | ||
| 21 | + | ||
| 22 | + /** 树父编码字段 */ | ||
| 23 | + public static final String TREE_PARENT_CODE = "treeParentCode"; | ||
| 24 | + | ||
| 25 | + /** 树名称字段 */ | ||
| 26 | + public static final String TREE_NAME = "treeName"; | ||
| 27 | + | ||
| 28 | + /** 上级菜单ID字段 */ | ||
| 29 | + public static final String PARENT_MENU_ID = "parentMenuId"; | ||
| 30 | + | ||
| 31 | + /** 上级菜单名称字段 */ | ||
| 32 | + public static final String PARENT_MENU_NAME = "parentMenuName"; | ||
| 33 | + | ||
| 34 | + /** 数据库字符串类型 */ | ||
| 35 | + public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; | ||
| 36 | + | ||
| 37 | + /** 数据库文本类型 */ | ||
| 38 | + public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" }; | ||
| 39 | + | ||
| 40 | + /** 数据库时间类型 */ | ||
| 41 | + public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; | ||
| 42 | + | ||
| 43 | + /** 数据库数字类型 */ | ||
| 44 | + public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer", | ||
| 45 | + "bit", "bigint", "float", "double", "decimal" }; | ||
| 46 | + | ||
| 47 | + /** 页面不需要编辑字段 */ | ||
| 48 | + public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" }; | ||
| 49 | + | ||
| 50 | + /** 页面不需要显示的列表字段 */ | ||
| 51 | + public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", | ||
| 52 | + "update_time" }; | ||
| 53 | + | ||
| 54 | + /** 页面不需要查询字段 */ | ||
| 55 | + public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by", | ||
| 56 | + "update_time", "remark" }; | ||
| 57 | + | ||
| 58 | + /** Entity基类字段 */ | ||
| 59 | + public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; | ||
| 60 | + | ||
| 61 | + /** Tree基类字段 */ | ||
| 62 | + public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" }; | ||
| 63 | + | ||
| 64 | + /** 文本框 */ | ||
| 65 | + public static final String HTML_INPUT = "input"; | ||
| 66 | + | ||
| 67 | + /** 文本域 */ | ||
| 68 | + public static final String HTML_TEXTAREA = "textarea"; | ||
| 69 | + | ||
| 70 | + /** 下拉框 */ | ||
| 71 | + public static final String HTML_SELECT = "select"; | ||
| 72 | + | ||
| 73 | + /** 单选框 */ | ||
| 74 | + public static final String HTML_RADIO = "radio"; | ||
| 75 | + | ||
| 76 | + /** 复选框 */ | ||
| 77 | + public static final String HTML_CHECKBOX = "checkbox"; | ||
| 78 | + | ||
| 79 | + /** 日期控件 */ | ||
| 80 | + public static final String HTML_DATETIME = "datetime"; | ||
| 81 | + | ||
| 82 | + /** 图片上传控件 */ | ||
| 83 | + public static final String HTML_IMAGE_UPLOAD = "imageUpload"; | ||
| 84 | + | ||
| 85 | + /** 文件上传控件 */ | ||
| 86 | + public static final String HTML_FILE_UPLOAD = "fileUpload"; | ||
| 87 | + | ||
| 88 | + /** 富文本控件 */ | ||
| 89 | + public static final String HTML_EDITOR = "editor"; | ||
| 90 | + | ||
| 91 | + /** 字符串类型 */ | ||
| 92 | + public static final String TYPE_STRING = "String"; | ||
| 93 | + | ||
| 94 | + /** 整型 */ | ||
| 95 | + public static final String TYPE_INTEGER = "Integer"; | ||
| 96 | + | ||
| 97 | + /** 长整型 */ | ||
| 98 | + public static final String TYPE_LONG = "Long"; | ||
| 99 | + | ||
| 100 | + /** 浮点型 */ | ||
| 101 | + public static final String TYPE_DOUBLE = "Double"; | ||
| 102 | + | ||
| 103 | + /** 高精度计算类型 */ | ||
| 104 | + public static final String TYPE_BIGDECIMAL = "BigDecimal"; | ||
| 105 | + | ||
| 106 | + /** 时间类型 */ | ||
| 107 | + public static final String TYPE_DATE = "Date"; | ||
| 108 | + | ||
| 109 | + /** 模糊查询 */ | ||
| 110 | + public static final String QUERY_LIKE = "LIKE"; | ||
| 111 | + | ||
| 112 | + /** 相等查询 */ | ||
| 113 | + public static final String QUERY_EQ = "EQ"; | ||
| 114 | + | ||
| 115 | + /** 需要 */ | ||
| 116 | + public static final String REQUIRE = "1"; | ||
| 117 | +} |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 返回状态码 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class HttpStatus | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * 操作成功 | ||
| 12 | + */ | ||
| 13 | + public static final int SUCCESS = 200; | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 对象创建成功 | ||
| 17 | + */ | ||
| 18 | + public static final int CREATED = 201; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 请求已经被接受 | ||
| 22 | + */ | ||
| 23 | + public static final int ACCEPTED = 202; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 操作已经执行成功,但是没有返回数据 | ||
| 27 | + */ | ||
| 28 | + public static final int NO_CONTENT = 204; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 资源已被移除 | ||
| 32 | + */ | ||
| 33 | + public static final int MOVED_PERM = 301; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 重定向 | ||
| 37 | + */ | ||
| 38 | + public static final int SEE_OTHER = 303; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 资源没有被修改 | ||
| 42 | + */ | ||
| 43 | + public static final int NOT_MODIFIED = 304; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 参数列表错误(缺少,格式不匹配) | ||
| 47 | + */ | ||
| 48 | + public static final int BAD_REQUEST = 400; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 未授权 | ||
| 52 | + */ | ||
| 53 | + public static final int UNAUTHORIZED = 401; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 访问受限,授权过期 | ||
| 57 | + */ | ||
| 58 | + public static final int FORBIDDEN = 403; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 资源,服务未找到 | ||
| 62 | + */ | ||
| 63 | + public static final int NOT_FOUND = 404; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 不允许的http方法 | ||
| 67 | + */ | ||
| 68 | + public static final int BAD_METHOD = 405; | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 资源冲突,或者资源被锁 | ||
| 72 | + */ | ||
| 73 | + public static final int CONFLICT = 409; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 不支持的数据,媒体类型 | ||
| 77 | + */ | ||
| 78 | + public static final int UNSUPPORTED_TYPE = 415; | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * 系统内部错误 | ||
| 82 | + */ | ||
| 83 | + public static final int ERROR = 500; | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 接口未实现 | ||
| 87 | + */ | ||
| 88 | + public static final int NOT_IMPLEMENTED = 501; | ||
| 89 | +} |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 任务调度通用常量 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class ScheduleConstants | ||
| 9 | +{ | ||
| 10 | + public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; | ||
| 11 | + | ||
| 12 | + /** 执行目标key */ | ||
| 13 | + public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; | ||
| 14 | + | ||
| 15 | + /** 默认 */ | ||
| 16 | + public static final String MISFIRE_DEFAULT = "0"; | ||
| 17 | + | ||
| 18 | + /** 立即触发执行 */ | ||
| 19 | + public static final String MISFIRE_IGNORE_MISFIRES = "1"; | ||
| 20 | + | ||
| 21 | + /** 触发一次执行 */ | ||
| 22 | + public static final String MISFIRE_FIRE_AND_PROCEED = "2"; | ||
| 23 | + | ||
| 24 | + /** 不触发立即执行 */ | ||
| 25 | + public static final String MISFIRE_DO_NOTHING = "3"; | ||
| 26 | + | ||
| 27 | + public enum Status | ||
| 28 | + { | ||
| 29 | + /** | ||
| 30 | + * 正常 | ||
| 31 | + */ | ||
| 32 | + NORMAL("0"), | ||
| 33 | + /** | ||
| 34 | + * 暂停 | ||
| 35 | + */ | ||
| 36 | + PAUSE("1"); | ||
| 37 | + | ||
| 38 | + private String value; | ||
| 39 | + | ||
| 40 | + private Status(String value) | ||
| 41 | + { | ||
| 42 | + this.value = value; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getValue() | ||
| 46 | + { | ||
| 47 | + return value; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | +} |
| 1 | +package com.ruoyi.common.core.domain; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.constant.HttpStatus; | ||
| 4 | +import com.ruoyi.common.utils.StringUtils; | ||
| 5 | + | ||
| 6 | +import java.util.HashMap; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 操作消息提醒 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + */ | ||
| 13 | +public class AjaxResult extends HashMap<String, Object> | ||
| 14 | +{ | ||
| 15 | + private static final long serialVersionUID = 1L; | ||
| 16 | + | ||
| 17 | + /** 状态码 */ | ||
| 18 | + public static final String CODE_TAG = "code"; | ||
| 19 | + | ||
| 20 | + /** 返回内容 */ | ||
| 21 | + public static final String MSG_TAG = "msg"; | ||
| 22 | + | ||
| 23 | + /** 数据对象 */ | ||
| 24 | + public static final String DATA_TAG = "data"; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。 | ||
| 28 | + */ | ||
| 29 | + public AjaxResult() | ||
| 30 | + { | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 初始化一个新创建的 AjaxResult 对象 | ||
| 35 | + * | ||
| 36 | + * @param code 状态码 | ||
| 37 | + * @param msg 返回内容 | ||
| 38 | + */ | ||
| 39 | + public AjaxResult(int code, String msg) | ||
| 40 | + { | ||
| 41 | + super.put(CODE_TAG, code); | ||
| 42 | + super.put(MSG_TAG, msg); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 初始化一个新创建的 AjaxResult 对象 | ||
| 47 | + * | ||
| 48 | + * @param code 状态码 | ||
| 49 | + * @param msg 返回内容 | ||
| 50 | + * @param data 数据对象 | ||
| 51 | + */ | ||
| 52 | + public AjaxResult(int code, String msg, Object data) | ||
| 53 | + { | ||
| 54 | + super.put(CODE_TAG, code); | ||
| 55 | + super.put(MSG_TAG, msg); | ||
| 56 | + if (StringUtils.isNotNull(data)) | ||
| 57 | + { | ||
| 58 | + super.put(DATA_TAG, data); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 返回成功消息 | ||
| 64 | + * | ||
| 65 | + * @return 成功消息 | ||
| 66 | + */ | ||
| 67 | + public static AjaxResult success() | ||
| 68 | + { | ||
| 69 | + return AjaxResult.success("操作成功"); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 返回成功数据 | ||
| 74 | + * | ||
| 75 | + * @return 成功消息 | ||
| 76 | + */ | ||
| 77 | + public static AjaxResult success(Object data) | ||
| 78 | + { | ||
| 79 | + return AjaxResult.success("操作成功", data); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 返回成功消息 | ||
| 84 | + * | ||
| 85 | + * @param msg 返回内容 | ||
| 86 | + * @return 成功消息 | ||
| 87 | + */ | ||
| 88 | + public static AjaxResult success(String msg) | ||
| 89 | + { | ||
| 90 | + return AjaxResult.success(msg, null); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 返回成功消息 | ||
| 95 | + * | ||
| 96 | + * @param msg 返回内容 | ||
| 97 | + * @param data 数据对象 | ||
| 98 | + * @return 成功消息 | ||
| 99 | + */ | ||
| 100 | + public static AjaxResult success(String msg, Object data) | ||
| 101 | + { | ||
| 102 | + return new AjaxResult(HttpStatus.SUCCESS, msg, data); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * 返回错误消息 | ||
| 107 | + * | ||
| 108 | + * @return | ||
| 109 | + */ | ||
| 110 | + public static AjaxResult error() | ||
| 111 | + { | ||
| 112 | + return AjaxResult.error("操作失败"); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 返回错误消息 | ||
| 117 | + * | ||
| 118 | + * @param msg 返回内容 | ||
| 119 | + * @return 警告消息 | ||
| 120 | + */ | ||
| 121 | + public static AjaxResult error(String msg) | ||
| 122 | + { | ||
| 123 | + return AjaxResult.error(msg, null); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * 返回错误消息 | ||
| 128 | + * | ||
| 129 | + * @param msg 返回内容 | ||
| 130 | + * @param data 数据对象 | ||
| 131 | + * @return 警告消息 | ||
| 132 | + */ | ||
| 133 | + public static AjaxResult error(String msg, Object data) | ||
| 134 | + { | ||
| 135 | + return new AjaxResult(HttpStatus.ERROR, msg, data); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 返回错误消息 | ||
| 140 | + * | ||
| 141 | + * @param code 状态码 | ||
| 142 | + * @param msg 返回内容 | ||
| 143 | + * @return 警告消息 | ||
| 144 | + */ | ||
| 145 | + public static AjaxResult error(int code, String msg) | ||
| 146 | + { | ||
| 147 | + return new AjaxResult(code, msg, null); | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 方便链式调用 | ||
| 152 | + * | ||
| 153 | + * @param key 键 | ||
| 154 | + * @param value 值 | ||
| 155 | + * @return 数据对象 | ||
| 156 | + */ | ||
| 157 | + @Override | ||
| 158 | + public AjaxResult put(String key, Object value) | ||
| 159 | + { | ||
| 160 | + super.put(key, value); | ||
| 161 | + return this; | ||
| 162 | + } | ||
| 163 | +} |
| 1 | +package com.ruoyi.common.core.domain; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +@Data | ||
| 6 | +public class Message { | ||
| 7 | + private Integer code; | ||
| 8 | + private String message; | ||
| 9 | + private Object data; | ||
| 10 | + | ||
| 11 | + public Message() { | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public Message(MessageCodeType code, String message, Object data) { | ||
| 15 | + this.code = code.getCode(); | ||
| 16 | + this.message = message; | ||
| 17 | + if (null == message || "".equals(message)) { | ||
| 18 | + this.message = code.getMessage(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + this.data = data; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public Message(MessageCodeType code, Object data) { | ||
| 25 | + this.code = code.getCode(); | ||
| 26 | + this.message = code.getMessage(); | ||
| 27 | + this.data = data; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public Message(MessageCodeType code, String message) { | ||
| 31 | + this.code = code.getCode(); | ||
| 32 | + this.message = message; | ||
| 33 | + this.data = null; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public Message(MessageCodeType code) { | ||
| 37 | + this.code = code.getCode(); | ||
| 38 | + this.message = code.getMessage(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setCode(MessageCode messageCode ) | ||
| 42 | + { | ||
| 43 | + code = messageCode.code; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public void setCode(MessageCodeType code) { | ||
| 47 | + this.code = code.getCode(); | ||
| 48 | + } | ||
| 49 | +} |
| 1 | +package com.ruoyi.common.core.domain; | ||
| 2 | + | ||
| 3 | +public enum MessageCode implements MessageCodeType{ | ||
| 4 | + DEFAULT_FAIL_CODE(0, "请求失败"), | ||
| 5 | + DEFAULT_SUCCESS_CODE(1, "请求成功"), | ||
| 6 | + SESSION_TIME_OUT(2, "会话超时,请刷新令牌"), | ||
| 7 | + USER_INVALID(4, "用户失效,请重新登录"), | ||
| 8 | + SYS_ERROR(3, "已知系统错误"), | ||
| 9 | + REQUEST_METHOD_ERROR(6, "请求方式错误"), | ||
| 10 | + REQUEST_PATH_ERROR(7, "请求路径错误"), | ||
| 11 | + UNKNOWN_SYS_ERROR(5, "未知系统错误"); | ||
| 12 | + | ||
| 13 | + public int code; | ||
| 14 | + public String message; | ||
| 15 | + | ||
| 16 | + public int getCode() { | ||
| 17 | + return this.code; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public String getMessage() { | ||
| 21 | + return this.message; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + private MessageCode(int code, String message) { | ||
| 25 | + this.code = code; | ||
| 26 | + this.message = message; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + public static MessageCode getMessageCode(int code) | ||
| 31 | + { | ||
| 32 | + MessageCode[] messageCodes = MessageCode.values(); | ||
| 33 | + for(MessageCode messageCode:messageCodes) | ||
| 34 | + { | ||
| 35 | + if(messageCode.code==code) | ||
| 36 | + { | ||
| 37 | + return messageCode; | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + return DEFAULT_FAIL_CODE; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
| 1 | +package com.ruoyi.common.core.page; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.StringUtils; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 分页数据 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +public class PageDomain | ||
| 11 | +{ | ||
| 12 | + /** 当前记录起始索引 */ | ||
| 13 | + private Integer pageNum; | ||
| 14 | + | ||
| 15 | + /** 每页显示记录数 */ | ||
| 16 | + private Integer pageSize; | ||
| 17 | + | ||
| 18 | + /** 排序列 */ | ||
| 19 | + private String orderByColumn; | ||
| 20 | + | ||
| 21 | + /** 排序的方向desc或者asc */ | ||
| 22 | + private String isAsc = "asc"; | ||
| 23 | + | ||
| 24 | + /** 分页参数合理化 */ | ||
| 25 | + private Boolean reasonable = true; | ||
| 26 | + | ||
| 27 | + public String getOrderBy() | ||
| 28 | + { | ||
| 29 | + if (StringUtils.isEmpty(orderByColumn)) | ||
| 30 | + { | ||
| 31 | + return ""; | ||
| 32 | + } | ||
| 33 | + return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public Integer getPageNum() | ||
| 37 | + { | ||
| 38 | + return pageNum; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setPageNum(Integer pageNum) | ||
| 42 | + { | ||
| 43 | + this.pageNum = pageNum; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public Integer getPageSize() | ||
| 47 | + { | ||
| 48 | + return pageSize; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setPageSize(Integer pageSize) | ||
| 52 | + { | ||
| 53 | + this.pageSize = pageSize; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getOrderByColumn() | ||
| 57 | + { | ||
| 58 | + return orderByColumn; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setOrderByColumn(String orderByColumn) | ||
| 62 | + { | ||
| 63 | + this.orderByColumn = orderByColumn; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public String getIsAsc() | ||
| 67 | + { | ||
| 68 | + return isAsc; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setIsAsc(String isAsc) | ||
| 72 | + { | ||
| 73 | + if (StringUtils.isNotEmpty(isAsc)) | ||
| 74 | + { | ||
| 75 | + // 兼容前端排序类型 | ||
| 76 | + if ("ascending".equals(isAsc)) | ||
| 77 | + { | ||
| 78 | + isAsc = "asc"; | ||
| 79 | + } | ||
| 80 | + else if ("descending".equals(isAsc)) | ||
| 81 | + { | ||
| 82 | + isAsc = "desc"; | ||
| 83 | + } | ||
| 84 | + this.isAsc = isAsc; | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public Boolean getReasonable() | ||
| 89 | + { | ||
| 90 | + if (StringUtils.isNull(reasonable)) | ||
| 91 | + { | ||
| 92 | + return Boolean.TRUE; | ||
| 93 | + } | ||
| 94 | + return reasonable; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setReasonable(Boolean reasonable) | ||
| 98 | + { | ||
| 99 | + this.reasonable = reasonable; | ||
| 100 | + } | ||
| 101 | +} |
| 1 | +package com.ruoyi.common.core.page; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.annotation.PublicSQLConfig; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 表格分页数据对象 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + */ | ||
| 13 | +public class TableDataInfo implements Serializable | ||
| 14 | +{ | ||
| 15 | + @PublicSQLConfig(isSelect=false) | ||
| 16 | + private static final long serialVersionUID = 1L; | ||
| 17 | + | ||
| 18 | + /** 总记录数 */ | ||
| 19 | + private long total; | ||
| 20 | + | ||
| 21 | + /** 列表数据 */ | ||
| 22 | + private List<?> rows; | ||
| 23 | + | ||
| 24 | + /** 消息状态码 */ | ||
| 25 | + private int code; | ||
| 26 | + | ||
| 27 | + /** 消息内容 */ | ||
| 28 | + private String msg; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 表格数据对象 | ||
| 32 | + */ | ||
| 33 | + public TableDataInfo() | ||
| 34 | + { | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 分页 | ||
| 39 | + * | ||
| 40 | + * @param list 列表数据 | ||
| 41 | + * @param total 总记录数 | ||
| 42 | + */ | ||
| 43 | + public TableDataInfo(List<?> list, int total) | ||
| 44 | + { | ||
| 45 | + this.rows = list; | ||
| 46 | + this.total = total; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public long getTotal() | ||
| 50 | + { | ||
| 51 | + return total; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setTotal(long total) | ||
| 55 | + { | ||
| 56 | + this.total = total; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public List<?> getRows() | ||
| 60 | + { | ||
| 61 | + return rows; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setRows(List<?> rows) | ||
| 65 | + { | ||
| 66 | + this.rows = rows; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public int getCode() | ||
| 70 | + { | ||
| 71 | + return code; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setCode(int code) | ||
| 75 | + { | ||
| 76 | + this.code = code; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String getMsg() | ||
| 80 | + { | ||
| 81 | + return msg; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setMsg(String msg) | ||
| 85 | + { | ||
| 86 | + this.msg = msg; | ||
| 87 | + } | ||
| 88 | +} |
| 1 | +package com.ruoyi.common.core.page; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.ServletUtils; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 表格数据处理 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +public class TableSupport | ||
| 11 | +{ | ||
| 12 | + /** | ||
| 13 | + * 当前记录起始索引 | ||
| 14 | + */ | ||
| 15 | + public static final String PAGE_NUM = "pageNum"; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 每页显示记录数 | ||
| 19 | + */ | ||
| 20 | + public static final String PAGE_SIZE = "pageSize"; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 排序列 | ||
| 24 | + */ | ||
| 25 | + public static final String ORDER_BY_COLUMN = "orderByColumn"; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 排序的方向 "desc" 或者 "asc". | ||
| 29 | + */ | ||
| 30 | + public static final String IS_ASC = "isAsc"; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 分页参数合理化 | ||
| 34 | + */ | ||
| 35 | + public static final String REASONABLE = "reasonable"; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 封装分页对象 | ||
| 39 | + */ | ||
| 40 | + public static PageDomain getPageDomain() | ||
| 41 | + { | ||
| 42 | + PageDomain pageDomain = new PageDomain(); | ||
| 43 | + pageDomain.setPageNum(ServletUtils.getParameterToInt(PAGE_NUM)); | ||
| 44 | + pageDomain.setPageSize(ServletUtils.getParameterToInt(PAGE_SIZE)); | ||
| 45 | + pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN)); | ||
| 46 | + pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC)); | ||
| 47 | + pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE)); | ||
| 48 | + return pageDomain; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public static PageDomain buildPageRequest() | ||
| 52 | + { | ||
| 53 | + return getPageDomain(); | ||
| 54 | + } | ||
| 55 | +} |
| 1 | +package com.ruoyi.common.core.text; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.StringUtils; | ||
| 4 | + | ||
| 5 | +import java.nio.charset.Charset; | ||
| 6 | +import java.nio.charset.StandardCharsets; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 字符集工具类 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + */ | ||
| 13 | +public class CharsetKit | ||
| 14 | +{ | ||
| 15 | + /** ISO-8859-1 */ | ||
| 16 | + public static final String ISO_8859_1 = "ISO-8859-1"; | ||
| 17 | + /** UTF-8 */ | ||
| 18 | + public static final String UTF_8 = "UTF-8"; | ||
| 19 | + /** GBK */ | ||
| 20 | + public static final String GBK = "GBK"; | ||
| 21 | + | ||
| 22 | + /** ISO-8859-1 */ | ||
| 23 | + public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); | ||
| 24 | + /** UTF-8 */ | ||
| 25 | + public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); | ||
| 26 | + /** GBK */ | ||
| 27 | + public static final Charset CHARSET_GBK = Charset.forName(GBK); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 转换为Charset对象 | ||
| 31 | + * | ||
| 32 | + * @param charset 字符集,为空则返回默认字符集 | ||
| 33 | + * @return Charset | ||
| 34 | + */ | ||
| 35 | + public static Charset charset(String charset) | ||
| 36 | + { | ||
| 37 | + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 转换字符串的字符集编码 | ||
| 42 | + * | ||
| 43 | + * @param source 字符串 | ||
| 44 | + * @param srcCharset 源字符集,默认ISO-8859-1 | ||
| 45 | + * @param destCharset 目标字符集,默认UTF-8 | ||
| 46 | + * @return 转换后的字符集 | ||
| 47 | + */ | ||
| 48 | + public static String convert(String source, String srcCharset, String destCharset) | ||
| 49 | + { | ||
| 50 | + return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 转换字符串的字符集编码 | ||
| 55 | + * | ||
| 56 | + * @param source 字符串 | ||
| 57 | + * @param srcCharset 源字符集,默认ISO-8859-1 | ||
| 58 | + * @param destCharset 目标字符集,默认UTF-8 | ||
| 59 | + * @return 转换后的字符集 | ||
| 60 | + */ | ||
| 61 | + public static String convert(String source, Charset srcCharset, Charset destCharset) | ||
| 62 | + { | ||
| 63 | + if (null == srcCharset) | ||
| 64 | + { | ||
| 65 | + srcCharset = StandardCharsets.ISO_8859_1; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (null == destCharset) | ||
| 69 | + { | ||
| 70 | + destCharset = StandardCharsets.UTF_8; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) | ||
| 74 | + { | ||
| 75 | + return source; | ||
| 76 | + } | ||
| 77 | + return new String(source.getBytes(srcCharset), destCharset); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * @return 系统字符集编码 | ||
| 82 | + */ | ||
| 83 | + public static String systemCharset() | ||
| 84 | + { | ||
| 85 | + return Charset.defaultCharset().name(); | ||
| 86 | + } | ||
| 87 | +} |
| 1 | +package com.ruoyi.common.core.text; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.StringUtils; | ||
| 4 | +import org.apache.commons.lang3.ArrayUtils; | ||
| 5 | + | ||
| 6 | +import java.math.BigDecimal; | ||
| 7 | +import java.math.BigInteger; | ||
| 8 | +import java.nio.ByteBuffer; | ||
| 9 | +import java.nio.charset.Charset; | ||
| 10 | +import java.text.NumberFormat; | ||
| 11 | +import java.util.Set; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 类型转换器 | ||
| 15 | + * | ||
| 16 | + * @author ruoyi | ||
| 17 | + */ | ||
| 18 | +public class Convert | ||
| 19 | +{ | ||
| 20 | + /** | ||
| 21 | + * 转换为字符串<br> | ||
| 22 | + * 如果给定的值为null,或者转换失败,返回默认值<br> | ||
| 23 | + * 转换失败不会报错 | ||
| 24 | + * | ||
| 25 | + * @param value 被转换的值 | ||
| 26 | + * @param defaultValue 转换错误时的默认值 | ||
| 27 | + * @return 结果 | ||
| 28 | + */ | ||
| 29 | + public static String toStr(Object value, String defaultValue) | ||
| 30 | + { | ||
| 31 | + if (null == value) | ||
| 32 | + { | ||
| 33 | + return defaultValue; | ||
| 34 | + } | ||
| 35 | + if (value instanceof String) | ||
| 36 | + { | ||
| 37 | + return (String) value; | ||
| 38 | + } | ||
| 39 | + return value.toString(); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 转换为字符串<br> | ||
| 44 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 45 | + * 转换失败不会报错 | ||
| 46 | + * | ||
| 47 | + * @param value 被转换的值 | ||
| 48 | + * @return 结果 | ||
| 49 | + */ | ||
| 50 | + public static String toStr(Object value) | ||
| 51 | + { | ||
| 52 | + return toStr(value, null); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 转换为字符<br> | ||
| 57 | + * 如果给定的值为null,或者转换失败,返回默认值<br> | ||
| 58 | + * 转换失败不会报错 | ||
| 59 | + * | ||
| 60 | + * @param value 被转换的值 | ||
| 61 | + * @param defaultValue 转换错误时的默认值 | ||
| 62 | + * @return 结果 | ||
| 63 | + */ | ||
| 64 | + public static Character toChar(Object value, Character defaultValue) | ||
| 65 | + { | ||
| 66 | + if (null == value) | ||
| 67 | + { | ||
| 68 | + return defaultValue; | ||
| 69 | + } | ||
| 70 | + if (value instanceof Character) | ||
| 71 | + { | ||
| 72 | + return (Character) value; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + final String valueStr = toStr(value, null); | ||
| 76 | + return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 转换为字符<br> | ||
| 81 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 82 | + * 转换失败不会报错 | ||
| 83 | + * | ||
| 84 | + * @param value 被转换的值 | ||
| 85 | + * @return 结果 | ||
| 86 | + */ | ||
| 87 | + public static Character toChar(Object value) | ||
| 88 | + { | ||
| 89 | + return toChar(value, null); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 转换为byte<br> | ||
| 94 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br> | ||
| 95 | + * 转换失败不会报错 | ||
| 96 | + * | ||
| 97 | + * @param value 被转换的值 | ||
| 98 | + * @param defaultValue 转换错误时的默认值 | ||
| 99 | + * @return 结果 | ||
| 100 | + */ | ||
| 101 | + public static Byte toByte(Object value, Byte defaultValue) | ||
| 102 | + { | ||
| 103 | + if (value == null) | ||
| 104 | + { | ||
| 105 | + return defaultValue; | ||
| 106 | + } | ||
| 107 | + if (value instanceof Byte) | ||
| 108 | + { | ||
| 109 | + return (Byte) value; | ||
| 110 | + } | ||
| 111 | + if (value instanceof Number) | ||
| 112 | + { | ||
| 113 | + return ((Number) value).byteValue(); | ||
| 114 | + } | ||
| 115 | + final String valueStr = toStr(value, null); | ||
| 116 | + if (StringUtils.isEmpty(valueStr)) | ||
| 117 | + { | ||
| 118 | + return defaultValue; | ||
| 119 | + } | ||
| 120 | + try | ||
| 121 | + { | ||
| 122 | + return Byte.parseByte(valueStr); | ||
| 123 | + } | ||
| 124 | + catch (Exception e) | ||
| 125 | + { | ||
| 126 | + return defaultValue; | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 转换为byte<br> | ||
| 132 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 133 | + * 转换失败不会报错 | ||
| 134 | + * | ||
| 135 | + * @param value 被转换的值 | ||
| 136 | + * @return 结果 | ||
| 137 | + */ | ||
| 138 | + public static Byte toByte(Object value) | ||
| 139 | + { | ||
| 140 | + return toByte(value, null); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + /** | ||
| 144 | + * 转换为Short<br> | ||
| 145 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br> | ||
| 146 | + * 转换失败不会报错 | ||
| 147 | + * | ||
| 148 | + * @param value 被转换的值 | ||
| 149 | + * @param defaultValue 转换错误时的默认值 | ||
| 150 | + * @return 结果 | ||
| 151 | + */ | ||
| 152 | + public static Short toShort(Object value, Short defaultValue) | ||
| 153 | + { | ||
| 154 | + if (value == null) | ||
| 155 | + { | ||
| 156 | + return defaultValue; | ||
| 157 | + } | ||
| 158 | + if (value instanceof Short) | ||
| 159 | + { | ||
| 160 | + return (Short) value; | ||
| 161 | + } | ||
| 162 | + if (value instanceof Number) | ||
| 163 | + { | ||
| 164 | + return ((Number) value).shortValue(); | ||
| 165 | + } | ||
| 166 | + final String valueStr = toStr(value, null); | ||
| 167 | + if (StringUtils.isEmpty(valueStr)) | ||
| 168 | + { | ||
| 169 | + return defaultValue; | ||
| 170 | + } | ||
| 171 | + try | ||
| 172 | + { | ||
| 173 | + return Short.parseShort(valueStr.trim()); | ||
| 174 | + } | ||
| 175 | + catch (Exception e) | ||
| 176 | + { | ||
| 177 | + return defaultValue; | ||
| 178 | + } | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * 转换为Short<br> | ||
| 183 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 184 | + * 转换失败不会报错 | ||
| 185 | + * | ||
| 186 | + * @param value 被转换的值 | ||
| 187 | + * @return 结果 | ||
| 188 | + */ | ||
| 189 | + public static Short toShort(Object value) | ||
| 190 | + { | ||
| 191 | + return toShort(value, null); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * 转换为Number<br> | ||
| 196 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 197 | + * 转换失败不会报错 | ||
| 198 | + * | ||
| 199 | + * @param value 被转换的值 | ||
| 200 | + * @param defaultValue 转换错误时的默认值 | ||
| 201 | + * @return 结果 | ||
| 202 | + */ | ||
| 203 | + public static Number toNumber(Object value, Number defaultValue) | ||
| 204 | + { | ||
| 205 | + if (value == null) | ||
| 206 | + { | ||
| 207 | + return defaultValue; | ||
| 208 | + } | ||
| 209 | + if (value instanceof Number) | ||
| 210 | + { | ||
| 211 | + return (Number) value; | ||
| 212 | + } | ||
| 213 | + final String valueStr = toStr(value, null); | ||
| 214 | + if (StringUtils.isEmpty(valueStr)) | ||
| 215 | + { | ||
| 216 | + return defaultValue; | ||
| 217 | + } | ||
| 218 | + try | ||
| 219 | + { | ||
| 220 | + return NumberFormat.getInstance().parse(valueStr); | ||
| 221 | + } | ||
| 222 | + catch (Exception e) | ||
| 223 | + { | ||
| 224 | + return defaultValue; | ||
| 225 | + } | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + /** | ||
| 229 | + * 转换为Number<br> | ||
| 230 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 231 | + * 转换失败不会报错 | ||
| 232 | + * | ||
| 233 | + * @param value 被转换的值 | ||
| 234 | + * @return 结果 | ||
| 235 | + */ | ||
| 236 | + public static Number toNumber(Object value) | ||
| 237 | + { | ||
| 238 | + return toNumber(value, null); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + /** | ||
| 242 | + * 转换为int<br> | ||
| 243 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 244 | + * 转换失败不会报错 | ||
| 245 | + * | ||
| 246 | + * @param value 被转换的值 | ||
| 247 | + * @param defaultValue 转换错误时的默认值 | ||
| 248 | + * @return 结果 | ||
| 249 | + */ | ||
| 250 | + public static Integer toInt(Object value, Integer defaultValue) | ||
| 251 | + { | ||
| 252 | + if (value == null) | ||
| 253 | + { | ||
| 254 | + return defaultValue; | ||
| 255 | + } | ||
| 256 | + if (value instanceof Integer) | ||
| 257 | + { | ||
| 258 | + return (Integer) value; | ||
| 259 | + } | ||
| 260 | + if (value instanceof Number) | ||
| 261 | + { | ||
| 262 | + return ((Number) value).intValue(); | ||
| 263 | + } | ||
| 264 | + final String valueStr = toStr(value, null); | ||
| 265 | + if (StringUtils.isEmpty(valueStr)) | ||
| 266 | + { | ||
| 267 | + return defaultValue; | ||
| 268 | + } | ||
| 269 | + try | ||
| 270 | + { | ||
| 271 | + return Integer.parseInt(valueStr.trim()); | ||
| 272 | + } | ||
| 273 | + catch (Exception e) | ||
| 274 | + { | ||
| 275 | + return defaultValue; | ||
| 276 | + } | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + /** | ||
| 280 | + * 转换为int<br> | ||
| 281 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 282 | + * 转换失败不会报错 | ||
| 283 | + * | ||
| 284 | + * @param value 被转换的值 | ||
| 285 | + * @return 结果 | ||
| 286 | + */ | ||
| 287 | + public static Integer toInt(Object value) | ||
| 288 | + { | ||
| 289 | + return toInt(value, null); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /** | ||
| 293 | + * 转换为Integer数组<br> | ||
| 294 | + * | ||
| 295 | + * @param str 被转换的值 | ||
| 296 | + * @return 结果 | ||
| 297 | + */ | ||
| 298 | + public static Integer[] toIntArray(String str) | ||
| 299 | + { | ||
| 300 | + return toIntArray(",", str); | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + /** | ||
| 304 | + * 转换为Long数组<br> | ||
| 305 | + * | ||
| 306 | + * @param str 被转换的值 | ||
| 307 | + * @return 结果 | ||
| 308 | + */ | ||
| 309 | + public static Long[] toLongArray(String str) | ||
| 310 | + { | ||
| 311 | + return toLongArray(",", str); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 转换为Integer数组<br> | ||
| 316 | + * | ||
| 317 | + * @param split 分隔符 | ||
| 318 | + * @param split 被转换的值 | ||
| 319 | + * @return 结果 | ||
| 320 | + */ | ||
| 321 | + public static Integer[] toIntArray(String split, String str) | ||
| 322 | + { | ||
| 323 | + if (StringUtils.isEmpty(str)) | ||
| 324 | + { | ||
| 325 | + return new Integer[] {}; | ||
| 326 | + } | ||
| 327 | + String[] arr = str.split(split); | ||
| 328 | + final Integer[] ints = new Integer[arr.length]; | ||
| 329 | + for (int i = 0; i < arr.length; i++) | ||
| 330 | + { | ||
| 331 | + final Integer v = toInt(arr[i], 0); | ||
| 332 | + ints[i] = v; | ||
| 333 | + } | ||
| 334 | + return ints; | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + /** | ||
| 338 | + * 转换为Long数组<br> | ||
| 339 | + * | ||
| 340 | + * @param split 分隔符 | ||
| 341 | + * @param str 被转换的值 | ||
| 342 | + * @return 结果 | ||
| 343 | + */ | ||
| 344 | + public static Long[] toLongArray(String split, String str) | ||
| 345 | + { | ||
| 346 | + if (StringUtils.isEmpty(str)) | ||
| 347 | + { | ||
| 348 | + return new Long[] {}; | ||
| 349 | + } | ||
| 350 | + String[] arr = str.split(split); | ||
| 351 | + final Long[] longs = new Long[arr.length]; | ||
| 352 | + for (int i = 0; i < arr.length; i++) | ||
| 353 | + { | ||
| 354 | + final Long v = toLong(arr[i], null); | ||
| 355 | + longs[i] = v; | ||
| 356 | + } | ||
| 357 | + return longs; | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + /** | ||
| 361 | + * 转换为String数组<br> | ||
| 362 | + * | ||
| 363 | + * @param str 被转换的值 | ||
| 364 | + * @return 结果 | ||
| 365 | + */ | ||
| 366 | + public static String[] toStrArray(String str) | ||
| 367 | + { | ||
| 368 | + return toStrArray(",", str); | ||
| 369 | + } | ||
| 370 | + | ||
| 371 | + /** | ||
| 372 | + * 转换为String数组<br> | ||
| 373 | + * | ||
| 374 | + * @param split 分隔符 | ||
| 375 | + * @param split 被转换的值 | ||
| 376 | + * @return 结果 | ||
| 377 | + */ | ||
| 378 | + public static String[] toStrArray(String split, String str) | ||
| 379 | + { | ||
| 380 | + return str.split(split); | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + /** | ||
| 384 | + * 转换为long<br> | ||
| 385 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 386 | + * 转换失败不会报错 | ||
| 387 | + * | ||
| 388 | + * @param value 被转换的值 | ||
| 389 | + * @param defaultValue 转换错误时的默认值 | ||
| 390 | + * @return 结果 | ||
| 391 | + */ | ||
| 392 | + public static Long toLong(Object value, Long defaultValue) | ||
| 393 | + { | ||
| 394 | + if (value == null) | ||
| 395 | + { | ||
| 396 | + return defaultValue; | ||
| 397 | + } | ||
| 398 | + if (value instanceof Long) | ||
| 399 | + { | ||
| 400 | + return (Long) value; | ||
| 401 | + } | ||
| 402 | + if (value instanceof Number) | ||
| 403 | + { | ||
| 404 | + return ((Number) value).longValue(); | ||
| 405 | + } | ||
| 406 | + final String valueStr = toStr(value, null); | ||
| 407 | + if (StringUtils.isEmpty(valueStr)) | ||
| 408 | + { | ||
| 409 | + return defaultValue; | ||
| 410 | + } | ||
| 411 | + try | ||
| 412 | + { | ||
| 413 | + // 支持科学计数法 | ||
| 414 | + return new BigDecimal(valueStr.trim()).longValue(); | ||
| 415 | + } | ||
| 416 | + catch (Exception e) | ||
| 417 | + { | ||
| 418 | + return defaultValue; | ||
| 419 | + } | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + /** | ||
| 423 | + * 转换为long<br> | ||
| 424 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 425 | + * 转换失败不会报错 | ||
| 426 | + * | ||
| 427 | + * @param value 被转换的值 | ||
| 428 | + * @return 结果 | ||
| 429 | + */ | ||
| 430 | + public static Long toLong(Object value) | ||
| 431 | + { | ||
| 432 | + return toLong(value, null); | ||
| 433 | + } | ||
| 434 | + | ||
| 435 | + /** | ||
| 436 | + * 转换为double<br> | ||
| 437 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 438 | + * 转换失败不会报错 | ||
| 439 | + * | ||
| 440 | + * @param value 被转换的值 | ||
| 441 | + * @param defaultValue 转换错误时的默认值 | ||
| 442 | + * @return 结果 | ||
| 443 | + */ | ||
| 444 | + public static Double toDouble(Object value, Double defaultValue) | ||
| 445 | + { | ||
| 446 | + if (value == null) | ||
| 447 | + { | ||
| 448 | + return defaultValue; | ||
| 449 | + } | ||
| 450 | + if (value instanceof Double) | ||
| 451 | + { | ||
| 452 | + return (Double) value; | ||
| 453 | + } | ||
| 454 | + if (value instanceof Number) | ||
| 455 | + { | ||
| 456 | + return ((Number) value).doubleValue(); | ||
| 457 | + } | ||
| 458 | + final String valueStr = toStr(value, null); | ||
| 459 | + if (StringUtils.isEmpty(valueStr)) | ||
| 460 | + { | ||
| 461 | + return defaultValue; | ||
| 462 | + } | ||
| 463 | + try | ||
| 464 | + { | ||
| 465 | + // 支持科学计数法 | ||
| 466 | + return new BigDecimal(valueStr.trim()).doubleValue(); | ||
| 467 | + } | ||
| 468 | + catch (Exception e) | ||
| 469 | + { | ||
| 470 | + return defaultValue; | ||
| 471 | + } | ||
| 472 | + } | ||
| 473 | + | ||
| 474 | + /** | ||
| 475 | + * 转换为double<br> | ||
| 476 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 477 | + * 转换失败不会报错 | ||
| 478 | + * | ||
| 479 | + * @param value 被转换的值 | ||
| 480 | + * @return 结果 | ||
| 481 | + */ | ||
| 482 | + public static Double toDouble(Object value) | ||
| 483 | + { | ||
| 484 | + return toDouble(value, null); | ||
| 485 | + } | ||
| 486 | + | ||
| 487 | + /** | ||
| 488 | + * 转换为Float<br> | ||
| 489 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 490 | + * 转换失败不会报错 | ||
| 491 | + * | ||
| 492 | + * @param value 被转换的值 | ||
| 493 | + * @param defaultValue 转换错误时的默认值 | ||
| 494 | + * @return 结果 | ||
| 495 | + */ | ||
| 496 | + public static Float toFloat(Object value, Float defaultValue) | ||
| 497 | + { | ||
| 498 | + if (value == null) | ||
| 499 | + { | ||
| 500 | + return defaultValue; | ||
| 501 | + } | ||
| 502 | + if (value instanceof Float) | ||
| 503 | + { | ||
| 504 | + return (Float) value; | ||
| 505 | + } | ||
| 506 | + if (value instanceof Number) | ||
| 507 | + { | ||
| 508 | + return ((Number) value).floatValue(); | ||
| 509 | + } | ||
| 510 | + final String valueStr = toStr(value, null); | ||
| 511 | + if (StringUtils.isEmpty(valueStr)) | ||
| 512 | + { | ||
| 513 | + return defaultValue; | ||
| 514 | + } | ||
| 515 | + try | ||
| 516 | + { | ||
| 517 | + return Float.parseFloat(valueStr.trim()); | ||
| 518 | + } | ||
| 519 | + catch (Exception e) | ||
| 520 | + { | ||
| 521 | + return defaultValue; | ||
| 522 | + } | ||
| 523 | + } | ||
| 524 | + | ||
| 525 | + /** | ||
| 526 | + * 转换为Float<br> | ||
| 527 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 528 | + * 转换失败不会报错 | ||
| 529 | + * | ||
| 530 | + * @param value 被转换的值 | ||
| 531 | + * @return 结果 | ||
| 532 | + */ | ||
| 533 | + public static Float toFloat(Object value) | ||
| 534 | + { | ||
| 535 | + return toFloat(value, null); | ||
| 536 | + } | ||
| 537 | + | ||
| 538 | + /** | ||
| 539 | + * 转换为boolean<br> | ||
| 540 | + * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 541 | + * 转换失败不会报错 | ||
| 542 | + * | ||
| 543 | + * @param value 被转换的值 | ||
| 544 | + * @param defaultValue 转换错误时的默认值 | ||
| 545 | + * @return 结果 | ||
| 546 | + */ | ||
| 547 | + public static Boolean toBool(Object value, Boolean defaultValue) | ||
| 548 | + { | ||
| 549 | + if (value == null) | ||
| 550 | + { | ||
| 551 | + return defaultValue; | ||
| 552 | + } | ||
| 553 | + if (value instanceof Boolean) | ||
| 554 | + { | ||
| 555 | + return (Boolean) value; | ||
| 556 | + } | ||
| 557 | + String valueStr = toStr(value, null); | ||
| 558 | + if (StringUtils.isEmpty(valueStr)) | ||
| 559 | + { | ||
| 560 | + return defaultValue; | ||
| 561 | + } | ||
| 562 | + valueStr = valueStr.trim().toLowerCase(); | ||
| 563 | + switch (valueStr) | ||
| 564 | + { | ||
| 565 | + case "true": | ||
| 566 | + return true; | ||
| 567 | + case "false": | ||
| 568 | + return false; | ||
| 569 | + case "yes": | ||
| 570 | + return true; | ||
| 571 | + case "ok": | ||
| 572 | + return true; | ||
| 573 | + case "no": | ||
| 574 | + return false; | ||
| 575 | + case "1": | ||
| 576 | + return true; | ||
| 577 | + case "0": | ||
| 578 | + return false; | ||
| 579 | + default: | ||
| 580 | + return defaultValue; | ||
| 581 | + } | ||
| 582 | + } | ||
| 583 | + | ||
| 584 | + /** | ||
| 585 | + * 转换为boolean<br> | ||
| 586 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 587 | + * 转换失败不会报错 | ||
| 588 | + * | ||
| 589 | + * @param value 被转换的值 | ||
| 590 | + * @return 结果 | ||
| 591 | + */ | ||
| 592 | + public static Boolean toBool(Object value) | ||
| 593 | + { | ||
| 594 | + return toBool(value, null); | ||
| 595 | + } | ||
| 596 | + | ||
| 597 | + /** | ||
| 598 | + * 转换为Enum对象<br> | ||
| 599 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 600 | + * | ||
| 601 | + * @param clazz Enum的Class | ||
| 602 | + * @param value 值 | ||
| 603 | + * @param defaultValue 默认值 | ||
| 604 | + * @return Enum | ||
| 605 | + */ | ||
| 606 | + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) | ||
| 607 | + { | ||
| 608 | + if (value == null) | ||
| 609 | + { | ||
| 610 | + return defaultValue; | ||
| 611 | + } | ||
| 612 | + if (clazz.isAssignableFrom(value.getClass())) | ||
| 613 | + { | ||
| 614 | + @SuppressWarnings("unchecked") | ||
| 615 | + E myE = (E) value; | ||
| 616 | + return myE; | ||
| 617 | + } | ||
| 618 | + final String valueStr = toStr(value, null); | ||
| 619 | + if (StringUtils.isEmpty(valueStr)) | ||
| 620 | + { | ||
| 621 | + return defaultValue; | ||
| 622 | + } | ||
| 623 | + try | ||
| 624 | + { | ||
| 625 | + return Enum.valueOf(clazz, valueStr); | ||
| 626 | + } | ||
| 627 | + catch (Exception e) | ||
| 628 | + { | ||
| 629 | + return defaultValue; | ||
| 630 | + } | ||
| 631 | + } | ||
| 632 | + | ||
| 633 | + /** | ||
| 634 | + * 转换为Enum对象<br> | ||
| 635 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 636 | + * | ||
| 637 | + * @param clazz Enum的Class | ||
| 638 | + * @param value 值 | ||
| 639 | + * @return Enum | ||
| 640 | + */ | ||
| 641 | + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) | ||
| 642 | + { | ||
| 643 | + return toEnum(clazz, value, null); | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + /** | ||
| 647 | + * 转换为BigInteger<br> | ||
| 648 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 649 | + * 转换失败不会报错 | ||
| 650 | + * | ||
| 651 | + * @param value 被转换的值 | ||
| 652 | + * @param defaultValue 转换错误时的默认值 | ||
| 653 | + * @return 结果 | ||
| 654 | + */ | ||
| 655 | + public static BigInteger toBigInteger(Object value, BigInteger defaultValue) | ||
| 656 | + { | ||
| 657 | + if (value == null) | ||
| 658 | + { | ||
| 659 | + return defaultValue; | ||
| 660 | + } | ||
| 661 | + if (value instanceof BigInteger) | ||
| 662 | + { | ||
| 663 | + return (BigInteger) value; | ||
| 664 | + } | ||
| 665 | + if (value instanceof Long) | ||
| 666 | + { | ||
| 667 | + return BigInteger.valueOf((Long) value); | ||
| 668 | + } | ||
| 669 | + final String valueStr = toStr(value, null); | ||
| 670 | + if (StringUtils.isEmpty(valueStr)) | ||
| 671 | + { | ||
| 672 | + return defaultValue; | ||
| 673 | + } | ||
| 674 | + try | ||
| 675 | + { | ||
| 676 | + return new BigInteger(valueStr); | ||
| 677 | + } | ||
| 678 | + catch (Exception e) | ||
| 679 | + { | ||
| 680 | + return defaultValue; | ||
| 681 | + } | ||
| 682 | + } | ||
| 683 | + | ||
| 684 | + /** | ||
| 685 | + * 转换为BigInteger<br> | ||
| 686 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 687 | + * 转换失败不会报错 | ||
| 688 | + * | ||
| 689 | + * @param value 被转换的值 | ||
| 690 | + * @return 结果 | ||
| 691 | + */ | ||
| 692 | + public static BigInteger toBigInteger(Object value) | ||
| 693 | + { | ||
| 694 | + return toBigInteger(value, null); | ||
| 695 | + } | ||
| 696 | + | ||
| 697 | + /** | ||
| 698 | + * 转换为BigDecimal<br> | ||
| 699 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 700 | + * 转换失败不会报错 | ||
| 701 | + * | ||
| 702 | + * @param value 被转换的值 | ||
| 703 | + * @param defaultValue 转换错误时的默认值 | ||
| 704 | + * @return 结果 | ||
| 705 | + */ | ||
| 706 | + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) | ||
| 707 | + { | ||
| 708 | + if (value == null) | ||
| 709 | + { | ||
| 710 | + return defaultValue; | ||
| 711 | + } | ||
| 712 | + if (value instanceof BigDecimal) | ||
| 713 | + { | ||
| 714 | + return (BigDecimal) value; | ||
| 715 | + } | ||
| 716 | + if (value instanceof Long) | ||
| 717 | + { | ||
| 718 | + return new BigDecimal((Long) value); | ||
| 719 | + } | ||
| 720 | + if (value instanceof Double) | ||
| 721 | + { | ||
| 722 | + return new BigDecimal((Double) value); | ||
| 723 | + } | ||
| 724 | + if (value instanceof Integer) | ||
| 725 | + { | ||
| 726 | + return new BigDecimal((Integer) value); | ||
| 727 | + } | ||
| 728 | + final String valueStr = toStr(value, null); | ||
| 729 | + if (StringUtils.isEmpty(valueStr)) | ||
| 730 | + { | ||
| 731 | + return defaultValue; | ||
| 732 | + } | ||
| 733 | + try | ||
| 734 | + { | ||
| 735 | + return new BigDecimal(valueStr); | ||
| 736 | + } | ||
| 737 | + catch (Exception e) | ||
| 738 | + { | ||
| 739 | + return defaultValue; | ||
| 740 | + } | ||
| 741 | + } | ||
| 742 | + | ||
| 743 | + /** | ||
| 744 | + * 转换为BigDecimal<br> | ||
| 745 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 746 | + * 转换失败不会报错 | ||
| 747 | + * | ||
| 748 | + * @param value 被转换的值 | ||
| 749 | + * @return 结果 | ||
| 750 | + */ | ||
| 751 | + public static BigDecimal toBigDecimal(Object value) | ||
| 752 | + { | ||
| 753 | + return toBigDecimal(value, null); | ||
| 754 | + } | ||
| 755 | + | ||
| 756 | + /** | ||
| 757 | + * 将对象转为字符串<br> | ||
| 758 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 759 | + * | ||
| 760 | + * @param obj 对象 | ||
| 761 | + * @return 字符串 | ||
| 762 | + */ | ||
| 763 | + public static String utf8Str(Object obj) | ||
| 764 | + { | ||
| 765 | + return str(obj, CharsetKit.CHARSET_UTF_8); | ||
| 766 | + } | ||
| 767 | + | ||
| 768 | + /** | ||
| 769 | + * 将对象转为字符串<br> | ||
| 770 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 771 | + * | ||
| 772 | + * @param obj 对象 | ||
| 773 | + * @param charsetName 字符集 | ||
| 774 | + * @return 字符串 | ||
| 775 | + */ | ||
| 776 | + public static String str(Object obj, String charsetName) | ||
| 777 | + { | ||
| 778 | + return str(obj, Charset.forName(charsetName)); | ||
| 779 | + } | ||
| 780 | + | ||
| 781 | + /** | ||
| 782 | + * 将对象转为字符串<br> | ||
| 783 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 784 | + * | ||
| 785 | + * @param obj 对象 | ||
| 786 | + * @param charset 字符集 | ||
| 787 | + * @return 字符串 | ||
| 788 | + */ | ||
| 789 | + public static String str(Object obj, Charset charset) | ||
| 790 | + { | ||
| 791 | + if (null == obj) | ||
| 792 | + { | ||
| 793 | + return null; | ||
| 794 | + } | ||
| 795 | + | ||
| 796 | + if (obj instanceof String) | ||
| 797 | + { | ||
| 798 | + return (String) obj; | ||
| 799 | + } | ||
| 800 | + else if (obj instanceof byte[]) | ||
| 801 | + { | ||
| 802 | + return str((byte[]) obj, charset); | ||
| 803 | + } | ||
| 804 | + else if (obj instanceof Byte[]) | ||
| 805 | + { | ||
| 806 | + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); | ||
| 807 | + return str(bytes, charset); | ||
| 808 | + } | ||
| 809 | + else if (obj instanceof ByteBuffer) | ||
| 810 | + { | ||
| 811 | + return str((ByteBuffer) obj, charset); | ||
| 812 | + } | ||
| 813 | + return obj.toString(); | ||
| 814 | + } | ||
| 815 | + | ||
| 816 | + /** | ||
| 817 | + * 将byte数组转为字符串 | ||
| 818 | + * | ||
| 819 | + * @param bytes byte数组 | ||
| 820 | + * @param charset 字符集 | ||
| 821 | + * @return 字符串 | ||
| 822 | + */ | ||
| 823 | + public static String str(byte[] bytes, String charset) | ||
| 824 | + { | ||
| 825 | + return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); | ||
| 826 | + } | ||
| 827 | + | ||
| 828 | + /** | ||
| 829 | + * 解码字节码 | ||
| 830 | + * | ||
| 831 | + * @param data 字符串 | ||
| 832 | + * @param charset 字符集,如果此字段为空,则解码的结果取决于平台 | ||
| 833 | + * @return 解码后的字符串 | ||
| 834 | + */ | ||
| 835 | + public static String str(byte[] data, Charset charset) | ||
| 836 | + { | ||
| 837 | + if (data == null) | ||
| 838 | + { | ||
| 839 | + return null; | ||
| 840 | + } | ||
| 841 | + | ||
| 842 | + if (null == charset) | ||
| 843 | + { | ||
| 844 | + return new String(data); | ||
| 845 | + } | ||
| 846 | + return new String(data, charset); | ||
| 847 | + } | ||
| 848 | + | ||
| 849 | + /** | ||
| 850 | + * 将编码的byteBuffer数据转换为字符串 | ||
| 851 | + * | ||
| 852 | + * @param data 数据 | ||
| 853 | + * @param charset 字符集,如果为空使用当前系统字符集 | ||
| 854 | + * @return 字符串 | ||
| 855 | + */ | ||
| 856 | + public static String str(ByteBuffer data, String charset) | ||
| 857 | + { | ||
| 858 | + if (data == null) | ||
| 859 | + { | ||
| 860 | + return null; | ||
| 861 | + } | ||
| 862 | + | ||
| 863 | + return str(data, Charset.forName(charset)); | ||
| 864 | + } | ||
| 865 | + | ||
| 866 | + /** | ||
| 867 | + * 将编码的byteBuffer数据转换为字符串 | ||
| 868 | + * | ||
| 869 | + * @param data 数据 | ||
| 870 | + * @param charset 字符集,如果为空使用当前系统字符集 | ||
| 871 | + * @return 字符串 | ||
| 872 | + */ | ||
| 873 | + public static String str(ByteBuffer data, Charset charset) | ||
| 874 | + { | ||
| 875 | + if (null == charset) | ||
| 876 | + { | ||
| 877 | + charset = Charset.defaultCharset(); | ||
| 878 | + } | ||
| 879 | + return charset.decode(data).toString(); | ||
| 880 | + } | ||
| 881 | + | ||
| 882 | + // ----------------------------------------------------------------------- 全角半角转换 | ||
| 883 | + /** | ||
| 884 | + * 半角转全角 | ||
| 885 | + * | ||
| 886 | + * @param input String. | ||
| 887 | + * @return 全角字符串. | ||
| 888 | + */ | ||
| 889 | + public static String toSBC(String input) | ||
| 890 | + { | ||
| 891 | + return toSBC(input, null); | ||
| 892 | + } | ||
| 893 | + | ||
| 894 | + /** | ||
| 895 | + * 半角转全角 | ||
| 896 | + * | ||
| 897 | + * @param input String | ||
| 898 | + * @param notConvertSet 不替换的字符集合 | ||
| 899 | + * @return 全角字符串. | ||
| 900 | + */ | ||
| 901 | + public static String toSBC(String input, Set<Character> notConvertSet) | ||
| 902 | + { | ||
| 903 | + char c[] = input.toCharArray(); | ||
| 904 | + for (int i = 0; i < c.length; i++) | ||
| 905 | + { | ||
| 906 | + if (null != notConvertSet && notConvertSet.contains(c[i])) | ||
| 907 | + { | ||
| 908 | + // 跳过不替换的字符 | ||
| 909 | + continue; | ||
| 910 | + } | ||
| 911 | + | ||
| 912 | + if (c[i] == ' ') | ||
| 913 | + { | ||
| 914 | + c[i] = '\u3000'; | ||
| 915 | + } | ||
| 916 | + else if (c[i] < '\177') | ||
| 917 | + { | ||
| 918 | + c[i] = (char) (c[i] + 65248); | ||
| 919 | + | ||
| 920 | + } | ||
| 921 | + } | ||
| 922 | + return new String(c); | ||
| 923 | + } | ||
| 924 | + | ||
| 925 | + /** | ||
| 926 | + * 全角转半角 | ||
| 927 | + * | ||
| 928 | + * @param input String. | ||
| 929 | + * @return 半角字符串 | ||
| 930 | + */ | ||
| 931 | + public static String toDBC(String input) | ||
| 932 | + { | ||
| 933 | + return toDBC(input, null); | ||
| 934 | + } | ||
| 935 | + | ||
| 936 | + /** | ||
| 937 | + * 替换全角为半角 | ||
| 938 | + * | ||
| 939 | + * @param text 文本 | ||
| 940 | + * @param notConvertSet 不替换的字符集合 | ||
| 941 | + * @return 替换后的字符 | ||
| 942 | + */ | ||
| 943 | + public static String toDBC(String text, Set<Character> notConvertSet) | ||
| 944 | + { | ||
| 945 | + char c[] = text.toCharArray(); | ||
| 946 | + for (int i = 0; i < c.length; i++) | ||
| 947 | + { | ||
| 948 | + if (null != notConvertSet && notConvertSet.contains(c[i])) | ||
| 949 | + { | ||
| 950 | + // 跳过不替换的字符 | ||
| 951 | + continue; | ||
| 952 | + } | ||
| 953 | + | ||
| 954 | + if (c[i] == '\u3000') | ||
| 955 | + { | ||
| 956 | + c[i] = ' '; | ||
| 957 | + } | ||
| 958 | + else if (c[i] > '\uFF00' && c[i] < '\uFF5F') | ||
| 959 | + { | ||
| 960 | + c[i] = (char) (c[i] - 65248); | ||
| 961 | + } | ||
| 962 | + } | ||
| 963 | + String returnString = new String(c); | ||
| 964 | + | ||
| 965 | + return returnString; | ||
| 966 | + } | ||
| 967 | + | ||
| 968 | + /** | ||
| 969 | + * 数字金额大写转换 先写个完整的然后将如零拾替换成零 | ||
| 970 | + * | ||
| 971 | + * @param n 数字 | ||
| 972 | + * @return 中文大写数字 | ||
| 973 | + */ | ||
| 974 | + public static String digitUppercase(double n) | ||
| 975 | + { | ||
| 976 | + String[] fraction = { "角", "分" }; | ||
| 977 | + String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; | ||
| 978 | + String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } }; | ||
| 979 | + | ||
| 980 | + String head = n < 0 ? "负" : ""; | ||
| 981 | + n = Math.abs(n); | ||
| 982 | + | ||
| 983 | + String s = ""; | ||
| 984 | + for (int i = 0; i < fraction.length; i++) | ||
| 985 | + { | ||
| 986 | + s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", ""); | ||
| 987 | + } | ||
| 988 | + if (s.length() < 1) | ||
| 989 | + { | ||
| 990 | + s = "整"; | ||
| 991 | + } | ||
| 992 | + int integerPart = (int) Math.floor(n); | ||
| 993 | + | ||
| 994 | + for (int i = 0; i < unit[0].length && integerPart > 0; i++) | ||
| 995 | + { | ||
| 996 | + String p = ""; | ||
| 997 | + for (int j = 0; j < unit[1].length && n > 0; j++) | ||
| 998 | + { | ||
| 999 | + p = digit[integerPart % 10] + unit[1][j] + p; | ||
| 1000 | + integerPart = integerPart / 10; | ||
| 1001 | + } | ||
| 1002 | + s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s; | ||
| 1003 | + } | ||
| 1004 | + return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整"); | ||
| 1005 | + } | ||
| 1006 | +} |
| 1 | +package com.ruoyi.common.core.text; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.StringUtils; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 字符串格式化 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +public class StrFormatter | ||
| 11 | +{ | ||
| 12 | + public static final String EMPTY_JSON = "{}"; | ||
| 13 | + public static final char C_BACKSLASH = '\\'; | ||
| 14 | + public static final char C_DELIM_START = '{'; | ||
| 15 | + public static final char C_DELIM_END = '}'; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 格式化字符串<br> | ||
| 19 | + * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> | ||
| 20 | + * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> | ||
| 21 | + * 例:<br> | ||
| 22 | + * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> | ||
| 23 | + * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> | ||
| 24 | + * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> | ||
| 25 | + * | ||
| 26 | + * @param strPattern 字符串模板 | ||
| 27 | + * @param argArray 参数列表 | ||
| 28 | + * @return 结果 | ||
| 29 | + */ | ||
| 30 | + public static String format(final String strPattern, final Object... argArray) | ||
| 31 | + { | ||
| 32 | + if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) | ||
| 33 | + { | ||
| 34 | + return strPattern; | ||
| 35 | + } | ||
| 36 | + final int strPatternLength = strPattern.length(); | ||
| 37 | + | ||
| 38 | + // 初始化定义好的长度以获得更好的性能 | ||
| 39 | + StringBuilder sbuf = new StringBuilder(strPatternLength + 50); | ||
| 40 | + | ||
| 41 | + int handledPosition = 0; | ||
| 42 | + int delimIndex;// 占位符所在位置 | ||
| 43 | + for (int argIndex = 0; argIndex < argArray.length; argIndex++) | ||
| 44 | + { | ||
| 45 | + delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); | ||
| 46 | + if (delimIndex == -1) | ||
| 47 | + { | ||
| 48 | + if (handledPosition == 0) | ||
| 49 | + { | ||
| 50 | + return strPattern; | ||
| 51 | + } | ||
| 52 | + else | ||
| 53 | + { // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果 | ||
| 54 | + sbuf.append(strPattern, handledPosition, strPatternLength); | ||
| 55 | + return sbuf.toString(); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + else | ||
| 59 | + { | ||
| 60 | + if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) | ||
| 61 | + { | ||
| 62 | + if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) | ||
| 63 | + { | ||
| 64 | + // 转义符之前还有一个转义符,占位符依旧有效 | ||
| 65 | + sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
| 66 | + sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
| 67 | + handledPosition = delimIndex + 2; | ||
| 68 | + } | ||
| 69 | + else | ||
| 70 | + { | ||
| 71 | + // 占位符被转义 | ||
| 72 | + argIndex--; | ||
| 73 | + sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
| 74 | + sbuf.append(C_DELIM_START); | ||
| 75 | + handledPosition = delimIndex + 1; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + else | ||
| 79 | + { | ||
| 80 | + // 正常占位符 | ||
| 81 | + sbuf.append(strPattern, handledPosition, delimIndex); | ||
| 82 | + sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
| 83 | + handledPosition = delimIndex + 2; | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + // 加入最后一个占位符后所有的字符 | ||
| 88 | + sbuf.append(strPattern, handledPosition, strPattern.length()); | ||
| 89 | + | ||
| 90 | + return sbuf.toString(); | ||
| 91 | + } | ||
| 92 | +} |
| 1 | +package com.ruoyi.common.enums; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 业务操作类型 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public enum BusinessType | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * 其它 | ||
| 12 | + */ | ||
| 13 | + OTHER, | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 新增 | ||
| 17 | + */ | ||
| 18 | + INSERT, | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 修改 | ||
| 22 | + */ | ||
| 23 | + UPDATE, | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 删除 | ||
| 27 | + */ | ||
| 28 | + DELETE, | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 授权 | ||
| 32 | + */ | ||
| 33 | + GRANT, | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 导出 | ||
| 37 | + */ | ||
| 38 | + EXPORT, | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 导入 | ||
| 42 | + */ | ||
| 43 | + IMPORT, | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 强退 | ||
| 47 | + */ | ||
| 48 | + FORCE, | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 生成代码 | ||
| 52 | + */ | ||
| 53 | + GENCODE, | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 清空数据 | ||
| 57 | + */ | ||
| 58 | + CLEAN, | ||
| 59 | +} |
| 1 | +package com.ruoyi.common.enums; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | +import org.springframework.lang.Nullable; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 请求方式 | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + */ | ||
| 12 | +public enum HttpMethod | ||
| 13 | +{ | ||
| 14 | + GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; | ||
| 15 | + | ||
| 16 | + private static final Map<String, HttpMethod> mappings = new HashMap<>(16); | ||
| 17 | + | ||
| 18 | + static | ||
| 19 | + { | ||
| 20 | + for (HttpMethod httpMethod : values()) | ||
| 21 | + { | ||
| 22 | + mappings.put(httpMethod.name(), httpMethod); | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Nullable | ||
| 27 | + public static HttpMethod resolve(@Nullable String method) | ||
| 28 | + { | ||
| 29 | + return (method != null ? mappings.get(method) : null); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public boolean matches(String method) | ||
| 33 | + { | ||
| 34 | + return (this == resolve(method)); | ||
| 35 | + } | ||
| 36 | +} |
| 1 | +package com.ruoyi.common.enums; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 用户状态 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public enum UserStatus | ||
| 9 | +{ | ||
| 10 | + OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除"); | ||
| 11 | + | ||
| 12 | + private final String code; | ||
| 13 | + private final String info; | ||
| 14 | + | ||
| 15 | + UserStatus(String code, String info) | ||
| 16 | + { | ||
| 17 | + this.code = code; | ||
| 18 | + this.info = info; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public String getCode() | ||
| 22 | + { | ||
| 23 | + return code; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public String getInfo() | ||
| 27 | + { | ||
| 28 | + return info; | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package com.ruoyi.common.exception; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.ruoyi.common.annotation.PublicSQLConfig; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 演示模式异常 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public class DemoModeException extends RuntimeException | ||
| 12 | +{ | ||
| 13 | + @PublicSQLConfig(isSelect=false) | ||
| 14 | + private static final long serialVersionUID = 1L; | ||
| 15 | + | ||
| 16 | + public DemoModeException() | ||
| 17 | + { | ||
| 18 | + } | ||
| 19 | +} |
| 1 | +package com.ruoyi.common.exception; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.ruoyi.common.annotation.PublicSQLConfig; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 全局异常 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public class GlobalException extends RuntimeException | ||
| 12 | +{ | ||
| 13 | + @PublicSQLConfig(isSelect=false) | ||
| 14 | + private static final long serialVersionUID = 1L; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 错误提示 | ||
| 18 | + */ | ||
| 19 | + private String message; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 错误明细,内部调试错误 | ||
| 23 | + * | ||
| 24 | + * 和 {@link CommonResult#getDetailMessage()} 一致的设计 | ||
| 25 | + */ | ||
| 26 | + private String detailMessage; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 空构造方法,避免反序列化问题 | ||
| 30 | + */ | ||
| 31 | + public GlobalException() | ||
| 32 | + { | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public GlobalException(String message) | ||
| 36 | + { | ||
| 37 | + this.message = message; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public String getDetailMessage() | ||
| 41 | + { | ||
| 42 | + return detailMessage; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public GlobalException setDetailMessage(String detailMessage) | ||
| 46 | + { | ||
| 47 | + this.detailMessage = detailMessage; | ||
| 48 | + return this; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public String getMessage() | ||
| 52 | + { | ||
| 53 | + return message; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public GlobalException setMessage(String message) | ||
| 57 | + { | ||
| 58 | + this.message = message; | ||
| 59 | + return this; | ||
| 60 | + } | ||
| 61 | +} |
| 1 | +package com.ruoyi.common.exception; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.ruoyi.common.annotation.PublicSQLConfig; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 业务异常 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public final class ServiceException extends RuntimeException | ||
| 12 | +{ | ||
| 13 | + @PublicSQLConfig(isSelect=false) | ||
| 14 | + private static final long serialVersionUID = 1L; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 错误码 | ||
| 18 | + */ | ||
| 19 | + private Integer code; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 错误提示 | ||
| 23 | + */ | ||
| 24 | + private String message; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 错误明细,内部调试错误 | ||
| 28 | + * | ||
| 29 | + * 和 {@link CommonResult#getDetailMessage()} 一致的设计 | ||
| 30 | + */ | ||
| 31 | + private String detailMessage; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 空构造方法,避免反序列化问题 | ||
| 35 | + */ | ||
| 36 | + public ServiceException() | ||
| 37 | + { | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public ServiceException(String message) | ||
| 41 | + { | ||
| 42 | + this.message = message; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public ServiceException(String message, Integer code) | ||
| 46 | + { | ||
| 47 | + this.message = message; | ||
| 48 | + this.code = code; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public String getDetailMessage() | ||
| 52 | + { | ||
| 53 | + return detailMessage; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getMessage() | ||
| 57 | + { | ||
| 58 | + return message; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public Integer getCode() | ||
| 62 | + { | ||
| 63 | + return code; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public ServiceException setMessage(String message) | ||
| 67 | + { | ||
| 68 | + this.message = message; | ||
| 69 | + return this; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public ServiceException setDetailMessage(String detailMessage) | ||
| 73 | + { | ||
| 74 | + this.detailMessage = detailMessage; | ||
| 75 | + return this; | ||
| 76 | + } | ||
| 77 | +} |
| 1 | +package com.ruoyi.common.exception; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 工具类异常 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class UtilException extends RuntimeException | ||
| 9 | +{ | ||
| 10 | + private static final long serialVersionUID = 8247610319171014183L; | ||
| 11 | + | ||
| 12 | + public UtilException(Throwable e) | ||
| 13 | + { | ||
| 14 | + super(e.getMessage(), e); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public UtilException(String message) | ||
| 18 | + { | ||
| 19 | + super(message); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public UtilException(String message, Throwable throwable) | ||
| 23 | + { | ||
| 24 | + super(message, throwable); | ||
| 25 | + } | ||
| 26 | +} |
-
请 注册 或 登录 后发表评论