From e61108b9d44f0afc0c303db8914ebcc590c7013d Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期五, 19 四月 2019 18:12:50 +0800
Subject: [PATCH] 微信激活、绑定优化
---
fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java | 188 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 178 insertions(+), 10 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 f83d1dc..bfd0b6e 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
@@ -5,9 +5,13 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
@@ -27,6 +31,7 @@
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.yeshi.fanli.entity.accept.AcceptData;
+import com.yeshi.fanli.entity.bus.homemodule.Special;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
import com.yeshi.fanli.entity.bus.msg.MsgInviteDetail;
@@ -35,6 +40,7 @@
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.taobao.TaoBaoGoodsBrief;
@@ -43,8 +49,10 @@
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.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService;
+import com.yeshi.fanli.service.inter.homemodule.SpecialService;
import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
import com.yeshi.fanli.service.inter.msg.MsgAccountDetailService;
import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService;
@@ -63,6 +71,7 @@
import com.yeshi.fanli.util.factory.msg.UserMsgVOFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.msg.UserHomeMsgVO;
+import com.yeshi.fanli.vo.msg.UserMsgCenter;
import com.yeshi.fanli.vo.msg.UserMsgVO;
import com.yeshi.fanli.vo.msg.UserSystemMsgVO;
import com.yeshi.fanli.vo.user.UserSettingsVO;
@@ -73,6 +82,8 @@
@RequestMapping("api/v1/user/msg")
public class UserMsgController {
+ @Resource
+ private BusinessSystemService businessSystemService;
@Resource
private MsgOrderDetailService msgOrderDetailService;
@@ -111,6 +122,10 @@
@Resource
private RedisManager redisManager;
+
+ @Resource
+ private SpecialService specialService;
+
// 娑堟伅鐨勭被鍨�
final static String MSG_TYPE_ORDER = "order";
@@ -383,18 +398,21 @@
*/
@RequestMapping(value = "getHomeMsgList", method = RequestMethod.POST)
public void getHomeMsgList(AcceptData acceptData, Long uid, int page, HttpSession session, PrintWriter out) {
-
+
String device = acceptData.getDevice();
if (device == null || device.trim().length() == 0) {
out.print(JsonUtil.loadFalseResult("璁惧鍙蜂笉鑳戒负绌�"));
return;
}
-
+
if (page == 1) {
+ if (uid != null)
+ recommendUserGoodsService.syncDeviceAndUid(uid, acceptData.getDevice());
+
boolean canAdd = false;
int hour = Calendar.getInstance().get(Calendar.HOUR);
RecommendUserGoods goods = recommendUserGoodsService.getLatestRecommendUserGoodsByDevice(device);
-
+
if (goods == null) {
canAdd = true;
} else {
@@ -404,7 +422,7 @@
}
}
- //String key = "recommend-goods-user-" + uid;
+ // String key = "recommend-goods-user-" + uid;
String key = "recommend-goods-user-" + device;
if (Constant.IS_OUTNET) {
if (canAdd && StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
@@ -427,8 +445,9 @@
}
List<UserHomeMsgVO> volist = new ArrayList<>();
-
- List<RecommendUserGoods> list = recommendUserGoodsService.listRecommendGoodsByDevice(device, page, Constant.PAGE_SIZE);
+
+ List<RecommendUserGoods> list = recommendUserGoodsService.listRecommendGoodsByDevice(device, page,
+ Constant.PAGE_SIZE);
long count = recommendUserGoodsService.countRecommendGoodsByDevice(device);
Date now = new Date();
@@ -472,20 +491,19 @@
volist.add(vo);
}
- Long time = userInfoService.selectByPKey(uid).getCreatetime();
- if (time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd"))
- count++;// 璁$畻娆㈣繋璇殑鏁伴噺
+ Long time = (uid == null ? System.currentTimeMillis() : userInfoService.selectByPKey(uid).getCreatetime());
if (volist.size() > 0 && volist.size() < Constant.PAGE_SIZE) {
// 娣诲姞娆㈣繋璇�
// 鍒涘缓鏃堕棿鍦�28鍙峰悗鐨勬墠鏈夋柊浜烘杩�
- if (time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd")) {
+ if ((time > TimeUtil.convertToTimeTemp("2019-01-28", "yyyy-MM-dd") || uid == null)) {
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);
+ count++;
}
}
@@ -504,7 +522,157 @@
root.put("count", count);
out.print(JsonUtil.loadTrueResult(root));
}
+
+
+ /**
+ * 鑾峰彇娑堟伅鍒楄〃
+ *
+ * @param acceptData
+ * @param uid
+ * @param page
+ * @param type
+ * @param out
+ */
+ @RequestMapping(value = "getHomeMsgListNew", method = RequestMethod.POST)
+ public void getHomeMsgListNew(AcceptData acceptData, Long uid, PrintWriter out) {
+
+ List<UserMsgCenter> listCenter = new ArrayList<>();
+
+ // 1銆佹椿鍔ㄥ尯鍩�
+ List<Special> listSpecial = specialService.listByPlaceKey("msg_activities");
+ if (listSpecial != null && listSpecial.size() > 0) {
+ 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);
+ }
+ }
+
+ // 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);
+ }
+ }
+ 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));
+ UserMsgCenter msgCenternre = new UserMsgCenter();
+ msgCenternre.setWelcomeMsg(map);
+ listCenter.add(msgCenternre);
+ }
+
+ GsonBuilder builder = new GsonBuilder();
+ builder = getTimeDescJsonBuilder(builder);
+ JSONObject root = new JSONObject();
+
+ 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("count", listCenter.size());
+ out.print(JsonUtil.loadTrueResult(root));
+ }
+
+
+ public static void listSort(List<UserMsgVO> list) {
+ Collections.sort(list, new Comparator<UserMsgVO>() {
+ @Override
+ public int compare(UserMsgVO o1, UserMsgVO o2) {
+ if (o1.getTime().getTime() > o2.getTime().getTime()) {
+ return -1;
+ } else if (o1 == o2) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+ });
+ }
+
+
/**
* 鑾峰彇绯荤粺娑堟伅鍒楄〃
*
--
Gitblit v1.8.0