85 lines
2.9 KiB
XML
85 lines
2.9 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.unis.crm.mapper.ProfileMapper">
|
|
|
|
<select id="selectProfileOverview" resultType="com.unis.crm.dto.profile.ProfileOverviewDTO">
|
|
select
|
|
u.user_id as userId,
|
|
u.display_name as realName,
|
|
case
|
|
when u.created_at is null then 0
|
|
else greatest((current_date - u.created_at::date)::bigint, 0)
|
|
end as onboardingDays,
|
|
case
|
|
when u.status = 1 then '正常'
|
|
else '停用'
|
|
end as accountStatus
|
|
from sys_user u
|
|
where u.user_id = #{userId}
|
|
and u.is_deleted = 0
|
|
limit 1
|
|
</select>
|
|
|
|
<select id="selectUserRoleNames" resultType="java.lang.String">
|
|
select r.role_name
|
|
from sys_user_role ur
|
|
join sys_role r on r.role_id = ur.role_id
|
|
where ur.user_id = #{userId}
|
|
and ur.is_deleted = 0
|
|
and r.is_deleted = 0
|
|
order by r.role_id asc
|
|
</select>
|
|
|
|
<select id="selectUserOrgNames" resultType="java.lang.String">
|
|
select o.org_name
|
|
from sys_tenant_user tu
|
|
join sys_org o on o.id = tu.org_id
|
|
where tu.user_id = #{userId}
|
|
and tu.is_deleted = 0
|
|
and o.is_deleted = 0
|
|
order by tu.id asc
|
|
</select>
|
|
|
|
<select id="selectMonthlyOpportunityCount" resultType="java.lang.Long">
|
|
select count(1)::bigint
|
|
from crm_opportunity
|
|
where owner_user_id = #{userId}
|
|
and date_trunc('month', created_at) = date_trunc('month', now())
|
|
</select>
|
|
|
|
<select id="selectMonthlyExpansionCount" resultType="java.lang.Long">
|
|
select (
|
|
coalesce((
|
|
select count(1)
|
|
from crm_sales_expansion
|
|
where owner_user_id = #{userId}
|
|
and date_trunc('month', created_at) = date_trunc('month', now())
|
|
), 0)
|
|
+
|
|
coalesce((
|
|
select count(1)
|
|
from crm_channel_expansion
|
|
where owner_user_id = #{userId}
|
|
and date_trunc('month', created_at) = date_trunc('month', now())
|
|
), 0)
|
|
)::bigint
|
|
</select>
|
|
|
|
<select id="selectAverageScore" resultType="java.lang.Integer">
|
|
with latest_comment as (
|
|
select distinct on (c.report_id)
|
|
c.report_id,
|
|
c.score
|
|
from work_daily_report_comment c
|
|
order by c.report_id, c.reviewed_at desc nulls last, c.id desc
|
|
)
|
|
select coalesce(round(avg(coalesce(lc.score, r.score))), 0)::int
|
|
from work_daily_report r
|
|
left join latest_comment lc on lc.report_id = r.id
|
|
where r.user_id = #{userId}
|
|
and date_trunc('month', r.report_date::timestamp) = date_trunc('month', now())
|
|
</select>
|
|
</mapper>
|