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.
1310 lines
42 KiB
1310 lines
42 KiB
package commonus
|
|
|
|
//公共函数类
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
|
|
"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"
|
|
"github.com/mitchellh/mapstructure"
|
|
"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
|
|
}
|
|
|
|
//获取成员信息列表(企业威信数据库)
|
|
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)
|
|
}
|
|
}
|
|
|
|
//通用查询结果到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
|
|
}
|
|
|
|
//用户端身份解析
|
|
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
|
|
}
|
|
|
|
//更具微信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
|
|
}
|
|
|
|
//获取职务最大权重ID
|
|
func GetPositionMaxWeight(departmentID int64) (isTrue bool, content testpage.Position) {
|
|
isTrue = false
|
|
selectData := MapOut()
|
|
err := global.GVA_DB_Master.Model(&testpage.Position{}).Select("MAX(ps_weight) AS weight").Where("ps_bf_id = ?", departmentID).First(&selectData).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
conErr := global.GVA_DB_Master.Where("ps_bf_id = ? AND ps_weight = ?", departmentID, selectData["weight"]).First(&content).Error
|
|
if conErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取职责内容
|
|
func GetDutyContDepart(id int64) (isTrue bool, dutyAssClass DutyAssClass) {
|
|
isTrue = false
|
|
var dutyCont assessmentmodel.DepartDuty
|
|
err := global.GVA_DB_Performanceappraisal.Where("de_id = ?", id).First(&dutyCont).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
if dutyCont.State != 1 {
|
|
return
|
|
}
|
|
var dutyConts assessmentmodel.DutyContent
|
|
errCont := global.GVA_DB_Performanceappraisal.Where("dc_id = ?", dutyCont.DutyId).First(&dutyConts).Error
|
|
if errCont != nil {
|
|
return
|
|
}
|
|
if dutyConts.State != 1 {
|
|
return
|
|
}
|
|
dutyAssClass.Title = dutyConts.Title
|
|
dutyAssClass.ClassId = dutyCont.ClassId
|
|
dutyAssClass.AssessId = dutyCont.AssessId
|
|
var dutyClass assessmentmodel.DutyClass
|
|
errClass := global.GVA_DB_Performanceappraisal.Where("id = ?", dutyCont.ClassId).First(&dutyClass).Error
|
|
if errClass == nil {
|
|
dutyAssClass.ClassTitle = dutyClass.Title
|
|
}
|
|
var dutyassess assessmentmodel.AssessMentitems
|
|
errAss := global.GVA_DB_Performanceappraisal.Where("ai_id = ?", dutyCont.AssessId).First(&dutyassess).Error
|
|
if errAss == nil {
|
|
dutyAssClass.AssTitle = dutyassess.Title
|
|
}
|
|
isTrue = true
|
|
return
|
|
}
|
|
|
|
//获取集团信息
|
|
func GetGroupCont(id int64) (isTrue bool, ContInfo wechat.GroupForm) {
|
|
isTrue = false
|
|
err := global.GVA_DB_WatchDate.Where("g_id = ?", id).First(&ContInfo).Error
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核细则相关内容
|
|
func GetDutyCont(field, whereData interface{}) (isTrue bool, outData map[string]interface{}) {
|
|
isTrue = false
|
|
errAss := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DutyContent{}).Select(field).Where(whereData).First(&outData).Error
|
|
if errAss != nil {
|
|
return
|
|
}
|
|
isTrue = true
|
|
return
|
|
}
|
|
|
|
//获取人员信息
|
|
func GetUserInfoPublic(field interface{}, whereMap map[string]interface{}) (userCont testpage.PersonalDetails, isTrue bool) {
|
|
isTrue = false
|
|
var userInfo testpage.WorkMan
|
|
userErr := global.GVA_DB_Master.Model(&userInfo).Select(field).Joins("left join worker_man_data on worker_man_data.wmd_key = worker_man.wm_key").Where(whereMap).Find(&userCont).Error
|
|
if userErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核指标信息
|
|
func GetTargetInfo(id int64) (content assessmentmodel.EvaluationTarget, isTrue bool) {
|
|
isTrue = false
|
|
err := global.GVA_DB_Performanceappraisal.Where("et_id = ?", id).First(&content).Error
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核指标信息
|
|
func GetQualitativeTargetInfo(id int64) (content assessmentmodel.QualitativeTarget, isTrue bool) {
|
|
isTrue = false
|
|
err := global.GVA_DB_Performanceappraisal.Where("q_id = ?", id).First(&content).Error
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核指标细则
|
|
func GetDetailedTargetInfo(id int64) (content assessmentmodel.DetailedTarget, isTrue bool) {
|
|
isTrue = false
|
|
err := global.GVA_DB_Performanceappraisal.Where("dt_id = ?", id).First(&content).Error
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核类别
|
|
func GetDutyClassInfo(id int64) (content assessmentmodel.DutyClass, isTrue bool) {
|
|
isTrue = false
|
|
err := global.GVA_DB_Performanceappraisal.Where("id = ?", id).First(&content).Error
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//添加维度指标或维度权重
|
|
func AddDimenTargetWeight(setType, group, departmentID, dimensionId, targetId int64) {
|
|
var weightSum int64 = 0
|
|
// fmt.Printf("1-----@---2------->%v\n", targetId)
|
|
if targetId != 0 {
|
|
weghtErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.QualitativeEvaluation{}).Where("`qe_group` = ? AND `qe_accept_evaluation` = ? AND `qe_dimension` = ? AND `qe_target` = ?", group, departmentID, dimensionId, targetId).Pluck("COALESCE(SUM(qe_reference_score), 0) as qe_reference_score", &weightSum).Error
|
|
|
|
// msg = fmt.Sprintf("1-----@---1------->%v\n", weightSum)
|
|
if weghtErr == nil {
|
|
var ddwCont assessmentmodel.DepartmentDimensionWeight
|
|
judgeTrue := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Select("ddw_id").Where("`ddw_hierarchy` = 2 AND `ddw_group` = ? AND `ddw_derpatment` = ? AND `ddw_dimension` = ? AND `ddw_target` = ?", group, departmentID, dimensionId, targetId).First(&ddwCont).Error
|
|
if judgeTrue == nil {
|
|
targetWeightMap := MapOut()
|
|
targetWeightMap["ddw_hierarchy"] = 2
|
|
targetWeightMap["ddw_type"] = setType
|
|
targetWeightMap["ddw_weight"] = weightSum
|
|
targetWeightMap["ddw_time"] = time.Now().Unix()
|
|
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Where("`ddw_group` = ? AND `ddw_derpatment` = ? AND `ddw_dimension` = ? AND `ddw_target` = ?", group, departmentID, dimensionId, targetId).Updates(&targetWeightMap)
|
|
global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Where("`ddw_id` = ?", ddwCont.Id).Updates(&targetWeightMap)
|
|
// msg = fmt.Sprintf("1--------1------->%v\n", weightSum)
|
|
} else {
|
|
var saveData assessmentmodel.DepartmentDimensionWeight
|
|
saveData.Group = group
|
|
saveData.DepartmentId = departmentID
|
|
saveData.Dimension = dimensionId
|
|
saveData.Target = targetId
|
|
saveData.Weight = weightSum
|
|
saveData.Addtime = time.Now().Unix()
|
|
saveData.Type = int64(setType)
|
|
saveData.Hierarchy = 2
|
|
global.GVA_DB_Performanceappraisal.Create(&saveData)
|
|
// msg = fmt.Sprintf("2--------1------->%v\n", weightSum)
|
|
}
|
|
|
|
} else {
|
|
var saveData assessmentmodel.DepartmentDimensionWeight
|
|
saveData.Group = group
|
|
saveData.DepartmentId = departmentID
|
|
saveData.Dimension = dimensionId
|
|
saveData.Target = targetId
|
|
saveData.Weight = weightSum
|
|
saveData.Addtime = time.Now().Unix()
|
|
saveData.Type = int64(setType)
|
|
saveData.Hierarchy = 2
|
|
global.GVA_DB_Performanceappraisal.Create(&saveData)
|
|
// msg = fmt.Sprintf("3--------1------->%v\n", weightSum)
|
|
}
|
|
AddDimensionWeight(setType, group, departmentID, dimensionId)
|
|
}
|
|
// return
|
|
}
|
|
|
|
func AddDimensionWeight(setType, group, departmentID, dimensionId int64) {
|
|
var weightSum int64 = 0
|
|
fmt.Printf("1-------@-------->%v\n", departmentID)
|
|
if dimensionId != 0 {
|
|
weghtErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.QualitativeEvaluation{}).Where("`qe_group` = ? AND `qe_accept_evaluation` = ? AND `qe_dimension` = ?", group, departmentID, dimensionId).Pluck("COALESCE(SUM(qe_reference_score), 0) as qe_reference_score", &weightSum).Error
|
|
if weghtErr == nil {
|
|
var ddwCont assessmentmodel.DepartmentDimensionWeight
|
|
judgeTrue := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Select("ddw_id").Where("`ddw_hierarchy` = 1 AND `ddw_group` = ? AND `ddw_derpatment` = ? AND `ddw_dimension` = ?", group, departmentID, dimensionId).First(&ddwCont).Error
|
|
if judgeTrue == nil {
|
|
targetWeightMap := MapOut()
|
|
targetWeightMap["ddw_hierarchy"] = 1
|
|
targetWeightMap["ddw_type"] = setType
|
|
targetWeightMap["ddw_weight"] = weightSum
|
|
targetWeightMap["ddw_time"] = time.Now().Unix()
|
|
// global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Where("`ddw_group` = ? AND `ddw_derpatment` = ? AND `ddw_dimension` = ? AND `ddw_target` = ?", group, departmentID, dimensionId, targetId).Updates(&targetWeightMap)
|
|
global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DepartmentDimensionWeight{}).Where("`ddw_id` = ?", ddwCont.Id).Updates(&targetWeightMap)
|
|
// fmt.Printf("1--------------->%v\n", weightSum)
|
|
} else {
|
|
var saveData assessmentmodel.DepartmentDimensionWeight
|
|
saveData.Group = group
|
|
saveData.DepartmentId = departmentID
|
|
saveData.Dimension = dimensionId
|
|
saveData.Target = 0
|
|
saveData.Weight = weightSum
|
|
saveData.Addtime = time.Now().Unix()
|
|
saveData.Type = int64(setType)
|
|
saveData.Hierarchy = 1
|
|
global.GVA_DB_Performanceappraisal.Create(&saveData)
|
|
// fmt.Printf("2--------------->%v\n", weightSum)
|
|
}
|
|
|
|
} else {
|
|
var saveData assessmentmodel.DepartmentDimensionWeight
|
|
saveData.Group = group
|
|
saveData.DepartmentId = departmentID
|
|
saveData.Dimension = dimensionId
|
|
saveData.Target = 0
|
|
saveData.Weight = weightSum
|
|
saveData.Addtime = time.Now().Unix()
|
|
saveData.Type = int64(setType)
|
|
saveData.Hierarchy = 1
|
|
global.GVA_DB_Performanceappraisal.Create(&saveData)
|
|
// fmt.Printf("3--------------->%v\n", weightSum)
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取维度或指标权重
|
|
func GetDimesionTargetWeight(setType, group, departmentID, dimensionId, targetId int64) (weight int64) {
|
|
var ddwCont assessmentmodel.DepartmentDimensionWeight
|
|
gormDb := global.GVA_DB_Performanceappraisal
|
|
gormDb = gormDb.Select("ddw_weight").Where("`ddw_group` = ? AND `ddw_derpatment` = ? AND `ddw_dimension` = ?", group, departmentID, dimensionId)
|
|
if setType == 2 {
|
|
gormDb = gormDb.Where("`ddw_hierarchy` = 2 AND `ddw_target` = ?", targetId)
|
|
} else {
|
|
gormDb = gormDb.Where("`ddw_hierarchy` = 1")
|
|
}
|
|
judgeTrue := gormDb.First(&ddwCont).Error
|
|
if judgeTrue != nil {
|
|
weight = 0
|
|
} else {
|
|
weight = ddwCont.Weight
|
|
}
|
|
return
|
|
}
|
|
|
|
//根据部门获取内勤数据
|
|
func GetOfficeWork(id, departmentId int64) (isTrue bool, roleUser []roleGroupBodyAry) {
|
|
isTrue = false
|
|
departID := strconv.FormatInt(departmentId, 10)
|
|
var roleGroup systemuser.RoleGroup
|
|
err := global.GVA_DB_Master.Where("`srg_id` = ?", id).First(&roleGroup).Error //16118387069540343
|
|
if err != nil {
|
|
return
|
|
}
|
|
roleAry := MapOut()
|
|
errMap := json.Unmarshal([]byte(roleGroup.Contentes), &roleAry)
|
|
if errMap != nil {
|
|
return
|
|
}
|
|
for i, v := range roleAry {
|
|
// roleArys := MapOut()
|
|
if i == departID {
|
|
jsonMAp, _ := json.Marshal(v)
|
|
jsonErrs := json.Unmarshal(jsonMAp, &roleUser)
|
|
if jsonErrs == nil {
|
|
isTrue = true
|
|
}
|
|
// fmt.Printf("%v------->%v------->%v\n", i, roleGroup, roleUser)
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取企业微信信息接收人
|
|
func GetSendMsgUser(id, departmentId int64) (isTrue bool, userStr string) {
|
|
isTrue = false
|
|
err, departmentCont := GetBranchFactory(departmentId)
|
|
if err != true {
|
|
return
|
|
}
|
|
err, roleGroup := GetOfficeWork(id, int64(departmentCont.WechatId))
|
|
if err != true {
|
|
return
|
|
}
|
|
var userList []string
|
|
for _, v := range roleGroup {
|
|
userList = append(userList, v.Id)
|
|
}
|
|
if len(userList) > 0 {
|
|
userStr = strings.Join(userList, "|")
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取加减分订单
|
|
func GetScoreFlow(orderId string) (content assessmentmodel.ScoreFlow, isTrue bool) {
|
|
isTrue = false
|
|
judgeErr := global.GVA_DB_Performanceappraisal.Where("`sf_key` = ?", orderId).First(&content).Error
|
|
if judgeErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//审批流程
|
|
func GetEvaluationProcess(orderId string) (content assessmentmodel.EvaluationProcess, isTrue bool) {
|
|
isTrue = false
|
|
judgeErr := global.GVA_DB_Performanceappraisal.Where("`ep_order_key` = ?", orderId).First(&content).Error
|
|
if judgeErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//考核方案
|
|
func GetQualitativeEvaluation(orderId string) (content assessmentmodel.QualitativeEvaluation, isTrue bool) {
|
|
isTrue = false
|
|
judgeErr := global.GVA_DB_Performanceappraisal.Where("`qe_id` = ?", orderId).First(&content).Error
|
|
if judgeErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取考核项目关联项目
|
|
/*
|
|
@orderId 加减分订单Id
|
|
returnData
|
|
#targettitle 指标名称
|
|
#detailedRulesTitle 明细
|
|
#detailedRulesInfo 明细说明
|
|
*/
|
|
func GetDutyAssociatedItems(orderId string) (targettitle, detailedRulesTitle, detailedRulesInfo, unit string, flowContent assessmentmodel.ScoreFlow, isTrue bool) {
|
|
flowContent, isTrue = GetScoreFlow(orderId)
|
|
if isTrue != true {
|
|
return
|
|
}
|
|
qualEvalCont, qualEvalErr := GetQualitativeEvaluation(strconv.FormatInt(flowContent.EvaluationPlan, 10))
|
|
if qualEvalErr != true {
|
|
return
|
|
}
|
|
unit = qualEvalCont.Unit
|
|
targetCont, targetErr := GetTargetInfo(qualEvalCont.Target)
|
|
if targetErr == true {
|
|
targettitle = targetCont.Title
|
|
unit = targetCont.Uniteing
|
|
}
|
|
|
|
detailedTargetCont, detailedTargetErr := GetDetailedTargetInfo(qualEvalCont.Target)
|
|
if detailedTargetErr == true {
|
|
detailedRulesTitle = detailedTargetCont.Title
|
|
detailedRulesInfo = detailedTargetCont.Content
|
|
}
|
|
isTrue = true
|
|
return
|
|
}
|
|
|
|
//获取加减分订单
|
|
func GetFlowLog(orderId string) (content assessmentmodel.FlowLog, isTrue bool) {
|
|
isTrue = false
|
|
judgeErr := global.GVA_DB_Performanceappraisal.Where("`fl_key` = ?", orderId).First(&content).Error
|
|
if judgeErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
@orderId 加减分订单Id
|
|
returnData
|
|
#targettitle 指标名称
|
|
#detailedRulesTitle 明细
|
|
#detailedRulesInfo 明细说明
|
|
*/
|
|
func GetDutyRationtedItems(orderId string) (targettitle, detailedRulesTitle, detailedRulesInfo, unit string, flowContent assessmentmodel.FlowLog, isTrue bool) {
|
|
// flowContent, isTrue = GetFlowLog(orderId)
|
|
// if isTrue != true {
|
|
// return
|
|
// }
|
|
// qualEvalCont, qualEvalErr := GetQualitativeEvaluation(strconv.FormatInt(flowContent.EvaluationPlan, 10))
|
|
// if qualEvalErr != true {
|
|
// return
|
|
// }
|
|
// unit = qualEvalCont.Unit
|
|
// targetCont, targetErr := GetTargetInfo(qualEvalCont.Target)
|
|
// if targetErr == true {
|
|
// targettitle = targetCont.Title
|
|
// unit = targetCont.Uniteing
|
|
// }
|
|
|
|
// detailedTargetCont, detailedTargetErr := GetDetailedTargetInfo(qualEvalCont.Target)
|
|
// if detailedTargetErr == true {
|
|
// detailedRulesTitle = detailedTargetCont.Title
|
|
// detailedRulesInfo = detailedTargetCont.Content
|
|
// }
|
|
isTrue = true
|
|
return
|
|
}
|
|
|
|
//获取角色组
|
|
func GetRoleGroup(id int64) (roleGroup systemuser.RoleGroup, isTrue bool) {
|
|
isTrue = false
|
|
err := global.GVA_DB_Master.Where("`srg_id` = ?", id).First(&roleGroup).Error //16118387069540343
|
|
if err != nil {
|
|
return
|
|
}
|
|
isTrue = true
|
|
return
|
|
}
|
|
|