TemplateService.java
10.3 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.jflyfox.modules.front.template;
import com.jfinal.plugin.activerecord.Page;
import com.jflyfox.api.entity.BDemand;
import com.jflyfox.jfinal.base.BaseService;
import com.jflyfox.jfinal.base.Paginator;
import com.jflyfox.modules.admin.article.TbArticle;
import com.jflyfox.modules.admin.folder.TbFolder;
import com.jflyfox.modules.admin.foldernotice.TbFolderNotice;
import com.jflyfox.modules.admin.folderrollpicture.TbFolderRollPicture;
import com.jflyfox.modules.admin.tags.TbTags;
import com.jflyfox.modules.front.articlelike.ArticleLikeCache;
import com.jflyfox.modules.front.service.FrontCacheService;
import com.jflyfox.modules.web.entity.IndexArticle;
import com.jflyfox.system.config.ConfigCache;
import com.jflyfox.system.config.SysConfig;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.*;
/**
* 模板方法接口
* <p>
* 2016年1月18日 下午6:05:54 flyfox 369191470@qq.com
*/
public class TemplateService extends BaseService {
private final static FrontCacheService service = new FrontCacheService();
private final static ArticleLikeCache articleLikeservice = new ArticleLikeCache();
/**
* 获取浏览数
* <p>
* 2015年6月2日 下午6:30:56 flyfox 369191470@qq.com
*
* @param articleId
* @return
*/
public static int countView(int articleId) {
TbArticle article = service.getArticleCount(articleId);
return article == null ? 0 : article.getCountView();
}
/**
* 获取评论数
* <p>
* 2015年6月2日 下午6:30:56 flyfox 369191470@qq.com
*
* @param articleId
* @return
*/
public static int countComment(int articleId) {
TbArticle article = service.getArticleCount(articleId);
return article == null ? 0 : article.getCountComment();
}
/**
* 获取浏览数
* <p>
* 2015年6月2日 下午6:30:56 flyfox 369191470@qq.com
*
* @param articleId
* @return
*/
public static boolean isLike(int userId, int articleId) {
return articleLikeservice.isLike(userId, articleId);
}
/**
* 获取标签信息
* <p>
* 2015年5月25日 下午11:49:58 flyfox 369191470@qq.com
*
* @return
*/
public List<TbTags> tagsListByArticle(int articleId) {
return service.getTagsByArticle(articleId);
}
/**
* 获取标签信息
* <p>
* 2015年5月25日 下午11:49:58 flyfox 369191470@qq.com
*
* @param folderId 目录
* @return
*/
public Page<TbTags> tagsPageByFolder(int pageNo, int pageSize, int folderId) {
return service.getTagsByFolder(new Paginator(pageNo, pageSize), folderId);
}
/**
* 获取标签信息
* <p>
* 2015年5月25日 下午11:49:03 flyfox 369191470@qq.com
*
* @return
*/
public Page<TbTags> tagsPage(int pageNo, int pageSize, int siteId) {
return service.getTags(new Paginator(pageNo, pageSize), siteId);
}
/**
* 查询文章,展示的和类型为11,12的推荐文件,前10个
* <p>
* 2015年4月29日 下午4:48:24 flyfox 369191470@qq.com
*
* @return
*/
public Page<TbArticle> articlePageRecommend(int pageNo, int pageSize, int siteId) {
return service.getRecommendArticle(new Paginator(pageNo, pageSize), siteId);
}
/**
* 返回最新文章
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*
* @return
*/
public Page<TbArticle> articlePageTop(int pageNo, int pageSize, int siteId) {
return service.getNewArticle(new Paginator(pageNo, pageSize), siteId);
}
/**
* 返回文章列表
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*/
public Page<TbArticle> articlePageSite(int pageNo, int pageSize, int siteId) {
return service.getArticleBySiteId(new Paginator(pageNo, pageSize), siteId);
}
/**
* 按照特定排序,返回文章列表
* <p>
* 2017年1月17日 下午5:37:16
* flyfox 330627517@qq.com
*
* @param pageNo
* @param pageSize
* @param siteId
* @param orderType
* @return
*/
public Page<TbArticle> articleOrder(int pageNo, int pageSize, int siteId, int orderType) {
return service.getArticleByOrder(new Paginator(pageNo, pageSize), siteId, orderType);
}
/**
* 返回文章列表
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*
* @param folderId
* @return
*/
public Page<TbArticle> articlePage(int pageNo, int pageSize, int folderId) {
return service.getArticle(new Paginator(pageNo, pageSize), folderId);
}
/**
* 返回文章列表不走缓存
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*
* @param folderId
* @return
*/
public Page<TbArticle> articlePageNoCache(int pageNo, int pageSize, int folderId) {
return service.getArticleByNoCache(new Paginator(pageNo, pageSize), folderId);
}
/**
* 返回文章列表不走缓存
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*
* @return
*/
public Page<TbArticle> articlePageNoCache(int pageNo, int pageSize, String folderKey, Integer siteId) {
TbFolder folder = TbFolder.dao.findFirstByWhere("where `key` = ? and site_id = ?", folderKey, siteId);
return Optional.ofNullable(folder).map(e -> service.getArticleByNoCache(new Paginator(pageNo, pageSize), e.getId())).orElse(null);
}
/**
* 返回对应文章
* <p>
* 2015年5月24日 下午10:52:05 flyfox 369191470@qq.com
*
* @return
*/
public TbArticle article(int articleId) {
return service.getArticle(articleId);
}
/**
* 获取栏目滚动图片
* <p>
* 2016年1月28日 下午5:28:25 flyfox 369191470@qq.com
*
* @param folderId
* @return
*/
public List<TbFolderRollPicture> rollPicture(int folderId) {
return service.getRollPicture(folderId);
}
/**
* 获取栏目滚动图片
* <p>
* 2016年1月28日 下午5:28:25 flyfox 369191470@qq.com
*
* @return
*/
public List<TbFolderRollPicture> rollPicture(String folderKey, Integer siteId) {
TbFolder folder = TbFolder.dao.findFirstByWhere("where `key` = ? and site_id = ?", folderKey, siteId);
if (folder == null) {
return null;
} else {
return service.getRollPicture(folder.getId());
}
}
/**
* 获取公告信息
* <p>
* 2016年1月28日 下午5:29:47 flyfox 369191470@qq.com
*
* @param folderId
*/
public List<TbFolderNotice> notice(int folderId) {
return service.getNotice(folderId);
}
/**
* 官网首页产品与解决方案
*/
public List<IndexArticle> indexArticles(int folderId) {
return service.indexArticles(folderId);
}
/**
* 获取同级
*/
public List<TbFolder> folderBrother(int folderId) {
return service.folderBrother(folderId);
}
/**
* 获取下级
*/
public List<TbFolder> folderSon(int folderId) {
return service.folderSon(folderId);
}
/**
* 获取平级
*
* @param folderId 栏目Id
* @return 栏目对象
*/
public TbFolder folderParent(int folderId) {
return service.folderParent(folderId);
}
/**
* 获取下级
*/
public List<TbFolder> folderSon(String folderKey, Integer siteId) {
TbFolder folder = TbFolder.dao.findFirstByWhere("where `key` = ? and site_id = ?", folderKey, siteId);
return folder == null ? null : service.folderSon(folder.getId());
}
/**
* 获取栏目
*/
public TbFolder getFolder(String folderKey, Integer siteId) {
return TbFolder.dao.findFirstByWhere("where `key` = ? and site_id = ?", folderKey, siteId);
}
public String getSysConfig(String key) {
SysConfig config = ConfigCache.getSysConfig(key);
return config == null ? "" : config.getValue();
}
public Page<BDemand> getOrders(int pageNo, int pageSize) {
String fromSql = " from b_demand b where 1=1 ";
// 推荐文章列表
Page<BDemand> demands = BDemand.dao.paginate(new Paginator(pageNo, pageSize), "select * ", fromSql);
List<BDemand> list = demands.getList();
Map<String, String> map = new HashMap<>();
map.put("TRUCK", "车运");
map.put("SHIP", "船运");
map.put("TRUCK_AND_SHIP", "车船联运");
Map<String, String> stMap = new HashMap<>();
stMap.put("PUBLISH", "已发布");
stMap.put("RECEIVE", "已接受");
stMap.put("REJECT", "已拒绝");
stMap.put("GOING", "进行中");
stMap.put("FINISH", "已结束");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (BDemand demand : list) {
String type = (String) demand.getAttrs().get("type");
demand.setTYPE(map.get(type));
String status = (String) demand.getAttrs().get("status");
demand.setSTATUS(stMap.get(status));
Date date = (Date) demand.getAttrs().get("created_date");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, -8);
date = cal.getTime();
String strDate = formatter.format(date);
demand.setCREATED_DATE(strDate);
String userName = (String) demand.getAttrs().get("user_name");
int length = userName.length();
if (length < 2) {
//一个字,不处理
} else if (length == 2) {
String a = userName.substring(0, 1);
String b = "*";
demand.setUSER_NAME(a + b);
} else if (length == 3) {
String a = userName.substring(0, 1);
String b = "*";
String c = userName.substring(2, 3);
demand.setUSER_NAME(a + b + c);
} else {
String a = userName.substring(0, 1);
String b = "***";
String c = userName.substring(length-1,length);
demand.setUSER_NAME(a + b + c);
}
}
return demands;
}
}