/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package com.vci.ubcs.flow.engine.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.vci.ubcs.flow.core.entity.BladeFlow; import com.vci.ubcs.flow.core.enums.FlowModeEnum; import com.vci.ubcs.flow.core.utils.TaskUtil; import com.vci.ubcs.flow.engine.constant.FlowEngineConstant; import com.vci.ubcs.flow.engine.entity.*; import com.vci.ubcs.flow.engine.mapper.FlowMapper; import com.vci.ubcs.flow.engine.mapper.FlowTaskUserMapper; import com.vci.ubcs.flow.engine.mapper.ProcessTemplateMapper; import com.vci.ubcs.flow.engine.service.FlowEngineService; import com.vci.ubcs.flow.engine.service.FlowTaskUserService; import com.vci.ubcs.flow.engine.utils.FlowCache; import com.vci.ubcs.system.user.cache.UserCache; import com.vci.ubcs.system.user.entity.User; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.Process; import org.flowable.common.engine.impl.util.IoUtil; import org.flowable.common.engine.impl.util.io.StringStreamSource; import org.flowable.editor.language.json.converter.BpmnJsonConverter; import org.flowable.engine.*; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl; import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl; import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.repository.ProcessDefinitionQuery; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstanceQuery; import org.flowable.engine.task.Comment; import org.flowable.image.ProcessDiagramGenerator; import org.springblade.core.launch.constant.FlowConstant; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Condition; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.FileUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; import java.util.*; /** * 工作流服务实现类 * * @author wang1 */ @Slf4j @Service @AllArgsConstructor public class FlowTaskUserServiceImpl extends ServiceImpl implements FlowTaskUserService { private FlowEngineService flowEngineService; private FlowTaskUserMapper flowTaskUserMapper; private ProcessTemplateMapper processTemplateMapper; /** * 查询当前登陆人对这个流程的taskUser * @param type ProcessTemplateTypeEnum * @return */ @Override public Object getUser(String type,String templateId){ Map kv = new HashMap(); //根据type查询top流程数据 Map m = new HashMap<>(); m.put("button_type_key", type); m.put("template_id", templateId); List processTemplates = processTemplateMapper.selectByMap(m); if(processTemplates.size()==0){ throw new ServiceException("主题库定义-模板管理-流程模板,没有绑定流程!"); } ProcessTemplate processTemplate = processTemplates.get(0); kv.put("flow",processTemplate); //top收藏部分数据 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("CREATED_BY", TaskUtil.getTaskUser()); List flowTaskUsers = baseMapper.selectList(queryWrapper); List cl = new ArrayList<>(); Map> nameMap = new HashMap<>(); for(FlowTaskUser flowTaskUser:flowTaskUsers){ String name = flowTaskUser.getName();//收藏名称 List flowTaskUserListo = null; if(nameMap.get(name)==null){ flowTaskUserListo = new ArrayList<>(); }else { flowTaskUserListo = nameMap.get(name); } flowTaskUserListo.add(flowTaskUser); nameMap.put(name,flowTaskUserListo); } for (String name:nameMap.keySet()){ FlowTaskUserC flowTaskUserCR = new FlowTaskUserC(); flowTaskUserCR.setName(name);//收藏名称 flowTaskUserCR.setModelKey(nameMap.get(name).get(0).getModelKey()); flowTaskUserCR.setModelName(nameMap.get(name).get(0).getModelName()); flowTaskUserCR.setFlowTaskUsers(nameMap.get(name)); cl.add(flowTaskUserCR); } kv.put("collect",cl); //数据节点数据 List> tl = flowEngineService.getNodeByFlowableKey(processTemplate.getModelKey()); kv.put("user",tl); return kv; } @Override public void saveOrUpdateUser(FlowTaskUserC flowTaskUserC){ List flowTaskUsers = flowTaskUserC.getFlowTaskUsers(); String name = flowTaskUserC.getName();//收藏名称 //新增情况下验证收藏名称不重复 Map m = new HashMap<>(); m.put("name", name); m.put("created_by", TaskUtil.getTaskUser()); QueryWrapper q = Condition.getQueryWrapper(m, FlowTaskUser.class) .select("1"); if(flowTaskUserMapper.selectCount(q)>0){ throw new ServiceException("收藏名称已经存在!"); } for (FlowTaskUser flowTaskUseri:flowTaskUsers){ flowTaskUseri.setName(name); flowTaskUseri.setCreatedBy(TaskUtil.getTaskUser()); flowTaskUseri.setTemplateId(flowTaskUserC.getTemplateId()); flowTaskUseri.setModelKey(flowTaskUserC.getModelKey()); } //新增、修改 this.saveOrUpdateBatch(flowTaskUsers); } @Override public void deleteUser(String name){ Map m = new HashMap<>(); m.put("name", name); m.put("created_by", TaskUtil.getTaskUser()); baseMapper.deleteByMap(m); } public List getTaskUserByTemplateAndModelKey(String templateId,String modelKey){ Map m = new HashMap<>(); m.put("template_id", templateId); m.put("model_key", modelKey); return baseMapper.selectByMap(m); } }