Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/PrcIncomeBillFeeMapper.xml
T

190 lines
8.5 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.bms.price.mapper.PrcIncomeBillFeeMapper">
<resultMap type="PrcIncomeBillFee" id="PrcIncomeBillFeeResult">
<id property="feeId" column="fee_id" />
<result property="billId" column="bill_id" />
<result property="incomeBillId" column="income_bill_id" />
<result property="feeType" column="fee_type" />
<result property="feeName" column="fee_name" />
<result property="scId" column="sc_id" />
<result property="amount" column="amount" />
<result property="productAmount" column="product_amount" />
<result property="redlineAmount" column="redline_amount" />
<result property="currency" column="currency" />
<result property="roundMode" column="round_mode" />
<result property="remark" column="remark" />
<result property="arBillStatus" column="ar_bill_status" />
<result property="manualFlag" column="manual_flag" />
<result property="createTime" column="create_time" />
</resultMap>
<select id="selectByBillId" parameterType="Long" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where bill_id = #{billId}
order by field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), fee_id
</select>
<select id="selectByBillIds" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where bill_id in
<foreach collection="billIds" item="billId" open="(" separator="," close=")">
#{billId}
</foreach>
order by bill_id, field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), fee_id
</select>
<select id="selectUnbilledByBillIds" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where ar_bill_status = #{arBillStatus}
and bill_id in
<foreach collection="billIds" item="billId" open="(" separator="," close=")">
#{billId}
</foreach>
order by bill_id, field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), fee_id
</select>
<select id="selectByFeeId" parameterType="Long" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where fee_id = #{feeId}
</select>
<select id="selectByBillIdAndFeeTypeAndScId" resultMap="PrcIncomeBillFeeResult">
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
from prc_income_bill_fee
where bill_id = #{billId}
and fee_type = #{feeType}
and sc_id = #{scId}
limit 1
</select>
<select id="countByBillIdAndArBillStatusAndFeeType" resultType="int">
select count(1)
from prc_income_bill_fee
where bill_id = #{billId}
and ar_bill_status = #{arBillStatus}
and fee_type = #{feeType}
</select>
<insert id="insertPrcIncomeBillFee" parameterType="PrcIncomeBillFee" useGeneratedKeys="true" keyProperty="feeId">
insert into prc_income_bill_fee (
bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values (
#{billId}, #{incomeBillId}, #{feeType}, #{feeName}, #{scId}, #{amount}, #{productAmount}, #{redlineAmount}, #{currency}, #{roundMode}, #{remark},
#{arBillStatus}, #{manualFlag}, sysdate()
)
</insert>
<insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="feeId">
insert into prc_income_bill_fee (
bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values
<foreach collection="list" item="item" separator=",">
(#{item.billId}, #{item.incomeBillId}, #{item.feeType}, #{item.feeName}, #{item.scId}, #{item.amount},
#{item.productAmount}, #{item.redlineAmount},
#{item.currency}, #{item.roundMode}, #{item.remark},
#{item.arBillStatus}, #{item.manualFlag}, sysdate())
</foreach>
</insert>
<update id="updatePrcIncomeBillFee" parameterType="PrcIncomeBillFee">
update prc_income_bill_fee
set fee_type = #{feeType},
fee_name = #{feeName},
sc_id = #{scId},
amount = #{amount},
product_amount = #{productAmount},
redline_amount = #{redlineAmount},
currency = #{currency},
round_mode = #{roundMode},
remark = #{remark},
income_bill_id = #{incomeBillId},
manual_flag = #{manualFlag}
where fee_id = #{feeId}
</update>
<update id="updateArBillStatusByBillIds">
update prc_income_bill_fee
set ar_bill_status = #{toStatus}
where ar_bill_status = #{fromStatus}
and bill_id in
<foreach collection="billIds" item="billId" open="(" separator="," close=")">
#{billId}
</foreach>
</update>
<update id="updateArBillStatusByFeeIds">
update prc_income_bill_fee
set ar_bill_status = #{toStatus}
where ar_bill_status = #{fromStatus}
and fee_id in
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">
#{feeId}
</foreach>
</update>
<update id="restoreUnbilledIfNoActiveArBill">
update prc_income_bill_fee f
set f.ar_bill_status = 'UNBILLED'
where f.ar_bill_status = 'BILLED'
and f.fee_id in
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">
#{feeId}
</foreach>
and not exists (
select 1
from ar_bill_detail_fee df
inner join ar_bill_detail d on d.detail_id = df.detail_id
inner join ar_bill b on b.ar_bill_id = d.ar_bill_id
where df.prc_income_bill_fee_id = f.fee_id
and b.status &lt;&gt; 'VOID'
)
</update>
<update id="restoreUnbilledIfNoActiveArBillByArBillId">
update prc_income_bill_fee f
inner join ar_bill_detail_fee current_df on current_df.prc_income_bill_fee_id = f.fee_id
inner join ar_bill_detail current_d on current_d.detail_id = current_df.detail_id
and current_d.ar_bill_id = #{arBillId}
set f.ar_bill_status = 'UNBILLED'
where f.ar_bill_status = 'BILLED'
and not exists (
select 1
from ar_bill_detail_fee other_df
inner join ar_bill_detail other_d on other_d.detail_id = other_df.detail_id
inner join ar_bill other_b on other_b.ar_bill_id = other_d.ar_bill_id
where other_df.prc_income_bill_fee_id = f.fee_id
and other_b.status &lt;&gt; 'VOID'
and other_b.ar_bill_id &lt;&gt; #{arBillId}
)
</update>
<delete id="deleteByFeeId" parameterType="Long">
delete from prc_income_bill_fee where fee_id = #{feeId}
</delete>
<delete id="deleteByBillId" parameterType="Long">
delete from prc_income_bill_fee where bill_id = #{billId}
</delete>
<delete id="deleteAutoFeesByBillId" parameterType="Long">
delete from prc_income_bill_fee
where bill_id = #{billId}
and (manual_flag is null or manual_flag &lt;&gt; '1')
</delete>
</mapper>