Beispiel #1
0
def save_EmployeePic(key, data):
    u'''
    处理设备上传过来的照片
    '''
    pin = format_pin(key)
    empid = check_employee(pin)
    old_photo = get_photourl_by_uid(empid)
    update_sql = """
        update userinfo set photo= '%s' where userid = %s
    """
    content = data
    try:
        savepath = "photo/" + datetime.datetime.now().strftime(
            "%Y%m%d%H%M%S%f") + ".jpg"
        photopath = settings.ADDITION_FILE_ROOT + savepath
        f = file(photopath, "w+b")
        f.write(content)
        f.close()
        p_execute(update_sql % (savepath, empid))
        # 删除旧的照片
        if old_photo:
            oldpath = settings.ADDITION_FILE_ROOT + old_photo
            os.remove(oldpath)
    except:
        import traceback
        traceback.print_exc()
        pass
Beispiel #2
0
def save_face(key, field, data):
    u'''
        保存面部到数据库
    '''
    from mysite.iclock.models import FaceTemplate

    pin, ver = key.split('|')
    pin = format_pin(pin)
    faceid = field
    template = data
    dict_val = {
        "pin": pin,
        "faceid": field,
        "face_ver": ver,
        "template": template
    }
    sql_update = """
         update 
                face_template 
             set facetemp = '%(template)s'
        where 
             pin = '%(pin)s' and faceid='%(faceid)s' and face_ver = '%(face_ver)s' 
    """ % dict_val

    sql_insert = """
        insert into 
            face_template (pin,facetemp,faceid,face_ver) 
            values('%(pin)s','%(template)s','%(faceid)s','%(face_ver)s')
    """ % dict_val
    res = p_execute(sql_update)
    if res == 0:
        res = p_execute(sql_insert)
    return res
Beispiel #3
0
def save_finnger(key, field, data, force):
    '''
        保存指纹到数据库
    '''
    from mysite.iclock.models.model_bio import Template
    pin, ver = key.split('|')
    pin = format_pin(pin)
    fingger = field
    template = data
    Valid = force and "3" or "1"
    dict_val = {
        "pin": pin,
        "FingerID": fingger,
        "Fpversion": ver,
        "template": template,
        "Valid": Valid
    }
    sql_update = """
         update 
                finger_template 
             set Template = '%(template)s',
                 Valid = %(Valid)s
        where 
             pin = '%(pin)s' and FingerID='%(FingerID)s' and Fpversion = '%(Fpversion)s' 
    """ % dict_val

    sql_insert = """
        insert into 
            finger_template (pin,Template,FingerID,Fpversion,Valid) 
            values('%(pin)s','%(template)s','%(FingerID)s','%(Fpversion)s',%(Valid)s)
    """ % dict_val
    res = p_execute(sql_update)
    if res == 0:
        res = p_execute(sql_insert)
    return res
Beispiel #4
0
def sync_to_att(cursor, devobj, pin, time):
    from mysite.sql_utils import p_execute
    import sqls
    if int(pin):
        sql = sqls.sync_to_att_insert(devobj.sn, strtodatetime(time),
                                      format_pin(pin))
        res = p_execute(sql)
        if res is None:
            pass
Beispiel #5
0
def delete_face(pin):
    u"""
      根据人员 PIN 删除该人员面部信息
    """
    pin = format_pin(pin)
    sql = """
        delete from face_template
        where face_template.pin = '%s'
    """ % pin
    return p_execute(sql)
Beispiel #6
0
def delete_finnger(pin):
    u"""
      根据人员 PIN 删除该人员指纹信息
    """
    pin = format_pin(pin)
    sql = """
        delete from finger_template
        where finger_template.pin = '%s'
    """ % pin
    return p_execute(sql)
