edb_classify.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type EdbClassify struct {
  9. ClassifyId int `gorm:"primaryKey" `
  10. ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
  11. ClassifyName string `description:"分类名称"`
  12. ParentId int `description:"父级id"`
  13. RootId int `description:"顶级id"`
  14. HasData int `description:"是否含有指标数据"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. SysUserId int `description:"创建人id"`
  18. SysUserRealName string `description:"创建人姓名"`
  19. Level int `description:"层级"`
  20. UniqueCode string `description:"唯一编码"`
  21. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  22. LastModifyUserId int `description:"最后修改人ID"`
  23. LastModifyUserRealName string `description:"最后修改人姓名"`
  24. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  25. ClassifyNameEn string `description:"英文分类名称"`
  26. }
  27. func AddEdbClassify(item *EdbClassify) (lastId int64, err error) {
  28. err = global.DmSQL["data"].Create(item).Error
  29. if err != nil {
  30. return
  31. }
  32. lastId = int64(item.ClassifyId)
  33. return
  34. }
  35. type AddEdbClassifyReq struct {
  36. ClassifyName string `description:"分类名称"`
  37. ParentId int `description:"父级id,第一级传0"`
  38. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  39. ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
  40. }
  41. // GetEdbClassifyCount
  42. // @Description: 根据父级id获取同级中文名称的数量
  43. // @author: Roc
  44. // @datetime 2024-04-17 14:12:22
  45. // @param classifyName string
  46. // @param parentId int
  47. // @param classifyType uint8
  48. // @return count int
  49. // @return err error
  50. func GetEdbClassifyCount(classifyName string, parentId int, classifyType uint8) (count int, err error) {
  51. sql := `SELECT COUNT(1) AS count FROM edb_classify WHERE parent_id=? AND classify_name=? AND classify_type = ? `
  52. err = global.DmSQL["data"].Raw(sql, parentId, classifyName, classifyType).Scan(&count).Error
  53. return
  54. }
  55. // GetEdbClassifyEnCount
  56. // @Description: 根据父级id获取同级英文名称的数量
  57. // @author: Roc
  58. // @datetime 2024-04-17 14:12:09
  59. // @param classifyNameEn string
  60. // @param parentId int
  61. // @param classifyType uint8
  62. // @return count int
  63. // @return err error
  64. func GetEdbClassifyEnCount(classifyNameEn string, parentId int, classifyType uint8) (count int, err error) {
  65. sql := `SELECT COUNT(1) AS count FROM edb_classify WHERE parent_id=? AND classify_name_en = ? AND classify_type = ? `
  66. err = global.DmSQL["data"].Raw(sql, parentId, classifyNameEn, classifyType).Scan(&count).Error
  67. return
  68. }
  69. type EditEdbClassifyReq struct {
  70. ClassifyName string `description:"分类名称"`
  71. ClassifyId int `description:"分类名称"`
  72. }
  73. func GetEdbClassifyById(classifyId int) (item *EdbClassify, err error) {
  74. sql := `SELECT * FROM edb_classify WHERE classify_id=? `
  75. err = global.DmSQL["data"].Raw(sql, classifyId).First(&item).Error
  76. return
  77. }
  78. func GetEdbClassifyCountById(classifyId int) (count int, err error) {
  79. sql := `SELECT count(1) AS count FROM edb_classify WHERE classify_id=? `
  80. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
  81. return
  82. }
  83. // EditEdbClassify
  84. // @Description: 修改指标分类的中文名称
  85. // @author: Roc
  86. // @datetime 2024-04-17 14:14:48
  87. // @param classifyId int
  88. // @param classifyName string
  89. // @param userId int
  90. // @param userRealName string
  91. // @return err error
  92. func EditEdbClassify(classifyId int, classifyName string, userId int, userRealName string) (err error) {
  93. sql := `UPDATE edb_classify SET classify_name=?,modify_time=NOW(), last_modify_user_id = ?, last_modify_user_real_name = ? WHERE classify_id=? `
  94. err = global.DmSQL["data"].Exec(sql, classifyName, userId, userRealName, classifyId).Error
  95. return
  96. }
  97. type DeleteEdbClassifyReq struct {
  98. ClassifyId int `description:"分类id"`
  99. EdbInfoId int `description:"指标id"`
  100. }
  101. // TODO: sql优化,后续解决
  102. func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
  103. sql := `WITH RECURSIVE classify_cte(classify_id, parent_id) AS (
  104. SELECT classify_id, parent_id
  105. FROM edb_classify
  106. WHERE parent_id = ?
  107. UNION ALL
  108. SELECT e.classify_id, e.parent_id
  109. FROM edb_classify e
  110. INNER JOIN classify_cte c ON e.parent_id = c.classify_id
  111. )
  112. SELECT COUNT(1) AS COUNT
  113. FROM edb_info AS a
  114. WHERE a.classify_id IN (SELECT classify_id FROM classify_cte);`
  115. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
  116. return
  117. }
  118. func DeleteEdbClassify(classifyId int) (err error) {
  119. sql := `WITH RECURSIVE ClassifyHierarchy ( classify_id, parent_id ) AS
  120. (
  121. SELECT classify_id,
  122. parent_id
  123. FROM edb_classify
  124. WHERE parent_id = ? OR classify_id=?
  125. UNION ALL
  126. SELECT e.classify_id,
  127. e.parent_id
  128. FROM edb_classify e
  129. INNER JOIN ClassifyHierarchy ch
  130. ON e.parent_id = ch.classify_id
  131. )
  132. DELETE
  133. FROM edb_classify
  134. WHERE classify_id IN ( SELECT classify_id
  135. FROM ClassifyHierarchy
  136. );`
  137. err = global.DmSQL["data"].Exec(sql, classifyId, classifyId).Error
  138. return
  139. }
  140. func GetEdbClassifyByParentId(parentId int, classifyType int8) (items []*EdbClassifyItems, err error) {
  141. o := global.DmSQL["data"]
  142. sql := ` SELECT * FROM edb_classify WHERE parent_id=? AND classify_type = ? order by sort asc,classify_id asc`
  143. err = o.Raw(sql, parentId, classifyType).Scan(&items).Error
  144. return
  145. }
  146. func GetEdbClassifyByRootIdLevel(rootId int, classifyType uint8, orderStr string) (items []*EdbClassifyItems, err error) {
  147. o := global.DmSQL["data"]
  148. sql := ` SELECT * FROM edb_classify WHERE root_id=? AND classify_type = ? `
  149. if orderStr != "" {
  150. sql += orderStr
  151. } else {
  152. sql += ` order by level desc, sort asc, classify_id asc`
  153. }
  154. err = o.Raw(sql, rootId, classifyType).Scan(&items).Error
  155. return
  156. }
  157. // GetAllEdbClassify 获取所有的普通指标的分类列表(包含第一级)
  158. func GetAllEdbClassify() (items []*EdbClassifyItems, err error) {
  159. o := global.DmSQL["data"]
  160. sql := ` SELECT * FROM edb_classify WHERE classify_type = 0 order by sort asc,classify_id asc`
  161. err = o.Raw(sql).Scan(&items).Error
  162. return
  163. }
  164. // GetPredictEdbClassifyAll 获取预测指标的分类列表
  165. func GetPredictEdbClassifyAll() (items []*EdbClassifyItems, err error) {
  166. o := global.DmSQL["data"]
  167. sql := ` SELECT * FROM edb_classify WHERE classify_type = 1 order by sort asc,classify_id asc`
  168. err = o.Raw(sql).Scan(&items).Error
  169. return
  170. }
  171. // GetAllEdbClassifyByType 根据类型获取分类列表
  172. func GetAllEdbClassifyByType(classifyType int) (items []*EdbClassifyItems, err error) {
  173. o := global.DmSQL["data"]
  174. sql := ` SELECT * FROM edb_classify WHERE classify_type = ? order by sort ASC,classify_id ASC`
  175. err = o.Raw(sql, classifyType).Scan(&items).Error
  176. return
  177. }
  178. type EdbClassifyItems struct {
  179. ClassifyId int `description:"分类id"`
  180. EdbInfoId int `description:"指标id"`
  181. ClassifyName string
  182. ClassifyNameEn string
  183. ParentId int
  184. RootId int `description:"顶级id"`
  185. Level int `description:"层级"`
  186. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  187. UniqueCode string `description:"唯一编码"`
  188. Source int `description:"来源id"`
  189. SourceName string `description:"来源名称"`
  190. SysUserId int `description:"创建人id"`
  191. SysUserRealName string `description:"创建人姓名"`
  192. StartDate string
  193. EdbCode string
  194. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  195. Children []*EdbClassifyItems `gorm:"-"`
  196. Button EdbClassifyItemsButton `gorm:"-" description:"操作权限"`
  197. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  198. HaveOperaAuth bool `description:"是否有数据权限"`
  199. }
  200. type EdbClassifyIdItems struct {
  201. ClassifyId int `description:"分类id"`
  202. ClassifyName string
  203. ClassifyNameEn string
  204. UniqueCode string `description:"唯一编码"`
  205. ParentId int `description:"父级分类id"`
  206. Level int `description:"层级"`
  207. RootId int `description:"顶级分类id"`
  208. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" json:"-"`
  209. HaveOperaAuth bool `description:"是否有该数据权限,默认:false"`
  210. }
  211. type EdbClassifyItemList []*EdbClassifyItems
  212. func (m EdbClassifyItemList) Len() int {
  213. return len(m)
  214. }
  215. func (m EdbClassifyItemList) Less(i, j int) bool {
  216. return m[i].Sort < m[j].Sort
  217. }
  218. func (m EdbClassifyItemList) Swap(i, j int) {
  219. m[i], m[j] = m[j], m[i]
  220. }
  221. // EdbClassifyItemsButton 操作按钮
  222. type EdbClassifyItemsButton struct {
  223. AddButton bool `description:"是否可添加"`
  224. OpButton bool `description:"是否可编辑"`
  225. DeleteButton bool `description:"是否可删除"`
  226. MoveButton bool `description:"是否可移动"`
  227. ShowEdbRelation bool `description:"是否展示关联指标"`
  228. ShowChartRelation bool `description:"是否展示关联图表"`
  229. InsertNewDataButton bool `description:"是否可插入最新值"`
  230. }
  231. type EdbClassifyListResp struct {
  232. AllNodes EdbClassifyItemList
  233. CanOpClassify bool `description:"是否允许操作分类"`
  234. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  235. }
  236. type ClassifyDeleteCheckResp struct {
  237. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
  238. TipsMsg string `description:"提示信息"`
  239. TableList []*ExcelBaseInfo `description:"关联的表格"`
  240. }
  241. type ExcelBaseInfo struct {
  242. ExcelInfoId int `orm:"column(excel_info_id);pk" gorm:"primaryKey" `
  243. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  244. ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  245. ExcelName string `description:"表格名称"`
  246. UniqueCode string `description:"表格唯一编码"`
  247. ExcelClassifyId int `description:"表格分类id"`
  248. //SysUserId int `description:"操作人id"`
  249. //SysUserRealName string `description:"操作人真实姓名"`
  250. }
  251. type ClassifyDeleteCheckReq struct {
  252. ClassifyId int `description:"分类id"`
  253. EdbInfoId int `description:"指标id"`
  254. }
  255. func GetClassifyCountByClassifyId(classifyId int) (count int, err error) {
  256. o := global.DmSQL["data"]
  257. sql := `WITH RECURSIVE classify_cte(classify_id, parent_id) AS (
  258. SELECT classify_id, parent_id
  259. FROM edb_classify
  260. WHERE parent_id = ?
  261. UNION ALL
  262. SELECT e.classify_id, e.parent_id
  263. FROM edb_classify e
  264. INNER JOIN classify_cte c ON e.parent_id = c.classify_id
  265. )
  266. SELECT COUNT(1) AS COUNT
  267. FROM classify_cte
  268. WHERE classify_id <> ? ;`
  269. err = o.Raw(sql, classifyId, classifyId).Scan(&count).Error
  270. return
  271. }
  272. type EdbClassifySimplify struct {
  273. ClassifyId int `description:"分类id"`
  274. ClassifyName string `description:"分类名称"`
  275. ParentId int
  276. }
  277. // 递归获取所有目录
  278. func GetClassifyAllByClassifyId(classifyId int) (resultList []*EdbClassifySimplify, err error) {
  279. for {
  280. sql := ` SELECT * FROM edb_classify AS a
  281. WHERE a.classify_id=? order by sort asc,classify_id asc`
  282. item := new(EdbClassifySimplify)
  283. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&item).Error
  284. if err != nil {
  285. break
  286. }
  287. if item.ClassifyId > 0 {
  288. resultList = append(resultList, item)
  289. classifyId = item.ParentId
  290. } else {
  291. break
  292. }
  293. }
  294. return resultList, err
  295. }
  296. // MoveEdbClassifyReq 移动分类请求参数
  297. type MoveEdbClassifyReq struct {
  298. ClassifyId int `description:"分类id"`
  299. ParentClassifyId int `description:"父级分类id"`
  300. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  301. NextClassifyId int `description:"下一个兄弟节点分类id"`
  302. EdbInfoId int `description:"指标ID, 如果指标ID有值,则移动对象为指标,否则认为移动对象为分类"`
  303. PrevEdbInfoId int `description:"上一个指标ID"`
  304. NextEdbInfoId int `description:"下一个指标ID"`
  305. ClassifyType int `description:"分类类型:0-指标库;2-计算指标"`
  306. }
  307. // GetFirstEdbClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  308. func GetFirstEdbClassifyByParentId(parentId int) (item *EdbClassify, err error) {
  309. o := global.DmSQL["data"]
  310. sql := ` SELECT * FROM edb_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
  311. err = o.Raw(sql, parentId).First(&item).Error
  312. return
  313. }
  314. // UpdateEdbClassifySortByParentId 根据父类id更新排序
  315. func UpdateEdbClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string, classifyType uint8) (err error) {
  316. sql := ` update edb_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? AND classify_type = ? `
  317. if classifyId > 0 {
  318. sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  319. }
  320. err = global.DmSQL["data"].Exec(sql, parentId, nowSort, classifyType).Error
  321. return
  322. }
  323. // Update 更新分类基础信息
  324. func (edbClassify *EdbClassify) Update(cols []string) (err error) {
  325. err = global.DmSQL["data"].Select(cols).Updates(edbClassify).Error
  326. return
  327. }
  328. // GetEdbClassifyMaxSort 获取分类下最大的排序数
  329. func GetEdbClassifyMaxSort(parentId int, classifyType uint8) (sort int, err error) {
  330. sql := `SELECT COALESCE(Max(sort), 0) AS sort FROM edb_classify WHERE parent_id=? AND classify_type=? `
  331. err = global.DmSQL["data"].Raw(sql, parentId, classifyType).Scan(&sort).Error
  332. return
  333. }
  334. // GetEdbInfoMaxSortByClassifyId 获取分类下指标的最大的排序数
  335. func GetEdbInfoMaxSortByClassifyId(classifyId int) (sort int, err error) {
  336. sql := `SELECT COALESCE(Max(sort), 0) AS sort FROM edb_info WHERE classify_id=? `
  337. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&sort).Error
  338. return
  339. }
  340. type ClassifyEdbInfoListResp struct {
  341. EdbInfoList []*EdbClassifyItems
  342. }
  343. // GetEdbClassifyAllV2 获取普通指标的分类列表
  344. func GetEdbClassifyAllV2(classifyType int8) (items []*EdbClassifyItems, err error) {
  345. sql := ` SELECT * FROM edb_classify WHERE parent_id <>0 AND classify_type = ? order by sort asc,classify_id asc`
  346. err = global.DmSQL["data"].Raw(sql, classifyType).Scan(&items).Error
  347. return
  348. }
  349. func GetEdbClassifyByParentIdTwo(classifyType int8) (items []*EdbClassifyItems, err error) {
  350. sql := ` SELECT * FROM edb_classify WHERE level=2 AND classify_type = ? order by sort asc,classify_id asc`
  351. err = global.DmSQL["data"].Raw(sql, classifyType).Scan(&items).Error
  352. return
  353. }
  354. type AddEdbClassifyReqV2 struct {
  355. ClassifyName string `description:"分类名称"`
  356. ParentId int `description:"父级id,第一级传0"`
  357. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  358. ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
  359. }
  360. // GetEdbClassifyMaxSortV2 获取分类下最大的排序数
  361. func GetEdbClassifyMaxSortV2(parentId int, classifyType uint8) (sort int, err error) {
  362. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM edb_classify WHERE parent_id=? AND parent_id_two=? AND classify_type=? `
  363. err = global.DmSQL["data"].Raw(sql, parentId, classifyType).Scan(&sort).Error
  364. return
  365. }
  366. func GetEdbClassifyByLevel(level, source int) (items []*EdbClassifyItems, err error) {
  367. sql := ` SELECT * FROM edb_classify WHERE level=? AND classify_type = ? `
  368. err = global.DmSQL["data"].Raw(sql, level, source).Scan(&items).Error
  369. return
  370. }
  371. func FIXEdbClassifyId(newId, oldId int) (err error) {
  372. sql := ` UPDATE edb_info SET classify_id=? WHERE classify_id=? `
  373. err = global.DmSQL["data"].Exec(sql, newId, oldId).Error
  374. return
  375. }
  376. func EditEdbClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  377. sql := `UPDATE edb_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  378. err = global.DmSQL["data"].Exec(sql, sysUserId, chartClassifyName, classifyId).Error
  379. return
  380. }
  381. func UpdateEdbClassifyChildByParentClassifyId(classifyIds []int, rootId int, levelStep int) (err error) {
  382. var pars []interface{}
  383. pars = append(pars, rootId, levelStep)
  384. pars = append(pars, classifyIds)
  385. // 更新相关联的二级分类的parentId,和classify_name_second
  386. sql := `update edb_classify
  387. SET root_id = ?, level = level+?
  388. where classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  389. err = global.DmSQL["data"].Exec(sql, pars...).Error
  390. if err != nil {
  391. return
  392. }
  393. return
  394. }
  395. // GetEdbClassifyByParentIdAndName 根据父级ID和名称获取分类
  396. func GetEdbClassifyByParentIdAndName(parentId int, classifyName string, classifyId int, classifyType uint8) (item *EdbClassify, err error) {
  397. sql := `SELECT * FROM edb_classify WHERE parent_id = ? AND classify_name = ? AND classify_id <> ? and classify_type=? LIMIT 1`
  398. err = global.DmSQL["data"].Raw(sql, parentId, classifyName, classifyId, classifyType).First(&item).Error
  399. return
  400. }
  401. // GetEdbClassifyByIdList
  402. // @Description: 根据分类id列表获取分类列表
  403. // @author: Roc
  404. // @datetime 2024-03-29 10:30:21
  405. // @param classifyId int
  406. // @return item *EdbClassify
  407. // @return err error
  408. func GetEdbClassifyByIdList(classifyIdList []int) (item []*EdbClassify, err error) {
  409. num := len(classifyIdList)
  410. if num <= 0 {
  411. return
  412. }
  413. sql := `SELECT * FROM edb_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
  414. err = global.DmSQL["data"].Raw(sql, classifyIdList).Scan(&item).Error
  415. return
  416. }
  417. // GetEdbClassifyByClassifyTypeAndIsJoinPermission
  418. // @Description: 根据分类类型和是否涉密获取分类列表
  419. // @author: Roc
  420. // @datetime 2024-03-29 10:30:21
  421. // @param classifyType int
  422. // @param isJoinPermission int
  423. // @return items []*EdbClassify
  424. // @return err error
  425. func GetEdbClassifyByClassifyTypeAndIsJoinPermission(classifyType, isJoinPermission int) (items []*EdbClassify, err error) {
  426. sql := `SELECT * FROM edb_classify WHERE classify_type = ? AND is_join_permission = ? `
  427. err = global.DmSQL["data"].Raw(sql, classifyType, isJoinPermission).Scan(&items).Error
  428. return
  429. }
  430. // GetEdbClassifyRootIdsByClassifyIds 获取普通指标的顶级分类列表
  431. func GetEdbClassifyRootIdsByClassifyIds(classifyIds []int) (items []int, err error) {
  432. o := global.DmSQL["data"]
  433. sql := `SELECT distinct root_id FROM edb_classify WHERE classify_type=0 and classify_id in (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  434. err = o.Raw(sql, classifyIds).Scan(&items).Error
  435. return
  436. }
  437. // GetChildEdbClassifyByClassifyType 根据类型获取非顶级分类
  438. func GetChildEdbClassifyByClassifyType(classifyType int) (items []*EdbClassifyItems, err error) {
  439. o := global.DmSQL["data"]
  440. sql := `SELECT * FROM edb_classify WHERE parent_id <> 0 AND classify_type = ? ORDER BY sort ASC,classify_id ASC`
  441. err = o.Raw(sql, classifyType).Find(&items).Error
  442. return
  443. }
  444. // GetIsJoinPermissionEdbClassifyIdList
  445. // @Description: 获取已经加入指标管控的指标分类id列表
  446. // @param classifyType
  447. // @return list
  448. // @return err
  449. func GetIsJoinPermissionEdbClassifyIdList(classifyType int) (list []int, err error) {
  450. pars := make([]interface{}, 0)
  451. sql := ` SELECT classify_id FROM edb_classify WHERE 1=1 AND is_join_permission = 1 `
  452. if classifyType >= 0 {
  453. sql += ` AND classify_type = ? `
  454. pars = append(pars, classifyType)
  455. }
  456. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error
  457. return
  458. }
  459. // GetEdbClassifyByClassifyTypes 根据类型IDs获取分类
  460. func GetEdbClassifyByClassifyTypes(classifyTypes []int) (items []*EdbClassifyItems, err error) {
  461. if len(classifyTypes) == 0 {
  462. return
  463. }
  464. o := global.DmSQL["data"]
  465. sql := `SELECT * FROM edb_classify WHERE classify_type IN (?) ORDER BY classify_type ASC, sort ASC, classify_id ASC`
  466. err = o.Raw(sql, classifyTypes).Scan(&items).Error
  467. return
  468. }