yujian
2019-04-08 1da17d215d48e3e3aa9e8d7a3ef526904764f408
fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java
@@ -5,10 +5,17 @@
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;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,31 +31,50 @@
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;
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.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.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;
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.UserMsgCenter;
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;
@@ -56,6 +82,8 @@
@RequestMapping("api/v1/user/msg")
public class UserMsgController {
   @Resource
   private BusinessSystemService businessSystemService;
   @Resource
   private MsgOrderDetailService msgOrderDetailService;
@@ -69,6 +97,9 @@
   private MsgAccountDetailService msgAccountDetailService;
   @Resource
   private MsgOtherDetailService msgOtherDetailService;
   @Resource
   private UserMsgReadStateService userMsgReadStateService;
   @Resource
@@ -80,22 +111,40 @@
   @Resource
   private UserSystemMsgService userSystemMsgService;
   @Resource
   private CommonGoodsService commonGoodsService;
   @Resource
   private QualityFactoryService qualityFactoryService;
   @Resource
   private UserCustomSettingsService userCustomSettingsService;
   @Resource
   private RedisManager redisManager;
   @Resource
   private SpecialService specialService;
   // 消息的类型
   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 = "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, "用户未登录"));
@@ -112,7 +161,7 @@
      switch (type) {
      case MSG_TYPE_ORDER:
         msgOrderDetailService.readMsgByUid(uid);
         userMsgReadStateService.readOrderMsg(uid);
         List<MsgOrderDetail> detailList = msgOrderDetailService.listMsgOrderDetail(uid, page);
         count = msgOrderDetailService.countMsgOrderDetail(uid);
         if (detailList != null)
@@ -120,7 +169,7 @@
               list.add(UserMsgVOFactory.create(detail));
         break;
      case MSG_TYPE_MONEY:
         msgMoneyDetailService.readMsgByUid(uid);
         userMsgReadStateService.readMoneyMsg(uid);
         List<MsgMoneyDetail> detailList1 = msgMoneyDetailService.listMsgMoneyDetail(uid, page);
         count = msgMoneyDetailService.countMsgMoneyDetail(uid);
         if (detailList1 != null)
@@ -128,7 +177,7 @@
               list.add(UserMsgVOFactory.create(detail));
         break;
      case MSG_TYPE_ACCOUNT:
         msgAccountDetailService.readMsgByUid(uid);
         userMsgReadStateService.readAccountMsg(uid);
         List<MsgAccountDetail> detailList2 = msgAccountDetailService.listMsgAccountDetail(uid, page);
         count = msgAccountDetailService.countMsgAccountDetail(uid);
         if (detailList2 != null)
@@ -136,12 +185,30 @@
               list.add(UserMsgVOFactory.create(detail));
         break;
      case MSG_TYPE_INVITE:
         msgInviteDetailService.readMsgByUid(uid);
         userMsgReadStateService.readInviteMsg(uid);
         List<MsgInviteDetail> detailList3 = msgInviteDetailService.listMsgInviteDetail(uid, page);
         count = msgInviteDetailService.countMsgInviteDetail(uid);
         if (detailList3 != null)
            for (MsgInviteDetail detail : detailList3)
               list.add(UserMsgVOFactory.create(detail));
            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;
      }
@@ -167,13 +234,41 @@
         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());
      JSONObject root = new JSONObject();
      root.put("data", data);
      root.put("count", 1);
      out.print(JsonUtil.loadTrueResult(root));
      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) {
@@ -215,6 +310,84 @@
      return builder;
   }
   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++) {
            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, device, "", goodsList);
            } catch (RecommendUserGoodsException e) {
               e.printStackTrace();
            }
         }
      }
   }
   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++) {
            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, device, "", goodsList);
            } catch (RecommendUserGoodsException e) {
               e.printStackTrace();
            }
         }
      }
   }
   /**
    * 获取首页消息
    * 
@@ -224,15 +397,58 @@
    * @param out
    */
   @RequestMapping(value = "getHomeMsgList", method = RequestMethod.POST)
   public void getHomeMsgList(AcceptData acceptData, Long uid, int page, PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
   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 {
            // 是否和上次间隔时间足够
            if (System.currentTimeMillis() - goods.getCreateTime().getTime() >= 1000 * 60 * 60 * 4L) {
               canAdd = true;
            }
         }
         // 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) + 1;// 计算欢迎语的数量
      List<RecommendUserGoods> list = recommendUserGoodsService.listRecommendGoodsByDevice(device, page,
            Constant.PAGE_SIZE);
      long count = recommendUserGoodsService.countRecommendGoodsByDevice(device);
      Date now = new Date();
      for (RecommendUserGoods goods : list) {
@@ -248,11 +464,17 @@
         List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
         for (CommonGoods cg : goods.getGoodsList()) {
            if (goods.getGoodsList().size() == 1)
               cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 400));
               cg.setPicture(TbImgUtil.getTBSizeImg(
                     StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(),
                     400));
            else if (goods.getGoodsList().size() == 2)
               cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 320));
               cg.setPicture(TbImgUtil.getTBSizeImg(
                     StringUtil.isNullOrEmpty(cg.getPictureWhite()) ? cg.getPicture() : cg.getPictureWhite(),
                     320));
            else if (goods.getGoodsList().size() == 3)
               cg.setPicture(TbImgUtil.getTBSizeImg(cg.getPicture(), 220));
               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));
