|
|
package ImRelateDao
|
|
|
|
|
|
import (
|
|
|
"dsSzxy/Utils/CommonUtil"
|
|
|
"dsSzxy/Utils/ConfigUtil"
|
|
|
"dsSzxy/Utils/DbUtil"
|
|
|
"dsSzxy/Utils/EsUtil"
|
|
|
"dsSzxy/Utils/RedisUtil"
|
|
|
ssdb "dsSzxy/Utils/SsdbUtil"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/httplib"
|
|
|
"github.com/xormplus/xorm"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
//人员信息结构
|
|
|
type Person struct {
|
|
|
Success bool `json:"success"`
|
|
|
PageSize int `json:"pageSize"`
|
|
|
PageNumber int `json:"pageNumber"`
|
|
|
TotalRow int `json:"totalRow"`
|
|
|
TotalPage int `json:"totalPage"`
|
|
|
List []PersonList `json:"list"`
|
|
|
}
|
|
|
|
|
|
//人员信息LIST
|
|
|
type PersonList struct {
|
|
|
OrgName string `json:"org_name"`
|
|
|
OrgId string `json:"org_id"`
|
|
|
IdentityId string `json:"identity_id"`
|
|
|
PersonId string `json:"person_id"`
|
|
|
PersonName string `json:"person_name"`
|
|
|
BureauName string `json:"bureau_name"`
|
|
|
FinanceNo string `json:"finance_no"`
|
|
|
IdentityNum string `json:"identity_num"`
|
|
|
LoginPassword string `json:"login_password"`
|
|
|
SortId string `json:"sort_id"`
|
|
|
LoginName string `json:"login_name"`
|
|
|
XbName string `json:"xb_name"`
|
|
|
WorkersNo string `json:"workers_no"`
|
|
|
BureauId string `json:"bureau_id"`
|
|
|
AvatarUrl string `json:"avatar_url"`
|
|
|
}
|
|
|
|
|
|
//聊天记录结构
|
|
|
type ChatRecordStruct struct {
|
|
|
SenderUserId string `json:"sender_user_id"`
|
|
|
SenderUserName string `json:"sender_user_name"`
|
|
|
SenderUserAvatar string `json:"sender_user_avatar"`
|
|
|
ReceiverUserId string `json:"receiver_user_id"`
|
|
|
ReceiverUserName string `json:"receiver_user_name"`
|
|
|
ReceiverUserAvatar string `json:"receiver_user_avatar"`
|
|
|
SendTime string `json:"send_time"`
|
|
|
Content string `json:"content"`
|
|
|
Base64 string `json:"base64"`
|
|
|
FileType string `json:"file_type"`
|
|
|
Url string `json:"url"`
|
|
|
Size string `json:"size"`
|
|
|
MessageType string `json:"message_type"`
|
|
|
ChatType string `json:"chat_type"`
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-12
|
|
|
*/
|
|
|
func GetPersonAvatar(personId string, identityId string, serverLocation string) string {
|
|
|
fileId, extension := GetPersonAvatarFileId(personId, identityId)
|
|
|
url := GetPersonAvatarUrl(fileId, extension, serverLocation)
|
|
|
return url
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取头像文件ID
|
|
|
作者:吴缤
|
|
|
日期:2021-08-12
|
|
|
*/
|
|
|
func GetPersonAvatarFileId(personId string, identityId string) (string, string) {
|
|
|
fileId := "EA0BC5FB-52D9-E232-D3E3-E6C2960B5739"
|
|
|
extension := "png"
|
|
|
|
|
|
ssdbClient, ssdbClientErr := ssdb.Connect(ConfigUtil.SSDBIp, ConfigUtil.SSDBPort)
|
|
|
if ssdbClientErr != nil {
|
|
|
return fileId, extension
|
|
|
}
|
|
|
res, resErr := ssdbClient.Get("space_ajson_personbaseinfo_" + personId + "_" + identityId)
|
|
|
if resErr != nil {
|
|
|
return fileId, extension
|
|
|
}
|
|
|
if res == nil {
|
|
|
return fileId, extension
|
|
|
}
|
|
|
jsonObj, jsonObjErr := CommonUtil.JsonStringToMap(fmt.Sprintf("%v", res))
|
|
|
if jsonObjErr != nil {
|
|
|
return fileId, extension
|
|
|
}
|
|
|
avatarId := fmt.Sprintf("%v", jsonObj["space_avatar_fileid"])
|
|
|
arr := strings.Split(avatarId, ".")
|
|
|
return arr[0], arr[1]
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据头像ID获取头像地址
|
|
|
作者:吴缤
|
|
|
日期:2021-09-03
|
|
|
*/
|
|
|
func GetPersonAvatarUrl(fileId string, extension string, serverLocation string) string {
|
|
|
url := ""
|
|
|
if serverLocation == "1" {
|
|
|
url = fmt.Sprintf("https://image.edusoa.com/down/Material/%s/%s.%s?x-image-process=image/resize,w_72,h_72/quality,q_100", fileId[0:2], fileId, extension)
|
|
|
} else {
|
|
|
url = fmt.Sprintf("%s/dsideal_yy/html/thumb/Material/%s/%s.%s@72w_72h_100Q_1x.png", ConfigUtil.DsidealYy, fileId[0:2], fileId, extension)
|
|
|
}
|
|
|
return url
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取群组名称和头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetGroupNameAvatar(groupId string, w string, h string) (string, string) {
|
|
|
avatarUrl := "/dsideal_yy/html/thumb/Material/%s/%s@" + w + "w_" + h + "h_100Q_1x.png"
|
|
|
//默认头像
|
|
|
avatarId := "9750A6F8-2CBF-4CF0-A254-F2528C45D3A8.png"
|
|
|
avatar := fmt.Sprintf(avatarUrl, avatarId[0:2], avatarId)
|
|
|
|
|
|
db := DbUtil.Engine
|
|
|
record := make(xorm.Record)
|
|
|
sql := "select group_name,avater_url from t_base_group_new where id = ?"
|
|
|
_, err := db.SQL(sql, groupId).Get(&record)
|
|
|
if err != nil {
|
|
|
return "未知", avatar
|
|
|
}
|
|
|
|
|
|
avatarId = fmt.Sprintf("%v", record["avater_url"].String())
|
|
|
avatar = fmt.Sprintf(avatarUrl, avatarId[0:2], avatarId)
|
|
|
groupName := record["group_name"].String()
|
|
|
|
|
|
return groupName, avatar
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取人员姓名
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonName(personId string, identityId string) string {
|
|
|
personName := "未知"
|
|
|
personNameRedis, errRedis := GetPersonNameRedis(personId, identityId)
|
|
|
if errRedis != nil {
|
|
|
personNameMysql, errMysql := GetPersonNameMsyql(personId, identityId)
|
|
|
if errMysql != nil {
|
|
|
return personName
|
|
|
}
|
|
|
personName = personNameMysql
|
|
|
} else {
|
|
|
personName = personNameRedis
|
|
|
}
|
|
|
|
|
|
return personName
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:在Redis中获取人员姓名
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonNameRedis(personId string, identityId string) (string, error) {
|
|
|
key := fmt.Sprintf("person_%s_%s", personId, identityId)
|
|
|
result := RedisUtil.HMGETALL(key)
|
|
|
if len(result) == 0 {
|
|
|
return "", errors.New("redis中未找到")
|
|
|
}
|
|
|
return result["person_name"], nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:在Mysql中获取人员姓名
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonNameMsyql(personId string, identityId string) (string, error) {
|
|
|
|
|
|
db := DbUtil.Engine
|
|
|
record := make(xorm.Record)
|
|
|
|
|
|
sql := "select person_name from t_sys_loginperson where person_id = ? and identity_id=?"
|
|
|
|
|
|
_, err := db.SQL(sql, personId, identityId).Get(&record)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
personName := record["person_name"].String()
|
|
|
|
|
|
return personName, nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:发送融云消息
|
|
|
作者:吴缤
|
|
|
日期:2021-08-16
|
|
|
*/
|
|
|
func SendRongYunMsg(sendType string, fromId string, toId string, objectName string, content string) error {
|
|
|
sendTypeStr := ""
|
|
|
toTypeStr := ""
|
|
|
if sendType == "p" {
|
|
|
sendTypeStr = "private"
|
|
|
toTypeStr = "toUserId"
|
|
|
} else {
|
|
|
sendTypeStr = "group"
|
|
|
toTypeStr = "toGroupId"
|
|
|
}
|
|
|
url := fmt.Sprintf("https://api-cn.ronghub.com/message/%s/publish.json", sendTypeStr)
|
|
|
method := "POST"
|
|
|
|
|
|
parameter := fmt.Sprintf("fromUserId=%s&%s=%s&objectName=%s&content=%s", fromId, toTypeStr, toId, objectName, content)
|
|
|
|
|
|
payload := strings.NewReader(parameter)
|
|
|
|
|
|
client := &http.Client{
|
|
|
}
|
|
|
req, err := http.NewRequest(method, url, payload)
|
|
|
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
configMap, configErr := CommonUtil.GetRongYunConfig()
|
|
|
if configErr != nil {
|
|
|
return configErr
|
|
|
}
|
|
|
ak := configMap["app_key"]
|
|
|
r := CommonUtil.GetSixRandom()
|
|
|
ts := CommonUtil.GetTimeStamp()
|
|
|
sk := configMap["app_secret"]
|
|
|
|
|
|
st := CommonUtil.SHA1(sk + r + ts)
|
|
|
|
|
|
req.Header.Add("RC-App-Key", ak)
|
|
|
req.Header.Add("RC-Nonce", r)
|
|
|
req.Header.Add("RC-Timestamp", ts)
|
|
|
req.Header.Add("RC-Signature", st)
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
jsonObj, err := CommonUtil.JsonStringToMap(string(body))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
if jsonObj["code"] != float64(200) {
|
|
|
return errors.New("发送消息失败!")
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:保存聊天记录到ES
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func SaveChatRecord(indexName string, bodyString string) error {
|
|
|
esClient := EsUtil.EsClient
|
|
|
CTX := EsUtil.CTX
|
|
|
|
|
|
_, err := esClient.Index().
|
|
|
Index(indexName).
|
|
|
Id(CommonUtil.GetUUID()).
|
|
|
BodyString(bodyString).
|
|
|
Do(CTX)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据融云的userId拆分为人员ID和身份ID
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonIdIdentityId(userId string) (string, string) {
|
|
|
s := strings.Split(userId, "_")
|
|
|
return s[0], s[1]
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据融云的groupId拆分出组ID
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetGroupId(groupId string) string {
|
|
|
s := strings.Split(groupId, "_")
|
|
|
return s[0]
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据融云的userId获取人员姓名
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonNameByUserId(userId string) string {
|
|
|
pId, iId := GetPersonIdIdentityId(userId)
|
|
|
personName := GetPersonName(pId, iId)
|
|
|
return personName
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据融云的userId获取人员头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetPersonAvatarByUserId(userId string) string {
|
|
|
pId, iId := GetPersonIdIdentityId(userId)
|
|
|
avatar := GetPersonAvatar(pId, iId, "1")
|
|
|
return avatar
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据融云的groupId获取群组名称和头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-17
|
|
|
*/
|
|
|
func GetGroupNameAvatarByGroupId(groupId string) (string, string) {
|
|
|
gId := GetGroupId(groupId)
|
|
|
groupName, groupAvatar := GetGroupNameAvatar(gId, "36", "36")
|
|
|
return groupName, groupAvatar
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据发送人、接收人和发送类型获取人名和头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-23
|
|
|
*/
|
|
|
func GetPersonNameAvatar(fromId string, toId string, sendType string) (fromName, fromAvatar, toName, toAvatar string) {
|
|
|
fromName = GetPersonNameByUserId(fromId)
|
|
|
fromAvatar = GetPersonAvatarByUserId(fromId)
|
|
|
if sendType == "p" {
|
|
|
toName = GetPersonNameByUserId(toId)
|
|
|
toAvatar = GetPersonAvatarByUserId(toId)
|
|
|
} else
|
|
|
{
|
|
|
toName, toAvatar = GetGroupNameAvatarByGroupId(toId)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取系统类型 1:云版 2:局版
|
|
|
作者:吴缤
|
|
|
日期:2021-09-06
|
|
|
*/
|
|
|
func GetServerLocation() string {
|
|
|
url := ConfigUtil.DsidealYy + "/dsideal_yy/golbal/getValueByKey"
|
|
|
req := httplib.Get(url)
|
|
|
req.Param("key", "common.server.location")
|
|
|
resStr, err := req.String()
|
|
|
if err != nil {
|
|
|
return "2"
|
|
|
}
|
|
|
resObj, err := CommonUtil.JsonStringToMap(resStr)
|
|
|
if err != nil {
|
|
|
return "2"
|
|
|
}
|
|
|
|
|
|
return CommonUtil.ConvertInterfaceToString(resObj["common.server.location"])
|
|
|
}
|
|
|
|
|
|
func GetPersonList(bureauId string, orgId string, queryChild string, bUse string, personName string, queryBureauChild string,pageNumber string, pageSize string) (string, error) {
|
|
|
req := httplib.Get(fmt.Sprintf("%s/dsideal_yy/admin/new_base/personInfo_GetPersonInfoList", ConfigUtil.DsidealYy))
|
|
|
|
|
|
req.Param("bureau_id", bureauId)
|
|
|
req.Param("org_id", orgId)
|
|
|
req.Param("query_child", queryChild)
|
|
|
req.Param("b_use", bUse)
|
|
|
req.Param("person_name", personName)
|
|
|
req.Param("query_bureau_child", queryBureauChild)
|
|
|
req.Param("pageNumber", pageNumber)
|
|
|
req.Param("pageSize", pageSize)
|
|
|
|
|
|
resStr, err := req.String()
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
//获取是云版还是局版
|
|
|
serverLocation := GetServerLocation()
|
|
|
|
|
|
var p Person
|
|
|
json.Unmarshal([]byte(resStr), &p)
|
|
|
|
|
|
for i := 0; i < len(p.List); i++ {
|
|
|
personId := p.List[i].PersonId
|
|
|
identityId := p.List[i].IdentityId
|
|
|
p.List[i].AvatarUrl = GetPersonAvatar(personId, identityId, serverLocation)
|
|
|
}
|
|
|
jsonBytes, err := json.Marshal(p)
|
|
|
|
|
|
return string(jsonBytes), nil
|
|
|
}
|