📄 taskdb.java
字号:
package com.redmoon.oa.task;import java.sql.*;import java.sql.Date;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.db.SequenceManager;import com.redmoon.oa.ui.IDesktopUnit;import javax.servlet.http.HttpServletRequest;import com.redmoon.oa.person.UserDesktopSetupDb;import com.redmoon.oa.ui.DesktopMgr;import com.redmoon.oa.ui.DesktopUnit;import com.redmoon.oa.pvg.Privilege;public class TaskDb extends ObjectDb implements IDesktopUnit { private int id; public static final int NOPARENT = -1; public static final int TYPE_TASK = 0; public static final int TYPE_SUBTASK = 1; public static final int TYPE_RESULT = 2; public static final int TYPE_HURRY = 3; public static final int STATUS_NOTFINISHED = 0; public static final int STATUS_FINISHED = 1; public static final int STATUS_DISCARD = 2; public TaskDb() { init(); } public TaskDb(int id) { this.id = id; init(); load(); } public boolean create() { Conn conn = new Conn(connname); boolean re = false; try { id = (int) SequenceManager.nextID(SequenceManager.OA_TASK); if (rootId==-1) rootId = id; PreparedStatement ps = conn.prepareStatement(QUERY_CREATE); ps.setInt(1, id); ps.setString(2, title); ps.setString(3, content); ps.setString(4, fileName); ps.setString(5, ext); ps.setInt(6, type); ps.setInt(7, expression); ps.setString(8, initiator); ps.setInt(9, rootId); if (parentId==NOPARENT) person = initiator; ps.setString(10, person); ps.setInt(11, layer); ps.setInt(12, orders); ps.setInt(13, parentId); ps.setString(14, ip); ps.setInt(15, reCount); ps.setInt(16, status); ps.setString(17, jobCode); ps.setInt(18, actionId); re = conn.executePreUpdate()==1?true:false; if (re) { TaskCache rc = new TaskCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); } finally { if (conn!=null) { conn.close(); conn = null; } } return re; } public Attachment getAttachment(int attId) { Iterator ir = attachments.iterator(); while (ir.hasNext()) { Attachment at = (Attachment)ir.next(); if (at.getId()==attId) return at; } return null; } public String getPageList(HttpServletRequest request, UserDesktopSetupDb uds) { DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageList(); return url + StrUtil.UrlEncode(uds.getModuleItem()); } public String display(HttpServletRequest request, UserDesktopSetupDb uds) { Privilege privilege = new Privilege(); int count = uds.getCount(); DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageShow(); String str = "<ul>"; Vector tasks = getUserNotFinishedTask(privilege.getUser(request)); Iterator taskir = tasks.iterator(); String mydate = ""; int k = 1; while (taskir.hasNext()) { TaskDb td = (TaskDb) taskir.next(); mydate = DateUtil.format(td.getMyDate(), "yy-MM-dd HH:mm"); str += "<li><a href='" + url + "?showid=" + td.getId() + "&rootid=" + td.getId() + "'>" + StrUtil.toHtml(td.getTitle()) + " [" + mydate + "]</a></li>"; k++; if (k>count) break; } str += "</ul>"; return str; } public boolean del() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_DEL); ps.setInt(1, id); re = conn.executePreUpdate() == 1 ? true : false; if (re) { Iterator ir = attachments.iterator(); while (ir.hasNext()) { Attachment att = (Attachment)ir.next(); att.del(); } TaskCache rc = new TaskCache(this); primaryKey.setValue(new Integer(id)); rc.refreshDel(primaryKey); return true; } } catch (SQLException e) { logger.error("del: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public void initDB() { tableName = "task"; primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT); objectCache = new TaskCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (id,title,content,filename,ext,type,expression,initiator,rootid,person,layer,orders,parentid,ip,recount,status,jobCode,actionId,mydate) value (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())"; QUERY_SAVE = "update " + tableName + " set title=?,content=?,filename=?,ext=?,type=?,expression=?,initiator=?,rootid=?,person=?,layer=?,orders=?,parentid=?,ip=?,recount=?,status=?,jobCode=?,actionId=? where id=?"; QUERY_LIST = "select id from " + tableName + " order by mydate desc"; QUERY_DEL = "delete from " + tableName + " where id=?"; QUERY_LOAD = "select title,content,filename,ext,type,expression,initiator,rootid,person,layer,orders,parentid,ip,recount,status,mydate,jobCode,actionId from task where id=?"; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new TaskDb(pk.getIntValue()); } public TaskDb getTaskDb(int id) { return (TaskDb)getObjectDb(new Integer(id)); } public void load() { ResultSet rs = null; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(QUERY_LOAD); ps.setInt(1, id); rs = conn.executePreQuery(); if (rs != null && rs.next()) { title = rs.getString(1); content = rs.getString(2); fileName = StrUtil.getNullStr(rs.getString(3)); ext = StrUtil.getNullStr(rs.getString(4)); type = rs.getInt(5); expression = rs.getInt(6); initiator = rs.getString(7); rootId = rs.getInt(8); person = rs.getString(9); layer = rs.getInt(10); orders = rs.getInt(11); parentId = rs.getInt(12); ip = rs.getString(13); reCount = rs.getInt(14); status = rs.getInt(15); myDate = rs.getTimestamp(16); jobCode = rs.getString(17); actionId = rs.getInt(18); loaded = true; primaryKey.setValue(new Integer(id)); if (ps != null) { ps.close(); ps = null; } attachments = new Vector(); String sql = "select id from task_attach where taskId=?"; ps = conn.prepareStatement(sql); ps.setInt(1, id); rs = conn.executePreQuery(); if (rs != null) { while (rs.next()) { int aid = rs.getInt(1); Attachment am = new Attachment(aid); attachments.addElement(am); } } } } catch (SQLException e) { logger.error("load: " + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) {} rs = null; } if (conn!=null) { conn.close(); conn = null; } } } public boolean delAttachment(int attachId) { Attachment att = getAttachment(attachId); if (att==null) return false; boolean re = att.del(); TaskCache rc = new TaskCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); return re; } public boolean save() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_SAVE); ps.setString(1, title); ps.setString(2, content); ps.setString(3, fileName); ps.setString(4, ext); ps.setInt(5, type); ps.setInt(6, expression); ps.setString(7, initiator); ps.setInt(8, rootId); ps.setString(9, person); ps.setInt(10, layer); ps.setInt(11, orders); ps.setInt(12, parentId); ps.setString(13, ip); ps.setInt(14, reCount); ps.setInt(15, status); ps.setString(16, jobCode); ps.setInt(17, actionId); ps.setInt(18, id); re = conn.executePreUpdate()==1?true:false; if (re) { TaskCache rc = new TaskCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); } } catch (SQLException e) { logger.error("save: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public void setId(int id) { this.id = id; } public void setTitle(String title) { this.title = title; } public void setContent(String content) { this.content = content; } public void setFileName(String fileName) { this.fileName = fileName; } public void setExt(String ext) { this.ext = ext; } public void setType(int type) { this.type = type; } public void setExpression(int expression) { this.expression = expression; } public void setInitiator(String initiator) { this.initiator = initiator; } public void setRootId(int rootId) { this.rootId = rootId; } public void setPerson(String person) { this.person = person; } public void setLayer(int layer) { this.layer = layer; } public void setOrders(int orders) { this.orders = orders; } public void setParentId(int parentId) { this.parentId = parentId; } public void setIp(String ip) { this.ip = ip; } public void setReCount(int reCount) { this.reCount = reCount; } public void setStatus(int status) { this.status = status; } public void setMyDate(Date myDate) { this.myDate = myDate; } public void setJobCode(String jobCode) { this.jobCode = jobCode; } public void setAttachments(Vector attachments) { this.attachments = attachments; } public void setActionId(int actionId) { this.actionId = actionId; } public int getId() { return id; } public String getTitle() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -