manual_edb.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. etaTrialService "eta/eta_api/services/eta_trial"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "github.com/shopspring/decimal"
  14. "os"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // ManualEdbController 手工指标服务(鉴权)
  20. type ManualEdbController struct {
  21. controllers.BaseAuthController
  22. }
  23. // EdbDetail
  24. // @Title 指标列表
  25. // @Description 指标列表
  26. // @Param TradeCode query string true "指标编码"
  27. // @Success 200 {object} models.TargetDetailResp
  28. // @router /target/edb/detail [get]
  29. func (c *ManualEdbController) EdbDetail() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. c.Data["json"] = br
  33. c.ServeJSON()
  34. }()
  35. sysUser := c.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请重新登录"
  38. return
  39. }
  40. // 指标编码
  41. tradeCode := c.GetString("TradeCode")
  42. if tradeCode == `` {
  43. br.Msg = "请输入指标编码"
  44. br.IsSendEmail = false
  45. return
  46. }
  47. manualEdbInfo, err := models.GetTargetByTradeCode(tradeCode)
  48. if err != nil {
  49. br.Msg = "获取指标失败"
  50. br.ErrMsg = "获取指标失败,err:" + err.Error()
  51. return
  52. }
  53. // 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
  54. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  55. //获取账户所拥有权限的分类id集合
  56. count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
  57. if err != nil {
  58. br.Msg = "获取分类数据失败"
  59. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  60. return
  61. }
  62. if count <= 0 {
  63. br.Msg = "无权访问"
  64. br.ErrMsg = "无权访问"
  65. br.IsSendEmail = false
  66. return
  67. }
  68. }
  69. classifyList := make([]*models.EdbdataClassify, 0)
  70. {
  71. classify, err := models.GetManualClassifyByClassifyId(manualEdbInfo.ClassifyId)
  72. if err != nil {
  73. br.Msg = "获取分类信息失败"
  74. br.ErrMsg = "获取分类信息失败,err:" + err.Error()
  75. return
  76. }
  77. parentClassify, err := models.GetManualClassifyByClassifyId(classify.ParentId)
  78. if err != nil {
  79. br.Msg = "获取分类信息失败"
  80. br.ErrMsg = "获取父级分类信息失败,err:" + err.Error()
  81. return
  82. }
  83. classifyList = []*models.EdbdataClassify{
  84. parentClassify, classify,
  85. }
  86. }
  87. // 明细数据
  88. {
  89. dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode)
  90. if err != nil {
  91. br.Msg = "获取明细数据失败"
  92. br.ErrMsg = "获取明细数据失败,err:" + err.Error()
  93. return
  94. }
  95. manualEdbInfo.DataList = dataList
  96. }
  97. resp := models.TargetDetailResp{
  98. Detail: manualEdbInfo,
  99. ClassifyList: classifyList,
  100. }
  101. br.Ret = 200
  102. br.Success = true
  103. br.Msg = "获取成功"
  104. //br.Data = resp
  105. br.Data = resp
  106. }
  107. // ClassifyEdbList
  108. // @Title 分类指标列表
  109. // @Description 指标列表
  110. // @Param ClassifyId query string true "分类id"
  111. // @Success 200 {object} models.TargetDetailResp
  112. // @router /target/classify/edb/list [get]
  113. func (c *ManualEdbController) ClassifyEdbList() {
  114. br := new(models.BaseResponse).Init()
  115. defer func() {
  116. c.Data["json"] = br
  117. c.ServeJSON()
  118. }()
  119. sysUser := c.SysUser
  120. if sysUser == nil {
  121. br.Msg = "请登录"
  122. br.Ret = 408
  123. return
  124. }
  125. resp := new(models.EdbdataClassifyResp)
  126. classifyId, _ := c.GetInt("ClassifyId") //分类
  127. if classifyId <= 0 {
  128. br.Msg = "请传入分类"
  129. br.ErrMsg = "请传入分类"
  130. br.IsSendEmail = false
  131. }
  132. var condition string
  133. var pars []interface{}
  134. // 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
  135. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  136. //获取账户所拥有权限的分类id集合
  137. count, err := models.GetCountManualUserClassify(sysUser.AdminId, classifyId)
  138. if err != nil {
  139. br.Msg = "获取分类数据失败"
  140. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  141. return
  142. }
  143. if count <= 0 {
  144. br.Msg = "无权访问"
  145. br.ErrMsg = "无权访问"
  146. br.IsSendEmail = false
  147. return
  148. }
  149. }
  150. list := make([]*models.EdbdataClassifyList, 0)
  151. condition += ` AND a.classify_id = ? `
  152. pars = append(pars, classifyId)
  153. tmpList, err := models.GetEdbInfoList(condition, pars, 0, 0)
  154. if err != nil {
  155. br.Msg = "获取失败"
  156. br.ErrMsg = "获取失败,Err:" + err.Error()
  157. return
  158. }
  159. for _, v := range tmpList {
  160. list = append(list, &models.EdbdataClassifyList{
  161. ClassifyId: 0,
  162. ClassifyName: v.SecName,
  163. ParentId: v.ClassifyId,
  164. Child: nil,
  165. TradeCode: v.TradeCode,
  166. UniqueCode: utils.MD5(v.TradeCode),
  167. })
  168. }
  169. resp.List = list
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "获取成功"
  173. br.Data = resp
  174. }
  175. // EdbSearch
  176. // @Title 指标搜索
  177. // @Description 指标搜索
  178. // @Param Keyword query string false "关键字搜索"
  179. // @Success 200 {object} models.TargetItemListResp
  180. // @router /target/edb/search [get]
  181. func (c *ManualEdbController) EdbSearch() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. c.Data["json"] = br
  185. c.ServeJSON()
  186. }()
  187. sysUser := c.SysUser
  188. if sysUser == nil {
  189. br.Msg = "请重新登录"
  190. return
  191. }
  192. pageSize, _ := c.GetInt("PageSize")
  193. currentIndex, _ := c.GetInt("CurrentIndex")
  194. var startSize int
  195. if pageSize <= 0 {
  196. pageSize = utils.PageSize20
  197. }
  198. if currentIndex <= 0 {
  199. currentIndex = 1
  200. }
  201. startSize = utils.StartIndex(currentIndex, pageSize)
  202. //关键字
  203. keyword := c.GetString("Keyword")
  204. var condition string
  205. var pars []interface{}
  206. userId := sysUser.AdminId
  207. //超管账号可以查看分类下的所有频度数据
  208. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  209. classifyList, err := models.GetEdbdataClassify(int64(userId))
  210. if err != nil {
  211. br.Msg = "获取分类数据失败"
  212. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  213. return
  214. }
  215. num := len(classifyList)
  216. if num > 0 {
  217. classifyIdList := make([]int, 0)
  218. for _, v := range classifyList {
  219. classifyIdList = append(classifyIdList, v.ClassifyId)
  220. }
  221. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  222. pars = append(pars, classifyIdList)
  223. }
  224. }
  225. if keyword != "" {
  226. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  227. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  228. }
  229. total, err := models.GetCountEdbInfoList(condition, pars)
  230. if err != nil {
  231. br.Msg = "获取失败"
  232. br.ErrMsg = "获取失败,Err:" + err.Error()
  233. return
  234. }
  235. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  236. if err != nil {
  237. br.Msg = "获取失败"
  238. br.ErrMsg = "获取失败,Err:" + err.Error()
  239. return
  240. }
  241. for _, v := range list {
  242. v.UniqueCode = utils.MD5(v.TradeCode)
  243. }
  244. resp := models.EdbListResp{
  245. List: list,
  246. Paging: paging.GetPaging(currentIndex, pageSize, total),
  247. }
  248. br.Ret = 200
  249. br.Success = true
  250. br.Msg = "获取成功"
  251. br.Data = resp
  252. }
  253. // EdbList
  254. // @Title 获取研究员指标
  255. // @Description 获取研究员指标
  256. // @Param Frequency query string false "频度;枚举值:日度、周度、月度、季度、半年度、年度"
  257. // @Param Keyword query string false "关键字搜索"
  258. // @Param TradeCode query string false "指标唯一编码"
  259. // @Param ClassifyId query int false "分类id"
  260. // @Param UserId query int false "用户id"
  261. // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
  262. // @Success 200 {object} models.TargetItemListResp
  263. // @router /target/edb/list [get]
  264. func (c *ManualEdbController) EdbList() {
  265. br := new(models.BaseResponse).Init()
  266. defer func() {
  267. c.Data["json"] = br
  268. c.ServeJSON()
  269. }()
  270. sysUser := c.SysUser
  271. if sysUser == nil {
  272. br.Msg = "请重新登录"
  273. return
  274. }
  275. pageSize, _ := c.GetInt("PageSize")
  276. currentIndex, _ := c.GetInt("CurrentIndex")
  277. var startSize int
  278. if pageSize <= 0 {
  279. pageSize = utils.PageSize20
  280. }
  281. if currentIndex <= 0 {
  282. currentIndex = 1
  283. }
  284. startSize = utils.StartIndex(currentIndex, pageSize)
  285. // 频度
  286. frequency := c.GetString("Frequency")
  287. //关键字
  288. keyword := c.GetString("Keyword")
  289. //关键字
  290. classifyId, _ := c.GetInt("ClassifyId", 0)
  291. //用户ID
  292. userId, _ := c.GetInt("UserId", 0)
  293. var condition string
  294. var pars []interface{}
  295. //超管账号可以查看分类下的所有频度数据
  296. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  297. classifyList, err := models.GetEdbdataClassify(int64(sysUser.AdminId))
  298. if err != nil {
  299. br.Msg = "获取分类数据失败"
  300. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  301. return
  302. }
  303. num := len(classifyList)
  304. if num > 0 {
  305. classifyIdList := make([]int, 0)
  306. for _, v := range classifyList {
  307. classifyIdList = append(classifyIdList, v.ClassifyId)
  308. }
  309. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  310. pars = append(pars, classifyIdList)
  311. }
  312. }
  313. // 关键词
  314. if keyword != "" {
  315. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  316. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  317. }
  318. if frequency != "" {
  319. condition += ` AND a.frequency = ?`
  320. pars = append(pars, frequency)
  321. }
  322. // 所属分类
  323. if classifyId > 0 {
  324. condition += ` AND a.classify_id = ? `
  325. pars = append(pars, classifyId)
  326. }
  327. // 所属用户
  328. if userId > 0 {
  329. condition += ` AND a.user_id = ? `
  330. pars = append(pars, userId)
  331. }
  332. total, err := models.GetCountEdbInfoList(condition, pars)
  333. if err != nil {
  334. br.Msg = "获取失败"
  335. br.ErrMsg = "获取失败,Err:" + err.Error()
  336. return
  337. }
  338. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  339. if err != nil {
  340. br.Msg = "获取失败"
  341. br.ErrMsg = "获取失败,Err:" + err.Error()
  342. return
  343. }
  344. resp := models.EdbListResp{
  345. List: list,
  346. Paging: paging.GetPaging(currentIndex, pageSize, total),
  347. }
  348. br.Ret = 200
  349. br.Success = true
  350. br.Msg = "获取成功"
  351. br.Data = resp
  352. }
  353. // EditExcelData
  354. // @Title 根据excel的样式去编辑指标
  355. // @Description 根据excel的样式去编辑指标
  356. // @Param request body models.ManualEdbExcelStyleEditReq true "type json string"
  357. // @Success 200
  358. // @router /target/edb/excel_style/edit [post]
  359. func (c *ManualEdbController) EditExcelData() {
  360. br := new(models.BaseResponse).Init()
  361. var err error
  362. errs := make([]string, 0)
  363. defer func() {
  364. if len(errs) > 0 {
  365. utils.FileLog.Info("编辑EXCEL数据 新增或修改数据失败,Err:" + strings.Join(errs, "\n"))
  366. }
  367. c.Data["json"] = br
  368. c.ServeJSON()
  369. }()
  370. sysUser := c.SysUser
  371. if sysUser == nil {
  372. br.Msg = "请重新登录"
  373. return
  374. }
  375. var req data_manage.ManualEdbExcelStyleEditReq
  376. err = json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  377. if err != nil {
  378. br.Msg = "参数解析异常!"
  379. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  380. return
  381. }
  382. if req.TradeCode == `` {
  383. br.Msg = "指标编码异常!"
  384. br.ErrMsg = "指标编码异常!"
  385. return
  386. }
  387. if req.Unit == `` {
  388. br.Msg = "单位填写异常!"
  389. br.ErrMsg = "单位填写异常!"
  390. return
  391. }
  392. if req.Frequency == `` {
  393. br.Msg = "频度填写异常!"
  394. br.ErrMsg = "频度填写异常!"
  395. return
  396. }
  397. if req.ClassifyId <= 0 {
  398. br.Msg = "品种填写异常!"
  399. br.ErrMsg = "品种填写异常!"
  400. return
  401. }
  402. // 获取指标信息
  403. manualEdbInfo, err := models.GetEdbinfoByTradeCode(req.TradeCode)
  404. if err != nil {
  405. br.Msg = `找不到该指标`
  406. br.Msg = `找不到该指标,ERR:` + err.Error()
  407. return
  408. }
  409. // 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
  410. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  411. //获取账户所拥有权限的分类id集合
  412. count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
  413. if err != nil {
  414. br.Msg = "获取分类数据失败"
  415. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  416. return
  417. }
  418. if count <= 0 {
  419. br.Msg = "无权访问"
  420. br.ErrMsg = "无权访问"
  421. br.IsSendEmail = false
  422. return
  423. }
  424. }
  425. dateValueMap := make(map[string]string)
  426. //取到所有数据
  427. for _, dateValue := range req.Data {
  428. dateValueMap[dateValue.Date] = strconv.FormatFloat(dateValue.Value, 'f', -1, 64)
  429. }
  430. //操作指标,新增指标及数据等
  431. {
  432. var isUpdate bool
  433. secName := strings.TrimSpace(req.EdbName)
  434. frequency := strings.TrimSpace(req.Frequency)
  435. unit := strings.TrimSpace(req.Unit)
  436. // 指标基础信息变更
  437. {
  438. updateCols := make([]string, 0)
  439. if manualEdbInfo.SecName != secName {
  440. updateCols = append(updateCols, "SecName")
  441. manualEdbInfo.SecName = secName
  442. }
  443. if manualEdbInfo.ClassifyId != req.ClassifyId {
  444. updateCols = append(updateCols, "ClassifyId")
  445. manualEdbInfo.ClassifyId = req.ClassifyId
  446. }
  447. if manualEdbInfo.Frequency != frequency {
  448. updateCols = append(updateCols, "Frequency")
  449. manualEdbInfo.Frequency = frequency
  450. }
  451. if manualEdbInfo.Unit != unit {
  452. updateCols = append(updateCols, "Unit")
  453. manualEdbInfo.Unit = unit
  454. }
  455. if len(updateCols) > 0 {
  456. isUpdate = true
  457. manualEdbInfo.ModifyTime = time.Now().Format(utils.FormatDateTime)
  458. updateCols = append(updateCols, "ModifyTime")
  459. err = manualEdbInfo.Update(updateCols)
  460. if err != nil {
  461. br.Msg = `指标保存失败`
  462. br.Msg = `指标保存失败,ERR:` + err.Error()
  463. return
  464. }
  465. }
  466. }
  467. // 当前已经存在的指标明细数据
  468. targetDataList, tmpErr := models.GetTargetsDataList(manualEdbInfo.TradeCode)
  469. if tmpErr != nil {
  470. err = tmpErr
  471. }
  472. existDataMap := make(map[string]string)
  473. deleteDataMap := make(map[string]string)
  474. for _, tmpData := range targetDataList {
  475. existDataMap[tmpData.Dt] = tmpData.Close
  476. deleteDataMap[tmpData.Dt] = tmpData.Dt
  477. }
  478. addDataList := make([]*models.Edbdata, 0)
  479. for createDate, closeVal := range dateValueMap {
  480. if createDate == "" || closeVal == "" {
  481. continue
  482. }
  483. //判断数据是否已经存在
  484. tmpVal, ok3 := existDataMap[createDate]
  485. // 不存在,那么后面进行插入
  486. if !ok3 {
  487. addDataList = append(addDataList, &models.Edbdata{
  488. TradeCode: manualEdbInfo.TradeCode,
  489. Dt: createDate,
  490. Close: closeVal,
  491. ModifyTime: time.Now(),
  492. })
  493. continue
  494. }
  495. delete(deleteDataMap, createDate)
  496. // 库里面的数据
  497. tmpValDecimal, tmpErr := decimal.NewFromString(tmpVal)
  498. if tmpErr != nil {
  499. fmt.Println("tmpVal Parse err:", tmpErr.Error())
  500. err = tmpErr
  501. continue
  502. }
  503. // 用户填写的数据
  504. closeValDecimal, tmpErr := decimal.NewFromString(closeVal)
  505. if tmpErr != nil {
  506. fmt.Println("closeVal Parse err:", tmpErr.Error())
  507. err = tmpErr
  508. continue
  509. }
  510. if !tmpValDecimal.Equal(closeValDecimal) {
  511. isUpdate = true
  512. fmt.Println("更新数值")
  513. err = models.ModifyTargetsDataByImport(manualEdbInfo.TradeCode, createDate, closeVal)
  514. if err != nil {
  515. fmt.Println("ModifyTargetsDataByImport err:", err.Error())
  516. errs = append(errs, err.Error())
  517. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  518. }
  519. }
  520. }
  521. // 新增指标
  522. if len(addDataList) > 0 {
  523. isUpdate = true
  524. err = models.OnlyMultiAddEdbdata(addDataList)
  525. if err != nil {
  526. fmt.Println("MultiAddEdbdata err:", err.Error())
  527. errs = append(errs, err.Error())
  528. }
  529. }
  530. // 删除不需要的日期数据
  531. num := len(deleteDataMap)
  532. if num > 0 {
  533. isUpdate = true
  534. deleteDateList := make([]string, 0)
  535. for date := range deleteDataMap {
  536. deleteDateList = append(deleteDateList, date)
  537. }
  538. err = models.DelEdbdataByCodeAndDateList(manualEdbInfo.TradeCode, deleteDateList)
  539. if err != nil {
  540. fmt.Println("DelEdbdataByCodeAndDateList err:", err.Error())
  541. errs = append(errs, err.Error())
  542. }
  543. }
  544. // 添加记录
  545. if isUpdate {
  546. record := &models.EdbinfoOpRecord{
  547. TradeCode: manualEdbInfo.TradeCode,
  548. Remark: "编辑指标",
  549. UserId: sysUser.AdminId,
  550. UserName: sysUser.RealName,
  551. CreateTime: time.Now(),
  552. }
  553. go func() {
  554. data.ModifyManualEdbMaxMinDate(manualEdbInfo.TradeCode)
  555. _ = record.Create()
  556. }()
  557. }
  558. }
  559. br.Ret = 200
  560. br.Success = true
  561. br.Msg = "保存成功"
  562. }
  563. // BatchEdbList
  564. // @Title 获取研究员指标
  565. // @Description 获取研究员指标
  566. // @Param request body models.BatchAddEdbReq true "type json string"
  567. // @Success 200 {object} models.TargetItemListResp
  568. // @router /target/edb/batch/list [post]
  569. func (c *ManualEdbController) BatchEdbList() {
  570. br := new(models.BaseResponse).Init()
  571. defer func() {
  572. c.Data["json"] = br
  573. c.ServeJSON()
  574. }()
  575. sysUser := c.SysUser
  576. if sysUser == nil {
  577. br.Msg = "请重新登录"
  578. return
  579. }
  580. var req models.BatchManualEdbReq
  581. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  582. pageSize := req.PageSize
  583. currentIndex := req.CurrentIndex
  584. var startSize int
  585. if pageSize <= 0 {
  586. pageSize = utils.PageSize20
  587. }
  588. if currentIndex <= 0 {
  589. currentIndex = 1
  590. }
  591. startSize = utils.StartIndex(currentIndex, pageSize)
  592. req.Keyword = strings.TrimSpace(req.Keyword)
  593. var condition string
  594. var pars []interface{}
  595. // 是否加到指标库
  596. condition += ` AND a.is_join_edb = ? `
  597. pars = append(pars, 0)
  598. //超管账号可以查看分类下的所有频度数据
  599. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  600. classifyList, err := models.GetEdbdataClassify(int64(sysUser.AdminId))
  601. if err != nil {
  602. br.Msg = "获取分类数据失败"
  603. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  604. return
  605. }
  606. num := len(classifyList)
  607. if num > 0 {
  608. classifyIdList := make([]int, 0)
  609. for _, v := range classifyList {
  610. classifyIdList = append(classifyIdList, v.ClassifyId)
  611. }
  612. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  613. pars = append(pars, classifyIdList)
  614. }
  615. }
  616. // 关键词
  617. if req.Keyword != "" {
  618. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  619. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  620. }
  621. // 所属分类
  622. lenFrequency := len(req.FrequencyList)
  623. if lenFrequency > 0 {
  624. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  625. pars = append(pars, req.FrequencyList)
  626. }
  627. // 所属分类
  628. lenClassify := len(req.ClassifyIdList)
  629. if lenClassify > 0 {
  630. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  631. pars = append(pars, req.ClassifyIdList)
  632. }
  633. // 所属用户
  634. lenUser := len(req.UserIdList)
  635. if lenUser > 0 {
  636. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  637. pars = append(pars, req.UserIdList)
  638. }
  639. total, err := models.GetCountEdbInfoList(condition, pars)
  640. if err != nil {
  641. br.Msg = "获取失败"
  642. br.ErrMsg = "获取失败,Err:" + err.Error()
  643. return
  644. }
  645. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  646. if err != nil {
  647. br.Msg = "获取失败"
  648. br.ErrMsg = "获取失败,Err:" + err.Error()
  649. return
  650. }
  651. resp := models.EdbListResp{
  652. List: list,
  653. Paging: paging.GetPaging(currentIndex, pageSize, total),
  654. }
  655. br.Ret = 200
  656. br.Success = true
  657. br.Msg = "获取成功"
  658. br.Data = resp
  659. br.IsAddLog = false
  660. }
  661. // BatchAddEdbCheck
  662. // @Title 新增校验
  663. // @Description 新增校验
  664. // @Param request body data_manage.BatchManualEdbReq true "type json string"
  665. // @Success 200 string "操作成功"
  666. // @router /target/edb/batch/add/check [post]
  667. func (c *ManualEdbController) BatchAddEdbCheck() {
  668. br := new(models.BaseResponse).Init()
  669. defer func() {
  670. if br.ErrMsg == "" {
  671. br.IsSendEmail = false
  672. }
  673. c.Data["json"] = br
  674. c.ServeJSON()
  675. }()
  676. sysUser := c.SysUser
  677. if sysUser == nil {
  678. br.Msg = "请登录"
  679. br.ErrMsg = "请登录,SysUser Is Empty"
  680. br.Ret = 408
  681. return
  682. }
  683. // 最大批量添加的数量
  684. codeMax := 30
  685. var req models.BatchManualEdbReq
  686. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  687. req.Keyword = strings.TrimSpace(req.Keyword)
  688. var condition string
  689. var pars []interface{}
  690. //
  691. condition += ` AND a.is_join_edb = 0 `
  692. //超管账号可以查看分类下的所有频度数据
  693. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  694. classifyList, err := models.GetEdbdataClassify(int64(sysUser.AdminId))
  695. if err != nil {
  696. br.Msg = "获取分类数据失败"
  697. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  698. return
  699. }
  700. num := len(classifyList)
  701. if num > 0 {
  702. classifyIdList := make([]int, 0)
  703. for _, v := range classifyList {
  704. classifyIdList = append(classifyIdList, v.ClassifyId)
  705. }
  706. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  707. pars = append(pars, classifyIdList)
  708. }
  709. }
  710. if req.ListAll {
  711. // 关键词
  712. if req.Keyword != "" {
  713. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  714. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  715. }
  716. // 所属分类
  717. lenFrequency := len(req.FrequencyList)
  718. if lenFrequency > 0 {
  719. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  720. pars = append(pars, req.FrequencyList)
  721. }
  722. // 所属分类
  723. lenClassify := len(req.ClassifyIdList)
  724. if lenClassify > 0 {
  725. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  726. pars = append(pars, req.ClassifyIdList)
  727. }
  728. // 所属用户
  729. lenUser := len(req.UserIdList)
  730. if lenUser > 0 {
  731. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  732. pars = append(pars, req.UserIdList)
  733. }
  734. lenTradeList := len(req.TradeCodeList)
  735. // 指标
  736. if lenTradeList > 0 {
  737. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  738. pars = append(pars, req.TradeCodeList)
  739. }
  740. } else {
  741. lenTradeList := len(req.TradeCodeList)
  742. if lenTradeList <= 0 {
  743. br.Msg = "请选择指标"
  744. br.ErrMsg = "请选择指标"
  745. return
  746. }
  747. // 指标
  748. if lenTradeList > 0 {
  749. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  750. pars = append(pars, req.TradeCodeList)
  751. }
  752. }
  753. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  754. if err != nil {
  755. br.Msg = "获取失败"
  756. br.ErrMsg = "获取失败,Err:" + err.Error()
  757. return
  758. }
  759. if len(list) > codeMax {
  760. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  761. return
  762. }
  763. br.Data = list
  764. br.Msg = "校验成功"
  765. br.Ret = 200
  766. br.Success = true
  767. }
  768. // NameCheck
  769. // @Title 重名校验
  770. // @Description 批量新增
  771. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  772. // @Success 200 string "操作成功"
  773. // @router /target/edb/batch/add/name_check [post]
  774. func (c *ManualEdbController) NameCheck() {
  775. br := new(models.BaseResponse).Init()
  776. defer func() {
  777. if br.ErrMsg == "" {
  778. br.IsSendEmail = false
  779. }
  780. c.Data["json"] = br
  781. c.ServeJSON()
  782. }()
  783. sysUser := c.SysUser
  784. if sysUser == nil {
  785. br.Msg = "请登录"
  786. br.ErrMsg = "请登录,SysUser Is Empty"
  787. br.Ret = 408
  788. return
  789. }
  790. var req []*data_manage.AddEdbInfoReq
  791. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  792. br.Msg = "参数解析异常!"
  793. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  794. return
  795. }
  796. if len(req) == 0 {
  797. br.Msg = "请选择指标"
  798. return
  799. }
  800. type NameCheckResult struct {
  801. EdbCode string
  802. EdbName string
  803. Exist bool
  804. }
  805. indexNames := make([]string, 0)
  806. resp := make([]*NameCheckResult, 0)
  807. for _, v := range req {
  808. v.EdbCode = strings.TrimSpace(v.EdbCode)
  809. if v.EdbCode == "" {
  810. br.Msg = "指标ID不可为空"
  811. return
  812. }
  813. v.EdbName = strings.TrimSpace(v.EdbName)
  814. if v.EdbName == "" {
  815. br.Msg = "请输入指标名称"
  816. return
  817. }
  818. indexNames = append(indexNames, v.EdbName)
  819. resp = append(resp, &NameCheckResult{
  820. EdbCode: v.EdbCode,
  821. EdbName: v.EdbName,
  822. })
  823. }
  824. // 重名校验
  825. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  826. if e != nil {
  827. br.Msg = "操作失败"
  828. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  829. return
  830. }
  831. nameExists := make(map[string]bool)
  832. for _, v := range edbList {
  833. nameExists[v.EdbName] = true
  834. }
  835. if len(nameExists) > 0 {
  836. for _, v := range resp {
  837. v.Exist = nameExists[v.EdbName]
  838. }
  839. }
  840. br.Data = resp
  841. br.Msg = "操作成功"
  842. br.Ret = 200
  843. br.Success = true
  844. }
  845. // BatchAdd2Edb
  846. // @Title 批量新增到指标库
  847. // @Description 批量新增到指标库
  848. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  849. // @Success 200 string "操作成功"
  850. // @router /target/edb/batch/add [post]
  851. func (c *ManualEdbController) BatchAdd2Edb() {
  852. br := new(models.BaseResponse).Init()
  853. defer func() {
  854. if br.ErrMsg == "" {
  855. br.IsSendEmail = false
  856. }
  857. c.Data["json"] = br
  858. c.ServeJSON()
  859. }()
  860. sysUser := c.SysUser
  861. if sysUser == nil {
  862. br.Msg = "请登录"
  863. br.ErrMsg = "请登录,SysUser Is Empty"
  864. br.Ret = 408
  865. return
  866. }
  867. // 最大批量添加的数量
  868. codeMax := 30
  869. deleteCache := true
  870. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId)
  871. defer func() {
  872. if deleteCache {
  873. _ = utils.Rc.Delete(cacheKey)
  874. }
  875. }()
  876. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  877. deleteCache = false
  878. br.Msg = "系统处理中,请稍后重试!"
  879. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  880. return
  881. }
  882. var req []*data_manage.AddEdbInfoReq
  883. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  884. br.Msg = "参数解析异常!"
  885. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  886. return
  887. }
  888. if len(req) == 0 {
  889. br.Msg = "请选择指标"
  890. return
  891. }
  892. if len(req) > codeMax {
  893. br.Msg = "批量添加指标数量不得超过30个"
  894. return
  895. }
  896. indexNames := make([]string, 0)
  897. for _, v := range req {
  898. v.EdbCode = strings.TrimSpace(v.EdbCode)
  899. if v.EdbCode == "" {
  900. br.Msg = "指标ID不可为空"
  901. return
  902. }
  903. v.EdbName = strings.TrimSpace(v.EdbName)
  904. if v.EdbName == "" {
  905. br.Msg = "请输入指标名称"
  906. return
  907. }
  908. indexNames = append(indexNames, v.EdbName)
  909. v.Frequency = strings.TrimSpace(v.Frequency)
  910. if v.Frequency == "" {
  911. br.Msg = "请选择频度"
  912. return
  913. }
  914. v.Unit = strings.TrimSpace(v.Unit)
  915. if v.Unit == "" {
  916. br.Msg = "请输入单位"
  917. return
  918. }
  919. if v.ClassifyId <= 0 {
  920. br.Msg = "请选择分类"
  921. return
  922. }
  923. }
  924. // 限定同一时间最多批量新增30个指标
  925. for _, v := range req {
  926. var r data.ManualIndexSource2EdbReq
  927. r.EdbCode = v.EdbCode
  928. r.EdbName = v.EdbName
  929. r.Frequency = v.Frequency
  930. r.Unit = v.Unit
  931. r.ClassifyId = v.ClassifyId
  932. r.AdminId = sysUser.AdminId
  933. r.AdminRealName = sysUser.RealName
  934. edbInfo, e, errMsg, skip := data.ManualIndexSource2Edb(r, c.Lang)
  935. if e != nil {
  936. br.Msg = "操作失败"
  937. if errMsg != "" {
  938. br.Msg = errMsg
  939. }
  940. br.ErrMsg = e.Error()
  941. return
  942. }
  943. if skip {
  944. continue
  945. }
  946. // 试用平台更新用户累计新增指标数
  947. if utils.BusinessCode == utils.BusinessCodeSandbox {
  948. go func() {
  949. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  950. if e != nil {
  951. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  952. utils.FileLog.Info(tips)
  953. return
  954. }
  955. if adminItem.DepartmentName != "ETA试用客户" {
  956. return
  957. }
  958. var ur etaTrialService.EtaTrialUserReq
  959. ur.Mobile = adminItem.Mobile
  960. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  961. }()
  962. }
  963. // 新增操作日志
  964. {
  965. edbLog := new(data_manage.EdbInfoLog)
  966. edbLog.EdbInfoId = edbInfo.EdbInfoId
  967. edbLog.SourceName = edbInfo.SourceName
  968. edbLog.Source = edbInfo.Source
  969. edbLog.EdbCode = edbInfo.EdbCode
  970. edbLog.EdbName = edbInfo.EdbName
  971. edbLog.ClassifyId = edbInfo.ClassifyId
  972. edbLog.SysUserId = sysUser.AdminId
  973. edbLog.SysUserRealName = sysUser.RealName
  974. edbLog.CreateTime = time.Now()
  975. edbLog.Content = string(c.Ctx.Input.RequestBody)
  976. edbLog.Status = "新增指标"
  977. edbLog.Method = c.Ctx.Input.URI()
  978. go data_manage.AddEdbInfoLog(edbLog)
  979. }
  980. }
  981. br.Msg = "操作成功"
  982. br.Ret = 200
  983. br.Success = true
  984. br.IsAddLog = true
  985. }
  986. // BatchDelEdbCheck
  987. // @Title 新增校验
  988. // @Description 新增校验
  989. // @Param request body data_manage.BatchManualEdbReq true "type json string"
  990. // @Success 200 string "操作成功"
  991. // @router /target/edb/batch/del/check [post]
  992. func (c *ManualEdbController) BatchDelEdbCheck() {
  993. br := new(models.BaseResponse).Init()
  994. defer func() {
  995. if br.ErrMsg == "" {
  996. br.IsSendEmail = false
  997. }
  998. c.Data["json"] = br
  999. c.ServeJSON()
  1000. }()
  1001. sysUser := c.SysUser
  1002. if sysUser == nil {
  1003. br.Msg = "请登录"
  1004. br.ErrMsg = "请登录,SysUser Is Empty"
  1005. br.Ret = 408
  1006. return
  1007. }
  1008. var req models.BatchManualEdbReq
  1009. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1010. req.Keyword = strings.TrimSpace(req.Keyword)
  1011. var condition string
  1012. var pars []interface{}
  1013. // 就是为了找出已经加入指标库的指标
  1014. condition += ` AND a.is_join_edb = ? `
  1015. pars = append(pars, 1)
  1016. //超管账号可以查看分类下的所有频度数据
  1017. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1018. classifyList, err := models.GetEdbdataClassify(int64(sysUser.AdminId))
  1019. if err != nil {
  1020. br.Msg = "获取分类数据失败"
  1021. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. num := len(classifyList)
  1025. if num > 0 {
  1026. classifyIdList := make([]int, 0)
  1027. for _, v := range classifyList {
  1028. classifyIdList = append(classifyIdList, v.ClassifyId)
  1029. }
  1030. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1031. pars = append(pars, classifyIdList)
  1032. }
  1033. }
  1034. if req.ListAll {
  1035. // 关键词
  1036. if req.Keyword != "" {
  1037. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1038. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  1039. }
  1040. // 所属分类
  1041. lenFrequency := len(req.FrequencyList)
  1042. if lenFrequency > 0 {
  1043. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  1044. pars = append(pars, req.FrequencyList)
  1045. }
  1046. // 所属分类
  1047. lenClassify := len(req.ClassifyIdList)
  1048. if lenClassify > 0 {
  1049. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  1050. pars = append(pars, req.ClassifyIdList)
  1051. }
  1052. // 所属用户
  1053. lenUser := len(req.UserIdList)
  1054. if lenUser > 0 {
  1055. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  1056. pars = append(pars, req.UserIdList)
  1057. }
  1058. lenTradeList := len(req.TradeCodeList)
  1059. // 指标
  1060. if lenTradeList > 0 {
  1061. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1062. pars = append(pars, req.TradeCodeList)
  1063. }
  1064. } else {
  1065. lenTradeList := len(req.TradeCodeList)
  1066. if lenTradeList <= 0 {
  1067. br.Msg = "请选择指标"
  1068. br.ErrMsg = "请选择指标"
  1069. return
  1070. }
  1071. // 指标
  1072. if lenTradeList > 0 {
  1073. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1074. pars = append(pars, req.TradeCodeList)
  1075. }
  1076. }
  1077. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  1078. if err != nil {
  1079. br.Msg = "获取失败"
  1080. br.ErrMsg = "获取失败,Err:" + err.Error()
  1081. return
  1082. }
  1083. br.Data = list
  1084. br.Msg = "校验成功"
  1085. br.Ret = 200
  1086. br.Success = true
  1087. }
  1088. // BatchDel
  1089. // @Title 批量删除
  1090. // @Description 批量新增
  1091. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1092. // @Success 200 string "操作成功"
  1093. // @router /target/edb/batch/del [post]
  1094. func (c *ManualEdbController) BatchDel() {
  1095. br := new(models.BaseResponse).Init()
  1096. defer func() {
  1097. if br.ErrMsg == "" {
  1098. br.IsSendEmail = false
  1099. }
  1100. c.Data["json"] = br
  1101. c.ServeJSON()
  1102. }()
  1103. sysUser := c.SysUser
  1104. if sysUser == nil {
  1105. br.Msg = "请登录"
  1106. br.ErrMsg = "请登录,SysUser Is Empty"
  1107. br.Ret = 408
  1108. return
  1109. }
  1110. deleteCache := true
  1111. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId)
  1112. defer func() {
  1113. if deleteCache {
  1114. _ = utils.Rc.Delete(cacheKey)
  1115. }
  1116. }()
  1117. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1118. deleteCache = false
  1119. br.Msg = "系统处理中,请稍后重试!"
  1120. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  1121. return
  1122. }
  1123. var req models.BatchManualEdbReq
  1124. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1125. req.Keyword = strings.TrimSpace(req.Keyword)
  1126. var condition string
  1127. var pars []interface{}
  1128. // 就是为了找出已经加入指标库的指标
  1129. condition += ` AND a.is_join_edb = ? `
  1130. pars = append(pars, 0)
  1131. //超管账号可以查看分类下的所有频度数据
  1132. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1133. classifyList, err := models.GetEdbdataClassify(int64(sysUser.AdminId))
  1134. if err != nil {
  1135. br.Msg = "获取分类数据失败"
  1136. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  1137. return
  1138. }
  1139. num := len(classifyList)
  1140. if num > 0 {
  1141. classifyIdList := make([]int, 0)
  1142. for _, v := range classifyList {
  1143. classifyIdList = append(classifyIdList, v.ClassifyId)
  1144. }
  1145. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1146. pars = append(pars, classifyIdList)
  1147. }
  1148. }
  1149. if req.ListAll {
  1150. // 关键词
  1151. if req.Keyword != "" {
  1152. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1153. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  1154. }
  1155. // 所属分类
  1156. lenFrequency := len(req.FrequencyList)
  1157. if lenFrequency > 0 {
  1158. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  1159. pars = append(pars, req.FrequencyList)
  1160. }
  1161. // 所属分类
  1162. lenClassify := len(req.ClassifyIdList)
  1163. if lenClassify > 0 {
  1164. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  1165. pars = append(pars, req.ClassifyIdList)
  1166. }
  1167. // 所属用户
  1168. lenUser := len(req.UserIdList)
  1169. if lenUser > 0 {
  1170. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  1171. pars = append(pars, req.UserIdList)
  1172. }
  1173. lenTradeList := len(req.TradeCodeList)
  1174. // 指标
  1175. if lenTradeList > 0 {
  1176. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1177. pars = append(pars, req.TradeCodeList)
  1178. }
  1179. } else {
  1180. lenTradeList := len(req.TradeCodeList)
  1181. if lenTradeList <= 0 {
  1182. br.Msg = "请选择指标"
  1183. br.ErrMsg = "请选择指标"
  1184. return
  1185. }
  1186. // 指标
  1187. if lenTradeList > 0 {
  1188. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1189. pars = append(pars, req.TradeCodeList)
  1190. }
  1191. }
  1192. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  1193. if err != nil {
  1194. br.Msg = "删除失败"
  1195. br.ErrMsg = "删除失败,Err:" + err.Error()
  1196. return
  1197. }
  1198. // TODO 二次校验指标是否已经加到指标库
  1199. {
  1200. codeList := make([]string, 0)
  1201. // 限定同一时间最多批量新增30个指标
  1202. for _, v := range list {
  1203. codeList = append(codeList, v.TradeCode)
  1204. }
  1205. err = models.DelManualIndexByCodeList(codeList)
  1206. if err != nil {
  1207. br.Msg = "删除失败"
  1208. br.ErrMsg = "删除失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. }
  1212. br.Msg = "删除成功"
  1213. br.Ret = 200
  1214. br.Success = true
  1215. br.IsAddLog = true
  1216. }
  1217. // ImportData
  1218. // @Title 导入数据
  1219. // @Description 导入数据
  1220. // @Param EntryFile query file true "文件"
  1221. // @Success 200 Ret=200 录入成功
  1222. // @router /import/data [post]
  1223. func (c *ManualEdbController) ImportData() {
  1224. br := new(models.BaseResponse).Init()
  1225. defer func() {
  1226. c.Data["json"] = br
  1227. c.ServeJSON()
  1228. }()
  1229. sysUser := c.SysUser
  1230. if sysUser == nil {
  1231. br.Msg = "请重新登录"
  1232. return
  1233. }
  1234. file, _, err := c.GetFile("EntryFile")
  1235. if err != nil {
  1236. br.Msg = "获取文件失败"
  1237. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  1238. return
  1239. }
  1240. path := "./static/数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1241. defer file.Close()
  1242. err = c.SaveToFile("EntryFile", path)
  1243. if err != nil {
  1244. br.Msg = "文件保存失败"
  1245. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1246. return
  1247. }
  1248. if utils.RunMode == "debug" {
  1249. defer os.Remove(path)
  1250. }
  1251. successCount, failCount, err, errMsg := data.ImportManualData(path, sysUser)
  1252. if err != nil {
  1253. br.Msg = errMsg
  1254. br.ErrMsg = err.Error()
  1255. return
  1256. }
  1257. resp := models.EdbdataImportResp{
  1258. SuccessCount: successCount,
  1259. FailCount: failCount,
  1260. }
  1261. if failCount > 0 {
  1262. if successCount == 0 {
  1263. resp.Status = -1
  1264. resp.Msg = "导入失败"
  1265. } else {
  1266. resp.Status = 1
  1267. resp.Msg = "存在部分导入失败"
  1268. }
  1269. } else {
  1270. resp.Status = 0
  1271. }
  1272. br.Msg = "导入成功"
  1273. br.Ret = 200
  1274. br.Success = true
  1275. br.Data = resp
  1276. }
  1277. // RecordList
  1278. // @Title 获取指标操作记录列表
  1279. // @Description 获取指标操作记录列表
  1280. // @Param TradeCode query string false "指标编码"
  1281. // @Success 200 {object} models.EdbinfoOpRecordListResp
  1282. // @router /target/edb/op/record/list [get]
  1283. func (c *ManualEdbController) RecordList() {
  1284. br := new(models.BaseResponse).Init()
  1285. defer func() {
  1286. c.Data["json"] = br
  1287. c.ServeJSON()
  1288. }()
  1289. sysUser := c.SysUser
  1290. if sysUser == nil {
  1291. br.Msg = "请重新登录"
  1292. return
  1293. }
  1294. pageSize, _ := c.GetInt("PageSize")
  1295. currentIndex, _ := c.GetInt("CurrentIndex")
  1296. var startSize int
  1297. if pageSize <= 0 {
  1298. pageSize = utils.PageSize20
  1299. }
  1300. if currentIndex <= 0 {
  1301. currentIndex = 1
  1302. }
  1303. startSize = utils.StartIndex(currentIndex, pageSize)
  1304. // 频度
  1305. tradeCode := c.GetString("TradeCode")
  1306. if tradeCode == `` {
  1307. br.Msg = `请选择指标`
  1308. br.ErrMsg = `请选择指标`
  1309. br.IsSendEmail = false
  1310. return
  1311. }
  1312. total, list, err := models.GetEdbinfoOpRecordPageList(tradeCode, startSize, pageSize)
  1313. if err != nil {
  1314. br.Msg = "获取失败"
  1315. br.ErrMsg = "获取失败,Err:" + err.Error()
  1316. return
  1317. }
  1318. resp := models.EdbinfoOpRecordListResp{
  1319. List: list,
  1320. Paging: paging.GetPaging(currentIndex, pageSize, total),
  1321. }
  1322. br.Ret = 200
  1323. br.Success = true
  1324. br.Msg = "获取成功"
  1325. br.Data = resp
  1326. }