bug fixed
This commit is contained in:
@@ -32,6 +32,11 @@ type BordroPageScript struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func (l *Luca) ErrFunc(index bool) {
|
||||
if index {
|
||||
CloseBrowser(l.Browser)
|
||||
}
|
||||
}
|
||||
func VerifyCaptcha(page *rod.Page) error {
|
||||
captcha := "#captcha"
|
||||
picturePreparation := []string{
|
||||
@@ -292,18 +297,11 @@ func (l *Luca) Login(company company.Company, month float64, year float64) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Wait(newPage, 500)
|
||||
|
||||
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) {
|
||||
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 {
|
||||
@@ -420,19 +418,14 @@ func (l *Luca) PayrollPageLogin() error {
|
||||
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")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
fs3, err := newPage.Element("#frm3")
|
||||
frame3, err := l.GetFrame(newPage, "#frm3")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame3, err := fs3.Frame()
|
||||
err = newPage.WaitLoad()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
isyeriId := ""
|
||||
bolumId := ""
|
||||
@@ -441,7 +434,7 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
|
||||
text, err := bordroCompanySelectBox[j].Text()
|
||||
value, err := bordroCompanySelectBox[j].Property("value")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if strings.Trim(text, " ") == b.Sube { //.Sube.Value
|
||||
isyeriId = value.String()
|
||||
@@ -452,28 +445,28 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
|
||||
element, err := frame3.Element("#isyeriId")
|
||||
element.WaitLoad()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
selectInput := Select{Element: element, Selector: "#isyeriId"}
|
||||
err = selectInput.SelectItem(isyeriId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = WaitLoad(frame3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
bordroDepartmentSelectBox, err := frame3.Elements("#bolumId > option")
|
||||
element, err = frame3.Element("#bolumId > option")
|
||||
element.WaitLoad()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
for j := 0; j < len(bordroDepartmentSelectBox); j++ {
|
||||
text, err := bordroDepartmentSelectBox[j].Text()
|
||||
value, err := bordroDepartmentSelectBox[j].Property("value")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if strings.Trim(text, " ") == b.Bolum { //.Bolum.Value
|
||||
bolumId = value.String()
|
||||
@@ -484,65 +477,61 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
|
||||
|
||||
element, err = frame3.Element("#bolumId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
selectInput = Select{Element: element, Selector: "#bolumId"}
|
||||
err = selectInput.SelectItem(bolumId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = WaitLoad(frame3)
|
||||
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ı
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = WaitLoad(frame3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
var isEmpty bool = false
|
||||
//var targetID string
|
||||
elems, err := frame3.Elements("#scroll > table > tbody > tr > td[id^='tcKimlikNo']")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
elemsProcess, err := frame3.Elements("#scroll > table > tbody > tr > td > a")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
trs, err := frame3.Elements("#scroll > table > tbody > tr")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
var foundIndex int = -1
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = WaitLoad(frame3)
|
||||
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++ {
|
||||
tex, err := elems[j].Text()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
process, err := elemsProcess[j].Text()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if tex == b.TcNo { //.TCKimlikNo.Value
|
||||
foundIndex = j
|
||||
@@ -554,20 +543,16 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
|
||||
fmt.Print(elems, tex)
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = WaitLoad(frame3)
|
||||
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 {
|
||||
|
||||
@@ -576,7 +561,7 @@ func (l *Luca) BordroYaz(month, year int, b *LucaBordro) ([]string, error) {
|
||||
Wait(newPage, 1500)
|
||||
err = WaitLoad(frame3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
saveButtonMessage, err := ReceiveDOMMessages(frame3, ".alert-container", "innerText")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
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.WaitLoad()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
newBordroPage.Click(proto.InputMouseButtonLeft, 1)
|
||||
err = WaitLoad(frame3)
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
|
||||
}
|
||||
return pageErrors, err
|
||||
l.ErrFunc(lastItem)
|
||||
return errors.New(saveButtonMessage)
|
||||
}
|
||||
|
||||
err = WaitLoad(frame3)
|
||||
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.WaitLoad()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
newBordroPage.Click(proto.InputMouseButtonLeft, 1)
|
||||
err = WaitLoad(frame3)
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return pageErrors, err
|
||||
l.ErrFunc(lastItem)
|
||||
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) {
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -77,6 +77,26 @@ func Wait(frm *rod.Page, millisecond time.Duration) {
|
||||
func CloseBrowser(browser *rod.Browser) {
|
||||
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 {
|
||||
// for i := 0; i < len(changeValue); i++ {
|
||||
|
||||
@@ -104,6 +104,7 @@ func (s *Srv) Rpa(companyName string, month float64, year float64) error {
|
||||
rows = rows[1:]
|
||||
}
|
||||
var insertMessage []string
|
||||
var lastItem bool = false
|
||||
// data := make([]*model.Bordro, 0) // []*Bordro türünde bir dilim oluştur
|
||||
for i := 1; i < len(rows); i++ {
|
||||
brd := &bot.LucaBordro{
|
||||
@@ -125,25 +126,25 @@ func (s *Srv) Rpa(companyName string, month float64, year float64) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message, err := b.BordroYaz(int(month), int(year), brd)
|
||||
if len(message) > 0 {
|
||||
insertMessage = append(insertMessage, message...)
|
||||
if i == len(rows)-1 {
|
||||
lastItem = true
|
||||
}
|
||||
err := b.BordroYaz(int(month), int(year), brd, lastItem)
|
||||
var str string
|
||||
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)
|
||||
|
||||
} else {
|
||||
str += "işlem başarılı, "
|
||||
emitLog(str)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if len(insertMessage) > 0 && err != nil {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
//emitLog(err.message)
|
||||
return err
|
||||
} else {
|
||||
emitLog("işlem başarılı")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user