@ -1,9 +1,11 @@
package com.hnac.hzims.ticket.twoTicket.service.impl ;
package com.hnac.hzims.ticket.twoTicket.service.impl ;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils ;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils ;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils ;
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.common.logs.utils.StringUtils ;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity ;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity ;
import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient ;
import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient ;
@ -21,34 +23,44 @@ import com.hnac.hzims.ticket.twoTicket.enums.FlowWorkTicketConstants;
import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService ;
import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService ;
import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService ;
import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService ;
import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService ;
import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService ;
import com.hnac.hzims.ticket.twoTicket.vo.process.FristWorkTicketVo ;
import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo ;
import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo ;
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketContentDto ;
import com.hnac.hzims.ticket.utils.ExcelUtil ;
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketSafetyMeasureDto ;
import com.hnac.hzims.ticket.utils.PdfUtils ;
import com.hnac.hzims.ticket.workTicket.entity.* ;
import com.hnac.hzims.ticket.workTicket.entity.* ;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketContentService ;
import com.hnac.hzims.ticket.workTicket.service.* ;
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.WorkTicketDelayServiceImpl ;
import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketOperateTimeServiceImpl ;
import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketOperateTimeServiceImpl ;
import com.hnac.hzims.ticket.workTicket.vo.WorkTicketSafetyMeasureVO ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.poi.ss.usermodel.Workbook ;
import org.springblade.core.log.exception.ServiceException ;
import org.springblade.core.log.exception.ServiceException ;
import org.springblade.core.secure.utils.AuthUtil ;
import org.springblade.core.secure.utils.AuthUtil ;
import org.springblade.core.tool.api.R ;
import org.springblade.core.tool.api.R ;
import org.springblade.core.tool.utils.BeanUtil ;
import org.springblade.core.tool.utils.BeanUtil ;
import org.springblade.core.tool.utils.CollectionUtil ;
import org.springblade.core.tool.utils.CollectionUtil ;
import org.springblade.core.tool.utils.Func ;
import org.springblade.core.tool.utils.Func ;
import org.springblade.core.tool.utils.ObjectUtil ;
import org.springblade.flow.core.entity.BladeFlow ;
import org.springblade.flow.core.entity.BladeFlow ;
import org.springblade.flow.core.feign.IFlowClient ;
import org.springblade.flow.core.feign.IFlowClient ;
import org.springblade.system.user.cache.UserCache ;
import org.springblade.system.user.cache.UserCache ;
import org.springblade.system.user.entity.User ;
import org.springblade.system.user.entity.User ;
import org.springblade.system.user.feign.IUserClient ;
import org.springblade.system.user.feign.IUserClient ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.web.context.request.RequestContextHolder ;
import org.springframework.web.context.request.ServletRequestAttributes ;
import javax.servlet.http.HttpServletResponse ;
import java.time.Instant ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.util.* ;
import java.util.* ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
/ * *
/ * *
* 开票处理流程实现类
* 开票处理流程实现类
*
*
@ -109,6 +121,21 @@ public class TicketProcessServiceImpl implements TicketProcessService {
private final IWorkTicketPrincipalChangeService workTicketPrincipalChangeService ;
private final IWorkTicketPrincipalChangeService workTicketPrincipalChangeService ;
private final List < TicketProcessService > processService ;
private final IWorkTicketOperateTimeService workTicketOperateTimeService ;
private final IWorkTicketInfoService ticketInfoService ;
@Value ( "${hzims.ticket.path.pdf.savePath}" )
private String pdfSavePath ;
@Value ( "${hzims.ticket.path.xlsx.savePath}" )
private String xlsSavePath ;
/ * *
/ * *
* 启动开票流程
* 启动开票流程
*
*
@ -132,27 +159,34 @@ public class TicketProcessServiceImpl implements TicketProcessService {
throw new ServiceException ( "根据条件获取唯一站点暂无数据" ) ;
throw new ServiceException ( "根据条件获取唯一站点暂无数据" ) ;
}
}
log . info ( "前端查的站点编号 :{}" , workTicketVo . getWorkTicket ( ) . getSignage ( ) ) ;
log . info ( "前端查的站点编号 :{}" , workTicketVo . getWorkTicket ( ) . getSignage ( ) ) ;
log . info ( "后端查寻的站点编码 :{}" , station . getSignage ( ) ) ;
log . info ( "后端查寻的站点编码 :{}" , station . getSignage ( ) ) ;
if ( ! workTicketVo . getWorkTicket ( ) . getSignage ( ) . equals ( station . getSignage ( ) ) ) {
if ( ! workTicketVo . getWorkTicket ( ) . getSignage ( ) . equals ( station . getSignage ( ) ) ) {
throw new ServiceException ( "获取唯一站点不一致 " ) ;
throw new ServiceException ( "站点标识-两票编码不能为空 " ) ;
}
}
String signage =
station . getSignage ( ) . length ( ) = = 2 ?
//获取站点编号
station . getSignage ( ) : station . getSignage ( ) . substring ( 0 , 2 ) ;
String signage = station . getSignage ( ) ;
if ( StringUtils . isBlank ( signage ) | | signage . length ( ) < 2 ) {
throw new ServiceException ( "站点标识-两票编码不能为空" ) ;
}
signage = signage . length ( ) = = 2 ? station . getSignage ( ) : station . getSignage ( ) . substring ( 0 , 2 ) ;
workTicketVo . getWorkTicket ( ) . setSignage ( signage ) ;
workTicketVo . getWorkTicket ( ) . setSignage ( signage ) ;
workTicketVo . getWorkTicket ( ) . setSignageCode ( station . getCode ( ) ) ;
workTicketVo . getWorkTicket ( ) . setSignageCode ( station . getCode ( ) ) ;
//2. 获取编码
//2. 获取编码
String code = processIdWorker . getTicketByCode ( workTicketVo . getWorkTicket ( ) . getSignage ( ) , workTicketVo . getWorkTicket ( ) . getType ( ) , workTicketVo . getWorkTicket ( ) . getMakeDateTime ( ) ) ;
String code = processIdWorker . getTicketByCode ( workTicketVo . getWorkTicket ( ) . getSignage ( ) ,
workTicketVo . getWorkTicket ( ) . getType ( ) , LocalDateTime . now ( ) ) ;
workTicketVo . getWorkTicket ( ) . setCode ( code ) ;
workTicketVo . getWorkTicket ( ) . setCode ( code ) ;
//3 .保存工作对象
//2 .保存工作对象
this . saveWorkTicketInfo ( workTicketVo . getWorkTicket ( ) ) ;
this . saveWorkTicketInfo ( workTicketVo . getWorkTicket ( ) ) ;
//4. 保存安全措施
//3. 保存安全措施
log . info ( "获取报存安全措施:{}" , workTicketVo . getSafetyMeasuresList ( ) ) ;
this . saveSafetyMeasures ( workTicketVo . getSafetyMeasuresList ( ) , workTicketVo . getWorkTicket ( ) ) ;
this . saveSafetyMeasures ( workTicketVo . getSafetyMeasuresList ( ) , workTicketVo . getWorkTicket ( ) ) ;
//5 . 保存工作任务
//4 . 保存工作任务
this . saveWorkTicketContentDto ( workTicketVo . getWorkTicketContentDtoList ( ) , workTicketVo . getWorkTicket ( ) ) ;
this . saveWorkTicketContentDto ( workTicketVo . getWorkTicketContentDtoList ( ) , workTicketVo . getWorkTicket ( ) ) ;
//6 . 开启动作流
//5 . 开启动作流
this . dealProcess ( newFirstWorkTicketFlowKey , workTicketVo ) ;
this . dealProcess ( newFirstWorkTicketFlowKey , workTicketVo ) ;
}
}
@ -163,69 +197,207 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* /
* /
@Override
@Override
public void findPending ( ProcessWorkFlowResponse response ) {
public void findPending ( ProcessWorkFlowResponse response ) {
log . info ( "获取待处理的数据 {}" , response ) ;
log . info ( "获取businessKey: {}" , response . getBusinessKey ( ) ) ;
log . info ( "获取taskId: {}" , response . getTaskId ( ) ) ;
log . info ( "获取下一个审批人是: {}" , response . getNextStepOperator ( ) ) ;
if ( StringUtils . isNull ( response . getTaskId ( ) ) ) {
log . info ( "工作流结束~~~" ) ;
return ;
}
//json转换表单
//json转换表单
String formData = response . getVariables ( ) ;
String formData = JSON . toJSONString ( response . getVariables ( ) ) ;
WorkTicketVo workTicketVo = JSON . parseObject ( formData , WorkTicketVo . class ) ;
log . info ( "获取表单的数据:{}" , formData ) ;
FristWorkTicketVo fristWorkFlowResponse = null ;
try {
fristWorkFlowResponse = JSONObject . parseObject ( formData , FristWorkTicketVo . class ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
if ( ObjectUtils . isEmpty ( fristWorkFlowResponse ) ) {
log . error ( "获取表单的数据解析的数据为null" ) ;
return ;
}
//获取表单数据
WorkTicketVo workTicketVo = fristWorkFlowResponse . getWorkTicketVo ( ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//2.流程处理
//2.流程处理
Integer flowStatus = workTicket . getFlowStatus ( ) ;
String businessKey = response . getBusinessKey ( ) ;
FlowWorkTicketConstants enumByStatus = FlowWorkTicketConstants . getEnumByStatus ( flowStatus ) ;
WorkTicketInfoEntity workTicketInfo = firstWorkTicketService . getById ( businessKey ) ;
switch ( enumByStatus ) {
if ( ObjectUtils . isEmpty ( workTicketInfo ) | | ObjectUtils . isEmpty ( workTicket . getId ( ) ) ) {
log . error ( "获取工作票的数据为不存在" ) ;
return ;
}
//更新工作票
if ( workTicket . getId ( ) = = null ) {
workTicket . setId ( workTicketInfo . getId ( ) ) ;
}
//工作流ID
if ( StringUtils . isEmpty ( workTicketInfo . getProcessInstanceId ( ) ) ) {
workTicket . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
}
workTicketInfoService . updateById ( workTicket ) ;
//更新安全措施
List < WorkTicketSafetyMeasureEntity > safetyMeasuresList = workTicketVo . getSafetyMeasuresList ( ) ;
if ( CollectionUtils . isNotEmpty ( safetyMeasuresList ) ) {
log . info ( "获取安全措施的数据:{}" , safetyMeasuresList ) ;
safetyMeasuresList . forEach ( item - > {
if ( ObjectUtils . isEmpty ( item . getId ( ) ) ) {
LambdaQueryWrapper < WorkTicketSafetyMeasureEntity > queryWrapper = new LambdaQueryWrapper < > ( ) ;
queryWrapper . eq ( WorkTicketSafetyMeasureEntity : : getTicketId , workTicketInfo . getId ( ) ) ;
workTicketSafetyMeasureService . update ( item , queryWrapper ) ;
} else {
workTicketSafetyMeasureService . updateById ( item ) ;
}
} ) ;
}
//工作票工作任务组
List < WorkTicketContentEntity > workTicketContentDtoList = workTicketVo . getWorkTicketContentDtoList ( ) ;
if ( CollectionUtils . isNotEmpty ( workTicketContentDtoList ) ) {
log . info ( "获取工作票工作任务组:{}" , workTicketContentDtoList ) ;
workTicketContentDtoList . forEach ( item - > {
if ( ObjectUtils . isEmpty ( item . getId ( ) ) ) {
LambdaQueryWrapper < WorkTicketContentEntity > queryWrapper = new LambdaQueryWrapper < > ( ) ;
queryWrapper . eq ( WorkTicketContentEntity : : getTicketId , workTicketInfo . getId ( ) ) ;
contentService . update ( item , queryWrapper ) ;
} else {
contentService . updateById ( item ) ;
}
} ) ;
}
// 工作票延期
WorkTicketDelayEntity workTicketDelay = workTicketVo . getWorkTicketDelay ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketDelay ) & & ObjectUtils . isNotEmpty ( workTicketDelay . getCreateUser ( ) ) ) {
log . info ( "获取工作票延期:{}" , workTicketDelay ) ;
try {
workTicketDelay . setCreateDept ( workTicket . getCreateDept ( ) ) ;
workTicketDelay . setTicketId ( workTicketInfo . getId ( ) ) ;
workTicketDelay . setTenantId ( workTicketInfo . getTenantId ( ) ) ;
if ( ObjectUtils . isEmpty ( workTicketDelay . getId ( ) ) ) {
workTicketDelayService . save ( workTicketDelay ) ;
} else {
workTicketDelayService . updateById ( workTicketDelay ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
//工作结束
WorkTicketFinish workTicketFinish = workTicketVo . getWorkTicketFinish ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketFinish ) & & ObjectUtils . isNotEmpty ( workTicketFinish . getPrincipal ( ) ) ) {
log . info ( "获取工作结束:{}" , workTicketFinish ) ;
if ( ObjectUtils . isEmpty ( workTicketFinish . getId ( ) ) ) {
workTicketDelay . setTicketId ( workTicketInfo . getId ( ) ) ;
//workTicketDelay.setInitialTime(LocalDateTime.now());
workTicketFinishService . save ( workTicketFinish ) ;
} else {
workTicketDelay . setInitialTime ( LocalDateTime . now ( ) ) ;
workTicketFinishService . updateById ( workTicketFinish ) ;
}
}
//工作开始时间和结束时间
List < WorkTicketOperateTimeEntity > workTicketOperateTimeEntities = workTicketVo . getWorkTicketOperateTimeEntities ( ) ;
if ( CollectionUtils . isNotEmpty ( workTicketOperateTimeEntities ) ) {
log . info ( "工作开始时间和结束时间:{}" , workTicketFinish ) ;
workTicketOperateTimeService . saveBatch ( workTicketOperateTimeEntities ) ;
}
//工作票负责人变更
WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo . getWorkTicketPrincipalChange ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketPrincipalChange ) & & workTicketPrincipalChange . getInitialPrincipal ( ) ! = null ) {
log . info ( "工作票负责人变更: {}" , workTicketPrincipalChange ) ;
//原来的负责人
User user = UserCache . getUser ( workTicketPrincipalChange . getInitialPrincipal ( ) ) ;
//新的负责人
User newUser = UserCache . getUser ( workTicketPrincipalChange . getChangePrincipal ( ) ) ;
workTicketPrincipalChange . setCreateDept ( workTicket . getCreateDept ( ) ) ;
workTicketPrincipalChange . setTicketId ( workTicketInfo . getId ( ) ) ;
workTicketPrincipalChange . setTenantId ( workTicketInfo . getTenantId ( ) ) ;
if ( workTicketPrincipalChange . getId ( ) = = null ) {
workTicketPrincipalChangeService . save ( workTicketPrincipalChange ) ;
} else {
workTicketPrincipalChangeService . updateById ( workTicketPrincipalChange ) ;
}
log . info ( "工作负责人变更 原来的负责人 {},变更为 {}" , user . getName ( ) , newUser . getName ( ) ) ;
workTicket . setPrincipal ( workTicketPrincipalChange . getChangePrincipal ( ) ) ;
workTicket . setPrincipalName ( newUser . getName ( ) ) ;
//更新工作票
workTicketInfoService . updateById ( workTicket ) ;
}
// WorkTicketInfoEntity workTicketInfo = firstWorkTicketService.getById(workTicket.getId());
// Integer flowStatus = workTicketInfo.getFlowStatus();
// FlowWorkTicketConstants enumByStatus = FlowWorkTicketConstants.getEnumByStatus(flowStatus);
// ProcessService dbProcessService = processService.stream().filter(item -> item.isStatus(response.getProcessDefinitionKey(),
// enumByStatus)).findFirst().orElse(null);
// dbProcessService.execute(response,workTicketVo);
//
// switch (enumByStatus) {
// case START:
// case START:
// //开票
// //开票
// make(response, workTicketVo);
// make(response, workTicketVo);
// break;
// break;
case SIGN :
// case SIGN:
//签发人签发
// //签发人签发
//工作票签发人默认执行
// //工作票签发人默认执行
sign ( response , workTicketVo ) ;
// sign(response, workTicketVo);
break ;
// break;
case RECEIVE :
// case RECEIVE:
//运功人接收
// //运功人接收
reception ( response , workTicketVo ) ;
// reception(response, workTicketVo);
break ;
// break;
case FIX_UP :
// case FIX_UP:
// 运行人员布置安全措施
// // 运行人员布置安全措施
safety ( response , workTicketVo ) ;
// safety(response, workTicketVo);
break ;
// break;
case PRINCIPAL_CONFIRM_MEASURE :
// case PRINCIPAL_CONFIRM_MEASURE:
//工作负责人确认安全措施
// //工作负责人确认安全措施
principal ( response , workTicketVo ) ;
// principal(response, workTicketVo);
break ;
// break;
case LICENCE :
// case LICENCE:
//许可人许可
// //许可人许可
license ( response , workTicketVo ) ;
// license(response, workTicketVo);
break ;
// break;
case PRINCIPAL_CONFIRM_CONTENT :
// case PRINCIPAL_CONFIRM_CONTENT:
//工作负责人确认工作内容执行
// //工作负责人确认工作内容执行
principalConfirmContent ( response , workTicketVo ) ;
// principalConfirmContent(response, workTicketVo);
break ;
// break;
case PRINCIPAL_CONFIRM_END :
// case PRINCIPAL_CONFIRM_END:
//工作负责人确认工作票结束
// //工作负责人确认工作票结束
principalConfirmEnd ( response , workTicketVo ) ;
// principalConfirmEnd(response, workTicketVo);
break ;
// break;
case LICENSE_CONFIRM_END :
// case LICENSE_CONFIRM_END:
//许可人确认工作票结束
// //许可人确认工作票结束
licenseConfirmEnd ( response , workTicketVo ) ;
// licenseConfirmEnd(response, workTicketVo);
break ;
// break;
case PROCESS_POSTPONE :
// case PROCESS_POSTPONE:
//工作票延期
// //工作票延期
processPostpone ( response , workTicketVo ) ;
// processPostpone(response, workTicketVo);
break ;
// break;
case PROCESS_COURSE :
// case PROCESS_COURSE:
//工作票转移
// //工作票转移
processCourse ( response , workTicketVo ) ;
// processCourse(response, workTicketVo);
break ;
// break;
case SIGN_CONFIRM_DELAY :
// case SIGN_CONFIRM_DELAY:
//签发人审核
// //签发人审核
signConfirmDelay ( response , workTicketVo ) ;
// signConfirmDelay(response, workTicketVo);
break ;
// break;
}
// }
}
}
/ * *
/ * *
* 签发人审核
* 签发人审核
*
* @param response
* @param response
* @param workTicketVo
* @param workTicketVo
* /
* /
@ -236,12 +408,12 @@ public class TicketProcessServiceImpl implements TicketProcessService {
workTicketInfoService . updateById ( workTicket ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
}
/ * *
/ * *
* 工作票转移
* 工作票转移
*
* @param response
* @param response
* @param workTicketVo
* @param workTicketVo
* /
* /
@ -341,7 +513,7 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* @param workTicketVo
* @param workTicketVo
* /
* /
private void license ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
private void license ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
List < WorkTicketSafetyMeasureDto > safetyMeasuresList = workTicketVo . getSafetyMeasuresList ( ) ;
List < WorkTicketSafetyMeasureEntity > safetyMeasuresList = workTicketVo . getSafetyMeasuresList ( ) ;
if ( CollectionUtils . isEmpty ( safetyMeasuresList ) ) {
if ( CollectionUtils . isEmpty ( safetyMeasuresList ) ) {
log . error ( "没有安全措施数据" ) ;
log . error ( "没有安全措施数据" ) ;
return ;
return ;
@ -349,7 +521,7 @@ public class TicketProcessServiceImpl implements TicketProcessService {
//更新安全措施的状态
//更新安全措施的状态
List < WorkTicketSafetyMeasureEntity > workTicketSafetyMeasureEntities = new ArrayList < > ( ) ;
List < WorkTicketSafetyMeasureEntity > workTicketSafetyMeasureEntities = new ArrayList < > ( ) ;
for ( WorkTicketSafetyMeasureDto workTicketSafetyMeasureDto : safetyMeasuresList ) {
for ( WorkTicketSafetyMeasureEntity workTicketSafetyMeasureDto : safetyMeasuresList ) {
WorkTicketSafetyMeasureEntity workTicketSafetyMeasureEntity = BeanUtil . copyProperties ( workTicketSafetyMeasureDto , WorkTicketSafetyMeasureEntity . class ) ;
WorkTicketSafetyMeasureEntity workTicketSafetyMeasureEntity = BeanUtil . copyProperties ( workTicketSafetyMeasureDto , WorkTicketSafetyMeasureEntity . class ) ;
workTicketSafetyMeasureEntities . add ( workTicketSafetyMeasureEntity ) ;
workTicketSafetyMeasureEntities . add ( workTicketSafetyMeasureEntity ) ;
}
}
@ -373,8 +545,8 @@ public class TicketProcessServiceImpl implements TicketProcessService {
//负责人确认时间
//负责人确认时间
//workTicket.setConfirmDateTime(workTicketVo.getWorkTicket().getConfirmDateTime());
//workTicket.setConfirmDateTime(workTicketVo.getWorkTicket().getConfirmDateTime());
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASUR E. getStatus ( ) ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . LICENC E. getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASUR E. getDescription ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . LICENC E. getDescription ( ) ) ;
//更新状态值
//更新状态值
workTicketInfoService . updateById ( workTicket ) ;
workTicketInfoService . updateById ( workTicket ) ;
}
}
@ -391,8 +563,6 @@ public class TicketProcessServiceImpl implements TicketProcessService {
//值班负责人
//值班负责人
workTicket . setWatchPrincipal ( workTicketVo . getWorkTicket ( ) . getPrincipal ( ) ) ;
workTicket . setWatchPrincipal ( workTicketVo . getWorkTicket ( ) . getPrincipal ( ) ) ;
workTicket . setWatchPrincipalEndTime ( workTicketVo . getWorkTicket ( ) . getWatchPrincipalEndTime ( ) ) ;
workTicket . setWatchPrincipalEndTime ( workTicketVo . getWorkTicket ( ) . getWatchPrincipalEndTime ( ) ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getStatus ( ) ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getDescription ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . PRINCIPAL_CONFIRM_MEASURE . getDescription ( ) ) ;
//更新状态值
//更新状态值
@ -420,9 +590,9 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* /
* /
//@Transactional(rollbackFor = Exception.class)
//@Transactional(rollbackFor = Exception.class)
public void sign ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
public void sign ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
WorkTicketInfoEntity workTicketInfoEntity = workTicketVo . getWorkTicket ( ) ;
//更新状态值
//更新状态值
WorkTicketInfoEntity workTicketInfoEntity = new WorkTicketInfoEntity ( ) ;
workTicketInfoEntity . setStatus ( FlowWorkTicketConstants . RECEIVE . getStatus ( ) ) ;
workTicketInfoEntity . setFlowStatus ( FlowWorkTicketConstants . RECEIVE . getStatus ( ) ) ;
workTicketInfoEntity . setFlowStatus ( FlowWorkTicketConstants . RECEIVE . getStatus ( ) ) ;
workTicketInfoEntity . setFlowDescription ( FlowWorkTicketConstants . RECEIVE . getDescription ( ) ) ;
workTicketInfoEntity . setFlowDescription ( FlowWorkTicketConstants . RECEIVE . getDescription ( ) ) ;
workTicketInfoEntity . setSignerDateTime ( workTicketVo . getWorkTicket ( ) . getSignerDateTime ( ) ) ;
workTicketInfoEntity . setSignerDateTime ( workTicketVo . getWorkTicket ( ) . getSignerDateTime ( ) ) ;
@ -436,10 +606,11 @@ public class TicketProcessServiceImpl implements TicketProcessService {
private void make ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
private void make ( ProcessWorkFlowResponse response , WorkTicketVo workTicketVo ) {
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
workTicket . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
workTicket . setProcessInstanceId ( response . getProcessInstanceId ( ) ) ;
workTicket . setStatus ( FlowWorkTicketConstants . SIGN . getStatus ( ) ) ;
workTicket . setFlowStatus ( FlowWorkTicketConstants . SIGN . getStatus ( ) ) ;
workTicket . setFlowDescription ( FlowWorkTicketConstants . SIGN . getDescription ( ) ) ;
//保存工作流实例ID
//保存工作流实例ID
workTicketInfoService . update ( Wrappers . < WorkTicketInfoEntity > lambdaUpdate ( ) .
workTicketInfoService . updateById ( workTicket ) ;
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 ) ;
this . returnTicket ( workTicketVo ) ;
}
}
@ -477,41 +648,31 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* @param newFirstWorkTicketFlowKey
* @param newFirstWorkTicketFlowKey
* @param workTicketVo
* @param workTicketVo
* /
* /
private void
private void dealProcess ( String newFirstWorkTicketFlowKey , WorkTicketVo workTicketVo ) {
dealProcess ( String newFirstWorkTicketFlowKey , WorkTicketVo workTicketVo ) {
//若为线下工作票 则无需开启工作流
//若为线下工作票 则无需开启工作流
Integer status = WorkTicketConstants . FirstWorkTicketStatusEnum . SIGN . getStatus ( ) ;
Integer status = WorkTicketConstants . FirstWorkTicketStatusEnum . SIGN . getStatus ( ) ;
if ( status . intValue ( ) ! = workTicketVo . getWorkTicket ( ) . getStatus ( ) . intValue ( ) ) {
if ( status . intValue ( ) ! = workTicketVo . getWorkTicket ( ) . getFlow Status ( ) . intValue ( ) ) {
return ;
return ;
}
}
log . info ( "租户Id:{}" , AuthUtil . getTenantId ( ) ) ;
log . info ( "租户Id:{}" , AuthUtil . getTenantId ( ) ) ;
log . info ( "用户部门Id: {}" , AuthUtil . getUser ( ) . getDeptId ( ) ) ;
log . info ( "用户部门Id: {}" , AuthUtil . getUser ( ) . getDeptId ( ) ) ;
log . info ( "用户Id: {}" , AuthUtil . getUserId ( ) ) ;
log . info ( "用户Id: {}" , AuthUtil . getUserId ( ) ) ;
//获取签发人角色下的人员
//获取签发人角色下的人员
R < List < User > > listR = userClient . relationUserListByRoleAlias ( AuthUtil . getTenantId ( ) , Long . parseLong ( AuthUtil . getUser ( ) . getDeptId ( ) ) , TicketConstants . SIGNER_ROLE ) ;
R < List < User > > listR = userClient . relationUserListByRoleAlias ( AuthUtil . getTenantId ( ) , Long . parseLong ( AuthUtil . getUser ( ) . getDeptId ( ) ) , TicketConstants . SIGNER_ROLE ) ;
if ( ! listR . isSuccess ( ) | | CollectionUtil . isEmpty ( listR . getData ( ) ) ) {
if ( ! listR . isSuccess ( ) | | CollectionUtil . isEmpty ( listR . getData ( ) ) ) {
throw new ServiceException ( "工作票签发人角色下未查询到相关人员" ) ;
throw new ServiceException ( "工作票签发人角色下未查询到相关人员" ) ;
}
}
log . info ( "获取签发人角色下的人员: {}" , listR . getData ( ) ) ;
log . info ( "获取签发人角色下的人员: {}" , listR . getData ( ) ) ;
Map < String , Object > params = new HashMap < > ( 4 ) ;
Map < String , Object > params = new HashMap < > ( 4 ) ;
params . put ( "workTicketVo" , workTicketVo ) ;
params . put ( "workTicketVo" , workTicketVo ) ;
//已开启流程
workTicketVo . setIsState ( true ) ;
log . info ( "获取表单的数据: {}" , workTicketVo ) ;
R < BladeFlow > processInstanceContainNameByKey = flowClient . startProcessInstanceContainNameByKey ( newFirstWorkTicketFlowKey , String . valueOf ( workTicketVo . getWorkTicket ( ) . getId ( ) ) , workTicketVo . getWorkTicket ( ) . getWorkContent ( ) , params ) ;
R < BladeFlow > processInstanceContainNameByKey = flowClient . startProcessInstanceContainNameByKey ( newFirstWorkTicketFlowKey , String . valueOf ( workTicketVo . getWorkTicket ( ) . getId ( ) ) , workTicketVo . getWorkTicket ( ) . getWorkContent ( ) , params ) ;
if ( ! processInstanceContainNameByKey . isSuccess ( ) & & processInstanceContainNameByKey . getData ( ) = = null ) {
if ( ! processInstanceContainNameByKey . isSuccess ( ) & & processInstanceContainNameByKey . getData ( ) = = null ) {
throw new ServiceException ( "启动流程失败..." ) ;
throw new ServiceException ( "启动流程失败..." ) ;
}
}
//获取BladeFlow 数据库
BladeFlow bladeFlow = processInstanceContainNameByKey . getData ( ) ;
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 ) ;
}
}
@ -521,15 +682,14 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* @param workTicketContentDtoList
* @param workTicketContentDtoList
* @param workTicketInfoEntity
* @param workTicketInfoEntity
* /
* /
private void saveWorkTicketContentDto ( List < WorkTicketContentDto > workTicketContentDtoList , WorkTicketInfoEntity workTicketInfoEntity ) {
private void saveWorkTicketContentDto ( List < WorkTicketContentEntity > workTicketContentDtoList , WorkTicketInfoEntity workTicketInfoEntity ) {
if ( CollectionUtils . isEmpty ( workTicketContentDtoList ) ) {
if ( CollectionUtils . isEmpty ( workTicketContentDtoList ) ) {
return ;
return ;
}
}
List < WorkTicketContentEntity > contentEntities = workTicketContentDtoList . stream ( ) . map ( contentDto - > {
List < WorkTicketContentEntity > contentEntities = workTicketContentDtoList . stream ( ) . map ( contentDto - > {
WorkTicketContentEntity contentEntity = BeanUtil . copy ( contentDto , WorkTicketContentEntity . class ) ;
contentDto . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
contentEntity . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
contentDto . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
contentEntity . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
return contentDto ;
return contentEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
} ) . collect ( Collectors . toList ( ) ) ;
boolean savedBatch = contentService . saveBatch ( contentEntities ) ;
boolean savedBatch = contentService . saveBatch ( contentEntities ) ;
if ( ! savedBatch ) {
if ( ! savedBatch ) {
@ -545,16 +705,16 @@ public class TicketProcessServiceImpl implements TicketProcessService {
* @param safetyMeasuresList
* @param safetyMeasuresList
* @param workTicketInfoEntity
* @param workTicketInfoEntity
* /
* /
private void saveSafetyMeasures ( List < WorkTicketSafetyMeasureDto > safetyMeasuresList , WorkTicketInfoEntity workTicketInfoEntity ) {
private void saveSafetyMeasures ( List < WorkTicketSafetyMeasureEntity > safetyMeasuresList , WorkTicketInfoEntity workTicketInfoEntity ) {
if ( CollectionUtil . isEmpty ( safetyMeasuresList ) ) {
if ( CollectionUtil . isEmpty ( safetyMeasuresList ) ) {
return ;
return ;
}
}
log . info ( "获取安全措施的数据:{}" , safetyMeasuresList ) ;
List < WorkTicketSafetyMeasureEntity > measureEntityList = safetyMeasuresList . stream ( ) . map ( measure - > {
List < WorkTicketSafetyMeasureEntity > measureEntityList = safetyMeasuresList . stream ( ) . map ( measure - > {
WorkTicketSafetyMeasureEntity measureEntity = BeanUtil . copy ( measure , WorkTicketSafetyMeasureEntity . class ) ;
measure . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
measureEntity . setTicketId ( workTicketInfoEntity . getId ( ) ) ;
measure . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
measureEntity . setCreateDept ( workTicketInfoEntity . getCreateDept ( ) ) ;
measure . setCreateUser ( workTicketInfoEntity . getCreateUser ( ) ) ;
measureEntity . setCreateUser ( workTicketInfoEntity . getCreateUser ( ) ) ;
return measure ;
return measureEntity ;
} ) . collect ( Collectors . toList ( ) ) ;
} ) . collect ( Collectors . toList ( ) ) ;
boolean savedBatch = workTicketSafetyMeasureService . saveBatch ( measureEntityList ) ;
boolean savedBatch = workTicketSafetyMeasureService . saveBatch ( measureEntityList ) ;
if ( ! savedBatch ) {
if ( ! savedBatch ) {
@ -630,4 +790,109 @@ public class TicketProcessServiceImpl implements TicketProcessService {
return stringJoiner . toString ( ) ;
return stringJoiner . toString ( ) ;
}
}
/ * *
* 预览
*
* @param ticketType
* @param ticketId
* /
@Override
public void preview ( String ticketType , Long ticketId ) {
WorkTicketVo workTicketVo = ticketInfoService . selectDetailsById ( ticketId ) ;
//将查询的数据转换为map
Map < String , Object > workTicketInfoMap = this . convertMap ( workTicketVo ) ;
String fileName = TicketConstants . WordFileNameEnum . getFileNameByType ( ticketType ) + PdfUtils . XLSX_SUFFIX ;
log . info ( "工作票模板为:{}" , fileName ) ;
TemplateExportParams templateExportParams = new TemplateExportParams ( "template/" + fileName , true ) ;
Workbook workbook = null ;
try {
workbook = ExcelUtil . getWorkbook ( templateExportParams , workTicketInfoMap ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
//上传xlsx至服务器
try {
ExcelUtil . upload ( workbook , xlsSavePath , workTicketVo . getWorkTicket ( ) . getWorkContent ( ) + PdfUtils . XLSX_SUFFIX ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
//将xlsx文件转换为pdf并保存
String pdfFileName = workTicketVo . getWorkTicket ( ) . getWorkContent ( ) + PdfUtils . PDF_SUFFIX ;
String xlsFileName = workTicketVo . getWorkTicket ( ) . getWorkContent ( ) + PdfUtils . XLSX_SUFFIX ;
PdfUtils . convertPdf ( xlsSavePath , xlsFileName , pdfSavePath , pdfFileName ) ;
String savePath = pdfSavePath + pdfFileName ;
// 设置response参数,可以打开下载页面
ServletRequestAttributes servletRequestAttributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
HttpServletResponse response = servletRequestAttributes . getResponse ( ) ;
PdfUtils . readPdf ( response , savePath ) ;
}
//封装map 转换 excel导出
private Map < String , Object > convertMap ( WorkTicketVo workTicketVo ) {
Map < String , Object > result = new HashMap < > ( ) ;
WorkTicketInfoEntity workTicket = workTicketVo . getWorkTicket ( ) ;
//1. 工作对象
Map < String , Object > workTicketInfoMap = PdfUtils . objectToMap ( workTicket ) ;
result . putAll ( workTicketInfoMap ) ;
//2. 安全措施
List < WorkTicketSafetyMeasureEntity > safetyMeasuresList = workTicketVo . getSafetyMeasuresList ( ) ;
if ( CollectionUtils . isNotEmpty ( safetyMeasuresList ) ) {
Map < String , List < WorkTicketSafetyMeasureEntity > > measureMap = safetyMeasuresList . stream ( )
. collect ( Collectors . groupingBy ( WorkTicketSafetyMeasureEntity : : getType ) ) ;
Arrays . stream ( WorkTicketConstants . WorkTicketMeasureTypeEnum . class . getEnumConstants ( ) ) . forEach ( measureEnum - > {
if ( CollectionUtil . isNotEmpty ( measureMap . get ( measureEnum . getType ( ) ) ) ) {
List < Map < String , Object > > mapList = measureMap . get ( measureEnum . getType ( ) ) . stream ( ) . map ( measureVO - > {
Map < String , Object > map = PdfUtils . objectToMap ( measureVO ) ;
map . put ( "safetyMeasure" , ObjectUtil . isNotEmpty ( map . get ( "measure" ) ) ? map . get ( "measure" ) : null ) ;
String status = TicketConstants . SafetyMeasureStatusEnum . FINISH . getStatus ( ) . equals ( measureVO . getStatus ( ) ) ? TicketConstants . SafetyMeasureStatusEnum . FINISH . getDescribe ( ) : " " ;
map . put ( "status" , status ) ;
return map ;
} ) . collect ( Collectors . toList ( ) ) ;
workTicketInfoMap . put ( measureEnum . getConvertAttributes ( ) , mapList ) ;
} else {
workTicketInfoMap . put ( measureEnum . getConvertAttributes ( ) , new ArrayList < Map < String , String > > ( 1 ) ) ;
}
} ) ;
}
//3. 工作票工作任务组
List < WorkTicketContentEntity > workTicketContentDtoList = workTicketVo . getWorkTicketContentDtoList ( ) ;
if ( CollectionUtils . isNotEmpty ( workTicketContentDtoList ) ) {
result . put ( "workTicketContentDtoList" , workTicketContentDtoList ) ;
}
//4. 工作票延期
WorkTicketDelayEntity workTicketDelay = workTicketVo . getWorkTicketDelay ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketDelay ) ) {
result . putAll ( PdfUtils . objectToMap ( workTicketDelay ) ) ;
}
//5. 工作结束
WorkTicketFinish workTicketFinish = workTicketVo . getWorkTicketFinish ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketFinish ) ) {
result . putAll ( PdfUtils . objectToMap ( workTicketFinish ) ) ;
}
//5. 工作票负责人变更
WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo . getWorkTicketPrincipalChange ( ) ;
if ( ObjectUtils . isNotEmpty ( workTicketPrincipalChange ) ) {
result . putAll ( PdfUtils . objectToMap ( workTicketPrincipalChange ) ) ;
}
return result ;
}
/ * *
* 对象转map
* /
private static < T > Map < String , Object > parseObjectMap ( T target , Class clas ) {
return JSONObject . parseObject ( JSONObject . toJSONString ( target ) , Map . class ) ;
}
}
}