fix: 配置应用的数据读取支持当前操作应用下发

This commit is contained in:
TsMask
2024-07-17 16:48:02 +08:00
parent 60ea5ee87d
commit 3db0f83dcc
2 changed files with 61 additions and 16 deletions

View File

@@ -1,6 +1,9 @@
package controller
import (
"fmt"
"strings"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
@@ -26,6 +29,16 @@ type PtNeConfigApplyController struct {
ptNeConfigDataService service.IPtNeConfigDataService
}
// 班级学生列表 (仅教师操作)
//
// GET /students
func (s *PtNeConfigApplyController) Students(c *gin.Context) {
userName, _ := c.GetQuery("userName")
loginUser, _ := ctx.LoginUser(c)
data := s.ptNeConfigApplyService.SelectListByClass(loginUser.DeptID, userName)
c.JSON(200, result.OkData(data))
}
// 网元参数配置应用申请列表
//
// GET /list
@@ -66,7 +79,7 @@ func (s *PtNeConfigApplyController) Add(c *gin.Context) {
}
s.ptNeConfigApplyService.Insert(model.PtNeConfigApply{
CreateBy: currentUserName,
Status: "0",
Status: body.Status,
NeType: body.NeType,
})
c.JSON(200, result.OkMsg("Application Submission Complete!"))
@@ -82,7 +95,7 @@ func (s *PtNeConfigApplyController) Add(c *gin.Context) {
}
for _, v := range applyInfos {
v.UpdateBy = currentUserName
v.Status = "1"
v.Status = body.Status
s.ptNeConfigApplyService.Update(v)
}
c.JSON(200, result.OkMsg("Application Revocable Complete!"))
@@ -96,8 +109,9 @@ func (s *PtNeConfigApplyController) Add(c *gin.Context) {
func (s *PtNeConfigApplyController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
ApplyId string `json:"applyId" binding:"required"` // 申请ID
NeType string `json:"neType" binding:"required"` // 网元类型
ApplyId string `json:"applyId"` // 申请ID
BackId string `json:"backId"` // 批量退回申请ID,号分隔
NeType string `json:"neType"` // 网元类型
Status string `json:"status" binding:"required,oneof=2 3"` // 状态 2应用 3退回
BackInfo string `json:"backInfo"` // 退回信息
}
@@ -107,32 +121,63 @@ func (s *PtNeConfigApplyController) Edit(c *gin.Context) {
}
currentUserName := ctx.LoginUserToUserName(c)
applyInfos := s.ptNeConfigApplyService.SelectById(body.ApplyId)
if applyInfos.ID != body.ApplyId || applyInfos.Status != "0" {
// 不指定申请直接应用
if body.ApplyId == "" && body.NeType != "" && body.Status == "2" {
if err := s.ptNeConfigDataService.ApplyToNe(currentUserName, body.NeType); err != nil {
c.JSON(200, result.ErrMsg("Application Failed! "+err.Error()))
return
}
c.JSON(200, result.OkMsg("Application Appliance Complete!"))
return
}
// 不指定申请直接应用而是退回
if body.ApplyId == "" && body.BackId != "" && body.Status == "3" {
ids := strings.Split(body.BackId, ",")
num := 0
for _, id := range ids {
applyInfo := s.ptNeConfigApplyService.SelectById(id)
if applyInfo.ID == "" || applyInfo.Status != "0" {
continue
}
applyInfo.UpdateBy = currentUserName
applyInfo.Status = body.Status
applyInfo.BackInfo = body.BackInfo
s.ptNeConfigApplyService.Update(applyInfo)
num++
}
c.JSON(200, result.OkMsg(fmt.Sprintf("Application Return %d Complete!", num)))
return
}
applyInfo := s.ptNeConfigApplyService.SelectById(body.ApplyId)
if applyInfo.ID != body.ApplyId || applyInfo.Status != "0" {
// 申请信息不正确!
c.JSON(200, result.ErrMsg("Application Information Is Incorrect!"))
return
}
// 退回
if body.Status == "3" {
applyInfos.UpdateBy = currentUserName
applyInfos.Status = "3"
applyInfos.BackInfo = body.BackInfo
s.ptNeConfigApplyService.Update(applyInfos)
applyInfo.UpdateBy = currentUserName
applyInfo.Status = body.Status
applyInfo.BackInfo = body.BackInfo
s.ptNeConfigApplyService.Update(applyInfo)
c.JSON(200, result.OkMsg("Application Return Complete!"))
return
}
// 应用
if body.Status == "2" {
if err := s.ptNeConfigDataService.ApplyToNe(applyInfos.CreateBy, applyInfos.NeType); err != nil {
if err := s.ptNeConfigDataService.ApplyToNe(applyInfo.CreateBy, applyInfo.NeType); err != nil {
c.JSON(200, result.ErrMsg("Application Failed! "+err.Error()))
return
}
applyInfos.UpdateBy = currentUserName
applyInfos.Status = "1"
applyInfos.BackInfo = ""
s.ptNeConfigApplyService.Update(applyInfos)
applyInfo.UpdateBy = currentUserName
applyInfo.Status = body.Status
applyInfo.BackInfo = ""
s.ptNeConfigApplyService.Update(applyInfo)
c.JSON(200, result.OkMsg("Application Appliance Complete!"))
return
}

View File

@@ -210,7 +210,7 @@ func (r *PtNeConfigDataService) SelectByStubType(param model.PtNeConfigData) mod
// ApplyToNe 参数应用到网元
func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
ptConfs := r.SelectList(model.PtNeConfigData{CreateBy: paramUser, StubType: "2", NeType: neType})
ptConfs := r.SelectList(model.PtNeConfigData{CreateBy: paramUser, NeType: neType})
if len(ptConfs) == 0 {
return fmt.Errorf("NeConfigData Not Found")
}