This commit is contained in:
richboo111
2023-03-09 11:01:20 +08:00
parent 0e95eea7ac
commit 48eddab41d
2 changed files with 78 additions and 2 deletions

View File

@@ -1,17 +1,22 @@
package dao
import (
"errors"
"fmt"
"strings"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
//测试函数
func ReplaceInsertFreight2(storeID, templateID, warehouseID, tradeLimitID int, vendorStoreID, fenceID string) error {
if storeID == 0 || len(vendorStoreID) == 0 {
return fmt.Errorf("storeID或vendorStoreID不允许为空")
}
sqlStr := `REPLACE INTO freight_template (store_id, vendor_store_id, template_id, warehouse_id, fence_id, trade_limit_id)
SELECT ?,?,?,?,?,? FROM DUAL WHERE NOT EXISTS(SELECT COUNT(store_id) FROM freight_template WHERE store_id = ?)=0`
SELECT ?,?,?,?,?,? FROM DUAL WHERE NOT EXISTS(SELECT COUNT(store_id) FROM freight_template WHERE store_id = ?)=0`
sqlParam := []interface{}{storeID, vendorStoreID, templateID, warehouseID, fenceID, tradeLimitID, storeID}
_, err := ExecuteSQL(GetDB(), sqlStr, sqlParam)
return err
@@ -29,6 +34,52 @@ SELECT ?,?,?,?,?,? FROM DUAL WHERE NOT EXISTS(SELECT COUNT(store_id) FROM freigh
return err
}
func InsertItemFreight() {
//func InsertItemFreight2(storeID, templateID, warehouseID, tradeLimitID int, vendorStoreID, fenceID string) error {
// if storeID == 0 || len(vendorStoreID) == 0 {
// return fmt.Errorf("storeID或vendorStoreID不允许为空")
// }
// //sqlStr := `UPDATE freight_template f SET f.warehouse_id = ? WHERE f.store_id= ? AND f.vendor_store_id = ?`
// //sqlParam := []interface{}{}
//
// return nil
//}
func InsertItemFreight2(storeID int, vendorStoreID string, templateID, warehouseID, fenceID, tradeLimitID int64) error {
var (
sqlStr []string
tStr = ""
sqlParams []interface{}
)
if storeID == 0 && utils.Str2Int(vendorStoreID) == 0 {
return errors.New("storeID,vendorStoreID 必传")
}
sql := `UPDATE freight_template a SET `
if templateID != 0 {
templateIDSql := ` a.template_id = ? `
sqlParams = append(sqlParams, templateIDSql)
sqlStr = append(sqlStr, sql)
}
if warehouseID != 0 {
warehouseIDSql := ` a.warehouse_id = ? `
sqlParams = append(sqlParams, warehouseIDSql)
sqlStr = append(sqlStr, sql)
}
if fenceID != 0 {
fenceIDSql := ` a.fence_id = ?`
sqlParams = append(sqlParams, fenceIDSql)
sqlStr = append(sqlStr, sql)
}
if tradeLimitID != 0 {
sql += ` a.fence_id = ? `
sqlParams = append(sqlParams, templateID)
sqlStr = append(sqlStr, sql)
}
tStr = "WHERE a.store_id = ? AND a.vendor_store_id = ?"
tStr2 := sql + strings.Join(sqlStr, ",") + tStr
_, err := ExecuteSQL(GetDB(), tStr2, sqlParams...)
fmt.Println(tStr2)
return err
}