def pms_pass_cvs(com_id): omu = AuthUser('admin', default_password) _ivs = Interview.query.filter_by(company_id=com_id).all() for index, _iv in enumerate(_ivs): _pm = Pm.query.filter_by(id=_iv.pm_id).first() _pmu = AuthUser(_pm.phone, default_password) pm_pass_cv(omu, _pmu, _iv, index)
def create_company(): already_company = Company.query.order_by(db.desc(Company.id)).first() company_index = already_company.id + 1 if already_company else 1 name = f.company() company_om = f.name() email = f.email() # phone = '13366556715' # phone = f.phone_number() contract_name = '94017386-6fac-11e9-a419-acbc329114cf.r.pdf' contract_path = os.path.join(root_path, 'create_fake_data', contract_name) site_files = os.path.join(root_path, 'main', 'files', 'tem', contract_name) shutil.copyfile(contract_path, site_files) om_user = AuthUser('admin', default_password) company_data = dict(name=name, contact=company_om, phone=phone, email=email, address='adfa adf', om_name=phone, billing_cycle=1, service_fee_rate=0.1, tax_rate=0.05, hr_fee_rate=0.03, finance_rate=0.01) result = om_user.post('/api/v1/company', json=company_data) result = json.loads(result) return result['id']
def generate_month_bill(cg, year_month): auth_cg = AuthUser(cg.pre_username) auth_admin = AuthUser('admin') auth_admin.post('/api/v1/monthly_bill', json={ 'year_month': year_month, 'company_id': cg.company_id })
def add_pm2project(com_id): u = CompanyOm.query.filter_by(company_id=com_id).first() cou = AuthUser(u.username, default_password) _pms = Pm.query.filter_by(company_id=com_id).all() _projects = Project.query.filter_by(company_id=com_id).all() for _project in _projects: for _pm in _pms: cou.put('/api/v1/project?id={}&schema=ProjectAddPmSchema'.format( _project.id), json={"pm_id": _pm.id})
def push_engineer(): es = Engineer.query.all() os = Offer.query.all() es_num = len(es) admin = AuthUser('admin') for i in range(es_num - 10): one_engineer = es[i] one_offer = os[i % len(os)] interview_data = dict(offer_id=one_offer.id) interview_data['engineer_id'] = one_engineer.id admin.post('/api/v1/interview', json=interview_data)
def engineers_do_work(com_id): set_today('20190522') begin = get_today() pms = Pm.query.filter_by(company_id=com_id).all() for _pm in pms: pmu = AuthUser(_pm.pre_username, default_password) es = Engineer.query.filter_by(company_id=com_id, status='on_duty', pm_id=_pm.id).all() for e in es: eu = AuthUser(e.pre_username, default_password) engineer_do_work(pmu, eu, begin)
def check_work_report(pmx): auth_pm = AuthUser(pmx.pre_username) un_checked_work_reports = auth_pm.get( '/api/v1/audits?status=submit&sort_id=-1&audit_type=work_report') un_checked_work_reports = json.loads(un_checked_work_reports)['data'] for ucwr in un_checked_work_reports: auth_pm.put( '/api/v1/work_report?id={}&schema=WorkReportCheckPutSchema'.format( ucwr['id']), json={ "status": "checked", "attitude_score": random.randint(3, 5), "ability_score": random.randint(3, 5) })
def create_position_level(com_id): u = CompanyOm.query.filter_by(company_id=com_id).first() cou = AuthUser(u.username, default_password) _position = { "name": "前端", "salary_type": 0, "position_levels": [{ "name": "p1", "money": 500 }, { "name": "p2", "money": 600 }] } cou.post('/api/v1/position', json=_position)
def set_interview_appointment(): all_pms = Pm.query.all() auth_admin = AuthUser('admin') for one_pm in all_pms: interviews = auth_admin.get( '/api/v1/interviews?status={}&pm_id={}'.format( InterviewStatus.cv_pass, one_pm.id)) interviews = json.loads(interviews)['data'] for i, one_interview in enumerate(interviews[::-1]): if i < 6: continue if i < 7: status = InterviewStatus.interview_reject_by_engineer auth_admin.put( '/api/v1/interview?id={}&schema=InterviewStatusPutSchema'. format(one_interview['id']), json={"status": status}) else: status = InterviewStatus.interview_new pm_free_time = one_interview['pm_free_time'] chooices = [] for pft in pm_free_time: if (pft['am'] or pft['pmA'] or pft['pmB']) and (not pft['disable']): chooices.append(pft) appoint_time = chooices[i % len(chooices)] appoint_time.update(am=False, pmA=True, pmB=False) auth_admin.put( '/api/v1/interview?id={}&schema=InterviewStatusPutSchema'. format(one_interview['id']), json={ 'status': status, 'appoint_time': appoint_time })
def update_all_un_put_daily_logs(ex): auth_e = AuthUser(ex.pre_username) latest_daily_logs = _get_latest_daily_logs(auth_e) un_put_latest_daily_logs = list( filter( lambda x: x['duration'] == 0 and not x['content'] and x[ 'origin_type'] == 'normal_work', latest_daily_logs['data'])) for dl in un_put_latest_daily_logs: _put_daily_log_for(auth_e, dl['date'])
def push_engineers_to_offers(com_id): c = Company.query.filter_by(id=com_id).first() _om = AuthUser('admin', default_password) _offers = Offer.query.filter_by(company_id=com_id).all() _es = Engineer.query.filter(Engineer.real_name.like('测%'), Engineer.created > c.created).all() _eq = Queue() for _e in _es: _eq.put(_e) for _o in _offers: for i in range(8): _e = _eq.get() push_engineer_to_offer(_om, _e, _o)
def interview_result(): all_pms = Pm.query.all() for one_pm in all_pms: auth_pm = AuthUser(one_pm.pre_username) interviews = auth_pm.get('/api/v1/interviews?status={}'.format( InterviewStatus.interview_new)) interviews = json.loads(interviews)['data'] for i, one_interview in enumerate(interviews[::-1]): if i < 4: continue if i < 5: status = InterviewStatus.interview_undetermined elif i < 6: status = InterviewStatus.interview_reject elif i < 7: status = InterviewStatus.interview_absent else: status = InterviewStatus.interview_pass auth_pm.put( '/api/v1/interview?id={}&schema=InterviewStatusPutSchema'. format(one_interview['id']), json={"status": status})
def first_month_audit(): today = get_today() _, month_end_date = month_first_end_date(today.year, today.month) es = Engineer.query.filter_by(status=EngineerStatus.on_duty).all() pms = Pm.query.all() # 请假 for i, e in enumerate(es): e_auth = AuthUser(e.pre_username) e_auth.post('/api/v1/leave', json={ 'leave_type': LeaveType.personal, 'start_date': after_some_work_days(i % 5).strftime('%Y-%m-%d'), 'end_date': after_some_work_days(i % 5 + 2).strftime('%Y-%m-%d'), 'days': 3 - 0.5 * (i % 2), 'reason': '爱批不批', }) for _pm in pms: pm_auth = AuthUser(_pm.pre_username)
def create_offers(com_id): u = CompanyOm.query.filter_by(company_id=com_id).first() cou = AuthUser(u.username, default_password) _projects = Project.query.filter_by(company_id=com_id).all() _pms = Pm.query.filter_by(company_id=com_id).all() _position = Position.query.filter_by(company_id=com_id).first() for _pj in _projects: for _pm in _pms: data = dict( pm_id=_pm.id, project_id=_pj.id, position_id=_position.id, position_levels=[p.id for p in _position.position_levels]) create_offer(cou, data)
def first_month_daily_log(): today = get_today() _, month_end_date = month_first_end_date(today.year, today.month) es = Engineer.query.filter_by(status=EngineerStatus.on_duty).all() while today <= month_end_date: for e in es: if e.career[-1].start < today: continue auth_e = AuthUser(e.pre_username) auth_e.post('/api/v1/daily_log', json={''}) pms = Pm.query.all() for _pm in pms: auth_pm = AuthUser(_pm.pre_username) leave_audits = auth_pm.get( '/api/v1/leaves?audit_type=leave&status=submit') for index, la in enumerate(leave_audits[::-1]): if index < 2: auth_pm.put( '/api/v1/leave?id={}&schema=LeaveCheckPutSchema'.format( la.id))
def create_engineers(): for i in range(99): e = {} for key in engineers: e[key] = engineers[key](i) admin = AuthUser('admin') admin.post('/api/v1/engineer', json=e) admin.put( "/api/v1/engineer?schema=EngineerPutSchema&pre_username={}".format( e['pre_username']), json={"welfare_rate": e["welfare_rate"]})
def check_interviews(): all_pms = Pm.query.all() for one_pm in all_pms: auth_pm = AuthUser(one_pm.pre_username) appoint_time = auth_pm.get('/api/v1/pm?schema=PmAppointTimeSchema') appoint_time = json.loads(appoint_time) for d in appoint_time['default_can_appoint_time']: d['am'] = True auth_pm.put('/api/v1/pm?schema=PmCanAppointTimePutSchema', json={ "set_info": appoint_time['default_can_appoint_time'], "set_default": True }) interviews = Interview.query.filter_by(pm_id=one_pm.id).all() for i, one_interview in enumerate(interviews[::-1]): if i < 2: status = InterviewStatus.cv_new elif i < 4: status = InterviewStatus.cv_reject elif i < 5: status = InterviewStatus.cv_read else: status = InterviewStatus.cv_pass if status == InterviewStatus.cv_pass: auth_pm.put( '/api/v1/interview?id={}&schema=InterviewStatusPutSchema'. format(one_interview.id), json={ 'status': status, "pm_free_time": appoint_time['default_can_appoint_time'] }) else: auth_pm.put( '/api/v1/interview?id={}&schema=InterviewStatusPutSchema'. format(one_interview.id), json={'status': status})
def om_check_entry(com_id): c = Company.query.filter_by(id=com_id).first() _om = AuthUser('admin', default_password) eps = EnterProject.query.filter_by( company_id=com_id, status=EnterProjectStatus.purchase_agree).all() reject_id = eps[0].id _om.put( 'api/v1/enter_project?id={}&schema=EnterProjectOmRejectSchema'.format( reject_id), json={}) for ep in eps[1:]: _om.put('/api/v1/enter_project?id={}&schema=EnterProjectOmCheckSchema'. format(ep.id), json={ "employ_type": 0, "tax_free_rate": 0.1 })
def com_agree_entry(com_id): c = Company.query.filter_by(id=com_id).first() u = CompanyOm.query.filter_by(company_id=com_id).first() cou = AuthUser(u.username, default_password) eps = EnterProject.query.filter_by( company_id=com_id, status=EnterProjectStatus.pm_agree).all() reject_id = eps[0].id cou.put( '/api/v1/enter_project?id={}&schema=EnterProjectRejectSchema'.format( reject_id)) for ep in eps[1:]: cou.put('/api/v1/enter_project?id={}&schema=EnterProjectCheckSchema'. format(ep.id), json={ "work_content": "sdfads", "service_type": "asdfa", "auto_renew": 1, "renew_cycle": 3 })
def import_data(user_name, password='******'): e = AuthUser(user_name, password=password) result = e.get("daily_logs?sort_id=-1&page=1&per_page=1") pass
def create_engineers(): om_user = AuthUser('admin', default_password) for i in range(42): create_engineer(om_user)
def submit_work_report(ex, year_month): auth_e = AuthUser(ex.pre_username) auth_e.post('/api/v1/work_report', json={"year_month": year_month})
def create_pm_purchase_project(com_id): u = CompanyOm.query.filter_by(company_id=com_id).first() cou = AuthUser(u.username, default_password) _om = AuthUser('admin', default_password) from main.api.admin import _create_pre_username cg = { "pre_username": _create_pre_username(com_id), "real_name": f.name(), "phone": f.phone_number() } cou.post('/api/v1/purchase', json=cg) _pm = { "pre_username": _create_pre_username(com_id), "real_name": f.name(), "phone": f.phone_number() } cou.post('/api/v1/pm', json=_pm) _pm = { "pre_username": _create_pre_username(com_id), "real_name": f.name(), "phone": f.phone_number() } cou.post('/api/v1/pm', json=_pm) _project = { "company_id": com_id, "name": "项目{}".format(random.randint(0, 1000)) } cou.post('/api/v1/project', json=_project) _project = { "company_id": com_id, "name": "项目{}".format(random.randint(0, 1000)) } cou.post('/api/v1/project', json=_project)
def ex_work_content(ex, start_date): pm = Pm.query.get(ex.pm_id) auth_pm = AuthUser(pm.pre_username) # dls = DailyLog.query.filter_by(engineer_id=ex.id).all() # for dl in dls: # dl.delete() # 第一天的正常日志 set_today(start_date) auth_e = AuthUser(ex.pre_username) _get_latest_daily_logs(auth_e) _put_daily_log_for(auth_e, get_today()) # 提个明天的请假: next_work_date = after_some_work_days(1) next_work_date = str_date(next_work_date) response = auth_e.post('/api/v1/leave', json={ "leave_type": "person", "start_date": next_work_date, "end_date": next_work_date, "reason": "约会", "days": 1 }) response = json.loads(response) auth_pm.put('/api/v1/leave?id={}&schema=LeaveCheckPutSchema'.format( response['id']), json={"status": AuditStatus.checked}) # 请假了,虚度过去这一天 enter_next_work_date(1) # 正常日志 enter_next_work_date() _get_latest_daily_logs(auth_e) _put_daily_log_for(auth_e, get_today()) # 4天忘了写,打开日志,补了4天 enter_next_work_date(after=4) latest_daily_logs = _get_latest_daily_logs(auth_e) un_put_latest_daily_logs = list( filter( lambda x: x['duration'] == 0 and not x['content'] and x[ 'origin_type'] == 'normal_work', latest_daily_logs['data'])) assert len(un_put_latest_daily_logs) == 4 for daily in un_put_latest_daily_logs: _put_daily_log_for(auth_e, daily['date']) # 正常工作到周末之前 while is_work_day(after_some_days(1)): enter_next_date(1) _get_latest_daily_logs(auth_e) _put_daily_log_for(auth_e, get_today()) # 明天应该是周末了,申请1。5天的加班 next_day = after_some_days(1) response = auth_e.post('/api/v1/extra_work', json={ "start_date": str_date(next_day), "end_date": str_date(after_some_days(1, next_day)), "days": 1.5, "reason": "赶进度" }) audit_id = json.loads(response)['id'] auth_pm.put( '/api/v1/extra_work?schema=ExtraWorkCheckPutSchema&id={}'.format( audit_id), json={"status": AuditStatus.checked}) # 加班 enter_next_date(1) _put_daily_log_for(auth_e, get_today(), content='加班1', duration=1) enter_next_date(1) _put_daily_log_for(auth_e, get_today(), content="加班2", duration=0.5) # 加班这么累,调个休 next_day = after_some_work_days(1) can_shift_duration = auth_e.get('/api/v1/can_shift_duration') can_shift_duration = int(can_shift_duration) auth_e.post('/api/v1/shift', json={ 'start': next_day, 'end_date': next_day })
def entry(): auth_admin = AuthUser('admin') interviews = auth_admin.get('/api/v1/interviews?status={}'.format( InterviewStatus.interview_pass)) interviews = json.loads(interviews)['data'] for i, one_interview in enumerate(interviews[::-1]): if i < 4: continue entry_date = after_some_work_days(1) result = auth_admin.put( '/api/v1/interview?id={}&schema=InterviewEntryPutSchema'.format( one_interview['id']), json={'date': entry_date.strftime('%Y-%m-%d')}) all_pms = Pm.query.all() for one_pm in all_pms: auth_pm = AuthUser(one_pm.pre_username) entries = auth_pm.get('/api/v1/entries?status={}'.format( AuditStatus.submit)) entries = json.loads(entries)['data'] for i, one_entry in enumerate(entries[::-1]): if i < 1: continue if i < 2: status = AuditStatus.reject reason = '看不对眼' auth_pm.put( '/api/v1/entry?id={}&schema=EntryCheckSchema'.format( one_entry['id']), json={ 'status': status, 'comment': reason }) else: try: auth_pm.put( '/api/v1/entry?id={}&schema=EntryCheckSchema'.format( one_entry['id']), json={'status': AuditStatus.checked}) except Exception as e: print(e)
def create_company_data(): admin = AuthUser('admin') admin.post('/api/v1/company', json=company1['company_form']) company_model = Company.query.filter_by( name=company1['company_form']['name']).first() for cg in company1['purchases']: cg.update({'company_id': company_model.id}) admin.post('/api/v1/purchase', json=cg) for ipm in company1['pms']: ipm.update({'company_id': company_model.id}) admin.post('/api/v1/pm', json=ipm) for position in company1['positions']: position.update({'company_id': company_model.id}) admin.post('/api/v1/position', json=position) for position_level in company1['position_levels']: position_level.update({'company_id': company_model.id}) admin.post('/api/v1/position_level', json=position_level) # 创建报价单 position_models = Position.query.filter().all() position_level_models = PositionLevel.query.filter().all() for p in position_models: for pl in position_level_models: admin.post('/api/v1/offer_sheet', json={'company_id': company_model.id, 'position_id': p.id, \ 'position_level_id': pl.id, 'money': 10000}) # 创建项目 ps = company1['projects'] for p in ps: p['company_id'] = company_model.id admin.post('/api/v1/project', json=p) os = company1['offers'] all_project = Project.query.all() all_positions = Position.query.all() all_position_level = PositionLevel.query.all() all_pms = Pm.query.all() index = 0 for one_project in all_project[:2]: for one_position in all_positions[:2]: one_position_level = all_position_level[index % len(all_position_level)] o_data = {} o_data['name'] = os['name'](one_position.name + one_position_level.name) o_data['amount'] = os['amount'](index) o_data['position_id'] = one_position.id o_data['company_id'] = company_model.id o_data['project_id'] = one_project.id o_data['pm_id'] = all_pms[index % len(all_pms)].id o_data['position_id'] = one_position.id o_data['position_level_id'] = one_position_level.id o_data['description'] = '一个需求' admin.post('/api/v1/offer', json=o_data) index += 1