140 lines
4.0 KiB
Go
140 lines
4.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"be.ems/src/framework/i18n"
|
|
"be.ems/src/framework/utils/ctx"
|
|
"be.ems/src/framework/vo/result"
|
|
"be.ems/src/modules/practical_training/model"
|
|
"be.ems/src/modules/practical_training/service"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
)
|
|
|
|
// NewPtNeConfigApply 实例化控制层
|
|
var NewPtNeConfigApply = &PtNeConfigApplyController{
|
|
ptNeConfigApplyService: service.NewPtNeConfigApplyService,
|
|
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
|
}
|
|
|
|
// 网元参数配置应用申请
|
|
//
|
|
// PATH /neConfigApply
|
|
type PtNeConfigApplyController struct {
|
|
// 实训教学_网元参数配置应用申请服务
|
|
ptNeConfigApplyService service.IPtNeConfigApplyService
|
|
// 实训教学_网元参数配置服务
|
|
ptNeConfigDataService service.IPtNeConfigDataService
|
|
}
|
|
|
|
// 网元参数配置应用申请列表
|
|
//
|
|
// GET /list
|
|
func (s *PtNeConfigApplyController) List(c *gin.Context) {
|
|
querys := ctx.QueryMap(c)
|
|
data := s.ptNeConfigApplyService.SelectPage(querys)
|
|
|
|
c.JSON(200, result.Ok(data))
|
|
}
|
|
|
|
// 网元参数配置应用申请提交(仅学生操作)
|
|
//
|
|
// POST /
|
|
func (s *PtNeConfigApplyController) Add(c *gin.Context) {
|
|
language := ctx.AcceptLanguage(c)
|
|
var body struct {
|
|
NeType string `json:"neType" binding:"required"` // 网元类型
|
|
Status string `json:"status" binding:"required,oneof=0 1"` // 状态 0申请 1撤回
|
|
}
|
|
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
|
return
|
|
}
|
|
|
|
currentUserName := ctx.LoginUserToUserName(c)
|
|
applyInfos := s.ptNeConfigApplyService.SelectList(model.PtNeConfigApply{
|
|
CreateBy: currentUserName,
|
|
Status: "0",
|
|
NeType: body.NeType,
|
|
})
|
|
|
|
// 申请
|
|
if body.Status == "0" {
|
|
// 申请中
|
|
if len(applyInfos) > 0 {
|
|
c.JSON(200, result.OkMsg("Application In Progress"))
|
|
return
|
|
}
|
|
s.ptNeConfigApplyService.Insert(model.PtNeConfigApply{
|
|
CreateBy: currentUserName,
|
|
Status: "0",
|
|
NeType: body.NeType,
|
|
})
|
|
c.JSON(200, result.OkMsg("Application Submission Complete!"))
|
|
return
|
|
}
|
|
|
|
// 撤回
|
|
if body.Status == "1" {
|
|
// 没申请
|
|
if len(applyInfos) == 0 {
|
|
c.JSON(200, result.OkMsg("No Revocable Applications"))
|
|
return
|
|
}
|
|
for _, v := range applyInfos {
|
|
v.UpdateBy = currentUserName
|
|
v.Status = "1"
|
|
s.ptNeConfigApplyService.Update(v)
|
|
}
|
|
c.JSON(200, result.OkMsg("Application Revocable Complete!"))
|
|
return
|
|
}
|
|
}
|
|
|
|
// 网元参数配置应用申请状态变更(仅管理员/教师操作)
|
|
//
|
|
// PUT /
|
|
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"` // 网元类型
|
|
Status string `json:"status" binding:"required,oneof=2 3"` // 状态 2应用 3退回
|
|
BackInfo string `json:"backInfo"` // 退回信息
|
|
}
|
|
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
|
return
|
|
}
|
|
|
|
currentUserName := ctx.LoginUserToUserName(c)
|
|
applyInfos := s.ptNeConfigApplyService.SelectById(body.ApplyId)
|
|
if applyInfos.ID != body.ApplyId || applyInfos.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)
|
|
c.JSON(200, result.OkMsg("Application Return Complete!"))
|
|
return
|
|
}
|
|
|
|
// 应用
|
|
if body.Status == "2" {
|
|
if err := s.ptNeConfigDataService.ApplyToNe(applyInfos.CreateBy, applyInfos.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)
|
|
c.JSON(200, result.OkMsg("Application Appliance Complete!"))
|
|
return
|
|
}
|
|
}
|