def drop_meeting(self, mid, attenders=False, force=False): # delete a meeting and clear attender and remove from mqueue step = 1 rt = MEETING.delete(mid, bymark=not force) if not rt: loger.error("DROP_MEETING(%s): failure when delete from meeting." % mid) self.emsg = "数据库中不存在" return step = 2 if attenders or force: rt = ATTENDERS.drop_bymeeting(mid) if not rt: self.emsg = "删除成员失败" loger.error( "DROP_MEETING(%s): failure when clear attenders. but still continue." % mid) step = 3 _mqueue = Mqueue.get_queue(self.objid) rt = _mqueue.remove(mid) if rt is True: loger.info("DROP_MEETING(%s): success.") MEETING.delete(mid, bymark=False) else: loger.error("DROP_MEETING(%s): failure when remove from queque!") return rt
def today_next_meeting(self, userid, dtime=None): # 用户在指定时间点之后的,当日最近一次会议; # 不建议服务器端执行,用户登录后直接获取自己的当日会议列表,由客户端直接筛选列出来; dtime = dtime or DT.now() date = dtime.date() mqueue = Mqueue.get_queue(self.objid) today_meetings = mqueue.today(date) if today_meetings.length == 0: return 0 # get list of mids of user from db, check in today_meetings(sorted) for the first one today_meetings_str = ','.join([str(i) for i in today_meetings]) sqlcmd = 'SELECT mid FROM %s WHERE mid in (%s) AND userid="%s"' % ( ATTENDERS.work_table, today_meetings_str, userid) #sqlcmd2 = 'SELECT A.mid FROM %s AS A LEFT JION %s AS B ON A.mid=B.mid WHERE A.mid in (%s) AND A.userid="%s" AND B.status>=0' % \ #(ATTENDERS.work_table, METTING.work_table, today_meetings_str, userid) user_mids = self.con.query_db(sqlcmd, single=True) mid = 0 if user_mids: for m in user_mids: if m in today_meetings: mid = m break #if mid > 0: # return METTING.detail(mid) return mid
def list_attenders(self, mid, mcount=-1): mqueue = Mqueue.get_queue(self.objid) _meeting = mqueue[mid] if not _meeting: return ATTENDERS.get_attenders(mid) if mcount == -1: mcount = _meeting.counting return ATTENDERS.get_attenders(mid, mtimes=mcount)
def update_ontime(self, mid, formdata): if not action_ontime(self.objid, mid): return meeting = Mqueue.get_queue(self.objid)[mid] for k, v in formdata.items(): meeting[k] = v MEETING._manage_item('modify', **formdata) return True
def update_ontime(self, mid, formdata): # works for one time meeting only if not action_ontime(self.objid, mid): self.emsg = "不合法的操作时间" return False meeting = Mqueue.get_queue(self.objid)[mid] if meeting.rpmode != mnode.RMODE_ONCE: self.emsg = "只有一次性会议可以编辑时间" return False for k, v in formdata.items(): meeting[k] = v MEETING._manage_item('modify', **formdata) return True
def meeting_off(self, userid, mid, mcount=-1, remark=None): mqueue = Mqueue.get_queue(self.objid) _meeting = mqueue[mid] if not _meeting: # no meeting; one time meeting and overtime; return False now = DT.now() if (_meeting.nextdtime - now).days < 0: self.extdata = "会议已经开始;非可请假时间" if mcount == -1 or mcount is None: mcount = _meeting.counting sqlcmd = 'UPDATE %s SET status=%d,remark="%s" WHERE mid=%d AND userid="%s" AND mtimes=%d' % \ (ATTENDERS.work_table, ATTENDERS.STA_OFF, remark or "", mid, userid, mcount) return ATTENDERS._con_pool.execute_db(sqlcmd)
def meeting_signin(self, userid, mid, identify_key, roomid=None, stime=None, mcount=-1): stime = stime or DT.now() mqueue = Mqueue.get_queue(self.objid) _meeting = mqueue[mid] if not _meeting: self.extdata = '未找到对应的会议' return False print(_meeting, _meeting.mroom) _roomid = _meeting.mroom or METTING._vget(mid, 'mroom') if roomid and _roomid != roomid: self.extdata = '签到会议室和开会会议室不匹配' return False else: roomid = _roomid if not roomid: self.extdata = '找不到对应的会议室' return False if mcount == -1: mcount = _meeting.counting sign_pre, sign_limit = METTING._vget(mid, 'sign_pre,sign_limit', cols=2) #pre_sec = minfo[0] * 60 #limit_sec = minfo[1] * 60 #delta = stime - _meeting_time #if (delta.days == -1 and (24 * 60 *60 - delta.seconds < pre_sec)) or (delta.days == 0 and delta.seconds < limit_sec): # return ATTENDERS.sign(mid, userid, minfo[0], minfo[1], minfo[2], stime=stime) #return False rt = ATTENDERS.sign(mid, userid, _meeting.nextdtime, sign_pre, sign_limit, stime=stime, mcount=mcount) if isinstance(rt, float) and rt < 0: self.extdata = '未到签到时间' return False elif rt: return True else: self.extdata = '签到失败' return False
def action_ontime(cls, objid, mid, ondtime=None, mcount=0): # 确认当前对某个会议进行操作在时间上是否可行 # 会议开始前30分钟不可变更。 # mcount: 当明确给出mcount>0的数值,才会进行对应的比较 m_limit = cls.limits['meeting_modify'] * 60 meeting = Mqueue.get_queue(objid)[mid] if not meeting: loger.warning("mnode with id: %s not found!" % mid) return if mcount > 0 and mcount < meeting.counting: loger.warning("metting[%d] with counting[%d] overtime!" % (mid, mcount)) return if meeting.status == mnode.STA_IDLE: return True ondtime = ondtime or DT.now() delta = meeting.nextdtime - ondtime return delta.days > 0 or (delta.days == 0 and delta.seconds > m_limit)
def newmeeting_safe(self, params, autonode=True, getndtime=False): # return int: -n | 0 | n; # ==> v2: return int,nextdtime # 0: cannot create node or insert to db # -n: conflict with meeting mid = n # n: success create meeting with mid = n roomid = int(params['mroom']) mname = params.get('name') _rpmode = int(params['rpmode']) _ondate = params.get('ondate') _ontime = params['ontime'] _mtime = int(params['mtime']) # with roomid, precheck # precheck room if roomid > 0: if _rpmode == mnode.RMODE_ONCE: x_mid = Mqueue.get_queue(self.objid).filter_room_conflict_once( roomid, _ondate, _ontime, _mtime) else: _rparg = [int(_) for _ in params['rparg'].split(',')] _p_start = params['p_start'] _p_end = params['p_end'] x_mid = Mqueue.get_queue(self.objid).filter_room_conflict( _rpmode, _rparg, roomid, _ontime, _mtime, _p_start, _p_end) if x_mid > 0: loger.error("create meeting but conflic with meeting[%d]" % x_mid) return -x_mid # if no room or no conflict.... if not (_rpmode == mnode.RMODE_ONCE and self._test_ctime(_ondate, _ontime)): loger.error("not allow time") self.emsg = "非许可时间" return 0 try: if _rpmode == mnode.RMODE_ONCE: _node = mnode(0, mname, mroom=roomid, rpmode=_rpmode, ondate=_ondate, ontime=_ontime, mtime=_mtime) else: _rparg = [int(_) for _ in params['rparg'].split(',')] _p_start = params['p_start'] _p_end = params['p_end'] # counting=0 _node = mnode(0, mname, mroom=roomid, rpmode=_rpmode, rparg=_rparg, ontime=_ontime, mtime=_mtime, p_start=_p_start, p_end=_p_end) # for first create new, nextdtime aouto make by node, put with params params['nextdtime'] = _node.nextdtime except ValueError: loger.error("create node wrong with params: [%s]" % params) return 0 mid = MEETING.new(self.objid, params) if mid > 0: _node.mid = mid Mqueue.auto_node(self.objid, _node) if getndtime: self.extdata = _node.nextdtime return mid return 0