common_classify_ctx.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package data
  2. import (
  3. "eta/eta_api/models"
  4. )
  5. // CommonClassifyStrategy 通用分类策略接口
  6. type CommonClassifyStrategy interface {
  7. GetCommonClassifyCols() models.CommonClassifyCols
  8. GetCommonClassifyById(classifyId int) (*models.CommonClassify, error)
  9. GetClassifyByParentIdAndName(parentId int, name string, excludeId int) (*models.CommonClassify, error)
  10. GetClassifySortMaxByParentId(parentId int) (int, error)
  11. GetFirstClassifyByParentId(parentId int) (*models.CommonClassify, error)
  12. SetClassifySortByParentId(parentId, classifyId, sort int, sortUpdate string) error
  13. UpdateCommonClassify(classify *models.CommonClassify, updateCols []string) error
  14. UpdateClassifyChildByParentId(classifyIds []int, rootId int, stepLevel int) error
  15. GetCommonClassifyObjCols() models.CommonClassifyObjCols
  16. GetObjectById(objectId int) (*models.CommonClassifyObj, error)
  17. GetObjectSortMaxByClassifyId(classifyId int) (int, error)
  18. GetFirstObjectByClassifyId(classifyId int) (*models.CommonClassifyObj, error)
  19. SetObjectSortByClassifyId(classifyId, sort, prevObjectId int, sortUpdate string) error
  20. UpdateCommonClassifyObj(object *models.CommonClassifyObj, updateCols []string) (err error)
  21. }
  22. // CommonClassifyCtx 通用分类上下文
  23. type CommonClassifyCtx struct {
  24. strategy CommonClassifyStrategy
  25. }
  26. // NewCommonClassifyCtx New一个通用分类上下文
  27. func NewCommonClassifyCtx(strategy CommonClassifyStrategy) *CommonClassifyCtx {
  28. return &CommonClassifyCtx{strategy: strategy}
  29. }
  30. // GetCommonClassifyCols 通用分类字段映射
  31. func (c *CommonClassifyCtx) GetCommonClassifyCols() models.CommonClassifyCols {
  32. return c.strategy.GetCommonClassifyCols()
  33. }
  34. // GetCommonClassifyById 通过策略获取分类信息
  35. func (c *CommonClassifyCtx) GetCommonClassifyById(classifyId int) (*models.CommonClassify, error) {
  36. return c.strategy.GetCommonClassifyById(classifyId)
  37. }
  38. // GetClassifyByParentIdAndName 通过策略获取分类信息
  39. func (c *CommonClassifyCtx) GetClassifyByParentIdAndName(parentId int, name string, excludeId int) (*models.CommonClassify, error) {
  40. return c.strategy.GetClassifyByParentIdAndName(parentId, name, excludeId)
  41. }
  42. // GetClassifySortMaxByParentId 获取父级分类下最大排序
  43. func (c *CommonClassifyCtx) GetClassifySortMaxByParentId(parentId int) (int, error) {
  44. return c.strategy.GetClassifySortMaxByParentId(parentId)
  45. }
  46. // GetFirstClassifyByParentId 获取父级分类下首个分类
  47. func (c *CommonClassifyCtx) GetFirstClassifyByParentId(parentId int) (*models.CommonClassify, error) {
  48. return c.strategy.GetFirstClassifyByParentId(parentId)
  49. }
  50. // SetClassifySortByParentId 通过父级ID更新分类排序
  51. func (c *CommonClassifyCtx) SetClassifySortByParentId(parentId, classifyId, sort int, sortUpdate string) error {
  52. return c.strategy.SetClassifySortByParentId(parentId, classifyId, sort, sortUpdate)
  53. }
  54. // UpdateCommonClassify 更新通用分类
  55. func (c *CommonClassifyCtx) UpdateCommonClassify(classify *models.CommonClassify, updateCols []string) error {
  56. return c.strategy.UpdateCommonClassify(classify, updateCols)
  57. }
  58. // UpdateClassifyChildByParentId 更新分类子节点RootId
  59. func (c *CommonClassifyCtx) UpdateClassifyChildByParentId(classifyIds []int, rootId int, stepLevel int) error {
  60. return c.strategy.UpdateClassifyChildByParentId(classifyIds, rootId, stepLevel)
  61. }
  62. // GetCommonClassifyObjCols 通用分类对象字段映射
  63. func (c *CommonClassifyCtx) GetCommonClassifyObjCols() models.CommonClassifyObjCols {
  64. return c.strategy.GetCommonClassifyObjCols()
  65. }
  66. // GetObjectById 获取分类对象
  67. func (c *CommonClassifyCtx) GetObjectById(objectId int) (*models.CommonClassifyObj, error) {
  68. return c.strategy.GetObjectById(objectId)
  69. }
  70. // GetObjectSortMaxByClassifyId 获取分类下最大排序
  71. func (c *CommonClassifyCtx) GetObjectSortMaxByClassifyId(classifyId int) (int, error) {
  72. return c.strategy.GetObjectSortMaxByClassifyId(classifyId)
  73. }
  74. // GetFirstObjectByClassifyId 获取分类下首个对象
  75. func (c *CommonClassifyCtx) GetFirstObjectByClassifyId(classifyId int) (*models.CommonClassifyObj, error) {
  76. return c.strategy.GetFirstObjectByClassifyId(classifyId)
  77. }
  78. // SetObjectSortByClassifyId 通过分类ID更新对象排序
  79. func (c *CommonClassifyCtx) SetObjectSortByClassifyId(classifyId, sort, prevObjectId int, sortUpdate string) error {
  80. return c.strategy.SetObjectSortByClassifyId(classifyId, sort, prevObjectId, sortUpdate)
  81. }
  82. // UpdateCommonClassifyObj 更新分类对象
  83. func (c *CommonClassifyCtx) UpdateCommonClassifyObj(object *models.CommonClassifyObj, updateCols []string) (err error) {
  84. return c.strategy.UpdateCommonClassifyObj(object, updateCols)
  85. }