wangpengfei
2023-08-10 f2c7c7aa3218cd5ef688975ea9b5a0f3a6e5e74f
temp
5个文件已添加
8个文件已修改
611 ■■■■ 已修改文件
api/v1/collectionProjection.go 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/collectionProjection.go 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 216 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/collectionProjection.go 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/colletionProjection.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/collectionProjection.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/collectionProjection.go
New file
@@ -0,0 +1,40 @@
package v1
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "github.com/gin-gonic/gin"
)
type CollectionProjectionApi struct{}
// Add
//
//    @Tags        CollectionProjection
//    @Summary    添加收款预测
//    @Produce    application/json
//    @Param        object    body        request.AddCollectionProjection    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/collectionProjection/add [post]
func (cp *CollectionProjectionApi) Add(c *gin.Context) {
    var params request.AddCollectionProjection
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    tmp := new(model.CollectionProjection)
    tmp.EstimatedCollectionAmount = params.CollectionProjection.EstimatedCollectionAmount
    tmp.EstimatedCollectionDate = params.CollectionProjection.EstimatedCollectionTime
    tmp.SaleChanceId = params.CollectionProjection.SaleChanceId
    errCode := collectionProjectionService.AddCollectionProjection(tmp)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
api/v1/index.go
@@ -65,6 +65,7 @@
    VettingApi
    SatisfactionApi
    AssignApi
    CollectionProjectionApi
}
var ApiGroup = new(Group)
@@ -130,4 +131,5 @@
    quotationStatusService       = service.ServiceGroup.QuotationStatusService
    currencyService              = service.ServiceGroup.CurrencyService
    assignService                = service.ServiceGroup.AssignService
    collectionProjectionService  = service.ServiceGroup.CollectionProjectionService
)
docs/docs.go
@@ -1242,6 +1242,36 @@
                }
            }
        },
        "/api/collectionProjection/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CollectionProjection"
                ],
                "summary": "添加收款预测",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddCollectionProjection"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contact/add": {
            "post": {
                "produces": [
@@ -10457,6 +10487,12 @@
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
@@ -10706,7 +10742,7 @@
            "type": "object",
            "properties": {
                "amount": {
                    "type": "integer"
                    "type": "number"
                },
                "desc": {
                    "type": "string"
@@ -11380,6 +11416,13 @@
                "amountReceived": {
                    "description": "已收金额",
                    "type": "number"
                },
                "amountUnInvoiced": {
                    "description": "未开票金额",
                    "type": "number"
                },
                "client": {
                    "$ref": "#/definitions/model.Client"
                },
                "clientId": {
                    "type": "integer"
@@ -12060,6 +12103,23 @@
                }
            }
        },
        "request.AddCollectionProjection": {
            "type": "object",
            "properties": {
                "estimated_collection_amount": {
                    "description": "预计收款金额",
                    "type": "number"
                },
                "estimated_collection_time": {
                    "description": "预计收款时间",
                    "type": "string"
                },
                "sale_chance_id": {
                    "description": "销售机会id",
                    "type": "integer"
                }
            }
        },
        "request.AddContact": {
            "type": "object",
            "properties": {
@@ -12311,6 +12371,13 @@
                "principalId": {
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "description": "发票对应产品,从相应源单里获取",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
@@ -14907,6 +14974,9 @@
        },
        "request.UpdateInvoice": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "clientId": {
                    "description": "客户id",
@@ -14943,6 +15013,13 @@
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "description": "发票对应产品,从相应源单里获取",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
docs/swagger.json
@@ -1230,6 +1230,36 @@
                }
            }
        },
        "/api/collectionProjection/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "CollectionProjection"
                ],
                "summary": "添加收款预测",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddCollectionProjection"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contact/add": {
            "post": {
                "produces": [
@@ -10445,6 +10475,12 @@
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
@@ -10694,7 +10730,7 @@
            "type": "object",
            "properties": {
                "amount": {
                    "type": "integer"
                    "type": "number"
                },
                "desc": {
                    "type": "string"
@@ -11368,6 +11404,13 @@
                "amountReceived": {
                    "description": "已收金额",
                    "type": "number"
                },
                "amountUnInvoiced": {
                    "description": "未开票金额",
                    "type": "number"
                },
                "client": {
                    "$ref": "#/definitions/model.Client"
                },
                "clientId": {
                    "type": "integer"
@@ -12048,6 +12091,23 @@
                }
            }
        },
        "request.AddCollectionProjection": {
            "type": "object",
            "properties": {
                "estimated_collection_amount": {
                    "description": "预计收款金额",
                    "type": "number"
                },
                "estimated_collection_time": {
                    "description": "预计收款时间",
                    "type": "string"
                },
                "sale_chance_id": {
                    "description": "销售机会id",
                    "type": "integer"
                }
            }
        },
        "request.AddContact": {
            "type": "object",
            "properties": {
@@ -12299,6 +12359,13 @@
                "principalId": {
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "description": "发票对应产品,从相应源单里获取",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
@@ -14895,6 +14962,9 @@
        },
        "request.UpdateInvoice": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "clientId": {
                    "description": "客户id",
@@ -14931,6 +15001,13 @@
                    "description": "销售负责人id",
                    "type": "integer"
                },
                "products": {
                    "description": "发票对应产品,从相应源单里获取",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                },
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
docs/swagger.yaml
@@ -670,6 +670,10 @@
      principalId:
        description: 销售负责人id
        type: integer
      products:
        items:
          $ref: '#/definitions/model.Product'
        type: array
      sourceId:
        description: 源单id
        type: integer
@@ -832,7 +836,7 @@
  model.Product:
    properties:
      amount:
        type: integer
        type: number
      desc:
        type: string
      id:
@@ -1281,6 +1285,11 @@
      amountReceived:
        description: 已收金额
        type: number
      amountUnInvoiced:
        description: 未开票金额
        type: number
      client:
        $ref: '#/definitions/model.Client'
      clientId:
        type: integer
      contactId:
@@ -1744,6 +1753,18 @@
    required:
    - name
    type: object
  request.AddCollectionProjection:
    properties:
      estimated_collection_amount:
        description: 预计收款金额
        type: number
      estimated_collection_time:
        description: 预计收款时间
        type: string
      sale_chance_id:
        description: 销售机会id
        type: integer
    type: object
  request.AddContact:
    properties:
      birthday:
@@ -1916,6 +1937,11 @@
      principalId:
        description: 销售负责人id
        type: integer
      products:
        description: 发票对应产品,从相应源单里获取
        items:
          $ref: '#/definitions/model.Product'
        type: array
      sourceId:
        description: 源单id
        type: integer
@@ -3711,6 +3737,11 @@
      principalId:
        description: 销售负责人id
        type: integer
      products:
        description: 发票对应产品,从相应源单里获取
        items:
          $ref: '#/definitions/model.Product'
        type: array
      sourceId:
        description: 源单id
        type: integer
@@ -3723,6 +3754,8 @@
      taxpayerIdNumber:
        description: 纳税识别号
        type: string
    required:
    - id
    type: object
  request.UpdateInvoiceStatus:
    properties:
@@ -6067,6 +6100,25 @@
      summary: 更新客户类型
      tags:
      - ClientType
  /api/collectionProjection/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddCollectionProjection'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加收款预测
      tags:
      - CollectionProjection
  /api/contact/add:
    post:
      parameters:
model/collectionProjection.go
New file
@@ -0,0 +1,85 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    CollectionProjection struct {
        Id                        int     `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
        SaleChanceId              int     `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:销售机会id"`
        Creator                   int     `json:"creator" gorm:"column:creator;type:int(11);comment:创建人"`
        Modifier                  int     `json:"modifier" gorm:"column:modifier;type:int(11);comment:修改人"`
        EstimatedCollectionDate   string  `json:"estimated_collection_date" gorm:"column:estimated_collection_date;type:datetime;comment:预计收款日期"`
        EstimatedCollectionAmount float64 `json:"estimated_collection_amount" gorm:"column:estimated_collection_amount;type:decimal(10,2);comment:预计收款金额"`
        gorm.Model
    }
    CollectionProjectionSearch struct {
        CollectionProjection
        Orm      *gorm.DB
        OrderBy  string
        PageNum  int
        PageSize int
    }
)
func (CollectionProjection) TableName() string {
    return "collection_projection"
}
func NewCollectionProjectionSearch() *CollectionProjectionSearch {
    return &CollectionProjectionSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *CollectionProjectionSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&CollectionProjection{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    return db
}
func (slf *CollectionProjectionSearch) Create(record *CollectionProjection) (err error) {
    var db = slf.build()
    err = db.Create(record).Error
    return
}
func (slf *CollectionProjectionSearch) Update(record *CollectionProjection) (err error) {
    var db = slf.build()
    err = db.Updates(record).Error
    return
}
func (slf *CollectionProjectionSearch) Delete() (err error) {
    var db = slf.build()
    err = db.Delete(&CollectionProjection{}).Error
    return
}
func (slf *CollectionProjectionSearch) Find() (record CollectionProjection, err error) {
    var db = slf.build()
    err = db.First(&record).Error
    return
}
func (slf *CollectionProjectionSearch) SetID(id int) *CollectionProjectionSearch {
    slf.Id = id
    return slf
}
func (slf *CollectionProjectionSearch) SetSaleChanceId(saleChanceId int) *CollectionProjectionSearch {
    slf.SaleChanceId = saleChanceId
    return slf
}
func (slf *CollectionProjectionSearch) SetPage(page, size int) *CollectionProjectionSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
model/index.go
@@ -1,108 +1,108 @@
package model
import (
    "aps_crm/conf"
    "aps_crm/pkg/logx"
    "aps_crm/pkg/mysqlx"
    "aps_crm/pkg/safe"
    "gorm.io/gorm/schema"
)
func Init() error {
    if err := mysqlx.Init(&conf.Conf.Mysql, logx.GetLogger()); err != nil {
        return err
    }
    if err := RegisterTables(); err != nil {
        return err
    }
    safe.Go(func() {
        InsertDefaultData()
    })
    return nil
}
func RegisterTables() error {
    db := mysqlx.GetDB()
    err := db.AutoMigrate(
        User{},
        Menu{},
        JwtBlacklist{},
        Country{},
        Province{},
        City{},
        Client{},
        ClientLevel{},
        ClientOrigin{},
        ClientStatus{},
        ClientType{},
        Contact{},
        EnterpriseNature{},
        EnterpriseScale{},
        FollowRecord{},
        Industry{},
        RegisteredCapital{},
        SaleChance{},
        SalesLeads{},
        SalesSources{},
        SaleStage{},
        SaleType{},
        RegularCustomers{},
        Possibility{},
        Status{},
        Quotation{},
        MasterOrder{},
        SubOrder{},
        Product{},
        SalesDetails{},
        SalesReturn{},
        SalesRefund{},
        Contract{},
        Plan{},
        ServiceContract{},
        OrderManage{},
        ServiceFollowup{},
        CustomerServiceSheet{},
        ServiceFeeManage{},
        Authority{},
        Api{},
        Department{},
        Satisfaction{},
        TimelyRate{},
        SolveRate{},
        IsVisit{},
        IsVisit{},
        ReportSource{},
        OrderType{},
        ServiceContractStatus{},
        ServiceContractType{},
        RefundMethod{},
        IsInvoice{},
        AccountId{},
        SalesReturnStatus{},
        Repository{},
        QuotationStatus{},
        Currency{},
    )
    return err
}
type InitDefaultData interface {
    InitDefaultData() error
}
func InsertDefaultData() {
    models := []interface{}{
        NewServiceTypeSearch(),
        NewPriorityLevelSearch(),
        NewSeveritySearch(),
        NewTimeSpentSearch(),
    }
    for _, model := range models {
        if id, ok := model.(InitDefaultData); ok {
            if err := id.InitDefaultData(); err != nil {
                logx.Errorf("InitDefaultData for table: %v, err :%v", model.(schema.Tabler).TableName(), err.Error())
            }
        }
    }
}
package model
import (
    "aps_crm/conf"
    "aps_crm/pkg/logx"
    "aps_crm/pkg/mysqlx"
    "aps_crm/pkg/safe"
    "gorm.io/gorm/schema"
)
func Init() error {
    if err := mysqlx.Init(&conf.Conf.Mysql, logx.GetLogger()); err != nil {
        return err
    }
    if err := RegisterTables(); err != nil {
        return err
    }
    safe.Go(func() {
        InsertDefaultData()
    })
    return nil
}
func RegisterTables() error {
    db := mysqlx.GetDB()
    err := db.AutoMigrate(
        User{},
        Menu{},
        JwtBlacklist{},
        Country{},
        Province{},
        City{},
        Client{},
        ClientLevel{},
        ClientOrigin{},
        ClientStatus{},
        ClientType{},
        Contact{},
        EnterpriseNature{},
        EnterpriseScale{},
        FollowRecord{},
        Industry{},
        RegisteredCapital{},
        SaleChance{},
        SalesLeads{},
        SalesSources{},
        SaleStage{},
        SaleType{},
        RegularCustomers{},
        Possibility{},
        Status{},
        Quotation{},
        MasterOrder{},
        SubOrder{},
        Product{},
        SalesDetails{},
        SalesReturn{},
        SalesRefund{},
        Contract{},
        Plan{},
        ServiceContract{},
        OrderManage{},
        ServiceFollowup{},
        CustomerServiceSheet{},
        ServiceFeeManage{},
        Authority{},
        Api{},
        Department{},
        Satisfaction{},
        TimelyRate{},
        SolveRate{},
        IsVisit{},
        IsVisit{},
        ReportSource{},
        OrderType{},
        ServiceContractStatus{},
        ServiceContractType{},
        RefundMethod{},
        IsInvoice{},
        AccountId{},
        SalesReturnStatus{},
        Repository{},
        QuotationStatus{},
        Currency{},
    )
    return err
}
type InitDefaultData interface {
    InitDefaultData() error
}
func InsertDefaultData() {
    models := []interface{}{
        NewServiceTypeSearch(),
        NewPriorityLevelSearch(),
        NewSeveritySearch(),
        NewTimeSpentSearch(),
    }
    for _, model := range models {
        if id, ok := model.(InitDefaultData); ok {
            if err := id.InitDefaultData(); err != nil {
                logx.Errorf("InitDefaultData for table: %v, err :%v", model.(schema.Tabler).TableName(), err.Error())
            }
        }
    }
}
model/request/collectionProjection.go
New file
@@ -0,0 +1,11 @@
package request
type AddCollectionProjection struct {
    CollectionProjection
}
type CollectionProjection struct {
    EstimatedCollectionAmount float64 `json:"estimated_collection_amount"` // 预计收款金额
    EstimatedCollectionTime   string  `json:"estimated_collection_time"`   // 预计收款时间
    SaleChanceId              int     `json:"sale_chance_id"`              // 销售机会id
}
pkg/ecode/code.go
@@ -393,4 +393,9 @@
    AssignWrongId        = 5700003 // 分配失败,分配对象为空
    AssignWrongModelType = 5700004 // 分配失败,分配对象类型为空
    CollectionProjectionExist     = 5800001 // 收款预测已存在
    CollectionProjectionNotExist  = 5800002 // 收款预测不存在
    CollectionProjectionListErr   = 5800003 // 获取收款预测列表失败
    CollectionProjectionSetErr    = 5800004 // 设置收款预测失败
    CollectionProjectionUpdateErr = 5800005 // 更新收款预测失败
)
router/colletionProjection.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type CollectionProjectionRouter struct{}
func (c *CollectionProjectionRouter) InitCollectionProjectionRouter(router *gin.RouterGroup) {
    collectionProjectionRouter := router.Group("collectionProjection")
    collectionProjectionApi := v1.ApiGroup.CollectionProjectionApi
    {
        collectionProjectionRouter.POST("add", collectionProjectionApi.Add) // 添加收款预测
        //collectionProjectionRouter.DELETE("delete", collectionProjectionApi.Delete)     // 删除收款预测
        //collectionProjectionRouter.PUT("update", collectionProjectionApi.Update)        // 更新收款预测
        //collectionProjectionRouter.POST("list", collectionProjectionApi.List)            // 获取收款预测列表
    }
}
router/index.go
@@ -70,6 +70,7 @@
    DepartmentRouter
    SatisfactionRouter
    AssignRouter
    CollectionProjectionRouter
}
func InitRouter() *gin.Engine {
@@ -176,7 +177,7 @@
        InitInvoiceTypeRouter(PrivateGroup)
        InitCourierCompanyRouter(PrivateGroup)
        InitProductRouter(PrivateGroup)
        InitServiceCollectionPlanRouter(PrivateGroup)
    }
    return Router
}
service/collectionProjection.go
New file
@@ -0,0 +1,17 @@
package service
import (
    "aps_crm/model"
    "aps_crm/pkg/ecode"
)
type CollectionProjectionService struct{}
func (CollectionProjectionService) AddCollectionProjection(collectionProjection *model.CollectionProjection) int {
    err := model.NewCollectionProjectionSearch().Create(collectionProjection)
    if err != nil {
        return ecode.CollectionProjectionExist
    }
    return ecode.OK
}
service/index.go
@@ -61,6 +61,7 @@
    QuotationStatusService
    CurrencyService
    AssignService
    CollectionProjectionService
}
var ServiceGroup = new(Group)