From 19b9a324d0cb838d4279ffdd6cae670bfb675731 Mon Sep 17 00:00:00 2001 From: zhulh200868 <3205777381@qq.com> Date: Sat, 30 Dec 2017 18:50:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=BD=E7=84=B6=E6=A8=A1=E6=9D=BF=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=AD<=E8=AF=A5=E6=A8=A1=E6=9D=BF=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=AD=96=E7=95=A5=E5=88=97=E8=A1=A8>=E4=B8=AD?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E9=A1=B9=E6=98=AF=E5=8F=AF=E4=BB=A5=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E7=9A=84=EF=BC=8C=E7=9B=AE=E5=89=8D?= =?UTF-8?q?api=E4=B9=9F=E6=98=AF=E5=8F=AF=E4=BB=A5=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9A=84=EF=BC=8C=E4=BD=86=E6=98=AF=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=83=85=E5=86=B5=E4=B8=8B=E9=87=8D=E5=A4=8D=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=B8=E5=90=8C=E7=9A=84=E7=9B=91=E6=8E=A7=E9=A1=B9?= =?UTF-8?q?=E6=9C=89=E7=82=B9=E5=A4=9A=E4=BD=99=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E7=9A=84=E7=9B=91=E6=8E=A7=E9=A1=B9=E8=B6=8A?= =?UTF-8?q?=E6=9D=A5=E8=B6=8A=E5=A4=9A=E5=AF=B9=E4=BA=8E=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E9=80=9F=E5=BA=A6=E5=B0=86=E4=BC=9A=E5=8F=98?= =?UTF-8?q?=E6=85=A2=EF=BC=8C=E4=B8=AA=E4=BA=BA=E8=A7=89=E5=BE=97=E8=BF=98?= =?UTF-8?q?=E6=98=AF=E9=9C=80=E8=A6=81=E9=81=BF=E5=85=8D=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E7=9A=84=E6=95=B0=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/strategy/strategy_controller.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/api/app/controller/strategy/strategy_controller.go b/modules/api/app/controller/strategy/strategy_controller.go index f0be7dabc..18f787584 100644 --- a/modules/api/app/controller/strategy/strategy_controller.go +++ b/modules/api/app/controller/strategy/strategy_controller.go @@ -104,6 +104,18 @@ func CreateStrategy(c *gin.Context) { RunEnd: inputs.RunEnd, TplId: inputs.TplId, } + //在插入数据前先查一下数据中有没有一样的数据避免插入相同的数据。 + tx := db.Falcon.Begin() + strategy_count := []f.Strategy{} + if dt := tx.Where(&strategy).Find(&strategy_count); dt.Error != nil { + h.JSONR(c, expecstatus, fmt.Sprintf("select strategy got error: %s !", dt.Error)) + return + } else { + if len(strategy_count) > 0 { + h.JSONR(c, "This stragtegy is already created") + return + } + } dt := db.Falcon.Save(&strategy) if dt.Error != nil { h.JSONR(c, expecstatus, dt.Error)