admin
2020-04-23 6414d11724795daec088f622e517d5df59a53e83
团队分红来源订单与用户映射相关服务实现
2个文件已修改
2个文件已添加
418 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderUserMapMapper.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrderUserMap.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderUserMapMapper.xml 221 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderUserMapServiceImpl.java 110 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderUserMapMapper.java
New file
@@ -0,0 +1,70 @@
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.TeamDividentsSourceOrderUserMap;
public interface TeamDividentsSourceOrderUserMapMapper extends BaseMapper<TeamDividentsSourceOrderUserMap> {
    TeamDividentsSourceOrderUserMap selectByPrimaryKeyForUpdate(Long id);
    /**
     * 查询列表
     *
     * @param sourceOrderId
     * @param sourceUid
     * @param targetUid
     * @param preSendTime
     * @param stateList
     * @param typeList
     * @param start
     * @param count
     * @return
     */
    List<TeamDividentsSourceOrderUserMap> list(@Param("sourceOrderId") Long sourceOrderId,
            @Param("sourceUid") Long sourceUid, @Param("targetUid") Long targetUid,
            @Param("preSendTime") Date preSendTime, @Param("stateList") List<Integer> stateList,
            @Param("typeList") List<Integer> typeList, @Param("start") long start, @Param("count") int count);
    /**
     * 查询数量
     *
     * @param sourceOrderId
     * @param sourceUid
     * @param targetUid
     * @param preSendTime
     * @param stateList
     * @param typeList
     * @return
     */
    long count(@Param("sourceOrderId") Long sourceOrderId, @Param("sourceUid") Long sourceUid,
            @Param("targetUid") Long targetUid, @Param("preSendTime") Date preSendTime,
            @Param("stateList") List<Integer> stateList, @Param("typeList") List<Integer> typeList);
    /**
     * 查询可结算的列表
     * @param preSendTime
     * @param start
     * @param count
     * @return
     */
    List<Long> listCanSendSourceUidByPreSendTime(@Param("preSendTime") Date preSendTime, @Param("start") long start,
            @Param("count") int count);
    /**
     * 查询可结算的数量
     * @param preSendTime
     * @param start
     * @param count
     * @return
     */
    long countCanSendSourceUidByPreSendTime(@Param("preSendTime") Date preSendTime);
}
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrderUserMap.java
@@ -3,11 +3,16 @@
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 * 分红源订单对应用户ID
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_team_dividents_source_order_user")
public class TeamDividentsSourceOrderUserMap {
    public final static int TYPE_MORE_THAN_2 = 1;// 二级外分红
    public final static int TYPE_TEAM_DIVIDENTS = 2;// 团队分红
@@ -17,17 +22,29 @@
    public final static int STATE_JS = 2;
    public final static int STATE_YILINGQU = 3;
    @Column(name = "sou_id")
    private Long id;
    @Column(name = "sou_source_order_id")
    private TeamDividentsSourceOrder sourceOrder;
    @Column(name = "sou_source_uid")
    private Long sourceUid;
    @Column(name = "sou_target_uid")
    private Long targetUid;
    @Column(name = "sou_state")
    private Integer state;
    @Column(name = "sou_type")
    private Integer type;
    @Column(name = "sou_rate")
    private BigDecimal rate;
    @Column(name = "sou_money")
    private BigDecimal money;
    @Column(name = "sou_pre_send_time")
    private Date preSendTime;
    @Column(name = "sou_create_time")
    private Date createTime;
    @Column(name = "sou_update_time")
    private Date updateTime;
    @Column(name = "sou_beizhu")
    private String beiZhu;
    public Long getId() {
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderUserMapMapper.xml
New file
@@ -0,0 +1,221 @@
<?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.TeamDividentsSourceOrderUserMapMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">
        <id column="sou_id" property="id" jdbcType="BIGINT" />
        <result column="sou_source_uid" property="sourceUid" jdbcType="BIGINT" />
        <result column="sou_target_uid" property="targetUid" jdbcType="BIGINT" />
        <result column="sou_state" property="state" jdbcType="INTEGER" />
        <result column="sou_type" property="type" jdbcType="INTEGER" />
        <result column="sou_rate" property="rate" jdbcType="DECIMAL" />
        <result column="sou_money" property="money" jdbcType="DECIMAL" />
        <result column="sou_pre_send_time" property="preSendTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <association property="sourceOrder" column="sou_source_order_id"
            javaType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">
            <id column="sou_source_order_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where sou_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_dividents_source_order_user where sou_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_source_order_user
        (sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu)
        values
        (#{id,jdbcType=BIGINT},#{sourceOrder.id,jdbcType=BIGINT},#{sourceUid,jdbcType=BIGINT},#{targetUid,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{type,jdbcType=INTEGER},#{rate,jdbcType=DECIMAL},#{money,jdbcType=DECIMAL},#{preSendTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{beiZhu,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_dividents_source_order_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">sou_id,</if>
            <if test="sourceOrder != null">sou_source_order_id,</if>
            <if test="sourceUid != null">sou_source_uid,</if>
            <if test="targetUid != null">sou_target_uid,</if>
            <if test="state != null">sou_state,</if>
            <if test="type != null">sou_type,</if>
            <if test="rate != null">sou_rate,</if>
            <if test="money != null">sou_money,</if>
            <if test="preSendTime != null">sou_pre_send_time,</if>
            <if test="createTime != null">sou_create_time,</if>
            <if test="updateTime != null">sou_update_time,</if>
            <if test="beiZhu != null">sou_beizhu,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="sourceOrder != null">#{sourceOrder.id,jdbcType=BIGINT},</if>
            <if test="sourceUid != null">#{sourceUid,jdbcType=BIGINT},</if>
            <if test="targetUid != null">#{targetUid,jdbcType=BIGINT},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="rate != null">#{rate,jdbcType=DECIMAL},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">update yeshi_ec_team_dividents_source_order_user set
        sou_source_order_id = #{sourceOrder.id,jdbcType=BIGINT},sou_source_uid
        =
        #{sourceUid,jdbcType=BIGINT},sou_target_uid =
        #{targetUid,jdbcType=BIGINT},sou_state =
        #{state,jdbcType=INTEGER},sou_type = #{type,jdbcType=INTEGER},sou_rate
        = #{rate,jdbcType=DECIMAL},sou_money =
        #{money,jdbcType=DECIMAL},sou_pre_send_time =
        #{preSendTime,jdbcType=TIMESTAMP},sou_create_time =
        #{createTime,jdbcType=TIMESTAMP},sou_update_time =
        #{updateTime,jdbcType=TIMESTAMP},sou_beizhu =
        #{beiZhu,jdbcType=VARCHAR} where sou_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">
        update yeshi_ec_team_dividents_source_order_user
        <set>
            <if test="sourceOrder != null">sou_source_order_id=#{sourceOrder.id,jdbcType=BIGINT},
            </if>
            <if test="sourceUid != null">sou_source_uid=#{sourceUid,jdbcType=BIGINT},</if>
            <if test="targetUid != null">sou_target_uid=#{targetUid,jdbcType=BIGINT},</if>
            <if test="state != null">sou_state=#{state,jdbcType=INTEGER},</if>
            <if test="type != null">sou_type=#{type,jdbcType=INTEGER},</if>
            <if test="rate != null">sou_rate=#{rate,jdbcType=DECIMAL},</if>
            <if test="money != null">sou_money=#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">sou_pre_send_time=#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">sou_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">sou_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">sou_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
        </set>
        where sou_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_user where sou_id =
        #{0} for
        update
    </select>
    <select id="list" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where
        1=1
        <if test="sourceOrderId!=null">
            and sou_source_order_id=#{sourceOrderId}
        </if>
        <if test="sourceUid!=null">
            and sou_source_uid=#{sourceUid}
        </if>
        <if test="targetUid!=null">
            and sou_target_uid=#{targetUid}
        </if>
        <if test="preSendTime!=null">
            and sou_pre_send_time=#{preSendTime}
        </if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state"></foreach>
            sou_state=#{state}
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type"></foreach>
            sou_type=#{type}
        </if>
        limit #{start},#{count}
    </select>
    <select id="count" resultType="java.lang.Long">
        select
        count(*)
        from yeshi_ec_team_dividents_source_order_user where
        1=1
        <if test="sourceOrderId!=null">
            and sou_source_order_id=#{sourceOrderId}
        </if>
        <if test="sourceUid!=null">
            and sou_source_uid=#{sourceUid}
        </if>
        <if test="targetUid!=null">
            and sou_target_uid=#{targetUid}
        </if>
        <if test="preSendTime!=null">
            and sou_pre_send_time=#{preSendTime}
        </if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state"></foreach>
            sou_state=#{state}
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type"></foreach>
            sou_type=#{type}
        </if>
    </select>
    <select id="listCanSendSourceUidByPreSendTime" resultType="java.lang.Long">
        SELECT DISTINCT(o.`sou_source_uid`) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime} limit #{start},#{count}
    </select>
    <select id="countCanSendSourceUidByPreSendTime" resultType="java.lang.Long">
        SELECT count(DISTINCT(o.`sou_source_uid`)) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime} limit #{start},#{count}
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderUserMapServiceImpl.java
@@ -1,89 +1,155 @@
package com.yeshi.fanli.service.impl.order.dividents;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderUserMapMapper;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderUserMapService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
@Service
public class TeamDividentsSourceOrderUserMapServiceImpl implements TeamDividentsSourceOrderUserMapService {
    @Resource
    private TeamDividentsSourceOrderUserMapMapper teamDividentsSourceOrderUserMapMapper;
    @Override
    public TeamDividentsSourceOrderUserMap selectByPrimaryKeyForUpdate(Long id) {
        // TODO Auto-generated method stub
        return null;
        return teamDividentsSourceOrderUserMapMapper.selectByPrimaryKeyForUpdate(id);
    }
    @Transactional
    @Override
    public void send(Long id) {
        // TODO Auto-generated method stub
        TeamDividentsSourceOrderUserMap map = teamDividentsSourceOrderUserMapMapper.selectByPrimaryKeyForUpdate(id);
        if (map == null)
            return;
        if (map.getState() == TeamDividentsSourceOrderUserMap.STATE_JS) {
            TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
            update.setId(id);
            update.setState(TeamDividentsSourceOrderUserMap.STATE_YILINGQU);
            update.setUpdateTime(new Date());
            teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
        }
    }
    @Override
    public void addDividentsSourceOrderUserMap(TeamDividentsSourceOrderUserMap map) throws ParamsException {
        // TODO Auto-generated method stub
        if (map == null || map.getMoney() == null || map.getRate() == null || map.getSourceOrder() == null
                || map.getSourceUid() == null || map.getTargetUid() == null || map.getType() == null) {
            throw new ParamsException(1, "参数不完整");
        }
        List<Integer> typeList = new ArrayList<Integer>();
        typeList.add(map.getType());
        long count = teamDividentsSourceOrderUserMapMapper.count(map.getSourceOrder().getId(), null, map.getTargetUid(),
                null, null, typeList);
        if (count > 0)
            return;
        if (map.getCreateTime() == null)
            map.setCreateTime(new Date());
        teamDividentsSourceOrderUserMapMapper.insertSelective(map);
    }
    @Override
    public List<TeamDividentsSourceOrderUserMap> listCanSend(Long sourceUid, Date maxPreSendTime, int page,
            int pageSize) {
        // TODO Auto-generated method stub
        return null;
        List<Integer> stateList = new ArrayList<Integer>();
        stateList.add(TeamDividentsSourceOrderUserMap.STATE_JS);
        return teamDividentsSourceOrderUserMapMapper.list(null, sourceUid, null, maxPreSendTime, stateList, null,
                (page - 1) * pageSize, pageSize);
    }
    @Override
    public long countCanSend(Long sourceUid, Date maxPreSendTime) {
        // TODO Auto-generated method stub
        return 0;
        List<Integer> stateList = new ArrayList<Integer>();
        stateList.add(TeamDividentsSourceOrderUserMap.STATE_JS);
        return teamDividentsSourceOrderUserMapMapper.count(null, sourceUid, null, maxPreSendTime, stateList, null);
    }
    @Override
    public long countBySourceOrderId(Long sourceOrderId) {
        // TODO Auto-generated method stub
        return 0;
        return teamDividentsSourceOrderUserMapMapper.count(sourceOrderId, null, null, null, null, null);
    }
    @Override
    public List<TeamDividentsSourceOrderUserMap> listBySourceOrderId(Long sourceOrderId) {
        // TODO Auto-generated method stub
        return null;
        return teamDividentsSourceOrderUserMapMapper.list(sourceOrderId, null, null, null, null, null, 0, 10000);
    }
    @Override
    public List<Long> listCanSendSourceUidByPreSendTime(Date preSendTime, int page, int count) {
        // TODO Auto-generated method stub
        return null;
        return teamDividentsSourceOrderUserMapMapper.listCanSendSourceUidByPreSendTime(preSendTime, (page - 1) * count,
                count);
    }
    @Override
    public Long countCanSendSourceUidByPreSendTime(Date preSendTime) {
        // TODO Auto-generated method stub
        return null;
        return teamDividentsSourceOrderUserMapMapper.countCanSendSourceUidByPreSendTime(preSendTime);
    }
    @Transactional
    @Override
    public void invalidBySourceOrderId(Long sourceOrderId) {
        // TODO Auto-generated method stub
        List<TeamDividentsSourceOrderUserMap> mapList = listBySourceOrderId(sourceOrderId);
        if (mapList != null)
            for (TeamDividentsSourceOrderUserMap map : mapList) {
                if (map.getState() == TeamDividentsSourceOrderUserMap.STATE_FK
                        || map.getState() == TeamDividentsSourceOrderUserMap.STATE_JS) {
                    TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
                    update.setId(map.getId());
                    update.setUpdateTime(new Date());
                    update.setState(TeamDividentsSourceOrderUserMap.STATE_SX);
                    teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
                }
            }
    }
    @Transactional
    @Override
    public void orderSettle(Long sourceOrderId, Date preSendTime, BigDecimal income) {
        // TODO Auto-generated method stub
        List<TeamDividentsSourceOrderUserMap> mapList = listBySourceOrderId(sourceOrderId);
        if (mapList != null)
            for (TeamDividentsSourceOrderUserMap map : mapList) {
                if (map.getState() == TeamDividentsSourceOrderUserMap.STATE_FK) {
                    TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
                    update.setId(map.getId());
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 4));
                    update.setUpdateTime(new Date());
                    update.setState(TeamDividentsSourceOrderUserMap.STATE_JS);
                    teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
                }
            }
    }
    @Transactional
    @Override
    public void updateMoney(Long sourceOrderId, BigDecimal income) {
        // TODO Auto-generated method stub
        List<TeamDividentsSourceOrderUserMap> mapList = listBySourceOrderId(sourceOrderId);
        if (mapList != null)
            for (TeamDividentsSourceOrderUserMap map : mapList) {
                if (map.getState() == TeamDividentsSourceOrderUserMap.STATE_FK) {
                    TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
                    update.setId(map.getId());
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 4));
                    update.setUpdateTime(new Date());
                    teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
                }
            }
    }
}