12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/models/system/response"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- // 分类
- type ClassifyController struct {
- BaseAuthController
- }
- // Add
- // @Title 新增分类接口
- // @Description 新增分类
- // @Param request body models.ClassifyAddReq true "type json string"
- // @Success 200 新增成功
- // @router /add [post]
- func (this *ClassifyController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ClassifyAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
- /*menus, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, ``)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
- return
- }
- menuMap := make(map[string]bool)
- for _, m := range menus {
- if m.ButtonCode != "" {
- menuMap[m.ButtonCode] = true
- }
- }*/
- if req.ClassifyName == "" {
- br.Msg = "分类名称不可为空"
- return
- }
- if req.ClassifyType != utils.ReportTypeDefault && req.ClassifyType != utils.ReportTypePPT {
- br.Msg = "分类类型有误"
- br.ErrMsg = fmt.Sprintf("分类类型有误, %d", req.ClassifyType)
- return
- }
- if req.IsRemind == 1 {
- if req.RemindTime == "" {
- br.Msg = "请选择报告提醒时间"
- return
- }
- _, e := time.Parse("15:04", req.RemindTime)
- if e != nil {
- br.Msg = "提醒时间格式有误"
- br.ErrMsg = fmt.Sprintf("提醒时间格式有误, %s", req.RemindTime)
- return
- }
- }
- // 新增分类
- err, errMsg, isSentEmail := services.AddReportClassify(req.ClassifyName, req.ParentId, req.ClassifyType, req.IsRemind, req.RemindTime, req.VisibleUserIds)
- if err != nil {
- br.Msg = "添加失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "添加失败,Err:" + err.Error()
- br.IsSendEmail = isSentEmail
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // CheckDeleteClassify
- // @Title 删除分类-检测接口
- // @Description 删除分类-信息检测,是否符合删除条件
- // @Param ClassifyId query int true "分类ID"
- // @Success 200 {object} models.CheckDeleteClassifyResp
- // @router /checkDeleteClassify [get]
- func (this *ClassifyController) CheckDeleteClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, err := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- classify, e := models.GetClassifyById(classifyId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "分类不存在,请刷新页面"
- return
- }
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- resp := new(models.CheckDeleteClassifyResp)
- if classify == nil {
- br.Msg = "分类不存在"
- resp.Code = 1
- resp.Msg = "分类不存在"
- br.Data = resp
- br.Ret = 200
- br.Success = true
- return
- }
- if classify.ReportNum > 0 {
- resp.Code = 2
- resp.Msg = "该分类或子分类下有关联报告,不允许删除"
- br.Data = resp
- br.Ret = 200
- br.Msg = "该分类或子分类下有关联报告,不允许删除"
- br.Success = true
- return
- }
- //判断分类是否关联了报告
- //if classify.ParentId > 0 {
- // count, err := models.GetReportCountByClassifyId(classifyId)
- // if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- // }
- // if count > 0 {
- // resp.Code = 2
- // resp.Msg = "该分类有关联报告,不允许删除"
- // br.Data = resp
- // br.Ret = 200
- // br.Msg = "该分类有关联报告,不允许删除"
- // br.Success = true
- // return
- // }
- //} else {
- // subCount, err := models.GetClassifySubCountByClassifyId(classifyId)
- // if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- // }
- // if subCount > 0 {
- // resp.Code = 3
- // resp.Msg = "二级分类有关联报告,不允许删除"
- // br.Data = resp
- // br.Ret = 200
- // br.Msg = "二级分类有关联报告,不允许删除"
- // br.Success = true
- // return
- // }
- // subTotal, err := models.GetClassifySubCountByParentId(classifyId)
- // if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- // }
- // if subTotal > 0 {
- // resp.Code = 4
- // resp.Msg = "请先删除该分类下关联分类"
- // br.Data = resp
- // br.Ret = 200
- // br.Msg = "请先删除该分类下关联分类"
- // br.Success = true
- // return
- // }
- //}
- // 查询该分类是否关联了审批流
- //flowOb := new(report_approve.ReportApproveFlow)
- //flowCond := fmt.Sprintf(` AND %s = ? AND (%s = ? OR %s = ?)`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
- //flowPars := make([]interface{}, 0)
- //flowPars = append(flowPars, report_approve.FlowReportTypeChinese, classifyId, classifyId)
- //flowCount, e := flowOb.GetCountByCondition(flowCond, flowPars)
- //if e != nil {
- // br.Msg = "检测失败"
- // br.ErrMsg = "获取关联审批流失败, Err: " + e.Error()
- // return
- //}
- //if flowCount > 0 {
- // resp.Code = 5
- // resp.Msg = "该分类关联审批流,不允许删除"
- // br.Data = resp
- // br.Ret = 200
- // br.Msg = resp.Msg
- // br.Success = true
- // return
- //}
- resp.Code = 0
- resp.Msg = "检测完成,可进行删除操作"
- br.Ret = 200
- br.Data = resp
- br.Success = true
- br.Msg = "检测成功"
- }
- // Delete
- // @Title 删除分类接口
- // @Description 删除分类
- // @Param request body models.DeleteClassifyReq true "type json string"
- // @Success 200 Ret=200,删除成功
- // @router /delete [post]
- func (this *ClassifyController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, e := models.GetClassifyById(req.ClassifyId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- return
- }
- br.Msg = "删除失败"
- br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
- return
- }
- // 删除校验(上级分类报告数为子分类总和)
- if item.ReportNum > 0 {
- br.Msg = "分类下或子分类下有关联报告, 不允许删除"
- return
- }
- var removeIds []int
- {
- list, e := models.GetAllClassify()
- if e != nil {
- br.Msg = "删除失败"
- br.ErrMsg = fmt.Sprintf("获取所有分类失败, %v", e)
- return
- }
- removeIds = services.GetClassifyChildIdsTreeRecursive(list, item.Id)
- }
- removeIds = append(removeIds, item.Id)
- if e = models.DeleteClassify(removeIds); e != nil {
- br.Msg = "删除失败"
- br.ErrMsg = fmt.Sprintf("删除分类及子分类失败, %v", e)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // Edit
- // @Title 修改分类接口
- // @Description 修改分类
- // @Param request body models.EditClassifyReq true "type json string"
- // @Success 200 Ret=200,修改成功
- // @router /edit [post]
- func (this *ClassifyController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EditClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "分类名称不可为空"
- return
- }
- if req.IsRemind == 1 {
- if req.RemindTime == "" {
- br.Msg = "请选择报告提醒时间"
- return
- }
- _, e := time.Parse("15:04", req.RemindTime)
- if e != nil {
- br.Msg = "提醒时间格式有误"
- br.ErrMsg = fmt.Sprintf("提醒时间格式有误, %s", req.RemindTime)
- return
- }
- }
- // 修改分类
- err, errMsg, isSentEmail := services.EditReportClassify(req.ClassifyId, req.ClassifyName, req.IsRemind, req.RemindTime, req.VisibleUserIds)
- if err != nil {
- br.Msg = "修改失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "修改失败,Err:" + err.Error()
- br.IsSendEmail = isSentEmail
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- }
- // ParentClassify
- // @Title 获取父级分类接口
- // @Description 获取父级分类
- // @Success 200 {object} models.Classify
- // @router /parent [get]
- func (this *ClassifyController) ParentClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- items, err := models.GetAllClassify()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIds := make([]int, 0)
- for i := range items {
- classifyIds = append(classifyIds, items[i].Id)
- }
- classifyLen := len(classifyIds)
- if classifyLen == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取一级分类-子目录列表
- menuListMap := make(map[int][]*models.ClassifyMenu, 0)
- var menuCond string
- var menuPars []interface{}
- menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(classifyLen) + `)`
- menuPars = append(menuPars, classifyIds)
- parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取一级分类子目录列表失败"
- return
- }
- for i := range parentMenus {
- if menuListMap[parentMenus[i].ClassifyId] == nil {
- menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
- }
- menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
- }
- resp := make([]*models.ClassifyItem, 0)
- for i := range items {
- resp = append(resp, &models.ClassifyItem{
- Classify: *items[i],
- ClassifyMenuList: menuListMap[items[i].Id],
- })
- }
- resp = services.GetClassifyTreeRecursive(resp, 0)
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 根据id获取分类详情接口
- // @Description 根据id获取分类详情
- // @Param request body models.FindByIdClassifyReq true "type json string"
- // @Success 200 {object} models.Classify
- // @router /findById [get]
- func (this *ClassifyController) FindByIdClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.FindByIdClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- items, err := models.FindByIdClassify(req.ClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // ListClassify
- // @Title 获取分类列表
- // @Description 获取分类列表
- // @Param KeyWord query string true "检索关键词"
- // @Param ClassifyType query int false "分类类型:0-全部(默认);1-研报;2-PPT"
- // @Param Enabled query int false "启用状态:-1-全部(默认);0-禁用;1-启用"
- // @Success 200 {object} models.Classify
- // @router /list [get]
- func (this *ClassifyController) ListClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyType, _ := this.GetInt("ClassifyType", 0)
- keyWord := this.GetString("KeyWord")
- reqEnabled, _ := this.GetInt("Enabled", -1)
- enabled := -1
- if reqEnabled == 1 {
- enabled = reqEnabled
- }
- //list, err := models.GetClassifyListByKeyword(keyWord, enabled, classifyType)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //
- //if keyWord != `` {
- // idMap := make(map[int]bool)
- //
- // currParentClassifyIdList := make([]int, 0)
- // for _, v := range list {
- // idMap[v.Id] = true
- // if v.ParentId > 0 {
- // currParentClassifyIdList = append(currParentClassifyIdList, v.ParentId)
- // }
- // }
- //
- // findList := list
- // list = make([]*models.ClassifyList, 0)
- //
- // tmpList, tmpErr := services.GetParentClassifyListByParentIdList(currParentClassifyIdList)
- // if tmpErr != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取上级分类信息失败,Err:" + tmpErr.Error()
- // return
- // }
- // for _, v := range tmpList {
- // if _, ok := idMap[v.Id]; !ok {
- // list = append(list, v)
- // }
- // }
- //
- // list = append(list, findList...)
- //}
- //
- //classifyIdList := make([]int, 0)
- //for i := range list {
- // classifyIdList = append(classifyIdList, list[i].Id)
- //}
- //parentIdLen := len(classifyIdList)
- //if parentIdLen == 0 {
- // resp := &models.ClassifyListResp{
- // List: list,
- // }
- // br.Data = resp
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "获取成功"
- // return
- //}
- //
- //// 获取子目录列表
- //menuListMap := make(map[int][]*models.ClassifyMenu, 0)
- //var menuCond string
- //var menuPars []interface{}
- //menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
- //menuPars = append(menuPars, classifyIdList)
- //parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
- //if e != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取一级分类子目录列表失败"
- // return
- //}
- //for i := range parentMenus {
- // if menuListMap[parentMenus[i].ClassifyId] == nil {
- // menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
- // }
- // menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
- //}
- //
- //// 分类与子目录关联
- //relateMap := make(map[int]int, 0)
- //{
- // var relateCond string
- // var relatePars []interface{}
- // relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
- // relatePars = append(relatePars, classifyIdList)
- // relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
- // if e != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
- // return
- // }
- // for i := range relates {
- // relateMap[relates[i].ClassifyId] = relates[i].MenuId
- // }
- //}
- //
- //// 查询分类绑定的权限
- //permissionList, _ := models.GetAllPermissionMapping()
- //classifyPermissionMap := make(map[int][]int)
- //if len(permissionList) > 0 {
- // for _, v := range permissionList {
- // classifyPermissionMap[v.ClassifyId] = append(classifyPermissionMap[v.ClassifyId], v.ChartPermissionId)
- // }
- //}
- //// 遍历分类并绑定子目录和权限
- //for i, v := range list {
- // list[i].ClassifyMenuList = menuListMap[v.Id]
- //
- // list[i].ClassifyMenuId = relateMap[v.Id]
- // if permissionIds, ok := classifyPermissionMap[v.Id]; ok {
- // list[i].ChartPermissionIdList = permissionIds
- // }
- //}
- // 获取所有分类
- originList, err := models.GetClassifyListByKeyword("", enabled, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list := originList
- visibleUsers, err := models.GetClassifyVisibleAll()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- visibleUserMap := make(map[int][]int)
- for _, v := range visibleUsers {
- visibleUserMap[v.ClassifyId] = append(visibleUserMap[v.ClassifyId], v.AdminId)
- }
- for i, v := range list {
- list[i].VisiableUsers = visibleUserMap[v.Id]
- }
- // 指定分类类型(上级中的分类类型可能与最下层的不一致,但是要把上级也一起取出来, 这需求...=_=!)
- if classifyType > 0 {
- list = make([]*models.ClassifyList, 0)
- // 先取出指定分类以及他对应的LevelPath中的所有ID
- classifyIds := make([]int, 0)
- for _, v := range originList {
- if v.ClassifyType != classifyType {
- continue
- }
- pathArr := strings.Split(v.LevelPath, ",")
- for _, p := range pathArr {
- id, _ := strconv.Atoi(p)
- if id <= 0 {
- continue
- }
- if utils.InArrayByInt(classifyIds, id) {
- continue
- }
- classifyIds = append(classifyIds, id)
- }
- }
- // 过滤掉不在ID中的
- for _, v := range originList {
- if !utils.InArrayByInt(classifyIds, v.Id) {
- continue
- }
- if visible, ok := visibleUserMap[v.Id]; ok {
- if !utils.InArrayByInt(visible, this.SysUser.AdminId) {
- continue
- }
- }
- list = append(list, v)
- }
- }
- // 有关键词,那么按照上面的方法再筛一遍
- keyWord = strings.TrimSpace(keyWord)
- if keyWord != `` {
- classifyIds := make([]int, 0)
- for _, v := range list {
- if !strings.Contains(v.ClassifyName, keyWord) {
- continue
- }
- pathArr := strings.Split(v.LevelPath, ",")
- for _, p := range pathArr {
- id, _ := strconv.Atoi(p)
- if id <= 0 {
- continue
- }
- if utils.InArrayByInt(classifyIds, id) {
- continue
- }
- classifyIds = append(classifyIds, id)
- }
- }
- for _, v := range originList {
- if !utils.InArrayByInt(classifyIds, v.Id) {
- continue
- }
- list = append(list, v)
- }
- }
- // 先将分类列表排序
- services.SortClassifyListBySortAndCreateTime(list)
- // 接着转换结构
- list = services.GetClassifyListTreeRecursive(list, 0)
- // 过滤掉没有子目录的分类
- list = services.RecursiveFilterNoChildTreeClassify(list)
- resp := new(models.ClassifyListResp)
- resp.List = list
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // ClassifyPermission
- // @Title 获取分类权限列表
- // @Description 获取分类权限列表
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} []models.ChartPermissionSearchKeyWordMapping
- // @router /permission_list [get]
- func (this *ClassifyController) ClassifyPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- //获取报告分类详情
- classifyInfo, err := models.GetClassifyById(classifyId)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //获取报告分类权限列表
- list, err := models.GetPermissionByClassifyId(classifyInfo.Id)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // EditClassifyPermission
- // @Title 编辑分类权限
- // @Description 编辑分类权限
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} models.EditClassifyPermissionReq
- // @router /permission/edit [post]
- func (this *ClassifyController) EditClassifyPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EditClassifyPermissionReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- if len(req.ChartPermissionIdList) <= 0 {
- br.Msg = "请选择权限"
- return
- }
- //获取报告分类详情
- classifyInfo, err := models.GetClassifyById(req.ClassifyId)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //获取报告分类权限列表
- err = models.EditChartPermissionSearchKeyWordMappingMulti(classifyInfo.ClassifyName, req.ChartPermissionIdList, req.ClassifyId)
- if err != nil {
- br.Msg = "修改分类权限失败"
- br.ErrMsg = "修改分类权限失败,Err:" + err.Error()
- return
- }
- go func() {
- _ = services.EditClassifyChartPermissionSync(classifyInfo.ClassifyName, req.ClassifyId)
- }()
- // 是关联电话会二级分类修改了权限, 同步关联报告电话会的分类
- //if classifyInfo.ParentId > 0 && classifyInfo.RelateTel == 1 {
- // go func() {
- // _ = yb.SyncClassifyAndFiccActivityType()
- // }()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- }
- // @Title 含电话会分类列表
- // @Description 含电话会分类列表
- // @Success 200 {object} models.Classify
- // @router /tel_list [get]
- func (this *ClassifyController) TelListClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := make([]*models.SimpleClassifyList, 0)
- var condition, orderRule string
- var pars []interface{}
- telList, e := models.GetClassifyByCondition(condition, orderRule, pars)
- if e != nil {
- return
- }
- firstList := make([]*models.SimpleClassifyList, 0)
- secondList := make([]*models.SimpleClassifyList, 0)
- secondMap := make(map[int][]*models.SimpleClassifyList, 0)
- for i := range telList {
- if telList[i].ParentId == 0 {
- firstList = append(firstList, telList[i])
- } else {
- secondList = append(secondList, telList[i])
- secondMap[telList[i].ParentId] = append(secondMap[telList[i].ParentId], telList[i])
- }
- }
- for i := range firstList {
- firstList[i].Child = secondMap[firstList[i].Id]
- }
- resp = firstList
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Move
- // @Title 移动分类接口
- // @Description 移动分类
- // @Param request body models.ClassifyMoveReq true "type json string"
- // @Success 200 新增成功
- // @router /move [post]
- func (this *ClassifyController) Move() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ClassifyMoveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- e, msg := services.MoveReportClassify(req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "移动分类失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // SetEnabled
- // @Title 启用/禁用分类接口
- // @Description 启用/禁用分类
- // @Param request body models.ClassifyMoveReq true "type json string"
- // @Success 200 新增成功
- // @router /enabled/set [post]
- func (this *ClassifyController) SetEnabled() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ClassifySetEnabledReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- if req.Enabled != 0 && req.Enabled != 1 {
- br.Msg = "请选择正确的启用禁用状态"
- return
- }
- item, err := models.GetClassifyById(req.ClassifyId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "分类不存在"
- return
- }
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- return
- }
- ob := new(models.Classify)
- //设置分类启用、禁用状态
- err = ob.SetEnabled(req.ClassifyId, req.Enabled)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ClassifyPermissionV2
- // @Title 获取权限设置基础信息
- // @Description 获取权限设置基础信息接口
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param NoUpgrade query bool false "是否不展示升级权限,默认为 false"
- // @Success 200 {object} company.PermissionSetResp
- // @router /permission/list [get]
- func (this *ClassifyController) ClassifyPermissionV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- resp := make([]*models.ChartPermissionItem, 0)
- // 拥有的品种ID列表
- permissionIdMap := make(map[int]bool)
- {
- //获取报告分类详情
- classifyInfo, err := models.GetClassifyById(classifyId)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //获取报告分类权限列表
- list, err := models.GetPermission(classifyInfo.Id)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- permissionIdMap[v.ChartPermissionId] = true
- }
- }
- // 没有关联品种时,直接返回
- num := len(permissionIdMap)
- if num <= 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- cond := ` and product_id = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, 1)
- list, e := services.GetChartPermissionList(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
- return
- }
- // 品种树
- childMap := make(map[int][]*models.ChartPermissionItem)
- tmpResp := make([]*models.ChartPermissionItem, 0)
- for _, v := range list {
- t := new(models.ChartPermissionItem)
- t.PermissionId = v.ChartPermissionId
- t.PermissionName = v.PermissionName
- t.ParentId = v.ParentId
- t.IsPublic = v.IsPublic
- t.Enabled = v.Enabled
- t.Sort = v.Sort
- t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
- t.Child = make([]*models.ChartPermissionItem, 0)
- if v.ParentId == 0 {
- tmpResp = append(tmpResp, t)
- continue
- }
- if v.ParentId > 0 {
- if _, ok := permissionIdMap[v.ChartPermissionId]; ok {
- if childMap[v.ParentId] == nil {
- childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
- }
- childMap[v.ParentId] = append(childMap[v.ParentId], t)
- }
- }
- }
- for _, r := range tmpResp {
- childList, ok := childMap[r.PermissionId]
- if !ok {
- continue
- }
- r.Child = childList
- resp = append(resp, r)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // AdminList
- // @Title 用户列表
- // @Description 用户列表
- // @Success 200 {object} company.PermissionSetResp
- // @router /user/list [get]
- func (this *ClassifyController) AdminList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- adminList, err := system.GetSysAdminListAll()
- if err != nil {
- br.Msg = "获取管理员列表失败"
- br.ErrMsg = "获取管理员列表失败, Err: " + err.Error()
- }
- list := make([]*response.AdminItem, 0)
- for _, v := range adminList {
- item := new(response.AdminItem)
- item.AdminId = v.AdminId
- item.AdminName = v.AdminName
- item.RealName = v.RealName
- list = append(list, item)
- }
- resp := new(response.AdminListResp)
- resp.List = list
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|