@ -1,25 +1,53 @@
package com.hnac.hzims.ticket.twoTicket.service.impl ;
import com.alibaba.fastjson.JSON ;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils ;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.hnac.hzims.common.logs.utils.StringUtils ;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity ;
import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient ;
import com.hnac.hzims.operational.feign.IAccessTaskClient ;
import com.hnac.hzims.operational.maintenance.dto.OperMaintenanceTaskDTO ;
import com.hnac.hzims.operational.maintenance.feign.ITaskClient ;
import com.hnac.hzims.operational.station.entity.StationEntity ;
import com.hnac.hzims.operational.station.feign.IStationClient ;
import com.hnac.hzims.ticket.constants.TicketConstants ;
import com.hnac.hzims.ticket.constants.WorkTicketConstants ;
import com.hnac.hzims.ticket.processflow.strategy.core.ProcessIdWorker ;
import com.hnac.hzims.ticket.response.ProcessWorkFlowResponse ;
import com.hnac.hzims.ticket.twoTicket.entity.WorkTicketFinish ;
import com.hnac.hzims.ticket.twoTicket.enums.FlowWorkTicketConstants ;
import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService ;
import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService ;
import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService ;
import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo ;
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketContentDto ;
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketSafetyMeasureDto ;
import com.hnac.hzims.ticket.workTicket.entity.* ;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketContentService ;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService ;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketPrincipalChangeService ;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketSafetyMeasureService ;
import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketDelayServiceImpl ;
import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketOperateTimeServiceImpl ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.aspectj.apache.bcel.generic.TABLESWITCH ;
import org.springblade.core.log.exception.ServiceException ;
import org.springblade.core.secure.utils.AuthUtil ;
import org.springblade.core.tool.api.R ;
import org.springblade.core.tool.utils.BeanUtil ;
import org.springblade.core.tool.utils.CollectionUtil ;
import org.springblade.core.tool.utils.Func ;
import org.springblade.flow.core.entity.BladeFlow ;
import org.springblade.flow.core.entity.FlowAttachment ;
import org.springblade.flow.core.feign.IFlowClient ;
import org.springblade.flow.core.vo.ComleteTask ;
import org.springblade.flow.core.vo.TaskList ;
import org.springblade.system.user.cache.UserCache ;
import org.springblade.system.user.entity.User ;
import org.springblade.system.user.feign.IUserClient ;
import org.springframework.stereotype.Service ;
import javax.crypto.Mac ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import org.springframework.transaction.annotation.Transactional ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
* 开票处理流程实现类
@ -41,115 +69,565 @@ public class TicketProcessServiceImpl implements TicketProcessService {
private final IWorkTicketInfoService workTicketInfoService ;
private Map < String , Boolean > map = new HashMap < String , Boolean > ( ) { {
put ( "key" , true ) ;
} } ;
private final ProcessIdWorker processIdWorker ;
private final IFirstWorkTicketService firstWorkTicketService ;
private final IWorkTicketSafetyMeasureService workTicketSafetyMeasureService ;
private final IWorkTicketContentService contentService ;
private final IUserClient userClient ;
private final IOperAccessTaskClient operAccessTaskClient ;
private final ITaskClient taskClient ;
private final IAccessTaskClient accessTaskClient ;
private String newFirstWorkTicketFlowKey = "workTicket" ;
private final IStationClient stationClient ;
private final WorkTicketOperateTimeServiceImpl workTicketOperateTimeServiceImpl ;
private final IWorkTicketFinishService workTicketFinishService ;
private final WorkTicketDelayServiceImpl workTicketDelayService ;
private final IWorkTicketPrincipalChangeService workTicketPrincipalChangeService ;
/ * *
* 启动开票流程
*
* @param workTicketVo
* /
@Override
@Transactional
public void startUp ( WorkTicketVo workTicketVo ) {
if ( workTicketVo . getWorkTicket ( ) . getSignage ( ) = = null ) {
throw new ServiceException ( "站点标识-两票编码不能为空" ) ;
}
//1. 获取站点站点标识-两票编码
StationEntity stationEntity = new StationEntity ( ) ;
stationEntity . setCode ( workTicketVo . getWorkTicket ( ) . getSignageCode ( ) ) ;
R < StationEntity > stationClientOne = stationClient . getOne ( stationEntity ) ;
if ( ! stationClientOne . isSuccess ( ) ) {
throw new IllegalArgumentException ( "根据条件获取唯一站点出错呢" ) ;
}
StationEntity station = stationClientOne . getData ( ) ;
if ( station = = null ) {
throw new ServiceException ( "根据条件获取唯一站点暂无数据" ) ;
}
log . info ( "前端查的站点编号 :{}" , workTicketVo . getWorkTicket ( ) . getSignage ( ) ) ;
log . info ( "后端查寻的站点编码 :{}" , station . getSignage ( ) ) ;
if ( ! workTicketVo . getWorkTicket ( ) . getSignage ( ) . equals ( station . getSignage ( ) ) ) {
throw new ServiceException ( "获取唯一站点不一致" ) ;
}
String signage =
station . getSignage ( ) . length ( ) = = 2 ?
station . getSignage ( ) : station . getSignage ( ) . substring ( 0 , 2 ) ;
workTicketVo . getWorkTicket ( ) . setSignage ( signage ) ;
workTicketVo . getWorkTicket ( ) . setSignageCode ( station . getCode ( ) ) ;
//2. 获取编码
String code = processIdWorker . getTicketByCode ( workTicketVo . getWorkTicket ( ) . getSignage ( ) , workTicketVo . getWorkTicket ( ) . getType ( ) , workTicketVo . getWorkTicket ( ) . getMakeDateTime ( ) ) ;
workTicketVo . getWorkTicket ( ) . setCode ( code ) ;
//3 .保存工作对象
this . saveWorkTicketInfo ( workTicketVo . getWorkTicket ( ) ) ;
//4. 保存安全措施
this . saveSafetyMeasures ( workTicketVo . getSafetyMeasuresList ( ) , workTicketVo . getWorkTicket ( ) ) ;
//5. 保存工作任务
this . saveWorkTicketContentDto ( workTicketVo . getWorkTicketContentDtoList ( ) , workTicketVo . getWorkTicket ( ) ) ;
//6. 开启动作流
this . dealProcess ( newFirstWorkTicketFlowKey , workTicketVo ) ;
}
/ * *
* 待处理
*
* @param response
* /
@Override
public void startUp ( ProcessWorkFlowResponse response ) {
public void findPending ( ProcessWorkFlowResponse response ) {
//json转换表单
String formData = response . getVariables ( ) ;
WorkTicketVo workTicketVo = JSON . parseObject ( formData , WorkTicketVo . class ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//2.流程处理
Integer flowStatus = workTicket . getFlowStatus ( ) ;
FlowWorkTicketConstants enumByStatus = FlowWorkTicketConstants . getEnumByStatus ( flowStatus ) ;
switch ( enumByStatus ) {
// case START:
// //开票
// make(response, workTicketVo);
// break;
case SIGN :
//签发人签发
//工作票签发人默认执行
sign ( response , workTicketVo ) ;
break ;
case RECEIVE :
//运功人接收
reception ( response , workTicketVo ) ;
break ;
case FIX_UP :
// 运行人员布置安全措施
safety ( response , workTicketVo ) ;
break ;
case PRINCIPAL_CONFIRM_MEASURE :
//工作负责人确认安全措施
principal ( response , workTicketVo ) ;
break ;
case LICENCE :
//许可人许可
license ( response , workTicketVo ) ;
break ;
case PRINCIPAL_CONFIRM_CONTENT :
//工作负责人确认工作内容执行
principalConfirmContent ( response , workTicketVo ) ;
break ;
case PRINCIPAL_CONFIRM_END :
//工作负责人确认工作票结束
principalConfirmEnd ( response , workTicketVo ) ;
break ;
case LICENSE_CONFIRM_END :
//许可人确认工作票结束
licenseConfirmEnd ( response , workTicketVo ) ;
break ;
case PROCESS_POSTPONE :
//工作票延期
processPostpone ( response , workTicketVo ) ;
break ;
case PROCESS_COURSE :
//工作票转移
processCourse ( response , workTicketVo ) ;
break ;
case SIGN_CONFIRM_DELAY :
//签发人审核
signConfirmDelay ( response , workTicketVo ) ;
break ;
}
}
/ * *
* 签发人审核
* @param response
* @param workTicketVo
* /
private void signConfirmDelay ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . LICENCE . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . LICENCE . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 工作票转移
* @param response
* @param workTicketVo
* /
private void processCourse ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
//工作票负责人变更
WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo . getWorkTicketPrincipalChange ( ) ;
workTicketPrincipalChangeService . save ( workTicketPrincipalChange ) ;
//更新工作票信息
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . SIGN_CONFIRM_DELAY . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . SIGN_CONFIRM_DELAY . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 工作票延期
*
* @param response
* @param workTicketVo
* /
private void processPostpone ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
//保存工作票延期
WorkTicketDelayEntity workTicketDelay = workTicketVo . getWorkTicketDelay ( ) ;
workTicketDelayService . save ( workTicketDelay ) ;
//更新工作票信息
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . LICENCE . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . LICENCE . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 许可人确认工作票结束
*
* @param response
* @param workTicketVo
* /
private void licenseConfirmEnd ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
//工作结束
WorkTicketFinish workTicketFinish = workTicketVo . getWorkTicketFinish ( ) ;
workTicketFinishService . updateById ( workTicketFinish ) ;
//更新工作票信息
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . END . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . END . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 工作负责人确认工作票结束
*
* @param response
* @param workTicketVo
* /
private void principalConfirmEnd ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
//工作结束
WorkTicketFinish workTicketFinish = workTicketVo . getWorkTicketFinish ( ) ;
workTicketFinishService . save ( workTicketFinish ) ;
//更新工作票信息
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . LICENSE_CONFIRM_END . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . LICENSE_CONFIRM_END . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 工作负责人确认工作内容执行
*
* @param response
* @param workTicketVo
* /
private void principalConfirmContent ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
List < WorkTicketOperateTimeEntity > workTicketOperateTimeEntities = workTicketVo . getWorkTicketOperateTimeEntities ( ) ;
if ( CollectionUtils . isEmpty ( workTicketOperateTimeEntities ) ) {
log . info ( "暂时没有每日开工每日收的数据" ) ;
return ;
}
workTicketOperateTimeServiceImpl . saveBatch ( workTicketOperateTimeEntities ) ;
//更新工作票信息
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_END . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_END . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 许可人许可
*
* @param response
* @param workTicketVo
* /
private void license ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
List < WorkTicketSafetyMeasureDto > safetyMeasuresList = workTicketVo . getSafetyMeasuresList ( ) ;
if ( CollectionUtils . isEmpty ( safetyMeasuresList ) ) {
log . error ( "没有安全措施数据" ) ;
return ;
}
Boolean key = map . get ( "key" ) ;
//更新安全措施的状态
List < WorkTicketSafetyMeasureEntity > workTicketSafetyMeasureEntities = new ArrayList < > ( ) ;
for ( WorkTicketSafetyMeasureDto workTicketSafetyMeasureDto : safetyMeasuresList ) {
WorkTicketSafetyMeasureEntity workTicketSafetyMeasureEntity = BeanUtil . copyProperties ( workTicketSafetyMeasureDto , WorkTicketSafetyMeasureEntity . class ) ;
workTicketSafetyMeasureEntities . add ( workTicketSafetyMeasureEntity ) ;
}
workTicketSafetyMeasureService . saveBatch ( workTicketSafetyMeasureEntities ) ;
//当前环节Id
String processDefinitionKey = response . getProcessDefinitionKey ( ) ;
//当前任务Id
String taskId = response . getTaskId ( ) ;
//表单数据
String formData = response . getFormData ( ) ;
log . info ( "当前任务ID:{},当前流程定义ID:{},启动开票流程" , taskId , processDefinitionKey ) ;
System . out . println ( formData ) ;
//更新工作票
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_CONTENT . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_CONTENT . getDescription ( ) ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
// Map<String, Object> variables = new HashMap<>();
// variables.put("task_id", taskId);
// variables.put("signUserIds", formData);
/ * *
* 工作负责人确认安全措施
*
* @param response
* @param workTicketVo
* /
private void principal ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//负责人确认时间
//workTicket.setConfirmDateTime(workTicketVo.getWorkTicket().getConfirmDateTime());
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getDescription ( ) ) ;
//更新状态值
workTicketInfoService . updateById ( workTicket ) ;
}
if ( key ) {
Map < String , Object > params = new HashMap < String , Object > ( 2 ) { {
put ( "taskId" , "4066d774-df2c-11ed-b33e-fa163ee12c20" ) ;
put ( "signUserIds" , "1377143375838359553" ) ;
} } ;
/ * *
* 运行人员布置安全措施
*
* @param response
* @param workTicketVo
* /
private void safety ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//值班负责人
workTicket . setWatchPrincipal ( workTicketVo . getWorkTicket ( ) . getPrincipal ( ) ) ;
workTicket . setWatchPrincipalEndTime ( workTicketVo . getWorkTicket ( ) . getWatchPrincipalEndTime ( ) ) ;
R < BladeFlow > processInstanceContainNameByKey = flowClient . startProcessInstanceContainNameByKey (
processDefinitionKey , "workTicket:task:" + 1377143375838359553L ,
"开启工作的任务" ,
params ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getDescription ( ) ) ;
//更新状态值
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 运功人接收
*
* @param response
* @param workTicketVo
* /
private void reception ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . FIX_UP . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . FIX_UP . getDescription ( ) ) ;
//更新状态值
workTicketInfoService . updateById ( workTicket ) ;
}
/ * *
* 第一种工作票签发
* /
//@Transactional(rollbackFor = Exception.class)
public void sign ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//更新状态值
WorkTicketInfoEntity workTicketInfoEntity = new WorkTicketInfoEntity ( ) ;
workTicketInfoEntity . setFlowStatus ( FlowWorkTicketConstants . RECEIVE . getStatus ( ) ) ;
workTicketInfoEntity . setFlowDescription ( FlowWorkTicketConstants . RECEIVE . getDescription ( ) ) ;
workTicketInfoEntity . setSignerDateTime ( workTicketVo . getWorkTicket ( ) . getSignerDateTime ( ) ) ;
workTicketInfoService . updateById ( workTicketInfoEntity ) ;
}
/ * *
* 开票
* /
private void make ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
//保存工作流实例ID
workTicketInfoService . update ( Wrappers . < WorkTicketInfoEntity > lambdaUpdate ( ) .
set ( WorkTicketInfoEntity : : getProcessInstanceId , response . getProcessInstanceId ( ) ) .
set ( WorkTicketInfoEntity : : getFlowStatus , FlowWorkTicketConstants . SIGN . getStatus ( ) ) . set ( WorkTicketInfoEntity : : getFlowDescription , FlowWorkTicketConstants . SIGN . getDescription ( ) ) . eq ( WorkTicketInfoEntity : : getId , workTicket . getId ( ) ) ) ;
//处理来源任务
this . returnTicket ( workTicketVo ) ;
}
/ * *
* 处理来源任务
*
* @param workTicketVo
* /
private void returnTicket ( WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
if ( TicketConstants . TaskTypeEnum . JXRW . getType ( ) . equals ( workTicket . getTaskType ( ) ) ) {
OperAccessTaskEntity taskEntity = new OperAccessTaskEntity ( ) ;
taskEntity . setId ( workTicket . getTaskId ( ) ) ;
taskEntity . setTicketId ( workTicket . getId ( ) ) ;
operAccessTaskClient . updateById ( taskEntity ) ;
}
if ( TicketConstants . TaskTypeEnum . RCWH . getType ( ) . equals ( workTicket . getTaskType ( ) ) ) {
OperMaintenanceTaskDTO dto = new OperMaintenanceTaskDTO ( ) ;
dto . setId ( workTicket . getTaskId ( ) ) ;
dto . setTicketId ( workTicket . getId ( ) ) ;
taskClient . doUpdateTaskById ( dto ) ;
}
//消缺流程进行
if ( ( TicketConstants . TaskTypeEnum . JXRW . getType ( ) . equals ( workTicket . getTaskType ( ) ) | | TicketConstants . TaskTypeEnum . JXJH . getType ( ) . equals ( workTicket . getTaskType ( ) ) ) & & Func . isNotEmpty ( workTicket . getTaskId ( ) ) ) {
accessTaskClient . billing ( workTicket . getTaskId ( ) ) ;
}
}
if ( processInstanceContainNameByKey . getCode ( ) ! = 200 ) {
log . error ( "启动开票流程失败: {}" , processInstanceContainNameByKey ) ;
/ * *
* 开启流程
*
* @param newFirstWorkTicketFlowKey
* @param workTicketVo
* /
private void
dealProcess ( String newFirstWorkTicketFlowKey , WorkTicketVo workTicketVo ) {
//若为线下工作票 则无需开启工作流
Integer status = WorkTicketConstants . FirstWorkTicketStatusEnum . SIGN . getStatus ( ) ;
if ( status . intValue ( ) ! = workTicketVo . getWorkTicket ( ) . getStatus ( ) . intValue ( ) ) {
return ;
}
log . info ( "租户Id:{}" , AuthUtil . getTenantId ( ) ) ;
log . info ( "用户部门Id: {}" , AuthUtil . getUser ( ) . getDeptId ( ) ) ;
log . info ( "用户Id: {}" , AuthUtil . getUserId ( ) ) ;
//获取签发人角色下的人员
R < List < User > > listR = userClient . relationUserListByRoleAlias ( AuthUtil . getTenantId ( ) , Long . parseLong ( AuthUtil . getUser ( ) . getDeptId ( ) ) , TicketConstants . SIGNER_ROLE ) ;
if ( ! listR . isSuccess ( ) | | CollectionUtil . isEmpty ( listR . getData ( ) ) ) {
throw new ServiceException ( "工作票签发人角色下未查询到相关人员" ) ;
}
log . info ( "获取签发人角色下的人员: {}" , listR . getData ( ) ) ;
Map < String , Object > params = new HashMap < > ( 4 ) ;
params . put ( "workTicketVo" , workTicketVo ) ;
R < BladeFlow > processInstanceContainNameByKey = flowClient . startProcessInstanceContainNameByKey ( newFirstWorkTicketFlowKey , String . valueOf ( workTicketVo . getWorkTicket ( ) . getId ( ) ) , workTicketVo . getWorkTicket ( ) . getWorkContent ( ) , params ) ;
if ( ! processInstanceContainNameByKey . isSuccess ( ) & & processInstanceContainNameByKey . getData ( ) = = null ) {
throw new ServiceException ( "启动流程失败..." ) ;
}
//获取BladeFlow 数据库
BladeFlow bladeFlow = processInstanceContainNameByKey . getData ( ) ;
log . info ( "bladeFlow: {}" , bladeFlow ) ;
map . put ( "key" , false ) ;
log . info ( "获取工作流新的数据: {}" , bladeFlow ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setProcessInstanceId ( bladeFlow . getProcessInstanceId ( ) ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . SIGN . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . SIGN . getDescription ( ) ) ;
//保存工作流实例ID
firstWorkTicketService . updateById ( workTicket ) ;
workTicketVo . setWorkTicket ( workTicket ) ;
//处理来源任务
this . returnTicket ( workTicketVo ) ;
}
/ * *
* 保存工作任务
*
* @param workTicketContentDtoList
* @param workTicketInfoEntity
* /
private void saveWorkTicketContentDto ( List < WorkTicketContentDto > workTicketContentDtoList , WorkTicketInfoEntity workTicketInfoEntity ) {
if ( CollectionUtils . isEmpty ( workTicketContentDtoList ) ) {
return ;
}
List < WorkTicketContentEntity > contentEntities = workTicketContentDtoList . stream ( ) . map ( contentDto - > {
WorkTicketContentEntity contentEntity = BeanUtil . copy ( contentDto , WorkTicketContentEntity . class ) ;
contentEntity . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
contentEntity . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
return contentEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
boolean savedBatch = contentService . saveBatch ( contentEntities ) ;
if ( ! savedBatch ) {
throw new IllegalArgumentException ( "保存工作任务出错呢" ) ;
}
}
/ * *
* 保存安全措施
*
* @param safetyMeasuresList
* @param workTicketInfoEntity
* /
private void saveSafetyMeasures ( List < WorkTicketSafetyMeasureDto > safetyMeasuresList , WorkTicketInfoEntity workTicketInfoEntity ) {
if ( CollectionUtil . isEmpty ( safetyMeasuresList ) ) {
return ;
}
List < WorkTicketSafetyMeasureEntity > measureEntityList = safetyMeasuresList . stream ( ) . map ( measure - > {
WorkTicketSafetyMeasureEntity measureEntity = BeanUtil . copy ( measure , WorkTicketSafetyMeasureEntity . class ) ;
measureEntity . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
measureEntity . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
measureEntity . setCreateUser ( workTicketInfoEntity . getCreateUser ( ) ) ;
return measureEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
boolean savedBatch = workTicketSafetyMeasureService . saveBatch ( measureEntityList ) ;
if ( ! savedBatch ) {
throw new IllegalArgumentException ( "保存安全措施出错呢" ) ;
}
}
// R<BladeFlow> tasks = flowClient.getTaskByProcessInstanceIdAndUserId(response.getProcessInstanceId(),
// "1377143375838359553");
//
//
// flowClient.getTaskByProcessInstanceIdAndUserId(response.getProcessInstanceId(),
// "1377143375838359553");
//
// if (tasks.getCode() != 200){
// return;
// }
//
// BladeFlow bladeFlow1 = tasks.getData();
//
// String curStep = bladeFlow1.getCurStep();
// System.out.println("curStep = " + curStep);
//
// String status = bladeFlow1.getStatus();
// System.out.println("status = " + status);
//
// // R<List<TaskList>> listR = flowClient.todoList(processDefinitionKey);
// // listR.getData().forEach(taskList -> {
// // System.out.println("任务名称:"+taskList);
// // System.out.println(taskList.getTaskName());
// // System.out.println(taskList.getStatus());
// // });
//
// R<Map<String, Object>> taskedVariables = flowClient.taskVariables(response.getTaskId());
//
// System.out.println(taskedVariables);
// R<List<TaskList>> listR = flowClient.todoList(response.getProcessDefinitionKey());
// for (TaskList datum : listR.getData()) {
// System.out.println(datum);
// }
ComleteTask comleteTask = new ComleteTask ( ) ;
comleteTask . setPass ( true ) ;
comleteTask . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
comleteTask . setTaksUserId ( 1377143375838359553L ) ;
comleteTask . setTaskId ( response . getTaskId ( ) ) ;
comleteTask . setComment ( "同意" ) ;
FlowAttachment flowAttachment = new FlowAttachment ( ) ;
flowAttachment . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
flowAttachment . setTaskId ( taskId ) ;
flowAttachment . setAttachmentType ( "" ) ;
List < FlowAttachment > list = new ArrayList < > ( ) ;
list . add ( flowAttachment ) ;
comleteTask . setAttachments ( list ) ;
Map < String , Object > params = new HashMap < String , Object > ( 2 ) { {
put ( "taskId" , taskId ) ;
put ( "principalUserIds" , "1377143375838359553" ) ;
} } ;
comleteTask . setVariables ( params ) ;
flowClient . completeTask ( comleteTask ) ;
/ * *
* 保存工作对象
*
* @param workTicket
* @return
* /
private WorkTicketInfoEntity saveWorkTicketInfo ( WorkTicketInfoEntity workTicket ) {
workTicket . setStatus ( Func . isEmpty ( workTicket . getPrincipal ( ) ) | | Func . isEmpty ( workTicket . getClassGroupMembers ( ) ) ? WorkTicketConstants . FirstWorkTicketStatusEnum . OFFLINE_OPERATE . getStatus ( ) : WorkTicketConstants . FirstWorkTicketStatusEnum . SIGN . getStatus ( ) ) ;
//班组成员名称
String byclassGroupMembers = getByClassGroupMembers ( workTicket ) ;
workTicket . setClassGroupMembersName ( byclassGroupMembers ) ;
//班组负责人
String principalName = getByPrincipal ( workTicket ) ;
workTicket . setPrincipalName ( principalName ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . START . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . START . getDescription ( ) ) ;
//唯一
workTicket . setCreateUser ( AuthUtil . getUserId ( ) ) ;
boolean isSave = firstWorkTicketService . save ( workTicket ) ;
if ( ! isSave ) {
throw new IllegalArgumentException ( "保存工作对象错误" ) ;
}
return workTicket ;
}
/ * *
* 把班组负责人 = = > principalName 里
*
* @param workTicket
* @return
* /
private String getByPrincipal ( WorkTicketInfoEntity workTicket ) {
//班组成员
Long principal = workTicket . getPrincipal ( ) ;
if ( ObjectUtils . isNotEmpty ( principal ) ) {
return UserCache . getUser ( principal ) . getName ( ) ;
}
return workTicket . getPrincipalManual ( ) ;
}
/ * *
* 把班组成员 = = > classGroupMembersName 里
* /
private String getByClassGroupMembers ( WorkTicketInfoEntity workTicket ) {
StringJoiner stringJoiner = new StringJoiner ( "," ) ;
//班组成员
String classGroupMembers = workTicket . getClassGroupMembers ( ) ;
if ( StringUtils . isNotBlank ( classGroupMembers ) ) {
String [ ] splits = classGroupMembers . split ( "," ) ;
for ( String split : splits ) {
User user = UserCache . getUser ( Long . valueOf ( split ) ) ;
stringJoiner . add ( user ! = null ? user . getName ( ) : "" ) ;
}
}
String classGroupMembersManual = workTicket . getClassGroupMembersManual ( ) ;
if ( StringUtils . isNotBlank ( classGroupMembersManual ) ) {
String [ ] splits = classGroupMembersManual . split ( "," ) ;
for ( String split : splits ) {
stringJoiner . add ( split ) ;
}
}
return stringJoiner . toString ( ) ;
}
}