yinbentan
2024-08-02 3032034d254fc15f06a1d4260f35c49f0ef1e12f
添加接口,添加新的薪资查询和修改接口
1个文件已添加
8个文件已修改
828 ■■■■■ 已修改文件
controllers/request/salary_plan.go 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/response/salary_plan.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/salary_plan_controller.go 162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/payroll_constitute.go 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/salary_plan.go 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/request/salary_plan.go
@@ -1,5 +1,10 @@
package request
import (
    "github.com/shopspring/decimal"
    "silkserver/constvar"
)
type PayrollProductionCar struct {
    PageInfo
    Cycle          string `json:"cycle" form:"cycle"`                   // 统计周期(年-月-日)
@@ -28,3 +33,30 @@
    WorkTypeCode string `json:"workTypeCode"  form:"workTypeCode"` // 工种编码
    Keyword      string `json:"keyword"  form:"keyword"`           // 关键字
}
type UpdatePayrollConstitute struct {
    Cycle        string           `json:"cycle" `        //月份
    WorkerID     string           `json:"workerID"  `    //员工ID
    WorkTypeID   uint             `json:"workTypeID" `   //工种ID
    WorkTypeCode constvar.JobType `json:"workTypeCode" ` //工种代码
    Amount       decimal.Decimal  `json:"amount" `       //金额
}
type PayrollConstitute struct {
    PageInfo
    Cycle        string `json:"cycle"  form:"cycle"`               // 统计周期按月查询(年-月)
    WorkerID     string `json:"workerID"  form:"workerID"`         // 员工ID
    WorkTypeID   int    `json:"workTypeID"  form:"workTypeID"`     // 工种ID
    WorkTypeCode string `json:"workTypeCode"  form:"workTypeCode"` // 工种编码
    Keyword      string `json:"keyword"  form:"keyword"`           // 关键字
}
type SavePayrollConstitute struct {
    Cycle        string           `json:"cycle" from:"cycle"`               //周期(月份)
    WorkerID     string           `json:"workerId" from:"workerId"`         //员工ID
    WorkTypeID   uint             `json:"workTypeID" from:"workTypeID"`     //工种ID
    WorkTypeCode constvar.JobType `json:"workTypeCode" from:"workTypeCode"` //工种代码
    WorkTypeName string           `json:"workTypeName" from:"workTypeName"` //工种名称
    SalaryPlanId uint             `json:"salaryPlanId" from:"salaryPlanId"` //薪资方案ID
    Amount       decimal.Decimal  `json:"amount" from:"amount"`             // 金额
}
controllers/response/salary_plan.go
New file
@@ -0,0 +1,6 @@
package response
type PayrollSalaryPlan struct {
    // 人员信息
    //
}
controllers/salary_plan_controller.go
@@ -1,7 +1,9 @@
package controllers
import (
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
    "silkserver/constvar"
    "silkserver/controllers/request"
@@ -9,6 +11,7 @@
    "silkserver/extend/util"
    "silkserver/middleware"
    "silkserver/models"
    "silkserver/pkg/structx"
    "silkserver/pkg/timex"
    "strconv"
    "time"
@@ -335,3 +338,162 @@
    util.ResponseFormatList(c, code.Success, list, total)
}
// SavePayrollConstitute
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    薪酬数额调整
//    @Produce    application/json
//    @Param        object    body    request.SavePayrollConstitute    true    "参数"
//    @Param         Authorization    header string true "token"
//    @Success    200        {object}    util.Response        "成功"
//    @Router        /api-jl/v1/salary/savePayrollConstitute [post]
func (slf SalaryPlanController) SavePayrollConstitute(c *gin.Context) {
    var params request.SavePayrollConstitute
    var constitute models.PayrollConstitute
    err := c.BindJSON(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    err = structx.AssignTo(params, &constitute)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换失败")
        return
    }
    if len(constitute.Cycle) < 7 {
        util.ResponseFormat(c, code.RequestParamError, "周期参数为空或格式错误")
    }
    if len(constitute.WorkerID) == 0 {
        util.ResponseFormat(c, code.RequestParamError, "员工ID参数为空")
    }
    if constitute.SalaryPlanId == 0 {
        util.ResponseFormat(c, code.RequestParamError, "薪资方案ID参数为空")
    }
    info := middleware.GetUserInfo(c)
    if info == nil || info.NickName == "" {
        util.ResponseFormat(c, code.RequestParamError, "用户未登录")
    }
    constitute.CreatedBy = info.NickName
    if payrollConstitute, err := models.NewPayrollConstituteSearch().SetCycle(params.Cycle).SetWorkerID(params.WorkerID).SetSalaryPlanId(params.SalaryPlanId).First(); err != nil && payrollConstitute != nil {
        constitute.ID = payrollConstitute.ID
        constitute.CreatedAt = payrollConstitute.CreatedAt
    }
    if constitute.ID > 0 {
        err = models.NewPayrollConstituteSearch().Save(&constitute)
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "保存失败")
            return
        }
    } else {
        err = models.NewPayrollConstituteSearch().Create(&constitute)
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "保存失败")
            return
        }
    }
    util.ResponseFormat(c, code.Success, "保存成功")
}
// GetPayrollConstituteList
//
//    @Tags        员工薪资/薪酬方案
//    @Summary    获取人员每月的薪资列表
//    @Produce    application/json
//    @Param         Authorization    header string true "token"
//    @Param         object  query    request.PayrollConstitute true  "查询参数"
//    @Success    200        {object}    util.ResponseList{data=map[string]interface{}}    "成功"
//    @Router        /api-jl/v1/salary/getPayrollConstituteList [get]
func (slf SalaryPlanController) GetPayrollConstituteList(c *gin.Context) {
    var params request.PayrollConstitute
    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
    }
    groupList, err := models.NewPayrollConstituteSearch().ConstituteGroup(&models.ConstituteGroup{Cycle: params.Cycle})
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找工资分类失败")
        return
    }
    groupMap := make(map[string][]*models.ConstituteGroup, 0)
    for _, group := range groupList {
        if _, ok := groupMap[group.WorkerID]; ok {
            groupMap[group.WorkerID] = append(groupMap[group.WorkerID], group)
        } else {
            groupMap[group.WorkerID] = []*models.ConstituteGroup{group}
        }
    }
    // 员工信息
    workers, err := models.NewWorkerSearch().FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找用户失败")
    }
    workerMap := make(map[string]*models.Worker)
    for _, worker := range workers {
        workerMap[worker.ID] = worker
    }
    // 工资方案
    salaryPlans, err := models.NewSalaryPlanSearch().FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找薪资方案失败")
    }
    salaryPlanMap := make(map[uint]*models.SalaryPlan)
    for _, plan := range salaryPlans {
        salaryPlanMap[plan.ID] = plan
    }
    // 工资单项
    constituteList, err := models.NewPayrollConstituteSearch().SetCycle(params.Cycle).SetWorkerID(params.WorkerID).SetWorkTypeID(uint(params.WorkTypeID)).SetWorkTypeCode(params.WorkTypeCode).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找工资单项失败")
        return
    }
    constituteMap := make(map[string]*models.PayrollConstitute)
    for _, v := range constituteList {
        key := fmt.Sprintf("%v%v%v", v.Cycle, v.WorkerID, v.SalaryPlanId)
        constituteMap[key] = v
    }
    var list []map[string]interface{}
    for workerId, group := range groupMap {
        result := make(map[string]interface{})
        result["cycle"] = params.Cycle
        if _, ok := workerMap[workerId]; ok { // 人员信息
            result["worker"] = workerMap[workerId]
        }
        amount := decimal.NewFromInt(0)
        constituteList := make([]map[string]interface{}, 0)
        for _, v := range group {
            temp := make(map[string]interface{})
            if _, ok := salaryPlanMap[v.SalaryPlanId]; ok {
                temp["salaryPlan"] = salaryPlanMap[v.SalaryPlanId]
            }
            key := fmt.Sprintf("%v%v%v", v.Cycle, v.WorkerID, v.SalaryPlanId)
            if _, ok := constituteMap[key]; ok {
                temp["amount"] = constituteMap[key].Amount
                amount = amount.Add(constituteMap[key].Amount)
            }
            constituteList = append(constituteList, temp)
        }
        result["amount"] = amount       // 应发工资
        result["list"] = constituteList // 工资详情
        list = append(list, result)
    }
    util.ResponseFormat(c, code.Success, list)
}
docs/docs.go
@@ -1136,6 +1136,89 @@
                }
            }
        },
        "/api-jl/v1/salary/getPayrollConstituteList": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "员工薪资/薪酬方案"
                ],
                "summary": "获取人员每月的薪资列表",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "统计周期按月查询(年-月)",
                        "name": "cycle",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "关键字",
                        "name": "keyword",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "工种编码",
                        "name": "workTypeCode",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "工种ID",
                        "name": "workTypeID",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "员工ID",
                        "name": "workerID",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "additionalProperties": true
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-jl/v1/salary/getPayrollProductionCarList": {
            "get": {
                "produces": [
@@ -1505,6 +1588,43 @@
                }
            }
        },
        "/api-jl/v1/salary/savePayrollConstitute": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "员工薪资/薪酬方案"
                ],
                "summary": "薪酬数额调整",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SavePayrollConstitute"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/salary/saveSalaryPlan": {
            "post": {
                "produces": [
@@ -1650,23 +1770,20 @@
                            1,
                            2,
                            3,
                            4,
                            5
                            4
                        ],
                        "type": "integer",
                        "x-enum-comments": {
                            "DictTypeColor": "颜色",
                            "DictTypeMarket": "庄口",
                            "DictTypeSpec": "规格",
                            "DictTypeSubsidy": "补贴",
                            "DictTypeWorkshop": "车间"
                        },
                        "x-enum-varnames": [
                            "DictTypeMarket",
                            "DictTypeWorkshop",
                            "DictTypeColor",
                            "DictTypeSpec",
                            "DictTypeSubsidy"
                            "DictTypeSpec"
                        ],
                        "description": "字典类型",
                        "name": "dictType",
@@ -2790,22 +2907,19 @@
                1,
                2,
                3,
                4,
                5
                4
            ],
            "x-enum-comments": {
                "DictTypeColor": "颜色",
                "DictTypeMarket": "庄口",
                "DictTypeSpec": "规格",
                "DictTypeSubsidy": "补贴",
                "DictTypeWorkshop": "车间"
            },
            "x-enum-varnames": [
                "DictTypeMarket",
                "DictTypeWorkshop",
                "DictTypeColor",
                "DictTypeSpec",
                "DictTypeSubsidy"
                "DictTypeSpec"
            ]
        },
        "constvar.FileTemplateCategory": {
@@ -2835,7 +2949,9 @@
                "cleaner",
                "machine_cleaner",
                "all-powerful",
                "monitor"
                "monitor",
                "test",
                "other"
            ],
            "x-enum-comments": {
                "JobTypeAllPowerful": "全能机动",
@@ -2845,7 +2961,9 @@
                "JobTypeMachineCleaner": "感知器清洗工",
                "JobTypeMaintenance": "保全工",
                "JobTypeMonitor": "班长",
                "JobTypeOther": "其它",
                "JobTypeScoop": "舀茧工",
                "JobTypeTest": "测试",
                "JobTypeTransport": "送茧工",
                "JobTypeWeavers": "挡车工"
            },
