KwsUserDao.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. <select id="selectByKeys" resultMap="BaseResultMap">
  35. select
  36. <include refid="Base_Column_List" />
  37. from kws_user
  38. where del_flag = 0
  39. and id in
  40. <foreach collection="list" item="item" open="(" close=")" separator=",">
  41. #{item}
  42. </foreach>
  43. </select>
  44. <insert id="insert" parameterType="com.sckw.system.model.KwsUser">
  45. insert into kws_user
  46. <trim prefix="(" suffix=")" suffixOverrides=",">
  47. <if test="id != null">
  48. id,
  49. </if>
  50. <if test="systemType != null">
  51. system_type,
  52. </if>
  53. <if test="account != null">
  54. account,
  55. </if>
  56. <if test="password != null">
  57. password,
  58. </if>
  59. <if test="name != null">
  60. name,
  61. </if>
  62. <if test="phone != null">
  63. phone,
  64. </if>
  65. <if test="photo != null">
  66. photo,
  67. </if>
  68. <if test="email != null">
  69. email,
  70. </if>
  71. <if test="clientId != null">
  72. client_id,
  73. </if>
  74. <if test="isMain != null">
  75. is_main,
  76. </if>
  77. <if test="remark != null">
  78. remark,
  79. </if>
  80. <if test="status != null">
  81. status,
  82. </if>
  83. <if test="createBy != null">
  84. create_by,
  85. </if>
  86. <if test="createTime != null">
  87. create_time,
  88. </if>
  89. <if test="updateBy != null">
  90. update_by,
  91. </if>
  92. <if test="updateTime != null">
  93. update_time,
  94. </if>
  95. <if test="delFlag != null">
  96. del_flag,
  97. </if>
  98. <if test="salt != null">
  99. salt,
  100. </if>
  101. </trim>
  102. <trim prefix="values (" suffix=")" suffixOverrides=",">
  103. <if test="id != null">
  104. #{id,jdbcType=BIGINT},
  105. </if>
  106. <if test="systemType != null">
  107. #{systemType,jdbcType=INTEGER},
  108. </if>
  109. <if test="account != null">
  110. #{account,jdbcType=VARCHAR},
  111. </if>
  112. <if test="password != null">
  113. #{password,jdbcType=VARCHAR},
  114. </if>
  115. <if test="name != null">
  116. #{name,jdbcType=VARCHAR},
  117. </if>
  118. <if test="phone != null">
  119. #{phone,jdbcType=VARCHAR},
  120. </if>
  121. <if test="photo != null">
  122. #{photo,jdbcType=VARCHAR},
  123. </if>
  124. <if test="email != null">
  125. #{email,jdbcType=VARCHAR},
  126. </if>
  127. <if test="clientId != null">
  128. #{clientId,jdbcType=VARCHAR},
  129. </if>
  130. <if test="isMain != null">
  131. #{isMain,jdbcType=INTEGER},
  132. </if>
  133. <if test="remark != null">
  134. #{remark,jdbcType=VARCHAR},
  135. </if>
  136. <if test="status != null">
  137. #{status,jdbcType=INTEGER},
  138. </if>
  139. <if test="createBy != null">
  140. #{createBy,jdbcType=BIGINT},
  141. </if>
  142. <if test="createTime != null">
  143. #{createTime,jdbcType=TIMESTAMP},
  144. </if>
  145. <if test="updateBy != null">
  146. #{updateBy,jdbcType=BIGINT},
  147. </if>
  148. <if test="updateTime != null">
  149. #{updateTime,jdbcType=TIMESTAMP},
  150. </if>
  151. <if test="delFlag != null">
  152. #{delFlag,jdbcType=INTEGER},
  153. </if>
  154. <if test="salt != null">
  155. #{salt,jdbcType=VARCHAR},
  156. </if>
  157. </trim>
  158. </insert>
  159. <update id="update" parameterType="com.sckw.system.model.KwsUser">
  160. update kws_user
  161. <set>
  162. <if test="systemType != null">
  163. system_type = #{systemType,jdbcType=INTEGER},
  164. </if>
  165. <if test="account != null">
  166. account = #{account,jdbcType=VARCHAR},
  167. </if>
  168. <if test="password != null">
  169. password = #{password,jdbcType=VARCHAR},
  170. </if>
  171. <if test="name != null">
  172. name = #{name,jdbcType=VARCHAR},
  173. </if>
  174. <if test="phone != null">
  175. phone = #{phone,jdbcType=VARCHAR},
  176. </if>
  177. <if test="photo != null">
  178. photo = #{photo,jdbcType=VARCHAR},
  179. </if>
  180. <if test="email != null">
  181. email = #{email,jdbcType=VARCHAR},
  182. </if>
  183. <if test="clientId != null">
  184. client_id = #{clientId,jdbcType=VARCHAR},
  185. </if>
  186. <if test="isMain != null">
  187. is_main = #{isMain,jdbcType=INTEGER},
  188. </if>
  189. <if test="remark != null">
  190. remark = #{remark,jdbcType=VARCHAR},
  191. </if>
  192. <if test="status != null">
  193. status = #{status,jdbcType=INTEGER},
  194. </if>
  195. <if test="createBy != null">
  196. create_by = #{createBy,jdbcType=BIGINT},
  197. </if>
  198. <if test="createTime != null">
  199. create_time = #{createTime,jdbcType=TIMESTAMP},
  200. </if>
  201. <if test="updateBy != null">
  202. update_by = #{updateBy,jdbcType=BIGINT},
  203. </if>
  204. <if test="updateTime != null">
  205. update_time = #{updateTime,jdbcType=TIMESTAMP},
  206. </if>
  207. <if test="delFlag != null">
  208. del_flag = #{delFlag,jdbcType=INTEGER},
  209. </if>
  210. <if test="salt != null">
  211. salt = #{salt,jdbcType=VARCHAR},
  212. </if>
  213. </set>
  214. where id = #{id,jdbcType=BIGINT}
  215. </update>
  216. <select id="findPage" resultType="com.sckw.system.model.vo.res.KwsUserResVo" parameterType="java.util.Map" >
  217. select distinct
  218. su.id, su.system_type systemType, su.account, su.password, su.name,
  219. su.phone, su.photo, su.email, su.is_main isMain, su.remark, su.status, su.salt,
  220. c.id deptId,c.name deptName,e.id roleId, e.name roleName,
  221. su.create_time,
  222. su2.`name` createByName,
  223. su.update_time
  224. from kws_user su
  225. left join kws_user_dept b on su.id = b.user_id
  226. left join kws_dept c on b.dept_id = c.id
  227. left join kws_user_role d on su.id = d.user_id
  228. left join kws_role e on e.id = d.role_id
  229. left join kws_user su2 on su.create_by = su2.id
  230. where su.del_flag = 0
  231. and b.del_flag = 0
  232. and d.del_flag = 0
  233. <if test="systemType != null and systemType != ''">
  234. and su.system_type = #{systemType, jdbcType=VARCHAR}
  235. </if>
  236. <if test="idList != null and idList.size() > 0">
  237. and su.id in
  238. <foreach collection="idList" item="item" open="(" close=")" separator=",">
  239. #{item}
  240. </foreach>
  241. </if>
  242. <if test="account != null and account != ''">
  243. and su.account = #{account, jdbcType=VARCHAR}
  244. </if>
  245. <if test="name != null and name != ''">
  246. and su.name = #{name, jdbcType=VARCHAR}
  247. </if>
  248. <if test="phone != null and phone != ''">
  249. and su.phone = #{phone, jdbcType=VARCHAR}
  250. </if>
  251. <if test="email != null and email != ''">
  252. and su.email = #{email, jdbcType=VARCHAR}
  253. </if>
  254. <if test="isMain != null">
  255. and su.is_main = #{isMain}
  256. </if>
  257. <if test="deptId != null and deptId != ''">
  258. and c.id = #{deptId, jdbcType=VARCHAR}
  259. </if>
  260. <if test="roleId != null and roleId != ''">
  261. and e.id = #{roleId}
  262. </if>
  263. <if test="keywords != null and keywords != ''">
  264. and (su.name like concat('%', #{keywords}, '%') or su.account like concat('%', #{keywords}, '%') or su2.name like concat('%', #{keywords}, '%'))
  265. </if>
  266. <if test="entId != null and entId != ''">
  267. and c.ent_id = #{entId}
  268. </if>
  269. <if test="startTime != null and startTime != ''">
  270. and su.create_time >= #{startTime}
  271. </if>
  272. <if test="endTime != null and endTime != ''">
  273. and su.create_time &lt; date_add(#{endTime}, INTERVAL 1 DAY)
  274. </if>
  275. ORDER BY su.create_time desc
  276. </select>
  277. <select id="findList" resultType="com.sckw.system.model.vo.res.KwsUserResVo" parameterType="com.sckw.system.model.KwsUser" >
  278. select
  279. su.id, su.system_type systemType, su.account, su.password, su.name,
  280. su.phone, su.photo, su.email, su.is_main isMain, su.remark, su.status, su.salt,
  281. c.id deptId, c.name deptName, c.ent_id entId, e.id roleId, e.name roleName,
  282. u1.name createByName, su.create_time createTime, su.update_time updateTime
  283. from kws_user su
  284. left join kws_user_dept b on su.id = b.user_id
  285. left join kws_dept c on b.dept_id = c.id
  286. left join kws_user_role d on su.id = d.user_id
  287. left join kws_role e on e.id = d.role_id
  288. left join kws_user u1 on su.create_by = u1.id
  289. where su.del_flag = 0
  290. <if test="systemType != null and systemType != ''">
  291. and su.system_type = #{systemType, jdbcType=INTEGER}
  292. </if>
  293. <if test="account != null and account != ''">
  294. and su.account = #{account, jdbcType=VARCHAR}
  295. </if>
  296. <if test="name != null and name != ''">
  297. and su.name = #{name, jdbcType=VARCHAR}
  298. </if>
  299. <if test="userName != null and userName != ''">
  300. and su.name like concat('%', #{userName}, '%')
  301. </if>
  302. <if test="phone != null and phone != ''">
  303. and su.phone = #{phone, jdbcType=VARCHAR}
  304. </if>
  305. <choose>
  306. <when test="entIds != null and entIds != '' and entIds.size() > 0">
  307. and c.ent_id in
  308. <foreach collection="entIds" item="id" open="(" close=")" separator=",">
  309. #{id,jdbcType=BIGINT}
  310. </foreach>
  311. </when>
  312. </choose>
  313. ORDER BY su.create_time desc
  314. </select>
  315. <select id="queryUserDeptByUserId" resultType="com.sckw.system.model.KwsUserDept">
  316. select a.* from kws_user_dept a where a.user_id = #{userId} and a.del_flag = 0
  317. </select>
  318. <select id="queryDeptByIds" resultType="com.sckw.system.model.KwsDept">
  319. select a.*
  320. from kws_dept a
  321. where a.id in
  322. <foreach collection="list" item="item" open="(" close=")" separator=",">
  323. #{item}
  324. </foreach>
  325. </select>
  326. <select id="selectByEntId" resultType="com.sckw.system.model.KwsUser">
  327. select distinct c.*
  328. from kws_dept a
  329. left join kws_user_dept b on a.id = b.dept_id
  330. left join kws_user c on b.user_id = c.id
  331. where a.ent_id = #{entId}
  332. and a.del_flag = 0
  333. and b.del_flag = 0
  334. and c.del_flag = 0
  335. </select>
  336. <select id="selectByRoleIds" resultType="com.sckw.system.model.KwsUser">
  337. select distinct a.*
  338. from kws_user a
  339. left join kws_user_role b on a.id = b.user_id
  340. where a.del_flag = 0
  341. and b.del_flag = 0
  342. and b.role_id in
  343. <foreach collection="roleIdList" item="item" open="(" close=")" separator=",">
  344. #{item}
  345. </foreach>
  346. </select>
  347. <select id="getUserByName" resultType="com.sckw.system.model.KwsUser">
  348. select a.*
  349. from kws_user a
  350. where a.del_flag = 0
  351. and a.name like concat('%', #{name}, '%')
  352. </select>
  353. <select id="selectByDeptIds" resultType="com.sckw.system.model.KwsUser">
  354. select a.*
  355. from kws_user a
  356. left join kws_user_dept b on a.id = b.user_id
  357. left join kws_dept c on b.dept_id = c.id
  358. where a.del_flag = 0
  359. and c.del_flag = 0
  360. and c.id in
  361. <foreach collection="list" open="(" close=")" separator="," item="item">
  362. #{item}
  363. </foreach>
  364. </select>
  365. <select id="selectUserBySystemType" resultType="com.sckw.system.model.vo.res.KwsUserSystemTypeVo">
  366. select u.id AS id,u.system_type AS systemType,u.account AS account,u.name AS name, u.phone AS phone,u.is_main as isMain
  367. from kws_user AS u
  368. where u.del_flag = 0 and u.status = 0 and is_main =0 and u.system_type = #{systemType}
  369. </select>
  370. <select id="selectUserBySystemTypeAndMain" resultType="com.sckw.system.model.vo.res.KwsUserSystemTypeVo">
  371. select u.id AS id,u.system_type AS systemType,u.account AS account,u.name AS name, u.phone AS phone,u.is_main as isMain
  372. from kws_user AS u
  373. where u.del_flag = 0 and u.status = 0 and u.system_type = #{systemType} and u.is_main=#{isMain}
  374. </select>
  375. <select id="selectManager" resultMap="BaseResultMap">
  376. select a.*
  377. from kws_user a
  378. where a.del_flag = 0 and a.status = 0 and a.is_main = 0
  379. </select>
  380. </mapper>