Explorar o código

feature(web): 用户管理增加导出功能

sunmiao %!s(int64=2) %!d(string=hai) anos
pai
achega
42a64bf56c
Modificáronse 2 ficheiros con 130 adicións e 2 borrados
  1. 48 0
      .gitignore
  2. 82 2
      backend/src/dashoo.cn/mcs_api/controllers/user.go

+ 48 - 0
.gitignore

@@ -0,0 +1,48 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+pkg
+
+*.exe
+*.test
+*.prof
+
+# dist目录
+sample/front_end
+
+# 生成的可执行文件
+sample/sample
+src/dashoo.cn/mms_api/mms_api
+src/dashoo.cn/mcs_api_weixin/mms_api_weixin
+src/dashoo.cn/triggerservice/triggerservice
+src/dashoo.cn/qatoolsweb/qatoolsweb
+mcs_web_api
+mcs_api_weixin
+alertorapp
+
+# 上传下载的临时目录
+backend/src/dashoo.cn/mcs_api/static/file
+
+# beego临时文件
+lastupdate.tmp
+commentsRouter_*.go
+
+.idea

+ 82 - 2
backend/src/dashoo.cn/mcs_api/controllers/user.go

@@ -3,9 +3,9 @@ package controllers
 import (
 	"encoding/json"
 	"fmt"
-	"strings"
-
 	"github.com/nsqio/go-nsq"
+	"github.com/tealeg/xlsx"
+	"strings"
 
 	"dashoo.cn/base_common/business/auth"
 	"dashoo.cn/base_common/business/permission"
@@ -751,3 +751,83 @@ func sendFaceLockCheckMsg(userId, action string) {
 		fmt.Println("发送NSQ消息失败:", err)
 	}
 }
+
+// @Title 获取下载文件
+// @Description 获取下载文件
+// @Success 200 {object} ErrorInfo
+// @router /downfile [get]
+func (this *UserController) GetDownFile() {
+	keyword := this.GetString("keyword")
+	svc := permission.GetPermissionService(utils.DBE)
+	var users []userRole.Base_User
+
+	where := "IsVisible=1 and CreateUserId='" + utils.ToStr(this.User.Id) + "' "
+	if keyword != "" {
+		where = where + " and Realname like '%" + keyword + "%'"
+	}
+
+	//svc.GetEntities(&users, where)
+	svc.GetEntitiesByWhereOrder(&users, "ID desc", where)
+	xlsx.PagePrintheadContant = "用户列表"
+	f := xlsx.NewFile()
+	this.SaveXlsx(users, f)
+	SaveDirectory("static/file/excel/u/" + this.GetAccode())
+	f.Save("static/file/excel/u/" + this.GetAccode() + "/users.xlsx")
+
+	var errinfo ErrorInfo
+	errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/u/" + this.GetAccode() + "/users.xlsx"
+	errinfo.Code = 0
+	this.Data["json"] = &errinfo
+	this.ServeJSON()
+}
+
+func (this *UserController) SaveXlsx(list []userRole.Base_User, f *xlsx.File) {
+	sheet, _ := f.AddSheet("users")
+	rowhead := sheet.AddRow()
+	cell := rowhead.AddCell()
+	cell.Value = "序号"
+	cell = rowhead.AddCell()
+	cell.Value = "账号"
+	cell = rowhead.AddCell()
+	cell.Value = "用户名"
+	cell = rowhead.AddCell()
+	cell.Value = "手机"
+	cell = rowhead.AddCell()
+	cell.Value = "角色"
+	cell = rowhead.AddCell()
+	cell.Value = "备注"
+	cell = rowhead.AddCell()
+	cell.Value = "所属组织"
+
+	for i, v := range list {
+		row := sheet.AddRow()
+		cell = row.AddCell()
+		cell.Value = utils.ToStr(i + 1)
+		cell = row.AddCell()
+		cell.Value = v.Username
+		cell = row.AddCell()
+		cell.Value = v.Realname
+		cell = row.AddCell()
+		cell.Value = v.Telephone
+		cell = row.AddCell()
+		switch v.Roleid {
+		case 10000123:
+			cell.Value = "普通用户"
+		case 10000119:
+			cell.Value = "管理用户"
+		default:
+			cell.Value = "其他"
+		}
+		cell = row.AddCell()
+		cell.Value = v.Description
+		cell = row.AddCell()
+		cell.Value = v.Departmentname
+	}
+	sheet.Cols[0].Width = 8 //设置时间单元格的宽度
+	sheet.Cols[1].Width = 20
+	sheet.Cols[2].Width = 20
+	sheet.Cols[3].Width = 20
+	sheet.Cols[4].Width = 16
+	sheet.Cols[5].Width = 25
+	sheet.Cols[6].Width = 25
+}