<?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="org.jeecg.modules.stm.project.record.mapper.StProjectRecordMapper">
<select id="queryStProjectRecordVoByPage" resultType="org.jeecg.modules.stm.project.record.vo.StProjectRecordVo">
select
distinct
		b.id as id,
		a.project_name as projectName ,
		a.project_type as projectType ,
		a.exec_dep_code as execDepCode ,
		a.head_code as headCode ,
		a.plan_start_date as planStartDate ,
		a.plan_end_date as planEndDate ,
		a.id as projectCreId,
		b.record_Dep_Code as recordDepCode ,
		b.record_user as recordUser ,
		b.record_Date as recordDate ,
	        case 
	        when b.record_Date is null then '1' 
	        else '0'
	        end
	        as recordFlag ,

		(select depart_name from sys_depart c
		where c.id=a.exec_dep_code)
		as execDepName,
		(select realname from sys_user c where c.username=a.head_code) as
		headName,
		(select realname from sys_user c where c.username=b.record_user) as
		recordName,
		(select depart_name from sys_depart c
		where c.id=b.record_Dep_Code)
		as recordDepName,
		d.updated_time as updatedTime,
		a.project_Desc as projectDesc
		from
		st_project_check c,
		st_project_exec d ,
		st_project_cre a 
		left join st_project_record b on a.id=b.project_cre_id
		where a.id=c.project_cre_id
		and c.id=d.project_Check_Id
		and d.exec_level='0005'
		<if test="stProjectRecordVo.projectName!=null and stProjectRecordVo.projectName!='' ">
			and a.project_name like concat('%',#{stProjectRecordVo.projectName},'%')
		</if>
		<if test="stProjectRecordVo.execDepCode!=null   and  stProjectRecordVo.execDepCode!=''  ">
			and a.exec_dep_code =#{stProjectRecordVo.execDepCode}
		</if>
		<if test="stProjectRecordVo.projectType!=null and stProjectRecordVo.projectType!='' ">
			and a.project_type =#{stProjectRecordVo.projectType}
		</if>
		order by d.updated_time desc
	</select>
</mapper>