SysUserMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.dgtly.system.mapper.SysUserMapper">
  6. <resultMap id="SysUserResult" type="SysUser">
  7. <id property="userId" column="user_id" />
  8. <result property="companyId" column="company_id" />
  9. <result property="deptId" column="dept_id" />
  10. <result property="loginName" column="login_name" />
  11. <result property="userName" column="user_name" />
  12. <result property="email" column="email" />
  13. <result property="phonenumber" column="phonenumber" />
  14. <result property="sex" column="sex" />
  15. <result property="avatar" column="avatar" />
  16. <result property="password" column="password" />
  17. <result property="salt" column="salt" />
  18. <result property="idType" column="id_type" />
  19. <result property="idNumber" column="id_number" />
  20. <result property="accountId" column="account_id" />
  21. <result property="isAuthentication" column="is_authentication" />
  22. <result property="personAttestationTime" column="person_attestation_time" />
  23. <result property="receiveUrlMobileNo" column="receive_url_mobile_no" />
  24. <result property="status" column="status" />
  25. <result property="delFlag" column="del_flag" />
  26. <result property="loginIp" column="login_ip" />
  27. <result property="loginDate" column="login_date" />
  28. <result property="createBy" column="create_by" />
  29. <result property="createTime" column="create_time" />
  30. <result property="updateBy" column="update_by" />
  31. <result property="updateTime" column="update_time" />
  32. <result property="remark" column="remark" />
  33. <result property="isConsignee" column="is_consignee" />
  34. <result property="isIndependently" column="is_independently" />
  35. <result property="isSelfDelivery" column="is_self_delivery" />
  36. <result property="isSync" column="is_sync" />
  37. <result property="quit" column="quit" />
  38. <result property="isShopAccount" column="is_shop_account" />
  39. <result property="isAuthentication" column="is_authentication" />
  40. <result property="personAttestationTime" column="person_attestation_time" />
  41. <result property="isOrgAuthentication" column="is_org_authentication" />
  42. <result property="orgAttestationTime" column="org_attestation_time" />
  43. <!--<result property="salesLevel" column="sales_level" />-->
  44. <!--<result property="orgName" column="org_name" />-->
  45. <!--<result property="orgCode" column="org_code" />-->
  46. <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
  47. <association property="company" column="company_id" javaType="SysCompany" resultMap="companyResult" />
  48. <association property="sysUserExt" column="user_id" javaType="SysUserExt" resultMap="SysUserExtResult" />
  49. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  50. </resultMap>
  51. <resultMap id="deptResult" type="SysDept">
  52. <id property="deptId" column="dept_id" />
  53. <result property="parentId" column="parent_id" />
  54. <result property="deptName" column="dept_name" />
  55. <result property="orderNum" column="order_num" />
  56. <result property="leader" column="leader" />
  57. <result property="status" column="dept_status" />
  58. </resultMap>
  59. <resultMap id="companyResult" type="SysCompany">
  60. <id property="id" column="id" />
  61. <result property="companyName" column="company_name" />
  62. </resultMap>
  63. <resultMap id="RoleResult" type="SysRole">
  64. <id property="roleId" column="role_id" />
  65. <result property="roleName" column="role_name" />
  66. <result property="roleKey" column="role_key" />
  67. <result property="roleSort" column="role_sort" />
  68. <result property="dataScope" column="data_scope" />
  69. <result property="status" column="role_status" />
  70. </resultMap>
  71. <resultMap id="SysUserExtResult" type="SysUserExt" >
  72. <result property="userId" column="user_id" />
  73. <result property="orgCode" column="org_code" />
  74. <result property="salesLevel" column="sales_level" />
  75. <result property="orgName" column="org_name" />
  76. <result property="sapEmployeeId" column="sap_employee_id" />
  77. <result property="bossEmployeeId" column="boss_employee_id" />
  78. <result property="bossName" column="boss_name" />
  79. <result property="customerCode" column="customer_code" />
  80. <result property="isCustomerManager" column="is_customer_manager" />
  81. <result property="postName" column="post_name" />
  82. <result property="postCode" column="post_code" />
  83. <result property="identity" column="identity" />
  84. </resultMap>
  85. <sql id="selectUserVo">
  86. select u.user_id,u.company_id, u.dept_id, u.login_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt,u.id_type,u.id_number,u.account_id,u.is_authentication,u.receive_url_mobile_no, u.status,
  87. u.del_flag, u.login_ip, u.login_date, u.create_time, u.remark,u.is_consignee,u.person_attestation_time,u.is_independently,u.is_self_delivery,is_sync,
  88. c.company_name,u.quit,u.is_shop_account,
  89. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  90. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,
  91. suse.sales_level,suse.org_name,suse.org_code,suse.sap_employee_id,suse.boss_employee_id,suse.boss_name,suse.customer_code,suse.is_customer_manager,
  92. suse.post_name,suse.post_code,suse.identity
  93. from sys_user u
  94. left join sys_dept d on u.dept_id = d.dept_id
  95. left join sys_company c on u.company_id = c.id
  96. left join sys_user_role ur on u.user_id = ur.user_id
  97. left join sys_role r on r.role_id = ur.role_id
  98. left join sys_user_ext suse on suse.user_id = u.user_id and suse.del_flag = '0'
  99. </sql>
  100. <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
  101. select u.user_id,u.company_id, u.dept_id, u.login_name, u.user_name,u.id_type,u.id_number,u.account_id,u.is_authentication,u.receive_url_mobile_no, u.email, u.avatar,
  102. u.phonenumber, u.password, u.sex, u.salt, u.status, u.del_flag,u.quit,u.is_independently,u.is_self_delivery,
  103. u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  104. d.dept_name, d.leader,
  105. suse.identity,suse.sales_level,suse.org_name,suse.org_code,suse.post_name,suse.is_customer_manager,ce.is_authentication is_org_authentication,ce.org_attestation_time
  106. from sys_user u
  107. left join sys_dept d on u.dept_id = d.dept_id
  108. left join sys_company c on u.company_id = c.id
  109. left join sys_user_ext suse on suse.user_id = u.user_id and suse.del_flag = '0'
  110. LEFT JOIN customers_ext ce ON suse.org_code = ce.chains_code
  111. where u.del_flag = '0'
  112. <if test="loginName != null and loginName != ''">
  113. AND u.login_name like concat('%', #{loginName}, '%')
  114. </if>
  115. <if test="status != null and status != ''">
  116. AND u.status = #{status}
  117. </if>
  118. <if test="sysUserExt != null and sysUserExt.salesLevel !=null
  119. and sysUserExt.salesLevel != ''">
  120. AND suse.sales_level = #{sysUserExt.salesLevel}
  121. </if>
  122. <if test="sysUserExt != null and sysUserExt.orgCode !=null
  123. and sysUserExt.orgCode != ''">
  124. AND suse.org_code = #{sysUserExt.orgCode}
  125. </if>
  126. <if test="sysUserExt != null and sysUserExt.orgName !=null
  127. and sysUserExt.orgName != ''">
  128. AND suse.org_name like concat('%', #{sysUserExt.orgName}, '%')
  129. </if>
  130. <if test="sysUserExt != null and sysUserExt.postName !=null
  131. and sysUserExt.postName != ''">
  132. AND suse.post_name = #{sysUserExt.postName}
  133. </if>
  134. <if test="sysUserExt != null and sysUserExt.identity !=null
  135. and sysUserExt.identity != ''">
  136. AND suse.identity = #{sysUserExt.identity}
  137. </if>
  138. <if test="userName != null and userName != ''">
  139. AND u.user_name like concat('%', #{userName}, '%')
  140. </if>
  141. <if test="phonenumber != null and phonenumber != ''">
  142. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  143. </if>
  144. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  145. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  146. </if>
  147. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  148. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  149. </if>
  150. <if test="deptId != null and deptId != 0">
  151. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) ))
  152. </if>
  153. <if test="companyId != null and companyId != 0">
  154. AND u.company_id = #{companyId}
  155. </if>
  156. <if test="isAuthentication != null and isAuthentication != ''">
  157. AND u.is_authentication = #{isAuthentication}
  158. </if>
  159. <if test="isOrgAuthentication != null and isOrgAuthentication != '' and isOrgAuthentication =='1'.toString()">
  160. AND ce.is_authentication = '1'
  161. </if>
  162. <if test="isOrgAuthentication != null and isOrgAuthentication != '' and isOrgAuthentication =='0'.toString()">
  163. AND (ce.is_authentication = '0' or ce.is_authentication is null)
  164. </if>
  165. <!-- 数据范围过滤 -->
  166. ${params.dataScope}
  167. </select>
  168. <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
  169. select distinct u.user_id,u.company_id, u.dept_id,u.id_type,u.id_number,u.account_id,u.is_authentication,u.receive_url_mobile_no, u.login_name, u.user_name, u.email, u.avatar, u.phonenumber, u.status, u.create_time
  170. from sys_user u
  171. left join sys_dept d on u.dept_id = d.dept_id
  172. left join sys_company c on u.company_id = c.id
  173. left join sys_user_role ur on u.user_id = ur.user_id
  174. left join sys_role r on r.role_id = ur.role_id
  175. where u.del_flag = '0' and r.role_id = #{roleId}
  176. <if test="loginName != null and loginName != ''">
  177. AND u.login_name like concat('%', #{loginName}, '%')
  178. </if>
  179. <if test="phonenumber != null and phonenumber != ''">
  180. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  181. </if>
  182. <if test="companyId != null and companyId != ''">
  183. AND u.company_id like #{companyId}
  184. </if>
  185. <!-- 数据范围过滤 -->
  186. ${params.dataScope}
  187. </select>
  188. <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
  189. select distinct u.user_id,u.company_id,u.id_type,u.id_number,u.account_id,u.is_authentication,u.receive_url_mobile_no, u.dept_id, u.login_name, u.user_name, u.email, u.avatar, u.phonenumber, u.status, u.create_time
  190. from sys_user u
  191. left join sys_dept d on u.dept_id = d.dept_id
  192. left join sys_company c on u.company_id = c.id
  193. left join sys_user_role ur on u.user_id = ur.user_id
  194. left join sys_role r on r.role_id = ur.role_id
  195. where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
  196. and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
  197. <if test="loginName != null and loginName != ''">
  198. AND u.login_name like concat('%', #{loginName}, '%')
  199. </if>
  200. <if test="phonenumber != null and phonenumber != ''">
  201. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  202. </if>
  203. <if test="companyId != null and companyId != ''">
  204. AND u.company_id like #{companyId}
  205. </if>
  206. <!-- 数据范围过滤 -->
  207. ${params.dataScope}
  208. </select>
  209. <select id="selectUserByLoginName" parameterType="String" resultMap="SysUserResult">
  210. <include refid="selectUserVo"/>
  211. where u.login_name = #{userName} and u.quit is null and u.del_flag ='0' GROUP BY login_name
  212. </select>
  213. <select id="selectUserByIsManager" resultType="java.lang.String">
  214. select u.login_name
  215. from sys_user u
  216. left join sys_user_ext suse on suse.user_id = u.user_id
  217. where 1=1
  218. <if test="isCustomerManager !=null ">
  219. and suse.is_customer_manager like concat('%',#{isCustomerManager}, '%')
  220. </if>
  221. and u.quit is null and u.del_flag ='0' and suse.del_flag ='0'
  222. and u.login_name is not null
  223. </select>
  224. <select id="selectAllUser" parameterType="String" resultMap="SysUserResult">
  225. SELECT
  226. u.user_id,
  227. u.company_id,
  228. u.dept_id,
  229. u.login_name,
  230. u.user_name,
  231. u.email,
  232. u.avatar,
  233. u.phonenumber,
  234. u.sex,
  235. u.PASSWORD,
  236. u.salt,
  237. u.id_type,
  238. u.id_number,
  239. u.account_id,
  240. u.is_authentication,
  241. u.is_independently,
  242. u.is_self_delivery,
  243. u.receive_url_mobile_no,
  244. u.STATUS,
  245. u.del_flag,
  246. u.login_ip,
  247. u.login_date,
  248. u.create_time,
  249. u.remark,
  250. u.is_consignee,
  251. u.person_attestation_time,
  252. is_sync,
  253. u.quit,
  254. suse.sales_level,
  255. suse.org_name,
  256. suse.org_code,
  257. suse.sap_employee_id,
  258. suse.boss_employee_id,
  259. suse.boss_name,
  260. suse.customer_code,
  261. suse.is_customer_manager,
  262. suse.post_name,
  263. suse.post_code,
  264. suse.identity
  265. FROM
  266. sys_user u
  267. LEFT JOIN sys_user_ext suse ON suse.user_id = u.user_id
  268. where suse.is_customer_manager is not null and suse.is_customer_manager !=''
  269. </select>
  270. <select id="selectUserByPhoneNumber" parameterType="String" resultMap="SysUserResult">
  271. <include refid="selectUserVo"/>
  272. where u.phonenumber = #{phonenumber} and u.quit is null and u.del_flag ='0'
  273. </select>
  274. <select id="selectUserByEmail" parameterType="String" resultMap="SysUserResult">
  275. <include refid="selectUserVo"/>
  276. where u.email = #{email} and u.del_flag='0' and u.quit is null
  277. </select>
  278. <select id="checkLoginNameUnique" resultType="int">
  279. select count(1) from sys_user where login_name=#{loginName} and del_flag='0' and quit is null
  280. </select>
  281. <select id="checkPhoneUnique" resultMap="SysUserResult">
  282. select user_id, phonenumber from sys_user where phonenumber=#{phonenumber} and del_flag='0' and quit is null
  283. </select>
  284. <select id="checkEmailUnique" resultMap="SysUserResult">
  285. select user_id, email from sys_user where email=#{email} and del_flag='0' and quit is null
  286. </select>
  287. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  288. <include refid="selectUserVo"/>
  289. where u.user_id = #{userId} and u.del_flag='0' and u.quit is null
  290. </select>
  291. <delete id="deleteUserById" parameterType="Long">
  292. delete from sys_user where user_id = #{userId}
  293. </delete>
  294. <delete id="deleteUserByLoginName" parameterType="Long">
  295. delete from sys_user where login_name = #{loginName}
  296. </delete>
  297. <delete id="deleteUserByIds" parameterType="Long">
  298. update sys_user set del_flag = '2' where user_id in
  299. <foreach collection="array" item="userId" open="(" separator="," close=")">
  300. #{userId}
  301. </foreach>
  302. </delete>
  303. <update id="updateUser" parameterType="SysUser">
  304. update sys_user
  305. <set>
  306. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  307. <if test="loginName != null and loginName != ''">login_name = #{loginName},</if>
  308. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  309. <if test="email != null and email != ''">email = #{email},</if>
  310. <if test="phonenumber != null and phonenumber != ''">phonenumber = #{phonenumber},</if>
  311. <if test="sex != null and sex != ''">sex = #{sex},</if>
  312. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  313. <if test="password != null and password != ''">password = #{password},</if>
  314. <if test="salt != null and salt != ''">salt = #{salt},</if>
  315. <if test="idType != null and idType != ''">id_type = #{idType},</if>
  316. <if test="idNumber != null and idNumber != ''">id_number = #{idNumber},</if>
  317. <if test="accountId != null and accountId != ''">account_id = #{accountId},</if>
  318. <if test="isAuthentication != null and isAuthentication != ''">is_authentication = #{isAuthentication},</if>
  319. <if test="isIndependently != null ">is_independently = #{isIndependently},</if>
  320. <if test="isSelfDelivery !=null">is_self_delivery =#{isSelfDelivery},</if>
  321. <if test="personAttestationTime != null">person_attestation_time = #{personAttestationTime},</if>
  322. <if test="receiveUrlMobileNo != null and receiveUrlMobileNo != ''">receive_url_mobile_no = #{receiveUrlMobileNo},</if>
  323. <if test="status != null and status != ''">status = #{status},</if>
  324. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  325. <if test="loginDate != null">login_date = #{loginDate},</if>
  326. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  327. <if test="remark != null">remark = #{remark},</if>
  328. <if test="isConsignee != null">is_consignee = #{isConsignee},</if>
  329. <if test="isSync != null">is_sync = #{isSync},</if>
  330. <if test="quit != null">quit = #{quit},</if>
  331. <if test="isShopAccount != null">is_shop_account = #{isShopAccount},</if>
  332. update_time = sysdate()
  333. </set>
  334. where user_id = #{userId}
  335. </update>
  336. <update id="updateUserByLoginName" parameterType="SysUser">
  337. update sys_user
  338. <set>
  339. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  340. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  341. <if test="email != null and email != ''">email = #{email},</if>
  342. <if test="phonenumber != null and phonenumber != ''">phonenumber = #{phonenumber},</if>
  343. <if test="sex != null and sex != ''">sex = #{sex},</if>
  344. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  345. <if test="password != null and password != ''">password = #{password},</if>
  346. <if test="salt != null and salt != ''">salt = #{salt},</if>
  347. <if test="idType != null and idType != ''">id_type = #{idType},</if>
  348. <if test="idNumber != null and idNumber != ''">id_number = #{idNumber},</if>
  349. <if test="accountId != null and accountId != ''">account_id = #{accountId},</if>
  350. <if test="isAuthentication != null and isAuthentication != ''">is_authentication = #{isAuthentication},</if>
  351. <if test="personAttestationTime != null">person_attestation_time = #{personAttestationTime},</if>
  352. <if test="receiveUrlMobileNo != null and receiveUrlMobileNo != ''">receive_url_mobile_no = #{receiveUrlMobileNo},</if>
  353. <if test="status != null and status != ''">status = #{status},</if>
  354. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  355. <if test="loginDate != null">login_date = #{loginDate},</if>
  356. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  357. <if test="remark != null">remark = #{remark},</if>
  358. <if test="isConsignee != null">is_consignee = #{isConsignee},</if>
  359. <if test="isSync != null">is_sync = #{isSync},</if>
  360. <if test="isIndependently != null ">is_independently = #{isIndependently},</if>
  361. <if test="isSelfDelivery !=null">is_self_delivery =#{isSelfDelivery},</if>
  362. update_time = sysdate()
  363. </set>
  364. where login_name = #{loginName} and quit is null and del_flag='0'
  365. </update>
  366. <update id="updateIsAuthentication" parameterType="String">
  367. update sys_user set is_authentication = #{isAuthentication} ,person_attestation_time = now()
  368. where account_id = #{accountId}
  369. </update>
  370. <update id="changeStatus">
  371. update sys_user set del_flag = #{status}
  372. where company_id = #{companyId}
  373. <if test="status == 0 ">and del_flag = 3 </if>
  374. <if test="status == 3 ">and del_flag = 0 </if>
  375. </update>
  376. <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  377. <selectKey keyProperty="userId" order="AFTER" resultType="java.lang.Long">
  378. select LAST_INSERT_ID();
  379. </selectKey>
  380. insert into sys_user(
  381. <if test="userId != null and userId != 0">user_id,</if>
  382. <if test="deptId != null and deptId != 0">dept_id,</if>
  383. <if test="companyId != null and companyId != 0">company_id,</if>
  384. <if test="loginName != null and loginName != ''">login_name,</if>
  385. <if test="userName != null and userName != ''">user_name,</if>
  386. <if test="email != null and email != ''">email,</if>
  387. <if test="avatar != null and avatar != ''">avatar,</if>
  388. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  389. <if test="sex != null and sex != ''">sex,</if>
  390. <if test="password != null and password != ''">password,</if>
  391. <if test="salt != null and salt != ''">salt,</if>
  392. <if test="status != null and status != ''">status,</if>
  393. <if test="createBy != null and createBy != ''">create_by,</if>
  394. <if test="remark != null and remark != ''">remark,</if>
  395. <if test="isShopAccount != null and isShopAccount != ''">is_shop_account,</if>
  396. create_time
  397. )values(
  398. <if test="userId != null and userId != ''">#{userId},</if>
  399. <if test="deptId != null and deptId != ''">#{deptId},</if>
  400. <if test="companyId != null and companyId != 0">#{companyId},</if>
  401. <if test="loginName != null and loginName != ''">#{loginName},</if>
  402. <if test="userName != null and userName != ''">#{userName},</if>
  403. <if test="email != null and email != ''">#{email},</if>
  404. <if test="avatar != null and avatar != ''">#{avatar},</if>
  405. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  406. <if test="sex != null and sex != ''">#{sex},</if>
  407. <if test="password != null and password != ''">#{password},</if>
  408. <if test="salt != null and salt != ''">#{salt},</if>
  409. <if test="status != null and status != ''">#{status},</if>
  410. <if test="createBy != null and createBy != ''">#{createBy},</if>
  411. <if test="remark != null and remark != ''">#{remark},</if>
  412. <if test="isShopAccount != null and isShopAccount != ''">#{isShopAccount},</if>
  413. sysdate()
  414. )
  415. </insert>
  416. <select id="selectAllUserLoginName" resultType="java.lang.String">
  417. select u.login_name
  418. from sys_user u where u.quit is null and u.del_flag='0'
  419. </select>
  420. <select id="selectDiyUserLoginName" resultType="java.lang.String">
  421. select distinct(u.login_name)
  422. from sys_user u left join sys_user_ext b on u.user_id = b.user_id where b.post_name='DIY经销商' and u.quit is null and u.del_flag='0' and b.del_flag='0'
  423. </select>
  424. <insert id="insertUserNoKey" parameterType="SysUser" >
  425. insert into sys_user(
  426. <if test="userId != null and userId != 0">user_id,</if>
  427. <if test="deptId != null and deptId != 0">dept_id,</if>
  428. <if test="loginName != null and loginName != ''">login_name,</if>
  429. <if test="userName != null and userName != ''">user_name,</if>
  430. <if test="email != null and email != ''">email,</if>
  431. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  432. <if test="sex != null and sex != ''">sex,</if>
  433. <if test="password != null and password != ''">password,</if>
  434. <if test="salt != null and salt != ''">salt,</if>
  435. <if test="status != null and status != ''">status,</if>
  436. create_time
  437. )values(
  438. <if test="userId != null and userId != ''">#{userId},</if>
  439. <if test="deptId != null and deptId != ''">#{deptId},</if>
  440. <if test="loginName != null and loginName != ''">#{loginName},</if>
  441. <if test="userName != null and userName != ''">#{userName},</if>
  442. <if test="email != null and email != ''">#{email},</if>
  443. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  444. <if test="sex != null and sex != ''">#{sex},</if>
  445. <if test="password != null and password != ''">#{password},</if>
  446. <if test="salt != null and salt != ''">#{salt},</if>
  447. <if test="status != null and status != ''">#{status},</if>
  448. sysdate()
  449. )
  450. </insert>
  451. <select id="selectUserByEmplyeeId" parameterType="String" resultMap="SysUserResult">
  452. <include refid="selectUserVo"/>
  453. where suse.sap_employee_id = #{emplyeeId}
  454. </select>
  455. <select id="selectLoginNamesByCostumerCode" resultType="java.util.Map" parameterType="String">
  456. select sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user su
  457. left join sys_user_ext sue on sue.user_id = su.user_id and sue.del_flag = '0'
  458. where sue.org_code in
  459. <foreach collection="array" item="customerCode" open="(" separator="," close=")">
  460. #{customerCode}
  461. </foreach>
  462. and sue.is_customer_manager != 0 and su.quit is null and su.del_flag = '0'
  463. GROUP BY sue.org_code
  464. </select>
  465. <select id="selectLoginNamesByOrgCodeSelf" resultType="java.util.Map" parameterType="String">
  466. select sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user su
  467. left join sys_user_ext sue on sue.user_id = su.user_id and sue.del_flag = '0'
  468. where sue.org_code =#{customerCode}
  469. and sue.is_customer_manager in ('1','2','3')
  470. and sue.is_customer_manager != 0
  471. and su.quit is null
  472. and su.del_flag = '0'
  473. GROUP BY sue.org_code
  474. </select>
  475. <select id="selectLoginNameByCustomerCode" resultType="java.lang.String">
  476. SELECT
  477. u.login_name
  478. FROM
  479. order_sales_sum_tuc_customer c
  480. LEFT JOIN sys_user_ext e ON e.sap_employee_id = c.emp_id and e.del_flag = '0'
  481. LEFT JOIN sys_user u ON u.user_id = e.user_id
  482. WHERE
  483. c.customer_id =#{customerId}
  484. and u.quit is null
  485. and u.del_flag = '0'
  486. GROUP BY
  487. u.user_id limit 1
  488. </select>
  489. <select id="selectLoginNamesByCustomerModelVO" resultType="java.util.Map" parameterType="String">
  490. select DISTINCT sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user su
  491. left join sys_user_ext sue on sue.user_id = su.user_id and sue.del_flag = '0'
  492. where su.quit is null and su.del_flag = '0'
  493. <if test="customerCode !=null and customerCode !='' ">
  494. and sue.org_code =#{customerCode}
  495. </if>
  496. <if test="customerType !=null and customerType !='' and customerType =='D9' ">
  497. and sue.identity in ('1')
  498. </if>
  499. <if test="customerType !=null and customerType !='' and customerType =='Y9' ">
  500. and sue.identity in ('2')
  501. </if>
  502. and sue.is_customer_manager != 0
  503. GROUP BY sue.org_code
  504. </select>
  505. <select id="selectLoginNamesByCostumerCode1" resultType="java.util.Map" parameterType="String">
  506. select DISTINCT sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user su
  507. left join sys_user_ext sue on sue.user_id = su.user_id and sue.del_flag = '0'
  508. where su.quit is null and su.del_flag = '0' and sue.org_code in
  509. <foreach collection="array" item="customerCode" open="(" separator="," close=")">
  510. #{customerCode}
  511. </foreach>
  512. GROUP BY sue.org_code
  513. </select>
  514. <select id="selectLoginNamesByEmployeeCode" resultType="Map" parameterType="String">
  515. select DISTINCT sue.sap_employee_id employee_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser ,sue.org_code from sys_user su
  516. left join sys_user_ext sue on sue.user_id = su.user_id and sue.del_flag = '0'
  517. where su.quit is null and su.del_flag = '0' and sue.sap_employee_id in
  518. <foreach collection="array" item="employeeCode" open="(" separator="," close=")">
  519. #{employeeCode}
  520. </foreach>
  521. GROUP BY sue.sap_employee_id
  522. </select>
  523. <select id="selectUserByOrgCode" resultMap="SysUserResult" >
  524. SELECT
  525. u.user_id,
  526. u.user_name,
  527. a.is_consignee,
  528. a.is_independently,
  529. a.is_self_delivery,
  530. v.sap_employee_id,
  531. v.is_customer_manager,
  532. v.org_code
  533. FROM
  534. sys_user u
  535. LEFT JOIN sys_user_ext v ON u.user_id = v.user_id and v.del_flag = '0'
  536. left join sys_user_customer_authorization a on a.user_id = u.user_id
  537. WHERE
  538. v.org_code =#{orgCode} and u.quit is null and u.del_flag = '0'
  539. and v.is_customer_manager !='0' and v.is_customer_manager !='8' GROUP BY u.user_id
  540. </select>
  541. <select id="getCustomNameByCode" resultType="java.lang.String" >
  542. select customer_name from order_sales_sum_tuc_customer where customer_id=#{code} limit 1
  543. </select>
  544. <select id="selectSyncDateUser" resultType="java.lang.String" >
  545. select GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user su
  546. left join sys_user_sync_data sus on sus.user_id = su.user_id where sus.type = #{type}
  547. </select>
  548. <insert id="insertUserRole">
  549. insert into sys_user_role (user_id,role_id) select ${userId},${roleId} from dual where not exists ( select 1 from sys_user_role where user_id = #{userId} and role_id = #{roleId} )
  550. </insert>
  551. <delete id="deleteByLoginName" parameterType="int">
  552. delete from sys_user_author_rel where user_id = (
  553. select user_id from sys_user where 1=1 and del_flag='0' and quit is null
  554. <if test="loginName !=null and loginName !='' ">
  555. and login_name=#{loginName}
  556. </if>
  557. )
  558. </delete>
  559. <select id="selectUser" parameterType="SysUser" resultMap="SysUserResult">
  560. select u.user_id,u.company_id, u.dept_id, u.login_name, u.user_name,u.id_type,u.id_number,u.account_id,u.is_authentication,u.receive_url_mobile_no, u.email, u.avatar,
  561. u.phonenumber, u.password, u.sex, u.salt, u.status, u.del_flag,
  562. u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.quit
  563. from sys_user u where is_sync ='0' and quit is null
  564. </select>
  565. <select id="sendmailUnionUser" resultType="com.dgtly.system.domain.UserVO" >
  566. select u.user_name as userName,u.phonenumber,u.login_name as loginName
  567. from sys_user u LEFT JOIN sys_user_ext e on e.user_id =u.user_id and e.del_flag = '0' WHERE
  568. ( u.phonenumber, u.user_name ) IN (
  569. SELECT
  570. phonenumber,
  571. user_name
  572. FROM
  573. sys_user where del_flag=0 and quit is null
  574. GROUP BY
  575. phonenumber,
  576. user_name
  577. HAVING
  578. count(*) > 1) and u.del_flag = '0' and u.quit is null
  579. and e.is_customer_manager is null and u.is_shop_account ='0' order by user_name
  580. </select>
  581. <select id="selectAllUserByUserId" parameterType="Long" resultMap="SysUserResult">
  582. SELECT *
  583. FROM
  584. sys_user u
  585. LEFT JOIN sys_user_ext suse ON suse.user_id = u.user_id and suse.del_flag = '0'
  586. where u.user_id = #{userId}
  587. and u.del_flag = '0' and u.quit is null
  588. </select>
  589. </mapper>