⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workplandb.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.oa.workplan;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.kit.util.*;import com.redmoon.kit.util.FileInfo;import cn.js.fan.web.Global;import com.redmoon.oa.kernel.JobUnitDb;public class WorkPlanDb extends ObjectDb {    private int id;    public static final int TYPE_SYSTEM = 1;    public static final int TYPE_USER = 0;    public WorkPlanDb() {        init();    }    public WorkPlanDb(int id) {        this.id = id;        init();        load();    }    public int getId() {        return id;    }    public String getTitle() {        return title;    }    public String getContent() {        return content;    }    public java.util.Date getBeginDate() {        return beginDate;    }    public java.util.Date getEndDate() {        return endDate;    }    public int getTypeId() {        return typeId;    }    public String getRemark() {        return remark;    }    public String getPrincipal() {        return principal;    }    public void initDB() {        tableName = "work_plan";        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT);        objectCache = new WorkPlanCache(this);        isInitFromConfigDB = false;        QUERY_CREATE =                "insert into " + tableName + " (title,content,beginDate,endDate,typeId,remark,principal,author) values (?,?,?,?,?,?,?,?)";        QUERY_SAVE = "update " + tableName + " set title=?,content=?,beginDate=?,endDate=?,typeId=?,remark=?,principal=? where id=?";        QUERY_LIST =                "select id from " + tableName;        QUERY_DEL = "delete from " + tableName + " where id=?";        QUERY_LOAD = "select title,content,beginDate,endDate,typeId,remark,principal,author from " + tableName + " where id=?";    }    public WorkPlanDb getWorkPlanDb(int id) {        return (WorkPlanDb)getObjectDb(new Integer(id));    }    public boolean create(FileUpload fu) throws ErrMsgException {        Conn conn = new Conn(connname);        boolean re = false;        try {            conn.beginTrans();            PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);            ps.setString(1, title);            ps.setString(2, content);            ps.setString(3, DateUtil.format(beginDate, "yyyy-MM-dd HH:mm:ss"));            ps.setString(4, DateUtil.format(endDate, "yyyy-MM-dd HH:mm:ss"));            ps.setInt(5, typeId);            ps.setString(6, remark);            ps.setString(7, principal);            ps.setString(8, author);            re = conn.executePreUpdate()==1?true:false;            logger.info("create:re=" + re + " users=" + users);            if (ps != null) {                ps.close();                ps = null;            }                        ResultSet rs = conn.executeQuery("select last_insert_id() from " +                                             tableName + " limit 1");            if (rs != null && rs.next()) {                id = rs.getInt(1);            }            if (re) {                if (users!=null) {                    int len = users.length;                    String sql = "insert into work_plan_user (workPlanId, userName) values (?,?)";                    ps = conn.prepareStatement(sql);                    for (int i=0; i<len; i++) {                        ps.clearParameters();                        ps.setInt(1, id);                        ps.setString(2, users[i]);                        conn.executePreUpdate();                    }                }                if (ps!=null) {                    ps.close();                    ps = null;                }                if (depts!=null) {                    int len = depts.length;                    String sql = "insert into work_plan_dept (workPlanId, deptCode) values (?,?)";                    ps = conn.prepareStatement(sql);                    for (int i=0; i<len; i++) {                        ps.clearParameters();                        ps.setInt(1, id);                        ps.setString(2, depts[i]);                        conn.executePreUpdate();                    }                 }                                  if (fu.getRet() == fu.RET_SUCCESS) {                                          Calendar cal = Calendar.getInstance();                     String year = "" + (cal.get(cal.YEAR));                     String month = "" + (cal.get(cal.MONTH) + 1);                     com.redmoon.oa.Config cfg = new com.redmoon.oa.Config();                     String vpath = cfg.get("file_workplan") + "/" + year + "/" + month + "/";                     String filepath = Global.getRealPath() + vpath;                     fu.setSavePath(filepath);                                          fu.writeFile(true);                     Vector v = fu.getFiles();                     FileInfo fi = null;                     Iterator ir = v.iterator();                     while (ir.hasNext()) {                         fi = (FileInfo) ir.next();                         Attachment att = new Attachment();                         att.setFullPath(filepath + fi.getDiskName());                         att.setWorkPlanId(id);                         att.setName(fi.getName());                         att.setDiskName(fi.getDiskName());                         att.setVisualPath(vpath);                         re = att.create();                     }                 }                 WorkPlanCache rc = new WorkPlanCache(this);                 rc.refreshCreate();            }            conn.commit();        }        catch (SQLException e) {            conn.rollback();            logger.error("create:" + e.getMessage());            throw new ErrMsgException("数据库操作失败!");        }        finally {            if (conn!=null) {                conn.close();                conn = null;            }        }        return re;    }        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) {                WorkPlanCache rc = new WorkPlanCache(this);                primaryKey.setValue(new Integer(id));                rc.refreshDel(primaryKey);                                if (attachments!=null) {                    Iterator ir = attachments.iterator();                    while (ir.hasNext()) {                        Attachment att = (Attachment)ir.next();                        att.del();                    }                }                                JobUnitDb ju = new JobUnitDb();                ju.delJobOfWorkplan(id);            }        } catch (SQLException e) {            logger.error("del: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }        public ObjectDb getObjectRaw(PrimaryKey pk) {        return new WorkPlanDb(pk.getIntValue());    }        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);                beginDate = rs.getTimestamp(3);                endDate = rs.getTimestamp(4);                typeId = rs.getInt(5);                remark = rs.getString(6);                principal = rs.getString(7);                author = rs.getString(8);                loaded = true;                primaryKey.setValue(new Integer(id));                                if (ps!=null) {                    ps.close();                    ps = null;                }                String sql = "select id from work_plan_attach where workPlanId=?";                ps = conn.prepareStatement(sql);                ps.setInt(1, id);                rs = conn.executePreQuery();                attachments = new Vector();                while (rs.next()) {                    Attachment att = new Attachment(rs.getInt(1));                    attachments.addElement(att);                }                if (ps!=null) {                    ps.close();                    ps = null;                }                sql = "select deptCode from work_plan_dept where workPlanId=?";                ps = conn.prepareStatement(sql);                ps.setInt(1, id);                rs = conn.executePreQuery();                if (rs!=null) {                    depts = new String[conn.getRows()];                    int i = 0;                    while (rs.next()) {                        depts[i] = rs.getString(1);                        i++;                    }                }                if (ps!=null) {                    ps.close();                    ps = null;                }                sql = "select userName from work_plan_user where workPlanId=?";                ps = conn.prepareStatement(sql);                ps.setInt(1, id);                rs = conn.executePreQuery();                if (rs!=null) {                    users = new String[conn.getRows()];                    int i = 0;                    while (rs.next()) {                        users[i] = rs.getString(1);                        i++;                    }                }                if (ps!=null) {                    ps.close();                    ps = null;                }                sql = "select id from work_plan_attach where workPlanId=?";                ps = conn.prepareStatement(sql);                ps.setInt(1, id);                rs = conn.executePreQuery();                attachments = new Vector();                if (rs!=null) {                    while (rs.next()) {                        attachments.addElement(new Attachment(rs.getInt(1)));                    }                }                if (ps!=null) {                    ps.close();

⌨️ 快捷键说明

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