|
|
@@ -4,6 +4,10 @@
|
|
|
from typing import List
|
|
|
from typing_extensions import Annotated
|
|
|
from pydantic import BeforeValidator
|
|
|
+import json
|
|
|
+from datetime import datetime
|
|
|
+
|
|
|
+from flask import Response
|
|
|
|
|
|
from ruoyi_common.constant import UserConstants
|
|
|
from ruoyi_common.base.model import AjaxResponse, TableResponse
|
|
|
@@ -11,8 +15,8 @@ from ruoyi_common.base.transformer import ids_to_list
|
|
|
# from ruoyi_common.domain.entity import SysStuffInfoConf
|
|
|
from ruoyi_common.domain.entity import SysStuffInfoConf
|
|
|
from ruoyi_common.domain.enum import BusinessType
|
|
|
-from ruoyi_common.descriptor.serializer import JsonSerializer
|
|
|
-from ruoyi_common.descriptor.validator import BodyValidator, QueryValidator,PathValidator
|
|
|
+from ruoyi_common.descriptor.serializer import JsonSerializer, BaseSerializer
|
|
|
+from ruoyi_common.descriptor.validator import BodyValidator, QueryValidator, PathValidator, FileDownloadValidator
|
|
|
from ruoyi_common.utils import security_util as SecurityUtil
|
|
|
from ruoyi_system.service.module_conf.stuff_info_conf import SysModuleStuffinfoConfService
|
|
|
from ruoyi_framework.descriptor.log import Log
|
|
|
@@ -101,3 +105,52 @@ def system_stuffinfo_conf_delete(
|
|
|
# SysModuleStuffinfoConfService.check_stuffinfo_conf_data_scope(id)
|
|
|
flag = SysModuleStuffinfoConfService.delete_stuffinfo_conf_by_id(ids)
|
|
|
return AjaxResponse.from_success() if flag > 0 else AjaxResponse.from_error()
|
|
|
+
|
|
|
+
|
|
|
+@reg.api.route("/system/moduleConf/stuffInfoConf/export", methods=["POST"])
|
|
|
+@FileDownloadValidator()
|
|
|
+@PreAuthorize(HasPerm("moduleConf:stuffInfoConf:export"))
|
|
|
+@Log(title="员工配置管理", business_type=BusinessType.EXPORT)
|
|
|
+@BaseSerializer()
|
|
|
+def system_stuffinfo_conf_export(dto: SysStuffInfoConf):
|
|
|
+ '''
|
|
|
+ 导出员工配置列表为JSON
|
|
|
+ '''
|
|
|
+ try:
|
|
|
+ rows = SysModuleStuffinfoConfService.select_stuffinfo_conf_list(dto)
|
|
|
+ # 将Pydantic模型转换为字典
|
|
|
+ data = []
|
|
|
+ for row in rows:
|
|
|
+ try:
|
|
|
+ if hasattr(row, 'model_dump'):
|
|
|
+ data.append(row.model_dump())
|
|
|
+ elif hasattr(row, 'dict'):
|
|
|
+ data.append(row.dict())
|
|
|
+ else:
|
|
|
+ # 如果是字典类型,直接使用
|
|
|
+ data.append(dict(row) if hasattr(row, '__iter__') and not isinstance(row, str) else row)
|
|
|
+ except Exception as e:
|
|
|
+ # 如果序列化失败,尝试使用默认方法
|
|
|
+ data.append(str(row))
|
|
|
+ # 转换为JSON字符串
|
|
|
+ json_str = json.dumps(data, ensure_ascii=False, indent=2, default=str)
|
|
|
+ # 创建响应 - 使用application/octet-stream确保前端识别为文件下载
|
|
|
+ response = Response(
|
|
|
+ json_str.encode('utf-8'),
|
|
|
+ mimetype='application/octet-stream',
|
|
|
+ headers={
|
|
|
+ 'Content-Disposition': f'attachment; filename=stuffInfoConf_{datetime.now().strftime("%Y%m%d_%H%M%S")}.json',
|
|
|
+ 'Content-Type': 'application/json; charset=utf-8'
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return response
|
|
|
+ except Exception as e:
|
|
|
+ import traceback
|
|
|
+ error_msg = f"导出失败: {str(e)}"
|
|
|
+ error_json = json.dumps({"code": 500, "msg": error_msg}, ensure_ascii=False)
|
|
|
+ error_response = Response(
|
|
|
+ error_json,
|
|
|
+ mimetype='application/json',
|
|
|
+ status=500
|
|
|
+ )
|
|
|
+ return error_response
|