@ -1,13 +1,15 @@
package cn.iocoder.yudao.module.crm.service.statistics ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.LocalDateTimeUtil ;
import cn.hutool.core.util.ObjUtil ;
import cn.iocoder.yudao.framework.common.enums.DateIntervalEnum ;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils ;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils ;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.* ;
import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper ;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum ;
import cn.iocoder.yudao.module.system.api.dept.DeptApi ;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO ;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi ;
@ -20,14 +22,15 @@ import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal ;
import java.time.LocalDateTime ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Stream ;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception ;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.* ;
import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.* ;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.STATISTICS_CUSTOMER_TIMES_NOT_SET ;
/ * *
* CRM 客 户 分 析 Service 实 现 类
@ -58,114 +61,107 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
@Override
public List < CrmStatisticsCustomerSummaryByDateRespVO > getCustomerSummaryByDate ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
// TODO @dhb52: 如果是 list 变量,要么 List 要么 s 后缀
reqVO . setSqlDateFormat ( getSqlDateFormat ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ) ;
final List < CrmStatisticsCustomerSummaryByDateRespVO > customerCreateCount = customerMapper . selectCustomerCreateCountGroupbyDate ( reqVO ) ;
final List < CrmStatisticsCustomerSummaryByDateRespVO > customerDealCount = customerMapper . selectCustomerDealCountGroupbyDate ( reqVO ) ;
// 3. 获取时间序列
// TODO @dhb52: 3 和 4 其实做的是一类事情,所以可以考虑 3.1 获取时间序列、3.2 合并统计数据 这样注释;然后中间就不空行了;就是说,一般空行的目的,是让逻辑分片,看着整体性更好,但是不能让逻辑感觉碎碎的;
final List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
// 4. 合并统计数据
// TODO @dhb52: 这个是不是要 add 到 respVoList 里?或者还可以 convertList(times, time -> new CrmStatisticsCustomerDealCycleByDateRespVO()...)
List < CrmStatisticsCustomerSummaryByDateRespVO > respVoList = new ArrayList < > ( times . size ( ) ) ;
final Map < String , Integer > customerCreateCountMap = convertMap ( customerCreateCount ,
initParams ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByDateRespVO > customerCreateCountVoList = customerMapper . selectCustomerCreateCountGroupByDate ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByDateRespVO > customerDealCountVoList = customerMapper . selectCustomerDealCountGroupByDate ( reqVO ) ;
// 3. 合并数据
List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
Map < String , Integer > customerCreateCountMap = convertMap ( customerCreateCountVoList ,
CrmStatisticsCustomerSummaryByDateRespVO : : getTime ,
CrmStatisticsCustomerSummaryByDateRespVO : : getCustomerCreateCount ) ;
final Map < String , Integer > customerDealCountMap = convertMap ( customerDealCoun t,
Map < String , Integer > customerDealCountMap = convertMap ( customerDealCountVoList ,
CrmStatisticsCustomerSummaryByDateRespVO : : getTime ,
CrmStatisticsCustomerSummaryByDateRespVO : : getCustomerDealCount ) ;
times . forEach ( time - > respVoList . add (
new CrmStatisticsCustomerSummaryByDateRespVO ( ) . setTime ( time )
List < CrmStatisticsCustomerSummaryByDateRespVO > respVoList = convertList ( times ,
time - > new CrmStatisticsCustomerSummaryByDateRespVO ( )
. setTime ( time )
. setCustomerCreateCount ( customerCreateCountMap . getOrDefault ( time , 0 ) )
. setCustomerDealCount ( customerDealCountMap . getOrDefault ( time , 0 ) )
) ) ;
. setCustomerDealCount ( customerDealCountMap . getOrDefault ( time , 0 ) ) ) ;
return respVoList ;
}
@Override
public List < CrmStatisticsCustomerSummaryByUserRespVO > getCustomerSummaryByUser ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
final List < CrmStatisticsCustomerSummaryByUserRespVO > customerCreateCount = customerMapper . selectCustomerCreateCountGroupbyUser ( reqVO ) ;
final List < CrmStatisticsCustomerSummaryByUserRespVO > customerDealCount = customerMapper . selectCustomerDealCountGroupbyUser ( reqVO ) ;
final List < CrmStatisticsCustomerSummaryByUserRespVO > contractPrice = customerMapper . selectContractPriceGroupbyUser ( reqVO ) ;
final List < CrmStatisticsCustomerSummaryByUserRespVO > receivablePrice = customerMapper . selectReceivablePriceGroupbyUser ( reqVO ) ;
initParams ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > customerCreateCount = customerMapper . selectCustomerCreateCountGroupByUser ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > customerDealCount = customerMapper . selectCustomerDealCountGroupByUser ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > contractPrice = customerMapper . selectContractPriceGroupByUser ( reqVO ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > receivablePrice = customerMapper . selectReceivablePriceGroupByUser ( reqVO ) ;
// 3. 合并统计数据
final Map < Long , Integer > customerCreateCountMap = convertMap ( customerCreateCount ,
Map < Long , Integer > customerCreateCountMap = convertMap ( customerCreateCount ,
CrmStatisticsCustomerSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerSummaryByUserRespVO : : getCustomerCreateCount ) ;
final Map < Long , Integer > customerDealCountMap = convertMap ( customerDealCount ,
Map < Long , Integer > customerDealCountMap = convertMap ( customerDealCount ,
CrmStatisticsCustomerSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerSummaryByUserRespVO : : getCustomerDealCount ) ;
final Map < Long , BigDecimal > contractPriceMap = convertMap ( contractPrice ,
Map < Long , BigDecimal > contractPriceMap = convertMap ( contractPrice ,
CrmStatisticsCustomerSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerSummaryByUserRespVO : : getContractPrice ) ;
final Map < Long , BigDecimal > receivablePriceMap = convertMap ( receivablePrice ,
Map < Long , BigDecimal > receivablePriceMap = convertMap ( receivablePrice ,
CrmStatisticsCustomerSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerSummaryByUserRespVO : : getReceivablePrice ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > respVoList = new ArrayList < > ( userIds . size ( ) ) ;
userIds . forEach ( userId - > {
final CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO ( ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > respVoList = convertList ( userIds , userId - > {
CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO ( ) ;
// ownerUserId 为基类属性
vo . setOwnerUserId ( userId ) ;
vo . setCustomerCreateCount ( customerCreateCountMap . getOrDefault ( userId , 0 ) )
. setCustomerDealCount ( customerDealCountMap . getOrDefault ( userId , 0 ) )
. setContractPrice ( contractPriceMap . getOrDefault ( userId , BigDecimal . ZERO ) )
. setReceivablePrice ( receivablePriceMap . getOrDefault ( userId , BigDecimal . ZERO ) ) ;
respVoList . add ( vo ) ;
return vo ;
} ) ;
// 4. 拼接用户信息
appendUserInfo ( respVoList ) ;
return respVoList ;
}
@Override
public List < CrmStatisticsFollowupSummaryByDateRespVO > getFollowupSummaryByDate ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
reqVO . setSqlDateFormat ( getSqlDateFormat ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ) ;
reqVO . setBizType ( CrmBizTypeEnum . CRM_CUSTOMER . getType ( ) ) ;
final List < CrmStatisticsFollowupSummaryByDateRespVO > followupRecordCount = customerMapper . selectFollowupRecordCountGroupbyDate ( reqVO ) ;
final List < CrmStatisticsFollowupSummaryByDateRespVO > followupCustomerCount = customerMapper . selectFollowupCustomerCountGroupbyDate ( reqVO ) ;
// 3. 获取时间序列
final List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
initParams ( reqVO ) ;
List < CrmStatisticsFollowupSummaryByDateRespVO > followupRecordCount = customerMapper . selectFollowupRecordCountGroupByDate ( reqVO ) ;
List < CrmStatisticsFollowupSummaryByDateRespVO > followupCustomerCount = customerMapper . selectFollowupCustomerCountGroupByDate ( reqVO ) ;
// 4 . 合并统计数据
List < CrmStatisticsFollowupSummaryByDateRespVO> respVoList = new ArrayList < > ( times . size ( ) ) ;
final Map < String , Integer > followupRecordCountMap = convertMap ( followupRecordCount ,
// 3. 合并统计数据
List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
Map < String , Integer > followupRecordCountMap = convertMap ( followupRecordCount ,
CrmStatisticsFollowupSummaryByDateRespVO : : getTime ,
CrmStatisticsFollowupSummaryByDateRespVO : : getFollowupRecordCount ) ;
final Map < String , Integer > followupCustomerCountMap = convertMap ( followupCustomerCount ,
Map < String , Integer > followupCustomerCountMap = convertMap ( followupCustomerCount ,
CrmStatisticsFollowupSummaryByDateRespVO : : getTime ,
CrmStatisticsFollowupSummaryByDateRespVO : : getFollowupCustomerCount ) ;
times. forEach ( time - > respVoList . add (
List< CrmStatisticsFollowupSummaryByDateRespVO > respVoList = convertList ( times , time - >
new CrmStatisticsFollowupSummaryByDateRespVO ( ) . setTime ( time )
. setFollowupRecordCount ( followupRecordCountMap . getOrDefault ( time , 0 ) )
. setFollowupCustomerCount ( followupCustomerCountMap . getOrDefault ( time , 0 ) )
) ) ;
) ;
return respVoList ;
}
@ -173,31 +169,31 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
@Override
public List < CrmStatisticsFollowupSummaryByUserRespVO > getFollowupSummaryByUser ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
reqVO. setBizType ( CrmBizTypeEnum . CRM_CUSTOMER . getType ( ) ) ;
final List < CrmStatisticsFollowupSummaryByUserRespVO > followupRecordCount = customerMapper . selectFollowupRecordCountGroup b yUser( reqVO ) ;
final List < CrmStatisticsFollowupSummaryByUserRespVO > followupCustomerCount = customerMapper . selectFollowupCustomerCountGroup b yUser( reqVO ) ;
initParams( reqVO ) ;
List < CrmStatisticsFollowupSummaryByUserRespVO > followupRecordCount = customerMapper . selectFollowupRecordCountGroup B yUser( reqVO ) ;
List < CrmStatisticsFollowupSummaryByUserRespVO > followupCustomerCount = customerMapper . selectFollowupCustomerCountGroup B yUser( reqVO ) ;
// 3. 合并统计数据
final Map < Long , Integer > followupRecordCountMap = convertMap ( followupRecordCount ,
Map < Long , Integer > followupRecordCountMap = convertMap ( followupRecordCount ,
CrmStatisticsFollowupSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsFollowupSummaryByUserRespVO : : getFollowupRecordCount ) ;
final Map < Long , Integer > followupCustomerCountMap = convertMap ( followupCustomerCount ,
Map < Long , Integer > followupCustomerCountMap = convertMap ( followupCustomerCount ,
CrmStatisticsFollowupSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsFollowupSummaryByUserRespVO : : getFollowupCustomerCount ) ;
List < CrmStatisticsFollowupSummaryByUserRespVO > respVoList = new ArrayList < > ( userIds . size ( ) ) ;
userIds . forEach ( userId - > {
final CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO ( )
List < CrmStatisticsFollowupSummaryByUserRespVO > respVoList = convertList ( userIds , userId - > {
CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO ( )
. setFollowupRecordCount ( followupRecordCountMap . getOrDefault ( userId , 0 ) )
. setFollowupCustomerCount ( followupCustomerCountMap . getOrDefault ( userId , 0 ) ) ;
// ownerUserId 为基类属性
vo . setOwnerUserId ( userId ) ;
respVoList . add ( vo ) ;
return vo ;
} ) ;
// 4. 拼接用户信息
@ -208,19 +204,19 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
@Override
public List < CrmStatisticsFollowupSummaryByTypeRespVO > getFollowupSummaryByType ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获得排行数据
reqVO. setBizType ( CrmBizTypeEnum . CRM_CUSTOMER . getType ( ) ) ;
List < CrmStatisticsFollowupSummaryByTypeRespVO > respVoList = customerMapper . selectFollowupRecordCountGroup b yType( reqVO ) ;
initParams( reqVO ) ;
List < CrmStatisticsFollowupSummaryByTypeRespVO > respVoList = customerMapper . selectFollowupRecordCountGroup B yType( reqVO ) ;
// 3. 获取字典数据
List < DictDataRespDTO > followUpTypes = dictDataApi . getDictDataList ( CRM_FOLLOW_UP_TYPE ) ;
final Map < String , String > followUpTypeMap = convertMap ( followUpTypes ,
Map < String , String > followUpTypeMap = convertMap ( followUpTypes ,
DictDataRespDTO : : getValue , DictDataRespDTO : : getLabel ) ;
respVoList . forEach ( vo - > {
vo . setFollowupType ( followUpTypeMap . get ( vo . getFollowupType ( ) ) ) ;
@ -232,26 +228,27 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
@Override
public List < CrmStatisticsCustomerContractSummaryRespVO > getContractSummary ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取统计数据
initParams ( reqVO ) ;
List < CrmStatisticsCustomerContractSummaryRespVO > respVoList = customerMapper . selectContractSummary ( reqVO ) ;
// 3. 设置 创建人、负责人、行业、来源
// 获取客户所属行业
// 3.1 获取客户所属行业
Map < String , String > industryMap = convertMap ( dictDataApi . getDictDataList ( CRM_CUSTOMER_INDUSTRY ) ,
DictDataRespDTO : : getValue , DictDataRespDTO : : getLabel ) ;
// 获取客户来源
// 3.2 获取客户来源
Map < String , String > sourceMap = convertMap ( dictDataApi . getDictDataList ( CRM_CUSTOMER_SOURCE ) ,
DictDataRespDTO : : getValue , DictDataRespDTO : : getLabel ) ;
// 获取创建人、负责人列表
// 3.3 获取创建人、负责人列表
Map < Long , AdminUserRespDTO > userMap = adminUserApi . getUserMap ( convertSetByFlatMap ( respVoList ,
vo - > Stream . of ( NumberUtils . parseLong ( vo . getCreatorUserId ( ) ) , vo . getOwnerUserId ( ) ) ) ) ;
// 3.4 设置 创建人、负责人、行业、来源
respVoList . forEach ( vo - > {
MapUtils . findAndThen ( industryMap , vo . getIndustryId ( ) , vo : : setIndustryName ) ;
MapUtils . findAndThen ( sourceMap , vo . getSource ( ) , vo : : setSourceName ) ;
@ -266,60 +263,57 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
@Override
public List < CrmStatisticsCustomerDealCycleByDateRespVO > getCustomerDealCycleByDate ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
reqVO . setSqlDateFormat ( getSqlDateFormat ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ) ;
reqVO . setBizType ( CrmBizTypeEnum . CRM_CUSTOMER . getType ( ) ) ;
final List < CrmStatisticsCustomerDealCycleByDateRespVO > customerDealCycle = customerMapper . selectCustomerDealCycleGroupbyDate ( reqVO ) ;
// 3. 获取时间序列
final List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
initParams ( reqVO ) ;
List < CrmStatisticsCustomerDealCycleByDateRespVO > customerDealCycle = customerMapper . selectCustomerDealCycleGroupByDate ( reqVO ) ;
// 4 . 合并统计数据
List < CrmStatisticsCustomerDealCycleByDateRespVO> respVoList = new ArrayList < > ( times . size ( ) ) ;
final Map < String , Double > customerDealCycleMap = convertMap ( customerDealCycle ,
// 3. 合并统计数据
List < String > times = generateTimeSeries ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ;
Map < String , Double > customerDealCycleMap = convertMap ( customerDealCycle ,
CrmStatisticsCustomerDealCycleByDateRespVO : : getTime ,
CrmStatisticsCustomerDealCycleByDateRespVO : : getCustomerDealCycle ) ;
times. forEach ( time - > respVoList . add (
List< CrmStatisticsCustomerDealCycleByDateRespVO > respVoList = convertList ( times , time - >
new CrmStatisticsCustomerDealCycleByDateRespVO ( ) . setTime ( time )
. setCustomerDealCycle ( customerDealCycleMap . getOrDefault ( time , 0D ) )
) ) ;
) ;
return respVoList ;
}
@Override
public List < CrmStatisticsCustomerDealCycleByUserRespVO > getCustomerDealCycleByUser ( CrmStatisticsCustomerReqVO reqVO ) {
// 1. 获得用户编号数组
final List < Long > userIds = getUserIds ( reqVO ) ;
List < Long > userIds = getUserIds ( reqVO ) ;
if ( CollUtil . isEmpty ( userIds ) ) {
return Collections . emptyList ( ) ;
}
reqVO . setUserIds ( userIds ) ;
// 2. 获取分项统计数据
reqVO. setBizType ( CrmBizTypeEnum . CRM_CUSTOMER . getType ( ) ) ;
final List < CrmStatisticsCustomerDealCycleByUserRespVO > customerDealCycle = customerMapper . selectCustomerDealCycleGroup b yUser( reqVO ) ;
final List < CrmStatisticsCustomerSummaryByUserRespVO > customerDealCount = customerMapper . selectCustomerDealCountGroup b yUser( reqVO ) ;
initParams( reqVO ) ;
List < CrmStatisticsCustomerDealCycleByUserRespVO > customerDealCycle = customerMapper . selectCustomerDealCycleGroup B yUser( reqVO ) ;
List < CrmStatisticsCustomerSummaryByUserRespVO > customerDealCount = customerMapper . selectCustomerDealCountGroup B yUser( reqVO ) ;
// 3. 合并统计数据
final Map < Long , Double > customerDealCycleMap = convertMap ( customerDealCycle ,
Map < Long , Double > customerDealCycleMap = convertMap ( customerDealCycle ,
CrmStatisticsCustomerDealCycleByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerDealCycleByUserRespVO : : getCustomerDealCycle ) ;
final Map < Long , Integer > customerDealCountMap = convertMap ( customerDealCount ,
Map < Long , Integer > customerDealCountMap = convertMap ( customerDealCount ,
CrmStatisticsCustomerSummaryByUserRespVO : : getOwnerUserId ,
CrmStatisticsCustomerSummaryByUserRespVO : : getCustomerDealCount ) ;
List < CrmStatisticsCustomerDealCycleByUserRespVO > respVoList = new ArrayList < > ( userIds . size ( ) ) ;
userIds . forEach ( userId - > {
final CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO ( )
List < CrmStatisticsCustomerDealCycleByUserRespVO > respVoList = convertList ( userIds , userId - > {
CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO ( )
. setCustomerDealCycle ( customerDealCycleMap . getOrDefault ( userId , 0.0 ) )
. setCustomerDealCount ( customerDealCountMap . getOrDefault ( userId , 0 ) ) ;
// ownerUserId 为基类属性
vo . setOwnerUserId ( userId ) ;
respVoList . add ( vo ) ;
return vo ;
} ) ;
// 4. 拼接用户信息
@ -335,8 +329,9 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
* /
private < T extends CrmStatisticsCustomerByUserBaseRespVO > void appendUserInfo ( List < T > respVoList ) {
Map < Long , AdminUserRespDTO > userMap = adminUserApi . getUserMap ( convertSet ( respVoList ,
CrmStatisticsCustomerByUserBaseRespVO : : getOwnerUserId ) ) ;
respVoList . forEach ( vo - > MapUtils . findAndThen ( userMap , vo . getOwnerUserId ( ) , user - > vo . setOwnerUserName ( user . getNickname ( ) ) ) ) ;
CrmStatisticsCustomerByUserBaseRespVO : : getOwnerUserId ) ) ;
respVoList . forEach ( vo - > MapUtils . findAndThen ( userMap ,
vo . getOwnerUserId ( ) , user - > vo . setOwnerUserName ( user . getNickname ( ) ) ) ) ;
}
/ * *
@ -352,7 +347,7 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
}
// 情况二:选中某个部门
// 2.1 获得部门列表
final Long deptId = reqVO . getDeptId ( ) ;
Long deptId = reqVO . getDeptId ( ) ;
List < Long > deptIds = convertList ( deptApi . getChildDeptList ( deptId ) , DeptRespDTO : : getId ) ;
deptIds . add ( deptId ) ;
// 2.2 获得用户编号
@ -378,7 +373,6 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
* @param endTime 结 束 时 间
* @return 时 间 序 列
* /
// TODO @dhb52: 可以抽象到 DateUtils 里,开始时间、结束时间,事件间隔,然后返回这个哈;
private List < String > generateTimeSeries ( LocalDateTime startTime , LocalDateTime endTime ) {
boolean byMonth = queryByMonth ( startTime , endTime ) ;
List < String > times = CollUtil . newArrayList ( ) ;
@ -404,4 +398,62 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
return queryByMonth ( startTime , endTime ) ? SQL_DATE_FORMAT_BY_MONTH : SQL_DATE_FORMAT_BY_DAY ;
}
private void initParams ( CrmStatisticsCustomerReqVO reqVO ) {
final Integer intervalType = reqVO . getIntervalType ( ) ;
// 1. 自定义时间间隔,必须输入起始日期-结束日期
if ( DateIntervalEnum . CUSTOMER . getType ( ) . equals ( intervalType ) ) {
if ( ObjUtil . isEmpty ( reqVO . getTimes ( ) ) | | reqVO . getTimes ( ) . length ! = 2 ) {
throw exception ( STATISTICS_CUSTOMER_TIMES_NOT_SET ) ;
}
// 设置 mapper sqlDateFormat 参数
reqVO . setSqlDateFormat ( getSqlDateFormat ( reqVO . getTimes ( ) [ 0 ] , reqVO . getTimes ( ) [ 1 ] ) ) ;
// 自定义日期无需计算日期参数
return ;
}
// 2. 根据时间区间类型计算时间段区间日期
DateTime beginDate = null ;
DateTime endDate = null ;
if ( DateIntervalEnum . TODAY . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfDay ( DateUtil . date ( ) ) ;
endDate = DateUtil . endOfDay ( DateUtil . date ( ) ) ;
} else if ( DateIntervalEnum . YESTERDAY . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . offsetDay ( DateUtil . date ( ) , - 1 ) ;
endDate = DateUtil . offsetDay ( DateUtil . date ( ) , - 1 ) ;
} else if ( DateIntervalEnum . THIS_WEEK . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfWeek ( DateUtil . date ( ) ) ;
endDate = DateUtil . endOfWeek ( DateUtil . date ( ) ) ;
} else if ( DateIntervalEnum . LAST_WEEK . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfWeek ( DateUtil . offsetWeek ( DateUtil . date ( ) , - 1 ) ) ;
endDate = DateUtil . endOfWeek ( DateUtil . offsetWeek ( DateUtil . date ( ) , - 1 ) ) ;
} else if ( DateIntervalEnum . THIS_MONTH . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfMonth ( DateUtil . date ( ) ) ;
endDate = DateUtil . endOfMonth ( DateUtil . date ( ) ) ;
} else if ( DateIntervalEnum . LAST_MONTH . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfMonth ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 1 ) ) ;
endDate = DateUtil . endOfMonth ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 1 ) ) ;
} else if ( DateIntervalEnum . THIS_QUARTER . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfQuarter ( DateUtil . date ( ) ) ;
endDate = DateUtil . endOfQuarter ( DateUtil . date ( ) ) ;
} else if ( DateIntervalEnum . LAST_QUARTER . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfQuarter ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 3 ) ) ;
endDate = DateUtil . endOfQuarter ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 3 ) ) ;
} else if ( DateIntervalEnum . THIS_YEAR . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfYear ( DateUtil . date ( ) ) ;
endDate = DateUtil . endOfYear ( DateUtil . date ( ) ) ;
} else if ( DateIntervalEnum . LAST_YEAR . getType ( ) . equals ( intervalType ) ) {
beginDate = DateUtil . beginOfYear ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 12 ) ) ;
endDate = DateUtil . endOfYear ( DateUtil . offsetMonth ( DateUtil . date ( ) , - 12 ) ) ;
}
// 3. 计算开始、结束日期时间, 并设置reqVo
LocalDateTime [ ] times = new LocalDateTime [ 2 ] ;
times [ 0 ] = LocalDateTimeUtil . beginOfDay ( LocalDateTimeUtil . of ( beginDate ) ) ;
times [ 1 ] = LocalDateTimeUtil . endOfDay ( LocalDateTimeUtil . of ( endDate ) ) ;
// 3.1 设置 mapper 时间区间 参数
reqVO . setTimes ( times ) ;
// 3.2 设置 mapper sqlDateFormat 参数
reqVO . setSqlDateFormat ( getSqlDateFormat ( times [ 0 ] , times [ 1 ] ) ) ;
}
}