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 @@ -115,15 +120,16 @@ 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, "用户未登录")); @@ -176,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(); @@ -202,7 +221,7 @@ 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()); + num.getTypeScore() + num.getTypeSystem()+num.getTypeOther()); try { UserSettingsVO vo = userCustomSettingsService.getMySettings(uid); @@ -373,10 +392,12 @@ session.removeAttribute("recommendgoods"); } } else { if (hour < 12) addRecommendGoods(uid); else addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa()); if (canAdd) { if (hour < 12) addRecommendGoods(uid); else addRecommendGoods(uid, acceptData.getImei(), acceptData.getIdfa()); } } } fanli/src/main/java/com/yeshi/fanli/service/impl/msg/MsgOtherDetailServiceImpl.java
@@ -13,6 +13,7 @@ import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum; import com.yeshi.fanli.exception.msg.MsgOtherDetailException; import com.yeshi.fanli.service.inter.msg.MsgOtherDetailService; import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService; import com.yeshi.fanli.util.Constant; @Service @@ -20,6 +21,9 @@ @Resource private MsgOtherDetailMapper msgOtherDetailMapper; @Resource private UserMsgReadStateService userMsgReadStateService; @Override public void addMsgOtherDetail(MsgOtherDetail detail) throws MsgOtherDetailException { @@ -32,6 +36,7 @@ detail.setContent(new Gson().toJson(detail.getCoupnContent())); detail.setCreateTime(new Date()); msgOtherDetailMapper.insertSelective(detail); userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1); } } fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserMsgReadStateServiceImpl.java
@@ -14,6 +14,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; @@ -34,7 +35,10 @@ @Resource private MsgMoneyDetailService msgMoneyDetailService; @Resource private MsgOtherDetailService msgOtherDetailService; @Resource private UserSystemMsgService userSystemMsgService; @@ -99,6 +103,16 @@ update.setUpdateTime(new Date()); userMsgUnReadNumMapper.updateByPrimaryKeySelective(update); } @Override public void addOtherMsgUnReadCount(Long uid, int count) { UserMsgUnReadNum num = getUserMsgUnReadNum(uid); UserMsgUnReadNum update = new UserMsgUnReadNum(); update.setId(num.getId()); update.setTypeOther(num.getTypeOther() + count); update.setUpdateTime(new Date()); userMsgUnReadNumMapper.updateByPrimaryKeySelective(update); } @Override public UserMsgUnReadNum getReadStateByUid(Long uid) { @@ -158,7 +172,6 @@ @Override public void readUserSystemMsg(Long uid) { userSystemMsgService.readMsgByUid(uid); UserMsgUnReadNum num = getUserMsgUnReadNum(uid); UserMsgUnReadNum update = new UserMsgUnReadNum(); update.setId(num.getId()); @@ -188,4 +201,17 @@ readUserSystemMsg(uid); } @Override public void readOtherMsg(Long uid) { msgOtherDetailService.readMsgByUid(uid); UserMsgUnReadNum num = getUserMsgUnReadNum(uid); UserMsgUnReadNum update = new UserMsgUnReadNum(); update.setId(num.getId()); update.setTypeOther(0); update.setUpdateTime(new Date()); userMsgUnReadNumMapper.updateByPrimaryKeySelective(update); } } fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserOtherMsgNotificationServiceImpl.java
New file @@ -0,0 +1,274 @@ package com.yeshi.fanli.service.impl.msg; import java.util.Date; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.yeshi.fanli.dto.msg.MsgOtherCouponContentDTO; import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum; import com.yeshi.fanli.entity.bus.user.UserSystemCoupon; import com.yeshi.fanli.exception.msg.MsgOtherDetailException; import com.yeshi.fanli.service.inter.msg.MsgOtherDetailService; import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService; import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.factory.msg.MsgOtherCouponContentDTOFactory; import com.yeshi.fanli.util.factory.msg.MsgOtherDetailFactory; @Service public class UserOtherMsgNotificationServiceImpl implements UserOtherMsgNotificationService { @Resource private MsgOtherDetailService msgOtherDetailService; private Integer getLeftDay(UserSystemCoupon coupon) { if (coupon != null && coupon.getEndTime() != null) { int cha = TimeUtil.getDayDifferenceCount(new Date(), coupon.getEndTime()); if (cha < 0) return 0; else return cha + 1; } else return null; } @Override public void welfareCouponGet(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponGet(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void welfareCouponActive(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponActive(getLeftDay(coupon), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void welfareCouponUsing(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponUsing(coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void welfareCouponUsed(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponUsed(getLeftDay(coupon), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void welfareCouponWillOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory .createWelfareCouponWillOutOfDate(getLeftDay(coupon), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void welfareCouponAlreadyOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory .createWelfareCouponAlreadyOutOfDate(coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponGet(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponGet(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponActive(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponActive(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponUsing(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponUsing(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponUsed(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponUsed(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponWillOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponWillOutOfDate(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void freeSheetCouponAlreadyOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponAlreadyOutOfDate(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponMianDan, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void rewardCouponGet(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createRewardCouponGet(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponReward, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void rewardCouponActive(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createRewardCouponActive(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponReward, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void rewardCouponUsed(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createRewardCouponUsed(getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponReward, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void rewardCouponWillOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createRewardCouponWillOutOfDate( getLeftDay(coupon), coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponReward, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } @Override public void rewardCouponAlreadyOutOfDate(UserSystemCoupon coupon) { if (coupon == null || coupon.getUid() == null) return; MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory .createRewardCouponAlreadyOutOfDate(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime()); try { msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), dto, MsgTypeOtherTypeEnum.couponReward, null)); } catch (MsgOtherDetailException e) { e.printStackTrace(); } } } fanli/src/main/java/com/yeshi/fanli/service/inter/msg/MsgOtherDetailService.java
@@ -7,7 +7,7 @@ public interface MsgOtherDetailService { /** * 添加到订单消息 * 添加到其他消息 * * @param detail * @throws MsgOtherDetailException @@ -15,7 +15,7 @@ public void addMsgOtherDetail(MsgOtherDetail detail) throws MsgOtherDetailException; /** * 根据订单号用户ID更新数据 * 更新数据 * * @param detail * @throws MsgOtherDetailException @@ -23,7 +23,7 @@ public void updateMsgOtherDetail(MsgOtherDetail detail) throws MsgOtherDetailException; /** * 订单消息列表 * 其他消息列表 * * @param uid * @param page @@ -32,7 +32,7 @@ public List<MsgOtherDetail> listMsgOtherDetail(Long uid, int page); /** * 订单消息数 * 其他消息数 * * @param uid * @return fanli/src/main/java/com/yeshi/fanli/service/inter/msg/UserMsgReadStateService.java
@@ -49,6 +49,14 @@ * @param count */ public void addSystemMsgUnReadCount(Long uid, int count); /** * 增加其他消息未读数 * @param uid * @param count */ public void addOtherMsgUnReadCount(Long uid, int count); /** * 获取用户所有未读消息数 @@ -99,4 +107,10 @@ * @param uid */ public void readUserSystemMsg(Long uid); /** * 读其他消息 * @param uid */ public void readOtherMsg(Long uid); } fanli/src/main/java/com/yeshi/fanli/service/inter/msg/UserOtherMsgNotificationService.java
New file @@ -0,0 +1,179 @@ package com.yeshi.fanli.service.inter.msg; import com.yeshi.fanli.entity.bus.user.UserSystemCoupon; /** * 用户订单消息通知 * * @author Administrator * */ public interface UserOtherMsgNotificationService { // 福利奖励券 /** * 获得福利免单券 * * @param leftDay * @param source * @param startTime * @param endTime */ public void welfareCouponGet(UserSystemCoupon coupon); /** * 福利免单券激活 * * @param leftDay * @param startTime * @param endTime */ public void welfareCouponActive(UserSystemCoupon coupon); /** * 福利免单券使用中 * * @param startTime * @param endTime */ public void welfareCouponUsing(UserSystemCoupon coupon); /** * 福利免单券已被使用 * * @param leftDay * @param startTime * @param endTime */ public void welfareCouponUsed(UserSystemCoupon coupon); /** * 福利免单券即将过期 * * @param leftDay * @param startTime * @param endTime */ public void welfareCouponWillOutOfDate(UserSystemCoupon coupon); /** * 福利免单券已经过期 * * @param startTime * @param endTime */ public void welfareCouponAlreadyOutOfDate(UserSystemCoupon coupon); // 免单券 /** * 免单券使用 * * @param leftDay * @param source * @param startTime * @param endTime */ public void freeSheetCouponGet(UserSystemCoupon coupon); /** * 免单券激活 * * @param leftDay * @param source * @param startTime * @param endTime */ public void freeSheetCouponActive(UserSystemCoupon coupon); /** * 免单券正在使用 * * @param source * @param startTime * @param endTime */ public void freeSheetCouponUsing(UserSystemCoupon coupon); /** * 免单券已经使用 * * @param leftDay * @param source * @param startTime * @param endTime */ public void freeSheetCouponUsed(UserSystemCoupon coupon); /** * 免单券即将过期 * * @param leftDay * @param source * @param startTime * @param endTime */ public void freeSheetCouponWillOutOfDate(UserSystemCoupon coupon); /** * 免单券已经过期 * * @param source * @param startTime * @param endTime */ public void freeSheetCouponAlreadyOutOfDate(UserSystemCoupon coupon); // 奖励券 /** * 奖励券获得 * * @param leftDay * @param source * @param startTime * @param endTime */ public void rewardCouponGet(UserSystemCoupon coupon); /** * 奖励券激活 * * @param leftDay * @param source * @param startTime * @param endTime */ public void rewardCouponActive(UserSystemCoupon coupon); /** * 奖励券已经使用 * * @param leftDay * @param source * @param startTime * @param endTime */ public void rewardCouponUsed(UserSystemCoupon coupon); /** * 奖励券即将过期 * * @param leftDay * @param source * @param startTime * @param endTime */ public void rewardCouponWillOutOfDate(UserSystemCoupon coupon); /** * 奖励券已经过期 * * @param source * @param startTime * @param endTime */ public void rewardCouponAlreadyOutOfDate(UserSystemCoupon coupon); } fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java
@@ -220,4 +220,36 @@ String date = sdf.format(new Date(time)); return date; } /** * 获取两个时间的天数差值 * * @param from * @param to * @return */ public static int getDayDifferenceCount(Date from, Date to) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(from); Calendar cal2 = Calendar.getInstance(); cal2.setTime(to); int day1 = cal1.get(Calendar.DAY_OF_YEAR); int day2 = cal2.get(Calendar.DAY_OF_YEAR); int year1 = cal1.get(Calendar.YEAR); int year2 = cal2.get(Calendar.YEAR); if (year1 != year2) { // 同一年 int timeDistance = 0; for (int i = year1; i < year2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { // 闰年 timeDistance += 366; } else { // 不是闰年 timeDistance += 365; } } return timeDistance + (day2 - day1); } else { // 不同年 return day2 - day1; } } } fanli/src/main/java/com/yeshi/fanli/util/factory/msg/MsgOtherDetailFactory.java
@@ -10,19 +10,15 @@ public class MsgOtherDetailFactory { /** * 返利订单 * 券相关信息的通知 * * @param uid * @param orderId * @param goodsCount * @param orderState * @param payMoney * @param money * @param state * @param content * @param type * @param beiZhu * @return */ public static MsgOtherDetail createFanLiOrder(Long uid, MsgOtherCouponContentDTO content, MsgTypeOtherTypeEnum type, public static MsgOtherDetail createCouponMsg(Long uid, MsgOtherCouponContentDTO content, MsgTypeOtherTypeEnum type, String beiZhu) { if (uid == null) return null; @@ -32,6 +28,7 @@ detail.setRead(false); detail.setUser(new UserInfo(uid)); detail.setCoupnContent(content); detail.setType(type); return detail; }