<?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="SapUserMapper">
	<insert id="saveOne">
		insert into sap_user(userId,personId,username,name,
			firstOrg,secondOrg,thirdOrg,fourthOrg,
			position,formatPosition,mobile,formatMobile,businessPhone,formatBusinessPhone,gender,
			email,formatEmail,isPrimary,delFlag,createDate) 
		values (#{userId},#{personId},#{username},#{name},
			#{firstOrg},#{secondOrg},#{thirdOrg},#{fourthOrg},
			#{position},#{formatPosition},#{mobile},#{formatMobile},#{businessPhone},#{formatBusinessPhone},#{gender},
			#{email},#{formatEmail},#{isPrimary},#{delFlag},#{createDate})
	</insert>
	
	<update id="updateOne">
		update sap_user 
		set username=#{username},name=#{name},personId=#{personId},
			firstOrg=#{firstOrg},secondOrg=#{secondOrg},thirdOrg=#{thirdOrg},fourthOrg=#{fourthOrg},
			position=#{position},formatPosition=#{formatPosition},
			mobile=#{mobile},formatMobile=#{formatMobile},businessPhone=#{businessPhone},formatBusinessPhone=#{formatBusinessPhone},
			gender=#{gender},email=#{email},formatEmail=#{formatEmail},
			isPrimary=#{isPrimary},delFlag=#{delFlag}
		where userId=#{userId}
	</update>
	
	<update id="updateDelFlag">
		update sap_user 
		set delFlag=#{delFlag}
		where userId=#{userId}
	</update>
	
	<update id="updateResult">
		update sap_user set result=#{result} where personId=#{personId}
	</update>
	
	<select id="selectOne" resultType="SapUser">
		select * from sap_user where userId=#{userId}
	</select>
	
	<select id="selectListByPersonId" resultType="SapUser">
		select * from sap_user where personId=#{personId} order by isPrimary desc
	</select>
	
	<select id="selectUnSyncList" resultType="SapUser">
		select * from sap_user where result is null and delFlag = 0
	</select>
	
	<select id="selectDeleteList" resultType="SapUser">
		select * from sap_user where delFlag = 1
	</select>
	
	<update id="updateAllDelete">
		update sap_user set delFlag = 1
	</update>
	
	<select id="selectReportUserList" resultType="SapUser">
		select * from sap_user where result != '垃圾数据' or result is null
	</select>
</mapper>