CmSpMapper.xml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.CmSpDao">
  4. <sql id="newCmSpColumns">
  5. a.serviceProviderID AS "serviceProviderID",
  6. a.userID AS "userID",
  7. a.name AS "name",
  8. a.linkMan AS "linkMan",
  9. a.contractMobile AS "contractMobile",
  10. a.contractEmail AS "contractEmail",
  11. a.duty AS "duty",
  12. a.status AS "status",
  13. a.addTime AS "addTime",
  14. a.insiderFlag as "insiderFlag"
  15. </sql>
  16. <select id="get" resultType="NewCmSp">
  17. SELECT
  18. <include refid="newCmSpColumns"/>
  19. FROM serviceprovider a
  20. WHERE a.serviceProviderID = #{id}
  21. </select>
  22. <select id="findList" resultType="NewCmSp">
  23. SELECT
  24. <include refid="newCmSpColumns"/>
  25. , c_userTypeName AS "spIdentity", c_serviceProviderStatusName AS "spStatusName"
  26. FROM serviceprovider a
  27. JOIN USER u ON a.userID = u.userID
  28. LEFT JOIN c_usertype c ON a.userID = u.userID and u.registerUserTypeID = c.c_userTypeID
  29. LEFT JOIN c_serviceproviderstatus cs ON a.`status` = cs.c_serviceProviderStatusID
  30. <where>
  31. organizeID = 0
  32. <if test="insiderFlag != null">
  33. AND insiderFlag = #{insiderFlag}
  34. </if>
  35. <if test="serviceProviderID != null and serviceProviderID != ''">
  36. AND a.serviceProviderID = #{serviceProviderID}
  37. </if>
  38. <if test="userID != null and userID != ''">
  39. AND a.userID = #{userID}
  40. </if>
  41. <if test="name != null and name != ''">
  42. AND a.name LIKE
  43. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  44. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  45. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  46. </if>
  47. <if test="contractMobile != null and contractMobile != ''">
  48. AND a.contractMobile = #{contractMobile}
  49. </if>
  50. <if test="linkMan != null and linkMan != ''">
  51. AND a.linkMan LIKE concat('%',#{linkMan},'%')
  52. </if>
  53. <if test="status != null and status != ''">
  54. AND a.status = #{status}
  55. </if>
  56. </where>
  57. <choose>
  58. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  59. ORDER BY ${page.orderBy}
  60. </when>
  61. <otherwise>
  62. ORDER BY a.serviceProviderID DESC
  63. </otherwise>
  64. </choose>
  65. </select>
  66. <select id="findAllList" resultType="NewCmSp">
  67. SELECT
  68. <include refid="newCmSpColumns"/>
  69. FROM serviceprovider a
  70. <where>
  71. </where>
  72. <choose>
  73. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  74. ORDER BY ${page.orderBy}
  75. </when>
  76. <otherwise>
  77. </otherwise>
  78. </choose>
  79. </select>
  80. <insert id="insert" parameterType="NewCmSp" keyProperty="serviceProviderID" useGeneratedKeys="true">
  81. INSERT INTO serviceprovider(
  82. userID,
  83. providerId,
  84. name,
  85. contractMobile,
  86. duty,
  87. contractEmail,
  88. linkMan,
  89. status,
  90. addTime,
  91. insiderFlag
  92. ) VALUES (
  93. #{userID},
  94. #{providerId},
  95. #{name},
  96. #{contractMobile},
  97. #{duty},
  98. #{contractEmail},
  99. #{linkMan},
  100. #{status},
  101. #{addTime},
  102. #{insiderFlag}
  103. )
  104. </insert>
  105. <update id="update">
  106. UPDATE serviceprovider SET
  107. userID = #{userID},
  108. providerId = if(#{insiderFlag} = 1,#{providerId},null),
  109. organizeID = 0,
  110. name = #{name},
  111. contractPhone = #{contractPhone},
  112. contractMobile = #{contractMobile},
  113. contractEmail = #{contractEmail},
  114. linkMan = #{linkMan},
  115. duty = #{duty},
  116. status = #{status},
  117. addTime = #{addTime},
  118. insiderFlag = #{insiderFlag}
  119. WHERE serviceProviderID = #{serviceProviderID}
  120. </update>
  121. <delete id="delete">
  122. DELETE FROM serviceprovider
  123. WHERE serviceProviderID = #{serviceProviderID}
  124. </delete>
  125. <delete id="deleteManager">
  126. DELETE FROM cm_serviceteam_manager
  127. </delete>
  128. <select id="findSpManager" resultType="com.caimei.modules.user.entity.NewCmSp">
  129. select
  130. <include refid="newCmSpColumns"/>
  131. FROM serviceprovider a
  132. JOIN user u on a.userID = u.userID
  133. where u.registerUserTypeID = 2
  134. </select>
  135. <select id="findSpUserLoginSum" resultType="java.util.HashMap" parameterType="string">
  136. select
  137. COUNT( CASE WHEN a.time=1 THEN 1 END) AS loginSum,
  138. ((SELECT count(1) from club
  139. WHERE status=90
  140. <if test="spID != null">
  141. and spID=#{spID}
  142. </if>
  143. )-COUNT( CASE WHEN a.time=1 THEN 1 END)) AS not_loginSum
  144. FROM (select a.*
  145. FROM ((
  146. select
  147. c.clubId,1 AS time,c.spID
  148. FROM club c
  149. LEFT JOIN user u ON u.userID = c.userID
  150. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = c.spID
  151. where c.status=90 and sp.status=90 and (u.userOrganizeID IN(0,1) or u.clubStatus != 92) and u.userOrganizeID != 4
  152. and u.loginTime >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
  153. GROUP BY c.clubId
  154. )UNION(
  155. select
  156. c.clubId,1 AS time,c.spID
  157. FROM club c
  158. LEFT JOIN user u ON u.userID = c.userID
  159. LEFT JOIN cm_club_remarks ccr ON ccr.clubId = c.clubId
  160. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = c.spID
  161. where c.status=90 and sp.status=90 and (u.userOrganizeID IN(0,1) or u.clubStatus != 92) and u.userOrganizeID != 4
  162. and ccr.addTime >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
  163. GROUP BY c.clubId
  164. )UNION(
  165. select c.clubId,1 AS time,c.spID
  166. FROM club c
  167. LEFT JOIN user u ON u.userID = c.userID
  168. LEFT JOIN cm_order cr ON cr.clubId = c.clubId
  169. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = c.spID
  170. where c.status=90 and sp.status=90 and (u.userOrganizeID IN(0,1) or u.clubStatus != 92) and u.userOrganizeID != 4
  171. and cr.orderTime >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
  172. GROUP BY c.clubId
  173. )
  174. ) a where 1=1
  175. <if test="spID != null">
  176. and a.spID=#{spID}
  177. </if>
  178. GROUP BY a.clubId ) a
  179. </select>
  180. <select id="findSelectList" resultType="com.caimei.modules.user.entity.NewCmSp">
  181. SELECT
  182. <include refid="newCmSpColumns"/>
  183. , c_userTypeName AS "spIdentity", c_serviceProviderStatusName AS "spStatusName"
  184. FROM serviceprovider a
  185. JOIN USER u ON a.userID = u.userID
  186. LEFT JOIN c_usertype c ON a.userID = u.userID and u.registerUserTypeID = c.c_userTypeID
  187. LEFT JOIN c_serviceproviderstatus cs ON a.`status` = cs.c_serviceProviderStatusID
  188. <where>
  189. a.organizeId = 0
  190. <if test="status != null and status != ''">
  191. AND a.status = #{status}
  192. </if>
  193. <if test="contractMobile != null and contractMobile != ''">
  194. AND a.contractMobile = #{contractMobile}
  195. </if>
  196. <if test="linkMan != null and linkMan != ''">
  197. AND a.linkMan LIKE concat('%',#{linkMan},'%')
  198. </if>
  199. </where>
  200. <choose>
  201. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  202. ORDER BY ${page.orderBy}
  203. </when>
  204. <otherwise>
  205. ORDER BY a.serviceProviderID DESC
  206. </otherwise>
  207. </choose>
  208. </select>
  209. <insert id="choseManager">
  210. insert into cm_serviceteam_manager (serviceProviderId,delflag)
  211. values (#{serviceProviderID},0)
  212. </insert>
  213. <select id="findByUserId" resultType="com.caimei.modules.user.entity.NewCmSp">
  214. SELECT
  215. <include refid="newCmSpColumns"/>
  216. FROM serviceprovider a
  217. WHERE a.userID = #{userId}
  218. </select>
  219. <select id="findTeam" resultType="com.caimei.modules.user.entity.CmSaleMan">
  220. select csr.leaderId,s.name as leaderName
  221. from cm_serviceteam_role csr
  222. left join serviceprovider s on csr.leaderId = s.serviceProviderID
  223. where csr.delflag = 0
  224. </select>
  225. <select id="findManagerInfo" resultType="com.caimei.modules.user.entity.NewCmSp">
  226. select csm.serviceProviderId as serviceProviderID,s.name
  227. from cm_serviceteam_manager csm
  228. left join serviceprovider s on csm.serviceProviderId=s.serviceProviderID
  229. </select>
  230. <select id="getSpClubActive" resultType="java.util.Map">
  231. SELECT
  232. COUNT(c.clubId) as number,
  233. coas.activeStatus as activeStatus
  234. FROM serviceprovider s
  235. LEFT JOIN club c ON c.spID = s.serviceProviderID
  236. LEFT JOIN cm_organ_active_system coas ON coas.userId = c.userId
  237. WHERE coas.stage = 0 and s.status = 90 and s.serviceProviderID = #{serviceProviderID}
  238. GROUP BY coas.activeStatus
  239. </select>
  240. <select id="findProviders" resultType="com.caimei.modules.user.entity.CmProvider">
  241. select id,name
  242. from cm_providers
  243. where status = 90
  244. </select>
  245. </mapper>