@@ -2859,7 +2977,9 @@
                "JobTypeCleaner",
                "JobTypeMachineCleaner",
                "JobTypeAllPowerful",
                "JobTypeMonitor"
                "JobTypeMonitor",
                "JobTypeTest",
                "JobTypeOther"
            ]
        },
        "constvar.MiniDictType": {
@@ -3404,6 +3524,10 @@
        "models.PayrollProductionCar": {
            "type": "object",
            "properties": {
                "badSilkAvgQuantity": {
                    "description": "野纤平均数量",
                    "type": "number"
                },
                "badSilkQuantity": {
                    "description": "野纤数量",
                    "type": "number"
@@ -3503,6 +3627,9 @@
                    "description": "规格",
                    "type": "string"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopNumber": {
                    "description": "车间编号",
                    "type": "string"
@@ -3561,6 +3688,9 @@
                "silkTotalAvgAmount": {
                    "description": "丝量人平均总价",
                    "type": "number"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopName": {
                    "description": "车间名称",
@@ -3836,6 +3966,9 @@
                "shopName": {
                    "type": "string"
                },
                "shopNumber": {
                    "type": "string"
                },
                "status": {
                    "$ref": "#/definitions/constvar.WorkerStatus"
                },
@@ -4080,6 +4213,9 @@
                },
                "vehicleSpeed": {
                    "type": "number"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopName": {
                    "description": "车间名",
@@ -4711,6 +4847,43 @@
                }
            }
        },
        "request.SavePayrollConstitute": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "金额",
                    "type": "number"
                },
                "cycle": {
                    "description": "周期(月份)",
                    "type": "string"
                },
                "salaryPlanId": {
                    "description": "薪资方案ID",
                    "type": "integer"
                },
                "workTypeCode": {
                    "description": "工种代码",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.JobType"
                        }
                    ]
                },
                "workTypeID": {
                    "description": "工种ID",
                    "type": "integer"
                },
                "workTypeName": {
                    "description": "工种名称",
                    "type": "string"
                },
                "workerId": {
                    "description": "员工ID",
                    "type": "string"
                }
            }
        },
        "request.SaveRankStandard": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -1125,6 +1125,89 @@
                }
            }
        },
        "/api-jl/v1/salary/getPayrollConstituteList": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "员工薪资/薪酬方案"
                ],
                "summary": "获取人员每月的薪资列表",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "统计周期按月查询(年-月)",
                        "name": "cycle",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "关键字",
                        "name": "keyword",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "工种编码",
                        "name": "workTypeCode",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "工种ID",
                        "name": "workTypeID",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "员工ID",
                        "name": "workerID",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "additionalProperties": true
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-jl/v1/salary/getPayrollProductionCarList": {
            "get": {
                "produces": [
@@ -1494,6 +1577,43 @@
                }
            }
        },
        "/api-jl/v1/salary/savePayrollConstitute": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "员工薪资/薪酬方案"
                ],
                "summary": "薪酬数额调整",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SavePayrollConstitute"
                        }
                    },
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-jl/v1/salary/saveSalaryPlan": {
            "post": {
                "produces": [
@@ -1639,23 +1759,20 @@
                            1,
                            2,
                            3,
                            4,
                            5
                            4
                        ],
                        "type": "integer",
                        "x-enum-comments": {
                            "DictTypeColor": "颜色",
                            "DictTypeMarket": "庄口",
                            "DictTypeSpec": "规格",
                            "DictTypeSubsidy": "补贴",
                            "DictTypeWorkshop": "车间"
                        },
                        "x-enum-varnames": [
                            "DictTypeMarket",
                            "DictTypeWorkshop",
                            "DictTypeColor",
                            "DictTypeSpec",
                            "DictTypeSubsidy"
                            "DictTypeSpec"
                        ],
                        "description": "字典类型",
                        "name": "dictType",
@@ -2779,22 +2896,19 @@
                1,
                2,
                3,
                4,
                5
                4
            ],
            "x-enum-comments": {
                "DictTypeColor": "颜色",
                "DictTypeMarket": "庄口",
                "DictTypeSpec": "规格",
                "DictTypeSubsidy": "补贴",
                "DictTypeWorkshop": "车间"
            },
            "x-enum-varnames": [
                "DictTypeMarket",
                "DictTypeWorkshop",
                "DictTypeColor",
                "DictTypeSpec",
                "DictTypeSubsidy"
                "DictTypeSpec"
            ]
        },
        "constvar.FileTemplateCategory": {
@@ -2824,7 +2938,9 @@
                "cleaner",
                "machine_cleaner",
                "all-powerful",
                "monitor"
                "monitor",
                "test",
                "other"
            ],
            "x-enum-comments": {
                "JobTypeAllPowerful": "全能机动",
@@ -2834,7 +2950,9 @@
                "JobTypeMachineCleaner": "感知器清洗工",
                "JobTypeMaintenance": "保全工",
                "JobTypeMonitor": "班长",
                "JobTypeOther": "其它",
                "JobTypeScoop": "舀茧工",
                "JobTypeTest": "测试",
                "JobTypeTransport": "送茧工",
                "JobTypeWeavers": "挡车工"
            },
