123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911 |
- package excel
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/models/data_manage/excel/request"
- response2 "eta/eta_api/models/data_manage/excel/response"
- "eta/eta_api/services/data/data_manage_permission"
- excel2 "eta/eta_api/services/data/excel"
- "eta/eta_api/utils"
- "fmt"
- "sort"
- "strconv"
- "time"
- )
- // ExcelClassifyController ETA表格分类
- type ExcelClassifyController struct {
- controllers.BaseAuthController
- }
- // List
- // @Title excel表格分类列表
- // @Description excel表格分类列表接口
- // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} response.ExcelClassifyListResp
- // @router /excel_classify/list [get]
- func (this *ExcelClassifyController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- if source <= 0 {
- source = utils.EXCEL_DEFAULT
- }
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- // 自定义分析只看自己的
- //if source == utils.CUSTOM_ANALYSIS_TABLE {
- // br = AnalysisClassifyList(this)
- // return
- //}
- showUserId := 0
- if isShowMe {
- showUserId = this.SysUser.AdminId
- }
- classifyList, err := excel.GetExcelClassifyBySource(source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 分类map
- classifyMap := make(map[int]*excel.ExcelClassifyItems)
- for _, v := range classifyList {
- classifyMap[v.ExcelClassifyId] = v
- }
- // 获取二级分类
- // 获取三级分类
- // 根据来源获取所有excel表格(无内容)
- allExcelInfo := make([]*excel.ExcelClassifyItems, 0)
- if source == utils.BALANCE_TABLE {
- //找到当前协作人相关的表格ID
- var excelIds []int
- if isShowMe {
- obj := new(excel.ExcelWorker)
- existList, err := obj.GetBySysUserId(this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取表格协作人失败!"
- br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
- return
- }
- if len(existList) > 0 {
- for _, v := range existList {
- excelIds = append(excelIds, v.ExcelInfoId)
- }
- }
- }
- allExcelInfo, err = excel.GetBalanceNoContentExcelInfoAll(source, excelIds, showUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- } else {
- allExcelInfo, err = excel.GetNoContentExcelInfoAll(source, showUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- ExcelInfoMap := make(map[int][]*excel.ExcelClassifyItems)
- for _, v := range allExcelInfo {
- // 数据权限
- if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- if source == utils.BALANCE_TABLE && isShowMe && !v.HaveOperaAuth { // 过滤我不可编辑的表格
- continue
- }
- ExcelInfoMap[v.ExcelClassifyId] = append(ExcelInfoMap[v.ExcelClassifyId], v)
- }
- classifyListMap := make(map[int][]*excel.ExcelClassifyItems)
- for _, v := range classifyList {
- // 数据权限
- v.HaveOperaAuth = data_manage_permission.CheckExcelClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ExcelClassifyId, permissionClassifyIdList)
- if existItems, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
- v.Children = existItems
- }
- }
- for _, v := range classifyList {
- if v.ParentId > 0 {
- classifyListMap[v.ParentId] = append(classifyListMap[v.ParentId], v)
- }
- }
- //组装三级分类
- for key, classify := range classifyList {
- subList, ok := classifyListMap[classify.ExcelClassifyId]
- if ok {
- classifyList[key].Children = append(classifyList[key].Children, subList...)
- sort.Slice(classifyList[key].Children, func(i, j int) bool {
- return excel.ExcelClassifyItemBySort(classifyList[key].Children[i], classifyList[key].Children[j])
- })
- }
- }
- nodeAll := make([]*excel.ExcelClassifyItems, 0)
- for _, v := range classifyList {
- if v.ParentId == 0 {
- sort.Slice(v.Children, func(i, j int) bool { return excel.ExcelClassifyItemBySort(v.Children[i], v.Children[j]) })
- nodeAll = append(nodeAll, v)
- }
- }
- if isShowMe {
- nodeAll = excel2.GetClassifyListRemoveNoExcel(nodeAll)
- }
- resp := response2.ExcelClassifyListResp{
- AllNodes: nodeAll,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func AnalysisClassifyList(this *ExcelClassifyController) (br *models.BaseResponse) {
- br = new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- if source <= 0 {
- source = utils.EXCEL_DEFAULT
- }
- //只看我的
- showUserId := this.SysUser.AdminId
- classifyList, err := excel.GetExcelClassifyBySource(source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 分类map
- classifyMap := make(map[int]*excel.ExcelClassifyItems)
- for _, v := range classifyList {
- classifyMap[v.ExcelClassifyId] = v
- }
- // 获取二级分类
- // 获取三级分类
- // 根据来源获取所有excel表格(无内容)
- allExcelInfo, err := excel.GetNoContentExcelInfoAll(source, showUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- ExcelInfoMap := make(map[int][]*excel.ExcelClassifyItems)
- for _, v := range allExcelInfo {
- // 数据权限
- if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- ExcelInfoMap[v.ExcelClassifyId] = append(ExcelInfoMap[v.ExcelClassifyId], v)
- }
- classifyListMap := make(map[int][]*excel.ExcelClassifyItems)
- for _, v := range classifyList {
- // 数据权限
- v.HaveOperaAuth = data_manage_permission.CheckExcelClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ExcelClassifyId, permissionClassifyIdList)
- if existItems, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
- v.Children = existItems
- }
- }
- for _, v := range classifyList {
- if v.ParentId > 0 {
- classifyListMap[v.ParentId] = append(classifyListMap[v.ParentId], v)
- }
- }
- //组装三级分类
- for key, classify := range classifyList {
- subList, ok := classifyListMap[classify.ExcelClassifyId]
- if ok {
- classifyList[key].Children = append(classifyList[key].Children, subList...)
- sort.Slice(classifyList[key].Children, func(i, j int) bool {
- return excel.ExcelClassifyItemBySort(classifyList[key].Children[i], classifyList[key].Children[j])
- })
- }
- }
- nodeAll := make([]*excel.ExcelClassifyItems, 0)
- for _, v := range classifyList {
- if v.ParentId == 0 {
- sort.Slice(v.Children, func(i, j int) bool { return excel.ExcelClassifyItemBySort(v.Children[i], v.Children[j]) })
- nodeAll = append(nodeAll, v)
- }
- }
- // 自定义分析只看自己的分类
- nodeAll = removeNodesWithAnalysisClassify(nodeAll, this.SysUser.AdminId)
- resp := response2.ExcelClassifyListResp{
- AllNodes: nodeAll,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // removeNodesWithAnalysisClassify
- // @Description: 自定义分析只看自己的分类,所以需要移除分类
- // @author: Roc
- // @datetime 2024-04-09 13:46:51
- // @param nodes []*excel.ExcelClassifyItems
- // @param adminId int
- // @return []*excel.ExcelClassifyItems
- func removeNodesWithAnalysisClassify(nodes []*excel.ExcelClassifyItems, adminId int) []*excel.ExcelClassifyItems {
- var newListNode []*excel.ExcelClassifyItems
- for _, node := range nodes {
- if node.Children != nil {
- node.Children = removeNodesWithAnalysisClassify(node.Children, adminId)
- }
- // 如果是ETA表格,那么就保留
- if node.ExcelInfoId > 0 {
- newListNode = append(newListNode, node)
- continue
- }
- // 如果是公共分类,且名下的ETA表格不为空,那么就保留
- if node.SysUserId == 0 && node.Children != nil && len(node.Children) > 0 {
- newListNode = append(newListNode, node)
- continue
- }
- // 如果是自己的分类,那么就保留
- if node.SysUserId == adminId {
- newListNode = append(newListNode, node)
- continue
- }
- }
- return newListNode
- }
- // ExcelClassifyItems
- // @Title 获取所有excel表格分类接口-不包含表格
- // @Description 获取所有excel表格分类接口-不包含表格
- // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
- // @Success 200 {object} response.ExcelClassifyListResp
- // @router /excel_classify/items [get]
- func (this *ExcelClassifyController) ExcelClassifyItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- if source <= 0 {
- source = utils.EXCEL_DEFAULT
- }
- classifyList, err := excel.GetExcelClassifyBySource(source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 获取二级分类
- // 获取三级分类
- classifyMap := make(map[int][]*excel.ExcelClassifyItems)
- for _, v := range classifyList {
- if v.ParentId > 0 {
- classifyMap[v.ParentId] = append(classifyMap[v.ParentId], v)
- }
- }
- //组装三级分类
- for key, classify := range classifyList {
- subList, ok := classifyMap[classify.ExcelClassifyId]
- if ok {
- classifyList[key].Children = append(classifyList[key].Children, subList...)
- }
- }
- nodeAll := make([]*excel.ExcelClassifyItems, 0)
- for _, v := range classifyList {
- if v.ParentId == 0 {
- nodeAll = append(nodeAll, v)
- }
- }
- resp := response2.ExcelClassifyListResp{
- AllNodes: nodeAll,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // AddExcelClassify
- // @Title 新增excel表格分类
- // @Description 新增excel表格分类接口
- // @Param request body request.AddExcelClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /excel_classify/add [post]
- func (this *ExcelClassifyController) AddExcelClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddExcelClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ParentId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- source := req.Source
- if source <= 0 {
- source = utils.EXCEL_DEFAULT
- }
- // 获取同级分类下存在同名分类的数量
- var count int
- if source == utils.CUSTOM_ANALYSIS_TABLE {
- // 自定义分析分类私有化了
- ct, e := excel.GetCustomAnalysisExcelClassifyCount(req.ExcelClassifyName, req.ParentId, source, this.SysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("获取自定义分析同级分类下同名分类失败, %v", e)
- return
- }
- count = ct
- } else {
- ct, e := excel.GetExcelClassifyCount(req.ExcelClassifyName, req.ParentId, source)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("获取同级分类下同名分类失败, %v", e)
- return
- }
- count = ct
- }
- if count > 0 {
- br.Msg = "分类名称已存在,请重新输入"
- br.IsSendEmail = false
- return
- }
- //获取该层级下最大的排序数
- maxSort, err := excel2.GetExcelClassifyMaxSort(req.ParentId, req.Source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询排序信息失败,Err:" + err.Error()
- return
- }
- level := 1
- // 查询父级分类是否存在
- if req.ParentId > 0 {
- var parent *excel.ExcelClassify
- parent, err = excel.GetExcelClassifyById(req.ParentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "父级分类不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级分类信息失败,Err:" + err.Error()
- return
- }
- level = parent.Level + 1
- }
- // 入库
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- classify := &excel.ExcelClassify{
- //ExcelClassifyId: 0,
- ExcelClassifyName: req.ExcelClassifyName,
- ParentId: req.ParentId,
- Source: source,
- SysUserId: this.SysUser.AdminId,
- SysUserRealName: this.SysUser.RealName,
- Level: level,
- UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
- Sort: maxSort + 1,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- _, err = excel.AddExcelClassify(classify)
- if err != nil {
- br.Msg = "保存分类失败"
- br.ErrMsg = "保存分类失败,Err:" + err.Error()
- return
- }
- // 继承分类权限
- {
- go data_manage_permission.InheritParentClassify(6, source, classify.ExcelClassifyId, classify.ParentId, classify.ExcelClassifyName)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- }
- // EditExcelClassify
- // @Title 修改excel表格分类
- // @Description 修改excel表格分类
- // @Param request body request.EditExcelClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /excel_classify/edit [post]
- func (this *ExcelClassifyController) EditExcelClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditExcelClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- item, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- br.Msg = "保存失败"
- br.Msg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- // 名字一致的话,直接返回成功
- if item.ExcelClassifyName == req.ExcelClassifyName {
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- return
- }
- // 获取同级分类下存在同名分类的数量
- count, err := excel.GetExcelClassifyCount(req.ExcelClassifyName, item.ParentId, item.Source)
- if err != nil {
- br.Msg = "判断名称是否已存在失败"
- br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类名称已存在,请重新输入"
- br.IsSendEmail = false
- return
- }
- // 修改分类名称
- item.ExcelClassifyName = req.ExcelClassifyName
- err = item.Update([]string{"ExcelClassifyName"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "修改成功"
- br.Success = true
- br.IsAddLog = true
- }
- // DeleteExcelClassifyCheck
- // @Title 删除表格检测接口
- // @Description 删除表格检测接口
- // @Param request body request.ExcelClassifyDeleteCheckReq true "type json string"
- // @Success 200 {object} response.ExcelClassifyDeleteCheckResp
- // @router /excel_classify/delete/check [post]
- func (this *ExcelClassifyController) DeleteExcelClassifyCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.ExcelClassifyDeleteCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- var deleteStatus int
- var tipsMsg string
- // 校验是否存在该分类
- ExcelClassifyInfo, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "该分类不存在"
- br.ErrMsg = "该分类不存在"
- return
- }
- br.Msg = "删除失败"
- br.ErrMsg = "查询该分类失败,Err:" + err.Error()
- return
- }
- if ExcelClassifyInfo == nil {
- br.Msg = "该分类不存在"
- br.ErrMsg = "该分类不存在"
- br.IsSendEmail = false
- return
- }
- //删除分类
- if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
- //判断表格分类下,是否含有表格
- count, err := excel.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- deleteStatus = 1
- tipsMsg = "该分类下关联表格不可删除"
- } else {
- childClassify, e := excel.GetChildClassifyById(req.ExcelClassifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- if len(childClassify) > 0 {
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ExcelClassifyId)
- }
- condition := fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- var pars []interface{}
- pars = append(pars, classifyIds)
- childCount, err := excel.GetExcelInfoCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "查询分类下表格数量失败,Err:" + err.Error()
- return
- }
- if childCount > 0 {
- deleteStatus = 1
- tipsMsg = "该分类下关联表格不可删除"
- }
- }
- }
- }
- //if deleteStatus != 1 && req.ExcelInfoId == 0 {
- // classifyCount, err := data_manage.GetExcelClassifyCountByClassifyId(req.ExcelClassifyId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "分类下是否含有表格失败,Err:" + err.Error()
- // return
- // }
- // if classifyCount > 0 {
- // deleteStatus = 2
- // tipsMsg = "确认删除当前目录及包含的子目录吗?"
- // }
- //}
- if deleteStatus == 0 {
- tipsMsg = "可删除,进行删除操作"
- }
- resp := response2.ExcelClassifyDeleteCheckResp{
- DeleteStatus: deleteStatus,
- TipsMsg: tipsMsg,
- }
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- // DeleteExcelClassify
- // @Title 删除表格分类/表格
- // @Description 删除表格分类/表格接口
- // @Param request body request.DeleteExcelClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /excel_classify/delete [post]
- func (this *ExcelClassifyController) DeleteExcelClassify() {
- 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
- }
- var req request.DeleteExcelClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- //删除分类
- if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
- //判断是否含有指标
- count, err := excel.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该目录下存在关联ETA表格,不可删除"
- br.IsSendEmail = false
- return
- } else {
- childClassify, e := excel.GetChildClassifyById(req.ExcelClassifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- if len(childClassify) > 0 {
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ExcelClassifyId)
- }
- condition := fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- var pars []interface{}
- pars = append(pars, classifyIds)
- childCount, err := excel.GetExcelInfoCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "查询分类下表格数量失败,Err:" + err.Error()
- return
- }
- if childCount > 0 {
- br.Msg = "该目录下存在关联ETA表格,不可删除"
- br.IsSendEmail = false
- return
- }
- }
- }
- classifyItem, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- }
- return
- }
- classifyItem.IsDelete = 1
- err = classifyItem.Update([]string{"IsDelete"})
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- }
- resp := response2.AddExcelInfoResp{}
- //删除表格
- if req.ExcelInfoId > 0 {
- excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "表格已删除,请刷新页面"
- br.ErrMsg = "表格已删除,请刷新页面"
- return
- } else {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
- return
- }
- }
- if excelInfo == nil {
- br.Msg = "表格已删除,请刷新页面"
- br.IsSendEmail = false
- return
- }
- // 删除excel
- err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
- if err != nil {
- br.Msg = "删除失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "删除失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 返回下一个表格的信息
- {
- var nextItem *excel.ExcelInfo
- var condition string
- var pars []interface{}
- condition += " AND excel_classify_id=? "
- pars = append(pars, excelInfo.ExcelClassifyId)
- if excelInfo.Source == utils.BALANCE_TABLE {
- condition += " AND parent_id=0 AND balance_type=0 "
- }
- condition += " AND (sort>? OR (sort=? AND excel_info_id<?) ) "
- pars = append(pars, excelInfo.Sort, excelInfo.Sort, excelInfo.ExcelInfoId)
- nextItem, err = excel.GetNextExcelInfoByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
- return
- }
- // 如果没找到,那么查找下一个分类的第一个表格
- if nextItem == nil {
- currClassifyInfo, err := excel.GetExcelClassifyById(excelInfo.ExcelClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
- return
- }
- nextItem, err = excel.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
- return
- }
- }
- // 如果找到下一个表格了,那么就返回
- if nextItem != nil {
- resp = response2.AddExcelInfoResp{
- ExcelInfoId: nextItem.ExcelInfoId,
- UniqueCode: nextItem.UniqueCode,
- }
- }
- }
- //新增操作日志
- //{
- // ExcelLog := new(data_manage.ExcelInfoLog)
- // ExcelLog.ExcelName = ExcelInfo.ExcelName
- // ExcelLog.ExcelInfoId = req.ExcelInfoId
- // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
- // ExcelLog.SysUserId = sysUser.AdminId
- // ExcelLog.SysUserRealName = sysUser.RealName
- // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
- // ExcelLog.CreateTime = time.Now()
- // ExcelLog.Content = string(this.Ctx.Input.RequestBody)
- // ExcelLog.Status = "删除表格"
- // ExcelLog.Method = this.Ctx.Input.URI()
- // go data_manage.AddExcelInfoLog(ExcelLog)
- //}
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.Data = resp
- br.IsAddLog = true
- }
- // ExcelClassifyMove
- // @Title 表格分类移动接口
- // @Description 表格分类移动接口
- // @Success 200 {object} request.MoveExcelClassifyReq
- // @router /excel_classify/move [post]
- func (this *ExcelClassifyController) ExcelClassifyMove() {
- 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
- }
- var req request.MoveExcelClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 && req.ExcelInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "请选择拖动目标,分类目录或者指标"
- return
- }
- //判断分类是否存在
- err, errMsg := excel2.MoveExcelClassify(req)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "移动成功"
- }
|