Browse Source

网格人员类别分析

dev
yinzuomei 4 years ago
parent
commit
af777cb478
  1. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java
  2. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactIcuserCategoryAnalysisDailyEntity.java
  3. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java
  4. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java
  5. 101
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactIcuserCategoryAnalysisDailyServiceImpl.java
  6. 10
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java
  7. 26
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java
  8. 35
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java

@ -278,5 +278,10 @@ public interface UserDao {
@Param("agencyId") String agencyId);
List<OrgIcUserTotalDTO> selectGridIcUserCategoryTotal(@Param("customerId")String customerId, @Param("dateId")String dateId);
List<OrgIcUserTotalDTO> selectGridIcUserCategoryIncr(@Param("customerId")String customerId,
@Param("startDate")String startDate,
@Param("endDate")String endDate,
@Param("type")String type);
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactIcuserCategoryAnalysisDailyEntity.java

@ -27,7 +27,10 @@ public class FactIcuserCategoryAnalysisDailyEntity extends BaseEpmetEntity {
* 预警配置ID
*/
private String configId;
/**
* 类别列名对个数据太麻烦了在这个表存一下
*/
private String columnName;
/**
* 当前数据是截止到XXX的yyyyMMdd
*/

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenCustomerGridService.java

@ -19,7 +19,6 @@ package com.epmet.service.evaluationindex.screen;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.extract.form.*;
import com.epmet.dto.extract.result.GridInfoResultDTO;
import com.epmet.dto.indexcollect.form.CustomerBizOrgFormDTO;
@ -138,5 +137,5 @@ public interface ScreenCustomerGridService extends BaseService<ScreenCustomerGri
*/
Date getLastSyncEndTime();
List<CustomerGridDTO> getByCustomerId(String customerId);
List<ScreenCustomerGridEntity> getByCustomerId(String customerId);
}

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerGridServiceImpl.java

@ -29,7 +29,6 @@ import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.OrgSourceTypeConstant;
import com.epmet.dao.evaluationindex.screen.DimLastSyncRecordDao;
import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao;
import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.extract.form.*;
import com.epmet.dto.extract.result.GridInfoResultDTO;
import com.epmet.dto.indexcollect.form.CustomerBizOrgFormDTO;
@ -293,10 +292,9 @@ public class ScreenCustomerGridServiceImpl extends BaseServiceImpl<ScreenCustome
}
@Override
public List<CustomerGridDTO> getByCustomerId(String customerId) {
public List<ScreenCustomerGridEntity> getByCustomerId(String customerId) {
LambdaQueryWrapper<ScreenCustomerGridEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ScreenCustomerGridEntity::getCustomerId, customerId);
List<ScreenCustomerGridEntity> list = baseDao.selectList(wrapper);
return ConvertUtils.sourceToTarget(list,CustomerGridDTO.class);
return baseDao.selectList(wrapper);
}
}

101
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactIcuserCategoryAnalysisDailyServiceImpl.java

