From 53b77ddf4d65db5aaf45a392147c3ddd00915a31 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 16 十一月 2023 10:56:50 +0800
Subject: [PATCH] 供应商编号重复校验
---
api/v1/test/supplier.go | 5 +++++
service/test/supplier.go | 12 ++++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/api/v1/test/supplier.go b/api/v1/test/supplier.go
index 197b10f..253e88d 100644
--- a/api/v1/test/supplier.go
+++ b/api/v1/test/supplier.go
@@ -3,6 +3,7 @@
import (
"github.com/gin-gonic/gin"
"go.uber.org/zap"
+ "gorm.io/gorm"
"srm/global"
"srm/model/common/request"
"srm/model/common/response"
@@ -33,6 +34,10 @@
response.FailWithMessage(err.Error(), c)
return
}
+ _, err = sService.GetSupplierByNumber(s.Number)
+ if err != gorm.ErrRecordNotFound {
+ response.FailWithMessage("缂栧彿閲嶅", c)
+ }
if err := sService.CreateSupplier(&s); err != nil {
global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err))
response.FailWithMessage("鍒涘缓澶辫触", c)
diff --git a/service/test/supplier.go b/service/test/supplier.go
index 5d7ac0c..aea759d 100644
--- a/service/test/supplier.go
+++ b/service/test/supplier.go
@@ -11,42 +11,42 @@
}
// CreateSupplier 鍒涘缓Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) CreateSupplier(s *test.Supplier) (err error) {
err = global.GVA_DB.Create(s).Error
return err
}
// DeleteSupplier 鍒犻櫎Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) DeleteSupplier(s test.Supplier) (err error) {
err = global.GVA_DB.Delete(&s).Error
return err
}
// DeleteSupplierByIds 鎵归噺鍒犻櫎Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) DeleteSupplierByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]test.Supplier{}, "id in ?", ids.Ids).Error
return err
}
// UpdateSupplier 鏇存柊Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) UpdateSupplier(s test.Supplier) (err error) {
err = global.GVA_DB.Updates(&s).Error
return err
}
// GetSupplier 鏍规嵁id鑾峰彇Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) GetSupplier(id uint) (s test.Supplier, err error) {
err = global.GVA_DB.Where("id = ?", id).First(&s).Error
return
}
+// GetSupplierByNumber 鏍规嵁缂栫爜鑾峰彇Supplier璁板綍
+func (sService *SupplierService) GetSupplierByNumber(number string) (s test.Supplier, err error) {
+ err = global.GVA_DB.Where("number = ?", number).First(&s).Error
+ return
+}
+
// GetSupplierInfoList 鍒嗛〉鑾峰彇Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
func (sService *SupplierService) GetSupplierInfoList(info testReq.SupplierSearch) (list []test.Supplier, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
--
Gitblit v1.8.0