예제 #1
0
def get_employee(pin, Device=None):
    '''
    根据给定员工PIN查找员工,若不存在就创建改PIN的员工
    '''
    s_pin = format_pin(pin)
    try:
        e=Employee.objects.get(PIN=s_pin)
        if e:
            e.IsNewEmp=False
            return e
        else:
            raise ObjectDoesNotExist
    except ObjectDoesNotExist:
        e = Employee(PIN=s_pin, EName=pin)
        e.save()
        e.IsNewEmp=True
        return e
예제 #2
0
def get_employee(pin, Device=None):
    '''
    根据给定员工PIN查找员工,若不存在就创建改PIN的员工
    '''
    s_pin = format_pin(pin)
    try:
        e = Employee.objects.get(PIN=s_pin)
        if e:
            e.IsNewEmp = False
            return e
        else:
            raise ObjectDoesNotExist
    except ObjectDoesNotExist:
        e = Employee(PIN=s_pin, EName=pin)
        e.save()
        e.IsNewEmp = True
        return e
예제 #3
0
def get_employee(pin, Device=None):
    '''
    根据给定员工PIN查找员工,若不存在就创建改PIN的员工
    '''
    s_pin = format_pin(pin)
    try:
        e=Employee.all_objects.get(PIN=s_pin)
        if e:
            e.IsNewEmp=False
            return e
        else:
            raise ObjectDoesNotExist
    except ObjectDoesNotExist:
        if not settings.DEVICE_CREATEUSER_FLAG:
            return None
        e = Employee(PIN=s_pin, EName=pin)
        e.save()
        e.IsNewEmp=True
        return e
예제 #4
0
    def process_row(self, row_data, calculate_dict):
        u'''
            特殊情况给开发人员提供的接口
            row_data 这一行的数据
            calculate_dict 文档附加的列,如部门编号,
            员工表是没有部门编号的,部门编号是用来初始化员工字段DeptID的
        '''
        from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID
        from mysite.personnel.models import Employee
        key = u"%s" % _(u"人员编号")
        emp_pin = u"%s" % calculate_dict[key]

        emp_pk = calculate_dict["user_pk"]
        if 'postgresql_psycopg2' in connection.__module__:
            userid_key = '"' + "UserID_id" + '"'
            cardstatus_key = '"' + "cardstatus" + '"'
        else:
            userid_key = "UserID_id"
            cardstatus_key = "cardstatus"
        if emp_pk:
            row_data[userid_key] = u'%s' % emp_pk  #初始化人员外键
        else:
            obj_emp = Employee()
            obj_emp.PIN = emp_pin
            obj_emp.DeptID_id = 1
            obj_emp.save()
            row_data[userid_key] = u'%s' % obj_emp.pk  #初始化部门
        row_data[cardstatus_key] = u'%s' % CARD_VALID

        return row_data
예제 #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 action(self,upload_attlog):
         from django.db import connection
         import datetime
         from mysite.personnel.models.model_emp import format_pin, Employee
         
         cursor = connection.cursor()
         if self.request.FILES:
             f=self.request.FILES['upload_attlog']
             f_format=str(f).split('.')
             format_list=['dat']
             ret = []
             try:
                format_list.index(str(f_format[1]))
             except:
                raise Exception (_(u"考勤文件格式无效!"))
         
             try:
                 file_data = f.read()
                 file_data = file_data.strip()
                 log_list = file_data.split("\r\n")
                 sql = []
                 MYSQL_INSERT = u'''INSERT INTO checkinout(userid,checktime,checktype,verifycode,workcode)
                     VALUES %(batch_rows)s
                     '''
 
                 SQLSERVER_INSERT = u'''INSERT INTO checkinout(userid,checktime,checktype,verifycode,workcode)
                     VALUES('%(uid)s','%(time)s','%(type)s','%(vf)s','%(wc)s')
                     '''
                 for row in log_list:
                     try:
                         elems = row.split("\t")
                         if len(elems) != 6:
                             ret.append(u"%(r)s:%(info)s"%{"r":row,"info":_(u"数据格式不正确")})
                             continue
                         pin = elems[0].strip() #用户PIN号
                         ttime = elems[1].strip() #考勤时间
                         sdevice_id = elems[2].strip() #设备号
                         state  = elems[3].strip() #考勤状态
                         verify = elems[4].strip() # 验证方式
                         workcode = elems[5].strip() # 工作代码
                         
                         try:
                             ttime = datetime.datetime.strptime(ttime,"%Y-%m-%d %H:%M:%S")
                         except:
                             ret.append(u"%(r)s:%(info)s"%{"r":row,"info":_(u"时间格式不正确")})
                             continue
                         obj_emp = None
                         try:
                             obj_emp = Employee.objects.get(PIN = format_pin(pin))
                         except:
                             #创建用户
                             obj_emp  = Employee()
                             obj_emp.PIN = pin
                             obj_emp.DeptID_id = 1
                             obj_emp.save()
                             obj_emp.attarea = [1,]
                         
                         if db_select == IS_SQLSERVER_DB:
                             sql.append(
                                 SQLSERVER_INSERT%{
                                     "uid":obj_emp.pk,
                                     "time":ttime,
                                     "type":normal_state(state),
                                     "vf":normal_verify(verify),
                                     "wc":workcode
                                 }
                             )
                         elif db_select == IS_MYSQL_DB:
                             sql.append(
                                 u'''('%(uid)s','%(time)s','%(type)s','%(vf)s','%(wc)s')'''%{
                                     "uid":obj_emp.pk,
                                     "time":ttime,
                                     "type":normal_state(state),
                                     "vf":normal_verify(verify),
                                     "wc":workcode
                                 }
                             )
                         if len(sql)>200:
                             if db_select == IS_SQLSERVER_DB:
                                 cursor.execute(";".join(sql))
                             elif db_select == IS_MYSQL_DB:
                                 cursor.execute(
                                     MYSQL_INSERT%({"batch_rows":",".join(sql)})
                                 )
                             sql = []
                     except IntegrityError:
                             if sql:        
                                 for elem in sql:
                                     try:
                                         if db_select == IS_SQLSERVER_DB:
                                             cursor.execute(elem)
                                         elif db_select == IS_MYSQL_DB:
                                             cursor.execute(
                                                 MYSQL_INSERT%({"batch_rows":elem})
                                             )
                                     except:
                                         pass
                                 sql = []
                     except Exception,e:
                         ret.append(u"%s"%e)
                 if sql:        
                     if db_select == IS_SQLSERVER_DB:
                         cursor.execute(";".join(sql))
                     elif db_select == IS_MYSQL_DB:
                         cursor.execute(
                             MYSQL_INSERT%({"batch_rows":",".join(sql)})
                         )
             except IntegrityError:
                 if sql:        
                     for elem in sql:
                         try:
                             if db_select == IS_SQLSERVER_DB:
                                 cursor.execute(elem)
                             elif db_select == IS_MYSQL_DB:
                                 cursor.execute(
                                     MYSQL_INSERT%({"batch_rows":elem})
                                 )
                         except:
                             pass
예제 #7
0
 def employee(self): #cached employee
         try:
                 return Employee.objByID(self.UserID_id)
         except:
                 return None
예제 #8
0
 def employee(self): #cached employee
         try:
                 return Employee.objByID(self.UserID_id)
         except:
                 return None