zhangqian
2023-08-29 0d86d93cff554f54f83927d4f8bf03ed8c847883
fix&字段完善
9个文件已修改
324 ■■■■■ 已修改文件
api/v1/purchase/purchase.go 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config.yaml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase_products.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/response/purchase.go 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/purchase/purchase.go 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/purchase/purchase.go
@@ -29,7 +29,7 @@
// @Security  ApiKeyAuth
// @accept    application/json
// @Produce   application/json
// @Param     data  body     purchaserequest.AddPurchase   true  "采购单用户名, 采购单手机号码"
// @Param     data  body     purchaserequest.AddPurchase   true  "采购单,采购单产品"
// @Success   200   {object}  response.Response{msg=string}  "创建采购单"
// @Router    /purchase/purchase [post]
func (e *PurchaseApi) CreatePurchase(c *gin.Context) {
@@ -149,7 +149,26 @@
        response.FailWithMessage("获取失败", c)
        return
    }
    response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: productList}, "获取成功", c)
    respProductList := make([]*purchaseRes.PurchaseProducts, len(productList))
    err = mapstructure.Decode(productList, &respProductList)
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
        return
    }
    for k, item := range productList {
        respProductList[k].Amount = item.Amount
        respProductList[k].Price = item.Price
        respProductList[k].Total = item.Total
        err = mapstructure.Decode(item.Product, &respProductList[k])
        if err != nil {
            global.GVA_LOG.Error("获取失败!", zap.Error(err))
            response.FailWithMessage("获取失败", c)
            return
        }
    }
    response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: respProductList}, "获取成功", c)
}
// GetPurchaseList
@@ -173,14 +192,14 @@
        response.FailWithMessage(err.Error(), c)
        return
    }
    PurchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo)
    purchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo)
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败"+err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     PurchaseList,
        List:     purchaseList,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
config.yaml
@@ -182,7 +182,7 @@
  iplimit-time: 3600
  use-multipoint: false
  use-redis: false
  grpc-url: 192.168.20.118:9091
  grpc-url: 192.168.20.119:9091
  grpc-admin-url: 192.168.20.119:50051
tencent-cos:
  bucket: xxxxx-10005608
