taskmgr.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 790 行 · 第 1/2 页
JAVA
790 行
package com.redmoon.oa.task;import java.io.*;import java.sql.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.redmoon.kit.util.*;import com.redmoon.kit.util.FileInfo;import com.redmoon.oa.Config;import com.redmoon.oa.dept.*;import com.redmoon.oa.flow.*;import com.redmoon.oa.pvg.*;import org.apache.log4j.*;import cn.js.fan.util.file.FileUtil;import com.redmoon.oa.message.MessageDb;import com.cloudwebsoft.framework.aop.ProxyFactory;import com.cloudwebsoft.framework.aop.base.Advisor;import com.cloudwebsoft.framework.aop.Pointcut.MethodNamePointcut;import com.redmoon.oa.message.IMessage;import com.redmoon.oa.message.MobileAfterAdvice;import com.redmoon.oa.person.UserDb;public class TaskMgr { String connname = Global.defaultDB; Logger logger = Logger.getLogger(TaskMgr.class.getName()); Privilege privilege = null; FileUpload fileUpload = null; int ret = 0; String title, content, person, ip; int type; int expression; String filenm; String extname; int parentid; String filepath; String initiator; String privurl; int rootid; TaskPrivilege taskprivilege = null; public TaskMgr() { privilege = new Privilege(); taskprivilege = new TaskPrivilege(); } public void ReceiveData(ServletContext application, HttpServletRequest request) { fileUpload = new FileUpload(); String[] extnames = { "jpg", "gif", "zip", "rar", "doc", "rm", "avi", "xls", "bmp", "swf", "txt", "htm", "html", "png"}; fileUpload.setValidExtname(extnames); fileUpload.setMaxFileSize(Global.FileSize); Config cfg = new Config(); filepath = cfg.get("file_task"); java.util.Date currentTime = new java.util.Date(); filenm = String.valueOf(currentTime.getTime()); try { ret = fileUpload.doUpload(application, request); } catch (IOException e) { logger.error("ReceiveData: " + e.getMessage()); } } public boolean Check(HttpServletRequest req) throws ErrMsgException { if (ret == -3) { throw new ErrMsgException("您上传的文件太大,请把文件大小限制在" + Global.FileSize + "K以内!"); } if (ret == -4) { throw new ErrMsgException( "扩展名非法,注意扩展名必须为:jpg,gif,zip,rar,doc,rm,avi,bmp,swf,txt,htm,html,png"); } String errMsg = ""; String sisUseMsg = StrUtil.getNullStr(fileUpload.getFieldValue("isUseMsg")); if (sisUseMsg.equals("true")) isUseMsg = true; title = fileUpload.getFieldValue("title"); if (title == null || title.trim().equals("")) errMsg += "请输入标题!"; content = fileUpload.getFieldValue("content"); try { type = Integer.parseInt(StrUtil.getNullStr(fileUpload.getFieldValue( "type"))); expression = Integer.parseInt(StrUtil.getNullStr(fileUpload. getFieldValue("expression"))); } catch (NumberFormatException e) { } ip = req.getRemoteAddr(); person = StrUtil.getNullStr(fileUpload.getFieldValue("person")); privurl = StrUtil.getNullStr(fileUpload.getFieldValue("privurl")); if (!errMsg.equals("")) { throw new ErrMsgException(errMsg); } return true; } public String getprivurl() { return privurl; } public String getTitle() { return title; } public String getContent() { return content; } public String getFilename() { return filenm; } public String getPerson() { return person; } public String getExtname() { return extname; } public int getType() { return type; } public int getRootid() { return rootid; } public int getExpression() { return expression; } public String getInitiator() { return initiator; } public String getJobCode() { return jobCode; } public int getId() { return id; } public boolean CheckReply(HttpServletRequest request) throws ErrMsgException { Check(request); String strparentid = fileUpload.getFieldValue("parentid"); String sisUseMsg = StrUtil.getNullStr(fileUpload.getFieldValue("isUseMsg")); if (sisUseMsg.equals("true")) isUseMsg = true; if (strparentid == null) throw new ErrMsgException("缺少任务标识!"); parentid = Integer.parseInt(strparentid); if (type == 2) if (!taskprivilege.canAddResult(request, parentid)) throw new ErrMsgException("您无权汇报结果!"); if (type == 3) if (!taskprivilege.canHurry(request, parentid)) throw new ErrMsgException("您无权催办!"); if (person.equals("")) throw new ErrMsgException("用户名不能为空!"); return true; } public boolean uploadDocument(ServletContext application, HttpServletRequest request) throws ErrMsgException { FileUpload fu = new FileUpload(); fu.setMaxFileSize(Global.FileSize); int ret = 0; try { ret = fu.doUpload(application, request); if (ret != fu.RET_SUCCESS) { throw new ErrMsgException(fu.getErrMessage()); } } catch (Exception e) { logger.error("uploadDocument:" + e.getMessage()); } if (ret == fu.RET_SUCCESS) { String strId = fu.getFieldValue("taskId"); String strAttachId = fu.getFieldValue("attachId"); if (!StrUtil.isNumeric(strId)) throw new ErrMsgException("id 必须为数字"); if (!taskprivilege.canEdit(request, StrUtil.toInt(strId))) throw new ErrMsgException(SkinUtil.LoadString(request, "pvg_invalid")); if (!StrUtil.isNumeric(strAttachId)) throw new ErrMsgException("attachId 必须为数字"); TaskDb td = new TaskDb(); td = td.getTaskDb(StrUtil.toInt(strId)); if (td==null || !td.isLoaded()) { throw new ErrMsgException("任务不存在!"); } Attachment att = td.getAttachment(StrUtil.toInt(strAttachId)); com.redmoon.kit.util.FileInfo fi = (com.redmoon.kit.util.FileInfo)(fu.getFiles().get(0)); return fi.write(Global.getRealPath() + att.getVisualPath() + "/", att.getDiskName()); } else return false; } public boolean Add(ServletContext application, HttpServletRequest request) throws ErrMsgException { ReceiveData(application, request); String op = fileUpload.getFieldValue("op"); initiator = privilege.getUser(request); if (op.equals("new")) { return AddNew(request); } else if (op.equals("newflowtask")) { return AddNewOfWorkflowAction(request); } else return AddReply(request); } public boolean AddNewOfWorkflowAction(HttpServletRequest request) throws ErrMsgException { try { Check(request); } catch (ErrMsgException e) { throw e; } String sql = ""; int length = 0; if (content != null) length = content.length(); String strActionId = fileUpload.getFieldValue("actionId"); if (!StrUtil.isNumeric(strActionId)) throw new ErrMsgException("actionId必须为数字!"); int actionId = Integer.parseInt(strActionId); String[] strAttachIds = fileUpload.getFieldValues("attachIds"); TaskDb td = new TaskDb(); td.setJobCode(jobCode); td.setInitiator(initiator); td.setType(type); td.setTitle(title); td.setContent(content); td.setPerson(person); td.setExpression(expression); td.setIp(ip); td.setActionId(actionId); if (ret != fileUpload.RET_SUCCESS) { throw new ErrMsgException(fileUpload.getErrMessage()); } boolean re = td.create(); this.id = td.getId(); this.rootid = td.getRootId(); if (re) { WorkflowActionDb wfa = new WorkflowActionDb(); wfa = wfa.getWorkflowActionDb(actionId); wfa.setTaskId(td.getId()); wfa.save(); if (fileUpload.getRet() == fileUpload.RET_SUCCESS) { Vector v = fileUpload.getFiles(); FileInfo fi = null; Iterator ir = v.iterator(); String vpath = ""; Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); vpath = filepath + "/" + year + "/" + month + "/"; String fullpath = fileUpload.getRealPath() + vpath; while (ir.hasNext()) { fi = (FileInfo) ir.next(); String newfilename = fileUpload.getRandName(); fi.write(fullpath, newfilename + "." + fi.getExt()); Attachment att = new Attachment(); att.setTaskId(td.getId()); att.setName(fi.getName()); att.setDiskName(fi.getDiskName()); att.setFullPath(fullpath + newfilename + "." + fi.getExt() ); att.setVisualPath(vpath); att.create(); } } int len = 0; if (strAttachIds!=null) len = strAttachIds.length; com.redmoon.oa.flow.Attachment flowAtt; for (int i = 0; i < len; i++) { Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); String vpath = filepath + "/" + year + "/" + month + "/"; flowAtt = new com.redmoon.oa.flow.Attachment(Integer.parseInt(strAttachIds[i])); Attachment att = new Attachment(); att.setTaskId(td.getId()); att.setName(flowAtt.getName()); att.setDiskName(flowAtt.getDiskName()); att.setFullPath(flowAtt.getFullPath()); att.setVisualPath(flowAtt.getVisualPath()); if (att.create()) { String fullpath = fileUpload.getRealPath() + vpath + att.getDiskName(); FileUtil.CopyFile(flowAtt.getFullPath(), fullpath); } } } return re; } public boolean AddNew(HttpServletRequest request) throws ErrMsgException { try { Check(request); } catch (ErrMsgException e) { throw e; } String sql = ""; int length = 0; if (content != null) length = content.length(); TaskDb td = new TaskDb(); td.setJobCode(jobCode); td.setInitiator(initiator); td.setType(type); td.setTitle(title); td.setContent(content); td.setPerson(person); td.setExpression(expression); td.setIp(ip); if (ret != fileUpload.RET_SUCCESS) { throw new ErrMsgException(fileUpload.getErrMessage()); } boolean re = td.create(); this.id = td.getId(); this.rootid = td.getRootId(); if (re) { if (fileUpload.getRet() == fileUpload.RET_SUCCESS) { Vector v = fileUpload.getFiles(); FileInfo fi = null; Iterator ir = v.iterator(); String vpath = ""; Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); vpath = filepath + "/" + year + "/" + month + "/"; String fullpath = fileUpload.getRealPath() + vpath; while (ir.hasNext()) { fi = (FileInfo) ir.next(); String newfilename = fileUpload.getRandName(); fi.write(fullpath, newfilename + "." + fi.getExt()); Attachment att = new Attachment(); att.setTaskId(td.getId());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?