<?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.UserMoneyDetailMapper">
|
<resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.money.UserMoneyDetail">
|
<id column="umd_id" property="id" jdbcType="BIGINT" />
|
<result column="umd_money" property="money" jdbcType="DECIMAL" />
|
<result column="umd_type" property="type"
|
typeHandler="com.yeshi.fanli.util.mybatishandler.UserMoneyDetailTypeEnumHandler" />
|
<result column="umd_title" property="title" jdbcType="VARCHAR" />
|
<result column="umd_sub_title" property="subTitle" jdbcType="VARCHAR" />
|
<result column="umd_desc_info" property="descInfo" jdbcType="VARCHAR" />
|
<result column="umd_source_identify_id" property="sourceIdentifyId"
|
jdbcType="BIGINT" />
|
<result column="umd_identify_code" property="identifyCode"
|
jdbcType="VARCHAR" />
|
<result column="umd_beizhu" property="beiZhu" jdbcType="VARCHAR" />
|
<result column="umd_createtime" property="createTime" jdbcType="TIMESTAMP" />
|
<result column="umd_updatetime" property="updateTime" jdbcType="TIMESTAMP" />
|
<!-- 老版明细适用该字段 -->
|
<result column="state" property="state" jdbcType="INTEGER" />
|
<association property="userInfo" column="umd_uid"
|
javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
|
<id column="umd_uid" property="id" jdbcType="BIGINT" />
|
</association>
|
</resultMap>
|
|
|
<resultMap id="UserMonthMoneyMap" type="com.yeshi.fanli.vo.money.UserMonthMoneyVO">
|
<result column="expend" property="expend" jdbcType="DECIMAL" />
|
<result column="income" property="income" jdbcType="DECIMAL" />
|
<result column="dateFormate" property="dateFormate" jdbcType="VARCHAR" />
|
</resultMap>
|
|
<sql id="Base_Column_List">umd_id,umd_uid,umd_money,umd_type,umd_title,umd_sub_title,umd_desc_info,umd_source_identify_id,umd_identify_code,umd_beizhu,umd_createtime,umd_updatetime
|
</sql>
|
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
|
parameterType="java.lang.Long">
|
select
|
<include refid="Base_Column_List" />
|
from yeshi_ec_user_money_detail where umd_id = #{id,jdbcType=BIGINT}
|
</select>
|
|
|
<select id="selectByUidWithIndexId" resultMap="BaseResultMap">
|
SELECT
|
<include refid="Base_Column_List" />
|
FROM yeshi_ec_user_money_detail d WHERE d.`umd_createtime`
|
<![CDATA[
|
<=
|
]]>
|
(SELECT
|
d.`umd_createtime` FROM yeshi_ec_user_money_detail d WHERE
|
d.`umd_id`=#{id}) and d.umd_uid=#{uid} order by d.`umd_createtime`
|
desc,d.umd_id desc limit #{count}
|
</select>
|
|
<select id="selectCountByUid" resultType="java.lang.Long"
|
parameterType="java.lang.Long">
|
SELECT count(umd_id) FROM yeshi_ec_user_money_detail
|
where umd_uid=#{uid}
|
</select>
|
|
|
|
<select id="selectByMaxCreateTime" resultMap="BaseResultMap">
|
SELECT
|
<include refid="Base_Column_List" />
|
FROM yeshi_ec_user_money_detail d WHERE d.umd_uid=#{uid} and
|
d.`umd_createtime`
|
<![CDATA[
|
<=
|
]]>
|
#{date}
|
order by d.`umd_createtime` desc,d.umd_id desc limit #{count}
|
</select>
|
|
<select id="selectCountByUidAndMaxCreateTime" resultType="java.lang.Long">
|
SELECT count(umd_id) FROM yeshi_ec_user_money_detail
|
where
|
umd_uid=#{uid} and `umd_createtime`
|
<![CDATA[
|
<=
|
]]>
|
#{date}
|
</select>
|
|
|
<select id="selectMonthCountByUid" resultType="java.lang.Integer">
|
SELECT COUNT(*) FROM (SELECT * FROM yeshi_ec_user_money_detail d WHERE
|
d.`umd_uid`=#{uid} and d.`umd_createtime` <![CDATA[<=]]>
|
#{date} group by DATE_FORMAT(d.`umd_createtime`,'%y-%m')) a
|
</select>
|
|
<select id="selectMonthMoneyByUid" resultMap="UserMonthMoneyMap">
|
<foreach collection="dateFormat" index="index" item="item"
|
separator="UNION ALL">
|
<trim prefix="(" suffix=")">
|
SELECT
|
a.time as dateFormate , if(a.money is null,0,a.money) as
|
income ,if(b.money is null,0,b.money) as expend
|
FROM
|
(
|
SELECT
|
DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m') AS
|
`time`,SUM(d.`umd_money`)
|
AS money
|
FROM
|
`yeshi_ec_user_money_detail`
|
d
|
WHERE d.`umd_uid`=#{uid}
|
AND
|
d.`umd_money`>=0 AND DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m')=#{item} GROUP BY DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m')
|
) a
|
LEFT JOIN
|
(
|
SELECT DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m') AS
|
`time`,SUM(d.`umd_money`) AS money
|
FROM
|
`yeshi_ec_user_money_detail`
|
d WHERE d.`umd_uid`=#{uid} AND
|
d.`umd_money` <![CDATA[<0]]>
|
AND DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m')=#{item} GROUP BY
|
DATE_FORMAT(
|
d.`umd_createtime`,'%Y-%m')
|
) b ON a.time=b.time
|
</trim>
|
</foreach>
|
</select>
|
|
|
<select id="selectByUidWithState" resultMap="BaseResultMap">
|
SELECT a.* FROM
|
((SELECT d.*,-1 AS state FROM
|
`yeshi_ec_user_money_detail` d
|
WHERE
|
d.`umd_uid`=#{uid} AND (d.`umd_type`!='extract' AND
|
d.`umd_type`!='extractReject')
|
)
|
UNION ALL(
|
SELECT d.*,-1 AS
|
state
|
FROM
|
`yeshi_ec_user_money_detail` d LEFT JOIN
|
`yeshi_ec_extract` e
|
ON
|
e.`id`=d.umd_source_identify_id WHERE d.`umd_uid`=#{uid} AND
|
d.umd_type='extractReject'
|
)
|
UNION ALL(
|
SELECT
|
d.*,e.state FROM
|
`yeshi_ec_user_money_detail` d LEFT JOIN
|
`yeshi_ec_extract` e ON
|
e.`id`=d.`umd_source_identify_id` WHERE d.`umd_uid`=#{uid} AND
|
d.umd_type='extract'
|
)) a ORDER BY a.umd_createtime DESC LIMIT
|
#{start},#{count}
|
|
</select>
|
|
|
<select id="selectCountByUidWithState" resultType="java.lang.Long">
|
SELECT
|
count(*) FROM
|
((SELECT d.*,-1 AS state FROM
|
`yeshi_ec_user_money_detail` d
|
WHERE
|
d.`umd_uid`=#{uid} AND
|
(d.`umd_type`!='extract' AND d.`umd_type`!='extractReject')
|
)
|
UNION ALL(
|
SELECT d.*,-1 AS
|
state
|
FROM `yeshi_ec_user_money_detail` d LEFT JOIN
|
`yeshi_ec_extract` e
|
ON
|
e.`id`=d.umd_source_identify_id WHERE
|
d.`umd_uid`=#{uid} AND
|
d.umd_type='extractReject'
|
)
|
UNION ALL(
|
SELECT
|
d.*,e.state FROM `yeshi_ec_user_money_detail` d LEFT JOIN
|
`yeshi_ec_extract` e ON e.`id`=d.`umd_source_identify_id` WHERE
|
d.`umd_uid`=#{uid} AND
|
d.umd_type='extract'
|
)) a
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
|
yeshi_ec_user_money_detail where umd_id = #{id,jdbcType=BIGINT}
|
</delete>
|
<insert id="insert" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail"
|
useGeneratedKeys="true" keyProperty="id">insert into
|
yeshi_ec_user_money_detail
|
(umd_id,umd_uid,umd_money,umd_type,umd_title,umd_sub_title,umd_desc_info,umd_source_identify_id,umd_identify_code,umd_beizhu,umd_createtime,umd_updatetime)
|
values
|
(#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{type,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{subTitle,jdbcType=VARCHAR},#{descInfo,jdbcType=VARCHAR},#{sourceIdentifyId,jdbcType=BIGINT},#{identifyCode,jdbcType=VARCHAR},#{beiZhu,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
|
</insert>
|
<insert id="insertSelective" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail"
|
useGeneratedKeys="true" keyProperty="id">
|
insert into yeshi_ec_user_money_detail
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">umd_id,</if>
|
<if test="userInfo != null">umd_uid,</if>
|
<if test="money != null">umd_money,</if>
|
<if test="type != null">umd_type,</if>
|
<if test="title != null">umd_title,</if>
|
<if test="subTitle != null">umd_sub_title,</if>
|
<if test="descInfo != null">umd_desc_info,</if>
|
<if test="sourceIdentifyId != null">umd_source_identify_id,</if>
|
<if test="identifyCode != null">umd_identify_code,</if>
|
<if test="beiZhu != null">umd_beizhu,</if>
|
<if test="createTime != null">umd_createtime,</if>
|
<if test="updateTime != null">umd_updatetime,</if>
|
</trim>
|
values
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">#{id,jdbcType=BIGINT},</if>
|
<if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
|
<if test="money != null">#{money,jdbcType=DECIMAL},</if>
|
<if test="type != null">#{type,jdbcType=VARCHAR},</if>
|
<if test="title != null">#{title,jdbcType=VARCHAR},</if>
|
<if test="subTitle != null">#{subTitle,jdbcType=VARCHAR},</if>
|
<if test="descInfo != null">#{descInfo,jdbcType=VARCHAR},</if>
|
<if test="sourceIdentifyId != null">#{sourceIdentifyId,jdbcType=BIGINT},</if>
|
<if test="identifyCode != null">#{identifyCode,jdbcType=VARCHAR},</if>
|
<if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</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.money.UserMoneyDetail">update
|
yeshi_ec_user_money_detail set umd_uid =
|
#{userInfo.id,jdbcType=BIGINT},umd_money =
|
#{money,jdbcType=DECIMAL},umd_type =
|
#{type,jdbcType=VARCHAR},umd_title =
|
#{title,jdbcType=VARCHAR},umd_sub_title =
|
#{subTitle,jdbcType=VARCHAR},umd_desc_info =
|
#{descInfo,jdbcType=VARCHAR},umd_source_identify_id =
|
#{sourceIdentifyId,jdbcType=BIGINT},umd_identify_code =
|
#{identifyCode,jdbcType=VARCHAR},umd_beizhu =
|
#{beiZhu,jdbcType=VARCHAR},umd_createtime =
|
#{createTime,jdbcType=TIMESTAMP},umd_updatetime =
|
#{updateTime,jdbcType=TIMESTAMP} where umd_id = #{id,jdbcType=BIGINT}
|
</update>
|
<update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail">
|
update yeshi_ec_user_money_detail
|
<set>
|
<if test="userInfo != null">umd_uid=#{userInfo.id,jdbcType=BIGINT},</if>
|
<if test="money != null">umd_money=#{money,jdbcType=DECIMAL},</if>
|
<if test="type != null">umd_type=#{type,jdbcType=VARCHAR},</if>
|
<if test="title != null">umd_title=#{title,jdbcType=VARCHAR},</if>
|
<if test="subTitle != null">umd_sub_title=#{subTitle,jdbcType=VARCHAR},</if>
|
<if test="descInfo != null">umd_desc_info=#{descInfo,jdbcType=VARCHAR},</if>
|
<if test="sourceIdentifyId != null">umd_source_identify_id=#{sourceIdentifyId,jdbcType=BIGINT},
|
</if>
|
<if test="identifyCode != null">umd_identify_code=#{identifyCode,jdbcType=VARCHAR},</if>
|
<if test="beiZhu != null">umd_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
|
<if test="createTime != null">umd_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
|
<if test="updateTime != null">umd_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
|
</set>
|
where umd_id = #{id,jdbcType=BIGINT}
|
</update>
|
</mapper>
|