Exemple #1
0
def appendDevCmdOld(dObj, cmdStr, Op, cmdTime=None):
        from mysite.iclock.models.model_devcmd import DevCmd
        try:
            #print cmdStr
            cmd=DevCmd(SN=dObj, CmdOperate=Op, CmdContent=cmdStr, CmdCommitTime=(cmdTime or datetime.datetime.now()))
            cmd.save(force_insert=True)
            return cmd.id
        except:
            print_exc()
Exemple #2
0
def appendDevCmdReturn(dObj, cmdStr):
    from mysite.iclock.models.model_devcmd import DevCmd
    try:
        cmd = DevCmd(SN=dObj,
                     CmdContent=cmdStr,
                     CmdCommitTime=datetime.datetime.now(),
                     CmdImmediately=True)
        cmd.save(force_insert=True)
        return cmd.id
    except:
        print_exc()
Exemple #3
0
def appendDevCmdReturn(dObj, cmdStr):
    '''
    执行设备信息查询命令
    dObj: 设备序列号
    cmdStr: 命令字符串
    返回命令编号
    '''
    from mysite.iclock.models.model_devcmd import DevCmd
    try:
        cmd=DevCmd(SN=dObj, CmdContent=cmdStr, CmdCommitTime=datetime.datetime.now(), CmdImmediately=True)
        cmd.save(force_insert=True)
        return cmd.id 
    except:
        print_exc()
Exemple #4
0
def process_upload_handler():
    from mysite.iclock.models.model_device import Device
    from mysite.iclock.models.model_devcmd import DevCmd
    from mysite.iclock.models.model_trans import Transaction

    startTime = datetime.date.today() - datetime.timedelta(days=3)
    EndTime = datetime.date.today()
    devices = Device.objects.all()
    for dev in devices:
        trans = Transaction.objects.filter(sn_name=dev.sn,
                                           TTime__range=(startTime, EndTime))
        cmdStr = "ACCOUNT Start=%s       End=%s       Count=%s" % (
            str(startTime), str(EndTime), str(len(trans)))
        try:
            cmd = DevCmd(SN=dev,
                         CmdContent=cmdStr,
                         CmdCommitTime=datetime.datetime.now())
            cmd.save(force_insert=True)
        except:
            import traceback
            traceback.print_exc()
Exemple #5
0
def parse_cmmdata(cmmdata):
    '''
	将操作命令转化为设备命令,主要用于会产生大批量设备命令的操作
	'''
    from model_device import Device
    from mysite.personnel.models import Employee
    from mysite.personnel.models import Area
    from mysite.iclock.device_http.device_view import write_data
    from mysite.iclock.models.model_devcmd import DevCmd
    #from dev_comm_operate import sync_delete_all_data, sync_set_all_data,sync_delete_user,sync_set_user
    from mysite.iclock.constant import REALTIME_EVENT, DEVICE_POST_DATA

    if cmmdata.cmm_type == 1:
        cmm = cmmdata.receive_data.split("\t;", 1)
        if cmm[0] == "cmmsubtype=1":
            tmp = cmm[1].split("\t;", 1)
            snid = tmp[0].split("=")[1]

            fn = tmp[1].split("=")[1]
            wf = file(fn, "r+")
            writedata = wf.read()
            wf.close()

            dev = Device.objects.get(pk=snid)
            if writedata:
                write_data(writedata, dev, cmmdata)

    elif cmmdata.cmm_type == 2:

        cmm = cmmdata.receive_data.split("\t;", 1)
        if cmm[0] == "cmmsubtype=2":
            alldata = cmmdata.receive_data.split("\n\r")
            for cmm in alldata:
                cmm = cmm.split("\t;", 1)
                tmp = cmm[1].split("\t;", 1)
                snid = tmp[0].split("=")[1]
                dev = Device.objects.get(pk=snid)
                if dev:
                    cmd = DevCmd(SN=dev,
                                 CmdOperate=cmmdata,
                                 CmdContent="CLEAR DATA",
                                 CmdCommitTime=datetime.datetime.now())
                    cmd.save(force_insert=True)

                    dev.set_all_data(cmmdata)
        if cmm[0] == "cmmsubtype=4":  #同步所有数据到设备
            alldata = cmmdata.receive_data.split("\n\r")
            for cmm in alldata:
                cmm = cmm.split("\t;", 1)
                tmp = cmm[1].split("\t;", 1)
                snid = tmp[0].split("=")[1]
                dev = Device.objects.get(pk=snid)
                if dev:
                    dev.set_all_data(cmmdata)

        if cmm[0] == "cmmsubtype=3":
            alldata = cmmdata.receive_data.split("\n\r")

            for cmm in alldata:
                cmm = cmm.split("\t;", 1)
                tmp = cmm[1].split("\t;")
                #print "Tmp:%s"%tmp
                user = tmp[0].split("=")[1].split(",")
                s_dev = tmp[1].split("=")[1].split(",")
                d_dev = tmp[2].split("=")[1].split(",")

                user = Employee.objects.filter(pk__in=user)
                if s_dev[0]:
                    devset = Device.objects.filter(pk__in=s_dev)
                    #sync_delete_user(dev,user)
                    for dev in devset:
                        dev.delete_user(user, cmmdata)

                if d_dev[0]:
                    devset = Device.objects.filter(pk__in=d_dev)

                    #sync_set_user(dev,user)
                    for dev in devset:
                        dev.set_user(user, cmmdata, "")
                        dev.set_user_fingerprint(user, cmmdata)
                        dev.set_user_face(user, cmmdata)  #----下发人脸模板

    else:
        pass
    pass
