|
|
package ImRelateController
|
|
|
|
|
|
import (
|
|
|
"dsSzxy/Business/ImRelate/ImRelateDao"
|
|
|
"dsSzxy/Utils/CommonUtil"
|
|
|
"dsSzxy/Utils/ConfigUtil"
|
|
|
"encoding/json"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
//模块的路由配置
|
|
|
func Routers(r *gin.RouterGroup) {
|
|
|
rr := r.Group("/imRelate")
|
|
|
rr.POST("/SaveChatRecord", SaveChatRecord)
|
|
|
rr.POST("/GetPersonAvatar", GetPersonAvatar)
|
|
|
rr.GET("/GetPersonInfoList", GetPersonInfoList)
|
|
|
rr.POST("/CreateGroup", CreateGroup)
|
|
|
rr.POST("/SyncRongYunUser", SyncRongYunUser)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:保存聊天记录
|
|
|
作者:吴缤
|
|
|
日期:2021-08-23
|
|
|
*/
|
|
|
func SaveChatRecord(c *gin.Context) {
|
|
|
//发送方Id。
|
|
|
fromId := c.PostForm("fromId")
|
|
|
//接收方Id。
|
|
|
toId := c.PostForm("toId")
|
|
|
//发送类型 p:单聊 g:群聊
|
|
|
sendType := c.PostForm("sendType")
|
|
|
|
|
|
//获取姓名和头像
|
|
|
fromName, fromAvatar, toName, toAvatar := ImRelateDao.GetPersonNameAvatar(fromId, toId, sendType)
|
|
|
|
|
|
var crs ImRelateDao.ChatRecordStruct
|
|
|
|
|
|
objectName := c.PostForm("objectName")
|
|
|
if objectName == "RC:TxtMsg" {
|
|
|
//文本消息内容。
|
|
|
content := c.PostForm("content")
|
|
|
crs = ImRelateDao.ChatRecordStruct{
|
|
|
SenderUserId: fromId,
|
|
|
SenderUserName: fromName,
|
|
|
SenderUserAvatar: fromAvatar,
|
|
|
ReceiverUserId: toId,
|
|
|
ReceiverUserName: toName,
|
|
|
ReceiverUserAvatar: toAvatar,
|
|
|
SendTime: CommonUtil.GetCurrentTime(),
|
|
|
Content: content,
|
|
|
MessageType: objectName,
|
|
|
ChatType: sendType,
|
|
|
}
|
|
|
} else if objectName == "RC:ImgMsg" {
|
|
|
//图片base64。
|
|
|
imgBase64 := c.PostForm("imgBase64")
|
|
|
//图片Url
|
|
|
imgUrl := c.PostForm("imgUrl")
|
|
|
//文件名
|
|
|
fileName := c.PostForm("fileName")
|
|
|
|
|
|
crs = ImRelateDao.ChatRecordStruct{
|
|
|
SenderUserId: fromId,
|
|
|
SenderUserName: fromName,
|
|
|
SenderUserAvatar: fromAvatar,
|
|
|
ReceiverUserId: toId,
|
|
|
ReceiverUserName: toName,
|
|
|
ReceiverUserAvatar: toAvatar,
|
|
|
SendTime: CommonUtil.GetCurrentTime(),
|
|
|
Content: fileName,
|
|
|
Base64: imgBase64,
|
|
|
Url: imgUrl,
|
|
|
MessageType: objectName,
|
|
|
ChatType: sendType,
|
|
|
}
|
|
|
} else if objectName == "RC:FileMsg" {
|
|
|
//文件名
|
|
|
fileName := c.PostForm("fileName")
|
|
|
//文件大小
|
|
|
fileSize := c.PostForm("fileSize")
|
|
|
//文件类型
|
|
|
fileType := c.PostForm("fileType")
|
|
|
//文件URL
|
|
|
fileUrl := c.PostForm("fileUrl")
|
|
|
|
|
|
crs = ImRelateDao.ChatRecordStruct{
|
|
|
SenderUserId: fromId,
|
|
|
SenderUserName: fromName,
|
|
|
SenderUserAvatar: fromAvatar,
|
|
|
ReceiverUserId: toId,
|
|
|
ReceiverUserName: toName,
|
|
|
ReceiverUserAvatar: toAvatar,
|
|
|
SendTime: CommonUtil.GetCurrentTime(),
|
|
|
Content: fileName,
|
|
|
Size: fileSize,
|
|
|
FileType: fileType,
|
|
|
Url: fileUrl,
|
|
|
MessageType: objectName,
|
|
|
ChatType: sendType,
|
|
|
}
|
|
|
} else if objectName == "RC:SightMsg" {
|
|
|
//视频URL
|
|
|
videoUrl := c.PostForm("videoUrl")
|
|
|
//视频缩略图base64编码
|
|
|
thumbBase64 := ConfigUtil.VideoThumb
|
|
|
//视频大小
|
|
|
videoSize := c.PostForm("videoSize")
|
|
|
//视频名称
|
|
|
videoName := c.PostForm("fileName")
|
|
|
|
|
|
crs = ImRelateDao.ChatRecordStruct{
|
|
|
SenderUserId: fromId,
|
|
|
SenderUserName: fromName,
|
|
|
SenderUserAvatar: fromAvatar,
|
|
|
ReceiverUserId: toId,
|
|
|
ReceiverUserName: toName,
|
|
|
ReceiverUserAvatar: toAvatar,
|
|
|
SendTime: CommonUtil.GetCurrentTime(),
|
|
|
Content: videoName,
|
|
|
Size: videoSize,
|
|
|
Base64: thumbBase64,
|
|
|
Url: videoUrl,
|
|
|
MessageType: objectName,
|
|
|
ChatType: sendType,
|
|
|
}
|
|
|
} else {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "objectName参数错误!"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
bodyJsonObj, _ := json.Marshal(crs)
|
|
|
bodyString := string(bodyJsonObj)
|
|
|
saveErr := ImRelateDao.SaveChatRecord("chat_record", bodyString)
|
|
|
if saveErr != nil {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "聊天记录保存失败!"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取人员头像
|
|
|
作者:吴缤
|
|
|
日期:2021-08-23
|
|
|
*/
|
|
|
func GetPersonAvatar(c *gin.Context) {
|
|
|
var personAvatar []map[string]string
|
|
|
personIds := c.PostForm("personIds")
|
|
|
personIdArr := strings.Split(personIds, ",")
|
|
|
//获取是云版还是局版
|
|
|
serverLocation := ImRelateDao.GetServerLocation()
|
|
|
for _, val := range personIdArr {
|
|
|
id := val + "_5"
|
|
|
avatar := ImRelateDao.GetPersonAvatarByUserId(id, serverLocation)
|
|
|
myMap := map[string]string{val: avatar}
|
|
|
personAvatar = append(personAvatar, myMap)
|
|
|
}
|
|
|
josnByte, _ := json.Marshal(personAvatar)
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "list": CommonUtil.ConvertJsonStringToMapArray(string(josnByte))})
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取人员信息列表
|
|
|
作者:吴缤
|
|
|
日期:2021-09-06
|
|
|
*/
|
|
|
func GetPersonInfoList(c *gin.Context) {
|
|
|
bureauId := c.Query("bureau_id")
|
|
|
orgId := c.Query("org_id")
|
|
|
queryChild := c.Query("query_child")
|
|
|
bUse := c.Query("b_use")
|
|
|
personName := c.Query("person_name")
|
|
|
queryBureauChild := c.Query("query_bureau_child")
|
|
|
pageNumber := c.Query("pageNumber")
|
|
|
pageSize := c.Query("pageSize")
|
|
|
|
|
|
res, err := ImRelateDao.GetPersonList(bureauId, orgId, queryChild, bUse, personName, queryBureauChild, pageNumber, pageSize)
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "获取人员信息列表失败!"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
jsonObj, _ := CommonUtil.JsonStringToMap(res)
|
|
|
|
|
|
c.JSON(http.StatusOK, jsonObj)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:向融云同步用户
|
|
|
作者:吴缤
|
|
|
日期:2021-09-07
|
|
|
*/
|
|
|
func SyncRongYunUser(c *gin.Context) {
|
|
|
//用户ID。
|
|
|
personId := c.PostForm("personId")
|
|
|
personName := c.PostForm("personName")
|
|
|
identityId := c.PostForm("identityId")
|
|
|
|
|
|
_, err := ImRelateDao.RongYunGetToken(personId, identityId, personName, "")
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "向融云同步用户失败!"})
|
|
|
return
|
|
|
}
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "向融云同步用户成功!"})
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:创建群组
|
|
|
作者:吴缤
|
|
|
日期:2021-08-23
|
|
|
*/
|
|
|
func CreateGroup(c *gin.Context) {
|
|
|
//群组名称
|
|
|
groupName := c.PostForm("group_name")
|
|
|
//人员列表
|
|
|
personList := c.PostForm("person_list")
|
|
|
|
|
|
personIdCookie, _ := c.Cookie("person_id")
|
|
|
identityIdCookie, _ := c.Cookie("identity_id")
|
|
|
tokenCookie, _ := c.Cookie("token")
|
|
|
qAccessTokenCookie, _ := c.Cookie("q_access_token")
|
|
|
|
|
|
groupId, err := ImRelateDao.SaveGroup(groupName, personIdCookie, identityIdCookie, tokenCookie, qAccessTokenCookie)
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": err.Error()})
|
|
|
return
|
|
|
}
|
|
|
err = ImRelateDao.AddGroupMember(groupId, personList, personIdCookie, identityIdCookie, tokenCookie, qAccessTokenCookie)
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "调用云平台的增加群组成员接口失败!"})
|
|
|
return
|
|
|
}
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "成功!"})
|
|
|
}
|