|
- package hdl
-
- import (
- implement2 "applet/app/db/implement"
- "applet/app/e"
- "applet/app/enum"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "github.com/gin-gonic/gin"
- )
-
- func MenuList(c *gin.Context) {
- engine := db.Db
- admin := svc.GetUser(c)
- qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
- groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- // 1、查询出当前用户所有角色
- adminRoleDb := implement.NewAdminRoleDb(engine)
- roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- roleDb := implement.NewRoleDb(engine, 0)
- var adminHasPermissionGroupIds []string
- for _, v := range *roles {
- list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- for _, v1 := range list {
- adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
- }
- }
-
- var tempRespMap = map[string]*md.PermissionGroupListResp{}
- var tempRespMapKeys []string
- for _, v := range *groupList {
-
- var isCheck bool
- if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
- isCheck = true
- } else {
- isCheck = false
- }
-
- if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
- isCheck = true
- }
-
- if v.State == enum.PermissionGroupStateForDiscard {
- isCheck = false
- }
-
- tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
- Id: v.Id,
- Name: v.Name,
- Key: v.Key,
- State: v.State,
- ParentId: v.ParentId,
- CreateAt: v.CreateAt,
- UpdateAt: v.UpdateAt,
- IsCheck: isCheck,
- }
- tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
- }
- for _, v := range tempRespMap {
- if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
- tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
- }
- }
- for _, v := range tempRespMap {
- if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
- tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
- }
- }
-
- var resp []*md.PermissionGroupListResp
- for _, v := range tempRespMapKeys {
- if tempRespMap[v].ParentId == 0 {
- resp = append(resp, tempRespMap[v])
- }
- }
-
- e.OutSuc(c, map[string]interface{}{
- "list": resp,
- "state": []map[string]interface{}{
- {
- "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
- "value": enum.PermissionGroupStateForNormal,
- },
- {
- "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
- "value": enum.PermissionGroupStateForDiscard,
- },
- },
- }, nil)
- return
- }
-
- // GetBaseInfo
- // @Summary 获取系统信息
- // @Tags 公共模块
- // @Description 公共模块-获取系统信息
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/comm/basicGet [GET]
- func GetBaseInfo(c *gin.Context) {
- masterId := "0"
- engine := db.Db
- sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
- res := sysCfgDb.SysCfgFindWithDb(enum.AppLogo, enum.AppName)
-
- e.OutSuc(c, md.BasicSetResp{
- AppName: res[enum.AppName],
- AppLogo: res[enum.AppLogo],
- }, nil)
- return
- }
-
- // UploadFile
- // @Summary 上传文件
- // @Tags 公共模块
- // @Description 公共模块-上传文件
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept multipart/form-data
- // @Produce multipart/form-data
- // @Param file formData file true "上传的文件"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/comm/uploadFile [POST]
- func UploadFile(c *gin.Context) {
- // 单文件上传
- file, err := c.FormFile("file")
- if err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
-
- dst := "./static/upload/" + file.Filename
- if err = c.SaveUploadedFile(file, dst); err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, map[string]string{
- "url": c.Request.Host + "/api/comm/upload/" + file.Filename,
- }, nil)
- return
- }
|