【代码格式修改】

This commit is contained in:
weizhihong 2023-08-31 16:16:18 +08:00
parent 1a4145bd5d
commit e4a84f8afb
13 changed files with 246 additions and 248 deletions

View File

@ -103,11 +103,8 @@ func createByProjectId(c *gin.Context) {
if err := c.ShouldBind(&req); nil != err { if err := c.ShouldBind(&req); nil != err {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
} }
zap.S().Debug("创建仿真请求:", req) rsp := dto.SimulationCreateRspDto{ProjectId: req.ProjectId}
rsp := dto.SimulationCreateRspDto{ mapInfos := service.QueryProjectPublishedGi(req.ProjectId)
ProjectId: req.ProjectId,
}
mapInfos := service.QueryPublishedGi(req.ProjectId)
if len(mapInfos) == 0 { if len(mapInfos) == 0 {
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: "项目未关联地图"}) panic(dto.ErrorDto{Code: dto.DataNotExist, Message: "项目未关联地图"})
} }
@ -203,9 +200,9 @@ func checkSimMapData(c *gin.Context) {
err := proto.Unmarshal(rt.Data, &graphicData.RtssGraphicStorage{}) err := proto.Unmarshal(rt.Data, &graphicData.RtssGraphicStorage{})
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, "参数错误") c.JSON(http.StatusInternalServerError, "参数错误")
} else { return
c.JSON(http.StatusOK, &dto.CheckMapDataRspDto{Success: true})
} }
c.JSON(http.StatusOK, &dto.CheckMapDataRspDto{Success: true})
} }
// ATS测试仿真-添加列车 // ATS测试仿真-添加列车
@ -232,7 +229,8 @@ func addTrain(c *gin.Context) {
id := getAddTrainPrimaryKey(simulation) id := getAddTrainPrimaryKey(simulation)
if id == -1 { if id == -1 {
c.JSON(http.StatusBadRequest, "已存在在线列车") c.JSON(http.StatusBadRequest, "已存在在线列车")
} else { return
}
rsp := &state.TrainState{ rsp := &state.TrainState{
Id: strconv.Itoa(id), Id: strconv.Itoa(id),
HeadDeviceId: req.Id, HeadDeviceId: req.Id,
@ -244,7 +242,6 @@ func addTrain(c *gin.Context) {
memory.AddTrainState(simulation, rsp) memory.AddTrainState(simulation, rsp)
c.JSON(http.StatusOK, &rsp) c.JSON(http.StatusOK, &rsp)
} }
}
// ATS测试仿真-移除列车 // ATS测试仿真-移除列车
// //
@ -340,16 +337,15 @@ func getAddTrainPrimaryKey(simulation *memory.VerifySimulation) int {
i := 1 i := 1
for { for {
t, ok := trainMap.Load(strconv.Itoa(i)) t, ok := trainMap.Load(strconv.Itoa(i))
if ok { if !ok {
break
}
ts := t.(*state.TrainState) ts := t.(*state.TrainState)
if ts.Show { if ts.Show {
i = -1 i = -1
break break
} }
i++ i++
} else {
break
}
} }
return i return i
} }

View File

@ -25,7 +25,9 @@ func init() {
for _, simulation := range GetSimulationArr() { for _, simulation := range GetSimulationArr() {
simulation.Memory.Status.TrainStateMap.Range(func(_, value any) bool { simulation.Memory.Status.TrainStateMap.Range(func(_, value any) bool {
train := value.(*state.TrainState) train := value.(*state.TrainState)
if train.Show { // 上线列车 if !train.Show { // 下线列车
return false
}
// 拼接列车ID // 拼接列车ID
trainId, err := strconv.Atoi(train.Id) trainId, err := strconv.Atoi(train.Id)
if err != nil { if err != nil {
@ -37,8 +39,7 @@ func init() {
dynamics.SendDynamicsTrainMsg(append(info, uint8(trainId))) dynamics.SendDynamicsTrainMsg(append(info, uint8(trainId)))
// 存放至列车中 // 存放至列车中
train.VobcState = trainInfo train.VobcState = trainInfo
} return true
return false
}) })
} }
@ -46,15 +47,15 @@ func init() {
dynamics.RegisterTrainInfoHandler(func(info *dynamics.TrainInfo) { dynamics.RegisterTrainInfoHandler(func(info *dynamics.TrainInfo) {
for _, simulation := range GetSimulationArr() { for _, simulation := range GetSimulationArr() {
sta, ok := simulation.Memory.Status.TrainStateMap.Load(strconv.Itoa(int(info.Number))) sta, ok := simulation.Memory.Status.TrainStateMap.Load(strconv.Itoa(int(info.Number)))
if ok { if !ok {
continue
}
trainState := sta.(*state.TrainState) trainState := sta.(*state.TrainState)
// 给半实物仿真发送速度 // 给半实物仿真发送速度
zap.S().Info("发送到vobc发送的速度", info.Speed*36) zap.S().Info("发送到vobc发送的速度", info.Speed*36)
vobc.SendTrainSpeedTask(info.Speed * 36) vobc.SendTrainSpeedTask(info.Speed * 36)
// 更新列车状态 // 更新列车状态
memory.UpdateTrainState(simulation, convert(info, trainState, simulation)) memory.UpdateTrainState(simulation, convert(info, trainState, simulation))
break
}
} }
}) })
} }
@ -109,7 +110,7 @@ func createSimulationId(mapId int32) string {
// 获取仿真列表 // 获取仿真列表
func ListAllSimulations() []*dto.SimulationInfoRspDto { func ListAllSimulations() []*dto.SimulationInfoRspDto {
simArr := []*dto.SimulationInfoRspDto{} var simArr []*dto.SimulationInfoRspDto
simulationMap.Range(func(_, v any) bool { simulationMap.Range(func(_, v any) bool {
s := v.(*memory.VerifySimulation) s := v.(*memory.VerifySimulation)
simArr = append(simArr, &dto.SimulationInfoRspDto{ simArr = append(simArr, &dto.SimulationInfoRspDto{
@ -133,7 +134,7 @@ func FindSimulation(simulationId string) *memory.VerifySimulation {
// 获取普通仿真数组 // 获取普通仿真数组
func GetSimulationArr() []*memory.VerifySimulation { func GetSimulationArr() []*memory.VerifySimulation {
result := []*memory.VerifySimulation{} var result []*memory.VerifySimulation
simulationMap.Range(func(_, v any) bool { simulationMap.Range(func(_, v any) bool {
result = append(result, v.(*memory.VerifySimulation)) result = append(result, v.(*memory.VerifySimulation))
return true return true
@ -152,14 +153,13 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory
sta.PointTo = pointTo sta.PointTo = pointTo
sta.RunDirection = runDirection sta.RunDirection = runDirection
//判定车头方向 //判定车头方向
sta.HeadDirection = runDirection
if sta.VobcState != nil { if sta.VobcState != nil {
if sta.VobcState.DirectionForward { if sta.VobcState.DirectionForward {
sta.HeadDirection = info.Up sta.HeadDirection = info.Up
} else if sta.VobcState.DirectionBackward { } else if sta.VobcState.DirectionBackward {
sta.HeadDirection = !info.Up sta.HeadDirection = !info.Up
} }
} else {
sta.HeadDirection = runDirection
} }
// 赋值动力学信息 // 赋值动力学信息
sta.DynamicState.Heartbeat = int32(info.LifeSignal) sta.DynamicState.Heartbeat = int32(info.LifeSignal)

View File

@ -49,7 +49,7 @@ func BuildCalculateLinkData(gd *graphicData.RtssGraphicStorage) []*graphicData.C
// 这里linkPath是排过序的公里标大小 // 这里linkPath是排过序的公里标大小
linkPathMap := getGraphicLinkPath(gm, startPointQueue) linkPathMap := getGraphicLinkPath(gm, startPointQueue)
// 根据路径开始包装结果数据 // 根据路径开始包装结果数据
resultArr := []*graphicData.CalculateLink{} var resultArr []*graphicData.CalculateLink
for id, pathArr := range linkPathMap { for id, pathArr := range linkPathMap {
item := &graphicData.CalculateLink{ item := &graphicData.CalculateLink{
Common: &graphicData.CommonInfo{}, Common: &graphicData.CommonInfo{},
@ -316,9 +316,9 @@ func getGraphicDataDeviceMap(gd *graphicData.RtssGraphicStorage) (*buildCalcStru
gm.TurnoutMap[t.Common.Id] = &buildCalcTurnoutStruct{ gm.TurnoutMap[t.Common.Id] = &buildCalcTurnoutStruct{
Data: t, Data: t,
CrossKilometerSystem: op, CrossKilometerSystem: op,
axlePoints: make(map[graphicData.RelatedRef_DevicePort]*graphicData.AxleCounting), axlePoints: make(map[graphicData.RelatedRef_DevicePort]*graphicData.AxleCounting, 3),
transponders: make(map[graphicData.RelatedRef_DevicePort][]*graphicData.Transponder), transponders: make(map[graphicData.RelatedRef_DevicePort][]*graphicData.Transponder),
signals: make(map[graphicData.RelatedRef_DevicePort]*graphicData.Signal), signals: make(map[graphicData.RelatedRef_DevicePort]*graphicData.Signal, 3),
slopes: make(map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem), slopes: make(map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem),
curvatures: make(map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem), curvatures: make(map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem),
} }
@ -327,7 +327,7 @@ func getGraphicDataDeviceMap(gd *graphicData.RtssGraphicStorage) (*buildCalcStru
for _, s := range gd.Section { for _, s := range gd.Section {
gm.SectionMap[s.Common.Id] = &buildCalcSectionStruct{ gm.SectionMap[s.Common.Id] = &buildCalcSectionStruct{
Data: s, Data: s,
axlePoints: make(map[graphicData.RelatedRef_DevicePort]*graphicData.AxleCounting), axlePoints: make(map[graphicData.RelatedRef_DevicePort]*graphicData.AxleCounting, 2),
slopes: make(map[string]*graphicData.KilometerSystem), slopes: make(map[string]*graphicData.KilometerSystem),
curvatures: make(map[string]*graphicData.KilometerSystem), curvatures: make(map[string]*graphicData.KilometerSystem),
} }
@ -544,7 +544,9 @@ func judgeKilometerInRange(k1, k2, k3 *graphicData.KilometerSystem) bool {
// 处理道岔坡度、曲度信息 // 处理道岔坡度、曲度信息
func handleSlopeCurvaturesMap(id string, kms []*graphicData.KilometerSystem, m map[graphicData.Direction]map[string]*graphicData.KilometerSystem) { func handleSlopeCurvaturesMap(id string, kms []*graphicData.KilometerSystem, m map[graphicData.Direction]map[string]*graphicData.KilometerSystem) {
for _, k := range kms { for _, k := range kms {
if judgeKilometerIsVaild(k) { if !judgeKilometerIsVaild(k) {
continue
}
kmMap := m[k.Direction] kmMap := m[k.Direction]
if kmMap == nil { if kmMap == nil {
kmMap = make(map[string]*graphicData.KilometerSystem) kmMap = make(map[string]*graphicData.KilometerSystem)
@ -553,18 +555,19 @@ func handleSlopeCurvaturesMap(id string, kms []*graphicData.KilometerSystem, m m
kmMap[id] = k kmMap[id] = k
} }
} }
}
func handleTurnoutSlopeCurvaturesMap(port graphicData.RelatedRef_DevicePort, func handleTurnoutSlopeCurvaturesMap(port graphicData.RelatedRef_DevicePort,
t *buildCalcTurnoutStruct, t *buildCalcTurnoutStruct,
scmap map[graphicData.Direction]map[string]*graphicData.KilometerSystem, scmap map[graphicData.Direction]map[string]*graphicData.KilometerSystem,
f func(*buildCalcTurnoutStruct) map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem) { f func(*buildCalcTurnoutStruct) map[graphicData.RelatedRef_DevicePort]map[string]*graphicData.KilometerSystem) {
point := t.axlePoints[port] point := t.axlePoints[port]
if point != nil { if point == nil {
return
}
m := f(t) m := f(t)
m[port] = make(map[string]*graphicData.KilometerSystem) m[port] = make(map[string]*graphicData.KilometerSystem)
kmMap := scmap[point.KilometerSystem.Direction] kmMap := scmap[point.KilometerSystem.Direction]
idArr := []string{} var idArr []string
for k, v := range kmMap { for k, v := range kmMap {
if judgeKilometerInRange(v, point.KilometerSystem, t.CrossKilometerSystem) { if judgeKilometerInRange(v, point.KilometerSystem, t.CrossKilometerSystem) {
m[port][k] = v m[port][k] = v
@ -575,7 +578,6 @@ func handleTurnoutSlopeCurvaturesMap(port graphicData.RelatedRef_DevicePort,
delete(kmMap, id) delete(kmMap, id)
} }
} }
}
func handleSectionSlopeCurvaturesMap(s *buildCalcSectionStruct, func handleSectionSlopeCurvaturesMap(s *buildCalcSectionStruct,
scmap map[graphicData.Direction]map[string]*graphicData.KilometerSystem, scmap map[graphicData.Direction]map[string]*graphicData.KilometerSystem,
@ -587,7 +589,7 @@ func handleSectionSlopeCurvaturesMap(s *buildCalcSectionStruct,
} }
m := f(s) m := f(s)
kmMap := scmap[pointA.KilometerSystem.Direction] kmMap := scmap[pointA.KilometerSystem.Direction]
idArr := []string{} var idArr []string
for k, v := range kmMap { for k, v := range kmMap {
if judgeKilometerInRange(v, pointA.KilometerSystem, pointB.KilometerSystem) { if judgeKilometerInRange(v, pointA.KilometerSystem, pointB.KilometerSystem) {
m[k] = v m[k] = v

View File

@ -50,17 +50,19 @@ func (t *MemoryChangeServer) onTick() []TopicMsg {
allSim := make(map[string]bool) allSim := make(map[string]bool)
for _, v := range simArr { for _, v := range simArr {
allSim[v.SimulationId] = true allSim[v.SimulationId] = true
if t.SimulationMap[v.SimulationId] == nil { if t.SimulationMap[v.SimulationId] != nil {
continue
}
status := &state.SimulationStatus{SimulationId: v.SimulationId, MapId: v.MapId, ProjectId: v.ProjectId} status := &state.SimulationStatus{SimulationId: v.SimulationId, MapId: v.MapId, ProjectId: v.ProjectId}
t.SimulationMap[v.SimulationId] = status t.SimulationMap[v.SimulationId] = status
addArr = append(addArr, status) addArr = append(addArr, status)
} }
}
// 已经移除的仿真 // 已经移除的仿真
for k, v := range t.SimulationMap { for k, v := range t.SimulationMap {
if !allSim[k] { if allSim[k] {
delArr = append(delArr, v) continue
} }
delArr = append(delArr, v)
} }
// 删除已替换仿真主键 // 删除已替换仿真主键
if len(delArr) > 0 { if len(delArr) > 0 {
@ -69,8 +71,8 @@ func (t *MemoryChangeServer) onTick() []TopicMsg {
} }
} }
if len(addArr) == 0 && len(delArr) == 0 { if len(addArr) == 0 && len(delArr) == 0 {
return []TopicMsg{} return nil
} else { }
msg := &state.MemoryDataStatus{AddSimulations: addArr, RemoveSimulations: delArr} msg := &state.MemoryDataStatus{AddSimulations: addArr, RemoveSimulations: delArr}
b, err := proto.Marshal(msg) b, err := proto.Marshal(msg)
if err != nil { if err != nil {
@ -78,4 +80,3 @@ func (t *MemoryChangeServer) onTick() []TopicMsg {
} }
return []TopicMsg{{channalName: t.getChannelName(), data: b}} return []TopicMsg{{channalName: t.getChannelName(), data: b}}
} }
}

View File

@ -57,11 +57,12 @@ func RegisterMsgServer(server IMsgServer) {
for { for {
<-tick.C <-tick.C
topicMsgs := server.onTick() topicMsgs := server.onTick()
if len(topicMsgs) != 0 { if len(topicMsgs) == 0 {
continue
}
for _, msg := range topicMsgs { for _, msg := range topicMsgs {
PublishMsg(msg.channalName, msg.data) PublishMsg(msg.channalName, msg.data)
} }
}
select { select {
case <-exitChannel: case <-exitChannel:
return return

View File

@ -48,10 +48,7 @@ func (t *SimulationServer) onTick() []TopicMsg {
if err != nil { if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
} }
msgArr[i] = TopicMsg{ msgArr[i] = TopicMsg{channalName: channelName, data: b}
channalName: channelName,
data: b,
}
} }
return msgArr return msgArr
} }

View File

@ -22,7 +22,8 @@ func permissionMiddleware() gin.HandlerFunc {
user, _ := c.Get(IdentityKey) user, _ := c.Get(IdentityKey)
if user == nil { // 用户未登录 if user == nil { // 用户未登录
c.Next() c.Next()
} else { return
}
uid := user.(*model.User).ID uid := user.(*model.User).ID
userAuth := userAuthPathMap[uid] userAuth := userAuthPathMap[uid]
if userAuth == nil { if userAuth == nil {
@ -31,33 +32,32 @@ func permissionMiddleware() gin.HandlerFunc {
} }
if userAuth.IsAdmin { // 用户是超级管理员 if userAuth.IsAdmin { // 用户是超级管理员
c.Next() c.Next()
} else { return
}
path, method := c.Request.URL.Path, c.Request.Method path, method := c.Request.URL.Path, c.Request.Method
if validateUserPath(path, method, userAuth.AuthPaths) { // 用户有权限 if validateUserPath(path, method, userAuth.AuthPaths) { // 用户有权限
c.Next() c.Next()
} else { return
}
zap.S().Errorf("无权限操作请求路径:%s, 方法:%s", path, method) zap.S().Errorf("无权限操作请求路径:%s, 方法:%s", path, method)
panic(dto.ErrorDto{Code: dto.NoAuthOperationError, Message: "无权限操作"}) panic(dto.ErrorDto{Code: dto.NoAuthOperationError, Message: "无权限操作"})
} }
} }
}
}
}
// 验证路径 // 验证路径
func validateUserPath(path, method string, paths []*dto.AuthPath) bool { func validateUserPath(path, method string, paths []*dto.AuthPath) bool {
for _, p := range paths { for _, p := range paths {
if p.Method == "*" || strings.Contains(p.Method, method) { // 判断方法是否匹配 if p.Method != "*" && !strings.Contains(p.Method, method) { // 判断方法是否匹配
continue
}
if p.Path == path { if p.Path == path {
return true return true
} else { }
authReg, _ := regexp.Compile(p.Path) authReg, _ := regexp.Compile(p.Path)
if authReg.MatchString(path) { // 匹配路径 if authReg.MatchString(path) { // 匹配路径
return true return true
} }
} }
}
}
return false return false
} }
@ -68,7 +68,7 @@ func ClearUserPermission(userId int32) {
// 修改角色后清理用户权限 // 修改角色后清理用户权限
func ClearUserPermissionByRid(roleId int32) { func ClearUserPermissionByRid(roleId int32) {
uids := []int32{} var uids []int32
for uid, u := range userAuthPathMap { for uid, u := range userAuthPathMap {
for _, r := range u.RoleIds { for _, r := range u.RoleIds {
if r == roleId { if r == roleId {
@ -77,9 +77,10 @@ func ClearUserPermissionByRid(roleId int32) {
} }
} }
} }
if len(uids) > 0 { if len(uids) == 0 {
return
}
for _, uid := range uids { for _, uid := range uids {
ClearUserPermission(uid) ClearUserPermission(uid)
} }
} }
}

View File

@ -31,17 +31,18 @@ func ListAuthRoleQuery() []*dto.AuthRoleRspDto {
// 创建权限角色 // 创建权限角色
func CreateAuthRole(a *dto.AuthRoleReqDto) bool { func CreateAuthRole(a *dto.AuthRoleReqDto) bool {
createTime := time.Now() d := model.AuthRole{Name: a.Name, CreateTime: time.Now()}
d := model.AuthRole{Name: a.Name, CreateTime: createTime}
aq := dbquery.AuthRole aq := dbquery.AuthRole
err := aq.Save(&d) err := aq.Save(&d)
if err != nil { if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
} }
n := len(a.AddPaths) n := len(a.AddPaths)
if n > 0 { if n == 0 {
return false
}
// 查询刚插入的角色 // 查询刚插入的角色
newAuthRole, _ := aq.Where(aq.Name.Eq(a.Name), aq.CreateTime.Eq(createTime)).First() newAuthRole, _ := aq.Where(aq.Name.Eq(a.Name)).Order(aq.CreateTime).Last()
rolePaths := make([]*model.AuthRoleAPIPath, n) rolePaths := make([]*model.AuthRoleAPIPath, n)
for i, v := range a.AddPaths { for i, v := range a.AddPaths {
rolePaths[i] = &model.AuthRoleAPIPath{Rid: newAuthRole.ID, Pid: v} rolePaths[i] = &model.AuthRoleAPIPath{Rid: newAuthRole.ID, Pid: v}
@ -49,8 +50,6 @@ func CreateAuthRole(a *dto.AuthRoleReqDto) bool {
dbquery.AuthRoleAPIPath.Save(rolePaths...) dbquery.AuthRoleAPIPath.Save(rolePaths...)
return true return true
} }
return false
}
// 查询角色详情 // 查询角色详情
func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto { func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
@ -66,7 +65,9 @@ func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
} }
pn := len(linkPids) pn := len(linkPids)
if pn > 0 { if pn == 0 { // 无关联路径
return rsp
}
pids := make([]int32, pn) pids := make([]int32, pn)
for i, r := range linkPids { for i, r := range linkPids {
pids[i] = r.Pid pids[i] = r.Pid
@ -76,7 +77,6 @@ func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()})
} }
rsp.Paths = apiPaths rsp.Paths = apiPaths
}
return rsp return rsp
} }
@ -87,24 +87,24 @@ func UpdateAuthRole(rid int32, info *dto.AuthRoleReqDto) bool {
if err != nil { if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
} }
role.Name = info.Name role.Name = info.Name // 更新名称
// 更新名称
dbquery.AuthRole.Updates(role) dbquery.AuthRole.Updates(role)
// 删除关联
dqarap := dbquery.AuthRoleAPIPath dqarap := dbquery.AuthRoleAPIPath
// 删除关联
rn := len(info.DelPaths) rn := len(info.DelPaths)
if rn > 0 { if rn > 0 {
dqarap.Where(dqarap.Rid.Eq(rid), dqarap.Pid.In(info.DelPaths...)).Delete() dqarap.Where(dqarap.Rid.Eq(rid), dqarap.Pid.In(info.DelPaths...)).Delete()
} }
// 增加关联 // 增加关联
an := len(info.AddPaths) an := len(info.AddPaths)
if an > 0 { if an == 0 {
return true
}
rolePaths := make([]*model.AuthRoleAPIPath, an) rolePaths := make([]*model.AuthRoleAPIPath, an)
for i, v := range info.AddPaths { for i, v := range info.AddPaths {
rolePaths[i] = &model.AuthRoleAPIPath{Rid: rid, Pid: v} rolePaths[i] = &model.AuthRoleAPIPath{Rid: rid, Pid: v}
} }
dqarap.Save(rolePaths...) dqarap.Save(rolePaths...)
}
return true return true
} }
@ -216,7 +216,9 @@ func UserLinkRole(linkInfo *dto.AuthRoleUserReqDto) bool {
} }
// 插入关联关系 // 插入关联关系
n := len(linkInfo.AddRids) n := len(linkInfo.AddRids)
if n > 0 { if n == 0 {
return true
}
arul := make([]*model.AuthRoleUser, n) arul := make([]*model.AuthRoleUser, n)
for i, l := range linkInfo.AddRids { for i, l := range linkInfo.AddRids {
arul[i] = &model.AuthRoleUser{UID: linkInfo.Uid, Rid: l} arul[i] = &model.AuthRoleUser{UID: linkInfo.Uid, Rid: l}
@ -225,7 +227,6 @@ func UserLinkRole(linkInfo *dto.AuthRoleUserReqDto) bool {
if err2 != nil { if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
} }
}
return true return true
} }
@ -257,14 +258,19 @@ func QueryUserAuthApiPath(uid int32) *dto.AuthUserStorageDto {
rids[i] = r.ID rids[i] = r.ID
authUser.IsAdmin = authUser.IsAdmin || (r.Weight == int32(dto.ADMIN)) authUser.IsAdmin = authUser.IsAdmin || (r.Weight == int32(dto.ADMIN))
} }
if !authUser.IsAdmin { // 非管理员时,查询角色权限路径 if authUser.IsAdmin { // 管理员直接返回
// 查询角色与路径关联信息 return authUser
}
// 非管理员时,查询角色权限路径
linkPids, err3 := dbquery.AuthRoleAPIPath.Distinct(dbquery.AuthRoleAPIPath.Pid).Where(dbquery.AuthRoleAPIPath.Rid.In(rids...)).Find() linkPids, err3 := dbquery.AuthRoleAPIPath.Distinct(dbquery.AuthRoleAPIPath.Pid).Where(dbquery.AuthRoleAPIPath.Rid.In(rids...)).Find()
if err3 != nil { if err3 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err3.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err3.Error()})
} }
// 非管理员路径信息
pn := len(linkPids) pn := len(linkPids)
if pn > 0 { if pn == 0 {
return authUser
}
pids := make([]int32, pn) pids := make([]int32, pn)
for i, r := range linkPids { for i, r := range linkPids {
pids[i] = r.Pid pids[i] = r.Pid
@ -274,7 +280,5 @@ func QueryUserAuthApiPath(uid int32) *dto.AuthUserStorageDto {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()}) panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()})
} }
authUser.AuthPaths = dto.ConvertFromAuthPath(apiPaths) // 赋值路径数组 authUser.AuthPaths = dto.ConvertFromAuthPath(apiPaths) // 赋值路径数组
}
}
return authUser return authUser
} }

View File

@ -73,15 +73,9 @@ func UpdateCategory(id int32, cd *dto.CategoryDto) bool {
if oldD == nil || err != nil { if oldD == nil || err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
} }
if cd.Code != "" {
oldD.Code = cd.Code oldD.Code = cd.Code
}
if cd.Config != "" {
oldD.Config = cd.Config oldD.Config = cd.Config
}
if len(cd.Name) > 0 {
oldD.Name = cd.Name oldD.Name = cd.Name
}
oldD.UpdateAt = time.Now() oldD.UpdateAt = time.Now()
_, error := dbquery.Category.Updates(oldD) _, error := dbquery.Category.Updates(oldD)
if error != nil { if error != nil {

View File

@ -98,12 +98,14 @@ func DeleteProjectById(id int) {
} }
func checkProjectInfo(code string, id int32) error { func checkProjectInfo(code string, id int32) error {
if code == "" {
return nil
}
findNameQuery := dbquery.Project findNameQuery := dbquery.Project
w := findNameQuery.Where() w := findNameQuery.Where()
if id != 0 { if id != 0 {
w = w.Where(findNameQuery.ID.NotIn(id)) w = w.Where(findNameQuery.ID.NotIn(id))
} }
if code != "" {
count, err := w.Where(findNameQuery.Code.Eq(code)).Debug().Count() count, err := w.Where(findNameQuery.Code.Eq(code)).Debug().Count()
if err != nil { if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
@ -111,6 +113,5 @@ func checkProjectInfo(code string, id int32) error {
if count > 0 { if count > 0 {
panic(dto.ErrorDto{Code: dto.DataAlreadyExist, Message: "编码已存在"}) panic(dto.ErrorDto{Code: dto.DataAlreadyExist, Message: "编码已存在"})
} }
}
return nil return nil
} }

View File

@ -16,7 +16,7 @@ func QueryProjectLinkInfo(id int32) *dto.ProjectLinkRspDto {
// 关联列车尺寸列表 // 关联列车尺寸列表
projectLink.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id)) projectLink.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id))
// 关联地图列表 // 关联地图列表
projectLink.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryPublishedGi(id)) projectLink.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryProjectPublishedGi(id))
return projectLink return projectLink
} }
@ -51,20 +51,22 @@ func delProjectMapLink(pid int32) {
// 保存项目尺寸关联关系 // 保存项目尺寸关联关系
func saveProjectSize(pid int32, sids []*int32) { func saveProjectSize(pid int32, sids []*int32) {
for _, sid := range sids { if len(sids) == 0 {
dbquery.ProjectTrainSizeLink.Save(&model.ProjectTrainSizeLink{ sizeInfos := make([]*model.ProjectTrainSizeLink, len(sids))
Pid: pid, for i, sid := range sids {
Sid: *sid, sizeInfos[i] = &model.ProjectTrainSizeLink{Pid: pid, Sid: *sid}
}) }
dbquery.ProjectTrainSizeLink.Save(sizeInfos...)
} }
} }
// 保存项目地图关联关系 // 保存项目地图关联关系
func saveProjectMapLink(pid int32, mids []*int32) { func saveProjectMapLink(pid int32, mids []*int32) {
for _, mid := range mids { if len(mids) == 0 {
dbquery.ProjectPublishLink.Save(&model.ProjectPublishLink{ mapInfos := make([]*model.ProjectPublishLink, len(mids))
Pid: pid, for i, mid := range mids {
Mid: *mid, mapInfos[i] = &model.ProjectPublishLink{Pid: pid, Mid: *mid}
}) }
dbquery.ProjectPublishLink.Save(mapInfos...)
} }
} }

View File

@ -31,7 +31,7 @@ func PageQueryPublishedGi(req *publishedGi.PublishedGiReqDto) *dto.PageDto {
} }
func ListQueryPublishedGi(req *publishedGi.PublishedGiListReqDto) []*publishedGi.PublishedGiDto { func ListQueryPublishedGi(req *publishedGi.PublishedGiListReqDto) []*publishedGi.PublishedGiDto {
where := dbquery.PublishedGi.Where(dbquery.PublishedGi.Status.Eq(1)) where := dbquery.PublishedGi.Omit(dbquery.PublishedGi.Proto).Where(dbquery.PublishedGi.Status.Eq(1))
if req.Name != "" { if req.Name != "" {
where = where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name))) where = where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name)))
} }
@ -115,21 +115,21 @@ func SaveAsDraftingFromPublish(id int32, user *model.User, name string) {
} }
} }
func QueryPublishedGi(id int32) []*model.PublishedGi { func QueryProjectPublishedGi(id int32) []*model.PublishedGi {
// 获取项目关联的发布地图 // 获取项目关联的发布地图
dppl := dbquery.ProjectPublishLink dppl := dbquery.ProjectPublishLink
links, _ := dppl.Select(dppl.Mid).Where(dppl.Pid.Eq(id)).Find() links, _ := dppl.Select(dppl.Mid).Where(dppl.Pid.Eq(id)).Find()
if len(links) > 0 { if len(links) == 0 {
mids := []int32{} return nil
for _, m := range links { }
mids = append(mids, m.Mid) mids := make([]int32, len(links))
for i, m := range links {
mids[i] = m.Mid
} }
dp := dbquery.PublishedGi dp := dbquery.PublishedGi
publishedGis, _ := dp.Select(dp.ID, dp.Name, dp.Category).Where(dp.ID.In(mids...)).Find() publishedGis, _ := dp.Select(dp.ID, dp.Name, dp.Category).Where(dp.ID.In(mids...)).Find()
return publishedGis return publishedGis
} }
return []*model.PublishedGi{}
}
// 操作地图数据中的link数据 // 操作地图数据中的link数据
// del 代表是否删除地图中的link数据 // del 代表是否删除地图中的link数据

View File

@ -75,9 +75,7 @@ func UpdateTrainModel(id int32, td *dto.TrainModelDto) bool {
if oldD == nil || err != nil { if oldD == nil || err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
} }
if len(td.Name) > 0 {
oldD.Name = td.Name oldD.Name = td.Name
}
oldD.UpdateAt = time.Now() oldD.UpdateAt = time.Now()
_, err2 := dbquery.TrainModel.Updates(oldD) _, err2 := dbquery.TrainModel.Updates(oldD)
if err2 != nil { if err2 != nil {
@ -171,18 +169,18 @@ func DeleteTrainSizeById(id int) {
func QueryProjectTrainSize(id int32) []*model.TrainSize { func QueryProjectTrainSize(id int32) []*model.TrainSize {
// 获取项目关联的列车尺寸 // 获取项目关联的列车尺寸
ptsl := dbquery.ProjectTrainSizeLink ptsl := dbquery.ProjectTrainSizeLink
slinks, _ := ptsl.Select(ptsl.Sid).Where(ptsl.Pid.Eq(id)).Find() slinks, _ := ptsl.Select(ptsl.Sid).Distinct(ptsl.Sid).Where(ptsl.Pid.Eq(id)).Find()
if len(slinks) > 0 { if len(slinks) == 0 {
sids := []int32{} return nil
for _, sid := range slinks { }
sids = append(sids, sid.Sid) sids := make([]int32, len(slinks))
for i, sid := range slinks {
sids[i] = sid.Sid
} }
ts := dbquery.TrainSize ts := dbquery.TrainSize
trainSizes, _ := ts.Select(ts.ID, ts.Name, ts.TotalLength, ts.CarriageLength, ts.Description).Where(ts.ID.In(sids...)).Find() trainSizes, _ := ts.Select(ts.ID, ts.Name, ts.TotalLength, ts.CarriageLength, ts.Description).Where(ts.ID.In(sids...)).Find()
return trainSizes return trainSizes
} }
return []*model.TrainSize{}
}
// 查询列车轮径信息列表 // 查询列车轮径信息列表
func PageTrainWheelDiameterQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error) { func PageTrainWheelDiameterQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error) {
@ -267,19 +265,20 @@ func DeleteTrainWheelDiameterById(id int) {
// 检查列车型号名称 // 检查列车型号名称
func checkTrainModel(name string, id int32) error { func checkTrainModel(name string, id int32) error {
if name == "" {
return nil
}
findNameQuery := dbquery.TrainModel findNameQuery := dbquery.TrainModel
w := findNameQuery.Where() w := findNameQuery.Where()
if id != 0 { if id != 0 {
w = w.Where(findNameQuery.ID.NotIn(id)) w = w.Where(findNameQuery.ID.NotIn(id))
} }
if name != "" {
count, err := w.Where(findNameQuery.Name.Eq(name)).Debug().Count() count, err := w.Where(findNameQuery.Name.Eq(name)).Debug().Count()
if err != nil { if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
} }
if count > 0 { if count > 0 {
panic("名称已存在") panic(dto.ErrorDto{Code: dto.DataAlreadyExist, Message: "名称已存在"})
}
} }
return nil return nil
} }