UserMapper.xml 12.6 KB
<?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.diligrp.manage.dao.impl.UserDaoImpl">
    <resultMap id="UserRM" type="com.diligrp.manage.domain.User">
            <id property="id" column="id"/>
            <result property="userName" column="user_name"/>
            <result property="password" column="password"/>
            <result property="lastLoginIp" column="last_login_ip"/>
            <result property="lastLoginTime" column="last_login_time"/>
            <result property="created" column="created"/>
            <result property="modified" column="modified"/>
            <result property="status" column="status"/>
            <result property="yn" column="yn"/>
            <result property="realName" column="real_name"/>
            <result property="serialNumber" column="serial_number"/>
            <result property="fixedLineTelephone" column="fixed_line_telephone"/>
            <result property="cellphone" column="cellphone"/>
            <result property="email" column="email"/>
            <result property="validTimeBegin" column="valid_time_begin"/>
            <result property="validTimeEnd" column="valid_time_end"/>
            <collection property="roles" javaType="java.util.List" resultMap="RoleRM"/>
    </resultMap>
    
     <resultMap id="RoleRM" type="com.diligrp.manage.domain.Role">
            <id property="id" column="id"/>
            <result property="roleName" column="role_name"/>
            <result property="description" column="description"/>
            <result property="created" column="created"/>
            <result property="modified" column="modified"/>
    </resultMap>
    
     <resultMap id="UserRoleRM" type="com.diligrp.manage.domain.UserRole">
            <id property="id" column="id"/>
            <result property="roleId" column="role_id"/>
    </resultMap>

	<insert id="batchSaveUserRoles" parameterType="map">
		
		 <selectKey keyProperty="id" resultType="long" order="AFTER">
            SELECT LAST_INSERT_ID();
        </selectKey>
	
	<![CDATA[
		INSERT INTO security_user_role(
                    user_id
                    ,role_id
		) VALUES(
					#{userId},
		        	#{roleId} 
		)
		]]>
	</insert>
	
	<select id="findRolesByUserId" parameterType="Long" resultMap="UserRoleRM">
		<![CDATA[
		SELECT
			u.id,
		    u.role_id
		FROM security_user_role u
		WHERE u.user_id=#{pk}
		]]>
	</select>

    <select id="findUserByRole" parameterType="Long" resultMap="UserRM">
        <![CDATA[
        SELECT *
        FROM security_user u
        LEFT JOIN security_user_role ur on ur.user_id = u.id
        where
        1 = 1
        and ur.role_id=#{id}
		]]>
    </select>
	
	<select id="checkUserNumber" parameterType="String" resultMap="UserRM">
		<![CDATA[
		SELECT u.id FROM security_user u where serial_number=#{serialNumber}
		]]>
	</select>



	<select id="getById" parameterType="Long" resultMap="UserRM">
		<![CDATA[
		SELECT
		    u.id
		    ,u.user_name
		    ,u.password
		    ,u.last_login_ip
		    ,u.last_login_time
		    ,u.created
		    ,u.modified
		    ,u.status
		    ,u.yn
		    ,u.real_name
		    ,u.serial_number
		    ,u.fixed_line_telephone
		    ,u.cellphone
		    ,u.email
		    ,u.valid_time_begin
		    ,u.valid_time_end
		FROM security_user u
		WHERE u.id=#{pk}
		and (u.yn is null or u.yn = 1)
		]]>
	</select>
	
	<select id="getByUserByIdIgoreDel" parameterType="Long" resultMap="UserRM">
		<![CDATA[
		SELECT
		    u.id
		    ,u.user_name
		    ,u.password
		    ,u.last_login_ip
		    ,u.last_login_time
		    ,u.created
		    ,u.modified
		    ,u.status
		    ,u.yn
		    ,u.real_name
		    ,u.serial_number
		    ,u.fixed_line_telephone
		    ,u.cellphone
		    ,u.email
		    ,u.valid_time_begin
		    ,u.valid_time_end
		FROM security_user u
		WHERE u.id=#{pk}
		]]>
	</select>
	
	<select id="getByUserName" parameterType="String" resultMap="UserRM">
		<![CDATA[
		SELECT
		    u.id
		    ,u.user_name
		    ,u.password
		    ,u.last_login_ip
		    ,u.last_login_time
		    ,u.created
		    ,u.modified
		    ,u.status
		    ,u.yn
		    ,u.real_name
		    ,u.serial_number
		    ,u.fixed_line_telephone
		    ,u.cellphone
		    ,u.email
		    ,u.valid_time_begin
		    ,u.valid_time_end
		FROM security_user u
		LEFT JOIN security_user_role ur on ur.user_id=u.id
		LEFT JOIN security_role r on r.id=ur.role_id
		WHERE u.user_name=#{username}
		and (u.yn is null or u.yn = 1)
		]]>
	</select>

    <select id="receptByUsername" parameterType="String" resultMap="UserRM">
        <![CDATA[
		SELECT
		    u.id
		    ,u.user_name
		    ,u.password
		    ,u.last_login_ip
		    ,u.last_login_time
		    ,u.created
		    ,u.modified
		    ,u.status
		    ,u.yn
		    ,u.real_name
		    ,u.serial_number
		    ,u.fixed_line_telephone
		    ,u.cellphone
		    ,u.email
		    ,u.valid_time_begin
		    ,u.valid_time_end
		FROM security_user u
		LEFT JOIN security_user_role ur on ur.user_id=u.id
		LEFT JOIN security_role r on r.id=ur.role_id
		WHERE u.user_name like concat(#{username},'%')
		and (u.yn is null or u.yn = 1)
		]]>
    </select>

	<insert id="save" parameterType="com.diligrp.manage.domain.User">
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            SELECT LAST_INSERT_ID();
        </selectKey>
		<![CDATA[
		INSERT INTO security_user(
                    user_name
                    ,password
                    ,last_login_ip
                    ,last_login_time
                    ,status
                    ,real_name
                    ,serial_number
                    ,fixed_line_telephone
                    ,cellphone
                    ,email
                    ,valid_time_begin
                    ,valid_time_end
		) VALUES(
                    #{userName}
                    ,#{password}
                    ,#{lastLoginIp}
                    ,#{lastLoginTime}
                    ,#{status}
                    ,#{realName}
                    ,#{serialNumber}
                    ,#{fixedLineTelephone}
                    ,#{cellphone}
                    ,#{email}
                    ,#{validTimeBegin}
                    ,#{validTimeEnd}
		)
		]]>
	</insert>

    <update id="update" parameterType="com.diligrp.manage.domain.User">
    <![CDATA[
            UPDATE security_user set
                        password=#{password}
                        ,last_login_ip=#{lastLoginIp}
                        ,last_login_time=#{lastLoginTime}
                        ,status=#{status}
                        ,real_name=#{realName}
                        ,serial_number=#{serialNumber}
                        ,fixed_line_telephone=#{fixedLineTelephone}
                        ,cellphone=#{cellphone}
                        ,email=#{email}
                        ,valid_time_begin=#{validTimeBegin}
                        ,valid_time_end=#{validTimeEnd}

            where 1=1
            and id = #{id}
            ]]>
    </update>

	<select id="countByCondition" parameterType="Query" resultType="Integer">
		<![CDATA[
		SELECT count(1) FROM security_user where 1=1
		]]>
        <if test="param != null">
            <if test="param.id != null and param.id != ''">
            and id = #{param.id}
            </if>
            <if test="param.userName != null and param.userName != ''">
            and user_name = #{param.userName}
            </if>
            <if test="param.password != null and param.password != ''">
            and password = #{param.password}
            </if>
            <if test="param.lastLoginIp != null and param.lastLoginIp != ''">
            and last_login_ip = #{param.lastLoginIp}
            </if>
            <if test="param.lastLoginTime != null and param.lastLoginTime != ''">
            and last_login_time = #{param.lastLoginTime}
            </if>
            <if test="param.created != null and param.created != ''">
            and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
            </if>
            <if test="param.modified != null and param.modified != ''">
            and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
            </if>
            <if test="param.status != null and param.status != ''">
            and status = #{param.status}
            </if>
            <![CDATA[
                    and (yn is null or yn = 1)
                    ]]>
            <if test="param.realName != null and param.realName != ''">
            and real_name = #{param.realName}
            </if>
            <if test="param.serialNumber != null and param.serialNumber != ''">
            and serial_number = #{param.serialNumber}
            </if>
            <if test="param.fixedLineTelephone != null and param.fixedLineTelephone != ''">
            and fixed_line_telephone = #{param.fixedLineTelephone}
            </if>
            <if test="param.cellphone != null and param.cellphone != ''">
            and cellphone = #{param.cellphone}
            </if>
            <if test="param.email != null and param.email != ''">
            and email = #{param.email}
            </if>
            <if test="param.validTimeBegin != null and param.validTimeBegin != ''">
            and valid_time_begin = #{param.validTimeBegin}
            </if>
            <if test="param.validTimeEnd != null and param.validTimeEnd != ''">
            and valid_time_end = #{param.validTimeEnd}
            </if>
        </if>
	</select>

	<select id="listByCondition" parameterType="Query" resultMap="UserRM">
		<![CDATA[
		SELECT
		    id
		    ,user_name
		    ,password
		    ,last_login_ip
		    ,last_login_time
		    ,created
		    ,modified
		    ,status
		    ,yn
		    ,real_name
		    ,serial_number
		    ,fixed_line_telephone
		    ,cellphone
		    ,email
		    ,valid_time_begin
		    ,valid_time_end
		FROM security_user where 1=1
		]]>
        <if test="param != null">
                <if test="param.id != null and param.id != ''">
                    and id = #{param.id}
                </if>
                <if test="param.userName != null and param.userName != ''">
                    and user_name = #{param.userName}
                </if>
                <if test="param.password != null and param.password != ''">
                    and password = #{param.password}
                </if>
                <if test="param.lastLoginIp != null and param.lastLoginIp != ''">
                    and last_login_ip = #{param.lastLoginIp}
                </if>
                <if test="param.lastLoginTime != null and param.lastLoginTime != ''">
                    and last_login_time = #{param.lastLoginTime}
                </if>
                <if test="param.created != null and param.created != ''">
                    and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
                </if>
                <if test="param.modified != null and param.modified != ''">
                    and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
                </if>
                <if test="param.status != null and param.status != ''">
                    and status = #{param.status}
                </if>
                  <![CDATA[
                    and (yn is null or yn = 1)
                    ]]>
				<if test="param.realName != null and param.realName != ''">
                    and real_name = #{param.realName}
                </if>
                <if test="param.serialNumber != null and param.serialNumber != ''">
                    and serial_number = #{param.serialNumber}
                </if>
                <if test="param.fixedLineTelephone != null and param.fixedLineTelephone != ''">
                    and fixed_line_telephone = #{param.fixedLineTelephone}
                </if>
                <if test="param.cellphone != null and param.cellphone != ''">
                    and cellphone = #{param.cellphone}
                </if>
                <if test="param.email != null and param.email != ''">
                    and email = #{param.email}
                </if>
                <if test="param.validTimeBegin != null and param.validTimeBegin != ''">
                    and valid_time_begin = #{param.validTimeBegin}
                </if>
                <if test="param.validTimeEnd != null and param.validTimeEnd != ''">
                    and valid_time_end = #{param.validTimeEnd}
                </if>
        </if>
        order by id desc
		<![CDATA[
		limit #{startRow},#{pageSize}
		]]>
	</select>


    <update id="deleteById" parameterType="Long">
    <![CDATA[
        update security_user set
        yn = 2
        where 1 = 1
        and id = #{id}
    ]]>
    </update>
    
    <delete id="deleteUserRoleByUserId" parameterType="Long">
    	 <![CDATA[
        delete from security_user_role
        where 
        user_id = #{pk}
    ]]>
    </delete>

</mapper>