Compare commits

...

2 Commits

Author SHA1 Message Date
huzhengkao cf9eb6a75a 修改 2025-10-21 14:21:49 +08:00
huzhengkao 07e797d498 nacos配置修改 2025-10-21 14:18:39 +08:00
61 changed files with 863 additions and 1422 deletions

12
pom.xml
View File

@ -38,16 +38,6 @@
<tomcat.version>9.0.102</tomcat.version> <tomcat.version>9.0.102</tomcat.version>
<logback.version>1.2.13</logback.version> <logback.version>1.2.13</logback.version>
<spring-framework.version>5.3.39</spring-framework.version> <spring-framework.version>5.3.39</spring-framework.version>
<lombok.version>1.18.36</lombok.version>
<mybatis-plus-boot-starter.version>3.5.1</mybatis-plus-boot-starter.version>
<mybatis-plus-join-boot-starter.version>1.5.0</mybatis-plus-join-boot-starter.version>
<artemis-http-client.version>1.1.3</artemis-http-client.version>
<mybatis-plus-annotation.version>3.5.3.1</mybatis-plus-annotation.version>
<mybatis-plus-core.version>3.5.3.1</mybatis-plus-core.version>
<mybatis-plus-extension.version>3.5.3.1</mybatis-plus-extension.version>
<hutool-all.version>5.1.0</hutool-all.version>
<jna.version>5.15.0</jna.version>
<org.eclipse.paho.client.mqttv3.version>1.2.5</org.eclipse.paho.client.mqttv3.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
@ -366,7 +356,7 @@
<!-- 环境标识,需要与配置文件的名称相对应 --> <!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>test</profiles.active> <profiles.active>test</profiles.active>
<nacos.username>nacos</nacos.username> <nacos.username>nacos</nacos.username>
<nacos.password>nacos123456</nacos.password> <nacos.password>jRrQh3w6A123</nacos.password>
</properties> </properties>
<activation> <activation>
<!-- 默认环境 --> <!-- 默认环境 -->

View File

@ -10,7 +10,6 @@
<modules> <modules>
<module>tcctyn-api-system</module> <module>tcctyn-api-system</module>
<module>tcctyn-api-iot</module>
</modules> </modules>
<artifactId>tcctyn-api</artifactId> <artifactId>tcctyn-api</artifactId>

View File

@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.tcctyn.common.core.constant.ServiceNameConstants; import com.tcctyn.common.core.constant.ServiceNameConstants;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.domain.SysFile; import com.tcctyn.system.api.domain.SysFile;
import com.tcctyn.system.api.factory.RemoteFileFallbackFactory; import com.tcctyn.system.api.factory.RemoteFileFallbackFactory;

View File

@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import com.tcctyn.common.core.constant.SecurityConstants; import com.tcctyn.common.core.constant.SecurityConstants;
import com.tcctyn.common.core.constant.ServiceNameConstants; import com.tcctyn.common.core.constant.ServiceNameConstants;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.domain.SysLogininfor; import com.tcctyn.system.api.domain.SysLogininfor;
import com.tcctyn.system.api.domain.SysOperLog; import com.tcctyn.system.api.domain.SysOperLog;
import com.tcctyn.system.api.factory.RemoteLogFallbackFactory; import com.tcctyn.system.api.factory.RemoteLogFallbackFactory;

View File

@ -1,16 +1,18 @@
package com.tcctyn.system.api; package com.tcctyn.system.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import com.tcctyn.common.core.constant.SecurityConstants; import com.tcctyn.common.core.constant.SecurityConstants;
import com.tcctyn.common.core.constant.ServiceNameConstants; import com.tcctyn.common.core.constant.ServiceNameConstants;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.domain.SysDept;
import com.tcctyn.system.api.domain.SysUser; import com.tcctyn.system.api.domain.SysUser;
import com.tcctyn.system.api.factory.RemoteUserFallbackFactory; import com.tcctyn.system.api.factory.RemoteUserFallbackFactory;
import com.tcctyn.system.api.model.LoginUser; import com.tcctyn.system.api.model.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 用户服务 * 用户服务
@ -27,7 +29,7 @@ public interface RemoteUserService
* @param source 请求来源 * @param source 请求来源
* @return 结果 * @return 结果
*/ */
@GetMapping("/system/user/info/{username}") @GetMapping("/user/info/{username}")
public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** /**
@ -37,7 +39,7 @@ public interface RemoteUserService
* @param source 请求来源 * @param source 请求来源
* @return 结果 * @return 结果
*/ */
@PostMapping("/system/user/register") @PostMapping("/user/register")
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** /**
@ -47,47 +49,6 @@ public interface RemoteUserService
* @param source 请求来源 * @param source 请求来源
* @return 结果 * @return 结果
*/ */
@PutMapping("/system/user/recordlogin") @PutMapping("/user/recordlogin")
public R<Boolean> recordUserLogin(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<Boolean> recordUserLogin(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 通过用户ID查询用户
*
* @return 结果
*/
@PostMapping("/system/user/selectUserById/{userId}")
public R<SysUser> selectUserById(@PathVariable("userId") Long userId);
/**
* 通过条件查询查询用户列表
*
* @param sysUser 用户信息
* @return 结果
*/
@PostMapping("/system/user/selectUserList")
public R<List<SysUser>> selectUserList(@RequestBody SysUser sysUser);
/**
* 获取用户列表用于前端选择器
* @param regionId 归属地区id
* @return
*/
@GetMapping("/system/user/userNames/{regionId}")
public R<List<SysUser>> selectUserByRegionIdList(@PathVariable("regionId") Long regionId) ;
/**
* 通过用户ID查询用户
*
* @return 结果
*/
@PostMapping("/system/dept/selectDeptById/{deptId}")
public R<SysDept> selectDeptById(@PathVariable("deptId") Long deptId);
/**
* 通过条件查询查询用户列表
*
* @return 结果
*/
@PostMapping("/system/dept/selectDeptList")
public R<List<SysDept>> selectDeptList(@RequestBody SysDept sysDept);
} }

View File

@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.RemoteFileService; import com.tcctyn.system.api.RemoteFileService;
import com.tcctyn.system.api.domain.SysFile; import com.tcctyn.system.api.domain.SysFile;

View File

@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.RemoteLogService; import com.tcctyn.system.api.RemoteLogService;
import com.tcctyn.system.api.domain.SysLogininfor; import com.tcctyn.system.api.domain.SysLogininfor;
import com.tcctyn.system.api.domain.SysOperLog; import com.tcctyn.system.api.domain.SysOperLog;

View File

@ -1,17 +1,14 @@
package com.tcctyn.system.api.factory; package com.tcctyn.system.api.factory;
import com.tcctyn.system.api.domain.SysDept;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.system.api.RemoteUserService; import com.tcctyn.system.api.RemoteUserService;
import com.tcctyn.system.api.domain.SysUser; import com.tcctyn.system.api.domain.SysUser;
import com.tcctyn.system.api.model.LoginUser; import com.tcctyn.system.api.model.LoginUser;
import java.util.List;
/** /**
* 用户服务降级处理 * 用户服务降级处理
* *
@ -45,31 +42,6 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
{ {
return R.fail("记录用户登录信息失败:" + throwable.getMessage()); return R.fail("记录用户登录信息失败:" + throwable.getMessage());
} }
@Override
public R<SysUser> selectUserById(Long userId) {
return R.fail("获取用户信息失败:" + throwable.getMessage());
}
@Override
public R<List<SysUser>> selectUserList(SysUser sysUser) {
return R.fail("获取用户信息列表失败:" + throwable.getMessage());
}
@Override
public R<List<SysUser>> selectUserByRegionIdList(Long regionId) {
return R.fail("获取用户区域id失败:" + throwable.getMessage());
}
@Override
public R<SysDept> selectDeptById(Long deptId) {
return R.fail("获取部门信息失败:" + throwable.getMessage());
}
@Override
public R<List<SysDept>> selectDeptList(SysDept sysDept) {
return R.fail("获取部门信息列表失败:" + throwable.getMessage());
}
}; };
} }
} }

View File

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.tcctyn.auth.form.LoginBody; import com.tcctyn.auth.form.LoginBody;
import com.tcctyn.auth.form.RegisterBody; import com.tcctyn.auth.form.RegisterBody;
import com.tcctyn.auth.service.SysLoginService; import com.tcctyn.auth.service.SysLoginService;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.utils.JwtUtils; import com.tcctyn.common.core.utils.JwtUtils;
import com.tcctyn.common.core.utils.StringUtils; import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.security.auth.AuthUtil; import com.tcctyn.common.security.auth.AuthUtil;

View File

@ -6,7 +6,7 @@ import com.tcctyn.common.core.constant.CacheConstants;
import com.tcctyn.common.core.constant.Constants; import com.tcctyn.common.core.constant.Constants;
import com.tcctyn.common.core.constant.SecurityConstants; import com.tcctyn.common.core.constant.SecurityConstants;
import com.tcctyn.common.core.constant.UserConstants; import com.tcctyn.common.core.constant.UserConstants;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.enums.UserStatus; import com.tcctyn.common.core.enums.UserStatus;
import com.tcctyn.common.core.exception.ServiceException; import com.tcctyn.common.core.exception.ServiceException;
import com.tcctyn.common.core.text.Convert; import com.tcctyn.common.core.text.Convert;

View File

@ -111,33 +111,6 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
<version>${mybatis-plus-annotation.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${org.eclipse.paho.client.mqttv3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool-all.version}</version>
</dependency>
</dependencies> </dependencies>

View File

@ -1,14 +1,13 @@
package com.tcctyn.common.core.annotation; package com.tcctyn.common.core.annotation;
import com.tcctyn.common.core.utils.poi.ExcelHandlerAdapter;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import com.tcctyn.common.core.utils.poi.ExcelHandlerAdapter;
/** /**
* 自定义导出Excel数据注解 * 自定义导出Excel数据注解
@ -34,11 +33,6 @@ public @interface Excel
*/ */
public String dateFormat() default ""; public String dateFormat() default "";
/**
* 如果是字典类型请设置字典的type值 (: sys_user_sex)
*/
public String dictType() default "";
/** /**
* 读取内容转表达式 (: 0=,1=,2=未知) * 读取内容转表达式 (: 0=,1=,2=未知)
*/ */
@ -84,16 +78,16 @@ public @interface Excel
*/ */
public String prompt() default ""; public String prompt() default "";
/**
* 是否允许内容换行
*/
public boolean wrapText() default false;
/** /**
* 设置只能选择不能输入的列内容. * 设置只能选择不能输入的列内容.
*/ */
public String[] combo() default {}; public String[] combo() default {};
/**
* 是否从字典读数据到combo,默认不读取,如读取需要设置dictType注解.
*/
public boolean comboReadDict() default false;
/** /**
* 是否需要纵向合并单元格,应对需求:含有list集合单元格) * 是否需要纵向合并单元格,应对需求:含有list集合单元格)
*/ */
@ -115,7 +109,7 @@ public @interface Excel
public boolean isStatistics() default false; public boolean isStatistics() default false;
/** /**
* 导出类型0数字 1字符串 2图片 * 导出类型0数字 1字符串
*/ */
public ColumnType cellType() default ColumnType.STRING; public ColumnType cellType() default ColumnType.STRING;

View File

@ -14,5 +14,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Excels public @interface Excels
{ {
public Excel[] value(); Excel[] value();
} }

View File

