<?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.xhpc.activity.mapper.XhpcWorkTypeDictMapper">
  <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcWorkTypeDictDomain">
    <id column="work_type_id" jdbcType="INTEGER" property="workTypeId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="sort" jdbcType="SMALLINT" property="sort" />
    <result column="parent_type_id" jdbcType="INTEGER" property="parentTypeId" />
    <result column="status" jdbcType="SMALLINT" property="status" />
    <result column="del_flag" jdbcType="SMALLINT" property="delFlag" />
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
  </resultMap>
  <sql id="Base_Column_List">
    work_type_id, name, sort, parent_type_id, `status`, del_flag, tenant_id,
    create_time, create_by, update_time, update_by
  </sql>

  <select id="selectListByParams" resultType="com.xhpc.activity.domain.XhpcWorkTypeDictDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_type_dict
    where del_flag = 0 and status = 1
    <if test="params.tenantId !=null and params.tenantId!=''">
      and tenant_id=#{params.tenantId}
    </if>
  </select>

  <select id="selectMapListByParams" resultType="map">
    select
     work_type_id as 'id',
    name as 'name'
    from xhpc_work_type_dict
    where del_flag = 0 and status = 1
    <if test="params.tenantId !=null and params.tenantId!=''">
      and tenant_id=#{params.tenantId}
    </if>
  </select>
  <select id="selectMapListByParentParams" resultType="map">
    select
    work_type_id as 'id',
    name as 'name',
    sort as 'sort',
    parent_type_id as 'parentId'
    from xhpc_work_type_dict
    where del_flag = 0 and status = 1
    <if test="params.tenantId !=null and params.tenantId!=''">
      and tenant_id=#{params.tenantId}
    </if>
    <choose>
      <when test="params.parentTypeId!=null and params.parentTypeId!='' ">
        and parent_type_id=#{params.parentTypeId}
      </when>
        <otherwise>
          and (parent_type_id is null or parent_type_id='')
        </otherwise>
    </choose>
    order by sort desc, work_type_id asc
  </select>


  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from xhpc_work_type_dict
    where work_type_id = #{workTypeId,jdbcType=INTEGER}
  </select>


  <select id="selectByName" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_type_dict
    where del_flag=0 and name = #{name}
    <choose>
      <when test="parentId == null">
        and parent_type_id is null
      </when>
      <otherwise>
         and parent_type_id=#{parentId}
      </otherwise>
    </choose>
  </select>

  <update id="deleteByPrimaryKeyLogic" parameterType="java.lang.Integer">
    update xhpc_work_type_dict set del_flag=2
    where work_type_id = #{workTypeId,jdbcType=INTEGER}
  </update>
  <insert id="insert" keyColumn="work_type_id" keyProperty="workTypeId" parameterType="com.xhpc.activity.domain.XhpcWorkTypeDictDomain" useGeneratedKeys="true">
    insert into xhpc_work_type_dict (name, sort,
      parent_type_id, `status`, del_flag,
      tenant_id, create_time, create_by, 
      update_time, update_by)
    values (#{name,jdbcType=VARCHAR}, #{sort,jdbcType=SMALLINT},
      #{parentTypeId,jdbcType=INTEGER}, #{status,jdbcType=SMALLINT}, 0,
      #{tenantId,jdbcType=VARCHAR}, SYSDATE(), #{createBy,jdbcType=VARCHAR},
      SYSDATE(), #{updateBy,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="work_type_id" keyProperty="workTypeId" parameterType="com.xhpc.activity.domain.XhpcWorkTypeDictDomain" useGeneratedKeys="true">
    insert into xhpc_work_type_dict
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">
        name,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="parentTypeId != null">
        parent_type_id,
      </if>
      <if test="status != null">
        `status`,
      </if>
        del_flag,
      <if test="tenantId != null">
        tenant_id,
      </if>
        create_time,
      <if test="createBy != null">
        create_by,
      </if>
        update_time,
      <if test="updateBy != null">
        update_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=SMALLINT},
      </if>
      <if test="parentTypeId != null">
        #{parentTypeId,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=SMALLINT},
      </if>
      0,
      <if test="tenantId != null">
        #{tenantId,jdbcType=VARCHAR},
      </if>
        SYSDATE(),
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      SYSDATE(),
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.xhpc.activity.domain.XhpcWorkTypeDictDomain">
    update xhpc_work_type_dict
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=SMALLINT},
      </if>
      <if test="parentTypeId != null">
        parent_type_id = #{parentTypeId,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=SMALLINT},
      </if>
      <if test="tenantId != null">
        tenant_id = #{tenantId,jdbcType=VARCHAR},
      </if>
        update_time = SYSDATE(),
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
    </set>
    where work_type_id = #{workTypeId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcWorkTypeDictDomain">
    update xhpc_work_type_dict
    set name = #{name,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=SMALLINT},
      parent_type_id = #{parentTypeId,jdbcType=INTEGER},
      `status` = #{status,jdbcType=SMALLINT},
      tenant_id = #{tenantId,jdbcType=VARCHAR},
      update_time = SYSDATE(),
      update_by = #{updateBy,jdbcType=VARCHAR}
    where work_type_id = #{workTypeId,jdbcType=INTEGER}
  </update>
</mapper>