fix: 系统数据导出格式优化

This commit is contained in:
TsMask
2024-04-22 18:18:59 +08:00
parent c59bb61ae2
commit 78226df9bd
10 changed files with 39 additions and 35 deletions

View File

@@ -474,21 +474,18 @@ func (s *SysUserController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
// querys := ctx.BodyJSONMap(c)
querys := map[string]any{
"pageNum": 1,
"pageSize": 1000,
}
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
// data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
// if data["total"].(int64) == 0 {
// // 导出数据记录为空
// c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
// return
// }
// rows := data["rows"].([]model.SysUser)
rows := s.sysUserService.SelectUserList(model.SysUser{}, dataScopeSQL)
if len(rows) <= 0 {
data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
if data["total"].(int64) == 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysUser)
// 闭包函数处理多语言
converI18n := func(language string, arr *[]model.SysUser) {
@@ -543,9 +540,7 @@ func (s *SysUserController) Export(c *gin.Context) {
// 用户角色, 默认导出首个
userRole := ""
if len(row.Roles) > 0 {
roleID := row.Roles[0].RoleID
roleName := i18n.TKey(language, row.Roles[0].RoleName)
userRole = fmt.Sprintf("%s-%s", roleID, roleName)
userRole = i18n.TKey(language, row.Roles[0].RoleName)
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.UserID,