@ -1,47 +1,12 @@
package com.tcctyn.common.core.constant; package com.tcctyn.common.core.constant;
/** /**
* 缓存的key 常量 * 缓存常量信息
* *
* @author tcctyn * @author tcctyn
*/ */
public class CacheConstants public class CacheConstants
{ {
/**
* 登录用户 redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* 验证码 redis key
*/
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
/**
* 参数管理 cache key
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 防重提交 redis key
*/
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
/**
* 限流 redis key
*/
public static final String RATE_LIMIT_KEY = "rate_limit:";
/**
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
/** /**
* 缓存有效期默认720分钟 * 缓存有效期默认720分钟
*/ */
@ -62,6 +27,30 @@ public class CacheConstants
*/ */
public final static long PASSWORD_LOCK_TIME = 10; public final static long PASSWORD_LOCK_TIME = 10;
/**
* 权限缓存前缀
*/
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* 验证码 redis key
*/
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
/**
* 参数管理 cache key
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
/** /**
* 登录IP黑名单 cache key * 登录IP黑名单 cache key

View File

@ -1,12 +1,8 @@
package com.tcctyn.common.core.constant; package com.tcctyn.common.core.constant;
import io.jsonwebtoken.Claims;
import java.util.Locale;
/** /**
* 通用常量信息 * 通用常量信息
* *
* @author tcctyn * @author tcctyn
*/ */
public class Constants public class Constants
@ -21,16 +17,26 @@ public class Constants
*/ */
public static final String GBK = "GBK"; public static final String GBK = "GBK";
/**
* 系统语言
*/
public static final Locale DEFAULT_LOCALE = Locale.SIMPLIFIED_CHINESE;
/** /**
* www主域 * www主域
*/ */
public static final String WWW = "www."; public static final String WWW = "www.";
/**
* RMI 远程方法调用
*/
public static final String LOOKUP_RMI = "rmi:";
/**
* LDAP 远程方法调用
*/
public static final String LOOKUP_LDAP = "ldap:";
/**
* LDAPS 远程方法调用
*/
public static final String LOOKUP_LDAPS = "ldaps:";
/** /**
* http请求 * http请求
*/ */
@ -42,14 +48,24 @@ public class Constants
public static final String HTTPS = "https://"; public static final String HTTPS = "https://";
/** /**
* 通用成功标识 * 成功标记
*/ */
public static final String SUCCESS = "0"; public static final Integer SUCCESS = 200;
/** /**
* 通用失败标识 * 失败标记
*/ */
public static final String FAIL = "1"; public static final Integer FAIL = 500;
/**
* 登录成功状态
*/
public static final String LOGIN_SUCCESS_STATUS = "0";
/**
* 登录失败状态
*/
public static final String LOGIN_FAIL_STATUS = "1";
/** /**
* 登录成功 * 登录成功
@ -72,91 +88,35 @@ public class Constants
public static final String LOGIN_FAIL = "Error"; public static final String LOGIN_FAIL = "Error";
/** /**
* 所有权限标识 * 当前记录起始索引
*/ */
public static final String ALL_PERMISSION = "*:*:*"; public static final String PAGE_NUM = "pageNum";
/** /**
* 管理员角色权限标识 * 每页显示记录数
*/ */
public static final String SUPER_ADMIN = "admin"; public static final String PAGE_SIZE = "pageSize";
/** /**
* 角色权限分隔符 * 排序列
*/ */
public static final String ROLE_DELIMETER = ","; public static final String ORDER_BY_COLUMN = "orderByColumn";
/** /**
* 权限标识分隔符 * 排序的方向 "desc" 或者 "asc".
*/ */
public static final String PERMISSION_DELIMETER = ","; public static final String IS_ASC = "isAsc";
/** /**
* 验证码有效期分钟 * 验证码有效期分钟
*/ */
public static final long CAPTCHA_EXPIRATION = 2; public static final long CAPTCHA_EXPIRATION = 2;
/**
* 令牌
*/
public static final String TOKEN = "token";
/**
* 令牌前缀
*/
public static final String TOKEN_PREFIX = "Bearer ";
/**
* 令牌前缀
*/
public static final String LOGIN_USER_KEY = "login_user_key";
/**
* 用户ID
*/
public static final String JWT_USERID = "userid";
/**
* 用户名称
*/
public static final String JWT_USERNAME = Claims.SUBJECT;
/**
* 用户头像
*/
public static final String JWT_AVATAR = "avatar";
/**
* 创建时间
*/
public static final String JWT_CREATED = "created";
/**
* 用户权限
*/
public static final String JWT_AUTHORITIES = "authorities";
/** /**
* 资源映射路径 前缀 * 资源映射路径 前缀
*/ */
public static final String RESOURCE_PREFIX = "/profile"; public static final String RESOURCE_PREFIX = "/profile";
/**
* RMI 远程方法调用
*/
public static final String LOOKUP_RMI = "rmi:";
/**
* LDAP 远程方法调用
*/
public static final String LOOKUP_LDAP = "ldap:";
/**
* LDAPS 远程方法调用
*/
public static final String LOOKUP_LDAPS = "ldaps:";
/** /**
* 自动识别json对象白名单配置仅允许解析的包名范围越小越安全 * 自动识别json对象白名单配置仅允许解析的包名范围越小越安全
*/ */
@ -165,21 +125,11 @@ public class Constants
/** /**
* 定时任务白名单配置仅允许访问的包名如其他需要可以自行添加 * 定时任务白名单配置仅允许访问的包名如其他需要可以自行添加
*/ */
public static final String[] JOB_WHITELIST_STR = { "com.tcctyn.quartz.task" }; public static final String[] JOB_WHITELIST_STR = { "com.tcctyn.job.task" };
/**
* 登录成功状态
*/
public static final String LOGIN_SUCCESS_STATUS = "0";
/**
* 登录失败状态
*/
public static final String LOGIN_FAIL_STATUS = "1";
/** /**
* 定时任务违规的字符 * 定时任务违规的字符
*/ */
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.tcctyn.common.utils.file", "com.tcctyn.common.config", "com.tcctyn.generator" }; "org.springframework", "org.apache", "com.tcctyn.common.core.utils.file" };
} }

View File

@ -59,7 +59,7 @@ public class GenConstants
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
/** Tree基类字段 */ /** Tree基类字段 */
public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" }; public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors" };
/** 文本框 */ /** 文本框 */
public static final String HTML_INPUT = "input"; public static final String HTML_INPUT = "input";

View File

@ -2,7 +2,7 @@ package com.tcctyn.common.core.constant;
/** /**
* 用户常量信息 * 用户常量信息
* *
* @author tcctyn * @author tcctyn
*/ */
public class UserConstants public class UserConstants

View File

@ -1,8 +1,7 @@
package com.tcctyn.common.core.web.domain; package com.tcctyn.common.core.domain;
import com.tcctyn.common.core.constant.HttpStatus;
import java.io.Serializable; import java.io.Serializable;
import com.tcctyn.common.core.constant.Constants;
/** /**
* 响应信息主体 * 响应信息主体
@ -14,10 +13,10 @@ public class R<T> implements Serializable
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 成功 */ /** 成功 */
public static final int SUCCESS = HttpStatus.SUCCESS; public static final int SUCCESS = Constants.SUCCESS;
/** 失败 */ /** 失败 */
public static final int FAIL = HttpStatus.ERROR; public static final int FAIL = Constants.FAIL;
private int code; private int code;
@ -27,12 +26,12 @@ public class R<T> implements Serializable
public static <T> R<T> ok() public static <T> R<T> ok()
{ {
return restResult(null, SUCCESS, "操作成功"); return restResult(null, SUCCESS, null);
} }
public static <T> R<T> ok(T data) public static <T> R<T> ok(T data)
{ {
return restResult(data, SUCCESS, "操作成功"); return restResult(data, SUCCESS, null);
} }
public static <T> R<T> ok(T data, String msg) public static <T> R<T> ok(T data, String msg)
@ -42,7 +41,7 @@ public class R<T> implements Serializable
public static <T> R<T> fail() public static <T> R<T> fail()
{ {
return restResult(null, FAIL, "操作失败"); return restResult(null, FAIL, null);
} }
public static <T> R<T> fail(String msg) public static <T> R<T> fail(String msg)
@ -52,7 +51,7 @@ public class R<T> implements Serializable
public static <T> R<T> fail(T data) public static <T> R<T> fail(T data)
{ {
return restResult(data, FAIL, "操作失败"); return restResult(data, FAIL, null);
} }
public static <T> R<T> fail(T data, String msg) public static <T> R<T> fail(T data, String msg)

View File

@ -1,8 +1,5 @@
package com.tcctyn.common.core.exception.base; package com.tcctyn.common.core.exception.base;
import com.tcctyn.common.core.utils.MessageUtils;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 基础异常 * 基础异常
* *
@ -60,21 +57,6 @@ public class BaseException extends RuntimeException
this(null, null, null, defaultMessage); this(null, null, null, defaultMessage);
} }
@Override
public String getMessage()
{
String message = null;
if (!StringUtils.isEmpty(code))
{
message = MessageUtils.message(code, args);
}
if (message == null)
{
message = defaultMessage;
}
return message;
}
public String getModule() public String getModule()
{ {
return module; return module;

View File

@ -11,9 +11,9 @@ public class FileException extends BaseException
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public FileException(String code, Object[] args) public FileException(String code, Object[] args, String msg)
{ {
super("file", code, args, null); super("file", code, args, msg);
} }
} }

View File

@ -11,6 +11,6 @@ public class FileNameLengthLimitExceededException extends FileException
public FileNameLengthLimitExceededException(int defaultFileNameLength) public FileNameLengthLimitExceededException(int defaultFileNameLength)
{ {
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }); super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }, "the filename is too long");
} }
} }

View File

@ -11,6 +11,6 @@ public class FileSizeLimitExceededException extends FileException
public FileSizeLimitExceededException(long defaultMaxSize) public FileSizeLimitExceededException(long defaultMaxSize)
{ {
super("upload.exceed.maxSize", new Object[] { defaultMaxSize }); super("upload.exceed.maxSize", new Object[] { defaultMaxSize }, "the filesize is too large");
} }
} }

View File

@ -17,7 +17,7 @@ public class InvalidExtensionException extends FileUploadException
public InvalidExtensionException(String[] allowedExtension, String extension, String filename) public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
{ {
super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式"); super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
this.allowedExtension = allowedExtension; this.allowedExtension = allowedExtension;
this.extension = extension; this.extension = extension;
this.filename = filename; this.filename = filename;
@ -67,7 +67,7 @@ public class InvalidExtensionException extends FileUploadException
super(allowedExtension, extension, filename); super(allowedExtension, extension, filename);
} }
} }
public static class InvalidVideoExtensionException extends InvalidExtensionException public static class InvalidVideoExtensionException extends InvalidExtensionException
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -1,9 +1,8 @@
package com.tcctyn.common.core.text; package com.tcctyn.common.core.text;
import com.tcctyn.common.core.utils.StringUtils;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 字符集工具类 * 字符集工具类

View File

