@ -17,6 +17,7 @@
package com.epmet.service.impl ;
import com.alibaba.fastjson.JSON ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl ;
@ -45,9 +46,7 @@ import com.epmet.dto.form.demand.*;
import com.epmet.dto.result.AllGridsByUserIdResultDTO ;
import com.epmet.dto.result.IcResiUserBriefDTO ;
import com.epmet.dto.result.UserBaseInfoResultDTO ;
import com.epmet.dto.result.demand.DemandRecResultDTO ;
import com.epmet.dto.result.demand.DemandResearchAnalysisResultDTO ;
import com.epmet.dto.result.demand.IcResiUserReportDemandRes ;
import com.epmet.dto.result.demand.* ;
import com.epmet.entity.* ;
import com.epmet.feign.EpmetAdminOpenFeignClient ;
import com.epmet.feign.EpmetUserOpenFeignClient ;
@ -56,6 +55,7 @@ import com.epmet.service.IcResiDemandDictService;
import com.epmet.service.IcUserDemandRecService ;
import com.github.pagehelper.PageHelper ;
import com.github.pagehelper.PageInfo ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.collections4.MapUtils ;
import org.apache.commons.lang3.StringUtils ;
@ -73,6 +73,7 @@ import java.util.stream.Collectors;
* @author generator generator @elink - cn . com
* @since v1 . 0 . 0 2021 - 11 - 19
* /
@Slf4j
@Service
public class IcUserDemandRecServiceImpl extends BaseServiceImpl < IcUserDemandRecDao , IcUserDemandRecEntity > implements IcUserDemandRecService {
@Autowired
@ -239,9 +240,9 @@ public class IcUserDemandRecServiceImpl extends BaseServiceImpl<IcUserDemandRecD
//3、查询志愿者
// 服务方类型:志愿者:volunteer;社会组织:social_org;社区自组织:community_org;区域党建单位:party_unit;
Map < String , String > userInfoMap = new HashMap < > ( ) ;
Lis t< String > userIdList = list . stream ( ) . filter ( item - > item . getServiceType ( ) . equals ( UserDemandConstant . VOLUNTEER ) ) . map ( DemandRecResultDTO : : getServerId ) . collect ( Collectors . toLis t ( ) ) ;
Se t< String > userIdList = list . stream ( ) . filter ( item - > item . getServiceType ( ) . equals ( UserDemandConstant . VOLUNTEER ) ) . map ( DemandRecResultDTO : : getServerId ) . collect ( Collectors . toSe t ( ) ) ;
if ( CollectionUtils . isNotEmpty ( userIdList ) ) {
Result < List < UserBaseInfoResultDTO > > userInfoRes = epmetUserOpenFeignClient . queryUserBaseInfo ( userIdList ) ;
Result < List < UserBaseInfoResultDTO > > userInfoRes = epmetUserOpenFeignClient . queryUserBaseInfo ( new ArrayList < > ( userIdList ) ) ;
if ( ! userInfoRes . success ( ) | | CollectionUtils . isEmpty ( userInfoRes . getData ( ) ) ) {
throw new RenException ( "查询志愿者信息异常" ) ;
}
@ -654,9 +655,9 @@ public class IcUserDemandRecServiceImpl extends BaseServiceImpl<IcUserDemandRecD
//3、查询志愿者
// 服务方类型:志愿者:volunteer;社会组织:social_org;社区自组织:community_org;区域党建单位:party_unit;
Map < String , String > userInfoMap = new HashMap < > ( ) ;
Lis t< String > userIdList = list . stream ( ) . filter ( item - > item . getServiceType ( ) . equals ( UserDemandConstant . VOLUNTEER ) ) . map ( DemandRecResultDTO : : getServerId ) . collect ( Collectors . toLis t ( ) ) ;
Se t< String > userIdList = list . stream ( ) . filter ( item - > item . getServiceType ( ) . equals ( UserDemandConstant . VOLUNTEER ) ) . map ( DemandRecResultDTO : : getServerId ) . collect ( Collectors . toSe t ( ) ) ;
if ( CollectionUtils . isNotEmpty ( userIdList ) ) {
Result < List < UserBaseInfoResultDTO > > userInfoRes = epmetUserOpenFeignClient . queryUserBaseInfo ( userIdList ) ;
Result < List < UserBaseInfoResultDTO > > userInfoRes = epmetUserOpenFeignClient . queryUserBaseInfo ( new ArrayList < > ( userIdList ) ) ;
if ( ! userInfoRes . success ( ) | | CollectionUtils . isEmpty ( userInfoRes . getData ( ) ) ) {
throw new RenException ( "查询志愿者信息异常" ) ;
}
@ -696,6 +697,121 @@ public class IcUserDemandRecServiceImpl extends BaseServiceImpl<IcUserDemandRecD
return new PageData < > ( list , total ) ;
}
/ * *
* 数据分析 - 服务措施分析 - 柱状图
*
* @param formDTO
* @return
* /
@Override
public CategoryAnalysisResDTO categoryAnalysis ( CategoryAnalysisFormDTO formDTO ) {
//1、一级分类字典,没有分类直接退出
SubCodeFormDTO subCodeFormDTO = new SubCodeFormDTO ( ) ;
subCodeFormDTO . setCustomerId ( formDTO . getCusotmerId ( ) ) ;
subCodeFormDTO . setParentCategoryCode ( NumConstant . ZERO_STR ) ;
List < OptionDTO > firstCategoryList = demandDictService . querySubCodeList ( subCodeFormDTO ) ;
if ( CollectionUtils . isEmpty ( firstCategoryList ) ) {
return new CategoryAnalysisResDTO ( Collections . EMPTY_LIST , Collections . EMPTY_LIST ) ;
}
//2、没有服务类型直接退出
Result < Map < String , String > > serviceTypeRes = adminOpenFeignClient . dictMap ( DictTypeEnum . USER_DEMAND_SERVICE_TYPE . getCode ( ) ) ;
if ( ! serviceTypeRes . success ( ) | | MapUtils . isEmpty ( serviceTypeRes . getData ( ) ) ) {
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , "查询服务方类型异常,请检查是否已经配置字典信息" ) ;
}
List < LegendDTO > legend = new ArrayList < > ( ) ;
serviceTypeRes . getData ( ) . forEach ( ( code , name ) - > {
LegendDTO legendDTO = new LegendDTO ( code , name ) ;
legend . add ( legendDTO ) ;
} ) ;
LegendDTO unfinishLegend = new LegendDTO ( "unfinished" , "未完成" ) ;
legend . add ( unfinishLegend ) ;
log . info ( "阶段性胜利1:" + JSON . toJSONString ( legend ) ) ;
// 3、传进来的是组织id的话,查询出全路径
if ( "agency" . equals ( formDTO . getOrgType ( ) ) ) {
if ( NumConstant . ZERO_STR . equals ( formDTO . getPid ( ) ) ) {
//当前传入的组织id=客户的根组织
formDTO . setGridPids ( formDTO . getOrgId ( ) ) ;
} else {
//找到当前组织的所有上级,再拼接上自己
Result < CustomerAgencyDTO > customerAgencyDTOResult = govOrgOpenFeignClient . getAgencyById ( formDTO . getOrgId ( ) ) ;
if ( ! customerAgencyDTOResult . success ( ) | | null = = customerAgencyDTOResult . getData ( ) ) {
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , "获取组织信息异常govOrgOpenFeignClient.getAgencyById" ) ;
}
formDTO . setGridPids ( customerAgencyDTOResult . getData ( ) . getPids ( ) . concat ( StrConstant . COLON ) . concat ( formDTO . getOrgId ( ) ) ) ;
}
}
//4、构造最后的反参
List < CategoryAnalysisDTO > list = new ArrayList < > ( ) ;
// firstCategoryList是所有的一级分类字典
firstCategoryList . forEach ( firstCategory - > {
CategoryAnalysisDTO categoryAnalysisDTO = new CategoryAnalysisDTO ( firstCategory . getValue ( ) , firstCategory . getLabel ( ) , NumConstant . ZERO , Collections . EMPTY_LIST ) ;
categoryAnalysisDTO . setDetail ( constructDefaultDetail ( legend ) ) ;
list . add ( categoryAnalysisDTO ) ;
} ) ;
log . info ( "阶段性胜利2:" + JSON . toJSONString ( list ) ) ;
// 5、查询出有数据的一级分类,sql计算出detail
List < CategoryAnalysisDTO > haveDemandList = baseDao . selectListCategoryAnalysisDTO ( firstCategoryList ,
formDTO . getCusotmerId ( ) ,
formDTO . getOrgId ( ) ,
formDTO . getOrgType ( ) ,
formDTO . getGridPids ( ) ,
formDTO . getStartDateId ( ) ,
formDTO . getEndDateId ( ) ) ;
if ( ! CollectionUtils . isEmpty ( haveDemandList ) ) {
log . info ( "阶段性胜利3:" + JSON . toJSONString ( haveDemandList ) ) ;
Map < String , CategoryAnalysisDTO > map = haveDemandList . stream ( ) . filter ( temp - > CollectionUtils . isNotEmpty ( temp . getDetail ( ) ) ) . collect ( Collectors . toMap ( CategoryAnalysisDTO : : getCategoryCode , dto - > dto ) ) ;
if ( MapUtils . isNotEmpty ( map ) ) {
log . info ( "阶段性胜利4:" + JSON . toJSONString ( map ) ) ;
for ( CategoryAnalysisDTO result : list ) {
if ( map . containsKey ( result . getCategoryCode ( ) ) & & null ! = map . get ( result . getCategoryCode ( ) ) ) {
//如果当前分类下有上报的需求,将原来的0改为实际的需求数量
CategoryAnalysisDTO tempDto = map . get ( result . getCategoryCode ( ) ) ;
result . setTotal ( tempDto . getTotal ( ) ) ;
//当前分类有居民的明细:未完成多少个,xxx个志愿者完成xxx个需求
if ( CollectionUtils . isNotEmpty ( tempDto . getDetail ( ) ) ) {
List < CategoryAnalysisDetail > resDetailList = tempDto . getDetail ( ) ;
Map < String , CategoryAnalysisDetail > detailMap = resDetailList . stream ( ) . collect ( Collectors . toMap ( CategoryAnalysisDetail : : getLegendCode , dto - > dto ) ) ;
//遍历之前构造好的图例
for ( CategoryAnalysisDetail resultDetail : result . getDetail ( ) ) {
if ( detailMap . containsKey ( resultDetail . getLegendCode ( ) ) & & null ! = detailMap . get ( resultDetail . getLegendCode ( ) ) ) {
resultDetail . setTotalService ( detailMap . get ( resultDetail . getLegendCode ( ) ) . getTotalService ( ) ) ;
resultDetail . setServiceDemandTotal ( detailMap . get ( resultDetail . getLegendCode ( ) ) . getServiceDemandTotal ( ) ) ;
}
}
}
}
}
}
}
//返回结果,也不知道对不对
CategoryAnalysisResDTO result = new CategoryAnalysisResDTO ( ) ;
result . setLegend ( legend ) ;
result . setCategoryList ( list ) ;
return result ;
}
private List < CategoryAnalysisDetail > constructDefaultDetail ( List < LegendDTO > legend ) {
List < CategoryAnalysisDetail > l = new ArrayList < > ( ) ;
legend . forEach ( legendDTO - > {
CategoryAnalysisDetail d = ConvertUtils . sourceToTarget ( legendDTO , CategoryAnalysisDetail . class ) ;
d . setServiceDemandTotal ( NumConstant . ZERO ) ;
d . setTotalService ( NumConstant . ZERO ) ;
l . add ( d ) ;
} ) ;
return l ;
}
}