def create_wordadd(): json_workadd = request.json worker_id = g.current_user.id add_start = json_workadd.get('workadd_start') add_end = json_workadd.get('workadd_end') add_reason = json_workadd.get('workadd_reason') add_type = json_workadd.get('workadd_type') workadd = WorkAdd(worker_id=worker_id, add_start=add_start, add_end=add_end, add_reason=add_reason, apply_time=datetime.now(), type=add_type) add_to_db(workadd) if workadd.add_start > workadd.add_end: delete_to_db(workadd) return bad_request('workadd start laster than end') if workadd.add_start <= datetime.now(): delete_to_db(workadd) return bad_request('workadd start laster than now') if add_reason is None or add_reason == "": delete_to_db(workadd) return bad_request('workadd must have reason') return jsonify({'workadd_id': workadd.id}), 201
def create_holiday(): json_holiday = request.json holiday_type = json_holiday.get('holiday_type') holiday_time_begin = json_holiday.get('holiday_time_begin') holiday_time_end = json_holiday.get('holiday_time_end') reason = json_holiday.get('holiday_reason') worker_id = g.current_user.id male = g.current_user.male print(male) if (male == True and holiday_type == str( HolidayType.query.filter(HolidayType.name == '产假').first().id)): return bad_request("男性不能请产假") if (male == False and holiday_type == str( HolidayType.query.filter(HolidayType.name == '陪产假').first().id)): return bad_request("女性不能请陪产假") holiday = Holiday(type=holiday_type, worker_id=worker_id, holiday_time_begin=holiday_time_begin, holiday_time_end=holiday_time_end, apply_time=datetime.now(), reason=reason) add_to_db(holiday) if holiday.holiday_time_begin > holiday.holiday_time_end: delete_to_db(holiday) return bad_request('begin is latter than end') if holiday.holiday_time_begin <= datetime.now(): delete_to_db(holiday) return bad_request('begin must latter than todays') if reason is None or reason == "": delete_to_db(holiday) return bad_request('you need reason to apply') if HolidayType.query.get(holiday_type) is None: delete_to_db(holiday) return bad_request('the holiday type not exit') if holiday.type == 2: long = (holiday.holiday_time_end - holiday.holiday_time_begin).days if holiday.worker.year_holidays_residue < long: delete_to_db(holiday) return bad_request("your annual leave nums isn't enough") else: sub_residue(holiday.worker, long) add_to_db(holiday) return jsonify({'holiday_id': holiday.id}), 201
def add_degree_to_worker(id): json_worker = request.json department_id = json_worker.get('degree_department_id') degree_id = json_worker.get('degree_degree_id') worker_id = id worker_degree = WorkerDegree(degree_id=degree_id, department_id=department_id, worker_id=worker_id) add_to_db(worker_degree) return jsonify({'message': 'your add the degree to worker {}'.format(id)})
def modify_workadd(id): workadd = WorkAdd.query.filter(WorkAdd.id == id).first() if workadd is None: return bad_request("the workadd isn't exit") json_workadd = request.json add_start = json_workadd.get('workadd_start') add_end = json_workadd.get('workadd_end') add_reason = json_workadd.get('workadd_reason') add_type = json_workadd.get('workadd_type') add_state = json_workadd.get('workadd_state') add_end = add_end if add_end else workadd.add_end add_start = add_start if add_start else workadd.add_start old_end = workadd.add_end old_start = workadd.add_start workadd.add_start = add_start workadd.add_end = add_end add_to_db(workadd) if workadd.add_start > workadd.add_end: workadd.add_end = old_end workadd.add_start = old_start delete_to_db(workadd) return bad_request('the start latter than end') if add_reason: workadd.add_reason = add_reason if add_type: if not WorkaddInfo.query.get(add_type): return bad_request('type is error') workadd.type = add_type if add_state: if add_state not in ['0', '-1', '1']: return bad_request('the add_state must in 0, -1, 1') else: workadd.add_state = add_state add_to_db(workadd) return jsonify({'message': 'you modify your workadd'})
def modify_worker_degree(uid, did): worker_degree = WorkerDegree.query.filter( WorkerDegree.worker_id == uid, WorkerDegree.department_id == did).first() if worker_degree is None: return bad_request("no exits the woker's degree") json_worker = request.json degree = json_worker.get('worker_degree_degree') if Degree.query.filter(Degree.id == degree).first() is None: return bad_request("no exits the degree") worker_degree.degree_id = degree add_to_db(worker_degree) return jsonify({'message': 'your modify the worker degree'})
def add_worker(): json_worker = request.json id = json_worker.get('worker_id') name = json_worker.get('worker_name') email = json_worker.get('worker_email') address = json_worker.get('worker_address') password = json_worker.get('password') worker = Worker(id=id, name=name, email=email, address=address, password=password) try: add_to_db(worker) except Exception: raise validation_error("your enter same error") return jsonify({'message': "add the new worker"})
def examine_check_holiday(id): json_holiday = request.json holiday_examine_ok = json_holiday.get('holiday_ok') holiday = Holiday.query.filter(Holiday.id == id).first() if holiday_examine_ok not in ['-1', '1']: return bad_request("don't examine the holiday") if holiday is None: return bad_request("don't exit the holiday") if holiday.apply_state == -1: return bad_request("the applyer cancel the holiday") if holiday.apply_ok != 0 or holiday.apply_over or holiday.apply_end: return bad_request("holiday not in check") current_worker_department = [] for current_degree in g.current_user.degree_infos: current_worker_department.append(current_degree.department_id) long = holiday.holiday_time_end - holiday.holiday_time_begin for holiday_degree in holiday.worker.degree_infos: if holiday_degree.department_id not in current_worker_department: continue holiday_degree_id = check_really_degree(holiday_degree) current_degree = WorkerDegree.query.filter( WorkerDegree.worker_id == g.current_user.id, WorkerDegree.department_id == holiday_degree.department_id).first() current_degree_id = check_really_degree(current_degree) if current_degree_id - 1 == holiday_degree_id and holiday.apply_state == 0: holiday.apply_state = 1 holiday.apply_ok = holiday_examine_ok if long <= datetime.timedelta( days=3) else 0 holiday.apply_ok = holiday.apply_ok if holiday_examine_ok == '1' else holiday_examine_ok add_to_db(holiday) return jsonify({"message": "examine ok"}) if current_degree_id - 2 == holiday_degree_id and holiday.apply_state == 1 and long > datetime.timedelta( days=3): holiday.apply_state = 2 holiday.apply_ok = holiday_examine_ok if datetime.timedelta( days=3) < long <= datetime.timedelta(days=9) else 0 holiday.apply_ok = holiday.apply_ok if holiday_examine_ok == '1' else holiday_examine_ok add_to_db(holiday) return jsonify({"message": "examine ok"}) if long > datetime.timedelta(days=9) and current_degree_id - 3 == holiday_degree_id and \ holiday.apply_state == 2: holiday.apply_state = 3 holiday.apply_ok = holiday_examine_ok add_to_db(holiday) return jsonify({"message": "examine ok"}) return bad_request("your can't examine the holidays")
def examine_workadd(id): json_holiday = request.json workadd_ok = json_holiday.get('workadd_ok') workadd = WorkAdd.query.filter(WorkAdd.id == id).first() if workadd_ok not in ['-1', '1']: return bad_request('please set the examine') if workadd is None: return bad_request("don't exit the examine") if workadd.add_state != 0: return bad_request('the workadd is examine over') current_worker_department = [] for current_degree in g.current_user.degree_infos: current_worker_department.append(current_degree.department_id) for workadd_degree in workadd.worker.degree_infos: if workadd_degree.department_id not in current_worker_department: continue workadd_degree_id = check_really_degree(workadd_degree) current_degree = WorkerDegree.query.filter( WorkerDegree.worker_id == g.current_user.id, WorkerDegree.department_id == workadd_degree.department_id).first() current_degree_id = check_really_degree(current_degree) if workadd_degree_id == current_degree_id - 1: workadd.add_state = workadd_ok if workadd_ok == '1': workadd.worker.workAdd_time += ( workadd.add_end - workadd.add_start).total_seconds() / 3600 # print(type(workadd.add_end - workadd.add_start).days) add_to_db(workadd) return jsonify({"message": "examine ok"}) return bad_request("your can't examine the workadd")
def modify_worker_info(id): worker = Worker.query.get(id) if worker is None: return bad_request('no exits the worker') json_worker = request.json name = json_worker.get('worker_name') email = json_worker.get('worker_email') address = json_worker.get('worker_address') password = json_worker.get('worker_password') year_holidays_residue = json_worker.get('worker_year_holidays_residue') year_holidays_used = json_worker.get('worker_year_holidays_use') workAdd_time = json_worker.get('workAdd_time') if name: worker.name = name if email: worker.email = email if address: worker.address = address if password: worker.password = password if year_holidays_used: worker.year_holidays_used = year_holidays_used if year_holidays_residue: worker.year_holidays_residue = year_holidays_residue if workAdd_time: worker.workAdd_time = workAdd_time add_to_db(worker) return jsonify({'message': 'you modify the worker info'})
def modify_holiday(id): holiday = Holiday.query.filter(Holiday.id == id).first() if holiday is None: return bad_request("the holiday isn't exit") json_holiday = request.json holiday_end = json_holiday.get('holiday_end') holiday_time_begin = json_holiday.get("holiday_time_begin") holiday_time_end = json_holiday.get("holiday_time_end") holiday_over = json_holiday.get('holiday_over') holiday_reason = json_holiday.get('holiday_reason') holiday_type = json_holiday.get('holiday_type') holiday_state = json_holiday.get('holiday_state') old_holiday_begin = holiday.holiday_time_begin old_holiday_end = holiday.holiday_time_end holiday.holiday_time_begin = holiday_time_begin if holiday_time_begin else old_holiday_begin holiday.holiday_time_end = holiday_time_end if holiday_time_end else old_holiday_end add_to_db(holiday) if holiday.holiday_time_begin > holiday.holiday_time_end: holiday.holiday_time_begin = old_holiday_begin holiday.holiday_time_end = old_holiday_end add_to_db(holiday) return bad_request('begin is latter than end') if holiday_reason: holiday.reason = holiday_reason if holiday_state: if holiday_state not in ['0', '-1', '1', '2', '3']: return bad_request('holiday_state is wrong') else: holiday.apply_state = holiday_state if holiday_over: if holiday_over not in ['0', '1']: return bad_request('holiday_over must in 0, 1') else: holiday.apply_over = holiday_over if holiday_type: if not HolidayType.query.get(holiday_type): return bad_request('the type is wrong') else: holiday.type = holiday_type if holiday_end: if holiday_end not in ['0', '1']: return bad_request('holiday_end must in 0, 1') else: holiday.apply_end = holiday_end add_to_db(holiday) return jsonify({'message': 'your modify worker holiday apply'})
def examine_over_holiday(id): json_holiday = request.json holiday_examine_over = json_holiday.get('holiday_over') holiday = Holiday.query.filter(Holiday.id == id).first() if holiday is None: return bad_request("don't exit the holiday") if holiday.apply_over: return bad_request("this holiday is over") if not holiday.apply_end: return bad_request("holiday isn't over and wait to check over") current_worker_department = [] for current_degree in g.current_user.degree_infos: current_worker_department.append(current_degree.department_id) for holiday_degree in holiday.worker.degree_infos: if holiday_degree.department_id not in current_worker_department: continue holiday_degree_id = check_really_degree(holiday_degree) current_degree = WorkerDegree.query.filter( WorkerDegree.worker_id == g.current_user.id, WorkerDegree.department_id == holiday_degree.department_id).first() current_degree_id = check_really_degree(current_degree) if current_degree_id - 1 == holiday_degree_id: holiday.apply_end = True holiday.apply_over = True holiday.end_time = datetime.datetime.now() add_to_db(holiday) return jsonify({'message': 'your examine over the holiday'}) return bad_request("your can't examine the holidays")
def modify_the_workadd(id): workadd = WorkAdd.query.filter(WorkAdd.id == id).first() if workadd is None: return bad_request("the workadd isn't exit") if workadd.worker_id != g.current_user.id: return bad_request("your can't modify the holiday isn't belong you") if workadd.add_state == 1 or workadd.add_state == -1: return bad_request("your can't modify the workadd is ok or cancel") json_workadd = request.json add_start = json_workadd.get('workadd_start') add_end = json_workadd.get('workadd_end') add_reason = json_workadd.get('workadd_reason') add_type = json_workadd.get('workadd_type') add_over = json_workadd.get('workadd_over') if add_over: workadd.add_state = -1 add_to_db(workadd) return jsonify({'message': 'you cancel your workadd'}) add_end = add_end if add_end else workadd.add_end add_start = add_start if add_start else workadd.add_start old_end = workadd.add_end old_start = workadd.add_start workadd.add_start = add_start workadd.add_end = add_end add_to_db(workadd) if workadd.add_start > workadd.add_end: workadd.add_end = old_end workadd.add_start = old_start delete_to_db(workadd) return bad_request('the start latter than end') if add_reason: workadd.add_reason = add_reason if add_type: if not WorkaddInfo.query.get(add_type): return bad_request('type is error') workadd.type = add_type workadd.add_state = 0 add_to_db(workadd) return jsonify({'message': 'you modify your workadd'})
def modify_the_holiday(id): holiday = Holiday.query.filter(Holiday.id == id).first() if holiday is None: return bad_request("the holiday isn't exit") if holiday.worker_id != g.current_user.id: return bad_request( "your can't modify the holiday which is not belong you") if holiday.apply_over: return bad_request("your can't modify the holiday is over") json_holiday = request.json holiday_end = json_holiday.get('holiday_end') if holiday_end: if holiday.apply_ok != 1: return bad_request( 'your can apply to end the holiday maybe in check or apply faily' ) holiday.apply_end = True add_to_db(holiday) return jsonify({"message": "your apply to end the holiday"}) if holiday.apply_ok == 1: return bad_request("you can't modify the apply ok holiday") if holiday.apply_state not in [0, -1] and holiday.apply_ok != -1: return bad_request("you can't modify the holiday in check") holiday_time_begin = json_holiday.get("holiday_time_begin") holiday_time_end = json_holiday.get("holiday_time_end") type = json_holiday.get('holiday_type') male = g.current_user.male if (male == True and type == str( HolidayType.query.filter(HolidayType.name == '产假').first().id)): return bad_request("男性不能请产假") if (male == False and type == str( HolidayType.query.filter(HolidayType.name == '陪产假').first().id)): return bad_request("女性不能请陪产假") old_holiday_begin = holiday.holiday_time_begin old_holiday_end = holiday.holiday_time_end holiday.holiday_time_begin = holiday_time_begin if holiday_time_begin else old_holiday_begin holiday.holiday_time_end = holiday_time_end if holiday_time_end else old_holiday_end add_to_db(holiday) holiday_over = json_holiday.get('holiday_over') # cancel the apply holiday if holiday_over: if holiday.type == 2: add_residue(holiday.worker, (old_holiday_end - old_holiday_begin).days) holiday.apply_over = True add_to_db(holiday) return jsonify({'message': 'you cancle your holiday'}) if holiday.holiday_time_begin < datetime.now(): holiday.holiday_time_begin = datetime.now() add_to_db(holiday) if holiday.holiday_time_begin > holiday.holiday_time_end: holiday.holiday_time_begin = old_holiday_begin holiday.holiday_time_end = old_holiday_end add_to_db(holiday) return bad_request('begin is latter than end') long = (holiday.holiday_time_end - holiday.holiday_time_begin).days old_long = (old_holiday_end - old_holiday_begin).days if holiday.type == 2: if type == '2': if holiday.worker.year_holidays_residue + old_long < long: holiday.holiday_time_begin = old_holiday_begin holiday.holiday_time_end = old_holiday_end add_to_db(holiday) return bad_request("your annual leave nums isn't enough") else: add_residue(holiday.worker, old_long) sub_residue(holiday.worker, long) elif HolidayType.query.get(type): # from year to other add_residue(holiday.worker, old_long) # this mean your change the holiday not year to year elif type == '2': if holiday.worker.year_holidays_residue < long: holiday.holiday_time_begin = holiday_time_begin holiday.holiday_time_end = holiday_time_end add_to_db(holiday) return bad_request("your annual leave nums isn't enough") else: sub_residue(holiday.worker, long) if json_holiday.get('holiday_reason'): holiday.reason = json_holiday.get('holiday_reason') if HolidayType.query.get(type): holiday.type = type holiday.apply_ok = 0 holiday.apply_state = 0 add_to_db(holiday) return jsonify({'message': 'your modify your holiday apply'})