From 61bebbdb99d6c1ca95236cc567a9718bc5f5b1eb Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 19 四月 2024 15:07:51 +0800
Subject: [PATCH] 带徒管理增删改查接口
---
controllers/request/mentor.go | 19
controllers/request/worker_request.go | 6
models/mentor.go | 293 ++++++++++++++
models/db.go | 1
docs/swagger.yaml | 171 ++++++++
controllers/mentor_controller.go | 153 +++++++
docs/docs.go | 260 ++++++++++++
docs/swagger.json | 260 ++++++++++++
router/router.go | 9
9 files changed, 1,160 insertions(+), 12 deletions(-)
diff --git a/controllers/mentor_controller.go b/controllers/mentor_controller.go
new file mode 100644
index 0000000..0eaaa56
--- /dev/null
+++ b/controllers/mentor_controller.go
@@ -0,0 +1,153 @@
+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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ 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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ 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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ 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, "鏃犳晥鐨刬d")
+ return
+ }
+ idInt := cast.ToUint(id)
+ if idInt == 0 {
+ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥鐨刬d")
+ return
+ }
+ err := models.NewMentorSearch().SetId(idInt).Delete()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
+}
diff --git a/controllers/request/mentor.go b/controllers/request/mentor.go
new file mode 100644
index 0000000..76f5492
--- /dev/null
+++ b/controllers/request/mentor.go
@@ -0,0 +1,19 @@
+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"`
+}
diff --git a/controllers/request/worker_request.go b/controllers/request/worker_request.go
index 2b8166e..1978712 100644
--- a/controllers/request/worker_request.go
+++ b/controllers/request/worker_request.go
@@ -4,17 +4,17 @@
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 {
diff --git a/docs/docs.go b/docs/docs.go
index 87fb0fa..46adac4 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -504,6 +504,167 @@
}
}
},
+ "/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": [
@@ -2066,6 +2227,46 @@
}
}
},
+ "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": {
@@ -2558,6 +2759,23 @@
}
}
},
+ "request.AddMentorRequest": {
+ "type": "object",
+ "properties": {
+ "days": {
+ "description": "澶╂暟",
+ "type": "integer"
+ },
+ "month": {
+ "description": "鏈堜唤",
+ "type": "string"
+ },
+ "workerId": {
+ "description": "宸ヤ汉ID",
+ "type": "string"
+ }
+ }
+ },
"request.ChangeYieldRegister": {
"type": "object",
"properties": {
@@ -2621,10 +2839,26 @@
}
}
},
+ "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": {
@@ -2640,7 +2874,7 @@
"request.GetWorkTypeList": {
"type": "object",
"properties": {
- "keyWord": {
+ "keyword": {
"type": "string"
},
"page": {
@@ -2656,7 +2890,7 @@
"request.GetWorkerList": {
"type": "object",
"properties": {
- "keyWord": {
+ "keyword": {
"type": "string"
},
"page": {
@@ -2831,6 +3065,26 @@
}
}
},
+ "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": {
diff --git a/docs/swagger.json b/docs/swagger.json
index a107c35..5adcd81 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -492,6 +492,167 @@
}
}
},
+ "/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": [
@@ -2054,6 +2215,46 @@
}
}
},
+ "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": {
@@ -2546,6 +2747,23 @@
}
}
},
+ "request.AddMentorRequest": {
+ "type": "object",
+ "properties": {
+ "days": {
+ "description": "澶╂暟",
+ "type": "integer"
+ },
+ "month": {
+ "description": "鏈堜唤",
+ "type": "string"
+ },
+ "workerId": {
+ "description": "宸ヤ汉ID",
+ "type": "string"
+ }
+ }
+ },
"request.ChangeYieldRegister": {
"type": "object",
"properties": {
@@ -2609,10 +2827,26 @@
}
}
},
+ "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": {
@@ -2628,7 +2862,7 @@
"request.GetWorkTypeList": {
"type": "object",
"properties": {
- "keyWord": {
+ "keyword": {
"type": "string"
},
"page": {
@@ -2644,7 +2878,7 @@
"request.GetWorkerList": {
"type": "object",
"properties": {
- "keyWord": {
+ "keyword": {
"type": "string"
},
"page": {
@@ -2819,6 +3053,26 @@
}
}
},
+ "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": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 7603dce..baf4f85 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -305,6 +305,32 @@
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:
@@ -634,6 +660,18 @@
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:
@@ -679,9 +717,20 @@
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: 椤电爜
@@ -692,7 +741,7 @@
type: object
request.GetWorkTypeList:
properties:
- keyWord:
+ keyword:
type: string
page:
description: 椤电爜
@@ -703,7 +752,7 @@
type: object
request.GetWorkerList:
properties:
- keyWord:
+ keyword:
type: string
page:
description: 椤电爜
@@ -817,6 +866,20 @@
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:
@@ -1342,6 +1405,108 @@
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:
diff --git a/models/db.go b/models/db.go
index 5fa289f..22c7d9f 100644
--- a/models/db.go
+++ b/models/db.go
@@ -87,6 +87,7 @@
Worker{},
WorkTypeManage{},
SalaryPlan{},
+ Mentor{},
)
return err
}
diff --git a/models/mentor.go b/models/mentor.go
new file mode 100644
index 0000000..24ed1d1
--- /dev/null
+++ b/models/mentor.go
@@ -0,0 +1,293 @@
+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
+}
diff --git a/router/router.go b/router/router.go
index e4e2fba..bac153d 100644
--- a/router/router.go
+++ b/router/router.go
@@ -100,5 +100,14 @@
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
}
--
Gitblit v1.8.0