package excel import ( "encoding/json" "errors" "eta/eta_mobile/models" "eta/eta_mobile/models/data_manage" "eta/eta_mobile/models/data_manage/excel" "eta/eta_mobile/models/data_manage/excel/request" "eta/eta_mobile/models/data_manage/excel/response" "eta/eta_mobile/services/data" "eta/eta_mobile/services/data/data_manage_permission" excelService "eta/eta_mobile/services/data/excel" "eta/eta_mobile/utils" "fmt" "time" ) // DeleteBalanceChart // @Title 删除平衡表图表 // @Description 删除平衡表图表 // @Param request body data_manage.DeleteChartClassifyReq true "type json string" // @Success 200 Ret=200 删除成功 // @router /excel_info/balance/chart_del [post] func (c *ExcelInfoController) DeleteBalanceChart() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.DeleteChartClassifyReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ChartInfoId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } //删除图表 if req.ChartInfoId > 0 { chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId) if err != nil { if err.Error() == utils.ErrNoRow() { br.Msg = "图表已删除,请刷新页面" br.ErrMsg = "指标不存在,Err:" + err.Error() return } else { br.Msg = "删除失败" br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error() return } } if chartInfo == nil { br.Msg = "图表已删除,请刷新页面" return } // 操作权限校验, 增加协作人判断 { // 获取表格信息 excelInfo, e := excel.GetExcelInfoByChartInfoId(req.ChartInfoId) if e != nil { br.Msg = "获取ETA表格失败" return } checkExcelInfo := excelInfo if excelInfo.Source == utils.BALANCE_TABLE { checkExcelInfoId := excelInfo.ExcelInfoId if excelInfo.BalanceType == 1 { checkExcelInfoId = excelInfo.RelExcelInfoId } else { if excelInfo.ParentId > 0 { checkExcelInfoId = excelInfo.ParentId } } if checkExcelInfoId != excelInfo.ExcelInfoId { checkExcelInfo, e = excel.GetExcelInfoById(checkExcelInfoId) if e != nil { br.Msg = "获取平衡表格信息失败" br.ErrMsg = "获取平衡表格信息失败,Err:" + e.Error() return } } } // 数据权限 haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId) if e != nil { br.Msg = "获取ETA表格权限失败" br.ErrMsg = "获取表格权限信息失败,Err" + e.Error() return } button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId) if !button.OpButton { br.Msg = "无操作权限" br.IsSendEmail = false return } } // 获取引用该图表的MyCharts, 用于ES删除 var myCond string var myPars []interface{} myCond += ` AND a.chart_info_id = ? ` myPars = append(myPars, req.ChartInfoId) myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars) if e != nil { br.Msg = "删除失败" br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error() return } myIds := make([]int, 0) for _, m := range myCharts { myIds = append(myIds, m.MyChartId) } //删除图表及关联指标 e = excel.DeleteBalanceExcelChartInfoAndData(req.ChartInfoId) if e != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + e.Error() return } //删除ES { go data.EsDeleteChartInfo(req.ChartInfoId) // 删除MY ETA 图表 es数据 //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId) go data.EsDeleteMyChartInfoByMyChartIds(myIds) } //新增操作日志 { chartLog := new(data_manage.ChartInfoLog) chartLog.ChartName = chartInfo.ChartName chartLog.ChartInfoId = req.ChartInfoId chartLog.ChartClassifyId = chartInfo.ChartClassifyId chartLog.SysUserId = sysUser.AdminId chartLog.SysUserRealName = sysUser.RealName chartLog.UniqueCode = chartInfo.UniqueCode chartLog.CreateTime = time.Now() chartLog.Content = string(c.Ctx.Input.RequestBody) chartLog.Status = "删除图表" chartLog.Method = c.Ctx.Input.URI() go data_manage.AddChartInfoLog(chartLog) } } br.Ret = 200 br.Msg = "删除成功" br.Success = true br.IsAddLog = true } func refreshBalanceTable(excelDetail response.ExcelInfoDetail, lang string) (err error) { edbInfoIds := make([]int, 0) edbInfoIdExist := make(map[int]bool) if excelDetail.ParentId > 0 { newResult := excelDetail.TableData.(request.MixedTableReq) newData := newResult.Data if len(newData) > 0 { for _, t := range newData { for _, v := range t { if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] { edbInfoIdExist[v.EdbInfoId] = true edbInfoIds = append(edbInfoIds, v.EdbInfoId) } } } } // 清除缓存 key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode if utils.Re == nil { _ = utils.Rc.Delete(key) } } else { //查询父表和子表 cCondition := " AND parent_id = ? AND balance_type=0" var cPars []interface{} cPars = append(cPars, excelDetail.ExcelInfoId) childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars) if e != nil { err = fmt.Errorf("获取子表失败 %s", err.Error()) return } // 遍历 for _, child := range childList { var result request.MixedTableReq err = json.Unmarshal([]byte(child.Content), &result) if err != nil { err = errors.New("表格json转结构体失败,Err:" + err.Error()) return } var newData [][]request.MixedTableCellDataReq newData, err, _ = excelService.GetMixedTableCellData(result, lang) if err != nil { return } if len(newData) > 0 { for _, t := range newData { for _, v := range t { if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] { edbInfoIdExist[v.EdbInfoId] = true edbInfoIds = append(edbInfoIds, v.EdbInfoId) } } } } // 清除缓存 key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + child.UniqueCode if utils.Re == nil { _ = utils.Rc.Delete(key) } } } if len(edbInfoIds) > 0 { err, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false) if err != nil { err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error()) return } } return }