工作流审批人默认时间和同意或拒绝的备注加到表单里面
This commit is contained in:
parent
ae8043f1e9
commit
1adf355c3d
@ -4,8 +4,38 @@ package com.wflow.service;
|
|||||||
* 流程里面的监听器Service
|
* 流程里面的监听器Service
|
||||||
*/
|
*/
|
||||||
public interface CustomListenService {
|
public interface CustomListenService {
|
||||||
|
/**
|
||||||
|
* 更新表单
|
||||||
|
*
|
||||||
|
* @param instanceId
|
||||||
|
* @param fieldId
|
||||||
|
* @param val
|
||||||
|
*/
|
||||||
void updateFormData(String instanceId, String fieldId, String val);
|
void updateFormData(String instanceId, String fieldId, String val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新表单时间
|
||||||
|
*
|
||||||
|
* @param instanceId
|
||||||
|
* @param fieldId
|
||||||
|
*/
|
||||||
|
void updateFormDataNow(String instanceId, String fieldId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新表单时间(指定时间)
|
||||||
|
*
|
||||||
|
* @param instanceId
|
||||||
|
* @param fieldId
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
void updateFormDataNow(String instanceId, String fieldId, Integer type);
|
void updateFormDataNow(String instanceId, String fieldId, Integer type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同意或拒绝的备注加到表单里面
|
||||||
|
*
|
||||||
|
* @param instanceId
|
||||||
|
* @param fieldId
|
||||||
|
*/
|
||||||
|
void addFormDataFromApprove(String instanceId, String fieldId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,27 @@
|
|||||||
package com.wflow.service.impl;
|
package com.wflow.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.wflow.bean.entity.WflowFormData;
|
import com.wflow.bean.entity.WflowFormData;
|
||||||
|
import com.wflow.bean.entity.WflowModelHistorys;
|
||||||
import com.wflow.mapper.WflowFormDataMapper;
|
import com.wflow.mapper.WflowFormDataMapper;
|
||||||
|
import com.wflow.mapper.WflowModelHistorysMapper;
|
||||||
import com.wflow.service.CustomListenService;
|
import com.wflow.service.CustomListenService;
|
||||||
import lombok.val;
|
import org.flowable.engine.HistoryService;
|
||||||
import org.flowable.engine.RuntimeService;
|
import org.flowable.engine.RuntimeService;
|
||||||
|
import org.flowable.engine.TaskService;
|
||||||
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
|
import org.flowable.engine.task.Comment;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service("customListenService")
|
@Service("customListenService")
|
||||||
public class CustomListenServiceImpl implements CustomListenService {
|
public class CustomListenServiceImpl implements CustomListenService {
|
||||||
@ -23,6 +31,13 @@ public class CustomListenServiceImpl implements CustomListenService {
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private WflowFormDataMapper formDataMapper;
|
private WflowFormDataMapper formDataMapper;
|
||||||
|
@Autowired
|
||||||
|
private HistoryService historyService;
|
||||||
|
@Lazy
|
||||||
|
@Autowired
|
||||||
|
private WflowModelHistorysMapper modelHistorysMapper;
|
||||||
|
@Autowired
|
||||||
|
private TaskService taskService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFormData(String instanceId, String fieldId, String val) {
|
public void updateFormData(String instanceId, String fieldId, String val) {
|
||||||
@ -38,27 +53,109 @@ public class CustomListenServiceImpl implements CustomListenService {
|
|||||||
runtimeService.setVariables(instanceId, dataMap);
|
runtimeService.setVariables(instanceId, dataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFormDataNow(String instanceId, String fieldId) {
|
||||||
|
List<String> split = StrUtil.split(fieldId, ",");
|
||||||
|
String format = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
//先查实例,然后判断是子流程还是主流程
|
||||||
|
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
|
||||||
|
.processInstanceId(instanceId).singleResult();
|
||||||
|
//是否是子流程
|
||||||
|
boolean isSub = StrUtil.isNotBlank(instance.getSuperProcessInstanceId());
|
||||||
|
HistoricProcessInstance mainInst = isSub ? null : instance;
|
||||||
|
if (isSub) {
|
||||||
|
//查出主流程表单数据
|
||||||
|
mainInst = historyService.createHistoricProcessInstanceQuery()
|
||||||
|
.processInstanceId(instance.getSuperProcessInstanceId()).singleResult();
|
||||||
|
}
|
||||||
|
//搜索当前版本流程的配置
|
||||||
|
WflowModelHistorys modelHistory = modelHistorysMapper.selectOne(new LambdaQueryWrapper<>(WflowModelHistorys.builder()
|
||||||
|
.processDefId(mainInst.getProcessDefinitionId()).version(mainInst.getProcessDefinitionVersion()).build()));
|
||||||
|
String formItems = modelHistory.getFormItems();
|
||||||
|
JSONArray root = JSON.parseArray(formItems);
|
||||||
|
for (String fid : split) {
|
||||||
|
boolean find = false;
|
||||||
|
for (int i = 0; i < root.size(); i++) {
|
||||||
|
JSONObject jo = root.getJSONObject(i);
|
||||||
|
String valueType = jo.getString("valueType");
|
||||||
|
if (Objects.equals(valueType, "Array")) {
|
||||||
|
JSONArray items = jo.getJSONObject("props").getJSONArray("items");
|
||||||
|
for (int j = 0; j < items.size(); j++) {
|
||||||
|
JSONObject jo1 = items.getJSONObject(j);
|
||||||
|
String valueType1 = jo.getString("valueType");
|
||||||
|
if (Objects.equals(valueType1, "Date")) {
|
||||||
|
if (jo1.getString("id").equals(fid)) {
|
||||||
|
find = true;
|
||||||
|
format = jo1.getJSONObject("props").getString("format");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String valueType1 = jo.getString("valueType");
|
||||||
|
if (Objects.equals(valueType1, "Date")) {
|
||||||
|
if (jo.getString("id").equals(fid)) {
|
||||||
|
find = true;
|
||||||
|
format = jo.getJSONObject("props").getString("format");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (find) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String value = DateUtil.format(new Date(), format);
|
||||||
|
WflowFormData data = new WflowFormData();
|
||||||
|
data.setInstanceId(instanceId);
|
||||||
|
data.setFieldId(fid);
|
||||||
|
data.setFieldValue(value);
|
||||||
|
formDataMapper.update(data, new LambdaQueryWrapper<WflowFormData>()
|
||||||
|
.eq(WflowFormData::getInstanceId, instanceId)
|
||||||
|
.eq(WflowFormData::getFieldId, fid));
|
||||||
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
|
dataMap.put(fid, value);
|
||||||
|
runtimeService.setVariables(instanceId, dataMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFormDataNow(String instanceId, String fieldId, Integer type) {
|
public void updateFormDataNow(String instanceId, String fieldId, Integer type) {
|
||||||
|
List<String> split = StrUtil.split(fieldId, ",");
|
||||||
String val;
|
String val;
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
val = DateUtil.format(date,"yyyy-MM-dd");
|
val = DateUtil.format(date, "yyyy-MM-dd");
|
||||||
} else if (type == 2){
|
} else if (type == 2) {
|
||||||
val = DateUtil.format(date,"yyyy-MM-dd HH:mm");
|
val = DateUtil.format(date, "yyyy-MM-dd HH:mm");
|
||||||
} else {
|
} else {
|
||||||
val = DateUtil.format(date,"yyyy-MM-dd HH:mm:ss");
|
val = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
//先查实例,然后判断是子流程还是主流程
|
||||||
|
for (String fid : split) {
|
||||||
|
WflowFormData data = new WflowFormData();
|
||||||
|
data.setInstanceId(instanceId);
|
||||||
|
data.setFieldId(fid);
|
||||||
|
data.setFieldValue(val);
|
||||||
|
formDataMapper.update(data, new LambdaQueryWrapper<WflowFormData>()
|
||||||
|
.eq(WflowFormData::getInstanceId, instanceId)
|
||||||
|
.eq(WflowFormData::getFieldId, fid));
|
||||||
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
|
dataMap.put(fid, val);
|
||||||
|
runtimeService.setVariables(instanceId, dataMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFormDataFromApprove(String instanceId, String fieldId) {
|
||||||
|
List<Comment> processInstanceComments = taskService.getProcessInstanceComments(instanceId);
|
||||||
|
if (CollUtil.isNotEmpty(processInstanceComments)) {
|
||||||
|
Comment comment = processInstanceComments.get(0);
|
||||||
|
String text = JSON.parseObject(comment.getFullMessage()).getString("text");
|
||||||
|
if (StrUtil.isNotBlank(text)) {
|
||||||
|
this.updateFormData(instanceId, fieldId, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WflowFormData data = new WflowFormData();
|
|
||||||
data.setInstanceId(instanceId);
|
|
||||||
data.setFieldId(fieldId);
|
|
||||||
data.setFieldValue(val);
|
|
||||||
formDataMapper.update(data, new LambdaQueryWrapper<WflowFormData>()
|
|
||||||
.eq(WflowFormData::getInstanceId, instanceId)
|
|
||||||
.eq(WflowFormData::getFieldId, fieldId));
|
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
|
||||||
dataMap.put(fieldId, val);
|
|
||||||
runtimeService.setVariables(instanceId, dataMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user