Commit 5b76913c by liuhui

Initial commit

parents
Showing with 5007 additions and 0 deletions
.DS_Store
######################################################################
# Build Tools
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
target/
!.mvn/wrapper/maven-wrapper.jar
######################################################################
# IDE
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
*/.externalToolBuilders/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/*
nbbuild/
dist/
nbdist/
.nb-gradle/
######################################################################
# Others
*.log
*.xml.versionsBackup
!*/build/*.java
!*/build/*.html
!*/build/*.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sinobase</groupId>
<artifactId>sinobase</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>com.sinobase</groupId>
<artifactId>sinobase-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sinobase-common</name>
<description>remote call interface</description>
<dependencies>
<!-- SpringBoot 核心包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- SpringBoot WEB依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- sinobase-datasource -->
<dependency>
<groupId>com.sinobase</groupId>
<artifactId>sinobase-datasource</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- http-client -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!-- SpringBoot集成mybatis Plus框架 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
<!-- json处理工具 -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<classifier>jdk15</classifier>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- shiro-spring -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<srource>1.8</srource>
<target>1.8</target>
<encoding>UTF-8</encoding>
<showWarning>true</showWarning>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.sinobase.common.constant;
import java.util.HashMap;
import java.util.Map;
/**
* 通用数据库映射Map数据
*
* @author sinobase
*/
public class CommonMap
{
/** 状态编码转换 */
public static Map<String, String> javaTypeMap = new HashMap<String, String>();
static
{
initJavaTypeMap();
}
/**
* 返回状态映射
*/
public static void initJavaTypeMap()
{
javaTypeMap.put("tinyint", "Integer");
javaTypeMap.put("smallint", "Integer");
javaTypeMap.put("mediumint", "Integer");
javaTypeMap.put("int", "Integer");
javaTypeMap.put("integer", "integer");
javaTypeMap.put("bigint", "Long");
javaTypeMap.put("float", "Float");
javaTypeMap.put("double", "Double");
javaTypeMap.put("decimal", "BigDecimal");
javaTypeMap.put("bit", "Boolean");
javaTypeMap.put("char", "String");
javaTypeMap.put("varchar", "String");
javaTypeMap.put("tinytext", "String");
javaTypeMap.put("text", "String");
javaTypeMap.put("mediumtext", "String");
javaTypeMap.put("longtext", "String");
javaTypeMap.put("time", "Date");
javaTypeMap.put("date", "Date");
javaTypeMap.put("datetime", "Date");
javaTypeMap.put("timestamp", "Date");
}
}
package com.sinobase.common.constant;
/**
* 通用常量信息
*
* @author sinobase
*/
public class Constants
{
/**
* UTF-8 字符集
*/
public static final String UTF8 = "UTF-8";
/**
* 通用成功标识
*/
public static final String SUCCESS = "0";
/**
* 通用失败标识
*/
public static final String FAIL = "1";
/**
* 登录成功
*/
public static final String LOGIN_SUCCESS = "Success";
/**
* 注销
*/
public static final String LOGOUT = "Logout";
/**
* 登录失败
*/
public static final String LOGIN_FAIL = "Error";
/**
* 自动去除表前缀
*/
public static String AUTO_REOMVE_PRE = "true";
/**
* 当前记录起始索引
*/
public static String PAGE_NUM = "pageNum";
/**
* 每页显示记录数
*/
public static String PAGE_SIZE = "pageSize";
/**
* 排序列
*/
public static String ORDER_BY_COLUMN = "orderByColumn";
/**
* 排序的方向 "desc" 或者 "asc".
*/
public static String IS_ASC = "isAsc";
/**
* 请假单状态标识 草稿
*/
public static String START_FLAG = "5";
/**
* 请假单状态标识 审核中
*/
public static String SUB_FLAG = "1";
/**
* 请假单状态标识 办结
*/
public static String END_FLAG = "4";
/**
*请假单状态标识 归档
*/
public static String DOSSIER_FLAG = "3";
/**
*请假单状态标识 撤办
*/
public static String REMOVE_FLAG = "0";
/**
*请假单状态标识 审批通过
*/
public static String APPROVAL_FLAG = "6";
/**
*请假单状态标识 审批不通过
*/
public static String NOAPPROVAL_FLAG = "7";
/**
* 国投智能外部单位
*
*/
public static String COMPANY_EXTEND = "231560";
}
package com.sinobase.common.constant;
/**
* 权限通用常量
*
* @author sinobase
*/
public class PermissionConstants
{
/** 新增权限 */
public static final String ADD_PERMISSION = "add";
/** 修改权限 */
public static final String EDIT_PERMISSION = "edit";
/** 删除权限 */
public static final String REMOVE_PERMISSION = "remove";
/** 导出权限 */
public static final String EXPORT_PERMISSION = "export";
/** 显示权限 */
public static final String VIEW_PERMISSION = "view";
/** 查询权限 */
public static final String LIST_PERMISSION = "list";
}
package com.sinobase.common.constant;
/**
* 任务调度通用常量
*
* @author sinobase
*/
public interface ScheduleConstants
{
public static final String TASK_CLASS_NAME = "__TASK_CLASS_NAME__";
public static final String TASK_PROPERTIES = "__TASK_PROPERTIES__";
/** 默认 */
public static final String MISFIRE_DEFAULT = "0";
/** 立即触发执行 */
public static final String MISFIRE_IGNORE_MISFIRES = "1";
/** 触发一次执行 */
public static final String MISFIRE_FIRE_AND_PROCEED = "2";
/** 不触发立即执行 */
public static final String MISFIRE_DO_NOTHING = "3";
public enum Status
{
/**
* 正常
*/
NORMAL("0"),
/**
* 暂停
*/
PAUSE("1");
private String value;
private Status(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}
}
package com.sinobase.common.constant;
/**
* Shiro通用常量
*
* @author sinobase
*/
public interface ShiroConstants
{
/**
* 当前登录的用户
*/
public static final String CURRENT_USER = "currentUser";
/**
* 用户名
*/
public static final String CURRENT_USERNAME = "username";
/**
* 消息key
*/
public static String MESSAGE = "message";
/**
* 错误key
*/
public static String ERROR = "errorMsg";
/**
* 编码格式
*/
public static String ENCODING = "UTF-8";
/**
* 当前在线会话
*/
public String ONLINE_SESSION = "online_session";
/**
* 验证码key
*/
public static final String CURRENT_CAPTCHA = "captcha";
/**
* 验证码开关
*/
public static final String CURRENT_ENABLED = "captchaEnabled";
/**
* 验证码开关
*/
public static final String CURRENT_TYPE = "captchaType";
/**
* 验证码
*/
public static final String CURRENT_VALIDATECODE = "validateCode";
/**
* 验证码错误
*/
public static final String CAPTCHA_ERROR = "captchaError";
}
package com.sinobase.common.constant;
public class SinoDept {
/**
* 办公厅 四位id
*/
public static final String BAN_GONG_TING = "00020034";
/** 保障中心 */
public static final String DEPT_SDIC_BZZX = "00020060";
}
package com.sinobase.common.constant;
/**
* 用户常量信息
*
* @author sinobase
*/
public class UserConstants
{
/** 正常状态 */
public static final String NORMAL = "0";
/** 异常状态 */
public static final String EXCEPTION = "1";
/** 用户封禁状态 */
public static final String USER_BLOCKED = "1";
/** 角色封禁状态 */
public static final String ROLE_BLOCKED = "0";
/** 部门正常状态 */
public static final String DEPT_NORMAL = "1";
/**
* 用户名长度限制
*/
public static final int USERNAME_MIN_LENGTH = 2;
public static final int USERNAME_MAX_LENGTH = 20;
/** 登录名称是否唯一的返回结果码 */
public final static String USER_NAME_UNIQUE = "0";
public final static String USER_NAME_NOT_UNIQUE = "1";
/** 手机号码是否唯一的返回结果 */
public final static String USER_PHONE_UNIQUE = "0";
public final static String USER_PHONE_NOT_UNIQUE = "1";
/** e-mail 是否唯一的返回结果 */
public final static String USER_EMAIL_UNIQUE = "0";
public final static String USER_EMAIL_NOT_UNIQUE = "1";
/** 部门名称是否唯一的返回结果码 */
public final static String DEPT_NAME_UNIQUE = "0";
public final static String DEPT_NAME_NOT_UNIQUE = "1";
/** 角色名称是否唯一的返回结果码 */
public final static String ROLE_NAME_UNIQUE = "0";
public final static String ROLE_NAME_NOT_UNIQUE = "1";
/** 岗位名称是否唯一的返回结果码 */
public final static String POST_NAME_UNIQUE = "0";
public final static String POST_NAME_NOT_UNIQUE = "1";
/** 角色权限是否唯一的返回结果码 */
public final static String ROLE_KEY_UNIQUE = "0";
public final static String ROLE_KEY_NOT_UNIQUE = "1";
/** 岗位编码是否唯一的返回结果码 */
public final static String POST_CODE_UNIQUE = "0";
public final static String POST_CODE_NOT_UNIQUE = "1";
/** 菜单名称是否唯一的返回结果码 */
public final static String MENU_NAME_UNIQUE = "0";
public final static String MENU_NAME_NOT_UNIQUE = "1";
/** 字典类型是否唯一的返回结果码 */
public final static String DICT_TYPE_UNIQUE = "0";
public final static String DICT_TYPE_NOT_UNIQUE = "1";
/** 参数键名是否唯一的返回结果码 */
public final static String CONFIG_KEY_UNIQUE = "0";
public final static String CONFIG_KEY_NOT_UNIQUE = "1";
/**
* 密码长度限制
*/
public static final int PASSWORD_MIN_LENGTH = 5;
public static final int PASSWORD_MAX_LENGTH = 20;
/**
* 手机号码格式限制
*/
public static final String MOBILE_PHONE_NUMBER_PATTERN = "^0{0,1}(13[0-9]|15[0-9]|14[0-9]|18[0-9])[0-9]{8}$";
/**
* 邮箱格式限制
*/
public static final String EMAIL_PATTERN = "^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?";
}
package com.sinobase.common.exception;
/**
* 业务异常
*
* @author sinobase
*/
public class BusinessException extends RuntimeException
{
private static final long serialVersionUID = 1L;
protected final String message;
public BusinessException(String message)
{
this.message = message;
}
@Override
public String getMessage()
{
return message;
}
}
package com.sinobase.common.exception;
/**
* 演示模式异常
*
* @author sinobase
*/
public class DemoModeException extends RuntimeException
{
private static final long serialVersionUID = 1L;
public DemoModeException()
{
}
}
package com.sinobase.common.exception.base;
import org.springframework.util.StringUtils;
import com.sinobase.common.utils.MessageUtils;
/**
* 基础异常
*
* @author sinobase
*/
public class BaseException extends RuntimeException
{
private static final long serialVersionUID = 1L;
/**
* 所属模块
*/
private String module;
/**
* 错误码
*/
private String code;
/**
* 错误码对应的参数
*/
private Object[] args;
/**
* 错误消息
*/
private String defaultMessage;
public BaseException(String module, String code, Object[] args, String defaultMessage)
{
this.module = module;
this.code = code;
this.args = args;
this.defaultMessage = defaultMessage;
}
public BaseException(String module, String code, Object[] args)
{
this(module, code, args, null);
}
public BaseException(String module, String defaultMessage)
{
this(module, null, null, defaultMessage);
}
public BaseException(String code, Object[] args)
{
this(null, code, args, null);
}
public BaseException(String 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()
{
return module;
}
public String getCode()
{
return code;
}
public Object[] getArgs()
{
return args;
}
public String getDefaultMessage()
{
return defaultMessage;
}
@Override
public String toString()
{
return this.getClass() + "{" + "module='" + module + '\'' + ", message='" + getMessage() + '\'' + '}';
}
}
package com.sinobase.common.support;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import com.sinobase.common.utils.StringUtils;
/**
* 字符集工具类
*
* @author sinobase
*
*/
public class CharsetKit
{
/** ISO-8859-1 */
public static final String ISO_8859_1 = "ISO-8859-1";
/** UTF-8 */
public static final String UTF_8 = "UTF-8";
/** GBK */
public static final String GBK = "GBK";
/** ISO-8859-1 */
public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1);
/** UTF-8 */
public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8);
/** GBK */
public static final Charset CHARSET_GBK = Charset.forName(GBK);
/**
* 转换为Charset对象
*
* @param charset 字符集,为空则返回默认字符集
* @return Charset
*/
public static Charset charset(String charset)
{
return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset);
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public static String convert(String source, String srcCharset, String destCharset)
{
return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public static String convert(String source, Charset srcCharset, Charset destCharset)
{
if (null == srcCharset)
{
srcCharset = StandardCharsets.ISO_8859_1;
}
if (null == destCharset)
{
srcCharset = StandardCharsets.UTF_8;
}
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
{
return source;
}
return new String(source.getBytes(srcCharset), destCharset);
}
/**
* @return 系统字符集编码
*/
public static String systemCharset()
{
return Charset.defaultCharset().name();
}
}
package com.sinobase.common.support;
import com.sinobase.common.utils.StringUtils;
public class StrFormatter
{
public static final String EMPTY_JSON = "{}";
public static final char C_BACKSLASH = '\\';
public static final char C_DELIM_START = '{';
public static final char C_DELIM_END = '}';
/**
* 格式化字符串<br>
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
* 例:<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 \a for b<br>
*
* @param strPattern 字符串模板
* @param argArray 参数列表
* @return 结果
*/
public static String format(final String strPattern, final Object... argArray)
{
if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray))
{
return strPattern;
}
final int strPatternLength = strPattern.length();
// 初始化定义好的长度以获得更好的性能
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
int handledPosition = 0;
int delimIndex;// 占位符所在位置
for (int argIndex = 0; argIndex < argArray.length; argIndex++)
{
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
if (delimIndex == -1)
{
if (handledPosition == 0)
{
return strPattern;
}
else
{ // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
sbuf.append(strPattern, handledPosition, strPatternLength);
return sbuf.toString();
}
}
else
{
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH)
{
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH)
{
// 转义符之前还有一个转义符,占位符依旧有效
sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(Convert.utf8Str(argArray[argIndex]));
handledPosition = delimIndex + 2;
}
else
{
// 占位符被转义
argIndex--;
sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(C_DELIM_START);
handledPosition = delimIndex + 1;
}
}
else
{
// 正常占位符
sbuf.append(strPattern, handledPosition, delimIndex);
sbuf.append(Convert.utf8Str(argArray[argIndex]));
handledPosition = delimIndex + 2;
}
}
}
// append the characters following the last {} pair.
// 加入最后一个占位符后所有的字符
sbuf.append(strPattern, handledPosition, strPattern.length());
return sbuf.toString();
}
}
\ No newline at end of file
package com.sinobase.common.util;
/**
* 常量专用类
*
* @author liuhui001
*
*/
public class CommonContent {
/**
* 国投智能外部单位
*
*/
public static String COMPANY_EXTEND = "231560";
}
package com.sinobase.common.util;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.util.UUID;
/**
* 用于生产各种各样的ID
* @author LouBin
*/
public class IdUtils {
private static String middle = "";
static {
middle = MathUtils.makeUpNewData(Math.abs(NetworkUtils.getHostIP().hashCode()) + "", 4) + // 4位IP地址hash
MathUtils.makeUpNewData(NetworkUtils.getPid(), 4); // 4位PID进程hash
}
/**
* 以毫微秒做基础计数, 返回唯一有序增长ID
* <pre> System.nanoTime() </pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 222 ms
* 数组长度: 100000
* Map Size: 100000
* @return ID长度32位
*/
public static String getIncreaseIdByNanoTime() {
return System.nanoTime() + // 时间戳-14位
middle + // 标志-8位
MathUtils.makeUpNewData(Thread.currentThread().hashCode() + "", 3) + // 3位线程标志
MathUtils.randomDigitNumber(7); // 随机7位数
}
/**
* 毫秒做基础计数, 返回ID, 有几率出现线程并发
* @return ID长度 15 位
*/
public static String getIdByTime() {
long r = 0;
synchronized (new byte[0]) {
r = (long) ((Math.random() + 1) * 100);
}
return System.currentTimeMillis() + String.valueOf(r).substring(1);
}
/**
* 以毫秒做基础计数, 返回唯一有序增长ID, 有几率出现线程并发
* <pre>
* System.currentTimeMillis()
* </pre>
* <pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 206 ms
* 数组长度: 100000
* Map Size: 99992
* </pre>
*
* @return ID长度32位
*/
public static String getIncreaseIdByCurrentTimeMillis() {
return System.currentTimeMillis() + // 时间戳-14位
middle + // 标志-8位
MathUtils.makeUpNewData(Thread.currentThread().hashCode() + "", 3) + // 3位线程标志
MathUtils.randomDigitNumber(8); // 随机8位数
}
/**
* 基于UUID+MD5产生唯一无序ID
*
* <pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 591 ms
* 数组长度: 100000
* Map Size: 100000
* </pre>
*
* @return ID长度32位
*/
public static String getRandomIdByUUID() {
return DigestUtils.md5Hex(UUID.randomUUID().toString());
}
/* ---------------------------------------------分割线------------------------- ----------------------- */
/** 字符串MD5处理类 */
private static class DigestUtils {
private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private static char[] encodeHex(final byte[] data, final char[] toDigits) {
final int l = data.length;
final char[] out = new char[l << 1];
for (int i = 0, j = 0; i < l; i++) {
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
out[j++] = toDigits[0x0F & data[i]];
}
return out;
}
public static String md5Hex(String str) {
return md5Hex(str, false);
}
public static String md5Hex(String str, boolean isUpper) {
try {
return new String(encodeHex(MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8")), isUpper ? DIGITS_UPPER : DIGITS_LOWER));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/* ---------------------------------------------分割线------------------------------------------------*/
/** 网络相关的处理类 */
private static class NetworkUtils {
private static final String DEFAULT_HOST_IP = "10.10.10.10";
/**
* 获取当前进程的PID
*/
public static String getPid() {
return ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
}
/**
* 获取当前进程的主机IP地址
*/
public static String getHostIP() {
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
return DEFAULT_HOST_IP;
}
}
}
/* ---------------------------------------------分割线------------------------------------------------*/
/** 数据处理的相关类 */
private static class MathUtils {
private static final String DEFAULT_DIGITS = "0";
private static final String FIRST_DEFAULT_DIGITS = "1";
/**
* @param target 目标数字
* @param length 需要补充到的位数, 补充默认数字[0], 第一位默认补充[1]
* @return 补充后的结果
*/
public static String makeUpNewData(String target, int length) {
return makeUpNewData(target, length, DEFAULT_DIGITS);
}
/**
* @param target 目标数字
* @param length 需要补充到的位数
* @param add 需要补充的数字, 补充默认数字[0], 第一位默认补充[1]
* @return 补充后的结果
*/
public static String makeUpNewData(String target, int length, String add) {
if (target.startsWith("-"))
target.replace("-", "");
if (target.length() >= length)
return target.substring(0, length);
StringBuffer sb = new StringBuffer(FIRST_DEFAULT_DIGITS);
for (int i = 0; i < length - (1 + target.length()); i++) {
sb.append(add);
}
return sb.append(target).toString();
}
/**
* 生产一个随机的指定位数的字符串数字
* @param length
* @return
*/
public static String randomDigitNumber(int length) {
int start = Integer.parseInt(makeUpNewData("", length));// 1000+8999=9999
int end = Integer.parseInt(makeUpNewData("", length + 1)) - start;// 9000
return (int) (Math.random() * end) + start + "";
}
public static void main(String args[]) {
System.out.println(UUID.randomUUID().toString());
System.out.println(DigestUtils.md5Hex(UUID.randomUUID().toString()));
}
}
}
package com.sinobase.common.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import com.sinobase.common.utils.StringUtils;
import com.sinobase.framework.web.page.TableDataInfo;
import com.sinobase.project.system.portal.domain.Message;
/**
* Map通用处理方法
*
* @author sinobase
*/
public class MapDataUtil {
public static Map<String, Object> convertDataMap(HttpServletRequest request) {
Map<String, String[]> properties = request.getParameterMap();
Map<String, Object> returnMap = new HashMap<String, Object>();
Iterator<?> entries = properties.entrySet().iterator();
Map.Entry<?, ?> entry;
String name = "";
String value = "";
while (entries.hasNext()) {
entry = (Entry<?, ?>) entries.next();
name = (String) entry.getKey();
Object valueObj = entry.getValue();
if (null == valueObj) {
value = "";
} else if (valueObj instanceof String[]) {
String[] values = (String[]) valueObj;
for (int i = 0; i < values.length; i++) {
value = values[i] + ",";
}
value = value.substring(0, value.length() - 1);
} else {
value = valueObj.toString();
}
returnMap.put(name, value);
}
return returnMap;
}
/**
* 将json对象转换成Map
* @param jsonmap
* @return
*/
@SuppressWarnings("unchecked")
public Map<String, String> jsonToMap(net.sf.json.JSONObject jsonmap) {
Map<String, String> map = new HashMap<String, String>();
Iterator<String> iterator = (Iterator<String>) jsonmap.keys();
String key = null;
String value = null;
while (iterator.hasNext()) {
key = iterator.next();
try {
value = jsonmap.getString(key);
} catch (Exception e) {
e.printStackTrace();
}
map.put(key, value);
}
return map;
}
/**
* APP数据返回封装
* @param code
* @param msg
* @param tableDataInfo 数据列表
* @return
*/
public static Map<String,Object> tableDataInfoToMap(String code, String msg, TableDataInfo tableDataInfo){
Map<String,Object> resultMap = new HashMap<>();
code = StringUtils.isNotEmpty(code) ? code : "1";
resultMap.put("code",code);
resultMap.put("msg", ("1".equals(code) ? "请求错误" : "操作成功") );
resultMap.put("data",tableDataInfo);
return resultMap;
}
/**
* APP数据返回封装
* @param code
* @param msg
* @param object 数据实体
* @return
*/
public static Map<String,Object> objectToMap(String code,String msg,Object object){
Map<String,Object> resultMap = new HashMap<>();
code = StringUtils.isNotEmpty(code) ? code : "1";
resultMap.put("code",code);
resultMap.put("msg", ("1".equals(code) ? "请求错误" : "操作成功") );
resultMap.put("data",object);
return resultMap;
}
/**
* 数据返回初始化
*
* @param list
* @param number
* @return
*/
public static Map<String, Object> initMap(List<Message> list, Integer number) {
if(number == null){
number = 0;
}
Map<String, Object> map = new HashMap<>();
if (list == null) {
map.put("data", new ArrayList<>());
map.put("number", 0);
} else {
if (number > 0) {
if (list.size() > number) {
map.put("data", list.subList(0, number));
} else {
map.put("data", list);
}
} else {
map.put("data", list);
}
map.put("number", list.size());
}
return map;
}
}
package com.sinobase.common.utils;
import java.math.BigDecimal;
/**
* 精确的浮点数运算
*
* @author sinobase
*/
public class Arith
{
/** 默认除法运算精度 */
private static final int DEF_DIV_SCALE = 10;
/** 这个类不能实例化 */
private Arith()
{
}
/**
* 提供精确的加法运算。
* @param v1 被加数
* @param v2 加数
* @return 两个参数的和
*/
public static double add(double v1, double v2)
{
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.add(b2).doubleValue();
}
/**
* 提供精确的减法运算。
* @param v1 被减数
* @param v2 减数
* @return 两个参数的差
*/
public static double sub(double v1, double v2)
{
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.subtract(b2).doubleValue();
}
/**
* 提供精确的乘法运算。
* @param v1 被乘数
* @param v2 乘数
* @return 两个参数的积
*/
public static double mul(double v1, double v2)
{
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.multiply(b2).doubleValue();
}
/**
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
* 小数点以后10位,以后的数字四舍五入。
* @param v1 被除数
* @param v2 除数
* @return 两个参数的商
*/
public static double div(double v1, double v2)
{
return div(v1, v2, DEF_DIV_SCALE);
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
* 定精度,以后的数字四舍五入。
* @param v1 被除数
* @param v2 除数
* @param scale 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public static double div(double v1, double v2, int scale)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
if (b1.compareTo(BigDecimal.ZERO) == 0)
{
return BigDecimal.ZERO.doubleValue();
}
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/**
* 提供精确的小数位四舍五入处理。
* @param v 需要四舍五入的数字
* @param scale 小数点后保留几位
* @return 四舍五入后的结果
*/
public static double round(double v, int scale)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
BigDecimal one = new BigDecimal("1");
return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}
package com.sinobase.common.utils;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.util.UUID;
/**
* 用于生产各种各样的ID
* @author LouBin
*/
public class IdUtils {
private static String middle = "";
static {
middle = MathUtils.makeUpNewData(Math.abs(NetworkUtils.getHostIP().hashCode()) + "", 4) + // 4位IP地址hash
MathUtils.makeUpNewData(NetworkUtils.getPid(), 4); // 4位PID进程hash
}
/**
* 以毫微秒做基础计数, 返回唯一有序增长ID
* <pre> System.nanoTime() </pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 222 ms
* 数组长度: 100000
* Map Size: 100000
* @return ID长度32位
*/
public static String getIncreaseIdByNanoTime() {
return System.nanoTime() + // 时间戳-14位
middle + // 标志-8位
MathUtils.makeUpNewData(Thread.currentThread().hashCode() + "", 3) + // 3位线程标志
MathUtils.randomDigitNumber(7); // 随机7位数
}
/**
* 毫秒做基础计数, 返回ID, 有几率出现线程并发
* @return ID长度 15 位
*/
public static String getIdByTime() {
long r = 0;
synchronized (new byte[0]) {
r = (long) ((Math.random() + 1) * 100);
}
return System.currentTimeMillis() + String.valueOf(r).substring(1);
}
/**
* 以毫秒做基础计数, 返回唯一有序增长ID, 有几率出现线程并发
* <pre>
* System.currentTimeMillis()
* </pre>
* <pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 206 ms
* 数组长度: 100000
* Map Size: 99992
* </pre>
*
* @return ID长度32位
*/
public static String getIncreaseIdByCurrentTimeMillis() {
return System.currentTimeMillis() + // 时间戳-14位
middle + // 标志-8位
MathUtils.makeUpNewData(Thread.currentThread().hashCode() + "", 3) + // 3位线程标志
MathUtils.randomDigitNumber(8); // 随机8位数
}
/**
* 基于UUID+MD5产生唯一无序ID
*
* <pre>
* 线程数量: 100
* 执行次数: 1000
* 平均耗时: 591 ms
* 数组长度: 100000
* Map Size: 100000
* </pre>
*
* @return ID长度32位
*/
public static String getRandomIdByUUID() {
return DigestUtils.md5Hex(UUID.randomUUID().toString());
}
/* ---------------------------------------------分割线------------------------- ----------------------- */
/** 字符串MD5处理类 */
private static class DigestUtils {
private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private static char[] encodeHex(final byte[] data, final char[] toDigits) {
final int l = data.length;
final char[] out = new char[l << 1];
for (int i = 0, j = 0; i < l; i++) {
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
out[j++] = toDigits[0x0F & data[i]];
}
return out;
}
public static String md5Hex(String str) {
return md5Hex(str, false);
}
public static String md5Hex(String str, boolean isUpper) {
try {
return new String(encodeHex(MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8")), isUpper ? DIGITS_UPPER : DIGITS_LOWER));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/* ---------------------------------------------分割线------------------------------------------------*/
/** 网络相关的处理类 */
private static class NetworkUtils {
private static final String DEFAULT_HOST_IP = "10.10.10.10";
/**
* 获取当前进程的PID
*/
public static String getPid() {
return ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
}
/**
* 获取当前进程的主机IP地址
*/
public static String getHostIP() {
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
return DEFAULT_HOST_IP;
}
}
}
/* ---------------------------------------------分割线------------------------------------------------*/
/** 数据处理的相关类 */
private static class MathUtils {
private static final String DEFAULT_DIGITS = "0";
private static final String FIRST_DEFAULT_DIGITS = "1";
/**
* @param target 目标数字
* @param length 需要补充到的位数, 补充默认数字[0], 第一位默认补充[1]
* @return 补充后的结果
*/
public static String makeUpNewData(String target, int length) {
return makeUpNewData(target, length, DEFAULT_DIGITS);
}
/**
* @param target 目标数字
* @param length 需要补充到的位数
* @param add 需要补充的数字, 补充默认数字[0], 第一位默认补充[1]
* @return 补充后的结果
*/
public static String makeUpNewData(String target, int length, String add) {
if (target.startsWith("-"))
target.replace("-", "");
if (target.length() >= length)
return target.substring(0, length);
StringBuffer sb = new StringBuffer(FIRST_DEFAULT_DIGITS);
for (int i = 0; i < length - (1 + target.length()); i++) {
sb.append(add);
}
return sb.append(target).toString();
}
/**
* 生产一个随机的指定位数的字符串数字
* @param length
* @return
*/
public static String randomDigitNumber(int length) {
int start = Integer.parseInt(makeUpNewData("", length));// 1000+8999=9999
int end = Integer.parseInt(makeUpNewData("", length + 1)) - start;// 9000
return (int) (Math.random() * end) + start + "";
}
public static void main(String args[]) {
System.out.println(UUID.randomUUID().toString());
System.out.println(DigestUtils.md5Hex(UUID.randomUUID().toString()));
}
}
}
package com.sinobase.common.utils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
/**
* 获取IP方法
*
* @author sinobase
*/
public class IpUtils
{
public static String getIpAddr(HttpServletRequest request)
{
if (request == null)
{
return "unknown";
}
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("X-Forwarded-For");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getRemoteAddr();
}
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
}
public static boolean internalIp(String ip)
{
byte[] addr = textToNumericFormatV4(ip);
return internalIp(addr) || "127.0.0.1".equals(ip);
}
private static boolean internalIp(byte[] addr)
{
final byte b0 = addr[0];
final byte b1 = addr[1];
// 10.x.x.x/8
final byte SECTION_1 = 0x0A;
// 172.16.x.x/12
final byte SECTION_2 = (byte) 0xAC;
final byte SECTION_3 = (byte) 0x10;
final byte SECTION_4 = (byte) 0x1F;
// 192.168.x.x/16
final byte SECTION_5 = (byte) 0xC0;
final byte SECTION_6 = (byte) 0xA8;
switch (b0)
{
case SECTION_1:
return true;
case SECTION_2:
if (b1 >= SECTION_3 && b1 <= SECTION_4)
{
return true;
}
case SECTION_5:
switch (b1)
{
case SECTION_6:
return true;
}
default:
return false;
}
}
/**
* 将IPv4地址转换成字节
*
* @param text IPv4地址
* @return byte 字节
*/
public static byte[] textToNumericFormatV4(String text)
{
if (text.length() == 0)
{
return null;
}
byte[] bytes = new byte[4];
String[] elements = text.split("\\.", -1);
try
{
long l;
int i;
switch (elements.length)
{
case 1:
l = Long.parseLong(elements[0]);
if ((l < 0L) || (l > 4294967295L))
return null;
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 2:
l = Integer.parseInt(elements[0]);
if ((l < 0L) || (l > 255L))
return null;
bytes[0] = (byte) (int) (l & 0xFF);
l = Integer.parseInt(elements[1]);
if ((l < 0L) || (l > 16777215L))
return null;
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 3:
for (i = 0; i < 2; ++i)
{
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L))
return null;
bytes[i] = (byte) (int) (l & 0xFF);
}
l = Integer.parseInt(elements[2]);
if ((l < 0L) || (l > 65535L))
return null;
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 4:
for (i = 0; i < 4; ++i)
{
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L))
return null;
bytes[i] = (byte) (int) (l & 0xFF);
}
break;
default:
return null;
}
}
catch (NumberFormatException e)
{
return null;
}
return bytes;
}
public static String getHostIp()
{
try
{
return InetAddress.getLocalHost().getHostAddress();
}
catch (UnknownHostException e)
{
}
return "127.0.0.1";
}
public static String getHostName()
{
try
{
return InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e)
{
}
return "未知";
}
}
\ No newline at end of file
package com.sinobase.common.utils;
import java.util.LinkedList;
public class LimitQueue<E> {
private int limit;
private LinkedList<E> queue = new LinkedList<E>();
public LimitQueue(int limit){
this.limit = limit;
}
public void append(E e){
if(queue.size() >= limit){
queue.poll();
}
queue.offer(e);
}
public E get(int position) {
return queue.get(position);
}
public E getLast() {
return queue.getLast();
}
public E getFirst() {
return queue.getFirst();
}
public int getLimit() {
return limit;
}
public int size() {
return queue.size();
}
public int indexOf(E e) {
return queue.indexOf(e);
}
}
package com.sinobase.common.utils;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
/**
* 处理并记录日志文件
*
* @author sinobase
*/
public class LogUtils {
public static final Logger ERROR_LOG = LoggerFactory.getLogger("sys-error");
public static final Logger ACCESS_LOG = LoggerFactory.getLogger("sys-access");
/**
* 记录访问日志
* [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
*
* @param request
*/
public static void logAccess(HttpServletRequest request) {
String username = getUsername();
String jsessionId = request.getRequestedSessionId();
String ip = IpUtils.getIpAddr(request);
String accept = request.getHeader("accept");
String userAgent = request.getHeader("User-Agent");
String url = request.getRequestURI();
String params = getParams(request);
StringBuilder s = new StringBuilder();
s.append(getBlock(username));
s.append(getBlock(jsessionId));
s.append(getBlock(ip));
s.append(getBlock(accept));
s.append(getBlock(userAgent));
s.append(getBlock(url));
s.append(getBlock(params));
s.append(getBlock(request.getHeader("Referer")));
getAccessLog().info(s.toString());
}
/**
* 记录异常错误 格式 [exception]
*
* @param message
* @param e
*/
public static void logError(String message, Throwable e) {
String username = getUsername();
StringBuilder s = new StringBuilder();
s.append(getBlock("exception"));
s.append(getBlock(username));
s.append(getBlock(message));
ERROR_LOG.error(s.toString(), e);
}
/**
* 记录页面错误 错误日志记录
* [page/eception][username][statusCode][errorMessage][servletName][uri][
* exceptionName][ip][exception]
*
* @param request
*/
public static void logPageError(HttpServletRequest request) {
String username = getUsername();
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
String message = (String) request.getAttribute("javax.servlet.error.message");
String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");
if (statusCode == null) {
statusCode = 0;
}
StringBuilder s = new StringBuilder();
s.append(getBlock(t == null ? "page" : "exception"));
s.append(getBlock(username));
s.append(getBlock(statusCode));
s.append(getBlock(message));
s.append(getBlock(IpUtils.getIpAddr(request)));
s.append(getBlock(uri));
s.append(getBlock(request.getHeader("Referer")));
StringWriter sw = new StringWriter();
while (t != null) {
t.printStackTrace(new PrintWriter(sw));
t = t.getCause();
}
s.append(getBlock(sw.toString()));
getErrorLog().error(s.toString());
}
public static String getBlock(Object msg) {
if (msg == null) {
msg = "";
}
return "[" + msg.toString() + "]";
}
protected static String getParams(HttpServletRequest request) {
Map<String, String[]> params = request.getParameterMap();
return JSON.toJSONString(params);
}
protected static String getUsername() {
return (String) SecurityUtils.getSubject().getPrincipal();
}
public static Logger getAccessLog() {
return ACCESS_LOG;
}
public static Logger getErrorLog() {
return ERROR_LOG;
}
}
package com.sinobase.common.utils;
import com.sinobase.framework.web.page.TableDataInfo;
import com.sinobase.project.system.portal.domain.Message;
import java.util.*;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
/**
* Map通用处理方法
*
* @author sinobase
*/
public class MapDataUtil {
public static Map<String, Object> convertDataMap(HttpServletRequest request) {
Map<String, String[]> properties = request.getParameterMap();
Map<String, Object> returnMap = new HashMap<String, Object>();
Iterator<?> entries = properties.entrySet().iterator();
Map.Entry<?, ?> entry;
String name = "";
String value = "";
while (entries.hasNext()) {
entry = (Entry<?, ?>) entries.next();
name = (String) entry.getKey();
Object valueObj = entry.getValue();
if (null == valueObj) {
value = "";
} else if (valueObj instanceof String[]) {
String[] values = (String[]) valueObj;
for (int i = 0; i < values.length; i++) {
value = values[i] + ",";
}
value = value.substring(0, value.length() - 1);
} else {
value = valueObj.toString();
}
returnMap.put(name, value);
}
return returnMap;
}
/**
* 将json对象转换成Map
* @param jsonmap
* @return
*/
@SuppressWarnings("unchecked")
public Map<String, String> jsonToMap(net.sf.json.JSONObject jsonmap) {
Map<String, String> map = new HashMap<String, String>();
Iterator<String> iterator = (Iterator<String>) jsonmap.keys();
String key = null;
String value = null;
while (iterator.hasNext()) {
key = iterator.next();
try {
value = jsonmap.getString(key);
} catch (Exception e) {
e.printStackTrace();
}
map.put(key, value);
}
return map;
}
/**
* APP数据返回封装
* @param code
* @param msg
* @param tableDataInfo 数据列表
* @return
*/
public static Map<String,Object> tableDataInfoToMap(String code, String msg, TableDataInfo tableDataInfo){
Map<String,Object> resultMap = new HashMap<>();
code = StringUtils.isNotEmpty(code) ? code : "1";
resultMap.put("code",code);
resultMap.put("msg", ("1".equals(code) ? "请求错误" : "操作成功") );
resultMap.put("data",tableDataInfo);
return resultMap;
}
/**
* APP数据返回封装
* @param code
* @param msg
* @param object 数据实体
* @return
*/
public static Map<String,Object> objectToMap(String code,String msg,Object object){
Map<String,Object> resultMap = new HashMap<>();
code = StringUtils.isNotEmpty(code) ? code : "1";
resultMap.put("code",code);
resultMap.put("msg", ("1".equals(code) ? "请求错误" : "操作成功") );
resultMap.put("data",object);
return resultMap;
}
/**
* 数据返回初始化
*
* @param list
* @param number
* @return
*/
public static Map<String, Object> initMap(List<Message> list, Integer number) {
if(number == null){
number = 0;
}
Map<String, Object> map = new HashMap<>();
if (list == null) {
map.put("data", new ArrayList<>());
map.put("number", 0);
} else {
if (number > 0) {
if (list.size() > number) {
map.put("data", list.subList(0, number));
} else {
map.put("data", list);
}
} else {
map.put("data", list);
}
map.put("number", list.size());
}
return map;
}
}
package com.sinobase.common.utils;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class MapUtil {
/**
*
* @Title: objectToMap
* @Description: 将object转换为map,默认不保留空值
* @param @param obj
* @return Map<String,Object> 返回类型
* @throws
*/
public static Map<String, Object> objectToMap(Object obj) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map = objectToMap(obj, false);
return map;
}
public static Map<String, Object> objectToMap(Object obj, boolean keepNullVal) {
if (obj == null) {
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
try {
Field[] declaredFields = obj.getClass().getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
if (keepNullVal == true) {
map.put(field.getName(), field.get(obj));
} else {
if (field.get(obj) != null && !"".equals(field.get(obj).toString())) {
map.put(field.getName(), field.get(obj));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}
package com.sinobase.common.utils;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Md5加密方法
*
* @author sinobase
*/
public class Md5Utils
{
private static final Logger log = LoggerFactory.getLogger(Md5Utils.class);
private static byte[] md5(String s)
{
MessageDigest algorithm;
try
{
algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(s.getBytes("UTF-8"));
byte[] messageDigest = algorithm.digest();
return messageDigest;
}
catch (Exception e)
{
log.error("MD5 Error...", e);
}
return null;
}
private static final String toHex(byte hash[])
{
if (hash == null)
{
return null;
}
StringBuffer buf = new StringBuffer(hash.length * 2);
int i;
for (i = 0; i < hash.length; i++)
{
if ((hash[i] & 0xff) < 0x10)
{
buf.append("0");
}
buf.append(Long.toString(hash[i] & 0xff, 16));
}
return buf.toString();
}
public static String hash(String s)
{
try
{
return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
}
catch (Exception e)
{
log.error("not supported charset...{}", e);
return s;
}
}
public static void main(String[] args) {
String str = "53564e922d710bad7a9de6bdc5ace2a5";
String time = new SimpleDateFormat("202102031935").format(new Date());
System.out.println(time);
String dd = Md5Utils.hash(str + time);
System.out.println(dd);
}
}
package com.sinobase.common.utils;
import org.springframework.context.MessageSource;
import com.sinobase.common.utils.spring.SpringUtils;
/**
* 获取i18n资源文件
*
* @author sinobase
*/
public class MessageUtils
{
/**
* 根据消息键和参数 获取消息 委托给spring messageSource
*
* @param code 消息键
* @param args 参数
* @return
*/
public static String message(String code, Object... args)
{
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
return messageSource.getMessage(code, args, null);
}
}
package com.sinobase.common.utils;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.sinobase.common.support.Convert;
/**
* 客户端工具类
*
* @author sinobase
*/
public class ServletUtils {
public static String[] getParameters(String name) {
return getRequest().getParameterValues(name);
}
/**
* 获取String参数
*/
public static String getParameter(String name) {
return Convert.toStr(getRequest().getParameter(name), "");
}
/**
* 获取String参数
*/
public static String getParameter(String name, String defaultValue) {
return Convert.toStr(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name) {
return Convert.toInt(getRequest().getParameter(name));
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name, Integer defaultValue) {
return Convert.toInt(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Boolean参数
* @return
*/
public static Boolean getParameterToBoolean(String name) {
return Convert.toBool(getRequest().getParameter(name));
}
/**
* 获取request
*/
public static HttpServletRequest getRequest() {
return getRequestAttributes().getRequest();
}
/**
* 获取response
*/
public static HttpServletResponse getResponse() {
return getRequestAttributes().getResponse();
}
/**
* 获取session
*/
public static HttpSession getSession() {
return getRequest().getSession();
}
public static ServletRequestAttributes getRequestAttributes() {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
return (ServletRequestAttributes) attributes;
}
/**
* 将字符串渲染到客户端
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @return null
*/
public static String renderString(HttpServletResponse response, String string) {
try {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 是否是Ajax异步请求
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request) {
String accept = request.getHeader("accept");
if (accept != null && accept.indexOf("application/json") != -1) {
return true;
}
String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) {
return true;
}
String uri = request.getRequestURI();
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) {
return true;
}
String ajax = request.getParameter("__ajax");
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) {
return true;
}
return false;
}
}
package com.sinobase.common.utils;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 线程相关工具类.
*
* @author sinobase
*/
public class Threads {
private static final Logger logger = LoggerFactory.getLogger("sys-user");
/**
* sleep等待,单位为毫秒
*/
public static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
return;
}
}
/**
* 停止线程池 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 如果超时, 则调用shutdownNow,
* 取消在workQueue中Pending的任务,并中断所有阻塞函数. 如果仍人超時,則強制退出.
* 另对在shutdown时线程本身被调用中断做了处理.
*/
public static void shutdownAndAwaitTermination(ExecutorService pool) {
if (pool != null && !pool.isShutdown()) {
pool.shutdown();
try {
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
pool.shutdownNow();
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
logger.info("Pool did not terminate");
}
}
} catch (InterruptedException ie) {
pool.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
}
package com.sinobase.common.utils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.sinobase.project.system.menu.domain.Menu;
/**
* 权限数据处理
*
* @author sinobase
*/
public class TreeUtils {
/**
* 根据父节点的ID获取所有子节点
*
* @param list 分类表
* @param parentId 传入的父节点ID
* @return String
*/
public static List<Menu> getChildPerms(List<Menu> list, String parentId) {
List<Menu> returnList = new ArrayList<Menu>();
for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext();) {
Menu t = (Menu) iterator.next();
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId().equals(parentId)) {
//System.out.println((t.getUrl().indexOf("parse_tab") > -1)+"------------"+ t.getMenuName()+"--------"+ t.getUrl());
if(t.getUrl().indexOf("parse_tab") < 0){
recursionFn(list, t);
}
returnList.add(t);
}
}
return returnList;
}
/**
* 递归列表
*
* @param list
* @param t
*/
private static void recursionFn(List<Menu> list, Menu t) {
// 得到子节点列表
List<Menu> childList = getChildList(list, t);
t.setChildren(childList);
for (Menu tChild : childList) {
if (hasChild(list, tChild)) {
// 判断是否有子节点
Iterator<Menu> it = childList.iterator();
while (it.hasNext()) {
Menu n = (Menu) it.next();
recursionFn(list, n);
}
}
}
}
/**
* 得到子节点列表
*/
private static List<Menu> getChildList(List<Menu> list, Menu t) {
List<Menu> tlist = new ArrayList<Menu>();
//20200103 LoubBin 添加 模块设置 标签页面功能无效BUG
if(t.getUrl().indexOf("parse_tab") < 0 && !t.getMenuType().equals("C")){
//System.out.println(t.getMenuName() + "------------"+t.getUrl());
Iterator<Menu> it = list.iterator();
while (it.hasNext()) {
Menu n = (Menu) it.next();
if (n.getParentId().equals(t.getMenuId())) {
tlist.add(n);
}
}
}
return tlist;
}
List<Menu> returnList = new ArrayList<Menu>();
/**
* 根据父节点的ID获取所有子节点
*
* @param list 分类表
* @param typeId 传入的父节点ID
* @param prefix 子节点前缀
*/
public List<Menu> getChildPerms(List<Menu> list, int typeId, String prefix) {
if (list == null) {
return null;
}
for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext();) {
Menu node = (Menu) iterator.next();
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
if (node.getParentId().equals(typeId)) {
recursionFn(list, node, prefix);
}
// 二、遍历所有的父节点下的所有子节点
/*
* if (node.getParentId()==0) { recursionFn(list, node); }
*/
}
return returnList;
}
private void recursionFn(List<Menu> list, Menu node, String p) {
// 得到子节点列表
List<Menu> childList = getChildList(list, node);
if (hasChild(list, node)) {
// 判断是否有子节点
returnList.add(node);
Iterator<Menu> it = childList.iterator();
while (it.hasNext()) {
Menu n = (Menu) it.next();
n.setMenuName(p + n.getMenuName());
recursionFn(list, n, p + p);
}
} else {
returnList.add(node);
}
}
/**
* 判断是否有子节点
*/
private static boolean hasChild(List<Menu> list, Menu t) {
return getChildList(list, t).size() > 0 ? true : false;
}
}
package com.sinobase.common.utils.bean;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Bean 工具类
*
* @author sinobase
*/
public class BeanUtils
{
/** Bean方法名中属性名开始的下标 */
private static final int BEAN_METHOD_PROP_INDEX = 3;
/** * 匹配getter方法的正则表达式 */
private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)");
/** * 匹配setter方法的正则表达式 */
private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)");
/**
* Bean属性复制工具方法。
*
* @param dest 目标对象
* @param src 源对象
*/
public static void copyBeanProp(Object dest, Object src)
{
List<Method> destSetters = getSetterMethods(dest);
List<Method> srcGetters = getGetterMethods(src);
try
{
for (Method setter : destSetters)
{
for (Method getter : srcGetters)
{
if (isMethodPropEquals(setter.getName(), getter.getName())
&& setter.getParameterTypes()[0].equals(getter.getReturnType()))
{
setter.invoke(dest, getter.invoke(src));
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* 获取对象的setter方法。
*
* @param obj 对象
* @return 对象的setter方法列表
*/
public static List<Method> getSetterMethods(Object obj)
{
// setter方法列表
List<Method> setterMethods = new ArrayList<Method>();
// 获取所有方法
Method[] methods = obj.getClass().getMethods();
// 查找setter方法
for (Method method : methods)
{
Matcher m = SET_PATTERN.matcher(method.getName());
if (m.matches() && (method.getParameterTypes().length == 1))
{
setterMethods.add(method);
}
}
// 返回setter方法列表
return setterMethods;
}
/**
* 获取对象的getter方法。
*
* @param obj 对象
* @return 对象的getter方法列表
*/
public static List<Method> getGetterMethods(Object obj)
{
// getter方法列表
List<Method> getterMethods = new ArrayList<Method>();
// 获取所有方法
Method[] methods = obj.getClass().getMethods();
// 查找getter方法
for (Method method : methods)
{
Matcher m = GET_PATTERN.matcher(method.getName());
if (m.matches() && (method.getParameterTypes().length == 0))
{
getterMethods.add(method);
}
}
// 返回getter方法列表
return getterMethods;
}
/**
* 检查Bean方法名中的属性名是否相等。<br>
* 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。
*
* @param m1 方法名1
* @param m2 方法名2
* @return 属性名一样返回true,否则返回false
*/
public static boolean isMethodPropEquals(String m1, String m2)
{
return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
}
}
package com.sinobase.common.utils.spring;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
/**
* spring工具类 方便在非spring管理环境中获取bean
*
* @author sinobase
*/
@Component
public final class SpringUtils implements BeanFactoryPostProcessor
{
/** Spring应用上下文环境 */
private static ConfigurableListableBeanFactory beanFactory;
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
{
SpringUtils.beanFactory = beanFactory;
}
/**
* 获取对象
*
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws org.springframework.beans.BeansException
*
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException
{
return (T) beanFactory.getBean(name);
}
/**
* 获取类型为requiredType的对象
*
* @param clz
* @return
* @throws org.springframework.beans.BeansException
*
*/
public static <T> T getBean(Class<T> clz) throws BeansException
{
T result = (T) beanFactory.getBean(clz);
return result;
}
/**
* 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
*
* @param name
* @return boolean
*/
public static boolean containsBean(String name)
{
return beanFactory.containsBean(name);
}
/**
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
*
* @param name
* @return boolean
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.isSingleton(name);
}
/**
* @param name
* @return Class 注册对象的类型
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getType(name);
}
/**
* 如果给定的bean名字在bean定义中有别名,则返回这些别名
*
* @param name
* @return
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getAliases(name);
}
}
package com.sinobase.framework.aspectj.lang.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 数据权限过滤注解
*
* @author sinobase
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataScope
{
/**
* 表的别名
*/
public String tableAlias() default "";
}
package com.sinobase.framework.aspectj.lang.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 自定义导出Excel数据注解
*
* @author ruoyi
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Excel {
/**
* 导出到Excel中的名字.
*/
public String name() default "";
/**
* 日期格式, 如: yyyy-MM-dd
*/
public String dateFormat() default "";
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
public String readConverterExp() default "";
/**
* 导出时在excel中每个列的高度 单位为字符
*/
public double height() default 14;
/**
* 导出时在excel中每个列的宽 单位为字符
*/
public double width() default 16;
/**
* 文字后缀,如% 90 变成90%
*/
public String suffix() default "";
/**
* 当值为空时,字段的默认值
*/
public String defaultValue() default "";
/**
* 提示信息
*/
public String prompt() default "";
/**
* 设置只能选择不能输入的列内容.
*/
public String[] combo() default {};
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
public boolean isExport() default true;
/**
* 另一个类中的属性名称,支持多级获取,以小数点隔开
*/
public String targetAttr() default "";
/**
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
*/
Type type() default Type.ALL;
public enum Type {
ALL(0), EXPORT(1), IMPORT(2);
private final int value;
Type(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}
}
\ No newline at end of file
package com.sinobase.framework.aspectj.lang.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Excel注解集
*
* @author ruoyi
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Excels {
Excel[] value();
}
\ No newline at end of file
package com.sinobase.framework.aspectj.lang.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.sinobase.framework.aspectj.lang.enums.BusinessType;
import com.sinobase.framework.aspectj.lang.enums.OperatorType;
/**
* 自定义操作日志记录注解
*
* @author sinobase
*
*/
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Log
{
/**
* 模块
*/
public String title() default "";
/**
* 功能
*/
public BusinessType businessType() default BusinessType.OTHER;
/**
* 操作人类别
*/
public OperatorType operatorType() default OperatorType.MANAGE;
/**
* 是否保存请求的参数
*/
public boolean isSaveRequestData() default true;
}
package com.sinobase.framework.aspectj.lang.enums;
/**
* 操作状态
*
* @author sinobase
*
*/
public enum BusinessStatus
{
/**
* 成功
*/
SUCCESS,
/**
* 失败
*/
FAIL,
}
package com.sinobase.framework.aspectj.lang.enums;
/**
* 业务操作类型
* @author sinobase
*
*/
public enum BusinessType{
/**
* 其它
*/
OTHER,
/**
* 新增
*/
INSERT,
/**
* 修改
*/
UPDATE,
/**
* 删除
*/
DELETE,
/**
* 授权
*/
GRANT,
/**
* 导出
*/
EXPORT,
/**
* 导入
*/
IMPORT,
/**
* 强退
*/
FORCE,
/**
* 生成代码
*/
GENCODE,
/**
* 清空数据
*/
CLEAN,
/**
* 查询
*/
QUERY,
/**
* 新增或修改
*/
SAVEORUPDATE,
}
package com.sinobase.framework.aspectj.lang.enums;
/**
* 操作人类别
*
* @author sinobase
*
*/
public enum OperatorType
{
/**
* 其它
*/
OTHER,
/**
* 后台用户
*/
MANAGE,
/**
* 手机端用户
*/
MOBILE
}
package com.sinobase.framework.web.domain;
import java.util.HashMap;
import java.util.Map;
import com.sinobase.common.utils.StringUtils;
/**
* 操作消息提醒
*/
public class AjaxResult extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public static final String CODE_TAG = "code";
public static final String MSG_TAG = "msg";
public static final String DATA_TAG = "data";
/**
* 状态类型
*/
public enum Type {
/** 成功 */
SUCCESS(0),
/** 警告 */
WARN(301),
/** 错误 */
ERROR(500);
private final int value;
Type(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}
/** 状态类型 */
private Type type;
/** 状态码 */
private int code;
/** 返回内容 */
private String msg;
/** 数据对象 */
private Object data;
/**
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
*/
public AjaxResult() {
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param type 状态类型
* @param msg 返回内容
*/
public AjaxResult(Type type, String msg) {
super.put(CODE_TAG, type.value);
super.put(MSG_TAG, msg);
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param type 状态类型
* @param msg 返回内容
* @param data 数据对象
*/
public AjaxResult(Type type, String msg, Object data) {
super.put(CODE_TAG, type.value);
super.put(MSG_TAG, msg);
if (StringUtils.isNotNull(data)) {
super.put(DATA_TAG, data);
}
}
/**
* 返回错误消息
*
* @return 错误消息
*/
public static AjaxResult error() {
return error(1, "操作失败");
}
/**
* 返回错误消息
*
* @param msg 内容
* @return 错误消息
*/
public static AjaxResult error(String msg) {
return error(500, msg);
}
/**
* 返回错误消息
*
* @param code 错误码
* @param msg 内容
* @return 错误消息
*/
public static AjaxResult error(int code, String msg) {
AjaxResult json = new AjaxResult();
json.put("code", code);
json.put("msg", msg);
return json;
}
/**
* 返回成功数据
* @return 成功消息
*/
public static AjaxResult success(Object data) {
return AjaxResult.success("操作成功", data);
}
/**
* 返回成功消息
* @param msg 内容
* @return 成功消息
*/
public static AjaxResult success(String msg) {
AjaxResult json = new AjaxResult();
json.put("msg", msg);
json.put("code", 0);
return json;
}
/**
* 返回成功消息
*
* @param msg 内容
* @param map 返回的数据对象
* @return 成功消息 + data
*/
public static AjaxResult success(String msg, Map<String, Object> map) {
AjaxResult json = new AjaxResult();
json.put("msg", msg);
json.put("code", 0);
json.put("data", map);
return json;
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static AjaxResult success(String msg, Object data) {
return new AjaxResult(Type.SUCCESS, msg, data);
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static AjaxResult success() {
return AjaxResult.success("操作成功");
}
/**
* 返回成功消息
*
* @param key 键值
* @param value 内容
* @return 成功消息
*/
@Override
public AjaxResult put(String key, Object value) {
super.put(key, value);
return this;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
package com.sinobase.framework.web.domain;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Maps;
/**
* Entity基类
*/
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/** 搜索值 */
@TableField(exist=false)
private String searchValue;
/** 创建者 */
@TableField(exist=false)
private String createBy;
/** 创建时间 */
@TableField(exist=false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新者 */
@TableField(exist=false)
private String updateBy;
/** 更新时间 */
@TableField(exist=false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")//因为我们是东八区(北京时间),所以在格式化的时候要指定时区(timezone )
private Date updateTime;
/** 备注 */
@TableField(exist=false)
private String remark;
/** 请求参数 */
@TableField(exist=false)
private Map<String, Object> params;
/**请求类型*/
@TableField(exist=false)
private String requestType;
public String getSearchValue() {
return searchValue;
}
public void setSearchValue(String searchValue) {
this.searchValue = searchValue;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Map<String, Object> getParams() {
if (params == null) {
params = Maps.newHashMap();
}
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
public String getRequestType() {
return requestType;
}
public void setRequestType(String requestType) {
this.requestType = requestType;
}
}
package com.sinobase.framework.web.domain;
import java.util.Date;
public class FlowBaseEntity {
/** 创建人 */
private String creUserId;
/** 创建人名称 */
private String creUserName;
/** 创建部门id */
private String creDeptId;
/** 创建部门名称 */
private String creDeptName;
/** 创建日志 */
private Date creDate;
/** 流程标识 */
private String subflag;
/** 流程类型 */
private String flowType;
public void setCreUserId(String creUserId){
this.creUserId = creUserId;
}
public String getCreUserId(){
return creUserId;
}
public void setCreUserName(String creUserName){
this.creUserName = creUserName;
}
public String getCreUserName(){
return creUserName;
}
public void setCreDeptId(String creDeptId){
this.creDeptId = creDeptId;
}
public String getCreDeptId(){
return creDeptId;
}
public void setCreDeptName(String creDeptName){
this.creDeptName = creDeptName;
}
public String getCreDeptName(){
return creDeptName;
}
public void setCreDate(Date creDate){
this.creDate = creDate;
}
public Date getCreDate(){
return creDate;
}
public void setSubflag(String subflag){
this.subflag = subflag;
}
public String getSubflag(){
return subflag;
}
public String getFlowType() {
return flowType;
}
public void setFlowType(String flowType) {
this.flowType = flowType;
}
}
package com.sinobase.framework.web.domain;
import java.io.Serializable;
/**
* Ztree树结构实体类
*/
public class Ztree implements Serializable {
private static final long serialVersionUID = 1L;
/** 节点ID */
private Long id;
/** 节点父ID */
private Long pId;
/** 节点名称 */
private String name;
/** 节点标题 */
private String title;
/** 是否勾选 */
private boolean checked = false;
/** 是否展开 */
private boolean open = false;
/** 是否能勾选 */
private boolean nocheck = false;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getpId() {
return pId;
}
public void setpId(Long pId) {
this.pId = pId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public boolean isOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
public boolean isNocheck() {
return nocheck;
}
public void setNocheck(boolean nocheck) {
this.nocheck = nocheck;
}
}
package com.sinobase.framework.web.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>{
/**
* 分页列表
* @param queryWrapper
* @return
*/
public List<T> selectPageList(Wrapper<T> queryWrapper);
}
package com.sinobase.framework.web.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
/**
* 接口返回数据
*
* @author Mikasa33
*/
@ApiModel
public class ApiData<T> implements Serializable
{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "状态码")
private Integer code;
@ApiModelProperty(value = "返回信息")
private String msg;
@ApiModelProperty("返回数据")
private T data; // 数据
public ApiData(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public static<T> ApiData info(Integer code, String msg, T data) {
ApiData api = new ApiData(code, msg);
api.setData(data);
return api;
}
public static ApiData info(Integer code, String msg) {
ApiData api = new ApiData(code, msg);
return api;
}
public static<T> ApiData success(T data) {
ApiData api = new ApiData(0, "success");
api.setData(data);
return api;
}
public static<T> ApiData fail(T data) {
ApiData api = new ApiData(500, "error");
api.setData(data);
return api;
}
public static ApiData success() {
ApiData api = new ApiData(200, "success");
return api;
}
public static ApiData fail() {
ApiData api = new ApiData(500, "error");
return api;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.sinobase.framework.web.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* 接口返回列表数据
*
* @author Mikasa33
*/
@ApiModel
public class PageData<T> implements Serializable
{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "总页数")
private long total;
@ApiModelProperty("返回数据")
private T list;
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public T getList() {
return list;
}
public void setList(T list) {
this.list = list;
}
}
package com.sinobase.framework.web.page;
import com.sinobase.common.utils.StringUtils;
/**
* 分页数据
*
* @author sinobase
*/
public class PageDomain
{
/** 当前记录起始索引 */
private Integer pageNum;
/** 每页显示记录数 */
private Integer pageSize;
/** 排序列 */
private String orderByColumn;
/** 排序的方向 "desc" 或者 "asc". */
private String isAsc;
public String getOrderBy()
{
if (StringUtils.isEmpty(orderByColumn))
{
return "";
}
return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
}
public Integer getPageNum()
{
return pageNum;
}
public void setPageNum(Integer pageNum)
{
this.pageNum = pageNum;
}
public Integer getPageSize()
{
return pageSize;
}
public void setPageSize(Integer pageSize)
{
this.pageSize = pageSize;
}
public String getOrderByColumn()
{
return orderByColumn;
}
public void setOrderByColumn(String orderByColumn)
{
this.orderByColumn = orderByColumn;
}
public String getIsAsc()
{
return isAsc;
}
public void setIsAsc(String isAsc)
{
this.isAsc = isAsc;
}
}
package com.sinobase.framework.web.page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 表格分页数据对象
*
* @author sinobase
*/
public class TableDataInfo implements Serializable
{
private static final long serialVersionUID = 1L;
/** 总记录数 */
private long total;
/** 列表数据 */
private List<?> rows;
/** 消息状态码 */
private int code;
/**
* 表格数据对象
*/
public TableDataInfo()
{
}
/**
* 分页
*
* @param list 列表数据
* @param total 总记录数
*/
public TableDataInfo(List<?> list, int total)
{
this.rows = list;
this.total = total;
}
public long getTotal()
{
return total;
}
public void setTotal(long total)
{
this.total = total;
}
public List<?> getRows()
{
return rows;
}
public void setRows(List<?> rows)
{
this.rows = rows;
}
public int getCode()
{
return code;
}
public void setCode(int code)
{
this.code = code;
}
public TableDataInfo(IPage<?> page){
this.total = 0;
this.rows = new ArrayList<>();
this.code = 0;
if(page!=null){
this.total = page.getTotal();
this.rows = page.getRecords();
}
}
}
package com.sinobase.framework.web.page;
import com.sinobase.common.utils.ServletUtils;
import com.sinobase.common.constant.Constants;
/**
* 表格数据处理
*
* @author sinobase
*/
public class TableSupport {
/**
* 封装分页对象
*/
public static PageDomain getPageDomain() {
PageDomain pageDomain = new PageDomain();
pageDomain.setPageNum(ServletUtils.getParameterToInt(Constants.PAGE_NUM));
pageDomain.setPageSize(ServletUtils.getParameterToInt(Constants.PAGE_SIZE));
pageDomain.setOrderByColumn(ServletUtils.getParameter(Constants.ORDER_BY_COLUMN));
pageDomain.setIsAsc(ServletUtils.getParameter(Constants.IS_ASC));
return pageDomain;
}
public static PageDomain buildPageRequest() {
return getPageDomain();
}
}
package com.sinobase.project.system.dept.constant;
public class DeptConstants {
/**
* 系统信息状态:集团公司id
*/
public static String GTOUP_ID = "162812";
/**
* 系统信息状态:集团公司history_id
*/
public static String GTOUP_HISTORY_ID = "001";
}
package com.sinobase.project.system.dept.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableField;
import com.sinobase.framework.web.domain.BaseEntity;
/**
* 部门表 sys_dept
*
* @author sinobase
*/
public class Dept extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 职能部门
*/
public static String DEPT_UNIT_TYPE_01 = "01"; //集团
/**
* 职能部门
*/
public static String DEPT_UNIT_TYPE_02 = "02"; //职能部门
/**
* 二级公司
*/
public static String DEPT_UNIT_TYPE_03 = "03"; //二级公司
/**
* 三级公司
*/
public static String DEPT_UNIT_TYPE_04 = "04"; //三级公司
/**
* 四级公司
*/
public static String DEPT_UNIT_TYPE_05 = "05"; //四级公司
/**
* 公司类型字符串Company
*/
public static String DEPT_UNIT_TYPE_COMPANY = "03,04,05"; //公司类型字符串
/** 部门ID */
private String deptId;
/** 父部门ID */
private String parentId;
/** 祖级列表 */
private String ancestors;
/** 部门名称 */
private String deptName;
/** 显示顺序 */
private Long orderNum;
/** 负责人 */
private String leader;
/** 联系电话 */
private String phone;
/** 邮箱 */
private String email;
/** 部门状态:1正常,0停用 */
private String status;
/** 删除标志(0代表存在 2代表删除) */
private String delFlag;
/** 父部门名称 */
private String parentName;
/**
* fromUnit 类别(公司或部门)
* @return
*/
private String fromUnit;
/**
* 部门编号
* @return
*/
private String deptNumber;
/** 备注 */
private String note;
/**
* 国泰历史数据ID
* @return
*/
private String historyId;
/**
* 历史公司ID
*/
private String historyCompanyId;
/**
* 用户所在老OA大部门id,主要指老OA集团的职能部门
*/
private String historyCompanyIdDept;
/** 国泰历史数据编码 */
private String historyCode;
/** 单元类型 */
private String unitType;
/** 是否为领导部门 */
private String isZhc;
/**
* 所在公司id
*/
private String companyId;
/**
* 所在公司名称
*/
private String companyName;
/**
* 公司简称
*/
@TableField(exist = false)
private String companyShortName;
/**
* 主数据部门编码
*/
private String deptcode;
/**
* 主数据公司编码
*/
private String companycode;
/**
* 主数据父部门编码
*/
private String supercode;
/**
* 部门树的显示状态,0任何树都显示,其他表示根据实际情况判断是否在树结构上显示
*/
private String isShow;
/**
* 单位属性:全资,控股等
*/
private String deptProperty;
/**
* 部门简称,树结构一般显示简称
*/
private String deptShort;
/**
* 部门层级
*/
private String deptLevel;
/**
* 用户所在大部门id,主要指集团的职能部门
*/
private String companyIdDept;
/**
*用户所在大部门名称
*/
private String companyNameDept;
/**
*用户所在大部门简称
*/
@TableField(exist = false)
private String companyShortNameDept;
private String hasChildren;
/**
* 子部门集合
*/
@TableField(exist = false)
private String childDeptIds;
public String getHasChildren() {
return hasChildren;
}
public void setHasChildren(String hasChildren) {
this.hasChildren = hasChildren;
}
public String getDeptcode() {
return deptcode;
}
public void setDeptcode(String deptcode) {
this.deptcode = deptcode;
}
public String getCompanycode() {
return companycode;
}
public void setCompanycode(String companycode) {
this.companycode = companycode;
}
public String getSupercode() {
return supercode;
}
public void setSupercode(String supercode) {
this.supercode = supercode;
}
public String getIsShow() {
return isShow;
}
public void setIsShow(String isShow) {
this.isShow = isShow;
}
public String getDeptProperty() {
return deptProperty;
}
public void setDeptProperty(String deptProperty) {
this.deptProperty = deptProperty;
}
public String getDeptShort() {
return deptShort;
}
public void setDeptShort(String deptShort) {
this.deptShort = deptShort;
}
public String getDeptLevel() {
return deptLevel;
}
public void setDeptLevel(String deptLevel) {
this.deptLevel = deptLevel;
}
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getIsZhc() {
return isZhc;
}
public void setIsZhc(String isZhc) {
this.isZhc = isZhc;
}
public String getDeptId() {
return deptId;
}
public void setDeptId(String deptId) {
this.deptId = deptId;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getAncestors() {
return ancestors;
}
public void setAncestors(String ancestors) {
this.ancestors = ancestors;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public Long getOrderNum() {
return orderNum;
}
public void setOrderNum(Long orderNum) {
this.orderNum = orderNum;
}
public String getLeader() {
return leader;
}
public void setLeader(String leader) {
this.leader = leader;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDelFlag() {
return delFlag;
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getFromUnit() {
return fromUnit;
}
public void setFromUnit(String fromUnit) {
this.fromUnit = fromUnit;
}
public String getDeptNumber() {
return deptNumber;
}
public void setDeptNumber(String deptNumber) {
this.deptNumber = deptNumber;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getHistoryId() {
return historyId;
}
public void setHistoryId(String historyId) {
this.historyId = historyId;
}
public String getHistoryCompanyId() {
return historyCompanyId;
}
public void setHistoryCompanyId(String historyCompanyId) {
this.historyCompanyId = historyCompanyId;
}
public String getHistoryCompanyIdDept() {
return historyCompanyIdDept;
}
public void setHistoryCompanyIdDept(String historyCompanyIdDept) {
this.historyCompanyIdDept = historyCompanyIdDept;
}
public String getHistoryCode() {
return historyCode;
}
public void setHistoryCode(String historyCode) {
this.historyCode = historyCode;
}
public String getUnitType() {
return unitType;
}
public void setUnitType(String unitType) {
this.unitType = unitType;
}
public String getCompanyIdDept() {
return companyIdDept;
}
public void setCompanyIdDept(String companyIdDept) {
this.companyIdDept = companyIdDept;
}
public String getCompanyNameDept() {
return companyNameDept;
}
public void setCompanyNameDept(String companyNameDept) {
this.companyNameDept = companyNameDept;
}
public String getCompanyShortName() {
return companyShortName;
}
public void setCompanyShortName(String companyShortName) {
this.companyShortName = companyShortName;
}
public String getCompanyShortNameDept() {
return companyShortNameDept;
}
public void setCompanyShortNameDept(String companyShortNameDept) {
this.companyShortNameDept = companyShortNameDept;
}
public String getChildDeptIds() {
return childDeptIds;
}
public void setChildDeptIds(String childDeptIds) {
this.childDeptIds = childDeptIds;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("deptId", getDeptId()).append("parentId", getParentId()).append("ancestors", getAncestors())
.append("deptName", getDeptName()).append("orderNum", getOrderNum()).append("leader", getLeader()).append("phone", getPhone()).append("email", getEmail()).append("status", getStatus())
.append("delFlag", getDelFlag()).append("createBy", getCreateBy()).append("createTime", getCreateTime()).append("updateBy", getUpdateBy()).append("updateTime", getUpdateTime())
.append("fromUnit", getFromUnit()).append("note", getNote()).append("historyId", getHistoryId()).append("deptNumber", getDeptNumber()).append("historyCode", getHistoryCode())
.append("deptcode", getDeptcode()).append("companyId", getCompanyId()).append("companycode", getCompanycode()).append("supercode", getSupercode()).append("isShow", getIsShow())
.append("deptProperty", getDeptProperty()).append("deptShort", getDeptShort()).append("deptLevel", getDeptLevel()).append("companyName", getCompanyName())
.append("unitType", getUnitType()).append("isZhc", getIsZhc()).toString();
}
}
package com.sinobase.project.system.dept.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.sinobase.framework.web.domain.BaseEntity;
/**
* 部门权限表 sys_dept_permission
*
* @author LouBin
* @date 2019-07-29
*/
public class DeptPermission {
private static final long serialVersionUID = 1L;
/** 主键 */
private String id;
/** 属性 */
private String property;
/** 部门级别 */
private String deptlevel;
/** 是否显示 */
private String isshow;
/** 部门权限 */
private String deptPermission;
/** 流程权限 */
private String flowPermission;
/**创建时间**/
private String createTime;
public void setId(String id){
this.id = id;
}
public String getId(){
return id;
}
public void setProperty(String property){
this.property = property;
}
public String getProperty(){
return property;
}
public void setDeptlevel(String deptlevel){
this.deptlevel = deptlevel;
}
public String getDeptlevel(){
return deptlevel;
}
public void setIsshow(String isshow){
this.isshow = isshow;
}
public String getIsshow(){
return isshow;
}
public void setDeptPermission(String deptPermission){
this.deptPermission = deptPermission;
}
public String getDeptPermission(){
return deptPermission;
}
public void setFlowPermission(String flowPermission){
this.flowPermission = flowPermission;
}
public String getFlowPermission(){
return flowPermission;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("property", getProperty())
.append("deptlevel", getDeptlevel())
.append("isshow", getIsshow())
.append("deptPermission", getDeptPermission())
.append("flowPermission", getFlowPermission())
.append("createTime", getCreateTime())
.toString();
}
}
package com.sinobase.project.system.dept.mapper;
import com.sinobase.datasource.aspectj.lang.annotation.DataSource;
import com.sinobase.datasource.aspectj.lang.enums.DataSourceType;
import com.sinobase.project.system.dept.domain.Dept;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 部门管理 数据层
*
* @author sinobase
*/
public interface DeptMapper {
/**
* 查询部门人数
* @param dept 部门信息
* @return 结果
*/
public int selectDeptCount(Dept dept);
/**
* 查询部门是否存在用户
* @param deptId 部门ID
* @return 结果
*/
public int checkDeptExistUser(String deptId);
/**
* 查询部门管理数据
* @param dept 部门信息
* @return 部门信息集合
*/
public List<Dept> selectDeptList(Dept dept);
/**
* 数据列表 ==》后台管理
*/
public List<Dept> listForManage(Dept dept);
/**
* 删除部门管理信息
* @param deptId 部门ID
* @return 结果
*/
public int deleteDeptById(String deptId);
/**
* 新增部门信息
* @param dept 部门信息
* @return 结果
*/
public int insertDept(Dept dept);
/**
* 部门排序保存
* @param deptIds 部门id串
* @return
*/
public int sortSave(String[] deptIds);
/**
* 修改部门信息
* @param dept 部门信息
* @return 结果
*/
public int updateDept(Dept dept);
/**
* 修改子元素关系
* @param depts 子元素
* @return 结果
*/
public int updateDeptChildren(@Param("depts") List<Dept> depts);
/**
* 根据部门ID查询信息
* @param deptId 部门ID
* @return 部门信息
*/
public Dept selectDeptById(String deptId);
/**
* 校验部门名称是否唯一
*
* @param deptName 部门名称
* @param parentId 父部门ID
* @return 结果
*/
public Dept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") String parentId);
/**
* 根据角色ID查询部门
*
* @param roleId 角色ID
* @return 部门列表
*/
public List<String> selectRoleDeptTree(String roleId);
/**
* 修改所在部门的父级部门状态
*
* @param dept 部门
*/
public void updateDeptStatus(Dept dept);
/**
* 根据部门对象集合添加部门
* @param deptList
*/
public Integer insertDeptList(List<Dept> deptList);
/**
* 获取本地数据库所有部门的id
* @return
*/
public List<String> selectAllDeptId();
/**
* 查询所有部门信息
* @return
*/
public List<Dept> selectAllDept();
/**
* 根据部门id获取子部门
* @param deptId
* @return
*/
public List<Dept> selectDeptListByDeptId(@Param(value = "deptId") String deptId);
/**
* 根据部门id获取其所有子孙部门
* @param deptId
* @return
*/
public List<Dept> selectDeptListsByDeptId(@Param(value = "deptId")String deptId);
/**
* 根据部门id和权限获取部门信息
* @param auth
* @return
*/
public List<Dept> selectDeptListByDeptIdAndAuthority(@Param(value = "auth")Map<String,String> auth);
/**
* 通过sql插入信息
* @param sql
* @return
*/
public int insertDeptBySql(@Param(value = "sql") String sql);
/**
* 通过sql查询信息
* @param sql
* @return
*/
public Map<String,String> selectBySql(@Param(value = "sql") String sql);
/**
* 通过sql查询信息,获取多条数据
* @param sql
* @return
*/
public List<Map<String,String>> selectAllBySql(@Param(value = "sql") String sql);
public List<Dept> selectDeptListByPID(String parentID);
/**
* 根据部门id获取顶级部门(公司)信息
* @param deptId
* @return
*/
public Dept getCompanyId(String deptId);
/**
* 根据部门ID数组获取部门列表
* @param ids
* @return
*/
List<Dept> listDeptByDeptId(String [] ids);
/**
* 根据用户ID获取部门信息
* @param userId 用户id
* @return
*/
public List<Dept> getDeptsByUserId(String userId);
/**
* 获取当前表最大ID值
* @return
*/
public int selectMaxId();
/**
* 过去符合条件的当前部门的所有子部门
*
* @param auth
* @return
*/
public List<Map<String,Object>> getAllChildrenDept(@Param(value = "auth")Map<String,String> auth);
/**
* 根据祖级列表模糊查询部门
*
*/
public List<Dept> getDeptLikeAncestors(@Param(value = "ancestors")String ancestors);
/**
* 根据部门名称获取部门列表
* @param deptName
* @return
*/
List<Dept> listDeptForDeptName(@Param(value = "deptName") String deptName);
/**
* 获取二级子公司(from_unit = 0)
* @param ancestors
* @return
*/
Dept getDeptByAncestors(@Param("ancestors") String ancestors);
/**
* 根据类别(0:子公司 1:部门)获取dept信息
* @param fromUnit
* @return
*/
List<Dept> getDeptByFromUnit(@Param("fromUnit") String fromUnit);
/**
* 获取老OA的部门信息
* @param historyId
* @return
*/
@DataSource(DataSourceType.ORACLE)
Map<String,String> getOldDeptInfo(@Param("historyId") String historyId);
/**
* 根据部门Id获取部门名称
* @param deptIds
* @return
*/
public List<String> getDeptNamesByDeptIds(String[] deptIds);
/**
* 据类别(0:子公司 1:部门)获取dept信息(返回内容包含子部门数据)
* @param fromUnit
* @return
*/
public List<Dept> getDeptByFromUnit_childDpetIds(@Param("fromUnit")String fromUnit);
}
package com.sinobase.project.system.dept.service;
import java.util.List;
import com.sinobase.project.system.dept.domain.DeptPermission;
/**
* 部门权限 服务层
*
* @author LouBin
* @date 2019-07-29
*/
public interface IDeptPermissionService {
/**
* 查询部门权限信息
* @param id 部门权限ID
* @return 部门权限信息
*/
public DeptPermission selectDeptPermissionById(String id);
/**
* 查询部门权限列表
* @param deptPermission 部门权限信息
* @return 部门权限集合
*/
public List<DeptPermission> selectDeptPermissionList(DeptPermission deptPermission);
/**
* 新增部门权限
* @param deptPermission 部门权限信息
* @return 结果
*/
public int insertDeptPermission(DeptPermission deptPermission);
/**
* 修改部门权限
* @param deptPermission 部门权限信息
* @return 结果
*/
public int updateDeptPermission(DeptPermission deptPermission);
/**
* 删除部门权限信息
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteDeptPermissionByIds(String ids);
}
package com.sinobase.project.system.dept.service;
import com.alibaba.fastjson.JSONObject;
import com.sinobase.project.system.dept.domain.Dept;
import com.sinobase.project.system.role.domain.Role;
import java.util.List;
import java.util.Map;
/**
* 部门管理 服务层
*
* @author sinobase
*/
public interface IDeptService {
/**
* 查询部门管理数据
* @param dept 部门信息
* @return 部门信息集合
*/
List<Dept> selectDeptList(Dept dept);
/**
* 数据列表 ==》后台管理
*/
List<Map<String, Object>> treeForManage();
/**
* 根据父级ID获取下一级所有部门信息数据
* @param parentID 父级ID
* @return
*/
List<Dept> selectDeptList(String parentID);
/**
* 查询部门管理树
*
* @param dept 部门信息
* @return 所有部门信息
*/
List<Map<String, Object>> selectDeptTree(Dept dept);
/**
* 根据角色ID查询菜单
*
* @param role 角色对象
* @return 菜单列表
*/
List<Map<String, Object>> roleDeptTreeData(Role role);
/**
* 查询部门人数
*
* @param parentId 父部门ID
* @return 结果
*/
int selectDeptCount(String parentId);
/**
* 查询部门是否存在用户
*
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
boolean checkDeptExistUser(String deptId);
/**
* 删除部门管理信息
*
* @param deptId 部门ID
* @return 结果
*/
int deleteDeptById(String deptId);
/**
* 新增保存部门信息
*
* @param dept 部门信息
* @return 结果
*/
int insertDept(Dept dept);
/**
* 修改保存部门信息
*
* @param dept 部门信息
* @return 结果
*/
int updateDept(Dept dept);
/**
* 根据部门ID查询信息
*
* @param deptId 部门ID
* @return 部门信息
*/
Dept selectDeptById(String deptId);
/**
* 根据部门ID查询信息,不包含公司信息
*
* @param deptId 部门ID
* @return 部门信息
*/
Dept selectDeptByIdNoCompany(String deptId);
/**
* 校验部门名称是否唯一
*
* @param dept 部门信息
* @return 结果
*/
String checkDeptNameUnique(Dept dept);
/**
* 排序保存
* @deptIds 部门id串
* @return
*/
int sortSave(String[] deptIds);
/**
* 根据用户ID获取部门信息(已经将部门所在公司装入)
* @param userId 用户id
* @return
*/
List<Dept> getDeptsByUserId(String userId);
/**
* 根据部门父级id获取部门所在的公司
* @param parentId
* @return
*/
Dept getCompanyByParentId(String parentId);
/****************************** 添加的代码 *******************************/
/**
* 根据部门对象集合添加部门
*/
Integer insertDeptList(List<Dept> deptList);
/**
* 获取本地数据库所有部门的id
* @return
*/
List<String> selectAllDeptId();
/**
* 查询所有部门信息
* @return
*/
List<Dept> selectAlldept();
/**
* 根据部门id获取其所有子孙部门
* @param rootId
* @return
*/
List<Dept> selectDeptListByDeptId(String rootId);
/**
* 根据部门id获取其所有子孙部门
* @param deptId
* @return
*/
List<Dept> selectDeptListsByDeptId(String deptId);
/**
* 获取部门树信息
* @param rootId 根节点部门 id
* @param deptId 部门 id
* @authority 部门权限信息
* @return
*/
List getDeptTree(String rootId, String deptId, JSONObject authority);
/**
* 获取部门树信息
* @param deptId
* @return
*/
List<Map<String, Object>> getDeptTree(String deptId);
/**
* 通过sql插入部门信息
* @param sql
* @return
*/
int insertDeptBySql(String sql);
/**
* 得到当前用户所在的公司或大部门信息
* @param deptId
* @param unitType
* @param deptflag
* @return
*/
Map<String, String> getCompanyInfoByDeptId(String deptId, String unitType, String deptflag);
/**
* 根据部门ID数组获取部门列表
* @param ids
* @return
*/
List<Dept> listDeptByDeptId(String [] ids);
/**
*
* 查询出当前部门的所有子部门
* @param deptId
* @param json
* @return
*/
List<Map<String, Object>> getDeptSearch(String deptId, String deptname,JSONObject json);
/**
* 根据祖级列表模糊查询部门
*
*/
List<Dept> getDeptLikeAncestors(String ancestors);
/**
* 根据部门名称获取部门列表
* @param deptName
* @return
*/
List<Dept> listDeptForDeptName(String deptName);
/**
* 获取二级子公司(from_unit = 0)
* @param ancestors
* @return
*/
Dept getDeptByAncestors(String ancestors);
/**
* 根据类别(0:子公司 1:部门)获取dept信息
* @param fromUnit
* @return
*/
public List<Dept> getDeptByFromUnit(String fromUnit);
/**
* 据类别(0:子公司 1:部门)获取dept信息(返回内容包含子部门数据)
* @param fromUnit
* @return
*/
public List<Dept> getDeptByFromUnit_childDpetIds(String fromUnit);
public List<Map<String, String>> getDeptIdAndParentId();
public String getHistoryCompanyId(String historyId);
/**
* 获取老OA部门信息
* @param historyId
* @return
*/
public Map<String,String> getHistoryDeptInfo(String historyId);
/**
* 根据部门Id获取部门名称
* @param deptIds
* @return
*/
public List<String> getDeptNamesByDeptIds(String[] deptIds);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment