New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "silkserver/controllers/request" |
| | | "silkserver/extend/code" |
| | | "silkserver/extend/util" |
| | | "silkserver/middleware" |
| | | "silkserver/models" |
| | | ) |
| | | |
| | | type MentorController struct { |
| | | } |
| | | |
| | | // CreateMentorInfo |
| | | // @Tags 带徒管理 |
| | | // @Summary 创建带徒信息 |
| | | // @Produce application/json |
| | | // @Param object body request.AddMentorRequest true "参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/mentor/createMentorInfo [post] |
| | | func (slf MentorController) CreateMentorInfo(c *gin.Context) { |
| | | var params request.AddMentorRequest |
| | | err := c.BindJSON(¶ms) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | if params.WorkerId == "" || params.Month == "" || params.Days == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | //查询是否重复 |
| | | _, err = models.NewMentorSearch().SetWorkerId(params.WorkerId).SetMonth(params.Month).First() |
| | | if err != gorm.ErrRecordNotFound { |
| | | util.ResponseFormat(c, code.RequestParamError, "请勿重复添加") |
| | | return |
| | | } |
| | | |
| | | record := &models.Mentor{ |
| | | WorkerId: params.WorkerId, |
| | | Month: params.Month, |
| | | Days: params.Days, |
| | | } |
| | | |
| | | info := middleware.GetUserInfo(c) |
| | | if info != nil { |
| | | record.Creator = info.NickName |
| | | } |
| | | |
| | | err = models.NewMentorSearch().Create(record) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "创建失败, 请重试") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "创建成功") |
| | | } |
| | | |
| | | // UpdateMentorInfo |
| | | // @Tags 带徒管理 |
| | | // @Summary 更新带徒信息 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateMentorRequest true "参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/mentor/updateMentorInfo [post] |
| | | func (slf MentorController) UpdateMentorInfo(c *gin.Context) { |
| | | var params request.UpdateMentorRequest |
| | | err := c.BindJSON(¶ms) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.ID == 0 || params.WorkerId == "" || params.Month == "" || params.Days == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | record := &models.Mentor{ |
| | | WorkerId: params.WorkerId, |
| | | Month: params.Month, |
| | | Days: params.Days, |
| | | } |
| | | |
| | | info := middleware.GetUserInfo(c) |
| | | if info != nil { |
| | | record.Creator = info.NickName |
| | | } |
| | | |
| | | err = models.NewMentorSearch().SetId(params.ID).Update(record) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "更新失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "更新成功") |
| | | } |
| | | |
| | | // GetMentorList |
| | | // |
| | | // @Tags 带徒管理 |
| | | // @Summary 获取带徒信息列表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetMentorList true "参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Mentor} "成功" |
| | | // @Router /api-jl/v1/mentor/getMentorList [post] |
| | | func (slf MentorController) GetMentorList(c *gin.Context) { |
| | | var params request.GetMentorList |
| | | err := c.BindJSON(¶ms) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | mentors, total, err := models.NewMentorSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetPreload(true).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |
| | | } |
| | | util.ResponseFormatList(c, code.Success, mentors, total) |
| | | } |
| | | |
| | | // DeleteMentorInfo |
| | | // |
| | | // @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/mentor/deleteMentorInfo/{id} [delete] |
| | | func (slf MentorController) DeleteMentorInfo(c *gin.Context) { |
| | | id := c.Param("id") |
| | | if id == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "无效的id") |
| | | return |
| | | } |
| | | idInt := cast.ToUint(id) |
| | | if idInt == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "无效的id") |
| | | return |
| | | } |
| | | err := models.NewMentorSearch().SetId(idInt).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddMentorRequest struct { |
| | | WorkerId string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:工人ID" json:"workerId"` //工人ID |
| | | Month string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:月份" json:"month"` //月份 |
| | | Days int `gorm:"type:tinyint;not null;default:0;comment:天数" json:"days"` //天数 |
| | | } |
| | | |
| | | type UpdateMentorRequest struct { |
| | | ID uint `json:"id"` |
| | | WorkerId string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:工人ID" json:"workerId"` //工人ID |
| | | Month string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:月份" json:"month"` //月份 |
| | | Days int `gorm:"type:tinyint;not null;default:0;comment:天数" json:"days"` //天数 |
| | | } |
| | | |
| | | type GetMentorList struct { |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | } |
| | |
| | | |
| | | type GetWorkerList struct { |
| | | PageInfo |
| | | KeyWord string `json:"keyWord"` |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type GetWorkTypeList struct { |
| | | PageInfo |
| | | KeyWord string `json:"keyWord"` |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type GetSalaryPlanList struct { |
| | | PageInfo |
| | | KeyWord string `json:"keyWord"` |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type SalaryType struct { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/createMentorInfo": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "创建带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddMentorRequest" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/deleteMentorInfo/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "删除带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/getMentorList": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "获取带徒信息列表", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetMentorList" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.Mentor" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/updateMentorInfo": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "更新带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateMentorRequest" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/salary/deleteSalaryPlanInfo/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.Mentor": { |
| | | "type": "object", |
| | | "properties": { |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "type": "string" |
| | | }, |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | }, |
| | | "worker": { |
| | | "description": "工人ID", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/models.Worker" |
| | | } |
| | | ] |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "models.MiniDict": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddMentorRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ChangeYieldRegister": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetMentorList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | | }, |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.GetSalaryPlanList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | "request.GetWorkTypeList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | "request.GetWorkerList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateMentorRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.YieldRegisterCircleInfo": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/createMentorInfo": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "创建带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddMentorRequest" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/deleteMentorInfo/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "删除带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/getMentorList": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "获取带徒信息列表", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetMentorList" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.Mentor" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/mentor/updateMentorInfo": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "带徒管理" |
| | | ], |
| | | "summary": "更新带徒信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateMentorRequest" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/salary/deleteSalaryPlanInfo/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.Mentor": { |
| | | "type": "object", |
| | | "properties": { |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "type": "string" |
| | | }, |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | }, |
| | | "worker": { |
| | | "description": "工人ID", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/models.Worker" |
| | | } |
| | | ] |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "models.MiniDict": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddMentorRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ChangeYieldRegister": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetMentorList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | | }, |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.GetSalaryPlanList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | "request.GetWorkTypeList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | "request.GetWorkerList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyWord": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateMentorRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "days": { |
| | | "description": "天数", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "month": { |
| | | "description": "月份", |
| | | "type": "string" |
| | | }, |
| | | "workerId": { |
| | | "description": "工人ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.YieldRegisterCircleInfo": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | description: 数量 |
| | | type: integer |
| | | type: object |
| | | models.Mentor: |
| | | properties: |
| | | createdAt: |
| | | type: string |
| | | creator: |
| | | type: string |
| | | days: |
| | | description: 天数 |
| | | type: integer |
| | | deletedAt: |
| | | $ref: '#/definitions/gorm.DeletedAt' |
| | | id: |
| | | type: integer |
| | | month: |
| | | description: 月份 |
| | | type: string |
| | | updatedAt: |
| | | type: string |
| | | worker: |
| | | allOf: |
| | | - $ref: '#/definitions/models.Worker' |
| | | description: 工人ID |
| | | workerId: |
| | | description: 工人ID |
| | | type: string |
| | | type: object |
| | | models.MiniDict: |
| | | properties: |
| | | id: |
| | |
| | | description: 车组 |
| | | type: integer |
| | | type: object |
| | | request.AddMentorRequest: |
| | | properties: |
| | | days: |
| | | description: 天数 |
| | | type: integer |
| | | month: |
| | | description: 月份 |
| | | type: string |
| | | workerId: |
| | | description: 工人ID |
| | | type: string |
| | | type: object |
| | | request.ChangeYieldRegister: |
| | | properties: |
| | | createTime: |
| | |
| | | description: 合计 |
| | | type: number |
| | | type: object |
| | | request.GetMentorList: |
| | | properties: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | | pageSize: |
| | | description: 每页大小 |
| | | type: integer |
| | | type: object |
| | | request.GetSalaryPlanList: |
| | | properties: |
| | | keyWord: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | |
| | | type: object |
| | | request.GetWorkTypeList: |
| | | properties: |
| | | keyWord: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | |
| | | type: object |
| | | request.GetWorkerList: |
| | | properties: |
| | | keyWord: |
| | | keyword: |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | |
| | | type: string |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | | type: object |
| | | request.UpdateMentorRequest: |
| | | properties: |
| | | days: |
| | | description: 天数 |
| | | type: integer |
| | | id: |
| | | type: integer |
| | | month: |
| | | description: 月份 |
| | | type: string |
| | | workerId: |
| | | description: 工人ID |
| | | type: string |
| | | type: object |
| | | request.YieldRegisterCircleInfo: |
| | |
| | | summary: 保存产量登记表 |
| | | tags: |
| | | - 生产管理/产量登记表 |
| | | /api-jl/v1/mentor/createMentorInfo: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddMentorRequest' |
| | | - 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/mentor/deleteMentorInfo/{id}: |
| | | delete: |
| | | parameters: |
| | | - description: id |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: string |
| | | - 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/mentor/getMentorList: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.GetMentorList' |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/util.ResponseList' |
| | | - properties: |
| | | data: |
| | | items: |
| | | $ref: '#/definitions/models.Mentor' |
| | | type: array |
| | | type: object |
| | | summary: 获取带徒信息列表 |
| | | tags: |
| | | - 带徒管理 |
| | | /api-jl/v1/mentor/updateMentorInfo: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateMentorRequest' |
| | | - 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/deleteSalaryPlanInfo/{id}: |
| | | delete: |
| | | parameters: |
| | |
| | | Worker{}, |
| | | WorkTypeManage{}, |
| | | SalaryPlan{}, |
| | | Mentor{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "silkserver/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | // Mentor 带徒 |
| | | Mentor struct { |
| | | gorm.Model |
| | | WorkerId string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:工人ID" json:"workerId"` //工人ID |
| | | Worker Worker `gorm:"foreignkey:WorkerId" json:"worker"` //工人ID |
| | | Creator string `gorm:"type:varchar(255);not null;default:'';comment:添加人" json:"creator"` |
| | | Month string `gorm:"unique_index:worker_id_month;type:varchar(255);not null;default:'';comment:月份" json:"month"` //月份 |
| | | Days int `gorm:"type:tinyint;not null;default:0;comment:天数" json:"days"` //天数 |
| | | } |
| | | |
| | | MentorSearch struct { |
| | | Mentor |
| | | Keyword string |
| | | Preload bool |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Fields string |
| | | } |
| | | ) |
| | | |
| | | func (slf Mentor) TableName() string { |
| | | return "silk_mentor" |
| | | } |
| | | |
| | | func NewMentorSearch() *MentorSearch { |
| | | return &MentorSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetOrm(tx *gorm.DB) *MentorSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetPage(page, size int) *MentorSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetOrder(order string) *MentorSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetId(id uint) *MentorSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetKeyword(keyword string) *MentorSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetPreload(preload bool) *MentorSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetFields(fields string) *MentorSearch { |
| | | slf.Fields = fields |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetWorkerId(workerId string) *MentorSearch { |
| | | slf.WorkerId = workerId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) SetMonth(month string) *MentorSearch { |
| | | slf.Month = month |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MentorSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.Keyword != "" { |
| | | kw := "%" + slf.Keyword + "%" |
| | | db = db.Joins("Worker").Where("silk_mentor.worker_id LIKE ? or Worker.name LIKE ?", kw, kw) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&Mentor{}).Preload("Worker") |
| | | } |
| | | |
| | | if slf.Fields != "" { |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if slf.WorkerId != "" { |
| | | db = db.Where("worker_id = ?", slf.WorkerId) |
| | | } |
| | | |
| | | if slf.Month != "" { |
| | | db = db.Where("month = ?", slf.Month) |
| | | } |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | // Create 单条插入 |
| | | func (slf *MentorSearch) Create(record *Mentor) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return fmt.Errorf("create err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *MentorSearch) CreateBatch(records []*Mentor) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) Save(record *Mentor) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) Update(record *Mentor) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Updates(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) Delete() error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Delete(&Mentor{}).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) First() (*Mentor, error) { |
| | | var ( |
| | | record = new(Mentor) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) Find() ([]*Mentor, int64, error) { |
| | | var ( |
| | | records = make([]*Mentor, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) FindNotTotal() ([]*Mentor, error) { |
| | | var ( |
| | | records = make([]*Mentor, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | // FindByQuery 指定条件查询. |
| | | func (slf *MentorSearch) FindByQuery(query string, args []interface{}) ([]*Mentor, int64, error) { |
| | | var ( |
| | | records = make([]*Mentor, 0) |
| | | total int64 |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | // FindByQueryNotTotal 指定条件查询&不查询总条数. |
| | | func (slf *MentorSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Mentor, error) { |
| | | var ( |
| | | records = make([]*Mentor, 0) |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *MentorSearch) Count() (int64, error) { |
| | | var ( |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | return total, nil |
| | | } |
| | |
| | | salaryApi.POST("saveSalaryType", salaryPlanController.SaveSalaryType) //保存薪资类型 |
| | | } |
| | | |
| | | mentorApi := r.Group(urlPrefix + "/mentor") |
| | | mentorCtl := new(controllers.MentorController) |
| | | { |
| | | mentorApi.POST("createMentorInfo", mentorCtl.CreateMentorInfo) //创建带徒信息 |
| | | mentorApi.POST("updateMentorInfo", mentorCtl.UpdateMentorInfo) //更新带徒信息 |
| | | mentorApi.POST("getMentorList", mentorCtl.GetMentorList) //获取带徒信息列表 |
| | | mentorApi.DELETE("deleteMentorInfo/:id", mentorCtl.DeleteMentorInfo) //删除带徒信息 |
| | | } |
| | | |
| | | return r |
| | | } |