Quellcode durchsuchen

tmr 错误处理

bsj vor 2 Jahren
Ursprung
Commit
5fae1a7d37
1 geänderte Dateien mit 24 neuen und 12 gelöschten Zeilen
  1. 24 12
      routers/api/db.go

+ 24 - 12
routers/api/db.go

@@ -1,21 +1,11 @@
 package api
 
 import (
-	"../../pkg/app"
-	"../../pkg/e"
-	"../../pkg/logging"
-	"../../pkg/setting"
-	"../../routers/restful"
 	"bytes"
 	"database/sql"
 	"encoding/json"
 	"errors"
 	"fmt"
-	"github.com/360EntSecGroup-Skylar/excelize"
-	"github.com/Anderson-Lu/gofasion/gofasion"
-	"github.com/gin-gonic/gin"
-	"github.com/tealeg/xlsx"
-	"github.com/xormplus/xorm"
 	"io/ioutil"
 	"net/http"
 	"os"
@@ -24,6 +14,17 @@ import (
 	"strconv"
 	"strings"
 	"time"
+
+	"../../pkg/app"
+	"../../pkg/e"
+	"../../pkg/logging"
+	"../../pkg/setting"
+	"../../routers/restful"
+	"github.com/360EntSecGroup-Skylar/excelize"
+	"github.com/Anderson-Lu/gofasion/gofasion"
+	"github.com/gin-gonic/gin"
+	"github.com/tealeg/xlsx"
+	"github.com/xormplus/xorm"
 )
 
 // @Summary   根据SQL执行得到数据集
@@ -1047,8 +1048,19 @@ func PostDataByName(c *gin.Context) {
 		if err != nil {
 			logging.Error("PostDataByName  err: ", err)
 			//appG.Response(http.StatusOK, e.ERROR, err.Error())
-			msg := geterrmsg(err.Error())
-			appG.Response(http.StatusOK, e.ERROR, msg)
+
+			if (sqlnamestr == "copybarfeedremain" || sqlnamestr == "copyFtdry" || sqlnamestr == "copyPennsieve") &&
+				strings.Contains(err.Error(), "Duplicate entry") {
+
+				appG.Response(http.StatusOK, e.ERROR, "同一栏舍,同一班次不可重复录入")
+			} else if (sqlnamestr == "copybarmilk" || sqlnamestr == "copyBodyscore" || sqlnamestr == "copyDungsieve" || sqlnamestr == "copyDungscore") &&
+				strings.Contains(err.Error(), "Duplicate entry") {
+
+				appG.Response(http.StatusOK, e.ERROR, "同一栏舍不可重复录入")
+			} else {
+				msg := geterrmsg(err.Error())
+				appG.Response(http.StatusOK, e.ERROR, msg)
+			}
 		} else {
 			appG.Response(http.StatusOK, e.SUCCESS, queryData)
 		}