LoginMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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.caimei365.user.mapper.LoginMapper">
  4. <insert id="insertLoginFailRecord">
  5. insert into cm_loginfail_record (logintime, userid)
  6. values (#{time}, #{userId})
  7. </insert>
  8. <select id="getLoginUserByUserId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  9. select u.userID as userId,
  10. u.clubID as clubId,
  11. u.shopID as shopId,
  12. u.serviceProviderId as serviceProviderId,
  13. u.userName as userName,
  14. u.name as name,
  15. u.mobile as mobile,
  16. u.bindMobile as bindMobile,
  17. u.email as email,
  18. u.userPermission as userPermission,
  19. u.userIdentity as userIdentity,
  20. u.password as password,
  21. u.guideFlag as guideFlag,
  22. u.clubStatus as clubStatus,
  23. u.manufacturerStatus as shopStatus
  24. from user u
  25. where u.userID = #{userId}
  26. limit 1
  27. </select>
  28. <select id="getLoginUserByMobileOrEmail" resultType="com.caimei365.user.model.vo.UserLoginVo">
  29. select u.userID as userId,
  30. u.userOrganizeID as organizeId,
  31. u.clubID as clubId,
  32. u.shopID as shopId,
  33. u.serviceProviderId as serviceProviderId,
  34. u.userName as userName,
  35. u.name as name,
  36. u.mobile as mobile,
  37. u.bindMobile as bindMobile,
  38. u.email as email,
  39. u.userPermission as userPermission,
  40. u.userIdentity as userIdentity,
  41. u.password as password,
  42. u.guideFlag as guideFlag,
  43. u.clubStatus as clubStatus,
  44. u.manufacturerStatus as shopStatus,
  45. cu.id as operationId,
  46. cu.status as operationStatus,
  47. cu.mobile as operationMobile
  48. from user u
  49. left join cm_mall_operation_user cu on cu.userID = u.userID
  50. where (u.bindMobile = #{mobileOrEmail} or u.email = #{mobileOrEmail})
  51. and u.userIdentity in (1, 2, 3, 4)
  52. # and u.userOrganizeID = 0
  53. union
  54. SELECT u.userID AS userId,
  55. u.userOrganizeID as organizeId,
  56. u.clubID AS clubId,
  57. u.shopID AS shopId,
  58. u.serviceProviderId AS serviceProviderId,
  59. u.userName AS userName,
  60. u.name AS NAME,
  61. u.mobile AS mobile,
  62. u.bindMobile AS bindMobile,
  63. u.email AS email,
  64. u.userPermission AS userPermission,
  65. u.userIdentity AS userIdentity,
  66. u.password AS PASSWORD,
  67. u.guideFlag AS guideFlag,
  68. u.clubStatus AS clubStatus,
  69. u.manufacturerStatus AS shopStatus,
  70. cu.id AS operationId,
  71. cu.status AS operationStatus,
  72. cu.mobile AS operationMobile
  73. FROM USER u
  74. LEFT JOIN cm_mall_operation_user cu ON cu.userID = u.userID
  75. WHERE
  76. cu.mobile = #{mobileOrEmail}
  77. and cu.delFlag != 1
  78. AND u.userIdentity IN (1, 2, 3, 4)
  79. # AND u.userOrganizeID = 0
  80. limit 1
  81. </select>
  82. <select id="getLoginUserByMobile" resultType="com.caimei365.user.model.vo.UserLoginVo">
  83. select u.userID as userId,
  84. u.clubID as clubId,
  85. u.shopID as shopId,
  86. u.serviceProviderId as serviceProviderId,
  87. u.userName as userName,
  88. u.name as name,
  89. u.mobile as mobile,
  90. u.bindMobile as bindMobile,
  91. u.email as email,
  92. u.userPermission as userPermission,
  93. u.userIdentity as userIdentity,
  94. u.password as password,
  95. u.guideFlag as guideFlag,
  96. u.clubStatus as clubStatus,
  97. u.manufacturerStatus as shopStatus,
  98. cu.id as operationId,
  99. cu.status as operationStatus,
  100. cu.mobile as operationMobile
  101. from user u
  102. left join cm_mall_operation_user cu on cu.userID = u.userID
  103. where (u.bindMobile = #{mobile} or (cu.mobile = #{mobile} and cu.delFlag != 1))
  104. and u.userOrganizeID = 0
  105. and u.userIdentity in (1, 2, 3, 4)
  106. limit 1
  107. </select>
  108. <select id="getServiceProviderUserByOpenId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  109. select s.serviceProviderId as serviceProviderId,
  110. s.userID as userId,
  111. u.userName as userName,
  112. u.name as name,
  113. u.mobile as mobile,
  114. u.bindMobile as bindMobile,
  115. u.email as email,
  116. u.userPermission as userPermission,
  117. u.userIdentity as userIdentity,
  118. u.guideFlag as guideFlag,
  119. u.password as password
  120. from serviceprovider s
  121. left join user u on s.userID = u.userID
  122. where s.openid = #{openId}
  123. and u.validFlag = 1
  124. limit 1
  125. </select>
  126. <select id="getServiceProviderByUserId" resultType="com.caimei365.user.model.vo.ServiceProviderVo">
  127. select s.serviceProviderId as serviceProviderId,
  128. s.status as status,
  129. s.userID as userId
  130. from serviceprovider s
  131. where s.userID = #{userId}
  132. limit 1
  133. </select>
  134. <select id="getLoginUserByUnionId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  135. select u.userID as userId,
  136. u.clubID as clubId,
  137. u.shopID as shopId,
  138. u.serviceProviderId as serviceProviderId,
  139. u.userName as userName,u.name as name,
  140. u.mobile as mobile,
  141. u.bindMobile as bindMobile,
  142. u.email as email,
  143. u.userPermission as userPermission,
  144. u.userIdentity as userIdentity,
  145. u.password as password,
  146. u.guideFlag as guideFlag,
  147. u.clubStatus as clubStatus,
  148. u.manufacturerStatus as shopStatus,
  149. o.unionId as unionId,
  150. o.status as operationStatus,
  151. o.mobile as operationMobile,
  152. <if test="source=='www'">
  153. o.pcOpenid as openId
  154. </if>
  155. <if test="source=='mini'">
  156. o.openid as openId
  157. </if>
  158. from user u
  159. left join cm_mall_operation_user o on o.userID = u.userID
  160. where (o.unionId = #{unionId} and o.delFlag = '0')
  161. and (u.userIdentity in (1,2,3,4) and u.userOrganizeID = 0)
  162. limit 1
  163. </select>
  164. <select id="getOrganizeLoginUserByUnionId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  165. select u.userID as userId,
  166. u.clubID as clubId,
  167. u.shopID as shopId,
  168. u.serviceProviderId as serviceProviderId,
  169. u.userName as userName,u.name as name,
  170. u.mobile as mobile,
  171. u.bindMobile as bindMobile,
  172. u.email as email,
  173. u.userPermission as userPermission,
  174. u.userIdentity as userIdentity,
  175. u.password as password,
  176. u.guideFlag as guideFlag,
  177. u.clubStatus as clubStatus,
  178. u.manufacturerStatus as shopStatus,
  179. o.unionId as unionId,
  180. o.status as operationStatus,
  181. o.mobile as operationMobile,
  182. c.headpic AS shopPhoto,
  183. <if test="source=='www'">
  184. o.pcOpenid as openId
  185. </if>
  186. <if test="source=='mini'">
  187. o.openid as openId
  188. </if>
  189. from user u
  190. left join cm_mall_operation_user o on o.userID = u.userID
  191. LEFT JOIN club c ON c.userID = u.userID
  192. where (o.unionId = #{unionId} and o.delFlag = '0')
  193. and (u.userIdentity in (1,2,3,4) and u.userOrganizeID != 0)
  194. limit 1
  195. </select>
  196. <select id="getLoginUserByOpenId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  197. select u.userID as userId,
  198. u.clubID as clubId,
  199. u.shopID as shopId,
  200. u.serviceProviderId as serviceProviderId,
  201. u.userName as userName,u.name as name,
  202. u.mobile as mobile,
  203. u.bindMobile as bindMobile,
  204. u.email as email,
  205. u.userPermission as userPermission,
  206. u.userIdentity as userIdentity,
  207. u.password as password,
  208. u.guideFlag as guideFlag,
  209. u.clubStatus as clubStatus,
  210. u.manufacturerStatus as shopStatus,
  211. o.unionId as unionId,
  212. o.status as operationStatus,
  213. o.mobile as operationMobile,
  214. <if test="source=='www'">
  215. o.pcOpenid as openId
  216. </if>
  217. <if test="source=='mini'">
  218. o.openid as openId
  219. </if>
  220. from user u
  221. left join cm_mall_operation_user o on o.userID = u.userID
  222. where (
  223. <if test="source=='www'">
  224. o.pcOpenid = #{openId}
  225. </if>
  226. <if test="source=='crm'">
  227. o.crmOpenid = #{openId}
  228. </if>
  229. <if test="source=='mini'">
  230. o.openid = #{openId}
  231. </if>
  232. and o.delFlag = '0')
  233. and (u.userIdentity in (1,2,3,4) and u.userOrganizeID = 0)
  234. limit 1
  235. </select>
  236. <select id="getOrganizeLoginUserByOpenId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  237. select u.userID as userId,
  238. u.clubID as clubId,
  239. u.shopID as shopId,
  240. u.serviceProviderId as serviceProviderId,
  241. u.userName as userName,u.name as name,
  242. u.mobile as mobile,
  243. u.bindMobile as bindMobile,
  244. u.email as email,
  245. u.userPermission as userPermission,
  246. u.userIdentity as userIdentity,
  247. u.password as password,
  248. u.guideFlag as guideFlag,
  249. u.clubStatus as clubStatus,
  250. u.manufacturerStatus as shopStatus,
  251. o.unionId as unionId,
  252. o.status as operationStatus,
  253. o.mobile as operationMobile,
  254. c.headpic AS shopPhoto,
  255. <if test="source=='www'">
  256. o.pcOpenid as openId
  257. </if>
  258. <if test="source=='mini'">
  259. o.openid as openId
  260. </if>
  261. from user u
  262. left join cm_mall_operation_user o on o.userID = u.userID
  263. LEFT JOIN club c ON c.userID = u.userID
  264. where (
  265. <if test="source=='www'">
  266. o.pcOpenid = #{openId}
  267. </if>
  268. <if test="source=='crm'">
  269. o.crmOpenid = #{openId}
  270. </if>
  271. <if test="source=='mini'">
  272. o.openid = #{openId}
  273. </if>
  274. and o.delFlag = '0')
  275. and (u.userIdentity in (1,2,3,4) and u.userOrganizeID != 0)
  276. limit 1
  277. </select>
  278. <update id="updateServiceProviderUnionId">
  279. update serviceprovider
  280. set unionId = #{unionId}
  281. where userID = #{userId}
  282. </update>
  283. <update id="updateLogin">
  284. update user
  285. set loginTime = now()
  286. where userID = #{userId}
  287. </update>
  288. <update id="updateLoginFailRecord">
  289. UPDATE cm_loginfail_record
  290. SET delFlag = 1
  291. WHERE loginTime <![CDATA[ > ]]> #{time}
  292. AND userId = #{dbUserId}
  293. </update>
  294. <select id="getUserIdByOpenId" resultType="java.lang.Integer">
  295. select o.userID as userId
  296. from
  297. cm_mall_operation_user o
  298. where
  299. <if test="source=='www'">
  300. pcOpenid = #{openId}
  301. </if>
  302. <if test="source=='mini'">
  303. openid = #{openId}
  304. </if>
  305. and delFlag = '0'
  306. and userOrganizeID=0
  307. limit 1
  308. </select>
  309. <select id="getOperationUserByInvitationCode" resultType="com.caimei365.user.model.vo.UserLoginVo">
  310. SELECT cou.id as operationId,
  311. u.userID as userId,
  312. u.clubID as clubId,
  313. u.shopID as shopId,
  314. u.userName as userName,
  315. u.name as name,
  316. u.userIdentity,
  317. u.guideFlag as guideFlag,
  318. u.clubStatus as clubStatus,
  319. u.manufacturerStatus as shopStatus,
  320. cou.invitationCodeTime,
  321. cou.mobile as operationMobile,
  322. cou.status as operationStatus,
  323. cou.delFlag
  324. FROM cm_mall_operation_user cou
  325. LEFT JOIN user u ON u.userID = cou.userID
  326. WHERE cou.invitationCode = #{invitationCode}
  327. AND cou.userOrganizeID = 0
  328. AND u.userIdentity in (2, 3, 4)
  329. </select>
  330. <select id="getOperationUserByOperationId" resultType="com.caimei365.user.model.vo.UserLoginVo">
  331. SELECT cou.id as operationId,
  332. u.userID as userId,
  333. u.clubID as clubId,
  334. u.shopID as shopId,
  335. u.userName as userName,
  336. u.name as name,
  337. u.userIdentity,
  338. u.guideFlag as guideFlag,
  339. u.clubStatus as clubStatus,
  340. u.manufacturerStatus as shopStatus,
  341. cou.invitationCodeTime,
  342. cou.mobile as operationMobile,
  343. cou.status as operationStatus,
  344. cou.delFlag
  345. FROM cm_mall_operation_user cou
  346. LEFT JOIN user u ON u.userID = cou.userID
  347. WHERE cou.id = #{operationId}
  348. AND cou.userOrganizeID = 0
  349. AND u.userIdentity in (2, 3, 4)
  350. </select>
  351. <select id="getClubCountByClubName" resultType="java.lang.Integer">
  352. SELECT count(*)
  353. FROM club
  354. WHERE name = #{name}
  355. AND status NOT IN (2, 20, 21, 3, 30)
  356. </select>
  357. <select id="getMaxClubId" resultType="java.lang.Integer">
  358. SELECT MAX(clubID)
  359. FROM club
  360. </select>
  361. <select id="getMaxUserId" resultType="java.lang.Integer">
  362. SELECT MAX(userID)
  363. FROM user
  364. </select>
  365. <select id="getClubTypeById" resultType="java.lang.Integer">
  366. SELECT firstClubType
  367. FROM club
  368. WHERE userID = #{userId}
  369. limit 1
  370. </select>
  371. <select id="findLoginFailRecord" resultType="com.caimei365.user.model.vo.LoginFailRecordVo">
  372. select id, loginTime, userId
  373. from cm_loginfail_record
  374. where userId = #{userId}
  375. and loginTime <![CDATA[ > ]]> #{time}
  376. and delFlag = 0
  377. order by loginTime asc
  378. </select>
  379. <select id="findTimes" resultType="java.lang.Integer">
  380. SELECT TIMESTAMPDIFF(MINUTE, loginTime, #{time}) AS times
  381. FROM cm_loginfail_record
  382. WHERE id = #{id}
  383. </select>
  384. </mapper>