- UpdateEntityLogicallyAndUpdateSyncStatus for model.SyncFlagModifiedMask
This commit is contained in:
@@ -70,6 +70,41 @@ func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface
|
||||
}), conditions)
|
||||
}
|
||||
|
||||
// 些函数会更新同步标志
|
||||
func UpdateEntityLogicallyAndUpdateSyncStatus(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}, syncStatusFieldName string) (num int64, err error) {
|
||||
if conditions != nil {
|
||||
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||
})
|
||||
} else {
|
||||
conditions = map[string]interface{}{
|
||||
model.FieldID: jxutils.GetObjFieldByName(item, model.FieldID),
|
||||
}
|
||||
}
|
||||
typeInfo := reflect.TypeOf(item)
|
||||
valueRows := reflect.New(reflect.SliceOf(typeInfo))
|
||||
rows := valueRows.Interface()
|
||||
if err = GetEntitiesByKV(db, rows, conditions, false); err == nil {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(rows, false))
|
||||
valueRows = reflect.Indirect(valueRows)
|
||||
for i := 0; i < valueRows.Len(); i++ {
|
||||
value := reflect.Indirect(valueRows.Index(i))
|
||||
status := value.FieldByName(syncStatusFieldName).Int() | model.SyncFlagModifiedMask
|
||||
num2, err2 := UpdateEntityByKV(db, value.Interface(), utils.MergeMaps(kvs, map[string]interface{}{
|
||||
model.FieldUpdatedAt: time.Now(),
|
||||
model.FieldLastOperator: userName,
|
||||
syncStatusFieldName: status,
|
||||
}), nil)
|
||||
if err = err2; err == nil {
|
||||
num += num2
|
||||
} else {
|
||||
return num, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}) (num int64, err error) {
|
||||
return UpdateEntityLogically(db, item, utils.MergeMaps(kvs, map[string]interface{}{
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
|
||||
Reference in New Issue
Block a user