|
@@ -1,6 +1,7 @@
|
|
|
package importer
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"sync/atomic"
|
|
@@ -45,36 +46,53 @@ func NewODBCImporter() *ODBCImporter {
|
|
|
}
|
|
|
|
|
|
// 根据数据修正类定义
|
|
|
-func (odbci *ODBCImporter) ReviseClassStruct(data map[string]any) (err error) {
|
|
|
- e := odbci.createClass("cgitest", "/cgitest", nil)
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+func (odbci *ODBCImporter) ReviseClassStruct(data map[string]any) (classname string, err error) {
|
|
|
+ switch {
|
|
|
+ case data["uniqueId"] != nil:
|
|
|
+ classname = "/cgitest/x10/x1002"
|
|
|
+ case data["UNIQUEID"] != nil:
|
|
|
+ classname = "/cgitest/x10/x1001"
|
|
|
+ case data["FROMUNIQUEID"] != nil:
|
|
|
+ classname = "/cgitest/x10/x1003"
|
|
|
+ default:
|
|
|
+ bs, e := json.MarshalIndent(data, "", " ")
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = merrs.NewError("no mapping classname", merrs.SSMaps{{"data": string(bs)}})
|
|
|
}
|
|
|
- e = odbci.createClass("x10", "/cgitest/x10", nil)
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+
|
|
|
+ err = odbci.createClass("cgitest", "/cgitest", nil)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
- e = odbci.createClass("x1001", "/cgitest/x10/x1001", []*fieldinfo{
|
|
|
+ err = odbci.createClass("x10", "/cgitest/x10", nil)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = odbci.createClass("x1001", "/cgitest/x10/x1001", []*fieldinfo{
|
|
|
{fieldname: "uniqueid", datakey: "UNIQUEID", fieldtype: "varchar", keyidx: 1},
|
|
|
{fieldname: "distname", datakey: "BASENAME", fieldtype: "varchar"},
|
|
|
})
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
- e = odbci.createClass("x1002", "/cgitest/x10/x1002", []*fieldinfo{
|
|
|
+ err = odbci.createClass("x1002", "/cgitest/x10/x1002", []*fieldinfo{
|
|
|
{fieldname: "uniqueid", datakey: "uniqueId", fieldtype: "varchar", keyidx: 1},
|
|
|
{fieldname: "distname", datakey: "distName", fieldtype: "varchar"},
|
|
|
})
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
- e = odbci.createClass("x1003", "/cgitest/x10/x1003", []*fieldinfo{
|
|
|
+ err = odbci.createClass("x1003", "/cgitest/x10/x1003", []*fieldinfo{
|
|
|
{fieldname: "fromuniqueid", datakey: "FROMUNIQUEID", fieldtype: "varchar", keyidx: 1},
|
|
|
{fieldname: "touniqueid", datakey: "TOUNIQUEID", fieldtype: "varchar", keyidx: 2},
|
|
|
})
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -112,9 +130,24 @@ func (odbci *ODBCImporter) InsertData(classname string, data map[string]any) (er
|
|
|
func (odbci *ODBCImporter) done() {
|
|
|
odbci.classinfos.Fetch(func(cn string, ci *classinfo) bool {
|
|
|
ci.mutex.Lock()
|
|
|
- ci.lastlogtime = time.Now()
|
|
|
- ci.lastlogicount = ci.insertcount
|
|
|
- logger.Info("class", ci.classname, "import", ci.insertcount, "records")
|
|
|
+ if ci.lastlogicount != ci.insertcount {
|
|
|
+ ci.lastlogtime = time.Now()
|
|
|
+ ci.lastlogicount = ci.insertcount
|
|
|
+ logger.Info("class", ci.classname, "import", ci.insertcount, "records")
|
|
|
+ }
|
|
|
+ ci.mutex.Unlock()
|
|
|
+ return true
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (odbci *ODBCImporter) alldone() {
|
|
|
+ odbci.classinfos.Fetch(func(cn string, ci *classinfo) bool {
|
|
|
+ ci.mutex.Lock()
|
|
|
+ if ci.insertcount != 0 {
|
|
|
+ ci.lastlogtime = time.Now()
|
|
|
+ ci.lastlogicount = ci.insertcount
|
|
|
+ logger.Info("class", ci.classname, "import", ci.insertcount, "records")
|
|
|
+ }
|
|
|
ci.mutex.Unlock()
|
|
|
return true
|
|
|
})
|