|
|
|
|
package commonus
|
|
|
|
|
|
|
|
|
|
//公共函数类
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/location"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/testpage"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/wechat"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//遍历所有父类
|
|
|
|
|
type ErgodicStruct struct {
|
|
|
|
|
ParentId int64
|
|
|
|
|
Date []int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//遍历组织架构
|
|
|
|
|
func (e *ErgodicStruct) ErgodicParentClassGroup(id int64, groupStruct []wechat.GroupForm) {
|
|
|
|
|
for _, v := range groupStruct {
|
|
|
|
|
if e.ParentId == 1 {
|
|
|
|
|
if v.Id == id {
|
|
|
|
|
e.Date = append(e.Date, v.Parentid)
|
|
|
|
|
e.ErgodicParentClassGroup(v.Parentid, groupStruct)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if v.Id == id {
|
|
|
|
|
if v.Parentid != 1 {
|
|
|
|
|
e.Date = append(e.Date, v.Parentid)
|
|
|
|
|
}
|
|
|
|
|
e.ErgodicParentClassGroup(v.Parentid, groupStruct)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//冒泡排序法
|
|
|
|
|
func BubbleSort(slice []int64) []int64 {
|
|
|
|
|
for n := 0; n <= len(slice); n++ {
|
|
|
|
|
for i := 1; i < len(slice)-n; i++ {
|
|
|
|
|
if slice[i] < slice[i-1] {
|
|
|
|
|
slice[i], slice[i-1] = slice[i-1], slice[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return slice
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取公司,分厂,工段
|
|
|
|
|
func GetGroupInfo(id int64) (isTrue bool, groupStruct wechat.GroupForm) {
|
|
|
|
|
isTrue = false
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
isTrues, tokenInfo := redisClient.Get("organStructure:group_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + strconv.FormatInt(id, 10))
|
|
|
|
|
if isTrues == true {
|
|
|
|
|
jsonUserList := json.Unmarshal([]byte(tokenInfo), &groupStruct)
|
|
|
|
|
if jsonUserList != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
isTrue = true
|
|
|
|
|
} else {
|
|
|
|
|
var groupStructs wechat.GroupForm //集团表结构
|
|
|
|
|
err := global.GVA_DB_WatchDate.Where("g_id = ?", id).First(&groupStruct).Error //获取集团信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
groupStruct, isTrue = AddWechatGroup(id, groupStructs)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
jsonUserList, jsonErr := json.Marshal(groupStruct)
|
|
|
|
|
if jsonErr != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
redisClient.SetRedisTime(604800)
|
|
|
|
|
redisClient.Set("organStructure:group_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+strconv.FormatInt(id, 10), string(jsonUserList))
|
|
|
|
|
isTrue = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// groupInfo["name"] = groupStruct.Name
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获主数据库员工信息(微信版本)
|
|
|
|
|
func GetMainDataBaseUserInfo(weChatId string) (isTrue bool, myInfo testpage.WorkMan) {
|
|
|
|
|
isTrue = false
|
|
|
|
|
err := global.GVA_DB_Master.Where("qywx_key = ? or wx_key = ?", weChatId, weChatId).First(&myInfo).Error //获取集团信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
userWechat := GetWechatUserInfo(weChatId)
|
|
|
|
|
isTrues, myDepartment := GetGroupInfo(int64(userWechat.MainDepartment))
|
|
|
|
|
if isTrues == false {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
myInfo.WorkWechatId = userWechat.UserId
|
|
|
|
|
|
|
|
|
|
var arrAy []int64
|
|
|
|
|
errdd := json.Unmarshal([]byte(myDepartment.Group), &arrAy)
|
|
|
|
|
|
|
|
|
|
if errdd == nil {
|
|
|
|
|
if len(arrAy) >= 2 {
|
|
|
|
|
if arrAy[0] == 1 {
|
|
|
|
|
myInfo.Group = arrAy[1]
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
myInfo.Group = arrAy[1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var weChatInfo wechat.WechatUsers
|
|
|
|
|
weChatInfo.Uid = GetFileNumber()
|
|
|
|
|
weChatInfo.Userid = userWechat.UserId
|
|
|
|
|
weChatInfo.Name = userWechat.Name
|
|
|
|
|
|
|
|
|
|
jsonStr, jsonErr := json.Marshal(userWechat.Department)
|
|
|
|
|
if jsonErr == nil {
|
|
|
|
|
weChatInfo.Department = string(jsonStr)
|
|
|
|
|
} else {
|
|
|
|
|
weChatInfo.Department = "[]"
|
|
|
|
|
}
|
|
|
|
|
weChatInfo.Position = userWechat.Position
|
|
|
|
|
weChatInfo.Mobile = userWechat.Mobile
|
|
|
|
|
GenderInt, gendererr := strconv.Atoi(userWechat.Gender)
|
|
|
|
|
if gendererr == nil {
|
|
|
|
|
weChatInfo.Gender = GenderInt
|
|
|
|
|
} else {
|
|
|
|
|
weChatInfo.Gender = 1
|
|
|
|
|
}
|
|
|
|
|
weChatInfo.Email = userWechat.Email
|
|
|
|
|
weChatInfo.Avatar = userWechat.Avatar
|
|
|
|
|
weChatInfo.Status = userWechat.Status
|
|
|
|
|
|
|
|
|
|
extattrStr, extattrErr := json.Marshal(userWechat.Extattr)
|
|
|
|
|
if extattrErr == nil {
|
|
|
|
|
weChatInfo.Extattr = string(extattrStr)
|
|
|
|
|
} else {
|
|
|
|
|
weChatInfo.Extattr = "{\"attrs\":[]}"
|
|
|
|
|
}
|
|
|
|
|
weChatInfo.MainDepartment = int64(userWechat.MainDepartment)
|
|
|
|
|
weChatInfo.QrCode = userWechat.QrCode
|
|
|
|
|
|
|
|
|
|
isLeaderInDeptStr, isLeaderInDeptrErr := json.Marshal(userWechat.IsLeaderInDept)
|
|
|
|
|
if isLeaderInDeptrErr == nil {
|
|
|
|
|
weChatInfo.IsLeaderInDept = string(isLeaderInDeptStr)
|
|
|
|
|
} else {
|
|
|
|
|
weChatInfo.IsLeaderInDept = "[0]"
|
|
|
|
|
}
|
|
|
|
|
weChatInfo.ThumbAvatar = userWechat.ThumbAvatar
|
|
|
|
|
weChatInfo.Time = time.Now().Unix()
|
|
|
|
|
addErr := global.GVA_DB_WatchDate.Create(&weChatInfo).Error
|
|
|
|
|
if addErr == nil {
|
|
|
|
|
isTrue = true
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
isTrue = true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取成员信息
|
|
|
|
|
func GetWechatUserInfo(weChatId string) (us UserListStruct) {
|
|
|
|
|
if weChatId == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
isTrue, tokenInfo := redisClient.HashGet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+weChatId)
|
|
|
|
|
if isTrue != true {
|
|
|
|
|
userInfo, _, _ := GetOneAddressBookMember(weChatId)
|
|
|
|
|
// var callBackData WechatUserInfo
|
|
|
|
|
// json.Unmarshal(userInfo, &callBackData)
|
|
|
|
|
|
|
|
|
|
// var us UserListStruct
|
|
|
|
|
json.Unmarshal(userInfo, &us)
|
|
|
|
|
|
|
|
|
|
userMap := MapOut()
|
|
|
|
|
json.Unmarshal(userInfo, &userMap)
|
|
|
|
|
jsonUser, _ := json.Marshal(us)
|
|
|
|
|
redisClient.SetRedisTime(2678400)
|
|
|
|
|
redisClient.HashSet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+weChatId, string(jsonUser))
|
|
|
|
|
// fmt.Printf("未经过redis=====>%v\n", weChatId)
|
|
|
|
|
} else {
|
|
|
|
|
// var us UserListStruct
|
|
|
|
|
json.Unmarshal([]byte(tokenInfo), &us)
|
|
|
|
|
// fmt.Printf("经过redis=====>%v\n", weChatId)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加企业微信组织
|
|
|
|
|
func AddWechatGroup(id int64, groupStruct wechat.GroupForm) (groupInfo wechat.GroupForm, isTrue bool) {
|
|
|
|
|
isTrue = false
|
|
|
|
|
groupFrameWork, isTrueErr := GetWechatFramework(id)
|
|
|
|
|
if isTrueErr == false {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var callBackData dePartMent
|
|
|
|
|
err := json.Unmarshal(groupFrameWork, &callBackData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var sunGroup []int64
|
|
|
|
|
sunGroup = append(sunGroup, id)
|
|
|
|
|
if callBackData.Errcode == 0 {
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
redisClient.SetRedisTime(604800)
|
|
|
|
|
for _, val := range callBackData.DePartMent {
|
|
|
|
|
// fmt.Printf("Key ==> %v ------ Val ==> %v\n", key, val)
|
|
|
|
|
writeRedisData := map[string]interface{}{
|
|
|
|
|
"id": val.Id,
|
|
|
|
|
"name": val.Name,
|
|
|
|
|
"name_en": val.NameEN,
|
|
|
|
|
"parentid": val.Parentid,
|
|
|
|
|
"order": val.Order,
|
|
|
|
|
}
|
|
|
|
|
departId := strconv.FormatInt(val.Id, 10)
|
|
|
|
|
if id == val.Id {
|
|
|
|
|
groupInfo.Id = val.Id
|
|
|
|
|
groupInfo.Name = val.Name
|
|
|
|
|
groupInfo.Parentid = val.Parentid
|
|
|
|
|
groupInfo.Orderes = val.Order
|
|
|
|
|
groupInfo.Time = time.Now().Unix()
|
|
|
|
|
groupInfo.Sate = 1
|
|
|
|
|
jsonStr, jsonErr := json.Marshal(sunGroup)
|
|
|
|
|
if jsonErr == nil {
|
|
|
|
|
groupInfo.GroupSun = string(jsonStr)
|
|
|
|
|
}
|
|
|
|
|
var group []wechat.GroupForm
|
|
|
|
|
listErr := global.GVA_DB_WatchDate.Find(&group).Error
|
|
|
|
|
if listErr == nil {
|
|
|
|
|
var parentGroup ErgodicStruct
|
|
|
|
|
parentGroup.ParentId = val.Parentid
|
|
|
|
|
parentGroup.ErgodicParentClassGroup(val.Parentid, group)
|
|
|
|
|
parentGroup.Date = append(parentGroup.Date, val.Parentid)
|
|
|
|
|
parentGroup.Date = append(parentGroup.Date, val.Id)
|
|
|
|
|
parentGroup.Date = BubbleSort(parentGroup.Date)
|
|
|
|
|
jsonStrFather, jsonErrFather := json.Marshal(parentGroup.Date)
|
|
|
|
|
if jsonErrFather == nil {
|
|
|
|
|
groupInfo.Group = string(jsonStrFather)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
addErr := global.GVA_DB_WatchDate.Create(&groupInfo).Error
|
|
|
|
|
if addErr == nil {
|
|
|
|
|
isTrue = true
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sunGroup = append(sunGroup, val.Id)
|
|
|
|
|
}
|
|
|
|
|
redisClient.HashMsetAdd("dePartMentAry:ment_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+departId, writeRedisData)
|
|
|
|
|
}
|
|
|
|
|
dePartMentJson, _ := json.Marshal(callBackData.DePartMent)
|
|
|
|
|
dePartMentIdStr := strconv.FormatInt(id, 10)
|
|
|
|
|
redisClient.Set("dePartMentList:list_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+dePartMentIdStr, string(dePartMentJson))
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取成员信息列表(企业威信数据库)
|
|
|
|
|
func GetMemberList() (userStruct []wechat.WechatUsers, isTrue bool) {
|
|
|
|
|
isTrue = false
|
|
|
|
|
var userAry []wechat.WechatUsers
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
isTrues, tokenInfo := redisClient.Get("deUserAry:wechatUser_" + global.GVA_CONFIG.RedisPrefix.Alias + "_all")
|
|
|
|
|
if isTrues != true {
|
|
|
|
|
userErr := global.GVA_DB_WatchDate.Where("status = 1").Find(&userAry).Error
|
|
|
|
|
if userErr != nil {
|
|
|
|
|
wechatAllList, _, isYes := GetDepartmentUserList(1)
|
|
|
|
|
if isYes != true {
|
|
|
|
|
var callBackData WechatUserInfoDepartment
|
|
|
|
|
json.Unmarshal(wechatAllList, &callBackData)
|
|
|
|
|
if callBackData.Errcode != 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, jsonVal := range callBackData.UserList {
|
|
|
|
|
var userInfo wechat.WechatUsers
|
|
|
|
|
|
|
|
|
|
userInfo.Userid = jsonVal.UserId
|
|
|
|
|
userInfo.Name = jsonVal.Name
|
|
|
|
|
|
|
|
|
|
jsonStr, jsonErr := json.Marshal(jsonVal.Department)
|
|
|
|
|
if jsonErr == nil {
|
|
|
|
|
userInfo.Department = string(jsonStr)
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.Department = "[]"
|
|
|
|
|
}
|
|
|
|
|
userInfo.Position = jsonVal.Position
|
|
|
|
|
|
|
|
|
|
userInfo.Mobile = jsonVal.Mobile
|
|
|
|
|
|
|
|
|
|
GenderInt, genderErr := strconv.Atoi(jsonVal.Gender)
|
|
|
|
|
if genderErr == nil {
|
|
|
|
|
userInfo.Gender = GenderInt
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.Gender = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfo.Email = jsonVal.Email
|
|
|
|
|
userInfo.Avatar = jsonVal.Avatar
|
|
|
|
|
userInfo.Status = jsonVal.Status
|
|
|
|
|
extattrJson, extattrErr := json.Marshal(jsonVal.Extattr)
|
|
|
|
|
if extattrErr == nil {
|
|
|
|
|
userInfo.Extattr = string(extattrJson)
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.Extattr = "{\"attrs\":[]}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfo.MainDepartment = int64(jsonVal.MainDepartment)
|
|
|
|
|
userInfo.QrCode = jsonVal.QrCode
|
|
|
|
|
|
|
|
|
|
isLeaderInDeptJson, isLeaderInDeptErr := json.Marshal(jsonVal.IsLeaderInDept)
|
|
|
|
|
if isLeaderInDeptErr == nil {
|
|
|
|
|
userInfo.IsLeaderInDept = string(isLeaderInDeptJson)
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.IsLeaderInDept = "[0]"
|
|
|
|
|
}
|
|
|
|
|
userInfo.ThumbAvatar = jsonVal.ThumbAvatar
|
|
|
|
|
userInfo.UserNumber = ""
|
|
|
|
|
userInfo.SysBf = 0
|
|
|
|
|
userInfo.SysWs = 0
|
|
|
|
|
userInfo.SysPs = 0
|
|
|
|
|
userInfo.WmTema = 0
|
|
|
|
|
userInfo.IsAdmin = 1
|
|
|
|
|
userInfo.IsRole = 0
|
|
|
|
|
userInfo.Pwd = ""
|
|
|
|
|
userInfo.Time = time.Now().Unix()
|
|
|
|
|
|
|
|
|
|
userStruct = append(userStruct, userInfo)
|
|
|
|
|
}
|
|
|
|
|
isTrue = true
|
|
|
|
|
jsonUserList, jsonErr := json.Marshal(userStruct)
|
|
|
|
|
if jsonErr != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
redisClient.SetRedisTime(259200)
|
|
|
|
|
redisClient.Set("deUserAry:wechatUser_"+global.GVA_CONFIG.RedisPrefix.Alias+"_all", string(jsonUserList))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, userCont := range userAry {
|
|
|
|
|
var userInfo wechat.WechatUsers
|
|
|
|
|
userInfo.Uid = userCont.Uid
|
|
|
|
|
userInfo.Userid = userCont.Userid
|
|
|
|
|
userInfo.Name = userCont.Name
|
|
|
|
|
userInfo.Department = userCont.Department
|
|
|
|
|
userInfo.Position = userCont.Position
|
|
|
|
|
userInfo.Mobile = userCont.Mobile
|
|
|
|
|
userInfo.Gender = userCont.Gender
|
|
|
|
|
userInfo.Email = userCont.Email
|
|
|
|
|
userInfo.Avatar = userCont.Avatar
|
|
|
|
|
userInfo.Status = userCont.Status
|
|
|
|
|
userInfo.Extattr = userCont.Extattr
|
|
|
|
|
userInfo.MainDepartment = userCont.MainDepartment
|
|
|
|
|
userInfo.QrCode = userCont.QrCode
|
|
|
|
|
userInfo.IsLeaderInDept = userCont.IsLeaderInDept
|
|
|
|
|
userInfo.ThumbAvatar = userCont.ThumbAvatar
|
|
|
|
|
userInfo.UserNumber = userCont.UserNumber
|
|
|
|
|
userInfo.SysBf = userCont.SysBf
|
|
|
|
|
userInfo.SysWs = userCont.SysWs
|
|
|
|
|
userInfo.SysPs = userCont.SysPs
|
|
|
|
|
userInfo.WmTema = userCont.WmTema
|
|
|
|
|
userInfo.IsAdmin = userCont.IsAdmin
|
|
|
|
|
userInfo.IsRole = userCont.IsRole
|
|
|
|
|
userInfo.Pwd = userCont.Pwd
|
|
|
|
|
userInfo.Time = userCont.Time
|
|
|
|
|
userStruct = append(userStruct, userInfo)
|
|
|
|
|
}
|
|
|
|
|
isTrue = true
|
|
|
|
|
jsonUserList, jsonErr := json.Marshal(userAry)
|
|
|
|
|
if jsonErr != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
redisClient.SetRedisTime(259200)
|
|
|
|
|
redisClient.Set("deUserAry:wechatUser_"+global.GVA_CONFIG.RedisPrefix.Alias+"_all", string(jsonUserList))
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
jsonUserList := json.Unmarshal([]byte(tokenInfo), &userAry)
|
|
|
|
|
if jsonUserList != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, userCont := range userAry {
|
|
|
|
|
var userInfo wechat.WechatUsers
|
|
|
|
|
userInfo.Uid = userCont.Uid
|
|
|
|
|
userInfo.Userid = userCont.Userid
|
|
|
|
|
userInfo.Name = userCont.Name
|
|
|
|
|
userInfo.Department = userCont.Department
|
|
|
|
|
userInfo.Position = userCont.Position
|
|
|
|
|
userInfo.Mobile = userCont.Mobile
|
|
|
|
|
userInfo.Gender = userCont.Gender
|
|
|
|
|
userInfo.Email = userCont.Email
|
|
|
|
|
userInfo.Avatar = userCont.Avatar
|
|
|
|
|
userInfo.Status = userCont.Status
|
|
|
|
|
userInfo.Extattr = userCont.Extattr
|
|
|
|
|
userInfo.MainDepartment = userCont.MainDepartment
|
|
|
|
|
userInfo.QrCode = userCont.QrCode
|
|
|
|
|
userInfo.IsLeaderInDept = userCont.IsLeaderInDept
|
|
|
|
|
userInfo.ThumbAvatar = userCont.ThumbAvatar
|
|
|
|
|
userInfo.UserNumber = userCont.UserNumber
|
|
|
|
|
userInfo.SysBf = userCont.SysBf
|
|
|
|
|
userInfo.SysWs = userCont.SysWs
|
|
|
|
|
userInfo.SysPs = userCont.SysPs
|
|
|
|
|
userInfo.WmTema = userCont.WmTema
|
|
|
|
|
userInfo.IsAdmin = userCont.IsAdmin
|
|
|
|
|
userInfo.IsRole = userCont.IsRole
|
|
|
|
|
userInfo.Pwd = userCont.Pwd
|
|
|
|
|
userInfo.Time = userCont.Time
|
|
|
|
|
userStruct = append(userStruct, userInfo)
|
|
|
|
|
}
|
|
|
|
|
isTrue = true
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取全国风险地区列表(企鹅接口 https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5)
|
|
|
|
|
func NationalRiskArea() []byte {
|
|
|
|
|
nationalUrl := "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
|
|
|
|
|
userInfo := CurlGet(nationalUrl)
|
|
|
|
|
return userInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取全国风险地区列表数据处理
|
|
|
|
|
func GetNationalRiskArea() (riskAreaCityList []RegionalRiskLevel, isTrue bool) {
|
|
|
|
|
isTrue = false
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
redisClient.SetRedisTime(7200)
|
|
|
|
|
isTrueStr, riskAreaRedis := redisClient.Get("nationalRiskArea:cityList_" + global.GVA_CONFIG.RedisPrefix.Alias)
|
|
|
|
|
if isTrueStr != true {
|
|
|
|
|
nationalRiskArea := NationalRiskArea() //获取鹅厂数据
|
|
|
|
|
var tencentJsonData TencentJsonData
|
|
|
|
|
jsonErr := json.Unmarshal(nationalRiskArea, &tencentJsonData) //反json化鹅厂数据
|
|
|
|
|
if jsonErr != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var DataJSonTencent DataJSonTencent
|
|
|
|
|
tencentJsonDataSerialize := json.RawMessage(tencentJsonData.Data)
|
|
|
|
|
jsonSerializeErr := json.Unmarshal(tencentJsonDataSerialize, &DataJSonTencent) //地区反序列化
|
|
|
|
|
if jsonSerializeErr != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// var regionalRiskAry []RegionalRiskLevel //风险等级模型数组切片
|
|
|
|
|
for _, chinaAry := range DataJSonTencent.AreaTree { //国家级
|
|
|
|
|
for _, provinceAry := range chinaAry.Children { //省级
|
|
|
|
|
for _, cityAry := range provinceAry.Children { //市级
|
|
|
|
|
isYes := 0
|
|
|
|
|
var regionalRisk RegionalRiskLevel //风险等级模型
|
|
|
|
|
regionalRisk.ProvinceName = provinceAry.Name
|
|
|
|
|
regionalRisk.CityName = cityAry.Name
|
|
|
|
|
regionalRisk.RiskText = cityAry.Total.Grade
|
|
|
|
|
regionalRisk.RiskLevel = 0
|
|
|
|
|
//切分数据结果,判断风险等级
|
|
|
|
|
countSplit := strings.Split(cityAry.Total.Grade, "中高")
|
|
|
|
|
regionalRisk.Province = int64(len(countSplit))
|
|
|
|
|
//0:无;1:低风险;2:中低风险;3:中风险;4:中高风险;5:高风险
|
|
|
|
|
if len(countSplit) >= 2 {
|
|
|
|
|
regionalRisk.RiskLevel = 4
|
|
|
|
|
isYes = 1
|
|
|
|
|
} else {
|
|
|
|
|
countSplits := strings.Split(cityAry.Total.Grade, "中低")
|
|
|
|
|
regionalRisk.City = int64(len(countSplits))
|
|
|
|
|
if len(countSplits) >= 2 {
|
|
|
|
|
regionalRisk.RiskLevel = 2
|
|
|
|
|
isYes = 1
|
|
|
|
|
} else {
|
|
|
|
|
countSplitcont := strings.Split(cityAry.Total.Grade, "中")
|
|
|
|
|
regionalRisk.County = int64(len(countSplitcont))
|
|
|
|
|
if len(countSplitcont) >= 2 {
|
|
|
|
|
regionalRisk.RiskLevel = 3
|
|
|
|
|
isYes = 1
|
|
|
|
|
} else {
|
|
|
|
|
countSpliHigh := strings.Split(cityAry.Total.Grade, "高")
|
|
|
|
|
regionalRisk.County = int64(len(countSpliHigh))
|
|
|
|
|
if len(countSpliHigh) >= 2 {
|
|
|
|
|
regionalRisk.RiskLevel = 5
|
|
|
|
|
isYes = 1
|
|
|
|
|
}
|
|
|
|
|
countSpliLown := strings.Split(cityAry.Total.Grade, "低")
|
|
|
|
|
regionalRisk.County = int64(len(countSpliLown))
|
|
|
|
|
if len(countSpliLown) >= 2 {
|
|
|
|
|
regionalRisk.RiskLevel = 1
|
|
|
|
|
isYes = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if isYes == 1 {
|
|
|
|
|
riskAreaCityList = append(riskAreaCityList, regionalRisk)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
regionalRiskJson, regionalRiskjsonErr := json.Marshal(riskAreaCityList)
|
|
|
|
|
if regionalRiskjsonErr == nil {
|
|
|
|
|
redisClient.Set("nationalRiskArea:cityList_"+global.GVA_CONFIG.RedisPrefix.Alias, string(regionalRiskJson))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
jsonUserList := json.Unmarshal([]byte(riskAreaRedis), &riskAreaCityList)
|
|
|
|
|
if jsonUserList == nil {
|
|
|
|
|
isTrue = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//写入异常人员列表
|
|
|
|
|
func WriteInMan(wechat, calCulTime string, groupId int64) {
|
|
|
|
|
if wechat == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
timeVal := time.Now().Unix() - 86400
|
|
|
|
|
if calCulTime != "" {
|
|
|
|
|
timeVals, errTime := DateToTimeStampEs(calCulTime)
|
|
|
|
|
if errTime == true {
|
|
|
|
|
timeVal = timeVals
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var abn location.AbnormalPeople
|
|
|
|
|
abnErr := global.GVA_DB_HealthReport.Where("abn_wechat_id = ?", wechat).First(&abn).Error
|
|
|
|
|
if abnErr != nil {
|
|
|
|
|
abn.WechatId = wechat
|
|
|
|
|
abn.GroupId = groupId
|
|
|
|
|
abn.Time = timeVal
|
|
|
|
|
global.GVA_DB_HealthReport.Create(&abn)
|
|
|
|
|
// fmt.Printf("Add -----> %v ------>%v\n", abnErr, abn)
|
|
|
|
|
} else {
|
|
|
|
|
abn.GroupId = groupId
|
|
|
|
|
abn.Time = timeVal
|
|
|
|
|
global.GVA_DB_HealthReport.Save(&abn)
|
|
|
|
|
// fmt.Printf("Eite -----> %v ------>%v\n", abnErr, abn)
|
|
|
|
|
}
|
|
|
|
|
}
|