ApiFinanceMapper.xml 7.97 KB
<?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.lhcredit.project.business.apiFinance.mapper.ApiFinanceMapper">
    
    <resultMap type="ApiFinance" id="ApiFinanceResult">
        <result property="id"    column="id"    />
        <result property="baseName"    column="base_name"    />
        <result property="creditCode"    column="credit_code"    />
        <result property="applicationTime"    column="application_time"    />
        <result property="type"    column="type"    />
        <result property="completionTime"    column="completion_time"    />
        <result property="authCode"    column="auth_code"    />
        <result property="uId"    column="u_id"    />
        <result property="progress"    column="progress"    />
        <result property="orgId"    column="org_id"    />
        <result property="reconciliation"    column="reconciliation"    />
    </resultMap>
	
	<sql id="selectApiFinanceVo">
        select id, base_name, credit_code, application_time, type, completion_time, auth_code, u_id ,  progress , org_id ,reconciliation from api_finance
    </sql>

    <select id="getFinanceCountByUser" parameterType="String" resultType="Long">
        SELECT
            COUNT( id ) AS "financeCount"
        FROM
            api_finance
        WHERE
            u_id = #{uId}
    </select>

    <select id="selectApiFinanceList" parameterType="com.lhcredit.project.business.apiFinance.domain.ApiFinance" resultMap="ApiFinanceResult">
        <include refid="selectApiFinanceVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="baseName != null and baseName != ''">
                and base_name LIKE CONCAT('%', #{baseName}, '%')
            </if>

            <if test="creditCode != null and creditCode != ''">
                and credit_code LIKE CONCAT('%', #{creditCode}, '%')
            </if>
            <if test="applicationTime != null "> and application_time = #{applicationTime}</if>
            <if test="type != null  and type != '' "> and type = #{type}</if>
            <if test="completionTime != null "> and completion_time = #{completionTime}</if>
            <if test="authCode != null  and authCode != '' "> and auth_code = #{authCode}</if>
            <if test="uId != null  and uId != '' "> and u_id = #{uId}</if>
            <if test="progress != null "> and progress = #{progress}</if> <!-- 修正字段名 -->
             <if test="orgId != null "> and org_id = #{orgId}</if>
            <if test="reconciliation != null "> and reconciliation = #{reconciliation}</if>

            <!-- 时间范围查询优化 -->
            <if test="startTime != null">
                <if test="endTime != null">
                    and application_time between #{startTime} and #{endTime}
                </if>
            </if>

        </where>

        <!-- 合并排序条件 -->
        <if test="(completionTimeOrder != null and completionTimeOrder != '')
        or (applicationTimeOrder != null and applicationTimeOrder != '')">
            order by
            <choose>
                <when test="completionTimeOrder != null and completionTimeOrder != ''">
                    completion_time ${completionTimeOrder}
                    <if test="applicationTimeOrder != null and applicationTimeOrder != ''">
                        , application_time ${applicationTimeOrder}
                    </if>
                </when>
                <otherwise>
                    application_time ${applicationTimeOrder}
                </otherwise>
            </choose>
        </if>
        <!-- 默认排序放在动态排序之后 -->
        <if test="(completionTimeOrder == null or completionTimeOrder == '')
        and (applicationTimeOrder == null or applicationTimeOrder == '')">
            order by application_time desc
        </if>
    </select>
    
    <select id="selectApiFinanceById" parameterType="Integer" resultMap="ApiFinanceResult">
        <include refid="selectApiFinanceVo"/>
        where id = #{id}
    </select>
    <select id="getAllByContractId" parameterType="com.lhcredit.project.business.apiFinance.domain.ApiFinance" resultMap="ApiFinanceResult">
        select a.*  from api_finance a join  front_dept f on a.org_id = f.id
        <where>
            <if test="contractId != null  and contractId != ''  ">
                and f.contract_num = #{contractId}
            </if>
            <if test="orgId != null  and orgId != ''  ">
                and a.org_id = #{orgId}
            </if>
            <if test="uId != null  and uId != ''  ">
                and a.u_id = #{uId}
            </if>
            <if test="type != null  and type != ''  ">
                and a.type = #{type}
            </if>
            <if test="startTime != null">
                <if test="endTime != null">
                    and application_time between #{startTime} and #{endTime}
                </if>
            </if>
        </where>
    </select>

    <insert id="insertApiFinance" parameterType="ApiFinance" useGeneratedKeys="true" keyProperty="id">
        insert into api_finance
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="baseName != null  and baseName != ''  ">base_name,</if>
			<if test="creditCode != null  and creditCode != ''  ">credit_code,</if>
			<if test="applicationTime != null  ">application_time,</if>
			<if test="type != null  and type != ''  ">type,</if>
			<if test="completionTime != null  ">completion_time,</if>
			<if test="authCode != null  and authCode != ''  ">auth_code,</if>
			<if test="uId != null  and uId != ''  ">u_id,</if>
            <if test="progress != null  ">progress,</if>
            <if test="orgId != null  ">org_id,</if>
            <if test="reconciliation != null  and reconciliation != ''  ">reconciliation,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="baseName != null  and baseName != ''  ">#{baseName},</if>
			<if test="creditCode != null  and creditCode != ''  ">#{creditCode},</if>
			<if test="applicationTime != null  ">#{applicationTime},</if>
			<if test="type != null  and type != ''  ">#{type},</if>
			<if test="completionTime != null  ">#{completionTime},</if>
			<if test="authCode != null  and authCode != ''  ">#{authCode},</if>
			<if test="uId != null  and uId != ''  ">#{uId},</if>
            <if test="progress != null  ">#{progress},</if>
            <if test="orgId != null  ">#{orgId},</if>
            <if test="reconciliation != null  and reconciliation != ''  ">#{reconciliation},</if>
         </trim>
    </insert>
	 
    <update id="updateApiFinance" parameterType="ApiFinance">
        update api_finance
        <trim prefix="SET" suffixOverrides=",">
            <if test="baseName != null  and baseName != ''  ">base_name = #{baseName},</if>
            <if test="creditCode != null  and creditCode != ''  ">credit_code = #{creditCode},</if>
            <if test="applicationTime != null  ">application_time = #{applicationTime},</if>
            <if test="type != null  and type != ''  ">type = #{type},</if>
            <if test="completionTime != null  ">completion_time = #{completionTime},</if>
            <if test="authCode != null  and authCode != ''  ">auth_code = #{authCode},</if>
            <if test="uId != null  and uId != ''  ">u_id = #{uId},</if>
            <if test="progress != null   ">progress = #{progress},</if>
            <if test="orgId != null  ">org_id = #{orgId},</if>
            <if test="reconciliation != null  and reconciliation != ''  ">reconciliation = #{reconciliation},</if>
        </trim>
        where id = #{id}
    </update>

	<delete id="deleteApiFinanceById" parameterType="Integer">
        delete from api_finance where id = #{id}
    </delete>
	
    <delete id="deleteApiFinanceByIds" parameterType="String">
        delete from api_finance where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>