@ -1,8 +1,5 @@
package com.tcctyn.common.core.text; package com.tcctyn.common.core.text;
import com.tcctyn.common.core.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -10,10 +7,11 @@ import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Set; import java.util.Set;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 类型转换器 * 类型转换器
* *
* @author tcctyn * @author tcctyn
*/ */
public class Convert public class Convert
@ -22,7 +20,7 @@ public class Convert
* 转换为字符串<br> * 转换为字符串<br>
* 如果给定的值为null或者转换失败返回默认值<br> * 如果给定的值为null或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -44,7 +42,7 @@ public class Convert
* 转换为字符串<br> * 转换为字符串<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -57,7 +55,7 @@ public class Convert
* 转换为字符<br> * 转换为字符<br>
* 如果给定的值为null或者转换失败返回默认值<br> * 如果给定的值为null或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -81,7 +79,7 @@ public class Convert
* 转换为字符<br> * 转换为字符<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -94,7 +92,7 @@ public class Convert
* 转换为byte<br> * 转换为byte<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -132,7 +130,7 @@ public class Convert
* 转换为byte<br> * 转换为byte<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -145,7 +143,7 @@ public class Convert
* 转换为Short<br> * 转换为Short<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -183,7 +181,7 @@ public class Convert
* 转换为Short<br> * 转换为Short<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -196,7 +194,7 @@ public class Convert
* 转换为Number<br> * 转换为Number<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -230,7 +228,7 @@ public class Convert
* 转换为Number<br> * 转换为Number<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -243,7 +241,7 @@ public class Convert
* 转换为int<br> * 转换为int<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -281,7 +279,7 @@ public class Convert
* 转换为int<br> * 转换为int<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -292,7 +290,7 @@ public class Convert
/** /**
* 转换为Integer数组<br> * 转换为Integer数组<br>
* *
* @param str 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
*/ */
@ -303,7 +301,7 @@ public class Convert
/** /**
* 转换为Long数组<br> * 转换为Long数组<br>
* *
* @param str 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
*/ */
@ -314,9 +312,9 @@ public class Convert
/** /**
* 转换为Integer数组<br> * 转换为Integer数组<br>
* *
* @param split 分隔符 * @param split 分隔符
* @param split 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
*/ */
public static Integer[] toIntArray(String split, String str) public static Integer[] toIntArray(String split, String str)
@ -337,7 +335,7 @@ public class Convert
/** /**
* 转换为Long数组<br> * 转换为Long数组<br>
* *
* @param split 分隔符 * @param split 分隔符
* @param str 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
@ -360,7 +358,7 @@ public class Convert
/** /**
* 转换为String数组<br> * 转换为String数组<br>
* *
* @param str 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
*/ */
@ -375,9 +373,9 @@ public class Convert
/** /**
* 转换为String数组<br> * 转换为String数组<br>
* *
* @param split 分隔符 * @param split 分隔符
* @param split 被转换的值 * @param str 被转换的值
* @return 结果 * @return 结果
*/ */
public static String[] toStrArray(String split, String str) public static String[] toStrArray(String split, String str)
@ -389,7 +387,7 @@ public class Convert
* 转换为long<br> * 转换为long<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -428,7 +426,7 @@ public class Convert
* 转换为long<br> * 转换为long<br>
* 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br> * 如果给定的值为<code>null</code>或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -441,7 +439,7 @@ public class Convert
* 转换为double<br> * 转换为double<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -480,7 +478,7 @@ public class Convert
* 转换为double<br> * 转换为double<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -493,7 +491,7 @@ public class Convert
* 转换为Float<br> * 转换为Float<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -531,7 +529,7 @@ public class Convert
* 转换为Float<br> * 转换为Float<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -542,7 +540,7 @@ public class Convert
/** /**
* 转换为boolean<br> * 转换为boolean<br>
* String支持的值为truefalseyesokno1,0 如果给定的值为空或者转换失败返回默认值<br> * String支持的值为truefalseyesokno10, 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
@ -571,10 +569,12 @@ public class Convert
case "yes": case "yes":
case "ok": case "ok":
case "1": case "1":
case "":
return true; return true;
case "false": case "false":
case "no": case "no":
case "0": case "0":
case "":
return false; return false;
default: default:
return defaultValue; return defaultValue;
@ -585,7 +585,7 @@ public class Convert
* 转换为boolean<br> * 转换为boolean<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -597,7 +597,7 @@ public class Convert
/** /**
* 转换为Enum对象<br> * 转换为Enum对象<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* *
* @param clazz Enum的Class * @param clazz Enum的Class
* @param value * @param value
* @param defaultValue 默认值 * @param defaultValue 默认值
@ -633,7 +633,7 @@ public class Convert
/** /**
* 转换为Enum对象<br> * 转换为Enum对象<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* *
* @param clazz Enum的Class * @param clazz Enum的Class
* @param value * @param value
* @return Enum * @return Enum
@ -647,7 +647,7 @@ public class Convert
* 转换为BigInteger<br> * 转换为BigInteger<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -685,7 +685,7 @@ public class Convert
* 转换为BigInteger<br> * 转换为BigInteger<br>
* 如果给定的值为空或者转换失败返回默认值<code>null</code><br> * 如果给定的值为空或者转换失败返回默认值<code>null</code><br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -698,7 +698,7 @@ public class Convert
* 转换为BigDecimal<br> * 转换为BigDecimal<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @param defaultValue 转换错误时的默认值 * @param defaultValue 转换错误时的默认值
* @return 结果 * @return 结果
@ -744,7 +744,7 @@ public class Convert
* 转换为BigDecimal<br> * 转换为BigDecimal<br>
* 如果给定的值为空或者转换失败返回默认值<br> * 如果给定的值为空或者转换失败返回默认值<br>
* 转换失败不会报错 * 转换失败不会报错
* *
* @param value 被转换的值 * @param value 被转换的值
* @return 结果 * @return 结果
*/ */
@ -756,7 +756,7 @@ public class Convert
/** /**
* 将对象转为字符串<br> * 将对象转为字符串<br>
* 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法 * 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法
* *
* @param obj 对象 * @param obj 对象
* @return 字符串 * @return 字符串
*/ */
@ -768,7 +768,7 @@ public class Convert
/** /**
* 将对象转为字符串<br> * 将对象转为字符串<br>
* 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法 * 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法
* *
* @param obj 对象 * @param obj 对象
* @param charsetName 字符集 * @param charsetName 字符集
* @return 字符串 * @return 字符串
@ -781,7 +781,7 @@ public class Convert
/** /**
* 将对象转为字符串<br> * 将对象转为字符串<br>
* 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法 * 1Byte数组和ByteBuffer会被转换为对应字符串的数组 2对象数组会调用Arrays.toString方法
* *
* @param obj 对象 * @param obj 对象
* @param charset 字符集 * @param charset 字符集
* @return 字符串 * @return 字符串
@ -797,14 +797,23 @@ public class Convert
{ {
return (String) obj; return (String) obj;
} }
else if (obj instanceof byte[]) else if (obj instanceof byte[] || obj instanceof Byte[])
{ {
return str((byte[]) obj, charset); if (obj instanceof byte[])
} {
else if (obj instanceof Byte[]) return str((byte[]) obj, charset);
{ }
byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); else
return str(bytes, charset); {
Byte[] bytes = (Byte[]) obj;
int length = bytes.length;
byte[] dest = new byte[length];
for (int i = 0; i < length; i++)
{
dest[i] = bytes[i];
}
return str(dest, charset);
}
} }
else if (obj instanceof ByteBuffer) else if (obj instanceof ByteBuffer)
{ {
@ -815,7 +824,7 @@ public class Convert
/** /**
* 将byte数组转为字符串 * 将byte数组转为字符串
* *
* @param bytes byte数组 * @param bytes byte数组
* @param charset 字符集 * @param charset 字符集
* @return 字符串 * @return 字符串
@ -827,7 +836,7 @@ public class Convert
/** /**
* 解码字节码 * 解码字节码
* *
* @param data 字符串 * @param data 字符串
* @param charset 字符集如果此字段为空则解码的结果取决于平台 * @param charset 字符集如果此字段为空则解码的结果取决于平台
* @return 解码后的字符串 * @return 解码后的字符串
@ -848,7 +857,7 @@ public class Convert
/** /**
* 将编码的byteBuffer数据转换为字符串 * 将编码的byteBuffer数据转换为字符串
* *
* @param data 数据 * @param data 数据
* @param charset 字符集如果为空使用当前系统字符集 * @param charset 字符集如果为空使用当前系统字符集
* @return 字符串 * @return 字符串
@ -865,7 +874,7 @@ public class Convert
/** /**
* 将编码的byteBuffer数据转换为字符串 * 将编码的byteBuffer数据转换为字符串
* *
* @param data 数据 * @param data 数据
* @param charset 字符集如果为空使用当前系统字符集 * @param charset 字符集如果为空使用当前系统字符集
* @return 字符串 * @return 字符串
@ -882,7 +891,7 @@ public class Convert
// ----------------------------------------------------------------------- 全角半角转换 // ----------------------------------------------------------------------- 全角半角转换
/** /**
* 半角转全角 * 半角转全角
* *
* @param input String. * @param input String.
* @return 全角字符串. * @return 全角字符串.
*/ */
@ -893,7 +902,7 @@ public class Convert
/** /**
* 半角转全角 * 半角转全角
* *
* @param input String * @param input String
* @param notConvertSet 不替换的字符集合 * @param notConvertSet 不替换的字符集合
* @return 全角字符串. * @return 全角字符串.
@ -924,7 +933,7 @@ public class Convert
/** /**
* 全角转半角 * 全角转半角
* *
* @param input String. * @param input String.
* @return 半角字符串 * @return 半角字符串
*/ */
@ -935,7 +944,7 @@ public class Convert
/** /**
* 替换全角为半角 * 替换全角为半角
* *
* @param text 文本 * @param text 文本
* @param notConvertSet 不替换的字符集合 * @param notConvertSet 不替换的字符集合
* @return 替换后的字符 * @return 替换后的字符
@ -960,14 +969,12 @@ public class Convert
c[i] = (char) (c[i] - 65248); c[i] = (char) (c[i] - 65248);
} }
} }
String returnString = new String(c); return new String(c);
return returnString;
} }
/** /**
* 数字金额大写转换 先写个完整的然后将如零拾替换成零 * 数字金额大写转换 先写个完整的然后将如零拾替换成零
* *
* @param n 数字 * @param n 数字
* @return 中文大写数字 * @return 中文大写数字
*/ */

View File

@ -1,28 +1,29 @@
package com.tcctyn.common.core.utils; package com.tcctyn.common.core.utils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.*; import java.time.LocalDate;
import java.util.Calendar; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
/** /**
* 时间工具类 * 时间工具类
* *
* @author tcctyn * @author tcctyn
*/ */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils { public class DateUtils extends org.apache.commons.lang3.time.DateUtils
{
public static String YYYY = "yyyy"; public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM"; public static String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd"; public static String YYYY_MM_DD = "yyyy-MM-dd";
public static final String YYYYMMDD = "yyyyMMdd";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
@ -37,7 +38,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* *
* @return Date() 当前日期 * @return Date() 当前日期
*/ */
public static Date getNowDate() { public static Date getNowDate()
{
return new Date(); return new Date();
} }
@ -46,43 +48,44 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* *
* @return String * @return String
*/ */
public static String getDate() { public static String getDate()
{
return dateTimeNow(YYYY_MM_DD); return dateTimeNow(YYYY_MM_DD);
} }
/** public static final String getTime()
* 获取当前日期 {
*
* @return String
*/
public static String getDate(String dateType) {
return dateTimeNow(dateType);
}
public static final String getTime() {
return dateTimeNow(YYYY_MM_DD_HH_MM_SS); return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
} }
public static final String dateTimeNow() { public static final String dateTimeNow()
{
return dateTimeNow(YYYYMMDDHHMMSS); return dateTimeNow(YYYYMMDDHHMMSS);
} }
public static final String dateTimeNow(final String format) { public static final String dateTimeNow(final String format)
{
return parseDateToStr(format, new Date()); return parseDateToStr(format, new Date());
} }
public static final String dateTime(final Date date) { public static final String dateTime(final Date date)
{
return parseDateToStr(YYYY_MM_DD, date); return parseDateToStr(YYYY_MM_DD, date);
} }
public static final String parseDateToStr(final String format, final Date date) { public static final String parseDateToStr(final String format, final Date date)
{
return new SimpleDateFormat(format).format(date); return new SimpleDateFormat(format).format(date);
} }
public static final Date dateTime(final String format, final String ts) { public static final Date dateTime(final String format, final String ts)
try { {
try
{
return new SimpleDateFormat(format).parse(ts); return new SimpleDateFormat(format).parse(ts);
} catch (ParseException e) { }
catch (ParseException e)
{
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -90,7 +93,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 日期路径 即年// 如2018/08/08 * 日期路径 即年// 如2018/08/08
*/ */
public static final String datePath() { public static final String datePath()
{
Date now = new Date(); Date now = new Date();
return DateFormatUtils.format(now, "yyyy/MM/dd"); return DateFormatUtils.format(now, "yyyy/MM/dd");
} }
@ -98,7 +102,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 日期路径 即年// 如20180808 * 日期路径 即年// 如20180808
*/ */
public static final String dateTime() { public static final String dateTime()
{
Date now = new Date(); Date now = new Date();
return DateFormatUtils.format(now, "yyyyMMdd"); return DateFormatUtils.format(now, "yyyyMMdd");
} }
@ -106,13 +111,18 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 日期型字符串转化为日期 格式 * 日期型字符串转化为日期 格式
*/ */
public static Date parseDate(Object str) { public static Date parseDate(Object str)
if (str == null) { {
if (str == null)
{
return null; return null;
} }
try { try
{
return parseDate(str.toString(), parsePatterns); return parseDate(str.toString(), parsePatterns);
} catch (ParseException e) { }
catch (ParseException e)
{
return null; return null;
} }
} }
@ -120,26 +130,21 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 获取服务器启动时间 * 获取服务器启动时间
*/ */
public static Date getServerStartDate() { public static Date getServerStartDate()
{
long time = ManagementFactory.getRuntimeMXBean().getStartTime(); long time = ManagementFactory.getRuntimeMXBean().getStartTime();
return new Date(time); return new Date(time);
} }
/**
* 计算相差天数
*/
public static int differentDaysByMillisecond(Date date1, Date date2) {
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
}
/** /**
* 计算时间差 * 计算时间差
* *
* @param endDate 最后时间 * @param endDate 最后时间
* @param startTime 开始时间 * @param startTime 开始时间
* @return 时间差/小时/分钟 * @return 时间差/小时/分钟
*/ */
public static String timeDistance(Date endDate, Date startTime) { public static String timeDistance(Date endDate, Date startTime)
{
long nd = 1000 * 24 * 60 * 60; long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60; long nh = 1000 * 60 * 60;
long nm = 1000 * 60; long nm = 1000 * 60;
@ -160,7 +165,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 增加 LocalDateTime ==> Date * 增加 LocalDateTime ==> Date
*/ */
public static Date toDate(LocalDateTime temporalAccessor) { public static Date toDate(LocalDateTime temporalAccessor)
{
ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault()); ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant()); return Date.from(zdt.toInstant());
} }
@ -168,59 +174,10 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/** /**
* 增加 LocalDate ==> Date * 增加 LocalDate ==> Date
*/ */
public static Date toDate(LocalDate temporalAccessor) { public static Date toDate(LocalDate temporalAccessor)
{
LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0)); LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant()); return Date.from(zdt.toInstant());
} }
/**
* 获取当前周的周一日期
*
* @param date 当前日期
* @return 周一的日期
*/
public static Date getThisWeekMonday(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 设置为周一
return cal.getTime();
}
/**
* 获取当前周的周日日期
*
* @param date 当前日期
* @return 周日的日期
*/
public static Date getThisWeekSunday(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // 设置为周日
return cal.getTime();
}
/**
* 获取星期
*
* @param date 日期
*/
public static int getWeek(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
dayOfWeek -= 1;
if (dayOfWeek == 0) {
dayOfWeek = 7;
}
return dayOfWeek;
}
public static void main(String[] args) {
String date = DateUtils.getDate(DateUtils.YYYYMMDD);
System.out.println(date);
}
} }

View File

@ -1,9 +1,8 @@
package com.tcctyn.common.core.utils; package com.tcctyn.common.core.utils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import org.apache.commons.lang3.exception.ExceptionUtils;
/** /**
* 错误信息处理类 * 错误信息处理类

View File

@ -1,9 +1,9 @@
package com.tcctyn.common.core.utils; package com.tcctyn.common.core.utils;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.tcctyn.common.core.utils.sql.SqlUtil;
import com.tcctyn.common.core.web.page.PageDomain; import com.tcctyn.common.core.web.page.PageDomain;
import com.tcctyn.common.core.web.page.TableSupport; import com.tcctyn.common.core.web.page.TableSupport;
import com.tcctyn.common.core.utils.sql.SqlUtil;
/** /**
* 分页工具类 * 分页工具类

View File

@ -1,9 +1,17 @@
package com.tcctyn.common.core.utils; package com.tcctyn.common.core.utils;
import com.alibaba.fastjson2.JSON; import java.io.IOException;
import com.tcctyn.common.core.constant.Constants; import java.io.UnsupportedEncodingException;
import com.tcctyn.common.core.web.domain.R; import java.net.URLDecoder;
import com.tcctyn.common.core.text.Convert; import java.net.URLEncoder;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -13,24 +21,15 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import com.alibaba.fastjson2.JSON;
import com.tcctyn.common.core.constant.Constants;
import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.text.Convert;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/** /**
* 客户端工具类 * 客户端工具类
* *
* @author tcctyn * @author tcctyn
*/ */
public class ServletUtils public class ServletUtils
@ -190,7 +189,7 @@ public class ServletUtils
/** /**
* 将字符串渲染到客户端 * 将字符串渲染到客户端
* *
* @param response 渲染对象 * @param response 渲染对象
* @param string 待渲染的字符串 * @param string 待渲染的字符串
*/ */
@ -211,7 +210,7 @@ public class ServletUtils
/** /**
* 是否是Ajax异步请求 * 是否是Ajax异步请求
* *
* @param request * @param request
*/ */
public static boolean isAjaxRequest(HttpServletRequest request) public static boolean isAjaxRequest(HttpServletRequest request)
@ -240,7 +239,7 @@ public class ServletUtils
/** /**
* 内容编码 * 内容编码
* *
* @param str 内容 * @param str 内容
* @return 编码后的内容 * @return 编码后的内容
*/ */
@ -258,7 +257,7 @@ public class ServletUtils
/** /**
* 内容解码 * 内容解码
* *
* @param str 内容 * @param str 内容
* @return 解码后的内容 * @return 解码后的内容
*/ */

