<?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.jpsoft.shinestar.modules.base.dao.CompanyPaymentInfoDAO">

    <resultMap id="CompanyPaymentInfoMap" type="com.jpsoft.shinestar.modules.base.entity.CompanyPaymentInfo">
        <id property="id" column="id_" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="delFlag" column="del_flag" />
        <result property="companyId" column="company_id" />
        <result property="parkingWechatNotifyUrl" column="parking_wechat_notify_url" />
        <result property="parkingAlipayNotifyUrl" column="parking_alipay_notify_url" />
        <result property="appId" column="app_id" />
        <result property="mchId" column="mch_id" />
        <result property="subAppId" column="sub_app_id" />
        <result property="subAppSecret" column="sub_app_secret" />
        <result property="subMchId" column="sub_mch_id" />
        <result property="appAuthToken" column="app_auth_token" />
        <result property="name" column="name_" />
        <result property="cycle" column="cycle_" />
        <result property="isOpenWechat" column="is_open_wechat" />
        <result property="isOpenAlipay" column="is_open_alipay" />
        <result property="bankName" column="bank_name" />
        <result property="bank" column="bank_" />
        <result property="account" column="account_" />
        <result property="isDefault" column="is_default" />
        <result property="financePersonId" column="finance_person_id" />
        <result property="financeUserId" column="finance_user_id" />

    </resultMap>

    <select id="findByCompanyId" resultMap="CompanyPaymentInfoMap">
        <![CDATA[select * from base_company_payment_info where company_id = #{companyId} and del_flag = 0 and is_default = true limit 1
        ]]>


    </select>
    <select id="findListByCompanyId" resultMap="CompanyPaymentInfoMap">
        select * from base_company_payment_info where company_id = #{companyId} and del_flag = 0
    </select>
    <select id="get" resultMap="CompanyPaymentInfoMap">
        <![CDATA[
        select * from base_company_payment_info where id_ = #{id} and del_flag = 0
        ]]>
    </select>
    <select id="list" resultMap="CompanyPaymentInfoMap">
          select * from base_company_payment_info where del_flag = 0
    </select>

    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CompanyPaymentInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_company_payment_info
	    (app_auth_token,sub_mch_id,sub_app_secret,sub_app_id,mch_id,app_id,parking_alipay_notify_url,parking_wechat_notify_url,
	    company_id,del_flag,update_time,update_by,create_time,create_by,name_,cycle_,is_open_wechat,is_open_alipay,bank_name,bank_,account_,is_default,finance_person_id,finance_user_id)
		values
		(
			#{appAuthToken,jdbcType= VARCHAR },
			#{subMchId,jdbcType= VARCHAR },
			#{subAppSecret,jdbcType= VARCHAR },
			#{subAppId,jdbcType= VARCHAR },
			#{mchId,jdbcType= VARCHAR },
			#{appId,jdbcType= VARCHAR },
			#{parkingAlipayNotifyUrl,jdbcType= VARCHAR },
			#{parkingWechatNotifyUrl,jdbcType= VARCHAR },
			#{companyId,jdbcType= VARCHAR },
			#{delFlag,jdbcType= NUMERIC },
			#{updateTime,jdbcType= TIMESTAMP },
			#{updateBy,jdbcType=VARCHAR},
			#{createTime,jdbcType= TIMESTAMP },
			#{createBy,jdbcType=VARCHAR},
			#{name,jdbcType=VARCHAR},
			#{cycle,jdbcType=VARCHAR},
			#{isOpenWechat,jdbcType= NUMERIC },
			#{isOpenAlipay,jdbcType= NUMERIC },
			#{bankName,jdbcType= VARCHAR },
			#{bank,jdbcType= VARCHAR },
			#{account,jdbcType= VARCHAR },
			#{isDefault,jdbcType= NUMERIC },
			#{financePersonId,jdbcType= NUMERIC },
			#{financeUserId,jdbcType= VARCHAR }
		)
	]]>
    </insert>


    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CompanyPaymentInfo">
        update base_company_payment_info
        <set>
            <if test="appAuthToken!=null">
                app_auth_token=#{appAuthToken,jdbcType= VARCHAR },
            </if>
            <if test="subMchId!=null">
                sub_mch_id=#{subMchId,jdbcType= VARCHAR },
            </if>
            <if test="subAppSecret!=null">
              sub_app_secret=#{subAppSecret,jdbcType= VARCHAR },
            </if>
            <if test="subAppId!=null">
                sub_app_id=#{subAppId,jdbcType= VARCHAR },
            </if>
            <if test="mchId!=null">
                mch_id=#{mchId,jdbcType= VARCHAR },
            </if>
            <if test="appId!=null">
                app_id=#{appId,jdbcType= VARCHAR },
            </if>
            <if test="parkingAlipayNotifyUrl!=null">
                parking_alipay_notify_url=#{parkingAlipayNotifyUrl,jdbcType= VARCHAR },
            </if>
            <if test="parkingWechatNotifyUrl!=null">
                parking_wechat_notify_url=#{parkingWechatNotifyUrl,jdbcType= VARCHAR },
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType= VARCHAR },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="name!=null">
                name_=#{name,jdbcType= VARCHAR },
            </if>
            <if test="cycle!=null">
                cycle_=#{cycle,jdbcType= VARCHAR },
            </if>
            <if test="isOpenWechat!=null">
                is_open_wechat=#{isOpenWechat,jdbcType= NUMERIC },
            </if>
            <if test="isOpenAlipay!=null">
                is_open_alipay=#{isOpenAlipay,jdbcType= NUMERIC },
            </if>

            <if test="bankName!=null">
                bank_name=#{bankName,jdbcType= VARCHAR },
            </if>
            <if test="bank!=null">
                bank_=#{bank,jdbcType= VARCHAR },
            </if>
            <if test="account!=null">
                account_=#{account,jdbcType= VARCHAR },
            </if>
            <if test="isDefault!=null">
                is_default=#{isDefault,jdbcType= NUMERIC },
            </if>
            <if test="financePersonId!=null">
                finance_person_id=#{financePersonId,jdbcType= NUMERIC },
            </if>
            <if test="financeUserId!=null">
                finance_user_id=#{financeUserId,jdbcType= VARCHAR },
            </if>
        </set>
        where id_=#{id}
    </update>

    <select id="search" parameterType="hashmap" resultMap="CompanyPaymentInfoMap">
        <![CDATA[
            select * from base_company_payment_info
		]]>
        <where>
            del_flag = 0
            <if test="searchParams.companyId != null">
                and company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.name != null">
                and name_ like #{searchParams.name}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByFinancePersonId" resultMap="CompanyPaymentInfoMap">
        <![CDATA[
        select * from base_company_payment_info where
        del_flag = 0
        and finance_person_id = #{personId}
        ]]>

    </select>
</mapper>
