<?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.nbclass.szxgl.mapper.ProjectTaskMapper">
  <resultMap id="BaseResultMap" type="com.nbclass.szxgl.model.ProjectTask">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="CHAR" property="id" />
    <result column="_project_id" jdbcType="CHAR" property="projectId" />
    <result column="_name" jdbcType="VARCHAR" property="name" />
    <result column="_start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="_end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="_content" jdbcType="VARCHAR" property="content" />
    <result column="_create_user_id" jdbcType="CHAR" property="createUserId" />
    <result column="_create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="_update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="_speed" jdbcType="TINYINT" property="speed" />
    <result column="_notify" jdbcType="SMALLINT" property="notify" />
  </resultMap>
  
  	<select id="getList" resultType="com.nbclass.szxgl.model.ProjectTask">
  		select p.*, 
		(select group_concat(su.true_name) from project_task_user ptu, sy_users su where ptu._project_task_id = p.id and ptu._user_id = su.user_name) as zxrNames
		,(select group_concat(su.user_name) from project_task_user ptu, sy_users su where ptu._project_task_id = p.id and ptu._user_id = su.user_name) as zxrIds
		, project._name as projectName 
		, sy_users.true_name as createUserName 
		from project_task p 
		left join project on p._project_id = project.id 
		left join sy_users on p._create_user_id = sy_users.user_name
		where _project_id = #{pid} 
  	</select>

    <select id="findById" parameterType="java.lang.String" resultType="com.nbclass.szxgl.model.ProjectTask">
		select * from project_task where id = #{id}
	</select>

    <delete id="deleteByProjectId" parameterType="java.lang.String">
		delete from project_task where _project_id = #{projectId}
	</delete>

    <select id="getProjectTaskIds" parameterType="java.lang.String" resultType="java.lang.String">
        select id from project_task where _project_id = #{projectId}
    </select>

    <select id="findByProjectId" parameterType="java.lang.String" resultType="com.nbclass.szxgl.model.ProjectTask">
		select * from project_task where _project_id = #{projectId}
	</select>

    <select id="getMyTaskList" parameterType="java.lang.String" resultType="map">
		SELECT su.true_name AS createUserName, a.* FROM (
		SELECT DISTINCT pt.id,pt._speed as speed,pt._name as name,pt._start_time as startTime,pt._end_time as endTime ,pt._create_user_id  AS createUserId
	,pt._project_id as projectId,pt._content AS content,pt._create_time AS createTime,p._name as projectName,p._status AS STATUS
	,(SELECT group_concat(su.true_name)  FROM project_task_user ptuser ,sy_users su WHERE ptuser._project_task_id = pt.id AND ptuser._user_id = su.user_name) AS userNames
	FROM project_task pt LEFT JOIN project p ON pt._project_id= p.id  LEFT JOIN project_task_user ptu on ptu._project_task_id = pt.id
		WHERE ptu._user_id = #{userid}
		ORDER BY pt._create_time DESC)a left join sy_users su on a.createUserId=su.user_name
	</select>

	<update id="updateTaskSpeed">
		update project_task set _speed = #{speed} where id = #{id}
	</update>
</mapper>