chart_classify.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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 ChartClassify struct {
  9. ChartClassifyId int `orm:"column(chart_classify_id);pk" gorm:"primaryKey" `
  10. ChartClassifyName string `description:"分类名称"`
  11. ParentId int `description:"父级id"`
  12. HasData int `description:"是否含有指标数据"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. SysUserId int `description:"创建人id"`
  16. SysUserRealName string `description:"创建人姓名"`
  17. Level int `description:"层级"`
  18. UniqueCode string `description:"唯一编码"`
  19. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  20. Source int `description:"1:ETA图库;2:商品价格曲线"`
  21. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  22. ChartClassifyNameEn string `description:"英文分类名称"`
  23. RootId int `description:"顶级ID"`
  24. ChartClassifyNamePath string `description:"分类名称的完整路径,格式为:父级分类名称|当前分类名称"`
  25. ChartClassifyIdPath string `description:"分类的完整路径,格式为:父级ID,当前ID"`
  26. }
  27. func AddChartClassify(item *ChartClassify) (err error) {
  28. err = global.DmSQL["data"].Create(item).Error
  29. if err != nil {
  30. return
  31. }
  32. return
  33. }
  34. type AddChartClassifyReq struct {
  35. ChartClassifyName string `description:"分类名称"`
  36. ParentId int `description:"父级id,第一级传0"`
  37. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  38. }
  39. // GetChartClassifyCount
  40. // @Description: 根据图表分类名称获取对应的数量
  41. // @author: Roc
  42. // @datetime 2024-04-16 18:13:40
  43. // @param chartClassifyName string
  44. // @param parentId int
  45. // @param source int
  46. // @return count int
  47. // @return err error
  48. func GetChartClassifyCount(chartClassifyName string, parentId, source int) (count int, err error) {
  49. o := global.DmSQL["data"]
  50. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name=? `
  51. err = o.Raw(sql, parentId, source, chartClassifyName).Scan(&count).Error
  52. return
  53. }
  54. // GetChartClassifyEnCount
  55. // @Description: 根据图表分类英文名称获取对应的数量
  56. // @author: Roc
  57. // @datetime 2024-04-16 18:13:24
  58. // @param chartClassifyNameEn string
  59. // @param parentId int
  60. // @param source int
  61. // @return count int
  62. // @return err error
  63. func GetChartClassifyEnCount(chartClassifyNameEn string, parentId, source int) (count int, err error) {
  64. o := global.DmSQL["data"]
  65. sql := `SELECT COUNT(1) AS count FROM chart_classify WHERE parent_id=? AND source = ? AND chart_classify_name_en = ? `
  66. err = o.Raw(sql, parentId, source, chartClassifyNameEn).Scan(&count).Error
  67. return
  68. }
  69. type EditChartClassifyReq struct {
  70. ChartClassifyName string `description:"分类名称"`
  71. ChartClassifyId int `description:"分类id"`
  72. }
  73. func GetChartClassifyById(classifyId int) (item *ChartClassify, err error) {
  74. o := global.DmSQL["data"]
  75. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  76. err = o.Raw(sql, classifyId).First(&item).Error
  77. return
  78. }
  79. func GetChartClassifyCountById(classifyId int) (count int, err error) {
  80. o := global.DmSQL["data"]
  81. sql := `SELECT count(1) AS count FROM chart_classify WHERE chart_classify_id=? `
  82. err = o.Raw(sql, classifyId).Scan(&count).Error
  83. return
  84. }
  85. type DeleteChartClassifyReq struct {
  86. ChartClassifyId int `description:"分类id"`
  87. ChartInfoId int `description:"指标id"`
  88. }
  89. // GetChartClassifyByParentId
  90. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  91. func GetChartClassifyByParentId(parentId, source, sysUserId int) (items []*ChartClassifyItems, err error) {
  92. o := global.DmSQL["data"]
  93. sql := ` SELECT * FROM chart_classify WHERE parent_id=? AND source = ? `
  94. if sysUserId > 0 {
  95. sql += fmt.Sprintf(` AND sys_user_id = %d `, sysUserId)
  96. }
  97. sql += ` order by sort asc,chart_classify_id asc `
  98. err = o.Raw(sql, parentId, source).Scan(&items).Error
  99. return
  100. }
  101. // GetChartClassifyAll
  102. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  103. func GetChartClassifyAll(source, sysUserId int) (items []*ChartClassifyItems, err error) {
  104. o := global.DmSQL["data"]
  105. sql := ` SELECT * FROM chart_classify WHERE parent_id<>0 AND source = ?`
  106. if sysUserId > 0 {
  107. sql += fmt.Sprintf(` AND sys_user_id = %d `, sysUserId)
  108. }
  109. sql += ` order by sort asc,chart_classify_id asc `
  110. err = o.Raw(sql, source).Scan(&items).Error
  111. return
  112. }
  113. // GetAllChartClassify
  114. // @Description: 获取所有类型的图表分类
  115. // @author: Roc
  116. // @datetime 2024-12-09 10:11:46
  117. // @return items []*ChartClassifyItems
  118. // @return err error
  119. func GetAllChartClassify() (items []*ChartClassifyItems, err error) {
  120. o := global.DmSQL["data"]
  121. sql := ` SELECT * FROM chart_classify order by sort asc,chart_classify_id asc`
  122. err = o.Raw(sql).Scan(&items).Error
  123. return
  124. }
  125. // GetChartClassifyByParentId
  126. // @param source int 1:ETA图库;2:商品价格曲线;3:相关性图表
  127. func GetAllChartClassifyByParentId(parentId int) (items []*ChartClassifyItems, err error) {
  128. o := global.DmSQL["data"]
  129. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc`
  130. err = o.Raw(sql, parentId).Scan(&items).Error
  131. return
  132. }
  133. type ChartClassifyItems struct {
  134. ChartClassifyId int `description:"分类id"`
  135. ChartInfoId int `description:"指标id"`
  136. ChartClassifyName string
  137. ChartClassifyNameEn string
  138. ParentId int
  139. Level int `description:"层级"`
  140. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  141. UniqueCode string `description:"唯一编码"`
  142. Source int `description:"来源id"`
  143. SourceName string `description:"来源名称"`
  144. SysUserId int `description:"创建人id"`
  145. SysUserRealName string `description:"创建人姓名"`
  146. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  147. StartDate string `description:"自定义开始日期"`
  148. EndDate string `description:"自定义结束日期"`
  149. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  150. Calendar string `description:"公历/农历"`
  151. SeasonStartDate string `description:"季节性图开始日期"`
  152. SeasonEndDate string `description:"季节性图开始日期"`
  153. Children []*ChartClassifyItems `gorm:"-"`
  154. Button ChartClassifyItemsButton `gorm:"-" description:"按钮权限"`
  155. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  156. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  157. ChartClassifyIdPath string `description:"分类的完整路径,格式为:父级ID,当前ID"`
  158. }
  159. // ChartClassifyItemsButton 操作按钮
  160. type ChartClassifyItemsButton struct {
  161. AddButton bool `description:"是否可添加"`
  162. OpButton bool `description:"是否可编辑"`
  163. DeleteButton bool `description:"是否可删除"`
  164. MoveButton bool `description:"是否可移动"`
  165. }
  166. type ChartClassifyListResp struct {
  167. AllNodes []*ChartClassifyItems
  168. Language string `description:"指标的展示语言,CN:中文,EN:英文"`
  169. CanOpClassify bool `description:"是否允许操作分类"`
  170. }
  171. type ChartClassifyDeleteCheckResp struct {
  172. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  173. TipsMsg string `description:"提示信息"`
  174. }
  175. type ChartClassifyDeleteCheckReq struct {
  176. ChartClassifyId int `description:"分类id"`
  177. ChartInfoId int `description:"指标id"`
  178. }
  179. func GetChartClassifyByCondition(condition string, pars []interface{}) (item *ChartClassify, err error) {
  180. o := global.DmSQL["data"]
  181. sql := ` SELECT * FROM chart_classify WHERE 1=1 `
  182. if condition != "" {
  183. sql += condition
  184. }
  185. err = o.Raw(sql, pars...).First(&item).Error
  186. return
  187. }
  188. // MoveChartClassifyReq 移动图表分类请求参数
  189. type MoveChartClassifyReq struct {
  190. ClassifyId int `description:"分类id"`
  191. ParentClassifyId int `description:"父级分类id"`
  192. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  193. NextClassifyId int `description:"下一个兄弟节点分类id"`
  194. ChartInfoId int `description:"图表ID, 如果图表ID有值,则移动对象为图表,否则认为移动对象分类"`
  195. PrevChartInfoId int `description:"上一个图表ID"`
  196. NextChartInfoId int `description:"下一个图表ID"`
  197. }
  198. // GetFirstChartClassifyByParentId 获取当前父级图表分类下的排序第一条的数据
  199. func GetFirstChartClassifyByParentId(parentId int) (item *ChartClassify, err error) {
  200. o := global.DmSQL["data"]
  201. sql := ` SELECT * FROM chart_classify WHERE parent_id=? order by sort asc,chart_classify_id asc limit 1`
  202. err = o.Raw(sql, parentId).First(&item).Error
  203. return
  204. }
  205. // GetFirstChartClassifyByParentIdAndSource 获取当前父级图表分类下的排序第一条的数据
  206. func GetFirstChartClassifyByParentIdAndSource(parentId, source int) (item *ChartClassify, err error) {
  207. o := global.DmSQL["data"]
  208. sql := ` SELECT * FROM chart_classify WHERE parent_id=? and source = ? order by sort asc,chart_classify_id asc limit 1`
  209. err = o.Raw(sql, parentId, source).First(&item).Error
  210. return
  211. }
  212. // UpdateChartClassifySortByParentId 根据图表父类id更新排序
  213. func UpdateChartClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  214. o := global.DmSQL["data"]
  215. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  216. if classifyId > 0 {
  217. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  218. }
  219. err = o.Exec(sql, parentId, nowSort).Error
  220. return
  221. }
  222. // Update 更新图表分类基础信息
  223. func (chartClassify *ChartClassify) Update(cols []string) (err error) {
  224. err = global.DmSQL["data"].Select(cols).Updates(chartClassify).Error
  225. return
  226. }
  227. // GetChartClassifyMaxSort 获取图表分类下最大的排序数
  228. func GetChartClassifyMaxSort(parentId, source int) (sort int, err error) {
  229. o := global.DmSQL["data"]
  230. sql := `SELECT COALESCE(MAX(sort),0) AS sort FROM chart_classify WHERE parent_id=? AND source = ? `
  231. err = o.Raw(sql, parentId, source).Scan(&sort).Error
  232. return
  233. }
  234. type ChartClassifyView struct {
  235. ChartClassifyId int `orm:"column(chart_classify_id);pk" gorm:"primaryKey" `
  236. ChartClassifyName string `description:"分类名称"`
  237. ParentId int `description:"父级id"`
  238. }
  239. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  240. o := global.DmSQL["data"]
  241. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  242. err = o.Raw(sql, classifyId).First(&item).Error
  243. return
  244. }
  245. func GetChartClassifyByLevel(level, source int) (items []*ChartClassifyItems, err error) {
  246. o := global.DmSQL["data"]
  247. sql := ` SELECT * FROM chart_classify WHERE level=? AND source = ? order by sort asc,chart_classify_id asc`
  248. err = o.Raw(sql, level, source).Scan(&items).Error
  249. return
  250. }
  251. func EditChartClassifySysUser(classifyId, sysUserId int, chartClassifyName string) (err error) {
  252. o := global.DmSQL["data"]
  253. sql := `UPDATE chart_classify SET sys_user_id=?,sys_user_real_name=?,modify_time=NOW() WHERE parent_id=? AND level=3 `
  254. err = o.Exec(sql, sysUserId, chartClassifyName, classifyId).Error
  255. return
  256. }
  257. func GetAllChartClassifyItemsBySource(source int) (items []*ChartClassifyItems, err error) {
  258. o := global.DmSQL["data"]
  259. sql := ` SELECT * FROM chart_classify WHERE source = ? order by sort ASC,chart_classify_id ASC`
  260. err = o.Raw(sql, source).Scan(&items).Error
  261. return
  262. }
  263. // GetCrossVarietyChartClassifyBySysUserId
  264. // @Description: 根据创建人获取跨品种分析的分类
  265. // @author: Roc
  266. // @datetime 2023-11-24 14:05:43
  267. // @param sysUserId int
  268. // @return item *ChartClassify
  269. // @return err error
  270. func GetCrossVarietyChartClassifyBySysUserId(sysUserId int) (item *ChartClassify, err error) {
  271. o := global.DmSQL["data"]
  272. sql := `SELECT * FROM chart_classify WHERE source = ? AND sys_user_id=?`
  273. err = o.Raw(sql, utils.CHART_SOURCE_CROSS_HEDGING, sysUserId).First(&item).Error
  274. return
  275. }
  276. // GetChartClassifyByParentIdAndName 根据父级ID和名称获取分类
  277. func GetChartClassifyByParentIdAndName(source, parentId int, classifyName string, classifyId int) (item *ChartClassify, err error) {
  278. o := global.DmSQL["data"]
  279. sql := `SELECT * FROM chart_classify WHERE source = ? AND parent_id = ? AND chart_classify_name = ? AND chart_classify_id <> ? LIMIT 1`
  280. err = o.Raw(sql, source, parentId, classifyName, classifyId).First(&item).Error
  281. return
  282. }
  283. // GetChartClassifyByIdList
  284. // @Description: 根据分类ID列表获取分类
  285. // @author: Roc
  286. // @datetime 2024-04-01 13:21:48
  287. // @param classifyId []int
  288. // @return items []*ChartClassify
  289. // @return err error
  290. func GetChartClassifyByIdList(classifyIdList []int) (items []*ChartClassify, err error) {
  291. num := len(classifyIdList)
  292. if num <= 0 {
  293. return
  294. }
  295. o := global.DmSQL["data"]
  296. sql := `SELECT * FROM chart_classify WHERE chart_classify_id in (` + utils.GetOrmInReplace(num) + `) `
  297. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  298. return
  299. }
  300. // GetChartClassifyItemsByIdList
  301. // @Description: 根据分类ID列表获取分类
  302. // @author: Roc
  303. // @datetime 2024-04-01 13:21:48
  304. // @param classifyId []int
  305. // @return items []*ChartClassify
  306. // @return err error
  307. func GetChartClassifyItemsByIdList(classifyIdList []int) (items []*ChartClassifyItems, err error) {
  308. num := len(classifyIdList)
  309. if num <= 0 {
  310. return
  311. }
  312. o := global.DmSQL["data"]
  313. sql := `SELECT * FROM chart_classify WHERE chart_classify_id in (` + utils.GetOrmInReplace(num) + `) `
  314. err = o.Raw(sql, classifyIdList).Scan(&items).Error
  315. return
  316. }
  317. // GetChartClassifyBySourceAndIsJoinPermission
  318. // @Description: 根据分类类型和是否涉密获取分类列表
  319. // @author: Roc
  320. // @datetime 2024-03-29 10:30:21
  321. // @param source int
  322. // @param isJoinPermission int
  323. // @return items []*ChartClassify
  324. // @return err error
  325. func GetChartClassifyBySourceAndIsJoinPermission(source, isJoinPermission int) (items []*ChartClassify, err error) {
  326. o := global.DmSQL["data"]
  327. sql := `SELECT * FROM chart_classify WHERE source = ? AND is_join_permission = ? `
  328. err = o.Raw(sql, source, isJoinPermission).Scan(&items).Error
  329. return
  330. }
  331. type ChartClassifyIdItems struct {
  332. ChartClassifyId int `description:"分类id"`
  333. ChartClassifyName string `description:"分类名称"`
  334. UniqueCode string `description:"唯一编码"`
  335. ParentId int `description:"父级分类id"`
  336. Level int `description:"层级"`
  337. RootId int `description:"顶级分类id"`
  338. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0" json:"-"`
  339. HaveOperaAuth bool `description:"是否有该数据权限,默认:false"`
  340. }
  341. func GetChartClassifyByRootIdLevel(rootId, source int, orderStr string) (items []*ChartClassifyIdItems, err error) {
  342. o := global.DmSQL["data"]
  343. sql := ` SELECT * FROM chart_classify WHERE root_id = ? AND source = ? `
  344. if orderStr != "" {
  345. sql += orderStr
  346. } else {
  347. sql += ` order by level desc, sort asc, chart_classify_id asc`
  348. }
  349. err = o.Raw(sql, rootId, source).Scan(&items).Error
  350. return
  351. }
  352. // UpdateChartClassifySortByParentIdAndSource 根据图表父类id更新排序
  353. func UpdateChartClassifySortByParentIdAndSource(parentId, classifyId, nowSort int, updateSort string, source int) (err error) {
  354. o := global.DmSQL["data"]
  355. sql := ` update chart_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? AND source = ? `
  356. if classifyId > 0 {
  357. sql += ` or ( chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  358. }
  359. err = o.Exec(sql, parentId, nowSort, source).Error
  360. return
  361. }
  362. // GetChartClassifyAllBySource 根据来源获取所有分类
  363. func GetChartClassifyAllBySource(source int) (items []*ChartClassifyItems, err error) {
  364. o := global.DmSQL["data"]
  365. sql := ` SELECT * FROM chart_classify WHERE source = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
  366. err = o.Raw(sql, source).Scan(&items).Error
  367. return
  368. }
  369. // delByIds
  370. func DeleteChartClassifyByIds(ids []int) (err error) {
  371. o := global.DmSQL["data"]
  372. sql := `DELETE FROM chart_classify WHERE chart_classify_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
  373. err = o.Exec(sql, ids).Error
  374. return
  375. }
  376. // UpdateChartClassify
  377. // @Description: 更新图表分类的基础信息
  378. // @author: Roc
  379. // @datetime 2024-12-09 10:29:51
  380. // @param classifyId int
  381. // @param classifyNamePath string
  382. // @param classifyIdPath string
  383. // @return err error
  384. func UpdateChartClassify(classifyId int, classifyNamePath, classifyIdPath string) (err error) {
  385. sql := `UPDATE chart_classify SET chart_classify_name_path = ?,chart_classify_id_path = ? WHERE chart_classify_id = ?`
  386. err = global.DmSQL["data"].Exec(sql, classifyNamePath, classifyIdPath, classifyId).Error
  387. return
  388. }
  389. // UpdateClassifyIdByChartInfoId
  390. // @Description: 根据图表id更新所属分类id
  391. // @author: Roc
  392. // @datetime 2024-11-29 17:54:44
  393. // @param edbInfoId int
  394. // @param edbClassifyId int
  395. // @return err error
  396. func UpdateClassifyIdByChartInfoId(chartInfoId, chartClassifyId int) (err error) {
  397. sql := ` UPDATE chart_info SET chart_classify_id = ? WHERE chart_info_id=? `
  398. err = global.DmSQL["data"].Exec(sql, chartClassifyId, chartInfoId).Error
  399. return
  400. }
  401. // DelChartClassifyByIdList
  402. // @Description: 根据id删除图表分类
  403. // @author: Roc
  404. // @datetime 2024-12-02 09:27:26
  405. // @param idList []int
  406. // @return err error
  407. func DelChartClassifyByIdList(idList []int) (err error) {
  408. num := len(idList)
  409. if num <= 0 {
  410. return
  411. }
  412. sql := `DELETE FROM chart_classify WHERE chart_classify_id IN (?) `
  413. err = global.DmSQL["data"].Exec(sql, idList).Error
  414. return
  415. }
  416. // UpdateClassifyNameAndNamePath
  417. // @Description: 更新分类名称和完整名称路径
  418. // @author: Roc
  419. // @receiver chartClassify
  420. // @datetime 2024-12-09 14:13:05
  421. // @param cols []string
  422. // @param oldClassifyNamePath string
  423. // @param newClassifyNamePath string
  424. // @return err error
  425. func (chartClassify *ChartClassify) UpdateClassifyNameAndNamePath(cols []string, oldClassifyNamePath, newClassifyNamePath string) (err error) {
  426. tx := global.DmSQL["data"].Begin()
  427. defer func() {
  428. if err != nil {
  429. _ = tx.Rollback()
  430. return
  431. }
  432. _ = tx.Commit()
  433. }()
  434. // 变更分类信息
  435. err = tx.Select(cols).Updates(chartClassify).Error
  436. if err != nil {
  437. return
  438. }
  439. // 更改子分类的完整的路径
  440. if oldClassifyNamePath != `` && newClassifyNamePath != `` {
  441. sql := `UPDATE chart_classify SET chart_classify_name_path = REPLACE(chart_classify_name_path,?,?) WHERE chart_classify_id_path LIKE ?`
  442. err = tx.Exec(sql, oldClassifyNamePath, newClassifyNamePath, fmt.Sprint(chartClassify.ChartClassifyIdPath+`,%`)).Error
  443. if err != nil {
  444. return
  445. }
  446. }
  447. return
  448. }
  449. // UpdateChartClassifyNameAndNamePathByOldClassifyIdPath
  450. // @Description: 根据源分类id全路径更新分类名称和子分类的全路径
  451. // @author: Roc
  452. // @receiver edbClassify
  453. // @datetime 2024-11-26 14:39:09
  454. // @param cols []string
  455. // @param oldClassifyNamePath string
  456. // @param newClassifyNamePath string
  457. // @return err error
  458. func UpdateChartClassifyNameAndNamePathByOldClassifyIdPath(oldClassifyIdPath, newClassifyIdPath, oldClassifyNamePath, newClassifyNamePath string) (err error) {
  459. // 更改子分类的完整的路径
  460. if oldClassifyIdPath != `` && newClassifyNamePath != `` && newClassifyIdPath != `` {
  461. sql := `UPDATE chart_classify SET chart_classify_id_path = REPLACE(chart_classify_id_path,?,?) ,chart_classify_name_path = REPLACE(chart_classify_name_path,?,?) WHERE chart_classify_id_path LIKE ?`
  462. err = global.DmSQL["data"].Exec(sql, oldClassifyIdPath, newClassifyIdPath, oldClassifyNamePath, newClassifyNamePath, fmt.Sprint(oldClassifyIdPath+`,%`)).Error
  463. if err != nil {
  464. return
  465. }
  466. }
  467. return
  468. }
  469. func GetChildChartClassifyListByParentId(classifyIdPath, orderStr string) (items []*ChartClassifyItems, err error) {
  470. o := global.DmSQL["data"]
  471. sql := ` SELECT * FROM chart_classify WHERE chart_classify_id_path like ? `
  472. if orderStr != "" {
  473. sql += orderStr
  474. } else {
  475. sql += ` order by level desc, sort asc, chart_classify_id asc`
  476. }
  477. err = o.Raw(sql, classifyIdPath).Scan(&items).Error
  478. return
  479. }
  480. // GetChartInfoMaxPublicSortByClassifyId
  481. // @Description: 获取分类下公共图库的最大的排序数
  482. // @param classifyId
  483. // @return sort
  484. // @return err
  485. func GetChartInfoMaxPublicSortByClassifyId(classifyId int) (sort int, err error) {
  486. sql := `SELECT COALESCE(Max(public_sort), 0) AS sort FROM chart_info WHERE public_status = 3 AND chart_public_classify_id = ? `
  487. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&sort).Error
  488. return
  489. }
  490. type ChartClassifyItemList []*ChartClassifyItems
  491. func (m ChartClassifyItemList) Len() int {
  492. return len(m)
  493. }
  494. func (m ChartClassifyItemList) Less(i, j int) bool {
  495. return m[i].Sort < m[j].Sort
  496. }
  497. func (m ChartClassifyItemList) Swap(i, j int) {
  498. m[i], m[j] = m[j], m[i]
  499. }