コード例 #1
0
ファイル: server_update.py プロジェクト: baksoikan/zktime_wlm
def set_card(emp, cardNO):
    from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID, CARD_STOP
    from mysite.personnel.models.model_iccard import ICcard
    if get_option("POS") or cardNO == "0" or (not cardNO.strip()):
        return
    try:
        tmp_issuecare = IssueCard.objects.filter(UserID=emp)
        if tmp_issuecare:  #编辑
            if tmp_issuecare[0].cardno <> cardNO:
                #				old_card = tmp_issuecare[0].cardno
                #				tmp_issuecare[0].cardstatus = CARD_STOP  #停用旧卡号
                tmp_issuecare[0].cardno = cardNO
                tmp_issuecare[0].save(force_update=True)
        else:
            issuecard = IssueCard()
            issuecard.UserID = emp
            issuecard.cardno = cardNO
            issuecard.issuedate = datetime.datetime.now().strftime("%Y-%m-%d")
            try:
                issuecard.save()
            except IntegrityError:
                conn._rollback()
                conn.close()
    except:
        import traceback
        traceback.print_exc()
コード例 #2
0
def funSaveCardmanage(request):
    from mysite.personnel.models.model_issuecard import IssueCard, PRIVAGE_CARD, POS_CARD, CARD_LOST, CARD_STOP, CARD_OVERDUE, CARD_VALID
    from mysite.iclock.models.dev_comm_operate import update_pos_device_info
    from mysite.iclock.models.model_device import Device, DEVICE_POS_SERVER
    from mysite.pos.models.model_cardmanage import CardManage
    from mysite.iclock.models.model_dininghall import Dininghall
    from mysite.pos.pos_constant import TIMEOUT
    from django.core.cache import cache
    obj = request.POST
    request.session.save()
    card_privage = obj['card_privage']
    card = int(obj['cardno'])
    sys_card_no = obj['sys_card_no']
    pwd = obj['Password']
    dining_id = obj['dining']
    try:
        if IssueCard.objects.get(cardno=card):
            return getJSResponse("result=ISUSE")  #卡号已经使用
    except:
        pass
    try:
        if IssueCard.objects.get(sys_card_no=sys_card_no):
            return getJSResponse("result=SYS_ISUSE")  #卡账号重复
    except:
        pass
    try:
        CardManage(card_no=card,
                   pass_word=pwd,
                   dining_id=dining_id,
                   cardstatus=CARD_VALID,
                   sys_card_no=sys_card_no,
                   card_privage=card_privage).save()
        IssueCard(cardno=card,
                  sys_card_no=sys_card_no,
                  cardstatus=CARD_VALID,
                  card_privage=card_privage,
                  Password=pwd,
                  type=None).save()
        dev = Device.objects.filter(
            device_type=DEVICE_POS_SERVER,
            dining=Dininghall.objects.get(pk=dining_id))
        objcard = IssueCard.objects.get(sys_card_no=sys_card_no)
        update_pos_device_info(dev, [objcard], "USERINFO")
        return getJSResponse("result=OK")
    except:
        cache.delete("IC_Card_Count")
        import traceback
        traceback.print_exc()
        return getJSResponse("result=FAIL")
コード例 #3
0
ファイル: test.py プロジェクト: baksoikan/zktime_wlm
def insert_card():
    pin=set_random(1,100)
    for i in pin:
        IssueCard(
                UserID_id=1,
                cardno=i,
                type_id=1,
                blance=Decimal('10000'),
                mng_cost=Decimal(10),
                card_cost=Decimal('10'),
                date_money=Decimal('20'),
                meal_money=Decimal('20'),
                card_privage='0',).save(force_insert=True, log_msg=False)
        print "inset date......"
    print "end"
