<?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.rectify.plan.mapper.StRectifyPlanMapper">
	<select id="queryStRectifyPlanVoByPage" resultType="org.jeecg.modules.stm.rectify.plan.vo.StRectifyPlanVo">
		select
		a.late_finish_time as lateFinishTime,
		a.problem_item as problemItem,
		a.problem_des as problemDes,
		a.strategy as strategy,
		a.programme as programme,
		b.exec_user as execUser,
		b.id as id,
		a.id as problemTaskId,
		b.head_dep_code as headDepCode,
		(select depart_name from sys_depart c
		where c.id=b.head_dep_code)
		as headDepName,
		b.head_code as headCode,
		(select realname from sys_user c where c.username=b.head_code) as
		headName,

		b.exec_dep_code as execDepCode,
		(select
		depart_name from sys_depart c where
		c.id=b.exec_dep_code)
		as
		execDepName,
		b.exec_user as execUser,
		(select realname from sys_user c where c.username=b.exec_user)

		execUserName,
		b.approve_dep_code as approveDepCode,
		(select depart_name from
		sys_depart c where
		c.id=b.approve_dep_code)
		as approveDepName,
		b.approve_user as approveUser,
		(select realname from sys_user c where c.username=b.approve_user)

		as approveUserName,

		b.plan_start_date as planStartDate,
		b.plan_end_date as
		planEndDate,
		case
		when b.edit_flag
		is null then 0
		else b.edit_flag
		end
		as
		editFlag,
		case
		when b.approve_flag
		is null then 0
		else b.approve_flag
		end
		as approveFlag,
		b.approve_des as
		approveDes,
		b.approve_time as
		approveTime,
		b.start_date
		as startDate,
		b.end_date as endDate,
		b.rectify_des as rectifyDes,
		b.file_upload_path
		as fileUploadPath,
		b.created_user as createdUser,
		b.created_time as
		createdTime,
		b.updated_user as updatedUser,
		b.updated_time as
		updatedTime
		from
		st_problem_task_assin a left join
		st_rectify_plan b on
		a.id=b.PROBLEM_TASK_ID
		<where>
			<if test="stRectifyPlanVo.editFlag!=null">
				b.edit_flag = #{stRectifyPlanVo.editFlag}
			</if>
			<if test="stRectifyPlanVo.approveFlag!=null">
				and b.approve_flag = #{stRectifyPlanVo.approveFlag}
			</if>
			<if test="stRectifyPlanVo.execUser!=null">
				and b.exec_user = #{stRectifyPlanVo.execUser}
			</if>
			<if test="stRectifyPlanVo.approveUser!=null">
				and b.approve_user  = #{stRectifyPlanVo.approveUser}
				and b.approve_flag !='0'
			</if>
			<if test="stRectifyPlanVo.headCode!=null">
				and a.head_code = #{stRectifyPlanVo.headCode}
			</if>
			<if test="stRectifyPlanVo.problemItem!=null">
				and a.problem_item like concat('%',#{stRectifyPlanVo.problemItem},'%')
			</if>
			<if test="stRectifyPlanVo.strategy!=null">
				and a.strategy = #{stRectifyPlanVo.strategy}
			</if>
			<if test="stRectifyPlanVo.editFlag!=null">
				and b.edit_Flag = #{stRectifyPlanVo.editFlag}
			</if>
		</where>
			<if test="stRectifyPlanVo.headCode!=null">
				order by a.updated_time desc
			</if>
			<if test="stRectifyPlanVo.execUser!=null">
				order by b.edit_date desc
			</if>
			<if test="stRectifyPlanVo.approveUser!=null">
				order by b.exec_date desc
			</if>
	</select>
</mapper>