-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
293 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"use client"; | ||
import { useCallback, useEffect } from "react"; | ||
import { useDBContext } from "./DBContext"; | ||
import { Field, Profession } from "./types"; | ||
import { parseProfessionJobCount } from "./util"; | ||
|
||
export function ProfessionTable() { | ||
const { | ||
state: { dbWorker, activeDb, baseTables }, | ||
} = useDBContext(); | ||
|
||
const parseAlltables = useCallback(async () => { | ||
const jobTables: string[] = []; | ||
for (const { name: tableName } of baseTables) { | ||
console.log(dbWorker); | ||
const cols = (await dbWorker!.execSql( | ||
`PRAGMA table_info(${tableName});` | ||
)) as Field[]; | ||
console.log(cols); | ||
|
||
if ( | ||
["职位代码", "专业要求"].every((s) => | ||
cols.map((e) => e.name).includes(s) | ||
) | ||
) { | ||
jobTables.push(tableName); | ||
} | ||
} | ||
console.log(jobTables); | ||
|
||
return await Promise.all(jobTables.map(parseTable)); | ||
|
||
async function parseTable(tableName: string) { | ||
let jobGroupsByProfession: { | ||
专业要求: string; | ||
cnt: number; | ||
}[] = []; | ||
let professions: Profession[] = []; | ||
const professionsSql = `select count(*) as cnt, 专业要求 from ${tableName} group by 专业要求 having 学历要求 like '%本科%' and (招录单位全称 like '%昆明%' or 招录单位全称 like '%云南省%') order by cnt desc;`; | ||
|
||
return dbWorker | ||
?.execSql(professionsSql) | ||
.then((res) => (jobGroupsByProfession = res)) | ||
.then(() => dbWorker?.execSql(`select * from 本科专业目录;`)) | ||
.then((res) => { | ||
professions = res.filter( | ||
(e) => !["▲", "★"].some((s) => JSON.stringify(e).includes(s)) | ||
); | ||
}) | ||
.then(() => { | ||
console.log(jobGroupsByProfession); | ||
jobGroupsByProfession.forEach(parseProfessionJobCount(professions)); | ||
return professions; | ||
}); | ||
} | ||
}, [dbWorker]); | ||
|
||
// todo: 表名是未知的,除非加一个 meta 表。。。才能知道哪些表是 Job 表 | ||
|
||
useEffect(() => { | ||
if (!dbWorker) { | ||
return; | ||
} | ||
|
||
parseAlltables().then((res) => { | ||
console.log(res); | ||
// const baseCnt = jobGroupsByProfession.find( | ||
// (e) => e.专业要求 == "不限" | ||
// )?.cnt; | ||
// console.log(baseCnt); | ||
// console.log( | ||
// `红牌专业 ${professions.filter((e) => e.岗位数 == baseCnt).length}` | ||
// ); | ||
// console.table( | ||
// professions | ||
// .sort((a, b) => a.岗位数 - b.岗位数) | ||
// .slice(0, 100) | ||
// .map((e) => ({ | ||
// ...e, | ||
// 除不限外岗位数: e.岗位数 - (baseCnt || 0), | ||
// })) | ||
// ); | ||
// console.log("top 100"); | ||
// console.log( | ||
// professions | ||
// .sort((a, b) => b.岗位数 - a.岗位数) | ||
// .map((e) => ({ | ||
// ...e, | ||
// 除不限外岗位数: e.岗位数 - (baseCnt || 0), | ||
// })) | ||
// ); | ||
}); | ||
}, [dbWorker]); | ||
|
||
return <></>; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.