docs/docs.go
@@ -4629,7 +4629,7 @@
                "summary": "创建采购单",
                "parameters": [
                    {
                        "description": "采购单用户名, 采购单手机号码",
                        "description": "采购单,采购单产品",
                        "name": "data",
                        "in": "body",
                        "required": true,
@@ -8425,8 +8425,16 @@
                    "description": "创建时间",
                    "type": "string"
                },
                "creator": {
                    "description": "制单人",
                    "type": "string"
                },
                "deliveryDate": {
                    "description": "交付日期",
                    "type": "string"
                },
                "handledBy": {
                    "description": "经办人",
                    "type": "string"
                },
                "id": {
@@ -8441,6 +8449,10 @@
                    "description": "采购编号",
                    "type": "string"
                },
                "orderType": {
                    "description": "单据类型",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
@@ -8451,6 +8463,10 @@
                "purchaseTypeId": {
                    "description": "采购类型id",
                    "type": "integer"
                },
                "quantity": {
                    "description": "采购数量",
                    "type": "number"
                },
                "remark": {
                    "description": "备注",
@@ -8474,6 +8490,10 @@
                "supplierId": {
                    "description": "供应商id",
                    "type": "integer"
                },
                "warehouse": {
                    "description": "收货仓库",
                    "type": "string"
                }
            }
        },
@@ -8496,6 +8516,9 @@
                    "description": "采购单价",
                    "type": "number"
                },
                "product": {
                    "$ref": "#/definitions/test.Product"
                },
                "productId": {
                    "description": "产品id",
                    "type": "integer"
@@ -8517,6 +8540,10 @@
        "purchase.PurchaseType": {
            "type": "object",
            "properties": {
                "created_at": {
                    "description": "创建时间",
                    "type": "string"
                },
                "id": {
                    "description": "主键ID",
                    "type": "integer"
@@ -9093,13 +9120,65 @@
                }
            }
        },
        "response.PurchaseProducts": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "采购数量",
                    "type": "number"
                },
                "deliveryTime": {
                    "type": "integer"
                },
                "modelNumber": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "number": {
                    "type": "string"
                },
                "price": {
                    "description": "采购单价",
                    "type": "number"
                },
                "productId": {
                    "description": "产品id",
                    "type": "integer"
                },
                "productType": {
                    "type": "string"
                },
                "purchaseId": {
                    "description": "采购id",
                    "type": "integer"
                },
                "purchasePrice": {
                    "type": "number"
                },
                "shippingDuration": {
                    "type": "integer"
                },
                "specifications": {
                    "type": "string"
                },
                "total": {
                    "description": "采购总价",
                    "type": "number"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "response.PurchaseResponse": {
            "type": "object",
            "properties": {
                "productList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/purchase.PurchaseProducts"
                        "$ref": "#/definitions/response.PurchaseProducts"
                    }
                },
                "purchase": {
docs/swagger.json
@@ -4620,7 +4620,7 @@
                "summary": "创建采购单",
                "parameters": [
                    {
                        "description": "采购单用户名, 采购单手机号码",
                        "description": "采购单,采购单产品",
                        "name": "data",
                        "in": "body",
                        "required": true,
@@ -8416,8 +8416,16 @@
                    "description": "创建时间",
                    "type": "string"
                },
                "creator": {
                    "description": "制单人",
                    "type": "string"
                },
                "deliveryDate": {
                    "description": "交付日期",
                    "type": "string"
                },
                "handledBy": {
                    "description": "经办人",
                    "type": "string"
                },
                "id": {
@@ -8432,6 +8440,10 @@
                    "description": "采购编号",
                    "type": "string"
                },
                "orderType": {
                    "description": "单据类型",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
@@ -8442,6 +8454,10 @@
                "purchaseTypeId": {
                    "description": "采购类型id",
                    "type": "integer"
                },
                "quantity": {
                    "description": "采购数量",
                    "type": "number"
                },
                "remark": {
                    "description": "备注",
@@ -8465,6 +8481,10 @@
                "supplierId": {
                    "description": "供应商id",
                    "type": "integer"
                },
                "warehouse": {
                    "description": "收货仓库",
                    "type": "string"
                }
            }
        },
@@ -8487,6 +8507,9 @@
                    "description": "采购单价",
                    "type": "number"
                },
                "product": {
                    "$ref": "#/definitions/test.Product"
                },
                "productId": {
                    "description": "产品id",
                    "type": "integer"
@@ -8508,6 +8531,10 @@
        "purchase.PurchaseType": {
            "type": "object",
            "properties": {
                "created_at": {
                    "description": "创建时间",
                    "type": "string"
                },
                "id": {
                    "description": "主键ID",
                    "type": "integer"
@@ -9084,13 +9111,65 @@
                }
            }
        },
        "response.PurchaseProducts": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "采购数量",
                    "type": "number"
                },
                "deliveryTime": {
                    "type": "integer"
                },
                "modelNumber": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "number": {
                    "type": "string"
                },
                "price": {
                    "description": "采购单价",
                    "type": "number"
                },
                "productId": {
                    "description": "产品id",
                    "type": "integer"
                },
                "productType": {
                    "type": "string"
                },
                "purchaseId": {
                    "description": "采购id",
                    "type": "integer"
                },
                "purchasePrice": {
                    "type": "number"
                },
                "shippingDuration": {
                    "type": "integer"
                },
                "specifications": {
                    "type": "string"
                },
                "total": {
                    "description": "采购总价",
                    "type": "number"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "response.PurchaseResponse": {
            "type": "object",
            "properties": {
                "productList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/purchase.PurchaseProducts"
                        "$ref": "#/definitions/response.PurchaseProducts"
                    }
                },
                "purchase": {
docs/swagger.yaml
@@ -702,8 +702,14 @@
      created_at:
        description: 创建时间
        type: string
      creator:
        description: 制单人
        type: string
      deliveryDate:
        description: 交付日期
        type: string
      handledBy:
        description: 经办人
        type: string
      id:
        description: 主键ID
@@ -714,6 +720,9 @@
      number:
        description: 采购编号
        type: string
      orderType:
        description: 单据类型
        type: string
      phone:
        description: 联系人电话
        type: string
@@ -722,6 +731,9 @@
      purchaseTypeId:
        description: 采购类型id
        type: integer
      quantity:
        description: 采购数量
        type: number
      remark:
        description: 备注
        type: string
@@ -737,6 +749,9 @@
      supplierId:
        description: 供应商id
        type: integer
      warehouse:
        description: 收货仓库
        type: string
    type: object
  purchase.PurchaseProducts:
    properties:
@@ -752,6 +767,8 @@
      price:
        description: 采购单价
        type: number
      product:
        $ref: '#/definitions/test.Product'
      productId:
        description: 产品id
        type: integer
@@ -767,6 +784,9 @@
    type: object
  purchase.PurchaseType:
    properties:
      created_at:
        description: 创建时间
        type: string
      id:
        description: 主键ID
        type: integer
@@ -1162,11 +1182,47 @@
          $ref: '#/definitions/request.CasbinInfo'
        type: array
    type: object
  response.PurchaseProducts:
    properties:
      amount:
        description: 采购数量
        type: number
      deliveryTime:
        type: integer
      modelNumber:
        type: string
      name:
        type: string
      number:
        type: string
      price:
        description: 采购单价
        type: number
      productId:
        description: 产品id
        type: integer
      productType:
        type: string
      purchaseId:
        description: 采购id
        type: integer
      purchasePrice:
        type: number
      shippingDuration:
        type: integer
      specifications:
        type: string
      total:
        description: 采购总价
        type: number
      unit:
        type: string
    type: object
  response.PurchaseResponse:
    properties:
      productList:
        items:
          $ref: '#/definitions/purchase.PurchaseProducts'
          $ref: '#/definitions/response.PurchaseProducts'
        type: array
      purchase:
        $ref: '#/definitions/purchase.Purchase'
@@ -4508,7 +4564,7 @@
      consumes:
      - application/json
      parameters:
      - description: 采购单用户名, 采购单手机号码
      - description: 采购单,采购单产品
        in: body
        name: data
        required: true
model/purchase/purchase.go
@@ -23,6 +23,8 @@
    Status         OrderStatus     `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"`                  //状态
    HandledBy      string          `json:"handledBy" form:"handledBy" gorm:"type:varchar(255);not null;default '';comment:经办人"`        //经办人
    Creator        string          `json:"creator" form:"creator" gorm:"type:varchar(255);not null;default '';comment:制单人"`            //制单人
    OrderType      string          `json:"orderType" form:"orderType" gorm:"type:varchar(255);not null;default '';comment:单据类型"`       //单据类型
    Warehouse      string          `json:"warehouse" form:"warehouse" gorm:"type:varchar(255);not null;default '';comment:收货仓库"`       //收货仓库
}
type OrderStatus int
model/purchase/purchase_products.go
@@ -3,14 +3,16 @@
import (
    "github.com/shopspring/decimal"
    "srm/global"
    "srm/model/test"
)
type PurchaseProducts struct {
    global.GVA_MODEL
    PurchaseId int             `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购id
    ProductId  int             `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"`     // 产品id
    Amount     decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:采购数量"`       // 采购数量
    Price      decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购单价"`      // 采购单价
    Total      decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购总价"`      // 采购总价
    Remark     string          `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"`       //描述
    Product    test.Product    `json:"product" gorm:"foreignKey:ProductId"`
    Amount     decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:采购数量"`  // 采购数量
    Price      decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购单价"` // 采购单价
    Total      decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购总价"` // 采购总价
    Remark     string          `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"`  //描述
}
model/purchase/response/purchase.go
@@ -1,8 +1,28 @@
package response
import "srm/model/purchase"
import (
    "github.com/shopspring/decimal"
    "srm/model/purchase"
)
type PurchaseResponse struct {
    Purchase    purchase.Purchase            `json:"purchase"`
    ProductList []*purchase.PurchaseProducts `json:"productList"`
    Purchase    purchase.Purchase   `json:"purchase"`
    ProductList []*PurchaseProducts `json:"productList"`
}
type PurchaseProducts struct {
    PurchaseId       int             `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购id
    ProductId        int             `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"`     // 产品id
    Amount           decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:采购数量"`       // 采购数量
    Price            decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购单价"`      // 采购单价
    Total            decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购总价"`      // 采购总价
    Name             string          `json:"name" form:"name" gorm:"column:name;comment:名称;size:255;"`
    Number           string          `json:"number" form:"number" gorm:"column:number;comment:编码;size:255;"`
    Unit             string          `json:"unit" form:"unit" gorm:"column:unit;comment:计量单位;size:255;"`
    PurchasePrice    *float64        `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:采购价格;"`
    DeliveryTime     *int            `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"`
    ShippingDuration *int            `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"`
    Specifications   string          `json:"specifications" form:"specifications" gorm:"column:specifications;comment:规格;size:255;"`
    ModelNumber      string          `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:型号;size:255;"`
    ProductType      string          `json:"productType" form:"productType" gorm:"column:product_type;comment:产品类别;size:255;"`
}
service/purchase/purchase.go
@@ -132,7 +132,7 @@
func (slf *PurchaseService) GetPurchaseProductList(purchaseId uint) (list []*purchase.PurchaseProducts, err error) {
    db := global.GVA_DB.Model(&purchase.PurchaseProducts{})
    list = make([]*purchase.PurchaseProducts, 0)
    err = db.Where("purchase_id = ?", purchaseId).Find(&list).Error
    err = db.Where("purchase_id = ?", purchaseId).Preload("Product").Find(&list).Error
    return list, err
}
@@ -214,15 +214,36 @@
}
func (slf *PurchaseService) SavePurchaseType(list []*purchase.PurchaseType) (err error) {
    ids := make([]uint, 0)
    newRecords := make([]*purchase.PurchaseType, 0)
    for _, item := range list {
        if item.ID != 0 {
            ids = append(ids, item.ID)
        } else {
            newRecords = append(newRecords, item)
        }
    }
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = tx.Where("1 = ?", 1).Delete(&purchase.PurchaseType{}).Error
        err = tx.Where("id not in ?", ids).Delete(&purchase.PurchaseType{}).Error
        if err != nil {
            return err
        }
        for _, item := range list {
            item.ID = 0
        if len(newRecords) > 0 {
            err = tx.Create(newRecords).Error
            if err != nil {
                return err
            }
        }
        return tx.Create(list).Error
        for _, item := range list {
            if item.ID != 0 {
                err = tx.Save(item).Error
                if err != nil {
                    return err
                }
            }
        }
        return nil
    })
    return err
}