map = new HashMap<>();
+ Class> clazz = obj.getClass();
+ for (Field field : clazz.getDeclaredFields()) {
+ field.setAccessible(true);
+ String fieldName = field.getName();
+ Object value = field.get(obj);
+ map.put(fieldName, value);
+ }
+ return map;
+ }
+
+ /**
+ * 判断是否是JSON格式
+ *
+ * @param str JSON字符串
+ * @return
+ */
+ private boolean isJson(String str) {
+ try {
+ JSONObject jsonStr = JSONObject.parseObject(str);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * MD5方法
+ *
+ * @param source
+ * @return
+ */
+ public static String md5(byte[] source) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(source);
+ StringBuffer buf = new StringBuffer();
+ for (byte b : md.digest()) {
+ buf.append(String.format("%02x", b & 0xff));
+ }
+ return buf.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * 密码加密
+ *
+ * @param password 密码
+ * @return
+ */
+ public static String password(String password) {
+ String md51 = md5(password.getBytes());
+ String pwd = md5((md51 + "IgtUdEQJyVevaCxQnY").getBytes());
+ return pwd;
+ }
+}
diff --git a/common/src/main/java/com/canvas/web/utils/ElAdminConstant.java b/common/src/main/java/com/canvas/web/utils/ElAdminConstant.java
new file mode 100644
index 0000000..e5a6a49
--- /dev/null
+++ b/common/src/main/java/com/canvas/web/utils/ElAdminConstant.java
@@ -0,0 +1,26 @@
+package com.canvas.web.utils;
+
+public class ElAdminConstant {
+
+ /**
+ * 用于IP定位转换
+ */
+ public static final String REGION = "内网IP|内网IP";
+ /**
+ * win 系统
+ */
+ public static final String WIN = "win";
+
+ /**
+ * mac 系统
+ */
+ public static final String MAC = "mac";
+
+ /**
+ * 常用接口
+ */
+ public static class Url {
+ // IP归属地查询
+ public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
+ }
+}
diff --git a/common/src/main/java/com/canvas/web/utils/ErrorCode.java b/common/src/main/java/com/canvas/web/utils/ErrorCode.java
new file mode 100644
index 0000000..0ec7d36
--- /dev/null
+++ b/common/src/main/java/com/canvas/web/utils/ErrorCode.java
@@ -0,0 +1,42 @@
+package com.canvas.web.utils;
+
+public enum ErrorCode {
+
+ FAILED(1, "操作失败"),
+ TOKEN_MISSING(300, "token丢失"),
+ TOKEN_ERROR(301, "token认证失败"),
+ PARAM_MISSING(400, "参数丢失"),
+ PARAM_ERROR(401, "参数错误"),
+ SYSTEM_ERROR(500, "系统错误"),
+ UNKNOWN_ERROR(501, "未知错误");
+
+ public static final Integer MESSAGE_PARAM_MISSING = 400;
+
+ /**
+ * 错误码
+ */
+ private Integer code;
+ /**
+ * 错误描述
+ */
+ private String msg;
+
+ public Integer getCode() {
+ return this.code;
+ }
+
+ public String getMsg() {
+ return this.msg;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param code
+ * @param msg
+ */
+ private ErrorCode(Integer code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+}
diff --git a/common/src/main/java/com/canvas/web/utils/FileUtil.java b/common/src/main/java/com/canvas/web/utils/FileUtil.java
new file mode 100644
index 0000000..5732b5f
--- /dev/null
+++ b/common/src/main/java/com/canvas/web/utils/FileUtil.java
@@ -0,0 +1,356 @@
+package com.canvas.web.utils;
+
+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.canvas.web.exception.BaseException;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.security.MessageDigest;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+public class FileUtil extends cn.hutool.core.io.FileUtil{
+
+ private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
+
+ /**
+ * 系统临时目录
+ *
+ * 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;
+ /**
+ * 定义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");
+
+ public static final String IMAGE = "图片";
+ public static final String TXT = "文档";
+ public static final String MUSIC = "音乐";
+ public static final String VIDEO = "视频";
+ public static final String OTHER = "其他";
+
+
+ /**
+ * 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) {
+ log.error(e.getMessage(), e);
+ }
+ 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 将文件名解析成文件的上传路径
+ */
+ public static File upload(MultipartFile file, String filePath) {
+ Date date = new Date();
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
+ String name = getFileNameNoEx(file.getOriginalFilename());
+ String suffix = getExtensionName(file.getOriginalFilename());
+ String nowStr = "-" + format.format(date);
+ try {
+ String fileName = name + nowStr + "." + suffix;
+ String path = filePath + fileName;
+ // getCanonicalFile 可解析正确各种路径
+ File dest = new File(path).getCanonicalFile();
+ // 检测是否存在目录
+ if (!dest.getParentFile().exists()) {
+ if (!dest.getParentFile().mkdirs()) {
+ System.out.println("was not successful.");
+ }
+ }
+ // 文件写入
+ file.transferTo(dest);
+ return dest;
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ * 导出excel
+ */
+ public static void downloadExcel(List