|
|
@@ -206,4 +206,267 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
#{orderId}
|
|
|
</foreach>
|
|
|
</delete>
|
|
|
+
|
|
|
+ <!-- ========== 报表查询 ========== -->
|
|
|
+
|
|
|
+ <!-- 拒收明细报表 - 订单维度 -->
|
|
|
+ <select id="selectGuCoinRejectOrderReport" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="com.fs.his.domain.vo.FsRejectOrderReportVO">
|
|
|
+ SELECT
|
|
|
+ o.order_code AS orderCode,
|
|
|
+ o.delivery_sn AS deliverySn,
|
|
|
+ o.user_name AS userName,
|
|
|
+ o.create_time AS externalCreateTime,
|
|
|
+ o.delivery_time AS deliveryTime,
|
|
|
+ o.total_money AS totalPrice,
|
|
|
+ o.delivery_name AS deliveryName,
|
|
|
+ o.follow_time AS followTime,
|
|
|
+ o.reject_return_time AS rejectReturnTime,
|
|
|
+ o.delivery_status_update_by AS rejectUser,
|
|
|
+ o.user_phone AS userPhone,
|
|
|
+ o.user_phone AS memberPhone,
|
|
|
+ cu.user_name AS companyUserName,
|
|
|
+ REPLACE(REPLACE(REPLACE(
|
|
|
+ CAST(IFNULL(JSON_EXTRACT(o.item_json, '$[*].goodsName'), '[]') AS CHAR),
|
|
|
+ '","', ','), '["', ''), '"]', '') AS productNames,
|
|
|
+ o.user_address AS userAddress
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company c ON o.company_id = c.company_id
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
|
|
|
+ <where>
|
|
|
+ o.delivery_status IN (4, 5, 6)
|
|
|
+ <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
|
|
|
+ <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
|
|
|
+ <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
|
|
|
+ <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
|
|
|
+ <if test="sTime != null"> AND o.create_time >= #{sTime}</if>
|
|
|
+ <if test="eTime != null"> AND o.create_time <= #{eTime}</if>
|
|
|
+ <if test="totalPrice != null"> AND o.total_money = #{totalPrice}</if>
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="rejectReturnTimeStart != null and rejectReturnTimeStart != ''"> AND o.reject_return_time >= #{rejectReturnTimeStart}</if>
|
|
|
+ <if test="rejectReturnTimeEnd != null and rejectReturnTimeEnd != ''"> AND o.reject_return_time <= #{rejectReturnTimeEnd}</if>
|
|
|
+ <if test="returnUser != null and returnUser != ''"> AND o.delivery_status_update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
|
|
|
+ <if test="userPhone != null and userPhone != ''"> AND o.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
|
|
|
+ <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
|
|
|
+ <if test="deliveryStartTime != null"> AND o.delivery_time >= #{deliveryStartTime}</if>
|
|
|
+ <if test="deliveryEndTime != null"> AND o.delivery_time <= #{deliveryEndTime}</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ GROUP BY o.order_id
|
|
|
+ <if test="productName != null and productName != ''">
|
|
|
+ HAVING REPLACE(REPLACE(REPLACE(
|
|
|
+ CAST(IFNULL(JSON_EXTRACT(o.item_json, '$[*].goodsName'), '[]') AS CHAR),
|
|
|
+ '","', ','), '["', ''), '"]', '') LIKE CONCAT('%', #{productName}, '%')
|
|
|
+ </if>
|
|
|
+ ORDER BY o.order_id DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 拒收明细报表 - 订单维度合计 -->
|
|
|
+ <select id="selectGuCoinRejectOrderReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
|
|
|
+ SELECT
|
|
|
+ SUM(t.totalPrice) AS totalPrice
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ o.total_money AS totalPrice
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ <where>
|
|
|
+ o.delivery_status IN (4, 5, 6)
|
|
|
+ <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
|
|
|
+ <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
|
|
|
+ <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
|
|
|
+ <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
|
|
|
+ <if test="sTime != null"> AND o.create_time >= #{sTime}</if>
|
|
|
+ <if test="eTime != null"> AND o.create_time <= #{eTime}</if>
|
|
|
+ <if test="totalPrice != null"> AND o.total_money = #{totalPrice}</if>
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="rejectReturnTimeStart != null and rejectReturnTimeStart != ''"> AND o.reject_return_time >= #{rejectReturnTimeStart}</if>
|
|
|
+ <if test="rejectReturnTimeEnd != null and rejectReturnTimeEnd != ''"> AND o.reject_return_time <= #{rejectReturnTimeEnd}</if>
|
|
|
+ <if test="returnUser != null and returnUser != ''"> AND o.delivery_status_update_by LIKE CONCAT('%', #{returnUser}, '%')</if>
|
|
|
+ <if test="userPhone != null and userPhone != ''"> AND o.user_phone LIKE CONCAT('%', #{userPhone}, '%')</if>
|
|
|
+ <if test="companyUserName != null and companyUserName != ''"> AND cu.user_name LIKE CONCAT('%', #{companyUserName}, '%')</if>
|
|
|
+ <if test="deliveryStartTime != null"> AND o.delivery_time >= #{deliveryStartTime}</if>
|
|
|
+ <if test="deliveryEndTime != null"> AND o.delivery_time <= #{deliveryEndTime}</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ GROUP BY o.order_id
|
|
|
+ <if test="productName != null and productName != ''">
|
|
|
+ HAVING REPLACE(REPLACE(REPLACE(
|
|
|
+ CAST(IFNULL(JSON_EXTRACT(o.item_json, '$[*].goodsName'), '[]') AS CHAR),
|
|
|
+ '","', ','), '["', ''), '"]', '') LIKE CONCAT('%', #{productName}, '%')
|
|
|
+ </if>
|
|
|
+ ) t
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 拒收明细报表 - 产品维度 -->
|
|
|
+ <select id="selectGuCoinRejectProductReport" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="com.fs.his.domain.vo.FsRejectProductReportVO">
|
|
|
+ SELECT
|
|
|
+ t.productName AS productName,
|
|
|
+ t.deliveryName AS deliveryName,
|
|
|
+ SUM(t.num) AS num,
|
|
|
+ SUM(t.num * t.price) AS totalPrice
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ o.delivery_name AS deliveryName,
|
|
|
+ JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].goodsName'))) AS productName,
|
|
|
+ CAST(JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].num'))) AS DECIMAL(10,0)) AS num,
|
|
|
+ CAST(JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].price'))) AS DECIMAL(10,2)) AS price
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ CROSS JOIN (SELECT 0 AS idx UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) seq
|
|
|
+ <where>
|
|
|
+ o.delivery_status IN (4, 5, 6)
|
|
|
+ AND JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].goodsName')) IS NOT NULL
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ ) t
|
|
|
+ <where>
|
|
|
+ <if test="productName != null and productName != ''"> AND t.productName LIKE CONCAT('%', #{productName}, '%')</if>
|
|
|
+ </where>
|
|
|
+ GROUP BY t.deliveryName, t.productName
|
|
|
+ <if test="totalNum != null or totalPrice != null">
|
|
|
+ HAVING 1=1
|
|
|
+ <if test="totalNum != null"> AND SUM(t.num) = #{totalNum}</if>
|
|
|
+ <if test="totalPrice != null"> AND SUM(t.num * t.price) = #{totalPrice}</if>
|
|
|
+ </if>
|
|
|
+ ORDER BY t.deliveryName, t.productName
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 拒收明细报表 - 产品维度合计 -->
|
|
|
+ <select id="selectGuCoinRejectProductReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
|
|
|
+ SELECT
|
|
|
+ SUM(t.num) AS num,
|
|
|
+ SUM(t.totalPrice) AS totalPrice
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ t2.deliveryName,
|
|
|
+ t2.productName,
|
|
|
+ SUM(t2.num) AS num,
|
|
|
+ SUM(t2.num * t2.price) AS totalPrice
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ o.delivery_name AS deliveryName,
|
|
|
+ JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].goodsName'))) AS productName,
|
|
|
+ CAST(JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].num'))) AS DECIMAL(10,0)) AS num,
|
|
|
+ CAST(JSON_UNQUOTE(JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].price'))) AS DECIMAL(10,2)) AS price
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ CROSS JOIN (SELECT 0 AS idx UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) seq
|
|
|
+ <where>
|
|
|
+ o.delivery_status IN (4, 5, 6)
|
|
|
+ AND JSON_EXTRACT(o.item_json, CONCAT('$[', seq.idx, '].goodsName')) IS NOT NULL
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ ) t2
|
|
|
+ <where>
|
|
|
+ <if test="productName != null and productName != ''"> AND t2.productName LIKE CONCAT('%', #{productName}, '%')</if>
|
|
|
+ </where>
|
|
|
+ GROUP BY t2.deliveryName, t2.productName
|
|
|
+ ) t
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 拒收未还货报表 -->
|
|
|
+ <select id="selectGuCoinRejectNoReturnReport" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="com.fs.his.domain.vo.FsRejectNoReturnReportVO">
|
|
|
+ SELECT
|
|
|
+ o.order_code AS orderCode,
|
|
|
+ o.delivery_sn AS deliverySn,
|
|
|
+ o.user_name AS userName,
|
|
|
+ o.user_address AS userAddress,
|
|
|
+ o.delivery_time AS deliveryTime,
|
|
|
+ o.total_money AS totalPrice,
|
|
|
+ o.follow_time AS followTime,
|
|
|
+ o.delivery_name AS deliveryName
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company c ON o.company_id = c.company_id
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
|
|
|
+ <where>
|
|
|
+ o.delivery_status = 4 AND (o.is_return_goods IS NULL OR o.is_return_goods = 2)
|
|
|
+ <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
|
|
|
+ <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
|
|
|
+ <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
|
|
|
+ <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
|
|
|
+ <if test="totalPrice != null"> AND o.total_money = #{totalPrice}</if>
|
|
|
+ <if test="followTimeStart != null and followTimeStart != ''"> AND o.follow_time >= #{followTimeStart}</if>
|
|
|
+ <if test="followTimeEnd != null and followTimeEnd != ''"> AND o.follow_time <= #{followTimeEnd}</if>
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="deliveryStartTime != null"> AND o.delivery_time >= #{deliveryStartTime}</if>
|
|
|
+ <if test="deliveryEndTime != null"> AND o.delivery_time <= #{deliveryEndTime}</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ ORDER BY o.order_id DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 拒收未还货合计 -->
|
|
|
+ <select id="selectGuCoinRejectNoReturnReportSum" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="java.util.Map">
|
|
|
+ SELECT
|
|
|
+ SUM(o.total_money) AS totalPrice
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company c ON o.company_id = c.company_id
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
|
|
|
+ <where>
|
|
|
+ o.delivery_status = 4 AND (o.is_return_goods IS NULL OR o.is_return_goods = 2)
|
|
|
+ <if test="orderCode != null and orderCode != ''"> AND o.order_code = #{orderCode}</if>
|
|
|
+ <if test="deliverySn != null and deliverySn != ''"> AND o.delivery_sn = #{deliverySn}</if>
|
|
|
+ <if test="userName != null and userName != ''"> AND o.user_name LIKE CONCAT('%', #{userName}, '%')</if>
|
|
|
+ <if test="userAddress != null and userAddress != ''"> AND o.user_address LIKE CONCAT('%', #{userAddress}, '%')</if>
|
|
|
+ <if test="totalPrice != null"> AND o.total_money = #{totalPrice}</if>
|
|
|
+ <if test="followTimeStart != null and followTimeStart != ''"> AND o.follow_time >= #{followTimeStart}</if>
|
|
|
+ <if test="followTimeEnd != null and followTimeEnd != ''"> AND o.follow_time <= #{followTimeEnd}</if>
|
|
|
+ <if test="deliveryName != null and deliveryName != ''"> AND o.delivery_name LIKE CONCAT('%', #{deliveryName}, '%')</if>
|
|
|
+ <if test="deliveryStartTime != null"> AND o.delivery_time >= #{deliveryStartTime}</if>
|
|
|
+ <if test="deliveryEndTime != null"> AND o.delivery_time <= #{deliveryEndTime}</if>
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 签收情况明细表 -->
|
|
|
+ <select id="selectGuCoinSignDetailReport" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="com.fs.his.domain.vo.FsSignDetailReportVO">
|
|
|
+ SELECT
|
|
|
+ t.order_type AS orderType,
|
|
|
+ t.delivery_count AS deliveryCount,
|
|
|
+ t.delivery_amount AS deliveryAmount,
|
|
|
+ t.sign_count AS signCount,
|
|
|
+ t.sign_amount AS signAmount,
|
|
|
+ CASE WHEN t.delivery_count > 0
|
|
|
+ THEN CONCAT(ROUND(t.sign_count * 100.0 / t.delivery_count, 2), '%')
|
|
|
+ ELSE '0%' END AS orderSignRate,
|
|
|
+ CASE WHEN t.delivery_amount > 0
|
|
|
+ THEN CONCAT(ROUND(t.sign_amount * 100.0 / t.delivery_amount, 2), '%')
|
|
|
+ ELSE '0%' END AS amountSignRate,
|
|
|
+ t.dept_name AS deptName,
|
|
|
+ t.company_name AS companyName
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ 5 AS order_type,
|
|
|
+ COUNT(o.order_id) AS delivery_count,
|
|
|
+ COALESCE(SUM(o.total_money), 0) AS delivery_amount,
|
|
|
+ COUNT(CASE WHEN o.delivery_status = 3 THEN 1 END) AS sign_count,
|
|
|
+ COALESCE(SUM(CASE WHEN o.delivery_status = 3 THEN o.total_money ELSE 0 END), 0) AS sign_amount,
|
|
|
+ d.dept_name AS dept_name,
|
|
|
+ c.company_name AS company_name
|
|
|
+ FROM fs_gu_coin_order o
|
|
|
+ LEFT JOIN company c ON o.company_id = c.company_id
|
|
|
+ LEFT JOIN company_user cu ON o.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
|
|
|
+ <where>
|
|
|
+ o.status >= 3
|
|
|
+ <if test="companyId != null"> AND o.company_id = #{companyId}</if>
|
|
|
+ <if test="deptId != null"> AND cu.dept_id = #{deptId}</if>
|
|
|
+ <if test="sTime != null and sTime != ''"> AND o.create_time >= #{sTime}</if>
|
|
|
+ <if test="eTime != null and eTime != ''"> AND o.create_time <= #{eTime}</if>
|
|
|
+ </where>
|
|
|
+ GROUP BY d.dept_id, d.dept_name, c.company_id, c.company_name
|
|
|
+ ) t
|
|
|
+ <where>
|
|
|
+ <if test="deliveryCount != null"> AND t.delivery_count = #{deliveryCount}</if>
|
|
|
+ <if test="deliveryAmount != null"> AND t.delivery_amount = #{deliveryAmount}</if>
|
|
|
+ <if test="signCount != null"> AND t.sign_count = #{signCount}</if>
|
|
|
+ <if test="signAmount != null"> AND t.sign_amount = #{signAmount}</if>
|
|
|
+ </where>
|
|
|
+ ORDER BY t.company_name, t.dept_name
|
|
|
+ </select>
|
|
|
</mapper>
|