This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,213 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-09-20 14:55:42
// 生成路径: internal/app/system/logic/bus_camera_channel.go
// 生成人gfast
// desc:摄像头(国标通道)
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"errors"
"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/system"
"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"
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
"strings"
)
func init() {
service.RegisterBusCameraChannel(New())
}
func New() *sBusCameraChannel {
return &sBusCameraChannel{}
}
type sBusCameraChannel struct{}
func (s *sBusCameraChannel) List(ctx context.Context, req *system.BusCameraChannelSearchReq) (listRes *system.BusCameraChannelSearchRes, err error) {
listRes = new(system.BusCameraChannelSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.BusCameraChannel.Ctx(ctx).WithAll()
m = m.Where(dao.BusCameraChannel.Columns().ProjectId+" = ?", req.ProjectId)
if req.CountryId != "" {
m = m.Where(dao.BusCameraChannel.Columns().CountryId, req.CountryId)
}
if req.ChannelName != "" {
m = m.Where(dao.BusCameraChannel.Columns().ChannelName+" like ?", "%"+req.ChannelName+"%")
}
if req.ChannelFormat != "" {
m = m.Where(dao.BusCameraChannel.Columns().ChannelFormat+" = ?", req.ChannelFormat)
}
if req.ChannelState != "" {
m = m.Where(dao.BusCameraChannel.Columns().ChannelState+" = ?", req.ChannelState)
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where(dao.BusCameraChannel.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where(dao.BusCameraChannel.Columns().CreatedAt+" >=? AND "+dao.BusCameraChannel.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
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.BusCameraChannelInfoRes
err = m.Fields(system.BusCameraChannelSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.BusCameraChannelListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.BusCameraChannelListRes{
Id: v.Id,
CountryId: v.CountryId,
ChannelNumber: v.ChannelNumber,
ChannelName: v.ChannelName,
ChannelPath: v.ChannelPath,
ChannelPathWs: v.ChannelPathWs,
ChannelPathRtc: v.ChannelPathRtc,
ChannelPathHls: v.ChannelPathHls,
ChannelFormat: v.ChannelFormat,
ChannelState: v.ChannelState,
SourceType: v.SourceType,
Remark: v.Remark,
CreatedAt: v.CreatedAt,
Detail: v.Detail,
Imei: v.Imei,
Iccid: v.Iccid,
}
}
})
return
}
func (s *sBusCameraChannel) GetById(ctx context.Context, id int64) (res *model.BusCameraChannelInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.BusCameraChannel.Ctx(ctx).WithAll().Where(dao.BusCameraChannel.Columns().Id, id).Scan(&res)
//获取创建人 更新人
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
infoRes := by.(model.BusCameraChannelInfoRes)
res = &infoRes
liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
func PJFunc(ctx context.Context, number string, channelFormat, channelNumber string) (path string, err error) {
path = number
//2、循环判断视频拼接的参数
statr := ""
end := ""
if channelFormat == "flv/hls" {
statr = "http"
end = ".flv"
} else if channelFormat == "ws-flv/hls" {
statr = "ws"
end = ".flv"
} else if channelFormat == "rtc" {
statr = "webrtc"
end = ""
} else if channelFormat == "hls" {
statr = "http"
end = "/live.m3u8"
} else {
err = errors.New("代码错误,请联系管理员!")
return
}
api, _ := g.Cfg().Get(ctx, "LiveGBS.safety.api")
sms, _ := g.Cfg().Get(ctx, "LiveGBS.safety.sms")
apiStr := api.String() + sms.String()
//2、拼接视频地址
path = strings.ReplaceAll(apiStr, "http", statr) + channelFormat + "/" + path + "_" + channelNumber + end
return
}
func (s *sBusCameraChannel) Add(ctx context.Context, req *system.BusCameraChannelAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//1、获取摄像头的国标
number, err := dao.BusCameraChineseStandard.Ctx(ctx).WherePri(req.CountryId).Fields(dao.BusCameraChineseStandard.Columns().CountryNumber).Value()
path1, err := PJFunc(ctx, number.String(), "flv/hls", req.ChannelNumber)
path2, err := PJFunc(ctx, number.String(), "ws-flv/hls", req.ChannelNumber)
path3, err := PJFunc(ctx, number.String(), "rtc", req.ChannelNumber)
path4, err := PJFunc(ctx, number.String(), "hls", req.ChannelNumber)
//2、新增
_, err = dao.BusCameraChannel.Ctx(ctx).Insert(do.BusCameraChannel{
CountryId: req.CountryId,
ProjectId: req.ProjectId,
ChannelNumber: req.ChannelNumber,
ChannelName: req.ChannelName,
ChannelPath: path1,
ChannelPathWs: path2,
ChannelPathRtc: path3,
ChannelPathHls: path4,
ChannelFormat: req.ChannelFormat,
Remark: req.Remark,
Imei: req.Imei,
Iccid: req.Iccid,
CreateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func (s *sBusCameraChannel) Edit(ctx context.Context, req *system.BusCameraChannelEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//1、获取摄像头的国标
number, err := dao.BusCameraChineseStandard.Ctx(ctx).WherePri(req.CountryId).Fields(dao.BusCameraChineseStandard.Columns().CountryNumber).Value()
path1, err := PJFunc(ctx, number.String(), "flv/hls", req.ChannelNumber)
path2, err := PJFunc(ctx, number.String(), "ws-flv/hls", req.ChannelNumber)
path3, err := PJFunc(ctx, number.String(), "rtc", req.ChannelNumber)
path4, err := PJFunc(ctx, number.String(), "hls", req.ChannelNumber)
//2、修改
_, err = dao.BusCameraChannel.Ctx(ctx).WherePri(req.Id).Update(do.BusCameraChannel{
CountryId: req.CountryId,
ProjectId: req.ProjectId,
ChannelNumber: req.ChannelNumber,
ChannelName: req.ChannelName,
ChannelPath: path1,
ChannelPathWs: path2,
ChannelPathRtc: path3,
ChannelPathHls: path4,
ChannelFormat: req.ChannelFormat,
ChannelState: req.ChannelState,
Remark: req.Remark,
Detail: req.Detail,
Imei: req.Imei,
Iccid: req.Iccid,
UpdateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sBusCameraChannel) Delete(ctx context.Context, ids []int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.BusCameraChannel.Ctx(ctx).Delete(dao.BusCameraChannel.Columns().Id+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}