package com.tiger.oa.action; import java.io.File; import java.io.FileInputStream; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.springframework.beans.BeanUtils; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ModelDriven; import org.apache.commons.beanutils.ConvertUtils; import com.tiger.oa.dto.DocumentDTO; import com.tiger.oa.dto.DownloadFileModel; import com.tiger.oa.dto.ImagePosition; import com.tiger.oa.dto.TaskModel; import com.tiger.oa.manager.DocumentManager; import com.tiger.oa.manager.FormManager; import com.tiger.oa.manager.WorkflowManager; import com.tiger.oa.model.ApproveInfo; import com.tiger.oa.model.Document; import com.tiger.oa.model.DocumentProperty; import com.tiger.oa.model.FieldType; import com.tiger.oa.model.FlowForm; import com.tiger.oa.model.FormField; import com.tiger.oa.util.FileUtil; import com.tiger.oa.util.SystemException; @Controller("documentAction") @Scope("prototype") public class DocumentAction extends BaseAction implements ModelDriven, ServletRequestAware, ServletResponseAware { private DocumentManager documentManager; private WorkflowManager workflowManager; private FormManager formManager; private DocumentDTO documentDTO = new DocumentDTO(); private Map<String,String> propsMap; private HttpServletRequest request; private HttpServletResponse response; @Resource public void setFormManager(FormManager formManager) { this.formManager = formManager; } @Resource public void setDocumentManager(DocumentManager documentManager) { this.documentManager = documentManager; } @Resource public void setWorkflowManager(WorkflowManager workflowManager) { this.workflowManager = workflowManager; } // ���Ĺ��������棬��ʾ�ҵĹ����б� @Override public String execute() throws Exception { request.setAttribute("pm", documentManager .searchMyDocuments(currentUser().getId())); return "index"; } /** * �������б?��ʾ�ɵ�ǰ��¼��Ա��˵Ĺ����б� * * @return * @throws Exception */ public String approvedList() throws Exception { request.setAttribute("pm", documentManager .searchApprovedDocuments(currentUser().getId())); return "approved_list"; } /** * �������б?��ʾ�ȴ�ǰ��¼��Ա��˵Ĺ����б� * * @return * @throws Exception */ public String approvingList() throws Exception { request.setAttribute("documents", documentManager.searchApprovingDocuments(currentUser().getId())); return "approving_list"; } /** * �ڴ������б��ϣ����ij���ĵ������Ե����������棬�Դ��ĵ��������� * * @return * @throws Exception */ public String approveInput() throws Exception { return "approve_input"; } /** * �û�����������Ϣ֮������棬���ĵ������������ * * @return * @throws Exception */ public String approve() throws Exception { String comment = documentDTO.getApproveInfo(); int documentId = documentDTO.getId(); int approverId = currentUser().getId(); ApproveInfo approveInfo = new ApproveInfo(); approveInfo.setApproveTime(new Date()); approveInfo.setComment(comment); documentManager.addApproveInfo(approveInfo, documentId, approverId); return "pub_add_success"; } /** * ���ҵĹ��Ļ�������б��ϣ�����ύ���ɴ��ύ��ѡ����� ����������ϣ��г���һ�����п�ѡ�IJ��裬�û�����ѡ������һ�� * ��������ύ������ϵͳ�������û���ѡ��ת�Ƶ���һ���ڵ� * * @return * @throws Exception */ public String submitInput() throws Exception { Document doc = documentManager.findDocument(documentDTO.getId()); TaskModel taskModel = workflowManager.searchNextTransitions(currentUser().getUsername(),doc.getProcessInstanceId()); documentDTO.setTaskId(taskModel.getTaskId()); request.setAttribute("steps", taskModel.getTransitions()); return "submit_input"; } /** * �û�ѡ��������һ�����裬����ύ * @return * @throws Exception */ public String submit() throws Exception { documentManager.submitToWorkflow(documentDTO.getId(),documentDTO.getTaskId(), documentDTO.getTransitionName()); return "pub_add_success"; } /** * �鿴���ĵ�������ʷ * * @return * @throws Exception */ public String approvedHistory() throws Exception { request.setAttribute("historys", documentManager.searchApproveInfos(documentDTO.getId())); return "approve_history"; } public String del() throws Exception { documentManager.delDocument(documentDTO.getId()); return "pub_del_success"; } /** * �����ӹ��ĵ�ʱ����Ҫѡ����Ӧ�����̣��˽����г����е������Թ�ѡ�� * * @return * @throws Exception */ public String selectFlow() throws Exception { request.setAttribute("workflows", workflowManager.searchAllWorkflows()); return "select_flow"; } /** * ѡ��������֮�����������ƣ�����Ҫ����¼����� * * @return * @throws Exception */ public String addInput() throws Exception { return "add_input"; } /** * ��ӹ��ĵIJ��� * * @return * @throws Exception */ public String add() throws Exception { Document document = new Document(); documentDTO.setProps(propsMap); BeanUtils.copyProperties(documentDTO,document); //����Map����� //��Map����ݣ����ձ?�����Ӧ������������ת���������õ�document���� if(documentDTO.getProps().isEmpty()){ document.setProps(null); }else{ int workflowId = documentDTO.getWorkflowId(); //���̶�Ӧ�ı?���� FlowForm flowForm = formManager.findForm(workflowId); if(flowForm == null){ document.setProps(null); }else{ Map documentProps = new HashMap(); //�õ��?�����Ӧ�����е����� Set fields = flowForm.getFields(); for (Iterator iter = fields.iterator(); iter.hasNext();) { FormField field = (FormField) iter.next(); String propertyName = field.getFieldName(); FieldType propertyType = field.getFieldType(); //��ݱ?��������ƣ���Map�н������ϴ�������ԭʼֵ�ó��� Object source = documentDTO.getProps().get(propertyName); Object target = null; if(source != null){ //����������ַ� if(source instanceof String && !propertyType.getType().equals("java.io.File")){ Class targetClass = Class.forName(propertyType.getType()); //����ConvertUtils���ߣ����ӽ����ϴ��������ַ� //ת��ΪFormFiled��Ӧ��FieldType��ָ�����͵Ķ��� target = ConvertUtils.convert((String)source, targetClass); } //���?�����ϴ��ļ� if(propertyType.getType().equals("java.io.File")){ //ע�⣺�������ϴ������ļ���struts�����Զ�ת��ΪFormFile //���͵Ķ������� FileInputStream is = new FileInputStream(new File((String)source)); byte[] fileData = new byte[is.available()]; target = fileData; } //���ڣ���Ҫ��target��ֵ����document���� if(target == null){ throw new SystemException("�����������ֵ��"); } DocumentProperty dp = new DocumentProperty(); String type = propertyType.getType(); if(type.equals("java.io.File")){ dp.setJava_io_File((byte[])target); } if(type.equals("java.lang.Integer")){ dp.setJava_lang_Integer((Integer)target); } if(type.equals("java.lang.String")){ dp.setJava_lang_String((String)target); } documentProps.put(propertyName, dp); System.out.println(documentProps); } } //��documentProps������document�����props���� document.setProps(documentProps); } } if(documentDTO.getUpload() != null){ document.setContent(FileUtil.getFileData(documentDTO.getUpload())); } documentManager.addDocument(document,documentDTO.getWorkflowId(), currentUser().getId()); return "pub_add_success"; } // ���ع��ĸ��� public String download() throws Exception { Document document = documentManager.findDocument(documentDTO.getId()); response.reset(); response.setContentType("application/x-download;charset=GBK"); response.setHeader("Content-Disposition", "attachment;filename=temp.doc"); response.getOutputStream().write(document.getContent()); response.getOutputStream().flush(); response.getOutputStream().close(); // ָʾstruts����Ҫ�Է���ֵ���д��� return null; } /* * ͼƬҳ�� */ public String viewPage() throws Exception{ ImagePosition image = workflowManager.getPngPosition(documentDTO.getProcessInstanceId()); request.setAttribute("image", image); return "view"; } // �鿴ͼƬ public String view() throws Exception { DownloadFileModel file = workflowManager.getPngByteByProcessId(documentDTO.getProcessInstanceId()); response.reset(); response.setContentType("image/png"); response.getOutputStream().write(file.getFileData()); response.getOutputStream().flush(); response.getOutputStream().close(); return null; } @Override public Object getModel() { return documentDTO; } @Override public void setServletRequest(HttpServletRequest request) { this.request = request; } @Override public void setServletResponse(HttpServletResponse response) { this.response = response; } public Map<String,String> getPropsMap() { return propsMap; } public void setPropsMap(Map<String,String> propsMap) { this.propsMap = propsMap; } }

校园网 LV9
2024年8月4日
carloscarlos LV1
2023年9月13日
15029223037 LV1
2023年7月18日
linmou LV8
2023年3月19日
微信网友_6376279687794688 LV1
2023年3月5日
快乐的程序员 LV25
2023年1月21日
微信网友_6292700852981760 LV1
2023年1月5日
15342201772 LV9
2022年12月10日
swd287797983 LV1
2022年12月6日
wazp4071 LV1
2022年6月24日