diff --git a/golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go b/golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go index 0275b72..483106f 100644 --- a/golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go +++ b/golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go @@ -3,10 +3,12 @@ package main import ( "database/sql" "encoding/json" + "flag" "fmt" "github.com/360EntSecGroup-Skylar/excelize" _ "github.com/go-sql-driver/mysql" "log" + "os" "strconv" "strings" "time" @@ -16,17 +18,35 @@ const sheetName = `Sheet1` const fileName = `公务员系统数据-` const fileType = `.xlsx` const linkStr = `root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8` -const sqlStr = `SELECT concat(code_type,code_value),code_name FROM CODE_VALUE where code_type in('%s') union SELECT concat(code_type,code_value),code_name3 FROM CODE_VALUE where code_type='ZB01'` +const sqlCodeStr = `SELECT concat(code_type,code_value),code_name FROM CODE_VALUE where code_type in('%s') union SELECT concat(code_type,code_value),code_name3 FROM CODE_VALUE where code_type='ZB01'` var CodeValueMap = make(map[string]string) +var demoType = `1` + +var typeStr string + +func init() { + flag.CommandLine = flag.NewFlagSet("", flag.ExitOnError) + flag.CommandLine.Usage = func() { + fmt.Fprintf(os.Stderr, "参数说明:\n") + flag.PrintDefaults() + } + flag.StringVar(&typeStr, "t", demoType, "选择 输出表册 格式\n(0-按照职务输出生成、\n 1-按照主职务生成)\n") +} + func main() { + flag.Parse() + if typeStr != "1" && typeStr != "0" { + log.Print("选择 输出表册 格式!") + return + } db, _ := sql.Open("mysql", linkStr) codes, headers, types, headWidth, err := getInit() if err { return } - QueryMap(db, fmt.Sprintf(sqlStr, strings.Join(types, "','")), CodeValueMap) + QueryMap(db, fmt.Sprintf(sqlCodeStr, strings.Join(types, "','")), CodeValueMap) log.Print("输出内容:", headers) log.Print("输出内容:", codes) log.Print("输出内容:", len(CodeValueMap)) @@ -179,7 +199,13 @@ func QueryB01(db *sql.DB) []*dept { // QueryA01 获取人员信息 func QueryA01(db *sql.DB, codes string, types []string, b0111 string, allObj *[][]interface{}) { - rows, _ := db.Query(fmt.Sprintf(`select %s from a01 where a0163='1' and exists(select 1 from a02 a02 where a01.a0000=a02.a0000 and a0281='true' and a02.A0201B='%s') order by (select lpad(max(a0225),5,'0') from a02 where a01.a0000=a02.a0000 and a02.a0281='true' and a02.A0201B='%s')`, codes, b0111, b0111)) + var sql string + if typeStr == "1" { + sql = fmt.Sprintf(`select %s from a01 where a0163='1' and exists(select 1 from a02 a02 where a01.a0000=a02.a0000 and a0279='1' and A0201B='%s') order by (select lpad(max(a0225),5,'0') from a02 where a01.a0000=a02.a0000 and a0279='1' and A0201B='%s')`, codes, b0111, b0111) + } else { + sql = fmt.Sprintf(`select %s from a01 where a0163='1' and exists(select 1 from a02 a02 where a01.a0000=a02.a0000 and a0281='true' and A0201B='%s') order by (select lpad(max(a0225),5,'0') from a02 where a01.a0000=a02.a0000 and a0281='true' and A0201B='%s')`, codes, b0111, b0111) + } + rows, _ := db.Query(sql) defer rows.Close() columns, _ := rows.Columns() columnsLen := len(columns) diff --git a/golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go b/golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go index 6389b1c..357e062 100644 --- a/golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go +++ b/golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go @@ -24,7 +24,7 @@ func main() { var AllIndex int = 2 var styleStr string = "" for _, sheetName := range sheetMap { - rows, _ := f.GetRows(sheetName) + rows := f.GetRows(sheetName) rows: for rowIndex, row := range rows { //排除开始的标题行