<?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.yeejoin.amos.boot.module.hygf.api.mapper.RepaymentMapper">

    <select id="queryPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.RepaymentDto">
        select * from hygf_repayment
        <where>
            <if test="sequenceNbr != null and sequenceNbr != ''">
                and sequence_nbr = #{sequenceNbr}
            </if>
            <if test="companyName != null and companyName != ''">
                and company_name like CONCAT('%',#{companyName},'%' )
            </if>
            <if test="loanPeriod != null and loanPeriod != ''">
                and loan_period like CONCAT('%',#{loanPeriod},'%' )
            </if>
            <if test="repayDate != null and repayDate != ''">
                and repay_date = #{repayDate}
            </if>
            <if test="period != null and period != ''">
                and period like CONCAT('%',#{period},'%' )
            </if>
            <if test="messageState != null and messageState != ''">
                and message_state = #{messageState}
            </if>
            <if test="repayState != null and repayState != ''">
                and repay_state = #{repayState}
            </if>
        </where>
        order by create_time DESC,sequence_nbr DESC
    </select>

    <select id="getPrivilegeCompanyByOrgCode"
            resultType="com.yeejoin.amos.boot.module.hygf.api.entity.PrivilegeCompany">
        SELECT * FROM privilege_company
        WHERE ORG_CODE=#{orgCode} LIMIT 1
    </select>

    <select id="getTodoUserIds" resultType="java.lang.String">
        SELECT USER_ID FROM privilege_user_org_role puor LEFT JOIN std_user_empower sue ON sue.amos_user_id=puor.USER_ID
        WHERE (sue.amos_org_code like #{companyOrgCode} or sue.amos_org_code like '%all%') and puor.ROLE_SEQ=#{roleId}
        and sue.permission_type='HYGF'
        GROUP BY USER_ID;
    </select>

    <select id="getSequenceNbrByName" resultType="java.lang.String">
        SELECT SEQUENCE_NBR from privilege_group where GROUP_NAME=#{groupName} LIMIT 1
    </select>

</mapper>
