|
@@ -1839,6 +1839,736 @@ def get_business_card(card_id):
|
|
error_msg = f"获取名片记录失败: {str(e)}"
|
|
error_msg = f"获取名片记录失败: {str(e)}"
|
|
logging.error(error_msg, exc_info=True)
|
|
logging.error(error_msg, exc_info=True)
|
|
|
|
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+# 酒店职位数据模型
|
|
|
|
+class HotelPosition(db.Model):
|
|
|
|
+ __tablename__ = 'hotel_positions'
|
|
|
|
+
|
|
|
|
+ id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
|
|
|
+ department_zh = db.Column(db.String(10), nullable=False)
|
|
|
|
+ department_en = db.Column(db.String(50), nullable=False)
|
|
|
|
+ position_zh = db.Column(db.String(20), nullable=False)
|
|
|
|
+ position_en = db.Column(db.String(100), nullable=False)
|
|
|
|
+ position_abbr = db.Column(db.String(20), nullable=True)
|
|
|
|
+ level_zh = db.Column(db.String(10), nullable=False)
|
|
|
|
+ level_en = db.Column(db.String(30), nullable=False)
|
|
|
|
+ created_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
|
|
|
|
+ updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
|
|
|
|
+ created_by = db.Column(db.String(50), default='system')
|
|
|
|
+ updated_by = db.Column(db.String(50), default='system')
|
|
|
|
+ status = db.Column(db.String(20), default='active')
|
|
|
|
+
|
|
|
|
+ def to_dict(self):
|
|
|
|
+ return {
|
|
|
|
+ 'id': self.id,
|
|
|
|
+ 'department_zh': self.department_zh,
|
|
|
|
+ 'department_en': self.department_en,
|
|
|
|
+ 'position_zh': self.position_zh,
|
|
|
|
+ 'position_en': self.position_en,
|
|
|
|
+ 'position_abbr': self.position_abbr,
|
|
|
|
+ 'level_zh': self.level_zh,
|
|
|
|
+ 'level_en': self.level_en,
|
|
|
|
+ 'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
|
|
|
|
+ 'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None,
|
|
|
|
+ 'created_by': self.created_by,
|
|
|
|
+ 'updated_by': self.updated_by,
|
|
|
|
+ 'status': self.status
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def get_hotel_positions_list():
|
|
|
|
+ """
|
|
|
|
+ 获取酒店职位数据表的全部记录
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和酒店职位列表的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 查询所有酒店职位记录,按部门和职位排序
|
|
|
|
+ positions = HotelPosition.query.order_by(
|
|
|
|
+ HotelPosition.department_zh,
|
|
|
|
+ HotelPosition.position_zh
|
|
|
|
+ ).all()
|
|
|
|
+
|
|
|
|
+ # 将所有记录转换为字典格式
|
|
|
|
+ positions_data = [position.to_dict() for position in positions]
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '获取酒店职位列表成功',
|
|
|
|
+ 'data': positions_data,
|
|
|
|
+ 'count': len(positions_data)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ error_msg = f"获取酒店职位列表失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': [],
|
|
|
|
+ 'count': 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def add_hotel_positions(position_data):
|
|
|
|
+ """
|
|
|
|
+ 新增酒店职位数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ position_data (dict): 包含职位信息的字典,包括:
|
|
|
|
+ - department_zh: 部门中文名称 (必填)
|
|
|
|
+ - department_en: 部门英文名称 (必填)
|
|
|
|
+ - position_zh: 职位中文名称 (必填)
|
|
|
|
+ - position_en: 职位英文名称 (必填)
|
|
|
|
+ - position_abbr: 职位英文缩写 (可选)
|
|
|
|
+ - level_zh: 职级中文名称 (必填)
|
|
|
|
+ - level_en: 职级英文名称 (必填)
|
|
|
|
+ - created_by: 创建者 (可选,默认为'system')
|
|
|
|
+ - updated_by: 更新者 (可选,默认为'system')
|
|
|
|
+ - status: 状态 (可选,默认为'active')
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和创建的职位信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 验证必填字段
|
|
|
|
+ required_fields = ['department_zh', 'department_en', 'position_zh', 'position_en', 'level_zh', 'level_en']
|
|
|
|
+ missing_fields = []
|
|
|
|
+
|
|
|
|
+ for field in required_fields:
|
|
|
|
+ if field not in position_data or not position_data[field] or not position_data[field].strip():
|
|
|
|
+ missing_fields.append(field)
|
|
|
|
+
|
|
|
|
+ if missing_fields:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 400,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'缺少必填字段: {", ".join(missing_fields)}',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 检查是否已存在相同的职位记录(基于部门和职位的中文名称)
|
|
|
|
+ existing_position = HotelPosition.query.filter_by(
|
|
|
|
+ department_zh=position_data['department_zh'].strip(),
|
|
|
|
+ position_zh=position_data['position_zh'].strip()
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
|
|
+ if existing_position:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 409,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'职位记录已存在:{position_data["department_zh"]} - {position_data["position_zh"]}',
|
|
|
|
+ 'data': existing_position.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 创建新的职位记录
|
|
|
|
+ new_position = HotelPosition(
|
|
|
|
+ department_zh=position_data['department_zh'].strip(),
|
|
|
|
+ department_en=position_data['department_en'].strip(),
|
|
|
|
+ position_zh=position_data['position_zh'].strip(),
|
|
|
|
+ position_en=position_data['position_en'].strip(),
|
|
|
|
+ position_abbr=position_data.get('position_abbr', '').strip() if position_data.get('position_abbr') else None,
|
|
|
|
+ level_zh=position_data['level_zh'].strip(),
|
|
|
|
+ level_en=position_data['level_en'].strip(),
|
|
|
|
+ created_by=position_data.get('created_by', 'system'),
|
|
|
|
+ updated_by=position_data.get('updated_by', 'system'),
|
|
|
|
+ status=position_data.get('status', 'active')
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ # 保存到数据库
|
|
|
|
+ db.session.add(new_position)
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功创建酒店职位记录,ID: {new_position.id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '酒店职位记录创建成功',
|
|
|
|
+ 'data': new_position.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"创建酒店职位记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def update_hotel_positions(position_id, position_data):
|
|
|
|
+ """
|
|
|
|
+ 修改酒店职位数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ position_id (int): 职位记录ID
|
|
|
|
+ position_data (dict): 包含要更新的职位信息的字典,可能包括:
|
|
|
|
+ - department_zh: 部门中文名称
|
|
|
|
+ - department_en: 部门英文名称
|
|
|
|
+ - position_zh: 职位中文名称
|
|
|
|
+ - position_en: 职位英文名称
|
|
|
|
+ - position_abbr: 职位英文缩写
|
|
|
|
+ - level_zh: 职级中文名称
|
|
|
|
+ - level_en: 职级英文名称
|
|
|
|
+ - updated_by: 更新者
|
|
|
|
+ - status: 状态
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和更新后的职位信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 查找要更新的职位记录
|
|
|
|
+ position = HotelPosition.query.get(position_id)
|
|
|
|
+
|
|
|
|
+ if not position:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{position_id}的职位记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 检查是否有数据需要更新
|
|
|
|
+ if not position_data:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 400,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': '请求数据为空',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 如果要更新部门和职位名称,检查是否会与其他记录冲突
|
|
|
|
+ new_department_zh = position_data.get('department_zh', position.department_zh).strip() if position_data.get('department_zh') else position.department_zh
|
|
|
|
+ new_position_zh = position_data.get('position_zh', position.position_zh).strip() if position_data.get('position_zh') else position.position_zh
|
|
|
|
+
|
|
|
|
+ # 查找是否存在相同的职位记录(排除当前记录)
|
|
|
|
+ existing_position = HotelPosition.query.filter(
|
|
|
|
+ HotelPosition.id != position_id,
|
|
|
|
+ HotelPosition.department_zh == new_department_zh,
|
|
|
|
+ HotelPosition.position_zh == new_position_zh
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
|
|
+ if existing_position:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 409,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'职位记录已存在:{new_department_zh} - {new_position_zh}',
|
|
|
|
+ 'data': existing_position.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 更新职位信息
|
|
|
|
+ if 'department_zh' in position_data and position_data['department_zh']:
|
|
|
|
+ position.department_zh = position_data['department_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'department_en' in position_data and position_data['department_en']:
|
|
|
|
+ position.department_en = position_data['department_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'position_zh' in position_data and position_data['position_zh']:
|
|
|
|
+ position.position_zh = position_data['position_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'position_en' in position_data and position_data['position_en']:
|
|
|
|
+ position.position_en = position_data['position_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'position_abbr' in position_data:
|
|
|
|
+ # 处理position_abbr,可能为空字符串或None
|
|
|
|
+ if position_data['position_abbr'] and position_data['position_abbr'].strip():
|
|
|
|
+ position.position_abbr = position_data['position_abbr'].strip()
|
|
|
|
+ else:
|
|
|
|
+ position.position_abbr = None
|
|
|
|
+
|
|
|
|
+ if 'level_zh' in position_data and position_data['level_zh']:
|
|
|
|
+ position.level_zh = position_data['level_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'level_en' in position_data and position_data['level_en']:
|
|
|
|
+ position.level_en = position_data['level_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'updated_by' in position_data:
|
|
|
|
+ position.updated_by = position_data['updated_by'] or 'system'
|
|
|
|
+
|
|
|
|
+ if 'status' in position_data:
|
|
|
|
+ position.status = position_data['status'] or 'active'
|
|
|
|
+
|
|
|
|
+ # 更新时间会自动设置(onupdate=datetime.now)
|
|
|
|
+
|
|
|
|
+ # 保存更新
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功更新酒店职位记录,ID: {position.id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '酒店职位记录更新成功',
|
|
|
|
+ 'data': position.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"更新酒店职位记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def query_hotel_positions(position_id):
|
|
|
|
+ """
|
|
|
|
+ 查找指定ID的酒店职位数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ position_id (int): 职位记录ID
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和职位信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 根据ID查找职位记录
|
|
|
|
+ position = HotelPosition.query.get(position_id)
|
|
|
|
+
|
|
|
|
+ if not position:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{position_id}的职位记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 返回找到的记录
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '查找职位记录成功',
|
|
|
|
+ 'data': position.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ error_msg = f"查找职位记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def delete_hotel_positions(position_id):
|
|
|
|
+ """
|
|
|
|
+ 删除指定ID的酒店职位数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ position_id (int): 职位记录ID
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 根据ID查找要删除的职位记录
|
|
|
|
+ position = HotelPosition.query.get(position_id)
|
|
|
|
+
|
|
|
|
+ if not position:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{position_id}的职位记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 保存被删除记录的信息,用于返回
|
|
|
|
+ deleted_position_info = position.to_dict()
|
|
|
|
+
|
|
|
|
+ # 执行删除操作
|
|
|
|
+ db.session.delete(position)
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功删除酒店职位记录,ID: {position_id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '职位记录删除成功',
|
|
|
|
+ 'data': deleted_position_info
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"删除职位记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+# 酒店集团子品牌数据模型
|
|
|
|
+class HotelGroupBrands(db.Model):
|
|
|
|
+ __tablename__ = 'hotel_group_brands'
|
|
|
|
+
|
|
|
|
+ id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
|
|
|
+ group_name_en = db.Column(db.String(60), nullable=False)
|
|
|
|
+ group_name_zh = db.Column(db.String(20), nullable=False)
|
|
|
|
+ brand_name_en = db.Column(db.String(40), nullable=False)
|
|
|
|
+ brand_name_zh = db.Column(db.String(40), nullable=False)
|
|
|
|
+ positioning_level_en = db.Column(db.String(20), nullable=False)
|
|
|
|
+ positioning_level_zh = db.Column(db.String(5), nullable=False)
|
|
|
|
+ created_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
|
|
|
|
+ updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
|
|
|
|
+ created_by = db.Column(db.String(50), default='system')
|
|
|
|
+ updated_by = db.Column(db.String(50), default='system')
|
|
|
|
+ status = db.Column(db.String(20), default='active')
|
|
|
|
+
|
|
|
|
+ def to_dict(self):
|
|
|
|
+ return {
|
|
|
|
+ 'id': self.id,
|
|
|
|
+ 'group_name_en': self.group_name_en,
|
|
|
|
+ 'group_name_zh': self.group_name_zh,
|
|
|
|
+ 'brand_name_en': self.brand_name_en,
|
|
|
|
+ 'brand_name_zh': self.brand_name_zh,
|
|
|
|
+ 'positioning_level_en': self.positioning_level_en,
|
|
|
|
+ 'positioning_level_zh': self.positioning_level_zh,
|
|
|
|
+ 'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
|
|
|
|
+ 'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None,
|
|
|
|
+ 'created_by': self.created_by,
|
|
|
|
+ 'updated_by': self.updated_by,
|
|
|
|
+ 'status': self.status
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def get_hotel_group_brands_list():
|
|
|
|
+ """
|
|
|
|
+ 获取酒店集团子品牌数据表的全部记录
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和酒店集团品牌列表的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 查询所有酒店集团品牌记录,按集团和品牌排序
|
|
|
|
+ brands = HotelGroupBrands.query.order_by(
|
|
|
|
+ HotelGroupBrands.group_name_zh,
|
|
|
|
+ HotelGroupBrands.brand_name_zh
|
|
|
|
+ ).all()
|
|
|
|
+
|
|
|
|
+ # 将所有记录转换为字典格式
|
|
|
|
+ brands_data = [brand.to_dict() for brand in brands]
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '获取酒店集团品牌列表成功',
|
|
|
|
+ 'data': brands_data,
|
|
|
|
+ 'count': len(brands_data)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ error_msg = f"获取酒店集团品牌列表失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': [],
|
|
|
|
+ 'count': 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def add_hotel_group_brands(brand_data):
|
|
|
|
+ """
|
|
|
|
+ 新增酒店集团子品牌数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ brand_data (dict): 包含品牌信息的字典,包括:
|
|
|
|
+ - group_name_en: 集团英文名称 (必填)
|
|
|
|
+ - group_name_zh: 集团中文名称 (必填)
|
|
|
|
+ - brand_name_en: 品牌英文名称 (必填)
|
|
|
|
+ - brand_name_zh: 品牌中文名称 (必填)
|
|
|
|
+ - positioning_level_en: 定位级别英文名称 (必填)
|
|
|
|
+ - positioning_level_zh: 定位级别中文名称 (必填)
|
|
|
|
+ - created_by: 创建者 (可选,默认为'system')
|
|
|
|
+ - updated_by: 更新者 (可选,默认为'system')
|
|
|
|
+ - status: 状态 (可选,默认为'active')
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和创建的品牌信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 验证必填字段
|
|
|
|
+ required_fields = ['group_name_en', 'group_name_zh', 'brand_name_en', 'brand_name_zh', 'positioning_level_en', 'positioning_level_zh']
|
|
|
|
+ missing_fields = []
|
|
|
|
+
|
|
|
|
+ for field in required_fields:
|
|
|
|
+ if field not in brand_data or not brand_data[field] or not brand_data[field].strip():
|
|
|
|
+ missing_fields.append(field)
|
|
|
|
+
|
|
|
|
+ if missing_fields:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 400,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'缺少必填字段: {", ".join(missing_fields)}',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 检查是否已存在相同的品牌记录(基于集团和品牌的中文名称)
|
|
|
|
+ existing_brand = HotelGroupBrands.query.filter_by(
|
|
|
|
+ group_name_zh=brand_data['group_name_zh'].strip(),
|
|
|
|
+ brand_name_zh=brand_data['brand_name_zh'].strip()
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
|
|
+ if existing_brand:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 409,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'品牌记录已存在:{brand_data["group_name_zh"]} - {brand_data["brand_name_zh"]}',
|
|
|
|
+ 'data': existing_brand.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 创建新的品牌记录
|
|
|
|
+ new_brand = HotelGroupBrands(
|
|
|
|
+ group_name_en=brand_data['group_name_en'].strip(),
|
|
|
|
+ group_name_zh=brand_data['group_name_zh'].strip(),
|
|
|
|
+ brand_name_en=brand_data['brand_name_en'].strip(),
|
|
|
|
+ brand_name_zh=brand_data['brand_name_zh'].strip(),
|
|
|
|
+ positioning_level_en=brand_data['positioning_level_en'].strip(),
|
|
|
|
+ positioning_level_zh=brand_data['positioning_level_zh'].strip(),
|
|
|
|
+ created_by=brand_data.get('created_by', 'system'),
|
|
|
|
+ updated_by=brand_data.get('updated_by', 'system'),
|
|
|
|
+ status=brand_data.get('status', 'active')
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ # 保存到数据库
|
|
|
|
+ db.session.add(new_brand)
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功创建酒店集团品牌记录,ID: {new_brand.id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '酒店集团品牌记录创建成功',
|
|
|
|
+ 'data': new_brand.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"创建酒店集团品牌记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def update_hotel_group_brands(brand_id, brand_data):
|
|
|
|
+ """
|
|
|
|
+ 修改酒店集团子品牌数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ brand_id (int): 品牌记录ID
|
|
|
|
+ brand_data (dict): 包含要更新的品牌信息的字典,可能包括:
|
|
|
|
+ - group_name_en: 集团英文名称
|
|
|
|
+ - group_name_zh: 集团中文名称
|
|
|
|
+ - brand_name_en: 品牌英文名称
|
|
|
|
+ - brand_name_zh: 品牌中文名称
|
|
|
|
+ - positioning_level_en: 定位级别英文名称
|
|
|
|
+ - positioning_level_zh: 定位级别中文名称
|
|
|
|
+ - updated_by: 更新者
|
|
|
|
+ - status: 状态
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和更新后的品牌信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 查找要更新的品牌记录
|
|
|
|
+ brand = HotelGroupBrands.query.get(brand_id)
|
|
|
|
+
|
|
|
|
+ if not brand:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{brand_id}的品牌记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 检查是否有数据需要更新
|
|
|
|
+ if not brand_data:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 400,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': '请求数据为空',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 如果要更新集团和品牌名称,检查是否会与其他记录冲突
|
|
|
|
+ new_group_name_zh = brand_data.get('group_name_zh', brand.group_name_zh).strip() if brand_data.get('group_name_zh') else brand.group_name_zh
|
|
|
|
+ new_brand_name_zh = brand_data.get('brand_name_zh', brand.brand_name_zh).strip() if brand_data.get('brand_name_zh') else brand.brand_name_zh
|
|
|
|
+
|
|
|
|
+ # 查找是否存在相同的品牌记录(排除当前记录)
|
|
|
|
+ existing_brand = HotelGroupBrands.query.filter(
|
|
|
|
+ HotelGroupBrands.id != brand_id,
|
|
|
|
+ HotelGroupBrands.group_name_zh == new_group_name_zh,
|
|
|
|
+ HotelGroupBrands.brand_name_zh == new_brand_name_zh
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
|
|
+ if existing_brand:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 409,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'品牌记录已存在:{new_group_name_zh} - {new_brand_name_zh}',
|
|
|
|
+ 'data': existing_brand.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 更新品牌信息
|
|
|
|
+ if 'group_name_en' in brand_data and brand_data['group_name_en']:
|
|
|
|
+ brand.group_name_en = brand_data['group_name_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'group_name_zh' in brand_data and brand_data['group_name_zh']:
|
|
|
|
+ brand.group_name_zh = brand_data['group_name_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'brand_name_en' in brand_data and brand_data['brand_name_en']:
|
|
|
|
+ brand.brand_name_en = brand_data['brand_name_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'brand_name_zh' in brand_data and brand_data['brand_name_zh']:
|
|
|
|
+ brand.brand_name_zh = brand_data['brand_name_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'positioning_level_en' in brand_data and brand_data['positioning_level_en']:
|
|
|
|
+ brand.positioning_level_en = brand_data['positioning_level_en'].strip()
|
|
|
|
+
|
|
|
|
+ if 'positioning_level_zh' in brand_data and brand_data['positioning_level_zh']:
|
|
|
|
+ brand.positioning_level_zh = brand_data['positioning_level_zh'].strip()
|
|
|
|
+
|
|
|
|
+ if 'updated_by' in brand_data:
|
|
|
|
+ brand.updated_by = brand_data['updated_by'] or 'system'
|
|
|
|
+
|
|
|
|
+ if 'status' in brand_data:
|
|
|
|
+ brand.status = brand_data['status'] or 'active'
|
|
|
|
+
|
|
|
|
+ # 更新时间会自动设置(onupdate=datetime.now)
|
|
|
|
+
|
|
|
|
+ # 保存更新
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功更新酒店集团品牌记录,ID: {brand.id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '酒店集团品牌记录更新成功',
|
|
|
|
+ 'data': brand.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"更新酒店集团品牌记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def query_hotel_group_brands(brand_id):
|
|
|
|
+ """
|
|
|
|
+ 查找指定ID的酒店集团子品牌数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ brand_id (int): 品牌记录ID
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和品牌信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 根据ID查找品牌记录
|
|
|
|
+ brand = HotelGroupBrands.query.get(brand_id)
|
|
|
|
+
|
|
|
|
+ if not brand:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{brand_id}的品牌记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 返回找到的记录
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '查找品牌记录成功',
|
|
|
|
+ 'data': brand.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ error_msg = f"查找品牌记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def delete_hotel_group_brands(brand_id):
|
|
|
|
+ """
|
|
|
|
+ 删除指定ID的酒店集团子品牌数据表记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ brand_id (int): 品牌记录ID
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 根据ID查找要删除的品牌记录
|
|
|
|
+ brand = HotelGroupBrands.query.get(brand_id)
|
|
|
|
+
|
|
|
|
+ if not brand:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{brand_id}的品牌记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 保存被删除记录的信息,用于返回
|
|
|
|
+ deleted_brand_info = brand.to_dict()
|
|
|
|
+
|
|
|
|
+ # 执行删除操作
|
|
|
|
+ db.session.delete(brand)
|
|
|
|
+ db.session.commit()
|
|
|
|
+
|
|
|
|
+ logging.info(f"成功删除酒店集团品牌记录,ID: {brand_id}")
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '品牌记录删除成功',
|
|
|
|
+ 'data': deleted_brand_info
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ db.session.rollback()
|
|
|
|
+ error_msg = f"删除品牌记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
return {
|
|
return {
|
|
'code': 500,
|
|
'code': 500,
|
|
'success': False,
|
|
'success': False,
|