<?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="UserEntity">
	<resultMap id="RM_userEntity" type="com.blueland.bpm.identity.model.User">
        <result property="userId" column="USER_ID"/>
        <result property="userCode" column="USER_CODE"/>
        <result property="userName" column="USER_NAME"/>
        <result property="userSex" column="USER_SEX"/>
        <result property="userAge" column="USER_AGE"/>
        <result property="companyId" column="COMPANY_ID"/>
        <result property="companyName" column="COMPANY_NAME"/>
        <result property="orgId" column="ORG_ID"/>
        <result property="orgName" column="ORG_NAME"/>
        <result property="deptId" column="DEPT_ID"/>
        <result property="deptName" column="DEPT_NAME"/>
        <result property="companyName" column="COMPANY_NAME"/>
        <result property="userMobile" column="USER_MOBILE"/>
        <result property="userMail" column="USER_MAIL"/>
        <result property="userWorkAddress" column="USER_WORK_ADDRESS"/>
        <result property="userWorkPhone" column="USER_WORK_PHONE"/>
        <result property="userHomeAddree" column="USER_HOME_ADDREE"/>
        <result property="userHomePhone" column="USER_HOME_PHONE"/>
        <result property="positionId" column="POSITION_ID"/>
        <result property="pluralityPositionId" column="PLURALITY_POSITION_ID"/>
        <result property="titleId" column="TITLE_ID"/>
        <result property="pluralityTitleId" column="PLURALITY_TITLE_ID"/>
        <result property="userSort" column="USER_SORT"/>
        <result property="userType" column="USER_TYPE"/>
        <result property="userStatus" column="USER_STATUS"/>
        <result property="userPwd" column="USER_PWD"/>
        <result property="userCreateTime" column="USER_CREATE_TIME"/>
        <result property="userUpdateTime" column="USER_UPDATE_TIME"/>
        <result property="userCreator" column="USER_CREATOR"/>
        <result property="remark" column="REMARK"/>
        <result property="deptId" column="DEPT_ID"/>
        <result property="deptName" column="DEPT_NAME"/>
	</resultMap>
	<sql id="Base_Column_List">
	    <!--@mbg.generated-->
	    `USER_ID`, `USER_CODE`, `USER_NAME`, `USER_SEX`, `USER_AGE`, `USER_MOBILE`, `USER_MAIL`, 
	    `USER_WORK_ADDRESS`, `USER_WORK_PHONE`, `USER_HOME_ADDREE`, `USER_HOME_PHONE`, `POSITION_ID`, 
	    `PLURALITY_POSITION_ID`, `TITLE_ID`, `PLURALITY_TITLE_ID`, `USER_TYPE`, `USER_STATUS`, 
	    `USER_SORT`, `USER_PWD`, `USER_CREATE_TIME`, `USER_UPDATE_TIME`, `USER_CREATOR`, 
	    `REMARK`, `COMPANY_ID`, `ORG_ID`, `DEPT_ID`, `COMPANY_NAME`, `DEPT_NAME`, `ORG_NAME`
	</sql>
	<insert id="insert">
		insert into `T_PUB_USER` (<include refid="Base_Column_List"/>) VALUES (
			#{userId,jdbcType=VARCHAR}, 
			#{userCode,jdbcType=VARCHAR}, 
			#{userName,jdbcType=VARCHAR},
			#{userSex,jdbcType=VARCHAR}, 
			#{userAge,jdbcType=INTEGER}, 
			#{userMobile,jdbcType=VARCHAR},
			#{userMail,jdbcType=VARCHAR}, 
			#{userWorkAddress,jdbcType=CHAR}, 
			#{userWorkPhone,jdbcType=CHAR},
			#{userHomeAddree,jdbcType=CHAR}, 
			#{userHomePhone,jdbcType=CHAR}, 
			#{positionId,jdbcType=CHAR},
			#{pluralityPositionId,jdbcType=CHAR}, 
			#{titleId,jdbcType=CHAR}, 
			#{pluralityTitleId,jdbcType=CHAR},
			#{userType,jdbcType=CHAR}, 
			#{userStatus,jdbcType=VARCHAR}, 
			#{userSort,jdbcType=INTEGER},
			#{userPwd,jdbcType=VARCHAR}, 
			#{userCreateTime,jdbcType=VARBINARY},
			#{userUpdateTime,jdbcType=VARBINARY}, 
			#{userCreator,jdbcType=CHAR}, 
			#{remark,jdbcType=VARCHAR},
			#{companyId,jdbcType=VARCHAR}, 
			#{orgId,jdbcType=VARCHAR}, 
			#{deptId,jdbcType=VARCHAR},
			#{companyName,jdbcType=VARCHAR}, 
			#{deptName,jdbcType=VARCHAR}, 
			#{orgName,jdbcType=VARCHAR}
		)
	</insert>
	<update id="updateByRemark">
        UPDATE T_PUB_USER 
        <set>   
            <if test="@Ognl@isNotEmpty(userId)">
                USER_ID = #{userId,jdbcType=VARCHAR},
            </if>     
            <if test="@Ognl@isNotEmpty(userCode)">
                USER_CODE = #{userCode,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userName)">
                USER_NAME = #{userName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userSex)">
                USER_SEX = #{userSex,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userAge)">
                USER_AGE = #{userAge,jdbcType=INTEGER},
            </if>
            <if test="@Ognl@isNotEmpty(companyId)">
                COMPANY_ID =
                        #{companyId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(companyName)">
                COMPANY_NAME = #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(orgId)">
                ORG_ID = #{orgId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(orgName)">
                ORG_NAME = #{orgName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(deptId)">
                DEPT_ID = #{deptId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(deptName)">
                DEPT_NAME = #{deptName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(companyName)">
                COMPANY_NAME = #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userMobile)">
                USER_MOBILE =
                        #{userMobile,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userMail)">
                USER_MAIL =
                        #{userMail,jdbcType=VARCHAR},
            </if>
             <if test="@Ognl@isNotEmpty(userPwd)">
                USER_PWD = #{userPwd,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userStatus)">
                USER_STATUS = #{userStatus,jdbcType=VARCHAR}
            </if>
           
        </set>
        WHERE  REMARK = #{remark,jdbcType=VARCHAR} and USER_ID = #{userId,jdbcType=VARCHAR}
    </update>
	<update id="updateByUserId">
        UPDATE T_PUB_USER 
        <set>        
            <if test="@Ognl@isNotEmpty(userCode)">
                USER_CODE = #{userCode,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userName)">
                USER_NAME = #{userName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userSex)">
                USER_SEX = #{userSex,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userAge)">
                USER_AGE = #{userAge,jdbcType=INTEGER},
            </if>
            <if test="@Ognl@isNotEmpty(companyId)">
                COMPANY_ID =
                        #{companyId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(companyName)">
                COMPANY_NAME = #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(orgId)">
                ORG_ID = #{orgId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(orgName)">
                ORG_NAME = #{orgName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(deptId)">
                DEPT_ID = #{deptId,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(deptName)">
                DEPT_NAME = #{deptName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(companyName)">
                COMPANY_NAME = #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userMobile)">
                USER_MOBILE =
                        #{userMobile,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userMail)">
                USER_MAIL =
                        #{userMail,jdbcType=VARCHAR},
            </if>
             <if test="@Ognl@isNotEmpty(userPwd)">
                USER_PWD = #{userPwd,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(remark)">
                REMARK = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="@Ognl@isNotEmpty(userStatus)">
                USER_STATUS = #{userStatus,jdbcType=VARCHAR}
            </if>
           
        </set>
        WHERE  USER_ID = #{userId,jdbcType=VARCHAR}
    </update>
    <delete id="deleteByUserId">
    	DELETE FROM T_PUB_USER WHERE USER_ID= #{userId,jdbcType=VARCHAR}
    </delete>
    <select id="findUserByUserId" resultMap="RM_userEntity">
     SELECT * FROM T_PUB_USER WHERE USER_ID = #{userId,jdbcType=VARCHAR}
    </select>
    <select id="findUserByRemark" resultMap="RM_userEntity">
     SELECT * FROM T_PUB_USER WHERE REMARK = #{remark,jdbcType=VARCHAR} ORDER BY USER_CREATE_TIME LIMIT 1
    </select>
    <update id="updateStatusByUserId">
    	UPDATE T_PUB_USER SET USER_STATUS='JY'  WHERE USER_ID= #{userId,jdbcType=VARCHAR}
    </update>
    
    <update id="updateQyStatusByUserId">
    	UPDATE T_PUB_USER SET USER_STATUS='QY'  WHERE USER_ID= #{userId,jdbcType=VARCHAR}
    </update>
 
</mapper>