コード例 #4
0
def funIssueAddCardSave(request):
    from mysite.pos.models import CarCashSZ, CarCashType
    from mysite.personnel.models.model_emp import Employee
    from django.core.cache import cache
    from mysite.pos.pos_constant import TIMEOUT
    from mysite.iclock.models.dev_comm_operate import update_pos_device_info
    from mysite.iclock.models.model_device import Device, DEVICE_POS_SERVER
    from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID, PRIVAGE_CARD, POS_CARD, CARD_STOP, CARD_OVERDUE
    obj = request.POST
    request.session.save()
    try:
        if obj.has_key("UserID"):
            user_id = obj['UserID']
            emp = Employee.objects.get(id=user_id)
        else:
            user_pin = obj['user_pin']
            emp = Employee.objects.get(PIN=user_pin)
        card = int(obj['cardno'])
        money = Decimal(obj['blance'])
        card_serial_no = obj['card_serial_no']
        operate_type = obj['operate_type']
        sys_card_no = obj['sys_card_no']
        type = obj['type']
        card_cost = obj['card_cost']
        mng_cost = obj['mng_cost']
        card_privage = obj['card_privage']
        pwd = obj['Password']
        newblance = money
        if operate_type == '12':  #换卡
            newblance = 0
            from mysite.pos.models import ReplenishCard
            old_sys_card_no = obj['old_sys_card_no']
            ReplenishCard(user=emp,
                          oldcardno=old_sys_card_no,
                          newcardno=sys_card_no,
                          blance=0).save()
            objcard = IssueCard.objects.get(sys_card_no=old_sys_card_no)
            objcard.cardstatus = CARD_STOP
            objcard.save()
            IssueCard(UserID=emp,
                      cardno=card,
                      sys_card_no=sys_card_no,
                      cardstatus=CARD_VALID,
                      card_privage=POS_CARD,
                      card_cost=card_cost,
                      mng_cost=mng_cost,
                      issuedate=datetime.now().date(),
                      type_id=type,
                      blance=0,
                      Password=pwd,
                      card_serial_num=card_serial_no).save()
            #            cache.set("IC_Card_Count",sys_card_no,TIMEOUT)
            dev = Device.objects.filter(device_type=DEVICE_POS_SERVER)
            update_pos_device_info(dev, [objcard], "USERINFO")  #下发原卡为黑名单
            new_objcard = IssueCard.objects.get(sys_card_no=sys_card_no)
            update_pos_device_info(dev, [new_objcard], "USERINFO")  #下发白名单卡
        else:  #发卡
            obj = IssueCard.objects.filter(
                UserID=emp,
                cardstatus__in=[CARD_OVERDUE, CARD_VALID],
                card_privage=POS_CARD,
                sys_card_no__isnull=True)
            if obj:
                obj[0].type_id = type
                obj[0].blance = money
                obj[0].Password = pwd
                obj[0].sys_card_no = sys_card_no
                obj[0].cardno = card
                obj[0].card_cost = card_cost
                obj[0].mng_cost = mng_cost
                obj[0].card_serial_num = 1
                obj[0].issuedate = datetime.now().date()
                obj[0].create_time = datetime.now()
                obj[0].save(force_update=True)
#                cache.set("IC_Card_Count",sys_card_no,TIMEOUT)
            else:
                IssueCard(UserID=emp,
                          cardno=card,
                          sys_card_no=sys_card_no,
                          cardstatus=CARD_VALID,
                          card_privage=card_privage,
                          card_cost=card_cost,
                          mng_cost=mng_cost,
                          issuedate=datetime.now().date(),
                          type_id=type,
                          blance=money,
                          Password=pwd,
                          card_serial_num=1).save()
#                cache.set("IC_Card_Count",sys_card_no,TIMEOUT)
            objcard = IssueCard.objects.get(sys_card_no=sys_card_no)
            dev = Device.objects.filter(device_type=DEVICE_POS_SERVER)
            update_pos_device_info(dev, [objcard], "USERINFO")  #下发白名单卡
        if card_privage == POS_CARD:
            #            blance_valid(type,newblance,emp)#验证余额
            CarCashSZ(
                user=emp,
                card=card,
                checktime=datetime.now(),
                type_id=7,  #cost type 发卡
                cardserial=card_serial_no,
                money=card_cost,
                sys_card_no=sys_card_no,
                hide_column=7,
                blance=newblance,
                log_flag=2).save()
            if operate_type <> '12' and money > 0:  #换卡
                CarCashSZ(
                    user=emp,
                    card=card,
                    sys_card_no=sys_card_no,
                    checktime=datetime.now(),
                    cardserial=card_serial_no,
                    type_id=1,  #cost type发卡的时候充值
                    money=money,
                    hide_column=1,
                    blance=newblance,
                    log_flag=2).save()
            CarCashSZ(
                user=emp,
                card=card,
                sys_card_no=sys_card_no,
                checktime=datetime.now(),
                type_id=11,  #cost type 管理费
                cardserial=card_serial_no,
                money=mng_cost,
                hide_column=11,
                blance=newblance,
                log_flag=2).save()
            return getJSResponse("result=OK")
    except:
        import traceback
        traceback.print_exc()
        cache.delete("IC_Card_Count")
        return getJSResponse("result=FAIL")
