- 修复门店报警门店按城市排序的bug
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -1561,6 +1562,28 @@ func getAllUsers4Store(ctx *jxcontext.Context, db *dao.DaoDB, store *model.Store
|
|||||||
return userList
|
return userList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tStoreIDList struct {
|
||||||
|
StoreIDList []int
|
||||||
|
StoreMap map[int]*model.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *tStoreIDList) Len() int {
|
||||||
|
return len(l.StoreIDList)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *tStoreIDList) Less(i, j int) bool {
|
||||||
|
storei := l.StoreMap[l.StoreIDList[i]]
|
||||||
|
storej := l.StoreMap[l.StoreIDList[j]]
|
||||||
|
if storei.CityCode == storej.CityCode {
|
||||||
|
return storei.ID < storej.ID
|
||||||
|
}
|
||||||
|
return storei.CityCode < storej.CityCode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *tStoreIDList) Swap(i, j int) {
|
||||||
|
l.StoreIDList[i], l.StoreIDList[j] = l.StoreIDList[j], l.StoreIDList[i]
|
||||||
|
}
|
||||||
|
|
||||||
func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, prevSnapshotList, curSnapshotList []*model.VendorStoreSnapshot) (err error) {
|
func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, prevSnapshotList, curSnapshotList []*model.VendorStoreSnapshot) (err error) {
|
||||||
if len(prevSnapshotList) == 0 {
|
if len(prevSnapshotList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -1646,17 +1669,37 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(userList) > 0 {
|
if len(userList) > 0 {
|
||||||
|
allStores, err := dao.GetStoreList(db, nil, nil, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
allStoreMap := make(map[int]*model.Store)
|
||||||
|
for _, v := range allStores {
|
||||||
|
allStoreMap[v.ID] = v
|
||||||
|
}
|
||||||
|
|
||||||
const fixTitle = "门店状态变化"
|
const fixTitle = "门店状态变化"
|
||||||
title := fmt.Sprintf("%s:%s-->%s", fixTitle, utils.Time2Str(prevSnapshotList[0].SnapshotAt), utils.Time2Str(curSnapshotList[0].SnapshotAt))
|
title := fmt.Sprintf("%s:%s-->%s", fixTitle, utils.Time2Str(prevSnapshotList[0].SnapshotAt), utils.Time2Str(curSnapshotList[0].SnapshotAt))
|
||||||
task := tasksch.NewParallelTask("SendAlarmVendorSnapshot", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
task := tasksch.NewParallelTask("SendAlarmVendorSnapshot", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
user := batchItemList[0].(*model.User)
|
user := batchItemList[0].(*model.User)
|
||||||
|
if user.GetMobile() != "18048531223" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
var excelURL string
|
var excelURL string
|
||||||
if user.Type&model.UserTypeOperator != 0 {
|
if user.Type&model.UserTypeOperator != 0 {
|
||||||
var dataList []map[string]interface{}
|
var dataList []map[string]interface{}
|
||||||
captionList := []string{"京西门店ID", "门店名", "城市"}
|
captionList := []string{"京西门店ID", "门店名", "城市"}
|
||||||
isFirstRow := true
|
isFirstRow := true
|
||||||
|
|
||||||
|
storeIDList := &tStoreIDList{
|
||||||
|
StoreMap: allStoreMap,
|
||||||
|
}
|
||||||
for storeID := range userMap[user.GetID()] {
|
for storeID := range userMap[user.GetID()] {
|
||||||
|
storeIDList.StoreIDList = append(storeIDList.StoreIDList, storeID)
|
||||||
|
}
|
||||||
|
sort.Sort(storeIDList)
|
||||||
|
for _, storeID := range storeIDList.StoreIDList {
|
||||||
prevAlarmMap := prevSnapshotMap2[storeID]
|
prevAlarmMap := prevSnapshotMap2[storeID]
|
||||||
curAlarmMap := curSnapshotMap2[storeID]
|
curAlarmMap := curSnapshotMap2[storeID]
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
@@ -1789,7 +1832,6 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
|
|||||||
err = SaveStoresVendorSnapshot(db, curSnapshotAt, curSnapshotList)
|
err = SaveStoresVendorSnapshot(db, curSnapshotAt, curSnapshotList)
|
||||||
case 2:
|
case 2:
|
||||||
prevSnapshotList, err = dao.GetVendorStoreSnapshot(db, prevSnapshotAt)
|
prevSnapshotList, err = dao.GetVendorStoreSnapshot(db, prevSnapshotAt)
|
||||||
curSnapshotList, err = dao.GetVendorStoreSnapshot(db, curSnapshotAt) // 因为排序的原因,重新取一下
|
|
||||||
case 3:
|
case 3:
|
||||||
err = SendAlarmVendorSnapshot(ctx, task, prevSnapshotList, curSnapshotList)
|
err = SendAlarmVendorSnapshot(ctx, task, prevSnapshotList, curSnapshotList)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ func TestGetStoresVendorSnapshot(t *testing.T) {
|
|||||||
|
|
||||||
func TestSendAlarmVendorSnapshot(t *testing.T) {
|
func TestSendAlarmVendorSnapshot(t *testing.T) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
prevSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-09 10:00:00"))
|
prevSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-17 08:00:00"))
|
||||||
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-09 11:00:00"))
|
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-17 10:00:00"))
|
||||||
err := SendAlarmVendorSnapshot(jxcontext.AdminCtx, nil, prevSnapshotList, curSnapshotList)
|
err := SendAlarmVendorSnapshot(jxcontext.AdminCtx, nil, prevSnapshotList, curSnapshotList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user