| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.fs.his.mapper.FsPackageOrderMapper">
- <resultMap type="FsPackageOrder" id="FsPackageOrderResult">
- <result property="orderId" column="order_id" />
- <result property="orderSn" column="order_sn" />
- <result property="userId" column="user_id" />
- <result property="doctorId" column="doctor_id" />
- <result property="packageId" column="package_id" />
- <result property="packageName" column="package_name" />
- <result property="packageSecondName" column="package_second_name" />
- <result property="payMoney" column="pay_money" />
- <result property="isPay" column="is_pay" />
- <result property="days" column="days" />
- <result property="status" column="status" />
- <result property="startTime" column="start_time" />
- <result property="finishTime" column="finish_time" />
- <result property="createTime" column="create_time" />
- <result property="companyId" column="company_id" />
- <result property="companyUserId" column="company_user_id" />
- <result property="formJson" column="form_json" />
- <result property="inquiryOrderId" column="inquiry_order_id" />
- <result property="storeOrderId" column="store_order_id" />
- <result property="packageJson" column="package_json" />
- <result property="patientJson" column="patient_json" />
- <result property="refundImg" column="refund_img" />
- <result property="refundExplain" column="refund_explain" />
- <result property="refundReason" column="refund_reason" />
- <result property="refundTime" column="refund_time" />
- <result property="refundMoney" column="refund_money" />
- <result property="payTime" column="pay_time" />
- <result property="refundStatus" column="refund_status" />
- <result property="totalPrice" column="total_price" />
- <result property="addressJson" column="address_json" />
- <result property="payType" column="pay_type" />
- <result property="remark" column="remark" />
- <result property="storeId" column="store_id" />
- <result property="payPrice" column="pay_price" />
- <result property="payRemain" column="pay_remain" />
- <result property="payDelivery" column="pay_delivery" />
- <result property="discountMoney" column="discount_money" />
- <result property="followNum" column="follow_num" />
- <result property="followCount" column="follow_count" />
- <result property="productCostPrice" column="product_cost_price" />
- <result property="inquiryCostPrice" column="inquiry_cost_price" />
- <result property="totalCostPrice" column="total_cost_price" />
- <result property="costDiscountMoney" column="cost_discount_money" />
- <result property="cycle" column="cycle" />
- <result property="packageSubType" column="package_sub_type" />
- <result property="followTempId" column="follow_temp_id" />
- <result property="followRate" column="follow_rate" />
- <result property="followTime" column="follow_time" />
- <result property="followDoctorId" column="follow_doctor_id" />
- <result property="prescribePrice" column="prescribe_price" />
- <result property="deptId" column="dept_id" />
- <result property="doctorRemark" column="doctor_remark" />
- <result property="userCouponId" column="user_coupon_id" />
- <result property="icdCode" column="icd_code" />
- <result property="source" column="source" />
- </resultMap>
- <sql id="selectFsPackageOrderVo">
- 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
- </sql>
- <select id="selectFsPackageOrderList" parameterType="FsPackageOrder" resultMap="FsPackageOrderResult">
- <include refid="selectFsPackageOrderVo"/>
- <where>
- <if test="orderSn != null and orderSn != ''"> and order_sn = #{orderSn}</if>
- <if test="userId != null "> and user_id = #{userId}</if>
- <if test="doctorId != null "> and doctor_id = #{doctorId}</if>
- <if test="packageId != null "> and package_id = #{packageId}</if>
- <if test="packageName != null and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
- <if test="payMoney != null "> and pay_money = #{payMoney}</if>
- <if test="isPay != null "> and is_pay = #{isPay}</if>
- <if test="days != null "> and days = #{days}</if>
- <if test="status != null "> and status = #{status}</if>
- <if test="startTime != null "> and start_time = #{startTime}</if>
- <if test="finishTime != null "> and finish_time = #{finishTime}</if>
- <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- </where>
- </select>
- <select id="selectFsPackageOrderByOrderId" parameterType="Long" resultMap="FsPackageOrderResult">
- <include refid="selectFsPackageOrderVo"/>
- where order_id = #{orderId}
- </select>
- <insert id="insertFsPackageOrder" parameterType="FsPackageOrder" useGeneratedKeys="true" keyProperty="orderId">
- insert into fs_package_order
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="orderSn != null">order_sn,</if>
- <if test="userId != null">user_id,</if>
- <if test="doctorId != null">doctor_id,</if>
- <if test="packageId != null">package_id,</if>
- <if test="packageName != null">package_name,</if>
- <if test="packageSecondName != null">package_second_name,</if>
- <if test="payMoney != null">pay_money,</if>
- <if test="isPay != null">is_pay,</if>
- <if test="days != null">days,</if>
- <if test="status != null">status,</if>
- <if test="startTime != null">start_time,</if>
- <if test="finishTime != null">finish_time,</if>
- <if test="createTime != null">create_time,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="formJson != null">form_json,</if>
- <if test="inquiryOrderId != null">inquiry_order_id,</if>
- <if test="storeOrderId != null">inquiry_order_id,</if>
- <if test="packageJson != null">package_json,</if>
- <if test="patientJson != null">patient_json,</if>
- <if test="refundImg != null">refund_img,</if>
- <if test="refundExplain != null">refund_explain,</if>
- <if test="refundReason != null">refund_reason,</if>
- <if test="refundTime != null">refund_time,</if>
- <if test="refundMoney != null">refund_money,</if>
- <if test="payTime != null">pay_time,</if>
- <if test="refundStatus != null">refund_status,</if>
- <if test="totalPrice != null">total_price,</if>
- <if test="addressJson != null">address_json,</if>
- <if test="payType != null">pay_type,</if>
- <if test="remark != null">remark,</if>
- <if test="storeId != null">store_id,</if>
- <if test="payPrice != null">pay_price,</if>
- <if test="payRemain != null">pay_remain,</if>
- <if test="payDelivery != null">pay_delivery,</if>
- <if test="discountMoney != null">discount_money,</if>
- <if test="followNum != null">follow_num,</if>
- <if test="followCount != null">follow_count,</if>
- <if test="productCostPrice != null">product_cost_price,</if>
- <if test="inquiryCostPrice != null">inquiry_cost_price,</if>
- <if test="totalCostPrice != null">total_cost_price,</if>
- <if test="costDiscountMoney != null">cost_discount_money,</if>
- <if test="cycle != null">`cycle`,</if>
- <if test="packageSubType != null">package_sub_type,</if>
- <if test="followTempId != null">follow_temp_id,</if>
- <if test="followRate != null">follow_rate,</if>
- <if test="followTime != null">follow_time,</if>
- <if test="followDoctorId != null">follow_doctor_id,</if>
- <if test="prescribePrice != null">prescribe_price,</if>
- <if test="deptId != null">dept_id,</if>
- <if test="doctorRemark != null">doctor_remark,</if>
- <if test="userCouponId != null">user_coupon_id,</if>
- <if test="icdCode != null">icd_code,</if>
- <if test="source != null">source,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="orderSn != null">#{orderSn},</if>
- <if test="userId != null">#{userId},</if>
- <if test="doctorId != null">#{doctorId},</if>
- <if test="packageId != null">#{packageId},</if>
- <if test="packageName != null">#{packageName},</if>
- <if test="packageSecondName != null">#{packageSecondName},</if>
- <if test="payMoney != null">#{payMoney},</if>
- <if test="isPay != null">#{isPay},</if>
- <if test="days != null">#{days},</if>
- <if test="status != null">#{status},</if>
- <if test="startTime != null">#{startTime},</if>
- <if test="finishTime != null">#{finishTime},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- <if test="formJson != null">#{formJson},</if>
- <if test="inquiryOrderId != null">#{inquiryOrderId},</if>
- <if test="storeOrderId != null">#{storeOrderId},</if>
- <if test="packageJson != null">#{packageJson},</if>
- <if test="patientJson != null">#{patientJson},</if>
- <if test="refundImg != null">#{refundImg},</if>
- <if test="refundExplain != null">#{refundExplain},</if>
- <if test="refundReason != null">#{refundReason},</if>
- <if test="refundTime != null">#{refundTime},</if>
- <if test="refundMoney != null">#{refundMoney},</if>
- <if test="payTime != null">#{payTime},</if>
- <if test="refundStatus != null">#{refundStatus},</if>
- <if test="totalPrice != null">#{totalPrice},</if>
- <if test="addressJson != null">#{addressJson},</if>
- <if test="payType != null">#{payType},</if>
- <if test="remark != null">#{remark},</if>
- <if test="storeId != null">#{storeId},</if>
- <if test="payPrice != null">#{payPrice},</if>
- <if test="payRemain != null">#{payRemain},</if>
- <if test="payDelivery != null">#{payDelivery},</if>
- <if test="discountMoney != null">#{discountMoney},</if>
- <if test="followNum != null">#{followNum},</if>
- <if test="followCount != null">#{followCount},</if>
- <if test="productCostPrice != null">#{productCostPrice},</if>
- <if test="inquiryCostPrice != null">#{inquiryCostPrice},</if>
- <if test="totalCostPrice != null">#{totalCostPrice},</if>
- <if test="costDiscountMoney != null">#{costDiscountMoney},</if>
- <if test="cycle != null">#{cycle},</if>
- <if test="packageSubType != null">#{packageSubType},</if>
- <if test="followTempId != null">#{followTempId},</if>
- <if test="followRate != null">#{followRate},</if>
- <if test="followTime != null">#{followTime},</if>
- <if test="followDoctorId != null">#{followDoctorId},</if>
- <if test="prescribePrice != null">#{prescribePrice},</if>
- <if test="deptId != null">#{deptId},</if>
- <if test="doctorRemark != null">#{doctorRemark},</if>
- <if test="userCouponId != null">#{userCouponId},</if>
- <if test="icdCode != null">#{icdCode},</if>
- <if test="source != null">#{source},</if>
- </trim>
- </insert>
- <update id="updateFsPackageOrder" parameterType="FsPackageOrder">
- update fs_package_order
- <trim prefix="SET" suffixOverrides=",">
- <if test="orderSn != null">order_sn = #{orderSn},</if>
- <if test="userId != null">user_id = #{userId},</if>
- <if test="doctorId != null">doctor_id = #{doctorId},</if>
- <if test="packageId != null">package_id = #{packageId},</if>
- <if test="packageName != null">package_name = #{packageName},</if>
- <if test="packageSecondName != null">package_second_name = #{packageSecondName},</if>
- <if test="payMoney != null">pay_money = #{payMoney},</if>
- <if test="isPay != null">is_pay = #{isPay},</if>
- <if test="days != null">days = #{days},</if>
- <if test="status != null">status = #{status},</if>
- <if test="startTime != null">start_time = #{startTime},</if>
- <if test="finishTime != null">finish_time = #{finishTime},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
- <if test="formJson != null">form_json = #{formJson},</if>
- <if test="packageJson != null">package_json = #{packageJson},</if>
- <if test="inquiryOrderId != null">inquiry_order_id = #{inquiryOrderId},</if>
- <if test="storeOrderId != null">store_order_id = #{storeOrderId},</if>
- <if test="patientJson != null">patient_json = #{patientJson},</if>
- <if test="refundImg != null">refund_img = #{refundImg},</if>
- <if test="refundExplain != null">refund_explain = #{refundExplain},</if>
- <if test="refundReason != null">refund_reason = #{refundReason},</if>
- <if test="refundTime != null">refund_time = #{refundTime},</if>
- <if test="refundMoney != null">refund_money = #{refundMoney},</if>
- <if test="payTime != null">pay_time = #{payTime},</if>
- <if test="refundStatus != null">refund_status = #{refundStatus},</if>
- <if test="totalPrice != null">total_price = #{totalPrice},</if>
- <if test="addressJson != null">address_json = #{addressJson},</if>
- <if test="payType != null">pay_type = #{payType},</if>
- <if test="remark != null">remark = #{remark},</if>
- <if test="storeId != null">store_id = #{storeId},</if>
- <if test="payPrice != null">pay_price = #{payPrice},</if>
- <if test="payRemain != null">pay_remain = #{payRemain},</if>
- <if test="payDelivery != null">pay_delivery = #{payDelivery},</if>
- <if test="discountMoney != null">discount_money = #{discountMoney},</if>
- <if test="followNum != null">follow_num = #{followNum},</if>
- <if test="followCount != null">follow_count = #{followCount},</if>
- <if test="productCostPrice != null">product_cost_price = #{productCostPrice},</if>
- <if test="inquiryCostPrice != null">inquiry_cost_price = #{inquiryCostPrice},</if>
- <if test="totalCostPrice != null">total_cost_price = #{totalCostPrice},</if>
- <if test="costDiscountMoney != null">cost_discount_money = #{costDiscountMoney},</if>
- <if test="cycle != null">`cycle` = #{cycle},</if>
- <if test="packageSubType != null">package_sub_type = #{packageSubType},</if>
- <if test="followTempId != null">follow_temp_id = #{followTempId},</if>
- <if test="followRate != null">follow_rate = #{followRate},</if>
- <if test="followTime != null">follow_time = #{followTime},</if>
- <if test="followDoctorId != null">follow_doctor_id = #{followDoctorId},</if>
- <if test="prescribePrice != null">prescribe_price = #{prescribePrice},</if>
- <if test="deptId != null">dept_id = #{deptId},</if>
- <if test="doctorRemark != null">doctor_remark = #{doctorRemark},</if>
- <if test="userCouponId != null">user_coupon_id = #{userCouponId},</if>
- <if test="icdCode != null">icd_code = #{icdCode},</if>
- <if test="source != null">source = #{source},</if>
- </trim>
- where order_id = #{orderId}
- </update>
- <delete id="deleteFsPackageOrderByOrderId" parameterType="Long">
- delete from fs_package_order where order_id = #{orderId}
- </delete>
- <delete id="deleteFsPackageOrderByOrderIds" parameterType="String">
- delete from fs_package_order where order_id in
- <foreach item="orderId" collection="array" open="(" separator="," close=")">
- #{orderId}
- </foreach>
- </delete>
- <select id="selectFsPackageOrderListVO_COUNT" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="Long">
- select count(1) from fs_package_order o
- <if test="maps.phone != null"> LEFT JOIN fs_user u ON u.user_id = o.user_id </if>
- <if test="maps.doctorName != null">LEFT JOIN fs_doctor d ON d.doctor_id = o.doctor_id </if>
- <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>
- <if test='maps.companyUserName != null or maps.params.dataScope!=null'>LEFT JOIN company_user cu ON cu.user_id = o.company_user_id </if>
- where 1=1
- <if test="maps.orderSn != null and maps.orderSn != ''"> and o.order_sn = #{maps.orderSn}</if>
- <if test="maps.phone != null">and u.phone like concat( #{maps.phone}, '%')</if>
- <if test="maps.doctorName != null">and d.doctor_name like concat('%', #{maps.doctorName}, '%')</if>
- <if test="maps.packageName != null and maps.packageName != ''"> and o.package_name like concat('%', #{maps.packageName}, '%')</if>
- <if test="maps.isPay != null"> and o.is_pay = #{maps.isPay}</if>
- <if test="maps.packageSubType != null"> and o.package_sub_type = #{maps.packageSubType}</if>
- <if test="maps.userName != null and maps.userName != ''"> and fso.user_name like concat('%', #{maps.userName}, '%')</if>
- <if test="maps.userPhone != null and maps.userPhone != ''"> and fso.user_phone = #{maps.userPhone}</if>
- <if test="maps.status != null"> and o.status = #{maps.status}</if>
- <if test="maps.sTime != null"> and DATE(o.start_time) >= DATE(#{maps.sTime})</if>
- <if test="maps.eTime != null"> and DATE(o.start_time) <= DATE(#{maps.eTime})</if>
- <if test="maps.stTime != null"> and DATE(o.create_time) >= DATE(#{maps.stTime})</if>
- <if test="maps.endTime != null"> and DATE(o.create_time) <= DATE(#{maps.endTime})</if>
- <if test="maps.endStartTime != null"> and DATE(o.finish_time) >= DATE(#{maps.endStartTime})</if>
- <if test="maps.endEndTime != null"> and DATE(o.finish_time) <= DATE(#{maps.endEndTime})</if>
- <if test="maps.companyUserId != null"> and o.company_user_id = #{maps.companyUserId}</if>
- <if test='maps.companyUserName != null'> and cu.user_name like concat('%', #{maps.companyUserName}, '%')</if>
- <if test='maps.companyId != null and maps.companyId != "-1"'> and o.company_id =#{maps.companyId} </if>
- <if test=' maps.companyId == "-1"'> and o.company_id is null </if>
- <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>
- </select>
- <select id="selectFsPackageByOrderId" resultType="com.fs.his.domain.FsPackage">
- SELECT fp.* FROM fs_package_order fpo LEFT JOIN fs_package fp ON fpo.package_id = fp.package_id WHERE fpo.order_id = #{packageOrderId}
- </select>
- <select id="getNewOrder" resultType="com.fs.his.dto.PackageOrderDTO">
- SELECT O.pay_time AS payTime, O.create_time AS createTime , O.order_sn AS orderSn , O.user_id AS userId ,
- U.nick_name AS fsUserName , P.package_name AS packageName
- FROM fs_barrage_package_order O
- LEFT JOIN fs_user U ON O.user_id = U.user_id
- LEFT JOIN fs_package P ON O.package_id = P.package_id
- where O.is_pay = 1 ORDER BY RAND() desc LIMIT 20
- </select>
- <select id="selectOutTimeOrderList" resultType="com.fs.his.domain.FsPackageOrder">
- select * from fs_package_order where status = 1 AND NOW() > DATE_ADD(create_time, INTERVAL ${unPayTime} MINUTE)
- </select>
- <select id="selectFsPackageOrderReportVO" resultType="com.fs.his.vo.FsPackageOrderReportVO">
- WITH order_stats AS (
- SELECT
- po.company_id,
- COUNT(po.order_id) AS order_count,
- COALESCE(SUM(po.pay_money), 0) AS total_money,
- COUNT(CASE WHEN so.status = 3 THEN po.order_id END) AS receipt_order_count,
- COALESCE(SUM(CASE WHEN so.status = 3 THEN po.pay_money ELSE 0 END), 0) AS receipt_money
- FROM fs_package_order po
- INNER JOIN fs_store_order so ON po.order_id = so.order_id
- <where>
- <if test="stTime != null">
- AND po.start_time >= #{stTime}
- </if>
- <if test="endEndTime != null">
- AND po.finish_time <= #{endEndTime}
- </if>
- <!-- 训练营条件 -->
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = po.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- </where>
- GROUP BY po.company_id
- )
- <choose>
- <!-- 公司维度 -->
- <when test="dimension == 'company'">
- SELECT
- c.company_id AS id,
- c.company_name AS companyName,
- 'company' AS dimensionType,
- COALESCE(os.order_count, 0) AS orderNum,
- COALESCE(os.total_money, 0) AS money,
- COALESCE(os.receipt_order_count, 0) AS receiptOrder,
- COALESCE(os.receipt_money, 0) AS receiptMoney
- FROM company c
- LEFT JOIN order_stats os ON c.company_id = os.company_id
- WHERE COALESCE(os.order_count, 0) > 0
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND c.dept_id = #{deptId}
- </if>
- </when>
- <!-- 部门维度 -->
- <when test="dimension == 'dept'">
- SELECT
- cd.dept_id AS id,
- cd.dept_name AS deptName,
- 'dept' AS dimensionType,
- c.company_name AS companyName,
- COALESCE(os.order_count, 0) AS orderNum,
- COALESCE(os.total_money, 0) AS money,
- COALESCE(os.receipt_order_count, 0) AS receiptOrder,
- COALESCE(os.receipt_money, 0) AS receiptMoney
- FROM company_dept cd
- LEFT JOIN company c ON cd.company_id = c.company_id
- LEFT JOIN order_stats os ON c.company_id = os.company_id
- WHERE COALESCE(os.order_count, 0) > 0
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND cd.dept_id = #{deptId}
- </if>
- </when>
- </choose>
- ORDER BY orderNum DESC, money DESC
- </select>
- <select id="selectFsOrderReportVO" resultType="com.fs.his.vo.FsOrderReportVO">
- SELECT
- c.company_name AS companyName,
- COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_count END), 0) AS inquiryOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_amount END), 0) AS inquiryOrderAmount,
- COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_count END), 0) AS integralOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_amount END), 0) AS integralOrderAmount,
- COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_count END), 0) AS packageOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_amount END), 0) AS packageOrderAmount
- FROM company c
- LEFT JOIN (
- -- 合并三个查询,只扫描一次
- SELECT inquiry.company_id, 'inquiry' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_inquiry_order inquiry
- WHERE inquiry.status = 3
- <if test="stTime != null and endEndTime != null">
- AND inquiry.create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = inquiry.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY inquiry.company_id
- UNION ALL
- SELECT integral.company_id, 'integral' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_integral_order integral
- WHERE integral.status = 3 AND pay_money IS NOT NULL
- <if test="stTime != null and endEndTime != null">
- AND integral.create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = integral.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY integral.company_id
- UNION ALL
- SELECT package.company_id, 'package' AS order_type, COUNT(*) AS order_count, COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_package_order package
- WHERE package.status = 3
- <if test="stTime != null and endEndTime != null">
- AND package.create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = package.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY package.company_id
- ) AS all_orders ON c.company_id = all_orders.company_id
- WHERE 1=1
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- GROUP BY c.company_id, c.company_name
- HAVING inquiryOrderCount > 0 OR integralOrderCount > 0 OR packageOrderCount > 0
- ORDER BY inquiryOrderCount DESC, integralOrderCount DESC, packageOrderCount DESC
- </select>
- <select id="selectFsOrderReportVODept" resultType="com.fs.his.vo.FsOrderReportVO">
- SELECT
- d.dept_name AS deptName,
- COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_count END), 0) AS inquiryOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'inquiry' THEN order_amount END), 0) AS inquiryOrderAmount,
- COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_count END), 0) AS integralOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'integral' THEN order_amount END), 0) AS integralOrderAmount,
- COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_count END), 0) AS packageOrderCount,
- COALESCE(SUM(CASE WHEN order_type = 'package' THEN order_amount END), 0) AS packageOrderAmount
- FROM company_dept d
- LEFT JOIN company c ON d.company_id = c.company_id
- LEFT JOIN (
- <!-- 问诊订单 -->
- SELECT
- company_id,
- 'inquiry' AS order_type,
- COUNT(*) AS order_count,
- COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_inquiry_order
- WHERE status = 3
- <if test="stTime != null and endEndTime != null">
- AND create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = fs_inquiry_order.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY company_id
- UNION ALL
- <!-- 积分订单 -->
- SELECT
- company_id,
- 'integral' AS order_type,
- COUNT(*) AS order_count,
- COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_integral_order
- WHERE status = 3 AND pay_money IS NOT NULL
- <if test="stTime != null and endEndTime != null">
- AND create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = fs_integral_order.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY company_id
- UNION ALL
- <!-- 套餐订单 -->
- SELECT
- company_id,
- 'package' AS order_type,
- COUNT(*) AS order_count,
- COALESCE(SUM(pay_money), 0) AS order_amount
- FROM fs_package_order
- WHERE status = 3
- <if test="stTime != null and endEndTime != null">
- AND create_time BETWEEN #{stTime} AND #{endEndTime}
- </if>
- <if test="trainingCampId != null">
- AND EXISTS (
- SELECT 1 FROM fs_user_company_user ucu
- JOIN fs_user_course_training_camp camp ON ucu.company_user_id = camp.user_id
- WHERE ucu.company_id = fs_package_order.company_id
- AND camp.training_camp_id = #{trainingCampId}
- )
- </if>
- GROUP BY company_id
- ) AS all_orders ON c.company_id = all_orders.company_id
- WHERE 1=1
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <if test="companyId != null">
- AND d.company_id = #{companyId}
- </if>
- GROUP BY d.dept_id, d.dept_name
- HAVING inquiryOrderCount > 0 OR integralOrderCount > 0 OR packageOrderCount > 0
- ORDER BY inquiryOrderCount DESC, integralOrderCount DESC, packageOrderCount DESC
- </select>
- </mapper>
|