mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[fix]代码生成器
This commit is contained in:
@@ -155,7 +155,7 @@ func (g *Generator) Generate() (entity.DevGenTable, error) {
|
||||
var column entity.DevGenTableColumn
|
||||
column.ColumnComment = dbColumn[y].ColumnComment
|
||||
column.ColumnName = dbColumn[y].ColumnName
|
||||
column.ColumnType = dbColumn[y].ColumnType
|
||||
column.ColumnType = dbColumn[y].DataType
|
||||
column.Sort = y + 1
|
||||
column.IsPk = "0"
|
||||
|
||||
@@ -361,7 +361,7 @@ func GenCode(tableId int64) {
|
||||
t1, err := template.ParseFiles("resource/template/go/entity.template")
|
||||
biz.ErrIsNil(err, "entity模版读取失败!")
|
||||
|
||||
t2, err := template.ParseFiles("resource/template/go/services.template")
|
||||
t2, err := template.ParseFiles("resource/template/go/service.template")
|
||||
biz.ErrIsNil(err, "service模版读取失败!")
|
||||
|
||||
t3, err := template.ParseFiles("resource/template/go/api.template")
|
||||
|
||||
@@ -182,11 +182,15 @@ func SetDeviceShadow(etoken *model.DeviceAuth, msgVals map[string]interface{}, m
|
||||
for key, value := range msgVals {
|
||||
if message.AttributesMes == msgType {
|
||||
err := shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslAttributesType, key, value)
|
||||
biz.ErrIsNilAppendErr(err, "设置设备影子点失败")
|
||||
if err != nil {
|
||||
global.Log.Error("设置设备影子点失败", err)
|
||||
}
|
||||
}
|
||||
if message.TelemetryMes == msgType {
|
||||
err := shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, key, value)
|
||||
biz.ErrIsNilAppendErr(err, "设置设备影子点失败")
|
||||
if err != nil {
|
||||
global.Log.Error("设置设备影子点失败", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package ys
|
||||
|
||||
import (
|
||||
"pandax/pkg/tool"
|
||||
)
|
||||
|
||||
const (
|
||||
//设备列表
|
||||
DEVICELIST = "https://open.ys7.com/api/lapp/device/list"
|
||||
//获取指定设备的通道信息
|
||||
DEVICECHANNELLIST = "https://open.ys7.com/api/lapp/device/camera/list"
|
||||
// 获取播放地址
|
||||
DEVICELIVEADDRESS = "https://open.ys7.com/api/lapp/v2/live/address/get"
|
||||
)
|
||||
|
||||
// GetDeviceList 获取设备列表
|
||||
func (ys *Ys) GetDeviceList(pageNum, pageSize int) (devices []Device, total int64, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["pageStart"] = pageNum
|
||||
params["pageSize"] = pageSize
|
||||
status, err := ys.authorizeRequset("POST", DEVICELIST, params, &devices) //获取用户下的设备列表
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var page = Page{}
|
||||
err = tool.InterfaceToStruct(status.Page, &page)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return devices, int64(page.Total), nil
|
||||
}
|
||||
|
||||
// GetDeviceChannelList 获取指定设备的通道信息
|
||||
func (ys *Ys) GetDeviceChannelList(deviceSerial string) (cameras []Channel, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["deviceSerial"] = deviceSerial
|
||||
_, err = ys.authorizeRequset("POST", DEVICECHANNELLIST, params, &cameras)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cameras, nil
|
||||
}
|
||||
|
||||
// GetDeviceLiveAddress 获取指定设备通道的播放地址
|
||||
func (ys *Ys) GetDeviceLiveAddress(deviceSerial string, channelNo int) (live []LiveAddress, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["deviceSerial"] = deviceSerial
|
||||
params["channelNo"] = channelNo
|
||||
params["protocol"] = 4 //流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
|
||||
params["type"] = "1" //地址的类型,1-预览,2-本地录像回放,3-云存储录像回放,非必选,默认为1;回放仅支持rtmp、ezopen、flv协议
|
||||
params["quality"] = 1 //视频清晰度,1-高清(主码流)、2-流畅(子码流)
|
||||
_, err = ys.authorizeRequset("POST", DEVICELIVEADDRESS, params, &live)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return live, nil
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package ys
|
||||
|
||||
const (
|
||||
//云台控制开始
|
||||
URLPTZSTAR = "https://open.ys7.com/api/lapp/device/ptz/start"
|
||||
//云台控制结束
|
||||
URLPTZSTOP = "https://open.ys7.com/api/lapp/device/ptz/stop"
|
||||
)
|
||||
|
||||
// StartPtz 开始云台控制
|
||||
func (ys *Ys) StartPtz(deviceSerial string, channelNo, direction, speed int) (err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["deviceSerial"] = deviceSerial
|
||||
params["channelNo"] = channelNo
|
||||
params["direction"] = direction
|
||||
params["speed"] = speed
|
||||
|
||||
_, err = ys.authorizeRequset("POST", URLPTZSTAR, params, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopPtz 停止云台转动
|
||||
func (ys *Ys) StopPtz(deviceSerial string, channelNo, direction int) (err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["deviceSerial"] = deviceSerial
|
||||
params["channelNo"] = channelNo
|
||||
params["direction"] = direction
|
||||
|
||||
_, err = ys.authorizeRequset("POST", URLPTZSTOP, params, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package ys
|
||||
|
||||
type AccessToken struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
ExpireTime int64 `json:"expireTime"`
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
Page interface{} `json:"page"`
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
Total float64 `json:"total"`
|
||||
Page float64 `json:"page"`
|
||||
Size float64 `json:"size"`
|
||||
}
|
||||
|
||||
// Device 萤石设备数据结构
|
||||
type Device struct {
|
||||
DeviceSerial string `json:"deviceSerial"`
|
||||
DeviceName string `json:"deviceName"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
Status int `json:"status"`
|
||||
Defence int `json:"defence"`
|
||||
DeviceVersion string `json:"deviceVersion"`
|
||||
NetAddress string `json:"netAddress"`
|
||||
}
|
||||
|
||||
// Channel 萤石摄像头通道数据结构
|
||||
type Channel struct {
|
||||
DeviceSerial string `json:"deviceSerial"`
|
||||
IpcSerial string `json:"ipcSerial"`
|
||||
ChannelNo int `json:"channelNo"`
|
||||
ChannelName string `json:"channelName"`
|
||||
PicURL string `json:"picUrl"`
|
||||
IsShared string `json:"isShared"`
|
||||
VideoLevel int `json:"videoLevel"`
|
||||
IsEncrypt int `json:"isEncrypt"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// LiveAddress 播放地址
|
||||
type LiveAddress struct {
|
||||
Id string `json:"id"`
|
||||
Url string `json:"url"`
|
||||
ExpireTime string `json:"expireTime"`
|
||||
}
|
||||
107
pkg/ys/ys.go
107
pkg/ys/ys.go
@@ -1,107 +0,0 @@
|
||||
package ys
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"pandax/kit/httpclient"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
MASTERACC = 0 //主账号
|
||||
RAMACC = 1 //子账号
|
||||
//[用户]获取accessToken
|
||||
ACCESSTOKEN = "https://open.ys7.com/api/lapp/token/get"
|
||||
RAMTOKENGET = "https://open.ys7.com/api/lapp/ram/token/get" //获取子账户AccessToken
|
||||
)
|
||||
|
||||
type Ys struct {
|
||||
AppKey string
|
||||
Secret string
|
||||
IsRAM int
|
||||
AccountID string
|
||||
AccessToken string
|
||||
ExpireTime int64
|
||||
}
|
||||
|
||||
func (ys *Ys) GetAccessToken() error {
|
||||
params := make(map[string]interface{})
|
||||
params["appKey"] = ys.AppKey
|
||||
params["appSecret"] = ys.Secret
|
||||
ac := &AccessToken{}
|
||||
_, err := ys.requset("POST", ACCESSTOKEN, params, ac)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ys.IsRAM == MASTERACC {
|
||||
ys.AccessToken = ac.AccessToken
|
||||
ys.ExpireTime = ac.ExpireTime
|
||||
} else {
|
||||
ys.AccessToken = ac.AccessToken
|
||||
ac, err = ys.RAMGetAccessToken(ys.AccountID)
|
||||
if err != nil {
|
||||
ys.AccessToken = ""
|
||||
return err
|
||||
}
|
||||
ys.AccessToken = ac.AccessToken
|
||||
ys.ExpireTime = ac.ExpireTime
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RAMGetAccessToken 获取B模式子账户accessToken
|
||||
func (ys *Ys) RAMGetAccessToken(accountID string) (ac *AccessToken, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["accountId"] = accountID
|
||||
params["accessToken"] = ys.AccessToken
|
||||
ac = &AccessToken{}
|
||||
_, err = ys.requset("POST", RAMTOKENGET, params, ac)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Println(*ac)
|
||||
return ac, nil
|
||||
}
|
||||
|
||||
func (ys *Ys) requset(method, url string, params map[string]interface{}, data interface{}) (status *Status, err error) {
|
||||
defer func() {
|
||||
if Rerr := recover(); Rerr != nil {
|
||||
err = errors.New("recover error")
|
||||
return
|
||||
}
|
||||
}()
|
||||
ps := make([]string, 0)
|
||||
for k, v := range params {
|
||||
ps = append(ps, fmt.Sprintf("%s=%v", k, v))
|
||||
}
|
||||
status = &Status{
|
||||
Data: data,
|
||||
}
|
||||
err = httpclient.NewRequest(url).Timeout(60).PostParams(strings.Join(ps, "&")).BodyToObj(status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if status.Code != "200" {
|
||||
return status, errors.New(status.Msg)
|
||||
}
|
||||
return status, nil
|
||||
}
|
||||
|
||||
func (ys *Ys) authorizeRequset(method, url string, params map[string]interface{}, data interface{}) (status *Status, err error) {
|
||||
exTime := time.Unix(ys.ExpireTime/1000, 0)
|
||||
if exTime.Unix() < time.Now().Unix() {
|
||||
ys.GetAccessToken()
|
||||
}
|
||||
defer func() {
|
||||
if Rerr := recover(); Rerr != nil {
|
||||
err = errors.New("recover error")
|
||||
return
|
||||
}
|
||||
}()
|
||||
params["accessToken"] = ys.AccessToken
|
||||
status, err = ys.requset(method, url, params, data)
|
||||
return
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package ys
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestYs_GetDeviceList(t *testing.T) {
|
||||
ys := &Ys{
|
||||
AppKey: "",
|
||||
Secret: "",
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
devices, total, err := ys.GetDeviceList(0, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(devices)
|
||||
t.Log(total)
|
||||
}
|
||||
|
||||
func TestYs_GetDeviceChannelList(t *testing.T) {
|
||||
ys := &Ys{
|
||||
AppKey: "",
|
||||
Secret: "",
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
chans, err := ys.GetDeviceChannelList("BA1996108")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(chans)
|
||||
}
|
||||
|
||||
func TestYs_GetDeviceDeviceLiveAddress(t *testing.T) {
|
||||
ys := &Ys{
|
||||
AppKey: "",
|
||||
Secret: "",
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
live, err := ys.GetDeviceLiveAddress("BA1996108", 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(live)
|
||||
}
|
||||
@@ -7,11 +7,11 @@ package api
|
||||
import (
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
"strings"
|
||||
|
||||
"pandax/apps/{{.PackageName}}/entity"
|
||||
"pandax/apps/{{.PackageName}}/services"
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/utils"
|
||||
)
|
||||
|
||||
type {{.ClassName}}Api struct {
|
||||
@@ -61,7 +61,7 @@ func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
var data entity.{{.ClassName}}
|
||||
restfulx.BindQuery(rc, &data)
|
||||
|
||||
err := p.{{.ClassName}}App.Insert(data)
|
||||
_,err := p.{{.ClassName}}App.Insert(data)
|
||||
biz.ErrIsNil(err, "添加{{.TableComment}}失败")
|
||||
}
|
||||
|
||||
@@ -84,4 +84,4 @@ func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
||||
{{- end }}
|
||||
biz.ErrIsNil(p.{{.ClassName}}App.Delete({{.PkJsonField}}s), "删除{{.TableComment}}失败")
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ type (
|
||||
FindOne({{.PkJsonField}} {{.PkGoType}}) (*entity.{{.ClassName}},error)
|
||||
FindListPage(page, pageSize int, data entity.{{.ClassName}}) (*[]entity.{{.ClassName}}, int64, error)
|
||||
FindList(data entity.{{ .ClassName }}) (*[]entity.{{.ClassName}},error)
|
||||
Update(data entity.{{.ClassName}}) (*entity.{{.ClassName}},error)
|
||||
Update(data entity.{{.ClassName}}) error
|
||||
Delete({{.PkJsonField}}s []{{.PkGoType}}) error
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func (m *{{.BusinessName}}ModelImpl) FindListPage(page, pageSize int, data entit
|
||||
if err != nil {
|
||||
return &list, total, err
|
||||
}
|
||||
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
return &list, total, err
|
||||
}
|
||||
|
||||
@@ -188,15 +188,14 @@ func (m *{{.BusinessName}}ModelImpl) FindList(data entity.{{$model}}) (*[]entity
|
||||
db.Preload("{{$column.LinkTableClass}}")
|
||||
{{- end -}}
|
||||
{{- end}}
|
||||
err := db.Order("create_time").Find(&list).Error
|
||||
err := db.Find(&list).Error
|
||||
return &list, err
|
||||
}
|
||||
|
||||
func (m *{{.BusinessName}}ModelImpl) Update(data entity.{{$model}}) (*entity.{{$model}}, error) {
|
||||
err := global.Db.Table(m.table).Updates(&data).Error
|
||||
return &data, err
|
||||
func (m *{{.BusinessName}}ModelImpl) Update(data entity.{{$model}}) error {
|
||||
return global.Db.Table(m.table).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (m *{{.BusinessName}}ModelImpl) Delete({{.PkJsonField}}s []{{.PkGoType}}) error {
|
||||
return global.Db.Table(m.table).Delete(&entity.{{$model}}{}, "{{.PkColumn}} in (?)", {{.PkJsonField}}s).Error
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ export function list{{.FunctionName}}(query:any) {
|
||||
}
|
||||
|
||||
// 查询{{.FunctionName}}详细
|
||||
export function get{{.FunctionName}}({{.PkJsonField}}:number) {
|
||||
export function get{{.FunctionName}}({{.PkJsonField}}:{{.PkGoType}}) {
|
||||
return request({
|
||||
url: '/{{.PackageName}}/{{.BusinessName}}/' + {{.PkJsonField}},
|
||||
method: 'get'
|
||||
@@ -36,7 +36,7 @@ export function update{{.FunctionName}}(data:any) {
|
||||
}
|
||||
|
||||
// 删除{{.FunctionName}}
|
||||
export function del{{.FunctionName}}({{.PkJsonField}}: string) {
|
||||
export function del{{.FunctionName}}({{.PkJsonField}}: {{.PkGoType}}) {
|
||||
return request({
|
||||
url: '/{{.PackageName}}/{{.BusinessName}}/' + {{.PkJsonField}},
|
||||
method: 'delete'
|
||||
|
||||
@@ -162,14 +162,18 @@ const onSubmit = () => {
|
||||
state.loading = true;
|
||||
if (state.ruleForm.{{.PkJsonField}} != undefined && state.ruleForm.{{.PkJsonField}} != 0) {
|
||||
update{{.FunctionName}}(state.ruleForm).then((response) => {
|
||||
ElMessage.success("修改成功");
|
||||
if (response.code == 200){
|
||||
ElMessage.success("修改成功");
|
||||
closeDialog(state.ruleForm); // 关闭弹窗
|
||||
}
|
||||
state.loading = false;
|
||||
closeDialog(state.ruleForm); // 关闭弹窗
|
||||
});
|
||||
} else {
|
||||
add{{.FunctionName}}(state.ruleForm).then((response) => {
|
||||
ElMessage.success("新增成功");
|
||||
closeDialog(state.ruleForm); // 关闭弹窗
|
||||
if (response.code == 200){
|
||||
ElMessage.success("新增成功");
|
||||
closeDialog(state.ruleForm); // 关闭弹窗
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -179,4 +183,4 @@ const onSubmit = () => {
|
||||
defineExpose({
|
||||
openDialog,
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
Reference in New Issue
Block a user