170 lines
8.2 KiB
XML
170 lines
8.2 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.customer.customermoney.mapper.CreditQuotaMapper">
|
|
|
|
<!-- ================= 角色额度池 ================= -->
|
|
|
|
<select id="selectRoleQuotaList" resultType="com.bms.customer.customermoney.vo.RoleCreditQuotaVo">
|
|
select r.role_id as roleId,
|
|
r.role_name as roleName,
|
|
r.role_key as roleKey,
|
|
r.status as status,
|
|
coalesce(q.total_quota, 0) as totalQuota,
|
|
(select coalesce(sum(g.remaining), 0)
|
|
from ctr_customer_credit_grant g
|
|
where g.role_id = r.role_id and g.status = '0' and g.del_flag = '0') as usedQuota,
|
|
q.remark as remark
|
|
from sys_role r
|
|
left join sys_role_credit_quota q on q.role_id = r.role_id
|
|
where r.del_flag = '0'
|
|
order by r.role_sort, r.role_id
|
|
</select>
|
|
|
|
<select id="selectRoleQuotaListByUserId"
|
|
resultType="com.bms.customer.customermoney.vo.RoleCreditQuotaVo">
|
|
select r.role_id as roleId,
|
|
r.role_name as roleName,
|
|
r.role_key as roleKey,
|
|
r.status as status,
|
|
q.total_quota as totalQuota,
|
|
(select coalesce(sum(g.remaining), 0)
|
|
from ctr_customer_credit_grant g
|
|
where g.role_id = r.role_id and g.status = '0' and g.del_flag = '0') as usedQuota,
|
|
q.remark as remark
|
|
from sys_user_role ur
|
|
inner join sys_role r on r.role_id = ur.role_id and r.del_flag = '0' and r.status = '0'
|
|
inner join sys_role_credit_quota q on q.role_id = r.role_id
|
|
where ur.user_id = #{userId}
|
|
order by r.role_sort, r.role_id
|
|
</select>
|
|
|
|
<select id="selectQuotaForUpdate"
|
|
resultType="com.bms.customer.customermoney.domain.SysRoleCreditQuota">
|
|
select role_id as roleId, total_quota as totalQuota, version, remark
|
|
from sys_role_credit_quota
|
|
where role_id = #{roleId}
|
|
for update
|
|
</select>
|
|
|
|
<select id="sumActiveRemaining" resultType="java.math.BigDecimal">
|
|
select coalesce(sum(remaining), 0)
|
|
from ctr_customer_credit_grant
|
|
where role_id = #{roleId} and status = '0' and del_flag = '0'
|
|
</select>
|
|
|
|
<insert id="insertQuota" parameterType="com.bms.customer.customermoney.domain.SysRoleCreditQuota">
|
|
insert into sys_role_credit_quota (role_id, total_quota, version, create_by, create_time, remark)
|
|
values (#{roleId}, #{totalQuota}, 0, #{createBy}, sysdate(), #{remark})
|
|
on duplicate key update total_quota = values(total_quota),
|
|
remark = values(remark),
|
|
update_by = values(create_by),
|
|
update_time = now()
|
|
</insert>
|
|
|
|
<update id="updateQuota" parameterType="com.bms.customer.customermoney.domain.SysRoleCreditQuota">
|
|
update sys_role_credit_quota
|
|
set total_quota = #{totalQuota},
|
|
version = version + 1,
|
|
update_by = #{updateBy},
|
|
update_time = now(),
|
|
remark = #{remark}
|
|
where role_id = #{roleId} and version = #{version}
|
|
</update>
|
|
|
|
<!-- ================= 授信分配台账 ================= -->
|
|
|
|
<resultMap type="com.bms.customer.customermoney.domain.CustomerCreditGrant" id="CustomerCreditGrantResult">
|
|
<id property="grantId" column="grant_id" />
|
|
<result property="customerId" column="customer_id" />
|
|
<result property="accountId" column="account_id" />
|
|
<result property="roleId" column="role_id" />
|
|
<result property="approveUserId" column="approve_user_id" />
|
|
<result property="applyId" column="apply_id" />
|
|
<result property="flowId" column="flow_id" />
|
|
<result property="creditType" column="credit_type" />
|
|
<result property="amount" column="amount" />
|
|
<result property="remaining" column="remaining" />
|
|
<result property="effectiveDate" column="effective_date" />
|
|
<result property="expireDate" column="expire_date" />
|
|
<result property="status" column="status" />
|
|
<result property="releaseTime" column="release_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" />
|
|
<result property="delFlag" column="del_flag" />
|
|
<result property="customerCode" column="customer_code" />
|
|
<result property="customerName" column="customer_name" />
|
|
<result property="roleName" column="role_name" />
|
|
<result property="approveBy" column="approve_by" />
|
|
</resultMap>
|
|
|
|
<sql id="grantVo">
|
|
select g.grant_id, g.customer_id, g.account_id, g.role_id, g.approve_user_id, g.apply_id, g.flow_id,
|
|
g.credit_type, g.amount, g.remaining, g.effective_date, g.expire_date, g.status, g.release_time,
|
|
g.create_by, g.create_time, g.update_by, g.update_time, g.remark, g.del_flag,
|
|
c.customer_code, c.customer_name,
|
|
r.role_name,
|
|
u.user_name as approve_by
|
|
from ctr_customer_credit_grant g
|
|
left join ctr_customer c on c.customer_id = g.customer_id
|
|
left join sys_role r on r.role_id = g.role_id
|
|
left join sys_user u on u.user_id = g.approve_user_id
|
|
</sql>
|
|
|
|
<select id="selectGrantList"
|
|
parameterType="com.bms.customer.customermoney.domain.CustomerCreditGrant"
|
|
resultMap="CustomerCreditGrantResult">
|
|
<include refid="grantVo"/>
|
|
<where>
|
|
g.del_flag = '0'
|
|
<if test="customerId != null"> and g.customer_id = #{customerId}</if>
|
|
<if test="roleId != null"> and g.role_id = #{roleId}</if>
|
|
<if test="creditType != null and creditType != ''"> and g.credit_type = #{creditType}</if>
|
|
<if test="status != null and status != ''"> and g.status = #{status}</if>
|
|
</where>
|
|
order by g.grant_id desc
|
|
</select>
|
|
|
|
<select id="selectActiveGrantsForUpdate"
|
|
resultMap="CustomerCreditGrantResult">
|
|
select grant_id, customer_id, account_id, role_id, approve_user_id, apply_id, flow_id,
|
|
credit_type, amount, remaining, effective_date, expire_date, status,
|
|
create_by, create_time, update_by, update_time, del_flag
|
|
from ctr_customer_credit_grant
|
|
where customer_id = #{customerId}
|
|
and credit_type = #{creditType}
|
|
and status = '0'
|
|
and del_flag = '0'
|
|
order by grant_id
|
|
for update
|
|
</select>
|
|
|
|
<insert id="insertGrant" parameterType="com.bms.customer.customermoney.domain.CustomerCreditGrant"
|
|
useGeneratedKeys="true" keyProperty="grantId">
|
|
insert into ctr_customer_credit_grant (
|
|
customer_id, account_id, role_id, approve_user_id, apply_id, flow_id,
|
|
credit_type, amount, remaining, effective_date, expire_date, status,
|
|
create_by, create_time, remark, del_flag
|
|
) values (
|
|
#{customerId}, #{accountId}, #{roleId}, #{approveUserId}, #{applyId}, #{flowId},
|
|
#{creditType}, #{amount}, #{remaining}, #{effectiveDate}, #{expireDate}, #{status},
|
|
#{createBy}, sysdate(), #{remark}, '0'
|
|
)
|
|
</insert>
|
|
|
|
<update id="updateGrantRemaining"
|
|
parameterType="com.bms.customer.customermoney.domain.CustomerCreditGrant">
|
|
update ctr_customer_credit_grant
|
|
set remaining = #{remaining},
|
|
status = #{status},
|
|
release_time = #{releaseTime},
|
|
update_by = #{updateBy},
|
|
update_time = now()
|
|
where grant_id = #{grantId}
|
|
</update>
|
|
</mapper>
|