Browse Source

再次修改部分SQL报错问题::存在重复数数据取数问题

master
张献维 2 weeks ago
parent
commit
c81490e6c7
  1. 140
      golang_learn/data_office/get_hy_jctj/main.go
  2. 10
      golang_learn/data_office/get_hy_jctj/脚本.sql

140
golang_learn/data_office/get_hy_jctj/main.go

@ -24,20 +24,20 @@ select ifnull(A0184,'')IDNumber,
ifnull(substr(a0134, 1, 6),'') WorkStartDate, ifnull(substr(a0134, 1, 6),'') WorkStartDate,
ifnull((select min(code_name) from code_value where A0141=code_value and code_type='GB4762'),'') PoliticalStatus, ifnull((select min(code_name) from code_value where A0141=code_value and code_type='GB4762'),'') PoliticalStatus,
ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end
from A08 where A0831=1 and A01.A0000=A08.A0000), '') FullTimeEducation, from A08 where A0831=1 and A01.A0000=A08.A0000 limit 1), '') FullTimeEducation,
ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end
from A08 where A0834=1 and A01.A0000=A08.A0000), '') HighestEducation, from A08 where A0834=1 and A01.A0000=A08.A0000 limit 1), '') HighestEducation,
ifnull((select case when A0901B like '3%' then '硕士' when A0901B like '4%' then '学士' else '博士' end from A08 where A0835=1 and A01.A0000=A08.A0000), '') HighestDegree, ifnull((select case when A0901B like '3%' then '硕士' when A0901B like '4%' then '学士' else '博士' end from A08 where A0835=1 and A01.A0000=A08.A0000 limit 1), '') HighestDegree,
ifnull((select min(code_name) from code_value where A0123=code_value and code_type='XZ93'),'') JobCategory, ifnull((select min(code_name) from code_value where A0123=code_value and code_type='XZ93'),'') JobCategory,
ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB09' and A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionLevel, ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB09' and A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionLevel,
ifnull((select substr(A0504, 1, 6) from A05 where A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionStartDate, ifnull((select substr(A0504, 1, 6) from A05 where A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') CurrentPositionStartDate,
ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB148' and A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentRankLevel, ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB148' and A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentRankLevel,
ifnull((select ifnull(DATE_FORMAT(DATE_ADD(concat(substr(A0530, 1, 4),'-',substr(A0530, 5, 2),'-01'), INTERVAL ifnull(A0532, 0) MONTH), '%Y%m'), ifnull((select ifnull(DATE_FORMAT(DATE_ADD(concat(substr(A0530, 1, 4),'-',substr(A0530, 5, 2),'-01'), INTERVAL ifnull(A0532, 0) MONTH), '%Y%m'),
ifnull(substr(A0504, 1, 6), '')) from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') CurrentRankStartDate, ifnull(substr(A0504, 1, 6), '')) from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000 limit 1), '') CurrentRankStartDate,
IF(A0197 = 1, '是', '否') Has2YearsGrassrootsExp, 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 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 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), '否') SelectedFor2024 ifnull((select '是' from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '2024%' and A01.A0000=A99Z1.A0000 limit 1), '否') SelectedFor2024
from A01 from A01
where A0163 = '1' where A0163 = '1'
` `
@ -306,62 +306,96 @@ func queryByCzSQL(db *sql.DB, SQLCz string) []CzPerson {
mergeResults 基础人员对比 mergeResults 基础人员对比
*/ */
func mergeResults(peoplesJck, peoplesZjk, peoplesGzk []Person) []Diff { func mergeResults(peoplesJck, peoplesZjk, peoplesGzk []Person) []Diff {
jckMap := mapPersonToDiff(peoplesJck, "基础库") jckMap := mapPersonToDiff(peoplesJck)
zjkMap := mapPersonToDiff(peoplesZjk, "中间库") zjkMap := mapPersonToDiff(peoplesZjk)
gzkMap := mapPersonToDiff(peoplesGzk, "工资库") gzkMap := mapPersonToDiff(peoplesGzk)
var diffs []Diff var diffs []Diff
// 遍历所有可能的键 // 遍历所有可能的键
allKeys := make(map[string]bool) allKeys, nl := make(map[string]int), make(map[string]map[string]string)
for key := range jckMap { for key := range jckMap {
allKeys[key] = true allKeys[key] += 4
} }
for key := range zjkMap { for key := range zjkMap {
allKeys[key] = true allKeys[key] += 2
} }
for key := range gzkMap { for key := range gzkMap {
allKeys[key] = true allKeys[key] += 1
} }
for key := range allKeys { for key := range allKeys {
idNumber := strings.Split(key, "_")[0] idNumber := strings.Split(key, "_")[0]
name := strings.Split(key, "_")[1] name := strings.Split(key, "_")[1]
// 获取每个属性的值 if allKeys[key] == 1 {
for colName := range jckMap[key] { // 全部存在 基础
if colName == "身份证号" || colName == "姓名" { diffs = setDiffs(gzkMap, key, nl, nl, gzkMap, idNumber, name, diffs)
continue } else if allKeys[key] == 2 {
} // 全部存在 中间
var diff Diff diffs = setDiffs(zjkMap, key, nl, zjkMap, nl, idNumber, name, diffs)
if gzMap[colName] { } else if allKeys[key] == 3 {
// 指定需要注意工资部分 // 全部存在 中间 + 工资
if jckMap[key][colName] != zjkMap[key][colName] || diffs = setDiffs(zjkMap, key, nl, zjkMap, gzkMap, idNumber, name, diffs)
jckMap[key][colName] != gzkMap[key][colName] || } else if allKeys[key] == 4 {
zjkMap[key][colName] != gzkMap[key][colName] { // 全部存在 基础
diff = Diff{ diffs = setDiffs(jckMap, key, jckMap, nl, nl, idNumber, name, diffs)
IDNumber: idNumber, } else if allKeys[key] == 5 {
Name: name, // 全部存在 基础 + 工资
ColName: colName, diffs = setDiffs(jckMap, key, jckMap, nl, gzkMap, idNumber, name, diffs)
Jck: jckMap[key][colName], } else if allKeys[key] == 6 {
Zjk: zjkMap[key][colName], // 全部存在 基础 + 中间
Gzk: gzkMap[key][colName], diffs = setDiffs(zjkMap, key, jckMap, zjkMap, nl, idNumber, name, diffs)
} } else {
diffs = append(diffs, diff) // 全部存在 基础 + 中间 + 工资
diffs = setDiffs(jckMap, key, jckMap, zjkMap, gzkMap, idNumber, name, diffs)
}
}
return diffs
}
func setDiffs(
oneMap map[string]map[string]string,
key string,
jckMap map[string]map[string]string,
zjkMap map[string]map[string]string,
gzkMap map[string]map[string]string,
idNumber string,
name string,
diffs []Diff) []Diff {
for colName := range oneMap[key] {
if colName == "身份证号" || colName == "姓名" {
continue
}
var diff Diff
if gzMap[colName] {
// 指定需要注意工资部分
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],
} }
} else { diffs = append(diffs, diff)
// 需要公共比较 }
if jckMap[key][colName] != zjkMap[key][colName] { } else {
diff = Diff{ // 需要公共比较
IDNumber: idNumber, if jckMap[key][colName] != zjkMap[key][colName] {
Name: name, diff = Diff{
ColName: colName, IDNumber: idNumber,
Jck: jckMap[key][colName], Name: name,
Zjk: zjkMap[key][colName], ColName: colName,
Gzk: gzkMap[key][colName], Jck: jckMap[key][colName],
} Zjk: zjkMap[key][colName],
diffs = append(diffs, diff) Gzk: gzkMap[key][colName],
} }
diffs = append(diffs, diff)
} }
} }
} }
@ -373,8 +407,8 @@ func mergeResults(peoplesJck, peoplesZjk, peoplesGzk []Person) []Diff {
mergeCzResults 辞职人员对比 mergeCzResults 辞职人员对比
*/ */
func mergeCzResults(peoplesCzk, peoplesBhb []CzPerson) []Diff { func mergeCzResults(peoplesCzk, peoplesBhb []CzPerson) []Diff {
jckMap := mapCzPersonToDiff(peoplesCzk, "辞职库") jckMap := mapCzPersonToDiff(peoplesCzk)
zjkMap := mapCzPersonToDiff(peoplesBhb, "辞职表") zjkMap := mapCzPersonToDiff(peoplesBhb)
var diffs []Diff var diffs []Diff
@ -436,7 +470,7 @@ func init() {
/* /*
mapPersonToDiff 基础查询对比 mapPersonToDiff 基础查询对比
*/ */
func mapPersonToDiff(people []Person, source string) map[string]map[string]string { func mapPersonToDiff(people []Person) map[string]map[string]string {
result := make(map[string]map[string]string) result := make(map[string]map[string]string)
for _, person := range people { for _, person := range people {
key := person.IDNumber + "_" + person.Name key := person.IDNumber + "_" + person.Name
@ -469,7 +503,7 @@ func mapPersonToDiff(people []Person, source string) map[string]map[string]strin
/* /*
mapCzPersonToDiff 辞职查询对比 mapCzPersonToDiff 辞职查询对比
*/ */
func mapCzPersonToDiff(people []CzPerson, source string) map[string]map[string]string { func mapCzPersonToDiff(people []CzPerson) map[string]map[string]string {
result := make(map[string]map[string]string) result := make(map[string]map[string]string)
for _, person := range people { for _, person := range people {
key := person.IDNumber + "_" + person.Name key := person.IDNumber + "_" + person.Name
@ -485,6 +519,16 @@ func mapCzPersonToDiff(people []CzPerson, source string) map[string]map[string]s
return result return result
} }
func Eq(a, b *string) bool {
if *a == "" {
a = nil
}
if *b == "" {
a = nil
}
return a == b
}
type Person struct { type Person struct {
IDNumber string // 身份证号 IDNumber string // 身份证号
Name string // 姓名 Name string // 姓名

10
golang_learn/data_office/get_hy_jctj/脚本.sql

@ -79,19 +79,19 @@ select
ifnull(substr(a0134, 1, 6),'') , ifnull(substr(a0134, 1, 6),'') ,
ifnull((select min(code_name) from code_value where A0141=code_value and code_type='GB4762'),'') , ifnull((select min(code_name) from code_value where A0141=code_value and code_type='GB4762'),'') ,
ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end
from A08 where A0831=1 and A01.A0000=A08.A0000), '') , from A08 where A0831=1 and A01.A0000=A08.A0000 limit 1), '') ,
ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end ifnull((select case when A0801B like '1%' then '研究生' when A0801B like '2%' then '大学本科' when A0801B like '3%' then '大学专科' else '中专及以下' end
from A08 where A0834=1 and A01.A0000=A08.A0000), '') , from A08 where A0834=1 and A01.A0000=A08.A0000 limit 1), '') ,
ifnull((select case when A0901B like '3%' then '硕士' when A0901B like '4%' then '学士' else '博士' end from A08 where A0835=1 and A01.A0000=A08.A0000), '') , ifnull((select case when A0901B like '3%' then '硕士' when A0901B like '4%' then '学士' else '博士' end from A08 where A0835=1 and A01.A0000=A08.A0000 limit 1), '') ,
ifnull((select min(code_name) from code_value where A0123=code_value and code_type='XZ93'),'') , ifnull((select min(code_name) from code_value where A0123=code_value and code_type='XZ93'),'') ,
ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB09' and A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') , ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB09' and A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') ,
ifnull((select substr(A0504, 1, 6) from A05 where A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') , ifnull((select substr(A0504, 1, 6) from A05 where A0531=0 and A0524=1 and A01.A0000=A05.A0000), '') ,
ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB148' and A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') , ifnull((select min(code_name) from A05, code_value where A0501B=code_value and code_type='ZB148' and A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') ,
ifnull((select ifnull(DATE_FORMAT(DATE_ADD(concat(substr(A0530, 1, 4),'-',substr(A0530, 5, 2),'-01'), INTERVAL ifnull(A0532, 0) MONTH), '%Y%m'), ifnull((select ifnull(DATE_FORMAT(DATE_ADD(concat(substr(A0530, 1, 4),'-',substr(A0530, 5, 2),'-01'), INTERVAL ifnull(A0532, 0) MONTH), '%Y%m'),
ifnull(substr(A0504, 1, 6), '')) from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000), '') , ifnull(substr(A0504, 1, 6), '')) from A05 where A0531=1 and A0524=1 and A01.A0000=A05.A0000 limit 1), '') ,
IF(A0197 = 1, '', '') 2, IF(A0197 = 1, '', '') 2,
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), '') 2023, 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), '') 2023,
ifnull((select min(code_name) from code_value where A0160=code_value and code_type='ZB125'),'') , ifnull((select min(code_name) from code_value where A0160=code_value and code_type='ZB125'),'') ,
ifnull((select '' from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '2024%' and A01.A0000=A99Z1.A0000), '') 2024 ifnull((select '' from A99Z1 where A99Z101=1 and A99Z103=1 and A99Z102 like '2024%' and A01.A0000=A99Z1.A0000 limit 1), '') 2024
from A01 where A0163='1'; from A01 where A0163='1';

Loading…
Cancel
Save