admin
2024-01-23 81da61b828e29b7745e1382dfbbaeb685dc083ef
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserLevelUpgradedNotifyServiceImpl.java
@@ -1,94 +1,98 @@
package com.yeshi.fanli.service.impl.user.vip;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.user.vip.UserLevelUpgradedNotifyDao;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify;
import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
@Service
public class UserLevelUpgradedNotifyServiceImpl implements UserLevelUpgradedNotifyService {
   @Resource
   private UserLevelUpgradedNotifyDao userLevelUpgradedNotifyDao;
   @Override
   public void addUserLevelUpgradedNotify(UserLevelUpgradedNotify notify) {
      if (notify == null || notify.getUid() == null || notify.getToLevel() == null || notify.getFromLevel() == null) {
         return;
      }
      // 查询是否有当前提醒
      List<UserLevelEnum> levels = new ArrayList<>();
      levels.add(notify.getToLevel());
      List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(), levels);
      if (list != null)
         for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getValid() == false)
               list.remove(i--);
         }
      if (list != null && list.size() > 0)
         return;
      if (notify.getNotified() == null)
         notify.setNotified(false);
      if (notify.getValid() == null)
         notify.setValid(true);
      if (notify.getCreateTime() == null)
         notify.setCreateTime(new Date());
      if (notify.getId() == null)
         notify.setId(UUID.randomUUID().toString());
      userLevelUpgradedNotifyDao.save(notify);
   }
   @Override
   public void setNotified(String id) {
      UserLevelUpgradedNotify notify = userLevelUpgradedNotifyDao.get(id);
      if (notify == null)
         return;
      // 查询低等级的是否已读,如若未读则设为已读
      if (notify.getToLevel() == UserLevelEnum.highVIP || notify.getToLevel() == UserLevelEnum.superVIP) {
         List<UserLevelEnum> levels = new ArrayList<>();
         if (notify.getToLevel() == UserLevelEnum.highVIP) {
            levels.add(UserLevelEnum.normalVIP);
         } else {
            levels.add(UserLevelEnum.normalVIP);
            levels.add(UserLevelEnum.highVIP);
         }
         List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(), levels);
         if (list != null)
            for (UserLevelUpgradedNotify item : list) {
               item.setValid(false);
               item.setUpdateTime(new Date());
               userLevelUpgradedNotifyDao.save(item);
            }
      }
      notify.setUpdateTime(new Date());
      notify.setNotified(true);
      notify.setReadTime(new Date());
      userLevelUpgradedNotifyDao.save(notify);
   }
   @Override
   public UserLevelUpgradedNotify getNeedNotifyByUid(Long uid) {
      List<UserLevelUpgradedNotify> uidList = userLevelUpgradedNotifyDao.listNotNotifiedByUid(uid);
      if (uidList != null && uidList.size() > 0)
         return uidList.get(0);
      return null;
   }
}
package com.yeshi.fanli.service.impl.user.vip;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.user.vip.UserLevelUpgradedNotifyDao;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify;
import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
@Service
public class UserLevelUpgradedNotifyServiceImpl implements UserLevelUpgradedNotifyService {
   @Resource
   private UserLevelUpgradedNotifyDao userLevelUpgradedNotifyDao;
   @Override
   public void addUserLevelUpgradedNotify(UserLevelUpgradedNotify notify) {
      if (notify == null || notify.getUid() == null || notify.getToLevel() == null || notify.getFromLevel() == null) {
         return;
      }
      // 查询是否有当前提醒
      List<UserLevelEnum> levels = new ArrayList<>();
      levels.add(notify.getToLevel());
      List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(), levels);
      if (list != null)
         for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getValid() == false)
               list.remove(i--);
         }
      if (list != null && list.size() > 0)
         return;
      if (notify.getNotified() == null)
         notify.setNotified(false);
      if (notify.getValid() == null)
         notify.setValid(true);
      if (notify.getCreateTime() == null)
         notify.setCreateTime(new Date());
      if (notify.getId() == null)
         notify.setId(UUID.randomUUID().toString());
      userLevelUpgradedNotifyDao.save(notify);
   }
   @Override
   public void setNotified(String id) {
      UserLevelUpgradedNotify notify = userLevelUpgradedNotifyDao.get(id);
      if (notify == null)
         return;
      // 查询低等级的是否已读,如若未读则设为已读
      if (notify.getToLevel() == UserLevelEnum.superVIP || notify.getToLevel() == UserLevelEnum.tearcher) {
         List<UserLevelEnum> levels = new ArrayList<>();
         if (notify.getToLevel() == UserLevelEnum.tearcher) {
            levels.add(UserLevelEnum.highVIP);
            levels.add(UserLevelEnum.superVIP);
         } else if (notify.getToLevel() == UserLevelEnum.superVIP) {
            levels.add(UserLevelEnum.highVIP);
         }
         if (levels.size() > 0) {
            List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(),
                  levels);
            if (list != null)
               for (UserLevelUpgradedNotify item : list) {
                  item.setValid(false);
                  item.setUpdateTime(new Date());
                  userLevelUpgradedNotifyDao.save(item);
               }
         }
      }
      notify.setUpdateTime(new Date());
      notify.setNotified(true);
      notify.setReadTime(new Date());
      userLevelUpgradedNotifyDao.save(notify);
   }
   @Override
   public UserLevelUpgradedNotify getNeedNotifyByUid(Long uid) {
      List<UserLevelUpgradedNotify> uidList = userLevelUpgradedNotifyDao.listNotNotifiedByUid(uid);
      if (uidList != null && uidList.size() > 0)
         return uidList.get(0);
      return null;
   }
}