| | |
| | | |
| | | 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" |
| | | |
| | |
| | | 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 |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.AddPurchase true "采购单ID, 采购单信息" |
| | | // @Param data body purchaserequest.UpdatePurchase true "采购单ID, 采购单信息" |
| | | // @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) |
| | |
| | | } |
| | | 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) |
| | | } |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/purchaserequest.AddPurchase" |
| | | "$ref": "#/definitions/purchaserequest.UpdatePurchase" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "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" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | "description": "采购名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | | }, |
| | | "purchaseType": { |
| | | "$ref": "#/definitions/purchase.PurchaseType" |
| | | }, |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | |
| | | "signingDate": { |
| | | "description": "签约日期", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.OrderStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | } |
| | | }, |
| | | "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": "供应商id", |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/purchaserequest.AddPurchase" |
| | | "$ref": "#/definitions/purchaserequest.UpdatePurchase" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "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" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | "description": "采购名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | | }, |
| | | "purchaseType": { |
| | | "$ref": "#/definitions/purchase.PurchaseType" |
| | | }, |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | |
| | | "signingDate": { |
| | | "description": "签约日期", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.OrderStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | } |
| | | }, |
| | | "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": "供应商id", |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | 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: |
| | |
| | | name: |
| | | description: 采购名称 |
| | | type: string |
| | | number: |
| | | description: 采购编号 |
| | | type: string |
| | | phone: |
| | | description: 联系人电话 |
| | | type: string |
| | | purchaseType: |
| | | $ref: '#/definitions/purchase.PurchaseType' |
| | | purchaseTypeId: |
| | | description: 采购类型id |
| | | type: integer |
| | |
| | | signingDate: |
| | | description: 签约日期 |
| | | type: string |
| | | status: |
| | | allOf: |
| | | - $ref: '#/definitions/purchase.OrderStatus' |
| | | description: 状态 |
| | | supplier: |
| | | $ref: '#/definitions/test.Supplier' |
| | | supplierId: |
| | | description: 供应商id |
| | | type: integer |
| | |
| | | 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: |
| | |
| | | $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: 供应商id |
| | | 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: |
| | |
| | | name: data |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/purchaserequest.AddPurchase' |
| | | $ref: '#/definitions/purchaserequest.UpdatePurchase' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | 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: |
| | |
| | | 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:供应商id"` // 供应商id |
| | | PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"` |
| | | SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id |
| | | 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:联系人电话"` // 联系人电话 |
New file |
| | |
| | | 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:采购名称"` // 是否置顶 |
| | | } |
| | |
| | | } |
| | | |
| | | 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:供应商id"` // 供应商id |
| | | 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:状态"` //状态 |
| | | } |
New file |
| | |
| | | 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:采购名称"` // 是否置顶 |
| | | } |
| | |
| | | |
| | | 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) // 查询采购类型 |
| | | } |
| | | } |
| | |
| | | "srm/global" |
| | | "srm/model/common/request" |
| | | "srm/model/purchase" |
| | | purchaserequest "srm/model/purchase/request" |
| | | "srm/proto/qualityinspect" |
| | | "srm/service/test" |
| | | ) |
| | |
| | | //@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 |
| | |
| | | |
| | | 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 |
| | | } |
| | |
| | | //@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 |
| | | } |
| | |
| | | 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 |
| | | } |
| | |
| | | _, 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 |
| | | } |