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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package controllers
 
import (
    "github.com/gin-gonic/gin"
    "gorm.io/gorm"
    "silkserver/constvar"
    "silkserver/controllers/request"
    "silkserver/extend/code"
    "silkserver/extend/util"
    "silkserver/middleware"
    "silkserver/models"
    "silkserver/pkg/timex"
    "strconv"
    "time"
)
 
type SalaryPlanController struct {
}
 
// SaveSalaryPlan
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    保存薪酬方案
//    @Produce    application/json
//    @Param        object    body        models.SalaryPlan    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/salary/saveSalaryPlan [post]
func (slf SalaryPlanController) SaveSalaryPlan(c *gin.Context) {
    var params models.SalaryPlan
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.ID > 0 {
        //更新
        err = models.NewSalaryPlanSearch().Save(&params)
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "保存失败")
            return
        }
    } else {
        //新建
        info := middleware.GetUserInfo(c)
        params.AddPeople = info.NickName
        params.CreateTime = timex.TimeToString2(time.Now())
        err = models.NewSalaryPlanSearch().Create(&params)
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "保存失败")
            return
        }
    }
 
    util.ResponseFormat(c, code.Success, "保存成功")
}
 
// GetSalaryPlanList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取薪酬方案列表
//    @Produce    application/json
//    @Param        object    body        request.GetSalaryPlanList    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.ResponseList{data=[]models.SalaryPlan}        "成功"
//    @Router        /api-jl/v1/salary/getSalaryPlanList [post]
func (slf SalaryPlanController) GetSalaryPlanList(c *gin.Context) {
    var params request.GetSalaryPlanList
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    find, total, err := models.NewSalaryPlanSearch().SetPage(params.Page, params.PageSize).SetPreload(true).Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    util.ResponseFormatList(c, code.Success, find, total)
}
 
// DeleteSalaryPlanInfo
//
//    @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/salary/deleteSalaryPlanInfo/{id} [delete]
func (slf SalaryPlanController) DeleteSalaryPlanInfo(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效的id")
        return
    }
    atoi, _ := strconv.Atoi(id)
    if atoi == 0 {
        util.ResponseFormat(c, code.RequestParamError, "无效的id")
        return
    }
    err := models.NewSalaryPlanSearch().SetId(atoi).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}
 
// SaveSalaryType
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    保存薪资类型
//    @Produce    application/json
//    @Param        object    body        request.SalaryType    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/salary/saveSalaryType [post]
func (slf SalaryPlanController) SaveSalaryType(c *gin.Context) {
    var params request.SalaryType
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Type == 0 {
        util.ResponseFormat(c, code.RequestParamError, "类型不能为空")
        return
    }
    miniDicts, err := models.NewMiniDictSearch().SetType(params.Type).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, err)
        return
    }
    dicts := params.Values
    add := make([]*models.MiniDict, 0)
    del := make([]uint, 0)
    update := make([]*models.MiniDict, 0)
    for _, mini := range miniDicts {
        flag := true
        for i, value := range dicts {
            var dict models.MiniDict
            dict.Name = value.Name
            dict.IsDefault = value.IsDefault
            dict.Type = params.Type
            if value.Id == 0 {
                add = append(add, &dict)
                flag = false
                if i < len(dicts)-1 {
                    dicts = append(dicts[:i], dicts[i+1:]...)
                } else {
                    dicts = dicts[:i]
                }
                break
            } else if value.Id == mini.ID {
                dict.ID = mini.ID
                update = append(update, &dict)
                flag = false
                if i < len(dicts)-1 {
                    dicts = append(dicts[:i], dicts[i+1:]...)
                } else {
                    dicts = dicts[:i]
                }
                break
            }
        }
        if flag {
            del = append(del, mini.ID)
        }
    }
    //新增的
    for _, value := range dicts {
        var dict models.MiniDict
        dict.Name = value.Name
        dict.IsDefault = value.IsDefault
        dict.Type = params.Type
        add = append(add, &dict)
    }
 
    err = models.WithTransaction(func(db *gorm.DB) error {
        if len(del) > 0 {
            err = models.NewMiniDictSearch().SetOrm(db).SetIds(del).Delete()
            if err != nil {
                return err
            }
        }
        if len(update) > 0 {
            err = models.NewMiniDictSearch().SetOrm(db).SaveBatch(update)
            if err != nil {
                return err
            }
        }
        if len(add) > 0 {
            err = models.NewMiniDictSearch().SetOrm(db).CreateBatch(add)
            if err != nil {
                return err
            }
        }
 
        return nil
    })
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "保存失败")
        return
    }
    util.ResponseFormat(c, code.Success, "保存成功")
}
 
