2 Star 0 Fork 0

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DeviceWarmController.go 8.75 KB
一键复制 编辑 原始数据 按行查看 历史
dtal 提交于 2021-06-03 11:20 +08:00 . 视频聊吧接口8 返回值修改
package controllers
import (
"fmt"
"gitee.com/aywc_1/aywc_judge/src/configuration"
"gitee.com/aywc_1/aywc_judge/src/services"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/shenyisyn/goft-gin/goft"
log "github.com/sirupsen/logrus"
"io/ioutil"
"strconv"
)
type DeviceWarmController struct {
Db *gorm.DB `inject:"-"`
DeviceWarmService *services.DeviceWarmService `inject:"-"`
}
func NewDeviceWarmController() *DeviceWarmController {
return &DeviceWarmController{}
}
func (this *DeviceWarmController) Name() string {
return "DeviceWarmController"
}
func (this *DeviceWarmController) GetDeviceWarmList(ctx *gin.Context) goft.Json {
//return this.DeviceWarmService.GetDeviceWarmList()
sql := "select device_id, max(device_name) as device_name, max(create_time) as create_time,group_concat(concat(id,'_',upload_file_name) separator '###') as pictures,group_concat(distinct type separator '###') as type from device_warm where status=1 group by device_id order by create_time desc"
ret := goft.SimpleQuery(sql).WithKey("data").Get()
ret.(gin.H)["code"] = 200
return ret
}
func (this *DeviceWarmController) GetDeviceWarmHistory(ctx *gin.Context) goft.SimpleQuery {
return "select id,device_name,type,device_id,status,update_time,create_time,upload_file_name from device_warm where status>1 order by create_time desc"
}
func (this *DeviceWarmController) GetDeviceWarmHistory2(ctx *gin.Context) goft.Json {
sql := "select id,device_name,type,device_id,status,update_time,create_time,upload_file_name from device_warm where status>1 order by create_time desc"
ret := goft.SimpleQuery(sql).WithKey("result").Get() //map["result"]map[string]interface{}
ret.(gin.H)["code"] = 200
//return ret.(gin.H)["result"]
return ret
}
func (this *DeviceWarmController) GetDeviceWarmById(ctx *gin.Context) goft.Query {
return this.DeviceWarmService.GetDeviceWarmById(ctx.Param("id"))
}
func (this *DeviceWarmController) GetDeviceWarmExceptionPicture(ctx *gin.Context) string {
//ctx.Writer.Header().Set("Content-Type", "image/png")
id := ""
name := ""
result := ""
if id = ctx.Query("id"); id == "" {
panic("error params,not find id")
}
if name = ctx.Query("name"); name == "" {
panic("error params,not find name")
}
if result = ctx.Query("result"); result == "" {
panic("error params,not find result")
}
uploadPath := configuration.GetYamlValue([]string{"config", "upload_path"}, 0, "/mydata/go/upload").(string)
path := uploadPath + id + "_" + name
file, _ := ioutil.ReadFile(path)
fmt.Println(path)
return string(file)
}
func (this *DeviceWarmController) FindDeviceWarmByDeviceId(ctx *gin.Context) goft.Json {
if did := ctx.Query("did"); did != "" {
return gin.H{"result": this.DeviceWarmService.FindDeviceWarmByDeviceId(did)}
}
panic("error params,not find did")
}
/**
3,获取指定设备ID的视频聊吧相关信息接口,YYD上传数据:设备id,A55下发数据:设备id的名称,头像等
*/
func (this *DeviceWarmController) GetDeviceUserInfoByDeviceId(ctx *gin.Context) goft.Json {
deviceId := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
sql := fmt.Sprintf("select du.user_id,su.nickname,du.device_id,du.device_name,du.device_serial,du.head_picture from msys_device_user du left join sys_user su on du.user_id = su.user_id where du.status='1' and du.device_id= '%s'", deviceId)
ret := goft.SimpleQuery(sql).WithKey("data").Get() //map["result"]map[string]interface{}
ret.(gin.H)["code"] = 200
return ret
}
/**
4,通过设备ID添加好友接口,YYD上传数据:本地设备id,添加的设备id。A55下发数据:是否添加成功等
*/
func (this *DeviceWarmController) BindRelationShip(ctx *gin.Context) goft.Json {
deviceId := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
deviceIdBind := ""
if deviceIdBind = ctx.Query("device_id_bind"); deviceIdBind == "" {
panic(" params not find device_id_bind")
}
this.DeviceWarmService.BindRelationShip(deviceId, deviceIdBind)
return gin.H{"result": "success", "code": 200}
}
/**
5,获取其它所有设备的接口:YYD上传数据:本地设备id。A55下发数据:所有设备信息
*/
func (this *DeviceWarmController) GetDeviceUserList(ctx *gin.Context) goft.Json {
deviceId := ""
page := ""
limit := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
if page = ctx.Query("page"); page == "" {
page = "1"
}
if limit = ctx.Query("limit"); limit == "" {
limit = "10"
}
currentPage, err := strconv.Atoi(page)
if err != nil {
log.Errorf("Failed err:%s\n", err.Error())
panic(fmt.Sprintf("Failed ,err:%s\n", err.Error()))
}
pageSize := 0
pageSize, err = strconv.Atoi(limit)
if err != nil {
log.Errorf("Failed err:%s\n", err.Error())
panic(fmt.Sprintf("Failed ,err:%s\n", err.Error()))
}
start := (currentPage - 1) * pageSize
totalCount := this.DeviceWarmService.CountDeviceUserList()
sql := fmt.Sprintf("select du.user_id,su.nickname,du.device_id,du.device_name,du.device_serial,du.head_picture from msys_device_user du left join sys_user su on du.user_id = su.user_id where du.status='1' and du.device_id != '%s' limit %d,%d", deviceId, start, pageSize)
ret := goft.SimpleQuery(sql).WithKey("data").Get()
ret.(gin.H)["code"] = 200
ret.(gin.H)["totalCount"] = totalCount
ret.(gin.H)["pageSize"] = pageSize
totalPage := totalCount / pageSize
if totalCount%pageSize != 0 {
totalPage++
}
ret.(gin.H)["totalPage"] = totalPage
ret.(gin.H)["currPage"] = start
return ret
}
/**
6,获取该设备的通讯录列表接口:YYD上传数据:本地设备id,A55下发数据:该设备的所有好友信息(包括可以进行通讯的融云token等)
*/
func (this *DeviceWarmController) GetDeviceUserRelationShipList(ctx *gin.Context) goft.Json {
deviceId := ""
page := ""
limit := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
if page = ctx.Query("page"); page == "" {
page = "1"
}
if limit = ctx.Query("limit"); limit == "" {
limit = "10"
}
currentPage, err := strconv.Atoi(page)
if err != nil {
log.Errorf("Failed err:%s\n", err.Error())
panic(fmt.Sprintf("Failed ,err:%s\n", err.Error()))
}
pageSize := 0
pageSize, err = strconv.Atoi(limit)
if err != nil {
log.Errorf("Failed err:%s\n", err.Error())
panic(fmt.Sprintf("Failed ,err:%s\n", err.Error()))
}
start := (currentPage - 1) * pageSize
sql := fmt.Sprintf("select b.device_id,b.device_name,c.rc_token,d.nickname from (select rs_device_id from msys_device_user_relationship where device_id='%s' limit %d,%d) a inner join msys_device_user b on a.rs_device_id=b.device_id and b.status='1' inner join msys_rongcloud_account c on b.device_id=c.rc_id LEFT JOIN sys_user d ON b.user_id = d.user_id", deviceId, start, pageSize)
ret := goft.SimpleQuery(sql).WithKey("data").Get()
totalCount := this.DeviceWarmService.CountDeviceUserRelationShipList(deviceId)
ret.(gin.H)["code"] = 200
ret.(gin.H)["totalCount"] = totalCount
ret.(gin.H)["pageSize"] = pageSize
totalPage := totalCount / pageSize
if totalCount%pageSize != 0 {
totalPage++
}
ret.(gin.H)["totalPage"] = totalPage
ret.(gin.H)["currPage"] = start
return ret
}
/**
7,通过设备ID解绑好友接口,YYD上传数据:本地设备id,解绑的设备id。A55下发数据:是否添加成功等
*/
func (this *DeviceWarmController) UnbindRelationShip(ctx *gin.Context) goft.Json {
deviceId := ""
if deviceId = ctx.Query("device_id"); deviceId == "" {
panic(" params not find device_id")
}
deviceIdUnBind := ""
if deviceIdUnBind = ctx.Query("device_id_unbinding"); deviceIdUnBind == "" {
panic(" params not find device_id_unbinding")
}
var ret gin.H
/* defer func(ret gin.H) {
if err := recover(); err != nil {
ret =gin.H{"result":err,"code":500}
fmt.Println(ret)
}
return
}(ret)
*/
this.DeviceWarmService.UnBindRelationShip(deviceId, deviceIdUnBind)
ret = gin.H{"result": "success", "code": 200}
return ret
}
func (this *DeviceWarmController) Build(goft *goft.Goft) {
goft.
Handle("GET", "/deviceWarmList", this.GetDeviceWarmList).
Handle("GET", "/deviceWarmById/:id", this.GetDeviceWarmById).
Handle("GET", "/deviceWarmByDid", this.FindDeviceWarmByDeviceId).
Handle("GET", "/deviceWarmHistory", this.GetDeviceWarmHistory).
Handle("GET", "/deviceWarmHistory2", this.GetDeviceWarmHistory2).
Handle("GET", "/deviceWarmExceptionPicture", this.GetDeviceWarmExceptionPicture).
Handle("GET", "/getDeviceUserInfoByDeviceId", this.GetDeviceUserInfoByDeviceId).
Handle("GET", "/bindRelationShip", this.BindRelationShip).
Handle("POST", "/UnbindRelationShip", this.UnbindRelationShip).
Handle("GET", "/getDeviceUserList", this.GetDeviceUserList).
Handle("GET", "/getDeviceUserRelationShipList", this.GetDeviceUserRelationShipList)
}
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

搜索帮助