- 调整dao.GetVendorStoreSnapshot的实现
- updateVendorStoreStatusBySnapshot中更新本地平台门店信息
This commit is contained in:
@@ -1391,10 +1391,12 @@ func updateVendorStoreStatusBySnapshot(db *dao.DaoDB, curSnapshotList []*model.V
|
||||
}
|
||||
}()
|
||||
for _, v := range storeMapList {
|
||||
if snapshot := snapshotMap[jxutils.Combine2Int(v.StoreID, v.VendorID)]; snapshot != nil && v.Status != snapshot.Status {
|
||||
if snapshot := snapshotMap[jxutils.Combine2Int(v.StoreID, v.VendorID)]; snapshot != nil &&
|
||||
(v.Status != snapshot.Status || v.DeliveryType != snapshot.DeliveryType) {
|
||||
v.Status = snapshot.Status
|
||||
v.DeliveryType = snapshot.DeliveryType
|
||||
if _, err = dao.UpdateEntity(db, v, model.FieldStatus, "DeliveryType"); err != nil {
|
||||
v.LastOperator = model.AdminName
|
||||
if _, err = dao.UpdateEntity(db, v, model.FieldLastOperator, model.FieldUpdatedAt, model.FieldStatus, "DeliveryType"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1649,6 +1651,7 @@ func sendStoreStatusInfo2Mobile(mobile, title, txtAlarm string) {
|
||||
|
||||
func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync bool) (err error) {
|
||||
curSnapshotAt := getCurrentSnapshotAt(time.Now())
|
||||
prevSnapshotAt := getCurrentSnapshotAt(curSnapshotAt.Add(-1 * time.Second))
|
||||
db := dao.GetDB()
|
||||
var curSnapshotList, prevSnapshotList []*model.VendorStoreSnapshot
|
||||
task := tasksch.NewSeqTask("SaveAndSendAlarmVendorSnapshot", ctx,
|
||||
@@ -1664,7 +1667,7 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
|
||||
case 1:
|
||||
err = SaveStoresVendorSnapshot(db, curSnapshotAt, curSnapshotList)
|
||||
case 2:
|
||||
prevSnapshotList, err = dao.GetVendorStoreSnapshot(db, curSnapshotAt)
|
||||
prevSnapshotList, err = dao.GetVendorStoreSnapshot(db, prevSnapshotAt)
|
||||
case 3:
|
||||
err = SendAlarmVendorSnapshot(ctx, task, prevSnapshotList, curSnapshotList)
|
||||
}
|
||||
|
||||
@@ -27,3 +27,9 @@ func TestSendAlarmVendorSnapshot(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateVendorStoreStatusBySnapshot(t *testing.T) {
|
||||
db := dao.GetDB()
|
||||
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-07-30 08:00:00"))
|
||||
updateVendorStoreStatusBySnapshot(db, curSnapshotList)
|
||||
}
|
||||
|
||||
@@ -285,17 +285,12 @@ func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetVendorStoreSnapshot(db *DaoDB, excludeSnapshotAt time.Time) (snapshotList []*model.VendorStoreSnapshot, err error) {
|
||||
func GetVendorStoreSnapshot(db *DaoDB, snapshotAt time.Time) (snapshotList []*model.VendorStoreSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM vendor_store_snapshot t1
|
||||
WHERE t1.snapshot_at = (
|
||||
SELECT MAX(snapshot_at) snapshot_at
|
||||
FROM vendor_store_snapshot
|
||||
WHERE snapshot_at > ? AND snapshot_at <> ?
|
||||
)
|
||||
`
|
||||
err = GetRows(db, &snapshotList, sql, time.Now().Add(-48*time.Hour), excludeSnapshotAt)
|
||||
WHERE t1.snapshot_at = ?`
|
||||
err = GetRows(db, &snapshotList, sql, snapshotAt)
|
||||
return snapshotList, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user