xzs_choose_send.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxXzsChooseSend struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int `description:"用户ID"`
  9. Mobile string `description:"手机号"`
  10. Email string `description:"邮箱"`
  11. CompanyId int `description:"公司id"`
  12. CompanyName string `description:"公司名称"`
  13. RealName string `description:"用户实际名称"`
  14. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  15. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  16. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"更新时间"`
  19. AllInYiYao int `description:"是否选择医药全部赛道"`
  20. AllInXiaoFei int `description:"是否选择消费全部赛道"`
  21. AllInKeJi int `description:"是否选择科技全部赛道"`
  22. AllInZhiZao int `description:"是否选择智造全部赛道"`
  23. AllInCeLue int `description:"是否选择策略全部赛道"`
  24. AllInYanXuan int `description:"是否选择研选全部赛道"`
  25. }
  26. type CygxXzsChooseSendResp struct {
  27. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  28. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  29. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  30. List []*ChartPermissionResp
  31. }
  32. type SubmitChooseSendResp struct {
  33. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  34. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  35. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  36. IndustrialManagementIds []*IndustrialManagementIdResp
  37. }
  38. type IndustrialManagementIdResp struct {
  39. IndustrialManagementIds string `description:"产业ID 多个用 ,隔开"`
  40. ChartPermissionId int `description:"权限id"`
  41. }
  42. // 添加
  43. func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
  44. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  45. if err != nil {
  46. return
  47. }
  48. defer func() {
  49. if err == nil {
  50. o.Commit()
  51. } else {
  52. o.Rollback()
  53. }
  54. }()
  55. //如果用户选择不做任何推送,则之前的关注信息不做任何改动
  56. if item.IsRefuse == 0 {
  57. //删除原有的关注记录
  58. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  59. _, err = o.Raw(sql, item.Mobile).Exec()
  60. if err != nil {
  61. return err
  62. }
  63. if len(itemsFllow) > 0 {
  64. //批量添加新的关注记录
  65. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  66. if err != nil {
  67. return err
  68. }
  69. }
  70. //删除原有策略报告的关注记录
  71. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
  72. _, err = o.Raw(sql, item.Mobile).Exec()
  73. if err != nil {
  74. return err
  75. }
  76. if len(itemsCategory) > 0 {
  77. //批量添加新的关注记录
  78. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  79. if err != nil {
  80. return err
  81. }
  82. }
  83. }
  84. //添加所勾选的消息类型
  85. _, err = o.Insert(item)
  86. return
  87. }
  88. // 获取数量
  89. func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
  90. sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? `
  91. o := orm.NewOrmUsingDB("hz_cygx")
  92. err = o.Raw(sql, mobile).QueryRow(&count)
  93. return
  94. }
  95. // 添加
  96. func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
  97. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  98. if err != nil {
  99. return
  100. }
  101. defer func() {
  102. if err == nil {
  103. o.Commit()
  104. } else {
  105. o.Rollback()
  106. }
  107. }()
  108. //如果用户选择不做任何推送,则之前的关注信息不做任何改动
  109. if item.IsRefuse == 0 {
  110. //删除原有的关注记录
  111. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  112. _, err = o.Raw(sql, item.Mobile).Exec()
  113. if err != nil {
  114. return err
  115. }
  116. if len(itemsFllow) > 0 {
  117. //批量添加新的关注记录
  118. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  119. if err != nil {
  120. return err
  121. }
  122. }
  123. //删除原有策略报告的关注记录
  124. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
  125. _, err = o.Raw(sql, item.Mobile).Exec()
  126. if err != nil {
  127. return err
  128. }
  129. if len(itemsCategory) > 0 {
  130. //批量添加新的关注记录
  131. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  132. if err != nil {
  133. return err
  134. }
  135. }
  136. }
  137. //修改现有的类型
  138. updateParams := make(map[string]interface{})
  139. updateParams["UserId"] = item.UserId
  140. updateParams["Mobile"] = item.Mobile
  141. updateParams["Email"] = item.Email
  142. updateParams["CompanyId"] = item.CompanyId
  143. updateParams["CompanyName"] = item.CompanyName
  144. updateParams["RealName"] = item.RealName
  145. updateParams["ModifyTime"] = time.Now()
  146. updateParams["IsRefuse"] = item.IsRefuse
  147. updateParams["IsSubjective"] = item.IsSubjective
  148. updateParams["IsObjective"] = item.IsObjective
  149. updateParams["AllInYiYao"] = item.AllInYiYao
  150. updateParams["AllInXiaoFei"] = item.AllInXiaoFei
  151. updateParams["AllInKeJi"] = item.AllInKeJi
  152. updateParams["AllInZhiZao"] = item.AllInZhiZao
  153. updateParams["AllInCeLue"] = item.AllInCeLue
  154. updateParams["AllInYanXuan"] = item.AllInYanXuan
  155. whereParam := map[string]interface{}{"mobile": item.Mobile}
  156. err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
  157. return
  158. }
  159. // 根据用户openid获取token
  160. func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
  161. sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 `
  162. o := orm.NewOrmUsingDB("hz_cygx")
  163. err = o.Raw(sql, mobile).QueryRow(&item)
  164. return
  165. }
  166. type XzsChooseMapResp struct {
  167. Id int `description:"id"`
  168. CategoryId int `description:"权益文章对应分类,cygx_article"`
  169. CharPpermissionName string `description:"权限名称"`
  170. MatchTypeName string `description:"分类名称"`
  171. }
  172. // 根据手机号获取用户关注的产业
  173. func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
  174. o := orm.NewOrmUsingDB("hz_cygx")
  175. sql := `SELECT
  176. r.id,
  177. r.chart_permission_name,
  178. r.match_type_name,
  179. c.category_id
  180. FROM
  181. cygx_report_mapping_cygx AS r
  182. INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
  183. INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
  184. WHERE
  185. r.chart_permission_id IN (23,100000)`
  186. _, err = o.Raw(sql).QueryRows(&items)
  187. return
  188. }