zhangqian
2024-02-29 670cb9b9a9bd96f3a71682e944a4cf3f86f51528
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package controllers
 
import (
    "github.com/gin-gonic/gin"
    "silkserver/controllers/request"
    "silkserver/extend/code"
    "silkserver/extend/util"
    "silkserver/models"
    "silkserver/pkg/convertx"
    "silkserver/pkg/structx"
)
 
type FinenessController struct{}
 
// Add
// @Tags      纤度登记
// @Summary   纤度登记添加
// @Produce   application/json
// @Param     object  body  request.AddFinenessRegister true  "字典信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-jl/v1/fineness/register [post]
func (slf FinenessController) Add(c *gin.Context) {
    var reqParams request.AddFinenessRegister
    var params models.FinenessRegister
    if err := c.BindJSON(&reqParams); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if err := structx.AssignTo(reqParams, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误")
        return
    }
 
    if err := slf.ParamsCheck(params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
    if err := models.NewFinenessRegisterSearch().Create(&params); err != nil {
        util.ResponseFormat(c, code.SaveFail, "插入失败")
        return
    }
 
    util.ResponseFormat(c, code.Success, "添加成功")
}
 
func (slf FinenessController) ParamsCheck(params models.FinenessRegister) (err error) {
    return nil
}
 
// List
// @Tags      纤度登记
// @Summary   纤度登记列表
// @Produce   application/json
// @Param     object  query    request.GetFinenessRegisterList true  "查询参数"
// @Success   200   {object}  util.ResponseList{data=[]models.FinenessRegister}  "成功"
// @Router    /api-jl/v1/fineness/register [get]
func (slf FinenessController) List(c *gin.Context) {
    var params request.GetFinenessRegisterList
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
 
    list, total, err := models.NewFinenessRegisterSearch().Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
 
    util.ResponseFormatList(c, code.Success, list, total)
}
 
// Info
// @Tags      纤度登记
// @Summary   纤度登记详情
// @Produce   application/json
// @Param     id  path string true  "字典信息"
// @Success   200 {object} util.ResponseList{data=models.FinenessRegister} "成功"
// @Router    /api-jl/v1/fineness/register/{id} [get]
func (slf FinenessController) Info(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.NewFinenessRegisterSearch().SetID(id).SetPreload().First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    util.ResponseFormat(c, code.Success, info)
}
 
// Delete
// @Tags      纤度登记
// @Summary   纤度登记删除
// @Produce   application/json
// @Param     id  path string true  "字典信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-jl/v1/fineness/register/{id} [delete]
func (slf FinenessController) Delete(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
    }
 
    err := models.NewFinenessRegisterSearch().SetID(id).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.UpdateSuccess, "删除成功")
}