コード例 #5
0
def process_user_info(qret):
    if qret['result'] == 0:
        return {"ret": qret['result'], "retdata": ""}
    elif qret['result'] > 0:
        try:
            #处理从设备中获取的用户信息
            ret_data = qret['data'].split('\r\n')
            user_info_list = ret_data[1:-1]
            #print '+++++++++user_info_list =',qret['data']
            if user_info_list != []:
                i = 0
                if ret_data[0].split(",")[0] == "UID":  #inbio 比C3多一个字段
                    i = 1
#                print 'come into user_info'
                from mysite.personnel.models.model_morecardempgroup import AccMoreCardEmpGroup
                from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID, CARD_OVERDUE
                pin_list = []  #人员编号列表
                pin_emp_dict = {}  #字典,存储人员
                emps = Employee.all_objects.all()
                for emp in emps:
                    pin_list.append(emp.PIN)
                    pin_emp_dict[emp.PIN] = emp

                #将设备中的用户存放到一个默认部门
                from mysite.personnel.models.model_dept import Department
                dept = Department.objects.get(id=1)

                #发卡表
                issue_card_dict = {}
                issue_card = IssueCard.objects.filter(
                    cardstatus__in=[CARD_OVERDUE, CARD_VALID])
                for issue in issue_card:
                    issue_card_dict[issue.UserID] = issue

                for user_info in user_info_list:
                    user_info = user_info.split(",")
                    card = int(user_info[0 + i])
                    pin = format_pin(user_info[1 + i])
                    password = user_info[2 + i]
                    group = int(user_info[3 + i])  #人员组
                    start = user_info[4 + i]  #启用门禁日期
                    end = user_info[5 + i]  #结束门禁日期

                    start_time = start != '0' and str_to_date(start) or None
                    end_time = end != '0' and str_to_date(end) or None
                    card = card or ""
                    more_card_group = AccMoreCardEmpGroup.objects.filter(
                        id=group)  #查询人员组
                    if more_card_group:  #人员组存在
                        more_card_group = more_card_group[0]
                    else:
                        more_card_group = None

#                    if pin in pin_list:#如果用户存在,更新数据
#                        emp = pin_emp_dict[pin]
##                        print 'pin in pin_list'
#
#                        emp.acc_startdate = start_time
#                        emp.acc_enddate = end_time
#                        emp.morecard_group = more_card_group
#                        emp.Password = password
#                        emp.save(force_update=True)
                    if pin not in pin_list:  #不存在, 插入数据库
                        employee = Employee(PIN=pin,
                                            DeptID=dept,
                                            Password=password,
                                            acc_startdate=start_time,
                                            acc_enddate=end_time,
                                            morecard_group=more_card_group)
                        employee.save(force_insert=True)

                        if issue_card_dict.has_key(employee):
                            iss_card = issue_card_dict[employee]
                            iss_card.cardno = card
                            iss_card.save()
                        else:
                            iss_card = IssueCard()
                            iss_card.UserID = employee
                            iss_card.cardno = card
                            iss_card.cardstatus = CARD_VALID
                            iss_card.save()
        except:
            print_exc()
        return {"ret": qret['result'], "retdata": ""}

    else:
        return {"ret": -1, "retdata": ""}
