2 Star 0 Fork 0

江苏艾雨文承养老机器人有限公司/aywc_judge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ServiceCenterController.go 4.72 KB
一键复制 编辑 原始数据 按行查看 历史
dtal 提交于 2021-06-02 14:21 +08:00 . mtt0408--aywc_1 更改工作目录
package controllers
import (
"fmt"
"gitee.com/aywc_1/aywc_judge/src/configuration"
"gitee.com/aywc_1/aywc_judge/src/models"
"gitee.com/aywc_1/aywc_judge/src/services"
"gitee.com/aywc_1/aywc_judge/src/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/shenyisyn/goft-gin/goft"
log "github.com/sirupsen/logrus"
"io"
"os"
)
type ServiceCenterController struct {
Db *gorm.DB `inject:"-"`
ServiceCenterService *services.ServiceCenterService `inject:"-"`
}
func NewServiceCenterController() *ServiceCenterController {
return &ServiceCenterController{}
}
func (this *ServiceCenterController) Name() string {
return "ServiceCenterController"
}
/**
1、运维值班中心会有多个客服参与值班,当用户通过机器人端或者家属端呼叫值班中心时,值班中心需要提供一个音频连接的ID给机器人端/家属端,用户端发送ID号请求时,参数包括:
设备类型(机器人/家属端APP),设备或APP的ID,(机器人/家属端APP)的融云ID,请求时间,呼叫类型,保留字段。
*/
//func (this *ServiceCenterController) CallServiceCenter(ctx *gin.Context) goft.Json {
// sql:=fmt.Sprintf("select b.rc_id,b.user_id from msys_service_center a inner join sys_user b on a.service_id=b.user_id where a.service_status='1' and a.service_type='3' and b.status=1",deviceId)
// ret:=goft.SimpleQuery(sql).WithKey("data").Get()
// return ret
//}
func (this *ServiceCenterController) CallServiceCenter(ctx *gin.Context) goft.Json {
deviceId := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
messageType := ""
if messageType = ctx.Query("message_type"); messageType == "" {
panic(" params not find messageType")
}
center := this.ServiceCenterService.CallServiceCenter(deviceId, messageType)
ret := gin.H{"result": "success", "code": 200, "data": center}
return ret
}
func (this *ServiceCenterController) LoginServiceCenter(ctx *gin.Context) goft.Json {
form := &models.ServiceCenterModel{}
if err := ctx.BindJSON(&form); err == nil {
if form.ApplicationId == "" || form.ApplicationType == "" {
panic(fmt.Sprintf("param lack "))
}
user := this.ServiceCenterService.LoginServiceCenter(form.ApplicationId, form.ApplicationType)
ret := gin.H{"result": "success", "code": 200, "data": user}
return ret
} else {
log.Errorf("Failed err:%s\n", err.Error())
panic(fmt.Sprintf("Failed ,err:%s\n", err.Error()))
}
}
func (this *ServiceCenterController) UpdateDeviceUserInfo(ctx *gin.Context) goft.Json {
fileId, err := utils.GetID()
if err != nil {
log.Errorf("Failed to snowflake GetID,err:%s\n", err.Error())
panic(fmt.Sprintf("Failed to snowflake GetID,err:%s\n", err.Error()))
}
//https://my.oschina.net/u/3625745/blog/3055823
file, header, err := ctx.Request.FormFile("file")
if err != nil {
log.Errorf("Failed to get data,err:%s\n", err.Error())
panic(fmt.Sprintf("Failed to get data,err:%s\n", err.Error()))
}
defer file.Close()
value := ctx.Request.MultipartForm.Value
deviceName := ""
deviceId := ""
if _, ok := value["device_id"]; ok {
if str := value["device_id"][0]; len(str) > 50 {
deviceId = str[0:50]
} else {
deviceId = str
}
} else {
panic("param device_id is not found ")
}
if _, ok := value["device_name"]; ok {
if str := value["device_name"][0]; len(str) > 255 {
deviceName = str[0:255]
} else {
deviceName = str
}
} else {
panic("param device_name is not found ")
}
headPath := configuration.GetYamlValue([]string{"config", "head_picture_path"}, 0, "/mydata/head_picture/").(string)
headWebPath := configuration.GetYamlValue([]string{"config", "head_picture_web_path"}, 0, "").(string)
filePath := headPath + fileId + "_" + header.Filename
httpPath := headWebPath + fileId + "_" + header.Filename
newFile, err := os.Create(filePath)
if err != nil {
log.Errorf("Failed to create file,err:%s\n", err.Error())
panic(fmt.Sprintf("Failed to create file,err:%s\n", err.Error()))
}
deviceUserModel := &models.DeviceUserModel{
Id: fileId,
DeviceName: deviceName,
DeviceId: deviceId,
HeadPicture: httpPath,
}
defer newFile.Close()
_, err = io.Copy(newFile, file)
if err != nil {
log.Errorf("Failed to save data into file,err:%s\n", err.Error())
panic(fmt.Sprintf("Failed to save data into file,err:%s\n", err.Error()))
}
err = this.ServiceCenterService.UpdateDeviceUserInfo(deviceUserModel)
ret := gin.H{"result": "success", "code": 200}
return ret
}
func (this *ServiceCenterController) Build(goft *goft.Goft) {
goft.
Handle("GET", "/callServiceCenter", this.CallServiceCenter).
Handle("POST", "/loginServiceCenter", this.LoginServiceCenter).
Handle("POST", "/updateDeviceUserInfo", this.UpdateDeviceUserInfo)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/aywc_1/aywc_judge.git
git@gitee.com:aywc_1/aywc_judge.git
aywc_1
aywc_judge
aywc_judge
v0.6.4

搜索帮助