CmUserMapper.xml 17 KB

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