123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?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.zoniot.ccrc.dao.UserMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.User">
- <result column="id" property="id" jdbcType="INTEGER"/>
- <result column="username" property="username" jdbcType="VARCHAR"/>
- <result column="password" property="password" jdbcType="VARCHAR"/>
- <result column="mobile_phone" property="mobilePhone" jdbcType="VARCHAR"/>
- <result column="name" property="name" jdbcType="VARCHAR"/>
- <result column="status" property="status" jdbcType="INTEGER"/>
- <result column="work_unit" property="workUnit" jdbcType="VARCHAR"/>
- <result column="city" property="city" jdbcType="VARCHAR"/>
- <result column="address" property="address" jdbcType="VARCHAR"/>
- <result column="wechat" property="wechat" jdbcType="VARCHAR"/>
- <result column="email" property="email" jdbcType="VARCHAR"/>
- <result column="is_super_admin" property="isSuperAdmin" jdbcType="INTEGER"/>
- <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
- <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
- <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
- <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
- <result column="openid" property="openid" jdbcType="VARCHAR"/>
- </resultMap>
- <!--auto generated Code-->
- <sql id="Base_Column_List">
- id,
- username,
- password,
- mobile_phone,
- name,
- status,
- work_unit,
- city,
- address,
- wechat,
- email,
- is_super_admin,
- create_date,
- create_by,
- update_date,
- update_by,
- openid,
- enable
- </sql>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="user.id">
- INSERT INTO sc_user
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="user.id!=null"> id,</if>
- <if test="user.username!=null"> username,</if>
- <if test="user.password!=null"> password,</if>
- <if test="user.mobilePhone!=null"> mobile_phone,</if>
- <if test="user.name!=null"> name,</if>
- <if test="user.status!=null"> status,</if>
- <if test="user.workUnit!=null"> work_unit,</if>
- <if test="user.city!=null"> city,</if>
- <if test="user.address!=null"> address,</if>
- <if test="user.wechat!=null"> wechat,</if>
- <if test="user.email!=null"> email,</if>
- <if test="user.isSuperAdmin!=null"> is_super_admin,</if>
- <if test="user.createDate!=null"> create_date,</if>
- <if test="user.createBy!=null"> create_by,</if>
- <if test="user.updateDate!=null"> update_date,</if>
- <if test="user.updateBy!=null"> update_by,</if>
- <if test="user.openid!=null"> openid,</if>
- <if test="user.enable!=null"> enable</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="user.id!=null"> #{user.id,jdbcType=INTEGER},</if>
- <if test="user.username!=null"> #{user.username,jdbcType=VARCHAR},</if>
- <if test="user.password!=null"> #{user.password,jdbcType=VARCHAR},</if>
- <if test="user.mobilePhone!=null"> #{user.mobilePhone,jdbcType=VARCHAR},</if>
- <if test="user.name!=null"> #{user.name,jdbcType=VARCHAR},</if>
- <if test="user.status!=null"> #{user.status,jdbcType=INTEGER},</if>
- <if test="user.workUnit!=null"> #{user.workUnit,jdbcType=VARCHAR},</if>
- <if test="user.city!=null"> #{user.city,jdbcType=VARCHAR},</if>
- <if test="user.address!=null"> #{user.address,jdbcType=VARCHAR},</if>
- <if test="user.wechat!=null"> #{user.wechat,jdbcType=VARCHAR},</if>
- <if test="user.email!=null"> #{user.email,jdbcType=VARCHAR},</if>
- <if test="user.isSuperAdmin!=null"> #{user.isSuperAdmin,jdbcType=INTEGER},</if>
- <if test="user.createDate!=null"> #{user.createDate,jdbcType=TIMESTAMP},</if>
- <if test="user.createBy!=null"> #{user.createBy,jdbcType=VARCHAR},</if>
- <if test="user.updateDate!=null"> #{user.updateDate,jdbcType=TIMESTAMP},</if>
- <if test="user.updateBy!=null"> #{user.updateBy,jdbcType=VARCHAR},</if>
- <if test="user.openid!=null"> #{user.openid,jdbcType=VARCHAR},</if>
- <if test="user.enable!=null"> #{user.enable,jdbcType=INTEGER},</if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <update id="update">
- UPDATE sc_user
- <set>
- <if test="user.username != null"> username = #{user.username,jdbcType=VARCHAR},</if>
- <if test="user.password != null"> password = #{user.password,jdbcType=VARCHAR},</if>
- <if test="user.mobilePhone != null"> mobile_phone = #{user.mobilePhone,jdbcType=VARCHAR},</if>
- <if test="user.name != null"> name = #{user.name,jdbcType=VARCHAR},</if>
- <if test="user.status != null"> status = #{user.status,jdbcType=INTEGER},</if>
- <if test="user.workUnit != null"> work_unit = #{user.workUnit,jdbcType=VARCHAR},</if>
- <if test="user.city != null"> city = #{user.city,jdbcType=VARCHAR},</if>
- <if test="user.address != null"> address = #{user.address,jdbcType=VARCHAR},</if>
- <if test="user.wechat != null"> wechat = #{user.wechat,jdbcType=VARCHAR},</if>
- <if test="user.email != null"> email = #{user.email,jdbcType=VARCHAR},</if>
- <if test="user.isSuperAdmin != null"> is_super_admin = #{user.isSuperAdmin,jdbcType=INTEGER},</if>
- <if test="user.createDate != null"> create_date = #{user.createDate,jdbcType=TIMESTAMP},</if>
- <if test="user.createBy != null"> create_by = #{user.createBy,jdbcType=VARCHAR},</if>
- <if test="user.updateDate != null"> update_date = #{user.updateDate,jdbcType=TIMESTAMP},</if>
- <if test="user.updateBy != null"> update_by = #{user.updateBy,jdbcType=VARCHAR},</if>
- <if test="user.openid != null"> openid = #{user.openid,jdbcType=VARCHAR},</if>
- <if test="user.enable != null"> enable = #{user.enable,jdbcType=INTEGER}</if>
- </set>
- WHERE id = #{user.id,jdbcType=INTEGER}
- </update>
- <resultMap id="lazyLoadRoles" type="com.zoniot.ccrc.entity.User" extends="BaseResultMap">
- <result column="id" property="id" jdbcType="INTEGER"/>
- <result column="username" property="username" jdbcType="VARCHAR"/>
- <result column="password" property="password" jdbcType="VARCHAR"/>
- <result column="mobile_phone" property="mobilePhone" jdbcType="VARCHAR"/>
- <result column="name" property="name" jdbcType="VARCHAR"/>
- <result column="status" property="status" jdbcType="INTEGER"/>
- <result column="work_unit" property="workUnit" jdbcType="VARCHAR"/>
- <result column="city" property="city" jdbcType="VARCHAR"/>
- <result column="address" property="address" jdbcType="VARCHAR"/>
- <result column="wechat" property="wechat" jdbcType="VARCHAR"/>
- <result column="email" property="email" jdbcType="VARCHAR"/>
- <result column="is_super_admin" property="isSuperAdmin" jdbcType="INTEGER"/>
- <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
- <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
- <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
- <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
- <result column="openid" property="openid" jdbcType="VARCHAR"/>
- <result column="enable" property="enable" jdbcType="INTEGER"/>
- </resultMap>
- <select id="findUserById" resultType="com.zoniot.ccrc.entity.User">
- SELECT <include refid="Base_Column_List"/> FROM sc_user WHERE id = #{id}
- </select>
- <select id="findUserList" resultType="com.zoniot.ccrc.dto.UserRoleDto">
- SELECT su.*,(SELECT GROUP_CONCAT(ss.name SEPARATOR '、') FROM sc_site_user ssu LEFT JOIN sc_site ss on(ss.id = ssu.site_id and ss.`status`= 1) WHERE ssu.user_id = su.id and ssu.`status` =1) as site_name FROM sc_user su
- WHERE 1 = 1 and su.status = 1 and su.is_super_admin = 0
- <if test="username != null and username != ''"> AND su.username LIKE concat('%',#{username},'%')</if>
- <if test="name != null and name != ''"> AND su.`name` LIKE concat('%',#{name},'%')</if>
- <if test="mobilePhone != null and mobilePhone != ''"> AND su.mobile_phone LIKE concat('%',#{mobilePhone},'%')</if>
- order by su.create_date desc
- </select>
- <select id="loadUserByUsername" resultMap="lazyLoadRoles">
- SELECT * FROM sc_user WHERE status = 1 and username = #{username}
- </select>
- <select id="findUserByMobile" resultMap="BaseResultMap">
- SELECT * FROM sc_user WHERE status != 0 and mobile_phone = #{mobile}
- </select>
- <select id="getRolesByUserId" resultType="com.zoniot.ccrc.entity.Role">
- SELECT r.* FROM sc_user_role sur,sc_role r WHERE sur.rid=r.id AND sur.uid=#{id}
- </select>
- <select id="findUserByUsername" resultType="com.zoniot.ccrc.entity.User">
- SELECT * FROM sc_user WHERE status = 1 and username = #{username}
- </select>
- <update id="batchDelectUser" >
- update sc_user set status = 0,update_date=NOW(),update_by=#{updateBy}
- where
- <if test="userIds != null">
- id in <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- </update>
- <select id="findBySiteId" resultType="com.zoniot.ccrc.dto.UserRoleDto">
- SELECT
- su.id,
- su.username,
- su.password,
- su.mobile_phone,
- su.name,
- su.status,
- su.work_unit,
- su.city,
- su.address,
- su.wechat,
- su.email,
- su.is_super_admin,
- su.create_date,
- su.create_by,
- su.update_date,
- su.update_by,
- su.openid,
- su.enable,
- sr.id as role_id,
- sr.name as role_name,
- ssu.organ_id,
- so.name organName,
- ssu.type
- from sc_site_user ssu
- LEFT JOIN sc_user su on su.id = ssu.user_id
- LEFT JOIN sc_user_role sur on sur.uid = su.id and sur.status = 1
- LEFT JOIN sc_role sr on sr.id = sur.rid and sr.status = 1
- left join sc_organization so on ssu.organ_id =so.id
- WHERE ssu.status=1 and ssu.site_id = #{siteId} and sr.site_id = #{siteId}
- <if test="username != null and username != ''"> AND su.username LIKE concat('%',#{username},'%')</if>
- <if test="name != null and name != ''"> AND su.`name` LIKE concat('%',#{name},'%')</if>
- <if test="mobilePhone != null and mobilePhone != ''"> AND su.mobile_phone LIKE concat('%',#{mobilePhone},'%')</if>
- <if test="roleId != null"> and sr.id = #{roleId} </if>
- order by su.type asc,su.create_date desc
- </select>
- <select id="findUserByOrgsIds" resultType="com.zoniot.ccrc.entity.User">
- select
- id,
- username
- from sc_user where status = 1
- <if test="orgIds != null">
- and organ_id in
- <foreach collection="orgIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- </select>
- <select id="findUserByUserIds" resultType="com.zoniot.ccrc.entity.User">
- select
- id,
- username
- from sc_user where status = 1
- <if test="userIds != null">
- and id in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- </select>
- <update id="deleteByUserId">
- update sc_site_user set status = 0,update_date=NOW(),update_by=#{updateBy} where status=1 and user_id = #{userId}
- </update>
- <update id="deleteSiteUser">
- update sc_site_user set status = 0,update_date=NOW() where status=1 and user_id = #{userId} and site_id = #{siteId}
- </update>
- <update id="batchDeleteByUserIds">
- update sc_site_user set status = 0,update_date=NOW(),update_by=#{updateBy}
- where status=1
- <if test="userIds != null">
- and user_id in <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- </update>
- <select id="findUserByMobilePhoneUnique" resultType="int">
- select count(1) from sc_user where status = 1 and mobile_phone = #{mobilePhone}
- <if test="id != null"> and id != #{id}</if>
- </select>
- <select id="findUserByMobilePhoneSiteUnique" resultType="int">
- select count(1) from sc_user u
- LEFT JOIN sc_site_user su on(su.user_id = u.id)
- where u.status = 1 and su.status = 1 and su.site_id = #{siteId} and mobile_phone = #{mobilePhone}
- <if test="id != null"> and u.id != #{id}</if>
- </select>
- <select id="findUserByOpenid" resultMap="BaseResultMap">
- select <include refid="Base_Column_List"/> from sc_user where status = 1 and openid = #{openid}
- </select>
- <select id="countOrganId" resultType="java.lang.Integer">
- select count(1) from sc_site_user where status = 1 and organ_id = #{organId}
- </select>
- <select id="getAllUser" resultType="com.zoniot.ccrc.dto.UserTypeDto">
- SELECT su.id,su.username,su.name,su.is_super_admin,ssu.site_id,ssu.is_admin,su.type FROM sc_user su
- LEFT JOIN sc_site_user ssu on(ssu.user_id = su.id and ssu.`status`=1)
- WHERE su.`status`=1 ORDER BY id ASC
- </select>
- <select id="findUserByName" resultType="com.zoniot.ccrc.entity.User">
- select scuser.id,scuser.username,scuser.name
- from sc_site_user scsuser
- inner join sc_user scuser on scsuser.user_id= scuser.id
- where scsuser.site_id=#{sitId} and scuser.name=#{name} limit 1
- </select>
- <select id="findUserAmountById" resultType="com.zoniot.ccrc.dto.ClientUserDto">
- select d.id, d.customer_phone mobile_phone, d.customer_name as username,d.customer_no accountnumber
- ,e.loc_desc address
- from sc_grid_management d join sc_device e on d.device_id=e.id
- where d.id = #{id}
- </select>
- <select id="selectUserByPhone" resultType="java.lang.Integer">
- select id from sc_user where mobile_phone=#{phoneNumber} and status=1
- </select>
- <update id="updateOpenId">
- update sc_user set openid=#{openid} where id=#{id}
- </update>
- <update id="resetDefault">
- update sc_grid_management a,sc_user b set a.is_default = 0
- where b.status = 1 and b.openid = #{openid} and a.user_id=b.id
- </update>
- <select id="getDefaultNumer" resultType="string">
- select customer_no from sc_grid_management where id=#{id}
- </select>
- <select id="findClientUserByOpenid" resultType="com.zoniot.ccrc.entity.ClientUser">
- select DISTINCT
- e.id, e.customer_phone mobile_phone, e.customer_name as username,
- e.customer_no accountnumber,c.loc_desc address, a.openid,
- e.is_default,
- a.`status`, a.create_by, a.update_by,e.label
- from sc_user a
- join sc_grid_management e on a.id=e.user_id
- join sc_device c on c.id=e.device_id
- where a.status = 1 and a.openid = #{openid}
- <if test="type !=null">
- and e.is_default=1
- </if>
- <if test="type ==null">
- order by is_default desc, e.customer_no desc
- </if>
- </select>
- <select id="getUser" resultType="java.lang.Integer">
- select id from sc_user where openid=#{openid} and status=1
- </select>
- <update id="setDefault">
- update sc_grid_management set is_default = 1 where id = #{id}
- </update>
- </mapper>
|