Commit beb9f649 by Water Wang

optimize leads statistics

parent 977a77ea
...@@ -91,60 +91,21 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService { ...@@ -91,60 +91,21 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
public LeadsStatisticsResponseVO leadsStatistics(LeadsStatisticsRequestVO requestVO, HttpServletResponse response) { public LeadsStatisticsResponseVO leadsStatistics(LeadsStatisticsRequestVO requestVO, HttpServletResponse response) {
LeadsStatisticsResponseVO responseVO = new LeadsStatisticsResponseVO(); LeadsStatisticsResponseVO responseVO = new LeadsStatisticsResponseVO();
Integer expertApplyStatus = requestVO.getExpertApplyStatus(),leadsStatus = requestVO.getLeadsStatus(); Integer expertApplyStatus = requestVO.getExpertApplyStatus(),leadsStatus = requestVO.getLeadsStatus();
leadsStatus = (expertApplyStatus != null) ? 2 : leadsStatus;
String leadsDateSpan = requestVO.getLeadsDateSpan(); String leadsDateSpan = requestVO.getLeadsDateSpan();
Integer isStatement = requestVO.getIsStatement();//0=非报表,1=报表 Integer isStatement = requestVO.getIsStatement();//0=非报表,1=报表
PageInfo<LeadsStatisticsInfo> requestPage = requestVO.getPageInfo(); PageInfo<LeadsStatisticsInfo> requestPage = requestVO.getPageInfo();
//1、查询商机信息
List<LeadsStatisticsInfo> resultList;
List<LeadsStatisticsInfo> leadsInfos = getLeadsInfoByDate(leadsDateSpan);
if(leadsInfos != null && leadsInfos.size() > 0){
if(leadsStatus != null && leadsStatus == 1){//未派遣的商机
resultList = getIsNotAssignLeads(leadsInfos);
}else{
//2、查询商机的派遣情况
List<LeadsStatisticsInfo> isAssignLeadsInfos = mktLeadsPoolDALService.findIsAssignLeads();
Map<Long,LeadsStatisticsInfo> leadsAssignMap = new HashMap<>();
if(isAssignLeadsInfos != null && isAssignLeadsInfos.size() > 0){
isAssignLeadsInfos.forEach(i->leadsAssignMap.put(i.getAssignId(),i));
}
//3、商机状态
Map<Long,Long> leadsStatusMap = mktLeadsPoolDALService.findLeadsStatusMap();
//4、商机状态信息
List<MdDropOptions> dropList = mdDropOptionsDALService.findByDropMasterCodes(Arrays.asList("leads_manual_blood_type","leads_manual_zodiac_type","leads_manual_source","bizchance_promotion_action"));
Map<Long,String> dropMap = new HashMap<>();
if(dropList != null && dropList.size() > 0){
dropList.forEach(i->dropMap.put(i.getId(),i.getDropOptionName()));
}
//5、经纪人信息
List<AclPractitioner> practitionerList = aclPractitionerDALService.findAll();
Map<Long,AclPractitioner> practitionerMap = new HashMap<>();
if(practitionerList != null && practitionerList.size()>0){
practitionerList.forEach(i->practitionerMap.put(i.getId(),i));
}
/*
//6、城市信息
List<MdCity> cityList = mdCityDALService.findByInsurerId(2L);
Map<Long,String> cityMap = new HashMap<>();
if(cityList != null && cityList.size() > 0 ){
cityList.forEach(i->cityMap.put(i.getId(),i.getCityName()));
}
*/
//7、整理信息
resultList = integrateResponse(leadsInfos,leadsAssignMap,leadsStatusMap,dropMap,practitionerMap);
//8、安装条件筛选
resultList = screenResult(resultList,expertApplyStatus);
}
//9、报表
if(isStatement != null && isStatement == 1){
getLeadsStatement(resultList,response);
}
PageInfo<LeadsStatisticsInfo> pageInfoResult = PageInfoUtils.list2PageInfo(resultList,requestPage.getPageNum(),requestPage.getPageSize()); Map<String,String> leadsDataMap = obtainDate(leadsDateSpan);
responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000"))); String leadsStartTime = leadsDataMap.get("start");
responseVO.setStatisticsPageInfo(pageInfoResult); String leadsEndTime = leadsDataMap.get("end");
if(isStatement == 1){
List<LeadsStatisticsInfo> dataList = mktLeadsPoolDALService.findByCondition(isStatement,leadsStatus,expertApplyStatus,leadsStartTime,leadsEndTime);
getLeadsStatement(dataList,response);
}else{ }else{
responseVO.setCommonResult(new CommonResult(false,ZHBErrorConfig.getErrorInfo("820001"))); PageInfo<LeadsStatisticsInfo> dataPage = mktLeadsPoolDALService.findByConditionPage(requestPage.getPageNum(),requestPage.getSize(),isStatement,leadsStatus,expertApplyStatus,leadsStartTime,leadsEndTime);
responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000")));
responseVO.setStatisticsPageInfo(dataPage);
} }
return responseVO; return responseVO;
} }
...@@ -354,18 +315,6 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService { ...@@ -354,18 +315,6 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
/** /**
* 获取商机
* @param leadsDateSpan 商机时间
* @return 商机列表
*/
private List<LeadsStatisticsInfo> getLeadsInfoByDate(String leadsDateSpan) {
Map<String,String> leadsDataMap = obtainDate(leadsDateSpan);
String leadsStartTime = leadsDataMap.get("start");
String leadsEndTime = leadsDataMap.get("end");
return mktLeadsPoolDALService.findALLByDate(leadsStartTime,leadsEndTime);
}
/**
* 获取查询的起止时间 * 获取查询的起止时间
* @param dateSpan 时间段 * @param dateSpan 时间段
* @return map * @return map
......
package com.yd.dal.mapper.marketing; package com.yd.dal.mapper.marketing;
import com.github.pagehelper.Page;
import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo; import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo;
import com.yd.dal.entity.leads.LeadsStatusInfo; import com.yd.dal.entity.leads.LeadsStatusInfo;
import com.yd.dal.entity.marketing.MktLeadsPool; import com.yd.dal.entity.marketing.MktLeadsPool;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
public interface MktLeadsPoolMapper { public interface MktLeadsPoolMapper {
int deleteByPrimaryKey(Long id); int deleteByPrimaryKey(@Param("id") Long id);
int insert(MktLeadsPool record); int insert(MktLeadsPool record);
...@@ -23,11 +23,7 @@ public interface MktLeadsPoolMapper { ...@@ -23,11 +23,7 @@ public interface MktLeadsPoolMapper {
MktLeadsPool findByCustomerId(Long customerId); MktLeadsPool findByCustomerId(Long customerId);
List<LeadsStatisticsInfo> findALLByDate(@Param("leadsStartTime")String leadsStartTime, @Param("leadsEndTime")String leadsEndTime); Page<LeadsStatisticsInfo> findALLByDate(@Param("isStatement") Integer isStatement, @Param("leadsStatus") Integer leadsStatus, @Param("expertApplyStatus") Integer expertApplyStatus, @Param("leadsStartTime") String leadsStartTime, @Param("leadsEndTime") String leadsEndTime);
List<LeadsStatisticsInfo> findIsAssignByDate(@Param("leadsStartTime")String leadsStartTime, @Param("leadsEndTime")String leadsEndTime);
List<LeadsStatisticsInfo> findIsNotAssignByDate(@Param("leadsStartTime")String leadsStartTime, @Param("leadsEndTime")String leadsEndTime);
List<LeadsStatisticsInfo> findIsAssignLeads(); List<LeadsStatisticsInfo> findIsAssignLeads();
......
package com.yd.dal.service.marketing.Impl; package com.yd.dal.service.marketing.Impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo; import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo;
import com.yd.api.agms.vo.statistics.statementData;
import com.yd.dal.entity.leads.LeadsStatusInfo; import com.yd.dal.entity.leads.LeadsStatusInfo;
import com.yd.dal.entity.marketing.MktLeadsPool; import com.yd.dal.entity.marketing.MktLeadsPool;
import com.yd.dal.mapper.marketing.MktLeadsPoolMapper; import com.yd.dal.mapper.marketing.MktLeadsPoolMapper;
...@@ -28,18 +32,8 @@ public class MktLeadsPoolDALServiceImpl implements MktLeadsPoolDALService { ...@@ -28,18 +32,8 @@ public class MktLeadsPoolDALServiceImpl implements MktLeadsPoolDALService {
} }
@Override @Override
public List<LeadsStatisticsInfo> findALLByDate(String leadsStartTime, String leadsEndTime) { public List<LeadsStatisticsInfo> findByCondition(Integer isStatement,Integer leadsStatus,Integer expertApplyStatus,String leadsStartTime, String leadsEndTime) {
return mktLeadsPoolMapper.findALLByDate(leadsStartTime,leadsEndTime); return mktLeadsPoolMapper.findALLByDate(isStatement,leadsStatus,expertApplyStatus,leadsStartTime,leadsEndTime);
}
@Override
public List<LeadsStatisticsInfo> findIsAssignByDate(String leadsStartTime, String leadsEndTime) {
return mktLeadsPoolMapper.findIsAssignByDate(leadsStartTime,leadsEndTime);
}
@Override
public List<LeadsStatisticsInfo> findIsNotAssignByDate(String leadsStartTime, String leadsEndTime) {
return mktLeadsPoolMapper.findIsNotAssignByDate(leadsStartTime,leadsEndTime);
} }
@Override @Override
...@@ -54,4 +48,12 @@ public class MktLeadsPoolDALServiceImpl implements MktLeadsPoolDALService { ...@@ -54,4 +48,12 @@ public class MktLeadsPoolDALServiceImpl implements MktLeadsPoolDALService {
leadsStatusInfoList.forEach(i->leadsMap.put(i.getLeadsCustomerId(),i.getLeadsStatusId())); leadsStatusInfoList.forEach(i->leadsMap.put(i.getLeadsCustomerId(),i.getLeadsStatusId()));
return leadsMap; return leadsMap;
} }
@Override
public PageInfo<LeadsStatisticsInfo> findByConditionPage(int pageNum, int size, Integer isStatement, Integer leadsStatus, Integer expertApplyStatus, String leadsStartTime, String leadsEndTime) {
PageHelper.startPage(pageNum, size);
Page<LeadsStatisticsInfo> statementData = mktLeadsPoolMapper.findALLByDate(isStatement,leadsStatus,expertApplyStatus,leadsStartTime,leadsEndTime);
PageInfo<LeadsStatisticsInfo> pageInfo = new PageInfo<>(statementData);
return pageInfo;
}
} }
package com.yd.dal.service.marketing; package com.yd.dal.service.marketing;
import com.github.pagehelper.PageInfo;
import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo; import com.yd.api.agms.vo.statistics.LeadsStatisticsInfo;
import com.yd.dal.entity.marketing.MktLeadsPool; import com.yd.dal.entity.marketing.MktLeadsPool;
...@@ -11,13 +12,11 @@ public interface MktLeadsPoolDALService { ...@@ -11,13 +12,11 @@ public interface MktLeadsPoolDALService {
void save(MktLeadsPool pool); void save(MktLeadsPool pool);
List<LeadsStatisticsInfo> findALLByDate(String leadsStartTime, String leadsEndTime); List<LeadsStatisticsInfo> findByCondition(Integer isStatement,Integer leadsStatus,Integer expertApplyStatus,String leadsStartTime, String leadsEndTime);
List<LeadsStatisticsInfo> findIsAssignByDate(String leadsStartTime, String leadsEndTime);
List<LeadsStatisticsInfo> findIsNotAssignByDate(String leadsStartTime, String leadsEndTime);
List<LeadsStatisticsInfo> findIsAssignLeads(); List<LeadsStatisticsInfo> findIsAssignLeads();
Map<Long, Long> findLeadsStatusMap(); Map<Long, Long> findLeadsStatusMap();
PageInfo<LeadsStatisticsInfo> findByConditionPage(int pageNum, int size, Integer isStatement, Integer leadsStatus, Integer expertApplyStatus, String leadsStartTime, String leadsEndTime);
} }
...@@ -162,16 +162,71 @@ ...@@ -162,16 +162,71 @@
c.age as leadsAge, c.age as leadsAge,
c.address as leadsCity, c.address as leadsCity,
c.blood_type_id as leadsBloodTypeId, c.blood_type_id as leadsBloodTypeId,
c.zodiacTypeName as leadsZodiacType,
c.bloodTypeName as leadsBloodType,
c.zodiac_type_id as leadsZodiacTypeId, c.zodiac_type_id as leadsZodiacTypeId,
IF(c.gender = 1, '男', '女') as leadsGender, IF(c.gender = 1, '男', '女') as leadsGender,
date_format(pool.added_at , '%Y-%m-%d %H:%i:%s') as leadsCreateTime, date_format(pool.added_at , '%Y-%m-%d %H:%i:%s') as leadsCreateTime,
assign.id as assignId, assign.id as assignId,
assign.assigned_practitioner_id as practitionerId, assign.assigned_practitioner_id as practitionerId,
assign.name as practitionerName,
assign.login as practitionerMobileNo,
pool.source_from as leadsSourceId, pool.source_from as leadsSourceId,
date_format(assign.created_at, '%Y-%m-%d %H:%i:%s') as leadsAssignTime op.drop_option_name as leadsSource,
from ag_mkt_leads_pool pool LEFT JOIN ag_acl_customer c on pool.customer_id = c.id date_format(assign.created_at, '%Y-%m-%d %H:%i:%s') as leadsAssignTime,
left join ag_mkt_leads_assigneds assign on assign.customer_id = pool.customer_id expertAssign.expertId as smePractitionerId, -- 专家经纪人id
expertAssign.expertName as sme,
expertAssign.expertMobileNo as smeMobileNo,
date_format(expertAssign.expertAssignTime , '%Y-%m-%d %H:%i:%s') as assignSMEDate, -- 专家派遣时间
date_format(request.created_at , '%Y-%m-%d %H:%i:%s') as requestSMEDate, -- 专家请求时间
assign.FYC as predictFYP, -- 预计FYP
assign.FYP as predictFYC, -- 预计FYC
assign.pieces as predictPieces, -- 预计件数
date_format(assign.time_to_close , '%Y-%m-%d %H:%i:%s') as dealTime, -- 预计成交时间
assignStatus.leadsStatusId as leadsStatusId,
assignStatus.leadsStatusName as leadsStatus
from ag_mkt_leads_pool pool inner JOIN (select t.id,t.name,t.login,t.wechat_no,t.age,t.address,t.blood_type_id,t.zodiac_type_id,t.gender,op1.drop_option_name as bloodTypeName,op2.drop_option_name as zodiacTypeName
from ag_acl_customer t left join ag_md_drop_options op1 on t.blood_type_id = op1.id
left join ag_md_drop_options op2 on t.zodiac_type_id = op2.id) c on pool.customer_id = c.id
left join (select assign.id,assign.customer_id,assign.assigned_practitioner_id,assign.created_at,assign.FYC,assign.FYP,assign.pieces,assign.time_to_close,p.name,c.login
from ag_mkt_leads_assigneds assign left join ag_acl_practitioner p on assign.assigned_practitioner_id = p.id
inner join ag_acl_customer c on p.customer_id = c.id) assign on assign.customer_id = pool.customer_id
left join ag_mkt_leads_expert_request request on request.leads_assigned_id = assign.id
left join (select expertAssign.leads_expert_request_id as expertRequestId,p.id as expertId,p.name as expertName,c.login as expertMobileNo,expertAssign.created_at as expertAssignTime
from ag_mkt_leads_expert_assign expertAssign inner join ag_acl_practitioner p on expertAssign.expert_practitioner_id = p.id
inner join ag_acl_customer c on p.customer_id = c.id) expertAssign on request.id = expertAssign.expertRequestId
inner join (SELECT maxt.customer_id as leadsCustomerId,
tr.md_drop_option_id as leadsStatusId, -- 商机状态id
options.drop_option_name as leadsStatusName -- 商机状态名
FROM(SELECT customer_id,max(updated_at) as track_time FROM ag_mkt_leads_assigned_track tr GROUP BY tr.customer_id) maxt
INNER JOIN ag_mkt_leads_assigned_track tr on maxt.customer_id=tr.customer_id AND maxt.track_time = tr.updated_at
inner join ag_md_drop_options options on tr.md_drop_option_id = options.id
order by tr.leads_assigned_id) assignStatus on assignStatus.leadsCustomerId = pool.customer_id
left join ag_md_drop_options op on pool.source_from = op.id
where pool.is_active = 1 where pool.is_active = 1
<choose>
<when test="leadsStatus == 1">
and assign.id is null
</when>
<when test="leadsStatus == 2">
and assign.id is not null
<choose>
<when test="expertApplyStatus == 1">
and request.id is null
</when>
<when test="expertApplyStatus == 2">
and request.id is not null
and expertAssign.expertId is null
</when>
<when test="expertApplyStatus == 3">
and request.id is not null
and expertAssign.expertId is not null
</when>
<otherwise></otherwise>
</choose>
</when>
<otherwise></otherwise>
</choose>
<if test="leadsStartTime != null"> <if test="leadsStartTime != null">
and pool.added_at &gt;= #{leadsStartTime,jdbcType=VARCHAR} and pool.added_at &gt;= #{leadsStartTime,jdbcType=VARCHAR}
</if> </if>
...@@ -180,52 +235,7 @@ ...@@ -180,52 +235,7 @@
</if> </if>
order by pool.added_at desc order by pool.added_at desc
</select> </select>
<select id="findIsAssignByDate" resultType="com.yd.api.agms.vo.statistics.LeadsStatisticsInfo">
select c.`name` as leadsName,
c.login as leadsMobileNo,
c.wechat_no as leadsWeChatId,
c.age as leadsAge,
c.city_id as cityId,
c.blood_type_id as bloodTypeId,
c.zodiac_type_id as zodiacTypeId,
IF(c.gender = 1, '男', '女') as leadsGender,
date_format(pool.added_at , '%Y-%m-%d %H:%i:%s') as leadsCreatTime,
assgin.assigned_practitioner_id as practitionerId,
date_format(assgin.created_at, '%Y-%m-%d %H:%i:%s') as leadsAssignTime
from ag_mkt_leads_pool pool LEFT JOIN ag_acl_customer c on pool.customer_id = c.id
inner join ag_mkt_leads_assigneds assgin on assgin.customer_id = pool.customer_id
# where 1 == 1
<!-- <if test="leadsStartTime != null">-->
<!-- and pool.added_at >= #{leadsStartTime,jdbcType=VARCHAR}-->
<!-- </if>-->
<!-- <if test="leadsEndTime != null">-->
<!-- and pool.added_at <= #{leadsEndTime,jdbcType=VARCHAR}-->
<!-- </if>-->
order by pool.added_at desc
</select>
<select id="findIsNotAssignByDate" resultType="com.yd.api.agms.vo.statistics.LeadsStatisticsInfo">
select c.`name` as leadsName,
c.login as leadsMobileNo,
c.wechat_no as leadsWeChatId,
c.age as leadsAge,
c.city_id as cityId,
c.blood_type_id as bloodTypeId,
c.zodiac_type_id as zodiacTypeId,
IF(c.gender = 1, '男', '女') as leadsGender,
date_format(pool.added_at , '%Y-%m-%d %H:%i:%s') as leadsCreatTime,
assgin.assigned_practitioner_id as practitionerId,
date_format(assgin.created_at, '%Y-%m-%d %H:%i:%s') as leadsAssignTime
from ag_mkt_leads_pool pool LEFT JOIN ag_acl_customer c on pool.customer_id = c.id
left outer join ag_mkt_leads_assigneds assgin on assgin.customer_id = pool.customer_id
where assgin.customer_id is null
<!-- <if test="leadsStartTime != null">-->
<!-- and pool.added_at >= #{leadsStartTime,jdbcType=VARCHAR}-->
<!-- </if>-->
<!-- <if test="leadsEndTime != null">-->
<!-- and pool.added_at <= #{leadsEndTime,jdbcType=VARCHAR}-->
<!-- </if>-->
order by pool.added_at desc
</select>
<select id="findIsAssignLeads" resultType="com.yd.api.agms.vo.statistics.LeadsStatisticsInfo"> <select id="findIsAssignLeads" resultType="com.yd.api.agms.vo.statistics.LeadsStatisticsInfo">
SELECT SELECT
assign.id as assignId, -- 派遣id assign.id as assignId, -- 派遣id
...@@ -245,7 +255,6 @@ ...@@ -245,7 +255,6 @@
</select> </select>
<select id="findLeadsStatusMap" resultType="com.yd.dal.entity.leads.LeadsStatusInfo"> <select id="findLeadsStatusMap" resultType="com.yd.dal.entity.leads.LeadsStatusInfo">
SELECT maxt.customer_id as leadsCustomerId, SELECT maxt.customer_id as leadsCustomerId,
# tr.leads_assigned_id as assignId,
tr.md_drop_option_id as leadsStatusId -- 商机状态id tr.md_drop_option_id as leadsStatusId -- 商机状态id
FROM(SELECT customer_id,max(updated_at) as track_time FROM ag_mkt_leads_assigned_track tr GROUP BY tr.customer_id) maxt FROM(SELECT customer_id,max(updated_at) as track_time FROM ag_mkt_leads_assigned_track tr GROUP BY tr.customer_id) maxt
INNER JOIN ag_mkt_leads_assigned_track tr on maxt.customer_id=tr.customer_id AND maxt.track_time = tr.updated_at order by tr.leads_assigned_id INNER JOIN ag_mkt_leads_assigned_track tr on maxt.customer_id=tr.customer_id AND maxt.track_time = tr.updated_at order by tr.leads_assigned_id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment