feat: 实训教学模块
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/service"
|
||||
@@ -23,10 +24,8 @@ var NewPtNeConfigApply = &PtNeConfigApplyController{
|
||||
//
|
||||
// PATH /neConfigApply
|
||||
type PtNeConfigApplyController struct {
|
||||
// 实训教学_网元参数配置应用申请服务
|
||||
ptNeConfigApplyService service.IPtNeConfigApplyService
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
ptNeConfigApplyService *service.PtNeConfigApplyService // 实训教学_网元参数配置应用申请服务
|
||||
ptNeConfigDataService *service.PtNeConfigDataService // 实训教学_网元参数配置服务
|
||||
}
|
||||
|
||||
// 班级学生列表 (仅教师操作)
|
||||
@@ -44,9 +43,8 @@ func (s *PtNeConfigApplyController) Students(c *gin.Context) {
|
||||
// GET /list
|
||||
func (s *PtNeConfigApplyController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.ptNeConfigApplyService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
total, rows := s.ptNeConfigApplyService.SelectPage(querys)
|
||||
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
|
||||
}
|
||||
|
||||
// 网元参数配置应用申请提交(仅学生操作)
|
||||
@@ -109,7 +107,7 @@ 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"` // 申请ID
|
||||
ApplyId int64 `json:"applyId"` // 申请ID
|
||||
NeType string `json:"neType"` // 网元类型
|
||||
Status string `json:"status" binding:"required,oneof=2 3"` // 状态 2应用 3退回
|
||||
BackInfo string `json:"backInfo"` // 退回信息
|
||||
@@ -123,7 +121,7 @@ func (s *PtNeConfigApplyController) Edit(c *gin.Context) {
|
||||
currentUserName := ctx.LoginUserToUserName(c)
|
||||
|
||||
// 指定有申请的学生直接应用 (管理/教师自身操作)
|
||||
if body.ApplyId == "" && body.NeType != "" && body.Student != "" {
|
||||
if body.ApplyId <= 0 && body.NeType != "" && body.Student != "" {
|
||||
applyInfos := s.ptNeConfigApplyService.SelectList(model.PtNeConfigApply{CreateBy: body.Student, NeType: body.NeType, Status: "0"})
|
||||
if len(applyInfos) == 0 {
|
||||
// 未找到申请信息
|
||||
@@ -163,7 +161,7 @@ func (s *PtNeConfigApplyController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 不指定申请直接应用 (管理/教师自身操作)
|
||||
if body.ApplyId == "" && body.NeType != "" && body.Status == "2" {
|
||||
if body.ApplyId <= 0 && body.NeType != "" && body.Status == "2" {
|
||||
if body.Student != "" {
|
||||
currentUserName = body.Student
|
||||
}
|
||||
@@ -176,12 +174,12 @@ func (s *PtNeConfigApplyController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 不指定申请直接应用而是批量退回
|
||||
if body.ApplyId == "" && body.BackId != "" && body.Status == "3" {
|
||||
if body.ApplyId <= 0 && 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" {
|
||||
applyInfo := s.ptNeConfigApplyService.SelectById(parse.Number(id))
|
||||
if applyInfo.ID <= 0 || applyInfo.Status != "0" {
|
||||
continue
|
||||
}
|
||||
applyInfo.UpdateBy = currentUserName
|
||||
|
||||
@@ -18,18 +18,16 @@ import (
|
||||
|
||||
// NewPtNeConfigData 实例化控制层
|
||||
var NewPtNeConfigData = &PtNeConfigDataController{
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
ptNeConfigDataService: *service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: *service.NewPtNeConfigDataLogService,
|
||||
}
|
||||
|
||||
// 网元参数配置服务
|
||||
//
|
||||
// PATH /neConfigData
|
||||
type PtNeConfigDataController struct {
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
ptNeConfigDataLogService service.IPtNeConfigDataLogService
|
||||
ptNeConfigDataService service.PtNeConfigDataService // 实训教学_网元参数配置服务
|
||||
ptNeConfigDataLogService service.PtNeConfigDataLogService // 实训教学_网元参数配置数据变更日志服务
|
||||
}
|
||||
|
||||
// 保存为示例配置 (仅管理员操作)
|
||||
@@ -252,7 +250,7 @@ func (s *PtNeConfigDataController) Edit(c *gin.Context) {
|
||||
ParamData map[string]any `json:"paramData" binding:"required"`
|
||||
Loc string `json:"loc"` // 仅array使用与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index)
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,10 +23,8 @@ var NewPtNeConfigDataLog = &PtNeConfigDataLog{
|
||||
//
|
||||
// PATH /neConfigDataLog
|
||||
type PtNeConfigDataLog struct {
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
ptNeConfigDataLogService service.IPtNeConfigDataLogService
|
||||
ptNeConfigDataService *service.PtNeConfigDataService // 实训教学_网元参数配置服务
|
||||
ptNeConfigDataLogService *service.PtNeConfigDataLogService // 实训教学_网元参数配置数据变更日志服务
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志列表
|
||||
@@ -56,9 +54,8 @@ func (s *PtNeConfigDataLog) Info(c *gin.Context) {
|
||||
}
|
||||
query["stubType"] = stubType
|
||||
query["createBy"] = currentUserName
|
||||
data := s.ptNeConfigDataLogService.SelectPage(query)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
total, rows := s.ptNeConfigDataLogService.SelectPage(query)
|
||||
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志还原到数据
|
||||
@@ -67,7 +64,7 @@ func (s *PtNeConfigDataLog) Info(c *gin.Context) {
|
||||
func (s *PtNeConfigDataLog) Restore(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID string `json:"id" binding:"required"` // 变更日志ID
|
||||
ID int64 `json:"id" binding:"required"` // 变更日志ID
|
||||
Value string `json:"value" binding:"required,oneof=old new"` // 还原属性 old旧信息 new新信息
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
@@ -134,11 +131,19 @@ func (s *PtNeConfigDataLog) Remove(c *gin.Context) {
|
||||
// 处理字符转id数组后去重
|
||||
idsArr := strings.Split(id, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(idsArr)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
ids := []int64{}
|
||||
for _, v := range uniqueIDs {
|
||||
id := parse.Number(v)
|
||||
if id <= 0 {
|
||||
continue
|
||||
}
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
if len(ids) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.ptNeConfigDataLogService.DeleteByIds(uniqueIDs)
|
||||
rows, err := s.ptNeConfigDataLogService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
|
||||
249
src/modules/practical_training/controller/pt_sys_user.go
Normal file
249
src/modules/practical_training/controller/pt_sys_user.go
Normal file
@@ -0,0 +1,249 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/config"
|
||||
"be.ems/src/framework/constants/common"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/system/model"
|
||||
"be.ems/src/modules/system/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysUserController 结构体
|
||||
var NewSysUser = &PtSysUserController{
|
||||
sysUserService: service.NewSysUserImpl,
|
||||
sysDictDataService: service.NewSysDictData,
|
||||
sysConfigService: service.NewSysConfigImpl,
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
//
|
||||
// PATH /pt/system/user
|
||||
type PtSysUserController struct {
|
||||
sysUserService service.ISysUser // 用户服务
|
||||
sysDictDataService *service.SysDictData // 字典数据服务
|
||||
sysConfigService service.ISysConfig // 参数配置服务
|
||||
}
|
||||
|
||||
// 用户信息列表导入模板下载
|
||||
//
|
||||
// GET /importTemplate
|
||||
func (s *PtSysUserController) Template(c *gin.Context) {
|
||||
// 多语言处理
|
||||
language := ctx.AcceptLanguage(c)
|
||||
// 登录用户
|
||||
loginUser, err := ctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
// 根据角色指定导入模板
|
||||
fileKey := "user"
|
||||
roles := loginUser.User.Roles
|
||||
if len(roles) == 1 && roles[0].RoleKey == "teacher" {
|
||||
fileKey = "student"
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("%s_import_template_%d.xlsx", fileKey, time.Now().UnixMilli())
|
||||
asserPath := fmt.Sprintf("assets/template/excel/%s_import_template_%s.xlsx", fileKey, language)
|
||||
|
||||
// 从 embed.FS 中读取默认配置文件内容
|
||||
assetsDir := config.GetAssetsDirFS()
|
||||
// 读取内嵌文件
|
||||
fileData, err := assetsDir.ReadFile(asserPath)
|
||||
if err != nil {
|
||||
c.String(500, "Failed to read file")
|
||||
return
|
||||
}
|
||||
|
||||
// 设置响应头
|
||||
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileName))
|
||||
c.Header("Content-Type", "application/octet-stream")
|
||||
|
||||
// 返回响应体
|
||||
c.Data(200, "application/octet-stream", fileData)
|
||||
}
|
||||
|
||||
// 用户信息列表导入
|
||||
//
|
||||
// POST /importData
|
||||
func (s *PtSysUserController) ImportData(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
// 登录用户
|
||||
loginUser, err := ctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
// 允许进行更新
|
||||
updateSupport := c.PostForm("updateSupport")
|
||||
// 上传的文件
|
||||
formFile, err := c.FormFile("file")
|
||||
if err != nil || updateSupport == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 保存表格文件
|
||||
filePath, err := file.TransferExeclUploadFile(formFile)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 读取表格数据
|
||||
rows, err := file.ReadSheet(filePath, "")
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 根据角色指定导入模板
|
||||
roleKey := ""
|
||||
roles := loginUser.User.Roles
|
||||
if len(roles) == 1 && roles[0].RoleKey == "teacher" {
|
||||
roleKey = "student"
|
||||
}
|
||||
// 获取操作人名称
|
||||
operName := ctx.LoginUserToUserName(c)
|
||||
isUpdateSupport := parse.Boolean(updateSupport)
|
||||
|
||||
// 读取默认初始密码
|
||||
initPassword := s.sysConfigService.SelectConfigValueByKey("sys.user.initPassword")
|
||||
// 读取用户性别字典数据
|
||||
dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
|
||||
|
||||
// 导入记录
|
||||
successNum := 0
|
||||
failureNum := 0
|
||||
successMsgArr := []string{}
|
||||
failureMsgArr := []string{}
|
||||
mustItemArr := []string{"B", "C"}
|
||||
for _, row := range rows {
|
||||
// 检查必填列
|
||||
ownItem := true
|
||||
for _, item := range mustItemArr {
|
||||
if v, ok := row[item]; !ok || v == "" {
|
||||
ownItem = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if !ownItem {
|
||||
mustItemArrStr := strings.Join(mustItemArr, "、")
|
||||
failureNum++
|
||||
// 表格中必填列表项,
|
||||
msg := i18n.TTemplate(language, "user.import.mustItem", map[string]any{"text": mustItemArrStr})
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
continue
|
||||
}
|
||||
|
||||
// 用户性别转值
|
||||
sysUserSex := "0"
|
||||
for _, v := range dictSysUserSex {
|
||||
label := i18n.TKey(language, v.DictLabel)
|
||||
if row["D"] == label {
|
||||
sysUserSex = v.DictValue
|
||||
break
|
||||
}
|
||||
}
|
||||
// 用户状态
|
||||
sysUserStatus := common.STATUS_NO
|
||||
if row["E"] == "正常" || row["G"] == "Normal" {
|
||||
sysUserStatus = common.STATUS_YES
|
||||
}
|
||||
|
||||
sysUserRole := "" // 用户角色
|
||||
sysUserPost := "" // 用户岗位
|
||||
sysUserDept := "101" // 用户部门 101未指定
|
||||
if roleKey == "student" {
|
||||
sysUserRole = "4"
|
||||
sysUserPost = "3"
|
||||
sysUserDept = loginUser.DeptID
|
||||
}
|
||||
if v, ok := row["F"]; ok && v != "" {
|
||||
if v == "学生" || v == "Student" {
|
||||
sysUserRole = "4"
|
||||
sysUserPost = "3"
|
||||
} else if v == "教师" || v == "Teacher" {
|
||||
sysUserRole = "3"
|
||||
sysUserPost = "2"
|
||||
}
|
||||
}
|
||||
if v, ok := row["G"]; ok && v != "" && v != "100" {
|
||||
sysUserDept = v
|
||||
}
|
||||
|
||||
// 构建用户实体信息
|
||||
newSysUser := model.SysUser{
|
||||
UserType: "sys",
|
||||
Password: initPassword,
|
||||
DeptID: sysUserDept,
|
||||
UserName: row["B"],
|
||||
NickName: row["C"],
|
||||
Status: sysUserStatus,
|
||||
Sex: sysUserSex,
|
||||
RoleIDs: []string{sysUserRole},
|
||||
PostIDs: []string{sysUserPost},
|
||||
}
|
||||
|
||||
// 验证是否存在这个用户
|
||||
userInfo := s.sysUserService.SelectUserByUserName(newSysUser.UserName)
|
||||
if userInfo.UserName != newSysUser.UserName {
|
||||
newSysUser.CreateBy = operName
|
||||
insertId := s.sysUserService.InsertUser(newSysUser)
|
||||
if insertId != "" {
|
||||
// 用户编号:%s 登录名称 %s 导入成功
|
||||
msg := i18n.TTemplate(language, "user.import.success", map[string]any{"id": row["A"], "name": newSysUser.UserName})
|
||||
successNum++
|
||||
successMsgArr = append(successMsgArr, msg)
|
||||
} else {
|
||||
// 用户编号:%s 登录名称 %s 导入失败
|
||||
msg := i18n.TTemplate(language, "user.import.fail", map[string]any{"id": row["A"], "name": newSysUser.UserName})
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果用户已存在 同时 是否更新支持
|
||||
if userInfo.UserName == newSysUser.UserName && isUpdateSupport {
|
||||
newSysUser.UserID = userInfo.UserID
|
||||
newSysUser.UpdateBy = operName
|
||||
rows := s.sysUserService.UpdateUser(newSysUser)
|
||||
if rows > 0 {
|
||||
// 用户编号:%s 登录名称 %s 更新成功
|
||||
msg := i18n.TTemplate(language, "user.import.successUpdate", map[string]any{"id": row["A"], "name": newSysUser.UserName})
|
||||
successNum++
|
||||
successMsgArr = append(successMsgArr, msg)
|
||||
} else {
|
||||
// 用户编号:%s 登录名称 %s 更新失败
|
||||
msg := i18n.TTemplate(language, "user.import.failUpdate", map[string]any{"id": row["A"], "name": newSysUser.UserName})
|
||||
failureNum++
|
||||
failureMsgArr = append(failureMsgArr, msg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
message := ""
|
||||
if failureNum > 0 {
|
||||
// 很抱歉,导入失败!共 %d 条数据格式不正确,错误如下:
|
||||
msg := i18n.TTemplate(language, "user.import.failTip", map[string]any{"num": failureNum})
|
||||
message = strings.Join(append([]string{msg}, failureMsgArr...), "<br/>")
|
||||
} else {
|
||||
// 恭喜您,数据已全部导入成功!共 %d 条,数据如下:
|
||||
msg := i18n.TTemplate(language, "user.import.successTip", map[string]any{"num": successNum})
|
||||
message = strings.Join(append([]string{msg}, successMsgArr...), "<br/>")
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkMsg(message))
|
||||
}
|
||||
@@ -2,14 +2,14 @@ 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"` // 退回信息
|
||||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // ID
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
NeType string `json:"neType" gorm:"column:ne_type"` // 网元类型
|
||||
Status string `json:"status" gorm:"column:status"` // 应用状态 0申请 1撤回 2应用 3退回
|
||||
BackInfo string `json:"backInfo" gorm:"column:back_info"` // 退回信息
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
|
||||
@@ -2,19 +2,19 @@ package model
|
||||
|
||||
// PtNeConfigData 实训教学_网元参数配置数据信息
|
||||
type PtNeConfigData 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"` // 更新时间
|
||||
Remark string `json:"remark" gorm:"remark"` // 备注
|
||||
StubType string `json:"stubType" gorm:"stub_type"` // 存根数据类型 0系统 1班级 2个人
|
||||
NeType string `json:"neType" gorm:"ne_type"` // 网元类型
|
||||
ParamName string `json:"paramName" gorm:"param_name"` // 参数名
|
||||
ParamDisplay string `json:"paramDisplay" gorm:"param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJson string `json:"paramJson" gorm:"param_json"` // 参数数据
|
||||
DeptId string `json:"deptId" gorm:"dept_id"` // 部门班级ID 100系统
|
||||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // 默认ID
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
Remark string `json:"remark" gorm:"column:remark"` // 备注
|
||||
StubType string `json:"stubType" gorm:"column:stub_type"` // 存根数据类型 0系统 1班级 2个人
|
||||
NeType string `json:"neType" gorm:"column:ne_type"` // 网元类型
|
||||
ParamName string `json:"paramName" gorm:"column:param_name"` // 参数名
|
||||
ParamDisplay string `json:"paramDisplay" gorm:"column:param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"column:param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJson string `json:"paramJson" gorm:"column:param_json"` // 参数数据
|
||||
DeptId string `json:"deptId" gorm:"column:dept_id"` // 部门班级ID 100系统
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
|
||||
@@ -2,17 +2,17 @@ package model
|
||||
|
||||
// PtNeConfigDataLog 实训教学_网元参数配置数据变更日志
|
||||
type PtNeConfigDataLog 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"` // 创建时间
|
||||
StubType string `json:"stubType" gorm:"stub_type"` // 存根数据类型 0系统 1班级 2个人
|
||||
NeType string `json:"neType" gorm:"ne_type"` // 网元类型
|
||||
ParamName string `json:"paramName" gorm:"param_name"` // 参数名
|
||||
ParamDisplay string `json:"paramDisplay" gorm:"param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJsonOld string `json:"paramJsonOld" gorm:"param_json_old"` // 原始内容
|
||||
ParamJsonNew string `json:"paramJsonNew" gorm:"param_json_new"` // 当前内容
|
||||
OperaType int64 `json:"operaType" gorm:"opera_type"` // 操作类型 0其他 1新增 2更新 3删除
|
||||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // ID
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
StubType string `json:"stubType" gorm:"column:stub_type"` // 存根数据类型 0系统 1班级 2个人
|
||||
NeType string `json:"neType" gorm:"column:ne_type"` // 网元类型
|
||||
ParamName string `json:"paramName" gorm:"column:param_name"` // 参数名
|
||||
ParamDisplay string `json:"paramDisplay" gorm:"column:param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"column:param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJsonOld string `json:"paramJsonOld" gorm:"column:param_json_old"` // 原始内容
|
||||
ParamJsonNew string `json:"paramJsonNew" gorm:"column:param_json_new"` // 当前内容
|
||||
OperaType int64 `json:"operaType" gorm:"column:opera_type"` // 操作类型 0其他 1新增 2更新 3删除
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
|
||||
@@ -13,10 +13,8 @@ import (
|
||||
func Setup(router *gin.Engine) {
|
||||
logger.Infof("开始加载 ====> practical_training 模块路由")
|
||||
|
||||
ptGroup := router.Group("/pt")
|
||||
|
||||
// 网元参数配置
|
||||
neConfigDataGroup := ptGroup.Group("/neConfigData")
|
||||
neConfigDataGroup := router.Group("/pt/neConfigData")
|
||||
{
|
||||
neConfigDataGroup.POST("/saveAsDefault",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"admin"}}),
|
||||
@@ -59,7 +57,7 @@ func Setup(router *gin.Engine) {
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志
|
||||
neConfigDataLogGroup := ptGroup.Group("/neConfigDataLog")
|
||||
neConfigDataLogGroup := router.Group("/pt/neConfigDataLog")
|
||||
{
|
||||
neConfigDataLogGroup.GET("",
|
||||
middleware.PreAuthorize(nil),
|
||||
@@ -78,7 +76,7 @@ func Setup(router *gin.Engine) {
|
||||
}
|
||||
|
||||
// 网元参数配置应用申请
|
||||
neConfigApplyGroup := ptGroup.Group("/neConfigApply")
|
||||
neConfigApplyGroup := router.Group("/pt/neConfigApply")
|
||||
{
|
||||
neConfigApplyGroup.GET("/students",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"teacher"}}),
|
||||
@@ -99,4 +97,17 @@ func Setup(router *gin.Engine) {
|
||||
controller.NewPtNeConfigApply.Edit,
|
||||
)
|
||||
}
|
||||
|
||||
// 教学用户
|
||||
systemUserGroup := router.Group("/pt/system/user")
|
||||
{
|
||||
systemUserGroup.GET("/importTemplate",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewSysUser.Template,
|
||||
)
|
||||
systemUserGroup.POST("/importData",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewSysUser.ImportData,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,170 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/practical_training/model"
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
// NewPtNeConfigApplyRepository 实例化数据层
|
||||
var NewPtNeConfigApplyRepository = &PtNeConfigApplyRepository{}
|
||||
|
||||
// PtNeConfigApplyRepository 数据层处理
|
||||
type PtNeConfigApplyRepository struct{}
|
||||
|
||||
// IPtNeConfigApplyRepository 数据层接口
|
||||
type IPtNeConfigApplyRepository interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
func (r *PtNeConfigApplyRepository) SelectPage(query map[string]any) (int64, []model.PtNeConfigApply) {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigApply{})
|
||||
// 查询条件拼接
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
tx = tx.Where("neType = ?", v)
|
||||
}
|
||||
if v, ok := query["status"]; ok && v != "" {
|
||||
tx = tx.Where("status = ?", v)
|
||||
}
|
||||
|
||||
var total int64 = 0
|
||||
rows := []model.PtNeConfigApply{}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
tx = tx.Offset(int(pageNum * pageSize)).Limit(int(pageSize))
|
||||
|
||||
// 排序
|
||||
if v, ok := query["sortField"]; ok && v != "" {
|
||||
sortSql := v.(string)
|
||||
if o, ok := query["sortOrder"]; ok && o != nil && v != "" {
|
||||
if o == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
tx = tx.Order(sortSql)
|
||||
} else {
|
||||
tx = tx.Order("id desc")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply
|
||||
func (r *PtNeConfigApplyRepository) SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigApply{})
|
||||
// 查询条件拼接
|
||||
if param.CreateBy != "" {
|
||||
tx = tx.Where("create_by = ?", param.CreateBy)
|
||||
}
|
||||
if param.Status != "" {
|
||||
tx = tx.Where("status = ?", param.Status)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
tx = tx.Where("ne_type = ?", param.NeType)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
arr := []model.PtNeConfigApply{}
|
||||
if err := tx.Order("id asc").Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(paramIds []string) []model.PtNeConfigApply
|
||||
func (r *PtNeConfigApplyRepository) SelectByIds(paramIds []int64) []model.PtNeConfigApply {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigApply{})
|
||||
arr := []model.PtNeConfigApply{}
|
||||
// 查询条件拼接
|
||||
tx = tx.Where("id in ?", paramIds)
|
||||
// 查询数据
|
||||
if err := tx.Order("imsi asc").Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigApply) string
|
||||
func (r *PtNeConfigApplyRepository) Insert(param model.PtNeConfigApply) int64 {
|
||||
if param.CreateBy != "" {
|
||||
param.CreateTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
if err := datasource.DB("").Create(¶m).Error; err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return param.ID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigApply) int64
|
||||
func (r *PtNeConfigApplyRepository) Update(param model.PtNeConfigApply) int64 {
|
||||
if param.ID <= 0 {
|
||||
return 0
|
||||
}
|
||||
if param.UpdateBy != "" {
|
||||
param.UpdateTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
tx := datasource.DB("").Updates(¶m)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) int64
|
||||
func (r *PtNeConfigApplyRepository) DeleteByIds(paramIds []int64) int64 {
|
||||
tx := datasource.DefaultDB().Where("id in ?", paramIds).Delete(&model.PtNeConfigApply{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
SelectListByClass(deptId, userName string) []map[string]any
|
||||
func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if deptId != "" {
|
||||
conditions = append(conditions, "d.dept_id = ?")
|
||||
params = append(params, deptId)
|
||||
}
|
||||
if userName != "" {
|
||||
conditions = append(conditions, "u.user_name like concat('%',?,'%')")
|
||||
params = append(params, userName)
|
||||
}
|
||||
// 构建查询条件语句
|
||||
whereSql := " where u.del_flag = '0' AND u.user_id != '1' AND ur.role_id = '4' "
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " and " + strings.Join(conditions, " and ")
|
||||
}
|
||||
// 查询数据
|
||||
querySql := `SELECT
|
||||
u.user_Id as userId, u.user_name as userName, u.nick_name as nickName, u.login_ip as loginIp, u.login_date AS loginDate,
|
||||
COALESCE(pnca.id, '') as applyId, COALESCE(pnca.status, '') as applyStatus
|
||||
FROM sys_user u
|
||||
LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
|
||||
LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
|
||||
LEFT JOIN pt_ne_config_apply pnca ON pnca.create_by = u.user_name AND pnca.status = '0'
|
||||
` + whereSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
@@ -1,275 +0,0 @@
|
||||
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 := " ORDER BY id desc 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
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if deptId != "" {
|
||||
conditions = append(conditions, "d.dept_id = ?")
|
||||
params = append(params, deptId)
|
||||
}
|
||||
if userName != "" {
|
||||
conditions = append(conditions, "u.user_name like concat('%',?,'%')")
|
||||
params = append(params, userName)
|
||||
}
|
||||
// 构建查询条件语句
|
||||
whereSql := " where u.del_flag = '0' AND u.user_id != '1' AND ur.role_id = '4' "
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " and " + strings.Join(conditions, " and ")
|
||||
}
|
||||
// 查询数据
|
||||
querySql := `SELECT
|
||||
u.user_Id as userId, u.user_name as userName, u.nick_name as nickName, u.login_ip as loginIp, u.login_date AS loginDate,
|
||||
COALESCE(pnca.id, '') as applyId, COALESCE(pnca.status, '') as applyStatus
|
||||
FROM sys_user u
|
||||
LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
|
||||
LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
|
||||
LEFT JOIN pt_ne_config_apply pnca ON pnca.create_by = u.user_name AND pnca.status = '0'
|
||||
` + whereSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return results
|
||||
}
|
||||
@@ -1,24 +1,152 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/practical_training/model"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataRepository 实例化数据层
|
||||
var NewPtNeConfigDataRepository = &PtNeConfigDataRepository{}
|
||||
|
||||
// PtNeConfigDataRepository 数据层处理
|
||||
type PtNeConfigDataRepository struct{}
|
||||
|
||||
// IPtNeConfigDataRepository 数据层接口
|
||||
type IPtNeConfigDataRepository interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
func (r *PtNeConfigDataRepository) SelectPage(query map[string]any) (int64, []model.PtNeConfigData) {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigData{})
|
||||
// 查询条件拼接
|
||||
if v, ok := query["createBy"]; ok && v != "" {
|
||||
tx = tx.Where("create_by = ?", v)
|
||||
}
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
tx = tx.Where("ne_type = ?", v)
|
||||
}
|
||||
if v, ok := query["stubType"]; ok && v != "" {
|
||||
tx = tx.Where("stub_type = ?", v)
|
||||
}
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
tx = tx.Where("param_name = ?", v)
|
||||
}
|
||||
if v, ok := query["paramType"]; ok && v != "" {
|
||||
tx = tx.Where("param_type = ?", v)
|
||||
}
|
||||
|
||||
var total int64 = 0
|
||||
rows := []model.PtNeConfigData{}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
tx = tx.Offset(int(pageNum * pageSize)).Limit(int(pageSize))
|
||||
|
||||
// 排序
|
||||
if v, ok := query["sortField"]; ok && v != "" {
|
||||
sortSql := v.(string)
|
||||
if o, ok := query["sortOrder"]; ok && o != nil && v != "" {
|
||||
if o == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
tx = tx.Order(sortSql)
|
||||
} else {
|
||||
tx = tx.Order("id desc")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigData) []model.PtNeConfigData
|
||||
func (r *PtNeConfigDataRepository) SelectList(param model.PtNeConfigData) []model.PtNeConfigData {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigData{})
|
||||
// 查询条件拼接
|
||||
if param.CreateBy != "" {
|
||||
tx = tx.Where("create_by = ?", param.CreateBy)
|
||||
}
|
||||
if param.StubType != "" {
|
||||
tx = tx.Where("stub_type = ?", param.StubType)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
tx = tx.Where("ne_type = ?", param.NeType)
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
tx = tx.Where("param_name = ?", param.ParamName)
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
tx = tx.Where("param_type = ?", param.ParamType)
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
tx = tx.Where("dept_id = ?", param.DeptId)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
arr := []model.PtNeConfigData{}
|
||||
if err := tx.Order("update_time asc").Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(paramIds []string) []model.PtNeConfigData
|
||||
func (r *PtNeConfigDataRepository) SelectByIds(paramIds []string) []model.PtNeConfigData {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigData{})
|
||||
arr := []model.PtNeConfigData{}
|
||||
// 查询条件拼接
|
||||
tx = tx.Where("id in ?", paramIds)
|
||||
// 查询数据
|
||||
if err := tx.Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigData) string
|
||||
func (r *PtNeConfigDataRepository) Insert(param model.PtNeConfigData) int64 {
|
||||
if param.CreateBy != "" {
|
||||
param.CreateTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
if err := datasource.DB("").Create(¶m).Error; err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return param.ID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigData) int64
|
||||
func (r *PtNeConfigDataRepository) Update(param model.PtNeConfigData) int64 {
|
||||
if param.ID <= 0 {
|
||||
return 0
|
||||
}
|
||||
if param.UpdateBy != "" {
|
||||
param.UpdateTime = time.Now().UnixMilli()
|
||||
}
|
||||
tx := datasource.DB("").Updates(¶m)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) int64
|
||||
func (r *PtNeConfigDataRepository) DeleteByIds(paramIds []string) int64 {
|
||||
tx := datasource.DefaultDB().Where("id in ?", paramIds).Delete(&model.PtNeConfigDataLog{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
@@ -1,297 +0,0 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataRepository 实例化数据层
|
||||
var NewPtNeConfigDataRepository = &PtNeConfigDataRepository{
|
||||
selectSql: `select
|
||||
id, create_by, create_time, update_by, update_time, remark, stub_type, ne_type, param_name, param_display, param_type, param_json, dept_id
|
||||
from pt_ne_config_data`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"create_by": "CreateBy",
|
||||
"create_time": "CreateTime",
|
||||
"update_by": "UpdateBy",
|
||||
"update_time": "UpdateTime",
|
||||
"remark": "Remark",
|
||||
"stub_type": "StubType",
|
||||
"ne_type": "NeType",
|
||||
"param_name": "ParamName",
|
||||
"param_display": "ParamDisplay",
|
||||
"param_type": "ParamType",
|
||||
"param_json": "ParamJson",
|
||||
"dept_id": "DeptId",
|
||||
},
|
||||
}
|
||||
|
||||
// PtNeConfigDataRepository 数据层处理
|
||||
type PtNeConfigDataRepository struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *PtNeConfigDataRepository) convertResultRows(rows []map[string]any) []model.PtNeConfigData {
|
||||
arr := make([]model.PtNeConfigData, 0)
|
||||
for _, row := range rows {
|
||||
item := model.PtNeConfigData{}
|
||||
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 *PtNeConfigDataRepository) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["paramType"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.PtNeConfigData{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from pt_ne_config_data"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
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 *PtNeConfigDataRepository) SelectList(param model.PtNeConfigData) []model.PtNeConfigData {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if param.CreateBy != "" {
|
||||
conditions = append(conditions, "create_by = ?")
|
||||
params = append(params, param.CreateBy)
|
||||
}
|
||||
if param.StubType != "" {
|
||||
conditions = append(conditions, "stub_type = ?")
|
||||
params = append(params, param.StubType)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, param.NeType)
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, param.ParamName)
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
conditions = append(conditions, "param_type = ?")
|
||||
params = append(params, param.ParamType)
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
conditions = append(conditions, "dept_id = ?")
|
||||
params = append(params, param.DeptId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigDataRepository) SelectByIds(paramIds []string) []model.PtNeConfigData {
|
||||
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.PtNeConfigData{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigDataRepository) Insert(param model.PtNeConfigData) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.CreateBy != "" {
|
||||
params["create_by"] = param.CreateBy
|
||||
params["create_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
params["remark"] = param.Remark
|
||||
if param.StubType != "" {
|
||||
params["stub_type"] = param.StubType
|
||||
}
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
params["dept_id"] = param.DeptId
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into pt_ne_config_data (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *PtNeConfigDataRepository) Update(param model.PtNeConfigData) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.UpdateBy != "" {
|
||||
params["update_by"] = param.UpdateBy
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
params["remark"] = param.Remark
|
||||
if param.StubType != "" {
|
||||
params["stub_type"] = param.StubType
|
||||
}
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
params["dept_id"] = param.DeptId
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update pt_ne_config_data 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 *PtNeConfigDataRepository) DeleteByIds(paramIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(paramIds))
|
||||
sql := "delete from pt_ne_config_data 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
|
||||
}
|
||||
@@ -1,21 +1,143 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/practical_training/model"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataLogRepository 实例化数据层
|
||||
var NewPtNeConfigDataLogRepository = &PtNeConfigDataLogRepository{}
|
||||
|
||||
// PtNeConfigDataLogRepository 数据层处理
|
||||
type PtNeConfigDataLogRepository struct{}
|
||||
|
||||
// IPtNeConfigDataLogRepository 数据层接口
|
||||
type IPtNeConfigDataLogRepository interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
func (r *PtNeConfigDataLogRepository) SelectPage(query map[string]any) (int64, []model.PtNeConfigDataLog) {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigDataLog{})
|
||||
// 查询条件拼接
|
||||
if v, ok := query["createBy"]; ok && v != "" {
|
||||
tx = tx.Where("create_by = ?", v)
|
||||
}
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
tx = tx.Where("ne_type = ?", v)
|
||||
}
|
||||
if v, ok := query["stubType"]; ok && v != "" {
|
||||
tx = tx.Where("stub_type = ?", v)
|
||||
}
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
tx = tx.Where("param_name = ?", v)
|
||||
}
|
||||
if v, ok := query["paramType"]; ok && v != "" {
|
||||
tx = tx.Where("param_type = ?", v)
|
||||
}
|
||||
if v, ok := query["operaType"]; ok && v != "" {
|
||||
tx = tx.Where("opera_type = ?", v)
|
||||
}
|
||||
if v, ok := query["status"]; ok && v != "" {
|
||||
tx = tx.Where("status = ?", v)
|
||||
}
|
||||
|
||||
var total int64 = 0
|
||||
rows := []model.PtNeConfigDataLog{}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
tx = tx.Offset(int(pageNum * pageSize)).Limit(int(pageSize))
|
||||
|
||||
// 排序
|
||||
if v, ok := query["sortField"]; ok && v != "" {
|
||||
sortSql := v.(string)
|
||||
if o, ok := query["sortOrder"]; ok && o != nil && v != "" {
|
||||
if o == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
tx = tx.Order(sortSql)
|
||||
} else {
|
||||
tx = tx.Order("id desc")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
return total, rows
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog
|
||||
func (r *PtNeConfigDataLogRepository) SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigDataLog{})
|
||||
// 查询条件拼接
|
||||
if param.CreateBy != "" {
|
||||
tx = tx.Where("create_by = ?", param.CreateBy)
|
||||
}
|
||||
if param.StubType != "" {
|
||||
tx = tx.Where("stub_type = ?", param.StubType)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
tx = tx.Where("ne_type = ?", param.NeType)
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
tx = tx.Where("param_name = ?", param.ParamName)
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
tx = tx.Where("param_type = ?", param.ParamType)
|
||||
}
|
||||
if param.OperaType > 0 {
|
||||
tx = tx.Where("opera_type = ?", param.OperaType)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
arr := []model.PtNeConfigDataLog{}
|
||||
if err := tx.Order("create_time desc").Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(paramIds []string) []model.PtNeConfigDataLog
|
||||
func (r *PtNeConfigDataLogRepository) SelectByIds(paramIds []int64) []model.PtNeConfigDataLog {
|
||||
tx := datasource.DB("").Model(&model.PtNeConfigDataLog{})
|
||||
arr := []model.PtNeConfigDataLog{}
|
||||
// 查询条件拼接
|
||||
tx = tx.Where("id in ?", paramIds)
|
||||
// 查询数据
|
||||
if err := tx.Order("imsi asc").Find(&arr).Error; err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigDataLog) string
|
||||
func (r *PtNeConfigDataLogRepository) Insert(param model.PtNeConfigDataLog) int64 {
|
||||
if param.CreateBy != "" {
|
||||
param.CreateTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
if err := datasource.DB("").Create(¶m).Error; err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return param.ID
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) int64
|
||||
func (r *PtNeConfigDataLogRepository) DeleteByIds(paramIds []int64) int64 {
|
||||
tx := datasource.DefaultDB().Where("id in ?", paramIds).Delete(&model.PtNeConfigDataLog{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
@@ -1,262 +0,0 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataLogRepository 实例化数据层
|
||||
var NewPtNeConfigDataLogRepository = &PtNeConfigDataLogRepository{
|
||||
selectSql: `select
|
||||
id, create_by, create_time, stub_type, ne_type, param_name, param_display, param_type, param_json_old, param_json_new, opera_type
|
||||
from pt_ne_config_data_log`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"create_by": "CreateBy",
|
||||
"create_time": "CreateTime",
|
||||
"stub_type": "StubType",
|
||||
"ne_type": "NeType",
|
||||
"param_name": "ParamName",
|
||||
"param_display": "ParamDisplay",
|
||||
"param_type": "ParamType",
|
||||
"param_json_old": "ParamJsonOld",
|
||||
"param_json_new": "ParamJsonNew",
|
||||
"opera_type": "OperaType",
|
||||
},
|
||||
}
|
||||
|
||||
// PtNeConfigDataLogRepository 数据层处理
|
||||
type PtNeConfigDataLogRepository struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *PtNeConfigDataLogRepository) convertResultRows(rows []map[string]any) []model.PtNeConfigDataLog {
|
||||
arr := make([]model.PtNeConfigDataLog, 0)
|
||||
for _, row := range rows {
|
||||
item := model.PtNeConfigDataLog{}
|
||||
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 *PtNeConfigDataLogRepository) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["createBy"]; ok && v != "" {
|
||||
conditions = append(conditions, "create_by = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["stubType"]; ok && v != "" {
|
||||
conditions = append(conditions, "stub_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["paramType"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["operaType"]; ok && v != "" {
|
||||
conditions = append(conditions, "opera_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.PtNeConfigDataLog{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from pt_ne_config_data_log"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " ORDER BY create_time desc 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 *PtNeConfigDataLogRepository) SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if param.CreateBy != "" {
|
||||
conditions = append(conditions, "create_by = ?")
|
||||
params = append(params, param.CreateBy)
|
||||
}
|
||||
if param.StubType != "" {
|
||||
conditions = append(conditions, "stub_type = ?")
|
||||
params = append(params, param.StubType)
|
||||
}
|
||||
if param.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, param.NeType)
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, param.ParamName)
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
conditions = append(conditions, "param_type = ?")
|
||||
params = append(params, param.ParamType)
|
||||
}
|
||||
if param.OperaType >= 0 {
|
||||
conditions = append(conditions, "opera_type = ?")
|
||||
params = append(params, param.OperaType)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by create_time desc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigDataLogRepository) SelectByIds(paramIds []string) []model.PtNeConfigDataLog {
|
||||
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.PtNeConfigDataLog{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigDataLogRepository) Insert(param model.PtNeConfigDataLog) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.CreateBy != "" {
|
||||
params["create_by"] = param.CreateBy
|
||||
params["create_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
if param.StubType != "" {
|
||||
params["stub_type"] = param.StubType
|
||||
}
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.ParamJsonOld != "" {
|
||||
params["param_json_old"] = param.ParamJsonOld
|
||||
}
|
||||
if param.ParamJsonNew != "" {
|
||||
params["param_json_new"] = param.ParamJsonNew
|
||||
}
|
||||
params["opera_type"] = param.OperaType
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into pt_ne_config_data_log (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *PtNeConfigDataLogRepository) DeleteByIds(paramIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(paramIds))
|
||||
sql := "delete from pt_ne_config_data_log 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
|
||||
}
|
||||
@@ -1,29 +1,71 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
)
|
||||
|
||||
// IPtNeConfigApplyService 服务层接口
|
||||
type IPtNeConfigApplyService interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
// NewPtNeConfigApplyService 实例化服务层
|
||||
var NewPtNeConfigApplyService = &PtNeConfigApplyService{
|
||||
ptNeConfigApplyRepository: *repository.NewPtNeConfigApplyRepository,
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply
|
||||
// PtNeConfigApplyService 服务层处理
|
||||
type PtNeConfigApplyService struct {
|
||||
ptNeConfigApplyRepository repository.PtNeConfigApplyRepository // 实训教学_网元参数配置表
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigApplyService) SelectPage(query map[string]any) (int64, []model.PtNeConfigApply) {
|
||||
return r.ptNeConfigApplyRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigApplyService) SelectList(param model.PtNeConfigApply) []model.PtNeConfigApply {
|
||||
return r.ptNeConfigApplyRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(paramId string) model.PtNeConfigApply
|
||||
func (r *PtNeConfigApplyService) SelectById(paramId int64) model.PtNeConfigApply {
|
||||
if paramId <= 0 {
|
||||
return model.PtNeConfigApply{}
|
||||
}
|
||||
neHosts := r.ptNeConfigApplyRepository.SelectByIds([]int64{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigApply{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigApply) string
|
||||
func (r *PtNeConfigApplyService) Insert(param model.PtNeConfigApply) int64 {
|
||||
return r.ptNeConfigApplyRepository.Insert(param)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigApply) int64
|
||||
func (r *PtNeConfigApplyService) Update(param model.PtNeConfigApply) int64 {
|
||||
return r.ptNeConfigApplyRepository.Update(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
func (r *PtNeConfigApplyService) DeleteByIds(paramIds []int64) (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")
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
SelectListByClass(deptId, userName string) []map[string]any
|
||||
func (r *PtNeConfigApplyService) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
return r.ptNeConfigApplyRepository.SelectListByClass(deptId, userName)
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
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")
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
func (r *PtNeConfigApplyService) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
return r.ptNeConfigApplyRepository.SelectListByClass(deptId, userName)
|
||||
}
|
||||
@@ -1,42 +1,461 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
"be.ems/src/framework/constants/uploadsubpath"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// IPtNeConfigDataService 服务层接口
|
||||
type IPtNeConfigDataService interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
// NewPtNeConfigDataService 实例化服务层
|
||||
var NewPtNeConfigDataService = &PtNeConfigDataService{
|
||||
ptNeConfigDataLogRepository: repository.NewPtNeConfigDataLogRepository,
|
||||
ptNeConfigDataRepository: repository.NewPtNeConfigDataRepository,
|
||||
neConfigService: neService.NewNeConfig,
|
||||
neInfoService: neService.NewNeInfo,
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigData) []model.PtNeConfigData
|
||||
// PtNeConfigDataService 服务层处理
|
||||
type PtNeConfigDataService struct {
|
||||
// 实训教学_网元参数配置数据变更日志
|
||||
ptNeConfigDataLogRepository *repository.PtNeConfigDataLogRepository
|
||||
// 实训教学_网元参数配置表
|
||||
ptNeConfigDataRepository *repository.PtNeConfigDataRepository
|
||||
// 网元参数配置可用属性值服务
|
||||
neConfigService *neService.NeConfig
|
||||
// 网元信息服务
|
||||
neInfoService *neService.NeInfo
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigDataService) SelectPage(query map[string]any) (int64, []model.PtNeConfigData) {
|
||||
return r.ptNeConfigDataRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigDataService) SelectList(param model.PtNeConfigData) []model.PtNeConfigData {
|
||||
return r.ptNeConfigDataRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(paramId string) model.PtNeConfigData
|
||||
func (r *PtNeConfigDataService) SelectById(paramId string) model.PtNeConfigData {
|
||||
if paramId == "" {
|
||||
return model.PtNeConfigData{}
|
||||
}
|
||||
neHosts := r.ptNeConfigDataRepository.SelectByIds([]string{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigData{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigData) string
|
||||
func (r *PtNeConfigDataService) Insert(param model.PtNeConfigData) int64 {
|
||||
return r.ptNeConfigDataRepository.Insert(param)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
Update(param model.PtNeConfigData) int64
|
||||
func (r *PtNeConfigDataService) Update(param model.PtNeConfigData) int64 {
|
||||
return r.ptNeConfigDataRepository.Update(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
func (r *PtNeConfigDataService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.ptNeConfigDataRepository.SelectByIds(paramIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("ptNeConfigData.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(paramIds) {
|
||||
rows := r.ptNeConfigDataRepository.DeleteByIds(paramIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SaveAsDefault 系统网元配置保存为系统示例
|
||||
SaveAsDefault(neType, neId string)
|
||||
func (r *PtNeConfigDataService) SaveAsDefault(neType, neId string) {
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
return
|
||||
}
|
||||
|
||||
stubType := "0"
|
||||
operaUserName := "admin"
|
||||
deptId := "100"
|
||||
confs := r.neConfigService.SelectList(neModel.NeConfig{NeType: neInfo.NeType})
|
||||
for _, v := range confs {
|
||||
// 查询是否存在记录
|
||||
hasItems := r.SelectList(model.PtNeConfigData{
|
||||
NeType: v.NeType,
|
||||
StubType: stubType,
|
||||
ParamName: v.ParamName,
|
||||
ParamType: v.ParamType,
|
||||
})
|
||||
// 网元直连 获取网元配置信息
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, v.ParamName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// 将json数据转字符串存储 data:[{},{}]
|
||||
data, ok := resData["data"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
paramDataByte, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// 插入
|
||||
if len(hasItems) == 0 {
|
||||
r.Insert(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: string(paramDataByte),
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 更新
|
||||
if len(hasItems) == 1 {
|
||||
item := hasItems[0]
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = string(paramDataByte)
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetAsDefault 重置配置示例
|
||||
// stubType:2个人为班级示例 1班级为系统示例
|
||||
ResetAsDefault(operaUserName, stubType, neType, deptId string)
|
||||
func (r *PtNeConfigDataService) ResetAsDefault(operaUserName, stubType, neType, deptId string) {
|
||||
rootStubType := "1"
|
||||
if stubType == "1" {
|
||||
rootStubType = "0"
|
||||
}
|
||||
if stubType == "2" {
|
||||
rootStubType = "1"
|
||||
}
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{StubType: rootStubType, NeType: neType})
|
||||
|
||||
for _, v := range ptConfs {
|
||||
// 查询是否存在记录
|
||||
hasItems := r.SelectList(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
NeType: v.NeType,
|
||||
StubType: stubType,
|
||||
ParamName: v.ParamName,
|
||||
ParamType: v.ParamType,
|
||||
})
|
||||
|
||||
// 插入
|
||||
if len(hasItems) == 0 {
|
||||
r.Insert(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: v.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
// 保留变更日志
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
OperaType: 0,
|
||||
ParamJsonOld: "[]",
|
||||
ParamJsonNew: v.ParamJson,
|
||||
}
|
||||
r.ptNeConfigDataLogRepository.Insert(changeLog)
|
||||
}
|
||||
// 更新
|
||||
if len(hasItems) == 1 {
|
||||
item := hasItems[0]
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = v.ParamJson
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
// 保留变更日志
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: operaUserName,
|
||||
StubType: hasItems[0].StubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
OperaType: 0,
|
||||
ParamJsonOld: hasItems[0].ParamJson,
|
||||
ParamJsonNew: v.ParamJson,
|
||||
}
|
||||
r.ptNeConfigDataLogRepository.Insert(changeLog)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectByStubType 通过存根类型查询
|
||||
SelectByStubType(param model.PtNeConfigData) model.PtNeConfigData
|
||||
func (r *PtNeConfigDataService) SelectByStubType(param model.PtNeConfigData) model.PtNeConfigData {
|
||||
list := r.SelectList(param)
|
||||
if len(list) == 0 && param.StubType != "1" {
|
||||
param.CreateBy = ""
|
||||
param.StubType = "1"
|
||||
list = r.SelectList(param)
|
||||
}
|
||||
if len(list) == 0 && param.StubType != "0" {
|
||||
param.CreateBy = ""
|
||||
param.StubType = "0"
|
||||
param.DeptId = "100"
|
||||
list = r.SelectList(param)
|
||||
}
|
||||
var paraData model.PtNeConfigData
|
||||
if len(list) > 0 {
|
||||
paraData = list[0]
|
||||
if err := json.Unmarshal([]byte(paraData.ParamJson), ¶Data.ParamData); err != nil {
|
||||
paraData.ParamData = []map[string]any{}
|
||||
}
|
||||
}
|
||||
return paraData
|
||||
}
|
||||
|
||||
// ApplyToNe 参数应用到网元
|
||||
ApplyToNe(paramUser, neType string) error
|
||||
func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{CreateBy: paramUser, NeType: neType})
|
||||
if len(ptConfs) == 0 {
|
||||
return fmt.Errorf("NeConfigData Not Found")
|
||||
}
|
||||
|
||||
// 找网元,只有一套就固定neId:001
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, "001")
|
||||
if neInfo.NeType != neType || neInfo.ID == "" {
|
||||
return fmt.Errorf("NeInfo Not Found")
|
||||
}
|
||||
|
||||
// 遍历去设置参数
|
||||
for _, ptConf := range ptConfs {
|
||||
if err := json.Unmarshal([]byte(ptConf.ParamJson), &ptConf.ParamData); err != nil {
|
||||
ptConf.ParamData = []map[string]any{}
|
||||
}
|
||||
// 将json数据转字符串存储 [{},{}]
|
||||
if len(ptConf.ParamData) == 0 {
|
||||
continue
|
||||
}
|
||||
// 单层逐个更新
|
||||
if ptConf.ParamType == "list" {
|
||||
for k, v := range ptConf.ParamData[0] {
|
||||
neFetchlink.NeConfigUpdate(neInfo, ptConf.ParamName, "", map[string]any{k: v})
|
||||
}
|
||||
}
|
||||
// 多层逐个更新
|
||||
if ptConf.ParamType == "array" {
|
||||
// 删除原先配置
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, ptConf.ParamName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if data, ok := resData["data"]; ok {
|
||||
for i := 0; i < len(data.([]any)); i++ { // 倒序遍历
|
||||
originIndex := i
|
||||
newIndex := len(data.([]any)) - originIndex - 1
|
||||
element := data.([]any)[newIndex]
|
||||
loc := parse.Number(element.(map[string]any)["index"])
|
||||
neFetchlink.NeConfigDelete(neInfo, ptConf.ParamName, fmt.Sprint(loc))
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历新增
|
||||
for _, v := range ptConf.ParamData {
|
||||
loc := parse.Number(v["index"])
|
||||
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprint(loc), v)
|
||||
// 检查是否有array子层
|
||||
for vk, vv := range v {
|
||||
if reflect.TypeOf(vv).Kind() == reflect.Slice {
|
||||
for i, item := range vv.([]any) {
|
||||
data := item.(map[string]any)
|
||||
data["index"] = i
|
||||
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprintf("%v/%s/%v", loc, vk, i), data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportToExcel 导出网元的全部配置项数据
|
||||
ExportToExcel(operaUserName, fileName string) (string, error)
|
||||
func (r *PtNeConfigDataService) ExportToExcel(operaUserName, fileName string) (string, error) {
|
||||
confs := r.neConfigService.SelectNeConfigByNeType("*")
|
||||
datas := r.ptNeConfigDataRepository.SelectList(model.PtNeConfigData{CreateBy: operaUserName})
|
||||
return r.writeSheet(confs, datas, fileName)
|
||||
}
|
||||
|
||||
// writeSheet 写入表格
|
||||
func (r *PtNeConfigDataService) writeSheet(sheetData []neModel.NeConfig, cellData []model.PtNeConfigData, fileName string) (string, error) {
|
||||
f := excelize.NewFile()
|
||||
defer f.Close()
|
||||
|
||||
// 设置颜色填充
|
||||
styleType, _ := f.NewStyle(&excelize.Style{Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Pattern: 1,
|
||||
Color: []string{"F0F806"}, // RRGGBB 格式的
|
||||
}})
|
||||
styleRow, _ := f.NewStyle(&excelize.Style{Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Pattern: 1,
|
||||
Color: []string{"D0CECE"}, // RRGGBB 格式的
|
||||
}})
|
||||
styleMore, _ := f.NewStyle(&excelize.Style{Font: &excelize.Font{
|
||||
Color: "4472C4",
|
||||
VertAlign: "center",
|
||||
}})
|
||||
// 网元工作簿行计数
|
||||
sheetNameRows := make(map[string]int)
|
||||
|
||||
for _, sd := range sheetData {
|
||||
_ = json.Unmarshal([]byte(sd.ParamJson), &sd.ParamData)
|
||||
// 取到对应数据
|
||||
var data model.PtNeConfigData
|
||||
for _, cell := range cellData {
|
||||
if cell.NeType == sd.NeType && cell.ParamName == sd.ParamName {
|
||||
data = cell
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := json.Unmarshal([]byte(data.ParamJson), &data.ParamData); err != nil || len(data.ParamData) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
sheetName := sd.NeType
|
||||
// 创建一个工作表
|
||||
f.NewSheet(sheetName)
|
||||
// 设置工作表上宽度为 20
|
||||
// f.SetColWidth(sheetName, "B", "C", 20)
|
||||
sheetRows := 1
|
||||
if v, ok := sheetNameRows[sheetName]; ok && v != 0 {
|
||||
sheetRows = v
|
||||
}
|
||||
// 合并标题单元格
|
||||
f.MergeCell(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("C%d", sheetRows))
|
||||
f.SetCellStyle(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("C%d", sheetRows), styleType)
|
||||
// 标题
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("A%d", sheetRows), sd.ParamDisplay)
|
||||
sheetRows += 1
|
||||
|
||||
// fmt.Println(sheetName, " ========= ", sd.ParamDisplay, " ==== ", sd.ParamType, len(data.ParamData))
|
||||
itemData := []*[]any{}
|
||||
|
||||
if sd.ParamType == "list" {
|
||||
itemData = append(itemData, &[]any{"Key", "Value"})
|
||||
for _, v := range sd.ParamData {
|
||||
name := v["name"].(string)
|
||||
value := v["value"]
|
||||
// 取到对应数据
|
||||
for _, dv := range data.ParamData {
|
||||
value = dv[name]
|
||||
}
|
||||
itemData = append(itemData, &[]any{v["display"], value})
|
||||
}
|
||||
}
|
||||
|
||||
if sd.ParamType == "array" {
|
||||
rowTitle := []any{} // 行头
|
||||
rowData := make([][]any, len(data.ParamData)) // 行数据
|
||||
for _, v := range sd.ParamData {
|
||||
rowTitle = append(rowTitle, v["display"])
|
||||
name := v["name"].(string)
|
||||
// 取到对应数据
|
||||
for i, dv := range data.ParamData {
|
||||
rowData[i] = append(rowData[i], dv[name])
|
||||
}
|
||||
}
|
||||
itemData = append(itemData, &rowTitle)
|
||||
for _, v := range rowData {
|
||||
item := v
|
||||
itemData = append(itemData, &item)
|
||||
}
|
||||
}
|
||||
|
||||
for i, row := range itemData {
|
||||
// 行头样式
|
||||
if i == 0 {
|
||||
f.SetCellStyle(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("A%d", sheetRows), styleRow)
|
||||
}
|
||||
|
||||
f.SetSheetRow(sheetName, fmt.Sprintf("A%d", sheetRows), row)
|
||||
|
||||
// 存在array子层时转字符串
|
||||
for i, s := range *row {
|
||||
if reflect.ValueOf(s).Kind() == reflect.Slice {
|
||||
if cell, err := excelize.CoordinatesToCellName(i+1, sheetRows); err == nil {
|
||||
b, _ := json.Marshal(s)
|
||||
f.SetCellDefault(sheetName, cell, "#")
|
||||
f.SetCellStyle(sheetName, cell, cell, styleMore)
|
||||
f.AddComment(sheetName, excelize.Comment{
|
||||
Cell: cell,
|
||||
Author: "OMC",
|
||||
Text: string(b),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sheetRows += 1
|
||||
}
|
||||
|
||||
// 记下次写入的行数
|
||||
sheetRows += 2
|
||||
sheetNameRows[sheetName] = sheetRows
|
||||
}
|
||||
|
||||
// 默认工作表
|
||||
f.SetCellValue("Sheet1", "A1", cellData[0].CreateBy)
|
||||
f.MergeCell("Sheet1", "A1", "B1")
|
||||
f.SetCellStyle("Sheet1", "A1", "B1", styleType)
|
||||
f.SetCellValue("Sheet1", "A2", "5GC")
|
||||
f.SetCellStyle("Sheet1", "A2", "A2", styleRow)
|
||||
sheetNameData := []any{}
|
||||
for k := range sheetNameRows {
|
||||
sheetNameData = append(sheetNameData, k)
|
||||
}
|
||||
f.SetSheetRow("Sheet1", "A3", &sheetNameData)
|
||||
|
||||
// 上传资源路径
|
||||
filePath := file.ParseUploadFileDir(uploadsubpath.EXPORT)
|
||||
saveFilePath := filepath.ToSlash(filepath.Join(filePath, fileName))
|
||||
// 创建文件目录
|
||||
if err := os.MkdirAll(filepath.Dir(saveFilePath), 0775); err != nil {
|
||||
return "", fmt.Errorf("failed to create save file %v", err)
|
||||
}
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs(saveFilePath); err != nil {
|
||||
return "", fmt.Errorf("failed to save worksheet %v", err)
|
||||
}
|
||||
return saveFilePath, nil
|
||||
}
|
||||
|
||||
@@ -1,461 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
"be.ems/src/framework/constants/uploadsubpath"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataService 实例化服务层
|
||||
var NewPtNeConfigDataService = &PtNeConfigDataService{
|
||||
ptNeConfigDataLogRepository: repository.NewPtNeConfigDataLogRepository,
|
||||
ptNeConfigDataRepository: repository.NewPtNeConfigDataRepository,
|
||||
neConfigService: neService.NewNeConfigImpl,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// PtNeConfigDataService 服务层处理
|
||||
type PtNeConfigDataService struct {
|
||||
// 实训教学_网元参数配置数据变更日志
|
||||
ptNeConfigDataLogRepository repository.IPtNeConfigDataLogRepository
|
||||
// 实训教学_网元参数配置表
|
||||
ptNeConfigDataRepository repository.IPtNeConfigDataRepository
|
||||
// 网元参数配置可用属性值服务
|
||||
neConfigService neService.INeConfig
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigDataService) SelectPage(query map[string]any) map[string]any {
|
||||
return r.ptNeConfigDataRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigDataService) SelectList(param model.PtNeConfigData) []model.PtNeConfigData {
|
||||
return r.ptNeConfigDataRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigDataService) SelectById(paramId string) model.PtNeConfigData {
|
||||
if paramId == "" {
|
||||
return model.PtNeConfigData{}
|
||||
}
|
||||
neHosts := r.ptNeConfigDataRepository.SelectByIds([]string{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigData{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigDataService) Insert(param model.PtNeConfigData) string {
|
||||
return r.ptNeConfigDataRepository.Insert(param)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *PtNeConfigDataService) Update(param model.PtNeConfigData) int64 {
|
||||
return r.ptNeConfigDataRepository.Update(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *PtNeConfigDataService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.ptNeConfigDataRepository.SelectByIds(paramIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("ptNeConfigData.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(paramIds) {
|
||||
rows := r.ptNeConfigDataRepository.DeleteByIds(paramIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SaveAsDefault 系统网元配置保存为系统示例
|
||||
func (r *PtNeConfigDataService) SaveAsDefault(neType, neId string) {
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
return
|
||||
}
|
||||
|
||||
stubType := "0"
|
||||
operaUserName := "admin"
|
||||
deptId := "100"
|
||||
confs := r.neConfigService.SelectList(neModel.NeConfig{NeType: neInfo.NeType})
|
||||
for _, v := range confs {
|
||||
// 查询是否存在记录
|
||||
hasItems := r.SelectList(model.PtNeConfigData{
|
||||
NeType: v.NeType,
|
||||
StubType: stubType,
|
||||
ParamName: v.ParamName,
|
||||
ParamType: v.ParamType,
|
||||
})
|
||||
// 网元直连 获取网元配置信息
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, v.ParamName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// 将json数据转字符串存储 data:[{},{}]
|
||||
data, ok := resData["data"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
paramDataByte, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// 插入
|
||||
if len(hasItems) == 0 {
|
||||
r.Insert(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: string(paramDataByte),
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 更新
|
||||
if len(hasItems) == 1 {
|
||||
item := hasItems[0]
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = string(paramDataByte)
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetAsDefault 重置配置示例
|
||||
// stubType:2个人为班级示例 1班级为系统示例
|
||||
func (r *PtNeConfigDataService) ResetAsDefault(operaUserName, stubType, neType, deptId string) {
|
||||
rootStubType := "1"
|
||||
if stubType == "1" {
|
||||
rootStubType = "0"
|
||||
}
|
||||
if stubType == "2" {
|
||||
rootStubType = "1"
|
||||
}
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{StubType: rootStubType, NeType: neType})
|
||||
|
||||
for _, v := range ptConfs {
|
||||
// 查询是否存在记录
|
||||
hasItems := r.SelectList(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
NeType: v.NeType,
|
||||
StubType: stubType,
|
||||
ParamName: v.ParamName,
|
||||
ParamType: v.ParamType,
|
||||
})
|
||||
|
||||
// 插入
|
||||
if len(hasItems) == 0 {
|
||||
r.Insert(model.PtNeConfigData{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: v.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
// 保留变更日志
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: operaUserName,
|
||||
StubType: stubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
OperaType: 0,
|
||||
ParamJsonOld: "[]",
|
||||
ParamJsonNew: v.ParamJson,
|
||||
}
|
||||
r.ptNeConfigDataLogRepository.Insert(changeLog)
|
||||
}
|
||||
// 更新
|
||||
if len(hasItems) == 1 {
|
||||
item := hasItems[0]
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = v.ParamJson
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
// 保留变更日志
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: operaUserName,
|
||||
StubType: hasItems[0].StubType,
|
||||
NeType: v.NeType,
|
||||
ParamName: v.ParamName,
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
OperaType: 0,
|
||||
ParamJsonOld: hasItems[0].ParamJson,
|
||||
ParamJsonNew: v.ParamJson,
|
||||
}
|
||||
r.ptNeConfigDataLogRepository.Insert(changeLog)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SelectByStubType 通过存根类型查询
|
||||
func (r *PtNeConfigDataService) SelectByStubType(param model.PtNeConfigData) model.PtNeConfigData {
|
||||
list := r.SelectList(param)
|
||||
if len(list) == 0 && param.StubType != "1" {
|
||||
param.CreateBy = ""
|
||||
param.StubType = "1"
|
||||
list = r.SelectList(param)
|
||||
}
|
||||
if len(list) == 0 && param.StubType != "0" {
|
||||
param.CreateBy = ""
|
||||
param.StubType = "0"
|
||||
param.DeptId = "100"
|
||||
list = r.SelectList(param)
|
||||
}
|
||||
var paraData model.PtNeConfigData
|
||||
if len(list) > 0 {
|
||||
paraData = list[0]
|
||||
if err := json.Unmarshal([]byte(paraData.ParamJson), ¶Data.ParamData); err != nil {
|
||||
paraData.ParamData = []map[string]any{}
|
||||
}
|
||||
}
|
||||
return paraData
|
||||
}
|
||||
|
||||
// ApplyToNe 参数应用到网元
|
||||
func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{CreateBy: paramUser, NeType: neType})
|
||||
if len(ptConfs) == 0 {
|
||||
return fmt.Errorf("NeConfigData Not Found")
|
||||
}
|
||||
|
||||
// 找网元,只有一套就固定neId:001
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, "001")
|
||||
if neInfo.NeType != neType || neInfo.ID == "" {
|
||||
return fmt.Errorf("NeInfo Not Found")
|
||||
}
|
||||
|
||||
// 遍历去设置参数
|
||||
for _, ptConf := range ptConfs {
|
||||
if err := json.Unmarshal([]byte(ptConf.ParamJson), &ptConf.ParamData); err != nil {
|
||||
ptConf.ParamData = []map[string]any{}
|
||||
}
|
||||
// 将json数据转字符串存储 [{},{}]
|
||||
if len(ptConf.ParamData) == 0 {
|
||||
continue
|
||||
}
|
||||
// 单层逐个更新
|
||||
if ptConf.ParamType == "list" {
|
||||
for k, v := range ptConf.ParamData[0] {
|
||||
neFetchlink.NeConfigUpdate(neInfo, ptConf.ParamName, "", map[string]any{k: v})
|
||||
}
|
||||
}
|
||||
// 多层逐个更新
|
||||
if ptConf.ParamType == "array" {
|
||||
// 删除原先配置
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, ptConf.ParamName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if data, ok := resData["data"]; ok {
|
||||
for i := 0; i < len(data.([]any)); i++ { // 倒序遍历
|
||||
originIndex := i
|
||||
newIndex := len(data.([]any)) - originIndex - 1
|
||||
element := data.([]any)[newIndex]
|
||||
loc := parse.Number(element.(map[string]any)["index"])
|
||||
neFetchlink.NeConfigDelete(neInfo, ptConf.ParamName, fmt.Sprint(loc))
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历新增
|
||||
for _, v := range ptConf.ParamData {
|
||||
loc := parse.Number(v["index"])
|
||||
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprint(loc), v)
|
||||
// 检查是否有array子层
|
||||
for vk, vv := range v {
|
||||
if reflect.TypeOf(vv).Kind() == reflect.Slice {
|
||||
for i, item := range vv.([]any) {
|
||||
data := item.(map[string]any)
|
||||
data["index"] = i
|
||||
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprintf("%v/%s/%v", loc, vk, i), data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportToExcel 导出网元的全部配置项数据
|
||||
func (r *PtNeConfigDataService) ExportToExcel(operaUserName, fileName string) (string, error) {
|
||||
confs := r.neConfigService.SelectNeConfigByNeType("*")
|
||||
datas := r.ptNeConfigDataRepository.SelectList(model.PtNeConfigData{CreateBy: operaUserName})
|
||||
return r.writeSheet(confs, datas, fileName)
|
||||
}
|
||||
|
||||
// writeSheet 写入表格
|
||||
func (r *PtNeConfigDataService) writeSheet(sheetData []neModel.NeConfig, cellData []model.PtNeConfigData, fileName string) (string, error) {
|
||||
f := excelize.NewFile()
|
||||
defer f.Close()
|
||||
|
||||
// 设置颜色填充
|
||||
styleType, _ := f.NewStyle(&excelize.Style{Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Pattern: 1,
|
||||
Color: []string{"F0F806"}, // RRGGBB 格式的
|
||||
}})
|
||||
styleRow, _ := f.NewStyle(&excelize.Style{Fill: excelize.Fill{
|
||||
Type: "pattern",
|
||||
Pattern: 1,
|
||||
Color: []string{"D0CECE"}, // RRGGBB 格式的
|
||||
}})
|
||||
styleMore, _ := f.NewStyle(&excelize.Style{Font: &excelize.Font{
|
||||
Color: "4472C4",
|
||||
VertAlign: "center",
|
||||
}})
|
||||
// 网元工作簿行计数
|
||||
sheetNameRows := make(map[string]int)
|
||||
|
||||
for _, sd := range sheetData {
|
||||
_ = json.Unmarshal([]byte(sd.ParamJson), &sd.ParamData)
|
||||
// 取到对应数据
|
||||
var data model.PtNeConfigData
|
||||
for _, cell := range cellData {
|
||||
if cell.NeType == sd.NeType && cell.ParamName == sd.ParamName {
|
||||
data = cell
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := json.Unmarshal([]byte(data.ParamJson), &data.ParamData); err != nil || len(data.ParamData) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
sheetName := sd.NeType
|
||||
// 创建一个工作表
|
||||
f.NewSheet(sheetName)
|
||||
// 设置工作表上宽度为 20
|
||||
// f.SetColWidth(sheetName, "B", "C", 20)
|
||||
sheetRows := 1
|
||||
if v, ok := sheetNameRows[sheetName]; ok && v != 0 {
|
||||
sheetRows = v
|
||||
}
|
||||
// 合并标题单元格
|
||||
f.MergeCell(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("C%d", sheetRows))
|
||||
f.SetCellStyle(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("C%d", sheetRows), styleType)
|
||||
// 标题
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("A%d", sheetRows), sd.ParamDisplay)
|
||||
sheetRows += 1
|
||||
|
||||
// fmt.Println(sheetName, " ========= ", sd.ParamDisplay, " ==== ", sd.ParamType, len(data.ParamData))
|
||||
itemData := []*[]any{}
|
||||
|
||||
if sd.ParamType == "list" {
|
||||
itemData = append(itemData, &[]any{"Key", "Value"})
|
||||
for _, v := range sd.ParamData {
|
||||
name := v["name"].(string)
|
||||
value := v["value"]
|
||||
// 取到对应数据
|
||||
for _, dv := range data.ParamData {
|
||||
value = dv[name]
|
||||
}
|
||||
itemData = append(itemData, &[]any{v["display"], value})
|
||||
}
|
||||
}
|
||||
|
||||
if sd.ParamType == "array" {
|
||||
rowTitle := []any{} // 行头
|
||||
rowData := make([][]any, len(data.ParamData)) // 行数据
|
||||
for _, v := range sd.ParamData {
|
||||
rowTitle = append(rowTitle, v["display"])
|
||||
name := v["name"].(string)
|
||||
// 取到对应数据
|
||||
for i, dv := range data.ParamData {
|
||||
rowData[i] = append(rowData[i], dv[name])
|
||||
}
|
||||
}
|
||||
itemData = append(itemData, &rowTitle)
|
||||
for _, v := range rowData {
|
||||
item := v
|
||||
itemData = append(itemData, &item)
|
||||
}
|
||||
}
|
||||
|
||||
for i, row := range itemData {
|
||||
// 行头样式
|
||||
if i == 0 {
|
||||
f.SetCellStyle(sheetName, fmt.Sprintf("A%d", sheetRows), fmt.Sprintf("A%d", sheetRows), styleRow)
|
||||
}
|
||||
|
||||
f.SetSheetRow(sheetName, fmt.Sprintf("A%d", sheetRows), row)
|
||||
|
||||
// 存在array子层时转字符串
|
||||
for i, s := range *row {
|
||||
if reflect.ValueOf(s).Kind() == reflect.Slice {
|
||||
if cell, err := excelize.CoordinatesToCellName(i+1, sheetRows); err == nil {
|
||||
b, _ := json.Marshal(s)
|
||||
f.SetCellDefault(sheetName, cell, "#")
|
||||
f.SetCellStyle(sheetName, cell, cell, styleMore)
|
||||
f.AddComment(sheetName, excelize.Comment{
|
||||
Cell: cell,
|
||||
Author: "OMC",
|
||||
Text: string(b),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sheetRows += 1
|
||||
}
|
||||
|
||||
// 记下次写入的行数
|
||||
sheetRows += 2
|
||||
sheetNameRows[sheetName] = sheetRows
|
||||
}
|
||||
|
||||
// 默认工作表
|
||||
f.SetCellValue("Sheet1", "A1", cellData[0].CreateBy)
|
||||
f.MergeCell("Sheet1", "A1", "B1")
|
||||
f.SetCellStyle("Sheet1", "A1", "B1", styleType)
|
||||
f.SetCellValue("Sheet1", "A2", "5GC")
|
||||
f.SetCellStyle("Sheet1", "A2", "A2", styleRow)
|
||||
sheetNameData := []any{}
|
||||
for k := range sheetNameRows {
|
||||
sheetNameData = append(sheetNameData, k)
|
||||
}
|
||||
f.SetSheetRow("Sheet1", "A3", &sheetNameData)
|
||||
|
||||
// 上传资源路径
|
||||
filePath := file.ParseUploadFileDir(uploadsubpath.EXPORT)
|
||||
saveFilePath := filepath.ToSlash(filepath.Join(filePath, fileName))
|
||||
// 创建文件目录
|
||||
if err := os.MkdirAll(filepath.Dir(saveFilePath), 0775); err != nil {
|
||||
return "", fmt.Errorf("failed to create save file %v", err)
|
||||
}
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs(saveFilePath); err != nil {
|
||||
return "", fmt.Errorf("failed to save worksheet %v", err)
|
||||
}
|
||||
return saveFilePath, nil
|
||||
}
|
||||
@@ -1,23 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
)
|
||||
|
||||
// IPtNeConfigDataLogService 服务层接口
|
||||
type IPtNeConfigDataLogService interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
// NewPtNeConfigDataService 实例化服务层
|
||||
var NewPtNeConfigDataLogService = &PtNeConfigDataLogService{
|
||||
ptNeConfigDataLogRepository: *repository.NewPtNeConfigDataLogRepository,
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog
|
||||
// PtNeConfigDataLogService 服务层处理
|
||||
type PtNeConfigDataLogService struct {
|
||||
// 实训教学_网元参数配置数据变更日志
|
||||
ptNeConfigDataLogRepository repository.PtNeConfigDataLogRepository
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigDataLogService) SelectPage(query map[string]any) (int64, []model.PtNeConfigDataLog) {
|
||||
return r.ptNeConfigDataLogRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigDataLogService) SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog {
|
||||
return r.ptNeConfigDataLogRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(paramId string) model.PtNeConfigDataLog
|
||||
func (r *PtNeConfigDataLogService) SelectById(paramId int64) model.PtNeConfigDataLog {
|
||||
if paramId <= 0 {
|
||||
return model.PtNeConfigDataLog{}
|
||||
}
|
||||
neHosts := r.ptNeConfigDataLogRepository.SelectByIds([]int64{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigDataLog{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(param model.PtNeConfigDataLog) string
|
||||
func (r *PtNeConfigDataLogService) Insert(param model.PtNeConfigDataLog) int64 {
|
||||
return r.ptNeConfigDataLogRepository.Insert(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
func (r *PtNeConfigDataLogService) DeleteByIds(paramIds []int64) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.ptNeConfigDataLogRepository.SelectByIds(paramIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("ptNeConfigDataLog.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(paramIds) {
|
||||
rows := r.ptNeConfigDataLogRepository.DeleteByIds(paramIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/repository"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataService 实例化服务层
|
||||
var NewPtNeConfigDataLogService = &PtNeConfigDataLogService{
|
||||
ptNeConfigDataLogRepository: repository.NewPtNeConfigDataLogRepository,
|
||||
}
|
||||
|
||||
// PtNeConfigDataLogService 服务层处理
|
||||
type PtNeConfigDataLogService struct {
|
||||
// 实训教学_网元参数配置数据变更日志
|
||||
ptNeConfigDataLogRepository repository.IPtNeConfigDataLogRepository
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *PtNeConfigDataLogService) SelectPage(query map[string]any) map[string]any {
|
||||
return r.ptNeConfigDataLogRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *PtNeConfigDataLogService) SelectList(param model.PtNeConfigDataLog) []model.PtNeConfigDataLog {
|
||||
return r.ptNeConfigDataLogRepository.SelectList(param)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *PtNeConfigDataLogService) SelectById(paramId string) model.PtNeConfigDataLog {
|
||||
if paramId == "" {
|
||||
return model.PtNeConfigDataLog{}
|
||||
}
|
||||
neHosts := r.ptNeConfigDataLogRepository.SelectByIds([]string{paramId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.PtNeConfigDataLog{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *PtNeConfigDataLogService) Insert(param model.PtNeConfigDataLog) string {
|
||||
return r.ptNeConfigDataLogRepository.Insert(param)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *PtNeConfigDataLogService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.ptNeConfigDataLogRepository.SelectByIds(paramIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("ptNeConfigDataLog.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(paramIds) {
|
||||
rows := r.ptNeConfigDataLogRepository.DeleteByIds(paramIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
Reference in New Issue
Block a user