@ -17,13 +17,11 @@
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 ;
import com.epmet.commons.tools.constant.AppClientConstant ;
import com.epmet.commons.tools.constant.Constant ;
import com.epmet.commons.tools.constant.FieldConstant ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.* ;
import com.epmet.commons.tools.exception.EpmetErrorCode ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.page.PageData ;
@ -37,24 +35,27 @@ import com.epmet.constant.ParameterKeyConstant;
import com.epmet.constant.ProjectConstant ;
import com.epmet.constant.UserMessageConstant ;
import com.epmet.dao.ProjectDao ;
import com.epmet.dao.ProjectOrgRelationDao ;
import com.epmet.dto.* ;
import com.epmet.dto.form.* ;
import com.epmet.dto.result.* ;
import com.epmet.entity.ProjectEntity ;
import com.epmet.entity.ProjectProcessEntity ;
import com.epmet.entity.ProjectRelatedPersonnelEntity ;
import com.epmet.entity.ProjectStaffEntity ;
import com.epmet.entity.* ;
import com.epmet.feign.* ;
import com.epmet.redis.ProjectRedis ;
import com.epmet.service.* ;
import org.apache.commons.collections4.CollectionUtils ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.ListUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.text.SimpleDateFormat ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
/ * *
@ -64,6 +65,7 @@ import java.util.stream.Collectors;
* @since v1 . 0 . 0 2020 - 05 - 11
* /
@Service
@Slf4j
public class ProjectServiceImpl extends BaseServiceImpl < ProjectDao , ProjectEntity > implements ProjectService {
@Autowired
@ -90,6 +92,8 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
private String scanApiUrl ;
@Value ( "${openapi.scan.method.textSyncScan}" )
private String textSyncScanMethod ;
@Autowired
private ProjectOrgRelationDao relationDao ;
private final static String ONE_DAY = "<1" ;
@ -358,6 +362,8 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
if ( ProjectConstant . CLOSED . equals ( projectEntity . getStatus ( ) ) ) {
throw new RenException ( EpmetErrorCode . PROJECT_IS_CLOSED . getCode ( ) ) ;
}
Date current = new Date ( ) ;
projectEntity . setStatus ( ProjectConstant . CLOSED ) ;
projectEntity . setClosedStatus ( fromDTO . getClosedStatus ( ) ) ;
baseDao . updateById ( projectEntity ) ;
@ -367,19 +373,66 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
projectStaffEntity . setIsHandle ( ProjectConstant . HANDLE ) ;
projectStaffService . updateById ( projectStaffEntity ) ;
//查询结案人员的信息
ProjectStaffEntity operatorProjectReference = projectStaffService . selectById ( fromDTO . getProjectStaffId ( ) ) ;
if ( null = = operatorProjectReference ) {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.closed,找不到结案工作人员的相关记录,参数:{}" , JSON . toJSONString ( fromDTO ) ) ;
throw new RenException ( "找不到结案工作人员的相关记录" ) ;
}
//结案记录加入项目进展表
ProjectProcessEntity projectProcessEntity = new ProjectProcessEntity ( ) ;
projectProcessEntity . setProjectId ( fromDTO . getProjectId ( ) ) ;
projectProcessEntity . setCustomerId ( operatorProjectReference . getCustomerId ( ) ) ;
projectProcessEntity . setDepartmentName ( fromDTO . getDepartmentName ( ) ) ;
projectProcessEntity . setAgencyId ( operatorProjectReference . getOrgId ( ) ) ;
projectProcessEntity . setGridId ( operatorProjectReference . getGridId ( ) ) ;
projectProcessEntity . setDepartmentId ( operatorProjectReference . getDepartmentId ( ) ) ;
projectProcessEntity . setOrgIdPath ( operatorProjectReference . getOrgIdPath ( ) ) ;
projectProcessEntity . setEndTime ( new Date ( ) ) ;
projectProcessEntity . setOperation ( ProjectConstant . OPERATION_CLOSE ) ;
projectProcessEntity . setOperationName ( ProjectConstant . OPERATION_CLOSE_NAME ) ;
projectProcessEntity . setPublicReply ( fromDTO . getPublicReply ( ) ) ;
projectProcessEntity . setInternalRemark ( fromDTO . getInternalRemark ( ) ) ;
projectProcessEntity . setStaffId ( fromDTO . getUserId ( ) ) ;
projectProcessEntity . setCostWorkdays ( getDetentionDays ( ConvertUtils . sourceToTarget ( projectEntity , ProjectDTO . class ) ) ) ;
ProjectDTO projectDto = ConvertUtils . sourceToTarget ( projectEntity , ProjectDTO . class ) ;
projectDto . setUpdatedTime ( projectDto . getCreatedTime ( ) ) ;
projectProcessEntity . setCostWorkdays ( getDetentionDays ( projectDto ) ) ;
projectProcessService . insert ( projectProcessEntity ) ;
//对项目节点耗时记录进行更新,更新全部未处理节点以及结案人的节点耗时
//List<ProjectOrgRelationEntity> periodsToUpdate = relationDao.selectAllUnhandledProcess(fromDTO.getProjectId());
//if(CollectionUtils.isEmpty(periodsToUpdate)){
// log.error("com.epmet.service.impl.ProjectServiceImpl.closed,至少存在一条处理时间为空的项目节点耗时记录,但是没有找到,参数:{}",JSON.toJSONString(fromDTO));
// throw new RenException("至少存在一条处理时间为空的项目节点耗时记录,但是没有找到");
//}
//List<TimestampIntervalFormDTO> intervalList = new LinkedList<>();
//periodsToUpdate.forEach(local -> {
// TimestampIntervalFormDTO obj = new TimestampIntervalFormDTO();
// obj.setId(local.getProjectStaffId());
// obj.setLeft(local.getInformedDate());
// obj.setRight(current);
// intervalList.add(obj);
//});
ProjectOrgRelationEntity orientRelation = relationDao . selectByProjectStaffId ( operatorProjectReference . getId ( ) ) ;
if ( null = = orientRelation ) {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.closed,找不到结案工作人员的节点耗时相关记录,参数:{}" , JSON . toJSONString ( fromDTO ) ) ;
throw new RenException ( "找不到结案工作人员的节点耗时相关记录" ) ;
}
Integer delta_t = calculateDelta_T ( ProjectConstant . IMPRECISE_CALCULATION ,
ProjectConstant . CALCULATION_TYPE_DEFAULT , operatorProjectReference . getId ( ) , orientRelation . getInformedDate ( ) , current ) ;
ProjectOrgRelationEntity carrier = new ProjectOrgRelationEntity ( ) ;
carrier . setProjectStaffId ( operatorProjectReference . getId ( ) ) ;
carrier . setOperation ( ProjectConstant . OPERATION_CLOSE ) ;
carrier . setHandledDate ( current ) ;
carrier . setFirstReplyPeriod ( delta_t ) ;
relationDao . maintainTimePropertyConsistency ( carrier ) ;
//通知
List < UserMessageFormDTO > msgList = new ArrayList < > ( ) ;
//通知项目相关人员
@ -437,16 +490,30 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
throw new RenException ( EpmetErrorCode . PROJECT_IS_CLOSED . getCode ( ) ) ;
}
Date current = new Date ( ) ;
//更新项目关联表
ProjectStaffEntity projectStaffEntity = new ProjectStaffEntity ( ) ;
projectStaffEntity . setId ( fromDTO . getProjectStaffId ( ) ) ;
projectStaffEntity . setIsHandle ( ProjectConstant . HANDLE ) ;
projectStaffService . updateById ( projectStaffEntity ) ;
//查找对应的project_staff的信息,为了取出机关的信息,给即将要生成的“退回”节点赋值
ProjectStaffEntity sourceProjectStaff = projectStaffService . selectById ( fromDTO . getProjectStaffId ( ) ) ;
if ( null = = sourceProjectStaff ) {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.projectReturn,找不到发起退回的项目相关人员的记录,参数:{}" , JSON . toJSONString ( fromDTO ) ) ;
throw new RenException ( "找不到发起退回的项目相关人员的记录" ) ;
}
//结案记录加入项目进展表
ProjectProcessEntity projectProcessEntity = new ProjectProcessEntity ( ) ;
projectProcessEntity . setProjectId ( fromDTO . getProjectId ( ) ) ;
projectProcessEntity . setCustomerId ( sourceProjectStaff . getCustomerId ( ) ) ;
projectProcessEntity . setDepartmentName ( fromDTO . getDepartmentName ( ) ) ;
projectProcessEntity . setOrgIdPath ( sourceProjectStaff . getOrgIdPath ( ) ) ;
projectProcessEntity . setGridId ( sourceProjectStaff . getGridId ( ) ) ;
projectProcessEntity . setDepartmentId ( sourceProjectStaff . getDepartmentId ( ) ) ;
projectProcessEntity . setAgencyId ( sourceProjectStaff . getOrgId ( ) ) ;
projectProcessEntity . setOperation ( ProjectConstant . OPERATION_RETURN ) ;
projectProcessEntity . setOperationName ( ProjectConstant . OPERATION_RETURN_NAME ) ;
projectProcessEntity . setPublicReply ( fromDTO . getPublicReply ( ) ) ;
@ -459,12 +526,41 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
ProjectStaffEntity projectStaff = ConvertUtils . sourceToTarget ( projectStaffDTO , ProjectStaffEntity . class ) ;
projectStaff . setId ( null ) ;
//防止将被退回的项目相关人员节点的创建时间赋值给新增的相关人员节点的创建时间,否则数据统计将出现误差
projectStaff . setCreatedTime ( null ) ;
projectStaff . setUpdatedTime ( null ) ;
projectStaff . setCreatedTime ( current ) ;
projectStaff . setUpdatedTime ( current ) ;
projectStaff . setProcessId ( projectProcessEntity . getId ( ) ) ;
projectStaff . setIsHandle ( ProjectConstant . UNHANDLED ) ;
projectStaffService . insert ( projectStaff ) ;
//更新退回发起人的节点耗时记录
ProjectOrgRelationEntity orientRelation = relationDao . selectByProjectStaffId ( fromDTO . getProjectStaffId ( ) ) ;
if ( null = = orientRelation ) {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.projectReturn,找不到发起退回的项目相关人员的节点耗时记录,参数:{}" , JSON . toJSONString ( fromDTO ) ) ;
throw new RenException ( "找不到发起退回的项目相关人员的节点耗时记录" ) ;
}
ProjectOrgRelationEntity relationDto = new ProjectOrgRelationEntity ( ) ;
relationDto . setProjectStaffId ( orientRelation . getProjectStaffId ( ) ) ;
relationDto . setHandledDate ( current ) ;
Integer costTime = calculateDelta_T ( ProjectConstant . IMPRECISE_CALCULATION ,
ProjectConstant . CALCULATION_TYPE_DEFAULT ,
orientRelation . getProjectStaffId ( ) ,
orientRelation . getInformedDate ( ) ,
current ) ;
relationDto . setTotalPeriod ( costTime ) ;
relationDto . setOperation ( ProjectConstant . OPERATION_RETURN ) ;
if ( null = = orientRelation . getFirstDealtDate ( ) ) {
relationDto . setFirstDealtDate ( current ) ;
relationDto . setFirstReplyPeriod ( costTime ) ;
}
relationDao . maintainTimePropertyConsistency ( relationDto ) ;
//初始化被退回人的节点耗时记录
ProjectOrgRelationEntity newRelation = new ProjectOrgRelationEntity ( ) ;
newRelation . setProjectStaffId ( projectStaff . getId ( ) ) ;
newRelation . setSourceOperation ( ProjectConstant . OPERATION_RETURN ) ;
newRelation . setInformedDate ( current ) ;
relationDao . insert ( newRelation ) ;
//通知
List < UserMessageFormDTO > msgList = new ArrayList < > ( ) ;
UserMessageFormDTO messageFormDTO = new UserMessageFormDTO ( ) ;
@ -593,6 +689,7 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
//3:项目处理进展表新增数据
ProjectProcessEntity processEntity = new ProjectProcessEntity ( ) ;
processEntity . setProjectId ( projectEntity . getId ( ) ) ;
processEntity . setCustomerId ( issueDTO . getCustomerId ( ) ) ;
processEntity . setStaffId ( formDTO . getStaffId ( ) ) ;
processEntity . setOperation ( ProjectConstant . OPERATION_CREATED ) ;
processEntity . setOperationName ( ProjectConstant . OPERATION_CREATED_NAME ) ;
@ -601,11 +698,18 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
agencyDeptGrid . getAgencyList ( ) . forEach ( agency - > {
if ( issueDTO . getOrgId ( ) . equals ( agency . getId ( ) ) ) {
processEntity . setDepartmentName ( agency . getOrganizationName ( ) ) ;
processEntity . setAgencyId ( agency . getId ( ) ) ;
if ( StringUtils . isBlank ( agency . getPids ( ) ) | | StringUtils . equals ( NumConstant . ZERO_STR , agency . getPids ( ) . trim ( ) ) | | "" . equals ( agency . getPids ( ) . trim ( ) ) ) {
processEntity . setOrgIdPath ( agency . getId ( ) ) ;
} else {
processEntity . setOrgIdPath ( agency . getPids ( ) . concat ( ":" ) . concat ( agency . getId ( ) ) ) ;
}
}
} ) ;
agencyDeptGrid . getGridList ( ) . forEach ( grid - > {
if ( issueDTO . getGridId ( ) . equals ( grid . getId ( ) ) ) {
processEntity . setDepartmentName ( processEntity . getDepartmentName ( ) + "-" + grid . getGridName ( ) ) ;
processEntity . setGridId ( grid . getId ( ) ) ;
}
} ) ;
projectProcessService . insert ( processEntity ) ;
@ -643,6 +747,24 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
} ) ;
projectStaffService . insertBatch ( entityList ) ;
//7:初始化机关-项目时间关联数据
Date current = new Date ( ) ;
List < String > projectStaffIds = entityList . stream ( ) . map ( ProjectStaffEntity : : getId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( ! CollectionUtils . isEmpty ( projectStaffIds ) ) {
List < ProjectOrgRelationEntity > container = new LinkedList < > ( ) ;
projectStaffIds . forEach ( o - > {
ProjectOrgRelationEntity period = new ProjectOrgRelationEntity ( ) ;
period . setProjectStaffId ( o ) ;
period . setInformedDate ( current ) ;
//created
period . setSourceOperation ( ProjectConstant . OPERATION_CREATED ) ;
period . setCreatedBy ( formDTO . getStaffId ( ) ) ;
container . add ( period ) ;
} ) ;
relationDao . insertBatch ( container ) ;
}
//5:项目相关人员表初始数据
List < ProjectRelatedPersonnelEntity > list = new ArrayList < > ( ) ;
ProjectRelatedPersonnelEntity entity1 = new ProjectRelatedPersonnelEntity ( ) ;
@ -660,6 +782,8 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
issueProjectResultDTO . setProjectId ( projectEntity . getId ( ) ) ;
issueProjectResultDTO . setOrgName ( processEntity . getDepartmentName ( ) ) ;
issueProjectResultDTO . setShiftedTime ( projectEntity . getCreatedTime ( ) ) ;
return issueProjectResultDTO ;
}
@ -671,7 +795,6 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
* * /
@Override
public List < LatestListResultDTO > getClosedProjectList ( LatestListFormDTO formDTO ) {
return baseDao . selectClosedProjectList ( formDTO ) ;
}
@ -699,17 +822,390 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
if ( ProjectConstant . CLOSED . equals ( projectEntity . getStatus ( ) ) ) {
throw new RenException ( EpmetErrorCode . PROJECT_IS_CLOSED . getCode ( ) ) ;
}
ProjectStaffDTO projectStaff = projectStaffService . getLatestIdByProjectIdAndStaffId ( formDTO . getProjectId ( ) , formDTO . getUserId ( ) ) ;
if ( null = = projectStaff ) {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.response,project_staff表中没有与之对应的数据,传参:{}" , JSON . toJSONString ( formDTO ) ) ;
throw new RenException ( "未找到项目相关人员记录" ) ;
}
if ( StringUtils . isBlank ( formDTO . getProjectStaffId ( ) ) ) {
formDTO . setProjectStaffId ( projectStaff . getId ( ) ) ;
}
//处理响应记录加入项目进展表
ProjectProcessEntity projectProcessEntity = new ProjectProcessEntity ( ) ;
projectProcessEntity . setProjectId ( formDTO . getProjectId ( ) ) ;
projectEntity . setCustomerId ( projectStaff . getCustomerId ( ) ) ;
projectProcessEntity . setDepartmentName ( formDTO . getDepartmentName ( ) ) ;
projectProcessEntity . setOrgIdPath ( projectStaff . getOrgIdPath ( ) ) ;
projectProcessEntity . setGridId ( projectStaff . getGridId ( ) ) ;
projectProcessEntity . setDepartmentId ( projectStaff . getDepartmentId ( ) ) ;
projectProcessEntity . setAgencyId ( projectStaff . getOrgId ( ) ) ;
projectProcessEntity . setOperation ( ProjectConstant . OPERATION_RESPONSES ) ;
projectProcessEntity . setOperationName ( ProjectConstant . OPERATION_RESPONSES_NAME ) ;
projectProcessEntity . setPublicReply ( formDTO . getPublicReply ( ) ) ;
projectProcessEntity . setInternalRemark ( formDTO . getInternalRemark ( ) ) ;
projectProcessEntity . setStaffId ( formDTO . getUserId ( ) ) ;
projectProcessService . insert ( projectProcessEntity ) ;
//项目节点历时
ProjectOrgRelationEntity relationEntity = relationDao . selectByProjectStaffId ( formDTO . getProjectStaffId ( ) ) ;
if ( null ! = relationEntity ) {
ProjectOrgRelationEntity relationDto = new ProjectOrgRelationEntity ( ) ;
relationDto . setProjectStaffId ( relationEntity . getProjectStaffId ( ) ) ;
if ( null = = relationEntity . getFirstDealtDate ( ) ) {
Date current = new Date ( ) ;
relationDto . setFirstDealtDate ( current ) ;
relationDto . setFirstReplyPeriod ( calculateDelta_T ( ProjectConstant . IMPRECISE_CALCULATION ,
ProjectConstant . CALCULATION_TYPE_DEFAULT , projectStaff . getId ( ) ,
relationEntity . getInformedDate ( ) , current ) ) ;
relationDto . setOperation ( ProjectConstant . OPERATION_RESPONSES ) ;
relationDao . maintainTimePropertyConsistency ( relationDto ) ;
}
} else {
log . error ( "com.epmet.service.impl.ProjectServiceImpl#response,没有找到相关的节点耗时记录,参数:{}" , JSON . toJSONString ( formDTO ) ) ;
throw new RenException ( "没有找到相关的节点耗时记录" ) ;
}
}
private Integer calculateDelta_T ( String ifPrecise , String ifCustom , String identity , Date left , Date right ) {
WorkMinuteFormDTO timeParam = new WorkMinuteFormDTO ( ) ;
timeParam . setIfPrecise ( ifPrecise ) ;
timeParam . setIfCustom ( ifCustom ) ;
TimestampIntervalFormDTO interval = new TimestampIntervalFormDTO ( identity , left , right ) ;
List < TimestampIntervalFormDTO > intervalList = new LinkedList < > ( ) ; intervalList . add ( interval ) ;
timeParam . setTimeList ( intervalList ) ;
Result < Map < String , Integer > > timeResult = epmetCommonServiceOpenFeignClient . workMinutes ( timeParam ) ;
if ( timeResult . success ( ) & & ! org . springframework . util . CollectionUtils . isEmpty ( timeResult . getData ( ) ) & & null ! = timeResult . getData ( ) . get ( identity ) ) {
return timeResult . getData ( ) . get ( identity ) ;
} else {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.response,计算首次响应时间失败" ) ;
throw new RenException ( "计算首次响应时间失败" ) ;
}
}
private Map < String , Integer > batchCalculateDelta_T ( String ifPrecise , String ifCustom , List < TimestampIntervalFormDTO > intervalList ) {
WorkMinuteFormDTO timeParam = new WorkMinuteFormDTO ( ) ;
timeParam . setIfPrecise ( ifPrecise ) ;
timeParam . setIfCustom ( ifCustom ) ;
timeParam . setTimeList ( intervalList ) ;
Result < Map < String , Integer > > timeResult = epmetCommonServiceOpenFeignClient . workMinutes ( timeParam ) ;
if ( timeResult . success ( ) & & ! org . springframework . util . CollectionUtils . isEmpty ( timeResult . getData ( ) ) ) {
return timeResult . getData ( ) ;
} else {
log . error ( "com.epmet.service.impl.ProjectServiceImpl.response,计算首次响应时间失败" ) ;
throw new RenException ( "计算首次响应时间失败" ) ;
}
}
/ * *
* 项目滞留超期提醒
*
* @param customerId
* @return void
* @author zhaoqifeng
* @date 2020 / 10 / 21 15 : 21
* /
@Override
public void sendMessage ( String customerId ) {
List < CustomerProjectParameterDTO > paramList = parameterService . getParameterByCustomer ( customerId ) ;
//可滞留天数
int detentionDays = 5 ;
//计算方式
String calculation = ParameterKeyConstant . WORK ;
//即将超期提醒时间
int remindTime = 0 ;
//推送时间
String pushTime = "08:00" ;
if ( CollectionUtils . isNotEmpty ( paramList ) ) {
for ( CustomerProjectParameterDTO dto : paramList ) {
if ( ParameterKeyConstant . DETENTION_DAYS . equals ( dto . getParameterKey ( ) ) ) {
detentionDays = Integer . parseInt ( dto . getParameterValue ( ) ) ;
} else if ( ParameterKeyConstant . CALCULATION . equals ( dto . getParameterKey ( ) ) ) {
calculation = dto . getParameterValue ( ) ;
} else if ( ParameterKeyConstant . REMIND_TIME . equals ( dto . getParameterKey ( ) ) ) {
remindTime = Integer . parseInt ( dto . getParameterValue ( ) ) ;
} else if ( ParameterKeyConstant . PUSH_TIME . equals ( dto . getParameterKey ( ) ) ) {
pushTime = dto . getParameterValue ( ) ;
}
}
}
//获取工作人员未处理的节点
List < StaffUnHandledDTO > unHandledList = projectStaffService . getStaffUnHandledList ( customerId ) ;
List < CostDayFormDTO > form = unHandledList . stream ( ) . map ( item - > {
CostDayFormDTO dto = new CostDayFormDTO ( ) ;
dto . setId ( item . getId ( ) ) ;
dto . setStaffId ( item . getStaffId ( ) ) ;
if ( null ! = item . getUpdatedTime ( ) ) {
dto . setStartDate ( item . getUpdatedTime ( ) ) ;
} else {
dto . setStartDate ( item . getCreatedTime ( ) ) ;
}
dto . setEndDate ( new Date ( ) ) ;
return dto ;
} ) . collect ( Collectors . toList ( ) ) ;
List < CostDayResultDTO > costDayList ;
if ( ParameterKeyConstant . WORK . equals ( calculation ) ) {
//工作日计算
Result < List < CostDayResultDTO > > result = epmetCommonServiceOpenFeignClient . costWorkDays ( form ) ;
if ( ! result . success ( ) ) {
throw new RenException ( result . getCode ( ) , result . getMsg ( ) ) ;
}
costDayList = result . getData ( ) ;
} else {
//日历日计算
Result < List < CostDayResultDTO > > result = epmetCommonServiceOpenFeignClient . costCalendarDays ( form ) ;
if ( ! result . success ( ) ) {
throw new RenException ( result . getCode ( ) , result . getMsg ( ) ) ;
}
costDayList = result . getData ( ) ;
}
//即将超期项目
List < StaffUnHandledDTO > overdueList = new ArrayList < > ( ) ;
//滞留项目
List < StaffUnHandledDTO > delayList = new ArrayList < > ( ) ;
List < CostDayResultDTO > finalCostDayList = costDayList ;
List < OverdueAndDelayDTO > list = new ArrayList < > ( ) ;
int finalDetentionDays = detentionDays ;
int finalRemindTime = remindTime ;
unHandledList . forEach ( unHandle - > finalCostDayList . stream ( ) . filter ( cost - >
unHandle . getId ( ) . equals ( cost . getId ( ) ) ) . forEach ( item - > {
int diff = finalDetentionDays - item . getDetentionDays ( ) ;
OverdueAndDelayDTO dto = new OverdueAndDelayDTO ( ) ;
if ( diff < 0 ) {
dto . setStaffId ( unHandle . getStaffId ( ) ) ;
list . add ( dto ) ;
delayList . add ( unHandle ) ;
} else if ( diff < = finalRemindTime ) {
dto . setStaffId ( unHandle . getStaffId ( ) ) ;
overdueList . add ( unHandle ) ;
list . add ( dto ) ;
}
} ) ) ;
if ( CollectionUtils . isNotEmpty ( list ) ) {
setMessage ( customerId , overdueList , delayList , list ) ;
}
}
/ * *
* @Description 项目节点耗时数据补齐
* @param
* @return void
* @author wangc
* @date 2020 . 10 . 26 10 : 54
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public void projectProcessCostTimeDataCompensation ( ) {
List < String > customers = baseDao . selectAllCustomerIds ( ) ;
if ( CollectionUtils . isEmpty ( customers ) ) return ;
List < ProjectOrgRelationDTO > totalContainer = new LinkedList < > ( ) ;
customers . forEach ( customerId - > {
List < ProjectOrgPeriodResultDTO > projectNodePeriodPerOrgList = projectStaffService . selectProjectOrgPeriod ( customerId ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( projectNodePeriodPerOrgList ) ) {
Map < String , List < ProjectOrgPeriodResultDTO > > projectMap
= projectNodePeriodPerOrgList . stream ( ) . collect ( Collectors . groupingBy ( ProjectOrgPeriodResultDTO : : getProjectId ) ) ;
List < String > projects =
projectNodePeriodPerOrgList . stream ( ) . map ( ProjectOrgPeriodResultDTO : : getProjectId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( ! projects . isEmpty ( ) ) {
List < ProjectOrgRelationWhenResponseResultDTO > responseList = projectProcessService . selectResponseTrace ( projects ) ;
Map < String , List < ProjectOrgRelationWhenResponseResultDTO > > sorted =
responseList . stream ( ) . collect ( Collectors . groupingBy ( ProjectOrgRelationWhenResponseResultDTO : : getProjectId ) ) ;
skipLevelGrouping ( projectMap , sorted ) ;
List < ProjectOrgPeriodResultDTO > calculatedData = new LinkedList < > ( ) ;
projectMap . values ( ) . forEach ( list - > { list . forEach ( obj - > { calculatedData . add ( obj ) ; } ) ; } ) ;
if ( ! org . apache . commons . collections4 . CollectionUtils . isEmpty ( calculatedData ) ) {
List < ProjectOrgRelationDTO > formatted = calculatedData . stream ( ) . map ( period - > {
ProjectOrgRelationDTO relation = ConvertUtils . sourceToTarget ( period , ProjectOrgRelationDTO . class ) ;
relation . setFirstDealtDate ( period . getPeriodTillReplyFirstly ( ) ) ;
relation . setSourceOperation ( period . getLastAction ( ) ) ;
return relation ;
} ) . collect ( Collectors . toList ( ) ) ;
totalContainer . addAll ( formatted ) ;
}
}
}
} ) ;
if ( ! CollectionUtils . isEmpty ( totalContainer ) ) {
List < String > identities = totalContainer . stream ( ) . map ( ProjectOrgRelationDTO : : getProjectStaffId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
ListUtils . partition ( identities , NumConstant . ONE_THOUSAND ) . forEach ( partition - > { relationDao . deleteBatch ( partition ) ; } ) ;
List < TimestampIntervalFormDTO > timeInterval = totalContainer . stream ( ) . map ( relation - > {
TimestampIntervalFormDTO interval = new TimestampIntervalFormDTO ( ) ;
interval . setId ( relation . getProjectStaffId ( ) ) ;
interval . setLeft ( relation . getInformedDate ( ) ) ;
interval . setRight ( relation . getHandledDate ( ) ) ;
return interval ;
} ) . collect ( Collectors . toList ( ) ) ;
Map < String , Integer > batchDelta_T = batchCalculateDelta_T ( ProjectConstant . IMPRECISE_CALCULATION ,
ProjectConstant . CALCULATION_TYPE_DEFAULT , timeInterval ) ;
Map < String , ProjectOrgRelationDTO > dataMap =
totalContainer . stream ( ) . collect ( Collectors . toMap ( ProjectOrgRelationDTO : : getProjectStaffId , Function . identity ( ) , ( key1 , key2 ) - > key2 ) ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( batchDelta_T ) & &
! org . springframework . util . CollectionUtils . isEmpty ( dataMap ) ) {
dataMap . forEach ( ( k , v ) - > {
if ( null ! = v ) {
v . setTotalPeriod ( batchDelta_T . get ( k ) ) ;
}
} ) ;
List < List < ProjectOrgRelationDTO > > partition = ListUtils . partition ( totalContainer , NumConstant . ONE_HUNDRED ) ;
partition . forEach ( subList - > { relationDao . batchInsertProjectOrgRelation ( subList ) ; } ) ;
}
}
}
private void setMessage ( String customerId , List < StaffUnHandledDTO > overdueList , List < StaffUnHandledDTO > delayList , List < OverdueAndDelayDTO > list ) {
list = list . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
Map < String , List < StaffUnHandledDTO > > overdueMap = overdueList . stream ( ) . collect ( Collectors . groupingBy ( StaffUnHandledDTO : : getStaffId ) ) ;
Map < String , List < StaffUnHandledDTO > > delayMap = delayList . stream ( ) . collect ( Collectors . groupingBy ( StaffUnHandledDTO : : getStaffId ) ) ;
List < OverdueAndDelayDTO > overdue = overdueMap . entrySet ( ) . stream ( ) . map ( item - > {
OverdueAndDelayDTO dto = new OverdueAndDelayDTO ( ) ;
dto . setStaffId ( item . getKey ( ) ) ;
dto . setOverdueList ( item . getValue ( ) ) ;
return dto ;
} ) . collect ( Collectors . toList ( ) ) ;
List < OverdueAndDelayDTO > delay = delayMap . entrySet ( ) . stream ( ) . map ( item - > {
OverdueAndDelayDTO dto = new OverdueAndDelayDTO ( ) ;
dto . setStaffId ( item . getKey ( ) ) ;
dto . setDelayList ( item . getValue ( ) ) ;
return dto ;
} ) . collect ( Collectors . toList ( ) ) ;
list . forEach ( dto - > overdue . forEach ( item - > {
if ( dto . getStaffId ( ) . equals ( item . getStaffId ( ) ) ) {
dto . setOverdueList ( item . getOverdueList ( ) ) ;
}
} ) ) ;
list . forEach ( dto - > delay . forEach ( item - > {
if ( dto . getStaffId ( ) . equals ( item . getStaffId ( ) ) ) {
dto . setDelayList ( item . getDelayList ( ) ) ;
}
} ) ) ;
//通知
List < UserMessageFormDTO > msgList = new ArrayList < > ( ) ;
list . forEach ( dto - > {
String title ;
String msg ;
if ( CollectionUtils . isNotEmpty ( dto . getOverdueList ( ) ) & & CollectionUtils . isNotEmpty ( dto . getDelayList ( ) ) ) {
title = String . format ( UserMessageConstant . STAY_REMINDER_TITLE_1 , dto . getOverdueList ( ) . size ( ) , dto . getDelayList ( ) . size ( ) ) ;
StringBuilder overdueMsg = new StringBuilder ( ) ;
StringBuilder delayMsg = new StringBuilder ( ) ;
for ( int i = 0 ; i < dto . getOverdueList ( ) . size ( ) ; i + + ) {
overdueMsg . append ( i + 1 ) . append ( StrConstant . COMMA_ZH ) . append ( dto . getOverdueList ( ) . get ( i ) . getTitle ( ) ) . append ( "\n" ) ;
}
for ( int i = 0 ; i < dto . getDelayList ( ) . size ( ) ; i + + ) {
delayMsg . append ( i + 1 ) . append ( StrConstant . COMMA_ZH ) . append ( dto . getDelayList ( ) . get ( i ) . getTitle ( ) ) . append ( "\n" ) ;
}
msg = String . format ( UserMessageConstant . STAY_REMINDER_MSG_1 , overdueMsg . toString ( ) , delayMsg . toString ( ) ) ;
} else if ( CollectionUtils . isNotEmpty ( dto . getOverdueList ( ) ) & & CollectionUtils . isEmpty ( dto . getDelayList ( ) ) ) {
title = String . format ( UserMessageConstant . STAY_REMINDER_TITLE_2 , dto . getOverdueList ( ) . size ( ) ) ;
StringBuilder overdueMsg = new StringBuilder ( ) ;
for ( int i = 0 ; i < dto . getOverdueList ( ) . size ( ) ; i + + ) {
overdueMsg . append ( i + 1 ) . append ( StrConstant . COMMA_ZH ) . append ( dto . getOverdueList ( ) . get ( i ) . getTitle ( ) ) . append ( "\n" ) ;
}
msg = String . format ( UserMessageConstant . STAY_REMINDER_MSG_2 , overdueMsg . toString ( ) ) ;
} else {
title = String . format ( UserMessageConstant . STAY_REMINDER_TITLE_3 , dto . getDelayList ( ) . size ( ) ) ;
StringBuilder delayMsg = new StringBuilder ( ) ;
for ( int i = 0 ; i < dto . getDelayList ( ) . size ( ) ; i + + ) {
delayMsg . append ( i + 1 ) . append ( StrConstant . COMMA_ZH ) . append ( dto . getDelayList ( ) . get ( i ) . getTitle ( ) ) . append ( "\n" ) ;
}
msg = String . format ( UserMessageConstant . STAY_REMINDER_MSG_3 , delayMsg . toString ( ) ) ;
}
UserMessageFormDTO messageFormDTO = new UserMessageFormDTO ( ) ;
messageFormDTO . setCustomerId ( customerId ) ;
messageFormDTO . setApp ( ProjectConstant . GOV ) ;
messageFormDTO . setGridId ( StrConstant . STAR ) ;
messageFormDTO . setUserId ( dto . getStaffId ( ) ) ;
messageFormDTO . setTitle ( title ) ;
messageFormDTO . setMessageContent ( msg ) ;
messageFormDTO . setReadFlag ( Constant . UNREAD ) ;
msgList . add ( messageFormDTO ) ;
} ) ;
System . out . println ( msgList ) ;
messageFeignClient . saveUserMessageList ( msgList ) ;
}
/ * *
* @Description 跨级分组 eg - > transfer ; response response transfer ; return ; response close .
* @param dest - Map < String , List < ProjectOrgPeriodResultDTO > > 需要填充的数据 projectMap
* @param fillFactor - Map < String , List < ProjectOrgRelationWhenResponseResultDTO > > 填充因子
* @return
* @author wangc
* @date 2020 . 09 . 18 15 : 27
* * /
private void skipLevelGrouping ( Map < String , List < ProjectOrgPeriodResultDTO > > dest , Map < String , List < ProjectOrgRelationWhenResponseResultDTO > > fillFactor ) {
for ( String projectId : fillFactor . keySet ( ) ) {
//拿到同一个项目下的的节点记录(只有存在响应节点的项目)
List < ProjectOrgRelationWhenResponseResultDTO > projectTraceUnit = fillFactor . get ( projectId ) ;
if ( ! projectTraceUnit . isEmpty ( ) ) {
// K : staffId
// V : 项目下对于某个员工(可能是在不同部门、网格、机关下)的所有节点顺时针操作,因为对于但项目单人来说,只能串行不能并行
Map < String , List < ProjectOrgRelationWhenResponseResultDTO > > staffResponseTrace =
projectTraceUnit . stream ( ) . collect ( Collectors . groupingBy ( ProjectOrgRelationWhenResponseResultDTO : : getStaffId ) ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( staffResponseTrace ) ) {
List < ProjectOrgPeriodResultDTO > incompleteBody = dest . get ( projectId ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( incompleteBody ) ) {
Map < String , List < ProjectOrgPeriodResultDTO > > incompleteBodyGroupByStaffMap =
incompleteBody . stream ( ) . collect ( Collectors . groupingBy ( ProjectOrgPeriodResultDTO : : getStaffId ) ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( incompleteBodyGroupByStaffMap ) ) {
staffResponseTrace . keySet ( ) . forEach ( staffId - > {
List < ProjectOrgRelationWhenResponseResultDTO > staffResponseTraceUnit
= staffResponseTrace . get ( staffId ) ;
List < ProjectOrgPeriodResultDTO > incompleteBodyUnit = incompleteBodyGroupByStaffMap . get ( staffId ) ;
if ( ! org . springframework . util . CollectionUtils . isEmpty ( incompleteBodyUnit ) & & ! org . springframework . util . CollectionUtils . isEmpty ( staffResponseTraceUnit ) ) {
//int lastEndCount = NumConstant.ONE_NEG;
a :
for ( int index = NumConstant . ZERO ; index < staffResponseTraceUnit . size ( ) ; index + + ) {
if ( StringUtils . equals ( "response" , staffResponseTraceUnit . get ( index ) . getOperation ( ) ) ) {
replaceFirstResponseDate ( incompleteBodyUnit , staffResponseTraceUnit . get ( index ) ) ;
int cursor = index ;
if ( cursor = = staffResponseTraceUnit . size ( ) - NumConstant . ZERO ) break ;
while ( StringUtils . equals ( "response" , staffResponseTraceUnit . get ( cursor + + ) . getOperation ( ) ) ) {
if ( cursor = = staffResponseTraceUnit . size ( ) - NumConstant . ZERO ) break a ;
}
if ( cursor = = staffResponseTraceUnit . size ( ) - NumConstant . ZERO ) break ;
index = cursor ;
} else {
replaceFirstResponseDate ( incompleteBodyUnit , staffResponseTraceUnit . get ( index ) ) ;
}
}
}
} ) ;
}
}
}
}
}
}
private void replaceFirstResponseDate ( List < ProjectOrgPeriodResultDTO > dest ,
ProjectOrgRelationWhenResponseResultDTO staffResponseTraceUnit ) {
// 传递过来的dest是已经按照projectId分好组之后再按照staff分组的集合
// dest key->staff
for ( int cursor = 0 ; cursor < dest . size ( ) ; cursor + + ) {
if ( dest . get ( cursor ) . getPeriodTillReplyFirstly ( ) = = null ) continue ;
dest . get ( cursor ) . setPeriodTillReplyFirstly ( staffResponseTraceUnit . getCreatedTime ( ) ) ;
}
}
}