Example #1
0
def spread_employee(pin):
    '''
    重新分发人员 (基本信息、指纹、面部)
    '''
    if DEVELOP_MODEL:print 'spread_employee...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        e.call_sync(dev=False)
        time.sleep(0.01)
        fp=FingerPrint(e.PIN,'10')
        fp.call_sync(dev=False)
        time.sleep(0.01)
        fc=Face(e.PIN,'7')
        fc.call_sync(dev=False)
        time.sleep(0.01)
        ep=EmployeePic(e.PIN)
        ep.call_sync(dev=False)
        #读取磁盘数据到redis
        return 0
    except:
        return u'操作失败'
Example #2
0
def del_FingerPrint(pin):
    '''
    删除人员指纹
    '''
    if DEVELOP_MODEL:print 'del_FingerPrint...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        FingerPrint.deletes(e.getoo(),e.PIN)
        return 0
    except:
        return u'操作失败'
Example #3
0
def del_Face(pin):
    '''
    删除人员面部
    '''
    if DEVELOP_MODEL:print 'del_Face...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        Face.deletes(e.getoo(),e.PIN)
        return 0
    except:
        import traceback; traceback.print_exc()
        return u'操作失败'
Example #4
0
def spread_FingerPrint(pin):
    '''
    重新分发人员指纹
    '''
    if DEVELOP_MODEL:print 'spread_FingerPrint...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        fp=FingerPrint(e.PIN,'10')
        #读取磁盘数据到redis
        fp.call_sync(dev=False)
        return 0
    except:
        return u'操作失败'
Example #5
0
def spread_face(pin):
    '''
    重新分发人员面部
    '''
    if DEVELOP_MODEL:print 'spread_face...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        fc=Face(e.PIN,'7')
        fc.call_sync(dev=False)
        #读取磁盘数据到redis
        return 0
    except:
        return u'操作失败'
Example #6
0
def del_EmployeePic(pin):
    '''
    删除人员照片
    '''
    if DEVELOP_MODEL:print 'del_EmployeePic...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        ep=EmployeePic(e.PIN)
        ep.delete()
        #磁盘操作
        return 0
    except:
        return u'操作失败'
Example #7
0
def spread_EmployeePic(pin):
    '''
    重新分发人员照片
    '''
    if DEVELOP_MODEL:print 'spread_EmployeePic...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        ep=EmployeePic(e.PIN)
        #读取磁盘数据到redis
        ep.call_sync(dev=False)
        return 0
    except:
        return u'操作失败'
Example #8
0
def del_Employee(pin):
    '''
    删除人员(此操作会删除redis中该人员的所有数据 触发机器删除该人员
    并删除对应的指纹,面部和人员照片的本地存储和设备存储)
    '''
    if DEVELOP_MODEL:print 'del_Employee...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        e.delete()
        del_FingerPrint(e.PIN)
        del_Face(e.PIN)
        del_EmployeePic(e.PIN)
        return 0
    except:
        return u'操作失败'
Example #9
0
def cdata_get_pin(request, device):
    '''
    请求中 带人员PIN参数时的处理 返回人员基本信息和指纹模板信息、删除人员
    涉及 http参数:pin、save 
    '''
    resp = ""
    pin = request.REQUEST['PIN']
    #pin = format_pin(pin)
    try:
        emp = Employee(pin).get()
        emp_info = emp.get_info()
        emp_fp = ''  #emp.get_fp()
        cc = emp_info + emp_fp
        try:
            resp += cc.encode("gb18030")
        except:
            resp += cc.decode("utf-8").encode("gb18030")
        return device_response_write(resp)
    except ObjectDoesNotExist:  #---人员不存在
        return none_response()
Example #10
0
def set_EmployeePic(pin,data,call_sync=True):
    '''
    更新用户照片 (这里会将新用户照片加载到redis, 并触发sync同步到各设备) 
    '''
    if DEVELOP_MODEL:print 'set_EmployeePic...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        pic = EmployeePic(e.PIN)
        pic.init_counter()
        if data:
            pic.data = data
            pic.set("data")
        if call_sync:
            pic.call_sync(dev=False)
        return 0
    except:
        return u'操作失败'