View File

@ -1,16 +1,15 @@
package com.tcctyn.common.core.utils; package com.tcctyn.common.core.utils;
import com.tcctyn.common.core.constant.Constants;
import com.tcctyn.common.core.text.StrFormatter;
import org.springframework.util.AntPathMatcher;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.util.AntPathMatcher;
import com.tcctyn.common.core.constant.Constants;
import com.tcctyn.common.core.text.StrFormatter;
/** /**
* 字符串工具类 * 字符串工具类
* *
* @author tcctyn * @author tcctyn
*/ */
public class StringUtils extends org.apache.commons.lang3.StringUtils public class StringUtils extends org.apache.commons.lang3.StringUtils
@ -26,7 +25,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 获取参数不为空值 * 获取参数不为空值
* *
* @param value defaultValue 要判断的value * @param value defaultValue 要判断的value
* @return value 返回值 * @return value 返回值
*/ */
@ -37,7 +36,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个Collection是否为空 包含ListSetQueue * * 判断一个Collection是否为空 包含ListSetQueue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true为空 false非空 * @return true为空 false非空
*/ */
@ -48,7 +47,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个Collection是否非空包含ListSetQueue * * 判断一个Collection是否非空包含ListSetQueue
* *
* @param coll 要判断的Collection * @param coll 要判断的Collection
* @return true非空 false * @return true非空 false
*/ */
@ -59,7 +58,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个对象数组是否为空 * * 判断一个对象数组是否为空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
** @return true为空 false非空 ** @return true为空 false非空
*/ */
@ -70,7 +69,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个对象数组是否非空 * * 判断一个对象数组是否非空
* *
* @param objects 要判断的对象数组 * @param objects 要判断的对象数组
* @return true非空 false * @return true非空 false
*/ */
@ -81,7 +80,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个Map是否为空 * * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true为空 false非空 * @return true为空 false非空
*/ */
@ -92,7 +91,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个Map是否为空 * * 判断一个Map是否为空
* *
* @param map 要判断的Map * @param map 要判断的Map
* @return true非空 false * @return true非空 false
*/ */
@ -103,7 +102,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个字符串是否为空串 * * 判断一个字符串是否为空串
* *
* @param str String * @param str String
* @return true为空 false非空 * @return true为空 false非空
*/ */
@ -114,7 +113,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个字符串是否为非空串 * * 判断一个字符串是否为非空串
* *
* @param str String * @param str String
* @return true非空串 false空串 * @return true非空串 false空串
*/ */
@ -125,7 +124,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个对象是否为空 * * 判断一个对象是否为空
* *
* @param object Object * @param object Object
* @return true为空 false非空 * @return true为空 false非空
*/ */
@ -136,7 +135,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个对象是否非空 * * 判断一个对象是否非空
* *
* @param object Object * @param object Object
* @return true非空 false * @return true非空 false
*/ */
@ -147,7 +146,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* * 判断一个对象是否是数组类型Java基本型别的数组 * * 判断一个对象是否是数组类型Java基本型别的数组
* *
* @param object 对象 * @param object 对象
* @return true是数组 false不是数组 * @return true是数组 false不是数组
*/ */
@ -209,7 +208,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @return 结果 * @return 结果
@ -240,7 +239,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 截取字符串 * 截取字符串
* *
* @param str 字符串 * @param str 字符串
* @param start 开始 * @param start 开始
* @param end 结束 * @param end 结束
@ -286,7 +285,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 在字符串中查找第一个出现的 `open` 和最后一个出现的 `close` 之间的子字符串 * 在字符串中查找第一个出现的 `open` 和最后一个出现的 `close` 之间的子字符串
* *
* @param str 要截取的字符串 * @param str 要截取的字符串
* @param open 起始字符串 * @param open 起始字符串
* @param close 结束字符串 * @param close 结束字符串
@ -312,7 +311,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 判断是否为空并且不是空白字符 * 判断是否为空并且不是空白字符
* *
* @param str 要判断的value * @param str 要判断的value
* @return 结果 * @return 结果
*/ */
@ -342,7 +341,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br> * 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> * 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> * 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
* *
* @param template 文本模板被替换的部分用 {} 表示 * @param template 文本模板被替换的部分用 {} 表示
* @param params 参数值 * @param params 参数值
* @return 格式化后的文本 * @return 格式化后的文本
@ -358,7 +357,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 是否为http(s)://开头 * 是否为http(s)://开头
* *
* @param link 链接 * @param link 链接
* @return 结果 * @return 结果
*/ */
@ -444,7 +443,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 是否包含字符串 * 是否包含字符串
* *
* @param str 验证字符串 * @param str 验证字符串
* @param strs 字符串组 * @param strs 字符串组
* @return 包含返回true * @return 包含返回true
@ -466,7 +465,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 将下划线大写方式命名的字符串转换为驼峰式如果转换前的下划线大写方式命名的字符串为空则返回空字符串 例如HELLO_WORLD->HelloWorld * 将下划线大写方式命名的字符串转换为驼峰式如果转换前的下划线大写方式命名的字符串为空则返回空字符串 例如HELLO_WORLD->HelloWorld
* *
* @param name 转换前的下划线大写方式命名的字符串 * @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串 * @return 转换后的驼峰式命名的字符串
*/ */
@ -540,7 +539,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
* *
* @param str 指定字符串 * @param str 指定字符串
* @param strs 需要检查的字符串数组 * @param strs 需要检查的字符串数组
* @return 是否匹配 * @return 是否匹配
@ -562,11 +561,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
} }
/** /**
* 判断url是否与规则配置: * 判断url是否与规则配置:
* ? 表示单个字符; * ? 表示单个字符;
* * 表示一层路径内的任意字符串不可跨层级; * * 表示一层路径内的任意字符串不可跨层级;
* ** 表示任意层路径; * ** 表示任意层路径;
* *
* @param pattern 匹配规则 * @param pattern 匹配规则
* @param url 需要匹配的url * @param url 需要匹配的url
* @return * @return
@ -585,7 +584,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 数字左边补齐0使之达到指定长度注意如果数字转换为字符串后长度大于size则只保留 最后size个字符 * 数字左边补齐0使之达到指定长度注意如果数字转换为字符串后长度大于size则只保留 最后size个字符
* *
* @param num 数字对象 * @param num 数字对象
* @param size 字符串指定长度 * @param size 字符串指定长度
* @return 返回数字的字符串格式该字符串为指定长度 * @return 返回数字的字符串格式该字符串为指定长度
@ -597,7 +596,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
/** /**
* 字符串左补齐如果原始字符串s长度大于size则只保留最后size个字符 * 字符串左补齐如果原始字符串s长度大于size则只保留最后size个字符
* *
* @param s 原始字符串 * @param s 原始字符串
* @param size 字符串指定长度 * @param size 字符串指定长度
* @param c 用于补齐的字符 * @param c 用于补齐的字符

View File

@ -1,55 +1,53 @@
package com.tcctyn.common.core.utils.bean; package com.tcctyn.common.core.utils.bean;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static cn.hutool.core.bean.BeanUtil.toBean;
/** /**
* Bean 工具类 * Bean 工具类
* *
* @author tcctyn * @author tcctyn
*/ */
public class BeanUtils extends org.springframework.beans.BeanUtils { public class BeanUtils extends org.springframework.beans.BeanUtils
/** {
* Bean方法名中属性名开始的下标 /** Bean方法名中属性名开始的下标 */
*/
private static final int BEAN_METHOD_PROP_INDEX = 3; private static final int BEAN_METHOD_PROP_INDEX = 3;
/** /** * 匹配getter方法的正则表达式 */
* 匹配getter方法的正则表达式
*/
private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)"); private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)");
/** /** * 匹配setter方法的正则表达式 */
* 匹配setter方法的正则表达式
*/
private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)"); private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)");
/** /**
* Bean属性复制工具方法 * Bean属性复制工具方法
* *
* @param src 源对象
* @param dest 目标对象 * @param dest 目标对象
* @param src 源对象
*/ */
public static void copyBeanProp(Object src, Object dest) { public static void copyBeanProp(Object dest, Object src)
try { {
try
{
copyProperties(src, dest); copyProperties(src, dest);
} catch (Exception e) { }
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* 获取对象的setter方法 * 获取对象的setter方法
* *
* @param obj 对象 * @param obj 对象
* @return 对象的setter方法列表 * @return 对象的setter方法列表
*/ */
public static List<Method> getSetterMethods(Object obj) { public static List<Method> getSetterMethods(Object obj)
{
// setter方法列表 // setter方法列表
List<Method> setterMethods = new ArrayList<Method>(); List<Method> setterMethods = new ArrayList<Method>();
@ -58,9 +56,11 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
// 查找setter方法 // 查找setter方法
for (Method method : methods) { for (Method method : methods)
{
Matcher m = SET_PATTERN.matcher(method.getName()); Matcher m = SET_PATTERN.matcher(method.getName());
if (m.matches() && (method.getParameterTypes().length == 1)) { if (m.matches() && (method.getParameterTypes().length == 1))
{
setterMethods.add(method); setterMethods.add(method);
} }
} }
@ -70,20 +70,23 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
/** /**
* 获取对象的getter方法 * 获取对象的getter方法
* *
* @param obj 对象 * @param obj 对象
* @return 对象的getter方法列表 * @return 对象的getter方法列表
*/ */
public static List<Method> getGetterMethods(Object obj) { public static List<Method> getGetterMethods(Object obj)
{
// getter方法列表 // getter方法列表
List<Method> getterMethods = new ArrayList<Method>(); List<Method> getterMethods = new ArrayList<Method>();
// 获取所有方法 // 获取所有方法
Method[] methods = obj.getClass().getMethods(); Method[] methods = obj.getClass().getMethods();
// 查找getter方法 // 查找getter方法
for (Method method : methods) { for (Method method : methods)
{
Matcher m = GET_PATTERN.matcher(method.getName()); Matcher m = GET_PATTERN.matcher(method.getName());
if (m.matches() && (method.getParameterTypes().length == 0)) { if (m.matches() && (method.getParameterTypes().length == 0))
{
getterMethods.add(method); getterMethods.add(method);
} }
} }
@ -94,29 +97,14 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
/** /**
* 检查Bean方法名中的属性名是否相等<br> * 检查Bean方法名中的属性名是否相等<br>
* 如getName()和setName()属性名一样getName()和setAge()属性名不一样 * 如getName()和setName()属性名一样getName()和setAge()属性名不一样
* *
* @param m1 方法名1 * @param m1 方法名1
* @param m2 方法名2 * @param m2 方法名2
* @return 属性名一样返回true否则返回false * @return 属性名一样返回true否则返回false
*/ */
public static boolean isMethodPropEquals(String m1, String m2) { public static boolean isMethodPropEquals(String m1, String m2)
{
return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX)); return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
} }
/**
* List 对象复制工具方法
*
* @param sourceList
* @param destinationClass
* @return
*/
public static <T, E> List<T> copyList(Collection<E> sourceList, Class<T> destinationClass) {
if (sourceList == null || sourceList.isEmpty() || destinationClass == null) {
return Collections.emptyList();
}
return sourceList.parallelStream()
.filter(Objects::nonNull)
.map(source -> toBean(source, destinationClass)).collect(Collectors.toList());
}
} }

View File

@ -1,9 +1,9 @@
package com.tcctyn.common.core.utils.bean; package com.tcctyn.common.core.utils.bean;
import java.util.Set;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import javax.validation.Validator; import javax.validation.Validator;
import java.util.Set;
/** /**
* bean对象属性验证 * bean对象属性验证

View File

@ -1,11 +1,10 @@
package com.tcctyn.common.core.utils.file; package com.tcctyn.common.core.utils.file;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
/** /**
* 文件类型工具类 * 文件类型工具类
@ -18,7 +17,7 @@ public class FileTypeUtils
* 获取文件类型 * 获取文件类型
* <p> * <p>
* 例如: tcctyn.txt, 返回: txt * 例如: tcctyn.txt, 返回: txt
* *
* @param file 文件名 * @param file 文件名
* @return 后缀不含".") * @return 后缀不含".")
*/ */
@ -51,7 +50,7 @@ public class FileTypeUtils
/** /**
* 获取文件名的后缀 * 获取文件名的后缀
* *
* @param file 表单文件 * @param file 表单文件
* @return 后缀名 * @return 后缀名
*/ */
@ -67,7 +66,7 @@ public class FileTypeUtils
/** /**
* 获取文件类型 * 获取文件类型
* *
* @param photoByte 文件字节码 * @param photoByte 文件字节码
* @return 后缀不含".") * @return 后缀不含".")
*/ */

View File

@ -1,18 +1,17 @@
package com.tcctyn.common.core.utils.file; package com.tcctyn.common.core.utils.file;
import com.tcctyn.common.core.config.TcctynConfig; import java.io.File;
import com.tcctyn.common.core.utils.DateUtils; import java.io.FileInputStream;
import com.tcctyn.common.core.utils.StringUtils; import java.io.FileNotFoundException;
import com.tcctyn.common.core.utils.uuid.IdUtils; import java.io.IOException;
import org.apache.commons.io.FilenameUtils; import java.io.OutputStream;
import org.apache.commons.io.IOUtils; import java.io.UnsupportedEncodingException;
import org.apache.commons.lang3.ArrayUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 文件处理工具类 * 文件处理工具类
@ -21,6 +20,12 @@ import java.nio.charset.StandardCharsets;
*/ */
public class FileUtils public class FileUtils
{ {
/** 字符常量:斜杠 {@code '/'} */
public static final char SLASH = '/';
/** 字符常量:反斜杠 {@code '\\'} */
public static final char BACKSLASH = '\\';
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
/** /**
@ -54,50 +59,31 @@ public class FileUtils
} }
finally finally
{ {
IOUtils.close(os); if (os != null)
IOUtils.close(fis); {
try
{
os.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
if (fis != null)
{
try
{
fis.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
} }
} }
/**
* 写数据到文件中
*
* @param data 数据
* @return 目标文件
* @throws IOException IO异常
*/
public static String writeImportBytes(byte[] data) throws IOException
{
return writeBytes(data, TcctynConfig.getImportPath());
}
/**
* 写数据到文件中
*
* @param data 数据
* @param uploadDir 目标文件
* @return 目标文件
* @throws IOException IO异常
*/
public static String writeBytes(byte[] data, String uploadDir) throws IOException
{
FileOutputStream fos = null;
String pathName = "";
try
{
String extension = getFileExtendName(data);
pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName);
fos = new FileOutputStream(file);
fos.write(data);
}
finally
{
IOUtils.close(fos);
}
return FileUploadUtils.getPathFileName(uploadDir, pathName);
}
/** /**
* 删除文件 * 删除文件
* *
@ -140,15 +126,8 @@ public class FileUtils
{ {
return false; return false;
} }
// 判断是否在允许下载的文件规则内
// 检查允许下载的文件规则 return ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource));
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
{
return true;
}
// 不在允许下载的文件规则
return false;
} }
/** /**
@ -186,11 +165,63 @@ public class FileUtils
return filename; return filename;
} }
/**
* 返回文件名
*
* @param filePath 文件
* @return 文件名
*/
public static String getName(String filePath)
{
if (null == filePath)
{
return null;
}
int len = filePath.length();
if (0 == len)
{
return filePath;
}
if (isFileSeparator(filePath.charAt(len - 1)))
{
// 以分隔符结尾的去掉结尾分隔符
len--;
}
int begin = 0;
char c;
for (int i = len - 1; i > -1; i--)
{
c = filePath.charAt(i);
if (isFileSeparator(c))
{
// 查找最后一个路径分隔符/或者\
begin = i + 1;
break;
}
}
return filePath.substring(begin, len);
}
/**
* 是否为Windows或者LinuxUnix文件分隔符<br>
* Windows平台下分隔符为\LinuxUnix/
*
* @param c 字符
* @return 是否为Windows或者LinuxUnix文件分隔符
*/
public static boolean isFileSeparator(char c)
{
return SLASH == c || BACKSLASH == c;
}
/** /**
* 下载文件名重新编码 * 下载文件名重新编码
* *
* @param response 响应对象 * @param response 响应对象
* @param realFileName 真实文件名 * @param realFileName 真实文件名
* @return
*/ */
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
{ {
@ -204,7 +235,6 @@ public class FileUtils
.append("utf-8''") .append("utf-8''")
.append(percentEncodedFileName); .append(percentEncodedFileName);
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
response.setHeader("Content-disposition", contentDispositionValue.toString()); response.setHeader("Content-disposition", contentDispositionValue.toString());
response.setHeader("download-filename", percentEncodedFileName); response.setHeader("download-filename", percentEncodedFileName);
} }
@ -220,67 +250,4 @@ public class FileUtils
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString()); String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
return encode.replaceAll("\\+", "%20"); return encode.replaceAll("\\+", "%20");
} }
/**
* 获取图像后缀
*
* @param photoByte 图像数据
* @return 后缀名
*/
public static String getFileExtendName(byte[] photoByte)
{
String strFileExtendName = "jpg";
if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56)
&& ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97))
{
strFileExtendName = "gif";
}
else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70))
{
strFileExtendName = "jpg";
}
else if ((photoByte[0] == 66) && (photoByte[1] == 77))
{
strFileExtendName = "bmp";
}
else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71))
{
strFileExtendName = "png";
}
return strFileExtendName;
}
/**
* 获取文件名称 /profile/upload/2022/04/16/tcctyn.png -- tcctyn.png
*
* @param fileName 路径名称
* @return 没有文件路径的名称
*/
public static String getName(String fileName)
{
if (fileName == null)
{
return null;
}
int lastUnixPos = fileName.lastIndexOf('/');
int lastWindowsPos = fileName.lastIndexOf('\\');
int index = Math.max(lastUnixPos, lastWindowsPos);
return fileName.substring(index + 1);
}
/**
* 获取不带后缀文件名称 /profile/upload/2022/04/16/tcctyn.png -- tcctyn
*
* @param fileName 路径名称
* @return 没有文件路径和后缀的名称
*/
public static String getNameNotSuffix(String fileName)
{
if (fileName == null)
{
return null;
}
String baseName = FilenameUtils.getBaseName(fileName);
return baseName;
}
} }

