初始
This commit is contained in:
350
internal/app/system/logic/qianqiCamera/qianqi_camera.go
Normal file
350
internal/app/system/logic/qianqiCamera/qianqi_camera.go
Normal file
@ -0,0 +1,350 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-30 22:37:34
|
||||
// 生成路径: internal/app/system/logic/qianqi_camera.go
|
||||
// 生成人:gfast
|
||||
// desc:摄像头
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon/camera"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/shp"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/api/wxApplet/wxApplet"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterQianqiCamera(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiCamera {
|
||||
return &sQianqiCamera{}
|
||||
}
|
||||
|
||||
type sQianqiCamera struct{}
|
||||
|
||||
func (s *sQianqiCamera) NotPageList(ctx context.Context, req *wxApplet.QianqiCameraSearchReq) (listRes *wxApplet.QianqiCameraSearchRes, err error) {
|
||||
listRes = new(wxApplet.QianqiCameraSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiCamera.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.CameraName != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CameraName+" like ?", "%"+req.CameraName+"%")
|
||||
}
|
||||
if req.CameraCode != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CameraCode+" = ?", req.CameraCode)
|
||||
}
|
||||
if req.Detail != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Detail+" = ?", req.Detail)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Status+" = ?", gconv.Int(req.Status))
|
||||
}
|
||||
if req.CreateddAt != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CreateddAt+" = ?", gconv.Time(req.CreateddAt))
|
||||
}
|
||||
if req.SourceType != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().SourceType+" = ?", req.SourceType)
|
||||
}
|
||||
if req.Serial != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Serial+" = ?", req.Serial)
|
||||
}
|
||||
if req.Code != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Code+" = ?", req.Code)
|
||||
}
|
||||
order := "id desc"
|
||||
var res []*model.QianqiCameraInfoRes
|
||||
err = m.Fields(system.QianqiCameraSearchRes{}).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiCameraListRes, len(res))
|
||||
for k, v := range res {
|
||||
//坐标转换
|
||||
dt := shp.Detail{}
|
||||
err = json.Unmarshal([]byte(v.Detail), &dt)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
}
|
||||
dt.Position.Lng, dt.Position.Lat = coryCommon.WGS84toGCJ02(dt.Position.Lng, dt.Position.Lat)
|
||||
marshal, _ := json.Marshal(dt)
|
||||
listRes.List[k] = &model.QianqiCameraListRes{
|
||||
Id: v.Id,
|
||||
CameraName: v.CameraName,
|
||||
CameraCode: v.CameraCode,
|
||||
Detail: string(marshal),
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
Poster: v.Poster,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreateddAt: v.CreateddAt,
|
||||
SourceType: v.SourceType,
|
||||
Serial: v.Serial,
|
||||
Code: v.Code,
|
||||
Flv: v.Flv,
|
||||
Hls: v.Hls,
|
||||
Share: v.Share,
|
||||
Rtc: v.Rtc,
|
||||
Degree: v.Degree,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) EditCameraFunc(ctx context.Context, req *system.EditCameraReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
ip, _ := g.Cfg().Get(ctx, "LiveGBS.safety.ip")
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).WherePri(req.Id).Update(do.QianqiCamera{
|
||||
CameraName: req.CameraName,
|
||||
Serial: req.Serial,
|
||||
Code: req.Code,
|
||||
Flv: "http://" + ip.String() + ":10000/sms/34020000002020000001/flv/hls/" + getkey(req.Serial, req.Code) + ".flv",
|
||||
Hls: "http://" + ip.String() + ":10000/sms/34020000002020000001/hls/" + getkey(req.Serial, req.Code) + "/live.m3u8",
|
||||
Share: "http://" + ip.String() + ":10000/play.html?serial=" + req.Serial + "&code=" + req.Code,
|
||||
Rtc: "webrtc://" + ip.String() + ":10000/sms/34020000002020000001/rtc/" + getkey(req.Serial, req.Code),
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) EditNameAndDetail(ctx context.Context, req *system.QianqiCameraEditNameAndDetailReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
marshal, err := json.Marshal(req.Detail)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).Where(dao.QianqiCamera.Columns().CameraCode, req.CameraCode).Update(
|
||||
g.Map{
|
||||
"camera_name": req.CameraName,
|
||||
"detail": string(marshal),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) WxEditNameAndDetail(ctx context.Context, req *system.QianqiCameraEditNameAndDetailReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
req.Detail.Position.Lng, req.Detail.Position.Lat = coryCommon.GCJ02toWGS84(req.Detail.Position.Lng, req.Detail.Position.Lat)
|
||||
marshal, err := json.Marshal(req.Detail)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).Where(dao.QianqiCamera.Columns().CameraCode, req.CameraCode).Update(
|
||||
g.Map{
|
||||
"camera_name": req.CameraName,
|
||||
"detail": string(marshal),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) List(ctx context.Context, req *system.QianqiCameraSearchReq) (listRes *system.QianqiCameraSearchRes, err error) {
|
||||
listRes = new(system.QianqiCameraSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiCamera.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.CameraName != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CameraName+" like ?", "%"+req.CameraName+"%")
|
||||
}
|
||||
if req.CameraCode != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CameraCode+" = ?", req.CameraCode)
|
||||
}
|
||||
if req.Detail != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Detail+" = ?", req.Detail)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Status+" = ?", gconv.Int(req.Status))
|
||||
}
|
||||
if req.Poster != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Poster+" = ?", req.Poster)
|
||||
}
|
||||
if req.CreateBy != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CreateBy+" = ?", req.CreateBy)
|
||||
}
|
||||
if req.UpdateBy != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().UpdateBy+" = ?", req.UpdateBy)
|
||||
}
|
||||
if req.CreateddAt != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().CreateddAt+" = ?", gconv.Time(req.CreateddAt))
|
||||
}
|
||||
if req.SourceType != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().SourceType+" = ?", req.SourceType)
|
||||
}
|
||||
if req.Serial != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Serial+" = ?", req.Serial)
|
||||
}
|
||||
if req.Code != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Code+" = ?", req.Code)
|
||||
}
|
||||
if req.Flv != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Flv+" = ?", req.Flv)
|
||||
}
|
||||
if req.Hls != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Hls+" = ?", req.Hls)
|
||||
}
|
||||
if req.Share != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Share+" = ?", req.Share)
|
||||
}
|
||||
if req.Rtc != "" {
|
||||
m = m.Where(dao.QianqiCamera.Columns().Rtc+" = ?", req.Rtc)
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.QianqiCameraInfoRes
|
||||
err = m.Fields(system.QianqiCameraSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiCameraListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiCameraListRes{
|
||||
Id: v.Id,
|
||||
CameraName: v.CameraName,
|
||||
CameraCode: v.CameraCode,
|
||||
Detail: v.Detail,
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
Poster: v.Poster,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreateddAt: v.CreateddAt,
|
||||
SourceType: v.SourceType,
|
||||
Serial: v.Serial,
|
||||
Code: v.Code,
|
||||
Flv: v.Flv,
|
||||
Hls: v.Hls,
|
||||
Share: v.Share,
|
||||
Rtc: v.Rtc,
|
||||
Degree: v.Degree,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) GetById(ctx context.Context, id int) (res *model.QianqiCameraInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiCamera.Ctx(ctx).WithAll().Where(dao.QianqiCamera.Columns().Id, id).Scan(&res)
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.QianqiCameraInfoRes)
|
||||
res = &infoRes
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) Add(ctx context.Context, req *system.QianqiCameraAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
dt := shp.Detail{}
|
||||
dt.Position.Lng = 106.54975946463013
|
||||
dt.Position.Lat = 23.467636909544247
|
||||
marshal, err := json.Marshal(dt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).Insert(do.QianqiCamera{
|
||||
CameraName: req.CameraName,
|
||||
CameraCode: gmd5.MustEncryptString(req.Serial + req.Code),
|
||||
Detail: string(marshal),
|
||||
ProjectId: req.ProjectId,
|
||||
Serial: req.Serial,
|
||||
Code: req.Code,
|
||||
Flv: "http://119.45.210.154:10000/sms/34020000002020000001/flv/hls/" + getkey(req.Serial, req.Code) + ".flv",
|
||||
Hls: "http://119.45.210.154:10000/sms/34020000002020000001/hls/" + getkey(req.Serial, req.Code) + "/live.m3u8",
|
||||
Share: "http://119.45.210.154:10000/play.html?serial=" + req.Serial + "&code=" + req.Code,
|
||||
Rtc: "webrtc://119.45.210.154:10000/sms/34020000002020000001/rtc/" + getkey(req.Serial, req.Code),
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func getkey(serial, code string) string {
|
||||
return serial + "_" + code
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) Edit(ctx context.Context, req *system.QianqiCameraEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
marshal, err := json.Marshal(req.Degree)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).WherePri(req.Id).Update(do.QianqiCamera{
|
||||
Degree: string(marshal),
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiCamera) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiCamera.Ctx(ctx).Delete(dao.QianqiCamera.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// PeriodicCameraSnapshotFunc 获取摄像的通道,然后进行快照(安全帽)
|
||||
func (s *sQianqiCamera) PeriodicCameraSnapshotFunc(ctx context.Context) {
|
||||
//1、获取所有摄像头的通道id
|
||||
var entity []*model.QianqiCameraListRes
|
||||
_ = dao.QianqiCamera.Ctx(ctx).WithAll().Where("status", "1").Scan(&entity)
|
||||
if len(entity) > 0 {
|
||||
fmt.Println("开始快照-安全帽")
|
||||
for _, data := range entity {
|
||||
int64Str, _ := strconv.ParseInt(data.ProjectId, 10, 64)
|
||||
//获取预制点位
|
||||
//array, _ := dao.BusPresettingBit.Ctx(ctx).Where("camera_id", data.Id).Fields("preset").Array()
|
||||
//var arr []int
|
||||
//for _, ay := range array {
|
||||
// arr = append(arr, ay.Int())
|
||||
//}
|
||||
go camera.ChannelSnapFunc(ctx, data.Id, data.Serial, data.Code, int64Str)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user