admin
2020-04-22 d22d18f40d088277195e5c3ab587d07450f1a94d
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/TeamUserLevelStatisticServiceImpl.java
@@ -8,10 +8,10 @@
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.user.vip.TeamUserLevelStatisticMapper;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserInviteValidRecord;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.invite.UserInviteValidRecordService;
import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
import com.yeshi.fanli.service.manger.user.UserLevelManager;
@@ -19,13 +19,14 @@
public class TeamUserLevelStatisticServiceImpl implements TeamUserLevelStatisticService {
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserLevelManager userLevelManager;
   @Resource
   private TeamUserLevelStatisticMapper teamUserLevelStatisticMapper;
   @Resource
   private UserInviteValidRecordService userInviteValidRecordService;
   @Override
   public TeamUserLevelStatistic selectByUid(Long uid) {
@@ -34,53 +35,69 @@
   @Override
   public void initData(Long uid) {
      int state = ThreeSale.STATE_SUCCESS;
      long count = threeSaleSerivce.countFirstTeam(uid, state);
      List<ThreeSale> list = threeSaleSerivce.listFirstTeam(0L, (int) count, uid, state);
      int normalFirstCount = 0;
      int pageSize = 1000;
      // 直接粉丝统计
      int daRenFirstCount = 0;
      int highFirstCount = 0;
      int superFirstCount = 0;
      for (ThreeSale ts : list) {
         UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorker().getId());
         if (level == UserLevelEnum.normalVIP) {
            normalFirstCount++;
         } else if (level == UserLevelEnum.highVIP) {
            highFirstCount++;
         } else if (level == UserLevelEnum.superVIP) {
            superFirstCount++;
      int tearcherFirstCount = 0;
      for (int i = 0; i < 100; i ++) {
         List<UserInviteValidRecord> list = userInviteValidRecordService.listFirstTeam(i * pageSize, pageSize, uid);
         if (list == null || list.size() == 0) {
            break;
         }
         for (UserInviteValidRecord ts : list) {
            UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorkerId());
            if (level == UserLevelEnum.daRen) {
               daRenFirstCount++;
            }  else if (level == UserLevelEnum.highVIP) {
               highFirstCount++;
            } else if (level == UserLevelEnum.superVIP) {
               superFirstCount++;
            } else if (level == UserLevelEnum.tearcher) {
               tearcherFirstCount++;
            }
         }
      }
      int normalSecondCount = 0;
      // 间接粉丝统计
      int daRenSecondCount = 0;
      int highSecondCount = 0;
      int superSecondCount = 0;
      long secondCount = threeSaleSerivce.countSecondTeam(uid, state);
      int pageSize = 1000;
      int toalPage = (int) (secondCount % pageSize == 0 ? secondCount / pageSize : secondCount / pageSize + 1);
      for (int i = 0; i < toalPage; i++) {
         list = threeSaleSerivce.listSecondTeam(i * pageSize, pageSize, uid, state);
         if (list != null)
            for (ThreeSale ts : list) {
               UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorker().getId());
               if (level == UserLevelEnum.normalVIP) {
                  normalSecondCount++;
               } else if (level == UserLevelEnum.highVIP) {
                  highSecondCount++;
               } else if (level == UserLevelEnum.superVIP) {
                  superSecondCount++;
               }
      int tearcherSecondCount = 0;
      for (int i = 0; i < 100; i ++) {
         List<UserInviteValidRecord> list = userInviteValidRecordService.listSecondTeam(i * pageSize, pageSize, uid);
         if (list == null || list.size() == 0) {
            break;
         }
         for (UserInviteValidRecord ts : list) {
            UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorkerId());
            if (level == UserLevelEnum.daRen) {
               daRenSecondCount++;
            } else if (level == UserLevelEnum.highVIP) {
               highSecondCount++;
            } else if (level == UserLevelEnum.superVIP) {
               superSecondCount++;
            } else if (level == UserLevelEnum.tearcher) {
               tearcherSecondCount++;
            }
         }
      }
      UserLevelEnum level = userLevelManager.getUserLevel(uid);
      TeamUserLevelStatistic statistic = new TeamUserLevelStatistic();
      statistic.setNormalFirstCount(normalFirstCount);
      statistic.setNormalSecondCount(normalSecondCount);
      statistic.setDaRenFirstCount(daRenFirstCount);
      statistic.setDaRenSecondCount(daRenSecondCount);
      statistic.setHighFirstCount(highFirstCount);
      statistic.setHighSecondCount(highSecondCount);
      statistic.setSuperFirstCount(superFirstCount);
      statistic.setSuperSecondCount(superSecondCount);
      statistic.setTearcherFirstCount(tearcherFirstCount);
      statistic.setTearcherSecondCount(tearcherSecondCount);
      statistic.setId(uid);
      statistic.setLevel(level);
      add(statistic);
@@ -90,7 +107,7 @@
   public void add(TeamUserLevelStatistic statistic) {
      TeamUserLevelStatistic old = selectByUid(statistic.getId());
      if (old == null) {
         if(statistic.getCreateTime()==null)
         if (statistic.getCreateTime() == null)
            statistic.setCreateTime(new Date());
         teamUserLevelStatisticMapper.insertSelective(statistic);
      } else {
@@ -99,4 +116,14 @@
      }
   }
   @Override
   public void updateUserLevel(Long uid) {
      UserLevelEnum level = userLevelManager.getUserLevel(uid);
      TeamUserLevelStatistic statistic = new TeamUserLevelStatistic();
      statistic.setId(uid);
      statistic.setLevel(level);
      statistic.setUpdateTime(new Date());
      teamUserLevelStatisticMapper.updateByPrimaryKeySelective(statistic);
   }
}