<?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="org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper">

    <!-- 查询 财务结算-账户列表-->
    <select id="getSettlementList" resultType="org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo">
        SELECT * from (
        SELECT
            id,
            advertiser_id,
            ( SELECT ad.NAME FROM ctop_advertiser ad WHERE ad.id = cwjs.advertiser_id LIMIT 1 ) advertiserName,
            product_id,
            ( SELECT cp.product_name FROM ctop_product cp WHERE cp.id = cwjs.product_id LIMIT 1 ) productName,
            project_id,
            ( SELECT project.project_name FROM ctop_project project WHERE project.id = cwjs.project_id LIMIT 1 ) projectName,
            media_id,
            operate_type,
            account_id,
            account_name,
            kuai_shou_id,
            STATUS,
            del_flag,
            create_user_id,
            ( SELECT su.realname FROM sys_user su WHERE su.id = cwjs.create_user_id LIMIT 1 ) createUserName,
            create_time,
            update_time
        FROM
            ctop_cwjs_settlement_info cwjs
        WHERE
            cwjs.del_flag = 0) t
        <where>
            <if test="advertiserName !=null and advertiserName != ''">
                AND advertiserName like concat ('%',#{advertiserName},'%')
            </if>
            <if test="productName !=null and productName != ''">
                AND productName like concat ('%',#{productName},'%')
            </if>
            <if test="projectName !=null and projectName != ''">
                AND projectName like concat ('%',#{projectName},'%')
            </if>
            <if test="accountName !=null and accountName != ''">
                AND account_name like concat ('%',#{accountName},'%')
            </if>
            <if test="createUserName !=null and createUserName != ''">
                AND createUserName like concat ('%',#{createUserName},'%')
            </if>
            <if test="mediaId !=null and mediaId != ''">
                AND media_id = #{mediaId}
            </if>
            <if test="startTime !=null and startTime != ''">
                AND DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= #{startTime}
            </if>
            <if test="endTime !=null and endTime != ''">
                AND DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= #{endTime}
            </if>
            <if test="userIds !=null and userIds.size() > 0">
                AND create_user_id in
              <foreach collection="userIds" item="item" separator=","
                       open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <!-- 修改财务结算账户状态 -->
    <update id="updSettlementStatusById">
        UPDATE ctop_cwjs_settlement_info
            SET STATUS = #{status}
        WHERE
            id = #{id}
    </update>


    <!-- 根据账户id 查看财务账户 -->
    <select id="getSettlementByAccountId" resultType="org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo">
        select * from ctop_cwjs_settlement_info
        WHERE del_flag = 0
          and account_id = #{accountId}
    </select>


    <!-- 删除财务结算账户 -->
    <update id="deleteSettlementById">
        UPDATE ctop_cwjs_settlement_info
            SET del_flag = 1
        WHERE
            id = #{id}
    </update>



    <!-- 查询多个用户信息 -->
    <select id="getUserByIds" resultType="java.util.LinkedHashMap">
        SELECT
            id,realname
        from sys_user
        where status = 1
          and del_flag = 0

              <if test="userIds !=null and userIds != ''">
                  AND id in
                  <foreach collection="userIds" item="item" separator=","
                           open="(" close=")">
                      #{item}
                  </foreach>
              </if>


    </select>



</mapper>
