FsPackageOrderMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.his.mapper.FsPackageOrderMapper">
  6. <resultMap type="FsPackageOrder" id="FsPackageOrderResult">
  7. <result property="orderId" column="order_id" />
  8. <result property="orderSn" column="order_sn" />
  9. <result property="userId" column="user_id" />
  10. <result property="doctorId" column="doctor_id" />
  11. <result property="packageId" column="package_id" />
  12. <result property="packageName" column="package_name" />
  13. <result property="packageSecondName" column="package_second_name" />
  14. <result property="payMoney" column="pay_money" />
  15. <result property="isPay" column="is_pay" />
  16. <result property="days" column="days" />
  17. <result property="status" column="status" />
  18. <result property="startTime" column="start_time" />
  19. <result property="finishTime" column="finish_time" />
  20. <result property="createTime" column="create_time" />
  21. <result property="companyId" column="company_id" />
  22. <result property="companyUserId" column="company_user_id" />
  23. <result property="formJson" column="form_json" />
  24. <result property="inquiryOrderId" column="inquiry_order_id" />
  25. <result property="storeOrderId" column="store_order_id" />
  26. <result property="packageJson" column="package_json" />
  27. <result property="patientJson" column="patient_json" />
  28. <result property="refundImg" column="refund_img" />
  29. <result property="refundExplain" column="refund_explain" />
  30. <result property="refundReason" column="refund_reason" />
  31. <result property="refundTime" column="refund_time" />
  32. <result property="refundMoney" column="refund_money" />
  33. <result property="payTime" column="pay_time" />
  34. <result property="refundStatus" column="refund_status" />
  35. <result property="totalPrice" column="total_price" />
  36. <result property="addressJson" column="address_json" />
  37. <result property="payType" column="pay_type" />
  38. <result property="remark" column="remark" />
  39. <result property="storeId" column="store_id" />
  40. <result property="payPrice" column="pay_price" />
  41. <result property="payRemain" column="pay_remain" />
  42. <result property="payDelivery" column="pay_delivery" />
  43. <result property="discountMoney" column="discount_money" />
  44. <result property="followNum" column="follow_num" />
  45. <result property="followCount" column="follow_count" />
  46. <result property="productCostPrice" column="product_cost_price" />
  47. <result property="inquiryCostPrice" column="inquiry_cost_price" />
  48. <result property="totalCostPrice" column="total_cost_price" />
  49. <result property="costDiscountMoney" column="cost_discount_money" />
  50. <result property="cycle" column="cycle" />
  51. <result property="packageSubType" column="package_sub_type" />
  52. <result property="followTempId" column="follow_temp_id" />
  53. <result property="followRate" column="follow_rate" />
  54. <result property="followTime" column="follow_time" />
  55. <result property="followDoctorId" column="follow_doctor_id" />
  56. <result property="prescribePrice" column="prescribe_price" />
  57. <result property="deptId" column="dept_id" />
  58. <result property="doctorRemark" column="doctor_remark" />
  59. <result property="userCouponId" column="user_coupon_id" />
  60. <result property="icdCode" column="icd_code" />
  61. <result property="source" column="source" />
  62. </resultMap>
  63. <sql id="selectFsPackageOrderVo">
  64. select order_id,icd_code,source,pay_price,user_coupon_id,follow_temp_id,doctor_remark,dept_id,prescribe_price,follow_doctor_id,follow_rate,follow_time,follow_num,package_sub_type,cycle,product_cost_price,inquiry_cost_price,total_cost_price,cost_discount_money,follow_count,pay_remain,pay_delivery,discount_money, order_sn,refund_status,store_id,total_price,address_json,pay_type,remark,inquiry_order_id,pay_time,package_json,patient_json,refund_img,refund_explain,refund_reason,refund_time,refund_money,store_order_id, user_id,form_json, company_id,company_user_id,doctor_id, package_id, package_name,package_second_name, pay_money, is_pay, days, status, start_time, finish_time, create_time from fs_package_order
  65. </sql>
  66. <select id="selectFsPackageOrderList" parameterType="FsPackageOrder" resultMap="FsPackageOrderResult">
  67. <include refid="selectFsPackageOrderVo"/>
  68. <where>
  69. <if test="orderSn != null and orderSn != ''"> and order_sn = #{orderSn}</if>
  70. <if test="userId != null "> and user_id = #{userId}</if>
  71. <if test="doctorId != null "> and doctor_id = #{doctorId}</if>
  72. <if test="packageId != null "> and package_id = #{packageId}</if>
  73. <if test="packageName != null and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
  74. <if test="payMoney != null "> and pay_money = #{payMoney}</if>
  75. <if test="isPay != null "> and is_pay = #{isPay}</if>
  76. <if test="days != null "> and days = #{days}</if>
  77. <if test="status != null "> and status = #{status}</if>
  78. <if test="startTime != null "> and start_time = #{startTime}</if>
  79. <if test="finishTime != null "> and finish_time = #{finishTime}</if>
  80. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  81. <if test="companyId != null "> and company_id = #{companyId}</if>
  82. </where>
  83. </select>
  84. <select id="selectFsPackageOrderByOrderId" parameterType="Long" resultMap="FsPackageOrderResult">
  85. <include refid="selectFsPackageOrderVo"/>
  86. where order_id = #{orderId}
  87. </select>
  88. <insert id="insertFsPackageOrder" parameterType="FsPackageOrder" useGeneratedKeys="true" keyProperty="orderId">
  89. insert into fs_package_order
  90. <trim prefix="(" suffix=")" suffixOverrides=",">
  91. <if test="orderSn != null">order_sn,</if>
  92. <if test="userId != null">user_id,</if>
  93. <if test="doctorId != null">doctor_id,</if>
  94. <if test="packageId != null">package_id,</if>
  95. <if test="packageName != null">package_name,</if>
  96. <if test="packageSecondName != null">package_second_name,</if>
  97. <if test="payMoney != null">pay_money,</if>
  98. <if test="isPay != null">is_pay,</if>
  99. <if test="days != null">days,</if>
  100. <if test="status != null">status,</if>
  101. <if test="startTime != null">start_time,</if>
  102. <if test="finishTime != null">finish_time,</if>
  103. <if test="createTime != null">create_time,</if>
  104. <if test="companyId != null">company_id,</if>
  105. <if test="companyUserId != null">company_user_id,</if>
  106. <if test="formJson != null">form_json,</if>
  107. <if test="inquiryOrderId != null">inquiry_order_id,</if>
  108. <if test="storeOrderId != null">inquiry_order_id,</if>
  109. <if test="packageJson != null">package_json,</if>
  110. <if test="patientJson != null">patient_json,</if>
  111. <if test="refundImg != null">refund_img,</if>
  112. <if test="refundExplain != null">refund_explain,</if>
  113. <if test="refundReason != null">refund_reason,</if>
  114. <if test="refundTime != null">refund_time,</if>
  115. <if test="refundMoney != null">refund_money,</if>
  116. <if test="payTime != null">pay_time,</if>
  117. <if test="refundStatus != null">refund_status,</if>
  118. <if test="totalPrice != null">total_price,</if>
  119. <if test="addressJson != null">address_json,</if>
  120. <if test="payType != null">pay_type,</if>
  121. <if test="remark != null">remark,</if>
  122. <if test="storeId != null">store_id,</if>
  123. <if test="payPrice != null">pay_price,</if>
  124. <if test="payRemain != null">pay_remain,</if>
  125. <if test="payDelivery != null">pay_delivery,</if>
  126. <if test="discountMoney != null">discount_money,</if>
  127. <if test="followNum != null">follow_num,</if>
  128. <if test="followCount != null">follow_count,</if>
  129. <if test="productCostPrice != null">product_cost_price,</if>
  130. <if test="inquiryCostPrice != null">inquiry_cost_price,</if>
  131. <if test="totalCostPrice != null">total_cost_price,</if>
  132. <if test="costDiscountMoney != null">cost_discount_money,</if>
  133. <if test="cycle != null">`cycle`,</if>
  134. <if test="packageSubType != null">package_sub_type,</if>
  135. <if test="followTempId != null">follow_temp_id,</if>
  136. <if test="followRate != null">follow_rate,</if>
  137. <if test="followTime != null">follow_time,</if>
  138. <if test="followDoctorId != null">follow_doctor_id,</if>
  139. <if test="prescribePrice != null">prescribe_price,</if>
  140. <if test="deptId != null">dept_id,</if>
  141. <if test="doctorRemark != null">doctor_remark,</if>
  142. <if test="userCouponId != null">user_coupon_id,</if>
  143. <if test="icdCode != null">icd_code,</if>
  144. <if test="source != null">source,</if>
  145. </trim>
  146. <trim prefix="values (" suffix=")" suffixOverrides=",">
  147. <if test="orderSn != null">#{orderSn},</if>
  148. <if test="userId != null">#{userId},</if>
  149. <if test="doctorId != null">#{doctorId},</if>
  150. <if test="packageId != null">#{packageId},</if>
  151. <if test="packageName != null">#{packageName},</if>
  152. <if test="packageSecondName != null">#{packageSecondName},</if>
  153. <if test="payMoney != null">#{payMoney},</if>
  154. <if test="isPay != null">#{isPay},</if>
  155. <if test="days != null">#{days},</if>
  156. <if test="status != null">#{status},</if>
  157. <if test="startTime != null">#{startTime},</if>
  158. <if test="finishTime != null">#{finishTime},</if>
  159. <if test="createTime != null">#{createTime},</if>
  160. <if test="companyId != null">#{companyId},</if>
  161. <if test="companyUserId != null">#{companyUserId},</if>
  162. <if test="formJson != null">#{formJson},</if>
  163. <if test="inquiryOrderId != null">#{inquiryOrderId},</if>
  164. <if test="storeOrderId != null">#{storeOrderId},</if>
  165. <if test="packageJson != null">#{packageJson},</if>
  166. <if test="patientJson != null">#{patientJson},</if>
  167. <if test="refundImg != null">#{refundImg},</if>
  168. <if test="refundExplain != null">#{refundExplain},</if>
  169. <if test="refundReason != null">#{refundReason},</if>
  170. <if test="refundTime != null">#{refundTime},</if>
  171. <if test="refundMoney != null">#{refundMoney},</if>
  172. <if test="payTime != null">#{payTime},</if>
  173. <if test="refundStatus != null">#{refundStatus},</if>
  174. <if test="totalPrice != null">#{totalPrice},</if>
  175. <if test="addressJson != null">#{addressJson},</if>
  176. <if test="payType != null">#{payType},</if>
  177. <if test="remark != null">#{remark},</if>
  178. <if test="storeId != null">#{storeId},</if>
  179. <if test="payPrice != null">#{payPrice},</if>
  180. <if test="payRemain != null">#{payRemain},</if>
  181. <if test="payDelivery != null">#{payDelivery},</if>
  182. <if test="discountMoney != null">#{discountMoney},</if>
  183. <if test="followNum != null">#{followNum},</if>
  184. <if test="followCount != null">#{followCount},</if>
  185. <if test="productCostPrice != null">#{productCostPrice},</if>
  186. <if test="inquiryCostPrice != null">#{inquiryCostPrice},</if>
  187. <if test="totalCostPrice != null">#{totalCostPrice},</if>
  188. <if test="costDiscountMoney != null">#{costDiscountMoney},</if>
  189. <if test="cycle != null">#{cycle},</if>
  190. <if test="packageSubType != null">#{packageSubType},</if>
  191. <if test="followTempId != null">#{followTempId},</if>
  192. <if test="followRate != null">#{followRate},</if>
  193. <if test="followTime != null">#{followTime},</if>
  194. <if test="followDoctorId != null">#{followDoctorId},</if>
  195. <if test="prescribePrice != null">#{prescribePrice},</if>
  196. <if test="deptId != null">#{deptId},</if>
  197. <if test="doctorRemark != null">#{doctorRemark},</if>
  198. <if test="userCouponId != null">#{userCouponId},</if>
  199. <if test="icdCode != null">#{icdCode},</if>
  200. <if test="source != null">#{source},</if>
  201. </trim>
  202. </insert>
  203. <update id="updateFsPackageOrder" parameterType="FsPackageOrder">
  204. update fs_package_order
  205. <trim prefix="SET" suffixOverrides=",">
  206. <if test="orderSn != null">order_sn = #{orderSn},</if>
  207. <if test="userId != null">user_id = #{userId},</if>
  208. <if test="doctorId != null">doctor_id = #{doctorId},</if>
  209. <if test="packageId != null">package_id = #{packageId},</if>
  210. <if test="packageName != null">package_name = #{packageName},</if>
  211. <if test="packageSecondName != null">package_second_name = #{packageSecondName},</if>
  212. <if test="payMoney != null">pay_money = #{payMoney},</if>
  213. <if test="isPay != null">is_pay = #{isPay},</if>
  214. <if test="days != null">days = #{days},</if>
  215. <if test="status != null">status = #{status},</if>
  216. <if test="startTime != null">start_time = #{startTime},</if>
  217. <if test="finishTime != null">finish_time = #{finishTime},</if>
  218. <if test="createTime != null">create_time = #{createTime},</if>
  219. <if test="companyId != null">company_id = #{companyId},</if>
  220. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  221. <if test="formJson != null">form_json = #{formJson},</if>
  222. <if test="packageJson != null">package_json = #{packageJson},</if>
  223. <if test="inquiryOrderId != null">inquiry_order_id = #{inquiryOrderId},</if>
  224. <if test="storeOrderId != null">store_order_id = #{storeOrderId},</if>
  225. <if test="patientJson != null">patient_json = #{patientJson},</if>
  226. <if test="refundImg != null">refund_img = #{refundImg},</if>
  227. <if test="refundExplain != null">refund_explain = #{refundExplain},</if>
  228. <if test="refundReason != null">refund_reason = #{refundReason},</if>
  229. <if test="refundTime != null">refund_time = #{refundTime},</if>
  230. <if test="refundMoney != null">refund_money = #{refundMoney},</if>
  231. <if test="payTime != null">pay_time = #{payTime},</if>
  232. <if test="refundStatus != null">refund_status = #{refundStatus},</if>
  233. <if test="totalPrice != null">total_price = #{totalPrice},</if>
  234. <if test="addressJson != null">address_json = #{addressJson},</if>
  235. <if test="payType != null">pay_type = #{payType},</if>
  236. <if test="remark != null">remark = #{remark},</if>
  237. <if test="storeId != null">store_id = #{storeId},</if>
  238. <if test="payPrice != null">pay_price = #{payPrice},</if>
  239. <if test="payRemain != null">pay_remain = #{payRemain},</if>
  240. <if test="payDelivery != null">pay_delivery = #{payDelivery},</if>
  241. <if test="discountMoney != null">discount_money = #{discountMoney},</if>
  242. <if test="followNum != null">follow_num = #{followNum},</if>
  243. <if test="followCount != null">follow_count = #{followCount},</if>
  244. <if test="productCostPrice != null">product_cost_price = #{productCostPrice},</if>
  245. <if test="inquiryCostPrice != null">inquiry_cost_price = #{inquiryCostPrice},</if>
  246. <if test="totalCostPrice != null">total_cost_price = #{totalCostPrice},</if>
  247. <if test="costDiscountMoney != null">cost_discount_money = #{costDiscountMoney},</if>
  248. <if test="cycle != null">`cycle` = #{cycle},</if>
  249. <if test="packageSubType != null">package_sub_type = #{packageSubType},</if>
  250. <if test="followTempId != null">follow_temp_id = #{followTempId},</if>
  251. <if test="followRate != null">follow_rate = #{followRate},</if>
  252. <if test="followTime != null">follow_time = #{followTime},</if>
  253. <if test="followDoctorId != null">follow_doctor_id = #{followDoctorId},</if>
  254. <if test="prescribePrice != null">prescribe_price = #{prescribePrice},</if>
  255. <if test="deptId != null">dept_id = #{deptId},</if>
  256. <if test="doctorRemark != null">doctor_remark = #{doctorRemark},</if>
  257. <if test="userCouponId != null">user_coupon_id = #{userCouponId},</if>
  258. <if test="icdCode != null">icd_code = #{icdCode},</if>
  259. <if test="source != null">source = #{source},</if>
  260. </trim>
  261. where order_id = #{orderId}
  262. </update>
  263. <delete id="deleteFsPackageOrderByOrderId" parameterType="Long">
  264. delete from fs_package_order where order_id = #{orderId}
  265. </delete>
  266. <delete id="deleteFsPackageOrderByOrderIds" parameterType="String">
  267. delete from fs_package_order where order_id in
  268. <foreach item="orderId" collection="array" open="(" separator="," close=")">
  269. #{orderId}
  270. </foreach>
  271. </delete>
  272. <select id="selectFsPackageOrderListVO_COUNT" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="Long">
  273. select count(1) from fs_package_order o
  274. <if test="maps.phone != null"> LEFT JOIN fs_user u ON u.user_id = o.user_id </if>
  275. <if test="maps.doctorName != null">LEFT JOIN fs_doctor d ON d.doctor_id = o.doctor_id </if>
  276. <if test="(maps.userPhone != null and maps.userPhone != '') or (maps.userName != null and maps.userName != '')">LEFT JOIN fs_store_order fso ON fso.order_id = o.store_order_id </if>
  277. <if test='maps.companyUserName != null or maps.params.dataScope!=null'>LEFT JOIN company_user cu ON cu.user_id = o.company_user_id </if>
  278. <if test="maps.coursePlaySourceConfigId != null">LEFT JOIN (
  279. SELECT sp.*,
  280. ROW_NUMBER() OVER (PARTITION BY sp.business_code ORDER BY sp.create_time DESC) AS rn
  281. FROM fs_store_payment sp
  282. ) sp_latest ON sp_latest.business_code = o.order_sn AND sp_latest.rn = 1 LEFT JOIN fs_course_play_source_config csc ON csc.appid = sp_latest.app_id</if>
  283. where 1=1
  284. <if test="maps.orderSn != null and maps.orderSn != ''"> and o.order_sn = #{maps.orderSn}</if>
  285. <if test="maps.coursePlaySourceConfigId != null"> and csc.id = #{maps.coursePlaySourceConfigId}</if>
  286. <if test="maps.phone != null">and u.phone like concat( #{maps.phone}, '%')</if>
  287. <if test="maps.doctorName != null">and d.doctor_name like concat('%', #{maps.doctorName}, '%')</if>
  288. <if test="maps.packageName != null and maps.packageName != ''"> and o.package_name like concat('%', #{maps.packageName}, '%')</if>
  289. <if test="maps.isPay != null"> and o.is_pay = #{maps.isPay}</if>
  290. <if test="maps.packageSubType != null"> and o.package_sub_type = #{maps.packageSubType}</if>
  291. <if test="maps.userName != null and maps.userName != ''"> and fso.user_name like concat('%', #{maps.userName}, '%')</if>
  292. <if test="maps.userPhone != null and maps.userPhone != ''"> and fso.user_phone = #{maps.userPhone}</if>
  293. <if test="maps.status != null"> and o.status = #{maps.status}</if>
  294. <if test="maps.sTime != null"> and DATE(o.start_time) &gt;= DATE(#{maps.sTime})</if>
  295. <if test="maps.eTime != null"> and DATE(o.start_time) &lt;= DATE(#{maps.eTime})</if>
  296. <if test="maps.stTime != null"> and DATE(o.create_time) &gt;= DATE(#{maps.stTime})</if>
  297. <if test="maps.endTime != null"> and DATE(o.create_time) &lt;= DATE(#{maps.endTime})</if>
  298. <if test="maps.endStartTime != null"> and DATE(o.finish_time) &gt;= DATE(#{maps.endStartTime})</if>
  299. <if test="maps.endEndTime != null"> and DATE(o.finish_time) &lt;= DATE(#{maps.endEndTime})</if>
  300. <if test="maps.companyUserId != null"> and o.company_user_id = #{maps.companyUserId}</if>
  301. <if test='maps.companyUserName != null'> and cu.user_name like concat('%', #{maps.companyUserName}, '%')</if>
  302. <if test='maps.companyId != null and maps.companyId != "-1"'> and o.company_id =#{maps.companyId} </if>
  303. <if test=' maps.companyId == "-1"'> and o.company_id is null </if>
  304. <if test='maps.deptId != null'> AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) </if>
  305. </select>
  306. <select id="selectFsPackageByOrderId" resultType="com.fs.his.domain.FsPackage">
  307. SELECT fp.* FROM fs_package_order fpo LEFT JOIN fs_package fp ON fpo.package_id = fp.package_id WHERE fpo.order_id = #{packageOrderId}
  308. </select>
  309. <select id="getNewOrder" resultType="com.fs.his.dto.PackageOrderDTO">
  310. SELECT O.pay_time AS payTime, O.create_time AS createTime , O.order_sn AS orderSn , O.user_id AS userId ,
  311. U.nick_name AS fsUserName , P.package_name AS packageName
  312. FROM fs_barrage_package_order O
  313. LEFT JOIN fs_user U ON O.user_id = U.user_id
  314. LEFT JOIN fs_package P ON O.package_id = P.package_id
  315. where O.is_pay = 1 ORDER BY RAND() desc LIMIT 20
  316. </select>
  317. <select id="selectOutTimeOrderList" resultType="com.fs.his.domain.FsPackageOrder">
  318. select * from fs_package_order where status = 1 AND NOW() &gt; DATE_ADD(create_time, INTERVAL ${unPayTime} MINUTE)
  319. </select>
  320. <select id="selectFsPackageOrderReportVO" resultType="com.fs.his.vo.FsPackageOrderReportVO">
  321. WITH order_stats AS (
  322. SELECT
  323. po.company_id,
  324. po.start_time,
  325. po.finish_time,
  326. COUNT(po.order_id) AS order_count,
  327. COALESCE(SUM(po.pay_money), 0) AS total_money,
  328. COUNT(CASE WHEN so.status = 3 THEN po.order_id END) AS receipt_order_count,
  329. COALESCE(SUM(CASE WHEN so.status = 3 THEN po.pay_money ELSE 0 END), 0) AS receipt_money
  330. FROM fs_package_order po
  331. INNER JOIN fs_store_order so ON po.store_order_id = so.order_id
  332. GROUP BY po.company_id
  333. )
  334. <choose>
  335. <!-- 公司维度 -->
  336. <when test="dimension == 'company'">
  337. SELECT
  338. c.company_id AS id,
  339. c.company_name AS companyName,
  340. 'company' AS dimensionType,
  341. COALESCE(os.order_count, 0) AS orderNum,
  342. COALESCE(os.total_money, 0) AS money,
  343. COALESCE(os.receipt_order_count, 0) AS receiptOrder,
  344. COALESCE(os.receipt_money, 0) AS receiptMoney
  345. FROM company c
  346. LEFT JOIN order_stats os ON c.company_id = os.company_id
  347. <where>
  348. <if test="companyId != null and companyId != ''">
  349. AND c.company_id = #{companyId}
  350. </if>
  351. <if test="deptId != null and deptId != ''">
  352. AND c.dept_id = #{deptId}
  353. </if>
  354. <if test="stTime != null">
  355. AND os.start_time &gt;= #{stTime}
  356. </if>
  357. <if test="endEndTime != null">
  358. AND os.finish_time &lt;= #{endEndTime}
  359. </if>
  360. </where>
  361. </when>
  362. <!-- 部门维度 -->
  363. <when test="dimension == 'dept'">
  364. SELECT
  365. cd.dept_id AS id,
  366. cd.dept_name AS deptName,
  367. 'dept' AS dimensionType,
  368. c.company_name AS companyName,
  369. COALESCE(os.order_count, 0) AS orderNum,
  370. COALESCE(os.total_money, 0) AS money,
  371. COALESCE(os.receipt_order_count, 0) AS receiptOrder,
  372. COALESCE(os.receipt_money, 0) AS receiptMoney
  373. FROM company_dept cd
  374. LEFT JOIN company c ON cd.company_id = c.company_id
  375. LEFT JOIN order_stats os ON c.company_id = os.company_id
  376. <where>
  377. <if test="companyId != null and companyId != ''">
  378. AND c.company_id = #{companyId}
  379. </if>
  380. <if test="deptId != null and deptId != ''">
  381. AND cd.dept_id = #{deptId}
  382. </if>
  383. <if test="stTime != null">
  384. AND os.start_time &gt;= #{stTime}
  385. </if>
  386. <if test="endEndTime != null">
  387. AND os.finish_time &lt;= #{endEndTime}
  388. </if>
  389. </where>
  390. </when>
  391. </choose>
  392. ORDER BY orderNum DESC, money DESC
  393. </select>
  394. <select id="selectFsOrderReportVO" resultType="com.fs.his.vo.FsOrderReportVO">
  395. SELECT
  396. c.company_name AS companyName,
  397. COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_count END), 0) AS inquiryOrderCount,
  398. COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_amount END), 0) AS inquiryOrderAmount,
  399. COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_count END), 0) AS integralOrderCount,
  400. COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_amount END), 0) AS integralOrderAmount,
  401. COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_count END), 0) AS packageOrderCount,
  402. COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_amount END), 0) AS packageOrderAmount
  403. FROM company c
  404. LEFT JOIN (
  405. -- 合并三个查询,只扫描一次
  406. SELECT inquiry.company_id, 'inquiry' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
  407. FROM fs_inquiry_order inquiry
  408. WHERE inquiry.status = 3
  409. <if test="stTime != null and endEndTime != null">
  410. AND inquiry.create_time BETWEEN #{stTime} AND #{endEndTime}
  411. </if>
  412. <if test="trainingCampId != null">
  413. AND EXISTS (
  414. SELECT 1 FROM fs_user_company_user ucu
  415. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  416. WHERE ucu.company_id = inquiry.company_id
  417. AND camp.training_camp_id = #{trainingCampId}
  418. )
  419. </if>
  420. GROUP BY inquiry.company_id
  421. UNION ALL
  422. SELECT integral.company_id, 'integral' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
  423. FROM fs_integral_order integral
  424. WHERE integral.status = 3 AND pay_money IS NOT NULL
  425. <if test="stTime != null and endEndTime != null">
  426. AND integral.create_time BETWEEN #{stTime} AND #{endEndTime}
  427. </if>
  428. <if test="trainingCampId != null">
  429. AND EXISTS (
  430. SELECT 1 FROM fs_user_company_user ucu
  431. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  432. WHERE ucu.company_id = integral.company_id
  433. AND camp.training_camp_id = #{trainingCampId}
  434. )
  435. </if>
  436. GROUP BY integral.company_id
  437. UNION ALL
  438. SELECT package.company_id, 'package' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
  439. FROM fs_package_order package
  440. WHERE package.status = 3
  441. <if test="stTime != null and endEndTime != null">
  442. AND package.create_time BETWEEN #{stTime} AND #{endEndTime}
  443. </if>
  444. <if test="trainingCampId != null">
  445. AND EXISTS (
  446. SELECT 1 FROM fs_user_company_user ucu
  447. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  448. WHERE ucu.company_id = package.company_id
  449. AND camp.training_camp_id = #{trainingCampId}
  450. )
  451. </if>
  452. GROUP BY package.company_id
  453. ) AS all_orders ON c.company_id = all_orders.company_id
  454. WHERE 1=1
  455. <if test="companyId != null and companyId != ''">
  456. AND c.company_id = #{companyId}
  457. </if>
  458. <if test="stTime != null and endEndTime != null">
  459. AND c.company_id IN (
  460. SELECT DISTINCT company_id FROM fs_inquiry_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  461. UNION
  462. SELECT DISTINCT company_id FROM fs_integral_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  463. UNION
  464. SELECT DISTINCT company_id FROM fs_package_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  465. )
  466. </if>
  467. GROUP BY c.company_id, c.company_name
  468. ORDER BY inquiryOrderCount DESC, integralOrderCount DESC, packageOrderCount DESC
  469. </select>
  470. <select id="selectFsOrderReportVODept" resultType="com.fs.his.vo.FsOrderReportVO">
  471. SELECT
  472. d.dept_name AS deptName,
  473. COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_count END), 0) AS inquiryOrderCount,
  474. COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_amount END), 0) AS inquiryOrderAmount,
  475. COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_count END), 0) AS integralOrderCount,
  476. COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_amount END), 0) AS integralOrderAmount,
  477. COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_count END), 0) AS packageOrderCount,
  478. COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_amount END), 0) AS packageOrderAmount
  479. FROM company_dept d
  480. LEFT JOIN company c ON d.company_id = c.company_id
  481. LEFT JOIN (
  482. <!-- 问诊订单 -->
  483. SELECT
  484. company_id,
  485. 'inquiry' AS order_type,
  486. COUNT(*) AS order_count,
  487. COALESCE(SUM(pay_money), 0) AS order_amount
  488. FROM fs_inquiry_order
  489. WHERE status = 3
  490. <if test="stTime != null and endEndTime != null">
  491. AND create_time BETWEEN #{stTime} AND #{endEndTime}
  492. </if>
  493. <if test="trainingCampId != null">
  494. AND EXISTS (
  495. SELECT 1 FROM fs_user_company_user ucu
  496. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  497. WHERE ucu.company_id = fs_inquiry_order.company_id
  498. AND camp.training_camp_id = #{trainingCampId}
  499. )
  500. </if>
  501. GROUP BY company_id
  502. UNION ALL
  503. <!-- 积分订单 -->
  504. SELECT
  505. company_id,
  506. 'integral' AS order_type,
  507. COUNT(*) AS order_count,
  508. COALESCE(SUM(pay_money), 0) AS order_amount
  509. FROM fs_integral_order
  510. WHERE status = 3 AND pay_money IS NOT NULL
  511. <if test="stTime != null and endEndTime != null">
  512. AND create_time BETWEEN #{stTime} AND #{endEndTime}
  513. </if>
  514. <if test="trainingCampId != null">
  515. AND EXISTS (
  516. SELECT 1 FROM fs_user_company_user ucu
  517. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  518. WHERE ucu.company_id = fs_integral_order.company_id
  519. AND camp.training_camp_id = #{trainingCampId}
  520. )
  521. </if>
  522. GROUP BY company_id
  523. UNION ALL
  524. <!-- 套餐订单 -->
  525. SELECT
  526. company_id,
  527. 'package' AS order_type,
  528. COUNT(*) AS order_count,
  529. COALESCE(SUM(pay_money), 0) AS order_amount
  530. FROM fs_package_order
  531. WHERE status = 3
  532. <if test="stTime != null and endEndTime != null">
  533. AND create_time BETWEEN #{stTime} AND #{endEndTime}
  534. </if>
  535. <if test="trainingCampId != null">
  536. AND EXISTS (
  537. SELECT 1 FROM fs_user_company_user ucu
  538. JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
  539. WHERE ucu.company_id = fs_package_order.company_id
  540. AND camp.training_camp_id = #{trainingCampId}
  541. )
  542. </if>
  543. GROUP BY company_id
  544. ) AS all_orders ON c.company_id = all_orders.company_id
  545. WHERE 1=1
  546. <if test="deptId != null and deptId != ''">
  547. AND d.dept_id = #{deptId}
  548. </if>
  549. <if test="companyId != null">
  550. AND d.company_id = #{companyId}
  551. </if>
  552. <if test="stTime != null and endEndTime != null">
  553. AND d.dept_id IN (
  554. SELECT DISTINCT d2.dept_id
  555. FROM company_dept d2
  556. JOIN company c2 ON d2.company_id = c2.company_id
  557. WHERE c2.company_id IN (
  558. SELECT DISTINCT company_id FROM fs_inquiry_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  559. UNION
  560. SELECT DISTINCT company_id FROM fs_integral_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  561. UNION
  562. SELECT DISTINCT company_id FROM fs_package_order WHERE create_time BETWEEN #{stTime} AND #{endEndTime}
  563. )
  564. )
  565. </if>
  566. GROUP BY d.dept_id, d.dept_name
  567. ORDER BY inquiryOrderCount DESC, integralOrderCount DESC, packageOrderCount DESC
  568. </select>
  569. </mapper>