<?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="cn.superdesk.uniorder.dao.mapper.fund.SysFundGrantMapperEx">

	<!-- 自定义部分 -->
	<resultMap id="SysFundGrantMap" type="cn.superdesk.uniorder.dto.vo.fund.SysFundGrantVoEx">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="fund_user_id" jdbcType="BIGINT" property="fundUserId"/>
		<result column="organization_name" jdbcType="VARCHAR" property="organizationName"/>
		<result column="enterprise_name" jdbcType="VARCHAR" property="enterpriseName"/>
		<result column="realname" jdbcType="VARCHAR" property="realname"/>
		<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
		<result column="invoice_number" jdbcType="VARCHAR" property="invoiceNumber"/>
		<result column="invoice_count" jdbcType="DECIMAL" property="invoiceCount"/>
		<result column="no_check_count" jdbcType="DECIMAL" property="noCheckCount"/>
		<result column="fund_count" jdbcType="DECIMAL" property="fundCount"/>
		<result column="no_activated_fund" jdbcType="DECIMAL" property="noActivatedFund"/>
		<result column="activated_status" jdbcType="INTEGER" property="activatedStatus"/>
		<result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
		<result column="create_user_name" jdbcType="VARCHAR" property="createUserName"/>
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
	</resultMap>
	<select id="selectByCondition" resultMap="SysFundGrantMap">
		<!-- 条件搜索 -->
		SELECT
			fu.*, org.organization_name,
			en.enterprise_name,
			oru.realname,
			oru.mobile,
			user1.user_name AS create_user_name
		FROM
			sys_fund_grant fu
			LEFT JOIN sys_fund_user funu ON fu.fund_user_id = funu.id
			LEFT JOIN sys_oder_user oru ON funu.user_id = oru.user_id
			LEFT JOIN sys_enterprise en ON oru.enterprise_id = en.enterprise_id
			LEFT JOIN sys_organization org ON oru.organization_id = org.organization_id
			LEFT JOIN sys_user user1 ON fu.create_user_id = user1.id
		where 1=1
		<if test="organizationName != null and organizationName != ''">
			and org.organization_name like CONCAT(CONCAT('%',#{organizationName,jdbcType=VARCHAR}),'%')
		</if>
		<if test="enterpriseName != null and enterpriseName != ''">
			and en.enterprise_name like CONCAT(CONCAT('%',#{enterpriseName,jdbcType=VARCHAR}),'%')
		</if>
		<if test="mobile != null and mobile != ''">
			and oru.mobile like CONCAT(CONCAT('%',#{mobile,jdbcType=VARCHAR}),'%')
		</if>
		<if test="realname != null and realname != ''">
			and oru.realname like CONCAT(CONCAT('%',#{realname,jdbcType=VARCHAR}),'%')
		</if>
		<if test="invoiceNumber != null and invoiceNumber != ''">
			and fu.invoice_number like CONCAT(CONCAT('%',#{invoiceNumber,jdbcType=VARCHAR}),'%')
		</if>
		<if test="activatedStatus != null">
			and fu.activated_status = #{activatedStatus,jdbcType=INTEGER}
		</if>
		order by fu.create_time DESC
	</select>

</mapper>