CmUserMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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.caimei.modules.user.dao.CmUserDao">
  4. <sql id="cmUserColumns">
  5. a.userID AS "userID",
  6. a.mobile AS "mobile",
  7. a.userOrganizeID AS "userOrganizeID",
  8. a.bindMobile AS "bindMobile",
  9. a.email AS "email",
  10. a.account AS "account",
  11. a.realName AS "realName",
  12. a.userIdentity AS "userIdentity",
  13. a.userName AS "userName",
  14. a.source AS "source",
  15. a.image AS "image",
  16. a.password AS "password",
  17. a.name AS "name",
  18. a.registerUserTypeID AS "registerUserTypeID",
  19. a.manufacturerStatus AS "manufacturerStatus",
  20. a.shopID AS "shopID",
  21. a.auditStatus AS "auditStatus",
  22. a.auditTime AS "auditTime",
  23. a.auditNote AS "auditNote",
  24. a.registerTime AS "registerTime",
  25. a.registerIP AS "registerIP",
  26. a.loginTime AS "loginTime",
  27. a.loginFailTime AS "loginFailTime",
  28. a.loginIP AS "loginIP",
  29. a.validFlag AS "validFlag",
  30. a.clubStatus AS "clubStatus",
  31. a.clubID AS "clubID",
  32. a.agreeFlag AS "agreeFlag",
  33. a.serviceProviderStatus AS "serviceProviderStatus",
  34. a.serviceProviderID AS "serviceProviderID",
  35. a.userMoney AS "userMoney",
  36. a.ableUserMoney as "ableUserMoney",
  37. a.logoffTime AS "logoffTime",
  38. a.appKey AS "appKey",
  39. a.appSecret AS "appSecret",
  40. a.scanFlag AS "scanFlag",
  41. a.userBeans AS "userBeans",
  42. a.guideFlag AS "guideFlag",
  43. a.userPermission AS "userPermission"
  44. </sql>
  45. <select id="get" resultType="CmUser">
  46. SELECT
  47. <include refid="cmUserColumns"/>
  48. FROM user a
  49. WHERE a.userID = #{id}
  50. </select>
  51. <select id="findList" resultType="CmUser">
  52. SELECT
  53. <include refid="cmUserColumns"/>
  54. FROM user a
  55. <where>
  56. <if test="userID != null and userID != ''">
  57. AND a.userID = #{userID}
  58. </if>
  59. <if test="mobile != null and mobile != ''">
  60. AND (a.mobile LIKE
  61. <if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
  62. <if test="dbName == 'mssql'">'%'+#{mobile}+'%'</if>
  63. <if test="dbName == 'mysql'">concat('%',#{mobile},'%')</if>
  64. OR a.bindMobile LIKE
  65. <if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
  66. <if test="dbName == 'mssql'">'%'+#{mobile}+'%'</if>
  67. <if test="dbName == 'mysql'">concat('%',#{mobile},'%')</if>
  68. )
  69. </if>
  70. <if test="email != null and email != ''">
  71. AND a.email LIKE
  72. <if test="dbName == 'oracle'">'%'||#{email}||'%'</if>
  73. <if test="dbName == 'mssql'">'%'+#{email}+'%'</if>
  74. <if test="dbName == 'mysql'">concat('%',#{email},'%')</if>
  75. </if>
  76. <if test="userName != null and userName != ''">
  77. AND a.userName LIKE
  78. <if test="dbName == 'oracle'">'%'||#{userName}||'%'</if>
  79. <if test="dbName == 'mssql'">'%'+#{userName}+'%'</if>
  80. <if test="dbName == 'mysql'">concat('%',#{userName},'%')</if>
  81. </if>
  82. <if test="startTime != null and startTime != ''">
  83. AND (a.registerTime &gt; #{startTime} OR a.registerTime = #{startTime})
  84. </if>
  85. <if test="endTime != null and endTime != ''">
  86. AND (a.registerTime &lt; #{endTime} OR a.registerTime = #{endTime})
  87. </if>
  88. <if test="userOrganizeID != null and userOrganizeID != ''">
  89. AND a.userOrganizeID = #{userOrganizeID}
  90. </if>
  91. <choose>
  92. <when test="registerUserTypeID != null and registerUserTypeID != ''">
  93. AND a.registerUserTypeID = #{registerUserTypeID}
  94. </when>
  95. <otherwise>
  96. AND a.registerUserTypeID IN (0,10,1,24,34,2,32,3,23,33)
  97. </otherwise>
  98. </choose>
  99. </where>
  100. <choose>
  101. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  102. ORDER BY ${page.orderBy}
  103. </when>
  104. <otherwise>
  105. ORDER BY a.userID DESC
  106. </otherwise>
  107. </choose>
  108. </select>
  109. <!--适用于企业通过手机号码查询用户-->
  110. <select id="findListBuyBindMobile" resultType="CmUser">
  111. SELECT
  112. *
  113. FROM user a
  114. <where>
  115. a.bindMobile = #{bindMobile}
  116. <if test="clubID != null and clubID != ''">
  117. AND a.clubID != #{clubID}
  118. </if>
  119. </where>
  120. </select>
  121. <!--星范商城查询会所-->
  122. <select id="findListBuyUserInfo" resultType="CmUser">
  123. SELECT
  124. a.*
  125. ,c.linkMan AS "linkMan"
  126. ,t.name as "town"
  127. ,ci.name as "city"
  128. ,p.name as "province"
  129. ,c.address AS "address"
  130. FROM user a
  131. LEFT JOIN club c on c.userID = a.userID
  132. LEFT JOIN town t on t.townID = c.townID
  133. LEFT JOIN city ci ON ci.cityID = c.cityID
  134. LEFT JOIN province p ON p.provinceID = c.provinceID
  135. <where>
  136. a.userOrganizeID = #{userOrganizeID}
  137. <if test="bindMobile != null and bindMobile != ''">
  138. AND a.bindMobile LIKE concat('%',#{bindMobile},'%')
  139. </if>
  140. <if test="name != null and name != ''">
  141. AND a.name LIKE concat('%',#{name},'%')
  142. </if>
  143. <if test="linkMan != null and linkMan != ''">
  144. AND c.linkMan LIKE concat('%',#{linkMan},'%')
  145. </if>
  146. <if test="startTime != null and startTime != ''">
  147. AND a.registerTime <![CDATA[ >= ]]> #{startTime}
  148. </if>
  149. <if test="endTime != null and endTime != ''">
  150. AND a.registerTime <![CDATA[ <= ]]> #{endTime}
  151. </if>
  152. <if test="clubStatus != null and clubStatus != ''">
  153. AND a.clubStatus = #{clubStatus}
  154. </if>
  155. </where>
  156. ORDER BY a.registerTime DESC
  157. </select>
  158. <select id="findAllList" resultType="CmUser">
  159. SELECT
  160. <include refid="cmUserColumns"/>
  161. FROM user a
  162. <where>
  163. </where>
  164. <choose>
  165. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  166. ORDER BY ${page.orderBy}
  167. </when>
  168. <otherwise>
  169. ORDER BY a.userID DESC
  170. </otherwise>
  171. </choose>
  172. </select>
  173. <insert id="insert" parameterType="CmUser" keyProperty="userID" useGeneratedKeys="true">
  174. INSERT INTO user(
  175. userOrganizeID,
  176. account,
  177. realName,
  178. userIdentity,
  179. mobile,
  180. bindMobile,
  181. userPermission,
  182. email,
  183. userName,
  184. source,
  185. image,
  186. password,
  187. name,
  188. registerUserTypeID,
  189. manufacturerStatus,
  190. shopID,
  191. auditStatus,
  192. auditTime,
  193. auditNote,
  194. registerTime,
  195. registerIP,
  196. loginTime,
  197. loginFailTime,
  198. loginIP,
  199. validFlag,
  200. clubStatus,
  201. <if test="clubID != null and clubID != ''">
  202. clubID,
  203. </if>
  204. agreeFlag,
  205. serviceProviderStatus,
  206. serviceProviderID,
  207. userMoney,
  208. ableUserMoney,
  209. logoffTime,
  210. appKey,
  211. appSecret,
  212. scanFlag,
  213. userBeans
  214. ) VALUES (
  215. #{userOrganizeID},
  216. #{account},
  217. #{realName},
  218. #{userIdentity},
  219. #{mobile},
  220. #{bindMobile},
  221. #{userPermission},
  222. #{email},
  223. #{userName},
  224. #{source},
  225. #{image},
  226. #{password},
  227. #{name},
  228. #{registerUserTypeID},
  229. #{manufacturerStatus},
  230. #{shopID},
  231. #{auditStatus},
  232. #{auditTime},
  233. #{auditNote},
  234. #{registerTime},
  235. #{registerIP},
  236. #{loginTime},
  237. #{loginFailTime},
  238. #{loginIP},
  239. #{validFlag},
  240. #{clubStatus},
  241. <if test="clubID != null and clubID != ''">
  242. #{clubID},
  243. </if>
  244. #{agreeFlag},
  245. #{serviceProviderStatus},
  246. #{serviceProviderID},
  247. #{userMoney},
  248. #{ableUserMoney},
  249. #{logoffTime},
  250. #{appKey},
  251. #{appSecret},
  252. #{scanFlag},
  253. #{userBeans}
  254. )
  255. </insert>
  256. <update id="update">
  257. UPDATE user SET
  258. <if test="account != null and account != ''">
  259. account = #{account},
  260. </if>
  261. <if test="bindMobile != null and bindMobile != ''">
  262. bindMobile = #{bindMobile},
  263. </if>
  264. <if test="realName != null">
  265. realName = #{realName},
  266. </if>
  267. <if test="userIdentity != null and userIdentity != ''">
  268. userIdentity = #{userIdentity},
  269. </if>
  270. <if test="mobile != null and mobile != ''">
  271. mobile = #{mobile},
  272. </if>
  273. <if test="userPermission != null and userPermission != ''">
  274. userPermission = #{userPermission},
  275. </if>
  276. <if test="email != null and email != ''">
  277. email = #{email},
  278. </if>
  279. <if test="userName != null and userName != ''">
  280. userName = #{userName},
  281. </if>
  282. <if test="image != null and image != ''">
  283. image = #{image},
  284. </if>
  285. <if test="password != null and password != ''">
  286. password = #{password},
  287. </if>
  288. <if test="name != null and name != ''">
  289. name = #{name},
  290. </if>
  291. <if test="registerUserTypeID != null and registerUserTypeID != ''">
  292. registerUserTypeID = #{registerUserTypeID},
  293. </if>
  294. <if test="manufacturerStatus != null and manufacturerStatus != ''">
  295. manufacturerStatus = #{manufacturerStatus},
  296. </if>
  297. <if test="shopID != null and shopID != ''">
  298. shopID = #{shopID},
  299. </if>
  300. <if test="auditStatus != null and auditStatus != ''">
  301. auditStatus = #{auditStatus},
  302. </if>
  303. <if test="auditTime != null">
  304. auditTime = #{auditTime},
  305. </if>
  306. <if test="auditNote != null and auditNote != ''">
  307. auditNote = #{auditNote},
  308. </if>
  309. <if test="registerTime != null ">
  310. registerTime = #{registerTime},
  311. </if>
  312. <if test="registerIP != null and registerIP != ''">
  313. registerIP = #{registerIP},
  314. </if>
  315. <if test="loginTime != null and loginTime != ''">
  316. loginTime = #{loginTime},
  317. </if>
  318. <if test="loginFailTime != null and loginFailTime != ''">
  319. loginFailTime = #{loginFailTime},
  320. </if>
  321. <if test="loginIP != null and loginIP != ''">
  322. loginIP = #{loginIP},
  323. </if>
  324. <if test="validFlag != null and validFlag != ''">
  325. validFlag = #{validFlag},
  326. </if>
  327. <if test="clubStatus != null and clubStatus != ''">
  328. clubStatus = #{clubStatus},
  329. </if>
  330. <if test="clubID != null and clubID != ''">
  331. clubID = #{clubID},
  332. </if>
  333. <if test="agreeFlag != null and agreeFlag != ''">
  334. agreeFlag = #{agreeFlag},
  335. </if>
  336. <if test="serviceProviderStatus != null and serviceProviderStatus != ''">
  337. serviceProviderStatus = #{serviceProviderStatus},
  338. </if>
  339. <if test="serviceProviderID != null and serviceProviderID != ''">
  340. serviceProviderID = #{serviceProviderID},
  341. </if>
  342. <if test="userMoney != null and userMoney != ''">
  343. userMoney = #{userMoney},
  344. </if>
  345. <if test="logoffTime != null and logoffTime != ''">
  346. logoffTime = #{logoffTime},
  347. </if>
  348. <if test="appKey != null and appKey != ''">
  349. appKey = #{appKey},
  350. </if>
  351. <if test="appSecret != null and appSecret != ''">
  352. appSecret = #{appSecret},
  353. </if>
  354. <if test="scanFlag != null and scanFlag != ''">
  355. scanFlag = #{scanFlag},
  356. </if>
  357. <if test="userBeans != null and userBeans != ''">
  358. userBeans = #{userBeans},
  359. </if>
  360. <if test="guideFlag != null and guideFlag != ''">
  361. guideFlag = #{guideFlag},
  362. </if>
  363. userID = #{userID}
  364. WHERE userID = #{userID}
  365. </update>
  366. <delete id="delete">
  367. DELETE FROM user
  368. WHERE userID = #{userID}
  369. </delete>
  370. <select id="findUserByRegisterType" resultType="CmUser">
  371. SELECT
  372. <include refid="cmUserColumns"/>
  373. FROM user
  374. <where>
  375. registerUserTypeID = #{registerUserTypeID}
  376. </where>
  377. </select>
  378. <select id="findAllPersonalUser" resultType="CmUser">
  379. SELECT
  380. <include refid="cmUserColumns"/>
  381. FROM user
  382. <where>
  383. registerUserTypeID IN (0,5,10,24,34,2,32,23,33)
  384. </where>
  385. </select>
  386. <select id="findByCompanyUserID" resultType="CmUser">
  387. SELECT
  388. <include refid="cmUserColumns"/>
  389. FROM user a
  390. WHERE a.userID != #{companyUserID}
  391. ORDER BY case when registerUserTypeID in (1,2,3) then 1 else 0 end ,
  392. case when registerUserTypeID in (24,23) then 1 else 0 end ,
  393. case when auditStatus = 0 then 1 else 0 end ,
  394. auditTime DESC
  395. </select>
  396. <update id="updateEmployeeStatus">
  397. UPDATE user
  398. <set>
  399. <if test="userPermission != null and userPermission != ''">
  400. userPermission = #{userPermission},
  401. </if>
  402. <if test="clubStatus != null and clubStatus != ''">
  403. clubStatus = #{clubStatus},
  404. </if>
  405. <if test="manufacturerStatus != null and manufacturerStatus != ''">
  406. manufacturerStatus = #{manufacturerStatus},
  407. </if>
  408. <if test="tipStatus != null and tipStatus != ''">
  409. tipStatus = #{tipStatus},
  410. </if>
  411. </set>
  412. WHERE userID = #{companyUserID}
  413. </update>
  414. <update id="updateUserStatus">
  415. UPDATE user
  416. <set>
  417. <if test="manufacturerStatus != null and manufacturerStatus != ''">
  418. manufacturerStatus = #{manufacturerStatus},
  419. </if>
  420. <if test="validFlag != null and validFlag != ''">
  421. validFlag = #{validFlag},
  422. </if>
  423. </set>
  424. WHERE userID = #{userID}
  425. </update>
  426. <update id="updateShopStatus">
  427. UPDATE shop
  428. <set>
  429. <if test="status != null and status != ''">
  430. status = #{status},
  431. </if>
  432. </set>
  433. WHERE userID = #{userID}
  434. </update>
  435. <update id="updateUserAudit">
  436. UPDATE user
  437. <set>
  438. <if test="auditStatus != null and auditStatus != ''">
  439. auditStatus = #{auditStatus},
  440. </if>
  441. <if test="auditNote != null and auditNote != ''">
  442. auditNote = #{auditNote},
  443. </if>
  444. <if test="manufacturerStatus != null and manufacturerStatus != ''">
  445. manufacturerStatus = #{manufacturerStatus},
  446. </if>
  447. <if test="auditTime != null and auditTime != ''">
  448. auditTime = #{auditTime},
  449. </if>
  450. <if test="validFlag != null and validFlag != ''">
  451. validFlag = #{validFlag},
  452. </if>
  453. </set>
  454. WHERE userID = #{userId}
  455. </update>
  456. <update id="updateShopAudit">
  457. UPDATE shop
  458. <set>
  459. <if test="auditStatus != null and auditStatus != ''">
  460. auditStatus = #{auditStatus},
  461. </if>
  462. <if test="auditNote != null and auditNote != ''">
  463. auditNote = #{auditNote},
  464. </if>
  465. <if test="manufacturerStatus != null and manufacturerStatus != ''">
  466. status = #{manufacturerStatus},
  467. </if>
  468. <if test="auditTime != null and auditTime != ''">
  469. auditTime = #{auditTime},
  470. </if>
  471. <if test="name != null and name != ''">
  472. checkMan = #{name},
  473. </if>
  474. </set>
  475. WHERE shopID = #{shopId}
  476. </update>
  477. <update id="updateEmployeePermission">
  478. UPDATE user SET userPermission = #{userPermission}
  479. WHERE userID != #{companyUserID} AND auditStatus = '1'
  480. </update>
  481. <update id="updateUserInfo">
  482. UPDATE user SET
  483. realName = #{realName},
  484. name = #{name},
  485. userName = #{userName},
  486. bindMobile = #{bindMobile},
  487. email = #{email}
  488. WHERE userID = #{userID}
  489. </update>
  490. <update id="initEmployeeInfo">
  491. UPDATE user SET
  492. userIdentity = '0',
  493. userPermission = '1',
  494. registerUserTypeID = '10' ,
  495. auditStatus = NULL ,
  496. auditTime = NULL ,
  497. userName = realName,
  498. name = NULL ,
  499. clubID = NULL ,
  500. clubStatus = NULL ,
  501. shopID = NULL ,
  502. manufacturerStatus = NULL ,
  503. tipStatus = '1'
  504. WHERE userID != #{companyUserID}
  505. </update>
  506. <update id="updateAbleUserMoney">
  507. UPDATE user SET
  508. ableUserMoney = #{ableUserMoney}
  509. WHERE userID = #{userId}
  510. </update>
  511. <update id="updateMoney">
  512. UPDATE user SET
  513. userMoney = #{userMoney},
  514. ableUserMoney = #{ableUserMoney}
  515. WHERE userID = #{userID}
  516. </update>
  517. <select id="findUserByMobile" resultType="CmUser">
  518. SELECT
  519. <include refid="cmUserColumns"/>
  520. FROM user a
  521. WHERE a.mobile=#{mobile}
  522. </select>
  523. <select id="getUserPayOrder" resultType="com.caimei.modules.order.entity.NewShopOrder">
  524. select *
  525. from cm_shop_order
  526. where userID=#{userId}
  527. </select>
  528. <select id="selectByMobileOrEmail" resultType="com.caimei.modules.user.entity.CmUser">
  529. select u.*,cu.mobile as operatorMobile from user u
  530. left join cm_mall_operation_user cu on cu.userID = u.userID
  531. where (u.bindMobile = #{mobileOrEmail} or u.email = #{mobileOrEmail})
  532. AND u.userIdentity IN (1,2,3,4)
  533. AND u.userOrganizeID = 0
  534. <if test="source == 'www'">
  535. AND u.registerUserTypeID IN (1,3,4)
  536. </if>
  537. <if test="source == 'crm'">
  538. AND u.registerUserTypeID IN (1,2,3,32,4)
  539. </if>
  540. UNION
  541. select u.*,cu.mobile as operatorMobile from user u
  542. left join cm_mall_operation_user cu on cu.userID = u.userID
  543. where cu.mobile = #{mobileOrEmail}
  544. AND cu.delFlag != 1
  545. AND u.userIdentity IN (1,2,3,4)
  546. AND u.userOrganizeID = 0
  547. <if test="source == 'www'">
  548. AND u.registerUserTypeID IN (1,3,4)
  549. </if>
  550. <if test="source == 'crm'">
  551. AND u.registerUserTypeID IN (1,2,3,32,4)
  552. </if>
  553. </select>
  554. <update id="updateUserBeans">
  555. UPDATE USER SET userBeans = #{userBeans} WHERE userID = #{userID}
  556. </update>
  557. <select id="findUserByOrganizeId" resultType="com.caimei.modules.user.entity.CmUser">
  558. SELECT
  559. <include refid="cmUserColumns"/>
  560. FROM user a
  561. WHERE a.userOrganizeID=#{organizeId}
  562. limit 1
  563. </select>
  564. <select id="getOrganizeStoreName" resultType="java.lang.String">
  565. select name from cm_organize_store where id = #{organizeStoreId}
  566. </select>
  567. <update id="updateByClubStatus">
  568. UPDATE user SET clubStatus = #{clubStatus} WHERE userID = #{confirmUserId}
  569. </update>
  570. <select id="findByConfirmTime" resultType="date">
  571. SELECT
  572. confirmTime
  573. FROM
  574. club_confirm_record
  575. WHERE
  576. userId = #{userId}
  577. ORDER BY
  578. confirmTime DESC
  579. LIMIT
  580. 1
  581. </select>
  582. <select id="findUserBeans" resultType="java.lang.Integer">
  583. select userBeans
  584. from user
  585. where userID = #{userId}
  586. </select>
  587. <select id="selOrgan" resultType="com.caimei.modules.user.entity.CmOrganValueSystem">
  588. select * from cm_organ_value_system where userID = #{userId} and stage = 0 limit 1
  589. </select>
  590. <insert id="insertOrgan">
  591. INSERT INTO cm_organ_value_system
  592. (userID, stage, delType)
  593. VALUES(#{userId},0,1)
  594. </insert>
  595. </mapper>