package data_manage import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/services/data" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "github.com/shopspring/decimal" "os" "strconv" "strings" "time" ) type ManualEdbController struct { controllers.BaseAuthController } // @router /target/edb/detail [get] func (c *ManualEdbController) EdbDetail() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } tradeCode := c.GetString("TradeCode") if tradeCode == `` { br.Msg = "请输入指标编码" br.IsSendEmail = false return } manualEdbInfo, err := models.GetTargetByTradeCode(tradeCode) if err != nil { br.Msg = "获取指标失败" br.ErrMsg = "获取指标失败,err:" + err.Error() return } if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId) if err != nil { br.Msg = "获取分类数据失败" br.ErrMsg = "获取分类数据失败,err:" + err.Error() return } if count <= 0 { br.Msg = "无权访问" br.ErrMsg = "无权访问" br.IsSendEmail = false return } } classifyList := make([]*models.EdbdataClassify, 0) { classify, err := models.GetManualClassifyByClassifyId(manualEdbInfo.ClassifyId) if err != nil { br.Msg = "获取分类信息失败" br.ErrMsg = "获取分类信息失败,err:" + err.Error() return } parentClassify, err := models.GetManualClassifyByClassifyId(classify.ParentId) if err != nil { br.Msg = "获取分类信息失败" br.ErrMsg = "获取父级分类信息失败,err:" + err.Error() return } classifyList = []*models.EdbdataClassify{ parentClassify, classify, } } { dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode) if err != nil { br.Msg = "获取明细数据失败" br.ErrMsg = "获取明细数据失败,err:" + err.Error() return } manualEdbInfo.DataList = dataList } resp := models.TargetDetailResp{ Detail: manualEdbInfo, ClassifyList: classifyList, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /target/classify/edb/list [get] func (c *ManualEdbController) ClassifyEdbList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.Ret = 408 return } resp := new(models.EdbdataClassifyResp) classifyId, _ := c.GetInt("ClassifyId") //分类 if classifyId <= 0 { br.Msg = "请传入分类" br.ErrMsg = "请传入分类" br.IsSendEmail = false } frequency := c.GetString("Frequency") var condition string var pars []interface{} if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { count, err := models.GetCountManualUserClassify(sysUser.AdminId, classifyId) if err != nil { br.Msg = "获取分类数据失败" br.ErrMsg = "获取分类数据失败,err:" + err.Error() return } if count <= 0 { br.Msg = "无权访问" br.ErrMsg = "无权访问" br.IsSendEmail = false return } } list := make([]*models.EdbdataClassifyList, 0) condition += ` AND a.classify_id = ? ` pars = append(pars, classifyId) if frequency != "" { condition += ` AND a.frequency = ?` pars = append(pars, frequency) } tmpList, err := models.GetEdbInfoList(condition, pars, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } for _, v := range tmpList { list = append(list, &models.EdbdataClassifyList{ ClassifyId: 0, ClassifyName: v.SecName, ParentId: v.ClassifyId, Child: nil, TradeCode: v.TradeCode, UniqueCode: utils.MD5(v.TradeCode), }) } resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /target/edb/search [get] func (c *ManualEdbController) EdbSearch() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) keyword := c.GetString("Keyword") var condition string var pars []interface{} if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } if keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } total, err := models.GetCountEdbInfoList(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } for _, v := range list { v.UniqueCode = utils.MD5(v.TradeCode) } resp := models.EdbListResp{ List: list, Paging: paging.GetPaging(currentIndex, pageSize, total), } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /target/edb/list [get] func (c *ManualEdbController) EdbList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) frequency := c.GetString("Frequency") keyword := c.GetString("Keyword") classifyId, _ := c.GetInt("ClassifyId", 0) userId, _ := c.GetInt("UserId", 0) var condition string var pars []interface{} permissionUserId := sysUser.AdminId if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } else { permissionUserId = 0 } if keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } if frequency != "" { condition += ` AND a.frequency = ?` pars = append(pars, frequency) } if classifyId > 0 { classifyList, err := models.GetEdbdataClassify(int64(permissionUserId)) if err != nil { return } var isParent bool classifyIdList := make([]int, 0) for _, v := range classifyList { if v.ClassifyId == classifyId { isParent = true classifyIdList = append(classifyIdList, v.ClassifyId) if v.Child != nil && len(v.Child) > 0 { for _, vv := range v.Child { classifyIdList = append(classifyIdList, vv.ClassifyId) } } break } } num := len(classifyIdList) if num > 0 && isParent { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } else { condition += ` AND a.classify_id = ? ` pars = append(pars, classifyId) } } if userId > 0 { condition += ` AND a.user_id = ? ` pars = append(pars, userId) } total, err := models.GetCountEdbInfoList(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } resp := models.EdbListResp{ List: list, Paging: paging.GetPaging(currentIndex, pageSize, total), } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /target/edb/excel_style/edit [post] func (c *ManualEdbController) EditExcelData() { br := new(models.BaseResponse).Init() var err error errs := make([]string, 0) defer func() { if len(errs) > 0 { utils.FileLog.Info("编辑EXCEL数据 新增或修改数据失败,Err:" + strings.Join(errs, "\n")) } c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } var req data_manage.ManualEdbExcelStyleEditReq err = json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.TradeCode == `` { br.Msg = "指标编码异常!" br.ErrMsg = "指标编码异常!" return } if req.Unit == `` { br.Msg = "单位填写异常!" br.ErrMsg = "单位填写异常!" return } if req.Frequency == `` { br.Msg = "频度填写异常!" br.ErrMsg = "频度填写异常!" return } if req.ClassifyId <= 0 { br.Msg = "品种填写异常!" br.ErrMsg = "品种填写异常!" return } manualEdbInfo, err := models.GetEdbinfoByTradeCode(req.TradeCode) if err != nil { br.Msg = `找不到该指标` br.Msg = `找不到该指标,ERR:` + err.Error() return } if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId) if err != nil { br.Msg = "获取分类数据失败" br.ErrMsg = "获取分类数据失败,err:" + err.Error() return } if count <= 0 { br.Msg = "无权访问" br.ErrMsg = "无权访问" br.IsSendEmail = false return } } dateValueMap := make(map[string]string) for _, dateValue := range req.Data { dateValueMap[dateValue.Date] = strconv.FormatFloat(dateValue.Value, 'f', -1, 64) } { var isUpdateEdb, isUpdateData bool secName := strings.TrimSpace(req.EdbName) frequency := strings.TrimSpace(req.Frequency) unit := strings.TrimSpace(req.Unit) { updateCols := make([]string, 0) if manualEdbInfo.SecName != secName { var condition string var pars []interface{} condition += " AND SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' AND TRADE_CODE != ? " pars = append(pars, secName, req.TradeCode) count, err := models.GetManualEdbCountByCondition(condition, pars) if err != nil { br.Msg = `指标保存失败` br.ErrMsg = `获取同名指标信息异常,ERR:` + err.Error() return } if count > 0 { br.Msg = `已存在同名指标` br.ErrMsg = `已存在同名指标` br.IsSendEmail = false return } updateCols = append(updateCols, "SecName") manualEdbInfo.SecName = secName } if manualEdbInfo.ClassifyId != req.ClassifyId { updateCols = append(updateCols, "ClassifyId") manualEdbInfo.ClassifyId = req.ClassifyId } if manualEdbInfo.Frequency != frequency { updateCols = append(updateCols, "Frequency") manualEdbInfo.Frequency = frequency } if manualEdbInfo.Unit != unit { updateCols = append(updateCols, "Unit") manualEdbInfo.Unit = unit } if len(updateCols) > 0 { isUpdateEdb = true manualEdbInfo.ModifyTime = time.Now().Format(utils.FormatDateTime) updateCols = append(updateCols, "ModifyTime") err = manualEdbInfo.Update(updateCols) if err != nil { br.Msg = `指标保存失败` br.ErrMsg = `指标保存失败,ERR:` + err.Error() return } } } targetDataList, tmpErr := models.GetTargetsDataList(manualEdbInfo.TradeCode) if tmpErr != nil { err = tmpErr } existDataMap := make(map[string]string) deleteDataMap := make(map[string]string) for _, tmpData := range targetDataList { existDataMap[tmpData.Dt] = tmpData.Close deleteDataMap[tmpData.Dt] = tmpData.Dt } addDataList := make([]*models.Edbdata, 0) for createDate, closeVal := range dateValueMap { if createDate == "" || closeVal == "" { continue } tmpVal, ok3 := existDataMap[createDate] if !ok3 { addDataList = append(addDataList, &models.Edbdata{ TradeCode: manualEdbInfo.TradeCode, Dt: createDate, Close: closeVal, ModifyTime: time.Now(), }) continue } delete(deleteDataMap, createDate) tmpValDecimal, tmpErr := decimal.NewFromString(tmpVal) if tmpErr != nil { fmt.Println("tmpVal Parse err:", tmpErr.Error()) err = tmpErr continue } closeValDecimal, tmpErr := decimal.NewFromString(closeVal) if tmpErr != nil { fmt.Println("closeVal Parse err:", tmpErr.Error()) err = tmpErr continue } if !tmpValDecimal.Equal(closeValDecimal) { isUpdateData = true fmt.Println("更新数值") err = models.ModifyTargetsDataByImport(manualEdbInfo.TradeCode, createDate, closeVal) if err != nil { fmt.Println("ModifyTargetsDataByImport err:", err.Error()) errs = append(errs, err.Error()) } } } if len(addDataList) > 0 { isUpdateData = true err = models.OnlyMultiAddEdbdata(addDataList) if err != nil { fmt.Println("MultiAddEdbdata err:", err.Error()) errs = append(errs, err.Error()) } } num := len(deleteDataMap) if num > 0 { isUpdateData = true deleteDateList := make([]string, 0) for date := range deleteDataMap { deleteDateList = append(deleteDateList, date) } err = models.DelEdbdataByCodeAndDateList(manualEdbInfo.TradeCode, deleteDateList) if err != nil { fmt.Println("DelEdbdataByCodeAndDateList err:", err.Error()) errs = append(errs, err.Error()) } } if isUpdateEdb { record := &models.EdbinfoOpRecord{ TradeCode: manualEdbInfo.TradeCode, Remark: "编辑指标", UserId: sysUser.AdminId, UserName: sysUser.RealName, CreateTime: time.Now(), } go func() { _ = record.Create() }() } if isUpdateData { record := &models.EdbinfoOpRecord{ TradeCode: manualEdbInfo.TradeCode, Remark: "更新数据", UserId: sysUser.AdminId, UserName: sysUser.RealName, CreateTime: time.Now(), } go func() { data.ModifyManualEdbMaxMinDate(manualEdbInfo.TradeCode) _ = record.Create() }() } if utils.Re == nil { err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, manualEdbInfo.TradeCode) if err != nil { fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error()) } } } br.Ret = 200 br.Success = true br.Msg = "保存成功" } // @router /target/edb/batch/list [post] func (c *ManualEdbController) BatchEdbList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } var req models.BatchManualEdbReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) pageSize := req.PageSize currentIndex := req.CurrentIndex var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) req.Keyword = strings.TrimSpace(req.Keyword) var condition string var pars []interface{} condition += ` AND a.is_join_edb = ? ` pars = append(pars, 0) if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } if req.Keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2) } lenFrequency := len(req.FrequencyList) if lenFrequency > 0 { condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) ` pars = append(pars, req.FrequencyList) } lenClassify := len(req.ClassifyIdList) if lenClassify > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) ` pars = append(pars, req.ClassifyIdList) } lenUser := len(req.UserIdList) if lenUser > 0 { condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) ` pars = append(pars, req.UserIdList) } total, err := models.GetCountEdbInfoList(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } resp := models.EdbListResp{ List: list, Paging: paging.GetPaging(currentIndex, pageSize, total), } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp br.IsAddLog = false } // @router /target/edb/batch/add/check [post] func (c *ManualEdbController) BatchAddEdbCheck() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } codeMax := 30 var req models.BatchManualEdbReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) req.Keyword = strings.TrimSpace(req.Keyword) var condition string var pars []interface{} condition += ` AND a.is_join_edb = 0 ` if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } if req.ListAll { if req.Keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2) } lenFrequency := len(req.FrequencyList) if lenFrequency > 0 { condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) ` pars = append(pars, req.FrequencyList) } lenClassify := len(req.ClassifyIdList) if lenClassify > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) ` pars = append(pars, req.ClassifyIdList) } lenUser := len(req.UserIdList) if lenUser > 0 { condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) ` pars = append(pars, req.UserIdList) } lenTradeList := len(req.TradeCodeList) if lenTradeList > 0 { condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } else { lenTradeList := len(req.TradeCodeList) if lenTradeList <= 0 { br.Msg = "请选择指标" br.ErrMsg = "请选择指标" return } if lenTradeList > 0 { condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } list, err := models.GetEdbInfoList(condition, pars, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if len(list) > codeMax { br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax) return } br.Data = list br.Msg = "校验成功" br.Ret = 200 br.Success = true } // @router /target/edb/batch/add/name_check [post] func (c *ManualEdbController) NameCheck() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } 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.AddEdbInfoReq if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + e.Error() return } if len(req) == 0 { br.Msg = "请选择指标" return } type NameCheckResult struct { EdbCode string EdbName string Exist bool } indexNames := make([]string, 0) resp := make([]*NameCheckResult, 0) for _, v := range req { v.EdbCode = strings.TrimSpace(v.EdbCode) if v.EdbCode == "" { br.Msg = "指标ID不可为空" return } v.EdbName = strings.TrimSpace(v.EdbName) if v.EdbName == "" { br.Msg = "请输入指标名称" return } indexNames = append(indexNames, v.EdbName) resp = append(resp, &NameCheckResult{ EdbCode: v.EdbCode, EdbName: v.EdbName, }) } edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE) if e != nil { br.Msg = "操作失败" br.ErrMsg = "获取重名指标失败, Err: " + e.Error() return } nameExists := make(map[string]bool) for _, v := range edbList { nameExists[v.EdbName] = true } if len(nameExists) > 0 { for _, v := range resp { v.Exist = nameExists[v.EdbName] } } br.Data = resp br.Msg = "操作成功" br.Ret = 200 br.Success = true } // @router /target/edb/batch/add [post] func (c *ManualEdbController) BatchAdd2Edb() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } codeMax := 30 deleteCache := true cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId) defer func() { if deleteCache { _ = utils.Rc.Delete(cacheKey) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false br.Msg = "系统处理中,请稍后重试!" br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody) return } var req []*data_manage.AddEdbInfoReq if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + e.Error() return } if len(req) == 0 { br.Msg = "请选择指标" return } if len(req) > codeMax { br.Msg = "批量添加指标数量不得超过30个" return } indexNames := make([]string, 0) for _, v := range req { v.EdbCode = strings.TrimSpace(v.EdbCode) if v.EdbCode == "" { br.Msg = "指标ID不可为空" return } v.EdbName = strings.TrimSpace(v.EdbName) if v.EdbName == "" { br.Msg = "请输入指标名称" return } indexNames = append(indexNames, v.EdbName) v.Frequency = strings.TrimSpace(v.Frequency) if v.Frequency == "" { br.Msg = "请选择频度" return } v.Unit = strings.TrimSpace(v.Unit) if v.Unit == "" { br.Msg = "请输入单位" return } if v.ClassifyId <= 0 { br.Msg = "请选择分类" return } } for _, v := range req { var r data.ManualIndexSource2EdbReq r.EdbCode = v.EdbCode r.EdbName = v.EdbName r.Frequency = v.Frequency r.Unit = v.Unit r.ClassifyId = v.ClassifyId r.AdminId = sysUser.AdminId r.AdminRealName = sysUser.RealName edbInfo, e, errMsg, skip := data.ManualIndexSource2Edb(r, c.Lang) if e != nil { br.Msg = "操作失败" if errMsg != "" { br.Msg = errMsg } br.ErrMsg = e.Error() return } if skip { continue } { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(c.Ctx.Input.RequestBody) edbLog.Status = "新增指标" edbLog.Method = c.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } } br.Msg = "操作成功" br.Ret = 200 br.Success = true br.IsAddLog = true } // @router /target/edb/batch/del/check [post] func (c *ManualEdbController) BatchDelEdbCheck() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } 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 models.BatchManualEdbReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) req.Keyword = strings.TrimSpace(req.Keyword) var condition string var pars []interface{} condition += ` AND a.is_join_edb = ? ` pars = append(pars, 1) if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } if req.ListAll { if req.Keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2) } lenFrequency := len(req.FrequencyList) if lenFrequency > 0 { condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) ` pars = append(pars, req.FrequencyList) } lenClassify := len(req.ClassifyIdList) if lenClassify > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) ` pars = append(pars, req.ClassifyIdList) } lenUser := len(req.UserIdList) if lenUser > 0 { condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) ` pars = append(pars, req.UserIdList) } lenTradeList := len(req.TradeCodeList) if lenTradeList > 0 { condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } else { lenTradeList := len(req.TradeCodeList) if lenTradeList <= 0 { br.Msg = "请选择指标" br.ErrMsg = "请选择指标" return } if lenTradeList > 0 { condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } list, err := models.GetEdbInfoList(condition, pars, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } br.Data = list br.Msg = "校验成功" br.Ret = 200 br.Success = true } // @router /target/edb/batch/del [post] func (c *ManualEdbController) BatchDel() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } deleteCache := true cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId) defer func() { if deleteCache { _ = utils.Rc.Delete(cacheKey) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false br.Msg = "系统处理中,请稍后重试!" br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody) return } var req models.BatchManualEdbReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) req.Keyword = strings.TrimSpace(req.Keyword) var condition string var pars []interface{} condition += ` AND a.is_join_edb = ? ` pars = append(pars, 0) if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId) if err != nil { br.Msg = "获取分类数据失败" br.Msg = "获取拥有的分类数据失败,Err:" + err.Error() return } num := len(classifyIdList) if num > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) ` pars = append(pars, classifyIdList) } } if req.ListAll { if req.Keyword != "" { condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )` pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2) } lenFrequency := len(req.FrequencyList) if lenFrequency > 0 { condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) ` pars = append(pars, req.FrequencyList) } lenClassify := len(req.ClassifyIdList) if lenClassify > 0 { condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) ` pars = append(pars, req.ClassifyIdList) } lenUser := len(req.UserIdList) if lenUser > 0 { condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) ` pars = append(pars, req.UserIdList) } lenTradeList := len(req.TradeCodeList) if lenTradeList > 0 { condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } else { lenTradeList := len(req.TradeCodeList) if lenTradeList <= 0 { br.Msg = "请选择指标" br.ErrMsg = "请选择指标" return } if lenTradeList > 0 { condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) ` pars = append(pars, req.TradeCodeList) } } list, err := models.GetEdbInfoList(condition, pars, 0, 0) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } { codeList := make([]string, 0) for _, v := range list { codeList = append(codeList, v.TradeCode) } err = models.DelManualIndexByCodeList(codeList) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } } br.Msg = "删除成功" br.Ret = 200 br.Success = true br.IsAddLog = true } // @router /import/data [post] func (c *ManualEdbController) ImportData() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } file, _, err := c.GetFile("EntryFile") if err != nil { br.Msg = "获取文件失败" br.ErrMsg = "获取文件失败,Err:" + err.Error() return } path := "./static/数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx" defer file.Close() err = c.SaveToFile("EntryFile", path) if err != nil { br.Msg = "文件保存失败" br.ErrMsg = "文件保存失败,Err:" + err.Error() return } if utils.RunMode == "debug" { defer os.Remove(path) } successCount, failCount, err, errMsg := data.ImportManualData(path, sysUser) if err != nil { br.Msg = errMsg br.ErrMsg = err.Error() return } resp := models.EdbdataImportResp{ SuccessCount: successCount, FailCount: failCount, } if failCount > 0 { if successCount == 0 { resp.Status = -1 resp.Msg = "导入失败" } else { resp.Status = 1 resp.Msg = "存在部分导入失败" } } else { resp.Status = 0 } br.Msg = "导入成功" br.Ret = 200 br.Success = true br.Data = resp } // @router /target/edb/op/record/list [get] func (c *ManualEdbController) RecordList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请重新登录" return } pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) tradeCode := c.GetString("TradeCode") if tradeCode == `` { br.Msg = `请选择指标` br.ErrMsg = `请选择指标` br.IsSendEmail = false return } total, list, err := models.GetEdbinfoOpRecordPageList(tradeCode, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } resp := models.EdbinfoOpRecordListResp{ List: list, Paging: paging.GetPaging(currentIndex, pageSize, total), } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }