需求:评论点赞通知跟自己是好友或关注的评论点赞该条说说的人
这个功能是点赞和评论接口,在点赞的同时会给自己的朋友 (是在该条说说有联系的 评论或点赞)进行消息推送
还是跟上一个一样进行筛选。相同的进行推送。在完成之后感觉有问题。就是出现在推送哪里。微信的是 点赞 推送。取消点赞。但是推送还在。在点赞的情况下。消息不会重复,始终保证数据的唯一性。
而我这个是没有做处理。在取消的时候,消息不会进行删除。重新点赞的情况下,消息会重复添加。也就造成了。其实只有一个推送。却出现很多条数据。
当然解决起来其实也很简单。我在推送前做个判断 根据数据来进行查询。如果数据库里有数据,则不添加。这样就保证了数据的唯一性。
直接贴代码 应该都可以看得懂
public static Map<String, Object> createCaseHisTopReview(DispatchContext dctx, Map<String, ? extends Object> context) { Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); GenericValue gv = null; if (result.size() > 0) return result; String caseHisTopRevId = null; try { if (UtilValidate.isNotEmpty(context.get("caseHisTopRevId"))) { caseHisTopRevId = context.get("caseHisTopRevId").toString(); } else { caseHisTopRevId = delegator.getNextSeqId("CaseHisTopReview"); } String reviewTypeEnum = (String) context.get("reviewTypeEnum"); String caseHisTopId = (String) context.get("caseHisTopId"); String partyId = (String) context.get("partyId"); if(UtilValidate.isNotEmpty(reviewTypeEnum) && UtilValidate.isNotEmpty(caseHisTopId) && UtilValidate.isNotEmpty(partyId)){ List<GenericValue> CaseHisTopReviewList = delegator.findByAnd("CaseHisTopReview", UtilMisc.toMap("caseHisTopId", caseHisTopId, "partyId", partyId,"reviewTypeEnum", reviewTypeEnum,"thruDate", null),null,false); if(UtilValidate.isNotEmpty(CaseHisTopReviewList) && "reviewTypeEnum_2".equals(reviewTypeEnum)){ return ServiceUtil.returnError("已经点过赞!"); } }else{ return ServiceUtil.returnError("请输入必输项!!"); } } catch (IllegalArgumentException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "casehistopreview.id_generation_failure", locale)); } catch (GenericEntityException e) { // TODO Auto-generated catch block e.printStackTrace(); } gv = delegator.makeValue("CaseHisTopReview", UtilMisc.toMap("caseHisTopRevId", caseHisTopRevId)); gv.setNonPKFields(context); if (gv.containsKey("fromDate")) { gv.set("fromDate", UtilDateTime.nowTimestamp()); } if (gv.containsKey("createUserLogin")) { GenericValue userLogin = (GenericValue)context.get("userLogin"); if(userLogin!=null) gv.set("createUserLogin", userLogin.getString("userLoginId")); } //得到说说的id String caseHisTopId=(String) context.get("caseHisTopId"); //评论人Id String partyId=(String) context.get("partyId"); List partyIds=new ArrayList();//该评论点赞所有人集合 List myFriends=new ArrayList();//我的好友集合 List newsId=new ArrayList();//要通知的好友ID if(UtilValidate.isNotEmpty(caseHisTopId)){ //查找该说说的点赞和评论人的ID try { List<GenericValue> CaseHisTopReviewList = delegator.findList("CaseHisTopReview",EntityCondition.makeCondition("caseHisTopId", EntityOperator.EQUALS, caseHisTopId), UtilMisc.toSet("partyId"), null, null, true);//非我屏蔽的好友; if(UtilValidate.isNotEmpty(CaseHisTopReviewList)){ List<GenericValue> CaseHisTopReview = EntityUtil.getFieldListFromEntityList(CaseHisTopReviewList, "partyId", true);//非我屏蔽的我关注的人 if(UtilValidate.isNotEmpty(CaseHisTopReview)){ partyIds.addAll(CaseHisTopReview); } } //去重 partyIds = new ArrayList(new HashSet(partyIds)); //查询评论人的好友 和关注列表 List<EntityCondition> andExprs = FastList.newInstance(); andExprs.add(EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); andExprs.add(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null)); //好友列表 List<GenericValue> MyFriendsList = delegator.findList("MyFriends",EntityCondition.makeCondition(andExprs, EntityOperator.AND), UtilMisc.toSet("friendId"), null, null, true);//非我屏蔽的好友; if(UtilValidate.isNotEmpty(MyFriendsList)){ List<GenericValue> MyFriendsLists = EntityUtil.getFieldListFromEntityList(MyFriendsList, "friendId", true);//非我屏蔽的我关注的人 if(UtilValidate.isNotEmpty(MyFriendsLists)){ myFriends.addAll(MyFriendsLists); } } //关注列表 List<GenericValue> ConcernList = delegator.findList("Concern",EntityCondition.makeCondition(andExprs, EntityOperator.AND), UtilMisc.toSet("beConcernId"), null, null, true); if(UtilValidate.isNotEmpty(ConcernList)){ List<GenericValue> ConcernLists = EntityUtil.getFieldListFromEntityList(ConcernList, "beConcernId", true);//非我屏蔽的我关注的人 if(UtilValidate.isNotEmpty(ConcernLists)){ myFriends.addAll(ConcernLists); } } myFriends=new ArrayList(new HashSet(myFriends)); //比较自己的好友和其他的用户评论或点赞。如果是共同好友则推送消息 for(int i=0;i<myFriends.size();i++){ for(int j=0;j<partyIds.size();j++){ if(myFriends.get(i).equals(partyIds.get(j))){ newsId.add(partyIds.get(j)); } } } } catch (Exception e) { // TODO: handle exception } } try { //查询说说内容 GenericValue CaseHisTopReviewList = delegator.findOne("CaseHistoryTopic",UtilMisc.toMap("caseHisTopId",caseHisTopId), true); newsId.add(CaseHisTopReviewList.get("partyId"));//添加发起人 newsId = new ArrayList(new HashSet(newsId));//去重 String reviewTypeEnum = (String) context.get("reviewTypeEnum"); gv.create(); //news 已经得到共同的好友。 这里做消息通知 for(int i=0;i<newsId.size();i++){ // newsId.get(i) (String) context.get("partyId")caseHisTopId reviewTypeEnum List<GenericValue> AcademicNewsList = delegator.findByAnd("AcademicNews", UtilMisc.toMap("caseHisTopId", caseHisTopId, "partyId", (String) context.get("partyId"),"reviewTypeEnum", reviewTypeEnum,"thruDate", null,"receiveId",newsId.get(i)),null,false); //查询之前有没有发送过消息。有发送过则不重新发送 if(UtilValidate.isEmpty(AcademicNewsList)){ String academicNewsId = delegator.getNextSeqId("AcademicNews"); GenericValue newsGv = delegator.makeValue("AcademicNews", UtilMisc.toMap("academicNewsId", academicNewsId)); newsGv.set("receiveId",newsId.get(i));//消息接受人 newsGv.set("partyId", (String) context.get("partyId"));//发送人 if(UtilValidate.isNotEmpty(context.get("replyId"))){//判断回复评论人id newsGv.set("replyId", context.get("replyId")); } if(UtilValidate.isNotEmpty(context.get("replyTopRevId"))){//判断评论id newsGv.set("replyTopRevId", context.get("replyTopRevId")); } if(UtilValidate.isNotEmpty(caseHisTopId)){ newsGv.set("caseHisTopId", caseHisTopId); if(UtilValidate.isNotEmpty(CaseHisTopReviewList)){ if(UtilValidate.isNotEmpty(CaseHisTopReviewList.get("imagesPath"))){ newsGv.set("content", CaseHisTopReviewList.get("imagesPath")); }else{ newsGv.set("content", CaseHisTopReviewList.get("content")); } } } newsGv.set("reviewTypeEnum", reviewTypeEnum); // newsGv.set("partyClient", UtilDateTime.nowTimestamp()); newsGv.set("fromDate", UtilDateTime.nowTimestamp()); newsGv.create(); } } } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("新增失败"); } if (gv != null) { result.put("caseHisTopRevId", caseHisTopRevId); } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; }
最主要是我想的逻辑。写起代码来很简单。关键就是我们程序员的思维能不能跟得上。
转载请注明出处:http://www.cnblogs.com/huole/p/5757746.html