xzs_choose_send.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. "time"
  6. )
  7. type CygxXzsChooseSend struct {
  8. Id int `orm:"column(id);pk"`
  9. UserId int `description:"用户ID"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. CompanyId int `description:"公司id"`
  13. CompanyName string `description:"公司名称"`
  14. RealName string `description:"用户实际名称"`
  15. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  16. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  17. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"更新时间"`
  20. AllInYiYao int `description:"是否选择医药全部赛道"`
  21. AllInXiaoFei int `description:"是否选择消费全部赛道"`
  22. AllInKeJi int `description:"是否选择科技全部赛道"`
  23. AllInZhiZao int `description:"是否选择智造全部赛道"`
  24. AllInCeLue int `description:"是否选择策略全部赛道"`
  25. AllInYanXuan int `description:"是否选择研选全部赛道"`
  26. }
  27. // 获取提交过推送规则用户的userId
  28. func GetCygxXzsChooseSend() (items []*CygxXzsChooseSend, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT * FROM cygx_xzs_choose_send `
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. }
  34. // 获取某个行业勾选全部赛道的用户
  35. func GetCygxXzsChooseSendByAllIn(allIn string) (items []*CygxXzsChooseSend, err error) {
  36. o := orm.NewOrm()
  37. sql := `SELECT * FROM cygx_xzs_choose_send WHERE ` + allIn + ` = 1 `
  38. _, err = o.Raw(sql).QueryRows(&items)
  39. return
  40. }
  41. // 修改某个用户的行业是否勾选全部赛道
  42. func UpdateCygxXzsChooseSendIsAllIn(allIn string, isAllIn, userId int) (err error) {
  43. o := orm.NewOrm()
  44. sql := `UPDATE cygx_xzs_choose_send SET ` + allIn + ` = ? WHERE user_id = ?`
  45. _, err = o.Raw(sql, isAllIn, userId).Exec()
  46. return
  47. }
  48. type CygxXzsChooseSendResp struct {
  49. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  50. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  51. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  52. IsPush int `description:"是否接受推送,1是,0否"`
  53. List []*ChartPermissionXzsResp
  54. }
  55. // 获取数量
  56. func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
  57. o := orm.NewOrm()
  58. sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? `
  59. err = o.Raw(sql, mobile).QueryRow(&count)
  60. return
  61. }
  62. // 根据用户openid获取token
  63. func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
  64. o := orm.NewOrm()
  65. sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 `
  66. err = o.Raw(sql, mobile).QueryRow(&item)
  67. return
  68. }
  69. type SubmitChooseSendFollowTypeResp struct {
  70. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  71. List []*SubmitChooseSendFollowTypeList
  72. }
  73. type SubmitChooseSendFollowTypeList struct {
  74. ChartPermissionName string `description:"权限名称"`
  75. CheckList []int `description:"所选择的ID"`
  76. }
  77. // 添加
  78. func AddCygxXzsChooseSendFollow(mobile string, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory, itemsZhouqi []*CygxXzsChooseCategoryZhouqi, industryIds, celueIds, zhouqiIds []int) (err error) {
  79. o, err := orm.NewOrm().Begin()
  80. if err != nil {
  81. return
  82. }
  83. defer func() {
  84. if err == nil {
  85. o.Commit()
  86. } else {
  87. o.Rollback()
  88. }
  89. }()
  90. var sql string
  91. if len(industryIds) > 0 {
  92. //删除原有的关注记录
  93. sql = `DELETE FROM cygx_industry_fllow WHERE mobile = ? AND industrial_management_id IN (` + utils.GetOrmInReplace(len(industryIds)) + `)`
  94. _, err = o.Raw(sql, mobile, industryIds).Exec()
  95. if err != nil {
  96. return err
  97. }
  98. }
  99. if len(itemsFllow) > 0 {
  100. //批量添加新的关注记录
  101. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  102. if err != nil {
  103. return err
  104. }
  105. }
  106. if len(celueIds) > 0 {
  107. //删除原有策略报告的关注记录
  108. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(celueIds)) + `) `
  109. _, err = o.Raw(sql, mobile, celueIds).Exec()
  110. if err != nil {
  111. return err
  112. }
  113. }
  114. if len(itemsCategory) > 0 {
  115. //批量添加新的关注记录
  116. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  117. if err != nil {
  118. return err
  119. }
  120. }
  121. if len(zhouqiIds) > 0 {
  122. //删除原有周期的关注记录
  123. sql = `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(zhouqiIds)) + `) `
  124. _, err = o.Raw(sql, mobile, zhouqiIds).Exec()
  125. if err != nil {
  126. return err
  127. }
  128. }
  129. if len(itemsZhouqi) > 0 {
  130. //批量添加新的关注记录
  131. _, err = o.InsertMulti(len(itemsZhouqi), itemsZhouqi)
  132. if err != nil {
  133. return err
  134. }
  135. }
  136. return
  137. }
  138. type SubmitChooseSendResp struct {
  139. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  140. IsPush int `description:"是否接受推送,1是,0否"`
  141. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  142. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  143. IndustrialManagementIds []*IndustrialManagementIdResp
  144. }
  145. type IndustrialManagementIdResp struct {
  146. IndustrialManagementIds string `description:"产业ID 多个用 ,隔开"`
  147. ChartPermissionId int `description:"权限id"`
  148. }
  149. // 添加
  150. func AddCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
  151. o := orm.NewOrm()
  152. //添加所勾选的消息类型
  153. _, err = o.Insert(item)
  154. return
  155. }
  156. // 修改
  157. func UpdateCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
  158. o := orm.NewOrm()
  159. //修改现有的类型
  160. updateParams := make(map[string]interface{})
  161. updateParams["UserId"] = item.UserId
  162. updateParams["Mobile"] = item.Mobile
  163. updateParams["Email"] = item.Email
  164. updateParams["CompanyId"] = item.CompanyId
  165. updateParams["CompanyName"] = item.CompanyName
  166. updateParams["RealName"] = item.RealName
  167. updateParams["ModifyTime"] = time.Now()
  168. updateParams["IsRefuse"] = item.IsRefuse
  169. updateParams["IsSubjective"] = item.IsSubjective
  170. updateParams["IsObjective"] = item.IsObjective
  171. ptrStructOrTableName := "cygx_xzs_choose_send"
  172. whereParam := map[string]interface{}{"mobile": item.Mobile}
  173. qs := o.QueryTable(ptrStructOrTableName)
  174. for expr, exprV := range whereParam {
  175. qs = qs.Filter(expr, exprV)
  176. }
  177. _, err = qs.Update(updateParams)
  178. return
  179. }