|
|
@ -3,6 +3,7 @@ package com.epmet.dataaggre.service.govorg.impl; |
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.dingtalk.api.request.OapiRobotSendRequest; |
|
|
@ -24,17 +25,17 @@ import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.BuildingInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dataaggre.constant.DataSourceConstant; |
|
|
|
import com.epmet.dataaggre.constant.OrgConstant; |
|
|
|
import com.epmet.dataaggre.dao.govorg.*; |
|
|
|
import com.epmet.dataaggre.dto.datastats.result.SubAgencyProjectResultDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.CustomerStaffResultDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.ListStaffResultDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.StaffRoleListResultDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.StaffSelectResDTO; |
|
|
@ -66,6 +67,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
@ -75,6 +77,7 @@ import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.text.Collator; |
|
|
|
import java.text.NumberFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
@ -1153,17 +1156,12 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
public PageData<OrgProjectDetailResultDTO> orgProjectDetailList(TokenDto tokenDto, OrgStatisticsFormDTO formDTO) { |
|
|
|
List<OrgProjectDetailResultDTO> resultList = new ArrayList<>(); |
|
|
|
if (StringUtils.isBlank(formDTO.getAgencyId())) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
CustomerStaffInfoCacheResult staffInfo = getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
if (null == staffInfo) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取用户信息失败", "获取用户信息失败"); |
|
|
|
} |
|
|
|
formDTO.setAgencyId(staffInfo.getAgencyId()); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(formDTO.getStartDate()) && StringUtils.isEmpty(formDTO.getEndDate())) { |
|
|
|
//当前日期前一天
|
|
|
|
String dateId = DateUtils.format(DateUtils.addDateDays(new Date(), NumConstant.ONE_NEG), DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
formDTO.setEndDate(dateId); |
|
|
|
} |
|
|
|
CustomerAgencyEntity agencyEntity = customerAgencyDao.selectById(formDTO.getAgencyId()); |
|
|
|
if (null == agencyEntity) { |
|
|
|
return new PageData<>(Collections.emptyList(), NumConstant.ZERO); |
|
|
@ -1184,7 +1182,7 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
//统计网格关闭项目数
|
|
|
|
Map<String, Integer> closedMap = govProjectService.getGridClosedProjectMap(formDTO); |
|
|
|
//网格员统计
|
|
|
|
Map<String, Integer> memberMap = dataStatsService.getMemberMap(formDTO.getAgencyId()); |
|
|
|
Map<String, Long> memberMap = getMemberMap(tokenDto.getCustomerId(), formDTO.getAgencyId()); |
|
|
|
resultList = gridList.stream().map(grid -> { |
|
|
|
OrgProjectDetailResultDTO dto = new OrgProjectDetailResultDTO(); |
|
|
|
dto.setOrgId(grid.getId()); |
|
|
@ -1197,9 +1195,11 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
dto.setClosedCount(closedMap.get(grid.getId())); |
|
|
|
} |
|
|
|
if (memberMap.containsKey(grid.getId())) { |
|
|
|
dto.setMemberCount(memberMap.get(grid.getId())); |
|
|
|
dto.setProjectAve(dto.getProjectCount()/memberMap.get(grid.getId())); |
|
|
|
dto.setClosedAve(dto.getClosedCount()/memberMap.get(grid.getId())); |
|
|
|
dto.setMemberCount(Math.toIntExact(memberMap.get(grid.getId()))); |
|
|
|
if (NumConstant.ZERO != dto.getMemberCount()) { |
|
|
|
dto.setProjectAve(dto.getProjectCount() / dto.getMemberCount()); |
|
|
|
dto.setClosedAve(dto.getClosedCount() / dto.getMemberCount()); |
|
|
|
} |
|
|
|
} |
|
|
|
return dto; |
|
|
|
}).collect(Collectors.toList()); |
|
|
@ -1221,7 +1221,10 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
//拼装数据
|
|
|
|
if (CollectionUtils.isNotEmpty(agencyList)) { |
|
|
|
//项目相关统计
|
|
|
|
Map<String, SubAgencyProjectResultDTO> projectMap = dataStatsService.getAgencyProjectTotal(formDTO); |
|
|
|
//统计项目数
|
|
|
|
Map<String, Integer> projectMap = govProjectService.getAgencyProjectMap(formDTO); |
|
|
|
//统计关闭项目数
|
|
|
|
Map<String, Integer> closedMap = govProjectService.getAgencyClosedProjectMap(formDTO); |
|
|
|
//网格员统计
|
|
|
|
Map<String, Integer> memberMap = epmetUserService.getMemberCount(tokenDto.getCustomerId()); |
|
|
|
|
|
|
@ -1230,12 +1233,12 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
dto.setOrgId(agency.getId()); |
|
|
|
dto.setOrgType(OrgConstant.AGENCY); |
|
|
|
dto.setOrgName(agency.getOrganizationName()); |
|
|
|
if (projectMap.containsKey(agency.getId())) { |
|
|
|
dto.setProjectCount(projectMap.get(agency.getId()).getProjectTotal()); |
|
|
|
dto.setClosedCount(projectMap.get(agency.getId()).getClosedProjectTotal()); |
|
|
|
} |
|
|
|
//获取当前组织的所有下级组织ID(包含本级)
|
|
|
|
List<String> agencyIds = customerAgencyDao.getSubAgencyList(agency.getId()); |
|
|
|
int projectCount = agencyIds.stream().filter(projectMap::containsKey).mapToInt(projectMap::get).sum(); |
|
|
|
int closedCount = agencyIds.stream().filter(closedMap::containsKey).mapToInt(closedMap::get).sum(); |
|
|
|
dto.setProjectCount(projectCount); |
|
|
|
dto.setClosedCount(closedCount); |
|
|
|
//将下级组织网格员数加起来
|
|
|
|
int memberCount = agencyIds.stream().filter(memberMap::containsKey).mapToInt(memberMap::get).sum(); |
|
|
|
dto.setMemberCount(memberCount); |
|
|
@ -1268,30 +1271,25 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
@Override |
|
|
|
public PageData<MemberProjectInfoResultDTO> memberProjectInfoList(TokenDto tokenDto, OrgStatisticsFormDTO formDTO) { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
PageData<MemberProjectInfoResultDTO> result; |
|
|
|
if (StringUtils.isBlank(formDTO.getOrgId())) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
CustomerStaffInfoCacheResult staffInfo = getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
if (null == staffInfo) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取用户信息失败", "获取用户信息失败"); |
|
|
|
} |
|
|
|
formDTO.setOrgId(staffInfo.getAgencyId()); |
|
|
|
formDTO.setOrgType(OrgConstant.AGENCY); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(formDTO.getStartDate()) && StringUtils.isEmpty(formDTO.getEndDate())) { |
|
|
|
//当前日期前一天
|
|
|
|
String dateId = DateUtils.format(DateUtils.addDateDays(new Date(), NumConstant.ONE_NEG), DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
formDTO.setEndDate(dateId); |
|
|
|
} |
|
|
|
if (OrgConstant.AGENCY.contains(formDTO.getOrgType())) { |
|
|
|
//获取当前组织的所有下级组织ID(包含本级)
|
|
|
|
List<String> agencyIds = customerAgencyDao.getSubAgencyList(formDTO.getOrgId()); |
|
|
|
formDTO.setAgencyList(agencyIds); |
|
|
|
//获取组织下的网格员
|
|
|
|
result = epmetUserService.getMemberList(formDTO); |
|
|
|
} else { |
|
|
|
//获取网格下的网格员
|
|
|
|
result = dataStatsService.getMemberList(formDTO); |
|
|
|
} |
|
|
|
PageData<MemberProjectInfoResultDTO> result = getGridMemberList(formDTO); |
|
|
|
//if (OrgConstant.AGENCY.contains(formDTO.getOrgType())) {
|
|
|
|
// //获取当前组织的所有下级组织ID(包含本级)
|
|
|
|
// //List<String> agencyIds = customerAgencyDao.getSubAgencyList(formDTO.getOrgId());
|
|
|
|
// //formDTO.setAgencyList(agencyIds);
|
|
|
|
// //获取组织下的网格员
|
|
|
|
// result = epmetUserService.getMemberList(formDTO);
|
|
|
|
//} else {
|
|
|
|
// //获取网格下的网格员
|
|
|
|
// result = dataStatsService.getMemberList(formDTO);
|
|
|
|
//}
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getList())) { |
|
|
|
//统计项目数
|
|
|
|
Map<String, Integer> projectMap = govProjectService.getMemberProjectMap(formDTO); |
|
|
@ -1319,4 +1317,105 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private PageData<MemberProjectInfoResultDTO> getGridMemberList(OrgStatisticsFormDTO formDTO) { |
|
|
|
List<MemberProjectInfoResultDTO> list = new ArrayList<>(); |
|
|
|
List<StaffOrgRelationResultDTO> staffList = customerStaffAgencyDao.getStaffList(formDTO.getOrgId(), formDTO.getOrgType()); |
|
|
|
if (OrgConstant.AGENCY.equals(formDTO.getOrgType())) { |
|
|
|
for (StaffOrgRelationResultDTO staff : staffList) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = getStaffInfo(formDTO.getCustomerId(), staff.getStaffId()); |
|
|
|
if (null != staffInfo) { |
|
|
|
if(staffInfo.getRoleMap().containsKey("grid_member")) { |
|
|
|
MemberProjectInfoResultDTO dto = new MemberProjectInfoResultDTO(); |
|
|
|
dto.setStaffId(staff.getStaffId()); |
|
|
|
dto.setStaffName(staffInfo.getRealName()); |
|
|
|
dto.setOrgId(staff.getOrgId()); |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staff.getOrgId()); |
|
|
|
if (null != agencyInfo) { |
|
|
|
dto.setOrgName(agencyInfo.getOrganizationName()); |
|
|
|
} |
|
|
|
list.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (StaffOrgRelationResultDTO staff : staffList) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = getStaffInfo(formDTO.getCustomerId(), staff.getStaffId()); |
|
|
|
if (null != staffInfo) { |
|
|
|
if(staffInfo.getRoleMap().containsKey("grid_member")) { |
|
|
|
MemberProjectInfoResultDTO dto = new MemberProjectInfoResultDTO(); |
|
|
|
dto.setStaffId(staff.getStaffId()); |
|
|
|
dto.setStaffName(staffInfo.getRealName()); |
|
|
|
dto.setOrgId(staff.getOrgId()); |
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(staff.getOrgId()); |
|
|
|
if (null != gridInfo) { |
|
|
|
dto.setOrgName(gridInfo.getGridName()); |
|
|
|
} |
|
|
|
list.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
int num = (formDTO.getPageNo() - NumConstant.ONE) * formDTO.getPageSize(); |
|
|
|
PageInfo<MemberProjectInfoResultDTO> pageInfo = new PageInfo<>(list); |
|
|
|
list = list.stream().sorted((o1, o2) -> |
|
|
|
Collator.getInstance(Locale.SIMPLIFIED_CHINESE) |
|
|
|
.compare(o1.getStaffName(),o2.getStaffName())).collect(Collectors.toList()); |
|
|
|
list = list.stream().skip(num).limit(formDTO.getPageSize()).collect(Collectors.toList()); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, Long> getMemberMap(String customerId, String agencyId) { |
|
|
|
List<GridStaffResultDTO> list = customerStaffGridDao.getGridStaffByAgency(agencyId); |
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
return Collections.emptyMap(); |
|
|
|
} |
|
|
|
list = list.stream().filter(item -> { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = getStaffInfo(customerId, item.getStaffId()); |
|
|
|
if (null != staffInfo) { |
|
|
|
if (staffInfo.getRoleMap().containsKey("grid_member")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
return list.stream().collect(Collectors.groupingBy(GridStaffResultDTO::getGridId, Collectors.counting())); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CustomerStaffInfoCacheResult getStaffInfo(String customerId, String staffId) { |
|
|
|
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(staffId)){ |
|
|
|
log.warn("getStaffInfo param is blank,customerId:{},staffId:{}",customerId,staffId); |
|
|
|
return null; |
|
|
|
} |
|
|
|
String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId); |
|
|
|
Map<String, Object> roleMap = redisUtils.hGetAll(key); |
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(roleMap)) { |
|
|
|
return ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCacheResult.class); |
|
|
|
} |
|
|
|
|
|
|
|
CustomerStaffInfoCache resultData = reloadStaffCache(staffId, key); |
|
|
|
if (resultData == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(resultData, CustomerStaffInfoCacheResult.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Nullable |
|
|
|
private CustomerStaffInfoCache reloadStaffCache(String staffId, String key) { |
|
|
|
CustomerStaffResultDTO staffResult = epmetUserService.getStaffInfo(staffId); |
|
|
|
if (staffResult == null) { |
|
|
|
log.warn("getStaffInfo staff is null,staffId:{}", staffId); |
|
|
|
return null; |
|
|
|
} |
|
|
|
CustomerStaffInfoCache resultData =ConvertUtils.sourceToTarget(staffResult, CustomerStaffInfoCache.class); |
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(resultData, false, true); |
|
|
|
redisUtils.hMSet(key, map); |
|
|
|
return resultData; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|