From 30e38e3b2a55a4c9d503b7fbda303437865793be Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期二, 16 七月 2024 20:08:30 +0800
Subject: [PATCH] 添加方法,根据纤度登记ID获取纤度检验详情

---
 controllers/fineness.go |   54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/controllers/fineness.go b/controllers/fineness.go
index 9cc41d3..0eaa33d 100644
--- a/controllers/fineness.go
+++ b/controllers/fineness.go
@@ -66,14 +66,13 @@
 	err = models.WithTransaction(func(db *gorm.DB) error {
 		search := models.NewFinenessRegisterSearch().SetOrm(db)
 
-		if !isNew {
+		if !isNew { // id涓嶄负绌�
 			if err := models.NewFinenessItemSearch().SetOrm(db).SetFinenessRegisterID(params.ID).Delete(); err != nil {
 				return err
 			}
 			return search.Save(&params)
-		} else {
-			return search.Create(&params)
 		}
+		return search.Create(&params)
 	})
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触")
@@ -87,7 +86,7 @@
 		return
 	}
 
-	util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛")
+	util.ResponseFormat(c, code.Success, params)
 }
 
 func (slf FinenessController) ParamsCheck(params models.FinenessRegister) (err error) {
@@ -201,12 +200,17 @@
 		util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id")
 		return
 	}
-
-	err := models.NewFinenessRegisterSearch().SetID(id).Delete()
+	err := models.WithTransaction(func(db *gorm.DB) error {
+		if err := models.NewFinenessItemSearch().SetOrm(db).SetFinenessRegisterID(id).Delete(); err != nil {
+			return err
+		}
+		return models.NewFinenessRegisterSearch().SetOrm(db).SetID(id).Delete()
+	})
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
 		return
 	}
+
 	util.ResponseFormat(c, code.UpdateSuccess, "鍒犻櫎鎴愬姛")
 }
 
@@ -237,7 +241,7 @@
 // @Tags      绾ゅ害妫�楠�
 // @Summary   绾ゅ害妫�楠岃鎯�
 // @Produce   application/json
-// @Param     id  path string true  "瀛楀吀淇℃伅"
+// @Param     id  path string true  "绾ゅ害妫�楠孖D"
 // @Success   200 {object} util.ResponseList{data=response.FinenessCheckInfo} "鎴愬姛"
 // @Router    /api-jl/v1/fineness/check/{id} [get]
 func (slf FinenessController) CheckInfo(c *gin.Context) {
@@ -269,6 +273,42 @@
 	util.ResponseFormat(c, code.Success, resp)
 }
 
+// CheckInfoByFinenessID
+// @Tags      绾ゅ害妫�楠�
+// @Summary   鏍规嵁绾ゅ害鐧昏ID鑾峰彇绾ゅ害妫�楠岃鎯�
+// @Produce   application/json
+// @Param     id  path string true  "绾ゅ害鐧昏ID"
+// @Success   200 {object} util.ResponseList{data=response.FinenessCheckInfo} "鎴愬姛"
+// @Router    /api-jl/v1/fineness/checkFinenessID/{id} [get]
+func (slf FinenessController) CheckInfoByFinenessID(c *gin.Context) {
+	idStr := c.Param("id")
+	if idStr == "0" || idStr == "" {
+		util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id")
+		return
+	}
+
+	id := convertx.StringToUInt(idStr)
+	if id == 0 {
+		util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id")
+		return
+	}
+
+	info, err := models.NewFinenessCheckSearch().SetFinenessRegisterID(id).SetPreload().First()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "妫�鏌ヨ〃鏌ユ壘澶辫触")
+		return
+	}
+	resp := new(response.FinenessCheckInfo)
+	resp.Info = info
+	resp.Items, err = models.NewFinenessCheckItemSearch().SetFinenessRegisterID(info.FinenessRegisterID).FindAll()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "妫�鏌ヨ鎯呰〃鏌ユ壘澶辫触")
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, resp)
+}
+
 // CheckDelete
 // @Tags      绾ゅ害妫�楠�
 // @Summary   绾ゅ害妫�楠屽垹闄�

--
Gitblit v1.8.0