<?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.jeeplus.modules.sg.managementcenter.activiti.mapper.PersonnelManagementMapper">
    
	<sql id="constructionColumns">
		a.id AS "id",
		a.uId AS "uid",
		a.Pid AS "pid",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",

	</sql>

	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.PersonnelManagement" >
		SELECT *
		FROM xm_personnel_management a
		WHERE a.uId = #{uId}
	</select>
	
	<select id="findList" resultType="PersonnelManagement" >
		SELECT *
		FROM xm_personnel_management a
		<where>
			<if test="dataScope != null and dataScope != ''">
				${dataScope}
			</if>
			<if test="uId != null and uId != ''">
				AND a.uId = #{uId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="PersonnelManagement" >
		SELECT *
		FROM xm_personnel_management a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO xm_personnel_management(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE xm_personnel_management SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>

	<!--物理删除-->
	<update id="delete">
		DELETE FROM xm_personnel_management
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE xm_personnel_management SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	

	
</mapper>