emis-service/emis-biz/src/main/resources/mapper/EmisCreditCustomerMapper.xml

307 lines
17 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.xdadan.erp.emis.mapper.EmisCreditCustomerMapper">
<resultMap type="EmisCreditCustomer" id="EmisCreditCustomerResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
<result property="id" column="id" />
<result property="accCode" column="acc_code" />
<result property="customerCode" column="customer_code" />
<result property="monthlyPayCode" column="monthly_pay_code" />
<result property="creditMoney" column="credit_money" />
<result property="useMoney" column="use_money" />
<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" />
<result property="customerName" column="customer_name" />
<result property="payee" column="payee" />
<result property="salesmen" column="salesmen" />
</resultMap>
<sql id="selectEmisCreditCustomerVo">
select id, acc_code, customer_code, monthly_pay_code, credit_money, use_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_customer
</sql>
<select id="selectEmisCreditCustomerList" parameterType="EmisCreditCustomer" resultMap="EmisCreditCustomerResult">
select
a.id,a.acc_code, a.customer_code, a.monthly_pay_code,a.use_money,
a.credit_money,
COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
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,
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,
b.customer_name,b.salesmen,b.payee
from emis_credit_customer a,emis_customer_user b
<where>
a.del_flag='0' and b.del_flag='0' and a.customer_code=b.customer_code
<if test="id != null "> and a.id = #{id}</if>
<if test="accCode != null and accCode != ''"> and acc_code=#{accCode}</if>
<if test="customerCode != null and customerCode != ''"> and a.customer_code=#{customerCode}</if>
<if test="monthlyPayCode != null and monthlyPayCode != ''"> and a.monthly_pay_code=#{monthlyPayCode}</if>
<if test="creditMoney != null "> and a.credit_money = #{creditMoney}</if>
<if test="currency != null and currency != ''"> and a.currency=#{currency}</if>
<if test="transType != null and transType != ''"> and FIND_IN_SET(#{transType},a.trans_type)</if>
<if test="startDate != null "> and a.start_date = #{startDate}</if>
<if test="endDate != null "> and a.end_date = #{endDate}</if>
<if test="blOpen != null and blOpen != ''"> and a.bl_open=#{blOpen}</if>
<if test="remark != null and remark != ''"> and a.remark like concat('%', #{remark}, '%')</if>
<if test="tenantId != null and tenantId != ''"> and a.tenant_id like concat('%', #{tenantId}, '%')</if>
<if test="delFlag != null and delFlag != ''"> and a.del_flag=#{delFlag}</if>
<if test="createBy != null and createBy != ''"> and a.create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and a.create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and a.update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and a.update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and a.create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and a.update_site like concat('%', #{updateSite}, '%')</if>
<if test="params.beginCurMoney != null and params.beginCurMoney != ''">
and (COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
) - a.use_money) <![CDATA[ >= ]]> #{params.beginCurMoney}
</if>
<if test="params.endCurMoney != null and params.endCurMoney != ''">
and (COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
) - a.use_money) <![CDATA[ < ]]> #{params.endCurMoney}
</if>
<if test="params.beginCurMoneyRate != null and params.beginCurMoneyRate != ''">
and ((COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
) - a.use_money)/(COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
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}
</if>
<if test="params.endCurMoneyRate != null and params.endCurMoneyRate != ''">
and ((COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
and t.del_flag = '0'
and NOW() between t.start_date and t.end_date
order by t.create_time desc
limit 1), 0
) - a.use_money)/(COALESCE(a.credit_money, 0) + COALESCE(
(select temp_credit_money_adjust
from emis_temp_credit_customer t
where t.acc_code = a.acc_code
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}
</if>
<if test="params.sendDate != null ">
and ( a.start_date <![CDATA[ <= ]]> #{params.sendDate} ) and ( #{params.sendDate} <![CDATA[ < ]]> a.end_date )
</if>
<if test="params.payee != null and params.payee != ''">
and b.payee = #{params.payee}
</if>
<if test="params.salesmen != null and params.salesmen != ''">
and b.salesmen = #{params.salesmen}
</if>
</where>
order by a.create_time desc
</select>
<select id="checkUnique" parameterType="EmisCreditCustomer" resultMap="EmisCreditCustomerResult">
<include refid="selectEmisCreditCustomerVo"/>
where del_flag='0'
<if test="id != null "> and id != #{id}</if>
and monthly_pay_code = #{monthlyPayCode}
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 )
)
limit 1
</select>
<!-- 计算已使用金额 -->
<select id="getUseMoneyMap" parameterType="EmisCreditCustomer" resultType="map">
SELECT
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
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='2'
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)
)
and a.trans_line_type=c.line_code
and a.cust_no=#{monthlyPayCode}
and FIND_IN_SET(c.trans_type,#{transType})
and a.send_date <![CDATA[ > ]]> #{startDate} and a.send_date <![CDATA[ <= ]]> #{endDate}
</select>
<select id="selectEmisCreditCustomerById" parameterType="Long" resultMap="EmisCreditCustomerResult">
select
a.id,a.acc_code, a.customer_code,a.monthly_pay_code, a.use_money,
a.credit_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,
b.customer_name,b.salesmen,b.payee
from emis_credit_customer a,emis_customer_user b
where a.customer_code=b.customer_code and a.id = #{id}
</select>
<insert id="insertEmisCreditCustomer" parameterType="EmisCreditCustomer" useGeneratedKeys="true" keyProperty="id">
insert into emis_credit_customer
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="accCode != null and accCode != ''">acc_code,</if>
<if test="customerCode != null and customerCode != ''">customer_code,</if>
<if test="monthlyPayCode != null and monthlyPayCode != ''">monthly_pay_code,</if>
<if test="creditMoney != null">credit_money,</if>
<if test="useMoney != null">use_money,</if>
<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>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="accCode != null and accCode != ''">#{accCode},</if>
<if test="customerCode != null and customerCode != ''">#{customerCode},</if>
<if test="monthlyPayCode != null and monthlyPayCode != ''">#{monthlyPayCode},</if>
<if test="creditMoney != null">#{creditMoney},</if>
<if test="useMoney != null">#{useMoney},</if>
<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>
</trim>
</insert>
<update id="updateEmisCreditCustomer" parameterType="EmisCreditCustomer">
update emis_credit_customer
<trim prefix="SET" suffixOverrides=",">
<if test="accCode != null and accCode != ''">acc_code = #{accCode},</if>
<if test="customerCode != null and customerCode != ''">customer_code = #{customerCode},</if>
<if test="monthlyPayCode != null and monthlyPayCode != ''">monthly_pay_code = #{monthlyPayCode},</if>
<if test="creditMoney != null">credit_money = #{creditMoney},</if>
<if test="useMoney != null">use_money = #{useMoney},</if>
<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>
<update id="updateUseMoney" >
update emis_credit_customer set use_money = #{useMoney} where id = #{id}
</update>
<delete id="deleteEmisCreditCustomerById" parameterType="Long">
update emis_credit_customer set del_flag='1' where id = #{id}
</delete>
<delete id="deleteEmisCreditCustomerByIds" parameterType="String">
update emis_credit_customer set del_flag='1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectCreditCustomerInfo" parameterType="EmisCreditCustomer" resultMap="EmisCreditCustomerResult">
select
a.id, a.acc_code, a.customer_code, a.monthly_pay_code, a.credit_money,
a.use_money, a.currency, a.trans_type, a.start_date, a.end_date, a.bl_open,
b.customer_name
from emis_credit_customer a
inner join emis_customer_user b on a.customer_code = b.customer_code and b.del_flag = '0'
<where>
a.del_flag = '0'
<if test="accCode != null and accCode != ''"> and a.acc_code = #{accCode}</if>
<if test="customerCode != null and customerCode != ''"> and a.customer_code = #{customerCode}</if>
<if test="monthlyPayCode != null and monthlyPayCode != ''"> and a.monthly_pay_code = #{monthlyPayCode}</if>
<if test="transType != null and transType != ''"> and FIND_IN_SET(#{transType}, a.trans_type)</if>
<if test="customerName != null and customerName != ''"> and b.customer_name like concat('%', #{customerName}, '%')</if>
</where>
</select>
</mapper>