admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/GiveVIPApplyInfoServiceImpl.java
@@ -1,201 +1,201 @@
package com.yeshi.fanli.service.impl.user.vip;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.user.vip.GiveVIPApplyInfoDao;
import com.yeshi.fanli.entity.bus.user.UserInfoRegister;
import com.yeshi.fanli.entity.bus.user.vip.GiveVIPApplyInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.user.vip.GiveVIPApplyInfoException;
import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
import com.yeshi.fanli.service.inter.user.UserInfoRegisterService;
import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
import com.yeshi.fanli.service.inter.user.vip.GiveVIPApplyInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
@Service
public class GiveVIPApplyInfoServiceImpl implements GiveVIPApplyInfoService {
   @Resource
   private GiveVIPApplyInfoDao giveVIPApplyInfoDao;
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Resource
   private UserInfoRegisterService userInfoRegisterService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Async
   @Override
   public void saveImgs(String id, List<String> imgList) {
      giveVIPApplyInfoDao.saveImgs(id, imgList);
   }
   @Override
   public void updateGiveVIPApplyInfo(GiveVIPApplyInfo info) {
      giveVIPApplyInfoDao.updateSelective(info);
   }
   @Override
   public GiveVIPApplyInfo addGiveVIPApplyInfo(GiveVIPApplyInfo info)
         throws ParamsException, GiveVIPApplyInfoException {
      if (info.getTargetUid() == null || info.getSourceUid() == null || info.getLevel() == null)
         throw new ParamsException(1, "参数不完整");
      info.setId(StringUtil
            .Md5(String.format("%s#%s#%s", info.getTargetUid(), info.getSourceUid(), info.getLevel().name())));
      if (info.getCreateTime() == null)
         info.setCreateTime(new Date());
      if (info.getState() == null)
         info.setState(GiveVIPApplyInfo.STATE_NO_INFO);
      GiveVIPApplyInfo oldInfo = giveVIPApplyInfoDao.get(info.getId());
      if (oldInfo != null) {
         throw new GiveVIPApplyInfoException(2, "已经提交过申请");
      }
      giveVIPApplyInfoDao.save(info);
      return info;
   }
   @Override
   public List<GiveVIPApplyInfo> listByTargetUid(Long uid, int page, int pageSize) {
      return giveVIPApplyInfoDao.listByTargetUid(uid, null, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countByTargetUid(Long uid) {
      return giveVIPApplyInfoDao.countByTargetUid(uid, null);
   }
   @Override
   public List<GiveVIPApplyInfo> listByStateAndTargetUid(Long targetUid, Integer state, int page, int pageSize) {
      return giveVIPApplyInfoDao.listByTargetUid(targetUid, state, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countByStateAndTargetUid(Long targetUid, Integer state) {
      return giveVIPApplyInfoDao.countByTargetUid(targetUid, state);
   }
   @Override
   public GiveVIPApplyInfo selectByPrimaryKey(String id) {
      return giveVIPApplyInfoDao.get(id);
   }
   @Transactional
   @Override
   public void pass(String id, Long adminId) throws GiveVIPApplyInfoException, UserVIPPreInfoException {
      GiveVIPApplyInfo info = selectByPrimaryKey(id);
      if (info == null)
         throw new GiveVIPApplyInfoException(1, "记录不存在");
      // if (info.getState() == GiveVIPApplyInfo.STATE_NO_INFO)
      // throw new GiveVIPApplyInfoException(2, "用户未提交资料");
      if (info.getState() == GiveVIPApplyInfo.STATE_REJECT)
         throw new GiveVIPApplyInfoException(3, "已经被拒绝");
      if (info.getState() == GiveVIPApplyInfo.STATE_SUCCESS)
         throw new GiveVIPApplyInfoException(4, "已经被通过");
      Long uid = info.getTargetUid();
      // 查询当前的条件
      UserVIPPreInfo preInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
      if (preInfo == null || preInfo.getProcess() < info.getLevel().getLevel()) {
         // 会员升级
         UserVIPPreInfo newInfo = new UserVIPPreInfo();
         newInfo.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ARTIFICIAL);
         newInfo.setProcess(info.getLevel().getLevel());
         newInfo.setUid(uid);
         userVIPPreInfoService.addUserVIPPreInfo(newInfo);
         // 发送消息
         // 计算相隔天数
         // 默认值
         Date lastUpgradeTime = new Date(1577836800000L);
         if (preInfo != null)
            lastUpgradeTime = preInfo.getCreateTime();
         else {
            UserInfoRegister userInfoRegister = userInfoRegisterService.selectByPrimaryKey(uid);
            if (userInfoRegister != null && userInfoRegister.getCreateTime() != null) {
               lastUpgradeTime = userInfoRegister.getCreateTime();
            }
         }
         int days = TimeUtil.getDayDifferenceCount(lastUpgradeTime, new Date());
         userAccountMsgNotificationService.artificialVipUpgradePass(uid,
               preInfo == null ? UserLevelEnum.daRen.getName()
                     : UserLevelUtil.getByLevel(preInfo.getProcess()).getName(),
               info.getLevel().getName(), days);
      }
      GiveVIPApplyInfo update = new GiveVIPApplyInfo();
      update.setId(info.getId());
      update.setState(GiveVIPApplyInfo.STATE_SUCCESS);
      update.setVerifyTime(new Date());
      update.setAdminUserId(adminId);
      giveVIPApplyInfoDao.updateSelective(update);
   }
   @Transactional
   @Override
   public void reject(String id, Long adminId, String reason) throws GiveVIPApplyInfoException {
      GiveVIPApplyInfo info = selectByPrimaryKey(id);
      if (info == null)
         throw new GiveVIPApplyInfoException(1, "记录不存在");
      if (info.getState() == GiveVIPApplyInfo.STATE_REJECT)
         throw new GiveVIPApplyInfoException(3, "已经被拒绝");
      if (info.getState() == GiveVIPApplyInfo.STATE_SUCCESS)
         throw new GiveVIPApplyInfoException(4, "已经被通过");
      GiveVIPApplyInfo update = new GiveVIPApplyInfo();
      update.setId(info.getId());
      update.setState(GiveVIPApplyInfo.STATE_REJECT);
      update.setVerifyTime(new Date());
      update.setRejectReson(reason);
      update.setAdminUserId(adminId);
      giveVIPApplyInfoDao.updateSelective(update);
      Long uid = info.getTargetUid();
      UserVIPPreInfo preInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
      // 拒绝相关消息
      userAccountMsgNotificationService
            .artificialVipUpgradeReject(uid,
                  preInfo == null ? UserLevelEnum.daRen.getName()
                        : UserLevelUtil.getByLevel(preInfo.getProcess()).getName(),
                  info.getLevel().getName(), reason);
   }
   @Override
   public List<GiveVIPApplyInfo> listBySourceUid(Long uid, int page, int pageSize) {
      return giveVIPApplyInfoDao.listBySourceUid(uid, null, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countBySourceUid(Long uid) {
      return giveVIPApplyInfoDao.countBySourceUid(uid, null);
   }
}
package com.yeshi.fanli.service.impl.user.vip;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.user.vip.GiveVIPApplyInfoDao;
import com.yeshi.fanli.entity.bus.user.UserInfoRegister;
import com.yeshi.fanli.entity.bus.user.vip.GiveVIPApplyInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.user.vip.GiveVIPApplyInfoException;
import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
import com.yeshi.fanli.service.inter.user.UserInfoRegisterService;
import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
import com.yeshi.fanli.service.inter.user.vip.GiveVIPApplyInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.util.StringUtil;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
@Service
public class GiveVIPApplyInfoServiceImpl implements GiveVIPApplyInfoService {
   @Resource
   private GiveVIPApplyInfoDao giveVIPApplyInfoDao;
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Resource
   private UserInfoRegisterService userInfoRegisterService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Async
   @Override
   public void saveImgs(String id, List<String> imgList) {
      giveVIPApplyInfoDao.saveImgs(id, imgList);
   }
   @Override
   public void updateGiveVIPApplyInfo(GiveVIPApplyInfo info) {
      giveVIPApplyInfoDao.updateSelective(info);
   }
   @Override
   public GiveVIPApplyInfo addGiveVIPApplyInfo(GiveVIPApplyInfo info)
         throws ParamsException, GiveVIPApplyInfoException {
      if (info.getTargetUid() == null || info.getSourceUid() == null || info.getLevel() == null)
         throw new ParamsException(1, "参数不完整");
      info.setId(StringUtil
            .Md5(String.format("%s#%s#%s", info.getTargetUid(), info.getSourceUid(), info.getLevel().name())));
      if (info.getCreateTime() == null)
         info.setCreateTime(new Date());
      if (info.getState() == null)
         info.setState(GiveVIPApplyInfo.STATE_NO_INFO);
      GiveVIPApplyInfo oldInfo = giveVIPApplyInfoDao.get(info.getId());
      if (oldInfo != null) {
         throw new GiveVIPApplyInfoException(2, "已经提交过申请");
      }
      giveVIPApplyInfoDao.save(info);
      return info;
   }
   @Override
   public List<GiveVIPApplyInfo> listByTargetUid(Long uid, int page, int pageSize) {
      return giveVIPApplyInfoDao.listByTargetUid(uid, null, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countByTargetUid(Long uid) {
      return giveVIPApplyInfoDao.countByTargetUid(uid, null);
   }
   @Override
   public List<GiveVIPApplyInfo> listByStateAndTargetUid(Long targetUid, Integer state, int page, int pageSize) {
      return giveVIPApplyInfoDao.listByTargetUid(targetUid, state, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countByStateAndTargetUid(Long targetUid, Integer state) {
      return giveVIPApplyInfoDao.countByTargetUid(targetUid, state);
   }
   @Override
   public GiveVIPApplyInfo selectByPrimaryKey(String id) {
      return giveVIPApplyInfoDao.get(id);
   }
   @Transactional
   @Override
   public void pass(String id, Long adminId) throws GiveVIPApplyInfoException, UserVIPPreInfoException {
      GiveVIPApplyInfo info = selectByPrimaryKey(id);
      if (info == null)
         throw new GiveVIPApplyInfoException(1, "记录不存在");
      // if (info.getState() == GiveVIPApplyInfo.STATE_NO_INFO)
      // throw new GiveVIPApplyInfoException(2, "用户未提交资料");
      if (info.getState() == GiveVIPApplyInfo.STATE_REJECT)
         throw new GiveVIPApplyInfoException(3, "已经被拒绝");
      if (info.getState() == GiveVIPApplyInfo.STATE_SUCCESS)
         throw new GiveVIPApplyInfoException(4, "已经被通过");
      Long uid = info.getTargetUid();
      // 查询当前的条件
      UserVIPPreInfo preInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
      if (preInfo == null || preInfo.getProcess() < info.getLevel().getLevel()) {
         // 会员升级
         UserVIPPreInfo newInfo = new UserVIPPreInfo();
         newInfo.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ARTIFICIAL);
         newInfo.setProcess(info.getLevel().getLevel());
         newInfo.setUid(uid);
         userVIPPreInfoService.addUserVIPPreInfo(newInfo);
         // 发送消息
         // 计算相隔天数
         // 默认值
         Date lastUpgradeTime = new Date(1577836800000L);
         if (preInfo != null)
            lastUpgradeTime = preInfo.getCreateTime();
         else {
            UserInfoRegister userInfoRegister = userInfoRegisterService.selectByPrimaryKey(uid);
            if (userInfoRegister != null && userInfoRegister.getCreateTime() != null) {
               lastUpgradeTime = userInfoRegister.getCreateTime();
            }
         }
         int days = TimeUtil.getDayDifferenceCount(lastUpgradeTime, new Date());
         userAccountMsgNotificationService.artificialVipUpgradePass(uid,
               preInfo == null ? UserLevelEnum.daRen.getName()
                     : UserLevelUtil.getByLevel(preInfo.getProcess()).getName(),
               info.getLevel().getName(), days);
      }
      GiveVIPApplyInfo update = new GiveVIPApplyInfo();
      update.setId(info.getId());
      update.setState(GiveVIPApplyInfo.STATE_SUCCESS);
      update.setVerifyTime(new Date());
      update.setAdminUserId(adminId);
      giveVIPApplyInfoDao.updateSelective(update);
   }
   @Transactional
   @Override
   public void reject(String id, Long adminId, String reason) throws GiveVIPApplyInfoException {
      GiveVIPApplyInfo info = selectByPrimaryKey(id);
      if (info == null)
         throw new GiveVIPApplyInfoException(1, "记录不存在");
      if (info.getState() == GiveVIPApplyInfo.STATE_REJECT)
         throw new GiveVIPApplyInfoException(3, "已经被拒绝");
      if (info.getState() == GiveVIPApplyInfo.STATE_SUCCESS)
         throw new GiveVIPApplyInfoException(4, "已经被通过");
      GiveVIPApplyInfo update = new GiveVIPApplyInfo();
      update.setId(info.getId());
      update.setState(GiveVIPApplyInfo.STATE_REJECT);
      update.setVerifyTime(new Date());
      update.setRejectReson(reason);
      update.setAdminUserId(adminId);
      giveVIPApplyInfoDao.updateSelective(update);
      Long uid = info.getTargetUid();
      UserVIPPreInfo preInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
      // 拒绝相关消息
      userAccountMsgNotificationService
            .artificialVipUpgradeReject(uid,
                  preInfo == null ? UserLevelEnum.daRen.getName()
                        :UserLevelUtil.getShowLevel(UserLevelUtil.getByLevel(preInfo.getProcess())).getName(),
                  info.getLevel().getName(), reason);
   }
   @Override
   public List<GiveVIPApplyInfo> listBySourceUid(Long uid, int page, int pageSize) {
      return giveVIPApplyInfoDao.listBySourceUid(uid, null, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countBySourceUid(Long uid) {
      return giveVIPApplyInfoDao.countBySourceUid(uid, null);
   }
}