<?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.qunzhixinxi.hnqz.admin.mapper.WmScoreTaskTypeMapper" >
  <resultMap id="BaseResultMap" type="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="score_id" property="scoreId" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="task_type_id" property="taskTypeId" jdbcType="VARCHAR" />
	  <result property="taskTypeName" column="taskTypeName"/>
  </resultMap>
  <sql id="Base_Column_List" >
    id, score_id, type,task_type_id
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from wm_score_task_type
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from wm_score_task_type
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
    insert into wm_score_task_type (id, score_id, type,task_type_id
      )
    values (#{id,jdbcType=BIGINT}, #{scoreId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{taskTypeId,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
    insert into wm_score_task_type
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="scoreId != null" >
        score_id,
      </if>
      <if test="type != null" >
        type,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="scoreId != null" >
        #{scoreId,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
    update wm_score_task_type
    <set >
      <if test="scoreId != null" >
        score_id = #{scoreId,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
    update wm_score_task_type
    set score_id = #{scoreId,jdbcType=VARCHAR},
      type = #{type,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>

	<select id="listWmScoreTaskType" resultMap="BaseResultMap" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
		select
		<include refid="Base_Column_List" />
		from wm_score_task_type
		where 1 =1
		<if test="id != null">
			and id = #{id,jdbcType=BIGINT}
		</if>
		<if test="scoreId != null and scoreId != '' " >
			and	score_id = #{scoreId,jdbcType=VARCHAR}
		</if>
		<if test="type != null and type != ''" >
			and	type = #{type,jdbcType=VARCHAR}
		</if>
		<if test="taskTypeId != null and taskTypeId != ''" >
			and	task_type_id = #{taskTypeId,jdbcType=VARCHAR}
		</if>

	</select>

	<select id="listWmScoreTaskTypes" resultMap="BaseResultMap" parameterType="com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType" >
		select
		score_id,type,task_type_id
		from wm_score_task_type
		where 1 =1
		<if test="scoreId != null and scoreId != '' " >
			and	score_id = #{scoreId,jdbcType=VARCHAR}
		</if>
		<if test="type != null and type != ''" >
			and	type = #{type,jdbcType=VARCHAR}
		</if>
		<if test="taskTypeId != null and taskTypeId != ''" >
			and	task_type_id = #{taskTypeId,jdbcType=VARCHAR}
		</if>
	</select>

	<insert id="batchInsertType" parameterType="java.util.HashMap">
		insert into wm_score_task_type (id, score_id, type,task_type_id)
		values
		<foreach collection="list" item="item" index="index" separator=",">
			(#{item.id,jdbcType=BIGINT}, #{item.scoreId,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, #{item.taskTypeId,jdbcType=VARCHAR})
		</foreach>

	</insert>

	<delete id="deleteByScoreId" parameterType="java.lang.String" >
    delete from wm_score_task_type
    where score_id = #{scoreId,jdbcType=VARCHAR}
  </delete>

	<select id="getScoreTaskTypeByScoreId" resultMap="BaseResultMap">
		select t.*,
		CASE WHEN d.`value` is null THEN  tt.task_type_name ELSE d.label END as taskTypeName
		from
		wm_score_task_type t
		left join sys_dict_item d on d.`value`=t.task_type_id and d.type='score_task_type'
		left join wm_task_type tt on tt.id=t.task_type_id
		where 1=1
		<if test="scoreId!=null and scoreId!=''">
			AND t.score_id in(${scoreId})
		</if>
		order by t.id

	</select>

	<select id="selectByScoreId" resultMap="BaseResultMap">
		select
		*
		from wm_score_task_type
		where
		score_id = #{query.scoreId,jdbcType=VARCHAR}
	</select>
	<select id="selectByRelationScoreId" resultMap="BaseResultMap">
		select
		*
		from wm_score_task_type
		where
		score_id = #{scoreId,jdbcType=VARCHAR}
	</select>

</mapper>
