From cd6940f07750c1e2cd3a5c0eeafa6cc0309ef2f6 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 29 八月 2023 14:35:26 +0800
Subject: [PATCH] 新增和查询采购类型
---
api/v1/purchase/purchase.go | 82 +++++
model/purchase/purchase.go | 5
model/purchase/purchase_type.go | 13
model/purchase/request/purchase.go | 21 +
router/purchase/purchase.go | 15
docs/swagger.yaml | 163 ++++++++++
model/purchase/request/purchase_type.go | 12
docs/docs.go | 250 ++++++++++++++++
service/purchase/purchase.go | 50 ++-
docs/swagger.json | 250 ++++++++++++++++
10 files changed, 824 insertions(+), 37 deletions(-)
diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go
index c2b7c52..1d220d6 100644
--- a/api/v1/purchase/purchase.go
+++ b/api/v1/purchase/purchase.go
@@ -2,12 +2,16 @@
import (
"github.com/gin-gonic/gin"
+ "github.com/mitchellh/mapstructure"
"go.uber.org/zap"
+ "gorm.io/gorm"
"srm/global"
"srm/model/common/request"
"srm/model/common/response"
+ "srm/model/purchase"
purchaserequest "srm/model/purchase/request"
"strconv"
+ "strings"
//"srm/model/purchase"
@@ -35,8 +39,21 @@
response.FailWithMessage(err.Error(), c)
return
}
- err = service.NewPurchaseService().CreatePurchase(params)
+
+ var purchaseRecord purchase.Purchase
+ if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil {
+ response.FailWithMessage(err.Error(), c)
+ return
+ }
+
+ purchaseRecord.ID = 0
+ err = service.NewPurchaseService().CreatePurchase(&purchaseRecord, params.ProductList)
+
if err != nil {
+ if err == gorm.ErrDuplicatedKey || strings.Contains(err.Error(), "Duplicate entry") {
+ response.FailWithMessage("缂栧彿閲嶅", c)
+ return
+ }
global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err))
response.FailWithMessage("鍒涘缓澶辫触", c)
return
@@ -74,22 +91,24 @@
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
-// @Param data body purchaserequest.AddPurchase true "閲囪喘鍗旾D, 閲囪喘鍗曚俊鎭�"
+// @Param data body purchaserequest.UpdatePurchase true "閲囪喘鍗旾D, 閲囪喘鍗曚俊鎭�"
// @Success 200 {object} response.Response{msg=string} "鏇存柊閲囪喘鍗曚俊鎭�"
// @Router /purchase/purchase [put]
func (e *PurchaseApi) UpdatePurchase(c *gin.Context) {
- var params purchaserequest.AddPurchase
+ var params purchaserequest.UpdatePurchase
err := c.ShouldBindJSON(¶ms)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
- err = utils.Verify(params.Purchase.GVA_MODEL, utils.IdVerify)
- if err != nil {
+
+ var purchaseRecord purchase.Purchase
+ if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
- err = service.NewPurchaseService().UpdatePurchase(¶ms)
+
+ err = service.NewPurchaseService().UpdatePurchase(&purchaseRecord, params.ProductList)
if err != nil {
global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err))
response.FailWithMessage("鏇存柊澶辫触", c)
@@ -186,3 +205,54 @@
}
response.OkWithMessage("鏇存柊鎴愬姛", c)
}
+
+// SavePurchaseType
+// @Tags Purchase
+// @Summary 鍒涘缓閲囪喘绫诲瀷
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body []purchaserequest.PurchaseType true "閲囪喘绫诲瀷list"
+// @Success 200 {object} response.Response{msg=string} "鍒涘缓閲囪喘绫诲瀷"
+// @Router /purchase/purchaseType [post]
+func (e *PurchaseApi) SavePurchaseType(c *gin.Context) {
+ var params []*purchaserequest.PurchaseType
+ err := c.ShouldBindJSON(¶ms)
+ if err != nil {
+ response.FailWithMessage(err.Error(), c)
+ return
+ }
+
+ purchaseTypeList := make([]*purchase.PurchaseType, 0, len(params))
+ if err := mapstructure.Decode(params, &purchaseTypeList); err != nil {
+ response.FailWithMessage(err.Error(), c)
+ return
+ }
+
+ err = service.NewPurchaseService().SavePurchaseType(purchaseTypeList)
+
+ if err != nil {
+ global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err))
+ response.FailWithMessage("鍒涘缓澶辫触", c)
+ return
+ }
+ response.OkWithMessage("鍒涘缓鎴愬姛", c)
+}
+
+// GetPurchaseTypeList
+// @Tags Purchase
+// @Summary 鑾峰彇閲囪喘绫诲瀷鍒楄〃
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Success 200 {object} response.Response{data=[]purchase.PurchaseType,msg=string} "鑾峰彇閲囪喘绫诲瀷鍒楄〃"
+// @Router /purchase/purchaseTypeList [get]
+func (e *PurchaseApi) GetPurchaseTypeList(c *gin.Context) {
+ list, err := service.NewPurchaseService().GetPurchaseTypeList()
+ if err != nil {
+ global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+ response.FailWithMessage("鑾峰彇澶辫触"+err.Error(), c)
+ return
+ }
+ response.OkWithDetailed(list, "鑾峰彇鎴愬姛", c)
+}
diff --git a/docs/docs.go b/docs/docs.go
index 5052c01..5c82abd 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -4490,7 +4490,7 @@
"in": "body",
"required": true,
"schema": {
- "$ref": "#/definitions/purchaserequest.AddPurchase"
+ "$ref": "#/definitions/purchaserequest.UpdatePurchase"
}
}
],
@@ -4711,6 +4711,104 @@
"properties": {
"data": {
"$ref": "#/definitions/response.PageResult"
+ },
+ "msg": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/purchase/purchaseType": {
+ "post": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Purchase"
+ ],
+ "summary": "鍒涘缓閲囪喘绫诲瀷",
+ "parameters": [
+ {
+ "description": "閲囪喘绫诲瀷list",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchaserequest.PurchaseType"
+ }
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "鍒涘缓閲囪喘绫诲瀷",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "msg": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/purchase/purchaseTypeList": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Purchase"
+ ],
+ "summary": "鑾峰彇閲囪喘绫诲瀷鍒楄〃",
+ "responses": {
+ "200": {
+ "description": "鑾峰彇閲囪喘绫诲瀷鍒楄〃",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchase.PurchaseType"
+ }
},
"msg": {
"type": "string"
@@ -8123,6 +8221,27 @@
}
}
},
+ "purchase.OrderStatus": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "x-enum-comments": {
+ "OrderStatusCompleted": "宸插畬鎴�",
+ "OrderStatusConfirmed": "宸蹭笅鍗�",
+ "OrderStatusReceived": "宸插埌璐�",
+ "OrderStatusStored": "宸插叆搴�"
+ },
+ "x-enum-varnames": [
+ "OrderStatusConfirmed",
+ "OrderStatusReceived",
+ "OrderStatusStored",
+ "OrderStatusCompleted"
+ ]
+ },
"purchase.Purchase": {
"type": "object",
"properties": {
@@ -8142,9 +8261,16 @@
"description": "閲囪喘鍚嶇О",
"type": "string"
},
+ "number": {
+ "description": "閲囪喘缂栧彿",
+ "type": "string"
+ },
"phone": {
"description": "鑱旂郴浜虹數璇�",
"type": "string"
+ },
+ "purchaseType": {
+ "$ref": "#/definitions/purchase.PurchaseType"
},
"purchaseTypeId": {
"description": "閲囪喘绫诲瀷id",
@@ -8157,6 +8283,17 @@
"signingDate": {
"description": "绛剧害鏃ユ湡",
"type": "string"
+ },
+ "status": {
+ "description": "鐘舵��",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.OrderStatus"
+ }
+ ]
+ },
+ "supplier": {
+ "$ref": "#/definitions/test.Supplier"
},
"supplierId": {
"description": "渚涘簲鍟唅d",
@@ -8197,6 +8334,27 @@
}
}
},
+ "purchase.PurchaseType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘绫诲瀷",
+ "type": "string"
+ },
+ "pin": {
+ "description": "鏄惁缃《",
+ "type": "boolean"
+ },
+ "sort": {
+ "description": "鎺掑簭",
+ "type": "integer"
+ }
+ }
+ },
"purchaserequest.AddPurchase": {
"type": "object",
"properties": {
@@ -8207,7 +8365,95 @@
}
},
"purchase": {
- "$ref": "#/definitions/purchase.Purchase"
+ "$ref": "#/definitions/purchaserequest.Purchase"
+ }
+ }
+ },
+ "purchaserequest.Purchase": {
+ "type": "object",
+ "properties": {
+ "contact": {
+ "description": "鑱旂郴浜�",
+ "type": "string"
+ },
+ "deliveryDate": {
+ "description": "浜や粯鏃ユ湡",
+ "type": "string"
+ },
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘鍚嶇О",
+ "type": "string"
+ },
+ "number": {
+ "description": "閲囪喘缂栧彿",
+ "type": "string"
+ },
+ "phone": {
+ "description": "鑱旂郴浜虹數璇�",
+ "type": "string"
+ },
+ "purchaseTypeId": {
+ "description": "閲囪喘绫诲瀷id",
+ "type": "integer"
+ },
+ "remark": {
+ "description": "澶囨敞",
+ "type": "string"
+ },
+ "signingDate": {
+ "description": "绛剧害鏃ユ湡",
+ "type": "string"
+ },
+ "status": {
+ "description": "鐘舵��",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.OrderStatus"
+ }
+ ]
+ },
+ "supplierId": {
+ "description": "渚涘簲鍟唅d",
+ "type": "integer"
+ }
+ }
+ },
+ "purchaserequest.PurchaseType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘绫诲瀷",
+ "type": "string"
+ },
+ "pin": {
+ "description": "鏄惁缃《",
+ "type": "boolean"
+ },
+ "sort": {
+ "description": "鎺掑簭",
+ "type": "integer"
+ }
+ }
+ },
+ "purchaserequest.UpdatePurchase": {
+ "type": "object",
+ "properties": {
+ "productList": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchase.PurchaseProducts"
+ }
+ },
+ "purchase": {
+ "$ref": "#/definitions/purchaserequest.Purchase"
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 96f9360..6cefe36 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -4481,7 +4481,7 @@
"in": "body",
"required": true,
"schema": {
- "$ref": "#/definitions/purchaserequest.AddPurchase"
+ "$ref": "#/definitions/purchaserequest.UpdatePurchase"
}
}
],
@@ -4702,6 +4702,104 @@
"properties": {
"data": {
"$ref": "#/definitions/response.PageResult"
+ },
+ "msg": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/purchase/purchaseType": {
+ "post": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Purchase"
+ ],
+ "summary": "鍒涘缓閲囪喘绫诲瀷",
+ "parameters": [
+ {
+ "description": "閲囪喘绫诲瀷list",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchaserequest.PurchaseType"
+ }
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "鍒涘缓閲囪喘绫诲瀷",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "msg": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/purchase/purchaseTypeList": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Purchase"
+ ],
+ "summary": "鑾峰彇閲囪喘绫诲瀷鍒楄〃",
+ "responses": {
+ "200": {
+ "description": "鑾峰彇閲囪喘绫诲瀷鍒楄〃",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchase.PurchaseType"
+ }
},
"msg": {
"type": "string"
@@ -8114,6 +8212,27 @@
}
}
},
+ "purchase.OrderStatus": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "x-enum-comments": {
+ "OrderStatusCompleted": "宸插畬鎴�",
+ "OrderStatusConfirmed": "宸蹭笅鍗�",
+ "OrderStatusReceived": "宸插埌璐�",
+ "OrderStatusStored": "宸插叆搴�"
+ },
+ "x-enum-varnames": [
+ "OrderStatusConfirmed",
+ "OrderStatusReceived",
+ "OrderStatusStored",
+ "OrderStatusCompleted"
+ ]
+ },
"purchase.Purchase": {
"type": "object",
"properties": {
@@ -8133,9 +8252,16 @@
"description": "閲囪喘鍚嶇О",
"type": "string"
},
+ "number": {
+ "description": "閲囪喘缂栧彿",
+ "type": "string"
+ },
"phone": {
"description": "鑱旂郴浜虹數璇�",
"type": "string"
+ },
+ "purchaseType": {
+ "$ref": "#/definitions/purchase.PurchaseType"
},
"purchaseTypeId": {
"description": "閲囪喘绫诲瀷id",
@@ -8148,6 +8274,17 @@
"signingDate": {
"description": "绛剧害鏃ユ湡",
"type": "string"
+ },
+ "status": {
+ "description": "鐘舵��",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.OrderStatus"
+ }
+ ]
+ },
+ "supplier": {
+ "$ref": "#/definitions/test.Supplier"
},
"supplierId": {
"description": "渚涘簲鍟唅d",
@@ -8188,6 +8325,27 @@
}
}
},
+ "purchase.PurchaseType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘绫诲瀷",
+ "type": "string"
+ },
+ "pin": {
+ "description": "鏄惁缃《",
+ "type": "boolean"
+ },
+ "sort": {
+ "description": "鎺掑簭",
+ "type": "integer"
+ }
+ }
+ },
"purchaserequest.AddPurchase": {
"type": "object",
"properties": {
@@ -8198,7 +8356,95 @@
}
},
"purchase": {
- "$ref": "#/definitions/purchase.Purchase"
+ "$ref": "#/definitions/purchaserequest.Purchase"
+ }
+ }
+ },
+ "purchaserequest.Purchase": {
+ "type": "object",
+ "properties": {
+ "contact": {
+ "description": "鑱旂郴浜�",
+ "type": "string"
+ },
+ "deliveryDate": {
+ "description": "浜や粯鏃ユ湡",
+ "type": "string"
+ },
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘鍚嶇О",
+ "type": "string"
+ },
+ "number": {
+ "description": "閲囪喘缂栧彿",
+ "type": "string"
+ },
+ "phone": {
+ "description": "鑱旂郴浜虹數璇�",
+ "type": "string"
+ },
+ "purchaseTypeId": {
+ "description": "閲囪喘绫诲瀷id",
+ "type": "integer"
+ },
+ "remark": {
+ "description": "澶囨敞",
+ "type": "string"
+ },
+ "signingDate": {
+ "description": "绛剧害鏃ユ湡",
+ "type": "string"
+ },
+ "status": {
+ "description": "鐘舵��",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.OrderStatus"
+ }
+ ]
+ },
+ "supplierId": {
+ "description": "渚涘簲鍟唅d",
+ "type": "integer"
+ }
+ }
+ },
+ "purchaserequest.PurchaseType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "description": "涓婚敭ID",
+ "type": "integer"
+ },
+ "name": {
+ "description": "閲囪喘绫诲瀷",
+ "type": "string"
+ },
+ "pin": {
+ "description": "鏄惁缃《",
+ "type": "boolean"
+ },
+ "sort": {
+ "description": "鎺掑簭",
+ "type": "integer"
+ }
+ }
+ },
+ "purchaserequest.UpdatePurchase": {
+ "type": "object",
+ "properties": {
+ "productList": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/purchase.PurchaseProducts"
+ }
+ },
+ "purchase": {
+ "$ref": "#/definitions/purchaserequest.Purchase"
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index a58da37..2855cf4 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -665,6 +665,23 @@
description: 鏂囦欢鍦板潃
type: string
type: object
+ purchase.OrderStatus:
+ enum:
+ - 1
+ - 2
+ - 3
+ - 4
+ type: integer
+ x-enum-comments:
+ OrderStatusCompleted: 宸插畬鎴�
+ OrderStatusConfirmed: 宸蹭笅鍗�
+ OrderStatusReceived: 宸插埌璐�
+ OrderStatusStored: 宸插叆搴�
+ x-enum-varnames:
+ - OrderStatusConfirmed
+ - OrderStatusReceived
+ - OrderStatusStored
+ - OrderStatusCompleted
purchase.Purchase:
properties:
contact:
@@ -679,9 +696,14 @@
name:
description: 閲囪喘鍚嶇О
type: string
+ number:
+ description: 閲囪喘缂栧彿
+ type: string
phone:
description: 鑱旂郴浜虹數璇�
type: string
+ purchaseType:
+ $ref: '#/definitions/purchase.PurchaseType'
purchaseTypeId:
description: 閲囪喘绫诲瀷id
type: integer
@@ -691,6 +713,12 @@
signingDate:
description: 绛剧害鏃ユ湡
type: string
+ status:
+ allOf:
+ - $ref: '#/definitions/purchase.OrderStatus'
+ description: 鐘舵��
+ supplier:
+ $ref: '#/definitions/test.Supplier'
supplierId:
description: 渚涘簲鍟唅d
type: integer
@@ -719,6 +747,21 @@
description: 閲囪喘鎬讳环
type: number
type: object
+ purchase.PurchaseType:
+ properties:
+ id:
+ description: 涓婚敭ID
+ type: integer
+ name:
+ description: 閲囪喘绫诲瀷
+ type: string
+ pin:
+ description: 鏄惁缃《
+ type: boolean
+ sort:
+ description: 鎺掑簭
+ type: integer
+ type: object
purchaserequest.AddPurchase:
properties:
productList:
@@ -726,7 +769,68 @@
$ref: '#/definitions/purchase.PurchaseProducts'
type: array
purchase:
- $ref: '#/definitions/purchase.Purchase'
+ $ref: '#/definitions/purchaserequest.Purchase'
+ type: object
+ purchaserequest.Purchase:
+ properties:
+ contact:
+ description: 鑱旂郴浜�
+ type: string
+ deliveryDate:
+ description: 浜や粯鏃ユ湡
+ type: string
+ id:
+ description: 涓婚敭ID
+ type: integer
+ name:
+ description: 閲囪喘鍚嶇О
+ type: string
+ number:
+ description: 閲囪喘缂栧彿
+ type: string
+ phone:
+ description: 鑱旂郴浜虹數璇�
+ type: string
+ purchaseTypeId:
+ description: 閲囪喘绫诲瀷id
+ type: integer
+ remark:
+ description: 澶囨敞
+ type: string
+ signingDate:
+ description: 绛剧害鏃ユ湡
+ type: string
+ status:
+ allOf:
+ - $ref: '#/definitions/purchase.OrderStatus'
+ description: 鐘舵��
+ supplierId:
+ description: 渚涘簲鍟唅d
+ type: integer
+ type: object
+ purchaserequest.PurchaseType:
+ properties:
+ id:
+ description: 涓婚敭ID
+ type: integer
+ name:
+ description: 閲囪喘绫诲瀷
+ type: string
+ pin:
+ description: 鏄惁缃《
+ type: boolean
+ sort:
+ description: 鎺掑簭
+ type: integer
+ type: object
+ purchaserequest.UpdatePurchase:
+ properties:
+ productList:
+ items:
+ $ref: '#/definitions/purchase.PurchaseProducts'
+ type: array
+ purchase:
+ $ref: '#/definitions/purchaserequest.Purchase'
type: object
request.AddMenuAuthorityInfo:
properties:
@@ -4308,7 +4412,7 @@
name: data
required: true
schema:
- $ref: '#/definitions/purchaserequest.AddPurchase'
+ $ref: '#/definitions/purchaserequest.UpdatePurchase'
produces:
- application/json
responses:
@@ -4417,6 +4521,61 @@
summary: 鍒嗛〉鑾峰彇閲囪喘鍗曞垪琛�
tags:
- Purchase
+ /purchase/purchaseType:
+ post:
+ consumes:
+ - application/json
+ parameters:
+ - description: 閲囪喘绫诲瀷list
+ in: body
+ name: data
+ required: true
+ schema:
+ items:
+ $ref: '#/definitions/purchaserequest.PurchaseType'
+ type: array
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 鍒涘缓閲囪喘绫诲瀷
+ schema:
+ allOf:
+ - $ref: '#/definitions/response.Response'
+ - properties:
+ msg:
+ type: string
+ type: object
+ security:
+ - ApiKeyAuth: []
+ summary: 鍒涘缓閲囪喘绫诲瀷
+ tags:
+ - Purchase
+ /purchase/purchaseTypeList:
+ get:
+ consumes:
+ - application/json
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 鑾峰彇閲囪喘绫诲瀷鍒楄〃
+ schema:
+ allOf:
+ - $ref: '#/definitions/response.Response'
+ - properties:
+ data:
+ items:
+ $ref: '#/definitions/purchase.PurchaseType'
+ type: array
+ msg:
+ type: string
+ type: object
+ security:
+ - ApiKeyAuth: []
+ summary: 鑾峰彇閲囪喘绫诲瀷鍒楄〃
+ tags:
+ - Purchase
/purchase/submit/{id}:
post:
consumes:
diff --git a/model/purchase/purchase.go b/model/purchase/purchase.go
index 2b71527..0163640 100644
--- a/model/purchase/purchase.go
+++ b/model/purchase/purchase.go
@@ -8,9 +8,10 @@
type Purchase struct {
global.GVA_MODEL
PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘绫诲瀷id
- SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 渚涘簲鍟唅d
+ PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"`
+ SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 渚涘簲鍟唅d
Supplier test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"`
- Number string `json:"number" form:"number" gorm:"type:varchar(255);not null;default '';comment:閲囪喘缂栧彿"` // 閲囪喘缂栧彿
+ Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:閲囪喘缂栧彿"` // 閲囪喘缂栧彿
Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:閲囪喘鍚嶇О"` // 閲囪喘鍚嶇О
Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:鑱旂郴浜�"` // 鑱旂郴浜�
Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:鑱旂郴浜虹數璇�"` // 鑱旂郴浜虹數璇�
diff --git a/model/purchase/purchase_type.go b/model/purchase/purchase_type.go
new file mode 100644
index 0000000..4803067
--- /dev/null
+++ b/model/purchase/purchase_type.go
@@ -0,0 +1,13 @@
+package purchase
+
+import (
+ "srm/global"
+)
+
+type PurchaseType struct {
+ global.GVA_MODEL
+ ID uint `gorm:"primarykey"` // 涓婚敭ID
+ Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:閲囪喘绫诲瀷"` // 閲囪喘绫诲瀷
+ Sort int `json:"sort" form:"sort" gorm:"type:int(11);not null;default 0;comment:鎺掑簭"` // 鎺掑簭
+ Pin bool `json:"pin" form:"pin" gorm:"type:tinyint(1);not null;default 0;comment:閲囪喘鍚嶇О"` // 鏄惁缃《
+}
diff --git a/model/purchase/request/purchase.go b/model/purchase/request/purchase.go
index d0dad8c..a99c0b8 100644
--- a/model/purchase/request/purchase.go
+++ b/model/purchase/request/purchase.go
@@ -13,6 +13,25 @@
}
type AddPurchase struct {
- Purchase purchase.Purchase
+ Purchase Purchase `json:"purchase"`
ProductList []*purchase.PurchaseProducts `json:"productList"`
}
+
+type UpdatePurchase struct {
+ Purchase Purchase `json:"purchase"`
+ ProductList []*purchase.PurchaseProducts `json:"productList"`
+}
+
+type Purchase struct {
+ ID uint `gorm:"primarykey"` // 涓婚敭ID
+ PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘绫诲瀷id
+ SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 渚涘簲鍟唅d
+ Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:閲囪喘缂栧彿"` // 閲囪喘缂栧彿
+ Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:閲囪喘鍚嶇О"` // 閲囪喘鍚嶇О
+ Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:鑱旂郴浜�"` // 鑱旂郴浜�
+ Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:鑱旂郴浜虹數璇�"` // 鑱旂郴浜虹數璇�
+ SigningDate string `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:绛剧害鏃ユ湡"` // 绛剧害鏃ユ湡
+ DeliveryDate string `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:浜や粯鏃ユ湡"` //浜や粯鏃ユ湡
+ Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:澶囨敞"` //澶囨敞
+ Status purchase.OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:鐘舵��"` //鐘舵��
+}
diff --git a/model/purchase/request/purchase_type.go b/model/purchase/request/purchase_type.go
new file mode 100644
index 0000000..26956c6
--- /dev/null
+++ b/model/purchase/request/purchase_type.go
@@ -0,0 +1,12 @@
+package purchaserequest
+
+type SavePurchaseType struct {
+ List []*PurchaseType `json:"purchase"`
+}
+
+type PurchaseType struct {
+ ID uint `gorm:"primarykey"` // 涓婚敭ID
+ Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:閲囪喘绫诲瀷"` // 閲囪喘绫诲瀷
+ Sort int `json:"sort" form:"sort" gorm:"type:int(11);not null;default 0;comment:鎺掑簭"` // 鎺掑簭
+ Pin bool `json:"pin" form:"pin" gorm:"type:tinyint(1);not null;default 0;comment:閲囪喘鍚嶇О"` // 鏄惁缃《
+}
diff --git a/router/purchase/purchase.go b/router/purchase/purchase.go
index c133faf..a7b3728 100644
--- a/router/purchase/purchase.go
+++ b/router/purchase/purchase.go
@@ -7,14 +7,15 @@
func InitPurchaseRouter(Router *gin.RouterGroup) {
purchaseRouter := Router.Group("purchase")
- purchaseRouterWithoutRecord := Router.Group("purchase")
PurchaseApi := purchase.PurchaseApi{}
{
- purchaseRouter.POST("purchase", PurchaseApi.CreatePurchase) // 鍒涘缓閲囪喘鍗�
- purchaseRouter.PUT("purchase", PurchaseApi.UpdatePurchase) // 鏇存柊閲囪喘鍗�
- purchaseRouter.DELETE("purchase/:id", PurchaseApi.DeletePurchase) // 鍒犻櫎閲囪喘鍗�
- purchaseRouterWithoutRecord.GET("purchase/:id", PurchaseApi.GetPurchase) // 鑾峰彇鍗曚竴閲囪喘鍗曚俊鎭�
- purchaseRouterWithoutRecord.GET("purchaseList", PurchaseApi.GetPurchaseList) // 鑾峰彇閲囪喘鍗曞垪琛�
- purchaseRouterWithoutRecord.POST("submit/:id", PurchaseApi.Submit) // 鎻愪氦閲囪喘鍗�
+ purchaseRouter.POST("purchase", PurchaseApi.CreatePurchase) // 鍒涘缓閲囪喘鍗�
+ purchaseRouter.PUT("purchase", PurchaseApi.UpdatePurchase) // 鏇存柊閲囪喘鍗�
+ purchaseRouter.DELETE("purchase/:id", PurchaseApi.DeletePurchase) // 鍒犻櫎閲囪喘鍗�
+ purchaseRouter.GET("purchase/:id", PurchaseApi.GetPurchase) // 鑾峰彇鍗曚竴閲囪喘鍗曚俊鎭�
+ purchaseRouter.GET("purchaseList", PurchaseApi.GetPurchaseList) // 鑾峰彇閲囪喘鍗曞垪琛�
+ purchaseRouter.POST("submit/:id", PurchaseApi.Submit) // 鎻愪氦閲囪喘鍗�
+ purchaseRouter.POST("purchaseType", PurchaseApi.SavePurchaseType) // 淇濆瓨閲囪喘绫诲瀷
+ purchaseRouter.GET("purchaseTypeList", PurchaseApi.GetPurchaseTypeList) // 鏌ヨ閲囪喘绫诲瀷
}
}
diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go
index 58ae69d..c829fc1 100644
--- a/service/purchase/purchase.go
+++ b/service/purchase/purchase.go
@@ -7,7 +7,6 @@
"srm/global"
"srm/model/common/request"
"srm/model/purchase"
- purchaserequest "srm/model/purchase/request"
"srm/proto/qualityinspect"
"srm/service/test"
)
@@ -23,16 +22,16 @@
//@param: params *purchaserequest.AddPurchase
//@return: err error
-func (slf *PurchaseService) CreatePurchase(params purchaserequest.AddPurchase) (err error) {
+func (slf *PurchaseService) CreatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
- err = global.GVA_DB.Create(¶ms.Purchase).Error
+ err = tx.Create(¶ms).Error
if err != nil {
return err
}
- for _, product := range params.ProductList {
- product.PurchaseId = cast.ToInt(params.Purchase.ID)
+ for _, product := range productList {
+ product.PurchaseId = cast.ToInt(params.ID)
}
- return global.GVA_DB.Create(params.ProductList).Error
+ return tx.Create(productList).Error
})
return err
@@ -45,11 +44,11 @@
func (slf *PurchaseService) DeletePurchase(id uint) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
- err = global.GVA_DB.Where("id = ?", id).Delete(&purchase.Purchase{}).Error
+ err = tx.Where("id = ?", id).Delete(&purchase.Purchase{}).Error
if err != nil {
return err
}
- return global.GVA_DB.Where("purchase_id = ?", id).Delete(&purchase.PurchaseProducts{}).Error
+ return tx.Where("purchase_id = ?", id).Delete(&purchase.PurchaseProducts{}).Error
})
return err
}
@@ -59,21 +58,21 @@
//@param: params *purchaserequest.AddPurchase
//@return: err error
-func (slf *PurchaseService) UpdatePurchase(params *purchaserequest.AddPurchase) (err error) {
+func (slf *PurchaseService) UpdatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
- err = global.GVA_DB.Updates(params.Purchase).Error
+ err = tx.Where("id = ?", params.ID).Updates(params).Error
if err != nil {
return err
}
- err = global.GVA_DB.Where("purchase_id = ?", params.Purchase.ID).Delete(&purchase.PurchaseProducts{}).Error
+ err = tx.Where("purchase_id = ?", params.ID).Delete(&purchase.PurchaseProducts{}).Error
if err != nil {
return err
}
- for _, product := range params.ProductList {
+ for _, product := range productList {
product.ID = 0
- product.PurchaseId = cast.ToInt(params.Purchase.ID)
+ product.PurchaseId = cast.ToInt(params.ID)
}
- return global.GVA_DB.Create(params.ProductList).Error
+ return tx.Create(productList).Error
})
return err
}
@@ -147,7 +146,7 @@
targetStatus = purchase.OrderStatusCompleted
}
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
- err = global.GVA_DB.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": targetStatus}).Error
+ err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": targetStatus}).Error
if err != nil {
return err
}
@@ -200,3 +199,24 @@
_, err = qualityinspect.NewQualityInspectServiceClient(qualityinspect.Conn).SendPurchaseInspect(context.Background(), &inspectRequest)
return err
}
+
+func (slf *PurchaseService) SavePurchaseType(list []*purchase.PurchaseType) (err error) {
+ err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
+ err = tx.Where("1 = ?", 1).Delete(&purchase.PurchaseType{}).Error
+ if err != nil {
+ return err
+ }
+ for _, item := range list {
+ item.ID = 0
+ }
+ return tx.Create(list).Error
+ })
+ return err
+}
+
+func (slf *PurchaseService) GetPurchaseTypeList() (list []*purchase.PurchaseType, err error) {
+ db := global.GVA_DB.Model(&purchase.PurchaseType{})
+ list = make([]*purchase.PurchaseType, 0)
+ err = db.Order("pin desc, sort desc, id asc").Find(&list).Error
+ return list, err
+}
--
Gitblit v1.8.0