317 lines
15 KiB
XML
317 lines
15 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.ghy.payment.mapper.FinancialDetailMapper">
|
|
|
|
<resultMap id="FinancialDetailResult" type="com.ghy.payment.domain.FinancialDetail">
|
|
<id property="id" column="id"/>
|
|
<result property="deptId" column="dept_id"/>
|
|
<result property="code" column="code"/>
|
|
<result property="financialMasterId" column="financial_master_id"/>
|
|
<result property="financialMasterCode" column="financial_master_code"/>
|
|
<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"/>
|
|
<result property="financialDetailType" column="financial_detail_type"/>
|
|
<result property="payeeId" column="payee_id"/>
|
|
<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>
|
|
|
|
<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>
|
|
|
|
<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">
|
|
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>
|
|
<if test="financialMasterId != null and financialMasterId != 0">
|
|
AND fd.financial_master_id = #{financialMasterId}
|
|
</if>
|
|
<if test="financialMasterCode != null and financialMasterCode != ''">
|
|
AND fd.financial_master_code LIKE concat('%', #{financialMasterCode}, '%')
|
|
</if>
|
|
<if test="orderDetailId != null and orderDetailId != 0">
|
|
AND fd.order_detail_id = #{orderDetailId}
|
|
</if>
|
|
<if test="orderDetailCode != null and orderDetailCode != ''">
|
|
AND fd.order_detail_code LIKE concat('%', #{orderDetailCode}, '%')
|
|
</if>
|
|
<if test="payType != null">
|
|
AND fd.pay_type = #{payType}
|
|
</if>
|
|
<if test="payStatus != null">
|
|
AND fd.pay_status = #{payStatus}
|
|
</if>
|
|
<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') >= date_format(#{beginTime},'%y%m%d')
|
|
</if>
|
|
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
|
|
and date_format(fd.create_time,'%y%m%d') < date_format(#{endTime},'%y%m%d')
|
|
</if>
|
|
<if test="payeeId != null">
|
|
and fd.payee_id = #{payeeId}
|
|
</if>
|
|
<if test="financialDetailType != null">
|
|
and fd.financial_detail_type = #{financialDetailType}
|
|
</if>
|
|
<if test="financialDetailTypes != null and financialDetailTypes.size > 0">
|
|
and fd.financial_detail_type in
|
|
<foreach item="item" collection="financialDetailTypes" open="(" separator="," close=")">
|
|
#{item}
|
|
</foreach>
|
|
</if>
|
|
<if test="billingState == '1'.toString()">
|
|
and od.order_status in ('0','1','2','3','4')
|
|
</if>
|
|
<if test="billingState != null and billingState != '' and billingState != '1'.toString()">
|
|
and od.order_status = #{billingState}
|
|
</if>
|
|
</where>
|
|
order by fd.create_time desc
|
|
</select>
|
|
|
|
<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 >= #{beginTime}
|
|
</if>
|
|
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
|
|
and fd.create_time <= #{endTime}
|
|
</if>
|
|
</where>
|
|
order by om.create_time desc
|
|
</select>
|
|
|
|
<select id="selectById" parameterType="long" resultMap="FinancialDetailResult">
|
|
<include refid="selectFinancialDetail"/> WHERE id = #{financialDetailId}
|
|
</select>
|
|
|
|
<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>
|
|
<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>
|
|
<if test="reverseId != null and reverseId != ''">reverse_id = #{reverseId},</if>
|
|
update_time = SYSDATE()
|
|
</set>
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<update id="payReverseSucceeded">
|
|
UPDATE financial_detail SET
|
|
pay_status = 3
|
|
WHERE reverse_id = #{reverseId}
|
|
</update>
|
|
|
|
<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>
|
|
|
|
<update id="refundSucceeded">
|
|
UPDATE financial_detail SET
|
|
pay_status = 3 ,
|
|
update_time = SYSDATE()
|
|
WHERE reverse_id = #{reverseId}
|
|
</update>
|
|
|
|
<select id="selectByOrderDetailId" resultMap="FinancialDetailResult">
|
|
<include refid="selectFinancialDetail" />
|
|
WHERE
|
|
order_detail_id = #{orderDetailId}
|
|
</select>
|
|
|
|
<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
|
|
<where>
|
|
<if test="createTime != null">
|
|
and DATE_FORMAT(fd.create_time,'%Y-%m') = #{createTime}
|
|
</if>
|
|
<if test="flag == 'true'">
|
|
and fd.pay_money >= 0
|
|
</if>
|
|
<if test="flag == 'false'">
|
|
and fd.pay_money <= 0
|
|
</if>
|
|
<if test="payeeId != null">
|
|
and fd.payee_id = #{payeeId}
|
|
</if>
|
|
<if test="financialDetailTypes != null and financialDetailTypes.size > 0">
|
|
and fd.financial_detail_type in
|
|
<foreach item="item" collection="financialDetailTypes" open="(" separator="," close=")">
|
|
#{item}
|
|
</foreach>
|
|
</if>
|
|
<if test='billingState == "1"'>
|
|
and od.order_status in ('0','1','2','3','4')
|
|
</if>
|
|
<if test='billingState != null and billingState != "" and billingState != "1"'>
|
|
and od.order_status = #{billingState}
|
|
</if>
|
|
</where>
|
|
group by DATE_FORMAT(fd.create_time,'%Y-%m') order by DATE_FORMAT(fd.create_time,'%Y-%m') desc
|
|
</select>
|
|
|
|
<insert id="insertFinancialDetail" parameterType="com.ghy.payment.domain.FinancialDetail" useGeneratedKeys="true"
|
|
keyProperty="id">
|
|
INSERT INTO financial_detail(
|
|
<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>
|
|
<if test="reverseId != null and reverseId != 0">reverse_id,</if>
|
|
<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(
|
|
<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>
|
|
<if test="reverseId != null and reverseId != 0">#{reverseId},</if>
|
|
<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"/>
|
|
WHERE `code` = #{financialDetailCode} LIMIT 1
|
|
</select>
|
|
|
|
<select id="selectByOrderDetailIds" resultMap="FinancialDetailResult">
|
|
<include refid="selectFinancialDetail" />
|
|
<where>
|
|
and order_detail_id in
|
|
<foreach item="item" index="orderDetailIds" collection="orderDetailIds" open="(" separator="," close=")">
|
|
#{item}
|
|
</foreach>
|
|
</where>
|
|
</select>
|
|
|
|
</mapper>
|