def get_current_on_work_info(pipeline_code=None):
    response = {}

    person_col = get_target_mongo_collection('person')
    all_person_cur = person_col.find({}, {'_id': 0, 'code': 1})
    all_person_code = [x['code'] for x in all_person_cur]
    col = get_target_mongo_collection('checkin_info')
    # 获取当前签到情况,此处时间起始点后期可能会调整
    now = datetime.now()
    begin_of_today = datetime(now.year, now.month, now.day)
    query_str = {'record_time': {'$gt': begin_of_today}}
    if pipeline_code:
        query_str.update({
            'pipeline_code': pipeline_code
        })
    today_on_work_cur = col.find(query_str, {'_id': 0, 'code': 1, 'on_work': 1})
    on_work_mapper = {}
    for c in today_on_work_cur:
        on_work_mapper.update({
            c['code']: c['on_work']
        })

    for p in all_person_code:
        response.update({
            p: on_work_mapper.setdefault(p, False)
        })

    return response
def get_process_threshold_info():
    # 获取所有工序阈值
    person_col = get_target_mongo_collection('process')

    all_process_info = person_col.find({}, {'_id': 0, 'threshold_person_number': 1, 'code': 1})
    response = {}
    for x in all_process_info:
        response.update({
            x['code']: x.setdefault('threshold_person_number', 0)
        })
    return response
Exemple #3
0
async def init_process_info(msg):
    # 初始化工序信息
    get_logger().info('工序信息同步')
    get_logger().info(msg)

    # 更新库中数据
    col = get_target_mongo_collection('process')
    process_info = msg.setdefault('instance_list', [])
    all_process_info_code = []
    for p in process_info:
        all_process_info_code.append(p['code'])
        col.update({'code': p['code']}, {'$set': p}, upsert=True)
def get_attendance_info_group_by_month(month_begin, month_end):
    checkin_info = get_target_mongo_collection('checkin_info')

    checkin_records_by_month = checkin_info.find({'record_time': {'$gte': month_begin, '$lt': month_end}},
                                                 {'_id': 0, 'code': 1, 'check_point': 1, 'pipeline_code': 1})
    checkin_records = {}
    for record in checkin_records_by_month:
        work_hours = calc_work_hours(record['check_point'])
        if record['code'] in checkin_records.keys():
            checkin_records.get(record['code']).append(work_hours)
        else:
            checkin_records[record['code']] = list()
            checkin_records[record['code']].append(work_hours)

    return checkin_records
Exemple #5
0
async def init_product_line_info(msg):
    # 初始化所有产线信息
    get_logger().info('产线信息同步')
    get_logger().info(msg)

    # 更新库中数据
    col = get_target_mongo_collection('product_line')
    product_line_info = msg.setdefault('instance_list', [])
    all_product_line_code = []
    for p in product_line_info:
        all_product_line_code.append(p['code'])
        col.update({'code': p['code']}, {'$set': p}, upsert=True)

    # 移除多余产线信息
    col.remove({'code': {'$nin': all_product_line_code}})
Exemple #6
0
    def process_checkin_info(self, checkin_info):
        col = get_target_mongo_collection('checkin_info')

        now = datetime.now()
        begin_of_today = datetime(now.year, now.month, now.day)

        for i in checkin_info:
            person_code = i['code']
            on_work = i['on_work']
            now = datetime.now()
            if on_work:
                col.update({'code': person_code, 'record_time': {'$gt': begin_of_today}},
                           {'$set': {'code': person_code, 'on_work': True, 'record_time': now,
                                     'pipeline_code': self.pipeline_code},
                            '$push': {'check_point': now}}, upsert=True)
            else:
                col.update({'code': person_code, 'record_time': {'$gt': begin_of_today}},
                           {'$set': {'on_work': False, 'record_time': now},
                            '$push': {'check_point': now}})
Exemple #7
0
async def init_person_info(msg):
    # 初始化所有人员信息
    get_logger().info('人员信息同步')
    get_logger().info(msg)

    code_2_name = []
    people = msg['instance_list']
    for each in people:
        person = {}
        person.update({'code': each['code'], 'name': each['name']})
        code_2_name.append(person)
    update_context('person_info', code_2_name)
    # 更新库中数据
    col = get_target_mongo_collection('person')
    person_info = msg.setdefault('instance_list', [])
    all_person_code = []
    for p in person_info:
        all_person_code.append(p['code'])
        col.update({'code': p['code']}, {'$set': p}, upsert=True)
Exemple #8
0
async def init_process_number(msg):
    # 初始化工序人数信息
    get_logger().info('工序点亮信息同步')
    get_logger().info(msg)

    person_col = get_target_mongo_collection('process')

    if msg:
        msg = msg[0]['children'][0]
        for threshold_info in msg.setdefault('instance_list', []):
            threshold_value = int(threshold_info['name'])
            process_list = threshold_info['children'][0].setdefault(
                'instance_list', [])
            process_codes = [x['code'] for x in process_list]
            # 更新库中数据
            person_col.update_many({'code': {
                '$in': process_codes
            }}, {'$set': {
                'threshold_person_number': threshold_value
            }})
Exemple #9
0
    def process_working_hours(self, person_code, wage_type, start_time, end_time):
        col = get_target_mongo_collection('checkin_info')

        person_working_hour_info = col.find({'code': person_code, 'record_time': {'$gt': start_time, '$lt': end_time}},
                                            {'_id': 0})
        person_working_total_amount = 0
        for i in person_working_hour_info:
            check_point = i['check_point']
            if check_point:
                first_check_in = check_point[0]
                last_check_in = check_point[-1]
                if first_check_in != last_check_in:
                    pass
                else:
                    if first_check_in.hour > 18:
                        continue
                    else:
                        last_check_in = datetime(first_check_in.year, first_check_in.month, first_check_in.day, 18)
                get_logger().info(
                    '{} check in at:{} and check out at:{}'.format(person_code, first_check_in, last_check_in))
                work_time_delta = last_check_in - first_check_in
                total_seconds = work_time_delta.total_seconds()
                # 通过该员工的工资计费方式计算工作时间
                if wage_type == 'hourly_wage':
                    # 时薪

                    total_hour = round(float(total_seconds / 3600), 2)
                    person_working_total_amount += total_hour
                if wage_type == 'dayly_wage':
                    # 日薪
                    if total_seconds / 3600 > 8:
                        person_working_total_amount += 1
                if wage_type == 'monthly_wage':
                    # 月薪
                    if total_seconds / 3600 > 8:
                        person_working_total_amount += 1 / 21.5
        return {
            person_code: person_working_total_amount
        }