admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/msg/UserOtherMsgNotificationServiceImpl.java
@@ -1,370 +1,86 @@
package com.yeshi.fanli.service.impl.msg;
import java.math.BigDecimal;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.msg.MsgOtherCouponContentDTO;
import com.yeshi.fanli.dto.msg.MsgOtherExchangeContentDTO;
import com.yeshi.fanli.dto.msg.MsgOtherGiveContentDTO;
import com.yeshi.fanli.dto.msg.MsgOtherTaoLiJinContentDTO;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserInfo;
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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "至少成功邀请1个队员后可激活"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void welfareCouponActive(UserSystemCoupon coupon, UserInfo worker) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponActive(getLeftDay(coupon),
            "成功邀请队员:" + worker.getNickName(), coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "可在首页-免单商品-选择商品-使用"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void welfareCouponUsing(UserSystemCoupon coupon, String orderId, BigDecimal money) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponUsing(orderId, money,
            coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "实付款-返利=0元购(免单)"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void welfareCouponUsed(UserSystemCoupon coupon, String orderId) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponUsed(orderId,
            "实付款-返利=0元购(免单)", coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "参与其他活动可获得更多免单券"));
      } 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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "至少成功邀请1个队员后可激活"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void welfareCouponAlreadyOutOfDate(UserSystemCoupon coupon) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory
            .createWelfareCouponAlreadyOutOfDate(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime());
      try {
         MsgOtherDetail detail = MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), coupon.getId(), dto,
               MsgTypeOtherTypeEnum.couponWelfareMianDan, "参与其他活动可获得更多免单券");
         detail.setCreateTime(coupon.getEndTime());
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void welfareCouponDrawBack(UserSystemCoupon coupon, String orderId) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponDrawBack(getLeftDay(coupon),
            orderId, coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponWelfareMianDan, "退回后依然可在有效期内使用"));
      } 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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponMianDan, "可在首页-免单商品-选择商品-使用"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void freeSheetCouponUsing(UserSystemCoupon coupon, String orderId, BigDecimal money) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createCouponUsing(orderId, money,
            coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponMianDan, "实付款-返利=0元购(免单)"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void freeSheetCouponUsed(UserSystemCoupon coupon, String orderId) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponUsed(orderId,
            "实付款-返利=0元购(免单)", coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponMianDan, "参与其他活动可获得更多免单券"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void freeSheetCouponWillOutOfDate(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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponMianDan, "至少成功邀请1个队员后可激活"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void freeSheetCouponAlreadyOutOfDate(UserSystemCoupon coupon) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory
            .createWelfareCouponAlreadyOutOfDate(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime());
      try {
         MsgOtherDetail detail = MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), coupon.getId(), dto,
               MsgTypeOtherTypeEnum.couponMianDan, "参与其他活动可获得更多免单券");
         detail.setCreateTime(coupon.getEndTime());
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void freeSheetCouponDrawBack(UserSystemCoupon coupon, String orderId) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponDrawBack(getLeftDay(coupon),
            orderId, coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponMianDan, "退回后依然可在有效期内使用"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void rewardCouponGet(UserSystemCoupon coupon, int percent) {
      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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponReward, "使用本券已到账的返利再返" + percent + "%"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void rewardCouponUsed(UserSystemCoupon coupon, BigDecimal oldFanLiMoney, BigDecimal rewardMoney,
         String orderId) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createRewardCouponUsed(oldFanLiMoney,
            rewardMoney, orderId);
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponReward, "参与活动可获取更多奖励券"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void rewardCouponWillOutOfDate(UserSystemCoupon coupon, int percent) {
      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(),
               coupon.getId(), dto, MsgTypeOtherTypeEnum.couponReward, "使用本券已到账的返利再返" + percent + "%"));
      } 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 {
         MsgOtherDetail detail = MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), coupon.getId(), dto,
               MsgTypeOtherTypeEnum.couponReward, "参与活动可获取更多奖励券");
         detail.setCreateTime(coupon.getEndTime());
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void couponDrawBack(UserSystemCoupon coupon, String orderId, MsgTypeOtherTypeEnum type) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory.createWelfareCouponDrawBack(getLeftDay(coupon),
            orderId, coupon.getStartTime(), coupon.getEndTime());
      try {
         msgOtherDetailService.addMsgOtherDetail(MsgOtherDetailFactory.createCouponMsg(coupon.getUid(),
               coupon.getId(), dto, type, "退回后依然可在有效期内使用"));
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void outOfDate(UserSystemCoupon coupon, MsgTypeOtherTypeEnum type) {
      if (coupon == null || coupon.getUid() == null)
         return;
      MsgOtherCouponContentDTO dto = MsgOtherCouponContentDTOFactory
            .createRewardCouponAlreadyOutOfDate(coupon.getSource(), coupon.getStartTime(), coupon.getEndTime());
      try {
         MsgOtherDetail detail = MsgOtherDetailFactory.createCouponMsg(coupon.getUid(), coupon.getId(), dto,
               type, "参与活动可获取更多奖励券");
         detail.setCreateTime(coupon.getEndTime());
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void taoLiJinMsg(Long uid, String beiZhu, MsgOtherTaoLiJinContentDTO content) {
      try {
         MsgOtherDetail detail = new MsgOtherDetail();
         detail.setBeiZhu(beiZhu);
         detail.setCreateTime(new Date());
         detail.setRead(false);
         detail.setUser(new UserInfo(uid));
         detail.setContent(new Gson().toJson(content));
         detail.setType(MsgTypeOtherTypeEnum.taoLiJin);
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void tokenGiveMsg(Long uid, String beiZhu,  MsgOtherGiveContentDTO content) {
      try {
         MsgOtherDetail detail = new MsgOtherDetail();
         detail.setBeiZhu(beiZhu);
         detail.setCreateTime(new Date());
         detail.setRead(false);
         detail.setUser(new UserInfo(uid));
         detail.setContent(new Gson().toJson(content));
         detail.setType(MsgTypeOtherTypeEnum.give);
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void exchangeMsg(Long uid, String beiZhu,  MsgOtherExchangeContentDTO content) {
      try {
         MsgOtherDetail detail = new MsgOtherDetail();
         detail.setBeiZhu(beiZhu);
         detail.setCreateTime(new Date());
         detail.setRead(false);
         detail.setUser(new UserInfo(uid));
         detail.setContent(new Gson().toJson(content));
         detail.setType(MsgTypeOtherTypeEnum.exchange);
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
}
package com.yeshi.fanli.service.impl.msg;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail;
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.factory.msg.MsgOtherDetailFactory;
@Service
public class UserOtherMsgNotificationServiceImpl implements UserOtherMsgNotificationService {
   @Resource
   private MsgOtherDetailService msgOtherDetailService;
   @Transactional(rollbackFor = Exception.class)
   private void saveMsgDetail(MsgOtherDetail detail) {
      try {
         msgOtherDetailService.addMsgOtherDetail(detail);
      } catch (MsgOtherDetailException e) {
         e.printStackTrace();
      }
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void freeCouponWinMsg(Long uid, String name, String source, int num, String stateDesc, Date startTime, Date endTime) {
      saveMsgDetail(MsgOtherDetailFactory.freeCouponMsg(uid, name, source, num, stateDesc, startTime, endTime));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void freeCouponEndMsg(Long uid, String name, String source, int num, String stateDesc) {
      saveMsgDetail(MsgOtherDetailFactory.freeCouponMsg(uid, name, source, num, stateDesc, null, null));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void rewardCouponWinMsg(Long uid, String source, int num, String stateDesc, Date startTime, Date endTime) {
      saveMsgDetail(MsgOtherDetailFactory.rewardCouponMsg(uid, source, num, stateDesc, startTime, endTime));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void rewardCouponEndMsg(Long uid, String source, int num, String stateDesc) {
      saveMsgDetail(MsgOtherDetailFactory.rewardCouponMsg(uid, source, num, stateDesc, null, null));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void goldCoinSystemGiveMsg(Long uid, int num, int banlce) {
      saveMsgDetail(MsgOtherDetailFactory.goldCoinSystemGiveMsg(uid, num, banlce));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void goldCoinRewardInviteSucceedMsg(Long uid, int num, int banlce, boolean directFans) {
      saveMsgDetail(MsgOtherDetailFactory.goldCoinRewardInviteSucceedMsg(uid, num, banlce, directFans));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void  goldCoinOrderSubsidyMsg(Long uid, int num, int banlce, boolean directFans) {
      saveMsgDetail(MsgOtherDetailFactory.goldCoinOrderSubsidyMsg(uid, num, banlce, directFans));
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void goldCoinExChangeMsg(Long uid, int num, int banlce, String name, String exNum) {
      saveMsgDetail(MsgOtherDetailFactory.goldCoinExChangeMsg(uid, num, banlce, name, exNum));
   }
   @Override
   public void cloudMsg(Long uid, String category, String item, String desc) {
      saveMsgDetail(MsgOtherDetailFactory.cloudMsg(uid, category, item, desc));
   }
}