Commit 9564c3f9 authored by zhangsen's avatar zhangsen

安装告知工作流信息

parent 6770ab6c
...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.module.jg.api.dto.JgInstallationNoticeDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgInstallationNoticeDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice; import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
import netscape.javascript.JSObject;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Map; import java.util.Map;
...@@ -58,7 +59,7 @@ public interface IJgInstallationNoticeService extends IService<JgInstallationNot ...@@ -58,7 +59,7 @@ public interface IJgInstallationNoticeService extends IService<JgInstallationNot
* @param model 数据 * @param model 数据
* @param submitType 保存类型 * @param submitType 保存类型
*/ */
void saveNotice(String submitType, Map<String, JgInstallationNoticeDto> model, ReginParams reginParams); void saveNotice(String submitType, Map<String, JSObject> model, ReginParams reginParams);
/** /**
* 打印告知单 * 打印告知单
......
...@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService; ...@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
...@@ -46,7 +47,7 @@ public class JgInstallationNoticeController extends BaseController { ...@@ -46,7 +47,7 @@ public class JgInstallationNoticeController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/save") @PostMapping(value = "/save")
@ApiOperation(httpMethod = "POST", value = "新增安装告知", notes = "新增安装告知") @ApiOperation(httpMethod = "POST", value = "新增安装告知", notes = "新增安装告知")
public ResponseModel<String> save(@RequestParam String submitType, @RequestBody Map<String, JgInstallationNoticeDto> model) { public ResponseModel<String> save(@RequestParam String submitType, @RequestBody Map<String, JSObject> model) {
ReginParams reginParams = getSelectedOrgInfo(); ReginParams reginParams = getSelectedOrgInfo();
iJgInstallationNoticeService.saveNotice(submitType, model, reginParams); iJgInstallationNoticeService.saveNotice(submitType, model, reginParams);
......
package com.yeejoin.amos.boot.module.jg.biz.listener;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.systemctl.model.TaskV2Model;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener;
import javax.annotation.PostConstruct;
import java.util.List;
@Slf4j
@Component
public class PublicWorkFlowMessage extends EmqxListener {
@Autowired
protected EmqKeeper emqKeeper;
/**
* 创建任务主题
*/
public static final String WORKFLOW_TASK_CREATED = "workflow/task/created";
/**
* 执行完成任务主题
*/
public static final String WORKFLOW_TASK_COMPLETED = "workflow/task/completed";
// /**
// * 流程执行结束主题
// */
// public static final String WORKFLOW_PROCESS_COMPLETE = "workflow/process/complete";
@Autowired
private JgInstallationNoticeServiceImpl jgInstallationNoticeService;
@PostConstruct
void init() throws Exception {
emqKeeper.subscript(WORKFLOW_TASK_CREATED, 2, this);
emqKeeper.subscript(WORKFLOW_TASK_COMPLETED, 2, this);
// emqKeeper.subscript(WORKFLOW_PROCESS_COMPLETE, 2, this);
}
@Override
public void processMessage(String topic, MqttMessage message) throws Exception {
JSONObject messageObject = JSON.parseObject(new String(message.getPayload()));
String businessKey = messageObject.get("businessKey").toString();
String[] s = businessKey.split("_");
String businessId = s[0];
String type = s[1];
messageObject.put("businessId", businessId);
if (topic.equals(WORKFLOW_TASK_CREATED)) {
if ("installationNotice".equals(type)) {
jgInstallationNoticeService.updateByWorkFlow(messageObject);
}
} else if (topic.equals(WORKFLOW_TASK_COMPLETED)) {
if ("installationNotice".equals(type)) {
jgInstallationNoticeService.completeWorkFlow(messageObject);
}
}
}
}
...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.dao.mapper.DataDictionaryMapper; import com.yeejoin.amos.boot.biz.common.dao.mapper.DataDictionaryMapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary; import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
...@@ -40,6 +41,7 @@ import com.yeejoin.amos.feign.workflow.model.AjaxResult; ...@@ -40,6 +41,7 @@ import com.yeejoin.amos.feign.workflow.model.AjaxResult;
import com.yeejoin.amos.feign.workflow.model.TaskResultDTO; import com.yeejoin.amos.feign.workflow.model.TaskResultDTO;
import fr.opensagres.xdocreport.core.io.IOUtils; import fr.opensagres.xdocreport.core.io.IOUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -419,10 +421,10 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -419,10 +421,10 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
@Override @Override
@SuppressWarnings({"Duplicates", "rawtypes"}) @SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveNotice(String submitType, Map<String, JgInstallationNoticeDto> jgInstallationNoticeDtoMap, ReginParams reginParams) { public void saveNotice(String submitType, Map<String, JSObject> jgInstallationNoticeDtoMap, ReginParams reginParams) {
String[] taskName = new String[]{"流程结束"}; String[] taskName = new String[]{"流程结束"};
JgInstallationNoticeDto model = jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID); JgInstallationNoticeDto model = JSON.parseObject(jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID).toString(), JgInstallationNoticeDto.class);
// 字段转换 // 字段转换
convertField(model); convertField(model);
...@@ -444,66 +446,6 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -444,66 +446,6 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
throw new BadRequest("告知单生成失败!"); throw new BadRequest("告知单生成失败!");
} }
ArrayList<String> roleListFirst = new ArrayList<>();
ArrayList<String> roleListSecond = new ArrayList<>();
// 判断当前是否为提交
List<String> instanceIdList = new ArrayList<>();
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
// 发起流程
// ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
List<ActWorkflowStartDTO> list = new ArrayList<>();
for (int i = 0; i<deviceList.size() ; i++
) {
ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY);
dto.setBusinessKey(String.valueOf(i));
// dto.setCompleteFirstTask(true);
list.add(dto);
}
actWorkflowBatchDTO.setProcess(list);
try {
FeignClientResult result = Workflow.taskV2Client.startByVariableBatch(actWorkflowBatchDTO);
List<Object> returnList = (List<Object>) result.getResult();
for (Object obj :returnList
) {
JSONObject jsonObject = JSON.parseObject(JSONObject.toJSONString(obj));
String instanceId = jsonObject.getString("id");
instanceIdList.add(instanceId);
// 查询下节点任务
if(returnList.get(0).equals(obj)) {
getNext(roleListFirst, instanceId,taskName);
}
// 推动下一个节点
AjaxResult ajaxResult = Workflow.taskClient.getTask(instanceId);
JSONObject dataObject = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")));
String taskId = dataObject.getString("id");
//组装信息
TaskResultDTO dto = new TaskResultDTO();
dto.setResultCode("approvalStatus");
dto.setTaskId(taskId);
dto.setComment("");
HashMap<String, Object> map = new HashMap<>();
map.put("approvalStatus", "0");
dto.setVariable(map);
//执行流程
AjaxResult ajaxResult1 = null;
try {
ajaxResult1 = Workflow.taskClient.completeByTask(taskId, dto);
if (ajaxResult1.get("code").equals(200)) {
getNext(roleListSecond, instanceId,taskName);
} else {
log.error("提交失败");
}
} catch (Exception e) {
log.error("提交失败:{}", e);
}
}
} catch (Exception e) {
log.error("提交失败:{}", e);
}
}
List<JgInstallationNotice> list = new ArrayList<>(); List<JgInstallationNotice> list = new ArrayList<>();
List<JgInstallationNoticeEq> equipList = new ArrayList<>(); List<JgInstallationNoticeEq> equipList = new ArrayList<>();
...@@ -516,10 +458,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -516,10 +458,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
dto.setApplyNo(applyNo); dto.setApplyNo(applyNo);
dto.setNoticeDate(new Date()); dto.setNoticeDate(new Date());
if(SUBMIT_TYPE_FLOW.equals(submitType)) { if(SUBMIT_TYPE_FLOW.equals(submitType)) {
dto.setNextExecuteIds(String.join(",", roleListSecond));
dto.setInstanceStatus(String.join(",", roleListFirst));
dto.setPromoter(reginParams.getUserModel().getUserId()); dto.setPromoter(reginParams.getUserModel().getUserId());
dto.setStatus(taskName[0]); dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode()));
} }
dto.setInstallUnitName(reginParams.getCompany().getCompanyName()); dto.setInstallUnitName(reginParams.getCompany().getCompanyName());
dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode()); dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode());
...@@ -530,44 +470,59 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -530,44 +470,59 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
dto.setEquAddress(buffer.toString()); dto.setEquAddress(buffer.toString());
jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR"))); jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR")));
jgRelationEquip.setEquipTransferId(applyNo); jgRelationEquip.setEquipTransferId(applyNo);
if (!CollectionUtils.isEmpty(instanceIdList)) {
dto.setInstanceId(instanceIdList.get(i));
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
} else {
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode()));
}
list.add(dto); list.add(dto);
equipList.add(jgRelationEquip); equipList.add(jgRelationEquip);
}); });
jgInstallationNoticeMapper.insertBatchSomeColumn(list); jgInstallationNoticeMapper.insertBatchSomeColumn(list);
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
List<ActWorkflowStartDTO> workflowStartDTOS = new ArrayList<>();
list.forEach(item -> { list.forEach(item -> {
// 代办业务 if (SUBMIT_TYPE_FLOW.equals(submitType)) {
if(SUBMIT_TYPE_FLOW.equals(submitType)) { // 发起流程
TaskV2Model taskV2Model = new TaskV2Model(); ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
//获取待办任务执行人 dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY);
List<AgencyUserModel> userList = Privilege.agencyUserClient dto.setBusinessKey(item.getSequenceNbr() + "_" + "installationNotice");
.queryByRoleId(item.getNextExecuteIds(), null,Boolean.FALSE).getResult(); dto.setCompleteFirstTask(Boolean.TRUE);
List<String> userIds = userList.stream().map(AgencyUserModel::getUserId).collect(Collectors.toList()); workflowStartDTOS.add(dto);
taskV2Model.setExecuteUserIds(CollectionUtils.isEmpty(userIds)?"": String.join(",", userIds));
taskV2Model.setExtras(JSON.toJSONString(item));
taskV2Model.setRelationId(item.getInstanceId());
Map<String, Object> userOrgRoleMap = FeignUtil.remoteCall(() -> Privilege.userOrgRoleClient.getme());
List<String> userOrgRoleList = (List<String>) userOrgRoleMap.get("roleId");
String roleIds = String.join(",", userOrgRoleList);
taskV2Model.setTaskType("installNotice");
taskV2Model.setTaskTypeLabel("安装告知");
String url = getUrl(taskV2Model.getTaskType(), "look");
String format = String.format(url, item.getSequenceNbr(), item.getNextExecuteIds(), item.getNextExecuteIds(), item.getNoticeStatus(), item.getInstanceId());
taskV2Model.setRoutePath(format);
taskV2Model.setTaskTitle(item.getStatus());
taskV2Model.setTaskName(item.getStatus());
taskV2Model.setTaskStatus(FlowStatusEnum.TO_BE_PROCESSED.getCode());
taskV2Model.setTaskStatusLabel(FlowStatusEnum.TO_BE_PROCESSED.getName());
taskV2Model.setTaskCode(item.getApplyNo());
buildTaskModel(taskV2Model);
} }
}); });
try {
actWorkflowBatchDTO.setProcess(workflowStartDTOS);
Workflow.taskV2Client.startByVariableBatch(actWorkflowBatchDTO);
} catch (Exception e) {
log.error("提交失败:{}", e);
}
// list.forEach(item -> {
// // 代办业务
// if(SUBMIT_TYPE_FLOW.equals(submitType)) {
// TaskV2Model taskV2Model = new TaskV2Model();
// //获取待办任务执行人
// List<AgencyUserModel> userList = Privilege.agencyUserClient
// .queryByRoleId(item.getNextExecuteIds(), null,Boolean.FALSE).getResult();
// List<String> userIds = userList.stream().map(AgencyUserModel::getUserId).collect(Collectors.toList());
// taskV2Model.setExecuteUserIds(CollectionUtils.isEmpty(userIds)?"": String.join(",", userIds));
// taskV2Model.setExtras(JSON.toJSONString(item));
// taskV2Model.setRelationId(item.getInstanceId());
// Map<String, Object> userOrgRoleMap = FeignUtil.remoteCall(() -> Privilege.userOrgRoleClient.getme());
// List<String> userOrgRoleList = (List<String>) userOrgRoleMap.get("roleId");
// String roleIds = String.join(",", userOrgRoleList);
// taskV2Model.setTaskType("installNotice");
// taskV2Model.setTaskTypeLabel("安装告知");
// String url = getUrl(taskV2Model.getTaskType(), "look");
// String format = String.format(url, item.getSequenceNbr(), item.getNextExecuteIds(), item.getNextExecuteIds(), item.getNoticeStatus(), item.getInstanceId());
// taskV2Model.setRoutePath(format);
// taskV2Model.setTaskTitle(item.getStatus());
// taskV2Model.setTaskName(item.getStatus());
// taskV2Model.setTaskStatus(FlowStatusEnum.TO_BE_PROCESSED.getCode());
// taskV2Model.setTaskStatusLabel(FlowStatusEnum.TO_BE_PROCESSED.getName());
// taskV2Model.setTaskCode(item.getApplyNo());
// buildTaskModel(taskV2Model);
// }
// });
List<JgInstallationNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> { List<JgInstallationNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> {
List<JgInstallationNotice> collect = list.stream().filter(jgInstallationNotice -> jgRelationEquip.getEquipTransferId().equals(jgInstallationNotice.getApplyNo())).collect(Collectors.toList()); List<JgInstallationNotice> collect = list.stream().filter(jgInstallationNotice -> jgRelationEquip.getEquipTransferId().equals(jgInstallationNotice.getApplyNo())).collect(Collectors.toList());
...@@ -964,4 +919,51 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -964,4 +919,51 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
} }
return url; return url;
} }
public void updateByWorkFlow(JSONObject jsonObject) {
JgInstallationNotice jgInstallationNotice = this.getById(jsonObject.get("businessId").toString());
List<String> list = (List<String>) jsonObject.get("candidateGroups");
jgInstallationNotice.setInstanceId(jsonObject.get("processInstanceId").toString());
jgInstallationNotice.setNextExecuteIds(String.join(",", list));
jgInstallationNotice.setInstanceStatus(jgInstallationNotice.getInstanceStatus() + "," + String.join(",", list));
jgInstallationNotice.setStatus(jsonObject.get("nodeName").toString());
this.updateById(jgInstallationNotice);
// 代办业务
TaskV2Model taskV2Model = new TaskV2Model();
//获取待办任务执行人
List<AgencyUserModel> userList = Privilege.agencyUserClient
.queryByRoleId(jgInstallationNotice.getNextExecuteIds(), null,Boolean.FALSE).getResult();
List<String> userIds = userList.stream().map(AgencyUserModel::getUserId).collect(Collectors.toList());
taskV2Model.setExecuteUserIds(CollectionUtils.isEmpty(userIds)?"": String.join(",", userIds));
taskV2Model.setExtras(JSON.toJSONString(jgInstallationNotice));
taskV2Model.setRelationId(jgInstallationNotice.getInstanceId());
taskV2Model.setTaskType("installNotice");
taskV2Model.setTaskTypeLabel("安装告知");
String url = getUrl(taskV2Model.getTaskType(), "look");
String format = String.format(url, jgInstallationNotice.getSequenceNbr(), jgInstallationNotice.getNextExecuteIds(), jgInstallationNotice.getNextExecuteIds(), jgInstallationNotice.getNoticeStatus(), jgInstallationNotice.getInstanceId());
taskV2Model.setRoutePath(format);
taskV2Model.setTaskTitle(jgInstallationNotice.getStatus());
taskV2Model.setTaskName(jgInstallationNotice.getStatus());
taskV2Model.setTaskStatus(FlowStatusEnum.TO_BE_PROCESSED.getCode());
taskV2Model.setTaskStatusLabel(FlowStatusEnum.TO_BE_PROCESSED.getName());
taskV2Model.setTaskCode(jgInstallationNotice.getApplyNo());
buildTaskModel(taskV2Model);
}
public void completeWorkFlow(JSONObject jsonObject) {
JgInstallationNotice jgInstallationNotice = this.getById(jsonObject.get("businessId").toString());
List<TaskV2Model> result =Systemctl.taskV2Client.selectListByRelationId(jgInstallationNotice.getInstanceId()).getResult();
TaskV2Model model = result.stream().sorted((r1, r2) -> r2.getCreateDate().compareTo(r1.getCreateDate())) // 按时间降序排序
.findFirst()
.orElse(null);
// model.setTaskStatus(Integer.valueOf(jsonObject.get("nodeName").toString()));
model.setRoutePath(model.getRoutePath().replace("nextExecuteIds", "nextExecuteIdsOld"));
model.setTaskStatusLabel(jsonObject.get("nodeName").toString());
model.setEndDate(new Date());
model.setFinishStatus(Boolean.TRUE);
JSONObject userJson = JSON.parseObject(jsonObject.get("user").toString());
model.setEndUserId(userJson.get("userId").toString());
Systemctl.taskV2Client.update(model, model.getSequenceNbr());
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment