@ -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 ;
@ -28,30 +29,29 @@ import com.epmet.commons.tools.scan.param.TextScanParamDTO;
import com.epmet.commons.tools.scan.param.TextTaskDTO ;
import com.epmet.commons.tools.scan.result.SyncScanResult ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.DateUtils ;
import com.epmet.commons.tools.utils.Result ;
import com.epmet.commons.tools.utils.ScanContentUtils ;
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.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.stream.Collectors ;
@ -63,6 +63,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
@ -89,6 +90,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" ;
@ -357,6 +360,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 ) ;
@ -366,19 +371,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 < > ( ) ;
//通知项目相关人员
@ -436,16 +488,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 ( ) ) ;
@ -458,12 +524,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 ( ) ;
@ -592,6 +687,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 ) ;
@ -600,11 +696,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 ) ;
@ -642,6 +745,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 ( ) ;
@ -659,6 +780,8 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
issueProjectResultDTO . setProjectId ( projectEntity . getId ( ) ) ;
issueProjectResultDTO . setOrgName ( processEntity . getDepartmentName ( ) ) ;
issueProjectResultDTO . setShiftedTime ( projectEntity . getCreatedTime ( ) ) ;
return issueProjectResultDTO ;
}
@ -670,7 +793,6 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
* * /
@Override
public List < LatestListResultDTO > getClosedProjectList ( LatestListFormDTO formDTO ) {
return baseDao . selectClosedProjectList ( formDTO ) ;
}
@ -698,17 +820,81 @@ 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 ( "计算首次响应时间失败" ) ;
}
}
/ * *