getAllValueMap();
34 | }
35 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/enumeration/support/TopEnumType.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.enumeration.support;
2 |
3 | import java.io.Serializable;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 | import java.sql.PreparedStatement;
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.sql.Types;
10 | import java.util.Properties;
11 |
12 | import org.hibernate.HibernateException;
13 | import org.hibernate.engine.spi.SessionImplementor;
14 | import org.hibernate.usertype.ParameterizedType;
15 | import org.hibernate.usertype.UserType;
16 | import org.springframework.util.ObjectUtils;
17 |
18 | /**
19 | * 用户持久化枚举类型的用户自定义hibernate映射类型
20 | *
21 | * 使用此类型来进行映射的枚举类,必须实现{@link com.hitler.common.model.enumeration.support.PersistEnum} 接口
22 | *
23 | * @author Kylin
24 | * 2015-7-23 下午4:12:28
25 | */
26 | public class TopEnumType implements UserType, ParameterizedType {
27 |
28 | private Method returnEnum;
29 |
30 | private Method getPersistedValue;
31 |
32 | private Class> enumClass;
33 |
34 | private Object enumObject;
35 |
36 | @SuppressWarnings("unchecked")
37 | @Override
38 | public void setParameterValues(Properties parameters) {
39 | if (parameters != null) {
40 | try {
41 | enumClass = (Class>) Class.forName(parameters.get("enumClass").toString());
42 | enumObject = enumClass.getEnumConstants()[0];
43 | getPersistedValue = enumClass.getMethod("getPersistedValue");
44 | returnEnum = enumClass.getMethod("returnEnum",
45 | new Class[] { String.class });
46 | } catch (SecurityException e) {
47 | e.printStackTrace();
48 | } catch (NoSuchMethodException e) {
49 | e.printStackTrace();
50 | } catch (ClassNotFoundException e) {
51 | e.printStackTrace();
52 | }
53 | }
54 | }
55 |
56 | @Override
57 | public int[] sqlTypes() {
58 | return new int[] { Types.VARCHAR };
59 | }
60 |
61 | @SuppressWarnings("rawtypes")
62 | @Override
63 | public Class returnedClass() {
64 | return enumClass;
65 | }
66 |
67 | @Override
68 | public boolean equals(Object x, Object y) throws HibernateException {
69 | return ObjectUtils.nullSafeEquals(x, y);
70 | }
71 |
72 | @Override
73 | public int hashCode(Object x) throws HibernateException {
74 | return x.hashCode();
75 | }
76 |
77 | @Override
78 | public Object nullSafeGet(ResultSet rs, String[] names,
79 | SessionImplementor session, Object owner)
80 | throws HibernateException, SQLException {
81 | String value = rs.getString(names[0]);
82 | Object returnVal = null;
83 |
84 | if (value == null)
85 | return null;
86 | else {
87 | try {
88 | returnVal = returnEnum
89 | .invoke(enumObject, new Object[] { value });
90 | } catch (IllegalArgumentException e) {
91 | e.printStackTrace();
92 | } catch (IllegalAccessException e) {
93 | e.printStackTrace();
94 | } catch (InvocationTargetException e) {
95 | e.printStackTrace();
96 | }
97 | }
98 | return returnVal;
99 | }
100 |
101 | @Override
102 | public void nullSafeSet(PreparedStatement st, Object value, int index,
103 | SessionImplementor session) throws HibernateException, SQLException {
104 | String prepStmtVal = null;
105 |
106 | if (value == null) {
107 | st.setObject(index, null);
108 | } else {
109 | try {
110 | prepStmtVal = getPersistedValue.invoke(value).toString();
111 | st.setString(index, prepStmtVal);
112 | } catch (IllegalArgumentException e) {
113 | e.printStackTrace();
114 | } catch (IllegalAccessException e) {
115 | e.printStackTrace();
116 | } catch (InvocationTargetException e) {
117 | e.printStackTrace();
118 | }
119 | }
120 | }
121 |
122 | @Override
123 | public Object deepCopy(Object value) throws HibernateException {
124 | return value;
125 | }
126 |
127 | @Override
128 | public boolean isMutable() {
129 | return false;
130 | }
131 |
132 | @Override
133 | public Serializable disassemble(Object value) throws HibernateException {
134 | Object deepCopy = deepCopy(value);
135 |
136 | if (!(deepCopy instanceof Serializable))
137 | return (Serializable) deepCopy;
138 |
139 | return null;
140 | }
141 |
142 | @Override
143 | public Object assemble(Serializable cached, Object owner)
144 | throws HibernateException {
145 | return deepCopy(cached);
146 | }
147 |
148 | @Override
149 | public Object replace(Object original, Object target, Object owner)
150 | throws HibernateException {
151 | return deepCopy(original);
152 | }
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/json/serialize/CurrencySerializer.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.json.serialize;
2 |
3 | import java.io.IOException;
4 | import java.text.DecimalFormat;
5 |
6 | import com.fasterxml.jackson.core.JsonGenerator;
7 | import com.fasterxml.jackson.core.JsonProcessingException;
8 | import com.fasterxml.jackson.databind.JsonSerializer;
9 | import com.fasterxml.jackson.databind.SerializerProvider;
10 |
11 | public class CurrencySerializer extends JsonSerializer {
12 |
13 | private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.00");
14 |
15 | @Override
16 | public void serialize(Double value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
17 | jgen.writeString(DECIMAL_FORMAT.format(value));
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/listener/CheckingEntityListener.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.listener;
2 |
3 | import java.lang.reflect.Field;
4 | import java.util.ArrayList;
5 | import java.util.Date;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.concurrent.ConcurrentHashMap;
9 |
10 | import javax.persistence.PostLoad;
11 | import javax.persistence.PrePersist;
12 | import javax.persistence.PreUpdate;
13 |
14 | import org.apache.commons.logging.Log;
15 | import org.apache.commons.logging.LogFactory;
16 | import org.springframework.data.util.ReflectionUtils.AnnotationFieldFilter;
17 | import org.springframework.util.ReflectionUtils;
18 |
19 | import com.hitler.common.model.annotation.Checkable;
20 | import com.hitler.common.util.MD5Utils;
21 |
22 | public class CheckingEntityListener {
23 |
24 | private static final Log LOGGER = LogFactory.getLog(CheckingEntityListener.class);
25 |
26 | private static final String MD5_KEY = "19880704";
27 |
28 | @PrePersist
29 | @PreUpdate
30 | public void encode(Object target) {
31 | AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
32 | if (metadata.isCheckable()) {
33 | StringBuilder sb = new StringBuilder();
34 | for (Field field : metadata.getCheckedFields()) {
35 | ReflectionUtils.makeAccessible(field);
36 | Object value = ReflectionUtils.getField(field, target);
37 | if (value instanceof Date) {
38 | throw new RuntimeException("不支持时间类型字段加密!");
39 | }
40 | sb.append(value).append(" - ");
41 | }
42 | sb.append(MD5_KEY);
43 | LOGGER.debug("加密数据:" + sb);
44 | String hex = MD5Utils.encode(sb.toString());
45 | Field checksumField = metadata.getCheckableField();
46 | ReflectionUtils.makeAccessible(checksumField);
47 | ReflectionUtils.setField(checksumField, target, hex);
48 | }
49 | }
50 |
51 | @PostLoad
52 | public void checking(Object target) {
53 | AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
54 | if (metadata.isCheckable()) {
55 | StringBuilder sb = new StringBuilder();
56 | for (Field field : metadata.getCheckedFields()) {
57 | ReflectionUtils.makeAccessible(field);
58 | Object value = ReflectionUtils.getField(field, target);
59 | if (value instanceof Date) {
60 | throw new RuntimeException("不支持时间类型字段解密!");
61 | }
62 | sb.append(value).append(" - ");
63 | }
64 | sb.append(MD5_KEY);
65 | LOGGER.debug("验证数据:" + sb);
66 | String hex = MD5Utils.encode(sb.toString());
67 | Field checksumField = metadata.getCheckableField();
68 | ReflectionUtils.makeAccessible(checksumField);
69 | String checksum = (String) ReflectionUtils.getField(checksumField, target);
70 | if (!checksum.equals(hex)) {
71 | //throw new RuntimeException("数据验证失败!");
72 | }
73 | }
74 | }
75 |
76 | }
77 |
78 | class AnnotationCheckingMetadata {
79 |
80 | private static final Map, AnnotationCheckingMetadata> METADATA_CACHE = new ConcurrentHashMap, AnnotationCheckingMetadata>();
81 |
82 | private static final AnnotationFieldFilter CHECKABLE_FILTER = new AnnotationFieldFilter(Checkable.class);
83 | private static final AnnotationFieldFilter CHECKED_FILTER = new AnnotationFieldFilter(Checkable.class);
84 |
85 | private Field checkableField;
86 | private List checkedFields = new ArrayList();
87 |
88 | public AnnotationCheckingMetadata(Class> type) {
89 | while (type != Object.class) {
90 | for (Field field : type.getDeclaredFields()) {
91 | if (CHECKABLE_FILTER.matches(field)) {
92 | this.checkableField = field;
93 | } else if (CHECKED_FILTER.matches(field)) {
94 | this.checkedFields.add(field);
95 | }
96 | }
97 | type = type.getSuperclass();
98 | }
99 | }
100 |
101 | public static AnnotationCheckingMetadata getMetadata(Class> type) {
102 |
103 | if (METADATA_CACHE.containsKey(type)) {
104 | return METADATA_CACHE.get(type);
105 | }
106 |
107 | AnnotationCheckingMetadata metadata = new AnnotationCheckingMetadata(type);
108 | METADATA_CACHE.put(type, metadata);
109 | return metadata;
110 | }
111 |
112 | public boolean isCheckable() {
113 | if (checkableField == null || checkedFields.size() == 0) {
114 | return false;
115 | }
116 | return true;
117 | }
118 |
119 | public Field getCheckableField() {
120 | return checkableField;
121 | }
122 |
123 | public List getCheckedFields() {
124 | return checkedFields;
125 | }
126 |
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/menu/NavMenu.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.menu;
2 |
3 | import java.io.Serializable;
4 | import java.util.Collection;
5 |
6 | /**
7 | * 导航栏菜单vo
8 | * @author Kylin
9 | * 2015-10-10 上午9:44:27
10 | */
11 | public class NavMenu implements Serializable {
12 |
13 | private static final long serialVersionUID = 1L;
14 |
15 | private Integer id;
16 | /**
17 | * 显示内容
18 | */
19 | public String text;
20 | /**
21 | * 图标
22 | */
23 | public String icon;
24 | /**
25 | * 子节点
26 | */
27 | public Collection extends Serializable> children;
28 |
29 | public Integer getId() {
30 | return id;
31 | }
32 |
33 | public void setId(Integer id) {
34 | this.id = id;
35 | }
36 |
37 | public String getText() {
38 | return text;
39 | }
40 |
41 | public void setText(String text) {
42 | this.text = text;
43 | }
44 |
45 | public String getIcon() {
46 | return icon;
47 | }
48 |
49 | public void setIcon(String icon) {
50 | this.icon = icon;
51 | }
52 |
53 | public Collection extends Serializable> getChildren() {
54 | return children;
55 | }
56 |
57 | public void setChildren(Collection extends Serializable> children) {
58 | this.children = children;
59 | }
60 |
61 | @Override
62 | public int hashCode() {
63 | final int prime = 31;
64 | int result = 1;
65 | result = prime * result + ((text == null) ? 0 : text.hashCode());
66 | return result;
67 | }
68 |
69 | @Override
70 | public boolean equals(Object obj) {
71 | if (this == obj)
72 | return true;
73 | if (obj == null)
74 | return false;
75 | if (getClass() != obj.getClass())
76 | return false;
77 | NavMenu other = (NavMenu) obj;
78 | if (text == null) {
79 | if (other.text != null)
80 | return false;
81 | } else if (!text.equals(other.text))
82 | return false;
83 | return true;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/security/ShiroUser.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.security;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.apache.commons.lang3.builder.EqualsBuilder;
6 | import org.apache.commons.lang3.builder.HashCodeBuilder;
7 |
8 | /**
9 | * 自定义Authentication对象,使得Subject除了携带用户的登录名外还可以携带更多信息.
10 | *
11 | * @author shujianhui
12 | *
13 | */
14 | public class ShiroUser implements Serializable {
15 | private static final long serialVersionUID = 1L;
16 | public Integer id;
17 | public String username;
18 | public String password;
19 | public String salt;
20 |
21 | public String getPassword() {
22 | return password;
23 | }
24 |
25 | public void setPassword(String password) {
26 | this.password = password;
27 | }
28 |
29 | public String getSalt() {
30 | return salt;
31 | }
32 |
33 | public void setSalt(String salt) {
34 | this.salt = salt;
35 | }
36 |
37 | public ShiroUser(Integer id, String username,String password,String salt) {
38 | this.id = id;
39 | this.username = username;
40 | this.password=password;
41 | this.salt=salt;
42 | }
43 |
44 | /**
45 | * 本函数输出将作为默认的输出.
46 | */
47 | @Override
48 | public String toString() {
49 | return username;
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | return HashCodeBuilder.reflectionHashCode(this, "username");
55 | }
56 |
57 | @Override
58 | public boolean equals(Object obj) {
59 | return EqualsBuilder.reflectionEquals(this, obj, "username");
60 | }
61 |
62 | public Integer getId() {
63 | return id;
64 | }
65 |
66 | public void setId(Integer id) {
67 | this.id = id;
68 | }
69 |
70 | public String getUsername() {
71 | return username;
72 | }
73 |
74 | public void setUsername(String username) {
75 | this.username = username;
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/AuditableEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | import javax.persistence.Column;
7 | import javax.persistence.EntityListeners;
8 | import javax.persistence.MappedSuperclass;
9 | import javax.persistence.PrePersist;
10 | import javax.persistence.Temporal;
11 | import javax.persistence.TemporalType;
12 |
13 | import org.springframework.data.annotation.CreatedDate;
14 | import org.springframework.data.annotation.LastModifiedDate;
15 | import org.springframework.data.jpa.domain.support.AuditingEntityListener;
16 |
17 | import com.hitler.common.model.annotation.Checked;
18 |
19 | @MappedSuperclass
20 | @EntityListeners(AuditingEntityListener.class)
21 | public abstract class AuditableEntity extends PersistableEntity {
22 |
23 | private static final long serialVersionUID = 9150700774816395865L;
24 |
25 | /**
26 | * 创建者
27 | */
28 | @Checked
29 | /*@CreatedBy*/
30 | @Column(name="CREATED_BY", columnDefinition="varchar(16) DEFAULT '' COMMENT '创建者'")
31 | private String createdBy;
32 |
33 | /**
34 | * 创建时间
35 | */
36 | @CreatedDate
37 | @Temporal(TemporalType.TIMESTAMP)
38 | @Column(name="CREATED_DATE", columnDefinition="TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'")
39 | private Date createdDate;
40 |
41 | /**
42 | * 操作者
43 | */
44 | @Checked
45 | /*@LastModifiedBy*/
46 | @Column(name="LAST_MODIFIED_BY", columnDefinition="varchar(16) COMMENT '操作者'")
47 | private String lastModifiedBy;
48 |
49 | /**
50 | * 操作时间
51 | */
52 | @LastModifiedDate
53 | @Temporal(TemporalType.TIMESTAMP)
54 | @Column(name="LAST_MODIFIED_DATE", columnDefinition="TIMESTAMP NULL COMMENT '操作时间'")
55 | private Date lastModifiedDate;
56 |
57 | @PrePersist
58 | public void prePresist() {
59 | this.createdBy = this.lastModifiedBy;
60 | }
61 |
62 | public String getCreatedBy() {
63 | return createdBy;
64 | }
65 |
66 | public void setCreatedBy(String createdBy) {
67 | this.createdBy = createdBy;
68 | }
69 |
70 | public Date getCreatedDate() {
71 | return createdDate;
72 | }
73 |
74 | public void setCreatedDate(Date createdDate) {
75 | this.createdDate = createdDate;
76 | }
77 |
78 | public String getLastModifiedBy() {
79 | return lastModifiedBy;
80 | }
81 |
82 | public void setLastModifiedBy(String lastModifiedBy) {
83 | this.lastModifiedBy = lastModifiedBy;
84 | }
85 |
86 | public Date getLastModifiedDate() {
87 | return lastModifiedDate;
88 | }
89 |
90 | public void setLastModifiedDate(Date lastModifiedDate) {
91 | this.lastModifiedDate = lastModifiedDate;
92 | }
93 |
94 |
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/CheckableEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.MappedSuperclass;
6 |
7 | @MappedSuperclass
8 | //@EntityListeners(CheckingEntityListener.class)
9 | public abstract class CheckableEntity extends AuditableEntity {
10 |
11 | private static final long serialVersionUID = 2469813719494517116L;
12 | }
13 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/CustomPKPersistableEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.Id;
6 | import javax.persistence.MappedSuperclass;
7 |
8 | import org.springframework.data.domain.Persistable;
9 |
10 | /**
11 | * 主键不需要自增长
12 | *
13 | * @author
14 | *
15 | * @param
16 | */
17 | @MappedSuperclass
18 | public abstract class CustomPKPersistableEntity implements Persistable {
19 |
20 |
21 | /**
22 | *
23 | */
24 | private static final long serialVersionUID = 4129264629296054711L;
25 |
26 | @Id
27 | private PK id;
28 |
29 | @Override
30 | public PK getId() {
31 | return id;
32 | }
33 |
34 | public void setId(PK id) {
35 | this.id = id;
36 | }
37 | @Override
38 | public boolean isNew() {
39 | return null == getId();
40 | }
41 |
42 | @Override
43 | public boolean equals(Object obj) {
44 | if (null == obj) {
45 | return false;
46 | }
47 | if (this == obj) {
48 | return true;
49 | }
50 | if (!getClass().equals(obj.getClass())) {
51 | return false;
52 | }
53 | CustomPKPersistableEntity> that = (CustomPKPersistableEntity>) obj;
54 | return null == this.getId() ? false : this.getId().equals(that.getId());
55 | }
56 |
57 | @Override
58 | public int hashCode() {
59 | int hashCode = 17;
60 | hashCode += null == getId() ? 0 : getId().hashCode() * 31;
61 | return hashCode;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/PersistableEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 | import javax.persistence.Id;
8 | import javax.persistence.MappedSuperclass;
9 |
10 | import org.springframework.data.domain.Persistable;
11 |
12 | @MappedSuperclass
13 | public abstract class PersistableEntity implements Persistable {
14 |
15 | private static final long serialVersionUID = 8251232611423298391L;
16 |
17 | @Id
18 | @GeneratedValue(strategy = GenerationType.AUTO)
19 | private PK id;
20 |
21 | public PK getId() {
22 | return id;
23 | }
24 |
25 | public void setId(PK id) {
26 | this.id = id;
27 | }
28 |
29 | public boolean isNew() {
30 | return null == getId();
31 | }
32 |
33 | @Override
34 | public boolean equals(Object obj) {
35 | if (null == obj) {
36 | return false;
37 | }
38 | if (this == obj) {
39 | return true;
40 | }
41 | if (!getClass().equals(obj.getClass())) {
42 | return false;
43 | }
44 | PersistableEntity> that = (PersistableEntity>) obj;
45 | return null == this.getId() ? false : this.getId().equals(that.getId());
46 | }
47 |
48 | @Override
49 | public int hashCode() {
50 | int hashCode = 17;
51 | hashCode += null == getId() ? 0 : getId().hashCode() * 31;
52 | return hashCode;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/UserRelationEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.MappedSuperclass;
7 |
8 | import com.hitler.common.model.annotation.Checked;
9 | import com.hitler.model.User;
10 |
11 | @MappedSuperclass
12 | public abstract class UserRelationEntity extends CheckableEntity {
13 |
14 | private static final long serialVersionUID = 7405522757503732970L;
15 |
16 | /**
17 | * 用户ID
18 | */
19 | @Checked
20 | @Column(name = "USER_ID", columnDefinition="INT COMMENT '用户ID'", nullable = false)
21 | private Integer userId;
22 |
23 | /**
24 | * 用户帐号
25 | */
26 | @Checked
27 | @Column(name = "USER_NAME", columnDefinition="varchar(16) COMMENT '用户帐号'", nullable = false)
28 | private String userName;
29 |
30 | /**
31 | * 上级ID
32 | */
33 | @Checked
34 | @Column(name = "PARENT_ID", columnDefinition="INT COMMENT '上级ID'")
35 | private Integer parentId;
36 |
37 | /**
38 | * 直属上级帐号
39 | */
40 | @Checked
41 | @Column(name = "PARENT_NAME", columnDefinition="varchar(16) COMMENT '直属上级帐号'")
42 | private String parentName;
43 |
44 |
45 | public UserRelationEntity() {}
46 |
47 | public UserRelationEntity(User user) {
48 | this.userId = user.getId();
49 | this.userName = user.getUserName();
50 | this.parentId = user.getParentId();
51 | this.parentName = user.getParentName();
52 | }
53 |
54 | public String getUserName() {
55 | return userName;
56 | }
57 |
58 | public void setUserName(String userName) {
59 | this.userName = userName;
60 | }
61 |
62 | public String getParentName() {
63 | return parentName;
64 | }
65 |
66 | public void setParentName(String parentName) {
67 | this.parentName = parentName;
68 | }
69 |
70 | public Integer getUserId() {
71 | return userId;
72 | }
73 |
74 | public void setUserId(Integer userId) {
75 | this.userId = userId;
76 | }
77 |
78 | public Integer getParentId() {
79 | return parentId;
80 | }
81 |
82 | public void setParentId(Integer parentId) {
83 | this.parentId = parentId;
84 | }
85 |
86 | public User getUser() {
87 | User user = new User();
88 | user.setId(this.getUserId());
89 | user.setUserName(this.getUserName());
90 | user.setParentId(this.getParentId());
91 | user.setParentName(this.getParentName());
92 | return user;
93 | }
94 |
95 | /*********************************
96 | * 枚举
97 | *2015-05-08
98 | ***********************************/
99 | public static enum UserRelationEntity_ {
100 | userId("userId"),
101 | userName("userName"),
102 | parentId("parentId"),
103 | parentName("parentName");
104 |
105 | private final String _name;
106 | UserRelationEntity_(String _name) {
107 | this._name = _name;
108 | }
109 | public String getName() {
110 | return _name;
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/model/support/UserTreeRelationEntity.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.model.support;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.MappedSuperclass;
7 |
8 | import com.hitler.common.model.annotation.Checked;
9 | import com.hitler.common.model.support.PersistableEntity;
10 | import com.hitler.model.User;
11 |
12 | @MappedSuperclass
13 | public abstract class UserTreeRelationEntity extends PersistableEntity {
14 |
15 | private static final long serialVersionUID = 7405522757503732970L;
16 |
17 | /**
18 | * 用户ID
19 | */
20 | @Checked
21 | @Column(name = "USER_ID", columnDefinition="INT COMMENT '用户ID'", nullable = false)
22 | private Integer userId;
23 |
24 | /**
25 | * 用户帐号
26 | */
27 | @Checked
28 | @Column(name = "USER_NAME", columnDefinition="varchar(16) COMMENT '用户帐号'", nullable = false)
29 | private String userName;
30 |
31 | /**
32 | * 上级ID
33 | */
34 | @Checked
35 | @Column(name = "PARENT_ID", columnDefinition="INT COMMENT '上级ID'")
36 | private Integer parentId;
37 |
38 | /**
39 | * 上级帐号
40 | */
41 | @Checked
42 | @Column(name = "PARENT_NAME", columnDefinition="varchar(16) COMMENT '直属上级帐号'")
43 | private String parentName;
44 |
45 | /** 所在层级. */
46 | @Checked
47 | @Column(name = "FLOOR", columnDefinition="TINYINT COMMENT '所在层级'")
48 | private Short floor;
49 |
50 | public UserTreeRelationEntity() {}
51 |
52 | public UserTreeRelationEntity(User user) {
53 | this.userId = user.getId();
54 | this.userName = user.getUserName();
55 | this.parentId = user.getParentId();
56 | this.parentName = user.getParentName();
57 | }
58 | public String getUserName() {
59 | return userName;
60 | }
61 |
62 | public void setUserName(String userName) {
63 | this.userName = userName;
64 | }
65 |
66 | public String getParentName() {
67 | return parentName;
68 | }
69 |
70 | public void setParentName(String parentName) {
71 | this.parentName = parentName;
72 | }
73 |
74 | public Integer getUserId() {
75 | return userId;
76 | }
77 |
78 | public void setUserId(Integer userId) {
79 | this.userId = userId;
80 | }
81 |
82 | public Integer getParentId() {
83 | return parentId;
84 | }
85 |
86 | public void setParentId(Integer parentId) {
87 | this.parentId = parentId;
88 | }
89 |
90 | public Short getFloor() {
91 | return floor;
92 | }
93 |
94 | public void setFloor(Short floor) {
95 | this.floor = floor;
96 | }
97 |
98 | public User getUser() {
99 | User user = new User();
100 | user.setId(this.getUserId());
101 | user.setUserName(this.getUserName());
102 | user.setParentId(this.getParentId());
103 | user.setParentName(this.getParentName());
104 | return user;
105 | }
106 |
107 | /*********************************
108 | * 枚举
109 | *2015-05-08
110 | ***********************************/
111 | public static enum UserTreeRelationEntity_ {
112 | userId("userId"),
113 | userName("userName"),
114 | parentId("parentId"),
115 | parentName("parentName"),
116 | floor("floor");
117 |
118 | private final String _name;
119 | UserTreeRelationEntity_(String _name) {
120 | this._name = _name;
121 | }
122 | public String getName() {
123 | return _name;
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/AggregateExpression.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.util.List;
4 |
5 | import javax.persistence.criteria.CriteriaBuilder;
6 | import javax.persistence.criteria.CriteriaQuery;
7 | import javax.persistence.criteria.Root;
8 | import javax.persistence.criteria.Selection;
9 |
10 |
11 | /**
12 | * @author Lane
13 | *
14 | * 合计条件接口
15 | *
16 | * @param 实体类型
17 | */
18 | public interface AggregateExpression {
19 |
20 | List> buildExpression(Root root, CriteriaQuery> query, CriteriaBuilder builder);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/IPageResults.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.util.Iterator;
4 | import java.util.List;
5 |
6 | /**
7 | * 分页列表接口
8 | *
9 | * @param
10 | */
11 | public interface IPageResults {
12 |
13 | /**
14 | * 总页数
15 | *
16 | * @return
17 | */
18 | int getTotalPages();
19 |
20 | /**
21 | * 是否有下一页
22 | * @return
23 | */
24 | public boolean hasNext();
25 |
26 | /**
27 | * 总记录数
28 | *
29 | * @return
30 | */
31 | long getTotalElements();
32 |
33 | /**
34 | * 当前页数
35 | *
36 | * @return
37 | */
38 | public int getNumber();
39 |
40 | /**
41 | * 是否第一页
42 | *
43 | * @return
44 | */
45 | public boolean isFirst();
46 |
47 | /**
48 | * 是否最后一页
49 | *
50 | * @return
51 | */
52 | public boolean isLast();
53 |
54 | /**
55 | * 返回所有结果
56 | *
57 | * @return
58 | */
59 | public List getContent();
60 |
61 | /**
62 | * 迭代结果列表
63 | *
64 | * @return
65 | */
66 | public Iterator iterator();
67 |
68 | /**
69 | * 返回排序对象
70 | *
71 | * @return
72 | */
73 | public Sorter getSort();
74 | }
75 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/IPageable.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | /**
4 | * 分页接口
5 | *
6 | */
7 | public interface IPageable {
8 |
9 | /**
10 | * 当前页数,0-->
11 | * @return
12 | */
13 | int getPageNumber();
14 | /**
15 | * 每页记录数,默认10
16 | * @return
17 | */
18 | int getPageSize();
19 |
20 | /**
21 | * 返回排序条件
22 | * @return
23 | */
24 | Sorter getSort();
25 |
26 | /**
27 | * 构造下一页
28 | * @return
29 | */
30 | IPageable next();
31 |
32 | /**
33 | * 构造上一页或第一页
34 | * @return
35 | */
36 | IPageable previousOrFirst();
37 |
38 | /**
39 | * 构造第一页
40 | * @return
41 | */
42 | IPageable first();
43 | /**
44 | * 是否有上一页
45 | * @return
46 | */
47 | boolean hasPrevious();
48 | }
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/PageResultsImpl.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.Collections;
6 | import java.util.Iterator;
7 | import java.util.List;
8 |
9 | /**
10 | * 分页列表实现类
11 | *
12 | * @param
13 | */
14 | public class PageResultsImpl implements IPageResults, Serializable {
15 |
16 | private static final long serialVersionUID = 8262911041470573788L;
17 | private final long total;
18 | private List content = new ArrayList();
19 | private IPageable pageable = null;
20 |
21 | public PageResultsImpl(List content, IPageable pageable) {
22 | this.content.addAll(content);
23 | this.pageable = pageable;
24 | this.total = content.size();
25 | }
26 |
27 | public PageResultsImpl(List content, IPageable pageable, long totleSize) {
28 | this.content.addAll(content);
29 | this.pageable = pageable;
30 | this.total = totleSize;
31 | }
32 |
33 | @Override
34 | public int getTotalPages() {
35 | return getSize() == 0 ? 1 : (int) Math.ceil((double) total
36 | / (double) getSize());
37 | }
38 |
39 | @Override
40 | public long getTotalElements() {
41 | return total;
42 | }
43 |
44 | @Override
45 | public int getNumber() {
46 | return pageable == null ? 0 : pageable.getPageNumber();
47 | }
48 |
49 | @Override
50 | public boolean isFirst() {
51 | return !hasPrevious();
52 | }
53 |
54 | @Override
55 | public boolean isLast() {
56 | return !hasNext();
57 | }
58 |
59 | @Override
60 | public boolean hasNext() {
61 | return getNumber() + 1 < getTotalPages();
62 | }
63 |
64 | @Override
65 | public List getContent() {
66 | return Collections.unmodifiableList(content);
67 | }
68 |
69 | @Override
70 | public Iterator iterator() {
71 | return content.iterator();
72 | }
73 |
74 | @Override
75 | public Sorter getSort() {
76 | return pageable == null ? null : pageable.getSort();
77 | }
78 |
79 | private int getSize() {
80 | return pageable == null ? 0 : pageable.getPageSize();
81 | }
82 |
83 | private boolean hasPrevious() {
84 | return getNumber() > 0;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/PageableImpl.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 分页对象,实现分页接口
7 | *
8 | */
9 | public class PageableImpl implements IPageable, Serializable {
10 |
11 | private static final long serialVersionUID = 1232825578694716871L;
12 |
13 | /**
14 | * 当前页数,0-->
15 | */
16 | private final int page;
17 |
18 | /**
19 | * 每页记录数,默认10
20 | */
21 | private final int size;
22 |
23 | private Sorter sort = null;
24 |
25 | public PageableImpl(int page, int size) {
26 | if (page < 0) {
27 | throw new IllegalArgumentException(
28 | "Page index must not be less than zero!");
29 | }
30 | if (size < 1) {
31 | throw new IllegalArgumentException(
32 | "Page size must not be less than one!");
33 | }
34 | this.page = page;
35 | this.size = size;
36 | }
37 |
38 | public PageableImpl(int page, int size, Sorter sort) {
39 | this(page, size);
40 | this.sort = sort;
41 | }
42 |
43 | @Override
44 | public int getPageSize() {
45 | return size;
46 | }
47 |
48 | @Override
49 | public int getPageNumber() {
50 | return page;
51 | }
52 |
53 | @SuppressWarnings("unused")
54 | private int getOffset() {
55 | return page * size;
56 | }
57 |
58 | @Override
59 | public boolean hasPrevious() {
60 | return page > 0;
61 | }
62 |
63 | @Override
64 | public IPageable previousOrFirst() {
65 | return hasPrevious() ? previous() : first();
66 | }
67 |
68 | @Override
69 | public IPageable next() {
70 | return new PageableImpl(getPageNumber() + 1, getPageSize(), getSort());
71 | }
72 |
73 | public PageableImpl previous() {
74 | return getPageNumber() == 0 ? this : new PageableImpl(
75 | getPageNumber() - 1, getPageSize(), getSort());
76 | }
77 |
78 | @Override
79 | public IPageable first() {
80 | return new PageableImpl(0, getPageSize(), getSort());
81 | }
82 |
83 | @Override
84 | public Sorter getSort() {
85 | return sort;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/SearchFilter.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 | import java.util.Map;
6 | import java.util.Map.Entry;
7 |
8 | import javax.servlet.ServletRequest;
9 |
10 | import org.apache.commons.lang.StringUtils;
11 | import org.slf4j.Logger;
12 | import org.slf4j.LoggerFactory;
13 | import org.springframework.web.util.WebUtils;
14 |
15 | import com.google.common.collect.Lists;
16 |
17 | public class SearchFilter implements Serializable {
18 |
19 | private static final Logger logger = LoggerFactory
20 | .getLogger(SearchFilter.class);
21 |
22 | private static final long serialVersionUID = 8719997267153871707L;
23 |
24 | public static final String PREFIX = "search_";
25 |
26 | public enum Operator {
27 | /**
28 | * EQ : 等于 =
29 | * NE : 不等于 !=
30 | * LIKE : 相似 = like("%" + value + "%")
31 | * PLIKE : like("%" + value)
32 | * ALIKE : like(value + "%")
33 | * GT : 大于 >
34 | * LT : 小于 <
35 | * GTE : 大于等于 >=
36 | * LTE : 小于等于 <= IN : id in (1,2,3)
37 | */
38 | EQ, NE, LIKE, PLIKE, ALIKE, GT, LT, GTE, LTE, IN, OR
39 | }
40 |
41 | private String fieldName;
42 | private Object value;
43 | private Operator operator;
44 |
45 | public SearchFilter(String fieldName, Operator operator, Object value) {
46 | logger.debug("###search parameter:"+fieldName + "<[" + operator + "]>" + value);
47 | this.fieldName = fieldName;
48 | this.operator = operator;
49 | this.value = value;
50 | }
51 |
52 | public String getFieldName() {
53 | return fieldName;
54 | }
55 |
56 | public Object getValue() {
57 | return value;
58 | }
59 |
60 | public Operator getOperator() {
61 | return operator;
62 | }
63 |
64 | public static List parse(ServletRequest request) {
65 | return parse(WebUtils.getParametersStartingWith(request, PREFIX));
66 | }
67 |
68 | public static List parse(Map searchParams) {
69 | List filters = Lists.newArrayList();
70 | for (Entry entry : searchParams.entrySet()) {
71 | String key = entry.getKey();
72 | Object value = entry.getValue();
73 | if (StringUtils.isBlank((String) value)) {
74 | continue;
75 | }
76 | String[] names = StringUtils.split(key, "_");
77 | if (names.length != 2) {
78 | throw new IllegalArgumentException(key
79 | + " is not a valid search filter name");
80 | }
81 | String fieldName = names[1];
82 | Operator operator = Operator.valueOf(names[0]);
83 | SearchFilter filter = new SearchFilter(fieldName, operator, value);
84 | filters.add(filter);
85 | }
86 | return filters;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/repository/Sorter.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.repository;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import org.springframework.util.StringUtils;
9 |
10 | public class Sorter implements Serializable {
11 |
12 | private static final long serialVersionUID = 8774379137332701467L;
13 |
14 | public static final String DEFAULT_DIRECTION = "ASC";
15 |
16 | private final List orders;
17 |
18 | public Sorter(String _direction, String _propertie) {
19 | this(_direction, _propertie == null ? new ArrayList() : Arrays.asList(_propertie));
20 | }
21 |
22 | public Sorter(String _direction, String... _properties) {
23 | this(_direction, _properties == null ? new ArrayList() : Arrays.asList(_properties));
24 | }
25 |
26 | public Sorter(String direction, List properties) {
27 |
28 | if (properties == null || properties.isEmpty()) {
29 | throw new IllegalArgumentException("You have to provide at least one property to sort by!");
30 | }
31 |
32 | this.orders = new ArrayList(properties.size());
33 |
34 | for (String property : properties) {
35 | this.orders.add(new Order(direction, property));
36 | }
37 | }
38 |
39 | public Sorter(Order... orders) {
40 | this(Arrays.asList(orders));
41 | }
42 |
43 | public Sorter(List orders) {
44 |
45 | if (null == orders || orders.isEmpty()) {
46 | throw new IllegalArgumentException("You have to provide at least one sort property to sort by!");
47 | }
48 |
49 | this.orders = orders;
50 | }
51 |
52 | public Sorter(String... properties) {
53 | this(DEFAULT_DIRECTION, properties);
54 | }
55 |
56 | public List getOrders() {
57 | return orders;
58 | }
59 |
60 | public static class Order implements Serializable {
61 | private static final long serialVersionUID = 2286583688034115153L;
62 |
63 | private final String direction;
64 | private final String property;
65 |
66 | public Order(String direction, String property) {
67 | if (!StringUtils.hasText(property)) {
68 | throw new IllegalArgumentException("Property must not null or empty!");
69 | }
70 |
71 | this.direction = direction == null ? DEFAULT_DIRECTION : direction;
72 | this.property = property;
73 | }
74 |
75 | public Order(String property) {
76 | this(DEFAULT_DIRECTION, property);
77 | }
78 |
79 | public String getDirection() {
80 | return direction;
81 | }
82 |
83 | public String getProperty() {
84 | return property;
85 | }
86 |
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/saas-mycat/saas/src/main/java/com/hitler/common/util/ArrayUtils.java:
--------------------------------------------------------------------------------
1 | package com.hitler.common.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.HashSet;
6 | import java.util.List;
7 | import java.util.Set;
8 |
9 | public class ArrayUtils extends org.apache.commons.lang.ArrayUtils {
10 |
11 | /**
12 | * 统计arr数组中包含e元素的个数
13 | *
14 | * @param arr
15 | * @param e
16 | * @return
17 | */
18 | public static int countElements(Object[] arr, Object e) {
19 | int count = 0;
20 | for (Object o : arr) {
21 | if (o.equals(e)) {
22 | count++;
23 | }
24 | }
25 | return count;
26 | }
27 |
28 | public static Object[] sort(Object[] arr) {
29 | Arrays.sort(arr);
30 | return arr;
31 | }
32 |
33 | /**
34 | * 检查one数组是否包含two数组所有元素
35 | *
36 | * @param one
37 | * @param two
38 | * @return
39 | */
40 | public static boolean containsAll(Object[] one, Object[] two) {
41 | for (Object b : two) {
42 | if (!ArrayUtils.contains(one, b)) {
43 | return false;
44 | }
45 | }
46 | return true;
47 | }
48 |
49 | /**
50 | * 检查数组中是否有相同元素
51 | *
52 | * @param array
53 | * @return
54 | */
55 | public static boolean duplicate(Object[] array) {
56 | for (int i = 0; i < array.length - 1; i++) {
57 | for (int j = i + 1; j < array.length; j++) {
58 | if (array[i].equals(array[j])) {
59 | return true;
60 | }
61 | }
62 | }
63 | return false;
64 | }
65 |
66 | public static boolean duplicate(Object[] one, Object[] two) {
67 | for (Object a : one) {
68 | for (Object b : two) {
69 | if (a.equals(b)) {
70 | return true;
71 | }
72 | }
73 | }
74 | return false;
75 | }
76 |
77 | public static Object[] intersect(Object[] one, Object[] two) {
78 | Set