yinbentan
2024-07-31 b94bef381946e22fd1038f24e6d9de911d194640
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
128
129
130
131
132
133
package controllers
 
import (
    "github.com/gin-gonic/gin"
    "gorm.io/gorm"
    "silkserver/controllers/request"
    "silkserver/extend/code"
    "silkserver/extend/util"
    "silkserver/middleware"
    "silkserver/models"
)
 
type WorkerController struct {
}
 
// CreateWorkerInfo
//
//    @Tags        员工管理/员工信息
//    @Summary    创建人员信息
//    @Produce    application/json
//    @Param        object    body        models.Worker    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/worker/createWorkerInfo [post]
func (slf WorkerController) CreateWorkerInfo(c *gin.Context) {
    var params models.Worker
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.ID == "" {
        util.ResponseFormat(c, code.RequestParamError, "ID为空")
        return
    }
    if params.Name == "" {
        util.ResponseFormat(c, code.RequestParamError, "名称为空")
        return
    }
    _, err = models.NewWorkerSearch().SetID(params.ID).First()
    if err != gorm.ErrRecordNotFound {
        util.ResponseFormat(c, code.RequestParamError, "编码已存在")
        return
    }
    info := middleware.GetUserInfo(c)
    params.AddPeople = info.NickName
 
    err = models.NewWorkerSearch().Create(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "创建失败")
        return
    }
    util.ResponseFormat(c, code.Success, "创建成功")
}
 
// UpdateWorkerInfo
//
//    @Tags        员工管理/员工信息
//    @Summary    更新人员信息
//    @Produce    application/json
//    @Param        object    body        models.Worker    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/worker/updateWorkerInfo [post]
func (slf WorkerController) UpdateWorkerInfo(c *gin.Context) {
    var params models.Worker
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.ID == "" {
        util.ResponseFormat(c, code.RequestParamError, "ID为空")
        return
    }
    if params.Name == "" {
        util.ResponseFormat(c, code.RequestParamError, "名称为空")
        return
    }
    err = models.NewWorkerSearch().Save(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "更新失败")
        return
    }
    util.ResponseFormat(c, code.Success, "更新成功")
}
 
// GetWorkerList
//
//    @Tags        员工管理/员工信息
//    @Summary    获取人员信息列表
//    @Produce    application/json
//    @Param        object    body        request.GetWorkerList    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.ResponseList{data=[]models.Worker}        "成功"
//    @Router        /api-jl/v1/worker/getWorkerList [post]
func (slf WorkerController) GetWorkerList(c *gin.Context) {
    var params request.GetWorkerList
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    workers, total, err := models.NewWorkerSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("updated_at desc").Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询失败")
        return
    }
    util.ResponseFormatList(c, code.Success, workers, total)
}
 
// DeleteWorkerInfo
//
//    @Tags        员工管理/员工信息
//    @Summary    删除人员信息
//    @Produce    application/json
//    @Param        id    path        string            true    "id"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/worker/deleteWorkerInfo/{id} [delete]
func (slf WorkerController) DeleteWorkerInfo(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效的id")
        return
    }
    err := models.NewWorkerSearch().SetID(id).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}