Forráskód Böngészése

Вариативные часы

GhoosToy 5 éve
szülő
commit
c11001915a
4 módosított fájl, 80 hozzáadás és 24 törlés
  1. 7 2
      api/models.go
  2. 70 19
      api/studyplan.go
  3. 0 0
      log/Requests_URL.log
  4. 3 3
      settings/settings.go

+ 7 - 2
api/models.go

@@ -145,8 +145,13 @@ type Subjectofexample struct {
 	IDSubject     uint
 	IDExampleprogram     uint
 	Totalhours uint
-	Prefferedcourse string
+	Preferredcourse string
 	Labhours uint
 	Practicehours uint
 
-}
+}
+
+type VariateHours struct {
+		IDSubject uint
+		Freehours uint
+	}

+ 70 - 19
api/studyplan.go

@@ -6,10 +6,12 @@ import (
 	"fmt"
 	"net/http"
 	"strconv"
+	"strings"
 )
 
 var studyplan []Studyplan
 
+
 func StudyplanRoute(w http.ResponseWriter, r *http.Request) {
 	
 	showAPIRequest(r)
@@ -33,28 +35,39 @@ func StudyplanRoute(w http.ResponseWriter, r *http.Request) {
 		GetStudyPlan(w, r)
 		return
 	}
-	
-
-	num, err := strconv.Atoi(path)
-
-	if err != nil {
-		json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error"})
-		fmt.Println(err)
-		return
-	}
-	settings.DB.Find(&ScheduleOfGroups)
-	if num < 0 || num > len(ScheduleOfGroups)+1 {
-		json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error"})
-		fmt.Println(err)
-		return
-	}
 
-	if r.Method == "GET" {
+	if path != "" && strings.HasPrefix(path, "variative/") {
+    	path = replacePath(r.URL.Path, "/api/studyplan/variative/")
+    	groupnum, err := strconv.Atoi(path)
+	 	if err != nil {
+	 	json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error2"})
+	 	fmt.Println(err)
+	 	return
+		}
+    	VariativeHoursByGroup(w, r, groupnum)
+    } else {
+		path = replacePath(r.URL.Path, "/api/studyplan/")
+		num, err := strconv.Atoi(path)
+		if err != nil {
+			json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error1"})
+			fmt.Println(err)
+			return
+		}
+    
+		settings.DB.Find(&studyplan)
+		if num < 0 || num > len(studyplan)+1 {
+			json.NewEncoder(w).Encode(struct{ Error string }{Error: "strconv error3"})
+			fmt.Println(err)
+			return
+		}
+		
+		if r.Method == "GET" {
 		GetStudyPlanById(w, r, num)
 		return
-	}
-
-	json.NewEncoder(w).Encode(struct{ Error string }{Error: "This method is not supported"})
+		}
+		json.NewEncoder(w).Encode(struct{ Error string }{Error: "This method is not supported"})
+    }
+			
 }
 
 func UpdateStudyPlan(w http.ResponseWriter, r *http.Request) {
@@ -103,3 +116,41 @@ func GetStudyPlan(w http.ResponseWriter, r *http.Request) {
 	}
 	return
 }
+
+func VariativeHoursByGroup(w http.ResponseWriter, r *http.Request, groupnum int) {
+	var group Group
+	var StudyPlan Studyplan
+	var ExampleProgram Exampleprogram
+	var SubjectOfPlan []Subjectofplan
+	var opop []Subjectofexample
+	
+	// ишем id группы по ее номеру
+	settings.DB.Where("groupnumber = ?", groupnum).First(&group)
+	// нашли план обучения групы
+	 settings.DB.Where("id_group = ?", group.ID).First(&StudyPlan)
+	// // все предметы группы в ОПОП
+	 settings.DB.Where("id_specialty = ?", StudyPlan.IDSpecialty).First(&ExampleProgram)
+	 settings.DB.Where("id_exampleprogram = ?", ExampleProgram.ID).Find(&opop)
+	// // все предметы группы не в ОПОП
+	 settings.DB.Where("id_plan = ?", StudyPlan.ID).Find(&SubjectOfPlan)
+	
+	var vh VariateHours
+	var Variatehours []VariateHours
+	// //Вот тут ваще хз, проверь плез
+	  for i := range opop {
+	  	for j := range SubjectOfPlan {
+	  		//fmt.Println(opop[i].Totalhours, " -----> ",SubjectOfPlan[j].Hoursquantitytotal )
+	  		if opop[i].IDSubject == SubjectOfPlan[j].IDSubject {
+	 			//fmt.Println(opop[i].Totalhours, " -----> ",SubjectOfPlan[j].Hoursquantitytotal, "Sovpodaet" )
+	  			Freehours1 :=  opop[i].Totalhours - SubjectOfPlan[j].Hoursquantitytotal
+	  			IDSubject1 := opop[i].IDSubject
+	  			//fmt.Println(IDSubject1, " -----> IDSubject ",Freehours1, "-----> Freehours" )
+	  			vh = VariateHours{ IDSubject: IDSubject1, Freehours: Freehours1}
+	  			Variatehours= append(Variatehours, vh)
+	  			}
+	  		}
+	  	}
+	
+	json.NewEncoder(w).Encode(Variatehours) 
+	return
+	}

+ 0 - 0
log/Requests_URL.log


+ 3 - 3
settings/settings.go

@@ -7,9 +7,9 @@ var DB *gorm.DB
 const (
 	TimeLayout = "15:04"
 	dateLayout = ""
-	login      = "dbuser"
-	password   = "QWEasd123"
-	ipaddr     = "192.168.10.14"
+	login      = "root" //"dbuser"
+	password   = ""//"QWEasd123"
+	ipaddr     =  "127.0.0.1" //"192.168.10.14"
 	port       = "3306"
 	dbname     = "Schedule"
 	protocol   = "tcp"