package action; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.activiti.bpmn.model.SequenceFlow; import org.activiti.engine.HistoryService; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.history.HistoricTaskInstance; import org.activiti.engine.impl.RepositoryServiceImpl; import org.activiti.engine.impl.persistence.entity.ExecutionEntity; import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity; import org.activiti.engine.impl.pvm.process.ActivityImpl; import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl; import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.runtime.Execution; import org.activiti.engine.runtime.ProcessInstance; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class PitctureAction extends ActionSupport { private static final long serialVersionUID = 2754710324037673469L; private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_3BYTE_BGR; public String getProcessPic(){ HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); //创建流程引擎 ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine(); //RuntimeService runtimeService = processEngine.getRuntimeService(); RuntimeService runtimeService = processEngine.getRuntimeService(); ProcessInstance pq = runtimeService.createProcessInstanceQuery().processInstanceId("4605").singleResult(); RepositoryService reponsitoryService = processEngine.getRepositoryService(); InputStream imageStream = reponsitoryService.getProcessDiagram(pq.getProcessDefinitionId()); String realpath = ServletActionContext.getServletContext().getRealPath("/images"); File file = new File(new File(realpath), "ParallelGate.png"); BufferedImage image = null; try { image = javax.imageio.ImageIO.read(file); response.setContentType("image/png"); response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires", 0); Graphics2D g = (Graphics2D) image.getGraphics(); g.setStroke(new BasicStroke(2)); //g.drawRect(20, 20, 40, 40); g.setColor(Color.RED); g.drawRoundRect(90, 0, 100, 60,20, 20); ImageIO.write(image, "JPG", response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } return SUCCESS; } public String getProcessMap() { HttpServletResponse response = ServletActionContext.getResponse(); ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine(); //获取服务 RuntimeService runtimeService = processEngine.getRuntimeService(); RepositoryService repositoryService = processEngine.getRepositoryService(); HistoryService historyService = processEngine.getHistoryService(); //取得流程相应的实例 ProcessInstance pq = runtimeService.createProcessInstanceQuery().processInstanceId("4905").singleResult(); InputStream imageStream = repositoryService.getProcessDiagram(pq.getProcessDefinitionId()); List<HistoricTaskInstance> finishedlist = historyService.createHistoricTaskInstanceQuery().processInstanceId("4905").finished().list(); ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(pq.getProcessDefinitionId()); List<String> ActiveActivityIds = runtimeService.getActiveActivityIds(pq.getId());//获取所有的未执行的节点任务 List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点 List<ActivityImpl> actimpl = new ArrayList<ActivityImpl>();//存储未执行的节点任务 List<ActivityImpl> finishedimpl = new ArrayList<ActivityImpl>();//存储已执行的节点任务 int x = 1024,y=1024; for (ActivityImpl activityImpl : activitiList) { if(activityImpl.getX()<x){ x=activityImpl.getX(); } if(activityImpl.getY()<y){ y=activityImpl.getY(); } } for (ActivityImpl activityImpl : activitiList) { String id = activityImpl.getId(); for(String ids:ActiveActivityIds){// 获得未执行的节点任务 if (id.equals(ids)) { actimpl.add(activityImpl); break; } } for(HistoricTaskInstance history:finishedlist){// 获得已执行的节点任务 if (id.equals(history.getName())) { finishedimpl.add(activityImpl); break; } } } try { //取出流程图 // String realpath = ServletActionContext.getServletContext().getRealPath("/images"); //File file = new File(new File(realpath), "ParallelGate.png"); //对流程图进行加工处理 BufferedImage image =ImageIO.read(imageStream); //设置响应数据格式 ServletOutputStream sos = response.getOutputStream(); response.setContentType("image/JPEG"); response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires", 0); Graphics2D g = (Graphics2D) image.getGraphics(); g.setBackground(Color.WHITE); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING , RenderingHints.VALUE_ANTIALIAS_ON); g.setBackground(Color.WHITE); //将未执行的任务节点标红 for (ActivityImpl activity : actimpl){ g.setStroke(new BasicStroke(2)); g.setColor(Color.white); g.drawRoundRect(activity.getX()-x+5, activity.getY()-y+5, activity.getWidth(), activity.getHeight(),20, 20); g.setStroke(new BasicStroke(1)); g.setColor(Color.RED); g.drawRoundRect(activity.getX()-x+5, activity.getY()-y+5, activity.getWidth(), activity.getHeight(),20, 20); } //将已执行的任务节点标绿 for (ActivityImpl activity : finishedimpl){ g.setStroke(new BasicStroke(2)); g.setColor(Color.white); g.drawRoundRect(activity.getX()-x+5, activity.getY()-y+5, activity.getWidth(), activity.getHeight(),20, 20); g.setStroke(new BasicStroke(1)); g.setColor(Color.GREEN); g.drawRoundRect(activity.getX()-x+5, activity.getY()-y+5, activity.getWidth(), activity.getHeight(),20, 20); } //输出图像 ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(image, "JPEG", bos); byte[] buf = bos.toByteArray(); response.setContentLength(buf.length); sos.write(buf); bos.close(); sos.close(); } catch (IOException e) { e.printStackTrace(); } return SUCCESS; } }
最近下载更多
tiansitong LV14
2023年6月30日
pojo1010 LV1
2022年3月24日
wsk588 LV26
2021年3月16日
zhangbotao LV5
2020年12月16日
yxx_yxx LV11
2020年9月29日
双面伊人 LV1
2020年8月14日
wananall LV13
2020年7月24日
gan857569302 LV9
2020年6月8日
最代码安逸 LV15
2020年4月19日
liuxinglong LV10
2019年11月5日