コード例 #6
0
def line_to_emp(cursor, device, line, Op, event=True):
    '''
    解析设备命令    
    line:设备post过来的命令字符串
    device:传送命令的设备
    '''
    from mysite import settings
    import os
    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':  #-------------管理员操作记录        ops[0] 为标志名
        from conv_device import line_to_oplog
        return line_to_oplog(cursor, device, ops[1], event)

    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 pin in settings.DISABLED_PINS or len(
                pin) > settings.PIN_WIDTH:  #----用户编号有效性验证
            return
    except:
        return

    e = get_employee(pin, device)  #--- 得到命令对应的人员对象  必须有
    if not e:
        return
    if str(ops[0]).strip() == "USER":  #----------用户基本信息
        if not settings.DEVICE_CREATEUSER_FLAG:
            return
        try:
            ename = unicode(flds["Name"])[:40]
        except:
            ename = ' '
        passwd = flds.get("Passwd", "")
        card = flds.get("Card", "")
        tmp_card = ""  #卡号保存在isssuecard里面
        agrp = flds.get("Grp", "")
        tz = flds.get("TZ", "")
        priv = flds.get('Pri', 0)
        fldNames = ['SN', 'utime']
        values = [device.id, str(datetime.datetime.now())[:19]]
        if ename and (ename != e.EName):
            fldNames.append('name')
            values.append(ename)
            e.EName = ename
        from base.crypt import encryption  #设备传过来的密码没加密   需要加密再和数据库中的比较
        if passwd and (encryption(passwd) != e.Password):
            fldNames.append('password')
            values.append(passwd)
            e.Password = passwd
        if priv and (str(priv) != str(e.Privilege)):  #考虑下数据字段类型
            fldNames.append('privilege')
            values.append(str(priv))
            e.Privilege = str(priv)
        if card and (card_to_num(card) != e.Card):
            if str(card_to_num(card)).strip() != "0":
                vcard = card_to_num(card)
            else:
                vcard = ""
            fldNames.append('Card')
            values.append(vcard)
            tmp_card = vcard
        elif card == "" and e.Card:  #机器是否删除卡号
            fldNames.append('Card')
            values.append("")
            tmp_card = ""
        if agrp and (str(agrp) != str(e.AccGroup)):
            fldNames.append('AccGroup')
            values.append(str(agrp))
            e.AccGroup = str(agrp)
        if tz != e.TimeZones:
            fldNames.append('TimeZones')
            values.append(tz)
            e.TimeZones = tz
        try:
            e.IsNewEmp
        except:
            e.IsNewEmp = False
        if e.IsNewEmp:  #新增用户
            e.IsNewEmp = False
            e.DeptID_id = 1
            e.attarea = (device.area, )
            e.save()
            if tmp_card and not get_option("POS"):
                from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID
                obj_card = IssueCard()
                obj_card.UserID = e
                obj_card.cardno = tmp_card
                obj_card.cardstatus = CARD_VALID
                obj_card.save()
            devs = set(e.search_device_byuser())
            if devs:
                try:
                    devs.remove(device)
                except:
                    pass
            for dev in devs:
                dev.set_user([e], Op, "")
                dev.set_user_fingerprint([e], Op)
                time.sleep(0.01)
            sql = ''
        elif len(fldNames) > 2:  #有新的用户信息
            from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID, CARD_STOP
            devs = set(e.search_device_byuser())
            e.save()

            try:
                obj_card = IssueCard.objects.get(UserID=e, cardno=tmp_card)
            except:
                obj_card = None

                if not obj_card and not get_option("POS"):
                    try:
                        temp_card = IssueCard.objects.get(
                            UserID=e, cardstatus=CARD_VALID)
                        temp_card.cardstatus = CARD_STOP  #停用之前的卡号
                        temp_card.save()
                    except:
                        pass
                    if tmp_card:  #卡处理
                        obj_card = IssueCard()
                        obj_card.UserID = e
                        obj_card.cardno = tmp_card
                        obj_card.cardstatus = CARD_VALID
                        obj_card.save()
                else:
                    if not get_option("POS"):  #消费的时候不能覆盖
                        obj_card.cardno = tmp_card
                        obj_card.save()
            if devs:
                try:
                    devs.remove(device)
                except:
                    pass
            for dev in devs:
                dev.set_user([e], Op, "")
                dev.set_user_fingerprint([e], Op)
                time.sleep(0.01)
        else:
            pass
        return e

    elif str(ops[0]).strip() == "FP":  #----------------用户的指纹模板
        if not settings.DEVICE_CREATEBIO_FLAG:
            return

        if e.IsNewEmp:  #新增用户
            e.DeptID_id = 1
            e.attarea = (device.area, )
            e.save()
        emps = e
        try:
            size = flds["Size"]
            fp = flds["TMP"]
            d_len = len(fp.decode("base64"))
            if fp and (len(fp) == int(size) or d_len == int(size)):
                devs = set(e.search_device_byuser())
                if devs:
                    try:
                        devs.remove(device)
                    except:
                        pass
                e = Template.objects.filter(UserID=e.id,
                                            FingerID=int(flds["FID"]),
                                            Fpversion=device.Fpversion)
                if len(e) > 0:
                    e = e[0]
                    if fp[:100] == e.Template[:100]:
                        pass  # Template is same
                    else:  #指纹有修改
                        e.Template = fp
                        e.Fpversion = device.Fpversion
                        e.UTime = datetime.datetime.now().strftime(
                            "%Y-%m-%d %H:%M:%S")
                        e.save()
                        for dev in devs:
                            dev.set_user_fingerprint([emps], Op,
                                                     int(flds["FID"]))
                            time.sleep(0.01)
                else:  #新增指纹
                    e = Template()
                    e.UserID = emps
                    e.Template = fp
                    e.UTime = datetime.datetime.now().strftime(
                        "%Y-%m-%d %H:%M:%S")
                    e.FingerID = int(flds["FID"])
                    e.Fpversion = device.Fpversion
                    e.Valid = 1
                    e.save()
                    for dev in devs:
                        dev.set_user_fingerprint([emps], Op, int(flds["FID"]))
                        time.sleep(0.01)
                return True
            else:
                print "size:%s   TMP size:%s" % (size, len(fp))
                print "template length error"
        except:
            import traceback
            traceback.print_exc()
        else:
            return False

    elif str(ops[0]).strip(
    ) == "FACE":  ######################## 新增人脸模板相关命令处理  ##################
        if e.IsNewEmp:  #-----保存设备新增用户的其他信息
            e.DeptID_id = 1
            e.attarea = (device.area, )
            e.save()
        emps = e
        try:
            postuser_face(flds, e, device, Op)
            return True
        except:
            import traceback
            traceback.print_exc()
        else:
            return False
    elif str(ops[0]).strip() == "USERPIC":  #####################加入用户照片 处理
        if e.IsNewEmp:  #-----保存设备新增用户的其他信息
            e.DeptID_id = 1
            e.attarea = (device.area, )
            e.save()
        emps = e
        try:
            postuser_photo(flds, e, device)
            return True
        except:
            import traceback
            traceback.print_exc()
        else:
            return False