Example #11
0
def set_Face(pin,face_ver, fid, data, call_sync=True):
    '''
    更新指纹 (目前暂无客户端界面登录面部,功能 这里会将新面部存储并触发sync同步到各设备) 
    '''
    if DEVELOP_MODEL:print 'set_Face...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        fc=Face(e.PIN, face_ver)
        m_key = 'face%s'%int(fid)
        fc.init_counter()
        if data:
            setattr(fc, m_key , data)
            fc.set(m_key)
        if call_sync:
            fc.call_sync(dev=False)
        return 0
    except:
        return u'操作失败'
Example #12
0
def set_FingerPrint(pin,fpversion,fid,data, call_sync=True,force=False):
    '''
    更新指纹 (主要供登记指纹的操作调用, 这里会将新指纹存储并触发sync同步到各设备) 
    '''
    if DEVELOP_MODEL:print 'set_FingerPrint...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        fp=FingerPrint(e.PIN, fpversion)
        m_key = 'fp%s'%int(fid)
        fp.init_counter()
        if data:
            setattr(fp, m_key , data)
            fp.set(m_key,force)
        if call_sync:
            fp.call_sync(dev=False)
        return 0 
    except:
        return u'操作失败'
Example #13
0
def set_info(pin,info_dic,call_sync=True):
    '''
    更新人员信息(只用于info的更新,区域的更新另作处理 如果是新人员则在redis中创建)
    call_sync 是否触发同步
    '''
    if DEVELOP_MODEL:print 'set_info...'
    try:
        e=Employee(pin)
        try:
            e=e.get()
        except ObjectDoesNotExist:
            pass
        e.sets(info_dic)
        if call_sync:
            e.call_sync(dev=False)
        return 0
    except:
        import traceback;traceback.print_exc()
        return u'操作失败'
Example #14
0
def set_area(pin,area_list,call_sync=True):
    '''
    更新区域 (此操作会向老区域里下发del,向新区域下发info)
    call_sync 是否触发同步
    '''
    if DEVELOP_MODEL:print 'set_area...'
    e=Employee(pin)
    try:
        e=e.get()
    except ObjectDoesNotExist:
        return u'人员不存在'
    try:
        e.sync = call_sync
        m_list = [str(id) for id in area_list]
        e.set_areas(m_list)
        return 0
    except:
        return u'操作失败'
