121 lines
3.6 KiB
Go
121 lines
3.6 KiB
Go
package dao
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
)
|
|
|
|
func GetThingMapList(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (cats []*model.ThingMap, err error) {
|
|
sql := `
|
|
SELECT t1.*
|
|
FROM thing_map t1
|
|
WHERE t1.deleted_at = ? AND t1.thing_type = ?
|
|
`
|
|
sqlParams := []interface{}{
|
|
utils.DefaultTimeValue,
|
|
thingType,
|
|
}
|
|
if len(thingIDs) > 0 { // 必须要指定ID
|
|
sql += " AND t1.thing_id IN (" + GenQuestionMarks(len(thingIDs)) + ")"
|
|
sqlParams = append(sqlParams, thingIDs)
|
|
err = GetRows(db, &cats, sql, sqlParams...)
|
|
}
|
|
return cats, err
|
|
}
|
|
|
|
func GetThingMapMap(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (thingMapMap map[int64][]*model.ThingMap, err error) {
|
|
thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs)
|
|
if err == nil {
|
|
thingMapMap = make(map[int64][]*model.ThingMap)
|
|
for _, thingMap := range thingMapList {
|
|
thingMapMap[thingMap.ThingID] = append(thingMapMap[thingMap.ThingID], thingMap)
|
|
}
|
|
}
|
|
return thingMapMap, err
|
|
}
|
|
|
|
func SetThingMapSyncStatus(db *DaoDB, vendorIDs []int, vendorOrgCodes []string, thingType int, thingIDs []int, syncStatus int8) (num int64, err error) {
|
|
sql := `
|
|
UPDATE thing_map t1
|
|
SET t1.sync_status = t1.sync_status | ?
|
|
WHERE t1.deleted_at = ? AND t1.thing_type = ?
|
|
`
|
|
sqlParams := []interface{}{
|
|
syncStatus,
|
|
utils.DefaultTimeValue,
|
|
thingType,
|
|
}
|
|
if len(vendorIDs) > 0 {
|
|
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
|
sqlParams = append(sqlParams, vendorIDs)
|
|
}
|
|
if len(vendorOrgCodes) > 0 {
|
|
sql += " AND t1.vendor_org_code IN (" + GenQuestionMarks(len(vendorOrgCodes)) + ")"
|
|
sqlParams = append(sqlParams, vendorOrgCodes)
|
|
}
|
|
if len(thingIDs) > 0 {
|
|
sql += " AND t1.thing_id IN (" + GenQuestionMarks(len(thingIDs)) + ")"
|
|
sqlParams = append(sqlParams, thingIDs)
|
|
}
|
|
num, err = ExecuteSQL(db, sql, sqlParams...)
|
|
return num, err
|
|
}
|
|
|
|
func SetSkuNameSyncStatus(db *DaoDB, vendorIDs []int, vendorOrgCodes []string, nameIDs []int, syncStatus int8) (num int64, err error) {
|
|
if globals.IsUseThingMap {
|
|
skuIDs, err2 := GetSkuIDByNames(db, nameIDs)
|
|
if err = err2; err == nil {
|
|
num, err = SetThingMapSyncStatus(db, vendorIDs, vendorOrgCodes, model.ThingTypeSku, skuIDs, syncStatus)
|
|
}
|
|
} else {
|
|
sql := `
|
|
UPDATE sku t1
|
|
SET t1.jd_sync_status = t1.jd_sync_status | ?
|
|
WHERE t1.deleted_at = ?
|
|
`
|
|
sqlParams := []interface{}{
|
|
syncStatus,
|
|
utils.DefaultTimeValue,
|
|
}
|
|
if len(nameIDs) > 0 {
|
|
sql += " AND t1.name_id IN(" + GenQuestionMarks(len(nameIDs)) + ")"
|
|
sqlParams = append(sqlParams, nameIDs)
|
|
}
|
|
num, err = ExecuteSQL(db, sql, sqlParams...)
|
|
}
|
|
return num, err
|
|
}
|
|
|
|
func SetSkuSyncStatus(db *DaoDB, vendorID int, skuIDs []int, syncStatus int8) (num int64, err error) {
|
|
globals.SugarLogger.Debugf("SetSkuSyncStatus, vendorID:%d", vendorID)
|
|
|
|
if globals.IsUseThingMap {
|
|
num, err = SetThingMapSyncStatus(db, []int{vendorID}, nil, model.ThingTypeSku, skuIDs, syncStatus)
|
|
} else {
|
|
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
|
sql := fmt.Sprintf(`
|
|
UPDATE sku t1
|
|
SET t1.%s_sync_status = IF(t1.deleted_at = ?, t1.%s_sync_status | ?, 0)
|
|
`, fieldPrefix, fieldPrefix)
|
|
sqlParams := []interface{}{
|
|
utils.DefaultTimeValue,
|
|
syncStatus,
|
|
}
|
|
if (syncStatus & model.SyncFlagNewMask) != 0 {
|
|
sql += fmt.Sprintf(`,
|
|
t1.%s_id = 0
|
|
`, fieldPrefix)
|
|
}
|
|
sql += " WHERE 1 = 1"
|
|
if len(skuIDs) > 0 {
|
|
sql += " AND t1.id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
|
sqlParams = append(sqlParams, skuIDs)
|
|
}
|
|
num, err = ExecuteSQL(db, sql, sqlParams...)
|
|
}
|
|
return num, err
|
|
}
|