标签:
本文将给您介绍 AppAdmin 后台管理系统开发框架。
AppAdmin后台管理系统开发框架是一套Java开发的整合了当前众多比较流行的Java后台开发框架的系统,使用H5响应式布局。
整合了 spring + springMVC + hibernate (JPA) + shiro + ehcache 等框架,功能包括基本的系统管理、权限、角色、存储(oss、本地、ftp)、缓存、站内信、smtp邮件发送、微信公众号开发、富文本内容使用文件存储的统一实现等等众多模块,持续更新开发中。
public class Filter implements Serializable {
/**
* 运算符
*/
public enum Operator {
/** 等于 */
eq,
/** 不等于 */
ne,
/** 大于 */
gt, greaterThan,
/** 小于 */
lt, lessThan,
/** 大于等于 */
ge, greaterThanOrEqualTo,
/** 小于等于 */
le, lessThanOrEqualTo,
/** 相似 */
like,
/** 包含 */
in,
/** 为Null */
isNull,
/** 不为Null */
isNotNull;
}
/** 默认是否忽略大小写 */
private static final boolean DEFAULT_IGNORE_CASE = false;
/** 属性 */
private String property;
/** 运算符 */
private Operator operator;
/** 值 */
private Object value;
/** 标识值value是否是另外一个属性的名称 */
private Boolean isValuePropery = false;
/** 是否忽略大小写(仅针对value为String类型情况有效) */
private Boolean ignoreCase = DEFAULT_IGNORE_CASE;
/**
* 初始化一个新创建的Filter对象
*/
private Filter() {
}
/**
* 初始化一个新创建的Filter对象(使用Object value)
*
* @param property
* 属性
* @param operator
* 运算符
* @param isValuePropery
* value是否是属性
* @param value
* 值
*/
private Filter(String property, Operator operator, Object value, boolean isValuePropery) {
this.property = property;
this.operator = operator;
this.value = value;
this.isValuePropery = isValuePropery;
}
/**
* 初始化一个新创建的Filter对象(使用Object value)
*
* @param property
* 属性
* @param operator
* 运算符
* @param value
* 值
* @param isValuePropery
* value是否是属性
* @param ignoreCase
* 忽略大小写
*/
private Filter(String property, Operator operator, Object value, boolean isValuePropery, boolean ignoreCase) {
this.property = property;
this.operator = operator;
this.value = value;
this.ignoreCase = ignoreCase;
this.isValuePropery = isValuePropery;
}
}
protected void addRestrictions(CriteriaQuery<T> criteriaQuery, List<Filter> filters) {
if (criteriaQuery == null || filters == null || filters.isEmpty()) {
return;
}
Root<T> root = getRoot(criteriaQuery);
if (root == null) {
return;
}
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
Predicate restrictions = criteriaQuery.getRestriction() != null ? criteriaQuery.getRestriction() : criteriaBuilder.conjunction();
for (Filter filter : filters) {
if (filter == null || StringUtils.isEmpty(filter.getProperty())) {
continue;
}
if (filter.getOperator() == Operator.eq && filter.getValue() != null) {
if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(criteriaBuilder.lower(root.<String> get(filter.getProperty())), criteriaBuilder.lower(root.<String> get(filter.getComparePropery()))));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(criteriaBuilder.lower(root.<String> get(filter.getProperty())), ((String) filter.getValue()).toLowerCase()));
}
} else {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get(filter.getProperty()), root.get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get(filter.getProperty()), filter.getValue()));
}
}
} else if (filter.getOperator() == Operator.ne && filter.getValue() != null) {
if (filter.getIgnoreCase() != null && filter.getIgnoreCase() && filter.getValue() instanceof String) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(criteriaBuilder.lower(root.<String> get(filter.getProperty())), criteriaBuilder.lower(root.<String> get(filter.getComparePropery()))));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(criteriaBuilder.lower(root.<String> get(filter.getProperty())), ((String) filter.getValue()).toLowerCase()));
}
} else {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(root.get(filter.getProperty()), root.get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.notEqual(root.get(filter.getProperty()), filter.getValue()));
}
}
} else if (filter.getOperator() == Operator.gt && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.gt(root.<Number> get(filter.getProperty()), root.<Number> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.gt(root.<Number> get(filter.getProperty()), (Number) filter.getValue()));
}
} else if (filter.getOperator() == Operator.greaterThan && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThan(root.<Date> get(filter.getProperty()), root.<Date> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThan(root.<Date> get(filter.getProperty()), (Date) filter.getValue()));
}
} else if (filter.getOperator() == Operator.lt && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lt(root.<Number> get(filter.getProperty()), root.<Number> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lt(root.<Number> get(filter.getProperty()), (Number) filter.getValue()));
}
} else if (filter.getOperator() == Operator.lessThan && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThan(root.<Date> get(filter.getProperty()), root.<Date> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThan(root.<Date> get(filter.getProperty()), (Date) filter.getValue()));
}
} else if (filter.getOperator() == Operator.ge && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number> get(filter.getProperty()), root.<Number> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number> get(filter.getProperty()), (Number) filter.getValue()));
}
} else if (filter.getOperator() == Operator.greaterThanOrEqualTo && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date> get(filter.getProperty()), root.<Date> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date> get(filter.getProperty()), (Date) filter.getValue()));
}
} else if (filter.getOperator() == Operator.le && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number> get(filter.getProperty()), root.<Number> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number> get(filter.getProperty()), (Number) filter.getValue()));
}
} else if (filter.getOperator() == Operator.lessThanOrEqualTo && filter.getValue() != null) {
if (filter.valueIsPropery()) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date> get(filter.getProperty()), root.<Date> get(filter.getComparePropery())));
} else {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date> get(filter.getProperty()), (Date) filter.getValue()));
}
} else if (filter.getOperator() == Operator.like && filter.getValue() != null && filter.getValue() instanceof String) {
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.like(root.<String> get(filter.getProperty()), (String) filter.getValue()));
} else if (filter.getOperator() == Operator.in && filter.getValue() != null) {
restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).in((Collection<?>) filter.getValue()));
} else if (filter.getOperator() == Operator.isNull) {
restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNull());
} else if (filter.getOperator() == Operator.isNotNull) {
restrictions = criteriaBuilder.and(restrictions, root.get(filter.getProperty()).isNotNull());
}
}
criteriaQuery.where(restrictions);
}
public class FilePlugin extends StoragePlugin implements ServletContextAware {
/** servletContext */
private ServletContext servletContext;
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
@Override
public String getName() {
return "本地文件存储";
}
@Override
public String getVersion() {
return "1.0";
}
@Override
public String getAuthor() {
return "APP";
}
@Override
public String getSiteUrl() {
return "http://";
}
@Override
public String getInstallUrl() {
return "file/install.jhtml";
}
@Override
public String getUninstallUrl() {
return "file/uninstall.jhtml";
}
@Override
public String getSettingUrl() {
return "file/setting.jhtml";
}
@Override
public void upload(String path, File file, String contentType) {
File destFile = new File(servletContext.getRealPath(path));
try {
FileUtils.moveFile(file, destFile);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public String getUrl(String path) {
Setting setting = SettingUtils.get();
return setting.getSiteUrl() + path;
}
@Override
public List<FileInfo> browser(String path) {
Setting setting = SettingUtils.get();
List<FileInfo> fileInfos = new ArrayList<FileInfo>();
File directory = new File(servletContext.getRealPath(path));
if (directory.exists() && directory.isDirectory()) {
for (File file : directory.listFiles()) {
FileInfo fileInfo = new FileInfo();
fileInfo.setName(file.getName());
fileInfo.setUrl(setting.getSiteUrl() + path + file.getName());
fileInfo.setIsDirectory(file.isDirectory());
fileInfo.setSize(file.length());
fileInfo.setLastModified(new Date(file.lastModified()));
fileInfos.add(fileInfo);
}
}
return fileInfos;
}
}
/***
* 刷新 AccessToken
*/
public void refreshAccessToken() {
if (accessTokenRefreshingFlag.compareAndSet(false, true)) {
try {
// 记录上一次 AccessToken 刷新时间
long lastWeixinAccessTokenStartTime = weixinAccessTokenStartTime;
// 设置新的 AccessToken 开始时间
this.weixinAccessTokenStartTime = System.currentTimeMillis();
// 刷新
Map<String, Object> jsonMap = WeiXinHttpUtils.getJson(WeiXinURL.get_accessTokenUrl, this, null, null);
if (jsonMap.containsKey("access_token")) {
// example: {"access_token":"ACCESS_TOKEN","expires_in":7200}
this.accessToken = jsonMap.get("access_token").toString().trim();
if (jsonMap.containsKey("expires_in")) {
this.expireTime = (Integer) jsonMap.get("expires_in") * 1000;
}
log.info("WeiXinConfig.refreshAccessToken() info. jsonMap = " + jsonMap.toString());
} else if (jsonMap.containsKey("errcode")) {
// example: {"errcode":40013,"errmsg":"invalid appid"}
log.error("WeiXinConfig.refreshAccessToken() error. jsonMap = " + jsonMap.toString());
this.weixinAccessTokenStartTime = lastWeixinAccessTokenStartTime;
} else {
// unknown
log.error("WeiXinConfig.refreshAccessToken() unknown error. jsonMap = " + jsonMap.toString());
this.weixinAccessTokenStartTime = lastWeixinAccessTokenStartTime;
}
} finally {
accessTokenRefreshingFlag.set(false);
}
}
}
以上仅仅是部分功能,很多列表页面比较类似就不重复了。
Java 后台管理开发框架!CURD 一键生成,再也不要重复搬砖了!
标签:
原文地址:http://blog.csdn.net/u013887254/article/details/51406724