2025-03-08 16:26:34 +00: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.xdadan.erp.emis.mapper.EmisCreditSalesmenMapper" >
2025-08-21 05:39:03 +00:00
2025-03-08 16:27:34 +00:00
<resultMap type= "EmisCreditSalesmen" id= "EmisCreditSalesmenResult" extends= "com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult" >
2025-03-08 16:26:34 +00:00
<result property= "id" column= "id" />
2025-03-11 05:58:44 +00:00
<result property= "accCode" column= "acc_code" />
2025-03-08 16:26:34 +00:00
<result property= "salesmen" column= "salesmen" />
<result property= "creditMoney" column= "credit_money" />
2025-03-11 15:32:16 +00:00
<result property= "useMoney" column= "use_money" />
2025-04-11 09:17:19 +00:00
<result property= "overTermMoney" column= "over_term_money" />
<result property= "inTermMoney" column= "in_term_money" />
2025-08-21 05:39:03 +00:00
<result property= "satisfyMoney" column= "satisfy_money" />
2025-03-08 16:26:34 +00:00
<result property= "currency" column= "currency" />
<result property= "transType" column= "trans_type" />
<result property= "startDate" column= "start_date" />
<result property= "endDate" column= "end_date" />
<result property= "blOpen" column= "bl_open" />
</resultMap>
<sql id= "selectEmisCreditSalesmenVo" >
2025-08-21 05:39:03 +00:00
select id, acc_code, salesmen, credit_money, use_money, over_term_money, in_term_money, satisfy_money, currency, trans_type, start_date, end_date, bl_open, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_credit_salesmen
2025-03-08 16:26:34 +00:00
</sql>
<select id= "selectEmisCreditSalesmenList" parameterType= "EmisCreditSalesmen" resultMap= "EmisCreditSalesmenResult" >
2025-08-21 05:39:03 +00:00
select
2025-05-13 10:14:55 +00:00
a.id, a.acc_code, a.salesmen, a.credit_money,
COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
) as temp_credit_money,
2025-08-21 05:39:03 +00:00
a.use_money, a.over_term_money, a.in_term_money, a.currency,
a.trans_type, a.start_date, a.end_date, a.bl_open,
a.remark, a.tenant_id, a.del_flag, a.create_by,
a.create_time, a.update_by, a.update_time, a.create_site, a.update_site, a.satisfy_money
2025-03-10 22:49:04 +00:00
from emis_credit_salesmen a
<where >
2025-03-08 16:26:34 +00:00
del_flag='0'
<if test= "id != null " > and id = #{id}</if>
2025-03-11 05:58:44 +00:00
<if test= "accCode != null and accCode != ''" > and acc_code=#{accCode}</if>
<if test= "salesmen != null and salesmen != ''" > and salesmen=#{salesmen}</if>
2025-03-08 16:26:34 +00:00
<if test= "creditMoney != null " > and credit_money = #{creditMoney}</if>
2025-03-11 09:03:40 +00:00
<if test= "currency != null and currency != ''" > and currency=#{currency}</if>
<if test= "transType != null and transType != ''" > and FIND_IN_SET(#{transType},a.trans_type)</if>
2025-03-08 16:26:34 +00:00
<if test= "startDate != null " > and start_date = #{startDate}</if>
<if test= "endDate != null " > and end_date = #{endDate}</if>
2025-03-11 09:03:40 +00:00
<if test= "blOpen != null and blOpen != ''" > and bl_open=#{blOpen}</if>
2025-03-08 16:26:34 +00:00
<if test= "remark != null and remark != ''" > and remark like concat('%', #{remark}, '%')</if>
<if test= "tenantId != null and tenantId != ''" > and tenant_id like concat('%', #{tenantId}, '%')</if>
2025-03-11 09:03:40 +00:00
<if test= "delFlag != null and delFlag != ''" > and del_flag =#{delFlag}</if>
2025-03-08 16:26:34 +00:00
<if test= "createBy != null and createBy != ''" > and create_by like concat('%', #{createBy}, '%')</if>
<if test= "createTime != null " > and create_time = #{createTime}</if>
<if test= "updateBy != null and updateBy != ''" > and update_by like concat('%', #{updateBy}, '%')</if>
<if test= "updateTime != null " > and update_time = #{updateTime}</if>
<if test= "createSite != null and createSite != ''" > and create_site like concat('%', #{createSite}, '%')</if>
<if test= "updateSite != null and updateSite != ''" > and update_site like concat('%', #{updateSite}, '%')</if>
2025-03-10 22:49:04 +00:00
<if test= "params.beginCurMoney != null and params.beginCurMoney != ''" >
2025-05-13 10:14:55 +00:00
and (COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
2025-08-21 07:37:23 +00:00
) - a.use_money + COALESCE(a.satisfy_money, 0)) <![CDATA[ >= ]]> #{params.beginCurMoney}
2025-03-10 22:49:04 +00:00
</if>
<if test= "params.endCurMoney != null and params.endCurMoney != ''" >
2025-05-13 10:14:55 +00:00
and (COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
2025-08-21 07:37:23 +00:00
) - a.use_money + COALESCE(a.satisfy_money, 0)) <![CDATA[ < ]]> #{params.endCurMoney}
2025-03-11 05:58:44 +00:00
</if>
2025-03-10 22:49:04 +00:00
<if test= "params.beginCurMoneyRate != null and params.beginCurMoneyRate != ''" >
2025-05-13 10:14:55 +00:00
and ((COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
2025-08-21 07:37:23 +00:00
) - a.use_money + COALESCE(a.satisfy_money, 0))/(COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
)))*100 <![CDATA[ >= ]]> #{params.beginCurMoneyRate}
2025-03-10 22:49:04 +00:00
</if>
<if test= "params.endCurMoneyRate != null and params.endCurMoneyRate != ''" >
2025-05-13 10:14:55 +00:00
and ((COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
2025-08-21 07:37:23 +00:00
) - a.use_money + COALESCE(a.satisfy_money, 0))/(COALESCE(a.credit_money, 0) + COALESCE(
2025-08-21 05:39:03 +00:00
(select temp_credit_money_adjust
from emis_temp_credit_salesmen t
where t.acc_code = a.acc_code
2025-05-13 10:14:55 +00:00
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
)))*100 <![CDATA[ < ]]> #{params.endCurMoneyRate}
2025-03-11 14:38:22 +00:00
</if>
<if test= "params.sendDate != null " >
2025-03-11 15:04:24 +00:00
and ( a.start_date <![CDATA[ <= ]]> #{params.sendDate} ) and ( #{params.sendDate} <![CDATA[ < ]]> a.end_date )
2025-03-10 22:49:04 +00:00
</if>
2025-03-08 16:26:34 +00:00
</where>
order by create_time desc
</select>
2025-03-12 00:21:29 +00:00
<select id= "checkUnique" parameterType= "EmisCreditSalesmen" resultMap= "EmisCreditSalesmenResult" >
<include refid= "selectEmisCreditSalesmenVo" />
where del_flag='0'
<if test= "id != null " > and id != #{id}</if>
and salesmen=#{salesmen}
and FIND_IN_SET(#{transType},trans_type)
and (
( start_date <![CDATA[<= ]]> #{startDate} and #{startDate} <![CDATA[< ]]> end_date )
or ( start_date <![CDATA[<= ]]> #{endDate} and #{endDate} <![CDATA[< ]]> end_date )
)
</select>
2025-08-21 05:39:03 +00:00
2025-03-08 16:26:34 +00:00
<select id= "selectEmisCreditSalesmenById" parameterType= "Long" resultMap= "EmisCreditSalesmenResult" >
2025-08-21 05:39:03 +00:00
select id, acc_code, salesmen, credit_money, use_money, over_term_money, in_term_money, satisfy_money, currency, trans_type, start_date, end_date, bl_open, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
2025-03-08 16:26:34 +00:00
from emis_credit_salesmen a
where a.id = #{id}
</select>
2025-03-11 05:58:44 +00:00
2025-03-12 05:19:57 +00:00
<!-- 计算已使用金额 -->
2025-03-12 10:15:26 +00:00
<select id= "getUseMoneyMap" parameterType= "EmisCreditSalesmen" resultType= "map" >
2025-03-12 05:19:57 +00:00
SELECT
2025-03-12 10:15:26 +00:00
COALESCE(sum(bill_fee),0.00) as totalBillFee,
COALESCE(sum(reced_money),0.00) as totalRecedMoney,
COALESCE(sum(bill_fee-reced_money),0.00) as useMoney
2025-03-12 05:19:57 +00:00
FROM
emis_settle_sub_bill b,
emis_waybill a,
emis_trans_line c
WHERE
a.del_flag = '0'
AND b.del_flag = '0'
and c.del_flag='0'
and a.bill_code=b.bill_code
and settle_type='1'
and not exists(
select 1 from emis_waybill_problem_info ewpi where a.bill_code=ewpi.bill_code and ewpi.del_flag='0' and ewpi.`problem_type` in(173,170,151)
)
2025-04-09 09:32:36 +00:00
and b.bl_confirm_site != 2
2025-03-13 12:42:26 +00:00
and a.payment_type in('1','3')
2025-03-12 05:19:57 +00:00
and a.trans_line_type=c.line_code
2025-03-19 02:48:07 +00:00
and a.payee=#{salesmen}
2025-03-12 07:01:15 +00:00
and FIND_IN_SET(c.trans_type,#{transType})
2025-06-21 09:26:40 +00:00
and FIND_IN_SET(a.payment_status,'0,2')
2025-03-12 05:19:57 +00:00
and a.send_date <![CDATA[ > ]]> #{startDate} and a.send_date <![CDATA[ <= ]]> #{endDate}
</select>
2025-03-08 16:26:34 +00:00
<insert id= "insertEmisCreditSalesmen" parameterType= "EmisCreditSalesmen" useGeneratedKeys= "true" keyProperty= "id" >
insert into emis_credit_salesmen
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
2025-03-11 05:58:44 +00:00
<if test= "accCode != null and accCode != ''" > acc_code,</if>
2025-03-08 16:26:34 +00:00
<if test= "salesmen != null and salesmen != ''" > salesmen,</if>
<if test= "creditMoney != null" > credit_money,</if>
2025-03-11 15:32:16 +00:00
<if test= "useMoney != null" > use_money,</if>
2025-04-11 09:17:19 +00:00
<if test= "overTermMoney != null" > over_term_money,</if>
<if test= "inTermMoney != null" > in_term_Money,</if>
2025-08-21 05:39:03 +00:00
<if test= "satisfyMoney != null" > satisfy_money,</if>
2025-03-08 16:26:34 +00:00
<if test= "currency != null and currency != ''" > currency,</if>
<if test= "transType != null and transType != ''" > trans_type,</if>
<if test= "startDate != null" > start_date,</if>
<if test= "endDate != null" > end_date,</if>
<if test= "blOpen != null and blOpen != ''" > bl_open,</if>
<if test= "remark != null and remark != ''" > remark,</if>
<if test= "tenantId != null and tenantId != ''" > tenant_id,</if>
<if test= "delFlag != null and delFlag != ''" > del_flag,</if>
<if test= "createBy != null and createBy != ''" > create_by,</if>
<if test= "createTime != null" > create_time,</if>
<if test= "updateBy != null and updateBy != ''" > update_by,</if>
<if test= "updateTime != null" > update_time,</if>
<if test= "createSite != null and createSite != ''" > create_site,</if>
<if test= "updateSite != null and updateSite != ''" > update_site,</if>
2025-03-11 05:58:44 +00:00
</trim>
2025-03-08 16:26:34 +00:00
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
2025-03-11 05:58:44 +00:00
<if test= "accCode != null and accCode != ''" > #{accCode},</if>
2025-03-08 16:26:34 +00:00
<if test= "salesmen != null and salesmen != ''" > #{salesmen},</if>
<if test= "creditMoney != null" > #{creditMoney},</if>
2025-03-11 15:32:16 +00:00
<if test= "useMoney != null" > #{useMoney},</if>
2025-04-11 09:17:19 +00:00
<if test= "overTermMoney != null" > #{overTermMoney},</if>
<if test= "inTermMoney != null" > #{inTermMoney},</if>
2025-08-21 05:39:03 +00:00
<if test= "satisfyMoney != null" > #{satisfyMoney},</if>
2025-03-08 16:26:34 +00:00
<if test= "currency != null and currency != ''" > #{currency},</if>
<if test= "transType != null and transType != ''" > #{transType},</if>
<if test= "startDate != null" > #{startDate},</if>
<if test= "endDate != null" > #{endDate},</if>
<if test= "blOpen != null and blOpen != ''" > #{blOpen},</if>
<if test= "remark != null and remark != ''" > #{remark},</if>
<if test= "tenantId != null and tenantId != ''" > #{tenantId},</if>
<if test= "delFlag != null and delFlag != ''" > #{delFlag},</if>
<if test= "createBy != null and createBy != ''" > #{createBy},</if>
<if test= "createTime != null" > #{createTime},</if>
<if test= "updateBy != null and updateBy != ''" > #{updateBy},</if>
<if test= "updateTime != null" > #{updateTime},</if>
<if test= "createSite != null and createSite != ''" > #{createSite},</if>
<if test= "updateSite != null and updateSite != ''" > #{updateSite},</if>
2025-03-11 05:58:44 +00:00
</trim>
2025-03-08 16:26:34 +00:00
</insert>
<update id= "updateEmisCreditSalesmen" parameterType= "EmisCreditSalesmen" >
update emis_credit_salesmen
<trim prefix= "SET" suffixOverrides= "," >
<if test= "creditMoney != null" > credit_money = #{creditMoney},</if>
2025-03-11 15:32:16 +00:00
<if test= "useMoney != null" > use_money = #{useMoney},</if>
2025-04-11 09:17:19 +00:00
<if test= "overTermMoney != null" > over_term_money = #{overTermMoney},</if>
<if test= "inTermMoney != null" > in_term_Money = #{inTermMoney},</if>
2025-08-21 05:39:03 +00:00
<if test= "satisfyMoney != null" > satisfy_money = #{satisfyMoney},</if>
2025-03-08 16:26:34 +00:00
<if test= "currency != null and currency != ''" > currency = #{currency},</if>
<if test= "transType != null and transType != ''" > trans_type = #{transType},</if>
<if test= "startDate != null" > start_date = #{startDate},</if>
<if test= "endDate != null" > end_date = #{endDate},</if>
<if test= "blOpen != null and blOpen != ''" > bl_open = #{blOpen},</if>
<if test= "remark != null and remark != ''" > remark = #{remark},</if>
<if test= "tenantId != null and tenantId != ''" > tenant_id = #{tenantId},</if>
<if test= "delFlag != null and delFlag != ''" > del_flag = #{delFlag},</if>
<if test= "createBy != null and createBy != ''" > create_by = #{createBy},</if>
<if test= "createTime != null" > create_time = #{createTime},</if>
<if test= "updateBy != null and updateBy != ''" > update_by = #{updateBy},</if>
<if test= "updateTime != null" > update_time = #{updateTime},</if>
<if test= "createSite != null and createSite != ''" > create_site = #{createSite},</if>
<if test= "updateSite != null and updateSite != ''" > update_site = #{updateSite},</if>
</trim>
where id = #{id}
</update>
2025-03-11 06:38:46 +00:00
2025-03-14 10:08:08 +00:00
<update id= "updateUseMoney" >
update emis_credit_salesmen set use_money = #{useMoney} where id = #{id}
2025-03-11 06:38:46 +00:00
</update>
2025-03-08 16:26:34 +00:00
<delete id= "deleteEmisCreditSalesmenById" parameterType= "Long" >
2025-03-10 22:49:04 +00:00
update emis_credit_salesmen set del_flag='1' where id = #{id}
2025-03-08 16:26:34 +00:00
</delete>
<delete id= "deleteEmisCreditSalesmenByIds" parameterType= "String" >
2025-03-10 22:49:04 +00:00
update emis_credit_salesmen set del_flag='1' where id in
2025-03-08 16:26:34 +00:00
<foreach item= "id" collection= "array" open= "(" separator= "," close= ")" >
#{id}
</foreach>
</delete>
2025-08-21 05:39:03 +00:00
<!-- 查询销售理赔详情列表 -->
<select id= "selectSalesSatisfyDetailList" parameterType= "EmisWaybill" resultType= "EmisSettleBill" >
SELECT DISTINCT
sb.id,
sb.settle_bill_no as settleBillNo,
sb.settle_bill_name as settleBillName,
sb.settle_type as settleType,
sb.settle_start_date as settleStartDate,
sb.settle_end_date as settleEndDate,
sb.bill_month as billMonth,
sb.rec_money as recMoney,
sb.reced_money as recedMoney,
sb.invoiced_money as invoicedMoney,
sb.cust_no as custNo,
sb.cust_name as custName,
sb.customer_code as customerCode,
sb.customer_name as customerName,
sb.site_code as siteCode,
sb.site_name as siteName,
sb.satisfy_money as satisfyMoney,
sb.allowance_money as allowanceMoney,
sb.deduction_money as deductionMoney,
sb.other_money as otherMoney,
sb.satisfy_reason as satisfyReason,
sb.allowance_reason as allowanceReason,
sb.deduction_reason as deductionReason,
sb.other_reason as otherReason,
sb.open_bill_status as openBillStatus,
sb.payment_status as paymentStatus,
sb.charge_status as chargeStatus,
sb.send_piece_sum as sendPieceSum,
sb.piece_number as pieceNumber,
sb.fee_weight as feeWeight,
sb.uncollected_amount as uncollectedAmount,
sb.send_money_sum as sendMoneySum,
sb.refund_amount as refundAmount,
sb.refund_money as refundMoney,
sb.payee,
sb.salesmen,
sb.credit_period as creditPeriod,
sb.credit_period_type as creditPeriodType,
sb.settle_day as settleDay,
sb.payment_due_date as paymentDueDate,
sb.bl_send_oms as blSendOms,
sb.bl_confirm_center as blConfirmCenter,
sb.confirm_center_date as confirmCenterDate,
sb.confirm_center_note as confirmCenterNote,
sb.confirm_center_man_code as confirmCenterManCode,
sb.confirm_center_code as confirmCenterCode,
sb.bl_confirm_site as blConfirmSite,
sb.confirm_site_date as confirmSiteDate,
sb.confirm_site_man_code as confirmSiteManCode,
sb.confirm_site_note as confirmSiteNote,
sb.confirm_site_code as confirmSiteCode,
sb.remark,
sb.del_flag as delFlag,
sb.create_by as createBy,
sb.create_time as createTime,
sb.update_by as updateBy,
sb.update_time as updateTime,
sb.create_site as createSite,
sb.update_site as updateSite
FROM emis_settle_bill sb
INNER JOIN emis_settle_sub_bill ssb ON sb.settle_bill_no = ssb.settle_bill_no
INNER JOIN emis_waybill w ON ssb.bill_code = w.bill_code
WHERE sb.del_flag = '0'
AND ssb.del_flag = '0'
AND w.del_flag = '0'
and w.order_status !='0' and w.order_status!='2'
AND sb.satisfy_money > 0
<if test= "paymentType != null and paymentType != ''" >
AND FIND_IN_SET(w.payment_type, #{paymentType})
</if>
<if test= "payee != null and payee != ''" >
AND sb.payee = #{payee}
</if>
<if test= "paymentStatus != null and paymentStatus != ''" >
AND FIND_IN_SET(w.payment_status, #{paymentStatus})
</if>
<if test= "params.problemQueryType != null and params.problemQueryType == 1 and params.problemQueryIds != null and params.problemQueryIds !=''" >
and exists (
select 1 from emis_waybill_problem_info ewpi where w.bill_code=ewpi.bill_code and ewpi.del_flag='0' and FIND_IN_SET( ewpi.`problem_type`, #{params.problemQueryIds} )
)
</if>
<if test= "params.problemQueryType != null and params.problemQueryType == 2 and params.problemQueryIds != null and params.problemQueryIds !=''" >
and not exists (
select 1 from emis_waybill_problem_info ewpi where w.bill_code=ewpi.bill_code and ewpi.del_flag='0' and FIND_IN_SET( ewpi.`problem_type`, #{params.problemQueryIds} )
)
</if>
<!-- <if test="params.queryTabType != null and params.queryTabType != ''"> -->
<!-- AND w.query_tab_type = #{params.queryTabType} -->
<!-- </if> -->
<!-- <if test="params.querySendType != null and params.querySendType != ''"> -->
<!-- AND w.query_send_type = #{params.querySendType} -->
<!-- </if> -->
<if test= "params.beginSendDate != null and params.beginSendDate != ''" >
AND w.send_date <![CDATA[ >= ]]> #{params.beginSendDate}
</if>
<if test= "params.endSendDate != null and params.endSendDate != ''" >
AND w.send_date <![CDATA[ <= ]]> #{params.endSendDate}
</if>
<if test= "carryType != null and carryType != ''" >
AND FIND_IN_SET(w.carry_type, #{carryType})
</if>
ORDER BY sb.create_time DESC
</select>
</mapper>