<?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="houseMailRecordServiceDaoImpl">
|
|
<!-- 保存房屋邮寄记录信息 -->
|
<insert id="saveHouseMailRecordInfo" parameterType="Map">
|
insert into house_mail_record(
|
id, owner_id, house_id, send_date, mail_no,
|
service_fee, mail_result, remark, create_time, update_time, callable_id
|
) values (
|
#{id}, #{ownerId}, #{houseId}, #{sendDate},
|
<if test="mailNo == null">''</if>
|
<if test="mailNo != null">#{mailNo}</if>,
|
#{serviceFee}, #{mailResult}, #{remark},
|
<if test="createTime == null">CURRENT_TIMESTAMP</if>
|
<if test="createTime != null">#{createTime}</if>,
|
<if test="updateTime == null">CURRENT_TIMESTAMP</if>
|
<if test="updateTime != null">#{updateTime}</if>,
|
#{callableId}
|
)
|
</insert>
|
|
<!-- 批量插入房屋邮寄记录 -->
|
<insert id="saveHouseMailRecords" parameterType="Map">
|
insert into house_mail_record(
|
id, owner_id, house_id, send_date, mail_no,
|
service_fee, mail_result, remark, create_time, update_time, callable_id
|
) values
|
<foreach collection="houseMailRecordPos" item="item" separator=",">
|
( #{item.id}, #{item.ownerId}, #{item.houseId}, #{item.sendDate},
|
<if test="item.mailNo == null">''</if><if test="item.mailNo != null">#{item.mailNo}</if>,
|
#{item.serviceFee}, #{item.mailResult}, #{item.remark},
|
<if test="item.createTime == null">CURRENT_TIMESTAMP</if><if test="item.createTime != null">#{item.createTime}</if>,
|
<if test="item.updateTime == null">CURRENT_TIMESTAMP</if><if test="item.updateTime != null">#{item.updateTime}</if>,
|
#{item.callableId})
|
</foreach>
|
</insert>
|
|
<!-- 查询房屋邮寄记录信息(单条/多条) -->
|
<select id="getHouseMailRecordInfo" parameterType="Map" resultType="Map">
|
select
|
t.id,
|
t.owner_id as ownerId,
|
t.house_id as houseId,
|
t.send_date as sendDate,
|
t.mail_no as mailNo,
|
t.service_fee as serviceFee,
|
t.mail_result as mailResult,
|
t.remark,
|
t.create_time as createTime,
|
t.update_time as updateTime,
|
t.callable_id as callableId
|
from house_mail_record t
|
where 1 = 1
|
<if test="id != null">
|
and t.id = #{id}
|
</if>
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="sendDate != null">
|
and t.send_date = #{sendDate}
|
</if>
|
<if test="mailNo != null and mailNo != ''">
|
and t.mail_no = #{mailNo}
|
</if>
|
<if test="serviceFee != null">
|
and t.service_fee = #{serviceFee}
|
</if>
|
<if test="mailResult != null and mailResult != ''">
|
and t.mail_result = #{mailResult}
|
</if>
|
<if test="callableId != null and callableId != ''">
|
and t.callable_id = #{callableId}
|
</if>
|
<!-- 时间范围查询 -->
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
<if test="startCreateTime != null">
|
and t.create_time >= #{startCreateTime}
|
</if>
|
<if test="endCreateTime != null">
|
and t.create_time <= #{endCreateTime}
|
</if>
|
<!-- 结果列表筛选 -->
|
<if test="mailResultList != null and mailResultList.size() > 0">
|
and t.mail_result in
|
<foreach collection="mailResultList" item="item" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
order by t.id desc
|
<if test="page != -1 and page != null ">
|
limit #{page}, #{row}
|
</if>
|
</select>
|
|
<!-- 查询房屋邮寄记录数量 -->
|
<select id="queryHouseMailRecordsCount" parameterType="Map" resultType="Map">
|
select count(1) count
|
from house_mail_record t
|
where 1 = 1
|
<if test="id != null">
|
and t.id = #{id}
|
</if>
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="sendDate != null">
|
and t.send_date = #{sendDate}
|
</if>
|
<if test="mailNo != null and mailNo != ''">
|
and t.mail_no = #{mailNo}
|
</if>
|
<if test="serviceFee != null">
|
and t.service_fee = #{serviceFee}
|
</if>
|
<if test="mailResult != null and mailResult != ''">
|
and t.mail_result = #{mailResult}
|
</if>
|
<if test="callableId != null and callableId != ''">
|
and t.callable_id = #{callableId}
|
</if>
|
<!-- 时间范围查询 -->
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
<if test="startCreateTime != null">
|
and t.create_time >= #{startCreateTime}
|
</if>
|
<if test="endCreateTime != null">
|
and t.create_time <= #{endCreateTime}
|
</if>
|
</select>
|
|
<!-- 修改房屋邮寄记录信息 -->
|
<update id="updateHouseMailRecordInfo" parameterType="Map">
|
update house_mail_record t set
|
<if test="ownerId != null and ownerId != ''">
|
t.owner_id = #{ownerId},
|
</if>
|
<if test="houseId != null and houseId != ''">
|
t.house_id = #{houseId},
|
</if>
|
<if test="sendDate != null">
|
t.send_date = #{sendDate},
|
</if>
|
<if test="mailNo != null">
|
t.mail_no = #{mailNo},
|
</if>
|
<if test="serviceFee != null">
|
t.service_fee = #{serviceFee},
|
</if>
|
<if test="mailResult != null and mailResult != ''">
|
t.mail_result = #{mailResult},
|
</if>
|
<if test="remark != null">
|
t.remark = #{remark},
|
</if>
|
<if test="updateTime != null">
|
t.update_time = #{updateTime},
|
</if>
|
<if test="callableId != null and callableId != ''">
|
t.callable_id = #{callableId},
|
</if>
|
t.update_time = CURRENT_TIMESTAMP
|
where 1 = 1
|
<if test="id != null">
|
and t.id = #{id}
|
</if>
|
<if test="ownerId != null and ownerId != '' and houseId != null and houseId != ''">
|
and t.owner_id = #{ownerId} and t.house_id = #{houseId}
|
</if>
|
</update>
|
|
<!-- 删除房屋邮寄记录信息 -->
|
<delete id="deleteHouseMailRecordInfo" parameterType="Map">
|
delete from house_mail_record t
|
where 1 = 1
|
<if test="id != null">
|
and t.id = #{id}
|
</if>
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="mailResult != null and mailResult != ''">
|
and t.mail_result = #{mailResult}
|
</if>
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
</delete>
|
|
<!-- 查询房屋邮寄记录统计信息 -->
|
<select id="queryHouseMailRecordStatistics" parameterType="Map" resultType="Map">
|
select
|
count(1) as total_count,
|
sum(t.service_fee) as total_service_fee,
|
avg(t.service_fee) as avg_service_fee,
|
max(t.service_fee) as max_service_fee,
|
min(t.service_fee) as min_service_fee,
|
count(distinct t.owner_id) as distinct_owner_count,
|
count(distinct t.house_id) as distinct_house_count,
|
min(t.send_date) as earliest_send_date,
|
max(t.send_date) as latest_send_date,
|
-- 按邮寄结果分组统计数量
|
sum(case when t.mail_result = 'SENT' or t.mail_result = '已寄出' then 1 else 0 end) as sent_count,
|
sum(case when t.mail_result = 'PENDING' or t.mail_result = '待寄出' then 1 else 0 end) as pending_count,
|
sum(case when t.mail_result is null then 1 else 0 end) as unknown_result_count
|
from house_mail_record t
|
where 1 = 1
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
<if test="mailResult != null and mailResult != ''">
|
and t.mail_result = #{mailResult}
|
</if>
|
</select>
|
|
<!-- 按邮寄结果分组统计 -->
|
<select id="queryHouseMailRecordByMailResult" parameterType="Map" resultType="Map">
|
select
|
t.mail_result,
|
count(1) as count,
|
sum(t.service_fee) as service_fee_sum,
|
avg(t.service_fee) as service_fee_avg,
|
min(t.send_date) as earliest_send_date,
|
max(t.send_date) as latest_send_date
|
from house_mail_record t
|
where 1 = 1
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
group by t.mail_result
|
order by count desc
|
</select>
|
|
<!-- 按年月维度统计邮寄费用 -->
|
<select id="queryHouseMailRecordByMonth" parameterType="Map" resultType="Map">
|
select
|
date_format(t.send_date, '%Y-%m') as month,
|
count(1) as total_count,
|
sum(t.service_fee) as total_service_fee,
|
avg(t.service_fee) as avg_service_fee,
|
count(distinct t.house_id) as house_count
|
from house_mail_record t
|
where 1 = 1
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
group by date_format(t.send_date, '%Y-%m')
|
order by month desc
|
</select>
|
|
<!-- 查询未完成邮寄的记录(待寄出/结果为空) -->
|
<select id="queryUnfinishedMailRecords" parameterType="Map" resultType="Map">
|
select
|
t.id,
|
t.owner_id as ownerId,
|
t.house_id as houseId,
|
t.send_date as sendDate,
|
t.mail_no as mailNo,
|
t.service_fee as serviceFee,
|
t.mail_result as mailResult,
|
t.remark,
|
datediff(curdate(), t.send_date) as overdue_days
|
from house_mail_record t
|
where 1 = 1
|
and (t.mail_result = 'PENDING'
|
or t.mail_result = '待寄出'
|
or t.mail_result is null)
|
<if test="ownerId != null and ownerId != ''">
|
and t.owner_id = #{ownerId}
|
</if>
|
<if test="houseId != null and houseId != ''">
|
and t.house_id = #{houseId}
|
</if>
|
<if test="startSendDate != null">
|
and t.send_date >= #{startSendDate}
|
</if>
|
<if test="endSendDate != null">
|
and t.send_date <= #{endSendDate}
|
</if>
|
order by overdue_days desc, t.send_date asc
|
<if test="page != -1 and page != null ">
|
limit #{page}, #{row}
|
</if>
|
</select>
|
|
</mapper>
|