123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/report_approve"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // 分类
- type ClassifyController struct {
- BaseAuthController
- }
- // @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() {
- 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 menuMap[system.MenuSpecialHandleClassifyShowType] && req.ParentId != 0 && req.ShowType == 0 {
- br.Msg = "展示类型不可为空"
- return
- }
- if menuMap[system.MenuSpecialHandleClassifyChildMenu] && len(req.MenuList) > 0 && req.ParentId != 0 {
- br.Msg = "非一级分类不可添加子目录"
- return
- }
- if menuMap[system.MenuSpecialHandleClassifyReportImgs] && (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && req.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
- br.Msg = "报告合集配图不可为空"
- return
- }
- item, err := models.GetClassifyByName(req.ClassifyName, req.ParentId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- br.Msg = "分类名称:" + req.ClassifyName + "已存在"
- return
- }
- nowTime := time.Now().Local()
- classify := new(models.Classify)
- classify.ClassifyName = req.ClassifyName
- classify.ParentId = req.ParentId
- classify.CreateTime = nowTime
- classify.ModifyTime = nowTime
- classify.Abstract = req.Abstract
- classify.Descript = req.Descript
- classify.Abstract = req.Abstract
- classify.Descript = req.Descript
- classify.ReportAuthor = req.ReportAuthor
- classify.AuthorDescript = req.AuthorDescript
- classify.ColumnImgUrl = req.ColumnImgUrl
- classify.ReportImgUrl = req.ReportImgUrl
- classify.HeadImgUrl = req.HeadImgUrl
- classify.AvatarImgUrl = req.AvatarImgUrl
- classify.HomeImgUrl = req.HomeImgUrl
- classify.ClassifyLabel = req.ClassifyLabel
- classify.ShowType = req.ShowType
- classify.HasTeleconference = req.HasTeleconference
- classify.VipTitle = req.VipTitle
- classify.Sort = req.Sort
- classify.IsShow = req.IsShow
- classify.YbFiccSort = req.YbFiccSort
- classify.YbFiccIcon = req.YbFiccIcon
- classify.YbFiccPcIcon = req.YbFiccPcIcon
- classify.YbIconUrl = req.YbIconUrl
- classify.YbBgUrl = req.YbBgUrl
- classify.YbListImg = req.YbListImg
- classify.YbShareBgImg = req.YbShareBgImg
- classify.YbRightBanner = req.YbRightBanner
- classify.RelateTel = req.RelateTel
- classify.RelateVideo = req.RelateVideo
- if req.ParentId > 0 {
- parentClassify := new(models.Classify)
- if parentClassify, err = models.GetClassifyById(req.ParentId); err != nil {
- br.Msg = "获取父级分类信息失败"
- br.ErrMsg = "获取父级分类信息失败, Err:" + err.Error()
- return
- }
- updateParent := false
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "HasTeleconference")
- if req.HasTeleconference == 1 {
- // 二级分类包含电话会,则一级分类也默认包含电话会
- if parentClassify.HasTeleconference == 0 {
- parentClassify.HasTeleconference = 1
- updateParent = true
- }
- } else {
- // 二级分类均无电话会,则一级分类也无电话会
- if parentClassify.HasTeleconference == 1 {
- child, err := models.GetClassifyChild(parentClassify.Id, "")
- if err != nil {
- br.Msg = "获取子分类失败"
- br.ErrMsg = "获取子分类失败,Err:" + err.Error()
- return
- }
- // 存在同一级分类下的二级分类有电话会则不变动
- hasTel := false
- for i := 0; i < len(child); i++ {
- if child[i].HasTeleconference == 1 {
- hasTel = true
- break
- }
- }
- if !hasTel {
- parentClassify.HasTeleconference = 0
- updateParent = true
- }
- }
- }
- if updateParent {
- if err = parentClassify.UpdateClassify(updateCols); err != nil {
- br.Msg = "更新父级分类失败"
- br.ErrMsg = "更新父级分类失败, Err:" + err.Error()
- return
- }
- }
- }
- err = models.AddClassify(classify)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- // 一级分类-新增子目录
- if classify.ParentId == 0 && len(req.MenuList) > 0 {
- menus := make([]*models.ClassifyMenu, 0)
- for i := range req.MenuList {
- menus = append(menus, &models.ClassifyMenu{
- MenuName: req.MenuList[i].MenuName,
- ClassifyId: classify.Id,
- Sort: i + 1,
- CreateTime: nowTime,
- ModifyTime: nowTime,
- })
- }
- menuObj := new(models.ClassifyMenu)
- if e := menuObj.InsertMulti(menus); e != nil {
- br.Msg = "新增子目录失败"
- br.ErrMsg = "批量新增子目录失败, Err:" + e.Error()
- return
- }
- }
- // 二级分类-新增子目录关联
- if classify.ParentId > 0 && req.ClassifyMenuId > 0 {
- if e := models.DeleteAndInsertClassifyMenuRelation(classify.Id, req.ClassifyMenuId); e != nil {
- br.Msg = "新增子目录关联失败"
- br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
- return
- }
- }
- // 新增关联了电话会的二级分类时, 同步FICC活动分类
- //if req.ParentId > 0 && req.RelateTel == 1 {
- // go func() {
- // _ = yb.SyncClassifyAndFiccActivityType()
- // }()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // @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, err := models.GetClassifyById(classifyId)
- if err != nil {
- 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.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 = ? OR %s = ?) AND (%s = ? OR %s = ?)`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, report_approve.FlowReportTypeChinese, report_approve.FlowReportTypeSmart, 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 = "检测成功"
- }
- // @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, err := models.GetClassifyById(req.ClassifyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- return
- }
- err = models.DeleteClassify(req.ClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- // 被删除是二级分类且关联电话会时, 同步FICC活动分类
- //if item.ParentId > 0 && item.RelateTel == 1 {
- // go func() {
- // _ = yb.SyncClassifyAndFiccActivityType()
- // }()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @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
- }
- // 获取系统菜单, 如果没有对应的字段的特殊处理项, 则忽略必填
- 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.ClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "分类名称不可为空"
- return
- }
- if menuMap[system.MenuSpecialHandleClassifyShowType] && req.ParentId != 0 && req.ShowType == 0 {
- br.Msg = "展示类型不可为空"
- return
- }
- if req.ParentId == req.ClassifyId {
- br.Msg = "上级分类不能选择自己"
- return
- }
- if menuMap[system.MenuSpecialHandleClassifyReportImgs] && (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && req.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
- br.Msg = "报告合集配图不可为空"
- return
- }
- item, err := models.GetClassifyById(req.ClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在, 或已被删除"
- br.ErrMsg = "获取分类信息失败, Err: " + err.Error()
- return
- }
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- originName := item.ClassifyName
- oldParentId := item.ParentId
- //originRelateTel := item.RelateTel
- // 重名校验
- existName, e := models.GetClassifyByName(req.ClassifyName, item.ParentId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取重名分类失败, Err: " + err.Error()
- return
- }
- if existName != nil && existName.Id != item.Id {
- br.Msg = "分类名称:" + req.ClassifyName + "已存在"
- return
- }
- item.ClassifyName = req.ClassifyName
- item.Abstract = req.Abstract
- item.ParentId = req.ParentId
- item.Descript = req.Descript
- item.ReportAuthor = req.ReportAuthor
- item.AuthorDescript = req.AuthorDescript
- item.ColumnImgUrl = req.ColumnImgUrl
- item.HeadImgUrl = req.HeadImgUrl
- item.AvatarImgUrl = req.AvatarImgUrl
- item.ReportImgUrl = req.ReportImgUrl
- item.HomeImgUrl = req.HomeImgUrl
- item.ClassifyLabel = req.ClassifyLabel
- item.ShowType = req.ShowType
- item.HasTeleconference = req.HasTeleconference
- item.VipTitle = req.VipTitle
- item.Sort = req.Sort
- item.IsShow = req.IsShow
- item.YbFiccSort = req.YbFiccSort
- item.YbFiccIcon = req.YbFiccIcon
- item.YbFiccPcIcon = req.YbFiccPcIcon
- item.YbIconUrl = req.YbIconUrl
- item.YbBgUrl = req.YbBgUrl
- item.YbListImg = req.YbListImg
- item.YbShareBgImg = req.YbShareBgImg
- item.YbRightBanner = req.YbRightBanner
- item.RelateTel = req.RelateTel
- item.RelateVideo = req.RelateVideo
- item.ModifyTime = time.Now().Local()
- cols := make([]string, 0)
- cols = append(cols, "ClassifyName", "Abstract", "ParentId", "Descript", "ReportAuthor", "AuthorDescript", "ColumnImgUrl",
- "HeadImgUrl", "AvatarImgUrl", "ReportImgUrl", "HomeImgUrl", "ClassifyLabel", "ShowType", "HasTeleconference", "VipTitle", "Sort",
- "IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner",
- "RelateTel", "RelateVideo", "ModifyTime")
- if e := item.UpdateClassify(cols); e != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "修改失败,Err:" + e.Error()
- return
- }
- // 一级分类关联设置会强制修改二级分类的所有关联设置
- if item.ParentId == 0 {
- if e = models.UpdateChildClassifyRelateSetting(item.Id, req.RelateTel, req.RelateVideo); e != nil {
- br.Msg = "更新二级分类关联设置失败"
- br.ErrMsg = "更新二级分类关联设置失败, Err: " + e.Error()
- return
- }
- }
- // 为二级分类时, 更新父级分类是否含电话会字段
- if req.ParentId > 0 {
- go func() {
- _ = services.UpdateParentClassifyHasTel(req.ClassifyId, req.ParentId, req.HasTeleconference)
- }()
- }
- // 更新报告分类名称/父级分类后
- go func() {
- _ = services.AfterUpdateClassifyNameOrParent(item.Id, item.ParentId, oldParentId, originName, item.ClassifyName)
- }()
- // 获取编辑前子目录列表
- classifyId := item.Id
- var menuCond string
- var menuPars []interface{}
- menuCond += ` AND classify_id = ?`
- menuPars = append(menuPars, classifyId)
- menuList, e := models.GetClassifyMenuList(menuCond, menuPars)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "获取分类子目录列表失败, Err:" + e.Error()
- return
- }
- oriMenuIds := make([]int, 0)
- for i := range menuList {
- oriMenuIds = append(oriMenuIds, menuList[i].MenuId)
- }
- // 一级分类-新增/编辑/删除子目录
- if item.ParentId == 0 && len(req.MenuList) > 0 {
- nowTime := time.Now().Local()
- insertMenus := make([]*models.ClassifyMenu, 0)
- editMenus := make([]*models.ClassifyMenu, 0)
- deleteMenuIds := make([]int, 0)
- menuIds := make([]int, 0)
- for i := range req.MenuList {
- m := req.MenuList[i]
- v := new(models.ClassifyMenu)
- v.MenuName = req.MenuList[i].MenuName
- v.ClassifyId = classifyId
- v.Sort = i + 1
- v.MenuId = m.MenuId
- v.ModifyTime = nowTime
- if v.MenuId > 0 {
- // 编辑
- editMenus = append(editMenus, v)
- menuIds = append(menuIds, m.MenuId)
- } else {
- // 新增
- v.CreateTime = nowTime
- insertMenus = append(insertMenus, v)
- }
- }
- // 编辑前存在子目录则取"编辑前子目录IDs与编辑时子目录IDs的差集"作为删除IDs
- if len(oriMenuIds) > 0 {
- deleteMenuIds = utils.MinusInt(oriMenuIds, menuIds)
- }
- if e = models.InsertAndUpdateClassifyMenu(insertMenus, editMenus, deleteMenuIds); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "新增/编辑/删除分类子目录失败, Err:" + e.Error()
- return
- }
- }
- // 二级分类-新增子目录关联
- if item.ParentId > 0 {
- if e := models.DeleteAndInsertClassifyMenuRelation(classifyId, req.ClassifyMenuId); e != nil {
- br.Msg = "新增子目录关联失败"
- br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
- return
- }
- }
- // 关联电话会选项被更改时, 同步FICC活动分类
- //if originRelateTel != req.RelateTel {
- // go func() {
- // _ = yb.SyncClassifyAndFiccActivityType()
- // }()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- }
- // @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.ParentClassify()
- 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],
- })
- }
- 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 = "获取成功"
- }
- // @Title 获取分类列表
- // @Description 获取分类列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "检索关键词"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Param HideDayWeek query int false "是否隐藏晨周报"
- // @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()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- companyType := this.GetString("CompanyType")
- hideDayWeek, _ := this.GetInt("HideDayWeek")
- // 商家不隐藏晨周报
- if utils.BusinessCode != utils.BusinessCodeRelease {
- hideDayWeek = 0
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- list, err := models.GetClassifyList(startSize, pageSize, keyWord, companyType, hideDayWeek)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- total, err := models.GetClassifyListCount(keyWord, companyType, hideDayWeek)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- parentIds := make([]int, 0)
- for i := range list {
- parentIds = append(parentIds, list[i].Id)
- }
- parentIdLen := len(parentIds)
- if parentIdLen == 0 {
- resp := &models.ClassifyListResp{
- List: list,
- Paging: paging.GetPaging(currentIndex, pageSize, 0),
- }
- 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, parentIds)
- 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])
- }
- // 获取子分类
- children, e := models.GetClassifyChildByParentIds(parentIds, keyWord)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取子分类失败"
- return
- }
- childrenIds := make([]int, 0)
- for i := range children {
- childrenIds = append(childrenIds, children[i].Id)
- }
- childrenIdsLen := len(childrenIds)
- // 获取二级分类-子目录关联
- relateMap := make(map[int]int, 0)
- if childrenIdsLen > 0 {
- var relateCond string
- var relatePars []interface{}
- relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(childrenIdsLen) + `)`
- relatePars = append(relatePars, childrenIds)
- 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
- }
- }
- // 二级分类
- childrenMap := make(map[int][]*models.ClassifyItem, 0)
- for i := range children {
- if childrenMap[children[i].ParentId] == nil {
- childrenMap[children[i].ParentId] = make([]*models.ClassifyItem, 0)
- }
- childrenMap[children[i].ParentId] = append(childrenMap[children[i].ParentId], &models.ClassifyItem{
- Classify: *children[i],
- ClassifyMenuId: relateMap[children[i].Id],
- })
- }
- // 一级分类
- for i := range list {
- list[i].ClassifyMenuList = menuListMap[list[i].Id]
- list[i].Child = childrenMap[list[i].Id]
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ClassifyListResp)
- resp.List = list
- resp.Paging = page
- 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.GetPermission(classifyInfo.ClassifyName)
- 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)
- if err != nil {
- br.Msg = "修改分类权限失败"
- br.ErrMsg = "修改分类权限失败,Err:" + err.Error()
- return
- }
- // 是关联电话会二级分类修改了权限, 同步关联报告电话会的分类
- //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{}
- if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
- condition += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
- }
- 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 = "获取成功"
- }
|