Просмотр исходного кода

"go fmt", updated Units.PrepareFormulars() and added TimesheetRows.GetStfCardIds()

Dmitry Yu Okunev лет назад: 6
Родитель
Сommit
e4403859b3
4 измененных файлов с 26 добавлено и 14 удалено
  1. 1 1
      formular.go
  2. 1 1
      person.go
  3. 10 2
      timesheet_row.go
  4. 14 10
      unit.go

+ 1 - 1
formular.go

@@ -182,7 +182,7 @@ func (formulars Formulars) GetEmpGUIDs() (empGUIDs []int) {
 	for _, formular := range formulars {
 		empGUIDMap[formular.EmpGUID] = true
 	}
-	for empGUID, _ := range empGUIDMap {
+	for empGUID := range empGUIDMap {
 		empGUIDs = append(empGUIDs, empGUID)
 	}
 

+ 1 - 1
person.go

@@ -123,7 +123,7 @@ func (people People) PrepareFormulars() People {
 		(*personMap[formular.EmpGUID]).formulars = append((*personMap[formular.EmpGUID]).formulars, formular)
 	}
 
-	for idx, _ := range people {
+	for idx := range people {
 		people[idx].formularsReady = true
 	}
 

+ 10 - 2
timesheet_row.go

@@ -109,7 +109,7 @@ func (timesheetRows TimesheetRows) GetEmpGUIDs() (empGUIDs []int) {
 	for _, timesheetRow := range timesheetRows {
 		empGUIDMap[timesheetRow.EmpGUID] = true
 	}
-	for empGUID, _ := range empGUIDMap {
+	for empGUID := range empGUIDMap {
 		empGUIDs = append(empGUIDs, empGUID)
 	}
 
@@ -134,7 +134,7 @@ func (timesheetRows TimesheetRows) PrepareFormulars(activeOnly bool) TimesheetRo
 		panic("Not implemented, yet")
 	}
 
-	for idx, _ := range timesheetRows {
+	for idx := range timesheetRows {
 		timesheetRows[idx].formularReady = true
 	}
 
@@ -148,3 +148,11 @@ func (timesheetRows TimesheetRows) GetFormulars() (formulars Formulars) {
 
 	return
 }
+
+func (timesheetRows TimesheetRows) GetStfCardIds() (stfCardIds []int) {
+	for _, timesheetRow := range timesheetRows {
+		stfCardIds = append(stfCardIds, timesheetRow.StfCardId)
+	}
+
+	return
+}

+ 14 - 10
unit.go

@@ -129,7 +129,7 @@ func (units Units) ToMap() map[int]*Unit {
 func (units Units) calculateTree(strict bool) {
 	unitMap := units.ToMap()
 
-	for idx, _ := range units {
+	for idx := range units {
 		unit := &units[idx]
 
 		if unit.ParentId == nil {
@@ -148,7 +148,7 @@ func (units Units) calculateTree(strict bool) {
 		parent.children = append(parent.children, unit)
 	}
 
-	for idx, _ := range units {
+	for idx := range units {
 		units[idx].childrenReady = true
 	}
 }
@@ -193,7 +193,7 @@ func (u *Unit) PrepareFormulars() *Unit {
 		u.formulars, err = FormularSQL.Select(Formular{UnitId: u.Id})
 	} else {
 		u.formulars, err = FormularSQL.Select(Formular{PersNumber: u.PersNumber})
-		for idx, _ := range u.formulars {
+		for idx := range u.formulars {
 			u.formulars[idx].UnitId = u.Id
 		}
 	}
@@ -220,7 +220,7 @@ func (u Unit) GetFormulars() Formulars {
 	return u.formulars
 }
 
-func (units Units) PrepareFormulars(activeOnly bool) Units {
+func (units Units) PrepareFormulars(activeOnly bool, additionalCondition ...interface{}) Units {
 	if len(units) == 0 {
 		return units
 	}
@@ -239,9 +239,13 @@ func (units Units) PrepareFormulars(activeOnly bool) Units {
 	}
 
 	if len(nums) > 0 {
-		scope  = scope.Where("PersNumber IN (?) OR OrgDiv IN (?)", nums, ids)
+		scope = scope.Where("PersNumber IN (?) OR OrgDiv IN (?)", nums, ids)
 	} else {
-		scope  = scope.Where("OrgDiv IN (?)", ids)
+		scope = scope.Where("OrgDiv IN (?)", ids)
+	}
+
+	if len(additionalCondition) > 0 {
+		scope = scope.Where(additionalCondition[0].(string), additionalCondition[1:]...)
 	}
 
 	formulars, err := scope.Select()
@@ -262,7 +266,7 @@ func (units Units) PrepareFormulars(activeOnly bool) Units {
 		(*unitPtr).formulars = append((*unitPtr).formulars, formular)
 	}
 
-	for idx, _ := range units {
+	for idx := range units {
 		units[idx].formularsReady = true
 	}
 
@@ -319,7 +323,7 @@ func (u *Unit) prepareChildrenTree(recursive bool) *Unit {
 		panic(err)
 	}
 
-	for idx, _ := range children {
+	for idx := range children {
 		child := &children[idx]
 		if recursive {
 			child.PrepareChildrenTree()
@@ -340,14 +344,14 @@ func (u *Unit) PrepareChildren() *Unit {
 }
 
 func (units Units) PrepareChildrenTree() Units {
-	for idx, _ := range units {
+	for idx := range units {
 		units[idx].PrepareChildrenTree()
 	}
 
 	return units
 }
 func (units Units) PrepareChildren() Units {
-	for idx, _ := range units {
+	for idx := range units {
 		units[idx].PrepareChildren()
 	}