// GetSalaryTypeList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取薪资类型列表
//    @Produce    application/json
//    @Param        number    path        string            true    "type"    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.ResponseList{data=[]models.MiniDict}        "成功"
//    @Router        /api-jl/v1/salary/getSalaryTypeList/{type} [get]
func (slf SalaryPlanController) GetSalaryTypeList(c *gin.Context) {
    tp := c.Param("type")
    if tp == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效的类型")
        return
    }
    atoi, _ := strconv.Atoi(tp)
    if atoi == 0 {
        util.ResponseFormat(c, code.RequestParamError, "无效的类型")
        return
    }
    dicts, err := models.NewMiniDictSearch().SetType(constvar.MiniDictType(atoi)).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询失败")
        return
    }
    util.ResponseFormat(c, code.Success, dicts)
}
 
// GetPayrollProductionCarList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取车台每天的产量列表
//    @Produce    application/json
//    @Param         Authorization    header string true "token"
//    @Param         object  query    request.PayrollProductionCar true  "查询参数"
//    @Success    200        {object}    util.ResponseList{data=[]models.PayrollProductionCar}    "成功"
//    @Router        /api-jl/v1/salary/getPayrollProductionCarList [get]
func (slf SalaryPlanController) GetPayrollProductionCarList(c *gin.Context) {
    var params request.PayrollProductionCar
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
 
    carSearch := models.NewPayrollProductionCarSearch()
    if len(params.Cycle) == 0 && len(params.Monthly) == 0 {
        util.ResponseFormat(c, code.RequestParamError, "请检查查询周期,必须输入按天查询或按月查询。格式:Cycle(yyyy-MM-dd) 或 Monthly(yyyy-MM)")
        return
    }
    carSearch.SetPage(params.Page, params.PageSize)
    carSearch.SetWorkshopNumber(params.WorkshopNumber).SetGroupNumber(params.GroupNumber).SetCarNumber(params.CarNumber).SetMarketNumber(params.MarketNumber).SetSpec(params.Spec)
    list, total, err := carSearch.Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
 
    util.ResponseFormatList(c, code.Success, list, total)
}
 
// GetPayrollProductionGroupList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取小组每天的产量列表
//    @Produce    application/json
//    @Param         Authorization    header string true "token"
//    @Param         object  query    request.PayrollProductionGroup true  "查询参数"
//    @Success    200        {object}    util.ResponseList{data=[]models.PayrollProductionGroup}    "成功"
//    @Router        /api-jl/v1/salary/getPayrollProductionGroupList [get]
func (slf SalaryPlanController) GetPayrollProductionGroupList(c *gin.Context) {
    var params request.PayrollProductionGroup
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    //params = request.PayrollProductionGroup{
    //    Cycle:          c.Query("cycle"),
    //    Monthly:        c.Query("monthly"),
    //    WorkshopNumber: c.Query("workshopNumber"),
    //}
    //params.GroupNumber, _ = strconv.Atoi(c.Query("groupNumber"))
    //params.Page, _ = strconv.Atoi(c.Query("page"))
    //params.PageSize, _ = strconv.Atoi(c.Query("pageSize"))
 
    if len(params.Cycle) == 0 && len(params.Monthly) == 0 {
        util.ResponseFormat(c, code.RequestParamError, "请检查查询周期,必须输入按天查询或按月查询。格式:Cycle(yyyy-MM-dd) 或 Monthly(yyyy-MM)")
        return
    }
    list, total, err := models.NewPayrollProductionGroupSearch().SetPage(params.Page, params.PageSize).
        SetCycle(params.Cycle).SetMonthly(params.Monthly).SetWorkshopNumber(params.WorkshopNumber).SetGroupNumber(params.GroupNumber).
        Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
 
    util.ResponseFormatList(c, code.Success, list, total)
}
 
// GetPayrollSalaryPlanList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取人员每月的薪资列表
//    @Produce    application/json
//    @Param         Authorization    header string true "token"
//    @Param         object  query    request.PayrollSalaryPlan true  "查询参数"
//    @Success    200        {object}    util.ResponseList{data=[]models.PayrollSalaryPlan}    "成功"
//    @Router        /api-jl/v1/salary/getPayrollSalaryPlanList [get]
func (slf SalaryPlanController) GetPayrollSalaryPlanList(c *gin.Context) {
    var params request.PayrollSalaryPlan
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
 
    if len(params.Cycle) == 0 {
        util.ResponseFormat(c, code.RequestParamError, "请检查查询周期。格式:Cycle(yyyy-MM-dd)")
        return
    }
    list, total, err := models.NewPayrollSalaryPlanSearch().SetPage(params.Page, params.PageSize).
        SetCycle(params.Cycle).SetWorkerID(params.WorkerID).SetKeyword(params.Keyword).SetWorkTypeID(uint(params.WorkTypeID)).SetWorkTypeCode(constvar.JobType(params.WorkTypeCode)).
        Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
 
    util.ResponseFormatList(c, code.Success, list, total)
}