UserMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. <result property="companyOrgState" column="companyOrgState" jdbcType="INTEGER"/>
  25. <result property="departmentOrgState" column="departmentOrgState" jdbcType="INTEGER"/>
  26. <result property="tenantState" column="TENANT_STATE" jdbcType="INTEGER"/>
  27. <result property="iotPhoneNumber" column="iot_phone_number" jdbcType="VARCHAR"/>
  28. </resultMap>
  29. <!-- 基本字段 -->
  30. <sql id="Base_Column_List">
  31. 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>
  32. <!-- 查询单个 -->
  33. <select id="selectById" resultMap="UserMap">
  34. select
  35. <include refid="Base_Column_List"/>
  36. from uims_user
  37. where ID = #{id}
  38. </select>
  39. <!-- 查询全部 -->
  40. <select id="selectAll" resultMap="UserMap">
  41. select
  42. <include refid="Base_Column_List"/>
  43. from uims_user
  44. </select>
  45. <!--通过实体作为筛选条件查询-->
  46. <select id="selectList" resultMap="UserMap">
  47. select
  48. b.TENANT_STATE, a.*, b.LOGO,b.WEB_URL ,c.ORG_STATE companyOrgState,d.ORG_STATE departmentOrgState,
  49. b.iot_phone_number,b.customer_id from uims_user a join uims_tenant b on a.TENANT_ID=b.CODE
  50. join uims_org c on a.COMPANY_ORG_ID=c.id left join
  51. uims_org d on a.DEPT_ORG_ID=d.ID
  52. <where>
  53. and a.status=1
  54. <if test="id != null">
  55. and ID = #{id}
  56. </if>
  57. <if test="tenantId != null and tenantId != ''">
  58. and a.TENANT_ID = #{tenantId}
  59. </if>
  60. <if test="username != null and username != ''">
  61. and USERNAME = #{username}
  62. </if>
  63. <if test="phone != null and phone != ''">
  64. and PHONE = #{phone}
  65. </if>
  66. <if test="companyOrgId != null">
  67. and COMPANY_ORG_ID = #{companyOrgId}
  68. </if>
  69. <if test="deptOrgId != null">
  70. and DEPT_ORG_ID = #{deptOrgId}
  71. </if>
  72. <if test="photo != null and photo != ''">
  73. and PHOTO = #{photo}
  74. </if>
  75. <if test="userType != null and userType != ''">
  76. and USER_TYPE = #{userType}
  77. </if>
  78. <if test="enableState != null and enableState != ''">
  79. and ENABLE_STATE = #{enableState}
  80. </if>
  81. <if test="remark != null">
  82. and REMARK = #{remark}
  83. </if>
  84. <if test="email != null and email != ''">
  85. and EMAIL = #{email}
  86. </if>
  87. <if test="status != null">
  88. and STATUS = #{status}
  89. </if>
  90. <if test="dateCreate != null">
  91. and DATE_CREATE = #{dateCreate}
  92. </if>
  93. <if test="createBy != null and createBy != ''">
  94. and CREATE_BY = #{createBy}
  95. </if>
  96. <if test="dateUpdate != null">
  97. and DATE_UPDATE = #{dateUpdate}
  98. </if>
  99. <if test="updateBy != null and updateBy != ''">
  100. and UPDATE_BY = #{updateBy}
  101. </if>
  102. </where>
  103. </select>
  104. <!-- 新增所有列 -->
  105. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  106. 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)
  107. values ( #{id}, #{tenantId}, #{username}, #{phone}, #{companyOrgId}, #{deptOrgId}, #{photo}, #{userType}, #{enableState}, #{remark}, #{email}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
  108. </insert>
  109. <!-- 批量新增 -->
  110. <insert id="batchInsert">
  111. insert into uims_user(ID, TENANT_ID, USERNAME, PHONE, COMPANY_ORG_ID, DEPT_ORG_ID, PHOTO, USER_TYPE,
  112. ENABLE_STATE, REMARK, EMAIL, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  113. values
  114. <foreach collection="users" item="item" index="index" separator=",">
  115. (
  116. #{item.id}, #{item.tenantId}, #{item.username}, #{item.phone}, #{item.companyOrgId}, #{item.deptOrgId},
  117. #{item.photo}, #{item.userType}, #{item.enableState}, #{item.remark}, #{item.email}, #{item.status},
  118. #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate}, #{item.updateBy} )
  119. </foreach>
  120. </insert>
  121. <!-- 通过主键修改数据 -->
  122. <update id="update">
  123. update uims.uims_user
  124. <set>
  125. <if test="tenantId != null and tenantId != ''">
  126. TENANT_ID = #{tenantId},
  127. </if>
  128. <if test="username != null and username != ''">
  129. USERNAME = #{username},
  130. </if>
  131. <if test="phone != null and phone != ''">
  132. PHONE = #{phone},
  133. </if>
  134. <if test="companyOrgId != null">
  135. COMPANY_ORG_ID = #{companyOrgId},
  136. </if>
  137. <if test="deptOrgId != null">
  138. DEPT_ORG_ID = #{deptOrgId},
  139. </if>
  140. <if test="photo != null and photo != ''">
  141. PHOTO = #{photo},
  142. </if>
  143. <if test="userType != null and userType != ''">
  144. USER_TYPE = #{userType},
  145. </if>
  146. <if test="enableState != null and enableState != ''">
  147. ENABLE_STATE = #{enableState},
  148. </if>
  149. <if test="remark != null">
  150. REMARK = #{remark},
  151. </if>
  152. <if test="email != null and email != ''">
  153. EMAIL = #{email},
  154. </if>
  155. <if test="status != null">
  156. STATUS = #{status},
  157. </if>
  158. <if test="dateCreate != null">
  159. DATE_CREATE = #{dateCreate},
  160. </if>
  161. <if test="createBy != null and createBy != ''">
  162. CREATE_BY = #{createBy},
  163. </if>
  164. <if test="dateUpdate != null">
  165. DATE_UPDATE = #{dateUpdate},
  166. </if>
  167. <if test="updateBy != null and updateBy != ''">
  168. UPDATE_BY = #{updateBy},
  169. </if>
  170. </set>
  171. where ID = #{id}
  172. </update>
  173. <!--通过主键删除-->
  174. <delete id="deleteById">
  175. delete from uims_user where ID = #{id}
  176. </delete>
  177. <!-- 总数 -->
  178. <select id="count" resultType="int">
  179. select count(*) from uims_user
  180. </select>
  181. <select id="selectPage" resultMap="UserMap">
  182. select
  183. <include refid="Base_Column_List"/>
  184. from uims_user
  185. <where>
  186. <if test="user.id != null">
  187. and ID = #{user.id}
  188. </if>
  189. <if test="user.tenantId != null and user.tenantId != ''">
  190. and TENANT_ID = #{user.tenantId}
  191. </if>
  192. <if test="user.username != null and user.username != ''">
  193. and USERNAME = #{user.username}
  194. </if>
  195. <if test="user.phone != null and user.phone != ''">
  196. and PHONE = #{user.phone}
  197. </if>
  198. <if test="user.companyOrgId != null">
  199. and COMPANY_ORG_ID = #{user.companyOrgId}
  200. </if>
  201. <if test="user.deptOrgId != null">
  202. and DEPT_ORG_ID = #{user.deptOrgId}
  203. </if>
  204. <if test="user.photo != null and user.photo != ''">
  205. and PHOTO = #{user.photo}
  206. </if>
  207. <if test="user.userType != null and user.userType != ''">
  208. and USER_TYPE = #{user.userType}
  209. </if>
  210. <if test="user.enableState != null and user.enableState != ''">
  211. and ENABLE_STATE = #{user.enableState}
  212. </if>
  213. <if test="user.remark != null">
  214. and REMARK = #{user.remark}
  215. </if>
  216. <if test="user.email != null and user.email != ''">
  217. and EMAIL = #{user.email}
  218. </if>
  219. <if test="user.status != null">
  220. and STATUS = #{user.status}
  221. </if>
  222. <if test="user.dateCreate != null">
  223. and DATE_CREATE = #{user.dateCreate}
  224. </if>
  225. <if test="user.createBy != null and user.createBy != ''">
  226. and CREATE_BY = #{user.createBy}
  227. </if>
  228. <if test="user.dateUpdate != null">
  229. and DATE_UPDATE = #{user.dateUpdate}
  230. </if>
  231. <if test="user.updateBy != null and user.updateBy != ''">
  232. and UPDATE_BY = #{user.updateBy}
  233. </if>
  234. </where>
  235. </select>
  236. <select id="findPermission" resultType="com.huaxu.model.Permission">
  237. select c.PERMISSION_TYPE ,c.id roleId,c.ROLE_STATE roleState
  238. from uims_user a join uims_user_role b on a.id=b.USER_ID
  239. join uims_role c on b.ROLE_ID= c.ID
  240. where a.STATUS !=0 and b.status!=0 and c.status!=0
  241. and a.id=#{id}
  242. </select>
  243. <select id="findOrgRole" resultType="com.huaxu.model.ProgramItem">
  244. select d.ORG_ID orgId,c.ORG_TYPE newType from uims_user_role b
  245. join uims_role_org d on b.ROLE_ID=d.ROLE_ID join uims_org c
  246. on c.id=d.ORG_ID
  247. where b.USER_ID=#{id} and b.status!=0 and d.status!=0
  248. </select>
  249. <select id="findOrgs" resultType="com.huaxu.entity.Org">
  250. select ID, TENANT_ID, ORG_TYPE,
  251. PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME,
  252. ORG_LEADER_PHONE, ORG_LEADER_EMAIL,
  253. ORG_LEADER_SEX, STATUS, DATE_CREATE,
  254. CREATE_BY, DATE_UPDATE, UPDATE_BY
  255. from uims_org
  256. <where>
  257. <if test="orgType != null and orgType != ''">
  258. and ORG_TYPE=#{orgType}
  259. </if>
  260. and TENANT_ID=#{tenantId}
  261. and status!=0
  262. </where>
  263. </select>
  264. <select id="findLoginInfo" resultType="com.huaxu.dto.UserDto">
  265. select a.id, a.PHONE,b.TENANT_NAME,b.code tenantId,b.WEB_URL ,b.LOGO,a.USERNAME name
  266. from uims_user a join uims_tenant b on
  267. a.TENANT_ID=b.CODE
  268. where a.PHONE=#{phone} and a.status!=0 and b.status!=0
  269. </select>
  270. <!-- 新增注册数据 -->
  271. <insert id="insertRegister" keyProperty="id" useGeneratedKeys="true">
  272. insert into uims_user_register( ID, USERNAME, PHONE, USER_TYPE, REMARK, STATUS, CREATE_BY,DATE_CREATE,UPDATE_BY,DATE_UPDATE)
  273. values ( #{id}, #{username}, #{phone}, #{userType}, #{remark}, 1, #{createBy}, #{dateCreate}, #{updateBy}, #{dateUpdate})
  274. </insert>
  275. <!-- 超级管理员查询 一级菜单List -->
  276. <select id="findAllFirstMenu" resultType="com.huaxu.entity.MenuEntity">
  277. SELECT
  278. a.app_id appId
  279. FROM uims_menu a
  280. <where>
  281. a.status=1 and a.PARENT_MENU_ID=0 and a.SHOW_STATE=1 and a.is_admin=1
  282. </where>
  283. </select>
  284. <!-- 租户管理员查询租户菜单 -->
  285. <select id="findTenantFirstMenu" resultType="com.huaxu.entity.MenuEntity">
  286. select
  287. a.app_id appId
  288. from uims_tenant_menu b
  289. inner join uims_menu a on a.id= b.MENU_ID and a.status=1
  290. <where>
  291. b.status=1 and a.PARENT_MENU_ID=0 and a.show_state=1 and a.is_tenant=1
  292. <if test="tenantId != null and tenantId != ''">
  293. and b.tenant_id = #{tenantId}
  294. </if>
  295. </where>
  296. order by b.MENU_SEQ
  297. </select>
  298. <select id="findUserFirstMenu" resultType="com.huaxu.entity.MenuEntity">
  299. SELECT
  300. a.app_id as appId
  301. from uims_user_role userrole
  302. inner join uims_role_menu rolemenu on rolemenu.ROLE_ID=userrole.ROLE_ID and rolemenu.status=1
  303. inner join uims_menu a on a.id=rolemenu.MENU_ID and a.STATUS=1
  304. inner join uims_tenant_menu b on a.id= b.MENU_ID and b.status=1
  305. <if test="tenantId != null and tenantId != ''">
  306. and b.tenant_id = #{tenantId}
  307. </if>
  308. <where>
  309. userrole.status=1 and a.PARENT_MENU_ID=0 and a.SHOW_STATE=1 and a.is_tenant=1
  310. <if test="userId != null and userId != ''">
  311. and userrole.user_id = #{userId}
  312. </if>
  313. </where>
  314. order by b.MENU_SEQ
  315. </select>
  316. <select id="getAppSecret" resultType="string">
  317. select APP_SECRET_KEY from uims_app where APP_ID=#{appId}
  318. </select>
  319. <select id="getUniqueUserID" resultType="string">
  320. select uniq_id from uims_user where id=#{id}
  321. </select>
  322. <update id="updateUniqueUserID">
  323. update uims_user set uniq_id=#{uid} where id=#{id}
  324. </update>
  325. <select id="findThirdPartytLoginInfo" resultType="com.huaxu.entity.User">
  326. select login_account loginAccount,login_secret_key loginSecretKey,login_code loginCode,login_org_code loginOrgCode from uims_user where TENANT_ID =#{tenantId} and PHONE = #{phone}
  327. </select>
  328. </mapper>