feat: 网元参数配置应用申请功能接口
This commit is contained in:
145
src/modules/practical_training/controller/pt_ne_config_apply.go
Normal file
145
src/modules/practical_training/controller/pt_ne_config_apply.go
Normal file
@@ -0,0 +1,145 @@
|
||||
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 /
|
||||
func (s *PtNeConfigApplyController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id, idOk := c.GetQuery("id")
|
||||
if !idOk {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.ptNeConfigApplyService.SelectById(id)
|
||||
|
||||
c.JSON(200, result.OkData(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
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// NewPtNeConfigData 网元参数配置服务 实例化控制层
|
||||
var NewPtNeConfigData = &PtNeConfigData{
|
||||
// NewPtNeConfigData 实例化控制层
|
||||
var NewPtNeConfigData = &PtNeConfigDataController{
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
@@ -24,7 +24,7 @@ var NewPtNeConfigData = &PtNeConfigData{
|
||||
// 网元参数配置服务
|
||||
//
|
||||
// PATH /neConfigData
|
||||
type PtNeConfigData struct {
|
||||
type PtNeConfigDataController struct {
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
@@ -36,7 +36,7 @@ type PtNeConfigData struct {
|
||||
// 保存为示例配置 (仅管理员/教师操作)
|
||||
//
|
||||
// POST /saveAsDefault
|
||||
func (s *PtNeConfigData) SaveAsDefault(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) SaveAsDefault(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
@@ -72,7 +72,7 @@ func (s *PtNeConfigData) SaveAsDefault(c *gin.Context) {
|
||||
// 重置为示例配置 (仅学生/教师操作)
|
||||
//
|
||||
// POST /resetAsDefault
|
||||
func (s *PtNeConfigData) ResetAsDefault(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) ResetAsDefault(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
@@ -101,7 +101,7 @@ func (s *PtNeConfigData) ResetAsDefault(c *gin.Context) {
|
||||
// 网元参数配置信息
|
||||
//
|
||||
// GET /
|
||||
func (s *PtNeConfigData) Info(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
@@ -133,7 +133,7 @@ func (s *PtNeConfigData) Info(c *gin.Context) {
|
||||
// 网元参数配置修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.PtNeConfigData
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
@@ -228,7 +228,7 @@ func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
// 网元参数配置新增(array)
|
||||
//
|
||||
// POST /
|
||||
func (s *PtNeConfigData) Add(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.PtNeConfigData
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
@@ -316,7 +316,7 @@ func (s *PtNeConfigData) Add(c *gin.Context) {
|
||||
// 网元参数配置删除(array)
|
||||
//
|
||||
// DELETE /
|
||||
func (s *PtNeConfigData) Remove(c *gin.Context) {
|
||||
func (s *PtNeConfigDataController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
Index int64 `form:"index" binding:"required"` //定位变更数据项
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataLog 实例化控制层 PtNeConfigDataLog
|
||||
// NewPtNeConfigDataLog 实例化控制层
|
||||
var NewPtNeConfigDataLog = &PtNeConfigDataLog{
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
}
|
||||
|
||||
18
src/modules/practical_training/model/pt_ne_config_apply.go
Normal file
18
src/modules/practical_training/model/pt_ne_config_apply.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// PtNeConfigApply 实训教学_网元参数配置应用下发申请
|
||||
type PtNeConfigApply struct {
|
||||
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // ID
|
||||
CreateBy string `json:"createBy" gorm:"create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"update_time"` // 更新时间
|
||||
NeType string `json:"neType" gorm:"ne_type"` // 网元类型
|
||||
Status string `json:"status" gorm:"status"` // 应用状态 0申请 1撤回 2应用 3退回
|
||||
BackInfo string `json:"backInfo" gorm:"back_info"` // 退回信息
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (*PtNeConfigApply) TableName() string {
|
||||
return "pt_ne_config_apply"
|
||||
}
|
||||
@@ -16,33 +16,33 @@ func Setup(router *gin.Engine) {
|
||||
ptGroup := router.Group("/pt")
|
||||
|
||||
// 网元参数配置
|
||||
paramConfigGroup := ptGroup.Group("/neConfigData")
|
||||
neConfigDataGroup := ptGroup.Group("/neConfigData")
|
||||
{
|
||||
paramConfigGroup.POST("/saveAsDefault",
|
||||
neConfigDataGroup.POST("/saveAsDefault",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"admin", "teacher"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewPtNeConfigData.SaveAsDefault,
|
||||
)
|
||||
paramConfigGroup.POST("/resetAsDefault",
|
||||
neConfigDataGroup.POST("/resetAsDefault",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"student", "teacher"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewPtNeConfigData.ResetAsDefault,
|
||||
)
|
||||
paramConfigGroup.GET("",
|
||||
neConfigDataGroup.GET("",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigData.Info,
|
||||
)
|
||||
paramConfigGroup.POST("",
|
||||
neConfigDataGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewPtNeConfigData.Add,
|
||||
)
|
||||
paramConfigGroup.PUT("",
|
||||
neConfigDataGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewPtNeConfigData.Edit,
|
||||
)
|
||||
paramConfigGroup.DELETE("/",
|
||||
neConfigDataGroup.DELETE("/",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewPtNeConfigData.Remove,
|
||||
@@ -50,17 +50,35 @@ func Setup(router *gin.Engine) {
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志
|
||||
paramConfigLogGroup := ptGroup.Group("/neConfigDataLog")
|
||||
neConfigDataLogGroup := ptGroup.Group("/neConfigDataLog")
|
||||
{
|
||||
paramConfigLogGroup.GET("",
|
||||
neConfigDataLogGroup.GET("",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigDataLog.Info,
|
||||
)
|
||||
paramConfigLogGroup.DELETE("",
|
||||
neConfigDataLogGroup.DELETE("",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"admin"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigDataLog", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewPtNeConfigDataLog.Remove,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元参数配置应用申请
|
||||
neConfigApplyGroup := ptGroup.Group("/neConfigApply")
|
||||
{
|
||||
neConfigApplyGroup.GET("",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigApply.Info,
|
||||
)
|
||||
neConfigApplyGroup.POST("",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"student"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigApply", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewPtNeConfigApply.Add,
|
||||
)
|
||||
neConfigApplyGroup.PUT("",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"teacher", "admin"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigApply", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewPtNeConfigApply.Edit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/practical_training/model"
|
||||
|
||||
// IPtNeConfigApplyRepository 数据层接口
|
||||
type IPtNeConfigApplyRepository interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(paramIds []string) []model.PtNeConfigApply
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigApply) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigApply) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) int64
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
// NewPtNeConfigApplyRepository 实例化数据层
|
||||
var NewPtNeConfigApplyRepository = &PtNeConfigApplyRepository{
|
||||
selectSql: `select
|
||||
id, create_by, create_time, update_by, update_time, back_info,
|
||||
status, ne_type
|
||||
from pt_ne_config_apply`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"create_by": "CreateBy",
|
||||
"create_time": "CreateTime",
|
||||
"update_by": "UpdateBy",
|
||||
"update_time": "UpdateTime",
|
||||
"ne_type": "NeType",
|
||||
"status": "Status",
|
||||
"back_info": "BackInfo",
|
||||
},
|
||||
}
|
||||
|
||||
// PtNeConfigApplyRepository 数据层处理
|
||||
type PtNeConfigApplyRepository struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *PtNeConfigApplyRepository) convertResultRows(rows []map[string]any) []model.PtNeConfigApply {
|
||||
arr := make([]model.PtNeConfigApply, 0)
|
||||
for _, row := range rows {
|
||||
item := model.PtNeConfigApply{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *PtNeConfigApplyRepository) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["status"]; ok && v != "" {
|
||||
conditions = append(conditions, "status = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": int64(0),
|
||||
"rows": []model.PtNeConfigApply{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from pt_ne_config_apply"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
if total := parse.Number(totalRows[0]["total"]); total > 0 {
|
||||
result["total"] = total
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *PtNeConfigApplyRepository) SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if param.CreateBy != "" {
|
||||
conditions = append(conditions, "create_by = ?")
|
||||
params = append(params, param.CreateBy)
|
||||
}
|
||||
if param.Status != "" {
|
||||
conditions = append(conditions, "status = ?")
|
||||
params = append(params, param.Status)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, param.NeType)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by id asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigApplyRepository) SelectByIds(paramIds []string) []model.PtNeConfigApply {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(paramIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(paramIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.PtNeConfigApply{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigApplyRepository) Insert(param model.PtNeConfigApply) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.CreateBy != "" {
|
||||
params["create_by"] = param.CreateBy
|
||||
params["create_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
params["back_info"] = param.BackInfo
|
||||
if param.Status != "" {
|
||||
params["status"] = param.Status
|
||||
}
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into pt_ne_config_apply (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
tx := datasource.DefaultDB().Begin() // 开启事务
|
||||
// 执行插入
|
||||
if err := tx.Exec(sql, values...).Error; err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
if err := tx.Raw("select last_insert_id()").Row().Scan(&insertedID); err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
tx.Commit() // 提交事务
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *PtNeConfigApplyRepository) Update(param model.PtNeConfigApply) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.UpdateBy != "" {
|
||||
params["update_by"] = param.UpdateBy
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
params["back_info"] = param.BackInfo
|
||||
if param.Status != "" {
|
||||
params["status"] = param.Status
|
||||
}
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update pt_ne_config_apply set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, param.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *PtNeConfigApplyRepository) DeleteByIds(paramIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(paramIds))
|
||||
sql := "delete from pt_ne_config_apply where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(paramIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
26
src/modules/practical_training/service/pt_ne_config_apply.go
Normal file
26
src/modules/practical_training/service/pt_ne_config_apply.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
// IPtNeConfigApplyService 服务层接口
|
||||
type IPtNeConfigApplyService interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(paramId string) model.PtNeConfigApply
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigApply) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigApply) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
)
|
||||
|
||||
// NewPtNeConfigApplyService 实例化服务层
|
||||
var NewPtNeConfigApplyService = &PtNeConfigApplyService{
|
||||
ptNeConfigApplyRepository: repository.NewPtNeConfigApplyRepository,
|
||||
}
|
||||
|
||||
// PtNeConfigApplyService 服务层处理
|
||||
type PtNeConfigApplyService struct {
|
||||
// 实训教学_网元参数配置表
|
||||
ptNeConfigApplyRepository repository.IPtNeConfigApplyRepository
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigApplyService) SelectPage(query map[string]any) map[string]any {
|
||||
return r.ptNeConfigApplyRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigApplyService) SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply {
|
||||
return r.ptNeConfigApplyRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigApplyService) SelectById(paramId string) model.PtNeConfigApply {
|
||||
if paramId == "" {
|
||||
return model.PtNeConfigApply{}
|
||||
}
|
||||
neHosts := r.ptNeConfigApplyRepository.SelectByIds([]string{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigApply{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigApplyService) Insert(param model.PtNeConfigApply) string {
|
||||
return r.ptNeConfigApplyRepository.Insert(param)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *PtNeConfigApplyService) Update(param model.PtNeConfigApply) int64 {
|
||||
return r.ptNeConfigApplyRepository.Update(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *PtNeConfigApplyService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.ptNeConfigApplyRepository.SelectByIds(paramIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("ptNeConfigApply.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(paramIds) {
|
||||
rows := r.ptNeConfigApplyRepository.DeleteByIds(paramIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
Reference in New Issue
Block a user