@@ -2848,7 +2966,9 @@
                "JobTypeCleaner",
                "JobTypeMachineCleaner",
                "JobTypeAllPowerful",
                "JobTypeMonitor"
                "JobTypeMonitor",
                "JobTypeTest",
                "JobTypeOther"
            ]
        },
        "constvar.MiniDictType": {
@@ -3393,6 +3513,10 @@
        "models.PayrollProductionCar": {
            "type": "object",
            "properties": {
                "badSilkAvgQuantity": {
                    "description": "野纤平均数量",
                    "type": "number"
                },
                "badSilkQuantity": {
                    "description": "野纤数量",
                    "type": "number"
@@ -3492,6 +3616,9 @@
                    "description": "规格",
                    "type": "string"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopNumber": {
                    "description": "车间编号",
                    "type": "string"
@@ -3550,6 +3677,9 @@
                "silkTotalAvgAmount": {
                    "description": "丝量人平均总价",
                    "type": "number"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopName": {
                    "description": "车间名称",
@@ -3825,6 +3955,9 @@
                "shopName": {
                    "type": "string"
                },
                "shopNumber": {
                    "type": "string"
                },
                "status": {
                    "$ref": "#/definitions/constvar.WorkerStatus"
                },
@@ -4069,6 +4202,9 @@
                },
                "vehicleSpeed": {
                    "type": "number"
                },
                "workshopId": {
                    "type": "integer"
                },
                "workshopName": {
                    "description": "车间名",
@@ -4700,6 +4836,43 @@
                }
            }
        },
        "request.SavePayrollConstitute": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "金额",
                    "type": "number"
                },
                "cycle": {
                    "description": "周期(月份)",
                    "type": "string"
                },
                "salaryPlanId": {
                    "description": "薪资方案ID",
                    "type": "integer"
                },
                "workTypeCode": {
                    "description": "工种代码",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.JobType"
                        }
                    ]
                },
                "workTypeID": {
                    "description": "工种ID",
                    "type": "integer"
                },
                "workTypeName": {
                    "description": "工种名称",
                    "type": "string"
                },
                "workerId": {
                    "description": "员工ID",
                    "type": "string"
                }
            }
        },
        "request.SaveRankStandard": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -53,20 +53,17 @@
    - 2
    - 3
    - 4
    - 5
    type: integer
    x-enum-comments:
      DictTypeColor: 颜色
      DictTypeMarket: 庄口
      DictTypeSpec: 规格
      DictTypeSubsidy: 补贴
      DictTypeWorkshop: 车间
    x-enum-varnames:
    - DictTypeMarket
    - DictTypeWorkshop
    - DictTypeColor
    - DictTypeSpec
    - DictTypeSubsidy
  constvar.FileTemplateCategory:
    enum:
    - 1
