Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
data_report
/
data-report
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 22863aef
authored
Oct 20, 2026
by
周立明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
招聘管理报表离职数据统计
1 parent
804d9d28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
11 deletions
.workbuddy/memory/2026-10-19.md
data-process/outputs/baic_special_2026-08_task900002.xlsx
data-process/recruitment_processor.py
.workbuddy/memory/2026-10-19.md
View file @
22863ae
...
@@ -87,3 +87,15 @@ WHERE deleted_flag='N' AND business_type IN :biz_ids
...
@@ -87,3 +87,15 @@ WHERE deleted_flag='N' AND business_type IN :biz_ids
4.
models.py
`new_*`
注释改回「新增=招聘数量(recruitment_quantity)」,
`pend_month_*`
注释保持「待招人数=pendingCount」。
4.
models.py
`new_*`
注释改回「新增=招聘数量(recruitment_quantity)」,
`pend_month_*`
注释保持「待招人数=pendingCount」。
-
**真实验证(沙箱直连 D+,2026-10)**
:AG~AL(招聘数量) 合计=46、AM~AR(待招人数) 合计=25,且 46≥25(差=21,即已入职计划数)→ 符合"招聘数量≥待招人数"预期。各品牌:鸿蒙智行 招聘6/待招3、岚图 招聘6/待招6、其他品牌 招聘30/待招12。
-
**真实验证(沙箱直连 D+,2026-10)**
:AG~AL(招聘数量) 合计=46、AM~AR(待招人数) 合计=25,且 46≥25(差=21,即已入职计划数)→ 符合"招聘数量≥待招人数"预期。各品牌:鸿蒙智行 招聘6/待招3、岚图 招聘6/待招6、其他品牌 招聘30/待招12。
-
**生效**
:改了 recruitment_processor.py/models.py → 重启后端(PID 13536)→ 重跑 900005 → 导出 AG~AL/AM~AR 即对齐新口径。
-
**生效**
:改了 recruitment_processor.py/models.py → 重启后端(PID 13536)→ 重跑 900005 → 导出 AG~AL/AM~AR 即对齐新口径。
## ✅ 招聘 AS(入职)/AT(离职) + 月初/月末 日期 落地(2026-10-19 15:18)
用户要求:① AS(入职人数) 用
`SELECT COUNT(0) FROM dj_car_life_recruitment_onboarding_plan WHERE deleted_flag='N' AND created_date>=当月1 AND created_date<次月1`
(时间替换当月范围);② AT(离职) 数据清空、由使用人下载后手动填;③ 月初后面的数据填充当月1号日期。
-
**AS 落地(recruitment_processor.py)**
:
1.
新增
`RECRUIT_ENTRY_SQL`
+
`fetch_entry_count(month_start, month_end)`
(dj_smartcarlife,单总数,不区分品牌/业务);失败返回 0。
2.
`store_grid`
增
`entry_cnt`
参数,落库
`entry_cnt`
(8 行均存同一月总数,便于按任务查询)、
`leave_cnt=0`
。
3.
`generate_result_excel`
增
`entry_cnt`
参数,渲染合计行。
-
**模板合并坑(同 baic_special 的 MergedCell 问题)**
:模板
`AS4:AS12`
、
`AT4:AT12`
纵向合并,
**仅锚点 row4(问界行)可写**
,row5-12 为只读 MergedCell。初版在品牌行循环里写 col45/46 报
`MergedCell ... read-only`
;改为
**只写锚点 row4**
(合并区域随锚点贯穿至合计行展示)。AT 锚点写 0(透明清空,用户手动填)。
-
**日期基准(AV 列)修复**
:原代码把 AV1/AV2 都写成 cutoff_date(错误)。现 AU1=当前工作日(cutoff_date) / AU2=月初=当月1号(date(y,m,1)) / AU3=月末=当月最后一天(month_end-1天)。
-
**真实验证(沙箱直连 D+,2026-10)**
:入职人数=39(按月分布 01月38/02月11/03月58/04月37/05月22/06月41/07月50/08月49/09月37/10月39,数据可信)。端到端渲染测试(monkeypatch upload_file 落 outputs):AS1='10月入职'、AT1='10月离职'、锚点row4 AS=39/AT=0、AV2=2026-10-01、AV3=2026-10-31、AV1=2026-10-19 → 全部正确(注:openpyxl data_only 读合并非锚点行返回 None,Excel 中合并区显示锚点值,属正常)。
-
**生效**
:改了 recruitment_processor.py → 重启后端(PID 13536)→ 重跑 900005 → 导出 AS=当月入职总数、AT=0(手动填)、月初/月末日期正确。
-
**备注**
:入职为月总数无法按品牌拆分,按模板合并结构落在问界行锚点(贯穿至合计行);若用户希望入职/离职单独放某位置,需调整模板合并区域。
data-process/outputs/baic_special_2026-08_task900002.xlsx
deleted
100644 → 0
View file @
804d9d2
No preview for this file type
data-process/recruitment_processor.py
View file @
22863ae
...
@@ -28,7 +28,9 @@ WHERE d.deleted_flag = 'N'
...
@@ -28,7 +28,9 @@ WHERE d.deleted_flag = 'N'
行 14-25 = 第二块「待招聘需求汇总(品牌×4档)」:模板为空,待后续逻辑(本版未填)。
行 14-25 = 第二块「待招聘需求汇总(品牌×4档)」:模板为空,待后续逻辑(本版未填)。
AG~AL(33-38) = 新增招聘需求(当月提的全部需求,按业务)— 见 fetch_new_rows
AG~AL(33-38) = 新增招聘需求(当月提的全部需求,按业务)— 见 fetch_new_rows
AM~AR(39-44) = 月待招需求(当月提的待招需求,status=1,按业务)— 见 fetch_month_pending_rows
AM~AR(39-44) = 月待招需求(当月提的待招需求,status=1,按业务)— 见 fetch_month_pending_rows
AS/AT(45-46) = 入职/离职:待用户提供逻辑(本版未填,保留模板)。
AS(45)=入职人数(当月 dj_car_life_recruitment_onboarding_plan 入职计划总数,单值不区分品牌/业务,仅填合计行)— 见 fetch_entry_count
AT(46)=离职人数(本系统无源数据,固定留 0,由使用人下载后手动填写)
日期基准(AV 列):AU1=当前工作日(cutoff_date) / AU2=月初(当月1号) / AU3=月末(当月最后一天)
AG~AL / AM~AR 取值逻辑(用户 2026-10-19 提供,2026-10-19 修正口径):
AG~AL / AM~AR 取值逻辑(用户 2026-10-19 提供,2026-10-19 修正口径):
SELECT business_type, brand,
SELECT business_type, brand,
...
@@ -51,7 +53,7 @@ import logging
...
@@ -51,7 +53,7 @@ import logging
import
os
import
os
import
re
import
re
import
tempfile
import
tempfile
from
datetime
import
date
,
datetime
from
datetime
import
date
,
datetime
,
timedelta
import
openpyxl
import
openpyxl
from
openpyxl.utils
import
get_column_letter
from
openpyxl.utils
import
get_column_letter
...
@@ -263,6 +265,36 @@ def fetch_month_pending_rows(month_start, month_end):
...
@@ -263,6 +265,36 @@ def fetch_month_pending_rows(month_start, month_end):
return
_fetch_recruit_biz_rows
(
month_start
,
month_end
,
status_filter
=
True
)
return
_fetch_recruit_biz_rows
(
month_start
,
month_end
,
status_filter
=
True
)
# ---------- AS(入职人数) 源查询(当月入职计划总数,不区分品牌/业务) ----------
RECRUIT_ENTRY_SQL
=
"""
SELECT COUNT(0)
FROM dj_car_life_recruitment_onboarding_plan
WHERE deleted_flag = 'N'
AND created_date >= :month_start AND created_date < :month_end
"""
def
fetch_entry_count
(
month_start
,
month_end
):
"""AS(入职人数):当月入职计划数(dj_car_life_recruitment_onboarding_plan,单总数)。
不区分品牌/业务(用户 SQL 即 COUNT(0) 总数);返回单个整数,失败返回 0。
"""
engine
=
_get_biz_engine
()
try
:
with
engine
.
connect
()
as
conn
:
rows
=
conn
.
execute
(
text
(
RECRUIT_ENTRY_SQL
),
{
'month_start'
:
month_start
.
isoformat
(),
'month_end'
:
month_end
.
isoformat
()},
)
.
fetchall
()
cnt
=
int
(
rows
[
0
][
0
])
if
rows
else
0
logger
.
info
(
f
"[招聘] 当月入职人数={cnt}({month_start}~{month_end})"
)
return
cnt
except
Exception
as
e
:
logger
.
warning
(
f
"[招聘] D+ 入职人数查询失败({month_start}~{month_end}): {e}"
)
return
0
def
aggregate_by_biz
(
rows
,
value_key
=
'recruit_qty'
):
def
aggregate_by_biz
(
rows
,
value_key
=
'recruit_qty'
):
"""按 品牌 × 业务 聚合指定值(无周期档,用于 AG~AL/AM~AR)。
"""按 品牌 × 业务 聚合指定值(无周期档,用于 AG~AL/AM~AR)。
...
@@ -347,8 +379,12 @@ def aggregate(rows):
...
@@ -347,8 +379,12 @@ def aggregate(rows):
return
grid
return
grid
def
store_grid
(
task_id
,
stat_month
,
cutoff_date
,
grid
,
new_grid
,
pend_month_grid
):
def
store_grid
(
task_id
,
stat_month
,
cutoff_date
,
grid
,
new_grid
,
pend_month_grid
,
entry_cnt
):
"""软删旧行 + 插 8 品牌行(I~AF + AG~AL + AM~AR 全部落库)。"""
"""软删旧行 + 插 8 品牌行(I~AF + AG~AL + AM~AR + 入职/离职 全部落库)。
entry_cnt = 当月入职总数(单值,不区分品牌/业务);为便于按任务查询,8 行均存同一总数。
leave_cnt 本系统无源,固定 0(由使用人下载后手动填写)。
"""
# 软删同 (task_id, stat_month) 旧行
# 软删同 (task_id, stat_month) 旧行
old
=
RecruitmentMonthData
.
query
.
filter_by
(
old
=
RecruitmentMonthData
.
query
.
filter_by
(
task_id
=
task_id
,
stat_month
=
stat_month
,
is_deleted
=
0
)
.
all
()
task_id
=
task_id
,
stat_month
=
stat_month
,
is_deleted
=
0
)
.
all
()
...
@@ -392,14 +428,17 @@ def store_grid(task_id, stat_month, cutoff_date, grid, new_grid, pend_month_grid
...
@@ -392,14 +428,17 @@ def store_grid(task_id, stat_month, cutoff_date, grid, new_grid, pend_month_grid
rec
.
pend_month_light_sales
=
pend_month_grid
[
b
][
'light_sales'
]
rec
.
pend_month_light_sales
=
pend_month_grid
[
b
][
'light_sales'
]
rec
.
pend_month_technician
=
pend_month_grid
[
b
][
'technician'
]
rec
.
pend_month_technician
=
pend_month_grid
[
b
][
'technician'
]
rec
.
pend_month_used_car
=
pend_month_grid
[
b
][
'used_car'
]
rec
.
pend_month_used_car
=
pend_month_grid
[
b
][
'used_car'
]
# 入职/离职(AS/AT):入职为月总数(8 行存同一值便于查询);离职无源留 0
rec
.
entry_cnt
=
entry_cnt
rec
.
leave_cnt
=
0
objs
.
append
(
rec
)
objs
.
append
(
rec
)
db
.
session
.
bulk_save_objects
(
objs
)
db
.
session
.
bulk_save_objects
(
objs
)
db
.
session
.
commit
()
db
.
session
.
commit
()
logger
.
info
(
f
"[招聘] 已落库 {len(objs)} 行(task {task_id}, {stat_month})"
)
logger
.
info
(
f
"[招聘] 已落库 {len(objs)} 行(task {task_id}, {stat_month})"
)
def
generate_result_excel
(
task
,
grid
,
cutoff_date
,
new_grid
,
pend_month_grid
):
def
generate_result_excel
(
task
,
grid
,
cutoff_date
,
new_grid
,
pend_month_grid
,
entry_cnt
):
"""渲染结果表「统计」sheet:B~H + I~AF + AG~AL + AM~AR + 合计。返回 OSS url。"""
"""渲染结果表「统计」sheet:B~H + I~AF + AG~AL + AM~AR +
AS/AT +
合计。返回 OSS url。"""
if
not
os
.
path
.
exists
(
TEMPLATE_PATH
):
if
not
os
.
path
.
exists
(
TEMPLATE_PATH
):
raise
FileNotFoundError
(
f
"招聘结果表模板缺失: {TEMPLATE_PATH}"
)
raise
FileNotFoundError
(
f
"招聘结果表模板缺失: {TEMPLATE_PATH}"
)
wb
=
openpyxl
.
load_workbook
(
TEMPLATE_PATH
)
wb
=
openpyxl
.
load_workbook
(
TEMPLATE_PATH
)
...
@@ -448,15 +487,27 @@ def generate_result_excel(task, grid, cutoff_date, new_grid, pend_month_grid):
...
@@ -448,15 +487,27 @@ def generate_result_excel(task, grid, cutoff_date, new_grid, pend_month_grid):
value
=
sum
(
new_grid
[
b
][
g
]
for
b
in
BRAND_DISPLAY_ORDER
))
value
=
sum
(
new_grid
[
b
][
g
]
for
b
in
BRAND_DISPLAY_ORDER
))
ws
.
cell
(
row
=
r
,
column
=
MONTH_PENDING_BLOCK_START_COL
+
gi
,
ws
.
cell
(
row
=
r
,
column
=
MONTH_PENDING_BLOCK_START_COL
+
gi
,
value
=
sum
(
pend_month_grid
[
b
][
g
]
for
b
in
BRAND_DISPLAY_ORDER
))
value
=
sum
(
pend_month_grid
[
b
][
g
]
for
b
in
BRAND_DISPLAY_ORDER
))
# AS/AT(入职/离职):模板 AS4:AS12、AT4:AT12 纵向合并,仅锚点(问界行=row4)可写;
# 月总数写入锚点后随合并区域贯穿至合计行展示。
ws
.
cell
(
row
=
4
,
column
=
45
,
value
=
entry_cnt
)
# AS 入职(月总数,写入合并锚点)
ws
.
cell
(
row
=
4
,
column
=
46
,
value
=
0
)
# AT 离职(无源,留 0 由使用人手动填)
# 月份标签(AG~AT 等含「7月」-> 目标月)与基准日
# 月份标签(AG~AT 等含「7月」-> 目标月)与基准日
for
c
in
range
(
1
,
ws
.
max_column
+
1
):
for
c
in
range
(
1
,
ws
.
max_column
+
1
):
v
=
ws
.
cell
(
row
=
1
,
column
=
c
)
.
value
v
=
ws
.
cell
(
row
=
1
,
column
=
c
)
.
value
if
isinstance
(
v
,
str
)
and
'7月'
in
v
and
month_num
:
if
isinstance
(
v
,
str
)
and
'7月'
in
v
and
month_num
:
ws
.
cell
(
row
=
1
,
column
=
c
,
value
=
v
.
replace
(
'7月'
,
f
'{month_num}月'
))
ws
.
cell
(
row
=
1
,
column
=
c
,
value
=
v
.
replace
(
'7月'
,
f
'{month_num}月'
))
# 选月基准 / 当前工作日(模板 row1 col48=AV, row2 col48)
# 日期基准(AV 列):AU1=当前工作日 / AU2=月初(当月1号) / AU3=月末(当月最后一天)
for
rr
in
(
1
,
2
):
y
,
m
=
(
int
(
x
)
for
x
in
task
.
month
.
split
(
'-'
))
ws
.
cell
(
row
=
rr
,
column
=
48
,
value
=
cutoff_date
)
month_start
=
date
(
y
,
m
,
1
)
if
m
==
12
:
month_end
=
date
(
y
+
1
,
1
,
1
)
else
:
month_end
=
date
(
y
,
m
+
1
,
1
)
month_last
=
month_end
-
timedelta
(
days
=
1
)
ws
.
cell
(
row
=
1
,
column
=
48
,
value
=
cutoff_date
)
# AU1=当前工作日
ws
.
cell
(
row
=
2
,
column
=
48
,
value
=
month_start
)
# AU2=月初=当月1号
ws
.
cell
(
row
=
3
,
column
=
48
,
value
=
month_last
)
# AU3=月末=当月最后一天
# 写出临时文件 -> OSS
# 写出临时文件 -> OSS
tmp
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'.xlsx'
,
tmp
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
suffix
=
'.xlsx'
,
...
@@ -512,13 +563,14 @@ class RecruitmentProcessor:
...
@@ -512,13 +563,14 @@ class RecruitmentProcessor:
# AG~AL(新增招聘需求) 取 招聘数量(recruit_qty);AM~AR(待招聘需求) 取 待招人数(pending_count)
# AG~AL(新增招聘需求) 取 招聘数量(recruit_qty);AM~AR(待招聘需求) 取 待招人数(pending_count)
new_grid
=
aggregate_by_biz
(
new_rows
,
value_key
=
'recruit_qty'
)
new_grid
=
aggregate_by_biz
(
new_rows
,
value_key
=
'recruit_qty'
)
pend_month_grid
=
aggregate_by_biz
(
pend_month_rows
,
value_key
=
'pending_count'
)
pend_month_grid
=
aggregate_by_biz
(
pend_month_rows
,
value_key
=
'pending_count'
)
entry_cnt
=
fetch_entry_count
(
month_start
,
month_end
)
# AS 入职人数
store_grid
(
task_id
,
stat_month
,
cutoff_date
,
grid
,
new_grid
,
pend_month_grid
)
store_grid
(
task_id
,
stat_month
,
cutoff_date
,
grid
,
new_grid
,
pend_month_grid
,
entry_cnt
)
task
=
DataProcessTask
.
query
.
filter_by
(
id
=
task_id
)
.
first
()
task
=
DataProcessTask
.
query
.
filter_by
(
id
=
task_id
)
.
first
()
url
=
''
url
=
''
try
:
try
:
url
=
generate_result_excel
(
task
,
grid
,
cutoff_date
,
new_grid
,
pend_month_grid
)
url
=
generate_result_excel
(
task
,
grid
,
cutoff_date
,
new_grid
,
pend_month_grid
,
entry_cnt
)
except
Exception
as
ge
:
except
Exception
as
ge
:
logger
.
warning
(
f
"[招聘] 结果表生成失败(task {task_id}): {ge}"
)
logger
.
warning
(
f
"[招聘] 结果表生成失败(task {task_id}): {ge}"
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment