- 修复门店报警门店按城市排序的bug

This commit is contained in:
gazebo
2019-09-17 10:47:09 +08:00
parent 6bf8296963
commit 7bc963c31f
2 changed files with 45 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"math"
"sort"
"strconv"
"strings"
"time"
@@ -1561,6 +1562,28 @@ func getAllUsers4Store(ctx *jxcontext.Context, db *dao.DaoDB, store *model.Store
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) {
if len(prevSnapshotList) == 0 {
return nil
@@ -1646,17 +1669,37 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
}
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 = "门店状态变化"
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,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
user := batchItemList[0].(*model.User)
if user.GetMobile() != "18048531223" {
return nil, nil
}
var excelURL string
if user.Type&model.UserTypeOperator != 0 {
var dataList []map[string]interface{}
captionList := []string{"京西门店ID", "门店名", "城市"}
isFirstRow := true
storeIDList := &tStoreIDList{
StoreMap: allStoreMap,
}
for storeID := range userMap[user.GetID()] {
storeIDList.StoreIDList = append(storeIDList.StoreIDList, storeID)
}
sort.Sort(storeIDList)
for _, storeID := range storeIDList.StoreIDList {
prevAlarmMap := prevSnapshotMap2[storeID]
curAlarmMap := curSnapshotMap2[storeID]
data := map[string]interface{}{
@@ -1789,7 +1832,6 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
err = SaveStoresVendorSnapshot(db, curSnapshotAt, curSnapshotList)
case 2:
prevSnapshotList, err = dao.GetVendorStoreSnapshot(db, prevSnapshotAt)
curSnapshotList, err = dao.GetVendorStoreSnapshot(db, curSnapshotAt) // 因为排序的原因,重新取一下
case 3:
err = SendAlarmVendorSnapshot(ctx, task, prevSnapshotList, curSnapshotList)
}

View File

@@ -20,8 +20,8 @@ func TestGetStoresVendorSnapshot(t *testing.T) {
func TestSendAlarmVendorSnapshot(t *testing.T) {
db := dao.GetDB()
prevSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-09 10:00:00"))
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-09 11:00:00"))
prevSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-17 08:00:00"))
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-09-17 10:00:00"))
err := SendAlarmVendorSnapshot(jxcontext.AdminCtx, nil, prevSnapshotList, curSnapshotList)
if err != nil {
t.Fatal(err)