UserMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.zoniot.ccrc.dao.UserMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.User">
  6. <result column="id" property="id" jdbcType="INTEGER"/>
  7. <result column="username" property="username" jdbcType="VARCHAR"/>
  8. <result column="password" property="password" jdbcType="VARCHAR"/>
  9. <result column="mobile_phone" property="mobilePhone" jdbcType="VARCHAR"/>
  10. <result column="name" property="name" jdbcType="VARCHAR"/>
  11. <result column="status" property="status" jdbcType="INTEGER"/>
  12. <result column="work_unit" property="workUnit" jdbcType="VARCHAR"/>
  13. <result column="city" property="city" jdbcType="VARCHAR"/>
  14. <result column="address" property="address" jdbcType="VARCHAR"/>
  15. <result column="wechat" property="wechat" jdbcType="VARCHAR"/>
  16. <result column="email" property="email" jdbcType="VARCHAR"/>
  17. <result column="is_super_admin" property="isSuperAdmin" jdbcType="INTEGER"/>
  18. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  19. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  20. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
  21. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  22. <result column="openid" property="openid" jdbcType="VARCHAR"/>
  23. </resultMap>
  24. <!--auto generated Code-->
  25. <sql id="Base_Column_List">
  26. id,
  27. username,
  28. password,
  29. mobile_phone,
  30. name,
  31. status,
  32. work_unit,
  33. city,
  34. address,
  35. wechat,
  36. email,
  37. is_super_admin,
  38. create_date,
  39. create_by,
  40. update_date,
  41. update_by,
  42. openid,
  43. enable
  44. </sql>
  45. <!--auto generated Code-->
  46. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="user.id">
  47. INSERT INTO sc_user
  48. <trim prefix="(" suffix=")" suffixOverrides=",">
  49. <if test="user.id!=null"> id,</if>
  50. <if test="user.username!=null"> username,</if>
  51. <if test="user.password!=null"> password,</if>
  52. <if test="user.mobilePhone!=null"> mobile_phone,</if>
  53. <if test="user.name!=null"> name,</if>
  54. <if test="user.status!=null"> status,</if>
  55. <if test="user.workUnit!=null"> work_unit,</if>
  56. <if test="user.city!=null"> city,</if>
  57. <if test="user.address!=null"> address,</if>
  58. <if test="user.wechat!=null"> wechat,</if>
  59. <if test="user.email!=null"> email,</if>
  60. <if test="user.isSuperAdmin!=null"> is_super_admin,</if>
  61. <if test="user.createDate!=null"> create_date,</if>
  62. <if test="user.createBy!=null"> create_by,</if>
  63. <if test="user.updateDate!=null"> update_date,</if>
  64. <if test="user.updateBy!=null"> update_by,</if>
  65. <if test="user.openid!=null"> openid,</if>
  66. <if test="user.enable!=null"> enable</if>
  67. </trim>
  68. VALUES
  69. <trim prefix="(" suffix=")" suffixOverrides=",">
  70. <if test="user.id!=null"> #{user.id,jdbcType=INTEGER},</if>
  71. <if test="user.username!=null"> #{user.username,jdbcType=VARCHAR},</if>
  72. <if test="user.password!=null"> #{user.password,jdbcType=VARCHAR},</if>
  73. <if test="user.mobilePhone!=null"> #{user.mobilePhone,jdbcType=VARCHAR},</if>
  74. <if test="user.name!=null"> #{user.name,jdbcType=VARCHAR},</if>
  75. <if test="user.status!=null"> #{user.status,jdbcType=INTEGER},</if>
  76. <if test="user.workUnit!=null"> #{user.workUnit,jdbcType=VARCHAR},</if>
  77. <if test="user.city!=null"> #{user.city,jdbcType=VARCHAR},</if>
  78. <if test="user.address!=null"> #{user.address,jdbcType=VARCHAR},</if>
  79. <if test="user.wechat!=null"> #{user.wechat,jdbcType=VARCHAR},</if>
  80. <if test="user.email!=null"> #{user.email,jdbcType=VARCHAR},</if>
  81. <if test="user.isSuperAdmin!=null"> #{user.isSuperAdmin,jdbcType=INTEGER},</if>
  82. <if test="user.createDate!=null"> #{user.createDate,jdbcType=TIMESTAMP},</if>
  83. <if test="user.createBy!=null"> #{user.createBy,jdbcType=VARCHAR},</if>
  84. <if test="user.updateDate!=null"> #{user.updateDate,jdbcType=TIMESTAMP},</if>
  85. <if test="user.updateBy!=null"> #{user.updateBy,jdbcType=VARCHAR},</if>
  86. <if test="user.openid!=null"> #{user.openid,jdbcType=VARCHAR},</if>
  87. <if test="user.enable!=null"> #{user.enable,jdbcType=INTEGER},</if>
  88. </trim>
  89. </insert>
  90. <!--auto generated Code-->
  91. <update id="update">
  92. UPDATE sc_user
  93. <set>
  94. <if test="user.username != null"> username = #{user.username,jdbcType=VARCHAR},</if>
  95. <if test="user.password != null"> password = #{user.password,jdbcType=VARCHAR},</if>
  96. <if test="user.mobilePhone != null"> mobile_phone = #{user.mobilePhone,jdbcType=VARCHAR},</if>
  97. <if test="user.name != null"> name = #{user.name,jdbcType=VARCHAR},</if>
  98. <if test="user.status != null"> status = #{user.status,jdbcType=INTEGER},</if>
  99. <if test="user.workUnit != null"> work_unit = #{user.workUnit,jdbcType=VARCHAR},</if>
  100. <if test="user.city != null"> city = #{user.city,jdbcType=VARCHAR},</if>
  101. <if test="user.address != null"> address = #{user.address,jdbcType=VARCHAR},</if>
  102. <if test="user.wechat != null"> wechat = #{user.wechat,jdbcType=VARCHAR},</if>
  103. <if test="user.email != null"> email = #{user.email,jdbcType=VARCHAR},</if>
  104. <if test="user.isSuperAdmin != null"> is_super_admin = #{user.isSuperAdmin,jdbcType=INTEGER},</if>
  105. <if test="user.createDate != null"> create_date = #{user.createDate,jdbcType=TIMESTAMP},</if>
  106. <if test="user.createBy != null"> create_by = #{user.createBy,jdbcType=VARCHAR},</if>
  107. <if test="user.updateDate != null"> update_date = #{user.updateDate,jdbcType=TIMESTAMP},</if>
  108. <if test="user.updateBy != null"> update_by = #{user.updateBy,jdbcType=VARCHAR},</if>
  109. <if test="user.openid != null"> openid = #{user.openid,jdbcType=VARCHAR},</if>
  110. <if test="user.enable != null"> enable = #{user.enable,jdbcType=INTEGER}</if>
  111. </set>
  112. WHERE id = #{user.id,jdbcType=INTEGER}
  113. </update>
  114. <resultMap id="lazyLoadRoles" type="com.zoniot.ccrc.entity.User" extends="BaseResultMap">
  115. <result column="id" property="id" jdbcType="INTEGER"/>
  116. <result column="username" property="username" jdbcType="VARCHAR"/>
  117. <result column="password" property="password" jdbcType="VARCHAR"/>
  118. <result column="mobile_phone" property="mobilePhone" jdbcType="VARCHAR"/>
  119. <result column="name" property="name" jdbcType="VARCHAR"/>
  120. <result column="status" property="status" jdbcType="INTEGER"/>
  121. <result column="work_unit" property="workUnit" jdbcType="VARCHAR"/>
  122. <result column="city" property="city" jdbcType="VARCHAR"/>
  123. <result column="address" property="address" jdbcType="VARCHAR"/>
  124. <result column="wechat" property="wechat" jdbcType="VARCHAR"/>
  125. <result column="email" property="email" jdbcType="VARCHAR"/>
  126. <result column="is_super_admin" property="isSuperAdmin" jdbcType="INTEGER"/>
  127. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  128. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  129. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
  130. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  131. <result column="openid" property="openid" jdbcType="VARCHAR"/>
  132. <result column="enable" property="enable" jdbcType="INTEGER"/>
  133. </resultMap>
  134. <select id="findUserById" resultType="com.zoniot.ccrc.entity.User">
  135. SELECT <include refid="Base_Column_List"/> FROM sc_user WHERE id = #{id}
  136. </select>
  137. <select id="findUserList" resultType="com.zoniot.ccrc.dto.UserRoleDto">
  138. 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
  139. WHERE 1 = 1 and su.status = 1 and su.is_super_admin = 0
  140. <if test="username != null and username != ''"> AND su.username LIKE concat('%',#{username},'%')</if>
  141. <if test="name != null and name != ''"> AND su.`name` LIKE concat('%',#{name},'%')</if>
  142. <if test="mobilePhone != null and mobilePhone != ''"> AND su.mobile_phone LIKE concat('%',#{mobilePhone},'%')</if>
  143. order by su.create_date desc
  144. </select>
  145. <select id="loadUserByUsername" resultMap="lazyLoadRoles">
  146. SELECT * FROM sc_user WHERE status = 1 and username = #{username}
  147. </select>
  148. <select id="findUserByMobile" resultMap="BaseResultMap">
  149. SELECT * FROM sc_user WHERE status != 0 and mobile_phone = #{mobile}
  150. </select>
  151. <select id="getRolesByUserId" resultType="com.zoniot.ccrc.entity.Role">
  152. SELECT r.* FROM sc_user_role sur,sc_role r WHERE sur.rid=r.id AND sur.uid=#{id}
  153. </select>
  154. <select id="findUserByUsername" resultType="com.zoniot.ccrc.entity.User">
  155. SELECT * FROM sc_user WHERE status = 1 and username = #{username}
  156. </select>
  157. <update id="batchDelectUser" >
  158. update sc_user set status = 0,update_date=NOW(),update_by=#{updateBy}
  159. where
  160. <if test="userIds != null">
  161. id in <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  162. </if>
  163. </update>
  164. <select id="findBySiteId" resultType="com.zoniot.ccrc.dto.UserRoleDto">
  165. SELECT
  166. su.id,
  167. su.username,
  168. su.password,
  169. su.mobile_phone,
  170. su.name,
  171. su.status,
  172. su.work_unit,
  173. su.city,
  174. su.address,
  175. su.wechat,
  176. su.email,
  177. su.is_super_admin,
  178. su.create_date,
  179. su.create_by,
  180. su.update_date,
  181. su.update_by,
  182. su.openid,
  183. su.enable,
  184. sr.id as role_id,
  185. sr.name as role_name,
  186. ssu.organ_id,
  187. so.name organName,
  188. ssu.type
  189. from sc_site_user ssu
  190. LEFT JOIN sc_user su on su.id = ssu.user_id
  191. LEFT JOIN sc_user_role sur on sur.uid = su.id and sur.status = 1
  192. LEFT JOIN sc_role sr on sr.id = sur.rid and sr.status = 1
  193. left join sc_organization so on ssu.organ_id =so.id
  194. WHERE ssu.status=1 and ssu.site_id = #{siteId} and sr.site_id = #{siteId}
  195. <if test="username != null and username != ''"> AND su.username LIKE concat('%',#{username},'%')</if>
  196. <if test="name != null and name != ''"> AND su.`name` LIKE concat('%',#{name},'%')</if>
  197. <if test="mobilePhone != null and mobilePhone != ''"> AND su.mobile_phone LIKE concat('%',#{mobilePhone},'%')</if>
  198. <if test="roleId != null"> and sr.id = #{roleId} </if>
  199. order by su.type asc,su.create_date desc
  200. </select>
  201. <select id="findUserByOrgsIds" resultType="com.zoniot.ccrc.entity.User">
  202. select
  203. id,
  204. username
  205. from sc_user where status = 1
  206. <if test="orgIds != null">
  207. and organ_id in
  208. <foreach collection="orgIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  209. </if>
  210. </select>
  211. <select id="findUserByUserIds" resultType="com.zoniot.ccrc.entity.User">
  212. select
  213. id,
  214. username
  215. from sc_user where status = 1
  216. <if test="userIds != null">
  217. and id in
  218. <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  219. </if>
  220. </select>
  221. <update id="deleteByUserId">
  222. update sc_site_user set status = 0,update_date=NOW(),update_by=#{updateBy} where status=1 and user_id = #{userId}
  223. </update>
  224. <update id="deleteSiteUser">
  225. update sc_site_user set status = 0,update_date=NOW() where status=1 and user_id = #{userId} and site_id = #{siteId}
  226. </update>
  227. <update id="batchDeleteByUserIds">
  228. update sc_site_user set status = 0,update_date=NOW(),update_by=#{updateBy}
  229. where status=1
  230. <if test="userIds != null">
  231. and user_id in <foreach collection="userIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  232. </if>
  233. </update>
  234. <select id="findUserByMobilePhoneUnique" resultType="int">
  235. select count(1) from sc_user where status = 1 and mobile_phone = #{mobilePhone}
  236. <if test="id != null"> and id != #{id}</if>
  237. </select>
  238. <select id="findUserByMobilePhoneSiteUnique" resultType="int">
  239. select count(1) from sc_user u
  240. LEFT JOIN sc_site_user su on(su.user_id = u.id)
  241. where u.status = 1 and su.status = 1 and su.site_id = #{siteId} and mobile_phone = #{mobilePhone}
  242. <if test="id != null"> and u.id != #{id}</if>
  243. </select>
  244. <select id="findUserByOpenid" resultMap="BaseResultMap">
  245. select <include refid="Base_Column_List"/> from sc_user where status = 1 and openid = #{openid}
  246. </select>
  247. <select id="countOrganId" resultType="java.lang.Integer">
  248. select count(1) from sc_site_user where status = 1 and organ_id = #{organId}
  249. </select>
  250. <select id="getAllUser" resultType="com.zoniot.ccrc.dto.UserTypeDto">
  251. SELECT su.id,su.username,su.name,su.is_super_admin,ssu.site_id,ssu.is_admin,su.type FROM sc_user su
  252. LEFT JOIN sc_site_user ssu on(ssu.user_id = su.id and ssu.`status`=1)
  253. WHERE su.`status`=1 ORDER BY id ASC
  254. </select>
  255. <select id="findUserByName" resultType="com.zoniot.ccrc.entity.User">
  256. select scuser.id,scuser.username,scuser.name
  257. from sc_site_user scsuser
  258. inner join sc_user scuser on scsuser.user_id= scuser.id
  259. where scsuser.site_id=#{sitId} and scuser.name=#{name} limit 1
  260. </select>
  261. <select id="findUserAmountById" resultType="com.zoniot.ccrc.dto.ClientUserDto">
  262. select d.id, d.customer_phone mobile_phone, d.customer_name as username,d.customer_no accountnumber
  263. ,e.loc_desc address
  264. from sc_grid_management d join sc_device e on d.device_id=e.id
  265. where d.id = #{id}
  266. </select>
  267. <select id="selectUserByPhone" resultType="java.lang.Integer">
  268. select id from sc_user where mobile_phone=#{phoneNumber} and status=1
  269. </select>
  270. <update id="updateOpenId">
  271. update sc_user set openid=#{openid} where id=#{id}
  272. </update>
  273. <update id="resetDefault">
  274. update sc_grid_management a,sc_user b set a.is_default = 0
  275. where b.status = 1 and b.openid = #{openid} and a.user_id=b.id
  276. </update>
  277. <select id="getDefaultNumer" resultType="string">
  278. select customer_no from sc_grid_management where id=#{id}
  279. </select>
  280. <select id="findClientUserByOpenid" resultType="com.zoniot.ccrc.entity.ClientUser">
  281. select DISTINCT
  282. e.id, e.customer_phone mobile_phone, e.customer_name as username,
  283. e.customer_no accountnumber,c.loc_desc address, a.openid,
  284. e.is_default,
  285. a.`status`, a.create_by, a.update_by,e.label
  286. from sc_user a
  287. join sc_grid_management e on a.id=e.user_id
  288. join sc_device c on c.id=e.device_id
  289. where a.status = 1 and a.openid = #{openid}
  290. <if test="type !=null">
  291. and e.is_default=1
  292. </if>
  293. <if test="type ==null">
  294. order by is_default desc, e.customer_no desc
  295. </if>
  296. </select>
  297. <select id="getUser" resultType="java.lang.Integer">
  298. select id from sc_user where openid=#{openid} and status=1
  299. </select>
  300. <update id="setDefault">
  301. update sc_grid_management set is_default = 1 where id = #{id}
  302. </update>
  303. </mapper>