admin
2020-04-08 4e7d423e48139727ec7177855f5c4949530b8817
团队分红相关处理
37个文件已添加
12个文件已修改
3个文件已删除
3214 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamDividentsDebtMapper.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamDividentsDebtRepayHistoryMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsRecordMapper.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderMapper.java 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceUserMapper.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/vip/TeamUserLevelStatisticMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/OrderTopicTagEnum.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/user/UserTopicTagEnum.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/UserForbiddenMQMsg.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/order/dividents/UserDividentsDayDTO.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/vip/TeamUserLevelStatistic.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/money/UserMoneyDetail.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsDebt.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsDebtRepayHistory.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsRecord.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrder.java 135 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceUser.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/ParamsException.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/money/OrderTeamRewardDebtException.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/money/TeamDividentsDebtException.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsRecordException.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsSourceOrderException.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamDividentsJob.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamDividentsDebtMapper.xml 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamDividentsDebtRepayHistoryMapper.xml 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsRecordMapper.xml 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderMapper.xml 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceUserMapper.xml 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/vip/TeamUserLevelStatisticMapper.xml 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/OrderTeamRewardDebtServiceImpl.java 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamDividentsDebtServiceImpl.java 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/tb/TaoBaoWeiQuanDrawBackServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsRecordServiceImpl.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceUserServiceImpl.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/TeamUserLevelStatisticServiceImpl.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/money/OrderTeamRewardDebtService.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/money/TeamDividentsDebtService.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsRecordService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceOrderService.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceUserService.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/invite/ThreeSaleSerivce.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/vip/TeamUserLevelStatisticService.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java 263 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/CMQManager.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/MoneyBigDecimalUtil.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/factory/UserMoneyDetailFactory.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/test/java/org/fanli/MyBatisProduce.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamDividentsDebtMapper.java
New file
@@ -0,0 +1,49 @@
package com.yeshi.fanli.dao.mybatis.money;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt;
public interface TeamDividentsDebtMapper extends BaseMapper<TeamDividentsDebt> {
    /**
     * 检索(根据剩余资金与用户ID)
     *
     * @param minMoney
     * @param maxMoney
     * @param uid
     * @param page
     * @param pageSize
     * @return
     */
    List<TeamDividentsDebt> listByLeftMoneyAndUid(@Param("minMoney") BigDecimal minMoney,
            @Param("maxMoney") BigDecimal maxMoney, @Param("uid") Long uid, @Param("start") long start,
            @Param("count") int count);
    /**
     * 检索(根据剩余资金与用户ID)
     *
     * @param minMoney
     * @param maxMoney
     * @param uid
     * @return
     */
    long countByLeftMoneyAndUid(@Param("minMoney") BigDecimal minMoney, @Param("maxMoney") BigDecimal maxMoney,
            @Param("uid") Long uid);
    TeamDividentsDebt selectByPrimaryKeyForUpdate(Long id);
    /**
     * 计算欠款金额(根据用户ID)
     *
     * @param uid
     * @return
     */
    BigDecimal sumLeftMoneyByUid(Long uid);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamDividentsDebtRepayHistoryMapper.java
New file
@@ -0,0 +1,8 @@
package com.yeshi.fanli.dao.mybatis.money;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory;
public interface TeamDividentsDebtRepayHistoryMapper extends BaseMapper<TeamDividentsDebtRepayHistory> {
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsRecordMapper.java
New file
@@ -0,0 +1,20 @@
package com.yeshi.fanli.dao.mybatis.order.dividents;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord;
public interface TeamDividentsRecordMapper extends BaseMapper<TeamDividentsRecord> {
    /**
     * 根据用户ID与日期检索
     * @Title: selectByUidAndDay
     * @Description:
     * @param uid
     * @param day
     * @return
     * TeamDividentsRecord 返回类型
     * @throws
     */
    TeamDividentsRecord selectByUidAndDayForUpdate(Long uid, String day);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderMapper.java
New file
@@ -0,0 +1,76 @@
package com.yeshi.fanli.dao.mybatis.order.dividents;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
public interface TeamDividentsSourceOrderMapper extends BaseMapper<TeamDividentsSourceOrder> {
    TeamDividentsSourceOrder selectByPrimaryKeyForUpdate(Long id);
    /**
     * 根据用户ID和预计发送时间查询能参与分红的订单
     * @Title: listCanSendByUidAndPreSendTime
     * @Description:
     * @param uid
     * @param preSendTime
     * @param start
     * @param count
     * @return
     * List<TeamDividentsSourceOrder> 返回类型
     * @throws
     */
    List<TeamDividentsSourceOrder> lisByUidAndPreSendTimeAndState(@Param("uid") Long uid,
            @Param("preSendTime") Date preSendTime,    @Param("state") int state, @Param("start") long start, @Param("count") int count);
    long countByUidAndPreSendTimeAndState(@Param("uid") Long uid, @Param("preSendTime") Date preSendTime,
            @Param("state") int state);
    /**
     * 根据预计发送时间与状态统计产生分红订单的用户ID
     * @Title: listUidByPreSendTimeAndSatte
     * @Description:
     * @param preSendTime
     * @param state
     * @param start
     * @param count
     * @return
     * List<Long> 返回类型
     * @throws
     */
    List<Long> listUidByPreSendTimeAndState(@Param("preSendTime") Date preSendTime, @Param("state") Integer state,
            @Param("start") long start, @Param("count") int count);
    long countUidByPreSendTimeAndState(@Param("preSendTime") Date preSendTime, @Param("state") Integer state);
    /**
     * 设置用户的订单为无效
     * @Title: setInvalidByUidAndState
     * @Description:
     * @param uid
     * @param state
     * @param beiZhu
     * @return
     * int 返回类型
     * @throws
     */
    int setStateByUidAndState(@Param("uid") Long uid, @Param("targetState") int targetState, @Param("state") int state, @Param("beiZhu") String beiZhu);
    /**
     * 根据订单信息检索
     * @Title: selectByOrderNoSourceType
     * @Description:
     * @param orderNo
     * @param sourceType
     * @return
     * TeamDividentsSourceOrder 返回类型
     * @throws
     */
    TeamDividentsSourceOrder selectByOrderNoSourceType(@Param("orderNo") String orderNo,
            @Param("sourceType") int sourceType);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceUserMapper.java
New file
@@ -0,0 +1,60 @@
package com.yeshi.fanli.dao.mybatis.order.dividents;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser;
public interface TeamDividentsSourceUserMapper extends BaseMapper<TeamDividentsSourceUser> {
    /**
     * 根据日期与目标用户ID统计资金
     * @Title: sumMoneyByUidAndDay
     * @Description:
     * @param uid
     * @param day
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    BigDecimal sumMoneyByTargetUidAndDay(@Param("uid") Long uid, @Param("day") String day);
    /**
     * 根据日期检索用户ID
     * @Title: listTargetUidByDay
     * @Description:
     * @param day
     * @param start
     * @param count
     * @return
     * List<Long> 返回类型
     * @throws
     */
    List<Long> listTargetUidByDay(@Param("day") String day, @Param("start") long start, @Param("count") int count);
    /**
     * 根据日期查询目标用户ID
     * @Title: countTargetUidByDay
     * @Description:
     * @param day
     * @return
     * long 返回类型
     * @throws
     */
    long countTargetUidByDay(@Param("day") String day);
    /**
     * 根据日期与源用户ID查询
     * @Title: listBySourceUidAndDay
     * @Description:
     * @param sourceUid
     * @param day
     * @return
     * List<TeamDividentsSourceUser> 返回类型
     * @throws
     */
    List<TeamDividentsSourceUser> listBySourceUidAndDay(@Param("sourceUid") Long sourceUid, @Param("day") String day);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/vip/TeamUserLevelStatisticMapper.java
New file
@@ -0,0 +1,8 @@
package com.yeshi.fanli.dao.mybatis.user.vip;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
public interface TeamUserLevelStatisticMapper extends BaseMapper<TeamUserLevelStatistic> {
}
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/OrderTopicTagEnum.java
@@ -4,6 +4,7 @@
import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
public enum OrderTopicTagEnum {
    orderStatistic(OrderMQMsg.class), // 订单统计
@@ -15,7 +16,8 @@
    orderFanLiSeparateByOrderNo(OrderMoneyRecievedMQMsg.class),//订单实时到账,按订单号分离
    banLiShopOrderDelay(BanLiShopOrderMQMsg.class), // 板栗商城下单
    banLiShopOrderRefund(BanLiShopOrderMQMsg.class), // 板栗商城订单退款
    banLiShopOrderPaid(BanLiShopOrderMQMsg.class);// 商城订单支付成功
    banLiShopOrderPaid(BanLiShopOrderMQMsg.class), // 商城订单支付成功
    taoBaoOrderWeiQuan(TaoBaoWeiQuanOrder.class);// 淘宝维权订单
    private final Class<?> clazz;
fanli/src/main/java/com/yeshi/fanli/dto/mq/user/UserTopicTagEnum.java
@@ -4,6 +4,7 @@
import com.yeshi.fanli.dto.mq.user.body.InterTokenMQMsg;
import com.yeshi.fanli.dto.mq.user.body.InviteCodeActiveMQMsg;
import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg;
import com.yeshi.fanli.dto.mq.user.body.UserForbiddenMQMsg;
import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg;
import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg;
import com.yeshi.fanli.dto.mq.user.body.UserRedPackGiftMQMsg;
@@ -22,6 +23,7 @@
    tokenOutOfDate(InterTokenMQMsg.class),//口令过期
    redPackGiftDrawback(UserRedPackGiftMQMsg.class),// 红包赠送退回
    inviteCodeActive(InviteCodeActiveMQMsg.class),//邀请码激活
    forbiddenUser(UserForbiddenMQMsg.class), // 封禁用户
    userInfoUpdate(UserInfoUpdateMQMsg.class); //用户信息修改
    private final Class<?> clazz;
fanli/src/main/java/com/yeshi/fanli/dto/mq/user/body/UserForbiddenMQMsg.java
New file
@@ -0,0 +1,41 @@
package com.yeshi.fanli.dto.mq.user.body;
import java.util.Date;
import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
import com.yeshi.fanli.entity.common.AdminUser;
/**
 * 用户封禁
 * @author Administrator
 *
 */
public class UserForbiddenMQMsg extends BaseMQMsgBody {
    private Long uid;// 用户ID
    private Date createTime;// 创建时间
    private AdminUser admin;// 封禁的管理员
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public AdminUser getAdmin() {
        return admin;
    }
    public void setAdmin(AdminUser admin) {
        this.admin = admin;
    }
}
fanli/src/main/java/com/yeshi/fanli/dto/order/dividents/UserDividentsDayDTO.java
New file
@@ -0,0 +1,29 @@
package com.yeshi.fanli.dto.order.dividents;
public class UserDividentsDayDTO {
    private Long uid;
    private String day;
    public UserDividentsDayDTO(Long uid, String day) {
        super();
        this.uid = uid;
        this.day = day;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public String getDay() {
        return day;
    }
    public void setDay(String day) {
        this.day = day;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/vip/TeamUserLevelStatistic.java
New file
@@ -0,0 +1,115 @@
package com.yeshi.fanli.entity.bus.user.vip;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 * 团队成员等级统计
 * @author Administrator
 *
 */
@Table("yeshi_ec_team_user_level_statistic")
public class TeamUserLevelStatistic {
    @Column(name = "tuls_uid")
    private Long id;
    @Column(name = "tuls_level")
    private UserLevelEnum level;
    @Column(name = "tuls_normal_first_count")
    private Integer normalFirstCount;
    @Column(name = "tuls_normal_second_count")
    private Integer normalSecondCount;
    @Column(name = "tuls_high_first_count")
    private Integer highFirstCount;
    @Column(name = "tuls_high_second_count")
    private Integer highSecondCount;
    @Column(name = "tuls_super_first_count")
    private Integer superFirstCount;
    @Column(name = "tuls_super_second_count")
    private Integer superSecondCount;
    @Column(name = "tuls_create_time")
    private Date createTime;
    @Column(name = "tuls_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserLevelEnum getLevel() {
        return level;
    }
    public void setLevel(UserLevelEnum level) {
        this.level = level;
    }
    public Integer getNormalFirstCount() {
        return normalFirstCount;
    }
    public void setNormalFirstCount(Integer normalFirstCount) {
        this.normalFirstCount = normalFirstCount;
    }
    public Integer getNormalSecondCount() {
        return normalSecondCount;
    }
    public void setNormalSecondCount(Integer normalSecondCount) {
        this.normalSecondCount = normalSecondCount;
    }
    public Integer getHighFirstCount() {
        return highFirstCount;
    }
    public void setHighFirstCount(Integer highFirstCount) {
        this.highFirstCount = highFirstCount;
    }
    public Integer getHighSecondCount() {
        return highSecondCount;
    }
    public void setHighSecondCount(Integer highSecondCount) {
        this.highSecondCount = highSecondCount;
    }
    public Integer getSuperFirstCount() {
        return superFirstCount;
    }
    public void setSuperFirstCount(Integer superFirstCount) {
        this.superFirstCount = superFirstCount;
    }
    public Integer getSuperSecondCount() {
        return superSecondCount;
    }
    public void setSuperSecondCount(Integer superSecondCount) {
        this.superSecondCount = superSecondCount;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/money/UserMoneyDetail.java
@@ -57,7 +57,7 @@
        extractAutoWX("自动提现", "http://img.flqapp.com/resource/money_detail/icon_extract.png", ""),
        extractAutoWXRefund("自动提现失败", "http://img.flqapp.com/resource/money_detail/icon_extract.png", ""),
        subsidy("额外补贴", "http://img.flqapp.com/resource/msg/icon_msg_subsidy.png", ""),
        orderTeamReward("团队奖励", "http://img.flqapp.com/resource/msg/icon_msg_team_reward.png", "");
        orderTeamDividents("团队分红", "http://img.flqapp.com/resource/msg/icon_msg_team_reward.png", "");
        private final String desc;
        private final String picture;
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsDebt.java
New file
@@ -0,0 +1,91 @@
package com.yeshi.fanli.entity.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
@Table("yeshi_ec_order_team_dividents_debt")
public class TeamDividentsDebt {
    @Column(name="tdd_id")
    private Long id;
    @Column(name="tdd_uid")
    private Long uid;
    @Column(name="tdd_origin_money")
    private BigDecimal originMoney;
    @Column(name="tdd_left_money")
    private BigDecimal leftMoney;
    @Column(name="tdd_order_no")
    private String orderNo;
    @Column(name="tdd_source_type")
    private Integer sourceType;
    @Column(name="tdd_create_time")
    private Date createTime;
    @Column(name="tdd_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public BigDecimal getOriginMoney() {
        return originMoney;
    }
    public void setOriginMoney(BigDecimal originMoney) {
        this.originMoney = originMoney;
    }
    public BigDecimal getLeftMoney() {
        return leftMoney;
    }
    public void setLeftMoney(BigDecimal leftMoney) {
        this.leftMoney = leftMoney;
    }
    public String getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    public Integer getSourceType() {
        return sourceType;
    }
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsDebtRepayHistory.java
New file
@@ -0,0 +1,71 @@
package com.yeshi.fanli.entity.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
@Table("yeshi_ec_order_team_dividents_debt_repay_history")
public class TeamDividentsDebtRepayHistory {
    @Column(name = "drh_id")
    private Long id;
    @Column(name = "drh_debt_id")
    private TeamDividentsDebt debt;
    @Column(name = "drh_money")
    private BigDecimal money;
    @Column(name = "drh_uid")
    private Long uid;
    @Column(name = "drh_beizhu")
    private String beiZhu;
    @Column(name = "drh_create_time")
    private Date createTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public TeamDividentsDebt getDebt() {
        return debt;
    }
    public void setDebt(TeamDividentsDebt debt) {
        this.debt = debt;
    }
    public BigDecimal getMoney() {
        return money;
    }
    public void setMoney(BigDecimal money) {
        this.money = money;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public String getBeiZhu() {
        return beiZhu;
    }
    public void setBeiZhu(String beiZhu) {
        this.beiZhu = beiZhu;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsRecord.java
New file
@@ -0,0 +1,90 @@
package com.yeshi.fanli.entity.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 * 分红记录
 * @author Administrator
 *
 */
@Table("yeshi_ec_team_dividents_record")
public class TeamDividentsRecord {
    public final static int STATE_VALID = 1;
    public final static int STATE_INVALID = 0;
    @Column(name = "td_id")
    private Long id;
    @Column(name = "td_uid")
    private Long uid;
    @Column(name = "td_day")
    private String day;// 天,如:2020-04-01
    @Column(name = "td_money")
    private BigDecimal money;
    @Column(name = "td_state")
    private Integer state;
    @Column(name = "td_create_time")
    private Date createTime;
    @Column(name = "td_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public String getDay() {
        return day;
    }
    public void setDay(String day) {
        this.day = day;
    }
    public BigDecimal getMoney() {
        return money;
    }
    public void setMoney(BigDecimal money) {
        this.money = money;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrder.java
New file
@@ -0,0 +1,135 @@
package com.yeshi.fanli.entity.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 * 分红源订单
 * @author Administrator
 *
 */
@Table("yeshi_ec_team_dividents_source_order")
public class TeamDividentsSourceOrder {
    // 已经发送
    public final static int STATE_ALREADY_SEND = 2;
    // 可以发送
    public final static int STATE_CAN_SEND = 1;
    // 无效
    public final static int STATE_INVALID = 0;
    @Column(name = "tdo_id")
    private Long id;
    @Column(name = "tdo_uid")
    private Long uid;
    @Column(name = "tdo_order_no")
    private String orderNo;
    @Column(name = "tdo_source_type")
    private Integer sourceType;
    @Column(name = "tdo_state")
    private Integer state;
    @Column(name = "tdo_money")
    private BigDecimal money;
    @Column(name = "tdo_pre_send_time")
    private Date preSendTime;// 预计发送时间
    @Column(name = "tdo_send_time")
    private Date sendTime;
    @Column(name = "tdo_beizhu")
    private String beiZhu;// 备注
    @Column(name = "tdo_create_time")
    private Date createTime;
    @Column(name = "tdo_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public String getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    public Integer getSourceType() {
        return sourceType;
    }
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    public BigDecimal getMoney() {
        return money;
    }
    public void setMoney(BigDecimal money) {
        this.money = money;
    }
    public Date getPreSendTime() {
        return preSendTime;
    }
    public void setPreSendTime(Date preSendTime) {
        this.preSendTime = preSendTime;
    }
    public Date getSendTime() {
        return sendTime;
    }
    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getBeiZhu() {
        return beiZhu;
    }
    public void setBeiZhu(String beiZhu) {
        this.beiZhu = beiZhu;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceUser.java
New file
@@ -0,0 +1,87 @@
package com.yeshi.fanli.entity.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 *分红源用户
 * @author Administrator
 *
 */
@Table("yeshi_ec_team_dividents_source_user")
public class TeamDividentsSourceUser {
    @Column(name = "tdsu_id")
    private Long id;
    @Column(name = "tdsu_target_uid")
    private Long targetUid;
    @Column(name = "tdsu_source_uid")
    private Long sourceUid;
    @Column(name = "tdsu_day")
    private String day;
    @Column(name = "tdsu_money")
    private BigDecimal money;
    @Column(name = "tdsu_create_time")
    private Date createTime;
    @Column(name = "tdsu_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getTargetUid() {
        return targetUid;
    }
    public void setTargetUid(Long targetUid) {
        this.targetUid = targetUid;
    }
    public Long getSourceUid() {
        return sourceUid;
    }
    public void setSourceUid(Long sourceUid) {
        this.sourceUid = sourceUid;
    }
    public String getDay() {
        return day;
    }
    public void setDay(String day) {
        this.day = day;
    }
    public BigDecimal getMoney() {
        return money;
    }
    public void setMoney(BigDecimal money) {
        this.money = money;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/ParamsException.java
New file
@@ -0,0 +1,14 @@
package com.yeshi.fanli.exception;
public class ParamsException extends BaseException {
    private static final long serialVersionUID = 1L;
    public ParamsException(int code, String msg) {
        super(code, msg);
    }
    public ParamsException() {
        super();
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/money/OrderTeamRewardDebtException.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/exception/money/TeamDividentsDebtException.java
New file
@@ -0,0 +1,20 @@
package com.yeshi.fanli.exception.money;
import com.yeshi.fanli.exception.BaseException;
public class TeamDividentsDebtException extends BaseException {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    public TeamDividentsDebtException(int code, String msg) {
        super(code, msg);
    }
    public TeamDividentsDebtException() {
        super();
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsRecordException.java
New file
@@ -0,0 +1,16 @@
package com.yeshi.fanli.exception.order.dividents;
import com.yeshi.fanli.exception.BaseException;
public class TeamDividentsRecordException extends BaseException {
    private static final long serialVersionUID = 1L;
    public TeamDividentsRecordException(int code, String msg) {
        super(code, msg);
    }
    public TeamDividentsRecordException() {
        super();
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsSourceOrderException.java
New file
@@ -0,0 +1,16 @@
package com.yeshi.fanli.exception.order.dividents;
import com.yeshi.fanli.exception.BaseException;
public class TeamDividentsSourceOrderException extends BaseException {
    private static final long serialVersionUID = 1L;
    public TeamDividentsSourceOrderException(int code, String msg) {
        super(code, msg);
    }
    public TeamDividentsSourceOrderException() {
        super();
    }
}
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamDividentsJob.java
New file
@@ -0,0 +1,80 @@
package com.yeshi.fanli.job.order;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.dto.order.dividents.UserDividentsDayDTO;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.CMQManager;
import com.yeshi.fanli.util.TimeUtil;
//订单团队分红
@Component
public class OrderTeamDividentsJob {
    @Resource
    private TeamDividentsManager teamDividentsManager;
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private TeamDividentsSourceUserService teamDividentsSourceUserService;
    public OrderTeamDividentsJob() {
    }
    // 开始分红,每月25号执行
    @XxlJob("startOrderTeamDividents")
    public ReturnT<String> startDividents(String param) throws Exception {
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        Date preSendTime = new Date(TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd"));
        long count = teamDividentsSourceOrderService.countCanSendUidByPreSendTime(preSendTime);
        int pageSize = 500;
        int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize);
        for (int i = 0; i < totalPage; i++) {
            List<Long> list = teamDividentsSourceOrderService.listCanSendUidByPreSendTime(preSendTime, i + 1, pageSize);
            for (Long uid : list) {
                teamDividentsManager.startDividents(uid);
            }
        }
        startAddDividentsRecord(day);
        return ReturnT.SUCCESS;
    }
    private void startAddDividentsRecord(String day) {
        if (!teamDividentsManager.isSourceUserComupteFinish(day))
            return;
        // 统计资金
        int pageSize = 500;
        long count = teamDividentsSourceUserService.countTargetUid(day);
        int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
        List<Long> targetUidList = new ArrayList<>();
        for (int p = 0; p < totalPage; p++) {
            List<Long> uidList = teamDividentsSourceUserService.listTargetUid(day, p + 1, pageSize);
            if (uidList != null && uidList.size() > 0)
                targetUidList.addAll(uidList);
        }
        for (Long uid : targetUidList)
            CMQManager.getInstance().addTeamDividentsMsg(new UserDividentsDayDTO(uid, day));
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamDividentsDebtMapper.xml
New file
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.dao.mybatis.money.TeamDividentsDebtMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt">
        <id column="tdd_id" property="id" jdbcType="BIGINT" />
        <result column="tdd_uid" property="uid" jdbcType="BIGINT" />
        <result column="tdd_origin_money" property="originMoney"
            jdbcType="DECIMAL" />
        <result column="tdd_left_money" property="leftMoney" jdbcType="DECIMAL" />
        <result column="tdd_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="tdd_source_type" property="sourceType"
            jdbcType="INTEGER" />
        <result column="tdd_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="tdd_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">tdd_id,tdd_uid,tdd_origin_money,tdd_left_money,tdd_order_no,tdd_source_type,tdd_create_time,tdd_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_dividents_debt where tdd_id =
        #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_dividents_debt where tdd_id = #{0} for update
    </select>
    <select id="listByLeftMoneyAndUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_dividents_debt where tdd_uid = #{uid}
        <if test="minMoney!=null">and tdd_left_money&gt;=#{minMoney}</if>
        <if test="maxMoney!=null">and #{maxMoney}&gt;tdd_left_money</if>
        limit #{start},#{count}
    </select>
    <select id="countByLeftMoneyAndUid" resultType="java.lang.Long">
        select count(*) from yeshi_ec_order_team_dividents_debt where tdd_uid =
        #{uid}
        <if test="minMoney!=null">and tdd_left_money&gt;=#{minMoney}</if>
        <if test="maxMoney!=null">and #{maxMoney}&gt;tdd_left_money</if>
    </select>
    <select id="sumLeftMoneyByUid" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">select sum(tdd_left_money) from
        yeshi_ec_order_team_dividents_debt where tdd_uid = #{0}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_order_team_dividents_debt where tdd_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_order_team_dividents_debt
        (tdd_id,tdd_uid,tdd_origin_money,tdd_left_money,tdd_order_no,tdd_source_type,tdd_create_time,tdd_update_time)
        values
        (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{originMoney,jdbcType=DECIMAL},#{leftMoney,jdbcType=DECIMAL},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_order_team_dividents_debt
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">tdd_id,</if>
            <if test="uid != null">tdd_uid,</if>
            <if test="originMoney != null">tdd_origin_money,</if>
            <if test="leftMoney != null">tdd_left_money,</if>
            <if test="orderNo != null">tdd_order_no,</if>
            <if test="sourceType != null">tdd_source_type,</if>
            <if test="createTime != null">tdd_create_time,</if>
            <if test="updateTime != null">tdd_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="originMoney != null">#{originMoney,jdbcType=DECIMAL},</if>
            <if test="leftMoney != null">#{leftMoney,jdbcType=DECIMAL},</if>
            <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt">update yeshi_ec_order_team_dividents_debt set tdd_uid =
        #{uid,jdbcType=BIGINT},tdd_origin_money =
        #{originMoney,jdbcType=DECIMAL},tdd_left_money =
        #{leftMoney,jdbcType=DECIMAL},tdd_order_no =
        #{orderNo,jdbcType=VARCHAR},tdd_source_type =
        #{sourceType,jdbcType=INTEGER},tdd_create_time =
        #{createTime,jdbcType=TIMESTAMP},tdd_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where tdd_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt">
        update yeshi_ec_order_team_dividents_debt
        <set>
            <if test="uid != null">tdd_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="originMoney != null">tdd_origin_money=#{originMoney,jdbcType=DECIMAL},</if>
            <if test="leftMoney != null">tdd_left_money=#{leftMoney,jdbcType=DECIMAL},</if>
            <if test="orderNo != null">tdd_order_no=#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">tdd_source_type=#{sourceType,jdbcType=INTEGER},</if>
            <if test="createTime != null">tdd_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">tdd_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where tdd_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamDividentsDebtRepayHistoryMapper.xml
New file
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.yeshi.fanli.dao.mybatis.money.TeamDividentsDebtRepayHistoryMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory">
        <id column="drh_id" property="id" jdbcType="BIGINT" />
        <result column="drh_money" property="money" jdbcType="DECIMAL" />
        <result column="drh_uid" property="uid" jdbcType="BIGINT" />
        <result column="drh_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="drh_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <association property="debt" column="drh_debt_id"
            javaType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt">
            <id column="drh_debt_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">drh_id,drh_debt_id,drh_money,drh_uid,drh_beizhu,drh_create_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_dividents_debt_repay_history where drh_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_order_team_dividents_debt_repay_history where drh_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_order_team_dividents_debt_repay_history
        (drh_id,drh_debt_id,drh_money,drh_uid,drh_beizhu,drh_create_time)
        values
        (#{id,jdbcType=BIGINT},#{debt.id,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{uid,jdbcType=BIGINT},#{beiZhu,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_order_team_dividents_debt_repay_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">drh_id,</if>
            <if test="debt != null">drh_debt_id,</if>
            <if test="money != null">drh_money,</if>
            <if test="uid != null">drh_uid,</if>
            <if test="beiZhu != null">drh_beizhu,</if>
            <if test="createTime != null">drh_create_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="debt != null">#{debt.id,jdbcType=BIGINT},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory">update yeshi_ec_order_team_dividents_debt_repay_history
        set drh_debt_id = #{debt.id,jdbcType=BIGINT},drh_money =
        #{money,jdbcType=DECIMAL},drh_uid = #{uid,jdbcType=BIGINT},drh_beizhu
        = #{beiZhu,jdbcType=VARCHAR},drh_create_time =
        #{createTime,jdbcType=TIMESTAMP} where drh_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory">
        update yeshi_ec_order_team_dividents_debt_repay_history
        <set>
            <if test="debt != null">drh_debt_id=#{debt.id,jdbcType=BIGINT},</if>
            <if test="money != null">drh_money=#{money,jdbcType=DECIMAL},</if>
            <if test="uid != null">drh_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="beiZhu != null">drh_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="createTime != null">drh_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
        </set>
        where drh_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsRecordMapper.xml
New file
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsRecordMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord">
        <id column="td_id" property="id" jdbcType="BIGINT" />
        <result column="td_uid" property="uid" jdbcType="BIGINT" />
        <result column="td_day" property="day" jdbcType="VARCHAR" />
        <result column="td_money" property="money" jdbcType="DECIMAL" />
        <result column="td_state" property="state" jdbcType="INTEGER" />
        <result column="td_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="td_update_time" property="updateTime" jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">td_id,td_uid,td_day,td_money,td_state,td_create_time,td_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_record where td_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_dividents_record where td_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_record
        (td_id,td_uid,td_day,td_money,td_state,td_create_time,td_update_time)
        values
        (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{day,jdbcType=VARCHAR},#{money,jdbcType=DECIMAL},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_dividents_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">td_id,</if>
            <if test="uid != null">td_uid,</if>
            <if test="day != null">td_day,</if>
            <if test="money != null">td_money,</if>
            <if test="state != null">td_state,</if>
            <if test="createTime != null">td_create_time,</if>
            <if test="updateTime != null">td_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="day != null">#{day,jdbcType=VARCHAR},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord">update yeshi_ec_team_dividents_record set td_uid =
        #{uid,jdbcType=BIGINT},td_day = #{day,jdbcType=VARCHAR},td_money =
        #{money,jdbcType=DECIMAL},td_state =
        #{state,jdbcType=INTEGER},td_create_time =
        #{createTime,jdbcType=TIMESTAMP},td_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where td_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord">
        update yeshi_ec_team_dividents_record
        <set>
            <if test="uid != null">td_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="day != null">td_day=#{day,jdbcType=VARCHAR},</if>
            <if test="money != null">td_money=#{money,jdbcType=DECIMAL},</if>
            <if test="state != null">td_state=#{state,jdbcType=INTEGER},</if>
            <if test="createTime != null">td_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">td_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where td_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderMapper.xml
New file
@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">
        <id column="tdo_id" property="id" jdbcType="BIGINT" />
        <result column="tdo_uid" property="uid" jdbcType="BIGINT" />
        <result column="tdo_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="tdo_source_type" property="sourceType"
            jdbcType="INTEGER" />
        <result column="tdo_state" property="state" jdbcType="INTEGER" />
        <result column="tdo_money" property="money" jdbcType="DECIMAL" />
        <result column="tdo_pre_send_time" property="preSendTime"
            jdbcType="TIMESTAMP" />
        <result column="tdo_send_time" property="sendTime" jdbcType="TIMESTAMP" />
        <result column="tdo_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="tdo_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">tdo_id,tdo_uid,tdo_order_no,tdo_source_type,tdo_state,tdo_money,tdo_pre_send_time,tdo_send_time,tdo_create_time,tdo_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order where tdo_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_dividents_source_order where tdo_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_source_order
        (tdo_id,tdo_uid,tdo_order_no,tdo_source_type,tdo_state,tdo_money,tdo_pre_send_time,tdo_send_time,tdo_create_time,tdo_update_time)
        values
        (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{money,jdbcType=DECIMAL},#{preSendTime,jdbcType=TIMESTAMP},#{sendTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_dividents_source_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">tdo_id,</if>
            <if test="uid != null">tdo_uid,</if>
            <if test="orderNo != null">tdo_order_no,</if>
            <if test="sourceType != null">tdo_source_type,</if>
            <if test="state != null">tdo_state,</if>
            <if test="money != null">tdo_money,</if>
            <if test="preSendTime != null">tdo_pre_send_time,</if>
            <if test="sendTime != null">tdo_send_time,</if>
            <if test="createTime != null">tdo_create_time,</if>
            <if test="updateTime != null">tdo_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="sendTime != null">#{sendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">update yeshi_ec_team_dividents_source_order set tdo_uid
        = #{uid,jdbcType=BIGINT},tdo_order_no =
        #{orderNo,jdbcType=VARCHAR},tdo_source_type =
        #{sourceType,jdbcType=INTEGER},tdo_state =
        #{state,jdbcType=INTEGER},tdo_money =
        #{money,jdbcType=DECIMAL},tdo_pre_send_time =
        #{preSendTime,jdbcType=TIMESTAMP},tdo_send_time =
        #{sendTime,jdbcType=TIMESTAMP},tdo_create_time =
        #{createTime,jdbcType=TIMESTAMP},tdo_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where tdo_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">
        update yeshi_ec_team_dividents_source_order
        <set>
            <if test="uid != null">tdo_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="orderNo != null">tdo_order_no=#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">tdo_source_type=#{sourceType,jdbcType=INTEGER},</if>
            <if test="state != null">tdo_state=#{state,jdbcType=INTEGER},</if>
            <if test="money != null">tdo_money=#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">tdo_pre_send_time=#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="sendTime != null">tdo_send_time=#{sendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">tdo_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">tdo_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where tdo_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order where tdo_id =
        #{0} for
        update
    </select>
    <select id="lisByUidAndPreSendTimeAndState" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order where tdo_uid=#{uid} and
        tdo_pre_send_time=#{preSendTime} and tdo_state=#{state} limit
        #{start},#{count}
    </select>
    <select id="countByUidAndPreSendTimeAndState" resultType="java.lang.Long">
        select
        count(*)
        from yeshi_ec_team_dividents_source_order where tdo_uid=#{uid}
        and
        tdo_pre_send_time=#{preSendTime} and tdo_state=#{state}
    </select>
    <select id="listUidByPreSendTimeAndState" resultType="java.lang.Long">
        select
        distinct(tdo_uid)
        from yeshi_ec_team_dividents_source_order where
        tdo_uid=#{uid} and
        tdo_pre_send_time=#{preSendTime} and
        tdo_state=#{state} limit
        #{start},#{count}
    </select>
    <select id="countUidByPreSendTimeAndState" resultType="java.lang.Long">
        select
        count(distinct(tdo_uid))
        from yeshi_ec_team_dividents_source_order
        where tdo_uid=#{uid} and
        tdo_pre_send_time=#{preSendTime} and
        tdo_state=#{state}
    </select>
    <update id="setStateByUidAndState">
        update yeshi_ec_team_dividents_source_order
        <set>
            tdo_state=#{targetState},
            tdo_update_time=now(),
            tdo_beizhu=#{beiZhu},
        </set>
        where tdo_uid = #{uid} and tdo_state=#{state}
    </update>
    <select id="selectByOrderNoAndSourceType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order
        where tdo_order_no=#{orderNo}
        and
        tdo_source_type=#{sourceType}
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceUserMapper.xml
New file
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceUserMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser">
        <id column="tdsu_id" property="id" jdbcType="BIGINT" />
        <result column="tdsu_target_uid" property="targetUid" jdbcType="BIGINT" />
        <result column="tdsu_source_uid" property="sourceUid" jdbcType="BIGINT" />
        <result column="tdsu_day" property="day" jdbcType="VARCHAR" />
        <result column="tdsu_money" property="money" jdbcType="DECIMAL" />
        <result column="tdsu_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="tdsu_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">tdsu_id,tdsu_target_uid,tdsu_source_uid,tdsu_day,tdsu_money,tdsu_create_time,tdsu_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_user where tdsu_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_dividents_source_user where tdsu_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_source_user
        (tdsu_id,tdsu_target_uid,tdsu_source_uid,tdsu_day,tdsu_money,tdsu_create_time,tdsu_update_time)
        values
        (#{id,jdbcType=BIGINT},#{targetUid,jdbcType=BIGINT},#{sourceUid,jdbcType=BIGINT},#{day,jdbcType=VARCHAR},#{money,jdbcType=DECIMAL},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_dividents_source_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">tdsu_id,</if>
            <if test="targetUid != null">tdsu_target_uid,</if>
            <if test="sourceUid != null">tdsu_source_uid,</if>
            <if test="day != null">tdsu_day,</if>
            <if test="money != null">tdsu_money,</if>
            <if test="createTime != null">tdsu_create_time,</if>
            <if test="updateTime != null">tdsu_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="targetUid != null">#{targetUid,jdbcType=BIGINT},</if>
            <if test="sourceUid != null">#{sourceUid,jdbcType=BIGINT},</if>
            <if test="day != null">#{day,jdbcType=VARCHAR},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser">update yeshi_ec_team_dividents_source_user set
        tdsu_target_uid = #{targetUid,jdbcType=BIGINT},tdsu_source_uid =
        #{sourceUid,jdbcType=BIGINT},tdsu_day =
        #{day,jdbcType=VARCHAR},tdsu_money =
        #{money,jdbcType=DECIMAL},tdsu_create_time =
        #{createTime,jdbcType=TIMESTAMP},tdsu_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where tdsu_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser">
        update yeshi_ec_team_dividents_source_user
        <set>
            <if test="targetUid != null">tdsu_target_uid=#{targetUid,jdbcType=BIGINT},</if>
            <if test="sourceUid != null">tdsu_source_uid=#{sourceUid,jdbcType=BIGINT},</if>
            <if test="day != null">tdsu_day=#{day,jdbcType=VARCHAR},</if>
            <if test="money != null">tdsu_money=#{money,jdbcType=DECIMAL},</if>
            <if test="createTime != null">tdsu_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">tdsu_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where tdsu_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="sumMoneyByTargetUidAndDay" resultType="java.math.BigDecimal">
        select
        sum(tdsu_money)
        from yeshi_ec_team_dividents_source_user where
        tdsu_target_uid =#{uid} and tdsu_day=#{day}
        #{id,jdbcType=BIGINT}
    </select>
    <select id="listTargetUidByDay" resultType="java.lang.Long">
        SELECT
        DISTINCT(u.`tdsu_target_uid`) FROM
        yeshi_ec_team_dividents_source_user
        u WHERE u.`tdsu_day`=#{day} limit
        #{start},#{count}
    </select>
    <select id="countTargetUidByDay" resultType="java.lang.Long"
        parameterType="java.lang.String">
        SELECT count(DISTINCT(u.`tdsu_target_uid`)) FROM
        yeshi_ec_team_dividents_source_user u WHERE u.`tdsu_day`=#{day}
    </select>
    <select id="listBySourceUidAndDay" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        FROM
        yeshi_ec_team_dividents_source_user WHERE
        `tdsu_source_uid`=#{sourceUid} and tdsu_day=#{day}
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/user/vip/TeamUserLevelStatisticMapper.xml
New file
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.yeshi.fanli.dao.mybatis.user.vip.TeamUserLevelStatisticMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic">
        <id column="tuls_uid" property="id" jdbcType="BIGINT" />
        <result column="tuls_level" property="level" jdbcType="VARCHAR" />
        <result column="tuls_normal_first_count" property="normalFirstCount"
            jdbcType="INTEGER" />
        <result column="tuls_normal_second_count" property="normalSecondCount"
            jdbcType="INTEGER" />
        <result column="tuls_high_first_count" property="highFirstCount"
            jdbcType="INTEGER" />
        <result column="tuls_high_second_count" property="highSecondCount"
            jdbcType="INTEGER" />
        <result column="tuls_super_first_count" property="superFirstCount"
            jdbcType="INTEGER" />
        <result column="tuls_super_second_count" property="superSecondCount"
            jdbcType="INTEGER" />
        <result column="tuls_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="tuls_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">tuls_uid,tuls_level,tuls_normal_first_count,tuls_normal_second_count,tuls_high_first_count,tuls_high_second_count,tuls_super_first_count,tuls_super_second_count,tuls_create_time,tuls_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_user_level_statistic where tuls_uid =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_user_level_statistic where tuls_uid =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_user_level_statistic
        (tuls_uid,tuls_level,tuls_normal_first_count,tuls_normal_second_count,tuls_high_first_count,tuls_high_second_count,tuls_super_first_count,tuls_super_second_count,tuls_create_time,tuls_update_time)
        values
        (#{id,jdbcType=BIGINT},#{level,jdbcType=VARCHAR},#{normalFirstCount,jdbcType=INTEGER},#{normalSecondCount,jdbcType=INTEGER},#{highFirstCount,jdbcType=INTEGER},#{highSecondCount,jdbcType=INTEGER},#{superFirstCount,jdbcType=INTEGER},#{superSecondCount,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_user_level_statistic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">tuls_uid,</if>
            <if test="level != null">tuls_level,</if>
            <if test="normalFirstCount != null">tuls_normal_first_count,</if>
            <if test="normalSecondCount != null">tuls_normal_second_count,</if>
            <if test="highFirstCount != null">tuls_high_first_count,</if>
            <if test="highSecondCount != null">tuls_high_second_count,</if>
            <if test="superFirstCount != null">tuls_super_first_count,</if>
            <if test="superSecondCount != null">tuls_super_second_count,</if>
            <if test="createTime != null">tuls_create_time,</if>
            <if test="updateTime != null">tuls_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="level != null">#{level,jdbcType=VARCHAR},</if>
            <if test="normalFirstCount != null">#{normalFirstCount,jdbcType=INTEGER},</if>
            <if test="normalSecondCount != null">#{normalSecondCount,jdbcType=INTEGER},</if>
            <if test="highFirstCount != null">#{highFirstCount,jdbcType=INTEGER},</if>
            <if test="highSecondCount != null">#{highSecondCount,jdbcType=INTEGER},</if>
            <if test="superFirstCount != null">#{superFirstCount,jdbcType=INTEGER},</if>
            <if test="superSecondCount != null">#{superSecondCount,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic">update yeshi_ec_team_user_level_statistic set tuls_level
        = #{level,jdbcType=VARCHAR},tuls_normal_first_count =
        #{normalFirstCount,jdbcType=INTEGER},tuls_normal_second_count =
        #{normalSecondCount,jdbcType=INTEGER},tuls_high_first_count =
        #{highFirstCount,jdbcType=INTEGER},tuls_high_second_count =
        #{highSecondCount,jdbcType=INTEGER},tuls_super_first_count =
        #{superFirstCount,jdbcType=INTEGER},tuls_super_second_count =
        #{superSecondCount,jdbcType=INTEGER},tuls_create_time =
        #{createTime,jdbcType=TIMESTAMP},tuls_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where tuls_uid =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic">
        update yeshi_ec_team_user_level_statistic
        <set>
            <if test="level != null">tuls_level=#{level,jdbcType=VARCHAR},</if>
            <if test="normalFirstCount != null">tuls_normal_first_count=#{normalFirstCount,jdbcType=INTEGER},
            </if>
            <if test="normalSecondCount != null">tuls_normal_second_count=#{normalSecondCount,jdbcType=INTEGER},
            </if>
            <if test="highFirstCount != null">tuls_high_first_count=#{highFirstCount,jdbcType=INTEGER},
            </if>
            <if test="highSecondCount != null">tuls_high_second_count=#{highSecondCount,jdbcType=INTEGER},
            </if>
            <if test="superFirstCount != null">tuls_super_first_count=#{superFirstCount,jdbcType=INTEGER},
            </if>
            <if test="superSecondCount != null">tuls_super_second_count=#{superSecondCount,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">tuls_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">tuls_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where tuls_uid = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/money/OrderTeamRewardDebtServiceImpl.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamDividentsDebtServiceImpl.java
New file
@@ -0,0 +1,120 @@
package com.yeshi.fanli.service.impl.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.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.money.TeamDividentsDebtMapper;
import com.yeshi.fanli.dao.mybatis.money.TeamDividentsDebtRepayHistoryMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebtRepayHistory;
import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
import com.yeshi.fanli.service.inter.money.TeamDividentsDebtService;
@Service
public class TeamDividentsDebtServiceImpl implements TeamDividentsDebtService {
    @Resource
    private TeamDividentsDebtMapper teamDividentsDebtMapper;
    @Resource
    private TeamDividentsDebtRepayHistoryMapper teamDividentsDebtRepayHistoryMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addDebt(TeamDividentsDebt debt) throws TeamDividentsDebtException {
        if (debt == null || debt.getOriginMoney() == null || debt.getUid() == null) {
            throw new TeamDividentsDebtException(1, "数据不完整");
        }
        if (debt.getCreateTime() == null)
            debt.setCreateTime(new Date());
        debt.setLeftMoney(debt.getOriginMoney());
        teamDividentsDebtMapper.insertSelective(debt);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void repayDebt(Long debtId, BigDecimal money) throws TeamDividentsDebtException {
        TeamDividentsDebt debt = teamDividentsDebtMapper.selectByPrimaryKeyForUpdate(debtId);
        if (debt == null)
            throw new TeamDividentsDebtException(1, "债务ID不存在");
        if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
            throw new TeamDividentsDebtException(3, "还钱必须大于0");
        if (debt.getLeftMoney().compareTo(money) < 0)
            throw new TeamDividentsDebtException(2, "还钱过多");
        // 还钱
        TeamDividentsDebt update = new TeamDividentsDebt();
        update.setId(debt.getId());
        update.setLeftMoney(debt.getLeftMoney().subtract(money));
        update.setUpdateTime(new Date());
        teamDividentsDebtMapper.updateByPrimaryKeySelective(update);
        // 加入还钱记录
        TeamDividentsDebtRepayHistory record = new TeamDividentsDebtRepayHistory();
        record.setCreateTime(new Date());
        record.setDebt(debt);
        record.setMoney(money);
        record.setUid(debt.getUid());
        teamDividentsDebtRepayHistoryMapper.insertSelective(record);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public BigDecimal repayDebtByUid(Long uid, BigDecimal money) throws TeamDividentsDebtException {
        // 还钱
        long count = countNeedRepayDebt(uid);
        int page = (int) (count % 200 == 0 ? count / 200 : count / 200 + 1);
        List<TeamDividentsDebt> totalList = new ArrayList<>();
        for (int i = 0; i < page; i++) {
            List<TeamDividentsDebt> tempList = listNeedRepayDebt(uid, i + 1, 200);
            if (tempList != null && tempList.size() > 0) {
                totalList.addAll(tempList);
            }
        }
        // 剩余资金
        BigDecimal leftMoney = new BigDecimal(money.toString());
        for (TeamDividentsDebt debt : totalList) {
            if (leftMoney.compareTo(new BigDecimal(0)) <= 0)// 余额不足扣款
                break;
            BigDecimal repayMoney = null;
            if (debt.getLeftMoney().compareTo(leftMoney) >= 0)
                repayMoney = new BigDecimal(leftMoney.toString());
            else
                repayMoney = debt.getLeftMoney();
            try {
                repayDebt(debt.getId(), repayMoney);
                leftMoney = leftMoney.subtract(repayMoney);
            } catch (TeamDividentsDebtException e) {
                // 上笔还款未成功,继续下一笔还款
            }
        }
        return leftMoney;// 返回剩余的资金
    }
    @Override
    public List<TeamDividentsDebt> listNeedRepayDebt(Long uid, int page, int count) {
        return teamDividentsDebtMapper.listByLeftMoneyAndUid(new BigDecimal("0.01"), null, uid, (page - 1) * count,
                count);
    }
    @Override
    public long countNeedRepayDebt(Long uid) {
        return teamDividentsDebtMapper.countByLeftMoneyAndUid(new BigDecimal("0.01"), null, uid);
    }
    @Override
    public BigDecimal getTotalDebtMoney(Long uid) {
        BigDecimal money = teamDividentsDebtMapper.sumLeftMoneyByUid(uid);
        if (money == null)
            money = new BigDecimal(0);
        return money;
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/money/tb/TaoBaoWeiQuanDrawBackServiceImpl.java
@@ -38,7 +38,6 @@
import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
import com.yeshi.fanli.service.inter.money.OrderTeamRewardDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyDetailService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
@@ -90,9 +89,6 @@
    @Resource
    private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
    @Resource
    private OrderTeamRewardDebtService orderTeamRewardDebtService;
    @Resource
    private UserMoneyDetailService userMoneyDetailService;
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -46,7 +46,6 @@
import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService;
import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
import com.yeshi.fanli.service.inter.money.OrderTeamRewardDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
@@ -112,10 +111,6 @@
    @Resource
    private HongBaoV2SettleTempService hongBaoV2SettleTempService;
    @Resource
    private OrderTeamRewardDebtService orderTeamRewardDebtService;
    // 下级被封禁,红包失效
    private void invalidHongBaoForbidden(Long id) {
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsRecordServiceImpl.java
New file
@@ -0,0 +1,42 @@
package com.yeshi.fanli.service.impl.order.dividents;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsRecordMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsRecordException;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsRecordService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class TeamDividentsRecordServiceImpl implements TeamDividentsRecordService {
    @Resource
    private TeamDividentsRecordMapper teamDividentsRecordMapper;
    @Override
    public void addTeamDividentsRecord(TeamDividentsRecord record)
            throws TeamDividentsRecordException, ParamsException {
        // 验证参数完整性
        if (record == null || StringUtil.isNullOrEmpty(record.getDay()) || record.getMoney() == null
                || record.getState() == null || record.getUid() == null)
            throw new ParamsException(1, "参数不完整");
        // 判断是否存在
        TeamDividentsRecord old = teamDividentsRecordMapper.selectByUidAndDayForUpdate(record.getUid(),
                record.getDay());
        if (old != null)
            throw new TeamDividentsRecordException(1, "记录已存在");
        // 加入记录
        if (record.getCreateTime() == null)
            record.setCreateTime(new Date());
        teamDividentsRecordMapper.insertSelective(record);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java
New file
@@ -0,0 +1,115 @@
package com.yeshi.fanli.service.impl.order.dividents;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class TeamDividentsSourceOrderServiceImpl implements TeamDividentsSourceOrderService {
    @Resource
    private TeamDividentsSourceOrderMapper teamDividentsSourceOrderMapper;
    @Override
    public void addTeamDividentsSourceOrder(TeamDividentsSourceOrder order)
            throws TeamDividentsSourceOrderException, ParamsException {
        if (order == null || order.getMoney() == null || StringUtil.isNullOrEmpty(order.getOrderNo())
                || order.getSourceType() == null || order.getState() == null || order.getUid() == null
                || order.getPreSendTime() == null)
            throw new ParamsException(1, "参数不完整");
        TeamDividentsSourceOrder sourceOrder = selectByOrderNoSourceType(order.getOrderNo(), order.getSourceType());
        if (sourceOrder != null)
            throw new TeamDividentsSourceOrderException(1, "订单已存在");
        if (order.getCreateTime() == null)
            order.setCreateTime(new Date());
        teamDividentsSourceOrderMapper.insertSelective(order);
    }
    @Override
    public List<TeamDividentsSourceOrder> listCanSendByUidAndPreSendTime(Long uid, Date preSendTime, int page,
            int pageSize) {
        return teamDividentsSourceOrderMapper.lisByUidAndPreSendTimeAndState(uid, preSendTime,
                TeamDividentsSourceOrder.STATE_CAN_SEND, (page - 1) * pageSize, pageSize);
    }
    @Override
    public long countCanSendByUidAndPreSendTime(Long uid, Date preSendTime) {
        return teamDividentsSourceOrderMapper.countByUidAndPreSendTimeAndState(uid, preSendTime,
                TeamDividentsSourceOrder.STATE_CAN_SEND);
    }
    @Override
    public List<Long> listCanSendUidByPreSendTime(Date preSendTime, int page, int pageSize) {
        return teamDividentsSourceOrderMapper.listUidByPreSendTimeAndState(preSendTime,
                TeamDividentsSourceOrder.STATE_CAN_SEND, (page - 1) * pageSize, pageSize);
    }
    @Override
    public Long countCanSendUidByPreSendTime(Date preSendTime) {
        return teamDividentsSourceOrderMapper.countUidByPreSendTimeAndState(preSendTime,
                TeamDividentsSourceOrder.STATE_CAN_SEND);
    }
    @Override
    public TeamDividentsSourceOrder selectByPrimaryKeyForUpdate(Long id) {
        return teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id);
    }
    @Override
    public void invalidOrder(String orderNo, int sourceType, String beiZhu) {
        TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType);
        if (order == null)
            return;
        if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND)
            return;
        TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
        update.setId(order.getId());
        update.setState(TeamDividentsSourceOrder.STATE_INVALID);
        update.setUpdateTime(new Date());
        update.setBeiZhu(beiZhu);
        teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void invalidOrderByUid(Long uid, String beiZhu) {
        teamDividentsSourceOrderMapper.setStateByUidAndState(uid, TeamDividentsSourceOrder.STATE_INVALID,
                TeamDividentsSourceOrder.STATE_CAN_SEND, beiZhu);
    }
    @Override
    @Transactional
    public void send(Long id) {
        TeamDividentsSourceOrder order = teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id);
        if (order == null)
            return;
        if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND)
            return;
        TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
        update.setId(order.getId());
        update.setState(TeamDividentsSourceOrder.STATE_ALREADY_SEND);
        update.setUpdateTime(new Date());
        update.setSendTime(new Date());
        teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public TeamDividentsSourceOrder selectByOrderNoSourceType(String orderNo, int sourceType) {
        return teamDividentsSourceOrderMapper.selectByOrderNoSourceType(orderNo, sourceType);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceUserServiceImpl.java
New file
@@ -0,0 +1,57 @@
package com.yeshi.fanli.service.impl.order.dividents;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceUserMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class TeamDividentsSourceUserServiceImpl implements TeamDividentsSourceUserService {
    @Resource
    private TeamDividentsSourceUserMapper teamDividentsSourceUserMapper;
    @Override
    public void addTeamDividentsSourceUser(TeamDividentsSourceUser teamDividentsSourceUser) throws ParamsException {
        if (teamDividentsSourceUser == null || StringUtil.isNullOrEmpty(teamDividentsSourceUser.getDay())
                || teamDividentsSourceUser.getMoney() == null || teamDividentsSourceUser.getSourceUid() == null
                || teamDividentsSourceUser.getTargetUid() == null)
            throw new ParamsException(1, "参数不完整");
        if (teamDividentsSourceUser.getCreateTime() == null)
            teamDividentsSourceUser.setCreateTime(new Date());
        teamDividentsSourceUserMapper.insertSelective(teamDividentsSourceUser);
    }
    @Override
    public BigDecimal sumMoneyByUidAndDay(Long uid, String day) {
        BigDecimal money = teamDividentsSourceUserMapper.sumMoneyByTargetUidAndDay(uid, day);
        if (money == null)
            return new BigDecimal(0);
        return money;
    }
    @Override
    public List<Long> listTargetUid(String day, int page, int pageSize) {
        return teamDividentsSourceUserMapper.listTargetUidByDay(day, (page - 1) * pageSize, pageSize);
    }
    @Override
    public List<TeamDividentsSourceUser> listBySourceUidAndDay(Long sourceUid, String day) {
        return teamDividentsSourceUserMapper.listBySourceUidAndDay(sourceUid, day);
    }
    @Override
    public long countTargetUid(String day) {
        return teamDividentsSourceUserMapper.countTargetUidByDay(day);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java
@@ -671,6 +671,12 @@
        return deepList;
    }
    
    @Override
    public List<ThreeSale> getMyBossDeepList(Long uid) {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
@@ -713,4 +719,6 @@
        threeSaleMapper.updateByPrimaryKeySelective(update);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/TeamUserLevelStatisticServiceImpl.java
New file
@@ -0,0 +1,102 @@
package com.yeshi.fanli.service.impl.user.vip;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
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.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.vip.TeamUserLevelStatisticService;
import com.yeshi.fanli.service.manger.user.UserLevelManager;
@Service
public class TeamUserLevelStatisticServiceImpl implements TeamUserLevelStatisticService {
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    @Resource
    private UserLevelManager userLevelManager;
    @Resource
    private TeamUserLevelStatisticMapper teamUserLevelStatisticMapper;
    @Override
    public TeamUserLevelStatistic selectByUid(Long uid) {
        return teamUserLevelStatisticMapper.selectByPrimaryKey(uid);
    }
    @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 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 normalSecondCount = 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++;
                    }
                }
        }
        UserLevelEnum level = userLevelManager.getUserLevel(uid);
        TeamUserLevelStatistic statistic = new TeamUserLevelStatistic();
        statistic.setNormalFirstCount(normalFirstCount);
        statistic.setNormalSecondCount(normalSecondCount);
        statistic.setHighFirstCount(highFirstCount);
        statistic.setHighSecondCount(highSecondCount);
        statistic.setSuperFirstCount(superFirstCount);
        statistic.setSuperSecondCount(superSecondCount);
        statistic.setId(uid);
        statistic.setLevel(level);
        add(statistic);
    }
    @Override
    public void add(TeamUserLevelStatistic statistic) {
        TeamUserLevelStatistic old = selectByUid(statistic.getId());
        if (old == null) {
            if(statistic.getCreateTime()==null)
                statistic.setCreateTime(new Date());
            teamUserLevelStatisticMapper.insertSelective(statistic);
        } else {
            statistic.setUpdateTime(new Date());
            teamUserLevelStatisticMapper.updateByPrimaryKeySelective(statistic);
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/money/OrderTeamRewardDebtService.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/service/inter/money/TeamDividentsDebtService.java
New file
@@ -0,0 +1,68 @@
package com.yeshi.fanli.service.inter.money;
import java.math.BigDecimal;
import java.util.List;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt;
import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
/**
 * 团队奖金欠款处理
 * @author Administrator
 *
 */
public interface TeamDividentsDebtService {
    /**
     * 添加债务
     *
     * @param debt
     * @throws TeamDividentsDebtException
     */
    public void addDebt(TeamDividentsDebt debt) throws TeamDividentsDebtException;
    /**
     * 偿还债务
     *
     * @param debtId
     * @param money
     */
    public void repayDebt(Long debtId, BigDecimal money) throws TeamDividentsDebtException;
    /**
     * 还款
     *
     * @param uid
     * @param money
     * @return 还剩下的资金
     * @throws TeamDividentsDebtException
     */
    public BigDecimal repayDebtByUid(Long uid, BigDecimal money) throws TeamDividentsDebtException;
    /**
     * 检索需要偿还的债务
     *
     * @param uid
     * @param page
     * @param count
     * @return
     */
    public List<TeamDividentsDebt> listNeedRepayDebt(Long uid, int page, int count);
    /**
     * 检索需要偿还的债务
     *
     * @param uid
     * @return
     */
    public long countNeedRepayDebt(Long uid);
    /**
     * 获取总共欠钱金额
     *
     * @param uid
     * @return
     */
    public BigDecimal getTotalDebtMoney(Long uid);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsRecordService.java
New file
@@ -0,0 +1,19 @@
package com.yeshi.fanli.service.inter.order.dividents;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsRecordException;
public interface TeamDividentsRecordService {
    /**
     * 添加团队分红记录
     * @Title: addTeamDividentsRecord
     * @Description:
     * @param record
     * void 返回类型
     * @throws
     */
    public void addTeamDividentsRecord(TeamDividentsRecord record) throws TeamDividentsRecordException, ParamsException;
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceOrderService.java
New file
@@ -0,0 +1,128 @@
package com.yeshi.fanli.service.inter.order.dividents;
import java.util.Date;
import java.util.List;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
public interface TeamDividentsSourceOrderService {
    /**
     * 添加团队分红来源订单
     * @Title: addTeamDividentsSourceOrder
     * @Description:
     * @param order
     * void 返回类型
     * @throws
     */
    public void addTeamDividentsSourceOrder(TeamDividentsSourceOrder order) throws TeamDividentsSourceOrderException,ParamsException;
    /**
     *
     * @Title: listCanSendByUidAndPreSendTime
     * @Description:
     * @param uid
     * @param preSendTime
     * @return
     * List<TeamDividentsSourceOrder> 返回类型
     * @throws
     */
    public List<TeamDividentsSourceOrder> listCanSendByUidAndPreSendTime(Long uid, Date preSendTime, int page,
            int pageSize);
    /**
     *
     * @Title: countCanSendByUidAndPreSendTime
     * @Description:
     * @param uid
     * @param preSendTime
     * @return
     * long 返回类型
     * @throws
     */
    public long countCanSendByUidAndPreSendTime(Long uid, Date preSendTime);
    /**
     * 获取能够分红的订单源用户ID列表
     * @Title: listCanSendUidByPreSendTime
     * @Description:
     * @param preSendTime
     * @param page
     * @param count
     * @return
     * List<Long> 返回类型
     * @throws
     */
    public List<Long> listCanSendUidByPreSendTime(Date preSendTime, int page, int count);
    /**
     * 获取能够分红的订单源用户ID数量
     * @Title: countCanSendUidByPreSendTime
     * @Description:
     * @param preSendTime
     * @return
     * Long 返回类型
     * @throws
     */
    public Long countCanSendUidByPreSendTime(Date preSendTime);
    /**
     * 根据主键查询
     * @Title: selectByPrimaryKeyForUpdate
     * @Description:
     * @param id
     * @return
     * TeamDividentsSourceOrder 返回类型
     * @throws
     */
    public TeamDividentsSourceOrder selectByPrimaryKeyForUpdate(Long id);
    /**
     * 使订单失效
     * @Title: invalidOrder
     * @Description:
     * @param orderNo
     * @param sourceType
     * @param beiZhu
     * void 返回类型
     * @throws
     */
    public void invalidOrder(String orderNo, int sourceType, String beiZhu);
    /**
     * 根据uid失效
     * @Title: invalidOrderByUid
     * @Description:
     * @param uid
     * @param beiZhu
     * void 返回类型
     * @throws
     */
    public void invalidOrderByUid(Long uid, String beiZhu);
    /**
     * 发送
     * @Title: send
     * @Description:
     * @param id
     * void 返回类型
     * @throws
     */
    public void send(Long id);
    /**
     * 根据订单查询
     * @Title: selectByOrderNoSourceType
     * @Description:
     * @param orderNo
     * @param sourceType
     * @return
     * TeamDividentsSourceOrder 返回类型
     * @throws
     */
    public TeamDividentsSourceOrder selectByOrderNoSourceType(String orderNo,int sourceType);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceUserService.java
New file
@@ -0,0 +1,68 @@
package com.yeshi.fanli.service.inter.order.dividents;
import java.math.BigDecimal;
import java.util.List;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser;
import com.yeshi.fanli.exception.ParamsException;
public interface TeamDividentsSourceUserService {
    /**
     * 添加分红源用户
     * @Title: addTeamDividentsSourceUser
     * @Description:
     * @param teamDividentsSourceUser
     * void 返回类型
     * @throws
     */
    public void addTeamDividentsSourceUser(TeamDividentsSourceUser teamDividentsSourceUser) throws ParamsException;
    /**
     * 计算用户总共得到的分红
     * @Title: sumMoneyByUidAndDay
     * @Description:
     * @param uid
     * @param day
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal sumMoneyByUidAndDay(Long uid, String day);
    /**
     * 查询目标用户列表
     * @Title: listTargetUid
     * @Description:
     * @param page
     * @param pageSize
     * @return
     * List<Long> 返回类型
     * @throws
     */
    public List<Long> listTargetUid(String day, int page, int pageSize);
    /**
     * 根据来源用户ID与日期查询
     * @Title: listBySourceUidAndDay
     * @Description:
     * @param sourceUid
     * @param day
     * @return
     * List<TeamDividentsSourceUser> 返回类型
     * @throws
     */
    public List<TeamDividentsSourceUser> listBySourceUidAndDay(Long sourceUid, String day);
    /**
     * 计算用户数量
     * @Title: countTargetUid
     * @Description:
     * @param day
     * @return
     * long 返回类型
     * @throws
     */
    public long countTargetUid(String day);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/invite/ThreeSaleSerivce.java
@@ -340,6 +340,18 @@
     * @throws
     */
    public List<ThreeSale> getMyBossDeepList(Long uid,int deep);
    /**
     * 获取上级列表
     * @Title: getMyBossDeepList
     * @Description:
     * @param uid
     * @return
     * List<ThreeSale> 返回类型
     * @throws
     */
    public List<ThreeSale> getMyBossDeepList(Long uid);
    /**
     * 查询未删除版-粉丝一级
fanli/src/main/java/com/yeshi/fanli/service/inter/user/vip/TeamUserLevelStatisticService.java
New file
@@ -0,0 +1,42 @@
package com.yeshi.fanli.service.inter.user.vip;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
/**
 * 团队用户
 * @author Administrator
 *
 */
public interface TeamUserLevelStatisticService {
    /**
     * 根据用户检索
     * @Title: selectByUid
     * @Description:
     * @param uid
     * @return
     * TeamUserLevelStatistic 返回类型
     * @throws
     */
    public TeamUserLevelStatistic selectByUid(Long uid);
    /**
     * 初始化数据
     * @Title: initData
     * @Description:
     * @param uid
     * void 返回类型
     * @throws
     */
    public void initData(Long uid);
    /**
     * 添加
     * @Title: add
     * @Description:
     * @param statistic
     * void 返回类型
     * @throws
     */
    public void add(TeamUserLevelStatistic statistic);
}
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java
New file
@@ -0,0 +1,263 @@
package com.yeshi.fanli.service.manger.order;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsRecordException;
import com.yeshi.fanli.service.inter.money.TeamDividentsDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsRecordService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
/**
 * 团队分红管理
 * @author Administrator
 *
 */
@Component
public class TeamDividentsManager {
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private TeamDividentsSourceUserService teamDividentsSourceUserService;
    @Resource
    private TeamDividentsRecordService teamDividentsRecordService;
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    @Resource
    private TeamUserLevelStatisticService teamUserLevelStatisticService;
    @Resource
    private TeamDividentsDebtService teamDividentsDebtService;
    @Resource
    private UserMoneyService userMoneyService;
    /**
     *  开始分红
     * @Title: startDividents
     * @Description:
     * @param sourceUid -源用户
     * void 返回类型
     * @throws
     */
    @Transactional(rollbackFor = Exception.class)
    public void startDividents(Long sourceUid) throws ParamsException {
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        Date preSendTime = new Date(TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd"));
        // 查询出可用于分红的用户的总金额
        long count = teamDividentsSourceOrderService.countCanSendByUidAndPreSendTime(sourceUid, preSendTime);
        int pageSize = 1000;
        int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
        List<TeamDividentsSourceOrder> totalList = new ArrayList<>();
        for (int p = 0; p < page; p++) {
            List<TeamDividentsSourceOrder> list = teamDividentsSourceOrderService
                    .listCanSendByUidAndPreSendTime(sourceUid, preSendTime, p + 1, pageSize);
            if (list != null && list.size() > 0)
                totalList.addAll(list);
        }
        BigDecimal totalMoney = new BigDecimal(0);
        for (TeamDividentsSourceOrder order : totalList) {
            TeamDividentsSourceOrder sourceOrder = teamDividentsSourceOrderService
                    .selectByPrimaryKeyForUpdate(order.getId());
            if (sourceOrder != null && sourceOrder.getState() == TeamDividentsSourceOrder.STATE_CAN_SEND) {
                totalMoney = totalMoney.add(sourceOrder.getMoney());
                teamDividentsSourceOrderService.send(sourceOrder.getId());
            }
        }
        // 查询出可以参与分红的用户
        List<ThreeSale> threeSalesList = threeSaleSerivce.getMyBossDeepList(sourceUid);
        Map<Long, UserLevelEnum> uidLevel = new HashMap<Long, UserLevelEnum>();
        for (ThreeSale ts : threeSalesList) {
            if (ts.getBoss() != null) {
                TeamUserLevelStatistic tus = teamUserLevelStatisticService.selectByUid(ts.getBoss().getId());
                if (tus != null
                        && (tus.getLevel() == UserLevelEnum.highVIP || tus.getLevel() == UserLevelEnum.superVIP)) {
                    // TODO 需要判断团队的超级会员与高级会员
                    uidLevel.put(tus.getId(), tus.getLevel());
                }
            }
        }
        BigDecimal perDivident = computePerDivident(uidLevel, totalMoney);
        for (Iterator<Long> its = uidLevel.keySet().iterator(); its.hasNext();) {
            Long uid = its.next();
            BigDecimal dividents = computeUserDivident(perDivident, uidLevel.get(uid));
            // 将资金分配到参与分红的用户
            TeamDividentsSourceUser teamDividentsSourceUser = new TeamDividentsSourceUser();
            teamDividentsSourceUser.setDay(day);
            teamDividentsSourceUser.setMoney(dividents);
            teamDividentsSourceUser.setSourceUid(sourceUid);
            teamDividentsSourceUser.setTargetUid(uid);
            teamDividentsSourceUserService.addTeamDividentsSourceUser(teamDividentsSourceUser);
        }
    }
    // 计算平均分红
    private BigDecimal computePerDivident(Map<Long, UserLevelEnum> uidLevels, BigDecimal totalMoney) {
        int count = 0;
        for (Iterator<Long> its = uidLevels.keySet().iterator(); its.hasNext();) {
            Long uid = its.next();
            if (uidLevels.get(uid) == UserLevelEnum.highVIP) {
                count += 1;
            } else if (uidLevels.get(uid) == UserLevelEnum.superVIP) {
                count += 2;
            }
        }
        return MoneyBigDecimalUtil.div(totalMoney, new BigDecimal(count));
    }
    private BigDecimal computeUserDivident(BigDecimal perDivident, UserLevelEnum userLevel) {
        if (userLevel == UserLevelEnum.highVIP) {
            return perDivident;
        } else if (userLevel == UserLevelEnum.superVIP) {
            return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2));
        }
        return null;
    }
    /**
     * 分红计算是否完成
     * @Title: isSourceUserComupteFinish
     * @Description:
     * @return
     * boolean 返回类型
     * @throws
     */
    public boolean isSourceUserComupteFinish(String day) {
        Date preSendTime = new Date(TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd"));
        long count = teamDividentsSourceOrderService.countCanSendByUidAndPreSendTime(null, preSendTime);
        return count == 0;
    }
    /**
     * @throws TeamDividentsDebtException
     * 添加分红记录
     * @Title: addDividentsRecord
     * @Description:
     * @param uid -用户ID
     * @param money -分红金额
     * @param day -分红日期
     * void 返回类型
     * @throws
     */
    @Transactional(rollbackFor = Exception.class)
    public void addDividents(Long uid, String day)
            throws TeamDividentsRecordException, TeamDividentsDebtException, UserMoneyDetailException, ParamsException {
        BigDecimal money = teamDividentsSourceUserService.sumMoneyByUidAndDay(uid, day);
        // 查询需要扣除的资金
        List<TeamDividentsDebt> list = teamDividentsDebtService.listNeedRepayDebt(uid, 1, 1000);
        for (TeamDividentsDebt debt : list) {
            if (money.subtract(debt.getLeftMoney()).compareTo(new BigDecimal(0)) >= 0) {// 还有钱还
                money = money.subtract(debt.getLeftMoney());
                teamDividentsDebtService.repayDebt(debt.getId(), debt.getLeftMoney());
            } else if (money.compareTo(new BigDecimal(0)) > 0) {
                teamDividentsDebtService.repayDebt(debt.getId(), money);
                money = new BigDecimal(0);
            } else// 没有钱还了
                break;
        }
        // 统计资金
        TeamDividentsRecord record = new TeamDividentsRecord();
        record.setDay(day);
        record.setMoney(money);
        record.setState(TeamDividentsRecord.STATE_VALID);
        record.setUid(uid);
        teamDividentsRecordService.addTeamDividentsRecord(record);
        UserMoneyDetail detail = UserMoneyDetailFactory.createOrderTeamDividents(uid, money, new Date());
        // 增加资金
        userMoneyService.addUserMoney(uid, money, detail);
        // TODO 加入通知
    }
    /**
     * @throws TeamDividentsDebtException
     * 订单维权
     * @Title: weiQuan
     * @Description:
     * @param orderNo
     * @param tradeId
     * @param sourceType
     * void 返回类型
     * @throws
     */
    @Transactional(rollbackFor = Exception.class)
    public void weiQuan(String orderNo, int sourceType) throws TeamDividentsDebtException {
        // 查询订单是否已经分红
        TeamDividentsSourceOrder sourceOrder = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo,
                sourceType);
        if (sourceOrder == null)
            return;
        if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_INVALID)
            return;
        if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_ALREADY_SEND) {// 已经发送,需要参与分红的人分摊
            BigDecimal money = sourceOrder.getMoney();
            // 查询参与这一单分红的人
            String day = TimeUtil.getGernalTime(sourceOrder.getSendTime().getTime(), "yyyy-MM-dd");
            List<TeamDividentsSourceUser> list = teamDividentsSourceUserService
                    .listBySourceUidAndDay(sourceOrder.getUid(), day);
            // 计算每个人的比例
            BigDecimal total = new BigDecimal(0);
            for (TeamDividentsSourceUser su : list) {
                total = total.add(su.getMoney());
            }
            for (TeamDividentsSourceUser su : list) {
                BigDecimal debtMoney = MoneyBigDecimalUtil.divUp(money.multiply(su.getMoney()), total);
                // 需要偿还的资金
                TeamDividentsDebt debt = new TeamDividentsDebt();
                debt.setLeftMoney(debtMoney);
                debt.setOriginMoney(debtMoney);
                debt.setOrderNo(orderNo);
                debt.setSourceType(sourceType);
                debt.setUid(su.getTargetUid());
                // 加入待偿还记录
                teamDividentsDebtService.addDebt(debt);
            }
        } else if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_CAN_SEND) {
            teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, "订单维权");
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/util/CMQManager.java
@@ -12,6 +12,7 @@
import com.google.gson.GsonBuilder;
import com.qcloud.cmq.Message;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.order.dividents.UserDividentsDayDTO;
import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
import com.yeshi.fanli.entity.bus.user.Extract;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
@@ -53,6 +54,8 @@
    public static String GOODS_UPDATE = "goods_update_queue";
    // 重要数据更新
    public static String IMPORTANT_GOODS_UPDATE = "imp_goods_update_queue";
    // 团队分红
    public static String TEAM_DIVIDENTS = "team_dividents";
    static {
@@ -64,11 +67,10 @@
            FANLI_ORDER = "test-" + FANLI_ORDER;
            FANLI_ORDER_NEW = "test-" + FANLI_ORDER_NEW;
            FANLI_TICHENG_ORDER = "test-" + FANLI_TICHENG_ORDER;
            FANLI_ORDER_TEAM_REWARD = "test-" + FANLI_ORDER_TEAM_REWARD;
            ORDER_WEIQUAN = "test-" + ORDER_WEIQUAN;
            IMPORTANT_GOODS_UPDATE = "test-" + IMPORTANT_GOODS_UPDATE;
            TEAM_DIVIDENTS = "test-" + TEAM_DIVIDENTS;
        }
        QUEUENAME_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
@@ -79,9 +81,9 @@
        FANLI_ORDER_NEW += "-" + Constant.systemCommonConfig.getProjectName();
        FANLI_TICHENG_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
        FANLI_ORDER_TEAM_REWARD += "-" + Constant.systemCommonConfig.getProjectName();
        ORDER_WEIQUAN += "-" + Constant.systemCommonConfig.getProjectName();
        IMPORTANT_GOODS_UPDATE += "-" + Constant.systemCommonConfig.getProjectName();
        TEAM_DIVIDENTS += "-" + Constant.systemCommonConfig.getProjectName();
        cmqUtil = CMQUtil.getInstance(secretId, secretKey);
        // 最大消息为1M
@@ -96,6 +98,7 @@
        cmqUtil.createQueue(ORDER_WEIQUAN);
        cmqUtil.createQueue(GOODS_UPDATE);
        cmqUtil.createQueue(IMPORTANT_GOODS_UPDATE);
        cmqUtil.createQueue(TEAM_DIVIDENTS);
    }
    public static CMQManager getInstance() {
@@ -295,7 +298,6 @@
        cmqUtil.deleteMsg(FANLI_TICHENG_ORDER, receiptHandle);
    }
    // 维权订单
    public void addWeiQuanOrderMsg(TaoBaoWeiQuanOrder order) {
        cmqUtil.sendMsg(ORDER_WEIQUAN, new Gson().toJson(order));
@@ -445,4 +447,27 @@
        cmqUtil.deleteMsg(IMPORTANT_GOODS_UPDATE, receiptHandle);
    }
    // 团队分红
    public void addTeamDividentsMsg(UserDividentsDayDTO dto) {
        cmqUtil.sendMsg(TEAM_DIVIDENTS, new Gson().toJson(dto));
    }
    public Map<String, UserDividentsDayDTO> consumeTeamDividentsMsg(int count) {
        Gson gson = new Gson();
        List<Message> list = cmqUtil.recieveMsg(count, TEAM_DIVIDENTS);
        Map<String, UserDividentsDayDTO> map = new HashMap<>();
        if (list != null)
            for (Message msg : list) {
                String result = msg.msgBody;
                if (!StringUtil.isNullOrEmpty(result)) {
                    map.put(msg.receiptHandle, gson.fromJson(result, UserDividentsDayDTO.class));
                }
            }
        return map;
    }
    public void deleteTeamDividentsMsg(String receiptHandle) {
        cmqUtil.deleteMsg(TEAM_DIVIDENTS, receiptHandle);
    }
}
fanli/src/main/java/com/yeshi/fanli/util/MoneyBigDecimalUtil.java
@@ -24,6 +24,10 @@
        return d1.divide(d2,2, BigDecimal.ROUND_DOWN);
    }
    public static BigDecimal divUp(BigDecimal d1, BigDecimal d2) {// 进行除法运算
        return d1.divide(d2, 2, BigDecimal.ROUND_UP);
    }
    public static BigDecimal div3(BigDecimal d1, BigDecimal d2) {// 进行除法运算
        return d1.divide(d2, 3, BigDecimal.ROUND_DOWN);
    }
fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -20,6 +20,7 @@
import com.yeshi.fanli.dto.ad.DouYinDeviceActiveQueueDTO;
import com.yeshi.fanli.dto.money.UserMoneyChangeDTO;
import com.yeshi.fanli.dto.order.dividents.UserDividentsDayDTO;
import com.yeshi.fanli.entity.ad.DouYinClickEvent;
import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
@@ -57,6 +58,7 @@
import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.ad.DouYinAdUtil;
import com.yeshi.fanli.util.cmq.DouYinDeviceActiveCMQManager;
import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
@@ -138,6 +140,9 @@
    @Resource
    private DeviceActiveService deviceActiveService;
    @Resource
    private TeamDividentsManager teamDividentsManager;
    private static boolean isInited = false;
    public void onApplicationEvent(ContextRefreshedEvent arg0) {
@@ -174,6 +179,9 @@
            doHongBaoRecieveIntegralGetJob();// 返利到账,金币增加
            // doPlaceOrderIntegralJob();// 下单赠送金币任务
            // doDouYinDeviceActiveJob();// 抖音设备激活广告监测
            doDividentsJob();
        }
    }
@@ -1066,4 +1074,34 @@
        });
    }
    // 分红
    public void doDividentsJob() {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    Map<String, UserDividentsDayDTO> map = CMQManager.getInstance().consumeTeamDividentsMsg(16);
                    if (map != null) {
                        Iterator<String> its = map.keySet().iterator();
                        while (its.hasNext()) {
                            String key = its.next();
                            UserDividentsDayDTO dto = map.get(key);
                            try {
                                teamDividentsManager.addDividents(dto.getUid(), dto.getDay());
                            } catch (Exception e) {
                                try {
                                    LogHelper.errorDetailInfo(e);
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }
                            } finally {
                            }
                        }
                    }
                }
            }
        });
    }
}
fanli/src/main/java/com/yeshi/fanli/util/factory/UserMoneyDetailFactory.java
@@ -601,9 +601,19 @@
        return detail;
    }
    
    public static UserMoneyDetail createOrderTeamReward(Long uid,BigDecimal money, Date time)
    /**
     * 团队分红
     * @Title: createOrderTeamDividents
     * @Description:
     * @param uid
     * @param money
     * @param time
     * @return
     * @throws UserMoneyDetailException
     * UserMoneyDetail 返回类型
     * @throws
     */
    public static UserMoneyDetail createOrderTeamDividents(Long uid, BigDecimal money, Date time)
            throws UserMoneyDetailException {
        if (money == null)
            throw new UserMoneyDetailException(1, "返利金额为空");
@@ -623,12 +633,11 @@
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(
                StringUtil.Md5(UserMoneyDetailTypeEnum.orderTeamReward.name() + "-" + uid + "-" + timeF));
                StringUtil.Md5(UserMoneyDetailTypeEnum.orderTeamDividents.name() + "-" + uid + "-" + timeF));
        detail.setMoney(money);
        detail.setTitle(
                timeF + UserMoneyDetailTypeEnum.orderTeamReward.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.orderTeamReward);
        detail.setDescInfo("团队奖励");
        detail.setTitle(timeF + UserMoneyDetailTypeEnum.orderTeamDividents.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.orderTeamDividents);
        detail.setDescInfo("团队分红");
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java
New file
@@ -0,0 +1,121 @@
package com.yeshi.fanli.util.rocketmq.consumer.order;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserForbiddenMQMsg;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
/**
 * 订单分红消息
 * @author Administrator
 *
 */
@Component
public class OrderDividentsMessageListener implements MessageListener {
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private CommonOrderService commonOrderService;
    @Resource
    private TeamDividentsManager teamDividentsManager;
    public OrderDividentsMessageListener() {
    }
    @Override
    public Action consume(Message message, ConsumeContext context) {
        LogHelper.mqInfo("consumer:OrderDividentsMessageListener", message.getMsgID(), message.getTopic(),
                message.getTag(), new String(message.getBody()));
        String tag = message.getTag();
        if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
            if (tag.equalsIgnoreCase(UserTopicTagEnum.forbiddenUser.name())) {
                // 查询上级红包
                UserForbiddenMQMsg dto = new Gson().fromJson(new String(message.getBody()), UserForbiddenMQMsg.class);
                if (dto != null) {
                    teamDividentsSourceOrderService.invalidOrderByUid(dto.getUid(), "用户被封禁");
                    return Action.CommitMessage;
                }
            }
        } else if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
            // 订单确认收货
            if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderConfirm.name())) {
                // 插入分红
                OrderConfirmMQMsg dto = new Gson().fromJson(new String(message.getBody()), OrderConfirmMQMsg.class);
                List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(dto.getSourceType(),
                        dto.getOrderNo());
                BigDecimal eincome = new BigDecimal(0);
                Date settleTime = null;
                for (CommonOrder order : commonOrderList) {
                    if (order.getState() == CommonOrder.STATE_JS)
                        eincome = eincome.add(order.geteIncome());
                    if (settleTime == null)
                        settleTime = order.getSettleTime();
                }
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(settleTime);
                calendar.add(Calendar.MONTH, 1);
                Date preSendTime = new Date(TimeUtil.convertToTimeTemp(
                        calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
                TeamDividentsSourceOrder sourceOrder = new TeamDividentsSourceOrder();
                sourceOrder.setMoney(eincome);
                sourceOrder.setOrderNo(dto.getOrderNo());
                sourceOrder.setPreSendTime(preSendTime);
                sourceOrder.setSourceType(dto.getSourceType());
                sourceOrder.setState(TeamDividentsSourceOrder.STATE_CAN_SEND);
                sourceOrder.setUid(dto.getSourceUid());
                try {
                    teamDividentsSourceOrderService.addTeamDividentsSourceOrder(sourceOrder);
                    return Action.CommitMessage;
                } catch (ParamsException e) {
                    e.printStackTrace();
                } catch (TeamDividentsSourceOrderException e) {
                    e.printStackTrace();
                }
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.taoBaoOrderWeiQuan.name())) {
                TaoBaoWeiQuanOrder dto = new Gson().fromJson(new String(message.getBody()), TaoBaoWeiQuanOrder.class);
                try {
                    teamDividentsManager.weiQuan(dto.getOrderId(), Constant.SOURCE_TYPE_TAOBAO);
                    return Action.CommitMessage;
                } catch (TeamDividentsDebtException e) {
                    e.printStackTrace();
                }
            }
        }
        return Action.CommitMessage;
    }
}
fanli/src/test/java/org/fanli/MyBatisProduce.java
@@ -2,15 +2,17 @@
import org.junit.Test;
import org.yeshi.utils.mybatis.ColumnParseUtil;
import org.yeshi.utils.mybatis.MyBatisMapperUtil;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
import com.yeshi.fanli.entity.order.OrderTeamReward;
//@Ignore
public class MyBatisProduce {
    @Test
    public void test3() {
        MyBatisMapperUtil.createMapper(TeamUserLevelStatistic.class);
    }
    @Test