From a9a16bf0aabf5323a658d79a87473008d2197584 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 10 七月 2023 14:10:45 +0800
Subject: [PATCH] add
---
api/v1/index.go | 2
model/request/status.go | 14 +
router/status.go | 19 +
service/status.go | 59 ++++
pkg/ecode/code.go | 7
docs/swagger.yaml | 94 +++++++
docs/docs.go | 147 ++++++++++++
api/v1/status.go | 112 +++++++++
docs/swagger.json | 147 ++++++++++++
model/response/response.go | 4
service/index.go | 1
model/status.go | 86 +++++++
model/index.go | 1
router/index.go | 2
14 files changed, 695 insertions(+), 0 deletions(-)
diff --git a/api/v1/index.go b/api/v1/index.go
index 3c575ef..54ebbba 100644
--- a/api/v1/index.go
+++ b/api/v1/index.go
@@ -30,6 +30,7 @@
SaleTypeApi
RegularCustomersApi
PossibilityApi
+ StatusApi
}
var ApiGroup = new(Group)
@@ -59,4 +60,5 @@
saleTypeService = service.ServiceGroup.SaleTypeService
regularCustomersService = service.ServiceGroup.RegularCustomersService
possibilityService = service.ServiceGroup.PossibilityService
+ statusService = service.ServiceGroup.StatusService
)
diff --git a/api/v1/status.go b/api/v1/status.go
new file mode 100644
index 0000000..57729bc
--- /dev/null
+++ b/api/v1/status.go
@@ -0,0 +1,112 @@
+package v1
+
+import (
+ "aps_crm/model"
+ "aps_crm/model/request"
+ "aps_crm/model/response"
+ "aps_crm/pkg/contextx"
+ "aps_crm/pkg/ecode"
+ "github.com/gin-gonic/gin"
+ "strconv"
+)
+
+type StatusApi struct{}
+
+// Add
+//
+// @Tags Status
+// @Summary 娣诲姞鐘舵��
+// @Produce application/json
+// @Param object body request.AddStatus true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/status/add [post]
+func (s *StatusApi) Add(c *gin.Context) {
+ var params request.AddStatus
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ status := new(model.Status)
+ status.Name = params.Name
+
+ errCode := statusService.AddStatus(status)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Delete
+//
+// @Tags Status
+// @Summary 鍒犻櫎鐘舵��
+// @Produce application/json
+// @Param id path int true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/status/delete/{id} [delete]
+func (s *StatusApi) Delete(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+
+ id, _ := strconv.Atoi(c.Param("id"))
+ errCode := statusService.DeleteStatus(id)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Update
+//
+// @Tags Status
+// @Summary 鏇存柊鐘舵��
+// @Produce application/json
+// @Param object body request.UpdateStatusList true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/status/update [put]
+func (s *StatusApi) Update(c *gin.Context) {
+ var params request.UpdateStatusList
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ errCode := statusService.UpdateStatus(params.List)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// List
+//
+// @Tags Status
+// @Summary 鐘舵�佸垪琛�
+// @Produce application/json
+// @Success 200 {object} contextx.Response{}
+// @Router /api/status/list [get]
+func (s *StatusApi) List(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+
+ list, errCode := statusService.GetStatusList()
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.OkWithDetailed(response.StatusResponse{
+ List: list,
+ })
+}
diff --git a/docs/docs.go b/docs/docs.go
index e2eca69..6cbada4 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -2818,6 +2818,113 @@
}
}
},
+ "/api/status/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "娣诲姞鐘舵��",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddStatus"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鍒犻櫎鐘舵��",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鐘舵�佸垪琛�",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鏇存柊鐘舵��",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateStatusList"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/user/changePassword": {
"post": {
"produces": [
@@ -4400,6 +4507,17 @@
}
}
},
+ "request.AddStatus": {
+ "type": "object",
+ "required": [
+ "name"
+ ],
+ "properties": {
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"request.ChangePasswordReq": {
"type": "object",
"properties": {
@@ -5476,6 +5594,35 @@
}
}
},
+ "request.UpdateStatus": {
+ "type": "object",
+ "required": [
+ "id",
+ "name"
+ ],
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "request.UpdateStatusList": {
+ "type": "object",
+ "required": [
+ "list"
+ ],
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/request.UpdateStatus"
+ }
+ }
+ }
+ },
"response.CityResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 6f711d6..9805666 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -2806,6 +2806,113 @@
}
}
},
+ "/api/status/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "娣诲姞鐘舵��",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddStatus"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鍒犻櫎鐘舵��",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鐘舵�佸垪琛�",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/status/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Status"
+ ],
+ "summary": "鏇存柊鐘舵��",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateStatusList"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/user/changePassword": {
"post": {
"produces": [
@@ -4388,6 +4495,17 @@
}
}
},
+ "request.AddStatus": {
+ "type": "object",
+ "required": [
+ "name"
+ ],
+ "properties": {
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"request.ChangePasswordReq": {
"type": "object",
"properties": {
@@ -5464,6 +5582,35 @@
}
}
},
+ "request.UpdateStatus": {
+ "type": "object",
+ "required": [
+ "id",
+ "name"
+ ],
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "request.UpdateStatusList": {
+ "type": "object",
+ "required": [
+ "list"
+ ],
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/request.UpdateStatus"
+ }
+ }
+ }
+ },
"response.CityResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 219a2f8..6c8e6f6 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -895,6 +895,13 @@
required:
- name
type: object
+ request.AddStatus:
+ properties:
+ name:
+ type: string
+ required:
+ - name
+ type: object
request.ChangePasswordReq:
properties:
newPassword:
@@ -1632,6 +1639,25 @@
items:
$ref: '#/definitions/request.UpdateSalesSources'
type: array
+ type: object
+ request.UpdateStatus:
+ properties:
+ id:
+ type: integer
+ name:
+ type: string
+ required:
+ - id
+ - name
+ type: object
+ request.UpdateStatusList:
+ properties:
+ list:
+ items:
+ $ref: '#/definitions/request.UpdateStatus'
+ type: array
+ required:
+ - list
type: object
response.CityResponse:
properties:
@@ -3524,6 +3550,74 @@
summary: 鏇存柊鍟嗘満鏉ユ簮
tags:
- SalesSources
+ /api/status/add:
+ post:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.AddStatus'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 娣诲姞鐘舵��
+ tags:
+ - Status
+ /api/status/delete/{id}:
+ delete:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: path
+ name: id
+ required: true
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鍒犻櫎鐘舵��
+ tags:
+ - Status
+ /api/status/list:
+ get:
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鐘舵�佸垪琛�
+ tags:
+ - Status
+ /api/status/update:
+ put:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.UpdateStatusList'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鏇存柊鐘舵��
+ tags:
+ - Status
/api/user/changePassword:
post:
parameters:
diff --git a/model/index.go b/model/index.go
index 27988b4..0601b4d 100644
--- a/model/index.go
+++ b/model/index.go
@@ -45,6 +45,7 @@
SaleType{},
RegularCustomers{},
Possibility{},
+ Status{},
)
return err
}
diff --git a/model/request/status.go b/model/request/status.go
new file mode 100644
index 0000000..de2d202
--- /dev/null
+++ b/model/request/status.go
@@ -0,0 +1,14 @@
+package request
+
+type AddStatus struct {
+ Name string `json:"name" binding:"required"`
+}
+
+type UpdateStatus struct {
+ Id int `json:"id" binding:"required"`
+ Name string `json:"name" binding:"required"`
+}
+
+type UpdateStatusList struct {
+ List []*UpdateStatus `json:"list" binding:"required"`
+}
diff --git a/model/response/response.go b/model/response/response.go
index 71e7f48..07ce959 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -117,4 +117,8 @@
PossibilityResponse struct {
List []*model.Possibility `json:"list"`
}
+
+ StatusResponse struct {
+ List []*model.Status `json:"list"`
+ }
)
diff --git a/model/status.go b/model/status.go
new file mode 100644
index 0000000..a8cb7f9
--- /dev/null
+++ b/model/status.go
@@ -0,0 +1,86 @@
+package model
+
+import (
+ "aps_crm/pkg/mysqlx"
+ "gorm.io/gorm"
+)
+
+type (
+ // Status 鐘舵��
+ Status struct {
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鐘舵�佸悕绉�"`
+ }
+
+ // StatusSearch 鐘舵�佹悳绱㈡潯浠�
+ StatusSearch struct {
+ Status
+ Orm *gorm.DB
+ }
+)
+
+func (Status) TableName() string {
+ return "status"
+}
+
+func NewStatusSearch() *StatusSearch {
+ return &StatusSearch{
+ Orm: mysqlx.GetDB(),
+ }
+}
+
+func (slf *StatusSearch) build() *gorm.DB {
+ var db = slf.Orm.Model(&Status{})
+ if slf.Id != 0 {
+ db = db.Where("id = ?", slf.Id)
+ }
+ if slf.Name != "" {
+ db = db.Where("name = ?", slf.Name)
+ }
+
+ return db
+}
+
+func (slf *StatusSearch) Create(record *Status) error {
+ var db = slf.build()
+ return db.Create(record).Error
+}
+
+func (slf *StatusSearch) Delete() error {
+ var db = slf.build()
+ return db.Delete(&Status{}).Error
+}
+
+func (slf *StatusSearch) Update(record *Status) error {
+ var db = slf.build()
+ return db.Updates(record).Error
+}
+
+func (slf *StatusSearch) Find() (*Status, error) {
+ var db = slf.build()
+ var record = &Status{}
+ err := db.First(record).Error
+ return record, err
+}
+
+func (slf *StatusSearch) FindAll() ([]*Status, error) {
+ var db = slf.build()
+ var records = make([]*Status, 0)
+ err := db.Find(&records).Error
+ return records, err
+}
+
+func (slf *StatusSearch) SetId(id int) *StatusSearch {
+ slf.Id = id
+ return slf
+}
+
+func (slf *StatusSearch) SetName(name string) *StatusSearch {
+ slf.Name = name
+ return slf
+}
+
+func (slf *StatusSearch) Updates(data map[string]interface{}) error {
+ var db = slf.build()
+ return db.Updates(data).Error
+}
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 1307751..73faad0 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -170,4 +170,11 @@
PossibilityUpdateErr = 2300005 // 鏇存柊閿�鍞満浼氬彲鑳芥�уけ璐�
PossibilityDeleteErr = 2300006 // 鍒犻櫎閿�鍞満浼氬彲鑳芥�уけ璐�
+ StatusExist = 2400001 // 閿�鍞満浼氱姸鎬佸凡瀛樺湪
+ StatusNotExist = 2400002 // 閿�鍞満浼氱姸鎬佷笉瀛樺湪
+ StatusListErr = 2400003 // 鑾峰彇閿�鍞満浼氱姸鎬佸垪琛ㄥけ璐�
+ StatusSetErr = 2400004 // 璁剧疆閿�鍞満浼氱姸鎬佸け璐�
+ StatusUpdateErr = 2400005 // 鏇存柊閿�鍞満浼氱姸鎬佸け璐�
+ StatusDeleteErr = 2400006 // 鍒犻櫎閿�鍞満浼氱姸鎬佸け璐�
+
)
diff --git a/router/index.go b/router/index.go
index 52471eb..d9f823d 100644
--- a/router/index.go
+++ b/router/index.go
@@ -36,6 +36,7 @@
SaleTypeRouter
RegularCustomersRouter
PossibilityRouter
+ StatusRouter
}
func InitRouter() *gin.Engine {
@@ -89,6 +90,7 @@
routerGroup.InitSaleTypeRouter(PrivateGroup) // 娉ㄥ唽saleType璺敱
routerGroup.InitRegularCustomersRouter(PrivateGroup) // 娉ㄥ唽regularCustomers璺敱
routerGroup.InitPossibilityRouter(PrivateGroup) // 娉ㄥ唽possibility璺敱
+ routerGroup.InitStatusRouter(PrivateGroup) // 娉ㄥ唽status璺敱
}
return Router
}
diff --git a/router/status.go b/router/status.go
new file mode 100644
index 0000000..5536c4b
--- /dev/null
+++ b/router/status.go
@@ -0,0 +1,19 @@
+package router
+
+import (
+ v1 "aps_crm/api/v1"
+ "github.com/gin-gonic/gin"
+)
+
+type StatusRouter struct{}
+
+func (s *StatusRouter) InitStatusRouter(router *gin.RouterGroup) {
+ statusRouter := router.Group("status")
+ statusApi := v1.ApiGroup.StatusApi
+ {
+ statusRouter.POST("add", statusApi.Add) // 娣诲姞鐘舵��
+ statusRouter.DELETE("delete/:id", statusApi.Delete) // 鍒犻櫎鐘舵��
+ statusRouter.PUT("update", statusApi.Update) // 鏇存柊鐘舵��
+ statusRouter.GET("list", statusApi.List) // 鑾峰彇鐘舵�佸垪琛�
+ }
+}
diff --git a/service/index.go b/service/index.go
index 60ed2a6..0e56603 100644
--- a/service/index.go
+++ b/service/index.go
@@ -25,6 +25,7 @@
SaleTypeService
RegularCustomersService
PossibilityService
+ StatusService
}
var ServiceGroup = new(Group)
diff --git a/service/status.go b/service/status.go
new file mode 100644
index 0000000..f9cc80f
--- /dev/null
+++ b/service/status.go
@@ -0,0 +1,59 @@
+package service
+
+import (
+ "aps_crm/model"
+ "aps_crm/model/request"
+ "aps_crm/pkg/ecode"
+)
+
+type StatusService struct{}
+
+func (StatusService) AddStatus(status *model.Status) int {
+ err := model.NewStatusSearch().Create(status)
+ if err != nil {
+ return ecode.StatusExist
+ }
+
+ return ecode.OK
+}
+
+func (StatusService) DeleteStatus(id int) int {
+ _, err := model.NewStatusSearch().SetId(id).Find()
+ if err != nil {
+ return ecode.StatusNotExist
+ }
+
+ err = model.NewStatusSearch().SetId(id).Delete()
+ if err != nil {
+ return ecode.StatusNotExist
+ }
+ return ecode.OK
+}
+
+func (StatusService) GetStatusList() ([]*model.Status, int) {
+ list, err := model.NewStatusSearch().FindAll()
+ if err != nil {
+ return nil, ecode.StatusListErr
+ }
+
+ return list, ecode.OK
+}
+
+func (StatusService) UpdateStatus(statuses []*request.UpdateStatus) int {
+ for _, v := range statuses {
+ // check status exist
+ _, err := model.NewStatusSearch().SetId(v.Id).Find()
+ if err != nil {
+ return ecode.StatusNotExist
+ }
+
+ err = model.NewStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
+ "name": v.Name,
+ })
+ if err != nil {
+ return ecode.StatusSetErr
+ }
+ }
+
+ return ecode.OK
+}
--
Gitblit v1.8.0