UserMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.huaxu.dao.UserMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.entity.User" id="UserMap">
  6. <result property="id" column="ID" jdbcType="INTEGER"/>
  7. <result property="tenantId" column="TENANT_ID" jdbcType="VARCHAR"/>
  8. <result property="username" column="USERNAME" jdbcType="VARCHAR"/>
  9. <result property="phone" column="PHONE" jdbcType="VARCHAR"/>
  10. <result property="companyOrgId" column="COMPANY_ORG_ID" jdbcType="INTEGER"/>
  11. <result property="deptOrgId" column="DEPT_ORG_ID" jdbcType="INTEGER"/>
  12. <result property="photo" column="PHOTO" jdbcType="VARCHAR"/>
  13. <result property="userType" column="USER_TYPE" jdbcType="VARCHAR"/>
  14. <result property="enableState" column="ENABLE_STATE" jdbcType="VARCHAR"/>
  15. <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
  16. <result property="email" column="EMAIL" jdbcType="VARCHAR"/>
  17. <result property="status" column="STATUS" jdbcType="INTEGER"/>
  18. <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
  19. <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
  20. <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
  21. <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
  22. <result property="logo" column="LOGO" jdbcType="VARCHAR"/>
  23. <result property="webUrl" column="WEB_URL" jdbcType="VARCHAR"/>
  24. </resultMap>
  25. <!-- 基本字段 -->
  26. <sql id="Base_Column_List">
  27. ID, TENANT_ID, USERNAME, PHONE, COMPANY_ORG_ID, DEPT_ORG_ID, PHOTO, USER_TYPE, ENABLE_STATE, REMARK, EMAIL, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY </sql>
  28. <!-- 查询单个 -->
  29. <select id="selectById" resultMap="UserMap">
  30. select
  31. <include refid="Base_Column_List"/>
  32. from uims_user
  33. where ID = #{id}
  34. </select>
  35. <!-- 查询全部 -->
  36. <select id="selectAll" resultMap="UserMap">
  37. select
  38. <include refid="Base_Column_List"/>
  39. from uims_user
  40. </select>
  41. <!--通过实体作为筛选条件查询-->
  42. <select id="selectList" resultMap="UserMap">
  43. select
  44. a.*, b.LOGO,b.WEB_URL
  45. from uims_user a join uims_tenant b on a.TENANT_ID=b.CODE
  46. <where>
  47. <if test="id != null">
  48. and ID = #{id}
  49. </if>
  50. <if test="tenantId != null and tenantId != ''">
  51. and TENANT_ID = #{tenantId}
  52. </if>
  53. <if test="username != null and username != ''">
  54. and USERNAME = #{username}
  55. </if>
  56. <if test="phone != null and phone != ''">
  57. and PHONE = #{phone}
  58. </if>
  59. <if test="companyOrgId != null">
  60. and COMPANY_ORG_ID = #{companyOrgId}
  61. </if>
  62. <if test="deptOrgId != null">
  63. and DEPT_ORG_ID = #{deptOrgId}
  64. </if>
  65. <if test="photo != null and photo != ''">
  66. and PHOTO = #{photo}
  67. </if>
  68. <if test="userType != null and userType != ''">
  69. and USER_TYPE = #{userType}
  70. </if>
  71. <if test="enableState != null and enableState != ''">
  72. and ENABLE_STATE = #{enableState}
  73. </if>
  74. <if test="remark != null">
  75. and REMARK = #{remark}
  76. </if>
  77. <if test="email != null and email != ''">
  78. and EMAIL = #{email}
  79. </if>
  80. <if test="status != null">
  81. and STATUS = #{status}
  82. </if>
  83. <if test="dateCreate != null">
  84. and DATE_CREATE = #{dateCreate}
  85. </if>
  86. <if test="createBy != null and createBy != ''">
  87. and CREATE_BY = #{createBy}
  88. </if>
  89. <if test="dateUpdate != null">
  90. and DATE_UPDATE = #{dateUpdate}
  91. </if>
  92. <if test="updateBy != null and updateBy != ''">
  93. and UPDATE_BY = #{updateBy}
  94. </if>
  95. </where>
  96. </select>
  97. <!-- 新增所有列 -->
  98. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  99. insert into uims_user(ID, TENANT_ID, USERNAME, PHONE, COMPANY_ORG_ID, DEPT_ORG_ID, PHOTO, USER_TYPE, ENABLE_STATE, REMARK, EMAIL, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  100. values ( #{id}, #{tenantId}, #{username}, #{phone}, #{companyOrgId}, #{deptOrgId}, #{photo}, #{userType}, #{enableState}, #{remark}, #{email}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
  101. </insert>
  102. <!-- 批量新增 -->
  103. <insert id="batchInsert">
  104. insert into uims_user(ID, TENANT_ID, USERNAME, PHONE, COMPANY_ORG_ID, DEPT_ORG_ID, PHOTO, USER_TYPE,
  105. ENABLE_STATE, REMARK, EMAIL, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  106. values
  107. <foreach collection="users" item="item" index="index" separator=",">
  108. (
  109. #{item.id}, #{item.tenantId}, #{item.username}, #{item.phone}, #{item.companyOrgId}, #{item.deptOrgId},
  110. #{item.photo}, #{item.userType}, #{item.enableState}, #{item.remark}, #{item.email}, #{item.status},
  111. #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate}, #{item.updateBy} )
  112. </foreach>
  113. </insert>
  114. <!-- 通过主键修改数据 -->
  115. <update id="update">
  116. update uims.uims_user
  117. <set>
  118. <if test="tenantId != null and tenantId != ''">
  119. TENANT_ID = #{tenantId},
  120. </if>
  121. <if test="username != null and username != ''">
  122. USERNAME = #{username},
  123. </if>
  124. <if test="phone != null and phone != ''">
  125. PHONE = #{phone},
  126. </if>
  127. <if test="companyOrgId != null">
  128. COMPANY_ORG_ID = #{companyOrgId},
  129. </if>
  130. <if test="deptOrgId != null">
  131. DEPT_ORG_ID = #{deptOrgId},
  132. </if>
  133. <if test="photo != null and photo != ''">
  134. PHOTO = #{photo},
  135. </if>
  136. <if test="userType != null and userType != ''">
  137. USER_TYPE = #{userType},
  138. </if>
  139. <if test="enableState != null and enableState != ''">
  140. ENABLE_STATE = #{enableState},
  141. </if>
  142. <if test="remark != null">
  143. REMARK = #{remark},
  144. </if>
  145. <if test="email != null and email != ''">
  146. EMAIL = #{email},
  147. </if>
  148. <if test="status != null">
  149. STATUS = #{status},
  150. </if>
  151. <if test="dateCreate != null">
  152. DATE_CREATE = #{dateCreate},
  153. </if>
  154. <if test="createBy != null and createBy != ''">
  155. CREATE_BY = #{createBy},
  156. </if>
  157. <if test="dateUpdate != null">
  158. DATE_UPDATE = #{dateUpdate},
  159. </if>
  160. <if test="updateBy != null and updateBy != ''">
  161. UPDATE_BY = #{updateBy},
  162. </if>
  163. </set>
  164. where ID = #{id}
  165. </update>
  166. <!--通过主键删除-->
  167. <delete id="deleteById">
  168. delete from uims_user where ID = #{id}
  169. </delete>
  170. <!-- 总数 -->
  171. <select id="count" resultType="int">
  172. select count(*) from uims_user
  173. </select>
  174. <select id="selectPage" resultMap="UserMap">
  175. select
  176. <include refid="Base_Column_List"/>
  177. from uims_user
  178. <where>
  179. <if test="user.id != null">
  180. and ID = #{user.id}
  181. </if>
  182. <if test="user.tenantId != null and user.tenantId != ''">
  183. and TENANT_ID = #{user.tenantId}
  184. </if>
  185. <if test="user.username != null and user.username != ''">
  186. and USERNAME = #{user.username}
  187. </if>
  188. <if test="user.phone != null and user.phone != ''">
  189. and PHONE = #{user.phone}
  190. </if>
  191. <if test="user.companyOrgId != null">
  192. and COMPANY_ORG_ID = #{user.companyOrgId}
  193. </if>
  194. <if test="user.deptOrgId != null">
  195. and DEPT_ORG_ID = #{user.deptOrgId}
  196. </if>
  197. <if test="user.photo != null and user.photo != ''">
  198. and PHOTO = #{user.photo}
  199. </if>
  200. <if test="user.userType != null and user.userType != ''">
  201. and USER_TYPE = #{user.userType}
  202. </if>
  203. <if test="user.enableState != null and user.enableState != ''">
  204. and ENABLE_STATE = #{user.enableState}
  205. </if>
  206. <if test="user.remark != null">
  207. and REMARK = #{user.remark}
  208. </if>
  209. <if test="user.email != null and user.email != ''">
  210. and EMAIL = #{user.email}
  211. </if>
  212. <if test="user.status != null">
  213. and STATUS = #{user.status}
  214. </if>
  215. <if test="user.dateCreate != null">
  216. and DATE_CREATE = #{user.dateCreate}
  217. </if>
  218. <if test="user.createBy != null and user.createBy != ''">
  219. and CREATE_BY = #{user.createBy}
  220. </if>
  221. <if test="user.dateUpdate != null">
  222. and DATE_UPDATE = #{user.dateUpdate}
  223. </if>
  224. <if test="user.updateBy != null and user.updateBy != ''">
  225. and UPDATE_BY = #{user.updateBy}
  226. </if>
  227. </where>
  228. </select>
  229. <select id="findPermission" resultType="com.huaxu.model.Permission">
  230. select c.PERMISSION_TYPE ,c.id roleId,c.ROLE_STATE roleState
  231. from uims_user a join uims_user_role b on a.id=b.USER_ID
  232. join uims_role c on b.ROLE_ID= c.ID
  233. where a.STATUS !=0 and b.status!=0 and c.status!=0
  234. and a.id=#{id}
  235. </select>
  236. <select id="findOrgRole" resultType="com.huaxu.model.ProgramItem">
  237. select d.ORG_ID orgId from uims_user_role b
  238. join uims_role_org d on b.ROLE_ID=d.ROLE_ID
  239. where b.USER_ID=#{id}
  240. </select>
  241. <select id="findOrgs" resultType="com.huaxu.entity.Org">
  242. select ID, TENANT_ID, ORG_TYPE,
  243. PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME,
  244. ORG_LEADER_PHONE, ORG_LEADER_EMAIL,
  245. ORG_LEADER_SEX, STATUS, DATE_CREATE,
  246. CREATE_BY, DATE_UPDATE, UPDATE_BY
  247. from uims_org
  248. <where>
  249. <if test="orgType != null and orgType != ''">
  250. and ORG_TYPE=#{orgType}
  251. </if>
  252. and TENANT_ID=#{tenantId}
  253. and status!=0
  254. </where>
  255. </select>
  256. <select id="findLoginInfo" resultType="com.huaxu.dto.UserDto">
  257. select a.id, a.PHONE,b.TENANT_NAME,b.code tenantId,b.WEB_URL ,b.LOGO
  258. from uims_user a join uims_tenant b on
  259. a.TENANT_ID=b.CODE
  260. where a.PHONE=#{phone} and a.status!=0 and b.status!=0
  261. </select>
  262. <!-- 新增注册数据 -->
  263. <insert id="insertRegister" keyProperty="id" useGeneratedKeys="true">
  264. insert into uims_user_register( ID, USERNAME, PHONE, USER_TYPE, REMARK, STATUS, CREATE_BY,DATE_CREATE,UPDATE_BY,DATE_UPDATE)
  265. values ( #{id}, #{username}, #{phone}, #{userType}, #{remark}, 1, #{createBy}, #{dateCreate}, #{updateBy}, #{dateUpdate})
  266. </insert>
  267. </mapper>