task_config.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/admin/main/aegis/model"
  6. "go-common/app/admin/main/aegis/model/task"
  7. "go-common/library/xstr"
  8. )
  9. // QueryConfigs .
  10. func (s *Service) QueryConfigs(c context.Context, queryParams *task.QueryParams) (ls []*task.Config, count int64, err error) {
  11. ls, count, err = s.gorm.QueryConfigs(c, queryParams)
  12. if err != nil || count == 0 {
  13. return
  14. }
  15. switch queryParams.ConfType {
  16. case task.TaskConfigAssign:
  17. case task.TaskConfigRangeWeight:
  18. case task.TaskConfigEqualWeight:
  19. if len(queryParams.IDFilter) > 0 || len(queryParams.TypeFilter) > 0 {
  20. confItem := &task.EqualWeightConfig{}
  21. lsres := []*task.Config{}
  22. for _, item := range ls {
  23. if err = json.Unmarshal([]byte(item.ConfJSON), confItem); err != nil {
  24. continue
  25. }
  26. if len(queryParams.IDFilter) > 0 {
  27. ids1, _ := xstr.SplitInts(confItem.IDs)
  28. ids2, _ := xstr.SplitInts(queryParams.IDFilter)
  29. if len(mergeSlice(ids1, ids2)) == 0 {
  30. continue
  31. }
  32. }
  33. if len(queryParams.TypeFilter) > 0 {
  34. ids, _ := xstr.SplitInts(queryParams.TypeFilter)
  35. if len(mergeSlice(ids, []int64{int64(confItem.Type)})) == 0 {
  36. continue
  37. }
  38. }
  39. lsres = append(lsres, item)
  40. }
  41. return lsres, count, err
  42. }
  43. }
  44. return ls, count, err
  45. }
  46. // UpdateConfig .
  47. func (s *Service) UpdateConfig(c context.Context, config *task.Config) (err error) {
  48. return s.gorm.UpdateConfig(c, config)
  49. }
  50. // SetStateConfig .
  51. func (s *Service) SetStateConfig(c context.Context, id int64, state int8) (err error) {
  52. return s.gorm.SetStateConfig(c, id, state)
  53. }
  54. // AddConfig .
  55. func (s *Service) AddConfig(c context.Context, config *task.Config, confJSON interface{}) (err error) {
  56. return s.gorm.AddConfig(c, config, confJSON)
  57. }
  58. // DeleteConfig .
  59. func (s *Service) DeleteConfig(c context.Context, id int64) (err error) {
  60. return s.gorm.DeleteConfig(c, id)
  61. }
  62. // WeightLog .
  63. func (s *Service) WeightLog(c context.Context, taskid int64, pn, ps int) (ls []*model.WeightLog, count int, err error) {
  64. ls, count, err = s.searchWeightLog(c, taskid, pn, ps)
  65. if err != nil || len(ls) == 0 {
  66. return
  67. }
  68. var Name string
  69. if mid := ls[0].Mid; mid > 0 {
  70. if info, _ := s.rpc.Info3(c, mid); info != nil {
  71. Name = info.Name
  72. }
  73. }
  74. for _, item := range ls {
  75. item.MemName = Name
  76. }
  77. return
  78. }