bug fixed

This commit is contained in:
hysn99
2024-04-03 17:21:21 +03:00
parent 055ac013f9
commit 2913694585
3 changed files with 84 additions and 107 deletions

View File

@@ -32,6 +32,11 @@ type BordroPageScript struct {
Value string Value string
} }
func (l *Luca) ErrFunc(index bool) {
if index {
CloseBrowser(l.Browser)
}
}
func VerifyCaptcha(page *rod.Page) error { func VerifyCaptcha(page *rod.Page) error {
captcha := "#captcha" captcha := "#captcha"
picturePreparation := []string{ picturePreparation := []string{
@@ -292,18 +297,11 @@ func (l *Luca) Login(company company.Company, month float64, year float64) error
if err != nil { if err != nil {
return err return err
} }
Wait(newPage, 500)
return err return err
} }
func (l *Luca) GetPageByUrl(url string) (*rod.Page, error) {
allPages, err := l.Page.Browser().Pages()
if err != nil {
return nil, err
}
return allPages.FindByURL("https://auygs.luca.com.tr/Luca/luca.do")
}
func (l *Luca) BordroTableMaping(frame *rod.Page, b *LucaBordro) ([]BordroPageScript, error) { func (l *Luca) BordroTableMaping(frame *rod.Page, b *LucaBordro) ([]BordroPageScript, error) {
table, err := frame.Elements("#scroll > div > table > tbody > tr > td > table > tbody > tr > td") //table kontrol et var mı yok mu diye table, err := frame.Elements("#scroll > div > table > tbody > tr > td > table > tbody > tr > td") //table kontrol et var mı yok mu diye
if err != nil { if err != nil {
@@ -420,19 +418,14 @@ func (l *Luca) PayrollPageLogin() error {
return err return err
} }
func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) { func (l *Luca) BordroYaz(month, year int, b *LucaBordro, lastItem bool) error {
newPage, err := l.GetPageByUrl("https://auygs.luca.com.tr/Luca/luca.do") newPage, err := l.GetPageByUrl("https://auygs.luca.com.tr/Luca/luca.do")
if err != nil { if err != nil {
return nil, err return err
} }
fs3, err := newPage.Element("#frm3") frame3, err := l.GetFrame(newPage, "#frm3")
if err != nil { if err != nil {
return nil, err return err
}
frame3, err := fs3.Frame()
err = newPage.WaitLoad()
if err != nil {
return nil, err
} }
isyeriId := "" isyeriId := ""
bolumId := "" bolumId := ""
@@ -441,7 +434,7 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
text, err := bordroCompanySelectBox[j].Text() text, err := bordroCompanySelectBox[j].Text()
value, err := bordroCompanySelectBox[j].Property("value") value, err := bordroCompanySelectBox[j].Property("value")
if err != nil { if err != nil {
return nil, err return err
} }
if strings.Trim(text, " ") == b.Sube { //.Sube.Value if strings.Trim(text, " ") == b.Sube { //.Sube.Value
isyeriId = value.String() isyeriId = value.String()
@@ -452,28 +445,28 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
element, err := frame3.Element("#isyeriId") element, err := frame3.Element("#isyeriId")
element.WaitLoad() element.WaitLoad()
if err != nil { if err != nil {
return nil, err return err
} }
selectInput := Select{Element: element, Selector: "#isyeriId"} selectInput := Select{Element: element, Selector: "#isyeriId"}
err = selectInput.SelectItem(isyeriId) err = selectInput.SelectItem(isyeriId)
if err != nil { if err != nil {
return nil, err return err
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
bordroDepartmentSelectBox, err := frame3.Elements("#bolumId > option") bordroDepartmentSelectBox, err := frame3.Elements("#bolumId > option")
element, err = frame3.Element("#bolumId > option") element, err = frame3.Element("#bolumId > option")
element.WaitLoad() element.WaitLoad()
if err != nil { if err != nil {
return nil, err return err
} }
for j := 0; j < len(bordroDepartmentSelectBox); j++ { for j := 0; j < len(bordroDepartmentSelectBox); j++ {
text, err := bordroDepartmentSelectBox[j].Text() text, err := bordroDepartmentSelectBox[j].Text()
value, err := bordroDepartmentSelectBox[j].Property("value") value, err := bordroDepartmentSelectBox[j].Property("value")
if err != nil { if err != nil {
return nil, err return err
} }
if strings.Trim(text, " ") == b.Bolum { //.Bolum.Value if strings.Trim(text, " ") == b.Bolum { //.Bolum.Value
bolumId = value.String() bolumId = value.String()
@@ -484,65 +477,61 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
element, err = frame3.Element("#bolumId") element, err = frame3.Element("#bolumId")
if err != nil { if err != nil {
return nil, err return err
} }
selectInput = Select{Element: element, Selector: "#bolumId"} selectInput = Select{Element: element, Selector: "#bolumId"}
err = selectInput.SelectItem(bolumId) err = selectInput.SelectItem(bolumId)
if err != nil { if err != nil {
return nil, err return err
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
err = ClickItem(frame3, "#tr"+strconv.FormatFloat(float64(month), 'f', -1, 64)+" > td:nth-child(1)", 2) //aktarım ayı err = ClickItem(frame3, "#tr"+strconv.FormatFloat(float64(month), 'f', -1, 64)+" > td:nth-child(1)", 2) //aktarım ayı
if err != nil { if err != nil {
return nil, err return err
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
var isEmpty bool = false var isEmpty bool = false
//var targetID string //var targetID string
elems, err := frame3.Elements("#scroll > table > tbody > tr > td[id^='tcKimlikNo']") elems, err := frame3.Elements("#scroll > table > tbody > tr > td[id^='tcKimlikNo']")
if err != nil { if err != nil {
return nil, err return err
} }
elemsProcess, err := frame3.Elements("#scroll > table > tbody > tr > td > a") elemsProcess, err := frame3.Elements("#scroll > table > tbody > tr > td > a")
if err != nil { if err != nil {
return nil, err return err
} }
trs, err := frame3.Elements("#scroll > table > tbody > tr") trs, err := frame3.Elements("#scroll > table > tbody > tr")
if err != nil { if err != nil {
return nil, err return err
} }
var foundIndex int = -1 var foundIndex int = -1
if len(elems) == 0 { if len(elems) == 0 {
isEmptyError := errorInfo{
Error: "Böyle Bir Kullanıcı Bulunamadı",
Index: 1,
}
pageErrors = append(pageErrors, isEmptyError.Error+", Index: "+strconv.Itoa(isEmptyError.Index))
err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1) err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1)
if err != nil { if err != nil {
return nil, err return err
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
return pageErrors, err l.ErrFunc(lastItem)
return errors.New("Böyle Bir Kullanıcı Bulunamadı")
} }
for j := 0; j < len(elems); j++ { for j := 0; j < len(elems); j++ {
tex, err := elems[j].Text() tex, err := elems[j].Text()
if err != nil { if err != nil {
return nil, err return err
} }
process, err := elemsProcess[j].Text() process, err := elemsProcess[j].Text()
if err != nil { if err != nil {
return nil, err return err
} }
if tex == b.TcNo { //.TCKimlikNo.Value if tex == b.TcNo { //.TCKimlikNo.Value
foundIndex = j foundIndex = j
@@ -554,20 +543,16 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
fmt.Print(elems, tex) fmt.Print(elems, tex)
} }
if isEmpty == true { if isEmpty == true {
isEmptyError := errorInfo{
Error: "Yazılı Bordro Var Lütfen Siliniz",
Index: 1,
}
pageErrors = append(pageErrors, isEmptyError.Error+", Index: "+strconv.Itoa(isEmptyError.Index))
err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1) err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1)
if err != nil { if err != nil {
return nil, err return err
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
return pageErrors, err l.ErrFunc(lastItem)
return errors.New("Yazılı Bordro Var Lütfen Siliniz")
} }
if foundIndex != -1 && isEmpty == false { if foundIndex != -1 && isEmpty == false {
@@ -576,7 +561,7 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
Wait(newPage, 1500) Wait(newPage, 1500)
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
rsp, err := l.BordroTableMaping(frame3, b) rsp, err := l.BordroTableMaping(frame3, b)
@@ -591,7 +576,7 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
el, err := frame3.Element("#" + rsp[i].Index) el, err := frame3.Element("#" + rsp[i].Index)
if err != nil { if err != nil {
return nil, err return err
} }
err = el.Input(v.String()) err = el.Input(v.String())
} }
@@ -601,83 +586,54 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
} }
err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td.right > button", 1) err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td.right > button", 1)
if err != nil { if err != nil {
return nil, err return err
} }
saveButtonMessage, err := ReceiveDOMMessages(frame3, ".alert-container", "innerText") saveButtonMessage, err := ReceiveDOMMessages(frame3, ".alert-container", "innerText")
if err != nil { if err != nil {
return nil, err return err
} }
if saveButtonMessage != "Bordro hesaplanıyor." { if saveButtonMessage != "Bordro hesaplanıyor." {
isEmptyError := errorInfo{
Error: saveButtonMessage,
Index: 1,
}
pageErrors = append(pageErrors, isEmptyError.Error+", Index: "+strconv.Itoa(isEmptyError.Index))
newBordroPage, err := frame3.Element("body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(4)") newBordroPage, err := frame3.Element("body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(4)")
newBordroPage.WaitLoad() newBordroPage.WaitLoad()
if err != nil { if err != nil {
return nil, err return err
} }
newBordroPage.Click(proto.InputMouseButtonLeft, 1) newBordroPage.Click(proto.InputMouseButtonLeft, 1)
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1) err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1)
if err != nil { if err != nil {
return nil, err return err
} }
return pageErrors, err l.ErrFunc(lastItem)
return errors.New(saveButtonMessage)
} }
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
newBordroPage, err := frame3.Element("body > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(4)") newBordroPage, err := frame3.Element("body > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(4)")
newBordroPage.WaitLoad() newBordroPage.WaitLoad()
if err != nil { if err != nil {
return nil, err return err
} }
newBordroPage.Click(proto.InputMouseButtonLeft, 1) newBordroPage.Click(proto.InputMouseButtonLeft, 1)
err = WaitLoad(frame3) err = WaitLoad(frame3)
if err != nil { if err != nil {
return nil, err return err
} }
err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1) err = ClickItem(frame3, "body > form > table > tbody > tr.altBar.alt-button-bar > th > table > tbody > tr > td:nth-child(1) > button:nth-child(3)", 1)
if err != nil { if err != nil {
return nil, err return err
} }
l.ErrFunc(lastItem)
return pageErrors, err return err
} }
// CloseBrowser(l.Browser)
// func (l *Luca)pageInsert(data, b* model.PageStruct){
// }
//type Luca struct {
//}
//
//func NewLucaBot() *Luca {
// return &Luca{}
//}
//func (l *Luca) Login() error {
// return nil
//}
//func (l *Luca) NavigateBordroGiris() error {
// return nil
//}
//
//func (l *Luca) BordroYaz(b *model.Bordro) {
//
//}

View File

@@ -77,6 +77,26 @@ func Wait(frm *rod.Page, millisecond time.Duration) {
func CloseBrowser(browser *rod.Browser) { func CloseBrowser(browser *rod.Browser) {
browser.Close() browser.Close()
} }
func (l *Luca) GetPageByUrl(url string) (*rod.Page, error) {
allPages, err := l.Page.Browser().Pages()
if err != nil {
return nil, err
}
return allPages.FindByURL("https://auygs.luca.com.tr/Luca/luca.do")
}
func (l *Luca) GetFrame(page *rod.Page, selector string) (*rod.Page, error) {
err := page.WaitLoad()
if err != nil {
return nil, err
}
frm, err := page.Element(selector)
if err != nil {
return nil, err
}
frame, err := frm.Frame()
return frame, nil
}
// func (elemSelector *Select) MultipleEvalute(changeValue []string) error { // func (elemSelector *Select) MultipleEvalute(changeValue []string) error {
// for i := 0; i < len(changeValue); i++ { // for i := 0; i < len(changeValue); i++ {

View File

@@ -104,6 +104,7 @@ func (s *Srv) Rpa(companyName string, month float64, year float64) error {
rows = rows[1:] rows = rows[1:]
} }
var insertMessage []string var insertMessage []string
var lastItem bool = false
// data := make([]*model.Bordro, 0) // []*Bordro türünde bir dilim oluştur // data := make([]*model.Bordro, 0) // []*Bordro türünde bir dilim oluştur
for i := 1; i < len(rows); i++ { for i := 1; i < len(rows); i++ {
brd := &bot.LucaBordro{ brd := &bot.LucaBordro{
@@ -125,24 +126,24 @@ func (s *Srv) Rpa(companyName string, month float64, year float64) error {
} }
} }
} }
if i == len(rows)-1 {
message, err := b.BordroYaz(int(month), int(year), brd) lastItem = true
if len(message) > 0 {
insertMessage = append(insertMessage, message...)
} }
err := b.BordroYaz(int(month), int(year), brd, lastItem)
var str string
if err != nil { if err != nil {
fmt.Print(err) insertMessage = append(insertMessage, err.Error())
for _, v := range insertMessage {
str += "Şube : " + brd.Sube + "Bölüm : " + brd.Bolum + v + ", "
} }
emitLog(str)
}
if len(insertMessage) > 0 && err != nil {
return nil
}
if err != nil {
//emitLog(err.message)
return err
} else { } else {
emitLog("işlem başarılı") str += "işlem başarılı, "
emitLog(str)
}
} }
return nil return nil