activity_special_permission_points.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_task/utils"
  5. "time"
  6. )
  7. type CygxActivitySpecialPermissionPoints struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"公司ID"`
  10. Points int `description:"剩余点数"`
  11. CompanyName string `description:"公司名称"`
  12. ChartPermissionId int `description:"行业id"`
  13. ChartPermissionName string `description:"行业名称"`
  14. CreateTime time.Time `description:"创建时间"`
  15. ModifyTime time.Time `description:"更新时间"`
  16. }
  17. // MultiAddCygxActivitySpecialPermissionPoints 批量添加
  18. func MultiAddCygxActivitySpecialPermissionPoints(items []*CygxActivitySpecialPermissionPoints) (err error) {
  19. if len(items) == 0 {
  20. return
  21. }
  22. var chartPermissionIds []int
  23. var companyId int
  24. for _, v := range items {
  25. companyId = v.CompanyId
  26. if v.ChartPermissionId > 0 {
  27. chartPermissionIds = append(chartPermissionIds, v.ChartPermissionId)
  28. }
  29. }
  30. lenchartPermissionIds := len(chartPermissionIds)
  31. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  32. if err != nil {
  33. return
  34. }
  35. defer func() {
  36. if err == nil {
  37. o.Commit()
  38. } else {
  39. o.Rollback()
  40. }
  41. }()
  42. var condition string
  43. var pars []interface{}
  44. pars = make([]interface{}, 0)
  45. condition = " AND company_id = ? "
  46. pars = append(pars, companyId)
  47. if lenchartPermissionIds > 0 {
  48. condition += " AND chart_permission_id IN (" + utils.GetOrmInReplace(lenchartPermissionIds) + ") "
  49. pars = append(pars, chartPermissionIds)
  50. }
  51. //删除历史记录
  52. sql := ""
  53. if condition != "" {
  54. sql = " DELETE FROM cygx_activity_special_permission_points WHERE 1= 1 " + condition
  55. _, err = o.Raw(sql, pars).Exec()
  56. if err != nil {
  57. return
  58. }
  59. }
  60. //批量插入
  61. _, err = o.InsertMulti(len(items), items)
  62. if err != nil {
  63. return
  64. }
  65. return
  66. }
  67. // 获取公司每个行业剩余研选点数列表
  68. func GetCygxActivitySpecialPermissionPointsList(condition string, pars []interface{}) (items []*CygxActivitySpecialPermissionPoints, err error) {
  69. o := orm.NewOrmUsingDB("hz_cygx")
  70. sql := `SELECT * FROM cygx_activity_special_permission_points WHERE 1 = 1 `
  71. if condition != "" {
  72. sql += condition
  73. }
  74. _, err = o.Raw(sql, pars).QueryRows(&items)
  75. return
  76. }
  77. // 到期清零
  78. func UpdateCygxActivitySpecialPermissionPointsTryOutReduce( companyId int) (err error) {
  79. o := orm.NewOrmUsingDB("hz_cygx")
  80. sql := `UPDATE cygx_activity_special_permission_points SET points = 0 WHERE company_id=? `
  81. _, err = o.Raw(sql, companyId ).Exec()
  82. return
  83. }