package com.dl.workflow.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.dl.common.core.domain.PageQuery;
|
import com.dl.common.core.page.TableDataInfo;
|
import com.dl.common.helper.LoginHelper;
|
import com.dl.common.utils.StringUtils;
|
import com.dl.workflow.domain.WfCopy;
|
import com.dl.workflow.domain.bo.WfCopyBo;
|
import com.dl.workflow.domain.bo.WfTaskBo;
|
import com.dl.workflow.domain.vo.WfCopyVo;
|
import com.dl.workflow.mapper.WfCopyMapper;
|
import com.dl.workflow.service.IWfCopyService;
|
import lombok.RequiredArgsConstructor;
|
import org.flowable.engine.HistoryService;
|
import org.flowable.engine.history.HistoricProcessInstance;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 流程抄送Service业务层处理
|
*
|
* @author KonBAI
|
* @date 2022-05-19
|
*/
|
@RequiredArgsConstructor
|
@Service
|
public class WfCopyServiceImpl implements IWfCopyService {
|
|
private final WfCopyMapper baseMapper;
|
|
private final HistoryService historyService;
|
|
/**
|
* 查询流程抄送
|
*
|
* @param copyId 流程抄送主键
|
* @return 流程抄送
|
*/
|
@Override
|
public WfCopyVo queryById(Long copyId){
|
return baseMapper.selectVoById(copyId);
|
}
|
|
/**
|
* 查询流程抄送列表
|
*
|
* @param bo 流程抄送
|
* @return 流程抄送
|
*/
|
@Override
|
public TableDataInfo<WfCopyVo> selectPageList(WfCopyBo bo, PageQuery pageQuery) {
|
LambdaQueryWrapper<WfCopy> lqw = buildQueryWrapper(bo);
|
lqw.orderByDesc(WfCopy::getCreateTime);
|
Page<WfCopyVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
return TableDataInfo.build(result);
|
}
|
|
/**
|
* 查询流程抄送列表
|
*
|
* @param bo 流程抄送
|
* @return 流程抄送
|
*/
|
@Override
|
public List<WfCopyVo> selectList(WfCopyBo bo) {
|
LambdaQueryWrapper<WfCopy> lqw = buildQueryWrapper(bo);
|
return baseMapper.selectVoList(lqw);
|
}
|
|
private LambdaQueryWrapper<WfCopy> buildQueryWrapper(WfCopyBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<WfCopy> lqw = Wrappers.lambdaQuery();
|
lqw.eq(bo.getUserId() != null, WfCopy::getUserId, bo.getUserId());
|
lqw.like(StringUtils.isNotBlank(bo.getProcessName()), WfCopy::getProcessName, bo.getProcessName());
|
lqw.like(StringUtils.isNotBlank(bo.getOriginatorName()), WfCopy::getOriginatorName, bo.getOriginatorName());
|
return lqw;
|
}
|
|
@Override
|
public Boolean makeCopy(WfTaskBo taskBo) {
|
if (StringUtils.isBlank(taskBo.getCopyUserIds())) {
|
// 若抄送用户为空,则不需要处理,返回成功
|
return true;
|
}
|
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
|
.processInstanceId(taskBo.getProcInsId()).singleResult();
|
String[] ids = taskBo.getCopyUserIds().split(",");
|
List<WfCopy> copyList = new ArrayList<>(ids.length);
|
String originatorId = LoginHelper.getUserId();
|
String originatorName = LoginHelper.getNickName();
|
String title = historicProcessInstance.getProcessDefinitionName() + "-" + taskBo.getTaskName();
|
for (String id : ids) {
|
// Long userId = Long.valueOf(id);
|
WfCopy copy = new WfCopy();
|
copy.setTitle(title);
|
copy.setProcessId(historicProcessInstance.getProcessDefinitionId());
|
copy.setProcessName(historicProcessInstance.getProcessDefinitionName());
|
copy.setDeploymentId(historicProcessInstance.getDeploymentId());
|
copy.setInstanceId(taskBo.getProcInsId());
|
copy.setTaskId(taskBo.getTaskId());
|
copy.setUserId(id);
|
copy.setOriginatorId(originatorId);
|
copy.setOriginatorName(originatorName);
|
copyList.add(copy);
|
}
|
return baseMapper.insertBatch(copyList);
|
}
|
}
|