<?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.AgPoInformedMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AgPoInformed">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="leads_id" jdbcType="BIGINT" property="leadsId" />
    <result column="informed_no" jdbcType="VARCHAR" property="informedNo" />
    <result column="informed_oss_path" jdbcType="VARCHAR" property="informedOssPath" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="customer_mobile" jdbcType="VARCHAR" property="customerMobile" />
    <result column="practitioner_id" jdbcType="BIGINT" property="practitionerId" />
    <result column="practitioner_name" jdbcType="VARCHAR" property="practitionerName" />
    <result column="policy_no" jdbcType="VARCHAR" property="policyNo" />
    <result column="sign_date" jdbcType="VARCHAR" property="signDate" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <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, leads_id, informed_no, informed_oss_path, customer_id, customer_name, customer_mobile, 
    practitioner_id, policy_no, sign_date, `status`, is_active, remark, created_at, created_by, 
    updated_at, updated_by
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ag_po_informed
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_po_informed
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AgPoInformed" useGeneratedKeys="true">
    insert into ag_po_informed (leads_id, informed_no, informed_oss_path, 
      customer_id, customer_name, customer_mobile, 
      practitioner_id, policy_no, sign_date, 
      `status`, is_active, remark, 
      created_at, created_by, updated_at, 
      updated_by)
    values (#{leadsId,jdbcType=BIGINT}, #{informedNo,jdbcType=VARCHAR}, #{informedOssPath,jdbcType=VARCHAR}, 
      #{customerId,jdbcType=BIGINT}, #{customerName,jdbcType=VARCHAR}, #{customerMobile,jdbcType=VARCHAR},
      #{practitionerId,jdbcType=BIGINT}, #{policyNo,jdbcType=VARCHAR}, #{signDate,jdbcType=VARCHAR}, 
      #{status,jdbcType=VARCHAR}, #{isActive,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, 
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{updatedAt,jdbcType=TIMESTAMP}, 
      #{updatedBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AgPoInformed" useGeneratedKeys="true">
    insert into ag_po_informed
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="leadsId != null">
        leads_id,
      </if>
      <if test="informedNo != null">
        informed_no,
      </if>
      <if test="informedOssPath != null">
        informed_oss_path,
      </if>
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="customerName != null">
        customer_name,
      </if>
      <if test="customerMobile != null">
        customer_mobile,
      </if>
      <if test="practitionerId != null">
        practitioner_id,
      </if>
      <if test="policyNo != null">
        policy_no,
      </if>
      <if test="signDate != null">
        sign_date,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="leadsId != null">
        #{leadsId,jdbcType=BIGINT},
      </if>
      <if test="informedNo != null">
        #{informedNo,jdbcType=VARCHAR},
      </if>
      <if test="informedOssPath != null">
        #{informedOssPath,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        #{customerId,jdbcType=BIGINT},
      </if>
      <if test="customerName != null">
        #{customerName,jdbcType=BIGINT},
      </if>
      <if test="customerMobile != null">
        #{customerMobile,jdbcType=BIGINT},
      </if>
      <if test="practitionerId != null">
        #{practitionerId,jdbcType=BIGINT},
      </if>
      <if test="policyNo != null">
        #{policyNo,jdbcType=VARCHAR},
      </if>
      <if test="signDate != null">
        #{signDate,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AgPoInformed">
    update ag_po_informed
    <set>
      <if test="leadsId != null">
        leads_id = #{leadsId,jdbcType=BIGINT},
      </if>
      <if test="informedNo != null">
        informed_no = #{informedNo,jdbcType=VARCHAR},
      </if>
      <if test="informedOssPath != null">
        informed_oss_path = #{informedOssPath,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=BIGINT},
      </if>
      <if test="customerName != null">
        customer_name = #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="customerMobile != null">
        customer_mobile = #{customerMobile,jdbcType=VARCHAR},
      </if>
      <if test="practitionerId != null">
        practitioner_id = #{practitionerId,jdbcType=BIGINT},
      </if>
      <if test="policyNo != null">
        policy_no = #{policyNo,jdbcType=VARCHAR},
      </if>
      <if test="signDate != null">
        sign_date = #{signDate,jdbcType=VARCHAR},
      </if>
      <if test="signOssPath != null">
        sign_oss_path = #{signOssPath,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AgPoInformed">
    update ag_po_informed
    set leads_id = #{leadsId,jdbcType=BIGINT},
      informed_no = #{informedNo,jdbcType=VARCHAR},
      informed_oss_path = #{informedOssPath,jdbcType=VARCHAR},
      customer_id = #{customerId,jdbcType=BIGINT},
      customer_name = #{customerName,jdbcType=VARCHAR},
      customer_mobile = #{customerMobile,jdbcType=VARCHAR},
      practitioner_id = #{practitionerId,jdbcType=BIGINT},
      policy_no = #{policyNo,jdbcType=VARCHAR},
      sign_date = #{signDate,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=VARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      remark = #{remark,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectByRecord" parameterType="com.yd.dal.entity.customer.AgPoInformed" resultMap="BaseResultMap">
    select
    p.name practitioner_name,
    t.*
    from ag_po_informed t left join ag_acl_practitioner p on t.practitioner_id = p.id
    where 1=1
    <if test="customerName != null">
      and t.customer_name = #{customerName,jdbcType=VARCHAR}
    </if>
    <if test="customerMobile != null">
      and t.customer_mobile = #{customerMobile,jdbcType=VARCHAR}
    </if>
    <if test="practitionerId != null">
      and t.practitioner_id = #{practitionerId,jdbcType=BIGINT}
    </if>
    <if test="policyNo != null">
      and t.policy_no = #{policyNo,jdbcType=VARCHAR}
    </if>
    <if test="signDate != null">
      and t.sign_date = #{signDate,jdbcType=VARCHAR}
    </if>
    <if test="id != null">
      and t.id = #{id,jdbcType=BIGINT}
    </if>
    order by t.created_at desc
  </select>
  <select id="getNextInformedNo" resultType="java.lang.String" statementType="CALLABLE">
      select f_getNextInformedNo()
  </select>
</mapper>