From a6673284d4ec0b7c11079c65d940c9443d86d11e Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期三, 06 三月 2019 15:21:48 +0800 Subject: [PATCH] 冲突 --- fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java | 135 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 110 insertions(+), 25 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java index 5e0f2c0..59b0c0c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java @@ -11,6 +11,7 @@ import java.util.Set; import javax.annotation.Resource; +import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,6 +32,7 @@ import com.yeshi.fanli.entity.bus.msg.MsgInviteDetail; import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail; import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail; +import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail; import com.yeshi.fanli.entity.bus.msg.UserMsgUnReadNum; import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; import com.yeshi.fanli.entity.goods.CommonGoods; @@ -48,11 +50,13 @@ import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService; import com.yeshi.fanli.service.inter.msg.MsgMoneyDetailService; import com.yeshi.fanli.service.inter.msg.MsgOrderDetailService; +import com.yeshi.fanli.service.inter.msg.MsgOtherDetailService; import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService; import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; import com.yeshi.fanli.service.inter.user.UserCustomSettingsService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; @@ -82,6 +86,9 @@ private MsgAccountDetailService msgAccountDetailService; @Resource + private MsgOtherDetailService msgOtherDetailService; + + @Resource private UserMsgReadStateService userMsgReadStateService; @Resource @@ -102,22 +109,27 @@ @Resource private UserCustomSettingsService userCustomSettingsService; + @Resource + private RedisManager redisManager; + // 娑堟伅鐨勭被鍨� final static String MSG_TYPE_ORDER = "order"; final static String MSG_TYPE_MONEY = "money"; final static String MSG_TYPE_ACCOUNT = "account"; final static String MSG_TYPE_INVITE = "invite"; + final static String MSG_TYPE_OTHER = "other"; /** - * 鑾峰彇璁㈠崟娑堟伅鍒楄〃 + * 鑾峰彇娑堟伅鍒楄〃 * * @param acceptData * @param uid * @param page + * @param type * @param out */ @RequestMapping(value = "getMsgList", method = RequestMethod.POST) - public void getOrderMsgList(AcceptData acceptData, Long uid, int page, String type, PrintWriter out) { + public void getMsgList(AcceptData acceptData, Long uid, int page, String type, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); @@ -162,8 +174,26 @@ List<MsgInviteDetail> detailList3 = msgInviteDetailService.listMsgInviteDetail(uid, page); count = msgInviteDetailService.countMsgInviteDetail(uid); if (detailList3 != null) - for (MsgInviteDetail detail : detailList3) - list.add(UserMsgVOFactory.create(detail)); + for (MsgInviteDetail detail : detailList3) { + UserMsgVO vo = UserMsgVOFactory.create(detail); + if (vo != null) + list.add(vo); + else + count--; + } + break; + case MSG_TYPE_OTHER: + userMsgReadStateService.readOtherMsg(uid); + List<MsgOtherDetail> detailList4 = msgOtherDetailService.listMsgOtherDetail(uid, page); + count = msgOtherDetailService.countMsgOtherDetail(uid); + if (detailList4 != null) + for (MsgOtherDetail detail : detailList4) { + UserMsgVO vo = UserMsgVOFactory.create(detail); + if (vo != null) + list.add(vo); + else + count--; + } break; } @@ -189,9 +219,30 @@ return; } UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid); - JSONObject data = JSONObject.fromObject(JsonUtil.getApiCommonGson().toJson(num)); - data.put("totalCount", num.getTypeAccount() + num.getTypeInvite() + num.getTypeMoney() + num.getTypeOrder() - + num.getTypeScore() + num.getTypeSystem()); + + GsonBuilder androidBuilder = new GsonBuilder().registerTypeAdapter(Integer.class, + new JsonSerializer<Integer>() { + @Override + public JsonElement serialize(Integer value, Type theType, JsonSerializationContext context) { + if (value == null) { + return new JsonPrimitive("0"); + } else { + if (value >= 100) + return new JsonPrimitive("99+"); + else + return new JsonPrimitive(value); + } + } + }); + int totalCount = num.getTypeAccount() + num.getTypeInvite() + num.getTypeMoney() + num.getTypeOrder() + + num.getTypeScore() + num.getTypeSystem() + num.getTypeOther(); + JSONObject data = null; + if ("android".equalsIgnoreCase(acceptData.getPlatform())) { + data = JSONObject.fromObject(androidBuilder.excludeFieldsWithoutExposeAnnotation().create().toJson(num)); + } else { + data = JSONObject.fromObject(JsonUtil.getApiCommonGson().toJson(num)); + } + data.put("totalCount", totalCount); try { UserSettingsVO vo = userCustomSettingsService.getMySettings(uid); @@ -331,7 +382,7 @@ * @param out */ @RequestMapping(value = "getHomeMsgList", method = RequestMethod.POST) - public void getHomeMsgList(AcceptData acceptData, Long uid, int page, PrintWriter out) { + public void getHomeMsgList(AcceptData acceptData, Long uid, int page, HttpSession session, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); return; @@ -345,22 +396,35 @@ canAdd = true; } else { // 鏄惁鍜屼笂娆¢棿闅旀椂闂磋冻澶� - if (System.currentTimeMillis() - goods.getCreateTime().getTime() >= 1000 * 60 * 60 * 8L) { + if (System.currentTimeMillis() - goods.getCreateTime().getTime() >= 1000 * 60 * 60 * 4L) { canAdd = true; } } - if (canAdd) { - if (hour < 12) - addRecommendGoods(uid); - else - addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa()); + String key = "recommend-goods-user-" + uid; + if (Constant.IS_OUTNET) { + if (canAdd && StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) { + if (Constant.IS_OUTNET) + redisManager.cacheCommonString(key, "1", 20); + if (hour < 12) + addRecommendGoods(uid); + else + addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa()); + session.removeAttribute("recommendgoods"); + } + } else { + if (canAdd) { + if (hour < 12) + addRecommendGoods(uid); + else + addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa()); + } } } List<UserHomeMsgVO> volist = new ArrayList<>(); List<RecommendUserGoods> list = recommendUserGoodsService.listRecommend(uid, page, Constant.PAGE_SIZE); - long count = recommendUserGoodsService.countRecommend(uid) + 1;// 璁$畻娆㈣繋璇殑鏁伴噺 + long count = recommendUserGoodsService.countRecommend(uid);// Date now = new Date(); for (RecommendUserGoods goods : list) { @@ -376,11 +440,17 @@ List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); for (CommonGoods cg : goods.getGoodsList()) { if (goods.getGoodsList().size() == 1) - cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 400)); + cg.setPicture(TbImgUtil.getTBSizeImg( + StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(), + 400)); else if (goods.getGoodsList().size() == 2) - cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 320)); + cg.setPicture(TbImgUtil.getTBSizeImg( + StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(), + 320)); else if (goods.getGoodsList().size() == 3) - cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 220)); + cg.setPicture(TbImgUtil.getTBSizeImg( + StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(), + 220)); TaoBaoGoodsBrief tbGoods = new TaoBaoGoodsBrief(); if (cg.getCouponAmount() == null) tbGoods.setCouponAmount(new BigDecimal(0)); @@ -397,14 +467,21 @@ volist.add(vo); } + Long time = userInfoService.selectByPKey(uid).getCreatetime(); + if (time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd")) + count++;// 璁$畻娆㈣繋璇殑鏁伴噺 + if (volist.size() > 0 && volist.size() < Constant.PAGE_SIZE) { // 娣诲姞娆㈣繋璇� - UserHomeMsgVO vo = new UserHomeMsgVO(); - vo.setContent("鎭枩浣狅紝鎴愪负杩斿埄鍒哥殑鐢ㄦ埛\n鐙浼樻儬鍒稿府浣犵渷閽憋紱\n鍙備笌濂栭噾娲诲姩甯綘璧氶挶锛沑n璁╄繑鍒╁埜鎴愪负浣犵殑鐪侀挶鍔╂墜鍚э紒"); - vo.setTitle("鏂颁汉娆㈣繋"); - vo.setCreateTime(getTimeDesc(now, new Date(userInfoService.getUserById(uid).getCreatetime()))); - vo.setType(UserHomeMsgVO.TYPE_WELCOME); - volist.add(vo); + // 鍒涘缓鏃堕棿鍦�28鍙峰悗鐨勬墠鏈夋柊浜烘杩� + if (time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd")) { + UserHomeMsgVO vo = new UserHomeMsgVO(); + vo.setContent("鎭枩浣狅紝鎴愪负杩斿埄鍒哥殑鐢ㄦ埛\n鐙浼樻儬鍒稿府浣犵渷閽憋紱\n鍙備笌濂栭噾娲诲姩甯綘璧氶挶锛沑n璁╄繑鍒╁埜鎴愪负浣犵殑鐪侀挶鍔╂墜鍚э紒"); + vo.setTitle("鏂颁汉娆㈣繋"); + vo.setCreateTime(getTimeDesc(now, new Date(time))); + vo.setType(UserHomeMsgVO.TYPE_WELCOME); + volist.add(vo); + } } JSONObject root = new JSONObject(); @@ -491,7 +568,15 @@ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); return; } - userMsgReadStateService.setAllMsgRead(uid); + + UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid); + int totalNum = num.getTypeAccount() + num.getTypeInvite() + num.getTypeMoney() + num.getTypeOrder() + + num.getTypeScore() + num.getTypeSystem() + num.getTypeOther(); + if (totalNum == 0) { + out.print(JsonUtil.loadFalseResult(1, "娌℃湁鏈娑堟伅")); + return; + } else + userMsgReadStateService.setAllMsgRead(uid); out.print(JsonUtil.loadTrueResult("")); } -- Gitblit v1.8.0