浏览代码

修改bug

yjp 1 年之前
父节点
当前提交
95ff039733
共有 3 个文件被更改,包括 50 次插入46 次删除
  1. 13 11
      convenient/relation/one2many/service.go
  2. 13 11
      convenient/relation/one2one/service.go
  3. 24 24
      examples/examples/project/main.go

+ 13 - 11
convenient/relation/one2many/service.go

@@ -388,18 +388,20 @@ func QueryRightWithLeftInfo[RI any, LI any](rightTableName string, rightRelation
 			}
 		}
 
-		leftResults, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
-			TableName:  leftTableName,
-			Conditions: sql.NewConditions().In(entity.ColumnID, leftIDs),
-		})
-		if err != nil {
-			return errResponse, err
-		}
-
 		leftResultMap := make(map[string]sql.Result)
-		for _, leftResult := range leftResults {
-			leftID := leftResult.ColumnValueString(entity.ColumnID)
-			leftResultMap[leftID] = leftResult
+		if leftIDs != nil && len(leftIDs) != 0 {
+			leftResults, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
+				TableName:  leftTableName,
+				Conditions: sql.NewConditions().In(entity.ColumnID, leftIDs),
+			})
+			if err != nil {
+				return errResponse, err
+			}
+
+			for _, leftResult := range leftResults {
+				leftID := leftResult.ColumnValueString(entity.ColumnID)
+				leftResultMap[leftID] = leftResult
+			}
 		}
 
 		infos := make([]map[string]any, len(rightResults))

+ 13 - 11
convenient/relation/one2one/service.go

@@ -268,18 +268,20 @@ func QueryWithOtherInfo[FI any, TI any](fromTableName string, fromRelationColumn
 			}
 		}
 
-		toResults, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
-			TableName:  toTableName,
-			Conditions: sql.NewConditions().In(entity.ColumnID, toIDs),
-		})
-		if err != nil {
-			return errResponse, err
-		}
-
 		toResultMap := make(map[string]sql.Result)