View File

@ -1,18 +1,13 @@
package com.tcctyn.common.core.utils.file; package com.tcctyn.common.core.utils.file;
import com.tcctyn.common.core.config.TcctynConfig;
import com.tcctyn.common.core.constant.Constants;
import com.tcctyn.common.core.utils.StringUtils;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Arrays; import java.util.Arrays;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 图片处理工具类 * 图片处理工具类
@ -67,28 +62,18 @@ public class ImageUtils
InputStream in = null; InputStream in = null;
try try
{ {
if (url.startsWith("http")) // 网络地址
{ URL urlObj = new URL(url);
// 网络地址 URLConnection urlConnection = urlObj.openConnection();
URL urlObj = new URL(url); urlConnection.setConnectTimeout(30 * 1000);
URLConnection urlConnection = urlObj.openConnection(); urlConnection.setReadTimeout(60 * 1000);
urlConnection.setConnectTimeout(30 * 1000); urlConnection.setDoInput(true);
urlConnection.setReadTimeout(60 * 1000); in = urlConnection.getInputStream();
urlConnection.setDoInput(true);
in = urlConnection.getInputStream();
}
else
{
// 本机地址
String localPath = TcctynConfig.getProfile();
String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX);
in = new FileInputStream(downloadPath);
}
return IOUtils.toByteArray(in); return IOUtils.toByteArray(in);
} }
catch (Exception e) catch (Exception e)
{ {
log.error("获取文件路径异常 {}", e); log.error("访问文件异常 {}", e);
return null; return null;
} }
finally finally

View File

@ -16,7 +16,7 @@ public class MimeTypeUtils
public static final String IMAGE_BMP = "image/bmp"; public static final String IMAGE_BMP = "image/bmp";
public static final String IMAGE_GIF = "image/gif"; public static final String IMAGE_GIF = "image/gif";
public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" }; public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };
public static final String[] FLASH_EXTENSION = { "swf", "flv" }; public static final String[] FLASH_EXTENSION = { "swf", "flv" };

View File

@ -1,6 +1,10 @@
package com.tcctyn.common.core.utils.html; package com.tcctyn.common.core.utils.html;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;

View File

@ -1,11 +1,10 @@
package com.tcctyn.common.core.utils.ip; package com.tcctyn.common.core.utils.ip;
import com.tcctyn.common.core.utils.ServletUtils;
import com.tcctyn.common.core.utils.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
import com.tcctyn.common.core.utils.ServletUtils;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 获取IP方法 * 获取IP方法

View File

