add
wangpengfei
2023-07-21 34c99ef40f26f8812610e7ca14c56825f9bf2c3c
add

accountId 账户
add, Delete, update, lis
5个文件已添加
10个文件已修改
824 ■■■■■ 已修改文件
api/v1/accountId.go 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 188 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 188 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/accountId.go 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/accountId.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/accountId.go 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/accountId.go 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/dataServer.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/accountId.go
New file
@@ -0,0 +1,113 @@
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 AccountIdApi struct{}
// Add
//
//    @Tags        AccountId
//    @Summary    添加账户
//    @Produce    application/json
//    @Param        object    body        request.AddAccountId    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/accountId/add [post]
func (s *AccountIdApi) Add(c *gin.Context) {
    var params request.AddAccountId
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    accountId := new(model.AccountId)
    accountId.Name = params.Name
    errCode := accountIdService.AddAccountId(accountId)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        AccountId
//    @Summary    删除账户
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/accountId/delete/{id} [delete]
func (s *AccountIdApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := accountIdService.DeleteAccountId(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        AccountId
//    @Summary    更新账户
//    @Produce    application/json
//    @Param        object    body        request.UpdateAccountIds    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/accountId/update [put]
func (s *AccountIdApi) Update(c *gin.Context) {
    var params request.UpdateAccountIds
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := accountIdService.UpdateAccountId(params.AccountIds)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        AccountId
//    @Summary    获取账户列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.AccountIdResponse}
//    @Router        /api/accountId/list [get]
func (s *AccountIdApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    accountIds, errCode := accountIdService.GetAccountIdList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.AccountIdResponse{
        List: accountIds,
    })
}
api/v1/index.go
@@ -5,6 +5,7 @@
)
type Group struct {
    AccountIdApi
    IsInvoiceApi
    RefundMethodApi
    ServiceContractTypeApi
@@ -118,4 +119,5 @@
   serviceContractTypeService    = service.ServiceGroup.ServiceContractTypeService
   refundMethodService    = service.ServiceGroup.RefundMethodService
   isInvoiceService    = service.ServiceGroup.IsInvoiceService
   accountIdService    = service.ServiceGroup.AccountIdService
)
docs/docs.go
@@ -16,6 +16,125 @@
    "host": "{{.Host}}",
    "basePath": "{{.BasePath}}",
    "paths": {
        "/api/accountId/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "添加账户",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddAccountId"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/accountId/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "删除账户",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/accountId/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "获取账户列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.AccountIdResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/accountId/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "更新账户",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateAccountIds"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/authority/add": {
            "post": {
                "security": [
@@ -6297,6 +6416,17 @@
                }
            }
        },
        "model.AccountId": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Authority": {
            "type": "object",
            "properties": {
@@ -7722,6 +7852,17 @@
                    "type": "string"
                },
                "uuid": {
                    "type": "string"
                }
            }
        },
        "request.AddAccountId": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
@@ -9260,6 +9401,35 @@
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            }
        },
        "request.UpdateAccountId": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateAccountIds": {
            "type": "object",
            "required": [
                "account_id"
            ],
            "properties": {
                "account_id": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateAccountId"
                    }
                }
            }
@@ -10830,6 +11000,17 @@
                }
            }
        },
        "response.AccountIdResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.AccountId"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
@@ -10932,6 +11113,13 @@
        "response.DataResponse": {
            "type": "object",
            "properties": {
                "accountId": {
                    "description": "账户",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.AccountId"
                    }
                },
                "city": {
                    "description": "城市数据",
                    "type": "array",
docs/swagger.json
@@ -4,6 +4,125 @@
        "contact": {}
    },
    "paths": {
        "/api/accountId/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "添加账户",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddAccountId"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/accountId/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "删除账户",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/accountId/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "获取账户列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.AccountIdResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/accountId/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "AccountId"
                ],
                "summary": "更新账户",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateAccountIds"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/authority/add": {
            "post": {
                "security": [
@@ -6285,6 +6404,17 @@
                }
            }
        },
        "model.AccountId": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Authority": {
            "type": "object",
            "properties": {
@@ -7710,6 +7840,17 @@
                    "type": "string"
                },
                "uuid": {
                    "type": "string"
                }
            }
        },
        "request.AddAccountId": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
