<?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.customer.AclFileUploadMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclFileUpload">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="target_type" jdbcType="INTEGER" property="targetType" />
    <result column="target_id" jdbcType="BIGINT" property="targetId" />
    <result column="target_no" jdbcType="VARCHAR" property="targetNo" />
    <result column="target_use_for" jdbcType="INTEGER" property="targetUseFor" />
    <result column="target_seq" jdbcType="INTEGER" property="targetSeq" />
    <result column="file_type" jdbcType="VARCHAR" property="fileType" />
    <result column="file_name" jdbcType="VARCHAR" property="fileName" />
    <result column="file_path" jdbcType="VARCHAR" property="filePath" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="file_size" jdbcType="VARCHAR" property="fileSize" />
    <result column="oss_key" jdbcType="VARCHAR" property="ossKey" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="uploaded_at" jdbcType="TIMESTAMP" property="uploadedAt" />
    <result column="uploaded_by" jdbcType="BIGINT" property="uploadedBy" />
  </resultMap>
  <sql id="Base_Column_List">
    id, target_type, target_id, target_no, target_use_for, target_seq, file_type, file_name, 
    file_path, remark, file_size, oss_key, is_active, order_id, uploaded_at, uploaded_by
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ag_acl_file_upload
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_acl_file_upload
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclFileUpload" useGeneratedKeys="true">
    insert into ag_acl_file_upload (target_type, target_id, target_no, 
      target_use_for, target_seq, file_type, 
      file_name, file_path, remark, 
      file_size, oss_key, is_active, 
      order_id, uploaded_at, uploaded_by
      )
    values (#{targetType,jdbcType=INTEGER}, #{targetId,jdbcType=BIGINT}, #{targetNo,jdbcType=VARCHAR}, 
      #{targetUseFor,jdbcType=INTEGER}, #{targetSeq,jdbcType=INTEGER}, #{fileType,jdbcType=VARCHAR}, 
      #{fileName,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, 
      #{fileSize,jdbcType=VARCHAR}, #{ossKey,jdbcType=VARCHAR}, #{isActive,jdbcType=INTEGER}, 
      #{orderId,jdbcType=BIGINT}, #{uploadedAt,jdbcType=TIMESTAMP}, #{uploadedBy,jdbcType=BIGINT}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclFileUpload" useGeneratedKeys="true">
    insert into ag_acl_file_upload
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="targetType != null">
        target_type,
      </if>
      <if test="targetId != null">
        target_id,
      </if>
      <if test="targetNo != null">
        target_no,
      </if>
      <if test="targetUseFor != null">
        target_use_for,
      </if>
      <if test="targetSeq != null">
        target_seq,
      </if>
      <if test="fileType != null">
        file_type,
      </if>
      <if test="fileName != null">
        file_name,
      </if>
      <if test="filePath != null">
        file_path,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="fileSize != null">
        file_size,
      </if>
      <if test="ossKey != null">
        oss_key,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="uploadedAt != null">
        uploaded_at,
      </if>
      <if test="uploadedBy != null">
        uploaded_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="targetType != null">
        #{targetType,jdbcType=INTEGER},
      </if>
      <if test="targetId != null">
        #{targetId,jdbcType=BIGINT},
      </if>
      <if test="targetNo != null">
        #{targetNo,jdbcType=VARCHAR},
      </if>
      <if test="targetUseFor != null">
        #{targetUseFor,jdbcType=INTEGER},
      </if>
      <if test="targetSeq != null">
        #{targetSeq,jdbcType=INTEGER},
      </if>
      <if test="fileType != null">
        #{fileType,jdbcType=VARCHAR},
      </if>
      <if test="fileName != null">
        #{fileName,jdbcType=VARCHAR},
      </if>
      <if test="filePath != null">
        #{filePath,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="fileSize != null">
        #{fileSize,jdbcType=VARCHAR},
      </if>
      <if test="ossKey != null">
        #{ossKey,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="uploadedAt != null">
        #{uploadedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="uploadedBy != null">
        #{uploadedBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AclFileUpload">
    update ag_acl_file_upload
    <set>
      <if test="targetType != null">
        target_type = #{targetType,jdbcType=INTEGER},
      </if>
      <if test="targetId != null">
        target_id = #{targetId,jdbcType=BIGINT},
      </if>
      <if test="targetNo != null">
        target_no = #{targetNo,jdbcType=VARCHAR},
      </if>
      <if test="targetUseFor != null">
        target_use_for = #{targetUseFor,jdbcType=INTEGER},
      </if>
      <if test="targetSeq != null">
        target_seq = #{targetSeq,jdbcType=INTEGER},
      </if>
      <if test="fileType != null">
        file_type = #{fileType,jdbcType=VARCHAR},
      </if>
      <if test="fileName != null">
        file_name = #{fileName,jdbcType=VARCHAR},
      </if>
      <if test="filePath != null">
        file_path = #{filePath,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="fileSize != null">
        file_size = #{fileSize,jdbcType=VARCHAR},
      </if>
      <if test="ossKey != null">
        oss_key = #{ossKey,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="uploadedAt != null">
        uploaded_at = #{uploadedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="uploadedBy != null">
        uploaded_by = #{uploadedBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AclFileUpload">
    update ag_acl_file_upload
    set target_type = #{targetType,jdbcType=INTEGER},
      target_id = #{targetId,jdbcType=BIGINT},
      target_no = #{targetNo,jdbcType=VARCHAR},
      target_use_for = #{targetUseFor,jdbcType=INTEGER},
      target_seq = #{targetSeq,jdbcType=INTEGER},
      file_type = #{fileType,jdbcType=VARCHAR},
      file_name = #{fileName,jdbcType=VARCHAR},
      file_path = #{filePath,jdbcType=VARCHAR},
      remark = #{remark,jdbcType=VARCHAR},
      file_size = #{fileSize,jdbcType=VARCHAR},
      oss_key = #{ossKey,jdbcType=VARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      order_id = #{orderId,jdbcType=BIGINT},
      uploaded_at = #{uploadedAt,jdbcType=TIMESTAMP},
      uploaded_by = #{uploadedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <resultMap id="file_upload_map" type="com.yd.dal.entity.customer.CustomerFileUpload">
    <result column="id" property="id"/>
    <result column="fileName" property="fileName"/>
    <result column="filePath" property="filePath"/>
    <result column="remark" property="remark"/>
  </resultMap>
  <select id="findByTargetTypeAndTargetUseForAndTargetId" resultMap="file_upload_map">
        SELECT
            u.id as id,
            u.file_name as fileName,
            u.file_path as filePath,
            u.remark as remark
        FROM ag_acl_file_upload u
        where u.is_active = 1
            and u.target_type = #{targetType}
            and u.target_use_for = #{targetUseFor}
            and u.target_id = #{practitionerId}
    </select>
  <select id="findByAclFileUpload" parameterType="com.yd.dal.entity.customer.AclFileUpload" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_file_upload
    <where>
      <if test="id != null">
        id = #{id,jdbcType=INTEGER}
      </if>
      <if test="targetType != null">
        and target_type = #{targetType,jdbcType=INTEGER}
      </if>
      <if test="targetId != null">
        and target_id = #{targetId,jdbcType=BIGINT}
      </if>
      <if test="targetNo != null">
        and target_no = #{targetNo,jdbcType=VARCHAR}
      </if>
      <if test="targetUseFor != null">
        and target_use_for = #{targetUseFor,jdbcType=INTEGER}
      </if>
      <if test="targetSeq != null">
        and target_seq = #{targetSeq,jdbcType=INTEGER}
      </if>
      <if test="fileType != null">
        and file_type = #{fileType,jdbcType=VARCHAR}
      </if>
      <if test="fileName != null">
        and file_name = #{fileName,jdbcType=VARCHAR}
      </if>
      <if test="filePath != null">
        and file_path = #{filePath,jdbcType=VARCHAR}
      </if>
      <if test="remark != null">
        and remark = #{remark,jdbcType=VARCHAR}
      </if>
      <if test="fileSize != null">
        and file_size = #{fileSize,jdbcType=VARCHAR}
      </if>
      <if test="ossKey != null">
        and oss_key = #{ossKey,jdbcType=VARCHAR}
      </if>
      <if test="isActive != null">
        and is_active = #{isActive,jdbcType=INTEGER}
      </if>
      <if test="orderId != null">
        and order_id = #{orderId,jdbcType=BIGINT}
      </if>
      <if test="uploadedAt != null">
        and uploaded_at = #{uploadedAt,jdbcType=TIMESTAMP}
      </if>
      <if test="uploadedBy != null">
        and uploaded_by = #{uploadedBy,jdbcType=BIGINT}
      </if>
    </where>
  </select>

  <select id="findByTargetIdAndRemark" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_file_upload
    where target_type = #{type,jdbcType=INTEGER} and target_id = #{targetId,jdbcType=BIGINT} and remark = #{remark,jdbcType=VARCHAR} and is_active = 1
  </select>
</mapper>