LawFirmMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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="shop.alien.mapper.LawFirmMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="shop.alien.entity.store.LawFirm">
  6. <id column="id" property="id" />
  7. <result column="firm_name" property="firmName" />
  8. <result column="credit_code" property="creditCode" />
  9. <result column="short_name" property="shortName" />
  10. <result column="english_name" property="englishName" />
  11. <result column="establishment_date" property="establishmentDate" />
  12. <result column="firm_type" property="firmType" />
  13. <result column="firm_scale" property="firmScale" />
  14. <result column="phone" property="phone" />
  15. <result column="fax" property="fax" />
  16. <result column="email" property="email" />
  17. <result column="website" property="website" />
  18. <result column="introduction" property="introduction" />
  19. <result column="logo" property="logo" />
  20. <result column="business_license_image" property="businessLicenseImage" />
  21. <result column="practice_license_no" property="practiceLicenseNo" />
  22. <result column="practice_license_image" property="practiceLicenseImage" />
  23. <result column="director_name" property="directorName" />
  24. <result column="director_phone" property="directorPhone" />
  25. <result column="director_email" property="directorEmail" />
  26. <result column="lawyer_count" property="lawyerCount" />
  27. <result column="partner_count" property="partnerCount" />
  28. <result column="status" property="status" />
  29. <result column="certification_status" property="certificationStatus" />
  30. <result column="certification_fail_reason" property="certificationFailReason" />
  31. <result column="certification_time" property="certificationTime" />
  32. <result column="certification_reviewer_id" property="certificationReviewerId" />
  33. <result column="is_recommended" property="isRecommended" />
  34. <result column="recommend_sort" property="recommendSort" />
  35. <result column="delete_flag" property="deleteFlag" />
  36. <result column="created_time" property="createdTime" />
  37. <result column="created_user_id" property="createdUserId" />
  38. <result column="updated_time" property="updatedTime" />
  39. <result column="updated_user_id" property="updatedUserId" />
  40. <result column="remark" property="remark" />
  41. </resultMap>
  42. <!-- 通用查询结果列 -->
  43. <sql id="Base_Column_List">
  44. id, firm_name, credit_code, short_name, english_name, establishment_date, firm_type, firm_scale,
  45. phone, fax, email, website, introduction, logo,
  46. business_license_image, practice_license_no, practice_license_image, director_name, director_phone,
  47. director_email, lawyer_count, partner_count, status, certification_status, certification_fail_reason,
  48. certification_time, certification_reviewer_id, is_recommended, recommend_sort, delete_flag,
  49. created_time, created_user_id, updated_time, updated_user_id, remark, platform_commission_ratio
  50. </sql>
  51. <!-- 订单查询公共条件 -->
  52. <sql id="Order_Common_Where">
  53. lco.delete_flag = 0
  54. AND lco.order_status = 3
  55. <if test="startDate != null">
  56. AND lco.order_time &gt;= CONCAT(#{startDate}, ' 00:00:00')
  57. </if>
  58. <if test="endDate != null">
  59. AND lco.order_time &lt;= CONCAT(#{endDate}, ' 23:59:59')
  60. </if>
  61. </sql>
  62. <!-- 查询律所对账统计信息 -->
  63. <select id="getLawFirmReconciliationStatistics" resultType="java.util.HashMap">
  64. <choose>
  65. <when test="firmId != null">
  66. <!-- 指定律所ID时,从律所表开始,确保即使没有订单也返回 -->
  67. SELECT
  68. COUNT(DISTINCT lco.id) as order_count,
  69. COALESCE(SUM(lco.lawyer_earnings), 0) as total_amount,
  70. COALESCE(SUM(lco.consultation_fee), 0) as total_platform_service_fee
  71. FROM law_firm lf
  72. LEFT JOIN lawyer_consultation_order lco ON lco.place_id = lf.id
  73. AND lco.delete_flag = 0
  74. AND lco.order_status = 3
  75. <if test="startDate != null">
  76. AND lco.order_time &gt;= CONCAT(#{startDate}, ' 00:00:00')
  77. </if>
  78. <if test="endDate != null">
  79. AND lco.order_time &lt;= CONCAT(#{endDate}, ' 23:59:59')
  80. </if>
  81. WHERE lf.delete_flag = 0
  82. AND lf.id = #{firmId}
  83. </when>
  84. <otherwise>
  85. <!-- 未指定律所ID时,从订单表开始 -->
  86. SELECT
  87. COUNT(DISTINCT lco.id) as order_count,
  88. COALESCE(SUM(lco.lawyer_earnings), 0) as total_amount,
  89. COALESCE(SUM(lco.consultation_fee), 0) as total_platform_service_fee
  90. FROM lawyer_consultation_order lco
  91. LEFT JOIN law_firm lf ON lco.place_id = lf.id
  92. AND lf.delete_flag = 0
  93. WHERE
  94. <include refid="Order_Common_Where"/>
  95. <if test="firmName != null and firmName != ''">
  96. AND lf.firm_name LIKE CONCAT('%', #{firmName}, '%')
  97. </if>
  98. </otherwise>
  99. </choose>
  100. </select>
  101. <!-- 查询所有律所的对账统计信息(按律所分组) -->
  102. <resultMap id="LawFirmReconciliationStatisticsResultMap" type="shop.alien.entity.store.vo.LawFirmListVO">
  103. <result column="firm_id" property="firmId" />
  104. <result column="firm_name" property="firmName" />
  105. <result column="order_count" property="totalOrderCount" />
  106. <result column="total_amount_yuan" property="totalOrderAmountYuan" jdbcType="VARCHAR" />
  107. <result column="commission_fee_yuan" property="platformServiceFeeYuan" jdbcType="VARCHAR" />
  108. </resultMap>
  109. <!-- 查询律所下所有律师的对账统计信息(按律师分组) -->
  110. <resultMap id="LawyerReconciliationStatisticsResultMap" type="shop.alien.entity.store.vo.LawyerListVO">
  111. <result column="lawyer_id" property="lawyerId" />
  112. <result column="lawyer_name" property="lawyerName" />
  113. <result column="head_img" property="headImg" />
  114. <result column="lawyer_certificate_no" property="lawyerCertificateNo" />
  115. <result column="firm_id" property="firmId" />
  116. <result column="firm_name" property="firmName" />
  117. <result column="order_count" property="totalOrderCount" />
  118. <result column="total_amount_yuan" property="totalOrderAmountYuan" jdbcType="VARCHAR" />
  119. <result column="commission_fee_yuan" property="platformServiceFeeYuan" jdbcType="VARCHAR" />
  120. </resultMap>
  121. <select id="getAllLawFirmReconciliationStatistics" resultMap="LawFirmReconciliationStatisticsResultMap">
  122. SELECT
  123. lf.id as firm_id,
  124. lf.firm_name,
  125. COUNT(DISTINCT lco.id) as order_count,
  126. CAST(ROUND(COALESCE(SUM(lco.lawyer_earnings), 0) / 100.0, 2) AS CHAR) as total_amount_yuan,
  127. CAST(ROUND(COALESCE(SUM(lco.consultation_fee), 0) / 100.0, 2) AS CHAR) as commission_fee_yuan
  128. FROM law_firm lf
  129. LEFT JOIN lawyer_consultation_order lco ON lco.place_id = lf.id
  130. AND lco.delete_flag = 0
  131. AND lco.order_status = 3
  132. <if test="startDate != null">
  133. AND lco.order_time &gt;= CONCAT(#{startDate}, ' 00:00:00')
  134. </if>
  135. <if test="endDate != null">
  136. AND lco.order_time &lt;= CONCAT(#{endDate}, ' 23:59:59')
  137. </if>
  138. WHERE lf.delete_flag = 0
  139. <if test="firmName != null and firmName != ''">
  140. AND lf.firm_name LIKE CONCAT('%', #{firmName}, '%')
  141. </if>
  142. GROUP BY lf.id, lf.firm_name
  143. ORDER BY COALESCE(SUM(lco.lawyer_earnings), 0) DESC
  144. </select>
  145. <!-- 查询律所下所有律师的对账统计信息(按律师分组) -->
  146. <select id="getLawyerReconciliationStatistics" resultMap="LawyerReconciliationStatisticsResultMap">
  147. SELECT
  148. lu.id as lawyer_id,
  149. lu.name as lawyer_name,
  150. lu.head_img,
  151. lu.lawyer_certificate_no,
  152. lf.id as firm_id,
  153. lf.firm_name,
  154. COUNT(DISTINCT lco.id) as order_count,
  155. CAST(ROUND(COALESCE(SUM(lco.lawyer_earnings), 0) / 100.0, 2) AS CHAR) as total_amount_yuan,
  156. CAST(ROUND(COALESCE(SUM(lco.consultation_fee), 0) / 100.0, 2) AS CHAR) as commission_fee_yuan
  157. FROM lawyer_user lu
  158. INNER JOIN law_firm lf ON lu.firm_id = lf.id
  159. AND lf.delete_flag = 0
  160. AND lf.id = #{firmId}
  161. LEFT JOIN lawyer_consultation_order lco ON lco.lawyer_user_id = lu.id
  162. AND lco.place_id = #{firmId}
  163. AND lco.delete_flag = 0
  164. AND lco.order_status = 3
  165. <if test="startDate != null">
  166. AND lco.order_time &gt;= CONCAT(#{startDate}, ' 00:00:00')
  167. </if>
  168. <if test="endDate != null">
  169. AND lco.order_time &lt;= CONCAT(#{endDate}, ' 23:59:59')
  170. </if>
  171. WHERE lu.delete_flag = 0
  172. GROUP BY lu.id, lu.name, lu.head_img, lu.lawyer_certificate_no, lf.id, lf.firm_name
  173. ORDER BY COALESCE(SUM(lco.lawyer_earnings), 0) DESC
  174. </select>
  175. <!-- 查询律所下所有律师的对账统计信息(按律师分组,支持律师名称模糊查询) -->
  176. <select id="getLawyerReconciliationStatisticsWithName" resultMap="LawyerReconciliationStatisticsResultMap">
  177. SELECT
  178. lu.id as lawyer_id,
  179. lu.name as lawyer_name,
  180. lu.head_img,
  181. lu.lawyer_certificate_no,
  182. lf.id as firm_id,
  183. lf.firm_name,
  184. COUNT(DISTINCT lco.id) as order_count,
  185. CAST(ROUND(COALESCE(SUM(lco.lawyer_earnings), 0) / 100.0, 2) AS CHAR) as total_amount_yuan,
  186. CAST(ROUND(COALESCE(SUM(lco.consultation_fee), 0) / 100.0, 2) AS CHAR) as commission_fee_yuan
  187. FROM lawyer_user lu
  188. INNER JOIN law_firm lf ON lu.firm_id = lf.id
  189. AND lf.delete_flag = 0
  190. AND lf.id = #{firmId}
  191. LEFT JOIN lawyer_consultation_order lco ON lco.lawyer_user_id = lu.id
  192. AND lco.place_id = #{firmId}
  193. AND lco.delete_flag = 0
  194. AND lco.order_status = 3
  195. <if test="startDate != null">
  196. AND lco.order_time &gt;= CONCAT(#{startDate}, ' 00:00:00')
  197. </if>
  198. <if test="endDate != null">
  199. AND lco.order_time &lt;= CONCAT(#{endDate}, ' 23:59:59')
  200. </if>
  201. WHERE lu.delete_flag = 0
  202. <if test="lawyerName != null and lawyerName != ''">
  203. AND lu.name LIKE CONCAT('%', #{lawyerName}, '%')
  204. </if>
  205. GROUP BY lu.id, lu.name, lu.head_img, lu.lawyer_certificate_no, lf.id, lf.firm_name
  206. ORDER BY COALESCE(SUM(lco.lawyer_earnings), 0) DESC
  207. </select>
  208. <!-- 查询律师的已完成订单列表(分页) -->
  209. <resultMap id="LawyerOrderListResultMap" type="shop.alien.entity.store.vo.LawFirmReconciliationVO">
  210. <result column="lawyer_name" property="lawyerName" />
  211. <result column="order_number" property="orderNumber" />
  212. <result column="order_amount" property="orderAmount" />
  213. <result column="order_time" property="orderTime" />
  214. <result column="client_user_id" property="clientUserId" />
  215. <result column="client_user_name" property="clientUserName" />
  216. </resultMap>
  217. <select id="getLawyerOrderList" resultMap="LawyerOrderListResultMap">
  218. SELECT
  219. lu.name as lawyer_name,
  220. lco.order_number,
  221. lco.order_amount,
  222. lco.order_time,
  223. lco.client_user_id,
  224. life_user.user_name as client_user_name
  225. FROM lawyer_consultation_order lco
  226. INNER JOIN lawyer_user lu ON lco.lawyer_user_id = lu.id
  227. AND lu.delete_flag = 0
  228. LEFT JOIN life_user ON lco.client_user_id = life_user.id
  229. AND life_user.delete_flag = 0
  230. WHERE lco.lawyer_user_id = #{lawyerId}
  231. AND lco.delete_flag = 0
  232. AND lco.order_status = 3
  233. ORDER BY lco.order_time DESC
  234. </select>
  235. </mapper>