diff --git a/golang_learn/data_func/go_to_mysql/go_to_hzb/HZBMySQLComp.go b/golang_learn/data_func/go_to_mysql/go_to_hzb/HZBMySQLComp.go index 4dd82d4..662b7db 100644 --- a/golang_learn/data_func/go_to_mysql/go_to_hzb/HZBMySQLComp.go +++ b/golang_learn/data_func/go_to_mysql/go_to_hzb/HZBMySQLComp.go @@ -1,11 +1,15 @@ -/** +/* +* 该程序用于MySQL比较数据库某些字典信息。 参数方式说明: + 无参数 : 表示执行 -h : 表示查看说明 -r : 表示重构基础文件 -v : 表示查看版本号 + 当前记录信息项为: + code_type、 code_value、 code_table、 @@ -21,114 +25,117 @@ */ package main -import ( - "data_func/go_to_mysql/go_to_hzb/Obj" - "database/sql" - "fmt" - _ "github.com/go-sql-driver/mysql" - "golang.org/x/sys/windows/registry" - "os" - "strings" - "time" -) - -/** -概括文件 -*/ -type Files struct { - Creator string //创建人 - Edition string //创建版本 - CreatDate string //创建时间 -} - -/** -主方法 -*/ -func main() { - db, err := sql.Open("mysql", "root:admin@tcp(127.0.0.1:45017)/zwhzyq?charset=utf8") - if err != nil { - fmt.Println(err) - } - defer db.Close() - - rows, _ := db.Query("select * from CODE_TYPE") - c := Obj.CODE_TYPE{} - for rows.Next() { - err = rows.Scan(&c.CODE_TYPE, &c.TYPE_NAME, &c.CODE_GROUP, &c.CODE_DESCRIPTION, &c.ISCUSTOMIZE) - fmt.Println(c.CODE_TYPE) - } - - /*Mysql := [] string{"code_type","code_value","code_table","code_table_col","a01_config_init","smt_acl","smt_function","smt_resource","s_version","v_version","verify_scheme","verify_rule"} - - - for key, value := range Mysql { - fmt.Println(key, value) - } - - args := os.Args - hzbPath := funcName() //读取权限列表中项目的路径 - ctxPath := hzbPath //用于替换 - - if len(args) == 1 { // ----------------------------------------------------------表示执行 - - }else if len(args) == 2 { - if args[1] == "-h" { // -----------------------------------------------------表示帮助 - fmt.Println("该程序为该程序用于MySQL比较数据库某些字典信息" + - "。\n\t无参数时,表示直接执行程序,会生成csv文件(存在汉字会乱码,请使用文本查看)" + - ";\n\t壹参数时,(-h)表示查看帮助" + - ";\n\t壹参数时,(-r)表示按照基础字典重构程序" + - ";\n\t多参数时,(-r -code_value +code_type)表示重构程序减除code_value,新增code_type" + - "。") - }else if args[1] == "-r" { // -----------------------------------------------表示重构基础 - fmt.Println("") - }else{ - fmt.Println("无操作!") - } - }else {// -----------------------------------------------------------------------表示重构基础 + 新增字典 - if 1 == 1 { - - } - } - writeFile(ctxPath, "")*/ - -} - -/** -输出文件 -*/ -func writeFile(JsonPath, allStr string) { - file3, _ := os.Create(JsonPath + "_" + time.Now().Format("20060102150405") + ".go") - file3.WriteString(allStr) - file3.Close() -} - -/** -读取权限列表中项目的路径 -*/ -func funcName() string { - key, exists := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\全国公务员管理信息系统2017版`, registry.QUERY_VALUE) - defer key.Close() - if exists == nil { - version, _, _ := key.GetStringValue("DisplayVersion") - return version - } else { - return "" - } -} - -/** -字符串格式化 -*/ -func form(timeStr string) string { - return timeStr[0:4] + "-" + timeStr[4:6] + "-" + timeStr[6:8] + " " + timeStr[8:10] + ":" + timeStr[10:12] + ":" + timeStr[12:14] -} - -/** -获取文件名称 -*/ -func readFileName() string { - aaa := os.Args //当前目录数组 - aaastr := aaa[0] //当前目录字符串 - aaasz := strings.Split(aaastr, "\\") //获取文件目录数组 - return strings.Replace(aaasz[len(aaasz)-1], ".exe", "", 1) //获取操作程序名称 -} +// +// import ( +// "data_func/go_to_mysql/go_to_hzb/OBJ" +// "database/sql" +// "fmt" +// _ "github.com/go-sql-driver/mysql" +// "golang.org/x/sys/windows/registry" +// "golang_learn/data_func/go_to_mysql/go_to_hzb/Obj" +// "os" +// "strings" +// "time" +// ) +// +// /** +// 概括文件 +// */ +// type Files struct { +// Creator string //创建人 +// Edition string //创建版本 +// CreatDate string //创建时间 +// } +// +// /** +// 主方法 +// */ +// func main() { +// db, err := sql.Open("mysql", "root:admin@tcp(127.0.0.1:45017)/zwhzyq?charset=utf8") +// if err != nil { +// fmt.Println(err) +// } +// defer db.Close() +// +// rows, _ := db.Query("select * from CODE_TYPE") +// c := Obj.CODE_TYPE{} +// for rows.Next() { +// err = rows.Scan(&c.CODE_TYPE, &c.TYPE_NAME, &c.CODE_GROUP, &c.CODE_DESCRIPTION, &c.ISCUSTOMIZE) +// fmt.Println(c.CODE_TYPE) +// } +// +// /*Mysql := [] string{"code_type","code_value","code_table","code_table_col","a01_config_init","smt_acl","smt_function","smt_resource","s_version","v_version","verify_scheme","verify_rule"} +// +// +// for key, value := range Mysql { +// fmt.Println(key, value) +// } +// +// args := os.Args +// hzbPath := funcName() //读取权限列表中项目的路径 +// ctxPath := hzbPath //用于替换 +// +// if len(args) == 1 { // ----------------------------------------------------------表示执行 +// +// }else if len(args) == 2 { +// if args[1] == "-h" { // -----------------------------------------------------表示帮助 +// fmt.Println("该程序为该程序用于MySQL比较数据库某些字典信息" + +// "。\n\t无参数时,表示直接执行程序,会生成csv文件(存在汉字会乱码,请使用文本查看)" + +// ";\n\t壹参数时,(-h)表示查看帮助" + +// ";\n\t壹参数时,(-r)表示按照基础字典重构程序" + +// ";\n\t多参数时,(-r -code_value +code_type)表示重构程序减除code_value,新增code_type" + +// "。") +// }else if args[1] == "-r" { // -----------------------------------------------表示重构基础 +// fmt.Println("") +// }else{ +// fmt.Println("无操作!") +// } +// }else {// -----------------------------------------------------------------------表示重构基础 + 新增字典 +// if 1 == 1 { +// +// } +// } +// writeFile(ctxPath, "")*/ +// +// } +// +// /** +// 输出文件 +// */ +// func writeFile(JsonPath, allStr string) { +// file3, _ := os.Create(JsonPath + "_" + time.Now().Format("20060102150405") + ".go") +// file3.WriteString(allStr) +// file3.Close() +// } +// +// /** +// 读取权限列表中项目的路径 +// */ +// func funcName() string { +// key, exists := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\全国公务员管理信息系统2017版`, registry.QUERY_VALUE) +// defer key.Close() +// if exists == nil { +// version, _, _ := key.GetStringValue("DisplayVersion") +// return version +// } else { +// return "" +// } +// } +// +// /** +// 字符串格式化 +// */ +// func form(timeStr string) string { +// return timeStr[0:4] + "-" + timeStr[4:6] + "-" + timeStr[6:8] + " " + timeStr[8:10] + ":" + timeStr[10:12] + ":" + timeStr[12:14] +// } +// +// /** +// 获取文件名称 +// */ +// func readFileName() string { +// aaa := os.Args //当前目录数组 +// aaastr := aaa[0] //当前目录字符串 +// aaasz := strings.Split(aaastr, "\\") //获取文件目录数组 +// return strings.Replace(aaasz[len(aaasz)-1], ".exe", "", 1) //获取操作程序名称 +// } +// diff --git a/golang_learn/data_office/get_hy_jctj/main.exe.manifest b/golang_learn/data_office/get_hy_jctj/main.exe.manifest new file mode 100644 index 0000000..c52acbc --- /dev/null +++ b/golang_learn/data_office/get_hy_jctj/main.exe.manifest @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/golang_learn/data_office/get_hy_jctj/main.go b/golang_learn/data_office/get_hy_jctj/main.go new file mode 100644 index 0000000..192d10c --- /dev/null +++ b/golang_learn/data_office/get_hy_jctj/main.go @@ -0,0 +1,224 @@ +package main + +/* +思路: + 按照三个SQL进行查询,结果封装到指定结构体,并对比三个查询结果,按照姓名和身份证作为关联项,任意其他项值不等,则保留下来 + +*/ +import ( + "database/sql" + "fmt" + "github.com/xuri/excelize/v2" + "strings" + "time" + + _ "github.com/go-sql-driver/mysql" +) + +var SQLJck = "select ifnull(A0184,'') IDNumber, ifnull(A0101,'') Name, ifnull(substr(a0107, 1, 6),'') BirthDate, ifnull(A0101,'') Gender, ifnull(A0117,'') Ethnicity, ifnull(substr(a0134, 1, 6),'') WorkStartDate, ifnull(A0141,'') PoliticalStatus, ifnull((select MIN(A0801B) from A08 where A0831=1 and A01.A0000=A08.A0000), '') FullTimeEducation, ifnull((select MIN(A0801B) from A08 where A0834=1 and A01.A0000=A08.A0000), '') HighestEducation, ifnull((select MIN(A0901B) from A08 where A0835=1 and A01.A0000=A08.A0000), '') HighestDegree, ifnull(A0123,'') JobCategory, ifnull((select A0501B from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionLevel, ifnull((select substr(A0504, 1, 6) from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionStartDate, ifnull((select A0501B from A05 where A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') CurrentRankLevel, ifnull((select DATE_FORMAT(DATE_SUB(STR_TO_DATE(substr(A0504, 1, 6), '%Y%m'), INTERVAL ifnull(A0532, 0) MONTH), '%Y%m') from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentRankStartDate, ifnull(A0197,'0') Has2YearsGrassrootsExp, ifnull((select MIN(A1517) from A15 where A1521='2023' and A01.A0000=A15.A0000), '') AnnualAssessment2023, ifnull(A0160,'') PersonCategory, ifnull((select 1 from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '2024%' and A01.A0000=A99Z1.A0000), 0) SelectedFor2024 from A01 where A0163='1'" +var SQLZjk = "select ifnull(M0203,'') IDNumber, ifnull(M0201,'') Name, ifnull(M0204,'') BirthDate, ifnull(M0202,'') Gender, ifnull(M0205,'') Ethnicity, ifnull(M0216,'') WorkStartDate, ifnull(M0206,'') PoliticalStatus, ifnull(M0242,'') FullTimeEducation, ifnull(M0212,'') HighestEducation, ifnull(M0213,'') HighestDegree, ifnull(M0246,'') JobCategory, ifnull(M0208,'') CurrentPositionLevel, ifnull(M0233,'') CurrentPositionStartDate, ifnull(M0243,'') CurrentRankLevel, ifnull(M0244,'') CurrentRankStartDate, ifnull(M0215,'') Has2YearsGrassrootsExp, ifnull(M0201,'') AnnualAssessment2023, ifnull((select case M0104 when 2 then 5 when 3 then 6 else 1 end from M_M01 where M_M01.UNID=M_M02.UNID),'') PersonCategory, ifnull((select 1 from M_M05 where M0503=M0203 and rpt='2024'),0) SelectedFor2024 from M_M02 where rpt='2024'" +var SQLGzk = "select ifnull(S0203,'') IDNumber, ifnull(S0201,'') Name, '' BirthDate, '' Gender, '' Ethnicity, '' WorkStartDate, '' PoliticalStatus, '' FullTimeEducation, ifnull(S0225,'') HighestEducation, '' HighestDegree, '' JobCategory, ifnull(S0204,'') CurrentPositionLevel, '' CurrentPositionStartDate, ifnull(S0205,'') CurrentRankLevel, '' CurrentRankStartDate, '' Has2YearsGrassrootsExp, '' AnnualAssessment2023, '' PersonCategory, '' SelectedFor2024 from m_s02 where rpt='2024' union all select ifnull(S0403,'') IDNumber, ifnull(S0401,'') Name, '' BirthDate, '' Gender, '' Ethnicity, '' WorkStartDate, '' PoliticalStatus, '' FullTimeEducation, ifnull(S0425,'') HighestEducation, '' HighestDegree, '' JobCategory, ifnull(S0404,'') CurrentPositionLevel, '' CurrentPositionStartDate, ifnull(S0405,'') CurrentRankLevel, '' CurrentRankStartDate, '' Has2YearsGrassrootsExp, '' AnnualAssessment2023, '' PersonCategory, '' SelectedFor2024 from m_s04 where rpt='2024'" + +// 存在所有对象信息 - 集合 +func main() { + + db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8") + fmt.Println("操作数据库连接:", db) + + // 创建临时文件夹 + dir := time.Now().Format("2006102150405") + file := fmt.Sprintf("对比结果-%s.xlsx", dir) + + peoplesJck := queryBySQL(db, SQLJck) + peoplesZjk := queryBySQL(db, SQLZjk) + peoplesGzk := queryBySQL(db, SQLGzk) + + results := mergeResults(peoplesJck, peoplesZjk, peoplesGzk) + + // 创建一个新的 Excel 文件 + f := excelize.NewFile() + sheetName := "Sheet1" + + // 设置表头 + 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.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) + } + + // 保存文件 + if err := f.SaveAs(file); err != nil { + fmt.Println("保存文件失败:", err) + } else { + fmt.Printf("文件已保存为 %s", file) + } + + fmt.Println("执行结束!") +} + +func queryBySQL(db *sql.DB, SQLJck string) []Person { + rows, err := db.Query(SQLJck) + if err != nil { + _ = fmt.Errorf("发生报错:%s", err) + } + defer func(rows *sql.Rows) { + err := rows.Close() + if err != nil { + fmt.Printf("错误") + } + }(rows) + + var people []Person + for rows.Next() { + var p Person + err := rows.Scan( + &p.IDNumber, + &p.Name, + &p.BirthDate, + &p.Gender, + &p.Ethnicity, + &p.WorkStartDate, + &p.PoliticalStatus, + &p.FullTimeEducation, + &p.HighestEducation, + &p.HighestDegree, + &p.JobCategory, + &p.CurrentPositionLevel, + &p.CurrentPositionStartDate, + &p.CurrentRankLevel, + &p.CurrentRankStartDate, + &p.Has2YearsGrassrootsExp, + &p.AnnualAssessment2023, + &p.PersonCategory, + &p.SelectedFor2024, + ) + if err != nil { + _ = fmt.Errorf("发生报错:%s", err) + } + people = append(people, p) + } + + if err = rows.Err(); err != nil { + _ = fmt.Errorf("发生报错:%s", err) + } + return people +} + +func mergeResults(peoplesJck, peoplesZjk, peoplesGzk []Person) []Diff { + jckMap := mapPersonToDiff(peoplesJck, "基础库") + zjkMap := mapPersonToDiff(peoplesZjk, "中间库") + gzkMap := mapPersonToDiff(peoplesGzk, "工资库") + + var diffs []Diff + + // 遍历所有可能的键 + allKeys := make(map[string]bool) + for key := range jckMap { + allKeys[key] = true + } + for key := range zjkMap { + allKeys[key] = true + } + for key := range gzkMap { + allKeys[key] = true + } + + for key := range allKeys { + idNumber := strings.Split(key, "_")[0] + name := strings.Split(key, "_")[1] + + // 获取每个属性的值 + for colName := range jckMap[key] { + if colName == "身份证号" || colName == "姓名" { + continue + } + if jckMap[key][colName] != zjkMap[key][colName] || + jckMap[key][colName] != gzkMap[key][colName] || + zjkMap[key][colName] != gzkMap[key][colName] { + diff := Diff{ + IDNumber: idNumber, + Name: name, + ColName: colName, + Jck: jckMap[key][colName], + Zjk: zjkMap[key][colName], + Gzk: gzkMap[key][colName], + } + diffs = append(diffs, diff) + } + } + } + + return diffs +} + +func mapPersonToDiff(people []Person, source string) map[string]map[string]string { + result := make(map[string]map[string]string) + for _, person := range people { + key := person.IDNumber + "_" + person.Name + if result[key] == nil { + result[key] = make(map[string]string) + } + result[key]["身份证号"] = person.IDNumber + result[key]["姓名"] = person.Name + result[key]["出生时间"] = person.BirthDate + result[key]["性别"] = person.Gender + result[key]["民族"] = person.Ethnicity + result[key]["参加工作时间"] = person.WorkStartDate + result[key]["政治面貌"] = person.PoliticalStatus + result[key]["全日制学历"] = person.FullTimeEducation + result[key]["最高学历"] = person.HighestEducation + result[key]["最高学位"] = person.HighestDegree + result[key]["职位类别"] = person.JobCategory + result[key]["现职务层次"] = person.CurrentPositionLevel + result[key]["任现职务层次时间"] = person.CurrentPositionStartDate + result[key]["现职级层次"] = person.CurrentRankLevel + result[key]["任现职级层次时间"] = person.CurrentRankStartDate + result[key]["是否具有2年以上基层经验"] = person.Has2YearsGrassrootsExp + result[key]["2023年度考核结果"] = person.AnnualAssessment2023 + result[key]["人员类别"] = person.PersonCategory + result[key]["2024年考录选调生"] = person.SelectedFor2024 + } + return result +} + +type Person struct { + IDNumber string // 身份证号 + Name string // 姓名 + BirthDate string // 出生时间 + Gender string // 性别 + Ethnicity string // 民族 + WorkStartDate string // 参加工作时间 + PoliticalStatus string // 政治面貌 + FullTimeEducation string // 全日制学历 + HighestEducation string // 最高学历 + HighestDegree string // 最高学位 + JobCategory string // 职位类别 + CurrentPositionLevel string // 现职务层次 + CurrentPositionStartDate string // 任现职务层次时间 + CurrentRankLevel string // 现职级层次 + CurrentRankStartDate string // 任现职级层次时间 + Has2YearsGrassrootsExp string // 是否具有2年以上基层经验 + AnnualAssessment2023 string // 2023年度考核结果 + PersonCategory string // 人员类别 + SelectedFor2024 string // 2024年考录选调生 +} + +type Diff struct { + IDNumber string `json:"身份证号"` // 身份证号 + Name string `json:"姓名"` // 姓名 + ColName string `json:"项名称"` // 项名称 + Jck string `json:"基础库"` // 基础库 + Zjk string `json:"中间库"` // 中间库 + Gzk string `json:"工资库"` // 工资库 +} diff --git a/golang_learn/data_office/get_hy_jctj/main.syso b/golang_learn/data_office/get_hy_jctj/main.syso new file mode 100644 index 0000000..b620536 Binary files /dev/null and b/golang_learn/data_office/get_hy_jctj/main.syso differ diff --git a/golang_learn/data_office/get_hy_jctj/rc.ico b/golang_learn/data_office/get_hy_jctj/rc.ico new file mode 100644 index 0000000..a06bf77 Binary files /dev/null and b/golang_learn/data_office/get_hy_jctj/rc.ico differ diff --git a/golang_learn/data_office/get_hy_jctj/网新辅助工具.md b/golang_learn/data_office/get_hy_jctj/网新辅助工具.md new file mode 100644 index 0000000..59833b0 --- /dev/null +++ b/golang_learn/data_office/get_hy_jctj/网新辅助工具.md @@ -0,0 +1,14 @@ +# 网新辅助工具 + + + +#### 实现数据备份和照片迁移 + + + +> 需要创建表 kk 存在四个字段 a,b,c,d 主要针对 d 字段。存储身份证号码? + + + +> 会生成数据压缩包,里面包裹着 sql 脚本,且照片信息可以直接进行粘贴覆盖 +