workflow-engine-web/flowable-engine-java/UserMapper.xml

217 lines
8.6 KiB
XML

<?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.pwc.cn.crmsystem.mapper.UserMapper">
<!-- <select id="getUserByUserId" resultMap="CrmUserResult" parameterType="Long">-->
<select id="selectUserPassWordByUserId" resultType="String" parameterType="Long">
select password
from crm_user
where id = #{userId}
</select>
<select id="selectUserByUserName" resultType="com.pwc.cn.crmsystem.pojo.dto.UserDto" parameterType="String">
select id,username
from crm_user
where username = #{userName}
</select>
<resultMap id="CrmUserResult" type="com.pwc.cn.crmsystem.pojo.vo.UserVo">
<id column="id" property="userId"/>
<result column="username" property="userName"/>
<result column="email" property="email"/>
<result column="dept_type" property="deptType"/>
<result column="status" property="status"/>
<result column="phone" property="phone"/>
<result column="phone_type" property="phoneType"/>
<result column="position" property="position"/>
<result column="create_time" property="createTime"/>
<collection property="deptIds" column="id" select="selectDeptIds"/>
<collection property="roleIds" column="id" select="selectRoleIds"/>
</resultMap>
<select id="selectUserList" resultMap="CrmUserResult" parameterType="java.util.Map">
select
id,
username,
email,
dept_type,
status,
phone,
phone_type,
position,
create_time
from crm_user
<where>
<if test="params.userName!=null and params.userName!=''">
and username like concat('%/', #{params.userName}, '%') escape '/'
</if>
<if test="params.status!=null and params.status!=''">
and status = #{params.status}
</if>
<if test="params.deptId != -1">
and id in (select user_id from crm_user_dept where dept_id = #{params.deptId})
</if>
</where>
</select>
<select id="selectUserById" resultMap="CrmUserResult">
select id,
username,
email,
dept_type,
status,
phone,
phone_type,
position,
create_time
from crm_user
where id = #{userId}
</select>
<select id="selectUserListToDept" resultMap="CrmUserResult">
select
id,
username,
email,
dept_type,
status,
phone,
phone_type,
position,
create_time
from crm_user
where id in
<foreach collection="list" item="item" open="(" close=")" separator="," index="index">
#{item}
</foreach>
</select>
<select id="selectDeptIds" resultType="Long">
select dept_id
from crm_user_dept
where user_id = #{userId}
</select>
<select id="selectRoleIds" resultType="Long">
select role_id
from crm_user_role
where user_id = #{userId}
</select>
<select id="selectCountDeptUserByDeptId" resultType="java.lang.Integer">
select count(*)
from crm_user_dept cud
left join crm_user_role cur on cur.user_id = cud.user_id
where dept_id = #{deptId} and cur.role_id = 3
</select>
<select id="selectUserListToDeptId" resultType="com.pwc.cn.crmsystem.pojo.vo.UserVo">
select
cu.id as userId,
cu.username,
cu.email,
cu.dept_type,
cu.status,
cu.phone,
cu.phone_type,
cu.position,
cu.create_time
from crm_user cu
left join crm_user_dept cud on cu.id = cud.user_id
left join crm_user_role cur on cu.id = cur.user_id
where cud.dept_id = #{deptId}
and cur.role_id = 3
order by cu.create_time
</select>
<insert id="insertUser" parameterType="com.pwc.cn.crmsystem.pojo.CrmUser" useGeneratedKeys="true" keyProperty="id">
insert into crm_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="username != null and username !=''">username,</if>
<if test="email != null and email !=''">email,</if>
<if test="phone != null">phone,</if>
<if test="phoneType != null and phoneType !=''">phone_type,</if>
<if test="sex != null and sex !=''">sex,</if>
<if test="avatar != null and avatar !=''">avatar,</if>
<if test="password != null and password !=''">password,</if>
<if test="status != null and status !=''">status,</if>
<if test="deptType != null and deptType !=''">dept_type,</if>
<if test="position != null">position,</if>
<if test="delFlag != null and delFlag !=''">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null and remark !=''">remark</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="username != null and username !=''">#{username},</if>
<if test="email != null and email !=''">#{email},</if>
<if test="phone != null">#{phone},</if>
<if test="phoneType != null and phoneType !=''">#{phoneType},</if>
<if test="sex != null and sex !=''">#{sex},</if>
<if test="avatar != null and avatar !=''">#{avatar},</if>
<if test="password != null and password !=''">#{password},</if>
<if test="status != null and status !=''">#{status},</if>
<if test="deptType != null and deptType !=''">#{deptType},</if>
<if test="position != null">#{position},</if>
<if test="delFlag != null and delFlag !=''">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null and remark !=''">#{remark},</if>
</trim>
</insert>
<insert id="insertUserRole" parameterType="Long">
insert into crm_user_role (user_id, role_id) value (#{userId}, #{roleId})
</insert>
<insert id="insertUserRoles">
insert into crm_user_role (user_id, role_id) values
<foreach collection="list" separator="," item="item">
(#{item.userId},#{item.roleId})
</foreach>
</insert>
<insert id="insertUserDept">
insert into crm_user_dept (user_id, dept_id) values
<foreach collection="list" separator="," item="item">
(#{item.userId},#{item.deptId})
</foreach>
</insert>
<delete id="deleteUserRoleByUserId">
delete
from crm_user_role
where user_id = #{userId}
</delete>
<delete id="deleteUserDeptByUserId">
delete
from crm_user_dept
where user_id = #{userId}
</delete>
<update id="updateUserByUserId" parameterType="com.pwc.cn.crmsystem.pojo.CrmUser">
update crm_user
<set>
<if test="username != null and username !=''">username = #{username},</if>
<if test="email != null and email !=''">email = #{email},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="phoneType != null">phone_type = #{phoneType},</if>
<if test="sex != null and sex !=''">sex = #{sex},</if>
<if test="avatar != null and avatar !=''">avatar = #{avatar},</if>
<if test="password != null and password !=''">password = #{password},</if>
<if test="status != null and status !=''">status = #{status},</if>
<if test="deptType != null and deptType !=''">dept_type = #{deptType},</if>
<if test="position != null">position = #{position},</if>
<if test="delFlag != null and delFlag !=''">del_flag = #{delFlag},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="remark != null and remark !=''">remark = #{remark},</if>
update_time = sysdate()
</set>
where id = #{id}
</update>
<delete id="deleteUserByUserId">
delete from crm_user where id = #{userId}
<if test="deptType != null and deptType != ''">
and dept_type = #{deptType}
</if>
</delete>
</mapper>