admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/manger/money/TeamEincomeManager.java
@@ -1,159 +1,173 @@
package com.yeshi.fanli.service.manger.money;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.entity.money.TeamEincomeRecord;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.service.inter.money.TeamEincomeRecordService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.factory.money.TeamEincomeRecordFactory;
/**
 * 团队收益管理
 * @author Administrator
 *
 */
@Component
public class TeamEincomeManager {
   @Resource
   private TeamEincomeRecordService teamEincomeRecordService;
   @Resource
   private UserMoneyService userMoneyService;
   @Resource
   private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
   /**
    * @throws ParamsException
    * @throws TeamEincomeRecordException
    * 添加团队奖金
    * @Title: addTeamReward
    * @Description:
    * @param hongBaoList
    * @param uid
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamReward(Long uid, Date preSendTime, BigDecimal money, int sourceType)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamReward(day, uid, money, sourceType, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * 添加团队补贴
    * @Title: addTeamSubsidy
    * @Description:
    * @param uid
    * @param taskKey
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamSubsidy(Long uid, Date preSendTime, BigDecimal money, int sourceType)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamSubsidy(day, uid, money, sourceType, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * 添加团队分红
    * @Title: addTeamDividents
    * @Description:
    * @param uid
    * @param preSendTime
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamDividents(Long uid, Date preSendTime, BigDecimal money,int type)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamDividents(day, uid, money,type, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * @throws UserMoneyDetailException
    * 团队奖金 到账到用户余额
    * @Title: addTOUserAccount
    * @Description:
    * @param day
    * @param uid
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamRewardTOUserAccount(Date preSendTime, Long uid) throws UserMoneyDetailException {
      List<Integer> typeList = new ArrayList<>();
      typeList.add(TeamEincomeRecord.TYPE_TEAM_REWARD);
      Date now = new Date();
      List<TeamEincomeRecord> list = teamEincomeRecordService.listCanRecieveRecord(preSendTime, uid, typeList);
      BigDecimal money = new BigDecimal(0);
      for (TeamEincomeRecord record : list) {
         record = teamEincomeRecordService.selectByPrimaryKeyForUpdate(record.getId());
         money = money.add(record.getMoney());
         teamEincomeRecordService.setRecieved(record.getId());
      }
      UserMoneyDetail detail = UserMoneyDetailFactory.createTeamReward(uid, money, preSendTime);
      userMoneyService.addUserMoney(uid, money, detail);
      // 发送消息
      BigDecimal balance = userMoneyService.getBalance(uid);
      userMoneyMsgNotificationService.teamRewardReceive(uid, money, balance, now);
   }
   /**
    * 团队分红到账
    * @Title: addTeamDividentsTOUserAccount
    * @Description:
    * @param preSendTime
    * @param uid
    * @throws UserMoneyDetailException
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamDividentsTOUserAccount(Date preSendTime, Long uid) throws UserMoneyDetailException {
      List<Integer> typeList = new ArrayList<>();
      typeList.add(TeamEincomeRecord.TYPE_TEAM_DIVIDENTS);
      typeList.add(TeamEincomeRecord.TYPE_TEAM_SUBSIDY);
      Date now = new Date();
      List<TeamEincomeRecord> list = teamEincomeRecordService.listCanRecieveRecord(preSendTime, uid, typeList);
      BigDecimal money = new BigDecimal(0);
      for (TeamEincomeRecord record : list) {
         record = teamEincomeRecordService.selectByPrimaryKeyForUpdate(record.getId());
         money = money.add(record.getMoney());
         teamEincomeRecordService.setRecieved(record.getId());
      }
      UserMoneyDetail detail = UserMoneyDetailFactory.createTeamDividents(uid, money, preSendTime);
      userMoneyService.addUserMoney(uid, money, detail);
      // 发送消息
      BigDecimal balance = userMoneyService.getBalance(uid);
      userMoneyMsgNotificationService.teamDividend(uid, money, balance, now);
   }
}
package com.yeshi.fanli.service.manger.money;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.entity.money.TeamEincomeRecord;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.service.inter.money.TeamEincomeRecordService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.factory.money.TeamEincomeRecordFactory;
/**
 * 团队收益管理
 * @author Administrator
 *
 */
@Component
public class TeamEincomeManager {
   @Resource
   private TeamEincomeRecordService teamEincomeRecordService;
   @Resource
   private UserMoneyService userMoneyService;
   @Resource
   private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
   @Resource
   private HongBaoV2Service hongBaoV2Service;
   /**
    * @throws ParamsException
    * @throws TeamEincomeRecordException
    * 添加团队奖金
    * @Title: addTeamReward
    * @Description:
    * @param hongBaoList
    * @param uid
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamReward(Long uid, Date preSendTime, BigDecimal money, int sourceType)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamReward(day, uid, money, sourceType, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * 添加团队补贴
    * @Title: addTeamSubsidy
    * @Description:
    * @param uid
    * @param taskKey
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamSubsidy(Long uid, Date preSendTime, BigDecimal money, int sourceType)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamSubsidy(day, uid, money, sourceType, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * 添加团队分红
    * @Title: addTeamDividents
    * @Description:
    * @param uid
    * @param preSendTime
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamDividents(Long uid, Date preSendTime, BigDecimal money,int type)
         throws TeamEincomeRecordException, ParamsException {
      String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
      TeamEincomeRecord record = TeamEincomeRecordFactory.createTeamDividents(day, uid, money,type, null);
      teamEincomeRecordService.addTeamEincomeRecord(record);
   }
   /**
    * @throws UserMoneyDetailException
    * 团队奖金 到账到用户余额
    * @Title: addTOUserAccount
    * @Description:
    * @param day
    * @param uid
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamRewardTOUserAccount(Date preSendTime, Long uid) throws UserMoneyDetailException {
      List<Integer> typeList = new ArrayList<>();
      typeList.add(TeamEincomeRecord.TYPE_TEAM_REWARD);
      Date now = new Date();
      List<TeamEincomeRecord> list = teamEincomeRecordService.listCanRecieveRecord(preSendTime, uid, typeList);
      BigDecimal money = new BigDecimal(0);
      for (TeamEincomeRecord record : list) {
         record = teamEincomeRecordService.selectByPrimaryKeyForUpdate(record.getId());
         money = money.add(record.getMoney());
         teamEincomeRecordService.setRecieved(record.getId());
      }
      UserMoneyDetail detail = UserMoneyDetailFactory.createTeamReward(uid, money, preSendTime);
      userMoneyService.addUserMoney(uid, money, detail);
      // 发送消息
      BigDecimal balance = userMoneyService.getBalance(uid);
      userMoneyMsgNotificationService.teamRewardReceive(uid, money, balance, now);
      //更改状态
      List<Integer> hongBaoTypeList=new ArrayList<>();
      hongBaoTypeList.add(HongBaoV2.TYPE_YIJI);
      hongBaoTypeList.add(HongBaoV2.TYPE_ERJI);
      hongBaoTypeList.add(HongBaoV2.TYPE_SHARE_YIJI);
      hongBaoTypeList.add(HongBaoV2.TYPE_SHARE_ERJI);
      hongBaoV2Service.setHongBaoRecieved(uid,hongBaoTypeList,preSendTime);
   }
   /**
    * 团队分红到账
    * @Title: addTeamDividentsTOUserAccount
    * @Description:
    * @param preSendTime
    * @param uid
    * @throws UserMoneyDetailException
    * void 返回类型
    * @throws
    */
   @Transactional(rollbackFor = Exception.class)
   public void addTeamDividentsTOUserAccount(Date preSendTime, Long uid) throws UserMoneyDetailException {
      List<Integer> typeList = new ArrayList<>();
      typeList.add(TeamEincomeRecord.TYPE_TEAM_DIVIDENTS);
      typeList.add(TeamEincomeRecord.TYPE_TEAM_SUBSIDY);
      Date now = new Date();
      List<TeamEincomeRecord> list = teamEincomeRecordService.listCanRecieveRecord(preSendTime, uid, typeList);
      BigDecimal money = new BigDecimal(0);
      for (TeamEincomeRecord record : list) {
         record = teamEincomeRecordService.selectByPrimaryKeyForUpdate(record.getId());
         money = money.add(record.getMoney());
         teamEincomeRecordService.setRecieved(record.getId());
      }
      UserMoneyDetail detail = UserMoneyDetailFactory.createTeamDividents(uid, money, preSendTime);
      userMoneyService.addUserMoney(uid, money, detail);
      // 发送消息
      BigDecimal balance = userMoneyService.getBalance(uid);
      userMoneyMsgNotificationService.teamDividend(uid, money, balance, now);
   }
}