@@ -90,6 +87,8 @@
    - machine_cleaner
    - all-powerful
    - monitor
    - test
    - other
    type: string
    x-enum-comments:
      JobTypeAllPowerful: 全能机动
@@ -99,7 +98,9 @@
      JobTypeMachineCleaner: 感知器清洗工
      JobTypeMaintenance: 保全工
      JobTypeMonitor: 班长
      JobTypeOther: 其它
      JobTypeScoop: 舀茧工
      JobTypeTest: 测试
      JobTypeTransport: 送茧工
      JobTypeWeavers: 挡车工
    x-enum-varnames:
@@ -113,6 +114,8 @@
    - JobTypeMachineCleaner
    - JobTypeAllPowerful
    - JobTypeMonitor
    - JobTypeTest
    - JobTypeOther
  constvar.MiniDictType:
    enum:
    - 1
@@ -496,6 +499,9 @@
    type: object
  models.PayrollProductionCar:
    properties:
      badSilkAvgQuantity:
        description: 野纤平均数量
        type: number
      badSilkQuantity:
        description: 野纤数量
        type: number
@@ -570,6 +576,8 @@
      spec:
        description: 规格
        type: string
      workshopId:
        type: integer
      workshopNumber:
        description: 车间编号
        type: string
@@ -613,6 +621,8 @@
      silkTotalAvgAmount:
        description: 丝量人平均总价
        type: number
      workshopId:
        type: integer
      workshopName:
        description: 车间名称
        type: string