@ -1,37 +1,7 @@
package com.tcctyn.common.core.utils.poi; package com.tcctyn.common.core.utils.poi;
import com.tcctyn.common.core.annotation.Excel; import java.io.IOException;
import com.tcctyn.common.core.annotation.Excel.ColumnType; import java.io.InputStream;
import com.tcctyn.common.core.annotation.Excel.Type;
import com.tcctyn.common.core.annotation.Excels;
import com.tcctyn.common.core.config.TcctynConfig;
import com.tcctyn.common.core.web.domain.AjaxResult;
import com.tcctyn.common.core.exception.UtilException;
import com.tcctyn.common.core.text.Convert;
import com.tcctyn.common.core.utils.DateUtils;
import com.tcctyn.common.core.utils.DictUtils;
import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.file.FileTypeUtils;
import com.tcctyn.common.core.utils.file.FileUtils;
import com.tcctyn.common.core.utils.file.ImageUtils;
import com.tcctyn.common.core.utils.reflect.ReflectUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -39,12 +9,64 @@ import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tcctyn.common.core.annotation.Excel;
import com.tcctyn.common.core.annotation.Excel.ColumnType;
import com.tcctyn.common.core.annotation.Excel.Type;
import com.tcctyn.common.core.annotation.Excels;
import com.tcctyn.common.core.exception.UtilException;
import com.tcctyn.common.core.text.Convert;
import com.tcctyn.common.core.utils.DateUtils;
import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.file.FileTypeUtils;
import com.tcctyn.common.core.utils.file.ImageUtils;
import com.tcctyn.common.core.utils.reflect.ReflectUtils;
/** /**
* Excel相关处理 * Excel相关处理
* *
* @author tcctyn * @author tcctyn
*/ */
public class ExcelUtil<T> public class ExcelUtil<T>
@ -55,11 +77,6 @@ public class ExcelUtil<T>
public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
/**
* 用于dictType属性数据存储避免重复查缓存
*/
public Map<String, String> sysDictMap = new HashMap<String, String>();
/** /**
* Excel sheet最大行数默认65536 * Excel sheet最大行数默认65536
*/ */
@ -150,6 +167,11 @@ public class ExcelUtil<T>
*/ */
public Class<T> clazz; public Class<T> clazz;
/**
* 需要显示列属性
*/
public String[] includeFields;
/** /**
* 需要排除列属性 * 需要排除列属性
*/ */
@ -160,11 +182,20 @@ public class ExcelUtil<T>
this.clazz = clazz; this.clazz = clazz;
} }
/**
* 仅在Excel中显示列属性
*
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
*/
public void showColumn(String... fields)
{
this.includeFields = fields;
}
/** /**
* 隐藏Excel中列属性 * 隐藏Excel中列属性
* *
* @param fields 列属性名 示例[单个"name"/多个"id","name"] * @param fields 列属性名 示例[单个"name"/多个"id","name"]
* @throws Exception
*/ */
public void hideColumn(String... fields) public void hideColumn(String... fields)
{ {
@ -194,8 +225,6 @@ public class ExcelUtil<T>
{ {
if (StringUtils.isNotEmpty(title)) if (StringUtils.isNotEmpty(title))
{ {
subMergedFirstRowNum++;
subMergedLastRowNum++;
int titleLastCol = this.fields.size() - 1; int titleLastCol = this.fields.size() - 1;
if (isSubList()) if (isSubList())
{ {
@ -206,7 +235,7 @@ public class ExcelUtil<T>
Cell titleCell = titleRow.createCell(0); Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title")); titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title); titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol)); sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), 0, titleLastCol));
} }
} }
@ -217,23 +246,31 @@ public class ExcelUtil<T>
{ {
if (isSubList()) if (isSubList())
{ {
subMergedFirstRowNum++;
subMergedLastRowNum++;
Row subRow = sheet.createRow(rownum); Row subRow = sheet.createRow(rownum);
int excelNum = 0; int column = 0;
int subFieldSize = subFields != null ? subFields.size() : 0;
for (Object[] objects : fields) for (Object[] objects : fields)
{ {
Field field = (Field) objects[0];
Excel attr = (Excel) objects[1]; Excel attr = (Excel) objects[1];
Cell headCell1 = subRow.createCell(excelNum); if (Collection.class.isAssignableFrom(field.getType()))
headCell1.setCellValue(attr.name()); {
headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); Cell cell = subRow.createCell(column);
excelNum++; cell.setCellValue(attr.name());
} cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
int headFirstRow = excelNum - 1; if (subFieldSize > 1)
int headLastRow = headFirstRow + subFields.size() - 1; {
if (headLastRow > headFirstRow) CellRangeAddress cellAddress = new CellRangeAddress(rownum, rownum, column, column + subFieldSize - 1);
{ sheet.addMergedRegion(cellAddress);
sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow)); }
column += subFieldSize;
}
else
{
Cell cell = subRow.createCell(column++);
cell.setCellValue(attr.name());
cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
}
} }
rownum++; rownum++;
} }
@ -246,11 +283,23 @@ public class ExcelUtil<T>
* @return 转换后集合 * @return 转换后集合
*/ */
public List<T> importExcel(InputStream is) public List<T> importExcel(InputStream is)
{
return importExcel(is, 0);
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
*/
public List<T> importExcel(InputStream is, int titleNum)
{ {
List<T> list = null; List<T> list = null;
try try
{ {
list = importExcel(is, 0); list = importExcel(StringUtils.EMPTY, is, titleNum);
} }
catch (Exception e) catch (Exception e)
{ {
@ -264,18 +313,6 @@ public class ExcelUtil<T>
return list; return list;
} }
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
*/
public List<T> importExcel(InputStream is, int titleNum) throws Exception
{
return importExcel(StringUtils.EMPTY, is, titleNum);
}
/** /**
* 对excel表单指定表格索引名转换成list * 对excel表单指定表格索引名转换成list
* *
@ -295,16 +332,7 @@ public class ExcelUtil<T>
{ {
throw new IOException("文件sheet不存在"); throw new IOException("文件sheet不存在");
} }
boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
Map<String, PictureData> pictures;
if (isXSSFWorkbook)
{
pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
}
else
{
pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
}
// 获取最后一个非空行的行下标比如总行数为n则返回的为n-1 // 获取最后一个非空行的行下标比如总行数为n则返回的为n-1
int rows = sheet.getLastRowNum(); int rows = sheet.getLastRowNum();
if (rows > 0) if (rows > 0)
@ -362,7 +390,7 @@ public class ExcelUtil<T>
if (String.class == fieldType) if (String.class == fieldType)
{ {
String s = Convert.toStr(val); String s = Convert.toStr(val);
if (StringUtils.endsWith(s, ".0")) if (s.matches("^\\d+\\.0$"))
{ {
val = StringUtils.substringBefore(s, ".0"); val = StringUtils.substringBefore(s, ".0");
} }
@ -425,32 +453,10 @@ public class ExcelUtil<T>
{ {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
} }
else if (StringUtils.isNotEmpty(attr.dictType()))
{
if (!sysDictMap.containsKey(attr.dictType() + val))
{
String dictValue = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
sysDictMap.put(attr.dictType() + val, dictValue);
}
val = sysDictMap.get(attr.dictType() + val);
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class)) else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{ {
val = dataFormatHandlerAdapter(val, attr, null); val = dataFormatHandlerAdapter(val, attr, null);
} }
else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
{
PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
if (image == null)
{
val = "";
}
else
{
byte[] data = image.getData();
val = FileUtils.writeImportBytes(data);
}
}
ReflectUtils.invokeSetter(entity, propertyName, val); ReflectUtils.invokeSetter(entity, propertyName, val);
} }
} }
@ -462,33 +468,7 @@ public class ExcelUtil<T>
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
* @param list 导出数据集合
* @param sheetName 工作表的名称
* @return 结果
*/
public AjaxResult exportExcel(List<T> list, String sheetName)
{
return exportExcel(list, sheetName, StringUtils.EMPTY);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param list 导出数据集合
* @param sheetName 工作表的名称
* @param title 标题
* @return 结果
*/
public AjaxResult exportExcel(List<T> list, String sheetName, String title)
{
this.init(list, sheetName, title, Type.EXPORT);
return exportExcel();
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param response 返回数据 * @param response 返回数据
* @param list 导出数据集合 * @param list 导出数据集合
* @param sheetName 工作表的名称 * @param sheetName 工作表的名称
@ -501,7 +481,7 @@ public class ExcelUtil<T>
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
* @param response 返回数据 * @param response 返回数据
* @param list 导出数据集合 * @param list 导出数据集合
* @param sheetName 工作表的名称 * @param sheetName 工作表的名称
@ -518,31 +498,7 @@ public class ExcelUtil<T>
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
* @param sheetName 工作表的名称
* @return 结果
*/
public AjaxResult importTemplateExcel(String sheetName)
{
return importTemplateExcel(sheetName, StringUtils.EMPTY);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称
* @param title 标题
* @return 结果
*/
public AjaxResult importTemplateExcel(String sheetName, String title)
{
this.init(null, sheetName, title, Type.IMPORT);
return exportExcel();
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称 * @param sheetName 工作表的名称
* @return 结果 * @return 结果
*/ */
@ -553,7 +509,7 @@ public class ExcelUtil<T>
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
* @param sheetName 工作表的名称 * @param sheetName 工作表的名称
* @param title 标题 * @param title 标题
* @return 结果 * @return 结果
@ -588,34 +544,6 @@ public class ExcelUtil<T>
} }
} }
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @return 结果
*/
public AjaxResult exportExcel()
{
OutputStream out = null;
try
{
writeSheet();
String filename = encodingFilename(sheetName);
out = new FileOutputStream(getAbsoluteFile(filename));
wb.write(out);
return AjaxResult.success(filename);
}
catch (Exception e)
{
log.error("导出Excel异常{}", e.getMessage());
throw new UtilException("导出Excel失败请联系网站管理员");
}
finally
{
IOUtils.closeQuietly(wb);
IOUtils.closeQuietly(out);
}
}
/** /**
* 创建写入数据到Sheet * 创建写入数据到Sheet
*/ */
@ -667,64 +595,91 @@ public class ExcelUtil<T>
{ {
int startNo = index * sheetSize; int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size()); int endNo = Math.min(startNo + sheetSize, list.size());
int rowNo = (1 + rownum) - startNo; int currentRowNum = rownum + 1; // 从标题行后开始
for (int i = startNo; i < endNo; i++) for (int i = startNo; i < endNo; i++)
{ {
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo; row = sheet.createRow(currentRowNum);
row = sheet.createRow(rowNo);
// 得到导出对象.
T vo = (T) list.get(i); T vo = (T) list.get(i);
Collection<?> subList = null;
if (isSubList())
{
if (isSubListValue(vo))
{
subList = getListCellValue(vo);
subMergedLastRowNum = subMergedLastRowNum + subList.size();
}
else
{
subMergedFirstRowNum++;
subMergedLastRowNum++;
}
}
int column = 0; int column = 0;
int maxSubListSize = getCurrentMaxSubListSize(vo);
for (Object[] os : fields) for (Object[] os : fields)
{ {
Field field = (Field) os[0]; Field field = (Field) os[0];
Excel excel = (Excel) os[1]; Excel excel = (Excel) os[1];
if (Collection.class.isAssignableFrom(field.getType()) && StringUtils.isNotNull(subList)) if (Collection.class.isAssignableFrom(field.getType()))
{ {
boolean subFirst = false; try
for (Object obj : subList)
{ {
if (subFirst) Collection<?> subList = (Collection<?>) getTargetValue(vo, field, excel);
if (subList != null && !subList.isEmpty())
{ {
rowNo++; int subIndex = 0;
row = sheet.createRow(rowNo); for (Object subVo : subList)
}
List<Field> subFields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), Excel.class);
int subIndex = 0;
for (Field subField : subFields)
{
if (subField.isAnnotationPresent(Excel.class))
{ {
subField.setAccessible(true); Row subRow = sheet.getRow(currentRowNum + subIndex);
Excel attr = subField.getAnnotation(Excel.class); if (subRow == null)
this.addCell(attr, row, (T) obj, subField, column + subIndex); {
subRow = sheet.createRow(currentRowNum + subIndex);
}
int subColumn = column;
for (Field subField : subFields)
{
Excel subExcel = subField.getAnnotation(Excel.class);
addCell(subExcel, subRow, (T) subVo, subField, subColumn++);
}
subIndex++;
} }
subIndex++; column += subFields.size();
} }
subFirst = true;
} }
this.subMergedFirstRowNum = this.subMergedFirstRowNum + subList.size(); catch (Exception e)
{
log.error("填充集合数据失败", e);
}
} }
else else
{ {
this.addCell(excel, row, vo, field, column++); // 创建单元格并设置值
addCell(excel, row, vo, field, column);
if (maxSubListSize > 1 && excel.needMerge())
{
sheet.addMergedRegion(new CellRangeAddress(currentRowNum, currentRowNum + maxSubListSize - 1, column, column));
}
column++;
}
}
currentRowNum += maxSubListSize;
}
}
/**
* 获取子列表最大数
*/
private int getCurrentMaxSubListSize(T vo)
{
int maxSubListSize = 1;
for (Object[] os : fields)
{
Field field = (Field) os[0];
if (Collection.class.isAssignableFrom(field.getType()))
{
try
{
Collection<?> subList = (Collection<?>) getTargetValue(vo, field, (Excel) os[1]);
if (subList != null && !subList.isEmpty())
{
maxSubListSize = Math.max(maxSubListSize, subList.size());
}
}
catch (Exception e)
{
log.error("获取集合大小失败", e);
} }
} }
} }
return maxSubListSize;
} }
/** /**
@ -859,7 +814,7 @@ public class ExcelUtil<T>
*/ */
public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel) public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel)
{ {
String key = StringUtils.format("data_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType()); String key = StringUtils.format("data_{}_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType(), excel.wrapText());
if (!styles.containsKey(key)) if (!styles.containsKey(key))
{ {
CellStyle style = wb.createCellStyle(); CellStyle style = wb.createCellStyle();
@ -875,6 +830,7 @@ public class ExcelUtil<T>
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(excel.backgroundColor().getIndex()); style.setFillForegroundColor(excel.backgroundColor().getIndex());
style.setWrapText(excel.wrapText());
Font dataFont = wb.createFont(); Font dataFont = wb.createFont();
dataFont.setFontName("Arial"); dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10); dataFont.setFontHeightInPoints((short) 10);
@ -903,7 +859,7 @@ public class ExcelUtil<T>
if (isSubList()) if (isSubList())
{ {
// 填充默认样式防止合并单元格样式失效 // 填充默认样式防止合并单元格样式失效
sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType()))); sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
if (attr.needMerge()) if (attr.needMerge())
{ {
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column)); sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
@ -998,28 +954,17 @@ public class ExcelUtil<T>
// 设置列宽 // 设置列宽
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
} }
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0 || attr.comboReadDict()) if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
{ {
String[] comboArray = attr.combo(); if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
if (attr.comboReadDict())
{
if (!sysDictMap.containsKey("combo_" + attr.dictType()))
{
String labels = DictUtils.getDictLabels(attr.dictType());
sysDictMap.put("combo_" + attr.dictType(), labels);
}
String val = sysDictMap.get("combo_" + attr.dictType());
comboArray = StringUtils.split(val, DictUtils.SEPARATOR);
}
if (comboArray.length > 15 || StringUtils.join(comboArray).length() > 255)
{ {
// 如果下拉数大于15或字符串长度大于255则使用一个新sheet存储避免生成的模板下拉值获取不到 // 如果下拉数大于15或字符串长度大于255则使用一个新sheet存储避免生成的模板下拉值获取不到
setXSSFValidationWithHidden(sheet, comboArray, attr.prompt(), 1, 100, column, column); setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
} }
else else
{ {
// 提示信息或只能选择不能输入的列内容. // 提示信息或只能选择不能输入的列内容.
setPromptOrValidation(sheet, comboArray, attr.prompt(), 1, 100, column, column); setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
} }
} }
} }
@ -1041,34 +986,27 @@ public class ExcelUtil<T>
cell = row.createCell(column); cell = row.createCell(column);
if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge()) if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge())
{ {
CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column); if (subMergedLastRowNum >= subMergedFirstRowNum)
sheet.addMergedRegion(cellAddress); {
sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
}
} }
cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType()))); cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
// 用于读取对象中的属性 // 用于读取对象中的属性
Object value = getTargetValue(vo, field, attr); Object value = getTargetValue(vo, field, attr);
String dateFormat = attr.dateFormat(); String dateFormat = attr.dateFormat();
String readConverterExp = attr.readConverterExp(); String readConverterExp = attr.readConverterExp();
String separator = attr.separator(); String separator = attr.separator();
String dictType = attr.dictType();
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
{ {
cell.getCellStyle().setDataFormat(this.wb.getCreationHelper().createDataFormat().getFormat(dateFormat));
cell.setCellValue(parseDateToStr(dateFormat, value)); cell.setCellValue(parseDateToStr(dateFormat, value));
} }
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
{ {
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
} }
else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
{
if (!sysDictMap.containsKey(dictType + value))
{
String lable = convertDictByExp(Convert.toStr(value), dictType, separator);
sysDictMap.put(dictType + value, lable);
}
cell.setCellValue(sysDictMap.get(dictType + value));
}
else if (value instanceof BigDecimal && -1 != attr.scale()) else if (value instanceof BigDecimal && -1 != attr.scale())
{ {
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue());
@ -1255,35 +1193,9 @@ public class ExcelUtil<T>
return StringUtils.stripEnd(propertyString.toString(), separator); return StringUtils.stripEnd(propertyString.toString(), separator);
} }
/**
* 解析字典值
*
* @param dictValue 字典值
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典标签
*/
public static String convertDictByExp(String dictValue, String dictType, String separator)
{
return DictUtils.getDictLabel(dictType, dictValue, separator);
}
/**
* 反向解析值字典值
*
* @param dictLabel 字典标签
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典值
*/
public static String reverseDictByExp(String dictLabel, String dictType, String separator)
{
return DictUtils.getDictValue(dictType, dictLabel, separator);
}
/** /**
* 数据处理器 * 数据处理器
* *
* @param value 数据值 * @param value 数据值
* @param excel 数据注解 * @param excel 数据注解
* @return * @return
@ -1349,34 +1261,9 @@ public class ExcelUtil<T>
} }
} }
/**
* 编码文件名
*/
public String encodingFilename(String filename)
{
filename = UUID.randomUUID() + "_" + filename + ".xlsx";
return filename;
}
/**
* 获取下载路径
*
* @param filename 文件名称
*/
public String getAbsoluteFile(String filename)
{
String downloadPath = TcctynConfig.getDownloadPath() + filename;
File desc = new File(downloadPath);
if (!desc.getParentFile().exists())
{
desc.getParentFile().mkdirs();
}
return downloadPath;
}
/** /**
* 获取bean中的属性值 * 获取bean中的属性值
* *
* @param vo 实体对象 * @param vo 实体对象
* @param field 字段 * @param field 字段
* @param excel 注解 * @param excel 注解
@ -1385,6 +1272,7 @@ public class ExcelUtil<T>
*/ */
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
{ {
field.setAccessible(true);
Object o = field.get(vo); Object o = field.get(vo);
if (StringUtils.isNotEmpty(excel.targetAttr())) if (StringUtils.isNotEmpty(excel.targetAttr()))
{ {
@ -1407,7 +1295,7 @@ public class ExcelUtil<T>
/** /**
* 以类的属性的get方法方法形式获取值 * 以类的属性的get方法方法形式获取值
* *
* @param o * @param o
* @param name * @param name
* @return value * @return value
@ -1444,46 +1332,83 @@ public class ExcelUtil<T>
List<Field> tempFields = new ArrayList<>(); List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
for (Field field : tempFields) if (StringUtils.isNotEmpty(includeFields))
{ {
if (!ArrayUtils.contains(this.excludeFields, field.getName())) for (Field field : tempFields)
{ {
// 单注解 if (ArrayUtils.contains(this.includeFields, field.getName()) || field.isAnnotationPresent(Excels.class))
if (field.isAnnotationPresent(Excel.class))
{ {
Excel attr = field.getAnnotation(Excel.class); addField(fields, field);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) }
}
}
else if (StringUtils.isNotEmpty(excludeFields))
{
for (Field field : tempFields)
{
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
{
addField(fields, field);
}
}
}
else
{
for (Field field : tempFields)
{
addField(fields, field);
}
}
return fields;
}
/**
* 添加字段信息
*/
public void addField(List<Object[]> fields, Field field)
{
// 单注解
if (field.isAnnotationPresent(Excel.class))
{
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
{
fields.add(new Object[] { field, attr });
}
if (Collection.class.isAssignableFrom(field.getType()))
{
subMethod = getSubMethod(field.getName(), clazz);
ParameterizedType pt = (ParameterizedType) field.getGenericType();
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
}
}
// 多注解
if (field.isAnnotationPresent(Excels.class))
{
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel attr : excels)
{
if (StringUtils.isNotEmpty(includeFields))
{
if (ArrayUtils.contains(this.includeFields, field.getName() + "." + attr.targetAttr())
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
{ {
field.setAccessible(true);
fields.add(new Object[] { field, attr }); fields.add(new Object[] { field, attr });
} }
if (Collection.class.isAssignableFrom(field.getType()))
{
subMethod = getSubMethod(field.getName(), clazz);
ParameterizedType pt = (ParameterizedType) field.getGenericType();
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
}
} }
else
// 多注解
if (field.isAnnotationPresent(Excels.class))
{ {
Excels attrs = field.getAnnotation(Excels.class); if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
Excel[] excels = attrs.value(); && (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
for (Excel attr : excels)
{ {
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr()) fields.add(new Object[] { field, attr });
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
{
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
} }
} }
} }
} }
return fields;
} }
/** /**
@ -1611,71 +1536,6 @@ public class ExcelUtil<T>
return true; return true;
} }
/**
* 获取Excel2003图片
*
* @param sheet 当前sheet对象
* @param workbook 工作簿对象
* @return Map key:图片单元格索引1_1Stringvalue:图片流PictureData
*/
public static Map<String, PictureData> getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook)
{
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
List<HSSFPictureData> pictures = workbook.getAllPictures();
if (!pictures.isEmpty())
{
for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren())
{
HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
if (shape instanceof HSSFPicture)
{
HSSFPicture pic = (HSSFPicture) shape;
int pictureIndex = pic.getPictureIndex() - 1;
HSSFPictureData picData = pictures.get(pictureIndex);
String picIndex = anchor.getRow1() + "_" + anchor.getCol1();
sheetIndexPicMap.put(picIndex, picData);
}
}
return sheetIndexPicMap;
}
else
{
return sheetIndexPicMap;
}
}
/**
* 获取Excel2007图片
*
* @param sheet 当前sheet对象
* @param workbook 工作簿对象
* @return Map key:图片单元格索引1_1Stringvalue:图片流PictureData
*/
public static Map<String, PictureData> getSheetPictures07(XSSFSheet sheet, XSSFWorkbook workbook)
{
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
for (POIXMLDocumentPart dr : sheet.getRelations())
{
if (dr instanceof XSSFDrawing)
{
XSSFDrawing drawing = (XSSFDrawing) dr;
List<XSSFShape> shapes = drawing.getShapes();
for (XSSFShape shape : shapes)
{
if (shape instanceof XSSFPicture)
{
XSSFPicture pic = (XSSFPicture) shape;
XSSFClientAnchor anchor = pic.getPreferredSize();
CTMarker ctMarker = anchor.getFrom();
String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
sheetIndexPicMap.put(picIndex, pic.getPictureData());
}
}
}
}
return sheetIndexPicMap;
}
/** /**
* 格式化不同类型的日期对象 * 格式化不同类型的日期对象
* *

View File

@ -1,15 +1,19 @@
package com.tcctyn.common.core.utils.reflect; package com.tcctyn.common.core.utils.reflect;
import com.tcctyn.common.core.text.Convert; import java.lang.reflect.Field;
import com.tcctyn.common.core.utils.DateUtils; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.tcctyn.common.core.text.Convert;
import java.lang.reflect.*; import com.tcctyn.common.core.utils.DateUtils;
import java.util.Date;
/** /**
* 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数. * 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.

View File

@ -13,7 +13,7 @@ public class SqlUtil
/** /**
* 定义常用的 sql关键字 * 定义常用的 sql关键字
*/ */
public static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()"; public static String SQL_REGEX = "\u000B|and |extractvalue|updatexml|sleep|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |union |like |+|/*|user()";
/** /**
* 仅支持字母数字下划线空格逗号小数点支持多个字段排序 * 仅支持字母数字下划线空格逗号小数点支持多个字段排序

View File

@ -1,10 +1,9 @@
package com.tcctyn.common.core.utils.uuid; package com.tcctyn.common.core.utils.uuid;
import java.util.concurrent.atomic.AtomicInteger;
import com.tcctyn.common.core.utils.DateUtils; import com.tcctyn.common.core.utils.DateUtils;
import com.tcctyn.common.core.utils.StringUtils; import com.tcctyn.common.core.utils.StringUtils;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author tcctyn 序列生成类 * @author tcctyn 序列生成类
*/ */