@@ -9248,6 +9389,35 @@
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            }
        },
        "request.UpdateAccountId": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateAccountIds": {
            "type": "object",
            "required": [
                "account_id"
            ],
            "properties": {
                "account_id": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateAccountId"
                    }
                }
            }
@@ -10818,6 +10988,17 @@
                }
            }
        },
        "response.AccountIdResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.AccountId"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
@@ -10920,6 +11101,13 @@
        "response.DataResponse": {
            "type": "object",
            "properties": {
                "accountId": {
                    "description": "账户",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.AccountId"
                    }
                },
                "city": {
                    "description": "城市数据",
                    "type": "array",
docs/swagger.yaml
@@ -60,6 +60,13 @@
      msg:
        type: string
    type: object
  model.AccountId:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.Authority:
    properties:
      authorityName:
@@ -997,6 +1004,13 @@
        type: string
      uuid:
        type: string
    type: object
  request.AddAccountId:
    properties:
      name:
        type: string
    required:
    - name
    type: object
  request.AddAuthority:
    properties:
@@ -2038,6 +2052,25 @@
        items:
          type: integer
        type: array
    type: object
  request.UpdateAccountId:
    properties:
      id:
        type: integer
      name:
        type: string
    required:
    - id
    - name
    type: object
  request.UpdateAccountIds:
    properties:
      account_id:
        items:
          $ref: '#/definitions/request.UpdateAccountId'
        type: array
    required:
    - account_id
    type: object
  request.UpdateCities:
    properties:
@@ -3090,6 +3123,13 @@
    required:
    - timely_rate
    type: object
  response.AccountIdResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.AccountId'
        type: array
    type: object
  response.CityResponse:
    properties:
      list:
@@ -3155,6 +3195,11 @@
    type: object
  response.DataResponse:
    properties:
      accountId:
        description: 账户
        items:
          $ref: '#/definitions/model.AccountId'
        type: array
      city:
        description: 城市数据
        items:
@@ -3568,6 +3613,79 @@
info:
  contact: {}
paths:
  /api/accountId/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddAccountId'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加账户
      tags:
      - AccountId
  /api/accountId/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:
      - AccountId
  /api/accountId/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.AccountIdResponse'
              type: object
      summary: 获取账户列表
      tags:
      - AccountId
  /api/accountId/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateAccountIds'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新账户
      tags:
      - AccountId
  /api/authority/add:
    post:
      consumes:
model/accountId.go
New file
@@ -0,0 +1,85 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    // AccountId 商机阶段
    AccountId struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机阶段名称"`
    }
    AccountIdSearch struct {
        AccountId
        Orm *gorm.DB
    }
)
func (AccountId) TableName() string {
    return "account_id"
}
func NewAccountIdSearch() *AccountIdSearch {
    return &AccountIdSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *AccountIdSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&AccountId{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
func (slf *AccountIdSearch) Create(record *AccountId) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *AccountIdSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&AccountId{}).Error
}
func (slf *AccountIdSearch) Update(record *AccountId) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *AccountIdSearch) Find() (*AccountId, error) {
    var db = slf.build()
    var record = new(AccountId)
    err := db.First(record).Error
    return record, err
}
func (slf *AccountIdSearch) FindAll() ([]*AccountId, error) {
    var db = slf.build()
    var records = make([]*AccountId, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *AccountIdSearch) SetId(id int) *AccountIdSearch {
    slf.Id = id
    return slf
}
func (slf *AccountIdSearch) SetName(name string) *AccountIdSearch {
    slf.Name = name
    return slf
}
func (slf *AccountIdSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
model/index.go
@@ -74,6 +74,7 @@
        ServiceContractType{},
        RefundMethod{},
        IsInvoice{},
        AccountId{},
    )
    return err
}
model/request/accountId.go
New file
@@ -0,0 +1,15 @@
package request
type AddAccountId struct {
    Name string `  json:"name" binding:"required"`
}
type UpdateAccountId struct {
    Id   int    `json:"id" binding:"required"`
    Name string `json:"name" binding:"required"`
}
type UpdateAccountIds struct {
    AccountIds []*UpdateAccountId `json:"account_id" binding:"required"`
}
model/response/response.go
@@ -180,6 +180,10 @@
    DataResponse struct {
        // 账户
        AccountId []*model.AccountId `json:"accountId"`
        // 是否开票
        IsInvoice []*model.IsInvoice `json:"isInvoice"`
@@ -294,4 +298,8 @@
    IsInvoiceResponse struct {
        List []*model.IsInvoice `json:"list"`
    }
    AccountIdResponse struct {
        List []*model.AccountId `json:"list"`
    }
)
pkg/ecode/code.go
@@ -352,4 +352,11 @@
    IsInvoiceSetErr    = 5100004 // 设置是否开票失败
    IsInvoiceUpdateErr = 5100005 // 更新是否开票失败
)
    AccountIdExist     = 5000001 // 账户已存在
    AccountIdNotExist  = 5000002 // 账户不存在
    AccountIdListErr   = 5000003 // 获取账户列表失败
    AccountIdSetErr    = 5000004 // 设置账户失败
    AccountIdUpdateErr = 5000005 // 更新账户失败
)
router/accountId.go
New file
@@ -0,0 +1,20 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type AccountIdRouter struct{}
func (s *AccountIdRouter) InitAccountIdRouter(router *gin.RouterGroup) {
    accountIdRouter := router.Group("accountId")
    accountIdApi := v1.ApiGroup.AccountIdApi
    {
        accountIdRouter.POST("add", accountIdApi.Add)             // 添加$CName$
        accountIdRouter.DELETE("delete/:id", accountIdApi.Delete) // 删除$CName$
        accountIdRouter.PUT("update", accountIdApi.Update)        // 更新$CName$
        accountIdRouter.GET("list", accountIdApi.List)            // 获取$CName$列表
    }
}
router/index.go
@@ -11,6 +11,7 @@
)
type Group struct {
    AccountIdRouter
    IsInvoiceRouter
    RefundMethodRouter
    ServiceContractTypeRouter
@@ -147,6 +148,7 @@
        routerGroup.InitServiceContractTypeRouter(PrivateGroup)
        routerGroup.InitRefundMethodRouter(PrivateGroup)
        routerGroup.InitIsInvoiceRouter(PrivateGroup)
        routerGroup.InitAccountIdRouter(PrivateGroup)
    }
    return Router
}
service/accountId.go
New file
@@ -0,0 +1,69 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type AccountIdService struct{}
func (AccountIdService) AddAccountId(accountId *model.AccountId) int {
    err := model.NewAccountIdSearch().Create(accountId)
    if err != nil {
        return ecode.AccountIdExist
    }
    return ecode.OK
}
func (AccountIdService) DeleteAccountId(id int) int {
    _, err := model.NewAccountIdSearch().SetId(id).Find()
    if err != nil {
        return ecode.AccountIdNotExist
    }
    err = model.NewAccountIdSearch().SetId(id).Delete()
    if err != nil {
        return ecode.AccountIdNotExist
    }
    return ecode.OK
}
func (AccountIdService) GetAccountIdList() ([]*model.AccountId, int) {
    list, err := model.NewAccountIdSearch().FindAll()
    if err != nil {
        return nil, ecode.AccountIdListErr
    }
    return list, ecode.OK
}
func (AccountIdService) UpdateAccountId(accountIds []*request.UpdateAccountId) int {
    for _, v := range accountIds {
        // check accountId exist
        _, err := model.NewAccountIdSearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.AccountIdNotExist
        }
        err = model.NewAccountIdSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.AccountIdSetErr
        }
    }
    return ecode.OK
}
func (AccountIdService) GetAccountIdDetail(id int) (*model.AccountId, int) {
    accountId, err := model.NewAccountIdSearch().SetId(id).Find()
    if err != nil {
        return nil, ecode.AccountIdNotExist
    }
    return accountId, ecode.OK
}
service/dataServer.go
@@ -126,6 +126,11 @@
    data.IsInvoice = isInvoiceList
    // get AccountId list
    accountIdList, _ := ServiceGroup.GetAccountIdList()
    data.AccountId = accountIdList
    errCode = ecode.OK
    return
service/index.go
@@ -55,6 +55,7 @@
    ServiceContractTypeService
    RefundMethodService
    IsInvoiceService
    AccountIdService
}
var ServiceGroup = new(Group)