select task.id id, task.code code, task.name name, task.description description, planstarttime, planendtime, exestarttime, exeendtime, closemsg, submittime, dispatchtime, source.typename source, tasktype.typename tasktype, task.owner, buser.realname ownername, task.projectid, dept.description projectname, task.executer, taskstatus from p_projecttask task left join t_s_depart dept on task.projectid = dept.id left join t_s_type source on task.sourcetype = source.typecode and source.typegroupid in (select id from t_s_typegroup where typegroupcode = 'tasksourcetype') left join t_s_type tasktype on task.tasktype = tasktype.typecode and tasktype.typegroupid in (select id from t_s_typegroup where typegroupcode = 'tasktype') left join t_s_base_user buser on task.owner = buser.id where 1 = 1 <#if projectid ?exists && projectid ?length gt 0> and task.projectid = :projectid <#if openid ?exists && openid ?length gt 0> and owner in (select id from t_s_user where openid = :openid) <#if qrydate ?exists && qrydate ?length gt 0> and left(planendtime,10) = :qrydate <#if taskid ?exists && taskid ?length gt 0> and task.id = :taskid union all select task.id id, task.code code, task.name name, task.description description, planstarttime, planendtime, exestarttime, exeendtime, closemsg, submittime, dispatchtime, source.typename source, tasktype.typename tasktype, task.owner, buser.realname ownername, task.projectid, dept.description projectname, task.executer, taskstatus from p_projecttask task left join t_s_depart dept on task.projectid = dept.id left join t_s_type source on task.sourcetype = source.typecode and source.typegroupid in (select id from t_s_typegroup where typegroupcode = 'tasksourcetype') left join t_s_type tasktype on task.tasktype = tasktype.typecode and tasktype.typegroupid in (select id from t_s_typegroup where typegroupcode = 'tasktype') left join t_s_base_user buser on task.owner = buser.id where 1 = 1 <#if projectid ?exists && projectid ?length gt 0> and task.projectid = :projectid <#if openid ?exists && openid ?length gt 0> and owner in (select id from t_s_user where openid = :openid) <#if qrydate ?exists && qrydate ?length gt 0> and left(planendtime,10) < :qrydate <#if taskid ?exists && taskid ?length gt 0> and task.id = :taskid and taskstatus in ('0','1')