Commit 1274ad98 by 章家宝

config(common_equity):通用-权益新增下载模板

1 parent d741cf54
...@@ -301,11 +301,12 @@ def oss_upload_token(): ...@@ -301,11 +301,12 @@ def oss_upload_token():
@app.get('/api/meta/task-types') @app.get('/api/meta/task-types')
@login_required @login_required
def meta_task_types(): def meta_task_types():
"""数据表类型配置(含各类型所需表单类型清单、是否需要所属周期)""" """数据表类型配置(含各类型所需表单类型清单、是否需要所属周期、导入模板映射)"""
data = [ data = [
{'code': k, 'name': v['name'], 'forms': v['forms'], {'code': k, 'name': v['name'], 'forms': v['forms'],
'need_period': v.get('need_period', False), 'need_period': v.get('need_period', False),
'support_week': v.get('support_week', False)} 'support_week': v.get('support_week', False),
'templates': v.get('templates', {})}
for k, v in Config.DATA_TABLE_TYPES.items() for k, v in Config.DATA_TABLE_TYPES.items()
] ]
return ok(data) return ok(data)
...@@ -611,6 +612,33 @@ def task_regenerate(task_id): ...@@ -611,6 +612,33 @@ def task_regenerate(task_id):
return ok(t.to_dict(), '已重新生成数据流程,等待调度器处理') return ok(t.to_dict(), '已重新生成数据流程,等待调度器处理')
@app.get('/api/template/download')
@login_required
def template_download():
"""通用导入模板下载:根据数据表类型 + 表单类型返回对应的 Excel 模板文件。
query: type=common_equity&form_type=区域维度数据
"""
from io import BytesIO
type_code = (request.args.get('type') or '').strip()
form_type = (request.args.get('form_type') or '').strip()
if not type_code or not form_type:
return fail('参数错误:type 和 form_type 必填')
tcfg = get_type_config(type_code)
if not tcfg:
return fail(f'不支持的数据表类型:{type_code}')
templates = tcfg.get('templates') or {}
filename = templates.get(form_type)
if not filename:
return fail(f'「{form_type}」未配置导入模板')
from config import BASE_DIR
file_path = os.path.join(BASE_DIR, 'import_templates', filename)
if not os.path.exists(file_path):
return fail(f'模板文件不存在:{filename}')
with open(file_path, 'rb') as f:
data = f.read()
return _xlsx_attachment_response(BytesIO(data), filename)
@app.get('/api/guangai/template') @app.get('/api/guangai/template')
@login_required @login_required
def guangai_template(): def guangai_template():
......
...@@ -238,6 +238,12 @@ class Config: ...@@ -238,6 +238,12 @@ class Config:
'汇总区数据', '汇总区数据',
'红黄门店数据', '红黄门店数据',
], ],
# 导入模板文件名(存放于 import_templates/ 目录),前端据此提供「下载模板」按钮
'templates': {
'区域维度数据': '区域维度导入模版.xlsx',
'汇总区数据': '汇总区数据导入模版.xlsx',
'红黄门店数据': '红黄门店数据导入模板.xlsx',
},
}, },
# 招聘管理:无需上传数据源表(forms 为空),need_period=False; # 招聘管理:无需上传数据源表(forms 为空),need_period=False;
# 处理引擎已接入:processor.py 路由至 RecruitmentProcessor # 处理引擎已接入:processor.py 路由至 RecruitmentProcessor
......
...@@ -288,6 +288,8 @@ ...@@ -288,6 +288,8 @@
function renderFileInputs(forms) { function renderFileInputs(forms) {
mFiles.innerHTML = ''; mFiles.innerHTML = '';
formFiles = {}; formFiles = {};
var cfg = typeConfigs.find(function (t) { return t.code === mType.value; });
var templates = (cfg && cfg.templates) || {};
forms.forEach(function (formType) { forms.forEach(function (formType) {
var row = document.createElement('div'); var row = document.createElement('div');
row.className = 'modal-file'; row.className = 'modal-file';
...@@ -327,14 +329,21 @@ ...@@ -327,14 +329,21 @@
row.appendChild(upload); row.appendChild(upload);
row.appendChild(tip); row.appendChild(tip);
mFiles.appendChild(row); mFiles.appendChild(row);
// 广爱专项:「下载模板」独立一行(避免与说明文字挤在同一 flex 行重叠) // 该表单类型配置了导入模板时,显示「下载模板」链接(独立一行,避免与说明文字挤在同一 flex 行重叠)
if (mType.value === 'guangai_special') { if (templates[formType]) {
var tplRow = document.createElement('div'); var tplRow = document.createElement('div');
tplRow.style.cssText = 'margin:-6px 0 12px 142px;'; tplRow.style.cssText = 'margin:-6px 0 12px 142px;';
var tpl = document.createElement('a'); var tpl = document.createElement('a');
tpl.href = '/api/guangai/template'; // 广爱专项保留原独立接口(门店名称系统预填),其余类型走通用模板下载接口
if (mType.value === 'guangai_special') {
tpl.href = '/api/guangai/template';
tpl.textContent = '⬇ 下载模板(门店名称已预填,请勿修改门店名称列)';
} else {
tpl.href = '/api/template/download?type=' + encodeURIComponent(mType.value) +
'&form_type=' + encodeURIComponent(formType);
tpl.textContent = '⬇ 下载' + formType + '模板';
}
tpl.style.cssText = 'color:#1890ff;font-size:13px;text-decoration:underline;'; tpl.style.cssText = 'color:#1890ff;font-size:13px;text-decoration:underline;';
tpl.textContent = '⬇ 下载模板(门店名称已预填,请勿修改门店名称列)';
tplRow.appendChild(tpl); tplRow.appendChild(tpl);
mFiles.appendChild(tplRow); mFiles.appendChild(tplRow);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!