Browse Source

增加输出类别

master
VIVIMAN 3 years ago
parent
commit
1956b58de0
  1. 32
      golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go
  2. 2
      golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go

32
golang_learn/data_func/go_to_excel/go_to_mc/query_all/main.go

@ -3,10 +3,12 @@ package main
import ( import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"github.com/360EntSecGroup-Skylar/excelize" "github.com/360EntSecGroup-Skylar/excelize"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"log" "log"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -16,17 +18,35 @@ const sheetName = `Sheet1`
const fileName = `公务员系统数据-` const fileName = `公务员系统数据-`
const fileType = `.xlsx` const fileType = `.xlsx`
const linkStr = `root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8` 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 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() { func main() {
flag.Parse()
if typeStr != "1" && typeStr != "0" {
log.Print("选择 输出表册 格式!")
return
}
db, _ := sql.Open("mysql", linkStr) db, _ := sql.Open("mysql", linkStr)
codes, headers, types, headWidth, err := getInit() codes, headers, types, headWidth, err := getInit()
if err { if err {
return return
} }
QueryMap(db, fmt.Sprintf(sqlStr, strings.Join(types, "','")), CodeValueMap) QueryMap(db, fmt.Sprintf(sqlCodeStr, strings.Join(types, "','")), CodeValueMap)
log.Print("输出内容:", headers) log.Print("输出内容:", headers)
log.Print("输出内容:", codes) log.Print("输出内容:", codes)
log.Print("输出内容:", len(CodeValueMap)) log.Print("输出内容:", len(CodeValueMap))
@ -179,7 +199,13 @@ func QueryB01(db *sql.DB) []*dept {
// QueryA01 获取人员信息 // QueryA01 获取人员信息
func QueryA01(db *sql.DB, codes string, types []string, b0111 string, allObj *[][]interface{}) { 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() defer rows.Close()
columns, _ := rows.Columns() columns, _ := rows.Columns()
columnsLen := len(columns) columnsLen := len(columns)

2
golang_learn/data_func/go_to_excel/makeExcel/sheet-merge/demo.go

@ -24,7 +24,7 @@ func main() {
var AllIndex int = 2 var AllIndex int = 2
var styleStr string = "" var styleStr string = ""
for _, sheetName := range sheetMap { for _, sheetName := range sheetMap {
rows, _ := f.GetRows(sheetName) rows := f.GetRows(sheetName)
rows: rows:
for rowIndex, row := range rows { for rowIndex, row := range rows {
//排除开始的标题行 //排除开始的标题行

Loading…
Cancel
Save