unis_crm/backend/target/classes/mapper/expansion/ExpansionMapper.xml

280 lines
10 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.ExpansionMapper">
<select id="selectDepartments" resultType="com.unis.crm.dto.expansion.DepartmentOptionDTO">
select
id,
org_name as name
from sys_org
where status = 1
order by id asc
</select>
<select id="selectSalesExpansions" resultType="com.unis.crm.dto.expansion.SalesExpansionItemDTO">
select
s.id,
'sales' as type,
s.candidate_name as name,
coalesce(s.mobile, '无') as phone,
coalesce(s.email, '无') as email,
s.target_dept_id as targetDeptId,
'无' as dept,
coalesce(s.industry, '无') as industry,
coalesce(s.title, '无') as title,
s.intent_level as intentLevel,
case s.intent_level
when 'high' then '高'
when 'medium' then '中'
when 'low' then '低'
else '无'
end as intent,
s.stage as stageCode,
case s.stage
when 'initial_contact' then '初步沟通'
when 'solution_discussion' then '方案交流'
when 'bidding' then '招投标'
when 'business_negotiation' then '商务谈判'
when 'won' then '已成交'
when 'lost' then '已放弃'
else coalesce(s.stage, '无')
end as stage,
s.has_desktop_exp as hasExp,
s.in_progress as inProgress,
(s.employment_status = 'active') as active,
s.employment_status as employmentStatus,
coalesce(to_char(s.expected_join_date, 'YYYY-MM-DD'), '无') as expectedJoinDate,
coalesce(s.remark, '无') as notes
from crm_sales_expansion s
where s.owner_user_id = #{userId}
<if test="keyword != null and keyword != ''">
and (
s.candidate_name ilike concat('%', #{keyword}, '%')
or coalesce(s.industry, '') ilike concat('%', #{keyword}, '%')
)
</if>
order by s.updated_at desc, s.id desc
</select>
<select id="selectChannelExpansions" resultType="com.unis.crm.dto.expansion.ChannelExpansionItemDTO">
select
c.id,
'channel' as type,
c.channel_name as name,
coalesce(c.province, '无') as province,
coalesce(c.industry, '无') as industry,
coalesce(cast(c.annual_revenue as varchar), '') as annualRevenue,
case
when c.annual_revenue is null then '无'
when c.annual_revenue >= 10000 then trim(to_char(c.annual_revenue / 10000.0, 'FM999999990.##')) || '万'
else trim(to_char(c.annual_revenue, 'FM999999990.##'))
end as revenue,
coalesce(c.staff_size, 0) as size,
coalesce(c.contact_name, '无') as contact,
coalesce(c.contact_title, '无') as contactTitle,
coalesce(c.contact_mobile, '无') as phone,
c.stage as stageCode,
case c.stage
when 'initial_contact' then '初步接触'
when 'solution_discussion' then '方案交流'
when 'bidding' then '招投标'
when 'business_negotiation' then '合作洽谈'
when 'won' then '已合作'
when 'lost' then '已终止'
else coalesce(c.stage, '无')
end as stage,
c.landed_flag as landed,
coalesce(to_char(c.expected_sign_date, 'YYYY-MM-DD'), '无') as expectedSignDate,
coalesce(c.remark, '无') as notes
from crm_channel_expansion c
where c.owner_user_id = #{userId}
<if test="keyword != null and keyword != ''">
and (
c.channel_name ilike concat('%', #{keyword}, '%')
or coalesce(c.industry, '') ilike concat('%', #{keyword}, '%')
or coalesce(c.province, '') ilike concat('%', #{keyword}, '%')
)
</if>
order by c.updated_at desc, c.id desc
</select>
<select id="selectSalesFollowUps" resultType="com.unis.crm.dto.expansion.ExpansionFollowUpDTO">
select
f.id,
f.biz_id as bizId,
f.biz_type as bizType,
f.followup_time as followUpTime,
f.followup_type as type,
coalesce(f.content, '无') as content,
coalesce(u.display_name, '无') as user
from crm_expansion_followup f
join crm_sales_expansion s on s.id = f.biz_id and f.biz_type = 'sales'
left join sys_user u on u.user_id = f.followup_user_id
where s.owner_user_id = #{userId}
and f.biz_id in
<foreach collection="bizIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
order by f.followup_time desc, f.id desc
</select>
<select id="selectChannelFollowUps" resultType="com.unis.crm.dto.expansion.ExpansionFollowUpDTO">
select
f.id,
f.biz_id as bizId,
f.biz_type as bizType,
f.followup_time as followUpTime,
f.followup_type as type,
coalesce(f.content, '无') as content,
coalesce(u.display_name, '无') as user
from crm_expansion_followup f
join crm_channel_expansion c on c.id = f.biz_id and f.biz_type = 'channel'
left join sys_user u on u.user_id = f.followup_user_id
where c.owner_user_id = #{userId}
and f.biz_id in
<foreach collection="bizIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
order by f.followup_time desc, f.id desc
</select>
<insert id="insertSalesExpansion" useGeneratedKeys="true" keyProperty="request.id">
insert into crm_sales_expansion (
candidate_name,
mobile,
email,
target_dept_id,
industry,
title,
intent_level,
stage,
has_desktop_exp,
in_progress,
employment_status,
expected_join_date,
owner_user_id,
remark
) values (
#{request.candidateName},
#{request.mobile},
#{request.email},
#{request.targetDeptId},
#{request.industry},
#{request.title},
#{request.intentLevel},
#{request.stage},
#{request.hasDesktopExp},
#{request.inProgress},
#{request.employmentStatus},
#{request.expectedJoinDate},
#{userId},
#{request.remark}
)
</insert>
<insert id="insertChannelExpansion" useGeneratedKeys="true" keyProperty="request.id">
insert into crm_channel_expansion (
channel_name,
province,
industry,
annual_revenue,
staff_size,
contact_name,
contact_title,
contact_mobile,
stage,
landed_flag,
expected_sign_date,
owner_user_id,
remark
) values (
#{request.channelName},
#{request.province},
#{request.industry},
#{request.annualRevenue},
#{request.staffSize},
#{request.contactName},
#{request.contactTitle},
#{request.contactMobile},
#{request.stage},
#{request.landedFlag},
#{request.expectedSignDate},
#{userId},
#{request.remark}
)
</insert>
<update id="updateSalesExpansion">
update crm_sales_expansion
set candidate_name = #{request.candidateName},
mobile = #{request.mobile},
email = #{request.email},
target_dept_id = #{request.targetDeptId},
industry = #{request.industry},
title = #{request.title},
intent_level = #{request.intentLevel},
stage = #{request.stage},
has_desktop_exp = #{request.hasDesktopExp},
in_progress = #{request.inProgress},
employment_status = #{request.employmentStatus},
expected_join_date = #{request.expectedJoinDate},
remark = #{request.remark}
where id = #{id}
and owner_user_id = #{userId}
</update>
<update id="updateChannelExpansion">
update crm_channel_expansion
set channel_name = #{request.channelName},
province = #{request.province},
industry = #{request.industry},
annual_revenue = #{request.annualRevenue},
staff_size = #{request.staffSize},
contact_name = #{request.contactName},
contact_title = #{request.contactTitle},
contact_mobile = #{request.contactMobile},
stage = #{request.stage},
landed_flag = #{request.landedFlag},
expected_sign_date = #{request.expectedSignDate},
remark = #{request.remark}
where id = #{id}
and owner_user_id = #{userId}
</update>
<select id="countOwnedSalesExpansion" resultType="int">
select count(1)
from crm_sales_expansion
where id = #{id}
and owner_user_id = #{userId}
</select>
<select id="countOwnedChannelExpansion" resultType="int">
select count(1)
from crm_channel_expansion
where id = #{id}
and owner_user_id = #{userId}
</select>
<insert id="insertExpansionFollowUp">
insert into crm_expansion_followup (
biz_type,
biz_id,
followup_time,
followup_type,
content,
next_action,
followup_user_id
) values (
#{bizType},
#{bizId},
#{request.followUpTime},
#{request.followUpType},
#{request.content},
#{request.nextAction},
#{userId}
)
</insert>
</mapper>