@@ -264,33 +486,187 @@
         }
         vo.setGoodsList(goodsList);
         vo.setTitle("猜你喜欢");
         vo.setIcon("http://img.flqapp.com/resource/msg/icon_msg_guess_like.png");
         volist.add(vo);
      }
      if (volist.size() < Constant.PAGE_SIZE) {
      Long time = (uid == null ? System.currentTimeMillis() : userInfoService.selectByPKey(uid).getCreatetime());
      if (volist.size() > 0 && volist.size() < Constant.PAGE_SIZE) {
         // 添加欢迎语
         UserHomeMsgVO vo = new UserHomeMsgVO();
         vo.setContent("恭喜你,成为返利券的用户\n独家优惠券帮你省钱;\n参与奖金活动帮你赚钱;\n让返利券成为你的省钱助手吧!");
         vo.setTitle("新人欢迎");
         vo.setCreateTime(getTimeDesc(now, new Date(userInfoService.getUserById(uid).getCreatetime())));
         vo.setType(UserHomeMsgVO.TYPE_WELCOME);
         volist.add(vo);
         // 创建时间在28号后的才有新人欢迎
         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)
            root.put("systemMsg", 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" : "",
                  Constant.systemCommonConfig.getDefaultPortrait(), getTimeDesc(now, usm.getCreateTime())));
            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 type
    * @param out
    */
   @RequestMapping(value = "getHomeMsgListNew", method = RequestMethod.POST)
   public void getHomeMsgListNew(AcceptData acceptData, Long uid, PrintWriter out) {
      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());
      if (listSpecial != null && listSpecial.size() > 0) {
         for (Special special: listSpecial) {
            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);
         }
         for (UserMsgVO userMsgVO: list) {
            UserMsgCenter userMsgCenter = new UserMsgCenter();
            userMsgCenter.setUserMsg(userMsgVO);
            listCenter.add(userMsgCenter);
         }
      }
      // 添加欢迎语
      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();
      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;
            }
         }
      });
   }
   /**
    * 获取系统消息列表
    * 
@@ -313,11 +689,11 @@
            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() + ""));
                  usm.getCreateTime().getTime() + "", 0));
         }
      long count = userSystemMsgService.countUserSystemMsg(uid);
      userSystemMsgService.readMsgByUid(uid);
      userMsgReadStateService.readUserSystemMsg(uid);
      JSONObject root = new JSONObject();
      root.put("data", voList);
@@ -359,7 +735,15 @@
         out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
         return;
      }
      userMsgReadStateService.setAllMsgRead(uid);
      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(""));
   }