UserMapper.xml 11 KB

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