update
continuous-integration/drone/push Build is passing Details

master
kgdxpr 4 years ago
parent 808219bebb
commit 36c27842de

@ -5,8 +5,7 @@
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateController/ImRelateController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/ImRelate/ImRelateDao/ImRelateDao.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Config/Config.ini" beforeDir="false" afterPath="$PROJECT_DIR$/Config/Config.ini" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Utils/RedisUtil/RedisUtil.go" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/RedisUtil/RedisUtil.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/ConfigUtil/ConfigUtil.go" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ConfigUtil/ConfigUtil.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

@ -2,6 +2,7 @@ package ImRelateController
import ( import (
"dsSzxy/Business/ImRelate/ImRelateDao" "dsSzxy/Business/ImRelate/ImRelateDao"
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil" "dsSzxy/Utils/ConfigUtil"
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -14,7 +15,7 @@ func Routers(r *gin.RouterGroup) {
rr.POST("/sendTxtMsg", sendTxtMsg) rr.POST("/sendTxtMsg", sendTxtMsg)
rr.POST("/sendImgMsg", sendImgMsg) rr.POST("/sendImgMsg", sendImgMsg)
rr.POST("/sendFileMsg", sendFileMsg) rr.POST("/sendFileMsg", sendFileMsg)
rr.POST("/sendVideoMsg", sendVideoMsg) rr.POST("/sendSightMsg", sendSightMsg)
} }
/** /**
@ -42,7 +43,29 @@ func sendTxtMsg(c *gin.Context) {
return return
} }
cm := map[string]string{"name": "中华人民共和国1234", "country": "China", "age": "21", "date": "2021-08-17"} fromName := ImRelateDao.GetPersonNameByUserId(fromId)
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
var toName, toAvatar string
if sendType == "p" {
toName = ImRelateDao.GetPersonNameByUserId(toId)
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
} else
{
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
}
cm := map[string]string{
"sender_user_id": fromId,
"sender_user_name": fromName,
"sender_user_avatar": fromAvatar,
"receiver_user_id": toId,
"receiver_user_name": toName,
"receiver_user_avatar": toAvatar,
"send_time": CommonUtil.GetCurrentTime(),
"content": content,
"message_type": "TxtMsg",
"chat_type": sendType,
}
bodyJsonObj, _ := json.Marshal(cm) bodyJsonObj, _ := json.Marshal(cm)
bodyString := string(bodyJsonObj) bodyString := string(bodyJsonObj)
@ -72,7 +95,7 @@ func sendImgMsg(c *gin.Context) {
//imgUrl //imgUrl
imgUrl := c.PostForm("imgUrl") imgUrl := c.PostForm("imgUrl")
//文件名 //文件名
//fileName := c.PostForm("fileName") fileName := c.PostForm("fileName")
m := map[string]string{"content": imgBase64, "imageUri": imgUrl} m := map[string]string{"content": imgBase64, "imageUri": imgUrl}
contentJsonObj, _ := json.Marshal(m) contentJsonObj, _ := json.Marshal(m)
@ -84,6 +107,40 @@ func sendImgMsg(c *gin.Context) {
return return
} }
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
var toName, toAvatar string
if sendType == "p" {
toName = ImRelateDao.GetPersonNameByUserId(toId)
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
} else
{
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
}
cm := map[string]string{
"sender_user_id": fromId,
"sender_user_name": fromName,
"sender_user_avatar": fromAvatar,
"receiver_user_id": toId,
"receiver_user_name": toName,
"receiver_user_avatar": toAvatar,
"send_time": CommonUtil.GetCurrentTime(),
"content": fileName,
"base64": imgBase64,
"url": imgUrl,
"message_type": "ImgMsg",
"chat_type": sendType,
}
bodyJsonObj, _ := json.Marshal(cm)
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": "发送消息成功!"}) c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
} }
@ -118,6 +175,41 @@ func sendFileMsg(c *gin.Context) {
return return
} }
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
var toName, toAvatar string
if sendType == "p" {
toName = ImRelateDao.GetPersonNameByUserId(toId)
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
} else
{
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
}
cm := map[string]string{
"sender_user_id": fromId,
"sender_user_name": fromName,
"sender_user_avatar": fromAvatar,
"receiver_user_id": toId,
"receiver_user_name": toName,
"receiver_user_avatar": toAvatar,
"send_time": CommonUtil.GetCurrentTime(),
"content": fileName,
"size": fileSize,
"file_type": fileType,
"url": fileUrl,
"message_type": "FileMsg",
"chat_type": sendType,
}
bodyJsonObj, _ := json.Marshal(cm)
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": "发送消息成功!"}) c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
} }
@ -126,7 +218,7 @@ func sendFileMsg(c *gin.Context) {
2021-08-16 2021-08-16
*/ */
func sendVideoMsg(c *gin.Context) { func sendSightMsg(c *gin.Context) {
//发送方Id。 //发送方Id。
fromId := c.PostForm("fromId") fromId := c.PostForm("fromId")
//接收方Id。 //接收方Id。
@ -140,17 +232,52 @@ func sendVideoMsg(c *gin.Context) {
//视频大小 //视频大小
videoSize := c.PostForm("videoSize") videoSize := c.PostForm("videoSize")
//视频名称 //视频名称
fileName := c.PostForm("fileName") videoName := c.PostForm("fileName")
m := map[string]string{"sightUrl": videoUrl, "content": thumbBase64, "duration": "60", "size": videoSize, "name": fileName} m := map[string]string{"sightUrl": videoUrl, "content": thumbBase64, "duration": "60", "size": videoSize, "name": videoName}
contentJsonObj, _ := json.Marshal(m) contentJsonObj, _ := json.Marshal(m)
contentJsonStr := string(contentJsonObj) contentJsonStr := string(contentJsonObj)
err := ImRelateDao.SendRongYunMsg(sendType, fromId, toId, "RC:FileMsg", contentJsonStr) err := ImRelateDao.SendRongYunMsg(sendType, fromId, toId, "RC:SightMsg", contentJsonStr)
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "info": "发送消息失败!"}) c.JSON(http.StatusOK, gin.H{"success": false, "info": "发送消息失败!"})
return return
} }
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
var toName, toAvatar string
if sendType == "p" {
toName = ImRelateDao.GetPersonNameByUserId(toId)
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
} else
{
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
}
cm := map[string]string{
"sender_user_id": fromId,
"sender_user_name": fromName,
"sender_user_avatar": fromAvatar,
"receiver_user_id": toId,
"receiver_user_name": toName,
"receiver_user_avatar": toAvatar,
"send_time": CommonUtil.GetCurrentTime(),
"content": videoName,
"size": videoSize,
"base64": thumbBase64,
"url": videoUrl,
"message_type": "SightMsg",
"chat_type": sendType,
}
bodyJsonObj, _ := json.Marshal(cm)
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": "发送消息成功!"}) c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
} }