@@ -801,6 +811,8 @@
        type: string
      shopName:
        type: string
      shopNumber:
        type: string
      status:
        $ref: '#/definitions/constvar.WorkerStatus'
      workType:
@@ -964,6 +976,8 @@
        type: string
      vehicleSpeed:
        type: number
      workshopId:
        type: integer
      workshopName:
        description: 车间名
        type: string
@@ -1394,6 +1408,31 @@
        type: boolean
      name:
        description: 名称
        type: string
    type: object
  request.SavePayrollConstitute:
    properties:
      amount:
        description: 金额
        type: number
      cycle:
        description: 周期(月份)
        type: string
      salaryPlanId:
        description: 薪资方案ID
        type: integer
      workTypeCode:
        allOf:
        - $ref: '#/definitions/constvar.JobType'
        description: 工种代码
      workTypeID:
        description: 工种ID
        type: integer
      workTypeName:
        description: 工种名称
        type: string
      workerId:
        description: 员工ID
        type: string
    type: object
  request.SaveRankStandard:
@@ -2593,6 +2632,58 @@
      summary: 删除薪酬方案
      tags:
      - 员工薪资/薪酬方案
  /api-jl/v1/salary/getPayrollConstituteList:
    get:
      parameters:
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      - description: 统计周期按月查询(年-月)
        in: query
        name: cycle
        type: string
      - description: 关键字
        in: query
        name: keyword
        type: string
      - description: 页码
        in: query
        name: page
        type: integer
      - description: 每页大小
        in: query
        name: pageSize
        type: integer
      - description: 工种编码
        in: query
        name: workTypeCode
        type: string
      - description: 工种ID
        in: query
        name: workTypeID
        type: integer
      - description: 员工ID
        in: query
        name: workerID
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.ResponseList'
            - properties:
                data:
                  additionalProperties: true
                  type: object
              type: object
      summary: 获取人员每月的薪资列表
      tags:
      - 员工薪资/薪酬方案
  /api-jl/v1/salary/getPayrollProductionCarList:
    get:
      parameters:
