// Code generated by xgo (XGo); DO NOT EDIT. package main import ( "encoding/json" "fmt" "github.com/go-yaml/yaml" "github.com/qiniu/x/errors" "github.com/qiniu/x/stringutil" "github.com/xuri/excelize/v2" "os" "strconv" ) const _ = true type Config struct { FileName string `yaml:"file"` SheetName string `yaml:"sheet"` StartRow int `yaml:"start"` Columns map[string]string `yaml:"columns"` } //line tsa.xgo:20:1 // Чтение конфига func readConfig() Config { //line tsa.xgo:22:1 f := func() (_xgo_ret *os.File) { //line tsa.xgo:22:1 var _xgo_err error //line tsa.xgo:22:1 _xgo_ret, _xgo_err = os.Open("tsa.yaml") //line tsa.xgo:22:1 if _xgo_err != nil { //line tsa.xgo:22:1 _xgo_err = errors.NewFrame(_xgo_err, "os.Open(\"tsa.yaml\")", "tsa.xgo", 22, "main.readConfig") //line tsa.xgo:22:1 panic(_xgo_err) } //line tsa.xgo:22:1 return }() //line tsa.xgo:23:1 defer f.Close() //line tsa.xgo:25:1 cfg := Config{} //line tsa.xgo:26:1 decoder := yaml.NewDecoder(f) //line tsa.xgo:27:1 func() { //line tsa.xgo:27:1 var _xgo_err error //line tsa.xgo:27:1 _xgo_err = decoder.Decode(&cfg) //line tsa.xgo:27:1 if _xgo_err != nil { //line tsa.xgo:27:1 _xgo_err = errors.NewFrame(_xgo_err, "decoder.Decode(&cfg)", "tsa.xgo", 27, "main.readConfig") //line tsa.xgo:27:1 panic(_xgo_err) } //line tsa.xgo:27:1 return }() //line tsa.xgo:28:1 return cfg } //line tsa.xgo:31:1 // Получаем все строки листа func readExcel(filename string, sheetname string) [][]string { //line tsa.xgo:33:1 f := func() (_xgo_ret *excelize.File) { //line tsa.xgo:33:1 var _xgo_err error //line tsa.xgo:33:1 _xgo_ret, _xgo_err = excelize.OpenFile(filename) //line tsa.xgo:33:1 if _xgo_err != nil { //line tsa.xgo:33:1 _xgo_err = errors.NewFrame(_xgo_err, "excelize.OpenFile(filename)", "tsa.xgo", 33, "main.readExcel") //line tsa.xgo:33:1 panic(_xgo_err) } //line tsa.xgo:33:1 return }() //line tsa.xgo:34:1 defer f.Close() //line tsa.xgo:36:1 rows := func() (_xgo_ret [][]string) { //line tsa.xgo:36:1 var _xgo_err error //line tsa.xgo:36:1 _xgo_ret, _xgo_err = f.GetRows(sheetname) //line tsa.xgo:36:1 if _xgo_err != nil { //line tsa.xgo:36:1 _xgo_err = errors.NewFrame(_xgo_err, "f.GetRows(sheetname)", "tsa.xgo", 36, "main.readExcel") //line tsa.xgo:36:1 panic(_xgo_err) } //line tsa.xgo:36:1 return }() //line tsa.xgo:37:1 return rows } //line tsa.xgo:40:1 func getColumnName(cols map[string]string, col int) string { //line tsa.xgo:41:1 if col < 1 || col > 21 { //line tsa.xgo:42:1 fmt.Println(stringutil.Concat(`Столбец: `, strconv.Itoa(col), ` вне диапазона столбцов`)) //line tsa.xgo:43:1 os.Exit(0) } //line tsa.xgo:46:1 type ColsMap struct { num int str string } //line tsa.xgo:50:1 colsmap := []string{" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U"} //line tsa.xgo:54:1 return cols[colsmap[col]] } //line tsa.xgo:57:1 func convert2int(s string) int64 { //line tsa.xgo:58:1 f := func() (_xgo_ret float64) { //line tsa.xgo:58:1 var _xgo_err error //line tsa.xgo:58:1 _xgo_ret, _xgo_err = strconv.ParseFloat(s, 64) //line tsa.xgo:58:1 if _xgo_err != nil { //line tsa.xgo:58:1 _xgo_err = errors.NewFrame(_xgo_err, "strconv.ParseFloat(s, 64)", "tsa.xgo", 58, "main.convert2int") //line tsa.xgo:58:1 panic(_xgo_err) } //line tsa.xgo:58:1 return }() //line tsa.xgo:59:1 n := int64(f) //line tsa.xgo:60:1 return n } //line tsa.xgo:63 // ====================== основная программа ==================== func main() { //line tsa.xgo:64:1 cfg := readConfig() //line tsa.xgo:65:1 rows := readExcel(cfg.FileName, cfg.SheetName) //line tsa.xgo:66:1 fmt.Println(stringutil.Concat("Всего ", strconv.Itoa(len(rows)), " строк")) //line tsa.xgo:68:1 var dbValues = []map[string]string{} for //line tsa.xgo:69:1 _, row := range rows[cfg.StartRow-1 : 2] { //line tsa.xgo:70:1 rowValues := make(map[string]string) for //line tsa.xgo:71:1 col, val := range row { //line tsa.xgo:72:1 colname := getColumnName(cfg.Columns, col+1) //line tsa.xgo:75:1 if colname == "caseId" || colname == "policyNumber" { //line tsa.xgo:76:1 val = fmt.Sprintf("%d", convert2int(val)) } //line tsa.xgo:80:1 if colname != "" { //line tsa.xgo:81:1 rowValues[colname] = val } //line tsa.xgo:83:1 fmt.Println(stringutil.Concat(strconv.Itoa(col), ` [`, colname, `]: `, val)) } //line tsa.xgo:86:1 dbValues = append(dbValues, rowValues) } //line tsa.xgo:90:1 b := func() (_xgo_ret []byte) { //line tsa.xgo:90:1 var _xgo_err error //line tsa.xgo:90:1 _xgo_ret, _xgo_err = json.Marshal(dbValues) //line tsa.xgo:90:1 if _xgo_err != nil { //line tsa.xgo:90:1 _xgo_err = errors.NewFrame(_xgo_err, "json.Marshal(dbValues)", "tsa.xgo", 90, "main.main") //line tsa.xgo:90:1 panic(_xgo_err) } //line tsa.xgo:90:1 return }() //line tsa.xgo:94:1 fmt.Println(string(b)) }