Files
biz-api-cloud-zax/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml
T

385 lines
16 KiB
XML

<?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.bsd.pjcloud.hard.mapper.order.HardOrderMapper">
<resultMap id="hardwareOrderMap" type="com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity">
<id property="id" column="id"/>
<result property="orderNo" column="order_no"/>
<result property="userId" column="user_id"/>
<result property="userDeptId" column="user_dept_id"/>
<result property="merchantId" column="merchant_id"/>
<result property="merchantType" column="merchant_type"/>
<result property="merchantDeptId" column="merchant_dept_id"/>
<result property="hardId" column="hard_id"/>
<result property="deptId" column="dept_id"/>
<result property="walletId" column="wallet_id"/>
<result property="parentCarId" column="parent_car_id"/>
<result property="orderSourceTypeId" column="order_source_type_id"/>
<result property="orderType" column="order_type"/>
<result property="orderStatus" column="order_status"/>
<result property="payType" column="pay_type"/>
<result property="hourType" column="hour_type"/>
<result property="sysType" column="sys_type"/>
<result property="totalPrice" column="total_price"/>
<result property="extraPrice" column="extra_price"/>
<result property="payPrice" column="pay_price"/>
<result property="payTime" column="pay_time"/>
<result property="payRefundId" column="pay_refund_id"/>
<result property="refundPrice" column="refund_price"/>
<result property="refundTime" column="refund_time"/>
<result property="refundStatus" column="refund_status"/>
<result property="applyCancelTime" column="apply_cancel_time"/>
<result property="androidOrderCode" column="android_order_code"/>
<result property="isOfflineOrder" column="is_offline_order"/>
<result property="productDesc" column="product_desc"/>
<result property="offlinePaySuccess" column="offline_pay_success"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
<sql id="selectA">
select a.id,
a.order_no,
a.user_id,
a.user_dept_id,
a.merchant_id,
a.merchant_type,
a.merchant_dept_id,
a.hard_id,
a.dept_id,
a.wallet_id,
a.parent_car_id,
a.order_source_type_id,
a.order_type,
a.order_status,
a.pay_type,
a.hour_type,
a.sys_type,
a.total_price,
a.extra_price,
a.pay_price,
a.pay_time,
a.pay_refund_id,
a.refund_price,
a.refund_time,
a.refund_status,
a.apply_cancel_time,
a.android_order_code,
a.is_offline_order,
a.product_desc,
a.offline_pay_success,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.del_flag,
a.tenant_id,
</sql>
<sql id="whereA">
a.del_flag = '0'
<if test="dto.orderStatus != null and dto.orderStatus != '' ">
and a.order_status = #{dto.orderStatus}
</if>
<if test="dto.merchantType != null and dto.merchantType != '' ">
and a.merchant_type = #{dto.merchantType}
</if>
<if test="dto.orderType != null and dto.orderType != '' ">
and a.order_type = #{dto.orderType}
</if>
<if test="dto.hourType != null and dto.hourType != '' ">
and a.hour_type = #{dto.hourType}
</if>
<if test="dto.deptId != null">
and a.dept_id = #{dto.deptId}
</if>
<if test="dto.merchantId != null">
and a.merchant_id = #{dto.merchantId}
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and a.dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and a.dept_id NOT IN
</when>
<otherwise>
and a.dept_id IN
</otherwise>
</choose>
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.userDeptIds != null and dto.userDeptIds.size() != 0">
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and a.user_dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and a.user_dept_id NOT IN
</when>
<otherwise>
and a.user_dept_id IN
</otherwise>
</choose>
<foreach collection="dto.userDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.merchantDeptIds != null and dto.merchantDeptIds.size() != 0">
and a.merchant_dept_id in
<foreach collection="dto.merchantDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.userIds != null and dto.userIds.size() != 0">
and a.user_id in
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.mchIds != null and dto.mchIds.size() != 0">
and a.merchant_id in
<foreach collection="dto.mchIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and a.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.orderPayTypeCodes != null and dto.orderPayTypeCodes.size() != 0">
and a.pay_type in
<foreach collection="dto.orderPayTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.mchTypeCodes != null and dto.mchTypeCodes.size() != 0">
and a.merchant_type in
<foreach collection="dto.mchTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.payTimeList != null and dto.payTimeList.length == 2">
and a.pay_time between #{dto.payTimeList[0]} and #{dto.payTimeList[1]}
</if>
</sql>
<select id="scopePageList" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderVo">
<include refid="selectA"/>
m.name as hardName,
m.type as hardType,
m.dept_id as hardTypeDeptId
from hard_order a
left join hard_manager m on m.id = a.hard_id
<where>
<include refid="whereA"/>
<if test="dto.hardTypeCode != null and dto.hardTypeCode != '' ">
and m.type = #{dto.hardTypeCode}
</if>
<if test="dto.hardTypeCodes != null and dto.hardTypeCodes.size() != 0">
and m.type in
<foreach collection="dto.hardTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
order by a.create_time desc, a.user_id desc
</select>
<select id="listSb" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo">
select
a.hard_id,
a.merchant_id,
a.user_dept_id,
a.merchant_dept_id,
sum(a.pay_price) as totalPayPrice,
count(0) as totalPayCount
from hard_order a
left join hard_manager m on a.hard_id = m.id
<where>
<include refid="whereA"/>
and a.hard_id is not null
<if test="dto.hardTypeCodes != null and dto.hardTypeCodes.size() != 0">
and m.type in
<foreach collection="dto.hardTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.hard_id
</select>
<select id="listCs" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select
a.merchant_id,
a.user_dept_id,
a.merchant_dept_id,
sum(a.pay_price) as totalPayPrice,
count(0) as totalPayCount
from hard_order a
<where>
<include refid="whereA"/>
and a.merchant_id is not null
<if test="dto.hardTypeCodes != null and dto.hardTypeCodes.size() != 0">
and m.type in
<foreach collection="dto.hardTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.merchant_id
</select>
<select id="listCsByDay" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select a.merchant_id,
DATE_FORMAT(a.create_time, '%Y-%m-%d') as day,
sum(a.pay_price) as totalPayPrice,
count(0) as totalPayCount
from hard_order a
<where>
<include refid="whereA"/>
</where>
group by a.merchant_id, DATE_FORMAT(a.create_time, '%Y-%m-%d')
order by DATE_FORMAT(a.create_time, '%Y-%m-%d') desc, a.merchant_id desc
</select>
<select id="listCsTotal" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select a.merchant_id,
sum(a.pay_price) as totalPayPrice,
count(0) as totalPayCount
from hard_order a
<where>
<include refid="whereA"/>
</where>
</select>
<select id="listOrerPayType" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderPayTypeVo">
select
a.pay_type,
a.merchant_dept_id,
sum(a.pay_price) as totalPayPrice,
count(0) as totalPayCount
from hard_order a
<where>
<include refid="whereA"/>
</where>
group by a.pay_type
</select>
<select id="sumAndCount" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo">
select
a.user_dept_id as deptId,
sum(a.pay_price) as sum,
count(0) as count
from hard_order a
<where>
a.del_flag = 0
<if test="dto.walletTypeId != null">
</if>
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and a.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.getUserDeptIds != null and dto.getUserDeptIds.size() != 0">
and a.user_dept_id in
<foreach collection="dto.getUserDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.mchIds != null and dto.mchIds.size() != 0">
and a.merchant_id in
<foreach collection="dto.mchIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.user_dept_id
</select>
<select id="sumAndCountTotalByHourType" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo">
select
a.hour_type as hourType,
COALESCE(sum(a.pay_price), 0) as sum,
COALESCE(count(0), 0) as count
from hard_order a
<where>
a.del_flag = 0 and a.hour_type is not null
<if test="dto.walletTypeId != null">
</if>
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and a.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.getUserDeptIds != null and dto.getUserDeptIds.size() != 0">
and a.user_dept_id in
<foreach collection="dto.getUserDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.mchIds != null and dto.mchIds.size() != 0">
and a.merchant_id in
<foreach collection="dto.mchIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.hour_type
</select>
<select id="totalYearMonthDay" resultType="com.bsd.pjcloud.hard.api.vo.order.HardZyCardSyncVo">
SELECT
COALESCE(COUNT(0), 0) AS totalNum,
COALESCE(SUM(a.pay_price), 0) AS totalMoney,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) THEN 1 ELSE 0 END), 0) AS totalNumYear,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) THEN a.pay_price ELSE 0 END), 0) AS
totalMoneyYear,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) AND MONTH(a.create_time) =
MONTH(CURRENT_DATE()) THEN 1 ELSE 0 END), 0) AS totalNumMonth,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) AND MONTH(a.create_time) =
MONTH(CURRENT_DATE()) THEN a.pay_price ELSE 0 END), 0) AS totalMoneyMonth,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) AND MONTH(a.create_time) =
MONTH(CURRENT_DATE()) AND DAY(a.create_time) = DAY(CURRENT_DATE()) THEN 1 ELSE 0 END), 0) AS totalNumDay,
COALESCE(SUM(CASE WHEN YEAR(a.create_time) = YEAR(CURRENT_DATE()) AND MONTH(a.create_time) =
MONTH(CURRENT_DATE()) AND DAY(a.create_time) = DAY(CURRENT_DATE()) THEN a.pay_price ELSE 0 END), 0) AS
totalMoneyDay
FROM
hard_order a
<where>
a.del_flag = 0
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and a.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.orderTypeCodes != null and dto.orderTypeCodes.size() != 0">
and a.order_type in
<foreach collection="dto.orderTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
</select>
</mapper>