ghy-all/ghy-payment/src/main/resources/mapper/financial/FinancialDetailMapper.xml

317 lines
15 KiB
XML
Raw Normal View History

<?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.payment.mapper.FinancialDetailMapper">
<resultMap id="FinancialDetailResult" type="com.ghy.payment.domain.FinancialDetail">
<id property="id" column="id"/>
2022-05-24 22:26:26 +08:00
<result property="deptId" column="dept_id"/>
<result property="code" column="code"/>
2022-05-24 22:26:26 +08:00
<result property="financialMasterId" column="financial_master_id"/>
2022-05-25 11:48:07 +08:00
<result property="financialMasterCode" column="financial_master_code"/>
2022-05-24 22:26:26 +08:00
<result property="orderDetailId" column="order_detail_id"/>
<result property="orderDetailCode" column="order_detail_code"/>
<result property="totalMoney" column="total_money"/>
<result property="discountMoney" column="discount_money"/>
<result property="payMoney" column="pay_money"/>
2022-05-24 22:26:26 +08:00
<result property="financialDetailType" column="financial_detail_type"/>
<result property="payeeId" column="payee_id"/>
2022-06-01 16:29:52 +08:00
<result property="reverseId" column="reverse_id"/>
<result property="payType" column="pay_type"/>
<result property="payStatus" column="pay_status"/>
<result property="payTime" column="pay_time"/>
<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"/>
</resultMap>
2025-03-24 13:25:38 +08:00
<resultMap id="FinancialAccountBillResult" type="com.ghy.payment.response.FinancialAccountBillResp">
<id property="orderCode" column="order_code"/>
<id property="payMoney" column="pay_money"/>
<id property="createTime" column="create_time"/>
<id property="orderStatus" column="order_status"/>
<id property="payStatus" column="pay_status"/>
<id property="payCode" column="pay_code"/>
<id property="payTime" column="pay_time"/>
</resultMap>
2022-06-01 18:11:29 +08:00
<resultMap id="countResult" type="com.ghy.payment.response.FinancialCountResponse">
<result property="createTime" column="create_time"/>
<result property="payCount" column="pay_count"/>
<result property="incomeCount" column="income_count"/>
</resultMap>
<sql id="selectFinancialDetail">
2022-06-01 16:29:52 +08:00
SELECT id, dept_id, code, financial_master_id, financial_master_code, order_detail_id, order_detail_code,
total_money, discount_money, pay_money, financial_detail_type,payee_id, reverse_id, pay_type,
pay_status, pay_time, create_by, create_time, update_by, update_time, remark
FROM financial_detail
</sql>
<select id="selectFinancialDetailList" parameterType="com.ghy.payment.domain.FinancialDetail"
resultMap="FinancialDetailResult">
SELECT fd.id, fd.dept_id, fd.code, fd.financial_master_id, fd.financial_master_code, fd.order_detail_id, fd.order_detail_code,
fd.total_money, fd.discount_money, fd.pay_money, fd.financial_detail_type,payee_id, fd.reverse_id, fd.pay_type,
fd.pay_status, fd.pay_time, fd.create_by, fd.create_time, fd.update_by, fd.update_time, fd.remark
FROM financial_detail fd left join order_detail od on od.id = fd.order_detail_id
<where>
2022-05-25 11:48:07 +08:00
<if test="financialMasterId != null and financialMasterId != 0">
AND fd.financial_master_id = #{financialMasterId}
</if>
2022-05-25 11:48:07 +08:00
<if test="financialMasterCode != null and financialMasterCode != ''">
AND fd.financial_master_code LIKE concat('%', #{financialMasterCode}, '%')
</if>
2022-05-25 11:48:07 +08:00
<if test="orderDetailId != null and orderDetailId != 0">
AND fd.order_detail_id = #{orderDetailId}
2022-05-25 11:48:07 +08:00
</if>
<if test="orderDetailCode != null and orderDetailCode != ''">
AND fd.order_detail_code LIKE concat('%', #{orderDetailCode}, '%')
2022-05-25 11:48:07 +08:00
</if>
<if test="payType != null">
AND fd.pay_type = #{payType}
</if>
2022-05-25 11:48:07 +08:00
<if test="payStatus != null">
AND fd.pay_status = #{payStatus}
</if>
2022-05-25 11:48:07 +08:00
<if test="financialDetailType != null">
AND fd.financial_detail_type = #{financialDetailType}
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(fd.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
2022-06-01 22:25:50 +08:00
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(fd.create_time,'%y%m%d') &lt; date_format(#{endTime},'%y%m%d')
2022-06-01 22:25:50 +08:00
</if>
2022-11-28 01:27:09 +08:00
<if test="payeeId != null">
and fd.payee_id = #{payeeId}
2022-11-28 01:27:09 +08:00
</if>
2022-12-13 23:51:14 +08:00
<if test="financialDetailType != null">
and fd.financial_detail_type = #{financialDetailType}
2022-12-13 23:51:14 +08:00
</if>
2022-11-28 01:27:09 +08:00
<if test="financialDetailTypes != null and financialDetailTypes.size > 0">
and fd.financial_detail_type in
2022-11-28 01:27:09 +08:00
<foreach item="item" collection="financialDetailTypes" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2023-03-25 22:00:38 +08:00
<if test="billingState == '1'.toString()">
and od.order_status in ('0','1','2','3','4')
</if>
2023-03-25 22:00:38 +08:00
<if test="billingState != null and billingState != '' and billingState != '1'.toString()">
and od.order_status = #{billingState}
</if>
</where>
order by fd.create_time desc
</select>
2025-03-24 13:25:38 +08:00
<select id="selectFinancialDetailListV2" parameterType="com.ghy.payment.request.FinancialAccountBillReq"
resultMap="FinancialAccountBillResult">
select
om.code as order_code,
fd.pay_money as pay_money,
om.create_time as create_time,
om.order_status as order_status,
fm.pay_status as pay_status,
fm.code as pay_code,
fd.pay_time as pay_time
from financial_detail fd
left join financial_master fm on fd.financial_master_id = fm.id
left join order_master om on fm.order_master_id = om.id
<where>
<if test="deptId != null">
AND fd.dept_id = #{deptId}
</if>
<if test="workerId != null">
AND fd.payee_id = #{workerId}
</if>
<if test="customerId != null">
AND fd.payee_id = #{customerId}
</if>
<if test="orderCode != null and orderCode != ''">
AND om.code like concat('%', #{orderCode}, '%')
</if>
<if test="billType == '01'">
AND om.order_status in ('0','1','2','3','4')
</if>
<if test="billType == '02'">
AND om.order_status = '05'
</if>
<if test="billType == '03'">
AND om.order_status = '06'
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and fd.create_time &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and fd.create_time &lt;= #{endTime}
</if>
</where>
order by om.create_time desc
</select>
<select id="selectById" parameterType="long" resultMap="FinancialDetailResult">
2022-05-25 11:48:07 +08:00
<include refid="selectFinancialDetail"/> WHERE id = #{financialDetailId}
</select>
2022-07-20 15:10:01 +08:00
<select id="selectByFinancialMasterId" resultMap="FinancialDetailResult">
<include refid="selectFinancialDetail"/> WHERE financial_master_id = #{financialMasterId}
</select>
<delete id="deleteFinancialDetailByIds" parameterType="Long">
DELETE FROM financial_detail WHERE id IN
<foreach collection="array" item="financialDetailId" open="(" separator="," close=")">
#{financialDetailId}
</foreach>
</delete>
<delete id="deleteFinancialDetailByOrderDetailId" parameterType="Long">
DELETE FROM financial_detail WHERE order_detail_id = #{orderDetailId}
</delete>
<update id="updateFinancialDetail" parameterType="com.ghy.payment.domain.FinancialDetail">
UPDATE financial_detail
<set>
2022-05-25 11:48:07 +08:00
<if test="code != null and code != ''">code = #{code},</if>
<if test="totalMoney != null">total_money = #{totalMoney},</if>
<if test="discountMoney != null">discount_money = #{discountMoney},</if>
<if test="payType != null">pay_type = #{payType},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
<if test="payMoney != null">pay_money = #{payMoney},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
2023-04-18 10:39:22 +08:00
<if test="reverseId != null and reverseId != ''">reverse_id = #{reverseId},</if>
update_time = SYSDATE()
</set>
WHERE id = #{id}
</update>
2022-06-01 16:29:52 +08:00
<update id="payReverseSucceeded">
UPDATE financial_detail SET
2022-07-22 22:25:44 +08:00
pay_status = 3
2022-06-01 16:29:52 +08:00
WHERE reverse_id = #{reverseId}
</update>
2022-07-22 22:25:44 +08:00
<update id="updateByFinancialMasterId">
UPDATE financial_detail
<set>
<if test="payType != null">pay_type = #{payType},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
update_time = SYSDATE()
</set>
WHERE financial_master_id = #{financialMasterId}
</update>
<update id="updatePayStatus">
UPDATE financial_detail
SET pay_status = #{payStatus}
WHERE id = #{id}
</update>
2023-04-08 23:24:04 +08:00
<update id="refundSucceeded">
UPDATE financial_detail SET
pay_status = 3 ,
update_time = SYSDATE()
WHERE reverse_id = #{reverseId}
</update>
2022-06-09 17:52:21 +08:00
<select id="selectByOrderDetailId" resultMap="FinancialDetailResult">
<include refid="selectFinancialDetail" />
WHERE
order_detail_id = #{orderDetailId}
</select>
2022-06-01 16:29:52 +08:00
2022-06-01 18:11:29 +08:00
<select id="count" resultMap="countResult">
select DATE_FORMAT(fd.create_time,'%Y-%m') as create_time,
sum(fd.pay_money) as income_count from financial_detail fd
left join order_detail od on fd.order_detail_id = od.id
2022-06-01 18:11:29 +08:00
<where>
<if test="createTime != null">
and DATE_FORMAT(fd.create_time,'%Y-%m') = #{createTime}
2022-06-01 18:11:29 +08:00
</if>
2022-06-01 22:06:29 +08:00
<if test="flag == 'true'">
and fd.pay_money &gt;= 0
2022-06-01 18:11:29 +08:00
</if>
2022-06-01 22:06:29 +08:00
<if test="flag == 'false'">
and fd.pay_money &lt;= 0
2022-06-01 18:11:29 +08:00
</if>
2022-11-28 01:27:09 +08:00
<if test="payeeId != null">
and fd.payee_id = #{payeeId}
2022-11-28 01:27:09 +08:00
</if>
<if test="financialDetailTypes != null and financialDetailTypes.size > 0">
and fd.financial_detail_type in
2022-11-28 01:27:09 +08:00
<foreach item="item" collection="financialDetailTypes" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2023-03-08 10:50:38 +08:00
<if test='billingState == "1"'>
and od.order_status in ('0','1','2','3','4')
</if>
2023-03-08 10:50:38 +08:00
<if test='billingState != null and billingState != "" and billingState != "1"'>
and od.order_status = #{billingState}
</if>
2022-06-01 18:11:29 +08:00
</where>
group by DATE_FORMAT(fd.create_time,'%Y-%m') order by DATE_FORMAT(fd.create_time,'%Y-%m') desc
2022-06-01 18:11:29 +08:00
</select>
<insert id="insertFinancialDetail" parameterType="com.ghy.payment.domain.FinancialDetail" useGeneratedKeys="true"
keyProperty="id">
INSERT INTO financial_detail(
2022-05-25 11:48:07 +08:00
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="code != null and code != ''">code,</if>
<if test="financialMasterId != null and financialMasterId != 0">financial_master_id,</if>
<if test="financialMasterCode != null and financialMasterCode != ''">financial_master_code,</if>
<if test="orderDetailId != null and orderDetailId != 0">order_detail_id,</if>
<if test="orderDetailCode != null and orderDetailCode != ''">order_detail_code,</if>
<if test="totalMoney != null">total_money,</if>
<if test="discountMoney != null">discount_money,</if>
<if test="payMoney != null">pay_money,</if>
<if test="financialDetailType != null">financial_detail_type,</if>
<if test="payeeId != null and payeeId != 0">payee_id,</if>
2022-06-01 16:29:52 +08:00
<if test="reverseId != null and reverseId != 0">reverse_id,</if>
2022-05-25 11:48:07 +08:00
<if test="payType != null">pay_type,</if>
<if test="payStatus != null">pay_status,</if>
<if test="payTime != null">pay_time,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
2022-05-25 11:48:07 +08:00
<if test="deptId != null and deptId != 0">#{deptId},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="financialMasterId != null and financialMasterId != 0">#{financialMasterId},</if>
<if test="financialMasterCode != null and financialMasterCode != ''">#{financialMasterCode},</if>
<if test="orderDetailId != null and orderDetailId != 0">#{orderDetailId},</if>
<if test="orderDetailCode != null and orderDetailCode != ''">#{orderDetailCode},</if>
<if test="totalMoney != null">#{totalMoney},</if>
<if test="discountMoney != null">#{discountMoney},</if>
<if test="payMoney != null">#{payMoney},</if>
<if test="financialDetailType != null">#{financialDetailType},</if>
<if test="payeeId != null and payeeId != 0">#{payeeId},</if>
2022-06-01 16:29:52 +08:00
<if test="reverseId != null and reverseId != 0">#{reverseId},</if>
2022-05-25 11:48:07 +08:00
<if test="payType != null">#{payType},</if>
<if test="payStatus != null">#{payStatus},</if>
<if test="payTime != null">#{payTime},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)
</insert>
<select id="checkFinancialDetailCodeUnique" parameterType="String" resultMap="FinancialDetailResult">
<include refid="selectFinancialDetail"/>
2022-05-25 11:48:07 +08:00
WHERE `code` = #{financialDetailCode} LIMIT 1
</select>
2023-02-17 21:11:23 +08:00
<select id="selectByOrderDetailIds" resultMap="FinancialDetailResult">
2022-06-01 22:14:02 +08:00
<include refid="selectFinancialDetail" />
<where>
and order_detail_id in
2023-02-17 21:11:23 +08:00
<foreach item="item" index="orderDetailIds" collection="orderDetailIds" open="(" separator="," close=")">
2022-06-01 22:14:02 +08:00
#{item}
</foreach>
</where>
</select>
</mapper>