mirror of https://github.com/veops/cmdb.git
Merge pull request #146 from simontigers/common_setting_format
Common setting format
This commit is contained in:
commit
ddf02213db
|
@ -4,11 +4,11 @@ COMMON_SETTING_QUEUE = "common_setting_async"
|
||||||
|
|
||||||
|
|
||||||
class OperatorType(BaseEnum):
|
class OperatorType(BaseEnum):
|
||||||
EQUAL = 1 # 等于
|
EQUAL = 1
|
||||||
NOT_EQUAL = 2 # 不等于
|
NOT_EQUAL = 2
|
||||||
IN = 3 # 包含
|
IN = 3
|
||||||
NOT_IN = 4 # 不包含
|
NOT_IN = 4
|
||||||
GREATER_THAN = 5 # 大于
|
GREATER_THAN = 5
|
||||||
LESS_THAN = 6 # 小于
|
LESS_THAN = 6
|
||||||
IS_EMPTY = 7 # 为空
|
IS_EMPTY = 7
|
||||||
IS_NOT_EMPTY = 8 # 不为空
|
IS_NOT_EMPTY = 8
|
||||||
|
|
|
@ -7,6 +7,7 @@ from wtforms import IntegerField
|
||||||
from wtforms import StringField
|
from wtforms import StringField
|
||||||
from wtforms import validators
|
from wtforms import validators
|
||||||
|
|
||||||
|
from api.extensions import db
|
||||||
from api.lib.common_setting.resp_format import ErrFormat
|
from api.lib.common_setting.resp_format import ErrFormat
|
||||||
from api.lib.perm.acl.role import RoleCRUD
|
from api.lib.perm.acl.role import RoleCRUD
|
||||||
from api.models.common_setting import Department, Employee
|
from api.models.common_setting import Department, Employee
|
||||||
|
@ -44,7 +45,6 @@ def get_all_employee_list(block=0, to_dict=True):
|
||||||
'email',
|
'email',
|
||||||
'mobile',
|
'mobile',
|
||||||
'direct_supervisor_id',
|
'direct_supervisor_id',
|
||||||
'annual_leave',
|
|
||||||
'block',
|
'block',
|
||||||
'department_id',
|
'department_id',
|
||||||
]
|
]
|
||||||
|
@ -94,11 +94,9 @@ class DepartmentTree(object):
|
||||||
|
|
||||||
for top_d in top_departments:
|
for top_d in top_departments:
|
||||||
department_id = top_d['department_id']
|
department_id = top_d['department_id']
|
||||||
# 检查 department_id 是否作为其他部门的 parent
|
|
||||||
sub_deps = self.get_department_by_parent_id(department_id)
|
sub_deps = self.get_department_by_parent_id(department_id)
|
||||||
employees = []
|
employees = []
|
||||||
if self.append_employee:
|
if self.append_employee:
|
||||||
# 要包含员工
|
|
||||||
employees = self.get_employees_by_d_id(department_id)
|
employees = self.get_employees_by_d_id(department_id)
|
||||||
|
|
||||||
top_d['employees'] = employees
|
top_d['employees'] = employees
|
||||||
|
@ -127,7 +125,6 @@ class DepartmentTree(object):
|
||||||
sub_deps = self.get_department_by_parent_id(d['department_id'])
|
sub_deps = self.get_department_by_parent_id(d['department_id'])
|
||||||
employees = []
|
employees = []
|
||||||
if self.append_employee:
|
if self.append_employee:
|
||||||
# 要包含员工
|
|
||||||
employees = self.get_employees_by_d_id(d['department_id'])
|
employees = self.get_employees_by_d_id(d['department_id'])
|
||||||
|
|
||||||
d['employees'] = employees
|
d['employees'] = employees
|
||||||
|
@ -184,7 +181,6 @@ class DepartmentCRUD(object):
|
||||||
def check_department_parent_id_allow(d_id, department_parent_id):
|
def check_department_parent_id_allow(d_id, department_parent_id):
|
||||||
if department_parent_id == 0:
|
if department_parent_id == 0:
|
||||||
return
|
return
|
||||||
# 检查 department_parent_id 是否在许可范围内
|
|
||||||
allow_p_d_id_list = DepartmentCRUD.get_allow_parent_d_id_by(d_id)
|
allow_p_d_id_list = DepartmentCRUD.get_allow_parent_d_id_by(d_id)
|
||||||
target = list(
|
target = list(
|
||||||
filter(lambda d: d['department_id'] == department_parent_id, allow_p_d_id_list))
|
filter(lambda d: d['department_id'] == department_parent_id, allow_p_d_id_list))
|
||||||
|
@ -263,9 +259,6 @@ class DepartmentCRUD(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_allow_parent_d_id_by(department_id):
|
def get_allow_parent_d_id_by(department_id):
|
||||||
"""
|
|
||||||
获取可以成为 department_id 的 department_parent_id 的 list
|
|
||||||
"""
|
|
||||||
tree_list = DepartmentCRUD.get_department_tree_list()
|
tree_list = DepartmentCRUD.get_department_tree_list()
|
||||||
|
|
||||||
allow_d_id_list = []
|
allow_d_id_list = []
|
||||||
|
@ -307,7 +300,6 @@ class DepartmentCRUD(object):
|
||||||
if len(all_deps) == 0:
|
if len(all_deps) == 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# 一级部门
|
|
||||||
top_deps = list(filter(lambda d: d['department_parent_id'] == -1, all_deps))
|
top_deps = list(filter(lambda d: d['department_parent_id'] == -1, all_deps))
|
||||||
if len(top_deps) == 0:
|
if len(top_deps) == 0:
|
||||||
return []
|
return []
|
||||||
|
@ -321,7 +313,6 @@ class DepartmentCRUD(object):
|
||||||
top_d['department_name'],
|
top_d['department_name'],
|
||||||
identifier_root
|
identifier_root
|
||||||
)
|
)
|
||||||
# 检查 department_id 是否作为其他部门的 parent
|
|
||||||
sub_ds = list(filter(lambda d: d['department_parent_id'] == identifier_root, all_deps))
|
sub_ds = list(filter(lambda d: d['department_parent_id'] == identifier_root, all_deps))
|
||||||
if len(sub_ds) == 0:
|
if len(sub_ds) == 0:
|
||||||
tree_list.append(tree)
|
tree_list.append(tree)
|
||||||
|
@ -350,6 +341,13 @@ class DepartmentCRUD(object):
|
||||||
DepartmentCRUD.parse_sub_department_node(
|
DepartmentCRUD.parse_sub_department_node(
|
||||||
next_sub_ds, all_ds, tree, d['department_id'])
|
next_sub_ds, all_ds, tree, d['department_id'])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_department_by_query(query, to_dict=True):
|
||||||
|
results = query.all()
|
||||||
|
if not results:
|
||||||
|
return []
|
||||||
|
return results if not to_dict else [r.to_dict() for r in results]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_departments_and_ids(department_parent_id, block):
|
def get_departments_and_ids(department_parent_id, block):
|
||||||
query = Department.query.filter(
|
query = Department.query.filter(
|
||||||
|
|
|
@ -18,6 +18,18 @@ from api.lib.common_setting.const import COMMON_SETTING_QUEUE, OperatorType
|
||||||
from api.lib.common_setting.resp_format import ErrFormat
|
from api.lib.common_setting.resp_format import ErrFormat
|
||||||
from api.models.common_setting import Employee, Department
|
from api.models.common_setting import Employee, Department
|
||||||
|
|
||||||
|
acl_user_columns = [
|
||||||
|
'email',
|
||||||
|
'mobile',
|
||||||
|
'nickname',
|
||||||
|
'username',
|
||||||
|
'password',
|
||||||
|
'block',
|
||||||
|
'avatar',
|
||||||
|
]
|
||||||
|
employee_pop_columns = ['password']
|
||||||
|
can_not_edit_columns = ['email']
|
||||||
|
|
||||||
|
|
||||||
def edit_acl_user(uid, **kwargs):
|
def edit_acl_user(uid, **kwargs):
|
||||||
user_data = {column: kwargs.get(
|
user_data = {column: kwargs.get(
|
||||||
|
@ -68,9 +80,6 @@ class EmployeeCRUD(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_employee_by_uid_with_create(_uid):
|
def get_employee_by_uid_with_create(_uid):
|
||||||
"""
|
|
||||||
根据 uid 获取员工信息,不存在则创建
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
return EmployeeCRUD.get_employee_by_uid(_uid).to_dict()
|
return EmployeeCRUD.get_employee_by_uid(_uid).to_dict()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -100,7 +109,6 @@ class EmployeeCRUD(object):
|
||||||
acl_uid=user_info['uid'],
|
acl_uid=user_info['uid'],
|
||||||
)
|
)
|
||||||
return existed.to_dict()
|
return existed.to_dict()
|
||||||
# 创建员工
|
|
||||||
if not user_info.get('nickname', None):
|
if not user_info.get('nickname', None):
|
||||||
user_info['nickname'] = user_info['name']
|
user_info['nickname'] = user_info['name']
|
||||||
|
|
||||||
|
@ -143,9 +151,6 @@ class EmployeeCRUD(object):
|
||||||
|
|
||||||
if len(e_list) > 0:
|
if len(e_list) > 0:
|
||||||
from api.tasks.common_setting import edit_employee_department_in_acl
|
from api.tasks.common_setting import edit_employee_department_in_acl
|
||||||
# fixme: comment next line
|
|
||||||
# edit_employee_department_in_acl(e_list, new_department_id, current_user.uid)
|
|
||||||
|
|
||||||
edit_employee_department_in_acl.apply_async(
|
edit_employee_department_in_acl.apply_async(
|
||||||
args=(e_list, new_department_id, current_user.uid),
|
args=(e_list, new_department_id, current_user.uid),
|
||||||
queue=COMMON_SETTING_QUEUE
|
queue=COMMON_SETTING_QUEUE
|
||||||
|
@ -218,8 +223,6 @@ class EmployeeCRUD(object):
|
||||||
else:
|
else:
|
||||||
employees = Employee.get_by(to_dict=False)
|
employees = Employee.get_by(to_dict=False)
|
||||||
|
|
||||||
keep_cols = EmployeeCRUD.get_current_user_view_columns()
|
|
||||||
|
|
||||||
all_departments = Department.get_by(to_dict=False)
|
all_departments = Department.get_by(to_dict=False)
|
||||||
d_id_map = {d.department_id: d.department_name for d in all_departments}
|
d_id_map = {d.department_id: d.department_name for d in all_departments}
|
||||||
e_id_map = {e.employee_id: e.nickname for e in employees}
|
e_id_map = {e.employee_id: e.nickname for e in employees}
|
||||||
|
@ -249,8 +252,7 @@ class EmployeeCRUD(object):
|
||||||
data['department_name'] = department_name
|
data['department_name'] = department_name
|
||||||
data['nickname_direct_supervisor'] = nickname_direct_supervisor
|
data['nickname_direct_supervisor'] = nickname_direct_supervisor
|
||||||
|
|
||||||
tmp = {export_columns_map[k]: data[k] for k in export_columns_map.keys() if
|
tmp = {export_columns_map[k]: data[k] for k in export_columns_map.keys()}
|
||||||
k in keep_cols or k in sub_columns}
|
|
||||||
|
|
||||||
data_list.append(tmp)
|
data_list.append(tmp)
|
||||||
|
|
||||||
|
@ -355,7 +357,6 @@ class EmployeeCRUD(object):
|
||||||
existed = EmployeeCRUD.get_employee_by_id(_id)
|
existed = EmployeeCRUD.get_employee_by_id(_id)
|
||||||
value = get_block_value(kwargs.get('block'))
|
value = get_block_value(kwargs.get('block'))
|
||||||
if value is True:
|
if value is True:
|
||||||
# 判断该用户是否为 部门负责人,或者员工的直接上级
|
|
||||||
check_department_director_id_or_direct_supervisor_id(_id)
|
check_department_director_id_or_direct_supervisor_id(_id)
|
||||||
|
|
||||||
if is_acl:
|
if is_acl:
|
||||||
|
@ -449,7 +450,7 @@ class EmployeeCRUD(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_expr_by_condition(column, operator, value, relation):
|
def get_expr_by_condition(column, operator, value, relation):
|
||||||
"""
|
"""
|
||||||
根据conditions返回expr: (and_list, or_list)
|
get expr: (and_list, or_list)
|
||||||
"""
|
"""
|
||||||
attr = EmployeeCRUD.get_attr_by_column(column)
|
attr = EmployeeCRUD.get_attr_by_column(column)
|
||||||
# 根据operator生成条件表达式
|
# 根据operator生成条件表达式
|
||||||
|
@ -483,7 +484,6 @@ class EmployeeCRUD(object):
|
||||||
else:
|
else:
|
||||||
abort(400, ErrFormat.not_support_operator.format(operator))
|
abort(400, ErrFormat.not_support_operator.format(operator))
|
||||||
|
|
||||||
# 根据relation生成复合条件
|
|
||||||
if relation == "&":
|
if relation == "&":
|
||||||
return expr, []
|
return expr, []
|
||||||
elif relation == "|":
|
elif relation == "|":
|
||||||
|
@ -493,7 +493,6 @@ class EmployeeCRUD(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_condition(column, operator, value, relation):
|
def check_condition(column, operator, value, relation):
|
||||||
# 对于condition中column为空的,报错
|
|
||||||
if column is None or operator is None or relation is None:
|
if column is None or operator is None or relation is None:
|
||||||
return abort(400, ErrFormat.conditions_field_missing)
|
return abort(400, ErrFormat.conditions_field_missing)
|
||||||
|
|
||||||
|
@ -642,19 +641,6 @@ def get_user_map(key='uid', acl=None):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
acl_user_columns = [
|
|
||||||
'email',
|
|
||||||
'mobile',
|
|
||||||
'nickname',
|
|
||||||
'username',
|
|
||||||
'password',
|
|
||||||
'block',
|
|
||||||
'avatar',
|
|
||||||
]
|
|
||||||
employee_pop_columns = ['password']
|
|
||||||
can_not_edit_columns = ['email']
|
|
||||||
|
|
||||||
|
|
||||||
def format_params(params):
|
def format_params(params):
|
||||||
for k in ['_key', '_secret']:
|
for k in ['_key', '_secret']:
|
||||||
params.pop(k, None)
|
params.pop(k, None)
|
||||||
|
@ -664,19 +650,22 @@ def format_params(params):
|
||||||
class CreateEmployee(object):
|
class CreateEmployee(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.acl = ACLManager()
|
self.acl = ACLManager()
|
||||||
self.useremail_map = {}
|
self.all_acl_users = self.acl.get_all_users()
|
||||||
|
|
||||||
def check_acl_user(self, email):
|
def check_acl_user(self, user_data):
|
||||||
user_info = self.useremail_map.get(email, None)
|
target_email = list(filter(lambda x: x['email'] == user_data['email'], self.all_acl_users))
|
||||||
if user_info:
|
if target_email:
|
||||||
return user_info
|
return target_email[0]
|
||||||
return None
|
|
||||||
|
target_username = list(filter(lambda x: x['username'] == user_data['username'], self.all_acl_users))
|
||||||
|
if target_username:
|
||||||
|
return target_username[0]
|
||||||
|
|
||||||
def add_acl_user(self, **kwargs):
|
def add_acl_user(self, **kwargs):
|
||||||
user_data = {column: kwargs.get(
|
user_data = {column: kwargs.get(
|
||||||
column, '') for column in acl_user_columns if kwargs.get(column, '')}
|
column, '') for column in acl_user_columns if kwargs.get(column, '')}
|
||||||
try:
|
try:
|
||||||
existed = self.check_acl_user(user_data['email'])
|
existed = self.check_acl_user(user_data)
|
||||||
if not existed:
|
if not existed:
|
||||||
return self.acl.create_user(user_data)
|
return self.acl.create_user(user_data)
|
||||||
return existed
|
return existed
|
||||||
|
@ -685,8 +674,6 @@ class CreateEmployee(object):
|
||||||
|
|
||||||
def create_single(self, **kwargs):
|
def create_single(self, **kwargs):
|
||||||
EmployeeCRUD.check_email_unique(kwargs['email'])
|
EmployeeCRUD.check_email_unique(kwargs['email'])
|
||||||
self.useremail_map = self.useremail_map if self.useremail_map else get_user_map(
|
|
||||||
'email', self.acl)
|
|
||||||
user = self.add_acl_user(**kwargs)
|
user = self.add_acl_user(**kwargs)
|
||||||
kwargs['acl_uid'] = user['uid']
|
kwargs['acl_uid'] = user['uid']
|
||||||
kwargs['last_login'] = user['last_login']
|
kwargs['last_login'] = user['last_login']
|
||||||
|
@ -699,8 +686,6 @@ class CreateEmployee(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_single_with_import(self, **kwargs):
|
def create_single_with_import(self, **kwargs):
|
||||||
self.useremail_map = self.useremail_map if self.useremail_map else get_user_map(
|
|
||||||
'email', self.acl)
|
|
||||||
user = self.add_acl_user(**kwargs)
|
user = self.add_acl_user(**kwargs)
|
||||||
kwargs['acl_uid'] = user['uid']
|
kwargs['acl_uid'] = user['uid']
|
||||||
kwargs['last_login'] = user['last_login']
|
kwargs['last_login'] = user['last_login']
|
||||||
|
@ -743,9 +728,6 @@ class CreateEmployee(object):
|
||||||
return end_d_id
|
return end_d_id
|
||||||
|
|
||||||
def format_department_id(self, employee):
|
def format_department_id(self, employee):
|
||||||
"""
|
|
||||||
部门名称转化为ID,不存在则创建
|
|
||||||
"""
|
|
||||||
department_name_map = {}
|
department_name_map = {}
|
||||||
try:
|
try:
|
||||||
department_name = employee.get('department_name', '')
|
department_name = employee.get('department_name', '')
|
||||||
|
@ -762,16 +744,13 @@ class CreateEmployee(object):
|
||||||
|
|
||||||
def batch_create(self, employee_list):
|
def batch_create(self, employee_list):
|
||||||
err_list = []
|
err_list = []
|
||||||
self.useremail_map = get_user_map('email', self.acl)
|
|
||||||
|
|
||||||
for employee in employee_list:
|
for employee in employee_list:
|
||||||
try:
|
try:
|
||||||
# 获取username
|
|
||||||
username = employee.get('username', None)
|
username = employee.get('username', None)
|
||||||
if username is None:
|
if username is None:
|
||||||
employee['username'] = employee['email']
|
employee['username'] = employee['email']
|
||||||
|
|
||||||
# 校验通过后获取department_id
|
|
||||||
employee = self.format_department_id(employee)
|
employee = self.format_department_id(employee)
|
||||||
err = employee.get('err', None)
|
err = employee.get('err', None)
|
||||||
if err:
|
if err:
|
||||||
|
@ -783,7 +762,7 @@ class CreateEmployee(object):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
','.join(['{}: {}'.format(filed, ','.join(msg)) for filed, msg in form.errors.items()]))
|
','.join(['{}: {}'.format(filed, ','.join(msg)) for filed, msg in form.errors.items()]))
|
||||||
|
|
||||||
data = self.create_single_with_import(**form.data)
|
self.create_single_with_import(**form.data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err_list.append({
|
err_list.append({
|
||||||
'email': employee.get('email', ''),
|
'email': employee.get('email', ''),
|
||||||
|
@ -797,12 +776,12 @@ class CreateEmployee(object):
|
||||||
|
|
||||||
class EmployeeAddForm(Form):
|
class EmployeeAddForm(Form):
|
||||||
username = StringField(validators=[
|
username = StringField(validators=[
|
||||||
validators.DataRequired(message="username不能为空"),
|
validators.DataRequired(message=ErrFormat.username_is_required),
|
||||||
validators.Length(max=255),
|
validators.Length(max=255),
|
||||||
])
|
])
|
||||||
email = StringField(validators=[
|
email = StringField(validators=[
|
||||||
validators.DataRequired(message="邮箱不能为空"),
|
validators.DataRequired(message=ErrFormat.email_is_required),
|
||||||
validators.Email(message="邮箱格式不正确"),
|
validators.Email(message=ErrFormat.email_format_error),
|
||||||
validators.Length(max=255),
|
validators.Length(max=255),
|
||||||
])
|
])
|
||||||
password = StringField(validators=[
|
password = StringField(validators=[
|
||||||
|
@ -811,7 +790,7 @@ class EmployeeAddForm(Form):
|
||||||
position_name = StringField(validators=[])
|
position_name = StringField(validators=[])
|
||||||
|
|
||||||
nickname = StringField(validators=[
|
nickname = StringField(validators=[
|
||||||
validators.DataRequired(message="用户名不能为空"),
|
validators.DataRequired(message=ErrFormat.nickname_is_required),
|
||||||
validators.Length(max=255),
|
validators.Length(max=255),
|
||||||
])
|
])
|
||||||
sex = StringField(validators=[])
|
sex = StringField(validators=[])
|
||||||
|
@ -822,7 +801,7 @@ class EmployeeAddForm(Form):
|
||||||
|
|
||||||
class EmployeeUpdateByUidForm(Form):
|
class EmployeeUpdateByUidForm(Form):
|
||||||
nickname = StringField(validators=[
|
nickname = StringField(validators=[
|
||||||
validators.DataRequired(message="用户名不能为空"),
|
validators.DataRequired(message=ErrFormat.nickname_is_required),
|
||||||
validators.Length(max=255),
|
validators.Length(max=255),
|
||||||
])
|
])
|
||||||
avatar = StringField(validators=[])
|
avatar = StringField(validators=[])
|
||||||
|
|
|
@ -49,3 +49,8 @@ class ErrFormat(CommonErrFormat):
|
||||||
acl_add_user_to_role_failed = "ACL 添加用户到角色失败: {}"
|
acl_add_user_to_role_failed = "ACL 添加用户到角色失败: {}"
|
||||||
acl_import_user_failed = "ACL 导入用户[{}]失败: {}"
|
acl_import_user_failed = "ACL 导入用户[{}]失败: {}"
|
||||||
|
|
||||||
|
nickname_is_required = "用户名不能为空"
|
||||||
|
username_is_required = "username不能为空"
|
||||||
|
email_is_required = "邮箱不能为空"
|
||||||
|
email_format_error = "邮箱格式错误"
|
||||||
|
|
||||||
|
|
|
@ -13,40 +13,39 @@ class Department(ModelWithoutPK):
|
||||||
__tablename__ = 'common_department'
|
__tablename__ = 'common_department'
|
||||||
department_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
department_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
|
||||||
department_name = db.Column(db.VARCHAR(255), default='', comment='部门名称')
|
department_name = db.Column(db.VARCHAR(255), default='')
|
||||||
department_director_id = db.Column(
|
department_director_id = db.Column(
|
||||||
db.Integer, default=0, comment='部门负责人ID')
|
db.Integer, default=0)
|
||||||
department_parent_id = db.Column(db.Integer, default=1, comment='上级部门ID')
|
department_parent_id = db.Column(db.Integer, default=1)
|
||||||
|
|
||||||
sort_value = db.Column(db.Integer, default=0, comment='排序值')
|
sort_value = db.Column(db.Integer, default=0)
|
||||||
|
|
||||||
acl_rid = db.Column(db.Integer, comment='ACL中rid', default=0)
|
acl_rid = db.Column(db.Integer, default=0)
|
||||||
|
|
||||||
|
|
||||||
class Employee(ModelWithoutPK):
|
class Employee(ModelWithoutPK):
|
||||||
__tablename__ = 'common_employee'
|
__tablename__ = 'common_employee'
|
||||||
employee_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
employee_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
|
||||||
email = db.Column(db.VARCHAR(255), default='', comment='邮箱')
|
email = db.Column(db.VARCHAR(255), default='')
|
||||||
username = db.Column(db.VARCHAR(255), default='', comment='用户名')
|
username = db.Column(db.VARCHAR(255), default='')
|
||||||
nickname = db.Column(db.VARCHAR(255), default='', comment='姓名')
|
nickname = db.Column(db.VARCHAR(255), default='')
|
||||||
sex = db.Column(db.VARCHAR(64), default='', comment='性别')
|
sex = db.Column(db.VARCHAR(64), default='')
|
||||||
position_name = db.Column(db.VARCHAR(255), default='', comment='职位名称')
|
position_name = db.Column(db.VARCHAR(255), default='')
|
||||||
mobile = db.Column(db.VARCHAR(255), default='', comment='电话号码')
|
mobile = db.Column(db.VARCHAR(255), default='')
|
||||||
avatar = db.Column(db.VARCHAR(255), default='', comment='头像')
|
avatar = db.Column(db.VARCHAR(255), default='')
|
||||||
|
|
||||||
direct_supervisor_id = db.Column(db.Integer, default=0, comment='直接上级ID')
|
direct_supervisor_id = db.Column(db.Integer, default=0)
|
||||||
|
|
||||||
department_id = db.Column(db.Integer,
|
department_id = db.Column(db.Integer,
|
||||||
db.ForeignKey('common_department.department_id'),
|
db.ForeignKey('common_department.department_id')
|
||||||
comment='部门ID',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
acl_uid = db.Column(db.Integer, comment='ACL中uid', default=0)
|
acl_uid = db.Column(db.Integer, default=0)
|
||||||
acl_rid = db.Column(db.Integer, comment='ACL中rid', default=0)
|
acl_rid = db.Column(db.Integer, default=0)
|
||||||
acl_virtual_rid = db.Column(db.Integer, comment='ACL中虚拟角色rid', default=0)
|
acl_virtual_rid = db.Column(db.Integer, default=0)
|
||||||
last_login = db.Column(db.TIMESTAMP, nullable=True, comment='上次登录时间')
|
last_login = db.Column(db.TIMESTAMP, nullable=True)
|
||||||
block = db.Column(db.Integer, comment='锁定状态', default=0)
|
block = db.Column(db.Integer, default=0)
|
||||||
|
|
||||||
_department = db.relationship(
|
_department = db.relationship(
|
||||||
'Department', backref='common_employee.department_id',
|
'Department', backref='common_employee.department_id',
|
||||||
|
@ -55,14 +54,11 @@ class Employee(ModelWithoutPK):
|
||||||
|
|
||||||
|
|
||||||
class EmployeeInfo(Model):
|
class EmployeeInfo(Model):
|
||||||
"""
|
|
||||||
员工信息
|
|
||||||
"""
|
|
||||||
__tablename__ = 'common_employee_info'
|
__tablename__ = 'common_employee_info'
|
||||||
|
|
||||||
info = db.Column(db.JSON, default={}, comment='员工信息')
|
info = db.Column(db.JSON, default={})
|
||||||
employee_id = db.Column(db.Integer, db.ForeignKey(
|
employee_id = db.Column(db.Integer, db.ForeignKey(
|
||||||
'common_employee.employee_id'), comment='员工ID')
|
'common_employee.employee_id'))
|
||||||
employee = db.relationship(
|
employee = db.relationship(
|
||||||
'Employee', backref='common_employee.employee_id', lazy='joined')
|
'Employee', backref='common_employee.employee_id', lazy='joined')
|
||||||
|
|
||||||
|
@ -74,16 +70,13 @@ class CompanyInfo(Model):
|
||||||
|
|
||||||
|
|
||||||
class InternalMessage(Model):
|
class InternalMessage(Model):
|
||||||
"""
|
|
||||||
内部消息
|
|
||||||
"""
|
|
||||||
__tablename__ = "common_internal_message"
|
__tablename__ = "common_internal_message"
|
||||||
|
|
||||||
title = db.Column(db.VARCHAR(255), nullable=True, comment='标题')
|
title = db.Column(db.VARCHAR(255), nullable=True)
|
||||||
content = db.Column(db.TEXT, nullable=True, comment='内容')
|
content = db.Column(db.TEXT, nullable=True)
|
||||||
path = db.Column(db.VARCHAR(255), nullable=True, comment='跳转路径')
|
path = db.Column(db.VARCHAR(255), nullable=True)
|
||||||
is_read = db.Column(db.Boolean, default=False, comment='是否已读')
|
is_read = db.Column(db.Boolean, default=False)
|
||||||
app_name = db.Column(db.VARCHAR(128), nullable=False, comment='应用名称')
|
app_name = db.Column(db.VARCHAR(128), nullable=False)
|
||||||
category = db.Column(db.VARCHAR(128), nullable=False, comment='分类')
|
category = db.Column(db.VARCHAR(128), nullable=False)
|
||||||
message_data = db.Column(db.JSON, nullable=True, comment='数据')
|
message_data = db.Column(db.JSON, nullable=True)
|
||||||
employee_id = db.Column(db.Integer, db.ForeignKey('common_employee.employee_id'), comment='ID')
|
employee_id = db.Column(db.Integer, db.ForeignKey('common_employee.employee_id'), comment='ID')
|
||||||
|
|
|
@ -13,13 +13,9 @@ from api.models.common_setting import Department
|
||||||
@celery.task(name="common_setting.edit_employee_department_in_acl", queue=COMMON_SETTING_QUEUE)
|
@celery.task(name="common_setting.edit_employee_department_in_acl", queue=COMMON_SETTING_QUEUE)
|
||||||
def edit_employee_department_in_acl(e_list, new_d_id, op_uid):
|
def edit_employee_department_in_acl(e_list, new_d_id, op_uid):
|
||||||
"""
|
"""
|
||||||
在 ACL 员工更换部门
|
:param e_list:{acl_rid: 11, department_id: 22}
|
||||||
:param e_list: 员工列表 {acl_rid: 11, department_id: 22}
|
:param new_d_id
|
||||||
:param new_d_id: 新部门 ID
|
:param op_uid
|
||||||
:param op_uid: 操作人 ID
|
|
||||||
|
|
||||||
在老部门中删除员工
|
|
||||||
在新部门中添加员工
|
|
||||||
"""
|
"""
|
||||||
db.session.remove()
|
db.session.remove()
|
||||||
|
|
||||||
|
@ -43,7 +39,6 @@ def edit_employee_department_in_acl(e_list, new_d_id, op_uid):
|
||||||
new_department_acl_rid = new_department.acl_rid if new_d_rid_in_acl == new_department.acl_rid else new_d_rid_in_acl
|
new_department_acl_rid = new_department.acl_rid if new_d_rid_in_acl == new_department.acl_rid else new_d_rid_in_acl
|
||||||
|
|
||||||
for employee in e_list:
|
for employee in e_list:
|
||||||
# 根据 部门ID获取部门 acl_rid
|
|
||||||
old_department = Department.get_by(
|
old_department = Department.get_by(
|
||||||
first=True, department_id=employee.get('department_id'), to_dict=False)
|
first=True, department_id=employee.get('department_id'), to_dict=False)
|
||||||
if not old_department:
|
if not old_department:
|
||||||
|
@ -61,7 +56,6 @@ def edit_employee_department_in_acl(e_list, new_d_id, op_uid):
|
||||||
acl_rid=old_d_rid_in_acl
|
acl_rid=old_d_rid_in_acl
|
||||||
)
|
)
|
||||||
d_acl_rid = old_department.acl_rid if old_d_rid_in_acl == old_department.acl_rid else old_d_rid_in_acl
|
d_acl_rid = old_department.acl_rid if old_d_rid_in_acl == old_department.acl_rid else old_d_rid_in_acl
|
||||||
# 在老部门中删除员工
|
|
||||||
payload = {
|
payload = {
|
||||||
'app_id': 'acl',
|
'app_id': 'acl',
|
||||||
'parent_id': d_acl_rid,
|
'parent_id': d_acl_rid,
|
||||||
|
@ -71,7 +65,6 @@ def edit_employee_department_in_acl(e_list, new_d_id, op_uid):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result.append(ErrFormat.acl_remove_user_from_role_failed.format(str(e)))
|
result.append(ErrFormat.acl_remove_user_from_role_failed.format(str(e)))
|
||||||
|
|
||||||
# 在新部门中添加员工
|
|
||||||
payload = {
|
payload = {
|
||||||
'app_id': 'acl',
|
'app_id': 'acl',
|
||||||
'child_ids': [employee_acl_rid],
|
'child_ids': [employee_acl_rid],
|
||||||
|
|
|
@ -100,7 +100,7 @@ class DepartmentSortView(APIView):
|
||||||
|
|
||||||
def put(self):
|
def put(self):
|
||||||
"""
|
"""
|
||||||
修改部门排序,只能在同一个上级内排序
|
only can sort in the same parent
|
||||||
"""
|
"""
|
||||||
department_list = request.json.get('department_list', None)
|
department_list = request.json.get('department_list', None)
|
||||||
if department_list is None:
|
if department_list is None:
|
||||||
|
|
|
@ -150,12 +150,10 @@ class EmployeeViewExportExcel(APIView):
|
||||||
url_prefix = (f'{prefix}/export_all',)
|
url_prefix = (f'{prefix}/export_all',)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
# 规定了静态文件的存储位置
|
|
||||||
excel_filename = 'all_employee_info.xlsx'
|
excel_filename = 'all_employee_info.xlsx'
|
||||||
excel_path = current_app.config['UPLOAD_DIRECTORY_FULL']
|
excel_path = current_app.config['UPLOAD_DIRECTORY_FULL']
|
||||||
excel_path_with_filename = os.path.join(excel_path, excel_filename)
|
excel_path_with_filename = os.path.join(excel_path, excel_filename)
|
||||||
|
|
||||||
# 根据parameter查表,自连接通过上级id获取上级名字列
|
|
||||||
block_status = int(request.args.get('block_status', -1))
|
block_status = int(request.args.get('block_status', -1))
|
||||||
data_list = EmployeeCRUD.get_export_employee_list(block_status)
|
data_list = EmployeeCRUD.get_export_employee_list(block_status)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue