📄 plandb.java
字号:
package com.redmoon.oa.person;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.message.*;import com.cloudwebsoft.framework.aop.ProxyFactory;import com.cloudwebsoft.framework.aop.base.Advisor;import com.cloudwebsoft.framework.aop.Pointcut.MethodNamePointcut;import com.redmoon.oa.ui.IDesktopUnit;import javax.servlet.http.HttpServletRequest;import com.redmoon.oa.pvg.Privilege;import com.redmoon.oa.ui.DesktopMgr;import com.redmoon.oa.ui.DesktopUnit;import java.util.Iterator;public class PlanDb extends ObjectDb implements IDesktopUnit { private int id; public PlanDb() { init(); } public PlanDb(int id) { this.id = id; init(); load(); } public int getId() { return id; } public void initDB() { tableName = "user_plan"; primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT); objectCache = new PlanCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into user_plan (title,content,myDate,userName,zdrq,isRemind,remindDate,remindCount,IS_REMIND_BY_SMS) values (?,?,?,?,NOW(),?,?,?,?)"; QUERY_SAVE = "update " + tableName + " set title=?,content=?,myDate=?,isRemind=?,remindDate=?,remindCount=?,IS_REMIND_BY_SMS=? where id=?"; QUERY_LIST = "select id from " + tableName + " order by mydate desc"; QUERY_DEL = "delete from " + tableName + " where id=?"; QUERY_LOAD = "select title,content,myDate,userName,zdrq,isRemind,remindDate,remindCount,IS_REMIND_BY_SMS from " + tableName + " where id=?"; } public PlanDb getPlanDb(int id) { return (PlanDb)getObjectDb(new Integer(id)); } public void makeRemindMsg() { PlanDb pd = null; String sql = "select id from " + getTableName() + " where isRemind=1 and NOW()>remindDate and myDate>NOW() and remindCount=0"; Conn conn = new Conn(connname); ResultSet rs = null; try { rs = conn.executeQuery(sql); while (rs.next()) { pd = getPlanDb(rs.getInt(1)); try { pd.sendRemindMsg(); } catch (ErrMsgException e) { logger.error("makeRemindMsg1:" + e.getMessage()); } } } catch (SQLException e) { logger.error("makeRemindMsg2:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } } public boolean sendRemindMsg() throws ErrMsgException { MessageDb md = new MessageDb(); remindCount++; save(); if (remindBySMS) { 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(); return imsg.sendSysMsg(userName, "日程提醒:" + title, content); } else return md.sendSysMsg(userName, "日程提醒:" + title, content); } public boolean create() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_CREATE); ps.setString(1, title); ps.setString(2, content); ps.setString(3, DateUtil.format(myDate, "yyyy-MM-dd HH:mm:ss")); ps.setString(4, userName); ps.setInt(5, remind?1:0); ps.setString(6, DateUtil.format(remindDate, "yyyy-MM-dd HH:mm:ss")); ps.setInt(7, remindCount); ps.setInt(8, remindBySMS?1:0); re = conn.executePreUpdate()==1?true:false; if (re) { PlanCache rc = new PlanCache(this); rc.refreshCreate(); } } catch (SQLException e) { 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) { PlanCache rc = new PlanCache(this); primaryKey.setValue(new Integer(id)); rc.refreshDel(primaryKey); } } 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 PlanDb(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); try { String d = rs.getString(3); myDate = DateUtil.parse(d == null ? d : d.substring(0, 19), "yyyy-MM-dd HH:mm:ss"); } catch (Exception e) { logger.error("load1:" + e.getMessage()); } userName = rs.getString(4); zdrq = rs.getDate(5); remind = rs.getInt(6)==1?true:false; remindDate = rs.getTimestamp(7); remindCount = rs.getInt(8); remindBySMS = rs.getInt(9)==1; loaded = true; primaryKey.setValue(new Integer(id)); } } 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 String getPageList(HttpServletRequest request, UserDesktopSetupDb uds) { DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageList(); return url; } public String display(HttpServletRequest request, UserDesktopSetupDb uds) { Privilege privilege = new Privilege(); String sql = "select id from user_plan where userName=" + StrUtil.sqlstr(privilege.getUser(request)) + " order by mydate desc"; DesktopMgr dm = new DesktopMgr(); DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode()); String url = du.getPageShow(); String str = ""; try { ListResult lr = listResult(sql, 1, uds.getCount()); Iterator ir = lr.getResult().iterator(); str += "<ul>"; while (ir.hasNext()) { PlanDb pd = (PlanDb) ir.next(); String mydate = DateUtil.format(pd.getMyDate(), "yy-MM-dd HH:mm"); str += "<li><a href='" + url + "?id=" + pd.getId() + "'>" + mydate + " " + StrUtil.toHtml(pd.getTitle()) + "</a></li>"; } str += "</ul>"; } catch (ErrMsgException e) { logger.info("display:" + e.getMessage()); } return str; } 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, DateUtil.format(myDate, "yyyy-MM-dd HH:mm:ss")); ps.setInt(4, remind?1:0); ps.setString(5, DateUtil.format(remindDate, "yyyy-MM-dd HH:mm:ss")); ps.setInt(6, remindCount); ps.setInt(7, remindBySMS?1:0); ps.setInt(8, id); re = conn.executePreUpdate()==1?true:false; if (re) { PlanCache rc = new PlanCache(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 setTitle(String title) { this.title = title; } public void setContent(String content) { this.content = content; } public void setUserName(String userName) { this.userName = userName; } public void setZdrq(java.util.Date zdrq) { this.zdrq = zdrq; } public void setMyDate(java.util.Date myDate) { this.myDate = myDate; } public void setRemind(boolean remind) { this.remind = remind; } public void setRemindDate(java.util.Date remindDate) { this.remindDate = remindDate; } public void setRemindCount(int remindCount) { this.remindCount = remindCount; } public void setRemindBySMS(boolean remindBySMS) { this.remindBySMS = remindBySMS; } public String getTitle() { return title; } public String getContent() { return content; } public java.util.Date getZdrq() { return zdrq; } public java.util.Date getMyDate() { return myDate; } public String getUserName() { return userName; } public boolean isRemind() { return remind; } public java.util.Date getRemindDate() { return remindDate; } public int getRemindCount() { return remindCount; } public boolean isRemindBySMS() { return remindBySMS; } private String title; private String content; private java.util.Date zdrq; private java.util.Date myDate; private String userName; private boolean remind = false; private java.util.Date remindDate; private int remindCount = 0; private boolean remindBySMS = true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -