代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。