Browse Source

增加其他口径比较

master
张献维 2 weeks ago
parent
commit
672d6862f4
  1. 204
      golang_learn/data_office/get_hy_jctj/main.go

204
golang_learn/data_office/get_hy_jctj/main.go

@ -7,6 +7,7 @@ package main
*/
import (
"database/sql"
"errors"
"fmt"
excelize "github.com/xuri/excelize/v2"
"strings"
@ -15,9 +16,28 @@ import (
_ "github.com/go-sql-driver/mysql"
)
var SQL2Ku = ` select '公务员表统计多人' Type,'' AS A0195, m0207 Work,m0201 Name,m0203 IDNumber from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='1' and m1.rpt='@rpt' and m2.rpt='@rpt' and m0203 not in (select a0184 from a01 where a0163='1' and a0160='1')
union all select '公务员表采集多人' Type,'' AS A0195,a0192a Work,a0101 Name,a0184 IDNumber from a01 where a0163='1' and a0160='1' and a0184 not in(select m0203 from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='1' and m1.rpt='@rpt' and m2.rpt='@rpt')
union all select '参公群团表统计多人' Type,'' AS A0195,m0207 Work,m0201 Name,m0203 IDNumber from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='2' and m1.rpt='@rpt' and m2.rpt='@rpt' and m0203 not in (select a0184 from a01 where a0163='1' and a0160='5')
union all select '参公群团表采集多人' Type,'' AS A0195,a0192a Work,a0101 Name,a0184 IDNumber from a01 where a0163='1' and a0160='5' and a0184 not in(select m0203 from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='2' and m1.rpt='@rpt' and m2.rpt='@rpt')
union all select '参公事业表统计多人' Type,'' AS A0195,m0207 Work,m0201 Name,m0203 IDNumber from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='3' and m1.rpt='@rpt' and m2.rpt='@rpt' and m0203 not in (select a0184 from a01 where a0163='1' and a0160='6')
union all select '参公事业表采集多人' Type,'' AS A0195,a0192a Work,a0101 Name,a0184 IDNumber from a01 where a0163='1' and a0160='6' and a0184 not in(select m0203 from m_m02 m2 inner join m_m01 m1 on m2.ouuid=m1.ouuid where m0104='3' and m1.rpt='@rpt' and m2.rpt='@rpt')
union all select '基础库比统计库多' Type,(select b0101 from b01 where b0111=a.a0195) AS A0195,a0192a Work,a.a0101 Name,a.A0184 IDNumber from a01 a where a0163='1' and a0184 not in(select m0203 from m_m02 inner join tb_set_unit s on m_m02.unid=s.TBUNITID and rpid='@rpt' and rpt='@rpt' and TBUNITID<>'0' and ouuid in (select ouuid from m_m01))
union all select '基础库比统计库少' Type,(select m0101 from m_m01 where unid=m.unid and rpt='@rpt') AS A0195,m0207 Work,m.m0201 Name,m.m0203 IDNumber from m_m02 m inner join tb_set_unit s on m.unid=s.TBUNITID and rpid='@rpt' and rpt='@rpt' and TBUNITID<>'0' where m0203 not in(select a0184 from a01 where a0163='1') and ouuid in (select ouuid from m_m01)
`
var SQLJck = `
select ifnull(A0184,'')IDNumber,
ifnull(A0101,'') Name,
ifnull(A0192A,'') Work,
ifnull(substr(a0107, 1, 6),'') BirthDate,
IF(A0104 = 1, '男', '女') Gender,
ifnull((select min(code_name) from code_value where A0117=code_value and code_type='GB3304'),'') Ethnicity,
@ -37,37 +57,39 @@ select ifnull(A0184,'')IDNumber,
IF(A0197 = 1, '是', '否') Has2YearsGrassrootsExp,
ifnull((select min(code_name) from A15, code_value where A1517=code_value and code_type='ZB18' and A1521='2023' and A01.A0000=A15.A0000), '') AnnualAssessment2023,
ifnull((select min(code_name) from code_value where A0160=code_value and code_type='ZB125'),'') PersonCategory,
ifnull((select '是' from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '2024%' and A01.A0000=A99Z1.A0000 limit 1), '否') SelectedFor2024
ifnull((select '是' from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '@rpt%' and A01.A0000=A99Z1.A0000 limit 1), '否') SelectedFor2024
from A01
where A0163 = '1'
`
var SQLZjk = `
select ifnull(M0203,'') IDNumber,
ifnull(M0201,'') Name,
ifnull(M0207,'') Work,
ifnull(substr(M0204, 1, 6) ,'') BirthDate,
IF(M0202 = 1, '男', '女') Gender,
ifnull((select min(code_name) from code_value where M0205=code_value and code_type='M_D_CM16'),'') Ethnicity,
ifnull((select min(code_name) from code_value where M0205=code_value and code_type='GB3304'),'') Ethnicity,
ifnull(substr(M0216, 1, 6),'') WorkStartDate,
ifnull((select min(code_name) from code_value where M0206=code_value and code_type='M_D_CD17'),'') PoliticalStatus,
ifnull((select min(code_name) from code_value where M0206=code_value and code_type='GB4762'),'') PoliticalStatus,
ifnull((select min(code_name) from code_value where M0242=code_value and code_type='M_D_C11'),'') FullTimeEducation,
ifnull((select min(code_name) from code_value where M0212=code_value and code_type='M_D_C11'),'') HighestEducation,
ifnull((select min(code_name) from code_value where M0213=code_value and code_type='M_D_C12'),'') HighestDegree,
ifnull((select min(code_name) from code_value where M0246=code_value and code_type='M_D_M0246_1'),'') JobCategory,
ifnull((select min(code_name) from code_value where M0208=code_value and code_type='M_D_C32_2019'),'') CurrentPositionLevel,
ifnull((select min(code_name) from code_value where M0246=code_value and code_type='XZ93'),'') JobCategory,
ifnull((select min(code_name) from code_value where M0208=code_value and code_type='ZB09'),'') CurrentPositionLevel,
ifnull(substr(M0233, 1, 6),'') CurrentPositionStartDate,
ifnull((select min(code_name) from code_value where M0243=code_value and code_type='M_D_C31_2019'),'') CurrentRankLevel,
ifnull((select min(code_name) from code_value where M0243=code_value and code_type='ZB148'),'') CurrentRankLevel,
ifnull(substr(M0244, 1, 6),'') CurrentRankStartDate,
IF(M0215 = 1, '是', '否') Has2YearsGrassrootsExp,
ifnull((select min(code_name) from code_value where M0251=code_value and code_type='M_D_C32_2021'),'') AnnualAssessment2023,
ifnull((select case M0104 when 2 then '参照管理机关工作人员' when 3 then '参照管理事业单位人员' else '公务员' end from M_M01 where M_M01.UNID=M_M02.UNID and rpt='2024' limit 1),'') PersonCategory,
ifnull((select IF(M0525 = 1, '是', '否') from M_M05 where M0503=M0203 and rpt='2024' limit 1),'否') SelectedFor2024
ifnull((select min(code_name) from code_value where M0251=code_value and code_type='ZB18'),'') AnnualAssessment2023,
ifnull((select case M0104 when 2 then '参照管理机关工作人员' when 3 then '参照管理事业单位人员' else '公务员' end from M_M01 where M_M01.UNID=M_M02.UNID and rpt='@rpt' limit 1),'') PersonCategory,
ifnull((select IF(M0525 = 1, '是', '否') from M_M05 where M0503=M0203 and rpt='@rpt' limit 1),'否') SelectedFor2024
from M_M02
where rpt = '2024'
where rpt = '@rpt'
`
var SQLGzk = `
select
ifnull(S0203,'') IDNumber,
ifnull(S0202,'') IDNumber,
ifnull(S0201,'') Name,
ifnull(S0203,'') Work,
'-' BirthDate,
'-' Gender,
'-' Ethnicity,
@ -77,7 +99,7 @@ select
ifnull((select min(code_name) from code_value where S0225=code_value and code_type='M_D_C11'),'') HighestEducation,
'-' HighestDegree,
'-' JobCategory,
ifnull((select min(code_name) from code_value where S0204=code_value and code_type='M_D_S0204'),'') CurrentPositionLevel,
ifnull((select min(code_name) from code_value where S0204=code_value and code_type='ZB09'),'') CurrentPositionLevel,
'-' CurrentPositionStartDate,
ifnull((select min(code_name) from code_value where S0205=code_value and code_type='ZB148'),'') CurrentRankLevel,
'-' CurrentRankStartDate,
@ -85,10 +107,11 @@ select
'-' AnnualAssessment2023,
'-' PersonCategory,
'-' SelectedFor2024
from m_s02 where rpt='2024' union all
from m_s02 where rpt='@rpt' and S0208=1 union all
select
ifnull(S0403,'') IDNumber,
ifnull(S0402,'') IDNumber,
ifnull(S0401,'') Name,
ifnull(S0403,'') Work,
'-' BirthDate,
'-' Gender,
'-' Ethnicity,
@ -98,7 +121,7 @@ select
ifnull((select min(code_name) from code_value where S0425=code_value and code_type='M_D_C11'),'') HighestEducation,
'-' HighestDegree,
'-' JobCategory,
ifnull((select min(code_name) from code_value where S0404=code_value and code_type='M_D_S0204'),'') CurrentPositionLevel,
ifnull((select min(code_name) from code_value where S0404=code_value and code_type='ZB09'),'') CurrentPositionLevel,
'-' CurrentPositionStartDate,
ifnull((select min(code_name) from code_value where S0405=code_value and code_type='ZB148'),'') CurrentRankLevel,
'-' CurrentRankStartDate,
@ -106,7 +129,7 @@ select
'-' AnnualAssessment2023,
'-' PersonCategory,
'-' SelectedFor2024
from m_s04 where rpt='2024'
from m_s04 where rpt='@rpt' and S0408=1
`
var SQLCzk = `
@ -115,7 +138,7 @@ select
A0184 IDNumber,
ifnull((select min(code_name) from code_value where A0221=code_value and code_type='ZB09'),'') CurrentPositionLevel,
ifnull((select min(code_name) from code_value where A0192E=code_value and code_type='ZB148'),'') CurrentRankLevel,
ifnull(A0195, '') OldWork from C01 where C0105 like '2024%'
ifnull(A0195, '') OldWork from C01 where C0105 like '@rpt%'
`
var SQLBhb = `
@ -137,25 +160,45 @@ func main() {
dir := time.Now().Format("2006102150405")
file := fmt.Sprintf("对比结果-%s.xlsx", dir)
peoplesJck := queryBySQL(db, SQLJck)
peoplesZjk := queryBySQL(db, SQLZjk)
peoplesGzk := queryBySQL(db, SQLGzk)
var rpt string
// 获取全局报告期
query := "SELECT aaa005 FROM aa01 WHERE aaa001 = 'PERIOD'"
err := db.QueryRow(query).Scan(&rpt)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
fmt.Println("没有找到匹配的记录")
} else {
fmt.Println("查询失败:", err)
}
return
}
fmt.Println("当前报告期:", rpt)
peoplesJck := queryBySQL(db, SQLJck, rpt)
peoplesZjk := queryBySQL(db, SQLZjk, rpt)
peoplesGzk := queryBySQL(db, SQLGzk, rpt)
results1 := mergeResults(peoplesJck, peoplesZjk, peoplesGzk)
peoplesCzk := queryByCzSQL(db, SQLCzk)
peoplesBhb := queryByCzSQL(db, SQLBhb)
peoplesCzk := queryByCzSQL(db, SQLCzk, rpt)
peoplesBhb := queryByCzSQL(db, SQLBhb, rpt)
results2 := mergeCzResults(peoplesCzk, peoplesBhb)
results3 := queryByChaSQL(db, SQL2Ku, rpt)
// 创建一个新的 Excel 文件
f := excelize.NewFile()
_ = f.NewSheet("三库对比")
_ = f.NewSheet("辞职人员对比")
_ = f.NewSheet("两库人头差")
saveSheet1(f, results1)
saveSheet2(f, results2)
saveSheet3(f, results3)
f.DeleteSheet("Sheet1")
f.SetActiveSheet(1)
f.SetActiveSheet(0)
// 保存文件
if err := f.SaveAs(file); err != nil {
@ -173,7 +216,7 @@ func saveSheet1(f *excelize.File, results []Diff) {
sheetName := "三库对比"
// 设置表头
headers := []string{"身份证号", "姓名", "项名称", "基础库", "中间库", "工资库"}
headers := []string{"身份证号", "姓名", "职务", "项名称", "基础库", "中间库", "工资库"}
for i, header := range headers {
cell := fmt.Sprintf("%c1", 'A'+i)
_ = f.SetCellValue(sheetName, cell, header)
@ -184,10 +227,10 @@ func saveSheet1(f *excelize.File, results []Diff) {
row := i + 2 // 数据从第二行开始
_ = f.SetCellValue(sheetName, fmt.Sprintf("A%d", row), diff.IDNumber)
_ = f.SetCellValue(sheetName, fmt.Sprintf("B%d", row), diff.Name)
_ = f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), diff.ColName)
_ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), diff.Jck)
_ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", row), diff.Zjk)
_ = f.SetCellValue(sheetName, fmt.Sprintf("F%d", row), diff.Gzk)
_ = f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), diff.Work)
_ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), diff.ColName)
_ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", row), diff.Jck)
_ = f.SetCellValue(sheetName, fmt.Sprintf("F%d", row), diff.Zjk)
}
}
@ -214,11 +257,34 @@ func saveSheet2(f *excelize.File, results []Diff) {
}
}
/*
*/
func saveSheet3(f *excelize.File, results []Cha) {
sheetName := "两库人头差"
// 设置表头
headers := []string{"类型", "统计单位", "职务", "姓名", "身份证号"}
for i, header := range headers {
cell := fmt.Sprintf("%c1", 'A'+i)
_ = f.SetCellValue(sheetName, cell, header)
}
// 写入数据
for i, diff := range results {
row := i + 2 // 数据从第二行开始
_ = f.SetCellValue(sheetName, fmt.Sprintf("A%d", row), diff.Type)
_ = f.SetCellValue(sheetName, fmt.Sprintf("B%d", row), diff.A0195)
_ = f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), diff.Work)
_ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), diff.Name)
_ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", row), diff.IDNumber)
}
}
/*
queryBySQL 按照基础脚本查询
*/
func queryBySQL(db *sql.DB, SQLJck string) []Person {
rows, err := db.Query(SQLJck)
func queryBySQL(db *sql.DB, SQL, rpt string) []Person {
rows, err := db.Query(strings.Replace(SQL, "@rpt", rpt, -1))
if err != nil {
_ = fmt.Errorf("发生报错:%s", err)
}
@ -235,6 +301,7 @@ func queryBySQL(db *sql.DB, SQLJck string) []Person {
err := rows.Scan(
&p.IDNumber,
&p.Name,
&p.Work,
&p.BirthDate,
&p.Gender,
&p.Ethnicity,
@ -268,8 +335,8 @@ func queryBySQL(db *sql.DB, SQLJck string) []Person {
/*
queryByCzSQL 按照辞职脚本查询
*/
func queryByCzSQL(db *sql.DB, SQLCz string) []CzPerson {
rows, err := db.Query(SQLCz)
func queryByCzSQL(db *sql.DB, SQL, rpt string) []CzPerson {
rows, err := db.Query(strings.Replace(SQL, "@rpt", rpt, -1))
if err != nil {
_ = fmt.Errorf("发生报错:%s", err)
}
@ -302,6 +369,43 @@ func queryByCzSQL(db *sql.DB, SQLCz string) []CzPerson {
return people
}
/*
queryByCzSQL 按照辞职脚本查询
*/
func queryByChaSQL(db *sql.DB, SQL, rpt string) []Cha {
rows, err := db.Query(strings.Replace(SQL, "@rpt", rpt, -1))
if err != nil {
_ = fmt.Errorf("发生报错:%s", err)
}
defer func(rows *sql.Rows) {
err := rows.Close()
if err != nil {
fmt.Printf("错误")
}
}(rows)
var people []Cha
for rows.Next() {
var p Cha
err := rows.Scan(
&p.Type,
&p.A0195,
&p.Work,
&p.Name,
&p.IDNumber,
)
if err != nil {
_ = fmt.Errorf("发生报错:%s", err)
}
people = append(people, p)
}
if err = rows.Err(); err != nil {
_ = fmt.Errorf("发生报错:%s", err)
}
return people
}
/*
mergeResults 基础人员对比
*/
@ -330,25 +434,25 @@ func mergeResults(peoplesJck, peoplesZjk, peoplesGzk []Person) []Diff {
if allKeys[key] == 1 {
// 全部存在 基础
diffs = setDiffs(gzkMap, key, nl, nl, gzkMap, idNumber, name, diffs)
diffs = setDiffs(gzkMap, key, nl, nl, gzkMap, idNumber, name, gzkMap[key]["职务"], diffs)
} else if allKeys[key] == 2 {
// 全部存在 中间
diffs = setDiffs(zjkMap, key, nl, zjkMap, nl, idNumber, name, diffs)
diffs = setDiffs(zjkMap, key, nl, zjkMap, nl, idNumber, name, zjkMap[key]["职务"], diffs)
} else if allKeys[key] == 3 {
// 全部存在 中间 + 工资
diffs = setDiffs(zjkMap, key, nl, zjkMap, gzkMap, idNumber, name, diffs)
diffs = setDiffs(zjkMap, key, nl, zjkMap, gzkMap, idNumber, name, zjkMap[key]["职务"], diffs)
} else if allKeys[key] == 4 {
// 全部存在 基础
diffs = setDiffs(jckMap, key, jckMap, nl, nl, idNumber, name, diffs)
diffs = setDiffs(jckMap, key, jckMap, nl, nl, idNumber, name, jckMap[key]["职务"], diffs)
} else if allKeys[key] == 5 {
// 全部存在 基础 + 工资
diffs = setDiffs(jckMap, key, jckMap, nl, gzkMap, idNumber, name, diffs)
diffs = setDiffs(jckMap, key, jckMap, nl, gzkMap, idNumber, name, jckMap[key]["职务"], diffs)
} else if allKeys[key] == 6 {
// 全部存在 基础 + 中间
diffs = setDiffs(zjkMap, key, jckMap, zjkMap, nl, idNumber, name, diffs)
diffs = setDiffs(zjkMap, key, jckMap, zjkMap, nl, idNumber, name, zjkMap[key]["职务"], diffs)
} else {
// 全部存在 基础 + 中间 + 工资
diffs = setDiffs(jckMap, key, jckMap, zjkMap, gzkMap, idNumber, name, diffs)
diffs = setDiffs(jckMap, key, jckMap, zjkMap, gzkMap, idNumber, name, jckMap[key]["职务"], diffs)
}
}
@ -363,6 +467,7 @@ func setDiffs(
gzkMap map[string]map[string]string,
idNumber string,
name string,
work string,
diffs []Diff) []Diff {
for colName := range oneMap[key] {
if colName == "身份证号" || colName == "姓名" {
@ -377,6 +482,7 @@ func setDiffs(
diff = Diff{
IDNumber: idNumber,
Name: name,
Work: work,
ColName: colName,
Jck: jckMap[key][colName],
Zjk: zjkMap[key][colName],
@ -390,6 +496,7 @@ func setDiffs(
diff = Diff{
IDNumber: idNumber,
Name: name,
Work: work,
ColName: colName,
Jck: jckMap[key][colName],
Zjk: zjkMap[key][colName],
@ -479,6 +586,7 @@ func mapPersonToDiff(people []Person) map[string]map[string]string {
}
result[key]["身份证号"] = person.IDNumber
result[key]["姓名"] = person.Name
result[key]["职务"] = person.Work
result[key]["出生时间"] = person.BirthDate
result[key]["性别"] = person.Gender
result[key]["民族"] = person.Ethnicity
@ -493,9 +601,9 @@ func mapPersonToDiff(people []Person) map[string]map[string]string {
result[key]["现职级层次"] = person.CurrentRankLevel
result[key]["任现职级层次时间"] = person.CurrentRankStartDate
result[key]["是否具有2年以上基层经验"] = person.Has2YearsGrassrootsExp
result[key]["2023年度考核结果"] = person.AnnualAssessment2023
result[key]["上年年度考核结果"] = person.AnnualAssessment2023
result[key]["人员类别"] = person.PersonCategory
result[key]["2024年考录选调生"] = person.SelectedFor2024
result[key]["年考录选调生"] = person.SelectedFor2024
}
return result
}
@ -532,6 +640,7 @@ func Eq(a, b *string) bool {
type Person struct {
IDNumber string // 身份证号
Name string // 姓名
Work string // 职务
BirthDate string // 出生时间
Gender string // 性别
Ethnicity string // 民族
@ -546,9 +655,9 @@ type Person struct {
CurrentRankLevel string // 现职级层次
CurrentRankStartDate string // 任现职级层次时间
Has2YearsGrassrootsExp string // 是否具有2年以上基层经验
AnnualAssessment2023 string // 2023年度考核结果
AnnualAssessment2023 string // 年度考核结果
PersonCategory string // 人员类别
SelectedFor2024 string // 2024年考录选调生
SelectedFor2024 string // 年考录选调生
}
type CzPerson struct {
IDNumber string // 身份证号
@ -561,8 +670,17 @@ type CzPerson struct {
type Diff struct {
IDNumber string `json:"身份证号"` // 身份证号
Name string `json:"姓名"` // 姓名
Work string `json:"职务"` // 职务
ColName string `json:"项名称"` // 项名称
Jck string `json:"基础库"` // 基础库
Zjk string `json:"中间库"` // 中间库
Gzk string `json:"工资库"` // 工资库
}
type Cha struct {
Type string `json:"类型"` // 类型
A0195 string `json:"统计单位"` // 统计单位
Work string `json:"职务"` // 职务
Name string `json:"姓名"` // 姓名
IDNumber string `json:"身份证号"` // 身份证号
}

Loading…
Cancel
Save