NewCmClubMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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.NewCmClubDao">
  4. <sql id="newCmClubColumns">
  5. a.checkMan as "checkMan",
  6. a.clubID AS "clubID",
  7. a.userID AS "userID",
  8. u.name AS "name",
  9. a.sname AS "sname",
  10. a.logo AS "logo",
  11. a.legalPerson AS "legalPerson",
  12. a.provinceID AS "provinceID",
  13. a.cityID AS "cityID",
  14. a.townID AS "townID",
  15. a.flag AS "flag",
  16. a.inviterBindID AS "inviterBindID",
  17. a.inviterName AS "inviterName",
  18. a.spID AS "spID",
  19. a.mainServiceProviderID AS "mainServiceProviderID",
  20. a.scanTime AS "scanTime",
  21. a.address AS "address",
  22. a.linkMan AS "linkMan",
  23. a.linkManIdentity AS "linkManIdentity",
  24. a.contractPhone AS "contractPhone",
  25. a.contractMobile AS "contractMobile",
  26. a.contractEmail AS "contractEmail",
  27. a.fax AS "fax",
  28. a.info AS "info",
  29. a.addTime AS "addTime",
  30. a.auditTime AS "auditTime",
  31. a.auditNote AS "auditNote",
  32. a.status AS "status",
  33. a.businessLicenseImage AS "businessLicenseImage",
  34. a.defaultServiceProviderID AS "defaultServiceProviderID",
  35. a.defaultServiceProviderUpdTime AS "defaultServiceProviderUpdTime",
  36. a.mainpro AS "mainpro",
  37. a.scanFlag AS "scanFlag",
  38. a.headpic AS "headpic",
  39. a.socialCreditCode AS "socialCreditCode",
  40. a.lastModify AS "lastModify",
  41. a.firstClubType AS "firstClubType",
  42. a.secondClubType AS "secondClubType",
  43. a.department AS "department",
  44. a.medicalPracticeLicenseImg AS "medicalPracticeLicenseImg"
  45. </sql>
  46. <sql id="otherColumns">
  47. ,case sp.status when 91 then '采美默认协销经理(官方账号)' else sp.linkMan end AS "spName",
  48. d.name AS "province",
  49. c.name AS "city",
  50. b.name AS "town",
  51. u.account AS "account",
  52. u.registerTime AS "registerTime",
  53. u.registerIP AS "registerIP",
  54. u.userName AS "userName",
  55. u.bindMobile AS "bindMobile",
  56. u.email AS "email",
  57. u.userOrganizeID AS "userOrganizeID",
  58. u.userIdentity AS "userIdentity",
  59. if(csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime,1,0) as svipUserFlag
  60. </sql>
  61. <sql id="newCmClubJoins">
  62. LEFT JOIN user u ON u.userID = a.userID
  63. LEFT JOIN cm_svip_user csu ON csu.userId = u.userID
  64. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = a.spID
  65. LEFT JOIN town b ON b.townID=a.townID
  66. LEFT JOIN city c ON c.cityID=b.cityID
  67. LEFT JOIN province d ON d.provinceID=c.provinceID
  68. </sql>
  69. <select id="get" resultType="NewCmClub">
  70. SELECT
  71. <include refid="newCmClubColumns"/>
  72. <include refid="otherColumns"/>
  73. FROM club a
  74. <include refid="newCmClubJoins"/>
  75. WHERE a.clubID = #{id}
  76. </select>
  77. <select id="getclubByUserId" resultType="NewCmClub">
  78. SELECT
  79. <include refid="newCmClubColumns"/>
  80. FROM club a
  81. <include refid="newCmClubJoins"/>
  82. WHERE a.userID = #{userID}
  83. </select>
  84. <select id="findList" resultType="NewCmClub">
  85. SELECT
  86. <include refid="newCmClubColumns"/>
  87. <include refid="otherColumns"/>,u.userPermission,u.source
  88. FROM club a
  89. <include refid="newCmClubJoins"/>
  90. <where>
  91. <if test="clubID != null and clubID != ''">
  92. AND a.clubID = #{clubID}
  93. </if>
  94. <if test="userID != null and userID != ''">
  95. AND a.userID = #{userID}
  96. </if>
  97. <if test="account != null and account != ''">
  98. AND u.account = #{account}
  99. </if>
  100. <if test="name != null and name != ''">
  101. AND u.name LIKE concat('%',#{name},'%')
  102. </if>
  103. <if test="userName != null and userName != ''">
  104. AND u.userName LIKE concat('%',#{userName},'%')
  105. </if>
  106. <if test="townID != null and townID != ''">
  107. AND d.provinceID = #{provinceID}
  108. </if>
  109. <if test="cityID != null and cityID != ''">
  110. AND c.cityID = #{cityID}
  111. </if>
  112. <if test="townID != null and townID != ''">
  113. AND b.townID = #{townID}
  114. </if>
  115. <if test="status != null and status != ''">
  116. AND a.status = #{status}
  117. </if>
  118. <if test="bindMobile != null and bindMobile != ''">
  119. AND u.bindMobile LIKE concat('%',#{bindMobile},'%')
  120. </if>
  121. <if test="email != null and email != ''">
  122. AND u.email LIKE concat('%',#{email},'%')
  123. </if>
  124. <if test="linkMan != null and linkMan != ''">
  125. AND a.linkMan LIKE concat('%',#{linkMan},'%')
  126. </if>
  127. <if test="startTime != null and startTime != ''">
  128. AND (u.registerTime &gt; #{startTime} OR u.registerTime = #{startTime})
  129. </if>
  130. <if test="endTime != null and endTime != ''">
  131. AND (u.registerTime &lt; #{endTime} OR u.registerTime = #{endTime})
  132. </if>
  133. <if test="userIdentity != null and userIdentity != '' and userIdentity != '8'.toString()">
  134. AND u.userIdentity = #{userIdentity}
  135. </if>
  136. <if test="userIdentity != null and userIdentity != '' and userIdentity == '8'.toString()">
  137. AND csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
  138. </if>
  139. AND (u.userOrganizeID IN(0,1) or u.clubStatus != 92)
  140. </where>
  141. <choose>
  142. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  143. ORDER BY ${page.orderBy}
  144. </when>
  145. <otherwise>
  146. ORDER BY case when a.status = 91 then 0 else 1 end desc, a.addTime DESC
  147. </otherwise>
  148. </choose>
  149. </select>
  150. <select id="findAllList" resultType="NewCmClub">
  151. SELECT
  152. <include refid="newCmClubColumns"/>
  153. <include refid="otherColumns"/>
  154. FROM club a
  155. <include refid="newCmClubJoins"/>
  156. <where>
  157. </where>
  158. <choose>
  159. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  160. ORDER BY ${page.orderBy}
  161. </when>
  162. <otherwise>
  163. </otherwise>
  164. </choose>
  165. </select>
  166. <insert id="insert" parameterType="NewCmClub" keyProperty="clubID" useGeneratedKeys="true">
  167. INSERT INTO club(userID,
  168. name,
  169. sname,
  170. logo,
  171. legalPerson,
  172. provinceID,
  173. cityID,
  174. townID,
  175. flag,
  176. inviterBindID,
  177. inviterName,
  178. spID,
  179. mainServiceProviderID,
  180. scanTime,
  181. address,
  182. linkMan,
  183. linkManIdentity,
  184. contractPhone,
  185. contractMobile,
  186. contractEmail,
  187. fax,
  188. info,
  189. addTime,
  190. auditTime,
  191. auditNote,
  192. status,
  193. businessLicenseImage,
  194. defaultServiceProviderID,
  195. defaultServiceProviderUpdTime,
  196. mainpro,
  197. scanFlag,
  198. headpic,
  199. lastModify,
  200. firstClubType,
  201. socialCreditCode,
  202. secondClubType,
  203. department,
  204. medicalPracticeLicenseImg)
  205. VALUES (#{userID},
  206. #{name},
  207. #{sname},
  208. #{logo},
  209. #{legalPerson},
  210. #{provinceID},
  211. #{cityID},
  212. #{townID},
  213. #{flag},
  214. #{inviterBindID},
  215. #{inviterName},
  216. #{spID},
  217. #{mainServiceProviderID},
  218. #{scanTime},
  219. #{address},
  220. #{linkMan},
  221. #{linkManIdentity},
  222. #{contractPhone},
  223. #{contractMobile},
  224. #{contractEmail},
  225. #{fax},
  226. #{info},
  227. #{addTime},
  228. #{auditTime},
  229. #{auditNote},
  230. #{status},
  231. #{businessLicenseImage},
  232. #{defaultServiceProviderID},
  233. #{defaultServiceProviderUpdTime},
  234. #{mainpro},
  235. #{scanFlag},
  236. #{headpic},
  237. #{lastModify},
  238. #{firstClubType},
  239. #{socialCreditCode},
  240. #{secondClubType},
  241. #{department},
  242. #{medicalPracticeLicenseImg})
  243. </insert>
  244. <update id="update">
  245. UPDATE club SET
  246. <if test="checkMan != null and checkMan != ''">
  247. checkMan = #{checkMan},
  248. </if>
  249. <if test="name != null and name != ''">
  250. name = #{name},
  251. </if>
  252. <if test="sname != null">
  253. sname = #{sname},
  254. </if>
  255. <if test="logo != null and logo != ''">
  256. logo = #{logo},
  257. </if>
  258. <if test="legalPerson != null and legalPerson != ''">
  259. legalPerson = #{legalPerson},
  260. </if>
  261. <if test="provinceID != null and provinceID != ''">
  262. provinceID = #{provinceID},
  263. </if>
  264. <if test="cityID != null and cityID != ''">
  265. cityID = #{cityID},
  266. </if>
  267. <if test="townID != null and townID != ''">
  268. townID = #{townID},
  269. </if>
  270. <if test="flag != null and flag != ''">
  271. flag = #{flag},
  272. </if>
  273. <if test="inviterBindID != null and inviterBindID != ''">
  274. inviterBindID = #{inviterBindID},
  275. </if>
  276. <if test="inviterName != null and inviterName != ''">
  277. inviterName = #{inviterName},
  278. </if>
  279. <if test="spID != null and spID != ''">
  280. spID = #{spID},
  281. </if>
  282. <if test="mainServiceProviderID != null and mainServiceProviderID != ''">
  283. mainServiceProviderID = #{mainServiceProviderID},
  284. </if>
  285. <if test="scanTime != null">
  286. scanTime = #{scanTime},
  287. </if>
  288. <if test="address != null and address != ''">
  289. address = #{address},
  290. </if>
  291. <if test="linkMan != null and linkMan != ''">
  292. linkMan = #{linkMan},
  293. </if>
  294. <if test="linkManIdentity != null and linkManIdentity != ''">
  295. linkManIdentity = #{linkManIdentity},
  296. </if>
  297. <if test="contractPhone != null and contractPhone != ''">
  298. contractPhone = #{contractPhone},
  299. </if>
  300. <if test="contractMobile != null and contractMobile != ''">
  301. contractMobile = #{contractMobile},
  302. </if>
  303. <if test="contractEmail != null and contractEmail != ''">
  304. contractEmail = #{contractEmail},
  305. </if>
  306. <if test="fax != null and fax != ''">
  307. fax = #{fax},
  308. </if>
  309. <if test="info != null and info != ''">
  310. info = #{info},
  311. </if>
  312. <if test="addTime != null">
  313. addTime = #{addTime},
  314. </if>
  315. <if test="auditTime != null">
  316. auditTime = #{auditTime},
  317. </if>
  318. <if test="auditNote != null and auditNote != ''">
  319. auditNote = #{auditNote},
  320. </if>
  321. <if test="status != null and status != ''">
  322. status = #{status},
  323. </if>
  324. <if test="businessLicenseImage != null">
  325. businessLicenseImage = #{businessLicenseImage},
  326. </if>
  327. <if test="socialCreditCode != null and socialCreditCode != ''">
  328. socialCreditCode = #{socialCreditCode},
  329. </if>
  330. <if test="defaultServiceProviderID != null and defaultServiceProviderID != ''">
  331. defaultServiceProviderID = #{defaultServiceProviderID},
  332. </if>
  333. <if test="defaultServiceProviderUpdTime != null and defaultServiceProviderUpdTime != ''">
  334. defaultServiceProviderUpdTime = #{defaultServiceProviderUpdTime},
  335. </if>
  336. <if test="mainpro != null and mainpro != ''">
  337. mainpro = #{mainpro},
  338. </if>
  339. <if test="scanFlag != null and scanFlag != ''">
  340. scanFlag = #{scanFlag},
  341. </if>
  342. <if test="headpic != null">
  343. headpic = #{headpic},
  344. </if>
  345. <if test="lastModify != null and lastModify != ''">
  346. lastModify = DATE_FORMAT(#{lastModify},'%Y-%m-%d %H:%i:%s'),
  347. </if>
  348. <if test="firstClubType != null and firstClubType != ''">
  349. firstClubType=#{firstClubType},
  350. </if>
  351. <if test="secondClubType != null and secondClubType != ''">
  352. secondClubType=#{secondClubType},
  353. </if>
  354. <if test="department != null and department != ''">
  355. department=#{department},
  356. </if>
  357. <if test="medicalPracticeLicenseImg != null and medicalPracticeLicenseImg != ''">
  358. medicalPracticeLicenseImg=#{medicalPracticeLicenseImg},
  359. </if>
  360. userID = #{userID}
  361. WHERE clubID = #{clubID}
  362. </update>
  363. <delete id="delete">
  364. DELETE
  365. FROM club
  366. WHERE clubID = #{clubID}
  367. </delete>
  368. <select id="findClubById" resultType="NewCmClub">
  369. SELECT
  370. <include refid="newCmClubColumns"/>
  371. , CONCAT(d.name,c.name ,b.name ,a.`address` ) address
  372. FROM club a
  373. LEFT JOIN user u ON u.userID = a.userID
  374. LEFT JOIN town b ON a.townID =b.townID
  375. LEFT JOIN city c ON b.cityID=c.cityID
  376. JOIN province d ON c.`provinceID` =d.`provinceID`
  377. WHERE a.clubID=#{clubID}
  378. </select>
  379. <select id="findSpId" resultType="java.lang.Integer">
  380. select serviceProviderID
  381. from serviceprovider
  382. where serviceProviderID = #{spID}
  383. and status = 90
  384. </select>
  385. <select id="findRemarksList" resultType="com.caimei.modules.user.entity.CmClubRemarks">
  386. select DISTINCT ccr.id as remarksId,
  387. remarks,
  388. s.linkMan as spName,
  389. ccr.addTime,
  390. ccr.questionMan,
  391. ccr.consultType as consult,ccr.clubType,ccr.pinceSensitve,ccr.satisfied,ccr.followup,ccr.extra,
  392. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID = csr.leaderId) AS leaderName
  393. from cm_club_remarks ccr
  394. left join serviceprovider s on ccr.serviceProviderId = s.serviceProviderID
  395. LEFT JOIN cm_serviceteam_group csg ON ccr.serviceProviderId = csg.serviceId
  396. LEFT JOIN cm_serviceteam_role csr ON csr.id = csg.teamId
  397. where clubId = #{clubId}
  398. order by addTime desc
  399. </select>
  400. <select id="getRemarksImageList" resultType="java.lang.String">
  401. select imageUrl
  402. from cm_club_remarks_file
  403. where remarksId = #{remarksId}
  404. and fileType = 1
  405. </select>
  406. <select id="getRemarksFileList" resultType="com.caimei.modules.user.entity.RemarksFileVo">
  407. select fileName, ossName
  408. from cm_club_remarks_file
  409. where remarksId = #{remarksId}
  410. and fileType = 2
  411. </select>
  412. <insert id="insertBeansHistory">
  413. INSERT INTO `user_beans_history` (`userId`, `type`, `beansType`, `orderId`,
  414. `num`, `pushStatus`, `addTime`, delFlag)
  415. VALUES (#{userId}, #{type}, #{beansType}, #{orderId},
  416. #{num}, #{pushStatus}, #{addTime}, 0)
  417. </insert>
  418. <update id="updateByStatus">
  419. UPDATE club
  420. SET status = #{clubStatus}
  421. WHERE userID = #{confirmUserId}
  422. </update>
  423. <select id="findLowOrder" resultType="com.caimei.modules.user.entity.UserBeansHistory">
  424. select userId, type, beansType, orderId, num, addTime
  425. from user_beans_history
  426. where orderId = #{orderId}
  427. and delFlag = 0
  428. and type = 2
  429. and num = 500
  430. </select>
  431. <select id="findRegistList" resultType="com.caimei.modules.user.entity.CmClubRemarks">
  432. SELECT DISTINCT
  433. ccr.id AS remarksId, ccr.remarks,s.linkman AS spName, ccr.addTime,ccr.questionMan,
  434. csr.leaderId AS leaderId,ifnull(ccr.consultType,'') as consult, c.Name as
  435. clubName,ccr.clubType,ccr.pinceSensitve,ccr.satisfied,ccr.followup,ccr.extra,
  436. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID= csr.leaderId) AS leaderName,
  437. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID= ccr.oldserviceProviderId) AS oldName
  438. FROM cm_club_remarks ccr
  439. LEFT JOIN serviceprovider s ON ccr.serviceProviderId = s.serviceProviderID
  440. # LEFT JOIN serviceprovider s ON ccr.serviceProviderId = s.serviceProviderID
  441. LEFT JOIN club c ON c.clubId=ccr.clubId
  442. LEFT JOIN cm_serviceTeam_group csg ON ccr.serviceProviderId = csg.serviceId
  443. LEFT JOIN cm_serviceTeam_role csr ON csr.id = csg.teamId
  444. <where>
  445. <if test="remarks != null and remarks !=''">
  446. AND ccr.remarks LIKE concat('%',#{remarks},'%')
  447. </if>
  448. <if test="clubName !=null and clubName !=''">
  449. AND c.Name like concat('%',#{clubName},'%')
  450. </if>
  451. <if test="leaderId != null">
  452. and csr.leaderId = #{leaderId}
  453. </if>
  454. <if test="serviceProviderId != null">
  455. and csg.serviceId = #{serviceProviderId}
  456. </if>
  457. <if test="startAddTime != null and startAddTime != ''">
  458. and ccr.addTime <![CDATA[ > ]]> #{startAddTime}
  459. </if>
  460. <if test="endAddTime != null and endAddTime != ''">
  461. and ccr.addTime <![CDATA[ < ]]> #{endAddTime}
  462. </if>
  463. </where>
  464. ORDER BY ADDTIME DESC
  465. <choose>
  466. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  467. ORDER BY ${page.orderBy}
  468. </when>
  469. </choose>
  470. </select>
  471. <select id="findConsults" resultType="com.caimei.modules.consult.entity.type.CmConsulttype">
  472. select id, className, createdTime
  473. from cm_consulttype
  474. where delflag = 0
  475. </select>
  476. <select id="findTeams" resultType="com.caimei.modules.user.entity.CmSaleMan">
  477. select csr.leaderId, s.name as leaderName
  478. from cm_serviceteam_role csr
  479. left join serviceprovider s on s.serviceProviderID = csr.leaderId
  480. where csr.delflag = 0
  481. </select>
  482. <select id="findGroup" resultType="com.caimei.modules.project.model.ServiceProviderModel">
  483. SELECT serviceId as serviceProviderID, s.name
  484. FROM cm_serviceteam_group csg
  485. LEFT JOIN cm_serviceTeam_role csr ON csr.id = csg.teamid
  486. LEFT JOIN serviceprovider s ON s.serviceProviderID = csg.serviceId
  487. WHERE csr.leaderId = #{leaderId}
  488. </select>
  489. <select id="findClassName" resultType="java.lang.String">
  490. select className
  491. from cm_consulttype
  492. where id = #{string}
  493. </select>
  494. <delete id="deleteRamarks">
  495. DELETE
  496. FROM `cm_remarks`
  497. WHERE remarksId = #{remarksId}
  498. </delete>
  499. <insert id="addRemarks">
  500. INSERT INTO `cm_remarks`(remarks, `addtime`)
  501. VALUES (#{remarks}, #{addtime})
  502. </insert>
  503. <update id="upremarks">
  504. UPDATE `cm_remarks`
  505. SET remarks = #{remarks}
  506. WHERE remarksId = #{remarksId}
  507. </update>
  508. <select id="upremakasList" resultType="java.lang.String">
  509. SELECT remarks
  510. FROM `cm_remarks`
  511. WHERE remarksId = #{remarksId}
  512. </select>
  513. <select id="ClubsIds" resultType="java.lang.Integer">
  514. select oldserviceProviderId
  515. FROM `cm_club_remarks`
  516. WHERE clubId = #{clubID}
  517. </select>
  518. <!-- <insert id="oldname">-->
  519. <!-- INSERT INTO `cm_old_remarks`(serviceProviderId, `serviceProviderName`)-->
  520. <!-- VALUES (#{serviceProviderId}, #{serviceProviderName})-->
  521. <!-- </insert>-->
  522. <update id="oldname">
  523. UPDATE `cm_club_remarks`
  524. SET oldserviceProviderId = #{oldserviceProviderId},
  525. serviceProviderId=#{newSpID}
  526. WHERE clubId = #{clubID}
  527. AND serviceProviderId=#{oldSpID}
  528. </update>
  529. <update id="oldnames">
  530. UPDATE `cm_club_remarks`
  531. SET serviceProviderId=#{newSpID}
  532. WHERE clubId = #{clubID}
  533. AND serviceProviderId=#{oldSpID}
  534. </update>
  535. </mapper>