<?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.MdGoalsCalculateExpressionMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.meta.MdGoalsCalculateExpression">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="current_year" jdbcType="INTEGER" property="currentYear" />
    <result column="drop_master_id" jdbcType="BIGINT" property="dropMasterId" />
    <result column="drop_master_name" jdbcType="VARCHAR" property="dropMasterName" />
    <result column="action_id" jdbcType="BIGINT" property="actionId" />
    <result column="drop_option_name" jdbcType="VARCHAR" property="dropOptionName" />
    <result column="calculate_script_expression" jdbcType="LONGVARCHAR" property="calculateScriptExpression" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <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, current_year, drop_master_id, drop_master_name, action_id, drop_option_name, 
    calculate_script_expression, is_active, 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_md_goals_calculate_expression
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_md_goals_calculate_expression
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.meta.MdGoalsCalculateExpression" useGeneratedKeys="true">
    insert into ag_md_goals_calculate_expression (current_year, drop_master_id, drop_master_name, 
      action_id, drop_option_name, calculate_script_expression, 
      is_active, created_at, created_by, 
      updated_at, updated_by)
    values (#{currentYear,jdbcType=INTEGER}, #{dropMasterId,jdbcType=BIGINT}, #{dropMasterName,jdbcType=VARCHAR},
      #{actionId,jdbcType=BIGINT}, #{dropOptionName,jdbcType=VARCHAR}, #{calculateScriptExpression,jdbcType=LONGVARCHAR},
      #{isActive,jdbcType=INTEGER}, #{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.meta.MdGoalsCalculateExpression" useGeneratedKeys="true">
    insert into ag_md_goals_calculate_expression
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="currentYear != null">
        current_year,
      </if>
      <if test="dropMasterId != null">
        drop_master_id,
      </if>
      <if test="dropMasterName != null">
        drop_master_name,
      </if>
      <if test="actionId != null">
        action_id,
      </if>
      <if test="dropOptionName != null">
        drop_option_name,
      </if>
      <if test="calculateScriptExpression != null">
        calculate_script_expression,
      </if>
      <if test="isActive != null">
        is_active,
      </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="currentYear != null">
        #{currentYear,jdbcType=INTEGER},
      </if>
      <if test="dropMasterId != null">
        #{dropMasterId,jdbcType=BIGINT},
      </if>
      <if test="dropMasterName != null">
        #{dropMasterName,jdbcType=VARCHAR},
      </if>
      <if test="actionId != null">
        #{actionId,jdbcType=BIGINT},
      </if>
      <if test="dropOptionName != null">
        #{dropOptionName,jdbcType=VARCHAR},
      </if>
      <if test="calculateScriptExpression != null">
        #{calculateScriptExpression,jdbcType=LONGVARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </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.meta.MdGoalsCalculateExpression">
    update ag_md_goals_calculate_expression
    <set>
      <if test="currentYear != null">
        current_year = #{currentYear,jdbcType=INTEGER},
      </if>
      <if test="dropMasterId != null">
        drop_master_id = #{dropMasterId,jdbcType=BIGINT},
      </if>
      <if test="dropMasterName != null">
        drop_master_name = #{dropMasterName,jdbcType=VARCHAR},
      </if>
      <if test="actionId != null">
        action_id = #{actionId,jdbcType=BIGINT},
      </if>
      <if test="dropOptionName != null">
        drop_option_name = #{dropOptionName,jdbcType=VARCHAR},
      </if>
      <if test="calculateScriptExpression != null">
        calculate_script_expression = #{calculateScriptExpression,jdbcType=LONGVARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </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.meta.MdGoalsCalculateExpression">
    update ag_md_goals_calculate_expression
    set current_year = #{currentYear,jdbcType=INTEGER},
      drop_master_id = #{dropMasterId,jdbcType=BIGINT},
      drop_master_name = #{dropMasterName,jdbcType=VARCHAR},
      action_id = #{actionId,jdbcType=BIGINT},
      drop_option_name = #{dropOptionName,jdbcType=VARCHAR},
      calculate_script_expression = #{calculateScriptExpression,jdbcType=LONGVARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      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="findByMasterId" resultMap="BaseResultMap">
      select
          e.*
      from
          ag_md_goals_calculate_expression e
          left join ag_md_drop_options o on o.id = e.action_id
      where
              o.drop_master_id = #{masterId,jdbcType=BIGINT}
        and e.is_active = 1
      order by o.drop_option_order;
    </select>
  <select id="findByMasterCodeAndIsActive" resultType="com.yd.dal.entity.meta.MdGoalsCalculateExpression">
    select
      e.id id,
      e.current_year currentYear,
      e.drop_master_id dropMasterId,
      e.drop_master_name dropMasterName,
      e.action_id actionId,
      e.drop_option_name dropOptionName,
      e.calculate_script_expression calculateScriptExpression,
      e.is_active isActive,
      e.created_at createdAt,
      e.created_by createdBy,
      e.updated_at updatedAt,
      e.updated_by updatedBy
    from ag_md_drop_master m left join ag_md_goals_calculate_expression e on m.id = e.drop_master_id and e.is_active = #{isActive,jdbcType=INTEGER}
    where m.scenario_code = #{masterCode,jdbcType=VARCHAR}

  </select>
</mapper>