EricKIm 5 сар өмнө
parent
commit
1716dd806d
1 өөрчлөгдсөн 131 нэмэгдсэн , 56 устгасан
  1. 131 56
      controller.go

+ 131 - 56
controller.go

@@ -12,15 +12,14 @@ import (
 )
 
 func (c *Controller) Init() (int, string) {
-	status, msg := c.GetYDB()
-	return status, msg
-}
+	// status, msg := c.GetYDB()
+	// return status, msg
 
-func (c *Controller) GetYDB() (int, string) {
+	var gtb GateTokenBase
 
-	gtb := &struct {
-		GateTokenBase
-	}{}
+	// gtb := &struct {
+	// 	GateTokenBase
+	// }{}
 
 	var gtbStr string
 	var err error
@@ -40,40 +39,43 @@ func (c *Controller) GetYDB() (int, string) {
 		}
 
 	} else {
+		if c.GateToken == "" {
+			return 505, e.LogStr("QWCAFVD", "GateToken is Empty: ")
+		}
 		if gtbStr, err = MdbView(c.GateToken); err != nil {
-			// if c.ConnString, err = MdbView(c.GateToken); err != nil {
-			return 505, e.LogStr("QWFAECAFVD", "GateToken Not Found: "+c.GateToken)
+			return 505, e.LogStr("QWFAECD", "GateToken Not Found in MemoryDB: "+c.GateToken)
 		}
 
-		if err := json.Unmarshal([]byte(gtbStr), gtb); err == nil {
-			c.Gtb.ConnString = gtb.ConnString
-			c.Gtb.RemoteIp = gtb.RemoteIp
-			c.Gtb.DeviceDesc = gtb.DeviceDesc
-			c.Gtb.FrontIp = gtb.FrontIp
-			c.Gtb.FrontHost = gtb.FrontHost
-			c.Gtb.Referer = gtb.Referer
-			c.Gtb.SsoSubId = gtb.SsoSubId
-			c.Gtb.UserId = gtb.UserId
-			c.Gtb.UserPermId = gtb.UserPermId
-			c.Gtb.MemberId = gtb.MemberId
-			c.Gtb.MemberPermId = gtb.MemberPermId
-			c.Gtb.SgroupId = gtb.SgroupId
-			c.Gtb.BranchId = gtb.BranchId
-			c.Gtb.StorageId = gtb.StorageId
-			c.Gtb.AgroupId = gtb.AgroupId
-			c.Gtb.MemberBuyerId = gtb.MemberBuyerId
-			c.Gtb.MemberCompanyId = gtb.MemberCompanyId
-			c.Gtb.CompanySort = gtb.CompanySort
-			c.Gtb.SalesQtyPoint = gtb.SalesQtyPoint
-			c.Gtb.SalesPrcPoint = gtb.SalesPrcPoint
-			c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
-			c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
-			c.Gtb.PurchPrcPoint = gtb.PurchPrcPoint
-			c.Gtb.PurchAmtPoint = gtb.PurchAmtPoint
-			c.Gtb.StockQtyPoint = gtb.StockQtyPoint
-			c.Gtb.StockPrcPoint = gtb.StockPrcPoint
-			c.Gtb.StockAmtPoint = gtb.StockAmtPoint
-			c.Gtb.AccAmtPoint = gtb.AccAmtPoint
+		if err := json.Unmarshal([]byte(gtbStr), &gtb); err == nil {
+			c.Gtb = gtb
+			// c.Gtb.ConnString = gtb.ConnString
+			// c.Gtb.RemoteIp = gtb.RemoteIp
+			// c.Gtb.DeviceDesc = gtb.DeviceDesc
+			// c.Gtb.FrontIp = gtb.FrontIp
+			// c.Gtb.FrontHost = gtb.FrontHost
+			// c.Gtb.Referer = gtb.Referer
+			// c.Gtb.SsoSubId = gtb.SsoSubId
+			// c.Gtb.UserId = gtb.UserId
+			// c.Gtb.UserPermId = gtb.UserPermId
+			// c.Gtb.MemberId = gtb.MemberId
+			// c.Gtb.MemberPermId = gtb.MemberPermId
+			// c.Gtb.SgroupId = gtb.SgroupId
+			// c.Gtb.BranchId = gtb.BranchId
+			// c.Gtb.StorageId = gtb.StorageId
+			// c.Gtb.AgroupId = gtb.AgroupId
+			// c.Gtb.MemberBuyerId = gtb.MemberBuyerId
+			// c.Gtb.MemberCompanyId = gtb.MemberCompanyId
+			// c.Gtb.CompanySort = gtb.CompanySort
+			// c.Gtb.SalesQtyPoint = gtb.SalesQtyPoint
+			// c.Gtb.SalesPrcPoint = gtb.SalesPrcPoint
+			// c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
+			// c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
+			// c.Gtb.PurchPrcPoint = gtb.PurchPrcPoint
+			// c.Gtb.PurchAmtPoint = gtb.PurchAmtPoint
+			// c.Gtb.StockQtyPoint = gtb.StockQtyPoint
+			// c.Gtb.StockPrcPoint = gtb.StockPrcPoint
+			// c.Gtb.StockAmtPoint = gtb.StockAmtPoint
+			// c.Gtb.AccAmtPoint = gtb.AccAmtPoint
 		} else {
 			return 505, e.LogStr("QWFAEC1AFVDS", "AfterBase64Content Format mismatch: "+c.GateToken)
 		}
@@ -87,9 +89,82 @@ func (c *Controller) GetYDB() (int, string) {
 		return status, e.LogStr("PBUYJM-", msg)
 	}
 	return 200, ""
-
 }
 
+// func (c *Controller) GetYDB() (int, string) {
+
+// 	gtb := &struct {
+// 		GateTokenBase
+// 	}{}
+
+// 	var gtbStr string
+// 	var err error
+// 	if XConfig["IsYDBFixed"] == "Yes" {
+
+// 		data, err := ioutil.ReadFile("models/custom.yml")
+// 		if err != nil {
+// 			return 507, e.LogStr("ASDFQEWFA", "Can NOT Read custom.yml")
+// 		}
+
+// 		var config Config
+// 		if err := yaml.Unmarshal(data, &config); err == nil {
+// 			c.Gtb = config.Source
+// 			c.Gtb.ConnString = config.Source.ConnStr // custom.yml의 Variable name 이 서로 달라서 복사해줌.
+// 		} else {
+// 			return 507, e.LogStr("ASDWEWFA", "connString in custom.yml format mismatch ")
+// 		}
+
+// 	} else {
+// 		if gtbStr, err = MdbView(c.GateToken); err != nil {
+// 			// if c.ConnString, err = MdbView(c.GateToken); err != nil {
+// 			return 505, e.LogStr("QWFAECAFVD", "GateToken Not Found: "+c.GateToken)
+// 		}
+
+// 		if err := json.Unmarshal([]byte(gtbStr), gtb); err == nil {
+// 			c.Gtb.ConnString = gtb.ConnString
+// 			c.Gtb.RemoteIp = gtb.RemoteIp
+// 			c.Gtb.DeviceDesc = gtb.DeviceDesc
+// 			c.Gtb.FrontIp = gtb.FrontIp
+// 			c.Gtb.FrontHost = gtb.FrontHost
+// 			c.Gtb.Referer = gtb.Referer
+// 			c.Gtb.SsoSubId = gtb.SsoSubId
+// 			c.Gtb.UserId = gtb.UserId
+// 			c.Gtb.UserPermId = gtb.UserPermId
+// 			c.Gtb.MemberId = gtb.MemberId
+// 			c.Gtb.MemberPermId = gtb.MemberPermId
+// 			c.Gtb.SgroupId = gtb.SgroupId
+// 			c.Gtb.BranchId = gtb.BranchId
+// 			c.Gtb.StorageId = gtb.StorageId
+// 			c.Gtb.AgroupId = gtb.AgroupId
+// 			c.Gtb.MemberBuyerId = gtb.MemberBuyerId
+// 			c.Gtb.MemberCompanyId = gtb.MemberCompanyId
+// 			c.Gtb.CompanySort = gtb.CompanySort
+// 			c.Gtb.SalesQtyPoint = gtb.SalesQtyPoint
+// 			c.Gtb.SalesPrcPoint = gtb.SalesPrcPoint
+// 			c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
+// 			c.Gtb.SalesAmtPoint = gtb.SalesAmtPoint
+// 			c.Gtb.PurchPrcPoint = gtb.PurchPrcPoint
+// 			c.Gtb.PurchAmtPoint = gtb.PurchAmtPoint
+// 			c.Gtb.StockQtyPoint = gtb.StockQtyPoint
+// 			c.Gtb.StockPrcPoint = gtb.StockPrcPoint
+// 			c.Gtb.StockAmtPoint = gtb.StockAmtPoint
+// 			c.Gtb.AccAmtPoint = gtb.AccAmtPoint
+// 		} else {
+// 			return 505, e.LogStr("QWFAEC1AFVDS", "AfterBase64Content Format mismatch: "+c.GateToken)
+// 		}
+// 	}
+
+// 	if c.Db, err = xorm.NewEngine(XConfig["DbType"], c.Gtb.ConnString); err != nil {
+// 		return 600, e.LogStr("ADASEF", "DBEngine Open Error")
+// 	}
+
+// 	if status, msg := c.AttachDB(); status != 200 { // DB 까지 붙여야 memory error 가 안난다.
+// 		return status, e.LogStr("PBUYJM-", msg)
+// 	}
+// 	return 200, ""
+
+// }
+
 type Config struct {
 	// GateTokenDev string `yaml:"gate_token_dev"`
 	Source GateTokenBase
@@ -101,26 +176,26 @@ type Target struct {
 	OutputDir string `yaml:"output_dir"`
 }
 
-func (c *Controller) CustomYmlToGateTokenBaseAndDbGet() (int, string) {
-	data, err := ioutil.ReadFile("models/custom.yml")
-	if err != nil {
-		return 507, e.LogStr("ASDFQEWFA", "Can NOT Read custom.yml")
-	}
+// func (c *Controller) CustomYmlToGateTokenBaseAndDbGet() (int, string) {
+// 	data, err := ioutil.ReadFile("models/custom.yml")
+// 	if err != nil {
+// 		return 507, e.LogStr("ASDFQEWFA", "Can NOT Read custom.yml")
+// 	}
 
-	var config Config
-	if err := yaml.Unmarshal(data, &config); err == nil {
-		c.Gtb = config.Source
-		c.Gtb.ConnString = config.Source.ConnStr // custom.yml의 Variable name 이 서로 달라서 복사해줌.
-	} else {
-		return 507, e.LogStr("ASDWEWFA", "connString in custom.yml format mismatch ")
-	}
+// 	var config Config
+// 	if err := yaml.Unmarshal(data, &config); err == nil {
+// 		c.Gtb = config.Source
+// 		c.Gtb.ConnString = config.Source.ConnStr // custom.yml의 Variable name 이 서로 달라서 복사해줌.
+// 	} else {
+// 		return 507, e.LogStr("ASDWEWFA", "connString in custom.yml format mismatch ")
+// 	}
 
-	if status, msg := c.AttachDB(); status != 200 { // DB 까지 붙여야 memory error 가 안난다.
-		return status, e.LogStr("PBUYJM-", msg)
-	}
+// 	if status, msg := c.AttachDB(); status != 200 { // DB 까지 붙여야 memory error 가 안난다.
+// 		return status, e.LogStr("PBUYJM-", msg)
+// 	}
 
-	return 200, ""
-}
+// 	return 200, ""
+// }
 
 func (c *Controller) AttachDB() (int, string) {