From cdcbed9af813b2a02cdc01eefa24db8bec6b51a9 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期三, 27 三月 2019 12:17:33 +0800
Subject: [PATCH] 主分类 + 子分类 DAO改造

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java |  115 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 87 insertions(+), 28 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 363f51c..e5a316c 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
@@ -32,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;
@@ -49,6 +50,7 @@
 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;
@@ -84,6 +86,9 @@
 	private MsgAccountDetailService msgAccountDetailService;
 
 	@Resource
+	private MsgOtherDetailService msgOtherDetailService;
+
+	@Resource
 	private UserMsgReadStateService userMsgReadStateService;
 
 	@Resource
@@ -112,17 +117,19 @@
 	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, "鐢ㄦ埛鏈櫥褰�"));
@@ -175,6 +182,19 @@
 						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;
 		}
 
 		GsonBuilder builder = new GsonBuilder();
@@ -199,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);
@@ -254,7 +295,7 @@
 		return builder;
 	}
 
-	private void addRecommendGoods(Long uid, String imei, String idfa) {
+	private void addRecommendGoods(Long uid, String device, String imei, String idfa) {
 		TaoBaoSearchResult result = TaoKeApiUtil.guessDeviceLike(1, 50, imei, idfa);
 		if (result != null && result.getTaoBaoGoodsBriefs() != null) {
 			for (int i = 0; i < result.getTaoBaoGoodsBriefs().size(); i++) {
@@ -285,7 +326,7 @@
 					}
 				}
 				try {
-					recommendUserGoodsService.addRecommend(uid, "", goodsList);
+					recommendUserGoodsService.addRecommend(uid, device, "", goodsList);
 				} catch (RecommendUserGoodsException e) {
 					e.printStackTrace();
 				}
@@ -293,7 +334,7 @@
 		}
 	}
 
-	private void addRecommendGoods(Long uid) {
+	private void addRecommendGoods(Long uid, String device) {
 		List<QualityFactory> qfList = qualityFactoryService.listByMinSalesCountOrderByCreateTimeDesc(10000, 1, 20);
 		if (qfList != null && qfList != null) {
 			for (int i = 0; i < qfList.size(); i++) {
@@ -324,7 +365,7 @@
 					}
 				}
 				try {
-					recommendUserGoodsService.addRecommend(uid, "", goodsList);
+					recommendUserGoodsService.addRecommend(uid, device, "", goodsList);
 				} catch (RecommendUserGoodsException e) {
 					e.printStackTrace();
 				}
@@ -342,15 +383,21 @@
 	 */
 	@RequestMapping(value = "getHomeMsgList", method = RequestMethod.POST)
 	public void getHomeMsgList(AcceptData acceptData, Long uid, int page, HttpSession session, PrintWriter out) {
-		if (uid == null) {
-			out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+
+		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.getLatestRecommendUserGoods(uid);
+			RecommendUserGoods goods = recommendUserGoodsService.getLatestRecommendUserGoodsByDevice(device);
+
 			if (goods == null) {
 				canAdd = true;
 			} else {
@@ -360,20 +407,33 @@
 				}
 			}
 
-			String key = "recommend-goods-user-" + uid;
-			if (canAdd && StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
-				redisManager.cacheCommonString(key, "1", 20);
-				if (hour < 12)
-					addRecommendGoods(uid);
-				else
-					addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa());
-				session.removeAttribute("recommendgoods");
+			// String key = "recommend-goods-user-" + uid;
+			String key = "recommend-goods-user-" + device;
+			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, device);
+					else
+						addRecommendGoods(uid, device, acceptData.getImei(), acceptData.getIdfa());
+					session.removeAttribute("recommendgoods");
+				}
+			} else {
+				if (canAdd) {
+					if (hour < 12)
+						addRecommendGoods(uid, device);
+					else
+						addRecommendGoods(uid, device, acceptData.getImei(), acceptData.getIdfa());
+				}
 			}
 		}
 
 		List<UserHomeMsgVO> volist = new ArrayList<>();
-		List<RecommendUserGoods> list = recommendUserGoodsService.listRecommend(uid, page, Constant.PAGE_SIZE);
-		long count = recommendUserGoodsService.countRecommend(uid);//
+
+		List<RecommendUserGoods> list = recommendUserGoodsService.listRecommendGoodsByDevice(device, page,
+				Constant.PAGE_SIZE);
+		long count = recommendUserGoodsService.countRecommendGoodsByDevice(device);
 
 		Date now = new Date();
 		for (RecommendUserGoods goods : list) {
@@ -416,26 +476,25 @@
 			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++;
 			}
 		}
 
 		JSONObject root = new JSONObject();
 		root.put("msgList", new Gson().toJson(volist));
-		if (page == 1) {
+		if (page == 1 && uid != null) {
 			UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid);
 			UserSystemMsg usm = userSystemMsgService.getLatestUserSystemMsg(uid);
 			if (usm != null)
@@ -520,7 +579,7 @@
 
 		UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid);
 		int totalNum = num.getTypeAccount() + num.getTypeInvite() + num.getTypeMoney() + num.getTypeOrder()
-				+ num.getTypeScore() + num.getTypeSystem();
+				+ num.getTypeScore() + num.getTypeSystem() + num.getTypeOther();
 		if (totalNum == 0) {
 			out.print(JsonUtil.loadFalseResult(1, "娌℃湁鏈娑堟伅"));
 			return;

--
Gitblit v1.8.0