@ -6,15 +6,16 @@ import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.enums.OrgTypeEnum;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.stats.FactIcuserCategoryAnalysisDailyDao;
import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.customize.IcResiCategoryConfigDTO;
import com.epmet.dto.user.result.OrgIcUserTotalDTO;
import com.epmet.entity.evaluationindex.screen.ScreenCustomerGridEntity;
import com.epmet.entity.stats.FactIcuserCategoryAnalysisDailyEntity;
import com.epmet.service.customize.IcResiCategoryStatsConfigService;
import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService;
import com.epmet.service.evaluationindex.screen.ScreenCustomerGridService;
import com.epmet.service.stats.FactIcuserCategoryAnalysisDailyService;
import com.epmet.service.user.UserService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
@ -46,6 +47,7 @@ public class FactIcuserCategoryAnalysisDailyServiceImpl extends BaseServiceImpl<
private ScreenCustomerGridService gridService;
@Autowired
private UserService userService;
/**
* 数字社区-基础信息-人员类别分析-每个类别的人员总数较上月迁入迁出人数
*
@ -59,21 +61,35 @@ public class FactIcuserCategoryAnalysisDailyServiceImpl extends BaseServiceImpl<
if (CollectionUtils.isEmpty(columnList)) {
return;
}
// //所有网格和组织查询出来
// List<CustomerAgencyDTO> agencyDTOList=agencyService.getByCustomerId(customerId);
List<CustomerGridDTO> gridDTOList=gridService.getByCustomerId(customerId);
//所有网格查询出来
List<ScreenCustomerGridEntity> gridDTOList = gridService.getByCustomerId(customerId);
if (CollectionUtils.isEmpty(gridDTOList)) {
return;
}
//网格维度、组织维度初始好数据
List<FactIcuserCategoryAnalysisDailyEntity> initList = constructInitValue(customerId, dateId, gridDTOList, columnList);
if (CollectionUtils.isEmpty(initList)) {
return;
}
// 批量插入数据
//当这3个数都为0的时候不插入数据库了
List<FactIcuserCategoryAnalysisDailyEntity> insertList = initList.stream().filter(entity -> (null != entity.getTotal() && entity.getTotal() > 0)
|| (null != entity.getQcIncr() && entity.getQcIncr() > 0)
|| (null != entity.getQrIncr() && entity.getQrIncr() > 0)).collect(Collectors.toList());
//删除旧数据
clearOldDatas(customerId, dateId, OrgTypeEnum.GRID.getCode());
// 批量插入数据
Lists.partition(insertList, NumConstant.ONE_HUNDRED).forEach(list -> {
insertBatch(list);
});
}
/**
* 删除旧数据
*
* @param customerId
* @param dateId
* @param orgType gridagency
*/
private void clearOldDatas(String customerId, String dateId, String orgType) {
int deleteNum;
do {
@ -83,19 +99,14 @@ public class FactIcuserCategoryAnalysisDailyServiceImpl extends BaseServiceImpl<
}
/**
*
* @param customerId
* @param dateId yyyyMMdd
* @param gridDTOList 当前客户下所有的网格
* @param columnList 所有需要分析的类别对应的ic_resi_user的列名目前只有18类
* @return
*/
private List<FactIcuserCategoryAnalysisDailyEntity> constructInitValue(String customerId,String dateId, List<CustomerGridDTO> gridDTOList,List<IcResiCategoryConfigDTO> columnList) {
private List<FactIcuserCategoryAnalysisDailyEntity> constructInitValue(String customerId, String dateId, List<ScreenCustomerGridEntity> gridDTOList, List<IcResiCategoryConfigDTO> columnList) {
List<FactIcuserCategoryAnalysisDailyEntity> list = new ArrayList<>();
if(CollectionUtils.isEmpty(gridDTOList)){
//没有配置的类别,退出吧
return list;
}
//1、total
// 查询明细ic_user_change_detailed变更明细表,各个网格的各个分类的总人数
@ -106,48 +117,82 @@ public class FactIcuserCategoryAnalysisDailyServiceImpl extends BaseServiceImpl<
String endDate = dateId;
//2、迁入+30:eg:dateId:20211226, [20211201,20211226],类别sum值=1的
Map<String, List<OrgIcUserTotalDTO>> qrList=userService.calGridIcUserQr(customerId,dateId);
Map<String, List<OrgIcUserTotalDTO>> qrList = userService.calGridIcUserIncr(customerId, startDate, endDate, "qr");
//3、迁出 -10 :eg:dateId:20211226, [20211201,20211226],类别sum值 !=1的
Map<String, List<OrgIcUserTotalDTO>> qrList=userService.calGridIcUserQr(customerId,dateId);
Map<String, List<OrgIcUserTotalDTO>> qcList = userService.calGridIcUserIncr(customerId, startDate, endDate, "qc");
for (IcResiCategoryConfigDTO config : columnList) {
gridDTOList.forEach(grid -> {
FactIcuserCategoryAnalysisDailyEntity gridData = new FactIcuserCategoryAnalysisDailyEntity();
gridData.setCustomerId(customerId);
gridData.setConfigId(config.getConfigId());
gridData.setColumnName(config.getColumnName());
gridData.setDateId(dateId);
gridData.setOrgId(grid.getId());
gridData.setOrgId(grid.getGridId());
gridData.setOrgType(OrgTypeEnum.GRID.getCode());
gridData.setPid(StringUtils.isNotBlank(grid.getPid())?grid.getPid(): NumConstant.ZERO_STR);
gridData.setPids(grid.getPids());
gridData.setPid(StringUtils.isNotBlank(grid.getParentAgencyId()) ? grid.getParentAgencyId() : NumConstant.ZERO_STR);
gridData.setPids(grid.getAllParentIds());
boolean zeroFlag=true;
if(MapUtils.isNotEmpty(totalMapList)&&totalMapList.containsKey(grid.getId())){
//截止到目前累计值
boolean totalZeroFlag = true;
if (MapUtils.isNotEmpty(totalMapList) && totalMapList.containsKey(grid.getGridId())) {
//当前网格下,有的类别
List<OrgIcUserTotalDTO> crrentGrid=totalMapList.get(grid.getId());
List<OrgIcUserTotalDTO> crrentGrid = totalMapList.get(grid.getGridId());
if (CollectionUtils.isNotEmpty(crrentGrid)) {
//各个类别对应的数
Map<String, Integer> categoryTotalMap = crrentGrid.stream().collect(Collectors.toMap(OrgIcUserTotalDTO::getColumnName, OrgIcUserTotalDTO::getTotal, (key1, key2) -> key2));
if (MapUtils.isNotEmpty(categoryTotalMap) && categoryTotalMap.containsKey(config.getColumnName())) {
zeroFlag=false;
totalZeroFlag = false;
gridData.setTotal(categoryTotalMap.get(config.getColumnName()));
}
}
}
if(zeroFlag){
if (totalZeroFlag) {
gridData.setTotal(NumConstant.ZERO);
}
gridData.setQcIncr(NumConstant.ZERO);
//较上月迁入
boolean incrZeroFlag = true;
if (MapUtils.isNotEmpty(qrList) && qrList.containsKey(grid.getGridId())) {
//当前网格下,有的类别
List<OrgIcUserTotalDTO> crrentGrid = qrList.get(grid.getGridId());
if (CollectionUtils.isNotEmpty(crrentGrid)) {
//各个类别对应的数
Map<String, Integer> categoryTotalMap = crrentGrid.stream().collect(Collectors.toMap(OrgIcUserTotalDTO::getColumnName, OrgIcUserTotalDTO::getTotal, (key1, key2) -> key2));
if (MapUtils.isNotEmpty(categoryTotalMap) && categoryTotalMap.containsKey(config.getColumnName())) {
incrZeroFlag = false;
gridData.setQrIncr(categoryTotalMap.get(config.getColumnName()));
}
}
}
if (incrZeroFlag) {
gridData.setQrIncr(NumConstant.ZERO);
}
// 较上月迁出:
boolean qcZeroFlag = true;
if (MapUtils.isNotEmpty(qcList) && qcList.containsKey(grid.getGridId())) {
//当前网格下,有的类别
List<OrgIcUserTotalDTO> crrentGridQc = qcList.get(grid.getGridId());
if (CollectionUtils.isNotEmpty(crrentGridQc)) {
//各个类别对应的数
Map<String, Integer> categoryTotalMap = crrentGridQc.stream().collect(Collectors.toMap(OrgIcUserTotalDTO::getColumnName, OrgIcUserTotalDTO::getTotal, (key1, key2) -> key2));
if (MapUtils.isNotEmpty(categoryTotalMap) && categoryTotalMap.containsKey(config.getColumnName())) {
qcZeroFlag = false;
gridData.setQcIncr(categoryTotalMap.get(config.getColumnName()));
}
}
}
if (qcZeroFlag) {
gridData.setQcIncr(NumConstant.ZERO);
}
list.add(gridData);
});
}
return list;
}
public static void main(String[] args) {
String dateId="20211225";
System.out.println(dateId.substring(0,6));
}
}

10
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java

@ -176,4 +176,14 @@ public interface UserService {
* @return
*/
Map<String, List<OrgIcUserTotalDTO>> calGridIcUserTotal(String customerId, String dateId);
/**
*
* @param customerId
* @param startDate 变动时间在此范围内的 yyyyMMdd
* @param endDate :yyyyMMdd
* @param type:qr:迁入qc:迁出
* @return
*/
Map<String, List<OrgIcUserTotalDTO>> calGridIcUserIncr(String customerId, String startDate, String endDate, String type);
}

26
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java

@ -1201,4 +1201,30 @@ public class UserServiceImpl implements UserService {
return resultMap;
}
/**
* @param customerId
* @param startDate 变动时间在此范围内的 yyyyMMdd
* @param endDate :yyyyMMdd
* @param type :qr:迁入qc:迁出
* @return
*/
@Override
public Map<String, List<OrgIcUserTotalDTO>> calGridIcUserIncr(String customerId, String startDate, String endDate, String type) {
Map<String, List<OrgIcUserTotalDTO>> resultMap=new HashMap<>();
List<OrgIcUserTotalDTO> list=userDao.selectGridIcUserCategoryIncr(customerId,startDate,endDate,type);
if(CollectionUtils.isEmpty(list)){
return resultMap;
}
for(OrgIcUserTotalDTO dto:list){
if(resultMap.containsKey(dto.getOrgId())){
resultMap.get(dto.getOrgId()).add(dto);
continue;
}
List<OrgIcUserTotalDTO> newList=new ArrayList<>();
newList.add(dto);
resultMap.put(dto.getOrgId(),newList);
}
return resultMap;
}
}

35
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml

@ -1107,7 +1107,7 @@
select
temp.orgId,
temp.FIELD_NAME as columnName,
count(distinct temp.IC_USER_ID) as total
count(temp.IC_USER_ID) as total
from (
SELECT
d.GRID_ID as orgId,
@ -1120,9 +1120,40 @@
d.DEL_FLAG = '0'
AND d.CUSTOMER_ID = #{customerId}
AND DATE_FORMAT( d.CREATED_TIME, '%Y%m%d' ) &lt;= #{dateId}
group by d.orgId,d.IC_USER_ID,d.FIELD_NAME
group by d.GRID_ID,d.IC_USER_ID,d.FIELD_NAME
)temp
where temp.result=1
group by temp.orgId,temp.FIELD_NAME
</select>
<select id="selectGridIcUserCategoryIncr" parameterType="map" resultType="com.epmet.dto.user.result.OrgIcUserTotalDTO">
select
temp.orgId,
temp.FIELD_NAME as columnName,
count(temp.IC_USER_ID) as total
from (
SELECT
d.GRID_ID as orgId,
d.IC_USER_ID,
d.FIELD_NAME,
sum(d.`VALUE`)as result
FROM
ic_user_change_detailed d
WHERE
d.DEL_FLAG = '0'
AND d.CUSTOMER_ID = #{customerId}
AND DATE_FORMAT( d.CREATED_TIME, '%Y%m%d' ) &gt;= #{startDate}
AND DATE_FORMAT( d.CREATED_TIME, '%Y%m%d' ) &lt;= #{endDate}
group by d.GRID_ID,d.IC_USER_ID,d.FIELD_NAME
)temp
where 1=1
<if test="type != null and type == 'qr'">
and temp.result=1
</if>
<if test="type != null and type == 'qc'">
and temp.result !=1
</if>
group by temp.orgId,temp.FIELD_NAME
</select>
</mapper>

Loading…
Cancel
Save