Example #15
0
def line_to_emp(cursor, device, line, Op, event=True):
    '''
    设备更新人员信息的总接口    
    line:设备post过来的命令字符串
    device:传送命令的设备
    '''
    try:  #---行数据以空格分割标志名和键值对数据
        if line.find("\tName=") > 0:
            ops = unicode(line.decode("gb18030")).split(" ", 1)
        else:
            ops = line.split(" ", 1)
    except:
        ops = line.split(" ", 1)

    if ops[0] == 'OPLOG':  #设备操作记录
        from sync_conv_device import line_to_oplog
        return line_to_oplog(device, ops[1])

    flds = {}
    #获取行数据中包含的所有键值对
    for item in ops[1].split("\t"):
        index = item.find("=")
        if index > 0: flds[item[:index]] = item[index + 1:]

    try:  #工号有效性验证
        pin = flds["PIN"]
        if len(pin) > settings.PIN_WIDTH:
            return
    except:
        return

    e = Employee(pin)
    try:
        e = e.get()
    except ObjectDoesNotExist:
        if not DEVICE_CREATEUSER_FLAG:
            return None
        e.EName = pin

    data_type = str(ops[0]).strip()
    ########################### 人员基本信息 #########################
    if data_type == "USER":
        if not DEVICE_CREATEUSER_FLAG:
            return
        try:
            ename = unicode(flds["Name"])[:40]
        except:
            ename = ''
        passwd = flds.get("Passwd", "")
        if DEVICE_CREATECARD_FLAG:
            card = flds.get("Card", "")
        else:
            card = None
        vcard = card_to_num(card)
        agrp = flds.get("Grp", "")
        tz = flds.get("TZ", "")
        priv = flds.get('Pri', 0)
        if ename:
            e.EName = ename
        if passwd:
            e.Password = passwd
        if priv:
            e.Privilege = str(priv)
        if card:
            e.Card = vcard
        if agrp:
            e.AccGroup = str(agrp)
        if tz:
            e.TimeZones = tz
        e.set()  #触发redis保存
        if e.isnew():
            e.set_area(device.area, dev=device.sn)  #dev 用于指定不下发的设备
            e.call_sync(dev=device.sn, just=device.sn)  # 只触发webserver 更新
        else:
            if device.area in e.get_area():
                e.call_sync(device.sn)  #触发其他所有终端(包括webserver)更新
            else:
                e.set_area(device.area, dev=device.sn)
                e.call_sync(dev=device.sn, just=device.sn)  # 只触发webserver 更新
        return True
    ########################### 人员指纹模板 #########################
    elif data_type == "FP":
        if not DEVICE_CREATEBIO_FLAG:
            return
        try:
            size = flds["Size"]
            data = flds["TMP"]
            d_len = len(data.decode("base64"))
            if data and (len(data) == int(size) or d_len == int(size)):
                fp = FingerPrint(e.PIN, device.Fpversion or '10')
                m_key = 'fp%s' % int(flds["FID"])
                setattr(fp, m_key, data)
                try:
                    if e.isnew():
                        e.set()
                        e.set_area(device.area, dev=device.sn)
                        e.call_sync(dev=device.sn, just=device.sn)
                    fp.set(m_key)  #触发保存指纹到数据库
                    fp.call_sync(device.sn)  #触发其他设备更新
                except:
                    import traceback
                    traceback.print_exc()
                    print 'sync error 201'
                return True
            else:
                print "template length error"
                return False
        except:
            import traceback
            traceback.print_exc()
            return False
    ########################### 人员人脸模板 #########################
    elif data_type == "FACE":
        try:
            size = flds["SIZE"]
            data = flds["TMP"]
            d_len = len(data.decode("base64"))
            if data and (len(data) == int(size) or d_len == int(size)):
                fc = Face(e.PIN, device.face_ver or '7')
                m_key = 'face%s' % int(flds["FID"])
                setattr(fc, m_key, data)
                try:
                    if e.isnew():
                        e.set()
                        e.set_area(device.area, dev=device.sn)
                        e.call_sync(dev=device.sn, just=device.sn)
                    fc.set(m_key)
                    fc.call_sync(device.sn)
                except:
                    import traceback
                    traceback.print_exc()
                    print 'sync error 202 '
                return True
            else:
                print "face length error"
                return False
        except:
            import traceback
            traceback.print_exc()
            return False
    ########################### 人员照片 #########################
    elif data_type == "USERPIC":
        if device.alg_ver < '2.2.0':
            return
        try:
            userpin = flds["PIN"]
            filename = flds["FileName"]
            size = flds["Size"]
            pic = EmployeePic(e.PIN)
            pic.data = flds["Content"].decode('base64')
            try:
                if e.isnew():
                    e.set()
                    e.set_area(device.area, dev=device.sn)
                    e.call_sync(dev=device.sn, just=device.sn)
                pic.set("data")
                pic.call_sync(device.sn)
            except:
                import traceback
                traceback.print_exc()
                print 'sync error 203'
            return True
        except:
            import traceback
            traceback.print_exc()
            return False
Example #16
0
def get_area(pin):
    '''
    获得人员在redis中的区域
    '''
    e=Employee(pin)
    return e.get_area()
Example #17
0
def get_FingerPrint_count(pin):
    '''
    获取指纹数 
    '''
    e=Employee(pin)
    return e.getc_fp()
Example #18
0
def get_face_count(pin):
    '''
    获取面部数
    '''
    e=Employee(pin)
    return e.getc_face()