dddd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

904 lines
28 KiB

package commonus
4 years ago
//公共函数类
import (
"encoding/json"
4 years ago
"fmt"
"regexp"
"strconv"
4 years ago
"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/systemuser"
"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"
4 years ago
"github.com/mitchellh/mapstructure"
4 years ago
"gorm.io/gorm"
)
//遍历所有父类
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
}
4 years ago
//获取成员信息列表(企业威信数据库)
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 {
4 years ago
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
}
4 years ago
//获取全国风险地区列表(企鹅接口 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
4 years ago
//切分数据结果,判断风险等级
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)
}
}
4 years ago
//通用查询结果到map结构
type GormTopMap struct {
Db *gorm.DB
TableName string
WhereMap map[string]interface{}
}
//输出Map查询数据库结果(多行)
func (g *GormTopMap) PublicOrmToMap() (returnData []map[string]interface{}) {
if len(g.WhereMap) > 0 {
g.Db.Table(g.TableName).Where(g.WhereMap).Find(&returnData)
} else {
g.Db.Table(g.TableName).Find(&returnData)
}
return
}
//输出Map查询数据库结果(单行)
func (g *GormTopMap) PublicOrmToMapOne() (returnData map[string]interface{}) {
var selectData []map[string]interface{}
if len(g.WhereMap) > 0 {
g.Db.Table(g.TableName).Where(g.WhereMap).Take(&selectData)
} else {
g.Db.Table(g.TableName).Take(&selectData)
}
if len(selectData) < 1 && len(selectData) > 0 {
returnData = selectData[0]
}
return
}
//判断地址中是否还有http或https
func JudgeHttpOrHttps(urlStr string) (isTrue bool) {
isTrue = false
re := regexp.MustCompile(`(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?`)
result := re.FindAllStringSubmatch(urlStr, -1)
// fmt.Printf("urlStr ======>%v\n", result)
// for _,regVal := range result{
// if regVal
// }
if result == nil {
isTrue = true
}
return
}
//获取工段信息
func GetWorkShopSection(id int64) (isTrue bool, workShopesStruct testpage.WorkShopsection) { //工段表结构
isTrue = false
err := global.GVA_DB_Master.Where("ws_id = ?", id).First(&workShopesStruct).Error //获取工段信息
if err != nil {
return
}
isTrue = true
return
}
4 years ago
//用户端身份解析
func ClientIdentity() (isTrue bool, redisUserInfo testpage.RedisUserInfo) {
keyStr := strconv.FormatInt(global.GVA_INDEX_USERKEY, 10)
redisClient := redishandel.RunRedis()
tokenInfo, isTrue := redisClient.HashGetAll("system:userContent_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + keyStr)
if isTrue != true {
return
}
identityErr := mapstructure.Decode(tokenInfo, &redisUserInfo)
if identityErr != nil {
isTrue = false
return
}
return
}
//自定义管理端身份解析
func AdminClientIdentity() (isTrue bool, redisAdminInfo systemuser.RedisAdminInfo) {
keyStr := strconv.FormatInt(global.GVA_ADMIN_USERKEY, 10)
redisClient := redishandel.RunRedis()
tokenInfo, isTrue := redisClient.HashGetAll("system:SystemAdminInfo_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + keyStr)
if isTrue != true {
return
}
identityErr := mapstructure.Decode(tokenInfo, &redisAdminInfo)
if identityErr != nil {
isTrue = false
return
}
return
}
4 years ago
//更具微信ID获取员工信息
func GetUesrContForWechatID(wechatId string) (isTrue bool, myCont PublicUserCont) {
redisClient := redishandel.RunRedis()
isTrue = false
redisPrefix := "userInfo_" + global.GVA_CONFIG.RedisPrefix.PreFix + ":" + wechatId //redis KEY
redisCont, redisErr := redisClient.HashGetAll(redisPrefix)
if redisErr == true {
myCont.Number = redisCont["number"]
departmentid, departmentidErr := strconv.ParseInt(redisCont["departmentid"], 10, 64)
if departmentidErr == nil {
myCont.DepartmentId = departmentid
}
workshop, workshopErr := strconv.ParseInt(redisCont["workshopid"], 10, 64)
if workshopErr == nil {
myCont.WorkshopId = workshop
}
postid, postidErr := strconv.ParseInt(redisCont["postid"], 10, 64)
if postidErr == nil {
myCont.PostId = postid
}
tema, temaErr := strconv.ParseInt(redisCont["tema"], 10, 64)
if temaErr == nil {
myCont.Tema = tema
}
temakey, temakeyErr := strconv.ParseInt(redisCont["key"], 10, 64)
if temakeyErr == nil {
myCont.Key = temakey
}
stateval, statevalErr := strconv.Atoi(redisCont["key"])
if statevalErr == nil {
myCont.State = stateval
}
hireset, hiresetErr := strconv.Atoi(redisCont["hireset"])
if hiresetErr == nil {
myCont.HireSet = hireset
}
groupset, groupsetErr := strconv.ParseInt(redisCont["group"], 10, 64)
if groupsetErr == nil {
myCont.Group = groupset
}
myCont.WechatId = wechatId
myCont.Name = redisCont["name"]
gender, genderErr := strconv.Atoi(redisCont["gender"])
if genderErr == nil {
myCont.Gender = gender
}
age, ageErr := strconv.Atoi(redisCont["age"])
if ageErr == nil {
myCont.Age = age
}
myCont.Tel = redisCont["tel"]
category, categoryErr := strconv.Atoi(redisCont["category"])
if categoryErr == nil {
myCont.Category = category
}
certificatestype, certificatestypeErr := strconv.Atoi(redisCont["certificatestype"])
if certificatestypeErr == nil {
myCont.CertificatesType = certificatestype
}
myCont.CertificatesNum = redisCont["certificatesnum"]
myCont.Birthday = redisCont["birthday"]
myCont.EntryTime = redisCont["entrytime"]
myCont.QuitTimeAttr = redisCont["quittimeattr"]
myCont.Addrest = redisCont["addrest"]
myCont.Icon = redisCont["icon"]
myCont.NickName = redisCont["nickname"]
myCont.DepartmentName = redisCont["departmentname"]
myCont.WorkshopName = redisCont["workshopname"]
myCont.PostName = redisCont["postname"]
myCont.TemaName = redisCont["teamname"]
isTrue = true
// fmt.Printf("1===============>%v\n", myCont)
} else {
var userCont testpage.PersonalDetails
userErr := global.GVA_DB_Master.Model(&testpage.WorkMan{}).Select("worker_man.*", "worker_man_data.*").Joins("left join worker_man_data on worker_man_data.wmd_key = worker_man.wm_key").Where("`qywx_key` = ? OR `wx_key` = ?", wechatId, wechatId).Find(&userCont).Error
userInfo := MapOut()
if userErr == nil {
userInfo["number"] = userCont.Number
userInfo["departmentid"] = userCont.DepartmentId
userInfo["workshopid"] = userCont.WorkshopId
userInfo["postid"] = userCont.PostId
userInfo["tema"] = userCont.Tema
userInfo["key"] = userCont.Key
userInfo["state"] = userCont.State
userInfo["hireset"] = userCont.HireSet
userInfo["group"] = userCont.Group
userInfo["wechatid"] = wechatId
userInfo["name"] = userCont.Name
userInfo["gender"] = userCont.Gender
userInfo["age"] = userCont.Age
userInfo["tel"] = userCont.Tel
userInfo["category"] = userCont.Category
userInfo["certificatestype"] = userCont.CertificatesType
userInfo["certificatesnum"] = userCont.CertificatesNum
userInfo["birthday"] = TimeStampToDate(userCont.Birthday, 6)
userInfo["entrytime"] = TimeStampToDate(userCont.EntryTime, 6)
userInfo["quittimeattr"] = TimeStampToDate(userCont.QuitTimeAttr, 6)
userInfo["addrest"] = userCont.Addrest
userInfo["icon"] = userCont.Icon
userInfo["nickname"] = userCont.NickName
isTrue = true
myCont.Number = userCont.Number
myCont.DepartmentId = userCont.DepartmentId
bfIsTrue, bfInfo := GetBranchFactory(userCont.DepartmentId)
if bfIsTrue == true {
myCont.DepartmentName = bfInfo.Name
userInfo["departmentname"] = bfInfo.Name
} else {
userInfo["departmentname"] = ""
}
myCont.WorkshopId = userCont.WorkshopId
wsIsTrue, wsInfo := GetWorkShopSection(userCont.WorkshopId)
if wsIsTrue == true {
myCont.WorkshopName = wsInfo.Name
userInfo["workshopname"] = wsInfo.Name
} else {
userInfo["workshopname"] = ""
}
myCont.PostId = userCont.PostId
posErr, posCont := GetPosition(userCont.PostId)
if posErr == true {
myCont.PostName = posCont.Name
userInfo["postname"] = posCont.Name
} else {
userInfo["postname"] = ""
}
myCont.Tema = userCont.Tema
temErr, temCont := GetTeaming(userCont.Tema)
if temErr == true {
myCont.TemaName = temCont.Name
userInfo["teamname"] = temCont.Name
} else {
userInfo["teamname"] = ""
}
myCont.Key = userCont.Key
myCont.State = userCont.State
myCont.HireSet = userCont.HireSet
myCont.Group = userCont.Group
myCont.WechatId = wechatId
myCont.Name = userCont.Name
myCont.Gender = userCont.Gender
myCont.Age = userCont.Age
myCont.Tel = userCont.Tel
myCont.Category = userCont.Category
myCont.CertificatesType = userCont.CertificatesType
myCont.CertificatesNum = userCont.CertificatesNum
myCont.Birthday = TimeStampToDate(userCont.Birthday, 6)
myCont.EntryTime = TimeStampToDate(userCont.EntryTime, 6)
myCont.QuitTimeAttr = TimeStampToDate(userCont.QuitTimeAttr, 6)
myCont.Addrest = userCont.Addrest
myCont.Icon = userCont.Icon
myCont.NickName = userCont.NickName
redisClient.SetRedisTime(604800)
redisClient.HashMsetAdd(redisPrefix, userInfo)
fmt.Printf("2===============>\n")
} else {
var userInfoStruct wechat.WechatUsers
myErr := global.GVA_DB_WatchDate.Where("userid = ?", wechatId).First(&userInfoStruct).Error
if myErr != nil {
return
}
groupContErr, groupCont := GetGroupInfo(userInfoStruct.MainDepartment)
groupID := 1
if groupContErr == true {
var groupMap []int
jsonErr := json.Unmarshal([]byte(groupCont.Group), &groupMap)
if jsonErr == nil {
if len(groupMap) > 0 {
for g_index, g_val := range groupMap {
if g_index == 0 {
groupID = g_val
}
}
}
}
}
isTrue = true
tadyTime := time.Now().Unix()
userInfo["number"] = userInfoStruct.UserNumber
userInfo["departmentid"] = userInfoStruct.MainDepartment
userInfo["workshopid"] = 0
userInfo["postid"] = 0
userInfo["tema"] = 0
userInfo["key"] = 0
userInfo["state"] = userInfoStruct.Status
userInfo["hireset"] = 1
userInfo["group"] = groupID
userInfo["wechatid"] = wechatId
userInfo["name"] = userInfoStruct.Name
userInfo["gender"] = userInfoStruct.Gender
userInfo["age"] = 0
userInfo["tel"] = userInfoStruct.Mobile
userInfo["category"] = 1
userInfo["certificatestype"] = 1
userInfo["certificatesnum"] = ""
userInfo["birthday"] = TimeStampToDate(0, 6)
userInfo["entrytime"] = TimeStampToDate(tadyTime, 6)
userInfo["quittimeattr"] = TimeStampToDate(0, 6)
userInfo["addrest"] = 0
userInfo["icon"] = userInfoStruct.Avatar
userInfo["nickname"] = userInfoStruct.Name
userInfo["departmentname"] = ""
userInfo["workshopname"] = ""
userInfo["postname"] = ""
userInfo["teamname"] = ""
myCont.Number = userInfoStruct.UserNumber
myCont.DepartmentId = userInfoStruct.MainDepartment
myCont.WorkshopId = 0
myCont.PostId = 0
myCont.Tema = 0
myCont.Key = 0
myCont.State = userInfoStruct.Status
myCont.HireSet = 1
myCont.Group = 1
myCont.WechatId = wechatId
myCont.Name = userInfoStruct.Name
myCont.Gender = userInfoStruct.Gender
myCont.Age = 1
myCont.Tel = userInfoStruct.Mobile
myCont.Category = 1
myCont.CertificatesType = 1
myCont.CertificatesNum = ""
myCont.Birthday = TimeStampToDate(0, 6)
myCont.EntryTime = TimeStampToDate(tadyTime, 6)
myCont.QuitTimeAttr = TimeStampToDate(0, 6)
myCont.Addrest = ""
myCont.Icon = userInfoStruct.Avatar
myCont.NickName = userInfoStruct.Name
redisClient.SetRedisTime(604800)
redisClient.HashMsetAdd(redisPrefix, userInfo)
fmt.Printf("3===============>\n")
}
}
return
}
//获得分厂名称
func GetBranchFactory(id int64) (isTrue bool, ContInfo testpage.BranchFactory) {
isTrue = false
err := global.GVA_DB_Master.Where("bf_id = ?", id).First(&ContInfo).Error
if err == nil {
isTrue = true
}
return
}
//获取职务信息
func GetPosition(id int64) (isTrue bool, content testpage.Position) {
isTrue = false
err := global.GVA_DB_Master.Where("ps_id = ?", id).First(&content).Error
if err == nil {
isTrue = true
}
return
}
//获取班组信息
func GetTeaming(id int64) (isTrue bool, content testpage.Teaming) {
isTrue = false
err := global.GVA_DB_Master.Where("tm_id = ?", id).First(&content).Error
if err == nil {
isTrue = true
}
return
}
//