@@ -2821,6 +2912,30 @@
      summary: 获取薪资类型列表
      tags:
      - 员工薪资/薪酬方案
  /api-jl/v1/salary/savePayrollConstitute:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.SavePayrollConstitute'
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 薪酬数额调整
      tags:
      - 员工薪资/薪酬方案
  /api-jl/v1/salary/saveSalaryPlan:
    post:
      parameters:
@@ -2914,7 +3029,6 @@
        - 2
        - 3
        - 4
        - 5
        in: query
        name: dictType
        type: integer
@@ -2922,14 +3036,12 @@
          DictTypeColor: 颜色
          DictTypeMarket: 庄口
          DictTypeSpec: 规格
          DictTypeSubsidy: 补贴
          DictTypeWorkshop: 车间
        x-enum-varnames:
        - DictTypeMarket
        - DictTypeWorkshop
        - DictTypeColor
        - DictTypeSpec
        - DictTypeSubsidy
      - description: 搜索关键字
        in: query
        name: keyword
models/payroll_constitute.go
@@ -4,12 +4,13 @@
    "fmt"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
    "math/rand"
    "silkserver/constvar"
    "silkserver/pkg/mysqlx"
)
type (
    // PayrollConstitute 其它补贴、奖惩
    // PayrollConstitute 薪资分类项
    PayrollConstitute struct {
        BaseModelInt
        Cycle         string           `json:"cycle" gorm:"index;size:20;not null;comment:统计周期(yyyy-MM)"` //月份
@@ -18,17 +19,19 @@
        WorkTypeID    uint             `json:"workTypeID" gorm:"type:bigint(20);not null;comment:工种ID"`      //工种ID
        WorkType      WorkTypeManage   `json:"workType" gorm:"foreignKey:WorkTypeID;references:ID"`          //工种ID
        WorkTypeCode  constvar.JobType `json:"workTypeCode" gorm:"size:255;not null;comment:工种代码"`           //工种代码
        WorkTypeName  string           `json:"workTypeName" gorm:"size:255;not null;comment:工种名称"`           //工种名称
        WorkTypeName  string           `json:"workTypeName" gorm:"size:255;comment:工种名称"`                    //工种名称
        SalaryPlanId  uint             `json:"salaryPlanId" gorm:"type:bigint(20);not null;comment:薪资方案ID"`  //薪资方案ID
        SalaryPlan    SalaryPlan       `json:"subsidyTypeName" gorm:"foreignKey:SalaryPlanId;references:ID"` //薪资方案
        SalaryFormula string           `json:"salaryFormula" gorm:"size:255;not null;comment:薪资方案(翻译)"`      //薪资方案
        SalaryFormula string           `json:"salaryFormula" gorm:"size:255;comment:薪资方案(翻译)"`               //薪资方案
        Amount        decimal.Decimal  `json:"amount" gorm:"type:decimal(12,4);comment:金额"`                  // 金额
        CreatedBy     string           `json:"createdBy" gorm:"size:255;not null;comment:添加者"`               // 添加者(auto,用户id)
    }
    PayrollConstituteSearch struct {
        PayrollConstitute
        Monthly  string
        Monthly string
        Keyword string
        Order    string
        PageNum  int
        PageSize int
@@ -41,7 +44,7 @@
    return "silk_payroll_constitute"
}
// NewPayrollConstituteSearch 其它补贴
// NewPayrollConstituteSearch 薪资分类项
func NewPayrollConstituteSearch() *PayrollConstituteSearch {
    return &PayrollConstituteSearch{Orm: mysqlx.GetDB()}
}
@@ -81,6 +84,16 @@
    return slf
}
func (slf *PayrollConstituteSearch) SetWorkTypeCode(workTypeCode string) *PayrollConstituteSearch {
    slf.WorkTypeCode = constvar.JobType(workTypeCode)
    return slf
}
func (slf *PayrollConstituteSearch) SetSalaryPlanId(salaryPlanId uint) *PayrollConstituteSearch {
    slf.SalaryPlanId = salaryPlanId
    return slf
}
func (slf *PayrollConstituteSearch) SetWorkerID(workerID string) *PayrollConstituteSearch {
    slf.WorkerID = workerID
    return slf
@@ -114,16 +127,25 @@
        db = db.Where("work_type_id = ?", slf.WorkTypeID)
    }
    if slf.WorkerID != "" {
        db = db.Where("worker_id = ?", slf.WorkerID)
    if slf.WorkTypeCode != "" {
        db = db.Where("work_type_code = ?", slf.WorkTypeCode)
    }
    if slf.WorkerID != "" {
        db = db.Where("worker_id = ?", slf.WorkerID)
    }
    if slf.SalaryPlanId > 0 {
        db = db.Where("salary_plan_id = ?", slf.SalaryPlanId)
    }
    if slf.CreatedBy != "" {
        db = db.Where("created_by = ?", slf.SalaryPlanId)
        db = db.Where("created_by = ?", slf.CreatedBy)
    }
    if slf.Keyword != "" {
        key := "%" + slf.Keyword + "%"
        db = db.Where("work_type_name like ?", key)
    }
    db.Where("1 = 1")
@@ -304,3 +326,68 @@
    return records, nil
}
type ConstituteGroup struct {
    Cycle        string           `json:"cycle"`        //月份
    WorkerID     string           `json:"workerId"`     //员工ID
    WorkTypeCode constvar.JobType `json:"workTypeCode"` //工种代码
    SalaryPlanId uint             `json:"salaryPlanId"` //薪资方案ID
}
// ConstituteGroup 本月统计了工资的人员
func (slf *PayrollConstituteSearch) ConstituteGroup(cg *ConstituteGroup) ([]*ConstituteGroup, error) {
    var (
        records = make([]*ConstituteGroup, 0)
        db      = slf.Orm.Table(slf.TableName())
    )
    db.Select("cycle,worker_id,work_type_code,salary_plan_id")
    db.Where("cycle = ?", cg.Cycle)
    if cg.WorkerID != "" {
        db.Where("worker_id = ?", cg.WorkerID)
    }
    if cg.WorkTypeCode != "" {
        db.Where("work_type_code = ?", cg.WorkTypeCode)
    }
    if cg.SalaryPlanId > 0 {
        db.Where("salary_plan_id = ?", cg.SalaryPlanId)
    }
    db.Group("cycle,worker_id,work_type_code,salary_plan_id")
    return records, db.Find(&records).Error
}
// InitDefaultData 初始化数据
func (slf *PayrollConstituteSearch) InitDefaultData() error {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    date := "2024-06"
    if err := db.Where("cycle = ?", date).Count(&total).Error; err != nil {
        return err
    }
    if total != 0 {
        return nil
    }
    data := make([]*PayrollConstitute, 0)
    workers, _ := NewWorkerSearch().FindNotTotal()
    for _, record := range workers {
        r := rand.Intn(10)
        data = append(data, &PayrollConstitute{
            Cycle:        date,
            WorkerID:     record.ID,
            WorkTypeID:   uint(r + 1),
            WorkTypeCode: constvar.JobTypeArr[r],
            WorkTypeName: constvar.JobTypeMap[constvar.JobTypeArr[r]],
            SalaryPlanId: 7,
            Amount:       decimal.NewFromInt32(int32(r * 100)),
            CreatedBy:    "auto",
        })
    }
    err := slf.CreateBatch(data)
    if err != nil {
        return err
    }
    return nil
}
router/router.go
@@ -104,6 +104,8 @@
        salaryApi.GET("getPayrollProductionCarList", salaryPlanController.GetPayrollProductionCarList)     //获取车台每天的产量列表
        salaryApi.GET("getPayrollProductionGroupList", salaryPlanController.GetPayrollProductionGroupList) //获取小组每天的产量列表
        salaryApi.GET("getPayrollSalaryPlanList", salaryPlanController.GetPayrollSalaryPlanList)           //获取人员每月的薪资列表
        salaryApi.POST("savePayrollConstitute", salaryPlanController.SavePayrollConstitute)                //薪酬数额调整
        salaryApi.GET("getPayrollConstituteList", salaryPlanController.GetPayrollConstituteList)           //获取人员每月的薪资列表
    }
    //考勤管理
