|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.fr.design.mainframe.alphafine.search.manager.impl; |
|
|
|
|
|
|
|
|
|
import com.fr.concurrent.NamedThreadFactory; |
|
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
|
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
|
|
|
import com.fr.design.mainframe.alphafine.model.ProductNews; |
|
|
|
@ -12,17 +13,19 @@ import com.fr.json.JSONObject;
|
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
import java.awt.Image; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
|
|
|
|
public class ProductNewsSearchManager { |
|
|
|
|
|
|
|
|
@ -91,7 +94,7 @@ public class ProductNewsSearchManager {
|
|
|
|
|
setImage(getCoverImage(obj.getString("pic"))). |
|
|
|
|
setUrl(obj.getString("url")).setTag(ProductNews.Tag.parseCode(obj.getInt("tag"))). |
|
|
|
|
setStatus(ProductNews.Status.parseCode(obj.getInt("status"))).setTarget( |
|
|
|
|
ProductNews.Target.parseCode(obj.getInt("target"))). |
|
|
|
|
ProductNews.ParseTarget(obj.getString("target"))). |
|
|
|
|
setCreator(obj.getInt("creator")).setPushDate(new Date(obj.getLong("push_time"))); |
|
|
|
|
Date currentDate = new Date(System.currentTimeMillis()); |
|
|
|
|
// 推送时间check
|
|
|
|
@ -100,9 +103,70 @@ public class ProductNewsSearchManager {
|
|
|
|
|
idSet.add(productNews.getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
filterByDesignerId(productNewsList); |
|
|
|
|
|
|
|
|
|
return productNewsList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将productNews根据设计器id进行过滤 |
|
|
|
|
* productNews有个target字段,代表推送对象用户组,检查设计器id是否在用户组中来进行过滤 |
|
|
|
|
* */ |
|
|
|
|
private List<ProductNews> filterByDesignerId(List<ProductNews> list) { |
|
|
|
|
//设计器id
|
|
|
|
|
String designId = DesignerEnvManager.getEnvManager().getUUID(); |
|
|
|
|
|
|
|
|
|
HashMap<String, Set<String>> userGroupInfoCache = new HashMap<>(); |
|
|
|
|
//遍历资源,获取target下的所有用户组信息,检查是否包含设计器id
|
|
|
|
|
Iterator<ProductNews> iterator = list.iterator(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
List<String> targets = iterator.next().getTarget(); |
|
|
|
|
|
|
|
|
|
boolean targetsContainDesignerId = false; |
|
|
|
|
|
|
|
|
|
// 每条推送可能推送至多个用户组,需要逐一判断
|
|
|
|
|
for (String userGroupId : targets) { |
|
|
|
|
// 没有记录的用户组信息需要请求一下
|
|
|
|
|
if (!userGroupInfoCache.containsKey(userGroupId)) { |
|
|
|
|
userGroupInfoCache.put(userGroupId, searchUserGroupInfo(userGroupId)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 判断设计器id是否在这个用户组中,在则退出判断,不在则继续
|
|
|
|
|
if (userGroupInfoCache.get(userGroupId).contains(designId) || userGroupId.equals(ProductNews.ALL_USER_TARGET)) { |
|
|
|
|
targetsContainDesignerId = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!targetsContainDesignerId) { |
|
|
|
|
iterator.remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据用户组id,查询用户组信息(改用户组中的所有设计器id) |
|
|
|
|
* */ |
|
|
|
|
private Set<String> searchUserGroupInfo(String userGroupId) { |
|
|
|
|
String url = AlphaFineConstants.ALPHA_CID_USER_GROUP_INFO + AlphaFineConstants.SEARCH_BY_ID + userGroupId; |
|
|
|
|
Set<String> idSet = new HashSet<>(); |
|
|
|
|
try { |
|
|
|
|
String jsonStr = HttpToolbox.get(url); |
|
|
|
|
JSONObject jsonObject = new JSONObject(jsonStr); |
|
|
|
|
JSONArray idArray = jsonObject.getJSONArray("data"); |
|
|
|
|
for (int i = 0; i < idArray.length(); i++) { |
|
|
|
|
idSet.add(idArray.getJSONObject(i).getString("userid")); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return idSet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List<ProductNews> getCachedProductNewsList() { |
|
|
|
|
return productNewsList; |
|
|
|
|
} |
|
|
|
|