|
|
@@ -202,19 +202,29 @@ public class ContentService extends BaseService<Content> {
|
|
|
|
|
|
List<Map> result = new ArrayList<>();
|
|
|
|
|
|
- Content query = new Content();
|
|
|
- query.setDel_flag(false);
|
|
|
- List<Content> contentList = this.findListByWhere(query);
|
|
|
+// Content query = new Content();
|
|
|
+// query.setDel_flag(false);
|
|
|
+// List<Content> contentList = this.findListByWhere(query);
|
|
|
+
|
|
|
+ Example example = new Example(Content.class);
|
|
|
+ Example.Criteria criteria = example.createCriteria();
|
|
|
+ //倒序
|
|
|
+ example.orderBy("sort").asc();
|
|
|
+ example.orderBy("create_time").desc();
|
|
|
+ PageHelper.startPage(1, num);
|
|
|
+ List<Content> contentList = this.selectByExample(example);
|
|
|
+
|
|
|
int count = 0;
|
|
|
List<String> businessIdList = new ArrayList<>();
|
|
|
|
|
|
long interval = 0;
|
|
|
Date startTime = new Date();
|
|
|
|
|
|
- while (count < num && interval < 2) {
|
|
|
+ //500ms内必须结束
|
|
|
+ /*while (count < num && interval < 500) {
|
|
|
|
|
|
Date now = new Date();
|
|
|
- interval = (now.getTime() - startTime.getTime()) / 1000;
|
|
|
+ interval = (now.getTime() - startTime.getTime());
|
|
|
|
|
|
//随机在list里选一个
|
|
|
int index = (int) (Math.random() * (contentList.size() - 1));
|
|
|
@@ -222,7 +232,7 @@ public class ContentService extends BaseService<Content> {
|
|
|
//排除同一businessid
|
|
|
boolean idDuplicatedFlag = true;
|
|
|
for (String businessId : businessIdList) {
|
|
|
- if (Objects.equals(businessId, contentEntity.getId())) {
|
|
|
+ if (Objects.equals(businessId, contentEntity.getId() + "")) {
|
|
|
idDuplicatedFlag = false;
|
|
|
}
|
|
|
}
|
|
|
@@ -261,7 +271,7 @@ public class ContentService extends BaseService<Content> {
|
|
|
map.put("create_time", contentEntity.getCreate_time());
|
|
|
map.put("url", pics.get(0));
|
|
|
|
|
|
- /*String textStr = "";
|
|
|
+ *//*String textStr = "";
|
|
|
Pattern p_script;
|
|
|
Matcher m_script;
|
|
|
Pattern p_style;
|
|
|
@@ -283,13 +293,51 @@ public class ContentService extends BaseService<Content> {
|
|
|
htmlStr = m_html.replaceAll(""); //过滤html标签
|
|
|
textStr = htmlStr;
|
|
|
|
|
|
- map.put("content", textStr);*/
|
|
|
+ map.put("content", textStr);*//*
|
|
|
|
|
|
result.add(map);
|
|
|
|
|
|
businessIdList.add(contentEntity.getId() + "");
|
|
|
count++;
|
|
|
}
|
|
|
+ }*/
|
|
|
+
|
|
|
+ for (Content contentEntity : contentList) {
|
|
|
+ String htmlStr = contentEntity.getContent();
|
|
|
+ //排除没有图片标签的
|
|
|
+ if (!htmlStr.contains("<img")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //排除没有src内容的
|
|
|
+ if (!htmlStr.contains("src=")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String img = "";
|
|
|
+ Pattern p_image;
|
|
|
+ Matcher m_image;
|
|
|
+ List<String> pics = new ArrayList<String>();
|
|
|
+ //String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址
|
|
|
+ String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
|
|
|
+ p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
|
|
|
+ m_image = p_image.matcher(htmlStr);
|
|
|
+ while (m_image.find()) {
|
|
|
+ img = img + "," + m_image.group();
|
|
|
+ // Matcher m =
|
|
|
+ // Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(img); //匹配src
|
|
|
+ Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
|
|
|
+ while (m.find()) {
|
|
|
+ pics.add(m.group(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("id", contentEntity.getId() + "");
|
|
|
+ map.put("title", contentEntity.getTitle());
|
|
|
+ map.put("create_time", contentEntity.getCreate_time());
|
|
|
+ map.put("url", pics.get(0));
|
|
|
+
|
|
|
+ result.add(map);
|
|
|
}
|
|
|
// System.out.println("两个时间相差" + interval + "秒");
|
|
|
return result;
|