service/salary_plan.go
@@ -696,7 +696,8 @@
// 根据方案计算各工种薪资
func salaryCalculate(parameter *SalaryParameter, salaryPlan *models.SalaryPlan) (string, decimal.Decimal) {
    formula := strings.ReplaceAll(salaryPlan.SalaryFormula, " ", "")
    formula := strings.ReplaceAll(salaryPlan.SalaryFormula, ",", "")
    formula = strings.ReplaceAll(salaryPlan.SalaryFormula, " ", "")
    //var SplitFixedField = []string{"日产丝量", "生丝单价", "桶数", "野纤数量", "野纤单价", "同组挡车工月平均工资", "同组车头工工资", "出勤天数"}
    formula = strings.Replace(formula, "日产丝量*生丝单价", parameter.SilkTotalAmount.String(), -1)
    formula = strings.Replace(formula, "野纤数量*野纤单价", parameter.BadSilkTotalAmount.String(), -1)
@@ -709,6 +710,8 @@
    formula = strings.Replace(formula, "同组车头工工资", parameter.GroupCarHeadAvgAmount.String(), -1)
    formula = strings.Replace(formula, "出勤天数", parameter.JobDays.String(), -1)
    logx.Debugf("salary formula: %v", formula)
    result, err := calculator.ParseAndExec(formula)
    if err != nil {
        logx.Errorf("%s : %v", formula, err)