View File

@ -1,12 +1,11 @@
package com.tcctyn.common.core.utils.uuid; package com.tcctyn.common.core.utils.uuid;
import com.tcctyn.common.core.exception.UtilException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import com.tcctyn.common.core.exception.UtilException;
/** /**
* 提供通用唯一识别码universally unique identifierUUID实现 * 提供通用唯一识别码universally unique identifierUUID实现
@ -67,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
} }
/** /**
* 获取类型 4伪随机生成的UUID 的静态工厂 * 获取类型 4伪随机生成的UUID 的静态工厂
* *
* @return 随机生成的 {@code UUID} * @return 随机生成的 {@code UUID}
*/ */

View File

@ -1,44 +1,45 @@
package com.tcctyn.common.core.web.controller; package com.tcctyn.common.core.web.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tcctyn.common.core.constant.HttpStatus;
import com.tcctyn.common.core.web.domain.AjaxResult;
import com.tcctyn.common.core.web.domain.model.LoginUser;
import com.tcctyn.common.core.web.page.PageDomain;
import com.tcctyn.common.core.web.page.TableDataInfo;
import com.tcctyn.common.core.web.page.TableSupport;
import com.tcctyn.common.core.utils.DateUtils;
import com.tcctyn.common.core.utils.PageUtils;
import com.tcctyn.common.core.utils.SecurityUtils;
import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.sql.SqlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import java.beans.PropertyEditorSupport; import java.beans.PropertyEditorSupport;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tcctyn.common.core.constant.HttpStatus;
import com.tcctyn.common.core.utils.DateUtils;
import com.tcctyn.common.core.utils.PageUtils;
import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.sql.SqlUtil;
import com.tcctyn.common.core.web.domain.AjaxResult;
import com.tcctyn.common.core.web.page.PageDomain;
import com.tcctyn.common.core.web.page.TableDataInfo;
import com.tcctyn.common.core.web.page.TableSupport;
/** /**
* web层通用数据处理 * web层通用数据处理
* *
* @author tcctyn * @author tcctyn
*/ */
public class BaseController { public class BaseController
{
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/** /**
* 将前台传递过来的日期格式的字符串自动转化为Date类型 * 将前台传递过来的日期格式的字符串自动转化为Date类型
*/ */
@InitBinder @InitBinder
public void initBinder(WebDataBinder binder) { public void initBinder(WebDataBinder binder)
{
// Date 类型转换 // Date 类型转换
binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
{
@Override @Override
public void setAsText(String text) { public void setAsText(String text)
{
setValue(DateUtils.parseDate(text)); setValue(DateUtils.parseDate(text));
} }
}); });
@ -47,16 +48,19 @@ public class BaseController {
/** /**
* 设置请求分页数据 * 设置请求分页数据
*/ */
protected void startPage() { protected void startPage()
{
PageUtils.startPage(); PageUtils.startPage();
} }
/** /**
* 设置请求排序数据 * 设置请求排序数据
*/ */
protected void startOrderBy() { protected void startOrderBy()
{
PageDomain pageDomain = TableSupport.buildPageRequest(); PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) { if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
{
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
PageHelper.orderBy(orderBy); PageHelper.orderBy(orderBy);
} }
@ -65,132 +69,92 @@ public class BaseController {
/** /**
* 清理分页的线程变量 * 清理分页的线程变量
*/ */
protected void clearPage() { protected void clearPage()
{
PageUtils.clearPage(); PageUtils.clearPage();
} }
/** /**
* 响应请求分页数据 * 响应请求分页数据
*/ */
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({ "rawtypes", "unchecked" })
protected TableDataInfo getDataTable(List<?> list) { protected TableDataInfo getDataTable(List<?> list)
{
TableDataInfo rspData = new TableDataInfo(); TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS); rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
rspData.setRows(list); rspData.setRows(list);
rspData.setMsg("查询成功");
rspData.setTotal(new PageInfo(list).getTotal()); rspData.setTotal(new PageInfo(list).getTotal());
return rspData; return rspData;
} }
/**
* 涉及到DO转VO的使用下面这个方法
* @Param dolist 数据库查询出来的list
* @Param volist 前台展示的list
*/
protected TableDataInfo getDataTable(List<?> dolist, List<?> voList) {
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
rspData.setRows(voList);
rspData.setTotal(new PageInfo(dolist).getTotal());
return rspData;
}
/** /**
* 返回成功 * 返回成功
*/ */
public AjaxResult success() { public AjaxResult success()
{
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* 返回失败消息
*/
public AjaxResult error() {
return AjaxResult.error();
}
/** /**
* 返回成功消息 * 返回成功消息
*/ */
public AjaxResult success(String message) { public AjaxResult success(String message)
{
return AjaxResult.success(message); return AjaxResult.success(message);
} }
/** /**
* 返回成功消息 * 返回成功消息
*/ */
public AjaxResult success(Object data) { public AjaxResult success(Object data)
{
return AjaxResult.success(data); return AjaxResult.success(data);
} }
/** /**
* 返回失败消息 * 返回失败消息
*/ */
public AjaxResult error(String message) { public AjaxResult error()
{
return AjaxResult.error();
}
/**
* 返回失败消息
*/
public AjaxResult error(String message)
{
return AjaxResult.error(message); return AjaxResult.error(message);
} }
/** /**
* 返回警告消息 * 返回警告消息
*/ */
public AjaxResult warn(String message) { public AjaxResult warn(String message)
{
return AjaxResult.warn(message); return AjaxResult.warn(message);
} }
/** /**
* 响应返回结果 * 响应返回结果
* *
* @param rows 影响行数 * @param rows 影响行数
* @return 操作结果 * @return 操作结果
*/ */
protected AjaxResult toAjax(int rows) { protected AjaxResult toAjax(int rows)
{
return rows > 0 ? AjaxResult.success() : AjaxResult.error(); return rows > 0 ? AjaxResult.success() : AjaxResult.error();
} }
/** /**
* 响应返回结果 * 响应返回结果
* *
* @param result 结果 * @param result 结果
* @return 操作结果 * @return 操作结果
*/ */
protected AjaxResult toAjax(boolean result) { protected AjaxResult toAjax(boolean result)
{
return result ? success() : error(); return result ? success() : error();
} }
/**
* 页面跳转
*/
public String redirect(String url) {
return StringUtils.format("redirect:{}", url);
}
/**
* 获取用户缓存信息
*/
public LoginUser getLoginUser() {
return SecurityUtils.getLoginUser();
}
/**
* 获取登录用户id
*/
public Long getUserId() {
return getLoginUser().getUserId();
}
/**
* 获取登录部门id
*/
public Long getDeptId() {
return getLoginUser().getDeptId();
}
/**
* 获取登录用户名
*/
public String getUsername() {
return getLoginUser().getUsername();
}
} }

View File

@ -1,10 +1,9 @@
package com.tcctyn.common.core.web.domain; package com.tcctyn.common.core.web.domain;
import com.tcctyn.common.core.constant.HttpStatus;
import com.tcctyn.common.core.utils.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import com.tcctyn.common.core.constant.HttpStatus;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 操作消息提醒 * 操作消息提醒
@ -204,9 +203,9 @@ public class AjaxResult extends HashMap<String, Object>
/** /**
* 方便链式调用 * 方便链式调用
* *
* @param key * @param key
* @param value * @param value
* @return 数据对象 * @return
*/ */
@Override @Override
public AjaxResult put(String key, Object value) public AjaxResult put(String key, Object value)

View File

@ -1,14 +1,12 @@
package com.tcctyn.common.core.web.domain; package com.tcctyn.common.core.web.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
/** /**
* Entity基类 * Entity基类
@ -21,7 +19,6 @@ public class BaseEntity implements Serializable
/** 搜索值 */ /** 搜索值 */
@JsonIgnore @JsonIgnore
@TableField(exist = false)
private String searchValue; private String searchValue;
/** 创建者 */ /** 创建者 */
@ -39,12 +36,10 @@ public class BaseEntity implements Serializable
private Date updateTime; private Date updateTime;
/** 备注 */ /** 备注 */
@TableField(exist = false)
private String remark; private String remark;
/** 请求参数 */ /** 请求参数 */
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@TableField(exist = false)
private Map<String, Object> params; private Map<String, Object> params;
public String getSearchValue() public String getSearchValue()

View File

@ -37,7 +37,7 @@ public class TableDataInfo implements Serializable
* @param list 列表数据 * @param list 列表数据
* @param total 总记录数 * @param total 总记录数
*/ */
public TableDataInfo(List<?> list, int total) public TableDataInfo(List<?> list, long total)
{ {
this.rows = list; this.rows = list;
this.total = total; this.total = total;
@ -82,4 +82,4 @@ public class TableDataInfo implements Serializable
{ {
this.msg = msg; this.msg = msg;
} }
} }

View File

@ -1,11 +1,10 @@
package com.tcctyn.common.core.xss; package com.tcctyn.common.core.xss;
import com.tcctyn.common.core.utils.StringUtils;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import com.tcctyn.common.core.utils.StringUtils;
/** /**
* 自定义xss校验注解实现 * 自定义xss校验注解实现

View File

@ -85,24 +85,9 @@
<dependency> <dependency>
<groupId>com.hikvision.ga</groupId> <groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId> <artifactId>artemis-http-client</artifactId>
<version>${artemis-http-client.version}</version> <version>1.1.3</version>
</dependency> </dependency>
<!-- mybatis-plus 增强CRUD -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-boot-starter</artifactId>
<version>${mybatis-plus-join-boot-starter.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -4,12 +4,10 @@ import com.tcctyn.common.security.annotation.EnableCustomConfig;
import com.tcctyn.common.security.annotation.EnableRyFeignClients; import com.tcctyn.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@EnableCustomConfig @EnableCustomConfig
@EnableRyFeignClients @EnableRyFeignClients
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = {"com.tcctyn.iot.**", "com.tcctyn.common.**"})
public class TcctynIotApplication { public class TcctynIotApplication {
public static void main(String[] args) public static void main(String[] args)

View File

@ -23,29 +23,3 @@ spring:
import: import:
# - optional:nacos:application-@profiles.active@.yml # - optional:nacos:application-@profiles.active@.yml
- optional:nacos:${spring.application.name}-@profiles.active@.yml - optional:nacos:${spring.application.name}-@profiles.active@.yml
# 海康运营管理中心接口配置
artemis:
path: /artemis
host: 116.53.205.228:14443
app-key: 21887937
app-secret: hwOzOEqxuPDz5frAnEXb
# 测试使用为了系统安全通常生产环境不建议开启swagger。
springdoc:
swagger-ui:
path: /swagger-ui.html
disable-swagger-default-url: true
# 关键修复配置 ↓
url: /v3/api-docs # 改用YAML格式
config-url: /v3/api-docs/swagger-config
api-docs:
path: /v3/api-docs
enabled: true
# 必须配置扫描 ↓
paths-to-match: /**
packages-to-scan: com.tcctyn.iot.hk.controller
cache:
disabled: true # 开发时禁用缓存

View File

@ -4,6 +4,7 @@ import com.tcctyn.common.security.annotation.EnableCustomConfig;
import com.tcctyn.common.security.annotation.EnableRyFeignClients; import com.tcctyn.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/** /**
* 系统模块 * 系统模块

View File

@ -1,5 +1,17 @@
package com.tcctyn.system.controller; package com.tcctyn.system.controller;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tcctyn.common.core.constant.UserConstants; import com.tcctyn.common.core.constant.UserConstants;
import com.tcctyn.common.core.utils.StringUtils; import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.web.controller.BaseController; import com.tcctyn.common.core.web.controller.BaseController;
@ -10,12 +22,6 @@ import com.tcctyn.common.security.annotation.RequiresPermissions;
import com.tcctyn.common.security.utils.SecurityUtils; import com.tcctyn.common.security.utils.SecurityUtils;
import com.tcctyn.system.api.domain.SysDept; import com.tcctyn.system.api.domain.SysDept;
import com.tcctyn.system.service.ISysDeptService; import com.tcctyn.system.service.ISysDeptService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 部门信息 * 部门信息
@ -124,24 +130,4 @@ public class SysDeptController extends BaseController
deptService.checkDeptDataScope(deptId); deptService.checkDeptDataScope(deptId);
return toAjax(deptService.deleteDeptById(deptId)); return toAjax(deptService.deleteDeptById(deptId));
} }
/**
* 根据条件查询用户列表
*/
@PostMapping("/selectDeptList")
public List<SysDept> selectUserList(SysDept sysDept) {
return deptService.selectDeptList(sysDept);
}
/**
* 根据条件查询用户列表
*/
@PostMapping("/selectDeptById/{deptId}")
public SysDept selectDeptById(@PathVariable("deptId") Long deptId) {
return deptService.selectDeptById(deptId);
}
} }

View File

@ -1,6 +1,6 @@
package com.tcctyn.system.controller; package com.tcctyn.system.controller;
import com.tcctyn.common.core.web.domain.R; import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.utils.file.FileUtils; import com.tcctyn.common.core.utils.file.FileUtils;
import com.tcctyn.system.api.domain.SysFile; import com.tcctyn.system.api.domain.SysFile;
import com.tcctyn.system.service.ISysFileService; import com.tcctyn.system.service.ISysFileService;

View File

@ -1,6 +1,17 @@
package com.tcctyn.system.controller; package com.tcctyn.system.controller;
import com.tcctyn.common.core.web.domain.R; import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.utils.StringUtils; import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.file.FileTypeUtils; import com.tcctyn.common.core.utils.file.FileTypeUtils;
import com.tcctyn.common.core.utils.file.MimeTypeUtils; import com.tcctyn.common.core.utils.file.MimeTypeUtils;
@ -15,13 +26,6 @@ import com.tcctyn.system.api.domain.SysFile;
import com.tcctyn.system.api.domain.SysUser; import com.tcctyn.system.api.domain.SysUser;
import com.tcctyn.system.api.model.LoginUser; import com.tcctyn.system.api.model.LoginUser;
import com.tcctyn.system.service.ISysUserService; import com.tcctyn.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.Map;
/** /**
* 个人信息 业务处理 * 个人信息 业务处理
@ -33,7 +37,6 @@ import java.util.Map;
public class SysProfileController extends BaseController public class SysProfileController extends BaseController
{ {
@Autowired @Autowired
@Lazy
private ISysUserService userService; private ISysUserService userService;
@Autowired @Autowired

View File

@ -1,5 +1,17 @@
package com.tcctyn.system.controller; package com.tcctyn.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tcctyn.common.core.utils.poi.ExcelUtil; import com.tcctyn.common.core.utils.poi.ExcelUtil;
import com.tcctyn.common.core.web.controller.BaseController; import com.tcctyn.common.core.web.controller.BaseController;
import com.tcctyn.common.core.web.domain.AjaxResult; import com.tcctyn.common.core.web.domain.AjaxResult;
@ -15,12 +27,6 @@ import com.tcctyn.system.domain.SysUserRole;
import com.tcctyn.system.service.ISysDeptService; import com.tcctyn.system.service.ISysDeptService;
import com.tcctyn.system.service.ISysRoleService; import com.tcctyn.system.service.ISysRoleService;
import com.tcctyn.system.service.ISysUserService; import com.tcctyn.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/** /**
* 角色信息 * 角色信息

View File

@ -1,6 +1,23 @@
package com.tcctyn.system.controller; package com.tcctyn.system.controller;
import com.tcctyn.common.core.web.domain.R; import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.tcctyn.common.core.domain.R;
import com.tcctyn.common.core.utils.StringUtils; import com.tcctyn.common.core.utils.StringUtils;
import com.tcctyn.common.core.utils.poi.ExcelUtil; import com.tcctyn.common.core.utils.poi.ExcelUtil;
import com.tcctyn.common.core.web.controller.BaseController; import com.tcctyn.common.core.web.controller.BaseController;
@ -16,18 +33,12 @@ import com.tcctyn.system.api.domain.SysDept;
import com.tcctyn.system.api.domain.SysRole; import com.tcctyn.system.api.domain.SysRole;
import com.tcctyn.system.api.domain.SysUser; import com.tcctyn.system.api.domain.SysUser;
import com.tcctyn.system.api.model.LoginUser; import com.tcctyn.system.api.model.LoginUser;
import com.tcctyn.system.service.*; import com.tcctyn.system.service.ISysConfigService;
import org.apache.commons.lang3.ArrayUtils; import com.tcctyn.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired; import com.tcctyn.system.service.ISysPermissionService;
import org.springframework.validation.annotation.Validated; import com.tcctyn.system.service.ISysPostService;
import org.springframework.web.bind.annotation.*; import com.tcctyn.system.service.ISysRoleService;
import org.springframework.web.multipart.MultipartFile; import com.tcctyn.system.service.ISysUserService;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 用户信息 * 用户信息
@ -337,32 +348,4 @@ public class SysUserController extends BaseController
{ {
return success(deptService.selectDeptTreeList(dept)); return success(deptService.selectDeptTreeList(dept));
} }
/**
* 根据条件查询用户列表
*/
@PostMapping("/selectUserList")
public List<SysUser> selectUserList(SysUser user) {
return userService.selectUserList(user);
}
/**
* 根据条件查询用户列表
*/
@PostMapping("/selectUserById/{userId}")
public SysUser selectUserById(@PathVariable("userId") Long userId) {
return userService.selectUserById(userId);
}
/**
* 获取用户列表用于前端选择器
* @param regionId 归属地区id
* @return
*/
@GetMapping("/userNames/{regionId}")
public List<SysUser> getOrdinaryUser(@PathVariable("regionId") Long regionId) {
return userService.getOrdinaryUser(regionId);
}
} }

