ghy-all/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml

449 lines
19 KiB
XML
Raw Normal View History

2022-04-25 17:06:55 +08:00
<?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.ghy.order.mapper.OrderMasterMapper">
<resultMap id="OrderMasterResult" type="com.ghy.order.domain.OrderMaster">
<id property="id" column="id"/>
2022-05-24 22:26:26 +08:00
<result property="deptId" column="dept_id"/>
2022-04-25 17:06:55 +08:00
<result property="code" column="code"/>
<result property="customerId" column="customer_id"/>
2023-05-10 20:14:07 +08:00
<result property="addressId" column="address_id"/>
2022-04-25 17:06:55 +08:00
<result property="orderType" column="order_type"/>
2023-06-01 21:41:59 +08:00
<result property="orderMode" column="order_mode"/>
2022-04-25 17:06:55 +08:00
<result property="orderStatus" column="order_status"/>
<result property="payType" column="pay_type"/>
<result property="payStatus" column="pay_status"/>
<result property="workerId" column="worker_id"/>
<result property="payTime" column="pay_time"/>
<result property="revTime" column="rev_time"/>
<result property="expectTimeStart" column="expect_time_start"/>
<result property="expectTimeEnd" column="expect_time_end"/>
2022-04-25 17:06:55 +08:00
<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="remark" column="remark"/>
<result property="goodsId" column="goods_id"/>
2023-05-10 20:14:07 +08:00
<result property="allSelfAssigned" column="all_self_assigned"/>
<result property="hasDispatchedAll" column="has_dispatched_all"/>
2023-05-09 19:53:44 +08:00
<result property="timeout" column="timeout_"/>
2023-05-10 20:14:07 +08:00
<result property="timeoutFineTimes" column="timeout_fine_times"/>
2023-06-04 01:40:36 +08:00
<result property="isCall" column="is_call" />
2023-06-05 00:56:03 +08:00
<result property="serverMoney" column="server_money" />
2022-04-25 17:06:55 +08:00
</resultMap>
<sql id="selectOrderMaster">
SELECT id,
2022-05-24 22:26:26 +08:00
dept_id,
2022-04-25 17:06:55 +08:00
code,
customer_id,
2022-06-09 14:35:13 +08:00
address_id,
2022-04-25 17:06:55 +08:00
order_type,
2023-06-01 21:41:59 +08:00
order_mode,
2022-04-25 17:06:55 +08:00
order_status,
pay_type,
pay_status,
worker_id,
pay_time,
rev_time,
expect_time_start,
expect_time_end,
2022-04-25 17:06:55 +08:00
create_by,
create_time,
2023-05-10 20:14:07 +08:00
update_time,
remark,
2023-02-17 21:11:23 +08:00
all_self_assigned,
2023-05-09 19:53:44 +08:00
goods_id,
2023-05-10 20:14:07 +08:00
timeout_,
2023-06-04 01:40:36 +08:00
timeout_fine_times,
2023-06-05 00:56:03 +08:00
is_call,
order_mode
2022-04-25 17:06:55 +08:00
FROM order_master
</sql>
<sql id="selectOrderMasterMoreInfo">
SELECT om.id,
om.dept_id,
om.code,
om.customer_id,
om.address_id,
om.order_type,
2023-06-01 21:41:59 +08:00
om.order_mode,
om.order_status,
om.pay_type,
om.pay_status,
om.worker_id,
om.pay_time,
om.rev_time,
om.expect_time_start,
om.expect_time_end,
om.create_by,
om.create_time,
2023-05-10 20:14:07 +08:00
om.update_time,
om.remark,
om.all_self_assigned,
2023-05-09 19:53:44 +08:00
om.goods_id,
2023-05-10 20:14:07 +08:00
om.timeout_,
2023-06-04 01:40:36 +08:00
om.timeout_fine_times,
2023-06-05 00:56:03 +08:00
om.is_call,
fm.server_money
FROM order_master om
LEFT JOIN customer_address ca ON ca.customer_address_id = om.address_id
LEFT JOIN goods g ON g.goods_id = om.goods_id
2023-06-01 21:41:59 +08:00
LEFT JOIN financial_master fm ON om.id = fm.order_master_id
</sql>
2022-04-25 17:06:55 +08:00
<select id="selectOrderMasterList" parameterType="com.ghy.order.domain.OrderMaster" resultMap="OrderMasterResult">
<include refid="selectOrderMasterMoreInfo"></include>
2022-04-25 17:06:55 +08:00
<where>
<if test="isMonitoredOrder">
AND (om.all_self_assigned = 0 or om.all_self_assigned is null) AND om.order_status in (1,2,3,4)
</if>
<if test="allSelfAssigned != null">
AND all_self_assigned = #{allSelfAssigned}
</if>
2022-05-24 22:26:26 +08:00
<if test="deptId != null and deptId != 0">
AND om.dept_id = #{deptId}
2022-05-24 22:26:26 +08:00
</if>
2022-04-25 17:06:55 +08:00
<if test="code != null and code != ''">
AND om.code LIKE concat('%', #{code}, '%')
2022-04-25 17:06:55 +08:00
</if>
<if test="customerId != null and customerId != 0">
AND om.customer_id = #{customerId}
2022-04-25 17:06:55 +08:00
</if>
2022-11-16 01:58:58 +08:00
<if test="customerIds != null and customerIds.size > 0">
AND om.customer_id in
<foreach item="customerId" collection="customerIds" open="(" separator="," close=")">
#{customerId}
</foreach>
</if>
2022-05-24 22:26:26 +08:00
<if test="orderType != null">
AND om.order_type = #{orderType}
2022-04-25 17:06:55 +08:00
</if>
2022-05-24 22:26:26 +08:00
<if test="orderStatus != null">
AND om.order_status = #{orderStatus}
2022-04-25 17:06:55 +08:00
</if>
2022-05-24 22:26:26 +08:00
<if test="payType != null">
AND om.pay_type = #{payType}
2022-04-25 17:06:55 +08:00
</if>
2022-05-24 22:26:26 +08:00
<if test="payStatus != null">
AND om.pay_status = #{payStatus}
2022-04-25 17:06:55 +08:00
</if>
2022-10-17 00:07:02 +08:00
<if test="payStatusList != null">
AND om.pay_status in ( #{payStatusList} )
</if>
<if test="workerId != null and workerId > 0">
AND om.worker_id = #{workerId}
2022-04-25 17:06:55 +08:00
</if>
<if test="workerId == -1">
AND om.worker_id IS NULL
2023-06-01 21:41:59 +08:00
AND ( (om.order_mode in ('01','03','04'))
OR (om.order_mode = '02' and fm.pay_status = 1) OR (om.order_mode is null))
</if>
<if test="sysPayStatus != null">
AND fm.pay_status = #{sysPayStatus}
</if>
<if test="orderMode != null and orderMode != ''">
AND om.order_mode = #{orderMode}
</if>
<if test="goodsCategoryId != null">
AND g.dept_goods_category_id = #{goodsCategoryId}
</if>
<if test="goodsName != null and goodsName != ''">
AND g.goods_name like concat('%', #{goodsName}, '%')
</if>
<if test="countryId != null">
AND ca.country_id = #{countryId}
</if>
<if test="exceptOrderStatus != null">
AND om.order_status != #{exceptOrderStatus}
</if>
<if test="createTimeStart != null">
AND om.create_time &gt;= #{createTimeStart}
</if>
<if test="createTimeEnd != null">
2023-06-26 00:02:43 +08:00
AND om.create_time &lt;= #{createTimeEnd}
</if>
2022-10-06 18:29:47 +08:00
<if test="orderMasterIds != null and orderMasterIds != ''">
AND om.id in (${orderMasterIds})
2022-09-25 22:46:05 +08:00
</if>
2022-10-06 18:29:47 +08:00
<if test="orderStatuses != null and orderStatuses != ''">
AND om.order_status in (${orderStatuses})
</if>
2022-11-18 02:37:06 +08:00
<if test="hasDispatchedAll != null">
AND om.has_dispatched_all = #{hasDispatchedAll}
</if>
2022-12-11 21:38:01 +08:00
<if test="exceptOrderMasterIds != null and exceptOrderMasterIds.size > 0">
AND om.id not in
<foreach collection="exceptOrderMasterIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="timeout != null">
AND om.timeout_ = #{timeout}
</if>
2023-06-04 01:40:36 +08:00
<if test="isCall != null">
2023-06-04 01:57:21 +08:00
AND om.is_call = #{isCall}
2023-06-04 01:40:36 +08:00
</if>
2023-06-07 23:24:58 +08:00
<if test="expectTimeStart != null">
AND om.expect_time_start &gt;= #{expectTimeStart}
</if>
<if test="expectTimeEnd != null">
AND om.expect_time_end &lt;= #{expectTimeEnd}
</if>
2022-04-25 17:06:55 +08:00
</where>
order by om.create_time
<trim suffixOverrides=",">
<choose>
<when test="params.createTimeSort != null and params.createTimeSort != ''">
${params.createTimeSort}
</when>
<otherwise>
desc
</otherwise>
</choose>
</trim>
2022-04-25 17:06:55 +08:00
</select>
2022-07-13 11:11:04 +08:00
<select id="countOrderMasterList" parameterType="com.ghy.order.domain.OrderMaster" resultType="Long">
2023-06-07 23:24:58 +08:00
SELECT COUNT(*)
FROM order_master om
LEFT JOIN financial_master fm ON om.id = fm.order_master_id
2022-07-13 11:11:04 +08:00
<where>
<if test="isMonitoredOrder">
2023-05-17 21:50:03 +08:00
AND (om.all_self_assigned = 0 or om.all_self_assigned is null) AND om.order_status in (1,2,3,4)
</if>
2022-07-13 11:11:04 +08:00
<if test="deptId != null and deptId != 0">
AND om.dept_id = #{deptId}
</if>
<if test="code != null and code != ''">
AND om.code LIKE concat('%', #{code}, '%')
</if>
<if test="customerId != null and customerId != 0">
AND om.customer_id = #{customerId}
</if>
<if test="orderType != null">
AND om.order_type = #{orderType}
</if>
<if test="orderStatus != null">
AND om.order_status = #{orderStatus}
</if>
2022-10-31 00:07:07 +08:00
<if test="orderStatuses != null and orderStatuses != ''">
AND om.order_status in (${orderStatuses})
</if>
2022-07-13 11:11:04 +08:00
<if test="payType != null">
AND om.pay_type = #{payType}
</if>
<if test="payStatus != null">
AND om.pay_status = #{payStatus}
</if>
<if test="payStatusList != null">
AND om.pay_status in ( #{payStatusList} )
</if>
2022-07-13 11:11:04 +08:00
<if test="workerId != null and workerId > 0">
AND om.worker_id = #{workerId}
</if>
<if test="workerId == -1">
AND om.worker_id IS NULL
2023-06-07 23:24:58 +08:00
AND ( (om.order_mode in ('01','03','04'))
OR (om.order_mode = '02' and fm.pay_status = 1) )
</if>
<if test="sysPayStatus != null">
AND fm.pay_status = #{sysPayStatus}
</if>
<if test="orderMode != null and orderMode != ''">
AND om.order_mode = #{orderMode}
2022-07-13 11:11:04 +08:00
</if>
<if test="exceptOrderStatus != null">
AND om.order_status != #{exceptOrderStatus}
</if>
2022-11-18 02:39:37 +08:00
<if test="hasDispatchedAll != null">
2022-11-18 02:41:12 +08:00
AND om.has_dispatched_all = #{hasDispatchedAll}
2022-11-18 02:39:37 +08:00
</if>
<if test="orderMasterIds != null and orderMasterIds != ''">
AND om.id in (${orderMasterIds})
</if>
2023-06-04 01:40:36 +08:00
<if test="isCall != null">
2023-06-04 01:57:21 +08:00
AND om.is_call = #{isCall}
2023-06-04 01:40:36 +08:00
</if>
2023-06-07 23:24:58 +08:00
<if test="expectTimeStart != null">
AND om.expect_time_start &gt;= #{expectTimeStart}
</if>
<if test="expectTimeEnd != null">
AND om.expect_time_end &lt;= #{expectTimeEnd}
</if>
2022-07-13 11:11:04 +08:00
</where>
</select>
2022-04-25 17:06:55 +08:00
<select id="selectById" parameterType="long" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
<where>
<if test="orderMasterId != null and orderMasterId != 0">
AND id = #{orderMasterId}
</if>
</where>
</select>
<delete id="deleteOrderMasterByIds" parameterType="Long">
DELETE FROM order_master WHERE id IN
<foreach collection="array" item="orderMasterId" open="(" separator="," close=")">
#{orderMasterId}
</foreach>
</delete>
<update id="updateOrderMaster" parameterType="com.ghy.order.domain.OrderMaster">
UPDATE order_master
<set>
<if test="code != null and code != ''">code = #{code},</if>
2022-05-24 22:26:26 +08:00
<if test="customerId != null and customerId != 0">customer_id = #{customerId},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</if>
<if test="payType != null">pay_type = #{payType},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="workerId != null and workerId != 0">worker_id = #{workerId},</if>
<if test="workerId == -1">
worker_id = NULL,
</if>
2022-05-24 22:26:26 +08:00
<if test="payTime != null">pay_time = #{payTime},</if>
<if test="revTime != null">rev_time = #{revTime},</if>
<if test="expectTimeStart != null">expect_time_start = #{expectTimeStart},</if>
<if test="expectTimeEnd != null">expect_time_end = #{expectTimeEnd},</if>
2022-10-27 00:54:15 +08:00
<if test="useTimeNotRange">expect_time_end = null,</if>
2022-04-25 17:06:55 +08:00
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="allSelfAssigned != null">all_self_assigned = #{allSelfAssigned},</if>
<if test="resetAllSelfAssigned">all_self_assigned = null,</if>
<if test="hasDispatchedAll != null">has_dispatched_all = #{hasDispatchedAll},</if>
2023-06-04 01:40:36 +08:00
<if test="isCall != null">is_call = #{isCall},</if>
<if test="timeout != null">timeout_ = #{timeout},</if>
2022-04-25 17:06:55 +08:00
update_time = SYSDATE()
</set>
WHERE id = #{id}
</update>
2022-07-20 15:10:01 +08:00
<update id="updateStatus">
UPDATE order_master
SET order_status = #{orderStatus},
update_time = SYSDATE()
WHERE id = #{orderMasterId}
</update>
<update id="updatePayStatus">
UPDATE order_master
SET pay_status = #{payStatus},
update_time = SYSDATE()
WHERE id = #{orderMasterId}
</update>
2022-04-25 17:06:55 +08:00
<insert id="insertOrderMaster" parameterType="com.ghy.order.domain.OrderMaster" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_master(
2022-05-24 22:26:26 +08:00
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="code != null and code != ''">code,</if>
<if test="customerId != null and customerId != 0">customer_id,</if>
2022-06-09 14:35:13 +08:00
<if test="addressId != null and addressId != 0">address_id,</if>
<if test="goodsId != null and goodsId != 0">goods_id,</if>
2022-05-24 22:26:26 +08:00
<if test="orderType != null">order_type,</if>
2023-06-01 21:41:59 +08:00
<if test="orderMode != null">order_mode,</if>
2022-05-24 22:26:26 +08:00
<if test="orderStatus != null">order_status,</if>
<if test="payType != null">pay_type,</if>
<if test="payStatus != null">pay_status,</if>
<if test="workerId != null and workerId != 0">worker_id,</if>
<if test="payTime != null">pay_time,</if>
<if test="revTime != null">rev_time,</if>
<if test="remark != null">remark,</if>
<if test="expectTimeStart != null">expect_time_start,</if>
<if test="expectTimeEnd != null">expect_time_end,</if>
2022-04-25 17:06:55 +08:00
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
2022-05-24 22:26:26 +08:00
<if test="deptId != null and deptId != 0">#{deptId},</if>
2022-05-12 14:30:06 +08:00
<if test="code != null">#{code},</if>
2022-05-24 22:26:26 +08:00
<if test="customerId != null and customerId != 0">#{customerId},</if>
2022-06-20 10:07:44 +08:00
<if test="addressId != null and addressId != 0">#{addressId},</if>
<if test="goodsId != null and goodsId != 0">#{goodsId},</if>
2022-05-24 22:26:26 +08:00
<if test="orderType != null">#{orderType},</if>
2023-06-01 21:41:59 +08:00
<if test="orderMode != null">#{orderMode},</if>
2022-05-24 22:26:26 +08:00
<if test="orderStatus != null">#{orderStatus},</if>
<if test="payType != null">#{payType},</if>
<if test="payStatus != null">#{payStatus},</if>
<if test="workerId != null and workerId != 0">#{workerId},</if>
<if test="payTime != null">#{payTime},</if>
<if test="revTime != null">#{revTime},</if>
<if test="remark != null">#{remark},</if>
<if test="expectTimeStart != null">#{expectTimeStart},</if>
<if test="expectTimeEnd != null">#{expectTimeEnd},</if>
2022-04-25 17:06:55 +08:00
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)
</insert>
<select id="checkOrderMasterCodeUnique" parameterType="String" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
WHERE `code` = #{orderMasterCode} LIMIT 1
2022-04-25 17:06:55 +08:00
</select>
2022-05-29 17:52:49 +08:00
<select id="selectByCode" parameterType="String" resultMap="OrderMasterResult">
2022-05-11 20:10:00 +08:00
<include refid="selectOrderMaster"/>
WHERE `code` = #{orderMasterCode}
</select>
<select id="selectByStatus" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
WHERE `order_status` IN
<foreach collection="list" item="orderStatus" open="(" separator="," close=")">
#{orderStatus}
</foreach>
</select>
<select id="selectUnfinished" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
WHERE `order_status` &lt; 5
</select>
2023-02-17 21:11:23 +08:00
<select id="selectByIds" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
<where>
AND id IN
<foreach item="item" index="orderMasterId" collection="orderMasterId" open="(" separator="," close=")">
#{item}
</foreach>
</where>
</select>
2023-05-09 19:53:44 +08:00
<update id="updateTimeout">
UPDATE order_master
SET timeout_ = #{timeout}
2023-05-10 20:14:07 +08:00
<if test="timeoutFineTimes != null">,timeout_fine_times = #{timeoutFineTimes}</if>
2023-05-09 19:53:44 +08:00
WHERE id = #{id}
</update>
<update id="removeWorker">
UPDATE order_master
SET worker_id = NULL
WHERE id = #{id}
</update>
2023-06-26 00:02:43 +08:00
<select id="differentStatusOrderCount" resultType="com.ghy.order.domain.OrderMasterCount" parameterType="com.ghy.order.domain.OrderMaster">
2023-06-07 23:24:58 +08:00
select
2023-06-26 00:02:43 +08:00
count(case when om.order_status = 0 then 1 else null end) as newOrderNum,
2023-06-07 23:24:58 +08:00
count(case when om.order_status = 1 then 1 else null end) as acceptedOrderNum,
2023-06-26 00:31:20 +08:00
count(case when om.order_status = 1 and om.is_call = '01' then 1 else null end) as notAppointedOrderNum,
count(case when om.order_status = 1 and om.is_call = '02' then 1 else null end) as notArrangedOrderNum,
2023-06-07 23:24:58 +08:00
count(case when om.order_status = 2 then 1 else null end) as waitForDoorOrderNum,
count(case when om.order_status = 3 then 1 else null end) as servingOrderNum,
count(case when om.order_status = 4 then 1 else null end) as confirmingOrderNum,
count(case when om.order_status = 5 then 1 else null end) as finishedOrderNum,
count(case when om.order_status = 6 then 1 else null end) as canceledOrderNum
from order_master om
2023-06-26 00:02:43 +08:00
where 1 = 1
<if test="timeout != null">
AND om.timeout_ = #{timeout}
</if>
2023-06-26 00:31:20 +08:00
<if test="isCall != null">
AND om.is_call = #{isCall}
</if>
2023-06-07 23:24:58 +08:00
</select>
2022-05-12 14:30:06 +08:00
</mapper>