def active_worker(): """ Заповнення в БД працівників """ _1c = json.loads(load_users()) session = Session() for arg in _1c['data']: if not session.query(Worker).filter(Worker.sid == arg['SID']).first() and not arg['dismissed'] \ and arg['SID'] != '': load_from_1c(arg, 'active') session.close()
def active_worker_without_sid(): """ Заповнення в БД працівників в яких немає sid """ _1c = json.loads(load_users()) session = Session() for arg in _1c['data']: if not arg['dismissed'] and arg['SID'] == '' and not session.query( Worker).filter(Worker.name_ua == arg['name']).filter( Worker.surname_ua == arg['surname']).filter( Worker.middle_name_ua == arg['middlename']).first(): load_from_1c(arg, 'active') session.close()
def dismissed(): """ Заповнення в БД звільнених працівників """ _1c = json.loads(load_users()) session = Session() for arg in _1c['data']: if arg['dismissed'] and not session.query(Worker).filter( Worker.name_ua == arg['name']).filter( Worker.surname_ua == arg['surname']).filter( Worker.middle_name_ua == arg['middlename']).first(): load_from_1c(arg, 'dismissed') session.close()
def collisions_users(sid): """ Отримання даних по невідповідностям працівника за sid-ом з 1с,АД та mysql. :param sid: унікальний індифікатор """ session = Session() all_records = session.query(Worker).join(Person, Person.id == Worker.fk_person).join(Position, Position.id == Worker.fk_position, isouter=True).join( Department1c, Department1c.id == Worker.fk_department, isouter=True) \ .filter(Worker.sid == sid).all() converter = WorkerSchema(many=True, only=['sid', 'name_ua', 'name_en', 'surname_en', 'card_number', 'status', 'skype', 'email', 'started_to_work', 'finished_to_work', 'middle_name_ua', 'work_schedule', 'person.passport_id', 'person.date_of_issue', 'person.issued_by', 'ip_phone', 'surname_ua', 'person.mobile_phone', 'person.id', 'person.ipn', 'person.birthday', 'person.home_phone', 'position.name', 'department.name', 'person.place_of_residence', 'person.registration', 'person.marital_status', 'surname_ru', 'name_ru']) mysql_ = converter.dump(all_records).data user = [] res = ad.search(search_base='DC=busmarket,DC=ua', search_filter="(&(objectCategory=person)(objectClass=user)(objectSid={sid}))".format(sid=sid), attributes=['mail', 'telephoneNumber', 'sn', 'cn', 'givenName', 'displayName', 'department', 'mobile', 'givenName-En', 'givenNameUa', 'cityUa', 'departmentEn', 'ipPhone', 'isDeleted', 'userAccountControl', 'l', 'ManagedBy', 'Name', 'CanonicalName', 'givenName-En', 'snEn', 'givenNameUa', 'snUa', 'streetAddress', 'streetAddressCompany', 'streetAddressCompanyRu', 'co', 'title', 'titleEn', 'titleUa', 'departmentEn', 'departmentUa', 'company', 'companyEn', 'pager', 'st', 'streetAddressCompanyUa', 'streetAddressUa', 'stUa', 'postalCode', 'streetAddress', 'street', 'objectSid'] ) if res: for entry in ad.response: if 'dn' in entry: user.append(dict(entry['attributes'])) print(user) result = [] res = [] _1c = json.loads(load_users()) for arg in _1c['data']: if arg['SID'] == sid: res.append(arg) result.append(res) result.append(mysql_) result.append(user) session.close() return jsonify(result)
def update_user_db_1c(): """ оновлення даних з 1с """ _1c = json.loads(load_users()) session = Session() for arg in _1c['data']: worker = session.query(Worker).filter(Worker.sid == arg['SID']).first() if worker and arg['SID'] != '': if arg['dismissed']: status = 'dismissed' else: status = 'active' update_from_1c(arg, status, worker.fk_person) session.close()