View File

@ -1,9 +1,8 @@
package com.tcctyn.system.mapper; package com.tcctyn.system.mapper;
import com.tcctyn.system.api.domain.SysUser;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.tcctyn.system.api.domain.SysUser;
/** /**
* 用户表 数据层 * 用户表 数据层
@ -125,10 +124,4 @@ public interface SysUserMapper
* @return 结果 * @return 结果
*/ */
public SysUser checkEmailUnique(String email); public SysUser checkEmailUnique(String email);
/**
* 获取用户信息用于前端选择
* @return
*/
public List<SysUser> selectOrdinaryUser(Long regionId);
} }

View File

@ -1,8 +1,7 @@
package com.tcctyn.system.service; package com.tcctyn.system.service;
import com.tcctyn.system.api.domain.SysUser;
import java.util.List; import java.util.List;
import com.tcctyn.system.api.domain.SysUser;
/** /**
* 用户 业务层 * 用户 业务层
@ -204,6 +203,4 @@ public interface ISysUserService
* @return 结果 * @return 结果
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
List<SysUser> getOrdinaryUser(Long regionId);
} }

View File

@ -1,5 +1,15 @@
package com.tcctyn.system.service.impl; package com.tcctyn.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.tcctyn.common.core.constant.UserConstants; import com.tcctyn.common.core.constant.UserConstants;
import com.tcctyn.common.core.exception.ServiceException; import com.tcctyn.common.core.exception.ServiceException;
import com.tcctyn.common.core.utils.SpringUtils; import com.tcctyn.common.core.utils.SpringUtils;
@ -12,21 +22,14 @@ import com.tcctyn.system.api.domain.SysUser;
import com.tcctyn.system.domain.SysPost; import com.tcctyn.system.domain.SysPost;
import com.tcctyn.system.domain.SysUserPost; import com.tcctyn.system.domain.SysUserPost;
import com.tcctyn.system.domain.SysUserRole; import com.tcctyn.system.domain.SysUserRole;
import com.tcctyn.system.mapper.*; import com.tcctyn.system.mapper.SysPostMapper;
import com.tcctyn.system.mapper.SysRoleMapper;
import com.tcctyn.system.mapper.SysUserMapper;
import com.tcctyn.system.mapper.SysUserPostMapper;
import com.tcctyn.system.mapper.SysUserRoleMapper;
import com.tcctyn.system.service.ISysConfigService; import com.tcctyn.system.service.ISysConfigService;
import com.tcctyn.system.service.ISysDeptService; import com.tcctyn.system.service.ISysDeptService;
import com.tcctyn.system.service.ISysUserService; import com.tcctyn.system.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.validation.Validator;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 用户 业务层处理 * 用户 业务层处理
@ -34,7 +37,7 @@ import java.util.stream.Collectors;
* @author tcctyn * @author tcctyn
*/ */
@Service @Service
public abstract class SysUserServiceImpl implements ISysUserService public class SysUserServiceImpl implements ISysUserService
{ {
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
@ -544,13 +547,5 @@ public abstract class SysUserServiceImpl implements ISysUserService
} }
return successMsg.toString(); return successMsg.toString();
} }
/**
* 获取用户信息用于前端选择器
*
* @return
*/
@Override
public List<SysUser> getOrdinaryUser(Long regionId) {
return userMapper.selectOrdinaryUser(regionId);
}
} }

View File

@ -216,15 +216,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{userId} #{userId}
</foreach> </foreach>
</delete> </delete>
<!-- 查询用户信息用于前端选择器 -->
<select id="selectOrdinaryUser" parameterType="Long" resultMap="SysUserResult">
select u.user_id, u.region_id, u.user_name, u.nick_name
from sys_user u where u.del_flag = '0' and u.user_name != 'admin'
<if test="region_id != null">
AND u.region_id = #{region_id}
</if>
</select>
</mapper> </mapper>