sandbox.go 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package sandbox
  2. import (
  3. sandboxModel "hongze/hongze_yb/models/tables/sandbox"
  4. "time"
  5. )
  6. // SandboxItem 沙盘图
  7. type SandboxItem struct {
  8. SandboxID uint32 `gorm:"primaryKey;column:sandbox_id;type:int(9) unsigned;not null" json:"sandbox_id"` // 沙盘id
  9. Name string `gorm:"index:idx_name;column:name;type:varchar(64);not null;default:''" json:"name"` // 沙盘名称
  10. ChartPermissionID uint32 `gorm:"column:chart_permission_id;type:int(9) unsigned;not null;default:0" json:"chart_permission_id"` // 品种id
  11. ChartPermissionName string `gorm:"index:idx_chart_permission_name;column:chart_permission_name;type:varchar(32);not null;default:''" json:"chart_permission_name"` // 品种名称(冗余字段,避免列表页查询时再去关联表查询)
  12. CurrVersion uint32 `gorm:"column:curr_version;type:int(9) unsigned;not null;default:0" json:"curr_version"` // 当前版本
  13. Code string `gorm:"column:code;type:varchar(255);not null" json:"code"` // 沙盘code
  14. PicURL string `gorm:"column:pic_url;type:varchar(255);not null;default:''" json:"pic_url"` // 沙盘图片
  15. OpUserName string `gorm:"index:idx_op_user_name;column:op_user_name;type:varchar(32);not null;default:''" json:"op_user_name"` // 最近一次编辑的用户名称(冗余字段,避免查表)
  16. ModifyTime time.Time `gorm:"column:modify_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"modify_time"` // 最近一次更新时间
  17. }
  18. // GetList 获取沙盘列表数据
  19. func GetList(chartPermissionId int, companyPermissionIdList []int, keyword string, page, pageSize int) (total int64, list []SandboxItem, err error, errMsg string) {
  20. errMsg = `获取失败`
  21. var condition string
  22. var pars []interface{}
  23. condition = ` s.is_delete = ? `
  24. pars = append(pars, 0)
  25. // 客户拥有的品种权限
  26. if len(companyPermissionIdList) > 0 {
  27. condition += " AND c.chart_permission_id in (?) "
  28. pars = append(pars, companyPermissionIdList)
  29. }
  30. if chartPermissionId > 0 {
  31. condition += " AND c.chart_permission_id=? "
  32. pars = append(pars, chartPermissionId)
  33. }
  34. if keyword != "" {
  35. //condition += ` AND ( name LIKE '%` + keyword + `%' OR chart_permission_name LIKE '%` + keyword + `%' )`
  36. condition += ` AND ( s.name LIKE '%` + keyword + `%' )`
  37. }
  38. //获取指标信息
  39. tmpTotal, tmpList, tmpErr := sandboxModel.GetPageListByWhere(condition, pars, (page-1)*pageSize, pageSize)
  40. if tmpErr != nil {
  41. err = tmpErr
  42. return
  43. }
  44. total = tmpTotal
  45. for _, v := range tmpList {
  46. tmpSandBox := SandboxItem{
  47. SandboxID: v.SandboxID,
  48. Name: v.Name,
  49. ChartPermissionID: v.ChartPermissionID,
  50. ChartPermissionName: v.ChartPermissionName,
  51. CurrVersion: v.CurrVersion,
  52. Code: v.Code,
  53. PicURL: v.PicURL,
  54. OpUserName: v.OpUserName,
  55. ModifyTime: v.ModifyTime,
  56. //CreateTime: time.Time{},
  57. }
  58. list = append(list, tmpSandBox)
  59. }
  60. return
  61. }
  62. // GetPermissionCountList 获取沙盘列表数据
  63. func GetPermissionCountList(companyPermissionIdList []int) (list []*sandboxModel.PermissionSandboxCount, err error, errMsg string) {
  64. errMsg = `获取失败`
  65. var condition string
  66. var pars []interface{}
  67. condition = ` is_delete = ? `
  68. pars = append(pars, 0)
  69. // 客户拥有的品种权限
  70. if len(companyPermissionIdList) > 0 {
  71. condition += " AND chart_permission_id in (?) "
  72. pars = append(pars, companyPermissionIdList)
  73. }
  74. //获取指标信息
  75. list, err = sandboxModel.GetPermissionCountListByWhere(condition, pars)
  76. return
  77. }