Bläddra i källkod

Merge branch 'master' of http://git.daboryhost.com:10880/dabory/kkscrap-go

hakjinlee 1 år sedan
förälder
incheckning
96aca74838

+ 3 - 7
controllers/common-receiver-structs.go

@@ -1,12 +1,8 @@
 package controllers
 
-import (
-	"kkscrap-go/locals"
-)
-
-type CommonPageReq struct {
-	PageVars locals.PageVars
-}
+// type CommonPageReq struct {
+// 	PageVars locals.PageVars
+// }
 
 type SlipId struct {
 	SlipId int

+ 66 - 0
controllers/scraper/tct-main.go

@@ -2,10 +2,12 @@ package controllers_scraper
 
 import (
 	"encoding/json"
+	"fmt"
 	"kkscrap-go/controllers/scraper/cafe24"
 	"kkscrap-go/controllers/scraper/godo"
 	"kkscrap-go/controllers/scraper/magento"
 	"kkscrap-go/controllers/scraper/shopify"
+	"kkscrap-go/locals"
 
 	"kkscrap-go/controllers/scraper/wordpress"
 	"kkscrap-go/controllers/scraper/young"
@@ -22,6 +24,70 @@ import (
 	"github.com/labstack/echo"
 )
 
+type SolutionTypeGetReq struct {
+	Url string
+}
+
+func SolutionTypeGet(c echo.Context) error {
+
+	v := c.Get("receiver").(SolutionTypeGetReq)
+
+	retv := &struct {
+		SolutionType string
+		ThemeType    string
+	}{}
+
+	fmt.Println(v.Url)
+	// (1) function 공유될 수 있도록 해서 작업요
+	// v.SolutionType, v.ThemeType = solType(&kkk)
+	retv.SolutionType = "Wordpress"
+	retv.ThemeType = "Avada"
+	// ret, _ := json.MarshalIndent(itemInfo, "", "\t")
+	ret, _ := json.Marshal(retv)
+	return c.JSONBlob(http.StatusOK, ret)
+}
+
+type ProductPageGetReq struct {
+	SolutionType string
+	ThemeType    string
+	Products     []ProductUri
+}
+
+type ProductUri struct {
+	Uri string
+}
+
+// 오리지널 웹사이트 전체를 업테이트 하는 경우 Uri를 하나씩 보내면 비효율적이므로 하나의 배치로
+// 묶어서 요청할 수 있도록 한다. 주로 product-page-get를 쓰고 item-url-scrap은 deprecate 예정임.
+
+func ProductPageGet(c echo.Context) error {
+
+	v := c.Get("receiver").(ProductPageGetReq)
+
+	var vRet locals.ProductPage // Row(개별레코드)->Page(Row의 집합)->Book(Page의 집합)의 개념
+	for _, row := range v.Products {
+
+		// (1)Url 의 HTML를 2번 가져오는데 아래와 같이 1번만 가져와서 처리할 수 있도록 수정요.
+		// kkk := htmlGet(row.Uri)
+
+		// 전체 웹사이트가 아니라 개별 상품페이지(1개페이지)의 경우 SolutionType 없이 request됨
+		if v.SolutionType == "" {
+			// v.SolutionType, v.ThemeType = solType(&kkk)
+		}
+
+		prodInfo, err := parse(row.Uri)
+		if err != nil {
+			prodInfo.ItemNick = "Parsing Failed"
+		}
+		// 개별 prodInfo가 계속 추가될 수 있도록 코드를 변경요.
+		// vRet.ProductPage = append(vRet.ProductPage, *prodInfo)
+	}
+
+	// ret, _ := json.MarshalIndent(itemInfo, "", "\t")
+	ret, _ := json.Marshal(vRet)
+	return c.JSONBlob(http.StatusOK, ret)
+}
+
 type ItemUrlScrapReq struct {
 	ItemUrl string
 }

+ 0 - 31
locals/common-func.go

@@ -147,37 +147,6 @@ func (y *SyncController) Init() error {
 
 }
 
-func (t *PageVars) ChkPageVars(chk string) {
-
-	if t.Query == "" {
-		e.ChkLog(chk, "Query is empty")
-	}
-
-	if t.Fields == "" {
-		e.ChkLog(chk, "Fields is empty")
-	}
-
-	if t.Asc == "" {
-		e.ChkLog(chk, "Asc is empty")
-	}
-
-	if t.Desc == "" {
-		e.ChkLog(chk, "Desc is empty")
-	}
-
-	if t.Limit == 0 {
-		e.ChkLog(chk, "Limit is zero")
-	}
-
-	if t.Offset == 0 {
-		e.ChkLog(chk, "Offset is zero")
-	}
-
-	e.ChkLog(chk+", PageVars value is", *t)
-
-	return
-}
-
 type (
 	MemoryMap map[string]interface{}
 

+ 57 - 223
locals/structs.go

@@ -44,236 +44,70 @@ type ListFormBalanceVars struct {
 	EndCode    string
 }
 
-type CompanySearchVars struct {
-	CompanyName string
-	MainContact string
-	MobileNo    string
-	TelNo       string
-	OrderBy     string
-}
-
-type MediaSearchVars struct {
-	StartDate    string
-	EndDate      string
-	SlipNo       string
-	MediaName    string
-	FileName     string
-	LinkLocation string
-	Linked       string
-	NickName     string
-	BranchName   string
-	OrderBy      string
-}
-
-type ItemSearchVars struct {
-	IgroupId int
-	ItemCode string
-	ItemName string
-	SubName  string
-	OrderBy  string
-}
-
-type SlipSearchVars struct {
-	StartDate   string
-	EndDate     string
-	SlipNo      string
-	CompanyName string
-	ItemCode    string
-	QuerySpeed  string
-	OrderBy     string
-}
-
-type SlipSearchFields struct {
-	SlipDateField string
-	SlipNoField   string
-}
-
-type SingleVars struct {
-	QueryName string
-	Id        int
-}
-
-type SetupBase struct {
-	SetupCode string
-	SetupJson string
-}
-
-type QueryVars struct {
-	QueryName       string
-	FilterName      string
-	FilterValue     string
-	SimpleFilter    string
-	SubSimpleFilter string
-	IsntPagination  bool
-	TestMode        string
-}
-
-type SelectType1Vars struct {
-	ListToken string
-	NameValue string
-	// Str            []FilterBase
-	// Chk            []OptBase
-	// Rng            []RngBase
-	// Dec            []RngBase
-	// StrItem        []FilterBase
-	// ChkItem        []OptBase
-	// RngItem        []RngBase
-	// DecItem        []RngBase
-	Having         SelectFilters
-	Where          SelectFilters
-	IsDownloadList bool
-	Balance        string
-	OrderBy        string
-}
-
-type SelectFilters struct {
-	Prefix string
-	Str    []FilterBase
-	Chk    []OptBase
-	Rng    []RngBase
-	Dec    []RngBase
-}
-
-type OptBase struct {
-	Opt []FilterBase
-}
-
-type FilterBase struct {
-	FilterValue string
-}
-
-type RngBase struct {
-	FromValue string
-	ToValue   string
-}
-
-type PopupList1Vars struct {
-	PopupFilterName  string
-	PopupFilterValue string
-	SumFilterType    string // "" : Body/Sum 동시적용 1: Sum만 적용, 7: Filter OR SumFilter 로 둘다 적용, 8: OR 로 묶어 Sum만 적용
-	SumFilterName    string
-	SumFilterValue   string
-	SumSimpleFilter  string
-}
-
-type ListType1Vars struct {
-	ListToken string
-
-	FilterDate string
-	StartDate  string
-	EndDate    string
-
-	FilterFirst string
-	StartFirst  string
-	EndFirst    string
-
-	FilterSecond string
-	StartSecond  string
-	EndSecond    string
-
-	FilterThird string
-	StartThird  string
-	EndThird    string
-
-	FilterFourth string
-	StartFourth  string
-	EndFourth    string
-
-	IsAddTotalLine   bool
-	IsExcelColumn    bool
-	IsShowOnlyClosed bool
-	IsDownloadList   bool
-	IsntPageReturn   bool
-	IsTmpSqlUsed     bool
-	Balance          string
-	OrderBy          string
-
-	ListFilterName   string
-	ListFilterValue  string
-	ListSimpleFilter string
-
-	// SimpleFilter string
-
-	// SumFilterType   string // "" : Body/Sum 동시적용 1: Sum만 적용, 7: Filter OR SumFilter 로 둘다 적용, 8: OR 로 묶어 Sum만 적용
-	// SumFilterName   string
-	// SumFilterValue  string
-	// SumSimpleFilter string
-}
-
-type BodyCopyPageVars struct {
-	SlipNoField    string
-	SlipNo         string
-	ItemCode       string
-	CompanyName    string
-	ShowOnlyClosed string
-	Balance        string
-	DaysFromToday  string
-	OrderBy        string
-}
-
-type PageVars struct {
-	MyFilter   string
-	QueryCnt   int64
-	Query      string
-	Fields     string
-	Asc        string
-	Desc       string
-	Limit      int
-	Offset     int
-	ReturnJson string
-}
-
-type InputFieldJson struct {
-	StartDate  string
-	EndDate    string
-	Order      int
-	Select     int
-	QueryInput string
-}
-
-type Login struct {
-	UserId   string
-	Password string
-}
-
-// 3. Answer /////////////////////////////////////////////////////////////////
-type AnswerBase struct {
-	SvcSts string
-	SvcMsg string
-}
-
-type ActRowCom struct {
-	AnswerBase
-	IdBase
-}
-
-type ActPageCom struct {
-	AnswerBase
-	IdPageBase
-}
+// 2. Response  /////////////////////////////////////////////////////////////////
+
+type ProductPage struct {
+	SolutionType string
+	ThemeType    string
+	ProductPage  []Product
+}
+
+type Product struct {
+	SolutionName  SolutionType
+	Version       string
+	Emails        []string
+	DomainName    string
+	DomainURI     string
+	ItemName      string
+	ItemNick      string
+	ModelName     string
+	ModelNo       string
+	BrandName     string
+	Sku           string
+	ItemCategory  string
+	Manufacturer  string
+	Origin        string
+	Language      string
+	Currency      string
+	SalesPrice    float32
+	DeliveryPrice float32
+	MinimumQty    float32
+	UserCredit    float32
+	Options       []Option
+	Images        []string
+	ShortDesc     string
+	OriginDesc    string
+	TextDesc      string
+}
+
+type SolutionType string
+
+var (
+	SolutionTypeWooCommerce SolutionType = "WOOCOMMERCE"
+	SolutionTypeShopify     SolutionType = "SHOPIFY"
+	SolutionTypeMagento     SolutionType = "MAGENTO"
+	SolutionTypeCafe24      SolutionType = "CAFE24"
+	SolutionTypeGodo        SolutionType = "GODO"
+	SolutionTypeYoung       SolutionType = "YOUNG"
+	SolutionTypeOthers      SolutionType = "OTHERS"
+)
 
-type BodyCopyBase struct {
-	BdId int
-	Qty  string
+type Option struct {
+	Name    string
+	Choices []Choice
 }
 
-type IdBase struct {
-	Id int
+type Choice struct {
+	Name  string
+	Price float32
 }
 
-type IdPageBase struct {
-	Page []IdBase
+type Image struct {
+	Path   string
+	Width  int `json:"-"`
+	Height int `json:"-"`
 }
 
 type AbangoApp struct {
 	YDB *xorm.Engine
 }
-
-type InsertVars struct {
-	QueryName       string
-	InsertType      string
-	ListToken       string
-	IsTruncateTable bool
-	IsBackupTable   bool
-	IsBackupDb      bool
-}

+ 0 - 109
models/table/tmd-block.go

@@ -1,109 +0,0 @@
-package models_table
-
-import (
-	"errors"
-	"kkscrap-go/locals"
-
-	e "github.com/dabory/abango-rest/etc"
-)
-
-func (t *EthBlock) TableName() string { // 반드시 있어야 table name을 가져올 수 있다.
-	return e.TableName(*t)
-}
-
-func (t *EthBlock) RecordName() string { //필수
-	return "Id of " + e.NumToStr(t.Id) + " in " + e.TableName(*t) + " "
-}
-
-func (t *EthBlock) GetaRow(y *locals.SyncController) error {
-	if has, err := y.Db.Get(t); has == true {
-		e.RecRead("dfefefqef", t.RecordName())
-		return nil
-	} else {
-		if err == nil {
-			return errors.New(e.RecNotFound("wecasdfw", t.RecordName()))
-		} else {
-			return errors.New(e.RecReadErr("dsflkjfyfd", t.RecordName()+err.Error()))
-		}
-	}
-}
-
-func (t *EthBlock) AddaRow(y *locals.SyncController) error {
-	if affected, err := y.Db.Insert(t); affected == 1 && err == nil {
-		e.RecAdded("eradsfvzc", t.RecordName())
-		return nil
-	} else {
-		if err == nil {
-			return errors.New(e.RecNotAdded("cxzvfdfasd", t.RecordName()))
-		} else {
-			return errors.New(e.RecAddErr("jfhgkeytg", t.RecordName()+err.Error()))
-		}
-	}
-}
-
-func (t *EthBlock) EditaRow(y *locals.SyncController) error {
-
-	SyncEditaRowDefault(y, t)
-	if affected, err := SyncUpdateQry(y, t.Id).Update(t); affected == 1 && err == nil {
-		e.RecEdited("oiryhgsg", t.RecordName())
-		return nil
-	} else {
-		if err == nil { // 같은 컨텐츠의 경우 0 값을 리턴하면서 다음 레코드로 진행
-			e.RecNotEdited("liuytrgs", t.RecordName())
-			t.Id = 0
-			return nil // Error 아님
-		} else {
-			return errors.New(e.RecEditErr("petresfggs", t.RecordName()+err.Error()))
-		}
-	}
-}
-
-func (t *EthBlock) DelaRow(y *locals.SyncController) error {
-	if affected, err := y.Db.ID(t.Id).Delete(t); affected == 1 && err == nil {
-		e.RecDeleted("sdfwefavhk", t.RecordName())
-		return nil
-	} else {
-		if err == nil {
-			return errors.New(e.RecNotDeleted("lkdfgvfzv", t.RecordName())) // Error간주
-		} else {
-			return errors.New(e.RecDelErr("potuynbtr", t.RecordName()+err.Error()))
-		}
-	}
-}
-
-type BlockPageRet struct {
-	PageVars locals.PageVars
-	Page     []EthBlock
-}
-
-func (t *BlockPageRet) TableName() string {
-	return " Eth_Block "
-}
-
-func (t *BlockPageRet) RecordName() string { //필수
-	return "Id of " + e.NumToStr(t.TableName) + " in " + e.TableName(*t) + " "
-}
-
-func (t *BlockPageRet) GetPage(y *locals.SyncController) error {
-
-	qry := *y.Db.
-		Table("Eth_Block").
-		Where(t.PageVars.Query).
-		Cols(t.PageVars.Fields).
-		Limit(t.PageVars.Limit, t.PageVars.Offset)
-
-	if t.PageVars.Asc != "" {
-		qry = *qry.Asc(t.PageVars.Asc)
-	}
-	if t.PageVars.Desc != "" {
-		qry = *qry.Desc(t.PageVars.Desc)
-	}
-
-	if cnt, err := qry.FindAndCount(&t.Page); err == nil {
-		t.PageVars.QueryCnt = cnt
-		e.PageRead("qweopfgbjs", t.TableName())
-		return nil
-	} else {
-		return errors.New(e.PageQryErr("qreplhbdf", t.TableName()+err.Error()))
-	}
-}

+ 10 - 0
routers/init-a_router-func.go

@@ -91,6 +91,16 @@ func RestRouterInit(ask *abango.AbangoAsk) {
 				err = json.NewDecoder(r.Body).Decode(&v)
 				c.Set("receiver", v)
 
+			} else if uri == "/solution-type-get" {
+				var v controllers_scraper.SolutionTypeGetReq
+				err = json.NewDecoder(r.Body).Decode(&v)
+				c.Set("receiver", v)
+
+			} else if uri == "/product-page-get" {
+				var v controllers_scraper.ProductPageGetReq
+				err = json.NewDecoder(r.Body).Decode(&v)
+				c.Set("receiver", v)
+
 			} else { //!!주의 긴 string이 먼저나오게 지정할 것
 				if locals.HasPickActPage(uri, "dummydummy") {
 				} else {

+ 2 - 1
routers/init-func.go

@@ -7,7 +7,8 @@ import (
 
 func init() {
 
-	// Important 보안에 주의  할것
+	AddRoute(Route{[]string{"POST"}, "/product-page-get", controllers_scraper.ProductPageGet})
+	AddRoute(Route{[]string{"POST"}, "/solution-type-get", controllers_scraper.SolutionTypeGet})
 
 	AddRoute(Route{[]string{"POST"}, "/item-url-scrap", controllers_scraper.ItemUrlScrap})