<?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.yd.dal.mapper.meta.MdCodeMapper">
    <resultMap id="BaseResultMap" type="com.yd.dal.entity.meta.MdCode">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="code_type" jdbcType="VARCHAR" property="codeType" />
        <result column="display_no" jdbcType="INTEGER" property="displayNo" />
        <result column="code_code" jdbcType="VARCHAR" property="codeCode" />
        <result column="code_name" jdbcType="VARCHAR" property="codeName" />
        <result column="code_name_en" jdbcType="VARCHAR" property="codeNameEn" />
        <result column="is_active" jdbcType="INTEGER" property="isActive" />
        <result column="flag" jdbcType="VARCHAR" property="flag" />
        <result column="remark" jdbcType="VARCHAR" property="remark" />
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
        <result column="created_by" jdbcType="BIGINT" property="createdBy" />
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
        <result column="updated_by" jdbcType="BIGINT" property="updatedBy" />
    </resultMap>
    <sql id="Base_Column_List">
    id, code_type, display_no, code_code, code_name, code_name_en, is_active, flag, remark,
    created_at, created_by, updated_at, updated_by
  </sql>

    <select id="findByCodeType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ag_md_code
        where t.is_active = 1 and t.code_type = #{codeType}
    </select>
    <select id="findCodeByType" resultType="java.lang.String">
        SELECT
            t.code_code as codeCode
        FROM ag_md_code t
        where t.is_active = 1 and t.code_type = #{codeType}
    </select>

    <select id="findByMdCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ag_md_code
        <where>
            <if test="codeType != null">
                and code_type = #{codeType,jdbcType=VARCHAR}
            </if>
            <if test="displayNo != null">
                and display_no = #{displayNo,jdbcType=INTEGER}
            </if>
            <if test="codeCode != null">
                and code_code = #{codeCode,jdbcType=VARCHAR}
            </if>
            <if test="codeName != null">
                and code_name = #{codeName,jdbcType=VARCHAR}
            </if>
            <if test="codeNameEn != null">
                and code_name_en = #{codeNameEn,jdbcType=VARCHAR}
            </if>
            <if test="isActive != null">
                and is_active = #{isActive,jdbcType=INTEGER}
            </if>
            <if test="flag != null">
                and flag = #{flag,jdbcType=VARCHAR}
            </if>
            <if test="remark != null">
                and remark = #{remark,jdbcType=VARCHAR}
            </if>
            <if test="createdAt != null">
                and created_at = #{createdAt,jdbcType=TIMESTAMP}
            </if>
            <if test="createdBy != null">
                and created_by = #{createdBy,jdbcType=BIGINT}
            </if>
            <if test="updatedAt != null">
                and updated_at = #{updatedAt,jdbcType=TIMESTAMP}
            </if>
            <if test="updatedBy != null">
                and updated_by = #{updatedBy,jdbcType=BIGINT}
            </if>
        </where>
    </select>

</mapper>