コード例 #7
0
ファイル: conv_emp.py プロジェクト: SongJLG/johan-doc
def line_to_emp(cursor, device, line, Op,event=True):
    '''
    解析设备命令    
    line:设备post过来的命令字符串
    device:传送命令的设备
    '''
    from mysite import settings
    import os
    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':   #-------------管理员操作记录        ops[0] 为标志名
        from conv_device import line_to_oplog
        return line_to_oplog(cursor, device, ops[1], event)
    
    flds = {};  #-----------行数据中包含的所以键值对
    for item in ops[1].split("\t"):
        index = item.find("=")
        if index > 0: flds[item[:index]] = item[index + 1:]
        
    try:
        pin = str(int(flds["PIN"])) #---得到用户编号
        if int(pin) in settings.DISABLED_PINS or len(pin)>settings.PIN_WIDTH: #----用户编号有效性验证
            return
    except:
        return
    
    e = get_employee(pin, device)   #--- 得到命令对应的人员对象  必须有
    if not e:
        return
    if str(ops[0]).strip() == "USER":   #----------用户基本信息
        if not settings.DEVICE_CREATEUSER_FLAG:
            return 
        try:
            ename = unicode(flds["Name"])[:40]
        except:
            ename = ' '
        passwd = flds.get("Passwd","")
        card = flds.get("Card", "")
        tmp_card = "" #卡号保存在isssuecard里面
        agrp = flds.get("Grp", "")
        tz = flds.get("TZ","")
        priv = flds.get('Pri', 0)
        fldNames = ['SN', 'utime']
        values = [device.id, str(datetime.datetime.now())[:19]]
        if ename and (ename != e.EName):
            fldNames.append('name')
            values.append(ename)
            e.EName = ename
        from base.crypt import encryption#设备传过来的密码没加密   需要加密再和数据库中的比较
        if passwd and (encryption(passwd) != e.Password):
            fldNames.append('password')
            values.append(passwd)
            e.Password = passwd
        if priv and (str(priv) !=str(e.Privilege)):#考虑下数据字段类型
            fldNames.append('privilege')
            values.append(str(priv))
            e.Privilege = str(priv)
        if card and (card_to_num(card) != e.Card):
            if str(card_to_num(card)).strip()!="0":
                vcard=card_to_num(card)
            else:
                vcard=""
            fldNames.append('Card')
            values.append(vcard)
            tmp_card = vcard
        if agrp and (str(agrp) != str(e.AccGroup)):
            fldNames.append('AccGroup')
            values.append(str(agrp))
            e.AccGroup = str(agrp)
        if tz != e.TimeZones:
            fldNames.append('TimeZones')
            values.append(tz)
            e.TimeZones = tz
        try:
            e.IsNewEmp
        except:
            e.IsNewEmp = False
        if e.IsNewEmp:    #新增用户
            e.IsNewEmp = False     
            e.DeptID_id=1       
            e.attarea=(device.area,)
            e.save()
            if tmp_card and not get_option("POS"):
                from mysite.personnel.models.model_issuecard import IssueCard,CARD_VALID
                obj_card = IssueCard()
                obj_card.UserID = e
                obj_card.cardno = tmp_card
                obj_card.cardstatus = CARD_VALID
                obj_card.save()
                
            devs=set(e.search_device_byuser()) 
            if devs:
                try:
                    devs.remove(device)
                except:
                    pass
            for dev in devs:
                dev.set_user([e], Op,"")
                dev.set_user_fingerprint([e], Op)
                time.sleep(0.01)    
            sql = ''
        elif len(fldNames) > 2: #有新的用户信息
            devs=set(e.search_device_byuser()) 
            e.save()
            
            if tmp_card:#卡处理
                from mysite.personnel.models.model_issuecard import IssueCard,CARD_VALID
                try:
                    obj_card  = IssueCard.objects.get(UserID=e,cardstatus=CARD_VALID)
                except:
                    obj_card = None
                
                if not obj_card:
                    obj_card = IssueCard()
                    obj_card.UserID = e
                    obj_card.cardno = tmp_card
                    obj_card.cardstatus = CARD_VALID
                    obj_card.save()
                else:
                    if not get_option("POS"):#消费的时候不能覆盖
                        obj_card.cardno = tmp_card
                        obj_card.save()
            
            if devs:
                try:
                    devs.remove(device)
                except:
                    pass
            for dev in devs:
                dev.set_user([e], Op,"")
                dev.set_user_fingerprint([e], Op)
                time.sleep(0.01)
        else:
            pass
        return e
    
    elif str(ops[0]).strip() == "FP":   #----------------用户的指纹模板
        if not settings.DEVICE_CREATEBIO_FLAG:
            return
          
        if e.IsNewEmp:    #新增用户               
            e.DeptID_id=1       
            e.attarea=(device.area,)
            e.save()
        emps=e
        try:
            size=flds["Size"]            
            fp = flds["TMP"]    
            d_len=len(fp.decode("base64"))
            if fp and (len(fp)==int(size) or d_len==int(size) ):
                devs=set(e.search_device_byuser())
                if devs:
                    try:
                        devs.remove(device)
                    except:
                        pass
                e = Template.objects.filter(UserID=e.id, FingerID=int(flds["FID"]),Fpversion=device.Fpversion)
                if len(e)>0:
                    e=e[0]
                    if fp[:100] == e.Template[:100]:
                        pass # Template is same
                    else:                        #指纹有修改
                        e.Template=fp
                        e.Fpversion=device.Fpversion
                        e.UTime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                        e.save()
                        for dev in devs:
                            dev.set_user_fingerprint([emps], Op, int(flds["FID"]))
                            time.sleep(0.01)
                else:     #新增指纹
                    e=Template()
                    e.UserID=emps
                    e.Template=fp
                    e.UTime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    e.FingerID=int(flds["FID"])
                    e.Fpversion=device.Fpversion
                    e.Valid=1
                    e.save()
                    for dev in devs:
                        dev.set_user_fingerprint([emps], Op, int(flds["FID"]))
                        time.sleep(0.01)
                return True
            else:
                print "size:%s   TMP size:%s"%(size,len(fp))
                print "template length error"
        except:
            import traceback; traceback.print_exc();            
        else:
            return False
        
    elif str(ops[0]).strip() == "FACE" :    ######################## 新增人脸模板相关命令处理  ##################
        if e.IsNewEmp:    #-----保存设备新增用户的其他信息               
            e.DeptID_id=1       
            e.attarea=(device.area,)
            e.save()
        emps=e
        try:
            from  new_push import postuser_face
            postuser_face(flds,e,device,Op)
            return True
        except:
            import traceback; traceback.print_exc();            
        else:
            return False
    elif str(ops[0]).strip() == "USERPIC" :    #####################加入用户照片 处理
        if e.IsNewEmp:    #-----保存设备新增用户的其他信息               
            e.DeptID_id=1       
            e.attarea=(device.area,)
            e.save()
        emps=e
        try:
            from  new_push import postuser_photo
            postuser_photo(flds,e,device)
            return True
        except:
            import traceback; traceback.print_exc(); 
        else:
            return False