From 1bcfd2d6949bff749cec105f2f56d107edb519e5 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 14 三月 2019 10:48:19 +0800
Subject: [PATCH] 增加配置信息
---
fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java | 568 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 526 insertions(+), 42 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 4a827bf..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
@@ -4,96 +4,580 @@
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+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;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.taobao.TbImgUtil;
+import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.yeshi.fanli.entity.accept.AcceptData;
-import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
-import com.yeshi.fanli.vo.msg.CommonMsgItemVO;
+import com.yeshi.fanli.entity.bus.lable.QualityFactory;
+import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
+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;
+import com.yeshi.fanli.entity.goods.RecommendUserGoods;
+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.goods.CommonGoodsService;
+import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService;
+import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
+import com.yeshi.fanli.service.inter.msg.MsgAccountDetailService;
+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;
+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.UserMsgVO;
+import com.yeshi.fanli.vo.msg.UserSystemMsgVO;
+import com.yeshi.fanli.vo.user.UserSettingsVO;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v1/user/msg")
public class UserMsgController {
+
+ @Resource
+ private MsgOrderDetailService msgOrderDetailService;
+
+ @Resource
+ private MsgMoneyDetailService msgMoneyDetailService;
+
+ @Resource
+ private MsgInviteDetailService msgInviteDetailService;
+
+ @Resource
+ private MsgAccountDetailService msgAccountDetailService;
+
+ @Resource
+ private MsgOtherDetailService msgOtherDetailService;
+
+ @Resource
+ private UserMsgReadStateService userMsgReadStateService;
+
+ @Resource
+ private RecommendUserGoodsService recommendUserGoodsService;
+
+ @Resource
+ private UserInfoService userInfoService;
+
+ @Resource
+ private UserSystemMsgService userSystemMsgService;
+
+ @Resource
+ private CommonGoodsService commonGoodsService;
+
+ @Resource
+ private QualityFactoryService qualityFactoryService;
+
+ @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 = "getOrderMsgList", method = RequestMethod.POST)
- public void getOrderMsgList(AcceptData acceptData, Long uid, int page, PrintWriter out) {
+ @RequestMapping(value = "getMsgList", method = RequestMethod.POST)
+ public void getMsgList(AcceptData acceptData, Long uid, int page, String type, PrintWriter out) {
if (uid == null) {
out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
return;
}
+ if (StringUtil.isNullOrEmpty(type)) {
+ out.print(JsonUtil.loadFalseResult(2, "璇蜂笂浼爐ype"));
+ return;
+ }
+
List<UserMsgVO> list = new ArrayList<>();
+ long count = 0;
- List<CommonMsgItemVO> items = new ArrayList<>();
+ switch (type) {
+ case MSG_TYPE_ORDER:
+ userMsgReadStateService.readOrderMsg(uid);
+ List<MsgOrderDetail> detailList = msgOrderDetailService.listMsgOrderDetail(uid, page);
+ count = msgOrderDetailService.countMsgOrderDetail(uid);
+ if (detailList != null)
+ for (MsgOrderDetail detail : detailList)
+ list.add(UserMsgVOFactory.create(detail));
+ break;
+ case MSG_TYPE_MONEY:
+ userMsgReadStateService.readMoneyMsg(uid);
+ List<MsgMoneyDetail> detailList1 = msgMoneyDetailService.listMsgMoneyDetail(uid, page);
+ count = msgMoneyDetailService.countMsgMoneyDetail(uid);
+ if (detailList1 != null)
+ for (MsgMoneyDetail detail : detailList1)
+ list.add(UserMsgVOFactory.create(detail));
+ break;
+ case MSG_TYPE_ACCOUNT:
+ userMsgReadStateService.readAccountMsg(uid);
+ List<MsgAccountDetail> detailList2 = msgAccountDetailService.listMsgAccountDetail(uid, page);
+ count = msgAccountDetailService.countMsgAccountDetail(uid);
+ if (detailList2 != null)
+ for (MsgAccountDetail detail : detailList2)
+ list.add(UserMsgVOFactory.create(detail));
+ break;
+ case MSG_TYPE_INVITE:
+ userMsgReadStateService.readInviteMsg(uid);
+ List<MsgInviteDetail> detailList3 = msgInviteDetailService.listMsgInviteDetail(uid, page);
+ count = msgInviteDetailService.countMsgInviteDetail(uid);
+ if (detailList3 != null)
+ 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;
+ }
- List<ClientTextStyleVO> contentList = new ArrayList<>();
- contentList.add(new ClientTextStyleVO("206089388856584237", "#000000"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("璁㈠崟鍙�", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("鍏�", "#000000"));
- contentList.add(new ClientTextStyleVO("1", "#E5005C"));
- contentList.add(new ClientTextStyleVO("浠跺晢鍝�", "#000000"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("鍟嗗搧鏁伴噺", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("閭�璇疯鍗�", "#000000"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("璁㈠崟绫诲瀷", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("宸蹭粯娆�", "#E5005C"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("璁㈠崟鐘舵��", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("锟�58", "#E5005C"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("浠樻閲戦", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("锟�0.36", "#E5005C"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("閭�璇峰閲�", "#888888"), contentList));
-
- contentList.clear();
- contentList.add(new ClientTextStyleVO("鏃�", "#000000"));
- items.add(new CommonMsgItemVO(new ClientTextStyleVO("澶囨敞", "#888888"), contentList));
-
- list.add(new UserMsgVO("http://ec-1255749512.file.myqcloud.com/resource/portrait.png", "璁㈠崟娑堟伅", new Date(),
- items));
GsonBuilder builder = new GsonBuilder();
- builder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<Date>() {
+ builder = getTimeDescJsonBuilder(builder);
+ JSONObject root = new JSONObject();
+ root.put("data", builder.create().toJson(list));
+ root.put("count", count);
+ out.print(JsonUtil.loadTrueResult(root));
+ }
+
+ /**
+ * 鑾峰彇娑堟伅鏈鏁�
+ *
+ * @param acceptData
+ * @param uid
+ * @param out
+ */
+ @RequestMapping(value = "getUnReadMsgCount", method = RequestMethod.POST)
+ public void getUnReadMsgCount(AcceptData acceptData, Long uid, PrintWriter out) {
+ if (uid == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+ UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid);
+
+ 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);
+ if (vo != null && vo.getNoNewsRedDot() != null && vo.getNoNewsRedDot() == 1) {
+ data.put("totalCount", 0);
+ }
+ } catch (UserCustomSettingsException e) {
+ e.printStackTrace();
+ }
+
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+
+ private String getTimeDesc(Date nowDate, Date targetDate) {
+ Calendar now = Calendar.getInstance();
+ now.setTime(nowDate);
+ if (TimeUtil.getGernalTime(targetDate.getTime(), "yyyy-MM-dd")
+ .equalsIgnoreCase(TimeUtil.getGernalTime(now.getTimeInMillis(), "yyyy-MM-dd"))) {
+ return "浠婂ぉ " + TimeUtil.getGernalTime(targetDate.getTime(), "HH:mm");
+ } else if (TimeUtil.getGernalTime(targetDate.getTime(), "yyyy-MM-dd")
+ .equalsIgnoreCase(TimeUtil.getGernalTime(now.getTimeInMillis() - 1000 * 60 * 60 * 24L, "yyyy-MM-dd"))) {
+ return "鏄ㄥぉ " + TimeUtil.getGernalTime(targetDate.getTime(), "HH:mm");
+ } else {
+ return TimeUtil.getGernalTime(targetDate.getTime(), "yyyy.MM.dd HH:mm");
+ }
+ }
+
+ private GsonBuilder getTimeDescJsonBuilder(GsonBuilder builder) {
+ builder = builder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
if (value == null) {
return new JsonPrimitive("");
} else {
- return new JsonPrimitive("浠婂ぉ 10:25");
+ Calendar now = Calendar.getInstance();
+ return new JsonPrimitive(getTimeDesc(new Date(now.getTimeInMillis()), value));
+ }
+ }
+ }).registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() {
+ @Override
+ public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) {
+ if (value == null) {
+ return new JsonPrimitive("0");
+ } else {
+ return new JsonPrimitive(BigDecimalUtil.getWithNoZera(value).toString());
}
}
});
+
+ return builder;
+ }
+
+ private void addRecommendGoods(Long uid, 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++) {
+ if (result.getTaoBaoGoodsBriefs().get(i).getCouponAmount() == null
+ || result.getTaoBaoGoodsBriefs().get(i).getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
+ result.getTaoBaoGoodsBriefs().remove(i);
+ i--;
+ }
+ }
+ // 闅忔満鍑犱釜
+ int count = (int) (Math.random() * 3) + 1;
+ Set<Integer> positionList = new HashSet<>();
+ for (int i = 0; i < count; i++)
+ if (result.getTaoBaoGoodsBriefs().size() > 0) {
+ positionList.add((int) (result.getTaoBaoGoodsBriefs().size() * Math.random()));
+ }
+
+ if (positionList != null && positionList.size() > 0) {
+ List<CommonGoods> goodsList = new ArrayList<>();
+ for (Integer p : positionList) {
+ TaoBaoGoodsBrief goodsB = result.getTaoBaoGoodsBriefs().get(p);
+ try {
+ CommonGoods cgoods = commonGoodsService
+ .addOrUpdateCommonGoods(CommonGoodsFactory.create(goodsB));
+ goodsList.add(cgoods);
+ } catch (CommonGoodsException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ recommendUserGoodsService.addRecommend(uid, "", goodsList);
+ } catch (RecommendUserGoodsException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void addRecommendGoods(Long uid) {
+ List<QualityFactory> qfList = qualityFactoryService.listByMinSalesCountOrderByCreateTimeDesc(10000, 1, 20);
+ if (qfList != null && qfList != null) {
+ for (int i = 0; i < qfList.size(); i++) {
+ if (qfList.get(i).getTaoBaoGoodsBrief().getCouponAmount() == null
+ || qfList.get(i).getTaoBaoGoodsBrief().getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
+ qfList.remove(i);
+ i--;
+ }
+ }
+ // 闅忔満鍑犱釜
+ int count = (int) (Math.random() * 3) + 1;
+ Set<Integer> positionList = new HashSet<>();
+ for (int i = 0; i < count; i++)
+ if (qfList.size() > 0) {
+ positionList.add((int) (qfList.size() * Math.random()));
+ }
+
+ if (positionList != null && positionList.size() > 0) {
+ List<CommonGoods> goodsList = new ArrayList<>();
+ for (Integer p : positionList) {
+ TaoBaoGoodsBrief goodsB = qfList.get(p).getTaoBaoGoodsBrief();
+ try {
+ CommonGoods cgoods = commonGoodsService
+ .addOrUpdateCommonGoods(CommonGoodsFactory.create(goodsB));
+ goodsList.add(cgoods);
+ } catch (CommonGoodsException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ recommendUserGoodsService.addRecommend(uid, "", goodsList);
+ } catch (RecommendUserGoodsException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * 鑾峰彇棣栭〉娑堟伅
+ *
+ * @param acceptData
+ * @param uid
+ * @param page
+ * @param out
+ */
+ @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, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ if (page == 1) {
+ boolean canAdd = false;
+ int hour = Calendar.getInstance().get(Calendar.HOUR);
+ RecommendUserGoods goods = recommendUserGoodsService.getLatestRecommendUserGoods(uid);
+ if (goods == null) {
+ canAdd = true;
+ } else {
+ // 鏄惁鍜屼笂娆¢棿闅旀椂闂磋冻澶�
+ if (System.currentTimeMillis() - goods.getCreateTime().getTime() >= 1000 * 60 * 60 * 4L) {
+ canAdd = true;
+ }
+ }
+
+ 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);//
+
+ Date now = new Date();
+ for (RecommendUserGoods goods : list) {
+ UserHomeMsgVO vo = new UserHomeMsgVO();
+ vo.setContent(goods.getRecommendDesc());
+ vo.setCreateTime(getTimeDesc(now, goods.getCreateTime()));
+ if (goods.getGoodsList().size() == 1)
+ vo.setType(UserHomeMsgVO.TYPE_GOODS_1);
+ else if (goods.getGoodsList().size() == 2)
+ vo.setType(UserHomeMsgVO.TYPE_GOODS_2);
+ else if (goods.getGoodsList().size() == 3)
+ vo.setType(UserHomeMsgVO.TYPE_GOODS_3);
+ List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+ for (CommonGoods cg : goods.getGoodsList()) {
+ if (goods.getGoodsList().size() == 1)
+ cg.setPicture(TbImgUtil.getTBSizeImg(
+ StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(),
+ 400));
+ else if (goods.getGoodsList().size() == 2)
+ cg.setPicture(TbImgUtil.getTBSizeImg(
+ StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(),
+ 320));
+ else if (goods.getGoodsList().size() == 3)
+ 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));
+ else
+ tbGoods.setCouponAmount(cg.getCouponAmount());
+ tbGoods.setAuctionId(cg.getGoodsId());
+ tbGoods.setPictUrl(cg.getPicture());
+ goodsList.add(tbGoods);
+ }
+
+ vo.setGoodsList(goodsList);
+ vo.setTitle("鐚滀綘鍠滄");
+ vo.setIcon("http://img.flqapp.com/resource/msg/icon_msg_guess_like.png");
+ 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) {
+ // 娣诲姞娆㈣繋璇�
+ // 鍒涘缓鏃堕棿鍦�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();
- root.put("data", builder.create().toJson(list));
- root.put("count", 1);
+ root.put("msgList", new Gson().toJson(volist));
+ if (page == 1) {
+ 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(now, usm.getCreateTime()), num.getTypeSystem()));
+ }
+ root.put("count", count);
out.print(JsonUtil.loadTrueResult(root));
}
+ /**
+ * 鑾峰彇绯荤粺娑堟伅鍒楄〃
+ *
+ * @param acceptData
+ * @param uid
+ * @param page
+ * @param out
+ */
+ @RequestMapping(value = "getSystemMsgList", method = RequestMethod.POST)
+ public void getSystemMsgList(AcceptData acceptData, Long uid, int page, PrintWriter out) {
+ if (uid == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ List<UserSystemMsgVO> voList = new ArrayList<>();
+ List<UserSystemMsg> list = userSystemMsgService.listUserSystemMsg(uid, page, Constant.PAGE_SIZE);
+ if (list != null)
+ for (UserSystemMsg usm : list) {
+ voList.add(new UserSystemMsgVO(usm.getId(), usm.getType().name(), usm.getSolved(), usm.getTitle(),
+ usm.getContent(),
+ usm.getTimeTag() == 1 ? "http://img.flqapp.com/resource/msg/icon_emergent.png" : "", null,
+ usm.getCreateTime().getTime() + "", 0));
+ }
+ long count = userSystemMsgService.countUserSystemMsg(uid);
+
+ userMsgReadStateService.readUserSystemMsg(uid);
+
+ JSONObject root = new JSONObject();
+ root.put("data", voList);
+ root.put("count", count);
+ out.print(JsonUtil.loadTrueResult(root));
+ }
+
+ /**
+ * 璁剧疆闂宸茬粡瑙e喅
+ *
+ * @param acceptData
+ * @param uid
+ * @param id
+ * @param out
+ */
+ @RequestMapping(value = "setSystemMsgSolved", method = RequestMethod.POST)
+ public void setSystemMsgSolved(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
+ if (uid == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ if (id == null) {
+ out.print(JsonUtil.loadFalseResult(2, "娑堟伅ID涓虹┖"));
+ return;
+ }
+
+ try {
+ userSystemMsgService.setSystemMsgSolved(uid, id);
+ out.print(JsonUtil.loadTrueResult(""));
+ } catch (UserSystemMsgException e) {
+ out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
+ }
+ }
+
+ @RequestMapping(value = "setAllMsgRead", method = RequestMethod.POST)
+ public void setAllMsgRead(AcceptData acceptData, Long uid, PrintWriter out) {
+ if (uid == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ 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