<?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.goafanti.common.dao.TTaskMemberMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TTaskMember">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="tid" jdbcType="INTEGER" property="tid" />
    <result column="service_life" jdbcType="VARCHAR" property="serviceLife" />
    <result column="service_year" jdbcType="VARCHAR" property="serviceYear" />
    <result column="year_sum" jdbcType="INTEGER" property="yearSum" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="contract_term" jdbcType="VARCHAR" property="contractTerm" />
  </resultMap>
  <sql id="Base_Column_List">
    id, tid, service_life, service_year, year_sum, create_time, contract_term
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_task_member
    where id = #{id,jdbcType=INTEGER}
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_task_member
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TTaskMember">
    insert into t_task_member (id, tid, service_life,
      service_year, year_sum, create_time,
      contract_term)
    values (#{id,jdbcType=INTEGER}, #{tid,jdbcType=INTEGER}, #{serviceLife,jdbcType=VARCHAR},
      #{serviceYear,jdbcType=VARCHAR}, #{yearSum,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
      #{contractTerm,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TTaskMember">
    insert into t_task_member
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="serviceLife != null">
        service_life,
      </if>
      <if test="serviceYear != null">
        service_year,
      </if>
      <if test="yearSum != null">
        year_sum,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="contractTerm != null">
        contract_term,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="tid != null">
        #{tid,jdbcType=INTEGER},
      </if>
      <if test="serviceLife != null">
        #{serviceLife,jdbcType=VARCHAR},
      </if>
      <if test="serviceYear != null">
        #{serviceYear,jdbcType=VARCHAR},
      </if>
      <if test="yearSum != null">
        #{yearSum,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="contractTerm != null">
        #{contractTerm,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TTaskMember">
    update t_task_member
    <set>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="serviceLife != null">
        service_life = #{serviceLife,jdbcType=VARCHAR},
      </if>
      <if test="serviceYear != null">
        service_year = #{serviceYear,jdbcType=VARCHAR},
      </if>
      <if test="yearSum != null">
        year_sum = #{yearSum,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="contractTerm != null">
        contract_term = #{contractTerm,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TTaskMember">
    update t_task_member
    set tid = #{tid,jdbcType=INTEGER},
      service_life = #{serviceLife,jdbcType=VARCHAR},
      service_year = #{serviceYear,jdbcType=VARCHAR},
      year_sum = #{yearSum,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      contract_term = #{contractTerm,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updateByTid">
    update t_task_member
    <set>
      <if test="serviceLife != null">
        service_life = #{serviceLife,jdbcType=VARCHAR},
      </if>
      <if test="serviceYear != null">
        service_year = #{serviceYear,jdbcType=VARCHAR},
      </if>
      <if test="yearSum != null">
        year_sum = #{yearSum,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="contractTerm != null">
      contract_term = #{contractTerm,jdbcType=VARCHAR}
      </if>
    </set>
    where tid = #{tid,jdbcType=INTEGER}
  </update>
    <update id="updateSplitSuper">
      update  t_order_task a ,t_task_member b
      <set>
      <if test="serviceLife != null">
       b.service_life= #{serviceLife} ,
      </if>
        <if test="serviceYear != null">
          b.service_year= #{serviceYear} ,
        </if>
        <if test="yearSum != null">
          b.year_sum= #{yearSum} ,
        </if>
        <if test="contractTerm != null">
          b.contract_term= #{contractTerm},
        </if>
      </set>
      where a.id=b.tid and a.split_super = #{id}
    </update>


  <select id="selectByTid" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_task_member
    where tid = #{id,jdbcType=INTEGER}
  </select>

  <update id="updateServiceYearBySplitSuper">
    update t_task_member a,(select a.split_super,GROUP_CONCAT(b.service_year) counts
        from t_order_task a left join t_task_member b on a.id=b.tid
        where a.split_status =2 and a.split_super= #{tid}
        group by a.split_super)x
    set a.service_year =x.counts
    where a.tid =x.split_super
  </update>
</mapper>
