roles;
/** 角色组 */
- @TableField(exist = false)
private Long[] roleIds;
/** 岗位组 */
- @TableField(exist = false)
private Long[] postIds;
/** 角色ID */
- @TableField(exist = false)
private Long roleId;
private String remark;
public SysUser()
diff --git a/bs-common/src/main/java/com/bs/common/core/domain/entity/TenantConfig.java b/bs-common/src/main/java/com/bs/common/core/domain/entity/TenantConfig.java
deleted file mode 100644
index d091d14..0000000
--- a/bs-common/src/main/java/com/bs/common/core/domain/entity/TenantConfig.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package com.bs.common.core.domain.entity;
-
-import com.baomidou.mybatisplus.annotation.*;
-import com.bs.common.annotation.Excel;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-import java.time.LocalDateTime;
-import java.util.Date;
-
-/**
- * 租户配置对象 tenant_config
- *
- * @author ruoyi
- * @date 2023-04-02
- */
-@Accessors(chain = true)
-@TableName("tenant_config")
-@Data
-public class TenantConfig
-{
- private static final long serialVersionUID = 1L;
-
- /** $column.columnComment */
- @TableId(value = "ID",type = IdType.AUTO)
- @ApiModelProperty(value = "${column.columnComment}")
- private Long id;
-
- /**
- * 创建部门
- */
- @TableField(fill = FieldFill.INSERT)
- private Long createDept;
- @TableField(exist = false)
- private Long tenantId;
-
- /**
- * 创建者
- */
- @TableField(fill = FieldFill.INSERT)
- private Long createBy;
-
- /**
- * 创建时间
- */
- @TableField(fill = FieldFill.INSERT)
- private LocalDateTime createTime;
-
- /**
- * 更新者
- */
- @TableField(fill = FieldFill.INSERT_UPDATE)
- private Long updateBy;
-
- /**
- * 更新时间
- */
- @TableField(fill = FieldFill.INSERT_UPDATE)
- private LocalDateTime updateTime;
- /**
- * 逻辑删除标示
- */
- //做删除操作的时候,会变成update,del_flag = '2'
- @TableLogic(value = "0", delval = "2")
- @TableField(fill = FieldFill.INSERT)
- @JsonIgnore
- private String delFlag;
-
-
- @JsonFormat(pattern = "yyyy-MM-dd")
- @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
- @ApiModelProperty(value = "开始时间")
- private Date startData;
-
- /** 结束时间 */
-
- @JsonFormat(pattern = "yyyy-MM-dd")
- @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
- @ApiModelProperty(value = "结束时间")
- private Date stopData;
-
- /** 是否限制用户数 */
-
- @Excel(name = "是否限制用户数")
- @ApiModelProperty(value = "是否限制用户数")
- private String isUserAstrict;
-
- @Excel(name = "首页类型")
- @ApiModelProperty(value = "首页类型")
- private String homeType;
-
- /** 用户数 */
-
- @Excel(name = "用户数")
- @ApiModelProperty(value = "用户数")
- private Integer userQuantity;
-
- /** 是否限制在线数 */
-
- @Excel(name = "是否限制在线数")
- @ApiModelProperty(value = "是否限制在线数")
- private String isOnLine;
-
- /** 在线数 */
-
- @Excel(name = "在线数")
- @ApiModelProperty(value = "在线数")
- private Integer onLineUserQuantity;
-
- /** 是否定义系统名称 */
-
- @Excel(name = "是否定义系统名称")
- @ApiModelProperty(value = "是否定义系统名称")
- private String isDefinitionName;
-
- /** 系统名称 */
-
- @Excel(name = "系统名称")
- @ApiModelProperty(value = "系统名称")
- private String sysName;
-
- /** 是否定义系统logo */
-
- @Excel(name = "是否定义系统logo")
- @ApiModelProperty(value = "是否定义系统logo")
- private String isDefinitionLogo;
-
- /** 系统log */
-
- @Excel(name = "系统log")
- @ApiModelProperty(value = "系统log")
- private String sysLog;
-
- /** 是否定义系统色调 */
-
- @Excel(name = "是否定义系统色调")
- @ApiModelProperty(value = "是否定义系统色调")
- private String isDefinitionHue;
-
- /** 系统色调 */
-
- @Excel(name = "系统色调")
- @ApiModelProperty(value = "系统色调")
- private String sysHue;
-
- /** 定制化数据,键值对{key:{type1:"",type2:"",value:""},key2:{type1:"",type2:"",value:""}}具体操作时候,做具体说明 */
-
- @ApiModelProperty(value = "定制化数据,键值对{key:{type1:'',type2:'',value:''},key2:{type1:'',type2:'',value:''}}具体操作时候,做具体说明")
- private String customizationFields;
-
-
-
-}
diff --git a/bs-common/src/main/java/com/bs/common/core/domain/model/LoginUser.java b/bs-common/src/main/java/com/bs/common/core/domain/model/LoginUser.java
index 096e578..daa4af5 100644
--- a/bs-common/src/main/java/com/bs/common/core/domain/model/LoginUser.java
+++ b/bs-common/src/main/java/com/bs/common/core/domain/model/LoginUser.java
@@ -9,7 +9,7 @@ import java.util.Set;
/**
* 登录用户身份权限
- *
+ *
* @author bs
*/
public class LoginUser implements UserDetails
@@ -71,49 +71,6 @@ public class LoginUser implements UserDetails
*/
private SysUser user;
- /**
- * 租户id
- */
- private Long tenantId;
- /**
- * 是否租户
- */
- private String isTenant;
- /** 是否租户管理员 */
- /**
- * 是否租户admin
- * Y 是 N 否
- *
- * @return
- */
- private String isTenantAdmin;
-
- public Long getTenantId()
- {
- return tenantId;
- }
-
- public void setTenantId(Long tenantId)
- {
- this.tenantId = tenantId;
- }
-
- public String getIsTenant() {
- return isTenant;
- }
-
- public void setIsTenant(String isTenant) {
- this.isTenant = isTenant;
- }
-
- public String getIsTenantAdmin() {
- return isTenantAdmin;
- }
-
- public void setIsTenantAdmin(String isTenantAdmin) {
- this.isTenantAdmin = isTenantAdmin;
- }
-
public LoginUser()
{
}
@@ -128,9 +85,6 @@ public class LoginUser implements UserDetails
{
this.userId = userId;
this.deptId = deptId;
- this.tenantId = user.getTenantId();
- this.isTenant = user.getIsTenant();
- this.isTenantAdmin = user.getIsTenantAdmin();
this.user = user;
this.permissions = permissions;
}
@@ -190,7 +144,7 @@ public class LoginUser implements UserDetails
/**
* 指定用户是否解锁,锁定的用户无法进行身份验证
- *
+ *
* @return
*/
@JSONField(serialize = false)
@@ -202,7 +156,7 @@ public class LoginUser implements UserDetails
/**
* 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
- *
+ *
* @return
*/
@JSONField(serialize = false)
@@ -214,7 +168,7 @@ public class LoginUser implements UserDetails
/**
* 是否可用 ,禁用的用户不能身份验证
- *
+ *
* @return
*/
@JSONField(serialize = false)
diff --git a/bs-common/src/main/java/com/bs/common/filter/XssFilter.java b/bs-common/src/main/java/com/bs/common/filter/XssFilter.java
index a4b65d3..1ce2501 100644
--- a/bs-common/src/main/java/com/bs/common/filter/XssFilter.java
+++ b/bs-common/src/main/java/com/bs/common/filter/XssFilter.java
@@ -1,18 +1,22 @@
package com.bs.common.filter;
-import com.bs.common.enums.HttpMethod;
-import com.bs.common.utils.StringUtils;
-
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import com.bs.common.utils.StringUtils;
+import com.bs.common.enums.HttpMethod;
/**
* 防止XSS攻击的过滤器
- *
+ *
* @author bs
*/
public class XssFilter implements Filter
diff --git a/bs-common/src/main/java/com/bs/common/mybatis/handler/DefaultDBFieldHandler.java b/bs-common/src/main/java/com/bs/common/mybatis/handler/DefaultDBFieldHandler.java
index 4c25141..04088a6 100644
--- a/bs-common/src/main/java/com/bs/common/mybatis/handler/DefaultDBFieldHandler.java
+++ b/bs-common/src/main/java/com/bs/common/mybatis/handler/DefaultDBFieldHandler.java
@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bs.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
-import java.time.LocalDateTime;
-import java.util.Objects;
+import java.time.ZonedDateTime;
+import java.util.Date;
/**
* 通用参数填充实现类
@@ -31,7 +31,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
*/
boolean createTime = metaObject.hasSetter("createTime");
if(createTime){
- this.setFieldValByName("createTime", LocalDateTime.now() , metaObject);
+ this.setFieldValByName("createTime", Date.from(ZonedDateTime.now().toInstant()), metaObject);
}
/**
* createDate 创建时间
@@ -58,19 +58,15 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
*/
boolean updateByOf = metaObject.hasSetter("updateBy");
if(updateByOf){
- if (Objects.nonNull(SecurityUtils.getUsername())) {
- this.setFieldValByName("updateBy", SecurityUtils.getUsername(), metaObject);
- }
+ this.setFieldValByName("updateBy",SecurityUtils.getUsername(), metaObject);
}
-
-
/**
* updateDate 更新时间
*/
boolean updateTimeOf = metaObject.hasSetter("updateTime");
if(updateTimeOf){
- this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
+ this.setFieldValByName("updateTime", Date.from(ZonedDateTime.now().toInstant()), metaObject);
}
}
}
diff --git a/bs-common/src/main/java/com/bs/common/utils/DictUtils.java b/bs-common/src/main/java/com/bs/common/utils/DictUtils.java
index 9157b6a..84fed6a 100644
--- a/bs-common/src/main/java/com/bs/common/utils/DictUtils.java
+++ b/bs-common/src/main/java/com/bs/common/utils/DictUtils.java
@@ -1,17 +1,16 @@
package com.bs.common.utils;
+import java.util.Collection;
+import java.util.List;
import com.alibaba.fastjson2.JSONArray;
import com.bs.common.constant.CacheConstants;
import com.bs.common.core.domain.entity.SysDictData;
import com.bs.common.core.redis.RedisCache;
import com.bs.common.utils.spring.SpringUtils;
-import java.util.Collection;
-import java.util.List;
-
/**
* 字典工具类
- *
+ *
* @author bs
*/
public class DictUtils
@@ -23,7 +22,7 @@ public class DictUtils
/**
* 设置字典缓存
- *
+ *
* @param key 参数键
* @param dictDatas 字典数据列表
*/
@@ -34,7 +33,7 @@ public class DictUtils
/**
* 获取字典缓存
- *
+ *
* @param key 参数键
* @return dictDatas 字典数据列表
*/
@@ -50,7 +49,7 @@ public class DictUtils
/**
* 根据字典类型和字典值获取字典标签
- *
+ *
* @param dictType 字典类型
* @param dictValue 字典值
* @return 字典标签
@@ -62,7 +61,7 @@ public class DictUtils
/**
* 根据字典类型和字典标签获取字典值
- *
+ *
* @param dictType 字典类型
* @param dictLabel 字典标签
* @return 字典值
@@ -74,7 +73,7 @@ public class DictUtils
/**
* 根据字典类型和字典值获取字典标签
- *
+ *
* @param dictType 字典类型
* @param dictValue 字典值
* @param separator 分隔符
@@ -117,7 +116,7 @@ public class DictUtils
/**
* 根据字典类型和字典标签获取字典值
- *
+ *
* @param dictType 字典类型
* @param dictLabel 字典标签
* @param separator 分隔符
@@ -157,7 +156,7 @@ public class DictUtils
/**
* 删除指定字典缓存
- *
+ *
* @param key 字典键
*/
public static void removeDictCache(String key)
@@ -176,7 +175,7 @@ public class DictUtils
/**
* 设置cache key
- *
+ *
* @param configKey 参数键
* @return 缓存键key
*/
diff --git a/bs-common/src/main/java/com/bs/common/utils/FileUtil.java b/bs-common/src/main/java/com/bs/common/utils/FileUtil.java
deleted file mode 100644
index 4faf5f6..0000000
--- a/bs-common/src/main/java/com/bs/common/utils/FileUtil.java
+++ /dev/null
@@ -1,939 +0,0 @@
-package com.bs.common.utils;
-
-import cn.hutool.core.codec.Base64;
-import cn.hutool.core.io.IoUtil;
-import cn.hutool.core.util.IdUtil;
-import cn.hutool.poi.excel.BigExcelWriter;
-import cn.hutool.poi.excel.ExcelUtil;
-import com.bs.common.constant.Constants;
-import com.bs.common.core.domain.AjaxResult;
-import com.bs.common.exception.ServiceException;
-import com.bs.common.utils.uuid.IdUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.util.IOUtils;
-import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.apache.tools.zip.ZipEntry;
-import org.apache.tools.zip.ZipOutputStream;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
-import java.io.*;
-import java.net.URLEncoder;
-import java.security.MessageDigest;
-import java.security.SecureRandom;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/**
- * File工具类,扩展 hutool 工具包
- */
-@Slf4j
-public class FileUtil extends cn.hutool.core.io.FileUtil {
-
- /**
- * 定义GB的计算常量
- */
- private static final int GB = 1024 * 1024 * 1024;
- /**
- * 定义MB的计算常量
- */
- private static final int MB = 1024 * 1024;
- /**
- * 定义KB的计算常量
- */
- private static final int KB = 1024;
-
- /**
- * 格式化小数
- */
- private static final DecimalFormat DF = new DecimalFormat("0.00");
- /**
- * 系统临时目录
- *
- * windows 包含路径分割符,但Linux 不包含,
- * 在windows \\==\ 前提下,
- * 为安全起见 同意拼装 路径分割符,
- *
- * java.io.tmpdir
- * windows : C:\Users/xxx\AppData\Local\Temp\
- * linux: /temp
- *
- */
- public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
-
- private static final int FILE_READ_BTYE = 1024;
-
- /**
- * MultipartFile转File
- */
- public static File toFile(MultipartFile multipartFile) {
- // 获取文件名
- String fileName = multipartFile.getOriginalFilename();
- // 获取文件后缀
- String prefix = "." + getExtensionName(fileName);
- File file = null;
- try {
- // 用uuid作为文件名,防止生成的临时文件重复
- file = File.createTempFile(IdUtil.simpleUUID(), prefix);
- // MultipartFile to File
- multipartFile.transferTo(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return file;
- }
-
- /**
- * 获取文件扩展名,不带 .
- */
- public static String getExtensionName(String filename) {
- if ((filename != null) && (filename.length() > 0)) {
- int dot = filename.lastIndexOf('.');
- if ((dot > -1) && (dot < (filename.length() - 1))) {
- return filename.substring(dot + 1);
- }
- }
- return filename;
- }
-
- public static String getExtensionNameBase64(String filename) {
- if (filename.contains("data:image/png;base64")) {
- return "png";
- }else if(filename.contains("data:image/jpg;base64")){
- return "jpg";
- }else if(filename.contains("data:image/jpeg;base64")){
- return "jpeg";
- }
- return "bmp";
- }
- /**
- * Java文件操作 获取不带扩展名的文件名
- */
- public static String getFileNameNoEx(String filename) {
- if ((filename != null) && (filename.length() > 0)) {
- int dot = filename.lastIndexOf('.');
- if ((dot > -1) && (dot < (filename.length()))) {
- return filename.substring(0, dot);
- }
- }
- return filename;
- }
-
- /**
- * 文件大小转换
- */
- public static String getSize(long size) {
- String resultSize;
- if (size / GB >= 1) {
- //如果当前Byte的值大于等于1GB
- resultSize = DF.format(size / (float) GB) + "GB ";
- } else if (size / MB >= 1) {
- //如果当前Byte的值大于等于1MB
- resultSize = DF.format(size / (float) MB) + "MB ";
- } else if (size / KB >= 1) {
- //如果当前Byte的值大于等于1KB
- resultSize = DF.format(size / (float) KB) + "KB ";
- } else {
- resultSize = size + "B ";
- }
- return resultSize;
- }
-
-
- /**
- * 将文件名解析成文件的上传路径
- */
- public static File upload(MultipartFile file, String filePath) {
- //String name = getFileNameNoEx(file.getOriginalFilename());
- String suffix = getExtensionName(file.getOriginalFilename());
- StringBuffer nowStr = fileRename();
- try {
- String fileName = nowStr + "." + suffix;
- String path = filePath + fileName;
- // getCanonicalFile 可解析正确各种路径
- File dest = new File(path).getCanonicalFile();
- // 检测是否存在目录
- if (!dest.getParentFile().exists()) {
- dest.getParentFile().mkdirs();
- }
- // 文件写入
- file.transferTo(dest);
- return dest;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static String fileToBase64(File file) throws Exception {
- FileInputStream inputFile = new FileInputStream(file);
- String base64;
- byte[] buffer = new byte[(int) file.length()];
- inputFile.read(buffer);
- inputFile.close();
- base64 = Base64.encode(buffer);
- return base64.replaceAll("[\\s*\t\n\r]", "");
- }
-
-
- public static String getFileType(String type) {
- String documents = "txt doc pdf ppt pps xlsx xls docx";
- String music = "mp3 wav wma mpa ram ra aac aif m4a";
- String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
- String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
- if (image.contains(type)) {
- return "pic";
- } else if (documents.contains(type)) {
- return "txt";
- } else if (music.contains(type)) {
- return "music";
- } else if (video.contains(type)) {
- return "vedio";
- } else {
- return "other";
- }
- }
-
-
- public static void checkSize(long maxSize, long size) {
- // 1M
- int len = 1024 * 1024;
- if (size > (maxSize * len)) {
- throw new ServiceException("文件超出规定大小");
-
- }
- }
-
- /**
- * 判断两个文件是否相同
- */
- public static boolean check(File file1, File file2) {
- String img1Md5 = getMd5(file1);
- String img2Md5 = getMd5(file2);
- return img1Md5.equals(img2Md5);
- }
-
- /**
- * 判断两个文件是否相同
- */
- public static boolean check(String file1Md5, String file2Md5) {
- return file1Md5.equals(file2Md5);
- }
-
- private static byte[] getByte(File file) {
- // 得到文件长度
- byte[] b = new byte[(int) file.length()];
- try {
- InputStream in = new FileInputStream(file);
- try {
- in.read(b);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- return b;
- }
-
- private static String getMd5(byte[] bytes) {
- // 16进制字符
- char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
- try {
- MessageDigest mdTemp = MessageDigest.getInstance("MD5");
- mdTemp.update(bytes);
- byte[] md = mdTemp.digest();
- int j = md.length;
- char[] str = new char[j * 2];
- int k = 0;
- // 移位 输出字符串
- for (byte byte0 : md) {
- str[k++] = hexDigits[byte0 >>> 4 & 0xf];
- str[k++] = hexDigits[byte0 & 0xf];
- }
- return new String(str);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 下载文件
- *
- * @param request /
- * @param response /
- * @param file /
- */
- public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) {
- response.setCharacterEncoding(request.getCharacterEncoding());
- response.setContentType("application/octet-stream");
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(file);
- response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
- IOUtils.copy(fis, response.getOutputStream());
- response.flushBuffer();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (fis != null) {
- try {
- fis.close();
- if (deleteOnExit) {
- file.deleteOnExit();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- public static String getMd5(File file) {
- return getMd5(getByte(file));
- }
-
- /**
- * 读取json文件,返回json串
- *
- * @param fileName
- * @return
- */
- public static String readJsonFile(String fileName) {
- String jsonStr = "";
- try {
- File jsonFile = new File(fileName);
- FileReader fileReader = new FileReader(jsonFile);
-
- Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
- int ch = 0;
- StringBuffer sb = new StringBuffer();
- while ((ch = reader.read()) != -1) {
- sb.append((char) ch);
- }
- fileReader.close();
- reader.close();
- jsonStr = sb.toString();
- return jsonStr;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static BufferedImage inputImage(MultipartFile file) {
- BufferedImage srcImage = null;
- try {
- FileInputStream in = (FileInputStream) file.getInputStream();
- srcImage = javax.imageio.ImageIO.read(in);
- } catch (IOException e) {
- System.out.println("读取图片文件出错!" + e.getMessage());
- }
- return srcImage;
- }
-
- /**
- * 自动调节精度(经验数值)
- *
- * @param size 源图片大小
- * @return 图片压缩质量比
- */
- public static float getAccuracy(long size) {
- float accuracy;
- if (size < 400) {
- accuracy = 0.85f;
- } else if (size < 900) {
- accuracy = 0.75f;
- } else if (size < 2047) {
- accuracy = 0.6f;
- } else if (size < 3275) {
- accuracy = 0.44f;
- } else {
- accuracy = 0.4f;
- }
- return accuracy;
- }
-
- /**
- * 上传文件重命名
- *
- * @return 新的文件名
- */
- public static StringBuffer fileRename() {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
- String time = sdf.format(new Date());
- StringBuffer buf = new StringBuffer(time);
- SecureRandom r = new SecureRandom();
- //循环取得三个不大于10的随机整数
- for (int x = 0; x < 3; x++) {
- buf.append(r.nextInt(10));
- }
- return buf;
- }
-
- /**
- * 对中文字符进行UTF-8编码
- *
- * @param source 要转义的字符串
- * @return
- * @throws UnsupportedEncodingException
- */
- public static String transformStyle(String source) throws UnsupportedEncodingException {
- char[] arr = source.toCharArray();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < arr.length; i++) {
- char temp = arr[i];
- if (isChinese(temp)) {
- sb.append(URLEncoder.encode("" + temp, Constants.UTF8));
- continue;
- }
- sb.append(arr[i]);
- }
- return sb.toString();
- }
-
- /**
- * 判断是不是中文字符
- *
- * @param c
- * @return
- */
- public static boolean isChinese(char c) {
-
- Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
-
- if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
-
- || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
-
- || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
-
- || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
-
- || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
-
- || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
-
- return true;
-
- }
-
- return false;
-
- }
-
-
- /**
- * 上传文件重命名Mos系统
- *
- * @return 新的文件名
- */
- public static String fileRenameMos(String prefix, String suffix) {
- // 生成唯一的文件名[带前缀以及后缀]
- String fileName = (prefix == null ? ""
- : prefix.trim()) + IdUtils.simpleUUID() + (suffix == null ? ""
- : suffix.trim());
- return fileName;
- }
-
- /**
- * 上传文件Mos系统
- */
- public static File uploadMos(MultipartFile file, String path) {
- try {
- // getCanonicalFile 可解析正确各种路径
- File dest = new File(path).getCanonicalFile();
- // 检测是否存在目录
- if (!dest.getParentFile().exists()) {
- dest.getParentFile().mkdirs();
- }
- // 文件写入
- file.transferTo(dest);
- return dest;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static File uploadMosBase64(String imageStr, String path) {
- try {
- // getCanonicalFile 可解析正确各种路径
- File dest = new File(path).getCanonicalFile();
- // 检测是否存在目录
- if (!dest.getParentFile().exists()) {
- dest.getParentFile().mkdirs();
- }
- byte[] bytes=Base64.decode(imageStr); //imageStr.getBytes();
- FileOutputStream fos = new FileOutputStream(dest);
- try{
- // 文件写入
- fos.write(bytes,0,bytes.length);
- fos.flush();
- }catch (IOException e){
- e.printStackTrace();
- }finally {
- fos.close();
- }
- return dest;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 读取文件,返回文件字符串.
- *
- * @param in 文件输入流
- * @param encoding 文件编码
- * @return String
- */
- public static String readFile(InputStream in, String encoding) {
- if (in == null) {
- return null;
- }
-
- StringBuffer sb = new StringBuffer();
- InputStreamReader reader = null;
- try {
- reader = new InputStreamReader(in, encoding);
- int tmp = -1;
- char temp;
- while ((tmp = reader.read()) != -1) {
- temp = (char) tmp;
- sb.append(temp);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- return sb.toString();
- }
-
- /**
- * 将inputStream写入文件并关闭inputStream.
- *
- * @param is 文件输入流
- * @param filePath 文件路径
- * @param append true为追加,false为覆盖
- * @return 是否成功
- */
- public static boolean writeFile(InputStream is, String filePath,
- boolean append) {
- FileOutputStream fos = null;
- try {
- if (makeDir(filePath) && is != null) {
- fos = new FileOutputStream(filePath, append);
- byte[] buffer = new byte[FILE_READ_BTYE * FILE_READ_BTYE];
- // int bytesum = 0;
- int byteread = 0;
- while ((byteread = is.read(buffer)) != -1) {
- // bytesum+=byteread;
- fos.write(buffer, 0, byteread);
- fos.flush();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return true;
- }
-
- /**
- * 将字符串写入到文件.
- *
- * @param str 字符串
- * @param filePath 文件路径
- * @param encoding 编码
- * @param append 是否累加
- * @return 是否成功
- */
- public static boolean writeFile(String str, String filePath,
- String encoding, boolean append) {
- FileOutputStream fos = null;
- Writer out = null;
- boolean isSucc = false;
- try {
- if (makeDir(filePath)) {
- fos = new FileOutputStream(new File(filePath), append);
- out = new OutputStreamWriter(fos, encoding);
- out.write(str);
-
- out.flush();
- out.close();
-
- fos.flush();
- fos.close();
- } else {
- isSucc = false;
- }
- isSucc = true;
- } catch (IOException e) {
- e.printStackTrace();
- isSucc = false;
- } finally {
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return isSucc;
- }
-
- /**
- * 创建文件夹。
- *
- * @param destDirName 目标文件夹
- * @return 是否创建成功
- */
- public static boolean createDir(String destDirName) {
- if (validateEmail(destDirName)) {
- return false;
- }
- File dir = new File(destDirName);
- if (dir.exists()) { // 目录已经存在,不用创建
- return true;
- }
- // 创建单个目录
- if (dir.mkdirs()) { // 创建目录成功
- return true;
- }
- return true;
- }
-
- public static boolean validateEmail(String s) {
- return StringUtils.isEmpty(s)
- || s.matches("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a"
- + "-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
- }
-
-
- /**
- * 根据文件创建目录.
- *
- * @param file 文件
- * @return 是否成功
- */
- public static boolean makeDir(File file) {
- if (!file.exists()) {
- makeDir(file.getAbsolutePath());
- }
- return true;
- }
-
- /**
- * 根据文件名创建目录
- *
- * @param fileName
- * @return
- */
- public static boolean makeDir(String fileName) {
- int index = 0;
- int index1 = fileName.lastIndexOf("/");
- int index2 = fileName.lastIndexOf("\\");
- if (index1 > index2) {
- index = index1;
- } else {
- index = index2;
- }
- fileName = fileName.substring(0, index);
- File file = new File(fileName);
- file.setWritable(true, false);
- if (!file.exists()) {
- if (!file.mkdirs()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * 删除单个文件 。
- *
- * @param sPath 被删除文件的文件名
- * @return 单个文件删除成功返回true,否则返回false
- */
- public static boolean deleteFile(String sPath) {
- Boolean flag = false;
- File file = new File(sPath);
- // 路径为文件且不为空则进行删除
- if (file.isFile() && file.exists()) {
- file.delete();
- flag = true;
- }
- return flag;
- }
-
- /**
- * 删除单个文件 。
- *
- * @param file 被删除文件
- * @return 单个文件删除成功返回true,否则返回false
- */
- public static boolean deleteFile(File file) {
- Boolean flag = false;
- // 路径为文件且不为空则进行删除
- if (file.isFile() && file.exists()) {
- file.delete();
- flag = true;
- }
- return flag;
- }
-
- /**
- * 删除文件夹。
- *
- * @param sPath 文件夹路径
- * @param flags true删除文件夹,false只删除文件夹下的文件
- * @return 是否删除成功
- */
- public static boolean deleteDirectory(String sPath, Boolean flags) {
- // 如果sPath不以文件分隔符结尾,自动添加文件分隔符
- if (!sPath.endsWith(File.separator)) {
- sPath = sPath + File.separator;
- }
- File dirFile = new File(sPath);
- // 如果dir对应的文件不存在,或者不是一个目录,则退出
- if (!dirFile.exists() || !dirFile.isDirectory()) {
- return false;
- }
- Boolean flag = true;
- // 删除文件夹下的所有文件(包括子目录)
- File[] files = dirFile.listFiles();
- for (int i = 0; i < files.length; i++) {
- // 删除子文件
- if (files[i].isFile()) {
- flag = deleteFile(files[i].getAbsolutePath());
- if (!flag) {
- break;
- }
- } else {
- // 删除子目录
- flag = deleteDirectory(files[i].getAbsolutePath(), true);
- if (!flag) {
- break;
- }
- }
- }
- if (!flag) {
- return false;
- }
- if (flags) {
- // 删除当前目录
- return dirFile.delete();
- }
- return true;
- }
-
- /**
- * 文件打包(指定文件).
- *
- * @param zipFilePath 打包后压缩包的路径
- * @param files 需要打包的文件
- * @param targetFileNames 打包后文件的名称
- * @param encoding 文件名编码
- * @return flag 是否打包成功
- */
- public static Boolean zipFile(String zipFilePath, File[] files,
- String[] targetFileNames, String encoding) {
- Boolean flag = false;
- if (StringUtils.isEmpty(zipFilePath) || files == null
- || files.length == 0) {
- return flag;
- }
- if (targetFileNames != null && targetFileNames.length != files.length) {
- return flag;
- }
- byte[] buffer = new byte[FILE_READ_BTYE];
- try {
- ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
- zipFilePath));
- for (int i = 0; i < files.length; i++) {
- FileInputStream fis = new FileInputStream(files[i]);
- if (targetFileNames != null) {
- if (String.valueOf(targetFileNames[i].toCharArray()[0])
- .equals("/")) {
- out.putNextEntry(new ZipEntry(targetFileNames[i]
- .substring(1, targetFileNames[i].length())));
- } else {
- out.putNextEntry(new ZipEntry(targetFileNames[i]));
- }
- } else {
- out.putNextEntry(new ZipEntry(files[i].getName()));
- }
- if (StringUtils.isNotEmpty(encoding)) {
- out.setEncoding(encoding);
- }
- int len;
- while ((len = fis.read(buffer)) > 0) {
- out.write(buffer, 0, len);
- }
- out.closeEntry();
- fis.close();
- }
- out.close();
- flag = true;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return flag;
- }
-
- /**
- * inputStream 转 File
- */
- static File inputStreamToFile(InputStream ins, String name) throws Exception {
- File file = new File(SYS_TEM_DIR + name);
- if (file.exists()) {
- return file;
- }
- OutputStream os = new FileOutputStream(file);
- int bytesRead;
- int len = 8192;
- byte[] buffer = new byte[len];
- while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- os.close();
- ins.close();
- return file;
- }
-
- /**
- * 导出excel
- */
- public static void downloadExcel(List