taskmgr.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 790 行 · 第 1/2 页

JAVA
790
字号
                    att.setName(fi.getName());                    att.setDiskName(fi.getDiskName());                    att.setFullPath(fullpath + newfilename + "." + fi.getExt() );                    att.setVisualPath(vpath);                    att.create();                }            }        }        return re;    }    public TaskDb getTaskDb(int id) {        TaskDb td = new TaskDb();        return td.getTaskDb(id);    }    public boolean AddReply(HttpServletRequest request) throws            ErrMsgException {                CheckReply(request);        int isfinish = 0;                int recount = 0, layer = 1, orders = 1, rootid = -1, parentorders = 1;        int parentlayer = 1, parentreplyid = -1;        boolean isroot = false;        ResultSet rs = null;        String sql;        TaskDb parentTd = getTaskDb(parentid);        if (parentTd == null || parentTd.isLoaded()) {            recount = parentTd.getReCount();            parentlayer = parentTd.getLayer();            layer = parentlayer + 1;            rootid = parentTd.getRootId();                        parentreplyid = parentTd.getParentId();            if (parentreplyid == TaskDb.NOPARENT) {                 isroot = true;            } else                recount = 0;            parentorders = parentTd.getOrders();            isfinish = parentTd.getStatus();        } else            throw new ErrMsgException("被回复的任务不存在!");        TaskDb rootTd = getTaskDb(parentTd.getRootId());        if (!isroot) {             recount = rootTd.getReCount();            isfinish = rootTd.getStatus();        }        if (isfinish == 1)            throw new ErrMsgException("该任务已结束!");        boolean updateorders = true;        Conn conn = new Conn(connname);        try {            if (isroot && recount == 0)                orders = parentorders + 1;             else {                if (parentreplyid == -1) {                     orders = recount + 2;                    updateorders = false;                } else {                                        sql = "select min(orders) from task where orders>" +                          parentorders +                          " and layer<=" + parentlayer;                    rs = conn.executeQuery(sql);                    if (rs != null && rs.next())                        orders = rs.getInt(1);                     if (rs != null) {                        rs.close();                        rs = null;                    }                    if (orders == 0) {                        updateorders = false;                        orders = recount + 2;                    }                }            }            recount++;            rootTd.setReCount(recount);            rootTd.save();            if (updateorders) {                sql = "select id from task where rootid=" + rootid +                      " and orders>=" + orders;                rs = conn.executeQuery(sql);                if (rs != null) {                    while (rs.next()) {                        TaskDb t = parentTd.getTaskDb(rs.getInt(1));                        t.setOrders(t.getOrders() + 1);                        t.save();                    }                }            }        } catch (SQLException e) {            logger.error("AddReply:" + e.getMessage());            throw new ErrMsgException("AddReply: 数据库出错!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        TaskDb task = new TaskDb();        task.setInitiator(privilege.getUser(request));        task.setPerson(person);        task.setType(type);        task.setParentId(parentid);        task.setTitle(title);        task.setContent(content);        task.setExpression(expression);        task.setIp(ip);        task.setOrders(orders);        task.setLayer(layer);        task.setRootId(rootid);                task.setJobCode(jobCode);        boolean re = task.create();        this.id = task.getId();        this.rootid = task.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(task.getId());                    att.setName(fi.getName());                    att.setDiskName(fi.getDiskName());                    att.setFullPath(fullpath + newfilename + "." + fi.getExt());                    att.setVisualPath(vpath);                    att.create();                }            }                        boolean isToMobile = StrUtil.getNullStr(fileUpload.getFieldValue(                    "isToMobile")).equals("true");            System.out.println("TaskMgr.java: isToMobile=" + isToMobile + " isUseMsg=" + isUseMsg);            IMessage imsg = null;            String t = SkinUtil.LoadString(request,                                           "res.module.task",                                           "msg_create_title");            String c = SkinUtil.LoadString(request,                                           "res.module.task",                                           "msg_create_content");            if (isToMobile && isUseMsg) {                ProxyFactory proxyFactory = new ProxyFactory(                        "com.redmoon.oa.message.MessageDb");                Advisor adv = new Advisor();                MobileAfterAdvice mba = new MobileAfterAdvice();                adv.setAdvice(mba);                adv.setPointcut(new MethodNamePointcut("sendSysMsg", false));                proxyFactory.addAdvisor(adv);                imsg = (IMessage) proxyFactory.getProxy();                if (type == TaskDb.TYPE_SUBTASK) {                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    imsg.sendSysMsg(person, t, c);                } else if (type == TaskDb.TYPE_HURRY) {                    t = SkinUtil.LoadString(request,                                            "res.module.task",                                            "msg_hurry_title");                    c = SkinUtil.LoadString(request,                                            "res.module.task",                                            "msg_hurry_content");                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    UserDb ud = new UserDb();                    ud = ud.getUserDb(initiator);                    c = c.replaceFirst("\\$initiator", ud.getRealName());                    imsg.sendSysMsg(person, t, c);                }                else if (type==TaskDb.TYPE_RESULT) {                    t = SkinUtil.LoadString(request,                                                   "res.module.task",                                                   "msg_result_title");                    c = SkinUtil.LoadString(request,                                                   "res.module.task",                                           "msg_result_content");                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    imsg.sendSysMsg(parentTd.getInitiator(), t, c);                }            } else if (isUseMsg) {                MessageDb md = new MessageDb();                                if (type == TaskDb.TYPE_SUBTASK) {                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    md.sendSysMsg(person, t, c);                } else if (type == TaskDb.TYPE_HURRY) {                    t = SkinUtil.LoadString(request,                                            "res.module.task",                                            "msg_hurry_title");                    c = SkinUtil.LoadString(request,                                            "res.module.task",                                            "msg_hurry_content");                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    UserDb ud = new UserDb();                    ud = ud.getUserDb(initiator);                    c = c.replaceFirst("\\$initiator", ud.getRealName());                    md.sendSysMsg(person, t, c);                }                else if (type==TaskDb.TYPE_RESULT) {                    t = SkinUtil.LoadString(request,                                                   "res.module.task",                                                   "msg_result_title");                    c = SkinUtil.LoadString(request,                                                   "res.module.task",                                           "msg_result_content");                    t = t.replaceFirst("\\$title", title);                    c = c.replaceFirst("\\$content",                                       StrUtil.getLeft(content, 50) + "...");                    md.sendSysMsg(parentTd.getInitiator(), t, c);                }            }        }        return re;    }    public boolean del(HttpServletRequest request, int delid) throws            ErrMsgException {        TaskDb td = new TaskDb();        return td.del(delid);    }    public boolean edit(ServletContext application, HttpServletRequest request) throws ErrMsgException {        ReceiveData(application, request);        String editid = fileUpload.getFieldValue("editid");        if (editid == null || !StrUtil.isNumeric(editid)) {            throw new ErrMsgException("编辑标识非法!");        }        int id = Integer.parseInt(editid);        if (!taskprivilege.canEdit(request, id))                throw new ErrMsgException(SkinUtil.LoadString(request, "pvg_invalid"));        TaskDb td = getTaskDb(id);        Check(request);        java.text.SimpleDateFormat formatter                = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");         Calendar cal = Calendar.getInstance();        java.util.Date currentTime = cal.getTime();        String dateString = formatter.format(currentTime);        UserDb ud = new UserDb();        ud = ud.getUserDb(privilege.getUser(request));        content += "<p align=right>该项已被" + ud.getRealName() + "编辑于" +                dateString + "</p>";        td.setTitle(title);        td.setContent(content);        td.setPerson(person);        td.setExpression(expression);        td.setIp(ip);        boolean re = td.save();        if (re) {            if (fileUpload.getRet() == fileUpload.RET_SUCCESS) {                Vector v = fileUpload.getFiles();                FileInfo fi = null;                Iterator ir = v.iterator();                String vpath = "";                                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();                }                String t = SkinUtil.LoadString(request,                                               "res.module.task",                                               "msg_modify_title");                String c = SkinUtil.LoadString(request,                                               "res.module.task",                                               "msg_modify_content");                MessageDb md = new MessageDb();                t = t.replaceFirst("\\$title", title);                c = c.replaceFirst("\\$content",                                   StrUtil.getLeft(content, 50) + "...");                boolean isToMobile = StrUtil.getNullStr(fileUpload.getFieldValue("isToMobile")).equals("true");                                if (isToMobile && isUseMsg &&  !td.getInitiator().equals(person)) {                    IMessage imsg = null;                    ProxyFactory proxyFactory = new ProxyFactory(                            "com.redmoon.oa.message.MessageDb");                    Advisor adv = new Advisor();                    MobileAfterAdvice mba = new MobileAfterAdvice();                    adv.setAdvice(mba);                    adv.setPointcut(new MethodNamePointcut("sendSysMsg", false));                    proxyFactory.addAdvisor(adv);                    imsg = (IMessage) proxyFactory.getProxy();                    imsg.sendSysMsg(person, t, c);                }                else if (isUseMsg && !td.getInitiator().equals(person)) {                    md.sendSysMsg(person, t, c);                }            }        }        return re;    }    public boolean changeFinish(HttpServletRequest request, int taskid) throws            ErrMsgException {        if (!taskprivilege.isInitiator(request, taskid))            throw new ErrMsgException("您无权改变任务状态!");        String isfinish = request.getParameter("isfinish");        if (!StrUtil.isNumeric(isfinish))            throw new ErrMsgException("请输入正确的参数!");        TaskDb td = getTaskDb(taskid);        td.setStatus(Integer.parseInt(isfinish));        return td.save();    }    public Vector getUserJoinTask(String username) {        TaskDb td = new TaskDb();        return td.getUserJoinTask(username);    }        public Vector getUserNotFinishedTask(String username) {        TaskDb td = new TaskDb();        return td.getUserNotFinishedTask(username);    }    public void setJobCode(String jobCode) {        this.jobCode = jobCode;    }    public void setId(int id) {        this.id = id;    }    private String jobCode;    private int id;    private boolean isUseMsg = true;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?