def parse_cmmdata(cmmdata):
    '''
	解析操作命令为下发给设备的命令
	'''
    from model_device import Device
    from mysite.personnel.models import Employee
    from mysite.personnel.models import Area
    from mysite.iclock.devview import write_data
    from mysite.iclock.models.model_devcmd import DevCmd
    from mysite.iclock.constant import REALTIME_EVENT, DEVICE_POST_DATA
    from redis.server import check_and_start_queqe_server, queqe_server

    if cmmdata.cmm_type == 1:
        cmm = cmmdata.receive_data.split("\t;", 1)
        if cmm[0] == "cmmsubtype=1":
            tmp = cmm[1].split("\t;", 1)
            snid = tmp[0].split("=")[1]

            fn = tmp[1].split("=")[1]
            wf = file(fn, "r+")
            writedata = wf.read()
            wf.close()

            dev = Device.objects.get(pk=snid)
            if writedata:
                write_data(writedata, dev, cmmdata)

    elif cmmdata.cmm_type == 2:

        cmm = cmmdata.receive_data.split("\t;", 1)
        if cmm[0] == "cmmsubtype=2":
            alldata = cmmdata.receive_data.split("\n\r")
            for cmm in alldata:
                cmm = cmm.split("\t;", 1)
                tmp = cmm[1].split("\t;", 1)
                snid = tmp[0].split("=")[1]
                dev = Device.objects.get(pk=snid)
                if dev:
                    cmd = DevCmd(SN=dev,
                                 CmdOperate=cmmdata,
                                 CmdContent="CLEAR DATA",
                                 CmdCommitTime=datetime.datetime.now())
                    cmd.save(force_insert=True)

                    dev.set_all_data(cmmdata)

        if cmm[0] == "cmmsubtype=3":  #----所谓的调整用户到某区域
            alldata = cmmdata.receive_data.split("\n\r")
            for cmm in alldata:
                cmm = cmm.split("\t;", 1)
                tmp = cmm[1].split("\t;")
                user = tmp[0].split("=")[1].split(",")
                s_dev = tmp[1].split("=")[1].split(",")
                d_dev = tmp[2].split("=")[1].split(",")
                user = Employee.objects.filter(pk__in=user)
                if s_dev[0]:
                    devset = Device.objects.filter(pk__in=s_dev)
                    for dev in devset:
                        dev.delete_user(user, cmmdata)
                if d_dev[0]:
                    devset = Device.objects.filter(pk__in=d_dev)
                    for dev in devset:
                        dev.set_user(user, cmmdata, "")
                        dev.set_user_fingerprint(user, cmmdata)
    else:
        pass
    pass
Exemple #7
0
def parse_cmmdata(cmmdata):
	'''
	解析操作命令为下发给设备的命令
	'''
	from model_device import Device
	from mysite.personnel.models import Employee
	from mysite.personnel.models import Area
	from mysite.iclock.devview import write_data
	from mysite.iclock.models.model_devcmd import DevCmd
	from mysite.iclock.constant import REALTIME_EVENT, DEVICE_POST_DATA
	from redis.server import check_and_start_queqe_server, queqe_server
	
	if cmmdata.cmm_type==1:
		cmm=cmmdata.receive_data.split("\t;",1)
		if cmm[0]=="cmmsubtype=1":
			tmp=cmm[1].split("\t;",1)
			snid=tmp[0].split("=")[1]
			
			fn=tmp[1].split("=")[1]
			wf=file(fn,"r+")
			writedata=wf.read()
			wf.close()
			
			dev=Device.objects.get(pk=snid)
			if writedata:
				write_data(writedata,dev,cmmdata)
			
	elif cmmdata.cmm_type==2:

		cmm=cmmdata.receive_data.split("\t;",1)
		if cmm[0]=="cmmsubtype=2":
			alldata=cmmdata.receive_data.split("\n\r")
			for cmm in alldata:			
				cmm=cmm.split("\t;",1)	
				tmp=cmm[1].split("\t;",1)
				snid=tmp[0].split("=")[1]
				dev=Device.objects.get(pk=snid)
				if dev:
					cmd=DevCmd(SN=dev, CmdOperate=cmmdata, CmdContent="CLEAR DATA", CmdCommitTime=datetime.datetime.now())
					cmd.save(force_insert=True)
					
					dev.set_all_data(cmmdata)
					
		if cmm[0]=="cmmsubtype=3":	   #----所谓的调整用户到某区域
			alldata=cmmdata.receive_data.split("\n\r")
			for cmm in alldata:
				cmm=cmm.split("\t;",1)	
				tmp=cmm[1].split("\t;")
				user=tmp[0].split("=")[1].split(",")
				s_dev=tmp[1].split("=")[1].split(",")
				d_dev=tmp[2].split("=")[1].split(",")
				user=Employee.objects.filter(pk__in=user)
				if s_dev[0]:					
					devset=Device.objects.filter(pk__in=s_dev)			
					for dev in devset:
					    dev.delete_user(user, cmmdata)					    
				if d_dev[0]:
					devset=Device.objects.filter(pk__in=d_dev)		
					for dev in devset:
						dev.set_user(user,  cmmdata, "")
						dev.set_user_fingerprint(user, cmmdata)
	else:
		pass
	pass