admin
2019-05-05 81082e03207761edff6b317df8268dc3f968c20a
fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java
@@ -40,15 +40,16 @@
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.common.JumpDetailV2;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.goods.RecommendUserGoods;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.exception.goods.RecommendUserGoodsException;
import com.yeshi.fanli.exception.msg.UserSystemMsgException;
import com.yeshi.fanli.exception.user.UserCustomSettingsException;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService;
@@ -61,6 +62,7 @@
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.push.PushGoodsService;
import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
@@ -70,6 +72,7 @@
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
import com.yeshi.fanli.util.factory.msg.UserMsgVOFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.msg.UserCommonMsgVO;
import com.yeshi.fanli.vo.msg.UserHomeMsgVO;
import com.yeshi.fanli.vo.msg.UserMsgCenter;
import com.yeshi.fanli.vo.msg.UserMsgVO;
@@ -122,10 +125,15 @@
   @Resource
   private RedisManager redisManager;
   @Resource
   private SpecialService specialService;
   @Resource
   private JumpDetailV2Service jumpDetailV2Service;
   @Resource
   private PushGoodsService pushGoodsService;
   // 消息的类型
   final static String MSG_TYPE_ORDER = "order";
@@ -398,7 +406,8 @@
    */
   @RequestMapping(value = "getHomeMsgList", method = RequestMethod.POST)
   public void getHomeMsgList(AcceptData acceptData, Long uid, int page, HttpSession session, PrintWriter out) {
      if (uid != null && uid == 0)
         uid = null;
      String device = acceptData.getDevice();
      if (device == null || device.trim().length() == 0) {
         out.print(JsonUtil.loadFalseResult("设备号不能为空"));
@@ -522,8 +531,7 @@
      root.put("count", count);
      out.print(JsonUtil.loadTrueResult(root));
   }
   /**
    * 获取消息列表
    * 
@@ -535,121 +543,144 @@
    */
   @RequestMapping(value = "getHomeMsgListNew", method = RequestMethod.POST)
   public void getHomeMsgListNew(AcceptData acceptData, Long uid, PrintWriter out) {
      if (uid != null && uid == 0)
         uid = null;
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
         return;
      }
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
         return;
      }
      int page = 1;
      List<UserMsgVO> list = new ArrayList<>();
      List<MsgOrderDetail> detailList = msgOrderDetailService.listMsgOrderDetail(uid, page);
      if (detailList != null && detailList.size() > 0) {
         for (MsgOrderDetail detail : detailList) {
            list.add(UserMsgVOFactory.create(detail));
         }
      }
      List<MsgMoneyDetail> detailList1 = msgMoneyDetailService.listMsgMoneyDetail(uid, page);
      if (detailList1 != null && detailList1.size() > 0) {
         for (MsgMoneyDetail detail : detailList1) {
            list.add(UserMsgVOFactory.create(detail));
         }
      }
      List<MsgAccountDetail> detailList2 = msgAccountDetailService.listMsgAccountDetail(uid, page);
      if (detailList2 != null && detailList2.size() > 0) {
         for (MsgAccountDetail detail : detailList2) {
            list.add(UserMsgVOFactory.create(detail));
         }
      }
      List<MsgInviteDetail> detailList3 = msgInviteDetailService.listMsgInviteDetail(uid, page);
      if (detailList3 != null && detailList3.size() > 0) {
         for (MsgInviteDetail detail : detailList3) {
            UserMsgVO vo = UserMsgVOFactory.create(detail);
            if (vo != null) {
               list.add(vo);
            }
         }
      }
      List<MsgOtherDetail> detailList4 = msgOtherDetailService.listMsgOtherDetail(uid, page);
      if (detailList4 != null && detailList4.size() > 0) {
         for (MsgOtherDetail detail : detailList4) {
            UserMsgVO vo = UserMsgVOFactory.create(detail);
            if (vo != null) {
               list.add(vo);
            }
         }
      }
      List<UserMsgCenter> listCenter = new ArrayList<>();
      List<Special> listSpecial = specialService.listBySystemAndCard("", system.getId());
      // 单条消息
      List<UserCommonMsgVO> commonMsgList = new ArrayList<>();
      commonMsgList.add(new UserCommonMsgVO("http://img.flqapp.com/resource/msg/icon_kefu.png", "人工客服", new Date(),
            UserCommonMsgVO.TYPE_KEFU, "", false, null, null));
      // 推荐记录
      // list = pushGoodsService.listHistoryByPushTime(0, 1, uid, createTime);
      commonMsgList.add(new UserCommonMsgVO("http://img.flqapp.com/resource/msg/icon_recommend.png", "推荐记录",
            new Date(), UserCommonMsgVO.TYPE_RECOMMEND, "防油防水防潮,污渍一抹即净,从胃到心的暖意", false,
            jumpDetailV2Service.getByTypeCache("recommend_list"), null));
      // 1、活动区域
      List<Special> listSpecial = specialService.listByPlaceKey("msg_activities");
      if (listSpecial != null && listSpecial.size() > 0) {
         for (Special special: listSpecial) {
         for (Special special : listSpecial) {
            boolean needLogin = special.isJumpLogin();
            JumpDetailV2 jumpDetail = special.getJumpDetail();
            if (jumpDetail != null) {
               jumpDetail.setNeedLogin(needLogin);
               special.setJumpDetail(jumpDetail);
            }
            UserMsgCenter msgCenter = new UserMsgCenter();
            msgCenter.setSpecial(special);
            listCenter.add(msgCenter);
         }
      }
      if (list.size() > 0 ) {
         // 时间排序
         listSort(list);
         if (list.size() <= 20 ) {
         } else {
            list = list.subList(0, 19);
      // 2、消息区域
      if (uid != null && uid > 0) {
         int page = 1;
         List<UserMsgVO> list = new ArrayList<>();
         List<MsgOrderDetail> detailList = msgOrderDetailService.listMsgOrderDetail(uid, page);
         if (detailList != null && detailList.size() > 0) {
            for (MsgOrderDetail detail : detailList) {
               UserMsgVO userMsgVO = UserMsgVOFactory.create(detail);
               userMsgVO.setType(MSG_TYPE_ORDER);
               list.add(userMsgVO);
            }
         }
         for (UserMsgVO userMsgVO: list) {
            UserMsgCenter userMsgCenter = new UserMsgCenter();
            userMsgCenter.setUserMsg(userMsgVO);
            listCenter.add(userMsgCenter);
         List<MsgMoneyDetail> detailList1 = msgMoneyDetailService.listMsgMoneyDetail(uid, page);
         if (detailList1 != null && detailList1.size() > 0) {
            for (MsgMoneyDetail detail : detailList1) {
               UserMsgVO userMsgVO = UserMsgVOFactory.create(detail);
               userMsgVO.setType(MSG_TYPE_MONEY);
               list.add(userMsgVO);
            }
         }
         List<MsgAccountDetail> detailList2 = msgAccountDetailService.listMsgAccountDetail(uid, page);
         if (detailList2 != null && detailList2.size() > 0) {
            for (MsgAccountDetail detail : detailList2) {
               UserMsgVO userMsgVO = UserMsgVOFactory.create(detail);
               userMsgVO.setType(MSG_TYPE_ACCOUNT);
               list.add(userMsgVO);
            }
         }
         List<MsgInviteDetail> detailList3 = msgInviteDetailService.listMsgInviteDetail(uid, page);
         if (detailList3 != null && detailList3.size() > 0) {
            for (MsgInviteDetail detail : detailList3) {
               UserMsgVO userMsgVO = UserMsgVOFactory.create(detail);
               if (userMsgVO != null) {
                  userMsgVO.setType(MSG_TYPE_INVITE);
                  list.add(userMsgVO);
               }
            }
         }
         List<MsgOtherDetail> detailList4 = msgOtherDetailService.listMsgOtherDetail(uid, page);
         if (detailList4 != null && detailList4.size() > 0) {
            for (MsgOtherDetail detail : detailList4) {
               UserMsgVO userMsgVO = UserMsgVOFactory.create(detail);
               if (userMsgVO != null) {
                  userMsgVO.setType(MSG_TYPE_OTHER);
                  list.add(userMsgVO);
               }
            }
         }
         if (list.size() > 0) {
            // 时间排序
            listSort(list);
            if (list.size() >= 20) {
               list = list.subList(0, 19);
            }
            for (UserMsgVO userMsgVO : list) {
               UserMsgCenter userMsgCenter = new UserMsgCenter();
               userMsgCenter.setUserMsg(userMsgVO);
               listCenter.add(userMsgCenter);
            }
         }
      }
      // 添加欢迎语
      // 3、添加欢迎语
      Long time = (uid == null ? System.currentTimeMillis() : userInfoService.selectByPKey(uid).getCreatetime());
      // 创建时间在28号后的才有新人欢迎
      if ((time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd") || uid == null)) {
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("title", "新人欢迎");
         map.put("content", "恭喜你,成为返利券的用户\n独家优惠券帮你省钱;\n参与奖金活动帮你赚钱;\n让返利券成为你的省钱助手吧!");
         map.put("createTime",new Date(time));
         map.put("createTime", new Date(time));
         UserMsgCenter msgCenternre = new UserMsgCenter();
         msgCenternre.setWelcomeMsg(map);
         listCenter.add(msgCenternre);
      }
      GsonBuilder builder = new GsonBuilder();
      builder = getTimeDescJsonBuilder(builder);
      JSONObject root = new JSONObject();
      UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid);
      UserSystemMsg usm = userSystemMsgService.getLatestUserSystemMsg(uid);
      if (usm != null) {
         root.put("systemMsg", new UserSystemMsgVO(usm.getId(), usm.getType().name(), usm.getSolved(), "系统消息", usm.getTitle(),
            usm.getTimeTag() == 1 ? "http://img.flqapp.com/resource/msg/icon_emergent.png" : "", "http://img.flqapp.com/resource/msg/icon_msg_system.png",getTimeDesc(new Date(), usm.getCreateTime()), num.getTypeSystem()));
      if (uid != null && uid > 0) {
         UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid);
         UserSystemMsg usm = userSystemMsgService.getLatestUserSystemMsg(uid);
         if (usm != null) {
            root.put("systemMsg",
                  new UserSystemMsgVO(usm.getId(), usm.getType().name(), usm.getSolved(), "系统消息", usm.getTitle(),
                        usm.getTimeTag() == 1 ? "http://img.flqapp.com/resource/msg/icon_emergent.png" : "",
                        "http://img.flqapp.com/resource/msg/icon_msg_system.png",
                        getTimeDesc(new Date(), usm.getCreateTime()), num.getTypeSystem()));
         }
      }
      root.put("list", builder.create().toJson(listCenter));
      root.put("commonList", builder.create().toJson(commonMsgList));
      root.put("count", listCenter.size());
      out.print(JsonUtil.loadTrueResult(root));
   }
   public static void listSort(List<UserMsgVO> list) {
      Collections.sort(list, new Comparator<UserMsgVO>() {
@@ -665,8 +696,7 @@
         }
      });
   }
   /**
    * 获取系统消息列表
    *