yinbentan
2024-07-16 30e38e3b2a55a4c9d503b7fbda303437865793be
添加方法,根据纤度登记ID获取纤度检验详情
4个文件已修改
81 ■■■■ 已修改文件
controllers/fineness.go 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/request/fineness.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/dict.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/fineness_item.go 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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  "纤度检验ID"
// @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   纤度检验删除
controllers/request/fineness.go
@@ -30,5 +30,6 @@
type GetFinenessRegisterList struct {
    PageInfo
    Keyword string `json:"keyword" form:"keyword"`
    FinenessRegisterID uint   `json:"finenessRegisterID"` //纤度登记表ID
    Keyword            string `json:"keyword" form:"keyword"`
}
models/dict.go
@@ -8,13 +8,13 @@
)
type (
    // Dict 词典
    // Dict 缫丝词典
    Dict struct {
        gorm.Model
        DictType *constvar.DictType `gorm:"index;type:tinyint(3);not null;comment:字典类型"`         //字典类型
        Number   string             `gorm:"type:varchar(255);not null;comment:编号" json:"number"` //编号
        Name     string             `gorm:"type:varchar(255);not null;comment:名称" json:"name"`   //名称
        Remark   string             `gorm:"type:varchar(255);not null;comment:备注" json:"remark"` //备注
        DictType constvar.DictType `gorm:"index;type:tinyint(3);not null;comment:字典类型"`         //字典类型
        Number   string            `gorm:"type:varchar(255);not null;comment:编号" json:"number"` //编号
        Name     string            `gorm:"type:varchar(255);not null;comment:名称" json:"name"`   //名称
        Remark   string            `gorm:"type:varchar(255);not null;comment:备注" json:"remark"` //备注
    }
    DictSearch struct {
@@ -71,7 +71,7 @@
    return slf
}
func (slf *DictSearch) SetDictType(dt *constvar.DictType) *DictSearch {
func (slf *DictSearch) SetDictType(dt constvar.DictType) *DictSearch {
    slf.DictType = dt
    return slf
}
@@ -96,7 +96,7 @@
        db = db.Where("number = ?", slf.Number)
    }
    if slf.DictType != nil {
    if slf.DictType > 0 {
        db = db.Where("dict_type = ?", slf.DictType)
    }
models/fineness_item.go
@@ -11,11 +11,11 @@
    // FinenessItem 纤度登记
    FinenessItem struct {
        gorm.Model
        FinenessRegisterID uint            `gorm:"size:11;index" json:"finenessRegisterID"`
        Position           int             `gorm:"size:11;comment:车号" json:"position"`         // 车号
        Fineness           float32         `gorm:"comment:纤度" json:"fineness"`                 // 纤度
        Quantity           int             `gorm:"size:11;comment:数量" json:"quantity"`         // 数量
        Sum                decimal.Decimal `gorm:"type:decimal(12,4);comment:纤度合计" json:"sum"` //纤度合计
        FinenessRegisterID uint            `gorm:"size:11;index;comment:纤度登记ID" json:"finenessRegisterID"` // 纤度登记ID
        Position           int             `gorm:"size:11;comment:车号" json:"position"`                     // 车号
        Fineness           float32         `gorm:"comment:纤度" json:"fineness"`                             // 纤度
        Quantity           int             `gorm:"size:11;comment:数量" json:"quantity"`                     // 数量
        Sum                decimal.Decimal `gorm:"type:decimal(12,4);comment:纤度合计" json:"sum"`             // 纤度合计
    }
    FinenessItemSearch struct {