@ -3,10 +3,13 @@ package ImRelateDao
import ( import (
"dsSzxy/Utils/CommonUtil" "dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil" "dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"dsSzxy/Utils/EsUtil" "dsSzxy/Utils/EsUtil"
"dsSzxy/Utils/RedisUtil"
ssdb "dsSzxy/Utils/SsdbUtil" ssdb "dsSzxy/Utils/SsdbUtil"
"errors" "errors"
"fmt" "fmt"
"github.com/xormplus/xorm"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -40,8 +43,86 @@ func GetPersonAvatar(personId string, identityId string, w string, h string) str
return avatar return avatar
} }
/**
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 { func GetPersonName(personId string, identityId string) string {
return "" 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
} }
/** /**
@ -131,3 +212,56 @@ func SaveChatRecord(indexName string, bodyString string) error {
} }
return nil return nil
} }
/**
userIdIDID
2021-08-17
*/
func GetPersonIdIdentityId(userId string) (string, string) {
s := strings.Split(userId, "_")
return s[0], s[1]
}
/**
groupIdID
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, "36", "36")
return avatar
}
/**
groupId
2021-08-17
*/
func GetGroupNameAvatarByGroupId(groupId string) (string, string) {
gId := GetGroupId(groupId)
groupName, groupAvatar := GetGroupNameAvatar(gId, "36", "36")
return groupName, groupAvatar
}

@ -47,7 +47,7 @@ func HMGETALL(key string) map[string]string {
return resMap return resMap
} }
func HMGET(key string, fields []string) []interface{} { func HMGET(key string, fields []string) ([]interface{},error) {
resMap, _ := RedisClient.HMGet(key, fields...).Result() resMap, err := RedisClient.HMGet(key, fields...).Result()
return resMap return resMap,err
} }

Loading…
Cancel
Save