- 添加门店状态报警文本消息
This commit is contained in:
@@ -1333,60 +1333,140 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
|||||||
return nil
|
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)
|
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)
|
curSnapshotGroupMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||||
|
|
||||||
|
txtAlarmSnapshotMap := make(map[int][]*model.VendorStoreSnapshot)
|
||||||
|
// 之前是开店当前是关店的,或营业时间缩短的
|
||||||
for _, v := range curSnapshotList {
|
for _, v := range curSnapshotList {
|
||||||
curSnapshotMap[v.GenMapKey()] = v
|
|
||||||
curSnapshotGroupMap[v.StoreID] = append(curSnapshotGroupMap[v.StoreID], 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)
|
storeDetailMap := make(map[int]*dao.StoreDetail)
|
||||||
userMap := make(map[string]map[int]int)
|
userMap := make(map[string]map[int]int)
|
||||||
db := dao.GetDB()
|
userMapTxt := make(map[string][]*model.VendorStoreSnapshot)
|
||||||
alarmMapHandler := func(alarmMap map[int]map[int]*model.VendorStoreSnapshot, v *model.VendorStoreSnapshot) {
|
for storeID, list := range alarmSnapshotMap {
|
||||||
if alarmMap[v.StoreID] == nil {
|
storeDetail, _ := dao.GetStoreDetail(db, storeID, list[0].VendorID)
|
||||||
alarmMap[v.StoreID] = make(map[int]*model.VendorStoreSnapshot)
|
if storeDetail != nil {
|
||||||
if storeDetailMap[v.StoreID] == nil {
|
storeDetailMap[storeID] = storeDetail
|
||||||
storeDetail, _ := dao.GetStoreDetail(db, v.StoreID, v.VendorID)
|
for _, mobile := range []string{storeDetail.Tel1, storeDetail.MarketManPhone, storeDetail.OperatorPhone} {
|
||||||
if storeDetail != nil {
|
if mobile != "" {
|
||||||
storeDetailMap[v.StoreID] = storeDetail
|
if userMap[mobile] == nil {
|
||||||
for _, mobile := range []string{storeDetail.Tel1, storeDetail.MarketManPhone, storeDetail.OperatorPhone} {
|
userMap[mobile] = make(map[int]int)
|
||||||
if mobile != "" {
|
}
|
||||||
if userMap[mobile] == nil {
|
userMap[mobile][storeID] = 1
|
||||||
userMap[mobile] = make(map[int]int)
|
|
||||||
}
|
if txtAlarmSnapshotMap[storeID] != nil {
|
||||||
userMap[mobile][v.StoreID] = 1
|
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
|
var mobileList []string
|
||||||
for mobile := range userMap {
|
for mobile := range userMap {
|
||||||
if mobile != "" && !shouldSkipMobile4SendStoreStatusInfo(mobile) {
|
if mobile != "" && !shouldSkipMobile4SendStoreStatusInfo(mobile) {
|
||||||
mobileList = append(mobileList, 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 {
|
if len(mobileList) > 0 {
|
||||||
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))
|
||||||
@@ -1397,8 +1477,8 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
|||||||
captionList := []string{"京西门店ID", "门店名", "城市"}
|
captionList := []string{"京西门店ID", "门店名", "城市"}
|
||||||
isFirstRow := true
|
isFirstRow := true
|
||||||
for storeID := range userMap[mobile] {
|
for storeID := range userMap[mobile] {
|
||||||
prevAlarmMap := alarmMap[storeID]
|
prevAlarmMap := prevSnapshotMap2[storeID]
|
||||||
curAlarmMap := alarmMap4StatusNotSame[storeID]
|
curAlarmMap := curSnapshotMap2[storeID]
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"京西门店ID": storeID,
|
"京西门店ID": storeID,
|
||||||
"门店名": storeDetailMap[storeID].Store.Name,
|
"门店名": storeDetailMap[storeID].Store.Name,
|
||||||
@@ -1460,7 +1540,25 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
|
|||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
globals.SugarLogger.Warnf("SendAlarmVendorSnapshot, send %s failed with error:%v", key, err2)
|
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
|
return nil, nil
|
||||||
}, mobileList)
|
}, mobileList)
|
||||||
tasksch.HandleTask(task, parentTask, true).Run()
|
tasksch.HandleTask(task, parentTask, true).Run()
|
||||||
@@ -1473,7 +1571,7 @@ func shouldSkipMobile4SendStoreStatusInfo(mobile string) bool {
|
|||||||
return userProvider.GetUser(mobile, auth2.AuthTypeMobile) == nil
|
return userProvider.GetUser(mobile, auth2.AuthTypeMobile) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendStoreStatusInfo2Mobile(mobile, title, excelURL string) {
|
func sendStoreStatusInfo2Mobile(mobile, title, excelURL, txtAlarm string) {
|
||||||
mobileList := []string{mobile}
|
mobileList := []string{mobile}
|
||||||
for mobile := range mobileGroupMap[mobile] {
|
for mobile := range mobileGroupMap[mobile] {
|
||||||
mobileList = append(mobileList, mobile)
|
mobileList = append(mobileList, mobile)
|
||||||
@@ -1481,8 +1579,8 @@ func sendStoreStatusInfo2Mobile(mobile, title, excelURL string) {
|
|||||||
|
|
||||||
for _, mobile := range mobileList {
|
for _, mobile := range mobileList {
|
||||||
if user := userProvider.GetUser(mobile, auth2.AuthTypeMobile); user != nil {
|
if user := userProvider.GetUser(mobile, auth2.AuthTypeMobile); user != nil {
|
||||||
globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s:%s", mobile, excelURL)
|
globals.SugarLogger.Debugf("sendStoreStatusInfo2Mobile %s:%s, txtAlarm:\n%s", mobile, excelURL, txtAlarm)
|
||||||
msg.SendUserMessage(user.GetID(), title, fmt.Sprintf("详情见: \n%s", excelURL))
|
msg.SendUserMessage(user.GetID(), title, fmt.Sprintf("门店状态报警\n%s\n详情见: \n%s", txtAlarm, excelURL))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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-06-27 10:00:00"))
|
prevSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-07-16 10:00:00"))
|
||||||
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2018-06-27 10:00:00"))
|
curSnapshotList, _ := dao.GetVendorStoreSnapshot(db, utils.Str2Time("2019-07-16 11: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