BeeltFunctions.java
5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package com.jflyfox.component.beelt;
import java.util.Date;
import com.jflyfox.jfinal.base.BaseModel;
import com.jflyfox.jfinal.template.TemplateFunctions;
import com.jflyfox.modules.admin.folder.FolderService;
import com.jflyfox.system.config.ConfigCache;
import com.jflyfox.system.config.SysConfig;
import com.jflyfox.system.dict.DictCache;
import com.jflyfox.system.file.service.FileUploadService;
import com.jflyfox.system.user.SysUser;
import com.jflyfox.system.user.UserCache;
import com.jflyfox.util.DateUtils;
import com.jflyfox.util.NumberUtils;
import com.jflyfox.util.StrUtils;
import com.jflyfox.util.extend.HtmlUtils;
public class BeeltFunctions extends TemplateFunctions {
private static FileUploadService uploadSvc = new FileUploadService();
// //////////////////////////数据字典///////////////////////////////////////////
public static String dictSelect(String type, int selected_value) {
return DictCache.getSelect(type, selected_value);
}
public static String dictSelect(String type, String selected_value) {
return dictSelect(type, NumberUtils.parseInt(selected_value));
}
public static String dictValue(int key) {
return DictCache.getValue(key);
}
public static String dictValue(String key) {
return dictValue(NumberUtils.parseInt(key));
}
public static String dictCode(int key) {
return DictCache.getCode(key);
}
public static String dictCode(String key) {
return dictCode(NumberUtils.parseInt(key));
}
// //////////////////////////系统参数配置///////////////////////////////////////////
public static SysConfig getConfig(String key) {
return ConfigCache.getSysConfig(key);
}
// //////////////////////自定义方法///////////////////////////
/**
* 获取文件
*
* 2017年4月5日 下午10:08:57 flyfox 369191470@qq.com
*
* @param article
* @param attrName
* @return
*/
public static String getFile(BaseModel<?> article, String attrName) {
String fileName = article.getStr(attrName);
if (StrUtils.isNotEmpty(fileName)) {
uploadSvc.restore(fileName);
}
return fileName;
}
/**
* 获取图片路径
*
* 2015年6月2日 下午6:36:37 flyfox 369191470@qq.com
*
* @param article
* @return
*/
public static String getImage(BaseModel<?> article) {
String imageUrl = article.getStr("image_net_url");
if (StrUtils.isEmpty(imageUrl)) {
imageUrl = article.getStr("image_url");
}
uploadSvc.restore(imageUrl);
return imageUrl;
}
/**
* 获取视频路径
*
* 2015年6月2日 下午6:36:37 flyfox 369191470@qq.com
*
* @param video
* @return
*/
public static String getVideo(BaseModel<?> video) {
String videoUrl = video.getStr("video_net_url");
if (StrUtils.isEmpty(videoUrl)) {
videoUrl = video.getStr("video_url");
}
videoUrl = videoUrl.replaceAll("\\\\", "\\/");
uploadSvc.restore(videoUrl);
return videoUrl;
}
/**
* 获取菜单,数字和字符串转换
*
* 2015年5月26日 上午8:57:48 flyfox 369191470@qq.com
*
* @param key
* @return
*/
public static String getMenu(String key) {
return FolderService.getMenu(key);
}
/**
* 获取菜单,数字和字符串转换
*
* 2015年5月26日 上午8:57:48 flyfox 369191470@qq.com
*
* @param key
* @return
*/
public static String getMenu(int key) {
return FolderService.getMenu(key + "");
}
/**
* 字符串截取
*
* 2015年5月25日 下午3:58:45 flyfox 369191470@qq.com
*
* @param str
* @param start
* @param end
* @return
*/
public static String substr(String str, int start, int end) {
return str == null ? null : str.substring(start, end);
}
public static String getNow() {
return DateUtils.getNow();
}
public static String getNow(String regex) {
return DateUtils.getNow(regex);
}
public static String suojin(String str, int length) {
return StrUtils.suojin(str, length);
}
/**
* split
*
* 2015年5月17日 下午11:03:39 flyfox 369191470@qq.com
*
* @param str
* @param split
* @return
*/
public static String[] split(String str, String split) {
if (StrUtils.isEmpty(str)) {
return null;
}
return str.split(split);
}
/**
* html预览
*
* 2015年2月2日 下午3:40:34 flyfox 369191470@qq.com
*
* @param htmlStr
* @return
*/
public static String showHTML(String htmlStr, int num, String endStr) {
String tmpStr = HtmlUtils.delHTMLTag(htmlStr);
tmpStr = StrUtils.suojin(tmpStr, num + endStr.length(), endStr);
return tmpStr;
}
/**
* 获取用户
*
* 2015年2月26日 下午4:24:39 flyfox 369191470@qq.com
*
* @param pid
* @return
*/
public static SysUser getUser(Integer pid) {
SysUser user = UserCache.getUser(pid);
return user;
}
/**
* 获取用户名
*
* 2015年2月26日 下午4:24:39 flyfox 369191470@qq.com
*
* @param pid
* @return
*/
public static String getUserName(Integer pid) {
SysUser user = UserCache.getUser(pid);
if (user == null) {
return "";
}
if (StrUtils.isNotEmpty(user.getStr("realname"))) {
return user.getStr("realname");
}
return user.getStr("username");
}
/**
* 判断date距当前时间是否相差before天
*
* 2015年5月11日 下午2:07:40 flyfox 369191470@qq.com
*
* @param date
* @param before
* @return
*/
public static boolean isNew(String date, int before) {
DateUtils.parseByAll(date).getTime();
Date d1 = new Date();
Date d2 = DateUtils.parse(date, DateUtils.DEFAULT_REGEX_YYYY_MM_DD_HH_MIN_SS);
long diff = d1.getTime() - d2.getTime();
long days = diff / (1000 * 60 * 60 * 24);
return days - 7 <= 0;
}
}