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

Started to implement Units' preparing of formulars using timesheet data

Dmitry Yu Okunev лет назад: 6
Родитель
Сommit
109eafee1e
2 измененных файлов с 31 добавлено и 4 удалено
  1. 29 2
      app/controllers/units.go
  2. 2 2
      app/init.go

+ 29 - 2
app/controllers/units.go

@@ -1,9 +1,11 @@
 package controllers
 
 import (
+	"database/sql"
 	renderModels "devel.mephi.ru/dyokunev/cps-models/for_render"
 	asuModels "devel.mephi.ru/dyokunev/go-asu-models"
 	"github.com/revel/revel"
+	"time"
 )
 
 type Units struct {
@@ -32,7 +34,7 @@ func (c Units) scope(unit asuModels.Unit, activeOnly bool, unhiddenOnly bool, re
 	return scope
 }
 
-func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, notEmptyOnly, setIfHasFormularsRecursive, prepareFormulars, showChildren, forceRecursiveChildren, preparePeople bool) revel.Result {
+func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, notEmptyOnly, setIfHasFormularsRecursive, prepareFormulars, showChildren, forceRecursiveChildren, preparePeople bool, startDate, endDate time.Time) revel.Result {
 	if r := c.Init(); r != nil {
 		return r
 	}
@@ -50,8 +52,33 @@ func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, no
 		return r
 	}
 
+	timesheetRowScope := c.TimesheetRowSQL.Scope().SetQueryFieldsByNames("StfCardId").SetTableQuery("`table` JOIN formular on StaffCardId = formular.StfCardId").Group("StaffCardId")
+
+	timesheetRowScope = timesheetRowScope.Where("PersNumber IN (?)", asuModels.Units(units).GetPersNumbers())
+
+	if (time.Time{}) != startDate {
+		timesheetRowScope = timesheetRowScope.Where("ADate > ?", startDate)
+	}
+	if (time.Time{}) != endDate {
+		timesheetRowScope = timesheetRowScope.Where("ADate < ?", endDate)
+	}
+
+	staffCardIdRows, err := timesheetRowScope.Select()
+	if err == sql.ErrNoRows {
+		return c.Render(renderModels.NewUnits(units))
+	}
+	if r := c.ConsiderErr(err); r != nil {
+		return r
+	}
+
 	if prepareFormulars {
-		asuModels.Units(units).PrepareFormulars(true)
+		stfCardIds := asuModels.TimesheetRows(staffCardIdRows).GetStfCardIds()
+		if len(stfCardIds) > 0 {
+			asuModels.Units(units).PrepareFormulars(false, "StfCardId IN (?)", asuModels.TimesheetRows(staffCardIdRows).GetStfCardIds())
+		} else {
+			// Just to set formularsReady to true:
+			asuModels.Units(units).PrepareFormulars(false, "0=1")
+		}
 	}
 	if preparePeople {
 		for idx, _ := range units {

+ 2 - 2
app/init.go

@@ -148,9 +148,9 @@ func getMysqlConnectionString(dbname_cfg string) string {
 
 	switch protocol {
 	case "tcp", "tcp6":
-		return fmt.Sprintf("%s:%s@%s([%s]:%s)/%s%s?parseTime=true&readTimeout=5s", user, pass, protocol, host, port, dbname, "")
+		return fmt.Sprintf("%s:%s@%s([%s]:%s)/%s%s?parseTime=true&readTimeout=30s", user, pass, protocol, host, port, dbname, "")
 	case "unix":
-		return fmt.Sprintf("%s:%s@%s(%s)/%s%s?parseTime=true&readTimeout=5s", user, pass, protocol, socket, dbname, "")
+		return fmt.Sprintf("%s:%s@%s(%s)/%s%s?parseTime=true&readTimeout=30s", user, pass, protocol, socket, dbname, "")
 	default:
 		revel.ERROR.Fatalf("This protocol is not supported: %v", protocol)
 	}