- 添加门店状态报警文本消息
This commit is contained in:
@@ -1333,60 +1333,140 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
||||
return nil
|
||||
}
|
||||
|
||||
prevSnapshotMap := make(map[string]*model.VendorStoreSnapshot)
|
||||
prevSnapshotMap2 := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
for _, v := range prevSnapshotList {
|
||||
prevSnapshotMap[v.GenMapKey()] = v
|
||||
if prevSnapshotMap2[v.StoreID] == nil {
|
||||
prevSnapshotMap2[v.StoreID] = make(map[int]*model.VendorStoreSnapshot)
|
||||
}
|
||||
prevSnapshotMap2[v.StoreID][v.VendorID] = v
|
||||
}
|
||||
curSnapshotMap := make(map[string]*model.VendorStoreSnapshot)
|
||||
curSnapshotMap2 := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
alarmSnapshotMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||
curSnapshotGroupMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||
|
||||
txtAlarmSnapshotMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||
// 之前是开店当前是关店的,或营业时间缩短的
|
||||
for _, v := range curSnapshotList {
|
||||
curSnapshotMap[v.GenMapKey()] = v
|
||||
curSnapshotGroupMap[v.StoreID] = append(curSnapshotGroupMap[v.StoreID], v)
|
||||
if curSnapshotMap2[v.StoreID] == nil {
|
||||
curSnapshotMap2[v.StoreID] = make(map[int]*model.VendorStoreSnapshot)
|
||||
}
|
||||
curSnapshotMap2[v.StoreID][v.VendorID] = v
|
||||
|
||||
curSnapshotMap[v.GenMapKey()] = v
|
||||
prevSnapshot := prevSnapshotMap[v.GenMapKey()]
|
||||
if prevSnapshot != nil {
|
||||
if (prevSnapshot.Status == model.StoreStatusOpened && v.Status != model.StoreStatusOpened) ||
|
||||
v.CompareOperationTime(prevSnapshot) < 0 {
|
||||
alarmSnapshotMap[v.StoreID] = append(alarmSnapshotMap[v.StoreID], v)
|
||||
|
||||
txtAlarmSnapshotMap[prevSnapshot.StoreID] = append(txtAlarmSnapshotMap[prevSnapshot.StoreID], prevSnapshot)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//当前门店,不同平台门店状态不一致的
|
||||
for storeID, list := range curSnapshotGroupMap {
|
||||
if isVendorStoresStatusNotOk(list) {
|
||||
alarmSnapshotMap[storeID] = list
|
||||
}
|
||||
}
|
||||
|
||||
// 之前有店(且是开店状态),当前无店的
|
||||
for _, v := range prevSnapshotList {
|
||||
if v.Status == model.StoreStatusOpened && curSnapshotMap[v.GenMapKey()] == nil {
|
||||
alarmSnapshotMap[v.StoreID] = append(alarmSnapshotMap[v.StoreID], v)
|
||||
|
||||
txtAlarmSnapshotMap[v.StoreID] = append(txtAlarmSnapshotMap[v.StoreID], v)
|
||||
}
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
storeDetailMap := make(map[int]*dao.StoreDetail)
|
||||
userMap := make(map[string]map[int]int)
|
||||
db := dao.GetDB()
|
||||
alarmMapHandler := func(alarmMap map[int]map[int]*model.VendorStoreSnapshot, v *model.VendorStoreSnapshot) {
|
||||
if alarmMap[v.StoreID] == nil {
|
||||
alarmMap[v.StoreID] = make(map[int]*model.VendorStoreSnapshot)
|
||||
if storeDetailMap[v.StoreID] == nil {
|
||||
storeDetail, _ := dao.GetStoreDetail(db, v.StoreID, v.VendorID)
|
||||
if storeDetail != nil {
|
||||
storeDetailMap[v.StoreID] = storeDetail
|
||||
for _, mobile := range []string{storeDetail.Tel1, storeDetail.MarketManPhone, storeDetail.OperatorPhone} {
|
||||
if mobile != "" {
|
||||
if userMap[mobile] == nil {
|
||||
userMap[mobile] = make(map[int]int)
|
||||
}
|
||||
userMap[mobile][v.StoreID] = 1
|
||||
}
|
||||
userMapTxt := make(map[string][]*model.VendorStoreSnapshot)
|
||||
for storeID, list := range alarmSnapshotMap {
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeID, list[0].VendorID)
|
||||
if storeDetail != nil {
|
||||
storeDetailMap[storeID] = storeDetail
|
||||
for _, mobile := range []string{storeDetail.Tel1, storeDetail.MarketManPhone, storeDetail.OperatorPhone} {
|
||||
if mobile != "" {
|
||||
if userMap[mobile] == nil {
|
||||
userMap[mobile] = make(map[int]int)
|
||||
}
|
||||
userMap[mobile][storeID] = 1
|
||||
|
||||
if txtAlarmSnapshotMap[storeID] != nil {
|
||||
userMapTxt[mobile] = append(userMapTxt[mobile], txtAlarmSnapshotMap[storeID]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alarmMap[v.StoreID][v.VendorID] = v
|
||||
}
|
||||
|
||||
alarmMap := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
for _, v := range prevSnapshotList {
|
||||
curSnapshot := curSnapshotMap[v.GenMapKey()]
|
||||
if (curSnapshot == nil) || ((v.Status == model.StoreStatusOpened && curSnapshot.Status != model.StoreStatusOpened) ||
|
||||
curSnapshot.CompareOperationTime(v) < 0) {
|
||||
alarmMapHandler(alarmMap, v)
|
||||
}
|
||||
}
|
||||
alarmMap4StatusNotSame := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
for _, list := range curSnapshotGroupMap {
|
||||
if isVendorStoresStatusNotOk(list) {
|
||||
for _, v := range list {
|
||||
alarmMapHandler(alarmMap4StatusNotSame, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mobileList []string
|
||||
for mobile := range userMap {
|
||||
if mobile != "" && !shouldSkipMobile4SendStoreStatusInfo(mobile) {
|
||||
mobileList = append(mobileList, mobile)
|
||||
}
|
||||
}
|
||||
|
||||
//////
|
||||
// curSnapshotMap := make(map[string]*model.VendorStoreSnapshot)
|
||||
// curSnapshotGroupMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||
// for _, v := range curSnapshotList {
|
||||
// curSnapshotMap[v.GenMapKey()] = v
|
||||
// curSnapshotGroupMap[v.StoreID] = append(curSnapshotGroupMap[v.StoreID], v)
|
||||
// }
|
||||
|
||||
// storeDetailMap := make(map[int]*dao.StoreDetail)
|
||||
// userMap := make(map[string]map[int]int)
|
||||
// alarmMapHandler := func(alarmMap map[int]map[int]*model.VendorStoreSnapshot, v *model.VendorStoreSnapshot) {
|
||||
// if alarmMap[v.StoreID] == nil {
|
||||
// alarmMap[v.StoreID] = make(map[int]*model.VendorStoreSnapshot)
|
||||
// if storeDetailMap[v.StoreID] == nil {
|
||||
// storeDetail, _ := dao.GetStoreDetail(db, v.StoreID, v.VendorID)
|
||||
// if storeDetail != nil {
|
||||
// storeDetailMap[v.StoreID] = storeDetail
|
||||
// for _, mobile := range []string{storeDetail.Tel1, storeDetail.MarketManPhone, storeDetail.OperatorPhone} {
|
||||
// if mobile != "" {
|
||||
// if userMap[mobile] == nil {
|
||||
// userMap[mobile] = make(map[int]int)
|
||||
// }
|
||||
// userMap[mobile][v.StoreID] = 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// alarmMap[v.StoreID][v.VendorID] = v
|
||||
// }
|
||||
|
||||
// alarmMap := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
// for _, v := range prevSnapshotList {
|
||||
// curSnapshot := curSnapshotMap[v.GenMapKey()]
|
||||
// if (curSnapshot == nil) || ((v.Status == model.StoreStatusOpened && curSnapshot.Status != model.StoreStatusOpened) ||
|
||||
// curSnapshot.CompareOperationTime(v) < 0) {
|
||||
// alarmMapHandler(alarmMap, v)
|
||||
// }
|
||||
// }
|
||||
// alarmMap4StatusNotSame := make(map[int]map[int]*model.VendorStoreSnapshot)
|
||||
// for _, list := range curSnapshotGroupMap {
|
||||
// if isVendorStoresStatusNotOk(list) {
|
||||
// for _, v := range list {
|
||||
// alarmMapHandler(alarmMap4StatusNotSame, v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// var mobileList []string
|
||||
// for mobile := range userMap {
|
||||
// if mobile != "" && !shouldSkipMobile4SendStoreStatusInfo(mobile) {
|
||||
// mobileList = append(mobileList, mobile)
|
||||
// }
|
||||
// }
|
||||
if len(mobileList) > 0 {
|
||||
const fixTitle = "门店状态变化"
|
||||
title := fmt.Sprintf("%s:%s-->%s", fixTitle, utils.Time2Str(prevSnapshotList[0].SnapshotAt), utils.Time2Str(curSnapshotList[0].SnapshotAt))
|
||||
@@ -1397,8 +1477,8 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
||||
captionList := []string{"京西门店ID", "门店名", "城市"}
|
||||
isFirstRow := true
|
||||
for storeID := range userMap[mobile] {
|
||||
prevAlarmMap := alarmMap[storeID]
|
||||
curAlarmMap := alarmMap4StatusNotSame[storeID]
|
||||
prevAlarmMap := prevSnapshotMap2[storeID]
|
||||
curAlarmMap := curSnapshotMap2[storeID]
|
||||
data := map[string]interface{}{
|
||||
"京西门店ID": storeID,
|
||||
"门店名": storeDetailMap[storeID].Store.Name,
|
||||
@@ -1460,7 +1540,25 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
||||
if err2 != nil {
|
||||
globals.SugarLogger.Warnf("SendAlarmVendorSnapshot, send %s failed with error:%v", key, err2)
|
||||
}
|
||||
sendStoreStatusInfo2Mobile(mobile, title, excelURL)
|
||||
|
||||
var txtAlarm []string
|
||||
for _, v := range userMapTxt[mobile] {
|
||||
curSnapshot := curSnapshotMap[v.GenMapKey()]
|
||||
storeDetail := storeDetailMap[v.StoreID]
|
||||
curStoreStatus := "无店"
|
||||
if curSnapshot != nil {
|
||||
curStoreStatus = model.StoreStatusName[curSnapshot.Status]
|
||||
}
|
||||
txtAlarm = append(txtAlarm, fmt.Sprintf(`
|
||||
城市: %s
|
||||
门店: %s
|
||||
京西ID: %d
|
||||
平台: %s
|
||||
平台ID: %s
|
||||
之前状态: %s
|
||||
当前状态: %s`, storeDetail.CityName, storeDetail.Store.Name, v.StoreID, model.VendorChineseNames[v.VendorID], v.VendorStoreID, model.StoreStatusName[v.Status], curStoreStatus))
|
||||
}
|
||||
sendStoreStatusInfo2Mobile(mobile, title, excelURL, strings.Join(txtAlarm, "\n"))
|
||||
return nil, nil
|
||||
}, mobileList)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
@@ -1473,7 +1571,7 @@ func shouldSkipMobile4SendStoreStatusInfo(mobile string) bool {
|
||||
return userProvider.GetUser(mobile, auth2.AuthTypeMobile) == nil
|
||||
}
|
||||
|
||||
func sendStoreStatusInfo2Mobile(mobile, title, excelURL string) {
|
||||
func sendStoreStatusInfo2Mobile(mobile, title, excelURL, txtAlarm string) {
|
||||
mobileList := []string{mobile}
|
||||
for mobile := range mobileGroupMap[mobile] {
|
||||
mobileList = append(mobileList, mobile)
|
||||
@@ -1481,8 +1579,8 @@ func sendStoreStatusInfo2Mobile(mobile, title, excelURL string) {
|
||||
|
||||
for _, mobile := range mobileList {
|
||||
if user := userProvider.GetUser(mobile, auth2.AuthTypeMobile); user != nil {
|
||||
globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s:%s", mobile, excelURL)
|
||||
msg.SendUserMessage(user.GetID(), title, fmt.Sprintf("详情见: \n%s", excelURL))
|
||||
globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s:%s, txtAlarm:\n%s", mobile, excelURL, txtAlarm)
|
||||
msg.SendUserMessage(user.GetID(), title, fmt.Sprintf("门店状态报警\n%s\n详情见: \n%s", txtAlarm, excelURL))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user