| | |
| | | package com.yeshi.fanli.controller.wxmp.v1;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.lang.reflect.Type;
|
| | | 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.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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 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.dto.msg.MsgCommonDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState;
|
| | | 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.MsgOrderDetail.MsgTypeOrderTypeEnum;
|
| | | 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.service.inter.common.JumpDetailV2Service;
|
| | | import com.yeshi.fanli.service.inter.money.msg.MsgMoneyDetailService;
|
| | | import com.yeshi.fanli.service.inter.msg.MsgConfigService;
|
| | | import com.yeshi.fanli.service.inter.msg.MsgDeviceReadStateService;
|
| | | 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.order.msg.MsgOrderDetailService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService;
|
| | | import com.yeshi.fanli.service.inter.user.msg.MsgAccountDetailService;
|
| | | import com.yeshi.fanli.util.JumpDetailUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
|
| | | import com.yeshi.fanli.util.factory.msg.UserMsgVOFactory;
|
| | | import com.yeshi.fanli.vo.msg.UserCommonMsgVO;
|
| | | import com.yeshi.fanli.vo.msg.UserMsgCenter;
|
| | | import com.yeshi.fanli.vo.msg.UserMsgVO;
|
| | | import com.yeshi.fanli.vo.msg.UserSystemMsgVO;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller("WXMPUserMsgController")
|
| | | @RequestMapping("/wxmp/api/v1/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 UserSystemMsgService userSystemMsgService;
|
| | |
|
| | | @Resource
|
| | | private JumpDetailV2Service jumpDetailV2Service;
|
| | |
|
| | | @Resource
|
| | | private MsgConfigService msgConfigService;
|
| | |
|
| | | @Resource
|
| | | private MsgDeviceReadStateService msgDeviceReadStateService;
|
| | |
|
| | |
|
| | | // 消息的类型
|
| | | 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
|
| | | */
|
| | | @RequestSerializableByKey(key = "#acceptData.device")
|
| | | @RequestMapping(value = "getMsgList", method = RequestMethod.POST)
|
| | | public void getMsgList(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | if (uid != null && uid == 0)
|
| | | uid = null;
|
| | | if (uid != null) {
|
| | | userSystemMsgService.syncSystemZNX(uid);
|
| | | }
|
| | |
|
| | | List<UserMsgCenter> listCenter = new ArrayList<>();
|
| | |
|
| | | // 单条消息
|
| | | List<UserCommonMsgVO> commonMsgList = new ArrayList<>();
|
| | |
|
| | | long currentTime = System.currentTimeMillis();
|
| | |
|
| | | // 板栗快省小助手
|
| | | MsgCommonDTO zhuShouMsg = msgConfigService.getZhuShouMsg();
|
| | | if (zhuShouMsg != null && zhuShouMsg.getShow() == true) {
|
| | | boolean read = false;
|
| | | MsgDeviceReadState state = msgDeviceReadStateService.getByDeviceAndPlatformAndType(
|
| | | UserCommonMsgVO.TYPE_ZHUSHOU, acceptData.getDevice(),
|
| | | acceptData.getPlatform().equalsIgnoreCase("android") ? 1 : 2);
|
| | | if (state != null && state.getReadTime() != null
|
| | | && zhuShouMsg.getUpdateTime().getTime() < state.getReadTime().getTime())
|
| | | read = true;
|
| | | // 查询是否已读
|
| | |
|
| | | if ((zhuShouMsg.getStartTime() != null && currentTime < zhuShouMsg.getStartTime().getTime())
|
| | | || (zhuShouMsg.getEndTime() != null && currentTime > zhuShouMsg.getEndTime().getTime())) {
|
| | | // 不显示
|
| | | } else {
|
| | | JSONObject params = null;
|
| | | if (StringUtil.isNullOrEmpty(zhuShouMsg.getParams())) {
|
| | | params = JSONObject.fromObject(zhuShouMsg.getParams());
|
| | | }
|
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil.getWXMPJumDetail(zhuShouMsg.getJumpDetail(), params);
|
| | | |
| | | commonMsgList.add(new UserCommonMsgVO(zhuShouMsg.getIcon(), zhuShouMsg.getTitle(),
|
| | | zhuShouMsg.getUpdateTime(), UserCommonMsgVO.TYPE_ZHUSHOU, zhuShouMsg.getContent(), read,
|
| | | wxmpJumDetail, null, 0));
|
| | | |
| | | |
| | | }
|
| | | }
|
| | |
|
| | | // 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) {
|
| | | JSONObject params = new JSONObject();
|
| | | params.put("orderNo", detail.getOrderId());
|
| | | if (detail.getType() == MsgTypeOrderTypeEnum.share || detail.getType() == MsgTypeOrderTypeEnum.invite)
|
| | | params.put("orderHideNo", UserUtil.filterOrderId(detail.getOrderId()));
|
| | | |
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil.getWXMPJumDetail(jumpDetailV2Service.getByTypeCache("order_search"), params);
|
| | | |
| | | UserMsgVO userMsgVO = UserMsgVOFactory.create(detail, wxmpJumDetail, params);
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | 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) {
|
| | | UserSystemMsgVO userSystemMsgVO = 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());
|
| | | |
| | | // TODO 跳转地址 |
| | | JSONObject params = new JSONObject();
|
| | | params.put("url", "http://apph5.yeshitv.com/special/1.0.9/jingXuanN_9.html?type=9_9");
|
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil.getWXMPJumDetail(jumpDetailV2Service.getByTypeCache("web"), params);
|
| | | userSystemMsgVO.setJumpDetail(wxmpJumDetail);
|
| | | |
| | | root.put("systemMsg", userSystemMsgVO);
|
| | | }
|
| | | }
|
| | |
|
| | | root.put("list", builder.create().toJson(listCenter));
|
| | | root.put("commonList", builder.create().toJson(commonMsgList));
|
| | | root.put("count", listCenter.size());
|
| | | out.print(JsonUtil.loadTrueResult(root));
|
| | | }
|
| | |
|
| | | private 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;
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | |
| | | 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 {
|
| | | 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;
|
| | | }
|
| | | |
| | | /**
|
| | | * 消息未读清理
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "setAllMsgRead", method = RequestMethod.POST)
|
| | | public void setAllMsgRead(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | msgDeviceReadStateService.setAllMsgRead(acceptData.getDevice(),
|
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2);
|
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 初始化读取状态
|
| | | msgDeviceReadStateService.initReadState(acceptData.getDevice(),
|
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2, UserCommonMsgVO.TYPE_RECOMMEND);
|
| | | msgDeviceReadStateService.initReadState(acceptData.getDevice(),
|
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2, UserCommonMsgVO.TYPE_ZHUSHOU);
|
| | |
|
| | | // 设置设备消息所有已读
|
| | | msgDeviceReadStateService.setAllMsgRead(acceptData.getDevice(),
|
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2);
|
| | |
|
| | | 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(""));
|
| | | }
|
| | |
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.wxmp.v1; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.lang.reflect.Type; |
| | | 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.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | 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 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.dto.msg.MsgCommonDTO; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail; |
| | | import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState; |
| | | 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.MsgOrderDetail.MsgTypeOrderTypeEnum; |
| | | 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.service.inter.common.JumpDetailV2Service; |
| | | import com.yeshi.fanli.service.inter.money.msg.MsgMoneyDetailService; |
| | | import com.yeshi.fanli.service.inter.msg.MsgConfigService; |
| | | import com.yeshi.fanli.service.inter.msg.MsgDeviceReadStateService; |
| | | 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.order.msg.MsgOrderDetailService; |
| | | import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService; |
| | | import com.yeshi.fanli.service.inter.user.msg.MsgAccountDetailService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.JumpDetailUtil; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.account.UserUtil; |
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKey; |
| | | import com.yeshi.fanli.util.factory.msg.UserMsgVOFactory; |
| | | import com.yeshi.fanli.vo.msg.UserCommonMsgVO; |
| | | import com.yeshi.fanli.vo.msg.UserMsgCenter; |
| | | import com.yeshi.fanli.vo.msg.UserMsgVO; |
| | | import com.yeshi.fanli.vo.msg.UserSystemMsgVO; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller("WXMPUserMsgController") |
| | | @RequestMapping("/wxmp/api/v1/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 UserSystemMsgService userSystemMsgService; |
| | | |
| | | @Resource |
| | | private JumpDetailV2Service jumpDetailV2Service; |
| | | |
| | | @Resource |
| | | private MsgConfigService msgConfigService; |
| | | |
| | | @Resource |
| | | private MsgDeviceReadStateService msgDeviceReadStateService; |
| | | |
| | | // 消息的类型 |
| | | 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 |
| | | */ |
| | | @RequestSerializableByKey(key = "#acceptData.device") |
| | | @RequestMapping(value = "getMsgList", method = RequestMethod.POST) |
| | | public void getMsgList(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | if (uid != null && uid == 0) |
| | | uid = null; |
| | | if (uid != null) { |
| | | userSystemMsgService.syncSystemZNX(uid); |
| | | } |
| | | |
| | | List<UserMsgCenter> listCenter = new ArrayList<>(); |
| | | |
| | | // 单条消息 |
| | | List<UserCommonMsgVO> commonMsgList = new ArrayList<>(); |
| | | |
| | | long currentTime = System.currentTimeMillis(); |
| | | |
| | | // 板栗快省小助手 |
| | | MsgCommonDTO zhuShouMsg = msgConfigService.getZhuShouMsg(acceptData.getSystem()); |
| | | if (zhuShouMsg != null && zhuShouMsg.getShow() == true) { |
| | | boolean read = false; |
| | | MsgDeviceReadState state = msgDeviceReadStateService.getByDeviceAndPlatformAndType( |
| | | UserCommonMsgVO.TYPE_ZHUSHOU, acceptData.getDevice(), |
| | | acceptData.getPlatform().equalsIgnoreCase("android") ? 1 : 2); |
| | | if (state != null && state.getReadTime() != null |
| | | && zhuShouMsg.getUpdateTime().getTime() < state.getReadTime().getTime()) |
| | | read = true; |
| | | // 查询是否已读 |
| | | |
| | | if ((zhuShouMsg.getStartTime() != null && currentTime < zhuShouMsg.getStartTime().getTime()) |
| | | || (zhuShouMsg.getEndTime() != null && currentTime > zhuShouMsg.getEndTime().getTime())) { |
| | | // 不显示 |
| | | } else { |
| | | JSONObject params = null; |
| | | if (StringUtil.isNullOrEmpty(zhuShouMsg.getParams())) { |
| | | params = JSONObject.fromObject(zhuShouMsg.getParams()); |
| | | } |
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil.getWXMPJumDetail(zhuShouMsg.getJumpDetail()); |
| | | |
| | | if (Constant.IS_TEST) |
| | | read = false; |
| | | commonMsgList.add(new UserCommonMsgVO(zhuShouMsg.getIcon(), zhuShouMsg.getTitle(), |
| | | zhuShouMsg.getUpdateTime(), UserCommonMsgVO.TYPE_ZHUSHOU, zhuShouMsg.getContent(), read, |
| | | wxmpJumDetail, zhuShouMsg.getParams(), 0)); |
| | | } |
| | | } |
| | | |
| | | // 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) { |
| | | JSONObject params = new JSONObject(); |
| | | params.put("orderNo", detail.getOrderId()); |
| | | if (detail.getType() == MsgTypeOrderTypeEnum.invite || detail.getType() == MsgTypeOrderTypeEnum.orderInvite) |
| | | params.put("orderHideNo", UserUtil.filterOrderId(detail.getOrderId())); |
| | | |
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil |
| | | .getWXMPJumDetail(jumpDetailV2Service.getByTypeCache("order_search")); |
| | | |
| | | UserMsgVO userMsgVO = UserMsgVOFactory.create(detail, wxmpJumDetail, params); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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) { |
| | | UserSystemMsgVO userSystemMsgVO = 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()); |
| | | |
| | | // TODO 跳转地址 |
| | | JSONObject params = new JSONObject(); |
| | | params.put("url", "http://apph5.banliapp.com/special/1.0.9/jingXuanN_9.html?type=9_9"); |
| | | JumpDetailV2 wxmpJumDetail = JumpDetailUtil.getWXMPJumDetail(jumpDetailV2Service.getByTypeCache("web")); |
| | | userSystemMsgVO.setJumpDetail(wxmpJumDetail); |
| | | |
| | | root.put("systemMsg", userSystemMsgVO); |
| | | } |
| | | } |
| | | |
| | | root.put("list", builder.create().toJson(listCenter)); |
| | | root.put("commonList", builder.create().toJson(commonMsgList)); |
| | | root.put("count", listCenter.size()); |
| | | out.print(JsonUtil.loadTrueResult(root)); |
| | | } |
| | | |
| | | private 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; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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 { |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 消息未读清理 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "setAllMsgRead", method = RequestMethod.POST) |
| | | public void setAllMsgRead(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | msgDeviceReadStateService.setAllMsgRead(acceptData.getDevice(), |
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2); |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | // 初始化读取状态 |
| | | msgDeviceReadStateService.initReadState(acceptData.getDevice(), |
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2, UserCommonMsgVO.TYPE_RECOMMEND); |
| | | msgDeviceReadStateService.initReadState(acceptData.getDevice(), |
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2, UserCommonMsgVO.TYPE_ZHUSHOU); |
| | | |
| | | // 设置设备消息所有已读 |
| | | msgDeviceReadStateService.setAllMsgRead(acceptData.getDevice(), |
| | | "android".equalsIgnoreCase(acceptData.getPlatform()) ? 1 : 2); |
| | | |
| | | 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("")); |
| | | } |
| | | |
| | | @RequestMapping(value = "getUnReadMsgCount", method = RequestMethod.POST) |
| | | public void getUnReadMsgCount(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | JSONObject data = new JSONObject(); |
| | | if (uid == null) { |
| | | data.put("totalCount", 0); |
| | | } else { |
| | | UserMsgUnReadNum num = userMsgReadStateService.getReadStateByUid(uid); |
| | | int totalCount = num.getTypeAccount() + num.getTypeInvite() + num.getTypeMoney() + num.getTypeOrder() |
| | | + num.getTypeScore() + num.getTypeSystem() + num.getTypeOther(); |
| | | data.put("totalCount", totalCount >= 100 ? "99+" : totalCount + ""); |
| | | } |
| | | |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | } |