Beispiel #1
0
def get_apply_records(proj_id, page, filters):
    filter_condition = {'proj_id': proj_id, 'is_del': 0}
    expressions = []
    search_key = filters['searchKey'] if 'searchKey' in filters else None
    if search_key:
        crew_expression = [
            or_(CrewMgr.model.crew_name == search_key,
                CrewMgr.model.phone == search_key,
                CrewMgr.model.id_card_num == search_key,
                CrewMgr.model.crew_account == search_key)
        ]
        search_crews = CrewMgr.query({'is_del': 0},
                                     expressions=crew_expression)
        search_crew_ids = [item.id for item in search_crews]
        expressions.append(CrewProjMapMgr.model.crew_id.in_(search_crew_ids))
    if 'crew_id' in filters and filters['crew_id']:
        expressions.append(CrewProjMapMgr.model.crew_id == filters['crew_id'])
    if 'entry_status' in filters:
        expressions.append(
            CrewProjMapMgr.model.entry_status == filters['entry_status'])
    count = CrewProjMapMgr.count(expressions=expressions,
                                 filter_conditions=filter_condition)
    if page != 0:
        records = CrewProjMapMgr.query(
            expressions=expressions,
            filter_conditions=filter_condition,
            limit=10,
            offset=(page - 1) * 10,
            order_list=[CrewProjMapMgr.model.create_time.desc()])
    else:
        if count > 5000:  # 数据量过大保护
            records = CrewProjMapMgr.query(
                expressions=expressions,
                filter_conditions=filter_condition,
                limit=5000,
                order_list=[CrewProjMapMgr.model.create_time.desc()])
        else:
            records = CrewProjMapMgr.query(expressions=expressions,
                                           filter_conditions=filter_condition)
    data = {'proj_id': proj_id, 'count': count, 'records': records}
    for record in data['records']:
        crew = CrewMgr.get(record.crew_id)
        if not crew:
            continue
        crew = to_dict(crew)
        crew['create_time'] = time_util.timestamp2dateString(
            crew['create_time'])
        crew['start_time'] = time_util.timestamp2dateString(
            record.start_time) if record.start_time else '待定'
        crew['entry_status'] = CrewProjMapMgr.translate_entry_status(
            record.entry_status)
        crew['age'] = GetInformation(crew['id_card_num']).get_age()
        crew['gender'] = GetInformation(crew['id_card_num']).get_gender_text()
        crew['apply_id'] = record.id
        data['result'].append(crew)
    data['result'] = json.dumps(data['result'])
    return data['result']
Beispiel #2
0
 def list_crew_by_create_time_desc(proj_id, search_key, page, page_size=10):
     """获取员工列表并分页, 根据发生时间倒序排列"""
     filter_condition = {'is_del': 0}
     if proj_id:
         filter_condition['proj_id'] = proj_id
     expressions = []
     if search_key:
         expressions = [or_(CrewMgr.model.crew_name == search_key, CrewMgr.model.phone == search_key,
                            CrewMgr.model.id_card_num == search_key, CrewMgr.model.crew_account == search_key)]
     count = CrewMgr.count(expressions=expressions, filter_conditions=filter_condition)
     if page_size > 5000:  # 数据量过大保护
         page_size = 5000
     records = CrewMgr.query(expressions=expressions, filter_conditions=filter_condition, limit=page_size,
                             offset=page_size*(page-1), order_list=[CrewMgr.model.create_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
Beispiel #3
0
def create_wage_raw_data(proj_id, lines):
    line_index = 0
    data = {'errors': []}
    for line in lines:
        line_index += 1
        crew_id = CrewMgr.get_crew_id_by_account(line['crew_account'])
        if not crew_id:
            data['errors'].append(BatchUploadError(line_index, '该员工没有录入系统').to_dict())
            continue
        wage_time = time_util.dateString2timestampCommon(line['wage_time'])
        record = {
            'proj_id': proj_id,
            'crew_id': crew_id,
            'bill_id': '%d%d%d' % (proj_id, wage_time, crew_id),
            'wage_time': wage_time
        }
        records = []
        for key, value in line.items():
            if key.endswith('量') and float(value) > 0:
                record['position'] = key.replace('量', '')
                record['work_amount'] = value
                records.append(record.copy())
        for record in records:
            record['work_hours'] = float(line['work_hours']) / len(records)
            WageRawDataMgr.create_override_if_exist(record)
    return data
Beispiel #4
0
def create_wage_raw_data(proj_id, lines):
    line_index = 0
    data = {'errors': []}
    for line in lines:
        line_index += 1
        record = {'proj_id': data['proj_id'], 'meta': {}}
        for key, value in line.items():
            line[key] = value.strip()
            if key in WageMgr.params:
                record[key] = value
            else:
                record['meta'][key] = value
        if 'wage_time' in record:
            record['wage_time'] = time_util.dateString2timestampCommon(record['wage_time'])
        crew_id = CrewMgr.get_crew_id_by_account(line['crew_account'])
        if not crew_id:
            data['errors'].append(BatchUploadError(line_index, '该员工没有录入系统').to_dict())
            continue
        else:
            record['crew_id'] = crew_id

    for record in data['wage_raw_datas']:
        record['meta'] = json.dumps(record['meta'])
        WageRawDataMgr.create_override_if_exist(record)
    for record in data['wage']:
        record['meta'] = json.dumps(record['meta'])
        WageMgr.create_override_if_exist(record)
Beispiel #5
0
def create_fine_record(proj_id, lines):
    errors = []
    line_index = 0
    for line in lines:
        line_index += 1
        record = {'proj_id': proj_id, 'meta': {}}
        for key, value in line.items():
            line[key] = value.strip()
            if key in FineMgr.params:
                record[key] = value
            else:
                record['meta'][key] = value
        if 'occur_time' in record:
            record['occur_time'] = time_util.dateString2timestampCommon(
                line['occur_time'])
        if 'bill_id' not in line:
            errors.append(BatchUploadError(line_index, '缺少异常单号').to_dict())
            continue
        crew_id = CrewMgr.get_crew_id_by_account(line['crew_account'])
        if not crew_id:
            errors.append(BatchUploadError(line_index, '该员工没有录入系统').to_dict())
            continue
        else:
            record['crew_id'] = crew_id
        record['meta'] = json.dumps(record['meta'])
        FineMgr.create_override_if_exist(record)
    return {'errors': errors, 'lines': lines}
Beispiel #6
0
 def add_crew_base_info(data):
     """
     获取crew_name和crew_account
     """
     base_info = CrewMgr.get_crew_base_info_by_id(data['crew_id'])
     for key, value in base_info.items():
         data[key] = value
Beispiel #7
0
def create_crew_record(org_id, proj_id, lines):
    line_index = 0
    errors = []
    supplier_map = SupplierMgr.get_supplier_name_id_map(org_id)
    for line in lines:
        line_index += 1
        record = {'org_id': org_id, 'proj_id': proj_id, 'meta': {}}
        for key, value in line.items():
            line[key] = value.strip()
            if key in CrewMgr.params:
                record[key] = value
            else:
                record['meta'][key] = value
        if line['supplier_name'] in supplier_map:
            record['supplier_id'] = supplier_map[line['supplier_name']]
        else:
            errors.append(BatchUploadError(line_index, '供应商不存在').to_dict())
            continue
        record['id_card_num'] = record['id_card_num'].lower()
        record['meta'] = json.dumps(record['meta'])
        crew = CrewMgr.create_override_if_exist(record)
        level = CrewLevelMgr.query_first({'crew_id': crew.id, 'is_del': 0})
        if not level:
            CrewLevelMgr.create(crew_id=crew.id,
                                crew_name=record['crew_name'],
                                level_name='青铜')
    return {'errors': errors, 'lines': lines}
Beispiel #8
0
 def add_crew_num(data):
     """
     获取项目员工数量
     """
     if 'id' in data:
         crew_num = CrewMgr.count({'proj_id': data['id'], 'is_del': 0})
         data['crew_num'] = crew_num
Beispiel #9
0
 def add_total_crew_num(org_id, data):
     """
     获取项目员工数量
     """
     if 'id' in data:
         crew_num = CrewMgr.count({
             'org_id': org_id,
             'supplier_id': data['id'],
             'is_del': 0
         })
         data['total_crew_num'] = crew_num
Beispiel #10
0
 def add_current_crew_num(org_id, data):
     """
     获取项目员工数量
     """
     if 'id' in data:
         crew_num = CrewMgr.count({
             'org_id': org_id,
             'supplier_id': data['id'],
             'work_status': 1,
             'is_del': 0
         })
         data['current_crew_num'] = crew_num
Beispiel #11
0
def create_crew_record(proj_id, lines):
    line_index = 0
    for line in lines:
        line_index += 1
        record = {'proj_id': proj_id, 'meta': {}}
        for key, value in line.items():
            line[key] = value.strip()
            if key in CrewMgr.params:
                record[key] = value
            else:
                record['meta'][key] = value
        record['id_card_num'] = record['id_card_num'].lower()
        record['meta'] = json.dumps(record['meta'])
        crew = CrewMgr.create_override_if_exist(record)
        level = CrewLevelMgr.query_first({'crew_id': crew.id, 'is_del': 0})
        if not level:
            CrewLevelMgr.create(crew_id=crew.id,
                                crew_name=record['crew_name'],
                                level_name='青铜')
    return {'errors': [], 'lines': lines}
Beispiel #12
0
def proj_crew_income_billboard(org_id, proj_id):
    last_record = WageMgr.query_first({
        'proj_id': proj_id,
        'is_del': 0
    },
                                      order_list=[WageMgr.model.amount.desc()])
    records = WageMgr.query(
        {
            'proj_id': proj_id,
            'wage_time': last_record.wage_time,
            'is_del': 0
        },
        limit=10,
        order_list=[WageMgr.model.amount.desc()])
    billboard = []
    for record in records:
        crew = CrewMgr.get(record.crew_id)
        billboard.append({
            '员工': crew.crew_name + crew.crew_account,
            '收入': float(record.amount)
        })
    return json.dumps(billboard), last_record.wage_time
Beispiel #13
0
def org_total_crew_num(org_id, proj_id):
    total_crew_num = CrewMgr.count({'org_id': org_id, 'is_del': 0})
    return total_crew_num, time.time()
Beispiel #14
0
def delete_crew_record(crew_id):
    record = CrewMgr.get(crew_id)
    if record:
        CrewMgr.delete(record)
Beispiel #15
0
def update_crew_records(crew_id, content):
    crew = CrewMgr.get(crew_id)
    if crew:
        CrewMgr.update(crew, **content)
Beispiel #16
0
 def get_crew_by_id(crew_id):
     """通过员工id获取单个项目"""
     return to_dict(CrewMgr.get(crew_id))
Beispiel #17
0
 def add_source_str(data):
     """
     员工来源渠道: 0-网招报名, 1-供应商, 2-员工推荐
     """
     if 'source' in data:
         data['source_str'] = CrewMgr.translate_source(data['source'])
Beispiel #18
0
 def add_work_status_str(data):
     """
     员工工作状态: 0-空闲, 1-工作中
     """
     if 'work_status' in data:
         data['work_status_str'] = CrewMgr.translate_work_status(data['work_status'])