|
|
@@ -1,12 +1,12 @@
|
|
|
package controller
|
|
|
|
|
|
import (
|
|
|
- "bswas/excel"
|
|
|
- "bswas/orm"
|
|
|
- "bswas/utilities"
|
|
|
- "encoding/json"
|
|
|
- "net/http"
|
|
|
- "strconv"
|
|
|
+ "bswas/excel"
|
|
|
+ "bswas/orm"
|
|
|
+ "bswas/utilities"
|
|
|
+ "encoding/json"
|
|
|
+ "net/http"
|
|
|
+ "strconv"
|
|
|
)
|
|
|
|
|
|
func Export(w http.ResponseWriter,req *http.Request) {
|
|
|
@@ -204,18 +204,24 @@ func selectModule(params map[string]string) (row []interface{}, list [][]interfa
|
|
|
if err != nil {
|
|
|
utilities.WriteLog("/api/controller/controller.go:205 参数传递错误!","ERROR")
|
|
|
}
|
|
|
+ if params["mergeColumn"] != ""{
|
|
|
+ err = json.Unmarshal([]byte(params["mergeColumn"]), &mergeColumn)
|
|
|
+ if err != nil {
|
|
|
+ utilities.WriteLog("/api/controller/controller.go:210 参数传递错误!","ERROR")
|
|
|
+ }
|
|
|
+ }
|
|
|
err = json.Unmarshal([]byte(params["rule"]), &rule)
|
|
|
if params["connection"] == "oracle" {
|
|
|
data = orm.GetOracleData(params["sql"])
|
|
|
}else{
|
|
|
data = orm.GetMysqlData(params["sql"])
|
|
|
}
|
|
|
- list = unifyFormat(data, column, rule)
|
|
|
+ list, mergeRow = unifyFormat(data, column, rule, params["datum"])
|
|
|
}
|
|
|
return row,list,mergeRow,mergeColumn
|
|
|
}
|
|
|
|
|
|
-func unifyFormat(data []map[string]string, row []string, rule map[string]string) [][]interface{}{
|
|
|
+func unifyFormat(data []map[string]string, row []string, rule map[string]string, datum string) ([][]interface{}, map[string]string){
|
|
|
rowLen := len(row)
|
|
|
column := make(map[string]int,rowLen)
|
|
|
for i,c := range row {
|
|
|
@@ -223,7 +229,26 @@ func unifyFormat(data []map[string]string, row []string, rule map[string]string)
|
|
|
}
|
|
|
|
|
|
list := make([][]interface{},len(data))
|
|
|
+ mergeRow := make(map[string]string)
|
|
|
+ var columnName string
|
|
|
+ var startIndex int
|
|
|
+ rowAmount := 0
|
|
|
for k,v := range data{
|
|
|
+ if datum != "" {
|
|
|
+ if columnName == v[datum] {
|
|
|
+ rowAmount++
|
|
|
+ }else{
|
|
|
+ if rowAmount != 0 {
|
|
|
+ mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
|
|
|
+ }
|
|
|
+ columnName = v[datum]
|
|
|
+ startIndex = k
|
|
|
+ rowAmount = 0
|
|
|
+ }
|
|
|
+ if rowAmount != 0 {
|
|
|
+ mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
|
|
|
+ }
|
|
|
+ }
|
|
|
line := make([]interface{},rowLen)
|
|
|
for key,value := range column {
|
|
|
if rule[key] != ""{
|
|
|
@@ -234,7 +259,7 @@ func unifyFormat(data []map[string]string, row []string, rule map[string]string)
|
|
|
}
|
|
|
list[k] = line
|
|
|
}
|
|
|
- return list
|
|
|
+ return list, mergeRow
|
|
|
}
|
|
|
|
|
|
func dataFormat(ruleType string,value string)string{
|
|
|
@@ -250,4 +275,4 @@ func dataFormat(ruleType string,value string)string{
|
|
|
}
|
|
|
}
|
|
|
return value
|
|
|
-}
|
|
|
+}
|