Beispiel #7
0
def save_attrecord(att_dict_list, event=True):
    '''
    保存考勤原始记录到数据库 , 格式
    [
        {
        "pin": format_pin(pin),
        "checktime":logtime, 
        "checktype":normal_state(flds[2]), 
        "verifycode":normal_verify(flds[3]), 
        "WorkCode":flds[4], 
        "Reserved":flds[5],
        "sn_name":device.sn
        },
    ]
    realtime:
        True:  设备实时上传过来的数据
        False: 文件解析过来的数据 
    '''
    if att_dict_list:
        insert_sql = """
            if not exists(select id from checkinout where pin = '%(pin)s' and checktime= '%(checktime)s') 
            insert into checkinout (pin, checktime, checktype, verifycode, WorkCode, Reserved,sn_name) 
                            values('%(pin)s', '%(checktime)s', '%(checktype)s','%(verifycode)s', '%(WorkCode)s', '%(Reserved)s', '%(sn_name)s'); 
        """
        batch_sql = []
        for ad in att_dict_list:
            batch_sql.append(insert_sql % ad)
        success, res = p_mutiexec(batch_sql)
        if not success:
            # 出现异常,一条一条插入:
            if res and res[0] == -2:
                att_deal_logger(
                    "Insert attrecord failed ,Database has been disconnected!")
                if event <> "files":
                    #                        # 数据库连接失败,导致数据没有插入,由设备直接传过来的数据,写成文件,返回 True
                    #                        data_list = []
                    #                        for d in att_dict_list:
                    #                            data_list.append(u"%s\t%s\t%s\t%s"%(d["pin"],d["checktime"],d["checktype"],d["verifycode"]))
                    #                        save_att_file(att_dict_list[0]["sn_name"],("\r\n").join(data_list))
                    time.sleep(
                        2 *
                        60)  # 机器post 数据,如果服务器一段时间没有返回,则机器会默认为服务器没有收到,会再次post.

                return False

            else:
                for bs in batch_sql:
                    num = p_execute(bs)
                    if num is None:
                        att_deal_logger("Error sql -->%s" % bs)
                        if event <> "files":
                            # 设备上传数据,数据异常导致保存失败
                            time.sleep(2 * 60)
                        return True
        return True
Beispiel #8
0
def save_area(eid, epin):
    '''
    将人员的redis区域信息保存到数据库
    '''
    from mysite.iclock.models import Area
    from sync_action import get_area
    from protocol_content import device_pin
    pin = device_pin(epin)
    m_list = get_area(pin)
    delete_sql = """
      delete  userinfo_attarea where employee_id = %s
    """
    insert_sql = """
        if not exists(select id from userinfo_attarea where employee_id = %(employee_id)s and area_id= %(area_id)s) 
        insert into userinfo_attarea (employee_id,area_id) values(%(employee_id)s,%(area_id)s)
    """
    sqlList = []
    p_execute(delete_sql % eid)
    for a in m_list:
        p_execute(insert_sql % {'employee_id': eid, 'area_id': a})
Beispiel #9
0
def save_area(eid, epin):
    '''
    将人员的redis区域信息保存到数据库
    '''
    from mysite.iclock.models import Area
    from base.sync_api import get_area
    from mysite.personnel.models.model_emp import device_pin
    from mysite.sql_utils import p_query, p_execute
    pin = device_pin(epin)
    m_list = get_area(pin)
    delete_sql = """
      delete  userinfo_attarea where employee_id = %s
    """
    insert_sql = """
        if not exists(select id from userinfo_attarea where employee_id = %(employee_id)s and area_id= %(area_id)s) 
        insert into userinfo_attarea (employee_id,area_id) values(%(employee_id)s,%(area_id)s)
    """
    sqlList = []
    p_execute(delete_sql % eid)
    for a in m_list:
        p_execute(insert_sql % {'employee_id': eid, 'area_id': a})
Beispiel #10
0
def batch_insert(sql_list):
    if sql_list:
        flag, res = p_mutiexec(sql_list)
        if not flag:
            for elem in sql_list:
                p_execute(elem)