-		for _, toResult := range toResults {
-			toID := toResult.ColumnValueString(entity.ColumnID)
-			toResultMap[toID] = toResult
+		if toIDs != nil && len(toIDs) != 0 {
+			toResults, _, err := database.Query(dbExecutor, &sql.QueryExecuteParams{
+				TableName:  toTableName,
+				Conditions: sql.NewConditions().In(entity.ColumnID, toIDs),
+			})
+			if err != nil {
+				return errResponse, err
+			}
+
+			for _, toResult := range toResults {
+				toID := toResult.ColumnValueString(entity.ColumnID)
+				toResultMap[toID] = toResult
+			}
 		}
 
 		infos := make([]map[string]any, len(fromResults))

+ 24 - 24
examples/examples/project/main.go

@@ -16,24 +16,24 @@ import (
 
 // Class
 // curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:31000/example/v1/class/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"ed3f9cffdcfe4984ac72425b447b7ce6", "name":"test-new"}' "http://localhost:31000/example/v1/class/update"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"e4a3d4474e4e4469b54bf9d41e649bf4", "name":"test-new"}' "http://localhost:31000/example/v1/class/update"
 // curl -X GET "http://localhost:31000/example/v1/class/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:31000/example/v1/class/get?id=ed3f9cffdcfe4984ac72425b447b7ce6"
-// curl -X DELETE "http://localhost:31000/example/v1/class/ed3f9cffdcfe4984ac72425b447b7ce6/delete"
+// curl -X GET "http://localhost:31000/example/v1/class/get?id=e4a3d4474e4e4469b54bf9d41e649bf4"
+// curl -X DELETE "http://localhost:31000/example/v1/class/e4a3d4474e4e4469b54bf9d41e649bf4/delete"
 
 // Student
 // curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/v1/student/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"6e12ee71397746b8920fa94e5f229366", "name":"test-new"}' "http://localhost:31000/example/v1/student/update"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"fbee72deb9634497847620881eed995e", "name":"test-new"}' "http://localhost:31000/example/v1/student/update"
 // curl -X GET "http://localhost:31000/example/v1/student/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:31000/example/v1/student/get?id=6e12ee71397746b8920fa94e5f229366"
-// curl -X DELETE "http://localhost:31000/example/v1/student/6e12ee71397746b8920fa94e5f229366/delete"
+// curl -X GET "http://localhost:31000/example/v1/student/get?id=fbee72deb9634497847620881eed995e"
+// curl -X DELETE "http://localhost:31000/example/v1/student/fbee72deb9634497847620881eed995e/delete"
 
 // Family
 // curl -X POST -H "Content-Type: application/json" -d '{"father":"father", "mother": "mother"}' "http://localhost:31000/example/v1/family/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"8a3af91da12c4a3eb040ffb535693f1a", "father":"new-father", "mother": "new-mother"}' "http://localhost:31000/example/v1/family/update"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"85ffbfbef27b42879382b47718c7a99e", "father":"new-father", "mother": "new-mother"}' "http://localhost:31000/example/v1/family/update"
 // curl -X GET "http://localhost:31000/example/v1/family/query?father=new-father&pageNo=0&pageSize=0"
-// curl -X GET "http://localhost:31000/example/v1/family/get?id=8a3af91da12c4a3eb040ffb535693f1a"
-// curl -X DELETE "http://localhost:31000/example/v1/family/8a3af91da12c4a3eb040ffb535693f1a/delete"
+// curl -X GET "http://localhost:31000/example/v1/family/get?id=85ffbfbef27b42879382b47718c7a99e"
+// curl -X DELETE "http://localhost:31000/example/v1/family/85ffbfbef27b42879382b47718c7a99e/delete"
 
 // Identity
 // curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/v1/identity/create"
@@ -43,38 +43,38 @@ import (
 // curl -X DELETE "http://localhost:31000/example/v1/identity/6e12ee71397746b8920fa94e5f229366/delete"
 
 // Class-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"4199572c46494fd49d9179f095a44c48", "studentIds": ["31934e95b8ef414b9dae5c31dd8bf2bb"]}' "http://localhost:31000/example/v1/class/student/update"
-// curl -X GET "http://localhost:31000/example/v1/class/student/query?id=4199572c46494fd49d9179f095a44c48"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"a38786c698904224a6fc36a23c2eec1e", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/class/student/update"
+// curl -X GET "http://localhost:31000/example/v1/class/student/query?id=a38786c698904224a6fc36a23c2eec1e"
 
 // Student-Class
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"31934e95b8ef414b9dae5c31dd8bf2bb", "classId": "4199572c46494fd49d9179f095a44c48"}' "http://localhost:31000/example/v1/student/class/update"
-// curl -X GET "http://localhost:31000/example/v1/student/class/query?id=31934e95b8ef414b9dae5c31dd8bf2bb"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "classId": "a38786c698904224a6fc36a23c2eec1e"}' "http://localhost:31000/example/v1/student/class/update"
+// curl -X GET "http://localhost:31000/example/v1/student/class/query?id=00254b4a7102429db35e6edc8e47a764"
 // curl -X GET "http://localhost:31000/example/v1/student/class/queryWith?name=test"
 
 // Student-Family
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"fc3e96926aac46268ae783c4ad675d43", "familyId": "ed86bbb59a80429eb654d7f9f13ff116"}' "http://localhost:31000/example/v1/student/family/update"
-// curl -X GET "http://localhost:31000/example/v1/student/family/query?id=fc3e96926aac46268ae783c4ad675d43"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "familyId": "df3aeee04ce94c17878bbb5383d15f18"}' "http://localhost:31000/example/v1/student/family/update"
+// curl -X GET "http://localhost:31000/example/v1/student/family/query?id=00254b4a7102429db35e6edc8e47a764"
 // curl -X GET "http://localhost:31000/example/v1/student/family/queryWith?name=test"
 
 // Family-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"ed86bbb59a80429eb654d7f9f13ff116", "studentId": "fc3e96926aac46268ae783c4ad675d43"}' "http://localhost:31000/example/v1/family/student/update"
-// curl -X GET "http://localhost:31000/example/v1/family/student/query?id=ed86bbb59a80429eb654d7f9f13ff116"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"df3aeee04ce94c17878bbb5383d15f18", "studentId": "00254b4a7102429db35e6edc8e47a764"}' "http://localhost:31000/example/v1/family/student/update"
+// curl -X GET "http://localhost:31000/example/v1/family/student/query?id=df3aeee04ce94c17878bbb5383d15f18"
 // curl -X GET "http://localhost:31000/example/v1/family/student/queryWith?name=test"
 
 // Student-Identity
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"d21d93c7f189441fac5d27f14fdce13b", "identityIds": ["42b305bb292c4082a3e91a2967fe303c"]}' "http://localhost:31000/example/v1/student/identity/update"
-// curl -X GET "http://localhost:31000/example/v1/student/identity/query?id=d21d93c7f189441fac5d27f14fdce13b"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "identityIds": ["4481fd110a5f46d2babe52b650981384"]}' "http://localhost:31000/example/v1/student/identity/update"
+// curl -X GET "http://localhost:31000/example/v1/student/identity/query?id=00254b4a7102429db35e6edc8e47a764"
 
 // Identity-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967fe303c", "studentIds": ["d21d93c7f189441fac5d27f14fdce13b"]}' "http://localhost:31000/example/v1/identity/student/update"
-// curl -X GET "http://localhost:31000/example/v1/identity/student/query?id=42b305bb292c4082a3e91a2967fe303c"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"4481fd110a5f46d2babe52b650981384", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/identity/student/update"
+// curl -X GET "http://localhost:31000/example/v1/identity/student/query?id=4481fd110a5f46d2babe52b650981384"
 
 // Student-Hobby
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"fca9ad529fb04d22abd9fe0232c8a462", "hobbyIds": ["42b305bb292c4082a3e91a2967f11111"]}' "http://localhost:31000/example/v1/student/hobby/update"
-// curl -X GET "http://localhost:31000/example/v1/student/hobby/query?id=fca9ad529fb04d22abd9fe0232c8a462"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "hobbyIds": ["42b305bb292c4082a3e91a2967f11111"]}' "http://localhost:31000/example/v1/student/hobby/update"
+// curl -X GET "http://localhost:31000/example/v1/student/hobby/query?id=00254b4a7102429db35e6edc8e47a764"
 
 // Hobby-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967f11111", "studentIds": ["fca9ad529fb04d22abd9fe0232c8a462"]}' "http://localhost:31000/example/v1/hobby/student/update"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967f11111", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/hobby/student/update"
 // curl -X GET "http://localhost:31000/example/v1/hobby/student/query?id=42b305bb292c4082a3e91a2967f11111"
 
 func main() {