<?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.hr.dao.UserInfoDao">
    
	<sql id="userInfoColumns">
		a.id AS "id",
		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",
		a.user_id AS "userId",
		a.company_id AS "companyId",
		a.name AS "name",
		a.nick_name AS "nickName",
		a.gender AS "gender",
		a.job_number AS "jobNumber",
		a.highest_degree AS "highestDegree",
		a.highest_school AS "highestSchool",
		a.highest_profession AS "highestProfession",
		a.highest_graduationtime AS "highestGraduationTime",
		a.first_degree AS "firstDegree",
		a.first_chool AS "firstSchool",
		a.first_profession AS "firstProfession",
		a.first_graduationtime AS "firstGraduationTime",
		a.birthday AS "birthday",
		a.id_card AS "idCard",
		a.professional_title AS "professionalTitle",
		a.professional_getdate AS "professionalGetdate",
		a.social_insurance_account AS "socialInsuranceAccount",
		a.medical_insurance_account AS "medicalInsuranceAccount",
		a.bank_account AS "bankAccount",
		a.provident_fund_account AS "providentFundAccount",
		a.qq AS "qq",
		a.weixin AS "weixin",
		a.mobilephone AS "mobilePhone",
		a.email AS "email",
		a.is_costengineer AS "isCostengineer",
		a.costengineer_getdate AS "costengineerGetdate",
		a.workstart_date AS "workstartDate",
		a.probation_position AS "probationPosition",
		a.probation_duration AS "probationDuration",
		a.probation_enddate AS "probationEnddate",
		a.professional_qualification AS "professionalQualification",
		a.engaged_job AS "engagedJob",
		a.other_qualification AS "otherQualification",
		a.personal_profile AS "personalProfile"
	</sql>
	
	<sql id="userInfoJoins">
	</sql>


	<select id="findUserInfoList" resultType="UserInfo" >
		SELECT
			ui.id AS "id",
			ui.create_by AS "createBy",
			ui.create_date AS "reateDate",
			ui.update_by AS "updateBy.id",
			ui.update_date AS "updateDate",
			ui.remarks AS "remarks",
			ui.del_flag AS "delFlag",
			ui.user_id AS "userId",
			ui.company_id AS "companyId",
			ui.name AS "name",
			ui.nick_name AS "nickName",
			ui.gender AS "gender",
			ui.job_number AS "jobNumber",
			ui.highest_degree AS "highestDegree",
			ui.highest_school AS "highestSchool",
			ui.highest_profession AS "highestProfession",
			ui.highest_graduationtime AS "highestGraduationTime",
			ui.first_degree AS "firstDegree",
			ui.first_chool AS "firstSchool",
			ui.first_profession AS "firstProfession",
			ui.first_graduationtime AS "firstGraduationTime",
			ui.birthday AS "birthday",
			ui.id_card AS "idCard",
			ui.professional_title AS "professionalTitle",
			ui.professional_getdate AS "professionalGetdate",
			ui.social_insurance_account AS "socialInsuranceAccount",
			ui.medical_insurance_account AS "medicalInsuranceAccount",
			ui.bank_account AS "bankAccount",
			ui.provident_fund_account AS "providentFundAccount",
			ui.qq AS "qq",
			ui.weixin AS "weixin",
			ui.mobilephone AS "mobilePhone",
			ui.email AS "email",
			ui.is_costengineer AS "isCostengineer",
			ui.costengineer_getdate AS "costengineerGetdate",
			ui.workstart_date AS "workstartDate",
			ui.probation_position AS "probationPosition",
			ui.probation_duration AS "probationDuration",
			ui.probation_enddate AS "probationEnddate",
			ui.professional_qualification AS "professionalQualification",
			ui.engaged_job AS "engagedJob",
			ui.other_qualification AS "otherQualification",
			ui.personal_profile AS "personalProfile",
			uo.id AS "userOffice.id",
			uo.create_by AS "userOffice.createBy.id",
			uo.create_date AS "userOffice.createDate",
			uo.update_by AS "userOffice.updateBy.id",
			uo.update_date AS "userOffice.updateDate",
			uo.remarks AS "userOffice.remarks",
			uo.del_flag AS "userOffice.delFlag",
			uo.user_id AS "userOffice.userId",
			uo.company_id AS "userOffice.companyId",
			uo.office_id AS "userOffice.officeId",
			uo.master AS "userOffice.master",
			uo.status AS "userOffice.status",
			u.id AS "userOffice.user.id",
			u.com_id AS "userOffice.user.comId",
			u.company_id AS "userOffice.user.company.id",
			u.office_id AS "userOffice.user.office.id",
			u.login_name AS "userOffice.user.loginName",
			u.password AS "userOffice.user.passwork",
			u.password_remake AS "userOffice.user.passwordRemake",
			u.no AS "userOffice.user.no",
			u.name AS "userOffice.user.name",
			u.sex AS "userOffice.user.sex",
			u.email AS "userOffice.user.email",
			u.phone AS "userOffice.user.phone",
			u.mobile AS "userOffice.user.mobile",
			u.ishide AS "userOffice.user.ishide",
			u.user_type AS "userOffice.user.userType",
			u.login_ip AS "userOffice.user.loginIp",
			u.login_date AS "userOffice.user.loginDate",
			u.remarks AS "userOffice.user.remarks",
			u.login_flag AS "userOffice.user.loginFlag",
			u.photo AS "userOffice.user.photo",
			u.default_photo AS "userOffice.user.defaultPhoto",
			u.qrcode AS "userOffice.user.qrcode",
			u.sign AS "userOffice.user.sign",
			u.create_by AS "userOffice.user.createBy.id",
			u.create_date AS "userOffice.user.createDate",
			u.update_by AS "userOffice.user.updateBy.id",
			u.update_date AS "userOffice.user.updateDate",
			u.del_flag AS "userOffice.user.delFlag"
		FROM sys_user_office uo
		LEFT JOIN sys_user u ON u.id = uo.user_id
		LEFT JOIN sys_user_info ui ON ui.sys_user_office_id = uo.id
		<where>
			uo.del_flag = '0'
			AND uo.status = '3'
			<if test="companyId !=null and companyId !=''">
				AND uo.company_id = #{companyId}
			</if>
			<if test="name != null and name !=''">
				AND (ui.name LIKE concat('%',#{name},'%') or  u.name LIKE concat('%',#{name},'%'))
			</if>
			<if test="gender != null and gender !=''">
				AND (ui.gender = #{gender} or u.sex = #{gender})
			</if>
			<if test="mobilePhone !=null and mobilePhone != ''">
				AND (ui.mobilePhone LIKE  concat('%',#{mobilePhone},'%') or u.phone LIKE concat ('%',#{mobilePhone},'%'))
			</if>
			<if test="idCard !=null and idCard !=''">
				AND (ui.id_card LIKE concat('%',#{idCard},'%'))
			</if>
			<if test="officeId != null and officeId !=''">
				AND uo.office_id = #{officeId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY uo.create_by DESC
			</otherwise>
		</choose>
	</select>

	<select id="findUserInfoByUserIdCompanyId" resultType="UserInfo">
		SELECT <include refid="userInfoColumns"/>
		FROM sys_user_info a
		WHERE a.del_flag = '0'
			  AND user_id = #{userId}
			  AND company_id = #{companyId}
	</select>
    
	<select id="get" resultType="UserInfo" >
		SELECT 
			<include refid="userInfoColumns"/>
		FROM sys_user_info a
		<include refid="userInfoJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="UserInfo">
		SELECT 
			<include refid="userInfoColumns"/>,
		FROM sys_user_info a
			<include refid="userInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</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="UserInfo" >
		SELECT 
			<include refid="userInfoColumns"/>
		FROM sys_user_info a
		<include refid="userInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</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 sys_user_info(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			user_id,
			company_id,
			sys_user_office_id,
			name,
			nick_name,
			gender,
			job_number,
			highest_degree,
			highest_school,
			highest_profession,
			highest_graduationtime,
			first_degree,
			first_chool,
			first_profession,
			first_graduationtime,
			birthday,
			id_card,
			professional_title,
			professional_getdate,
			social_insurance_account,
			medical_insurance_account,
			bank_account,
			provident_fund_account,
			qq,
			weixin,
			mobilephone,
			email,
			is_costengineer,
			costengineer_getdate,
			workstart_date,
			probation_position,
			probation_duration,
			probation_enddate,
			professional_qualification,
			engaged_job,
			other_qualification,
			personal_profile
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{userId},
			#{companyId},
			#{userOffice.id},
			#{name},
			#{nickName},
			#{gender},
			#{jobNumber},
			#{highestDegree},
			#{highestSchool},
			#{highestProfession},
			#{highestGraduationTime},
			#{firstDegree},
			#{firstSchool},
			#{firstProfession},
			#{firstGraduationTime},
			#{birthday},
			#{idCard},
			#{professionalTitle},
			#{professionalGetdate},
			#{socialInsuranceAccount},
			#{medicalInsuranceAccount},
			#{bankAccount},
			#{providentFundAccount},
			#{qq},
			#{weixin},
			#{mobilePhone},
			#{email},
			#{isCostengineer},
			#{costengineerGetdate},
			#{workstartDate},
			#{probationPosition},
			#{probationDuration},
			#{probationEnddate},
			#{professionalQualification},
			#{engagedJob},
			#{otherQualification},
			#{personalProfile}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_user_info SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			user_id = #{userId},
			company_id = #{companyId},
			name = #{name},
			nick_name = #{nickName},
			gender = #{gender},
			job_number = #{jobNumber},
			highest_degree = #{highestDegree},
			highest_school = #{highestSchool},
			highest_profession = #{highestProfession},
			highest_graduationtime = #{highestGraduationTime},
			first_degree = #{firstDegree},
			first_chool = #{firstSchool},
			first_profession = #{firstProfession},
			first_graduationtime = #{firstGraduationTime},
			birthday = #{birthday},
			id_card = #{idCard},
			professional_title = #{professionalTitle},
			professional_getdate = #{professionalGetdate},
			social_insurance_account = #{socialInsuranceAccount},
			medical_insurance_account = #{medicalInsuranceAccount},
			bank_account = #{bankAccount},
			provident_fund_account = #{providentFundAccount},
			qq = #{qq},
			weixin = #{weixin},
			mobilephone = #{mobilePhone},
			email = #{email},
			is_costengineer = #{isCostengineer},
			costengineer_getdate = #{costengineerGetdate},
			workstart_date = #{workstartDate},
			probation_position = #{probationPosition},
			probation_duration = #{probationDuration},
			probation_enddate = #{probationEnddate},
			professional_qualification = #{professionalQualification},
			engaged_job = #{engagedJob},
			other_qualification = #{otherQualification},
			personal_profile = #{personalProfile},
			sys_user_office_id = #{userOffice.id}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_user_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_user_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="UserInfo" statementType="STATEMENT">
		select * FROM sys_user_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>