2023-07-18 17:19:03 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-31 18:20:00 +08:00
|
|
|
"time"
|
|
|
|
|
2023-08-01 17:08:45 +08:00
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
2023-07-18 17:19:03 +08:00
|
|
|
"joylink.club/bj-rtsts-server/db/dbquery"
|
|
|
|
"joylink.club/bj-rtsts-server/db/model"
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
2023-08-01 14:47:04 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/publishedGi"
|
2023-07-18 17:19:03 +08:00
|
|
|
)
|
|
|
|
|
2023-08-01 14:47:04 +08:00
|
|
|
func PageQueryPublishedGi(req *publishedGi.PublishedGiReqDto) *dto.PageDto {
|
|
|
|
where := dbquery.PublishedGi.Where()
|
2023-07-18 17:19:03 +08:00
|
|
|
if req.Name != "" {
|
2023-08-01 14:47:04 +08:00
|
|
|
where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name)))
|
|
|
|
}
|
|
|
|
result, count, err := where.Debug().FindByPage(req.Offset(), req.Size)
|
|
|
|
if err != nil {
|
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|
|
|
|
return &dto.PageDto{
|
|
|
|
Total: int(count),
|
|
|
|
PageQueryDto: req.PageQueryDto,
|
2023-08-01 14:47:04 +08:00
|
|
|
Records: publishedGi.ConvertFromSlice(result),
|
|
|
|
}
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|
|
|
|
|
2023-08-01 14:47:04 +08:00
|
|
|
func ListQueryPublishedGi(req *publishedGi.PublishedGiReqDto) []*publishedGi.PublishedGiDto {
|
2023-07-18 17:19:03 +08:00
|
|
|
where := dbquery.PublishedGi.Where()
|
|
|
|
if req.Name != "" {
|
|
|
|
where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name)))
|
|
|
|
}
|
2023-08-01 14:47:04 +08:00
|
|
|
find, err := where.Debug().Find()
|
|
|
|
if err != nil {
|
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
|
|
|
}
|
|
|
|
return publishedGi.ConvertFromSlice(find)
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetPublishedGiById(id int) (*model.PublishedGi, error) {
|
|
|
|
return dbquery.PublishedGi.Where(dbquery.PublishedGi.ID.Eq(int32(id))).Debug().First()
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:47:04 +08:00
|
|
|
func PublishFormDraft(req *publishedGi.PublishReqDto, user *model.User) {
|
2023-07-18 17:19:03 +08:00
|
|
|
draft := QueryDrafting(req.DraftId)
|
|
|
|
if draft.Proto == nil || len(draft.Proto) == 0 {
|
|
|
|
panic(fmt.Sprintf("草稿[%v]绘图数据信息为空", req.DraftId))
|
|
|
|
}
|
|
|
|
entity := model.PublishedGi{
|
|
|
|
Name: req.Name,
|
|
|
|
Proto: draft.Proto,
|
|
|
|
UserID: user.ID,
|
|
|
|
PublishAt: time.Now(),
|
|
|
|
}
|
2023-07-31 10:15:02 +08:00
|
|
|
//删除同名数据
|
2023-08-01 17:08:45 +08:00
|
|
|
oldData, _ := dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Find()
|
|
|
|
if oldData != nil && len(oldData) > 0 {
|
|
|
|
dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Delete()
|
|
|
|
for _, v := range oldData {
|
|
|
|
memory.DeleteMapVerifyStructure(v.ID) // 移除内存中的发布信息
|
|
|
|
}
|
|
|
|
}
|
2023-07-31 10:15:02 +08:00
|
|
|
//插入新数据
|
|
|
|
err := dbquery.PublishedGi.Debug().Create(&entity)
|
|
|
|
if err != nil {
|
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: fmt.Sprintf("数据创建失败:\n%s", err.Error())})
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|
2023-08-01 17:08:45 +08:00
|
|
|
newData, _ := dbquery.PublishedGi.Where(dbquery.PublishedGi.Name.Eq(req.Name)).First()
|
|
|
|
// 地图信息更新到缓存
|
|
|
|
if newData != nil {
|
|
|
|
memory.PublishMapVerifyStructure(newData)
|
|
|
|
}
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DeletePublishedGiById(id int) {
|
|
|
|
_, _ = dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.ID.Eq(int32(id))).Delete()
|
2023-08-01 17:08:45 +08:00
|
|
|
memory.DeleteMapVerifyStructure(int32(id)) // 移除内存中的发布信息
|
2023-07-18 17:19:03 +08:00
|
|
|
}
|