xzs_choose_send.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygxzs/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. type CygxXzsChooseSendResp struct {
  28. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  29. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  30. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  31. IsPush int `description:"是否接受推送,1是,0否"`
  32. List []*ChartPermissionResp
  33. }
  34. type SubmitChooseSendResp struct {
  35. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  36. IsPush int `description:"是否接受推送,1是,0否"`
  37. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  38. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  39. IndustrialManagementIds []*IndustrialManagementIdResp
  40. }
  41. type SubmitChooseSendFollowTypeResp struct {
  42. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  43. List []*SubmitChooseSendFollowTypeList
  44. }
  45. type SubmitChooseSendFollowTypeList struct {
  46. ChartPermissionName string `description:"权限名称"`
  47. CheckList []int `description:"所选择的ID"`
  48. }
  49. type IndustrialManagementIdResp struct {
  50. IndustrialManagementIds string `description:"产业ID 多个用 ,隔开"`
  51. ChartPermissionId int `description:"权限id"`
  52. }
  53. // 添加
  54. func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
  55. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  56. if err != nil {
  57. return
  58. }
  59. defer func() {
  60. if err == nil {
  61. o.Commit()
  62. } else {
  63. o.Rollback()
  64. }
  65. }()
  66. //如果用户选择不做任何推送,则之前的关注信息不做任何改动
  67. if item.IsRefuse == 0 {
  68. //删除原有的关注记录
  69. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  70. _, err = o.Raw(sql, item.Mobile).Exec()
  71. if err != nil {
  72. return err
  73. }
  74. if len(itemsFllow) > 0 {
  75. //批量添加新的关注记录
  76. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  77. if err != nil {
  78. return err
  79. }
  80. }
  81. //删除原有策略报告的关注记录
  82. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
  83. _, err = o.Raw(sql, item.Mobile).Exec()
  84. if err != nil {
  85. return err
  86. }
  87. if len(itemsCategory) > 0 {
  88. //批量添加新的关注记录
  89. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  90. if err != nil {
  91. return err
  92. }
  93. }
  94. }
  95. //添加所勾选的消息类型
  96. _, err = o.Insert(item)
  97. return
  98. }
  99. // 获取数量
  100. func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
  101. sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? `
  102. o := orm.NewOrmUsingDB("hz_cygx")
  103. err = o.Raw(sql, mobile).QueryRow(&count)
  104. return
  105. }
  106. // 添加
  107. func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
  108. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  109. if err != nil {
  110. return
  111. }
  112. defer func() {
  113. if err == nil {
  114. o.Commit()
  115. } else {
  116. o.Rollback()
  117. }
  118. }()
  119. //如果用户选择不做任何推送,则之前的关注信息不做任何改动
  120. if item.IsRefuse == 0 {
  121. //删除原有的关注记录
  122. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  123. _, err = o.Raw(sql, item.Mobile).Exec()
  124. if err != nil {
  125. return err
  126. }
  127. if len(itemsFllow) > 0 {
  128. //批量添加新的关注记录
  129. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  130. if err != nil {
  131. return err
  132. }
  133. }
  134. //删除原有策略报告的关注记录
  135. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
  136. _, err = o.Raw(sql, item.Mobile).Exec()
  137. if err != nil {
  138. return err
  139. }
  140. if len(itemsCategory) > 0 {
  141. //批量添加新的关注记录
  142. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  143. if err != nil {
  144. return err
  145. }
  146. }
  147. }
  148. //修改现有的类型
  149. updateParams := make(map[string]interface{})
  150. updateParams["UserId"] = item.UserId
  151. updateParams["Mobile"] = item.Mobile
  152. updateParams["Email"] = item.Email
  153. updateParams["CompanyId"] = item.CompanyId
  154. updateParams["CompanyName"] = item.CompanyName
  155. updateParams["RealName"] = item.RealName
  156. updateParams["ModifyTime"] = time.Now()
  157. updateParams["IsRefuse"] = item.IsRefuse
  158. updateParams["IsSubjective"] = item.IsSubjective
  159. updateParams["IsObjective"] = item.IsObjective
  160. updateParams["AllInYiYao"] = item.AllInYiYao
  161. updateParams["AllInXiaoFei"] = item.AllInXiaoFei
  162. updateParams["AllInKeJi"] = item.AllInKeJi
  163. updateParams["AllInZhiZao"] = item.AllInZhiZao
  164. updateParams["AllInCeLue"] = item.AllInCeLue
  165. updateParams["AllInYanXuan"] = item.AllInYanXuan
  166. whereParam := map[string]interface{}{"mobile": item.Mobile}
  167. err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
  168. return
  169. }
  170. // 根据用户openid获取token
  171. func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
  172. sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 `
  173. o := orm.NewOrmUsingDB("hz_cygx")
  174. err = o.Raw(sql, mobile).QueryRow(&item)
  175. return
  176. }
  177. type XzsChooseMapResp struct {
  178. Id int `description:"id"`
  179. CategoryId int `description:"权益文章对应分类,cygx_article"`
  180. CharPpermissionName string `description:"权限名称"`
  181. MatchTypeName string `description:"分类名称"`
  182. }
  183. // 根据手机号获取用户关注的产业
  184. func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
  185. o := orm.NewOrmUsingDB("hz_cygx")
  186. sql := `SELECT
  187. r.id,
  188. r.chart_permission_name,
  189. r.match_type_name,
  190. c.category_id
  191. FROM
  192. cygx_report_mapping_cygx AS r
  193. INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
  194. INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
  195. WHERE
  196. r.chart_permission_id IN (23,100000)`
  197. _, err = o.Raw(sql).QueryRows(&items)
  198. return
  199. }
  200. // 添加
  201. func AddCygxXzsChooseSendFollow(mobile string, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory, itemsZhouqi []*CygxXzsChooseCategoryZhouqi, industryIds, celueIds, zhouqiIds []int) (err error) {
  202. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  203. if err != nil {
  204. return
  205. }
  206. defer func() {
  207. if err == nil {
  208. o.Commit()
  209. } else {
  210. o.Rollback()
  211. }
  212. }()
  213. var sql string
  214. if len(industryIds) > 0 {
  215. //删除原有的关注记录
  216. sql = `DELETE FROM cygx_industry_fllow WHERE mobile = ? AND industrial_management_id IN (` + utils.GetOrmInReplace(len(industryIds)) + `)`
  217. _, err = o.Raw(sql, mobile, industryIds).Exec()
  218. if err != nil {
  219. return err
  220. }
  221. }
  222. if len(itemsFllow) > 0 {
  223. //批量添加新的关注记录
  224. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  225. if err != nil {
  226. return err
  227. }
  228. }
  229. if len(celueIds) > 0 {
  230. //删除原有策略报告的关注记录
  231. sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(celueIds)) + `) `
  232. _, err = o.Raw(sql, mobile, celueIds).Exec()
  233. if err != nil {
  234. return err
  235. }
  236. }
  237. if len(itemsCategory) > 0 {
  238. //批量添加新的关注记录
  239. _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
  240. if err != nil {
  241. return err
  242. }
  243. }
  244. if len(zhouqiIds) > 0 {
  245. //删除原有周期的关注记录
  246. sql = `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(zhouqiIds)) + `) `
  247. _, err = o.Raw(sql, mobile, zhouqiIds).Exec()
  248. if err != nil {
  249. return err
  250. }
  251. }
  252. if len(itemsZhouqi) > 0 {
  253. //批量添加新的关注记录
  254. _, err = o.InsertMulti(len(itemsZhouqi), itemsZhouqi)
  255. if err != nil {
  256. return err
  257. }
  258. }
  259. return
  260. }
  261. // 添加
  262. func AddCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
  263. o := orm.NewOrmUsingDB("hz_cygx")
  264. //添加所勾选的消息类型
  265. _, err = o.Insert(item)
  266. return
  267. }
  268. // 修改
  269. func UpdateCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
  270. o := orm.NewOrmUsingDB("hz_cygx")
  271. //修改现有的类型
  272. updateParams := make(map[string]interface{})
  273. updateParams["UserId"] = item.UserId
  274. updateParams["Mobile"] = item.Mobile
  275. updateParams["Email"] = item.Email
  276. updateParams["CompanyId"] = item.CompanyId
  277. updateParams["CompanyName"] = item.CompanyName
  278. updateParams["RealName"] = item.RealName
  279. updateParams["ModifyTime"] = time.Now()
  280. updateParams["IsRefuse"] = item.IsRefuse
  281. updateParams["IsSubjective"] = item.IsSubjective
  282. updateParams["IsObjective"] = item.IsObjective
  283. ptrStructOrTableName := "cygx_xzs_choose_send"
  284. whereParam := map[string]interface{}{"mobile": item.Mobile}
  285. qs := o.QueryTable(ptrStructOrTableName)
  286. for expr, exprV := range whereParam {
  287. qs = qs.Filter(expr, exprV)
  288. }
  289. _, err = qs.Update(updateParams)
  290. return
  291. }