| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <?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.fs.his.mapper.AdProfitDetailMapper">
- <resultMap type="AdProfitDetail" id="AdProfitDetailResult">
- <result property="id" column="id" />
- <result property="adTransId" column="ad_trans_id" />
- <result property="adTaskId" column="ad_task_id" />
- <result property="sumMoney" column="sum_money" />
- <result property="userId" column="user_id" />
- <result property="userMoney" column="user_money" />
- <result property="companyId" column="company_id" />
- <result property="companyMoney" column="company_money" />
- <result property="huyiMoney" column="huyi_money" />
- <result property="yunlianMoney" column="yunlian_money" />
- <result property="createTime" column="create_time" />
- </resultMap>
- <sql id="selectAdProfitDetailVo">
- select id, ad_trans_id, ad_task_id, sum_money, user_id, user_money, company_id, company_money, huyi_money, yunlian_money, create_time from ad_profit_detail
- </sql>
- <select id="selectAdProfitDetailById" parameterType="Long" resultMap="AdProfitDetailResult">
- <include refid="selectAdProfitDetailVo"/>
- where id = #{id}
- </select>
- <insert id="insertAdProfitDetail" parameterType="AdProfitDetail" useGeneratedKeys="true" keyProperty="id">
- insert into ad_profit_detail
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="adTransId != null and adTransId != ''">ad_trans_id,</if>
- <if test="adTaskId != null">ad_task_id,</if>
- <if test="sumMoney != null">sum_money,</if>
- <if test="userId != null">user_id,</if>
- <if test="userMoney != null">user_money,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyMoney != null">company_money,</if>
- <if test="huyiMoney != null">huyi_money,</if>
- <if test="yunlianMoney != null">yunlian_money,</if>
- <if test="createTime != null">create_time,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="adTransId != null and adTransId != ''">#{adTransId},</if>
- <if test="adTaskId != null">#{adTaskId},</if>
- <if test="sumMoney != null">#{sumMoney},</if>
- <if test="userId != null">#{userId},</if>
- <if test="userMoney != null">#{userMoney},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyMoney != null">#{companyMoney},</if>
- <if test="huyiMoney != null">#{huyiMoney},</if>
- <if test="yunlianMoney != null">#{yunlianMoney},</if>
- <if test="createTime != null">#{createTime},</if>
- </trim>
- </insert>
- <update id="updateAdProfitDetail" parameterType="AdProfitDetail">
- update ad_profit_detail
- <trim prefix="SET" suffixOverrides=",">
- <if test="adTransId != null and adTransId != ''">ad_trans_id = #{adTransId},</if>
- <if test="adTaskId != null">ad_task_id = #{adTaskId},</if>
- <if test="sumMoney != null">sum_money = #{sumMoney},</if>
- <if test="userId != null">user_id = #{userId},</if>
- <if test="userMoney != null">user_money = #{userMoney},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="companyMoney != null">company_money = #{companyMoney},</if>
- <if test="huyiMoney != null">huyi_money = #{huyiMoney},</if>
- <if test="yunlianMoney != null">yunlian_money = #{yunlianMoney},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- </trim>
- where id = #{id}
- </update>
- <delete id="deleteAdProfitDetailById" parameterType="Long">
- delete from ad_profit_detail where id = #{id}
- </delete>
- <delete id="deleteAdProfitDetailByIds" parameterType="String">
- delete from ad_profit_detail where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="getCompanyByUserId" resultType="java.lang.String">
- SELECT
- company_id
- FROM
- `qw_external_contact`
- WHERE
- fs_user_id = #{userId}
- ORDER BY
- create_time ASC LIMIT 1
- </select>
- <select id="selectAdProfitDetailList" resultType="com.fs.his.dto.AdProfitDetailDto">
- SELECT
- a.*,
- b.company_name,
- c.nick_name
- FROM
- `ad_profit_detail` a
- LEFT JOIN company b ON a.company_id = b.company_id
- LEFT JOIN fs_user c ON a.user_id = c.user_id
- <where>
- <if test="adTransId != null and adTransId != ''"> and a.ad_trans_id = #{adTransId}</if>
- <if test="adTaskId != null and adTaskId != ''"> and a.ad_task_id = #{adTaskId}</if>
- <if test="sumMoney != null "> and a.sum_money = #{sumMoney}</if>
- <if test="userId != null "> and a.user_id = #{userId}</if>
- <if test="userMoney != null "> and a.user_money = #{userMoney}</if>
- <if test="companyId != null "> and a.company_id = #{companyId}</if>
- <if test="companyMoney != null "> and a.company_money = #{companyMoney}</if>
- <if test="huyiMoney != null "> and a.huyi_money = #{huyiMoney}</if>
- <if test="yunlianMoney != null "> and a.yunlian_money = #{yunlianMoney}</if>
- <if test="companyName != null"> and b.company_name = #{companyName}</if>
- <if test="sTime != null"> and Date(a.create_time) >= Date(#{sTime})</if>
- <if test="eTime != null"> and Date(a.create_time) <= Date(#{eTime})</if>
- <if test="nickName != null"> and c.nick_name like concat('%',#{nickName},'%')</if>
- </where>
- order by a.create_time desc
- </select>
- <select id="getWithFinishAndMayWithdraw" resultType="java.util.Map">
- SELECT
- SUM(may_withdraw) AS totalMayWithdraw,
- SUM(withdraw_finish) AS totalWithdrawFinish
- FROM
- fs_user
- WHERE
- may_withdraw > 0.00
- OR withdraw_finish > 0.00
- </select>
- <select id="statisticsList" resultType="com.fs.his.vo.AdProfitDetailStatisticsVo">
- <!-- 1. 用户分润 -->
- SELECT
- '用户分润' AS `name`,
- IFNULL(ROUND(SUM(a.user_money) / 100, 2), 0) AS amountYuan,
- 'summary' AS type,
- 1 AS sortOrder
- FROM ad_profit_detail a
- WHERE <include refid="timeCondition"/>
- UNION ALL
- <!-- 2. 互医分润 -->
- SELECT
- '互医分润' AS `name`,
- IFNULL(ROUND(SUM(a.huyi_money) / 100, 2), 0) AS amountYuan,
- 'summary' AS type,
- 2 AS sortOrder
- FROM ad_profit_detail a
- WHERE <include refid="timeCondition"/>
- UNION ALL
- <!-- 3. 云联分润 -->
- SELECT
- '云联分润' AS `name`,
- IFNULL(ROUND(SUM(a.yunlian_money) / 100, 2), 0) AS amountYuan,
- 'summary' AS type,
- 3 AS sortOrder
- FROM ad_profit_detail a
- WHERE <include refid="timeCondition"/>
- UNION ALL
- <!-- 4. 各公司分润 -->
- SELECT
- c.company_name AS `name`,
- IFNULL(ROUND(SUM(a.company_money) / 100, 2), 0) AS amountYuan,
- 'company' AS type,
- a.company_id + 100 AS sortOrder
- FROM ad_profit_detail a
- LEFT JOIN company c ON a.company_id = c.company_id
- WHERE a.company_id IS NOT NULL
- AND <include refid="timeCondition"/>
- GROUP BY a.company_id, c.company_name
- ORDER BY sortOrder, `name`
- </select>
- <sql id="timeCondition">
- <choose>
- <!-- type为null时,使用startTime和endTime -->
- <when test="param.type == null">
- a.create_time >= #{param.startTime}
- AND a.create_time < DATE_ADD(#{param.endTime}, INTERVAL 1 DAY)
- </when>
- <!-- 1. 今天 -->
- <when test="param.type == 1">
- a.create_time >= CURDATE()
- AND a.create_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
- </when>
- <!-- 2. 昨天 -->
- <when test="param.type == 2">
- a.create_time >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
- AND a.create_time < CURDATE()
- </when>
- <!-- 3. 本周 -->
- <when test="param.type == 3">
- a.create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
- AND a.create_time < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
- </when>
- <!-- 4. 上周 -->
- <when test="param.type == 4">
- a.create_time >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
- AND a.create_time < DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
- </when>
- <!-- 5. 本月 -->
- <when test="param.type == 5">
- a.create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
- AND a.create_time < DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
- </when>
- <!-- 6. 上月 -->
- <when test="param.type == 6">
- a.create_time >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
- AND a.create_time < DATE_FORMAT(CURDATE(), '%Y-%m-01')
- </when>
- <!-- 7. 本季度 -->
- <when test="param.type == 7">
- a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
- AND a.create_time < DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
- </when>
- <!-- 8. 上季度 -->
- <when test="param.type == 8">
- a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
- AND a.create_time < STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
- </when>
- <!-- 9. 本年 -->
- <when test="param.type == 9">
- a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
- AND a.create_time < DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
- </when>
- <!-- 10. 去年 -->
- <when test="param.type == 10">
- a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
- AND a.create_time < STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
- </when>
- </choose>
- </sql>
- </mapper>
|