|
|
@ -26,14 +26,22 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.constant.DataSourceConstant; |
|
|
|
import com.epmet.constant.ScreenConstant; |
|
|
|
import com.epmet.dao.evaluationindex.screen.ScreenProjectCategoryGridDailyDao; |
|
|
|
import com.epmet.dao.evaluationindex.screen.ScreenProjectCategoryOrgDailyDao; |
|
|
|
import com.epmet.dto.ScreenCustomerGridDTO; |
|
|
|
import com.epmet.dto.extract.result.CustomerAgencyInfoResultDTO; |
|
|
|
import com.epmet.dto.screen.ScreenProjectCategoryOrgDailyDTO; |
|
|
|
import com.epmet.dto.screen.result.CategoryProjectResultDTO; |
|
|
|
import com.epmet.dto.screencoll.ScreenCollFormDTO; |
|
|
|
import com.epmet.entity.crm.CustomerRelationEntity; |
|
|
|
import com.epmet.entity.evaluationindex.screen.ScreenProjectCategoryOrgDailyEntity; |
|
|
|
import com.epmet.service.crm.CustomerRelationService; |
|
|
|
import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService; |
|
|
|
import com.epmet.service.evaluationindex.screen.ScreenCustomerGridService; |
|
|
|
import com.epmet.service.evaluationindex.screen.ScreenProjectCategoryOrgDailyService; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -45,6 +53,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 项目(事件)分类按组织_按天统计 |
|
|
@ -54,10 +63,17 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@DataSource(DataSourceConstant.EVALUATION_INDEX) |
|
|
|
@Slf4j |
|
|
|
public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<ScreenProjectCategoryOrgDailyDao, ScreenProjectCategoryOrgDailyEntity> implements ScreenProjectCategoryOrgDailyService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerRelationService relationService; |
|
|
|
@Autowired |
|
|
|
private ScreenCustomerAgencyService agencyService; |
|
|
|
@Autowired |
|
|
|
private ScreenProjectCategoryGridDailyDao gridDailyDao; |
|
|
|
@Autowired |
|
|
|
private ScreenCustomerGridService gridService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ScreenProjectCategoryOrgDailyDTO> page(Map<String, Object> params) { |
|
|
@ -147,15 +163,15 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void extractProjectCategoryOrgData(String customerId, String dateId) { |
|
|
|
List<ScreenProjectCategoryOrgDailyEntity> needInsert = new ArrayList<>(); |
|
|
|
// 先查询有无子客户
|
|
|
|
List<CustomerRelationEntity> relationInfo = relationService.selectSubCustomer(customerId); |
|
|
|
if (CollectionUtils.isEmpty(relationInfo)){ |
|
|
|
needInsert = disposeOneCustomer(customerId, dateId); |
|
|
|
// 单客户
|
|
|
|
disposeOneCustomer(customerId, dateId); |
|
|
|
}else { |
|
|
|
needInsert = disposeMoreCustomer(customerId,dateId,relationInfo); |
|
|
|
// 多客户
|
|
|
|
disposeMoreCustomer(customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
deleteAndInsert(customerId,dateId,needInsert); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -165,9 +181,75 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc |
|
|
|
* @author zxc |
|
|
|
* @date 2021/3/23 上午10:40 |
|
|
|
*/ |
|
|
|
private List<ScreenProjectCategoryOrgDailyEntity> disposeOneCustomer(String customerId, String dateId){ |
|
|
|
private void disposeOneCustomer(String customerId, String dateId){ |
|
|
|
List<CustomerAgencyInfoResultDTO> agencyIdList = agencyService.selectAllAgencyId(customerId); |
|
|
|
if (!CollectionUtils.isEmpty(agencyIdList)){ |
|
|
|
// 根据组织级别分组
|
|
|
|
Map<String, List<CustomerAgencyInfoResultDTO>> groupByLevel = agencyIdList.stream().collect(Collectors.groupingBy(CustomerAgencyInfoResultDTO::getLevel)); |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.COMMUNITY)){ |
|
|
|
// 社区级别
|
|
|
|
disposeOneCustomerSub(ScreenConstant.COMMUNITY,true,customerId,dateId); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.STREET)){ |
|
|
|
// 街道级别
|
|
|
|
disposeOneCustomerSub(ScreenConstant.STREET,false,customerId,dateId); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.DISTRICT)){ |
|
|
|
// 区级
|
|
|
|
disposeOneCustomerSub(ScreenConstant.DISTRICT,false,customerId,dateId); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.CITY)){ |
|
|
|
// 市级
|
|
|
|
disposeOneCustomerSub(ScreenConstant.CITY,false,customerId,dateId); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.PROVINCE)){ |
|
|
|
// 省级
|
|
|
|
disposeOneCustomerSub(ScreenConstant.PROVINCE,false,customerId,dateId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
/** |
|
|
|
* @Description 单客户处理 |
|
|
|
* @Param level |
|
|
|
* @Param isGrid |
|
|
|
* @Param customerId |
|
|
|
* @Param dateId |
|
|
|
* @author zxc |
|
|
|
* @date 2021/3/25 上午10:44 |
|
|
|
*/ |
|
|
|
public void disposeOneCustomerSub(String level, Boolean isGrid, String customerId, String dateId){ |
|
|
|
List<ScreenProjectCategoryOrgDailyEntity> result = new ArrayList<>(); |
|
|
|
if (isGrid){ |
|
|
|
// 是社区级别
|
|
|
|
List<CategoryProjectResultDTO> categoryInfos = gridDailyDao.selectCategoryInfo(customerId, dateId,null,null); |
|
|
|
if (!CollectionUtils.isEmpty(categoryInfos)){ |
|
|
|
result = ConvertUtils.sourceToTarget(categoryInfos, ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
} |
|
|
|
}else { |
|
|
|
List<CategoryProjectResultDTO> categoryProjectResultDTOS = baseDao.selectOrgCategoryInfo(customerId, dateId, level); |
|
|
|
List<ScreenCustomerGridDTO> belongGridInfos = gridService.selectBelongGridInfo(customerId, level); |
|
|
|
if (!CollectionUtils.isEmpty(belongGridInfos)){ |
|
|
|
// 存在直属网格
|
|
|
|
List<String> gridIds = belongGridInfos.stream().map(m -> m.getGridId()).collect(Collectors.toList()); |
|
|
|
List<CategoryProjectResultDTO> categoryProjectGrid = gridDailyDao.selectCategoryInfo(customerId, dateId, level, gridIds); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectGrid)){ |
|
|
|
categoryProjectResultDTOS.forEach(agency -> { |
|
|
|
categoryProjectGrid.forEach(grid -> { |
|
|
|
if (agency.getOrgId().equals(grid.getOrgId()) && agency.getCategoryCode().equals(grid.getCategoryCode())){ |
|
|
|
agency.setProjectTotal(agency.getProjectTotal() + grid.getProjectTotal()); |
|
|
|
grid.setStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectGrid.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); |
|
|
|
List<CategoryProjectResultDTO> categoryProjectResultDTOS1 = groupByStatus.get(false); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectResultDTOS1)) categoryProjectResultDTOS.addAll(categoryProjectResultDTOS1); |
|
|
|
} |
|
|
|
} |
|
|
|
result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
} |
|
|
|
deleteAndInsert(customerId,dateId,result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -178,9 +260,93 @@ public class ScreenProjectCategoryOrgDailyServiceImpl extends BaseServiceImpl<Sc |
|
|
|
* @author zxc |
|
|
|
* @date 2021/3/23 上午10:40 |
|
|
|
*/ |
|
|
|
private List<ScreenProjectCategoryOrgDailyEntity> disposeMoreCustomer(String customerId, String dateId,List<CustomerRelationEntity> relationInfo){ |
|
|
|
private void disposeMoreCustomer(String customerId, String dateId,List<CustomerRelationEntity> relationInfo){ |
|
|
|
List<CustomerAgencyInfoResultDTO> agencyIdList = agencyService.selectAllAgencyId(customerId); |
|
|
|
if (!CollectionUtils.isEmpty(agencyIdList)){ |
|
|
|
// 根据组织级别分组
|
|
|
|
Map<String, List<CustomerAgencyInfoResultDTO>> groupByLevel = agencyIdList.stream().collect(Collectors.groupingBy(CustomerAgencyInfoResultDTO::getLevel)); |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.COMMUNITY)){ |
|
|
|
// 社区级别
|
|
|
|
disposeMoreCustomerSub(ScreenConstant.COMMUNITY,true,customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.STREET)){ |
|
|
|
// 街道级别
|
|
|
|
disposeMoreCustomerSub(ScreenConstant.STREET,false,customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.DISTRICT)){ |
|
|
|
// 区级
|
|
|
|
disposeMoreCustomerSub(ScreenConstant.DISTRICT,false,customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.CITY)){ |
|
|
|
// 市级
|
|
|
|
disposeMoreCustomerSub(ScreenConstant.CITY,false,customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.PROVINCE)){ |
|
|
|
// 省级
|
|
|
|
disposeMoreCustomerSub(ScreenConstant.PROVINCE,false,customerId,dateId,relationInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
private void disposeMoreCustomerSub(String level,Boolean isGrid,String customerId, String dateId, List<CustomerRelationEntity> relationInfo){ |
|
|
|
List<ScreenProjectCategoryOrgDailyEntity> result = new ArrayList<>(); |
|
|
|
if (isGrid){ |
|
|
|
List<CategoryProjectResultDTO> categoryInfos = gridDailyDao.selectCategoryInfo(customerId, dateId,null,null); |
|
|
|
if (!CollectionUtils.isEmpty(categoryInfos)){ |
|
|
|
result = ConvertUtils.sourceToTarget(categoryInfos, ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
} |
|
|
|
}else { |
|
|
|
List<CategoryProjectResultDTO> categoryProjectResultDTOS = baseDao.selectOrgCategoryInfo(customerId, dateId, level); |
|
|
|
List<ScreenCustomerGridDTO> belongGridInfos = gridService.selectBelongGridInfo(customerId, level); |
|
|
|
if (!CollectionUtils.isEmpty(belongGridInfos)){ |
|
|
|
// 存在直属网格
|
|
|
|
List<String> gridIds = belongGridInfos.stream().map(m -> m.getGridId()).collect(Collectors.toList()); |
|
|
|
List<CategoryProjectResultDTO> categoryProjectGrid = gridDailyDao.selectCategoryInfo(customerId, dateId, level, gridIds); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectGrid)){ |
|
|
|
categoryProjectResultDTOS.forEach(agency -> { |
|
|
|
categoryProjectGrid.forEach(grid -> { |
|
|
|
if (agency.getOrgId().equals(grid.getOrgId()) && agency.getCategoryCode().equals(grid.getCategoryCode())){ |
|
|
|
agency.setProjectTotal(agency.getProjectTotal() + grid.getProjectTotal()); |
|
|
|
grid.setStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectGrid.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); |
|
|
|
List<CategoryProjectResultDTO> categoryProjectResultDTOS1 = groupByStatus.get(false); |
|
|
|
categoryProjectResultDTOS.addAll(categoryProjectResultDTOS1); |
|
|
|
} |
|
|
|
} |
|
|
|
result = ConvertUtils.sourceToTarget(categoryProjectResultDTOS,ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
if (ScreenConstant.DISTRICT.equals(level)){ |
|
|
|
// 子级客户ID
|
|
|
|
List<String> customerIds = relationInfo.stream().map(m -> m.getCustomerId()).collect(Collectors.toList()); |
|
|
|
// 父客户存在的分类
|
|
|
|
List<CategoryProjectResultDTO> categoryProjectExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, true); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectExists)){ |
|
|
|
result.forEach(r -> { |
|
|
|
categoryProjectExists.forEach(c -> { |
|
|
|
if (r.getCategoryCode().equals(c.getCategoryCode())){ |
|
|
|
r.setProjectTotal(r.getProjectTotal() + c.getProjectTotal()); |
|
|
|
c.setStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
Map<Boolean, List<CategoryProjectResultDTO>> groupByStatus = categoryProjectExists.stream().collect(Collectors.groupingBy(CategoryProjectResultDTO::getStatus)); |
|
|
|
List<CategoryProjectResultDTO> categoryProjectFalse = groupByStatus.get(false); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectFalse)){ |
|
|
|
List<ScreenProjectCategoryOrgDailyEntity> f = ConvertUtils.sourceToTarget(categoryProjectFalse, ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
result.addAll(f); |
|
|
|
} |
|
|
|
} |
|
|
|
// 父客户不存在的分类
|
|
|
|
List<CategoryProjectResultDTO> categoryProjectNotExists = baseDao.selectOrgCategoryMoreCustomerInfo(customerIds, dateId, level, customerId, false); |
|
|
|
if (!CollectionUtils.isEmpty(categoryProjectNotExists)){ |
|
|
|
List<ScreenProjectCategoryOrgDailyEntity> notExists = ConvertUtils.sourceToTarget(categoryProjectNotExists, ScreenProjectCategoryOrgDailyEntity.class); |
|
|
|
result.addAll(notExists); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
deleteAndInsert(customerId,dateId,result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|