feat: 添加导出所有网元配置数据的功能,并优化相关查询逻辑
This commit is contained in:
@@ -32,9 +32,10 @@ type PtNeConfigApplyController struct {
|
|||||||
//
|
//
|
||||||
// GET /students
|
// GET /students
|
||||||
func (s *PtNeConfigApplyController) Students(c *gin.Context) {
|
func (s *PtNeConfigApplyController) Students(c *gin.Context) {
|
||||||
userName, _ := c.GetQuery("userName")
|
neType := c.Query("neType")
|
||||||
|
userName := c.Query("userName")
|
||||||
loginUser, _ := ctx.LoginUser(c)
|
loginUser, _ := ctx.LoginUser(c)
|
||||||
data := s.ptNeConfigApplyService.SelectListByClass(loginUser.DeptID, userName)
|
data := s.ptNeConfigApplyService.SelectListByClass(loginUser.DeptID, userName, neType)
|
||||||
c.JSON(200, result.OkData(data))
|
c.JSON(200, result.OkData(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"be.ems/src/framework/constants/uploadsubpath"
|
||||||
"be.ems/src/framework/i18n"
|
"be.ems/src/framework/i18n"
|
||||||
"be.ems/src/framework/utils/ctx"
|
"be.ems/src/framework/utils/ctx"
|
||||||
|
"be.ems/src/framework/utils/file"
|
||||||
"be.ems/src/framework/utils/parse"
|
"be.ems/src/framework/utils/parse"
|
||||||
"be.ems/src/framework/vo/result"
|
"be.ems/src/framework/vo/result"
|
||||||
"be.ems/src/modules/practical_training/model"
|
"be.ems/src/modules/practical_training/model"
|
||||||
@@ -183,6 +187,31 @@ func (s *PtNeConfigDataController) Export(c *gin.Context) {
|
|||||||
c.FileAttachment(filePath, fileName)
|
c.FileAttachment(filePath, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 配置数据导出Excel (仅教师操作)
|
||||||
|
//
|
||||||
|
// GET /export-all
|
||||||
|
func (s *PtNeConfigDataController) ExportAll(c *gin.Context) {
|
||||||
|
loginUser, _ := ctx.LoginUser(c)
|
||||||
|
users := service.NewPtNeConfigApplyService.SelectListByClass(loginUser.DeptID, "", "")
|
||||||
|
for _, v := range users {
|
||||||
|
userName := fmt.Sprint(v["userName"])
|
||||||
|
fileName := fmt.Sprintf("/pt-all/%s_config_data.xlsx", userName)
|
||||||
|
s.ptNeConfigDataService.ExportToExcel(userName, fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := file.ParseUploadFileDir(uploadsubpath.EXPORT)
|
||||||
|
dirPath := filepath.ToSlash(filepath.Join(filePath, "pt-all"))
|
||||||
|
zipFileName := fmt.Sprintf("%s_students_config_data.zip", loginUser.DeptID)
|
||||||
|
zipFilePath := filepath.ToSlash(filepath.Join(filePath, zipFileName))
|
||||||
|
err := file.CompressZipByDir(zipFilePath, dirPath)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(fmt.Sprintf("exprot err: %s", err.Error())))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
os.RemoveAll(dirPath)
|
||||||
|
c.FileAttachment(zipFilePath, zipFileName)
|
||||||
|
}
|
||||||
|
|
||||||
// 网元参数配置信息
|
// 网元参数配置信息
|
||||||
//
|
//
|
||||||
// GET /
|
// GET /
|
||||||
@@ -281,8 +310,8 @@ func (s *PtNeConfigDataController) Edit(c *gin.Context) {
|
|||||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||||
changeLog := model.PtNeConfigDataLog{
|
changeLog := model.PtNeConfigDataLog{
|
||||||
CreateBy: currentUserName,
|
CreateBy: currentUserName,
|
||||||
StubType: info.StubType,
|
StubType: param.StubType,
|
||||||
NeType: info.NeType,
|
NeType: param.NeType,
|
||||||
ParamName: info.ParamName,
|
ParamName: info.ParamName,
|
||||||
ParamDisplay: info.ParamDisplay,
|
ParamDisplay: info.ParamDisplay,
|
||||||
ParamType: info.ParamType,
|
ParamType: info.ParamType,
|
||||||
@@ -423,8 +452,8 @@ func (s *PtNeConfigDataController) Add(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
changeLog := model.PtNeConfigDataLog{
|
changeLog := model.PtNeConfigDataLog{
|
||||||
CreateBy: currentUserName,
|
CreateBy: currentUserName,
|
||||||
StubType: info.StubType,
|
StubType: param.StubType,
|
||||||
NeType: info.NeType,
|
NeType: param.NeType,
|
||||||
ParamName: info.ParamName,
|
ParamName: info.ParamName,
|
||||||
ParamDisplay: info.ParamDisplay,
|
ParamDisplay: info.ParamDisplay,
|
||||||
ParamType: info.ParamType,
|
ParamType: info.ParamType,
|
||||||
@@ -537,8 +566,8 @@ func (s *PtNeConfigDataController) Remove(c *gin.Context) {
|
|||||||
// 变更日志
|
// 变更日志
|
||||||
changeLog := model.PtNeConfigDataLog{
|
changeLog := model.PtNeConfigDataLog{
|
||||||
CreateBy: currentUserName,
|
CreateBy: currentUserName,
|
||||||
StubType: info.StubType,
|
StubType: param.StubType,
|
||||||
NeType: info.NeType,
|
NeType: param.NeType,
|
||||||
ParamName: info.ParamName,
|
ParamName: info.ParamName,
|
||||||
ParamDisplay: info.ParamDisplay,
|
ParamDisplay: info.ParamDisplay,
|
||||||
ParamType: info.ParamType,
|
ParamType: info.ParamType,
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ func Setup(router *gin.Engine) {
|
|||||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_EXPORT)),
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_EXPORT)),
|
||||||
controller.NewPtNeConfigData.Export,
|
controller.NewPtNeConfigData.Export,
|
||||||
)
|
)
|
||||||
|
neConfigDataGroup.GET("/export-all",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigData", collectlogs.BUSINESS_TYPE_EXPORT)),
|
||||||
|
controller.NewPtNeConfigData.ExportAll,
|
||||||
|
)
|
||||||
neConfigDataGroup.GET("",
|
neConfigDataGroup.GET("",
|
||||||
middleware.PreAuthorize(nil),
|
middleware.PreAuthorize(nil),
|
||||||
controller.NewPtNeConfigData.Info,
|
controller.NewPtNeConfigData.Info,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -136,7 +137,7 @@ func (r *PtNeConfigApplyRepository) DeleteByIds(paramIds []int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectListByClass 查询班级学生信息
|
// SelectListByClass 查询班级学生信息
|
||||||
func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName string) []map[string]any {
|
func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName, neType string) []map[string]any {
|
||||||
// 查询条件拼接
|
// 查询条件拼接
|
||||||
var conditions []string
|
var conditions []string
|
||||||
var params []any
|
var params []any
|
||||||
@@ -155,16 +156,31 @@ func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName string) [
|
|||||||
}
|
}
|
||||||
// 查询数据
|
// 查询数据
|
||||||
querySql := `SELECT
|
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,
|
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
|
FROM sys_user u
|
||||||
LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
|
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 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
|
` + whereSql
|
||||||
results, err := datasource.RawDB("", querySql, params)
|
results, err := datasource.RawDB("", querySql, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("query err => %v", err)
|
logger.Errorf("query err => %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理数据
|
||||||
|
for i, v := range results {
|
||||||
|
arr := r.SelectList(model.PtNeConfigApply{
|
||||||
|
CreateBy: fmt.Sprint(v["userName"]),
|
||||||
|
NeType: neType,
|
||||||
|
Status: "0",
|
||||||
|
})
|
||||||
|
if len(arr) > 0 {
|
||||||
|
v["applyId"] = arr[0].ID
|
||||||
|
v["applyStatus"] = arr[0].Status
|
||||||
|
} else {
|
||||||
|
v["applyId"] = ""
|
||||||
|
v["applyStatus"] = ""
|
||||||
|
}
|
||||||
|
results[i] = v
|
||||||
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ func (r *PtNeConfigDataLogRepository) SelectPage(query map[string]any) (int64, [
|
|||||||
|
|
||||||
// 查询数量 长度为0直接返回
|
// 查询数量 长度为0直接返回
|
||||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||||
logger.Errorf("total err => %v", err)
|
|
||||||
return total, rows
|
return total, rows
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ func (r *PtNeConfigDataLogRepository) SelectByIds(paramIds []int64) []model.PtNe
|
|||||||
// 查询条件拼接
|
// 查询条件拼接
|
||||||
tx = tx.Where("id in ?", paramIds)
|
tx = tx.Where("id in ?", paramIds)
|
||||||
// 查询数据
|
// 查询数据
|
||||||
if err := tx.Order("imsi asc").Find(&arr).Error; err != nil {
|
if err := tx.Order("id asc").Find(&arr).Error; err != nil {
|
||||||
logger.Errorf("query err => %v", err)
|
logger.Errorf("query err => %v", err)
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
|
|||||||
@@ -66,6 +66,6 @@ func (r *PtNeConfigApplyService) DeleteByIds(paramIds []int64) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectListByClass 查询班级学生信息
|
// SelectListByClass 查询班级学生信息
|
||||||
func (r *PtNeConfigApplyService) SelectListByClass(deptId, userName string) []map[string]any {
|
func (r *PtNeConfigApplyService) SelectListByClass(deptId, userName, neType string) []map[string]any {
|
||||||
return r.ptNeConfigApplyRepository.SelectListByClass(deptId, userName)
|
return r.ptNeConfigApplyRepository.SelectListByClass(deptId, userName, neType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,12 +310,34 @@ func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
|
|||||||
|
|
||||||
// ExportToExcel 导出网元的全部配置项数据
|
// ExportToExcel 导出网元的全部配置项数据
|
||||||
func (r *PtNeConfigDataService) ExportToExcel(operaUserName, fileName string) (string, error) {
|
func (r *PtNeConfigDataService) ExportToExcel(operaUserName, fileName string) (string, error) {
|
||||||
|
param := model.PtNeConfigData{CreateBy: operaUserName}
|
||||||
confs := r.neConfigService.SelectNeConfigByNeType("*")
|
confs := r.neConfigService.SelectNeConfigByNeType("*")
|
||||||
datas := r.ptNeConfigDataRepository.SelectList(model.PtNeConfigData{CreateBy: operaUserName})
|
datas := r.SelectList(param)
|
||||||
if len(datas) == 0 {
|
if len(datas) == 0 {
|
||||||
return "", fmt.Errorf("no changes to data")
|
return "", fmt.Errorf("no changes to data")
|
||||||
}
|
}
|
||||||
return r.writeSheet(confs, datas, fileName)
|
|
||||||
|
// 找教师示例数据 没有就找系统示例数据
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同数据替换
|
||||||
|
for i, v := range list {
|
||||||
|
for _, item := range datas {
|
||||||
|
if item.NeType == v.NeType && item.ParamName == v.ParamName {
|
||||||
|
list[i] = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.writeSheet(confs, list, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeSheet 写入表格
|
// writeSheet 写入表格
|
||||||
|
|||||||
Reference in New Issue
Block a user