KwsUserDao.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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.sckw.system.dao.KwsUserDao">
  4. <resultMap id="BaseResultMap" type="com.sckw.system.model.KwsUser">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="system_type" jdbcType="INTEGER" property="systemType" />
  7. <result column="account" jdbcType="VARCHAR" property="account" />
  8. <result column="password" jdbcType="VARCHAR" property="password" />
  9. <result column="salt" jdbcType="VARCHAR" property="salt" />
  10. <result column="name" jdbcType="VARCHAR" property="name" />
  11. <result column="phone" jdbcType="VARCHAR" property="phone" />
  12. <result column="photo" jdbcType="VARCHAR" property="photo" />
  13. <result column="email" jdbcType="VARCHAR" property="email" />
  14. <result column="client_id" jdbcType="VARCHAR" property="clientId" />
  15. <result column="is_main" jdbcType="INTEGER" property="isMain" />
  16. <result column="remark" jdbcType="VARCHAR" property="remark" />
  17. <result column="status" jdbcType="INTEGER" property="status" />
  18. <result column="create_by" jdbcType="BIGINT" property="createBy" />
  19. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  20. <result column="update_by" jdbcType="BIGINT" property="updateBy" />
  21. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  22. <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
  23. </resultMap>
  24. <sql id="Base_Column_List">
  25. id, system_type, account, password, name, phone, photo, email, client_id, is_main,
  26. remark, status, create_by, create_time, update_by, update_time, del_flag, salt
  27. </sql>
  28. <select id="selectByKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  29. select
  30. <include refid="Base_Column_List" />
  31. from kws_user
  32. where id = #{id,jdbcType=BIGINT}
  33. </select>
  34. <insert id="insert" parameterType="com.sckw.system.model.KwsUser">
  35. insert into kws_user
  36. <trim prefix="(" suffix=")" suffixOverrides=",">
  37. <if test="id != null">
  38. id,
  39. </if>
  40. <if test="systemType != null">
  41. system_type,
  42. </if>
  43. <if test="account != null">
  44. account,
  45. </if>
  46. <if test="password != null">
  47. password,
  48. </if>
  49. <if test="name != null">
  50. name,
  51. </if>
  52. <if test="phone != null">
  53. phone,
  54. </if>
  55. <if test="photo != null">
  56. photo,
  57. </if>
  58. <if test="email != null">
  59. email,
  60. </if>
  61. <if test="clientId != null">
  62. client_id,
  63. </if>
  64. <if test="isMain != null">
  65. is_main,
  66. </if>
  67. <if test="remark != null">
  68. remark,
  69. </if>
  70. <if test="status != null">
  71. status,
  72. </if>
  73. <if test="createBy != null">
  74. create_by,
  75. </if>
  76. <if test="createTime != null">
  77. create_time,
  78. </if>
  79. <if test="updateBy != null">
  80. update_by,
  81. </if>
  82. <if test="updateTime != null">
  83. update_time,
  84. </if>
  85. <if test="delFlag != null">
  86. del_flag,
  87. </if>
  88. <if test="salt != null">
  89. salt,
  90. </if>
  91. </trim>
  92. <trim prefix="values (" suffix=")" suffixOverrides=",">
  93. <if test="id != null">
  94. #{id,jdbcType=BIGINT},
  95. </if>
  96. <if test="systemType != null">
  97. #{systemType,jdbcType=INTEGER},
  98. </if>
  99. <if test="account != null">
  100. #{account,jdbcType=VARCHAR},
  101. </if>
  102. <if test="password != null">
  103. #{password,jdbcType=VARCHAR},
  104. </if>
  105. <if test="name != null">
  106. #{name,jdbcType=VARCHAR},
  107. </if>
  108. <if test="phone != null">
  109. #{phone,jdbcType=VARCHAR},
  110. </if>
  111. <if test="photo != null">
  112. #{photo,jdbcType=VARCHAR},
  113. </if>
  114. <if test="email != null">
  115. #{email,jdbcType=VARCHAR},
  116. </if>
  117. <if test="clientId != null">
  118. #{clientId,jdbcType=VARCHAR},
  119. </if>
  120. <if test="isMain != null">
  121. #{isMain,jdbcType=INTEGER},
  122. </if>
  123. <if test="remark != null">
  124. #{remark,jdbcType=VARCHAR},
  125. </if>
  126. <if test="status != null">
  127. #{status,jdbcType=INTEGER},
  128. </if>
  129. <if test="createBy != null">
  130. #{createBy,jdbcType=BIGINT},
  131. </if>
  132. <if test="createTime != null">
  133. #{createTime,jdbcType=TIMESTAMP},
  134. </if>
  135. <if test="updateBy != null">
  136. #{updateBy,jdbcType=BIGINT},
  137. </if>
  138. <if test="updateTime != null">
  139. #{updateTime,jdbcType=TIMESTAMP},
  140. </if>
  141. <if test="delFlag != null">
  142. #{delFlag,jdbcType=INTEGER},
  143. </if>
  144. <if test="salt != null">
  145. #{salt,jdbcType=VARCHAR},
  146. </if>
  147. </trim>
  148. </insert>
  149. <update id="update" parameterType="com.sckw.system.model.KwsUser">
  150. update kws_user
  151. <set>
  152. <if test="systemType != null">
  153. system_type = #{systemType,jdbcType=INTEGER},
  154. </if>
  155. <if test="account != null">
  156. account = #{account,jdbcType=VARCHAR},
  157. </if>
  158. <if test="password != null">
  159. password = #{password,jdbcType=VARCHAR},
  160. </if>
  161. <if test="name != null">
  162. name = #{name,jdbcType=VARCHAR},
  163. </if>
  164. <if test="phone != null">
  165. phone = #{phone,jdbcType=VARCHAR},
  166. </if>
  167. <if test="photo != null">
  168. photo = #{photo,jdbcType=VARCHAR},
  169. </if>
  170. <if test="email != null">
  171. email = #{email,jdbcType=VARCHAR},
  172. </if>
  173. <if test="clientId != null">
  174. client_id = #{clientId,jdbcType=VARCHAR},
  175. </if>
  176. <if test="isMain != null">
  177. is_main = #{isMain,jdbcType=INTEGER},
  178. </if>
  179. <if test="remark != null">
  180. remark = #{remark,jdbcType=VARCHAR},
  181. </if>
  182. <if test="status != null">
  183. status = #{status,jdbcType=INTEGER},
  184. </if>
  185. <if test="createBy != null">
  186. create_by = #{createBy,jdbcType=BIGINT},
  187. </if>
  188. <if test="createTime != null">
  189. create_time = #{createTime,jdbcType=TIMESTAMP},
  190. </if>
  191. <if test="updateBy != null">
  192. update_by = #{updateBy,jdbcType=BIGINT},
  193. </if>
  194. <if test="updateTime != null">
  195. update_time = #{updateTime,jdbcType=TIMESTAMP},
  196. </if>
  197. <if test="delFlag != null">
  198. del_flag = #{delFlag,jdbcType=INTEGER},
  199. </if>
  200. <if test="salt != null">
  201. salt = #{salt,jdbcType=VARCHAR},
  202. </if>
  203. </set>
  204. where id = #{id,jdbcType=BIGINT}
  205. </update>
  206. <select id="findPage" resultType="com.sckw.system.model.vo.res.KwsUserResVo" parameterType="java.util.Map" >
  207. select distinct
  208. su.id, su.system_type systemType, su.account, su.password, su.name,
  209. su.phone, su.photo, su.email, su.is_main isMain, su.remark, su.status, su.salt,
  210. c.id deptId,c.name deptName,e.id roleId, e.name roleName,
  211. su.create_time,
  212. su2.`name` createByName,
  213. su.update_time
  214. from kws_user su
  215. left join kws_user_dept b on su.id = b.user_id
  216. left join kws_dept c on b.dept_id = c.id
  217. left join kws_user_role d on su.id = d.user_id
  218. left join kws_role e on e.id = d.role_id
  219. left join kws_user su2 on su.create_by = su2.id
  220. where su.del_flag = 0
  221. and b.del_flag = 0
  222. and d.del_flag = 0
  223. <if test="systemType != null and systemType != ''">
  224. and su.system_type = #{system_type, jdbcType=VARCHAR}
  225. </if>
  226. <if test="account != null and account != ''">
  227. and su.account = #{account, jdbcType=VARCHAR}
  228. </if>
  229. <if test="name != null and name != ''">
  230. and su.name = #{name, jdbcType=VARCHAR}
  231. </if>
  232. <if test="phone != null and phone != ''">
  233. and su.phone = #{phone, jdbcType=VARCHAR}
  234. </if>
  235. <if test="email != null and email != ''">
  236. and su.email = #{email, jdbcType=VARCHAR}
  237. </if>
  238. <if test="deptId != null and deptId != ''">
  239. and c.id = #{deptId, jdbcType=VARCHAR}
  240. </if>
  241. <if test="roleId != null and roleId != ''">
  242. and e.id = #{roleId}
  243. </if>
  244. <if test="keywords != null and keywords != ''">
  245. and (su.name like concat('%', #{keywords}, '%') or su.account like concat('%', #{keywords}, '%') or su2.name like concat('%', #{keywords}, '%'))
  246. </if>
  247. <if test="entId != null and entId != ''">
  248. and c.ent_id = #{entId}
  249. </if>
  250. <if test="startTime != null and startTime != ''">
  251. and su.create_time >= #{startTime}
  252. </if>
  253. <if test="endTime != null and endTime != ''">
  254. and su.create_time &lt;= #{endTime}
  255. </if>
  256. ORDER BY su.create_time desc
  257. </select>
  258. <select id="findList" resultType="com.sckw.system.model.vo.res.KwsUserResVo" parameterType="com.sckw.system.model.KwsUser" >
  259. select
  260. su.id, su.system_type systemType, su.account, su.password, su.name,
  261. su.phone, su.photo, su.email, su.is_main isMain, su.remark, su.status, su.salt,
  262. c.id deptId,c.name deptName,e.id roleId, e.name roleName,
  263. u1.name createByName, su.create_time createTime, su.update_time updateTime
  264. from kws_user su
  265. left join kws_user_dept b on su.id = b.user_id
  266. left join kws_dept c on b.dept_id = c.id
  267. left join kws_user_role d on su.id = d.user_id
  268. left join kws_role e on e.id = d.role_id
  269. left join kws_user u1 on su.create_by = u1.id
  270. where su.del_flag = 0
  271. <if test="systemType != null and systemType != ''">
  272. and su.system_type = #{systemType, jdbcType=INTEGER}
  273. </if>
  274. <if test="account != null and account != ''">
  275. and su.account = #{account, jdbcType=VARCHAR}
  276. </if>
  277. <if test="name != null and name != ''">
  278. and su.name = #{name, jdbcType=VARCHAR}
  279. </if>
  280. <if test="phone != null and phone != ''">
  281. and su.phone = #{phone, jdbcType=VARCHAR}
  282. </if>
  283. ORDER BY su.create_time desc
  284. </select>
  285. <select id="queryUserDeptByUserId" resultType="com.sckw.system.model.KwsUserDept">
  286. select a.* from kws_user_dept a where a.user_id = #{userId} and a.del_flag = 0
  287. </select>
  288. <select id="queryDeptByIds" resultType="com.sckw.system.model.KwsDept">
  289. select a.*
  290. from kws_dept a
  291. where a.id in
  292. <foreach collection="list" item="item" open="(" close=")" separator=",">
  293. #{item}
  294. </foreach>
  295. </select>
  296. <select id="selectByEntId" resultType="com.sckw.system.model.KwsUser">
  297. select distinct c.*
  298. from kws_dept a
  299. left join kws_user_dept b on a.id = b.dept_id
  300. left join kws_user c on b.user_id = c.id
  301. where a.ent_id = #{entId}
  302. and a.del_flag = 0
  303. and b.del_flag = 0
  304. and c.del_flag = 0
  305. </select>
  306. <select id="selectByRoleIds" resultType="com.sckw.system.model.KwsUser">
  307. select distinct a.*
  308. from kws_user a
  309. left join kws_user_role b on a.id = b.user_id
  310. where a.del_flag = 0
  311. and b.del_flag = 0
  312. and b.role_id in
  313. <foreach collection="roleIdList" item="item" open="(" close=")" separator=",">
  314. #{item}
  315. </foreach>
  316. </select>
  317. </mapper>