123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_cygxzs/utils"
- "time"
- )
- type CygxXzsChooseSend struct {
- Id int `orm:"column(id);pk"`
- UserId int `description:"用户ID"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- CompanyId int `description:"公司id"`
- CompanyName string `description:"公司名称"`
- RealName string `description:"用户实际名称"`
- IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
- IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
- IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"更新时间"`
- AllInYiYao int `description:"是否选择医药全部赛道"`
- AllInXiaoFei int `description:"是否选择消费全部赛道"`
- AllInKeJi int `description:"是否选择科技全部赛道"`
- AllInZhiZao int `description:"是否选择智造全部赛道"`
- AllInCeLue int `description:"是否选择策略全部赛道"`
- AllInYanXuan int `description:"是否选择研选全部赛道"`
- }
- type CygxXzsChooseSendResp struct {
- IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
- IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
- IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
- IsPush int `description:"是否接受推送,1是,0否"`
- List []*ChartPermissionResp
- }
- type SubmitChooseSendResp struct {
- IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
- IsPush int `description:"是否接受推送,1是,0否"`
- IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
- IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
- IndustrialManagementIds []*IndustrialManagementIdResp
- }
- type SubmitChooseSendFollowTypeResp struct {
- FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
- List []*SubmitChooseSendFollowTypeList
- }
- type SubmitChooseSendFollowTypeList struct {
- ChartPermissionName string `description:"权限名称"`
- CheckList []int `description:"所选择的ID"`
- }
- type IndustrialManagementIdResp struct {
- IndustrialManagementIds string `description:"产业ID 多个用 ,隔开"`
- ChartPermissionId int `description:"权限id"`
- }
- // 添加
- func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- //如果用户选择不做任何推送,则之前的关注信息不做任何改动
- if item.IsRefuse == 0 {
- //删除原有的关注记录
- sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
- _, err = o.Raw(sql, item.Mobile).Exec()
- if err != nil {
- return err
- }
- if len(itemsFllow) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
- if err != nil {
- return err
- }
- }
- //删除原有策略报告的关注记录
- sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
- _, err = o.Raw(sql, item.Mobile).Exec()
- if err != nil {
- return err
- }
- if len(itemsCategory) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
- if err != nil {
- return err
- }
- }
- }
- //添加所勾选的消息类型
- _, err = o.Insert(item)
- return
- }
- // 获取数量
- func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
- sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? `
- o := orm.NewOrmUsingDB("hz_cygx")
- err = o.Raw(sql, mobile).QueryRow(&count)
- return
- }
- // 添加
- func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- //如果用户选择不做任何推送,则之前的关注信息不做任何改动
- if item.IsRefuse == 0 {
- //删除原有的关注记录
- sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
- _, err = o.Raw(sql, item.Mobile).Exec()
- if err != nil {
- return err
- }
- if len(itemsFllow) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
- if err != nil {
- return err
- }
- }
- //删除原有策略报告的关注记录
- sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
- _, err = o.Raw(sql, item.Mobile).Exec()
- if err != nil {
- return err
- }
- if len(itemsCategory) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
- if err != nil {
- return err
- }
- }
- }
- //修改现有的类型
- updateParams := make(map[string]interface{})
- updateParams["UserId"] = item.UserId
- updateParams["Mobile"] = item.Mobile
- updateParams["Email"] = item.Email
- updateParams["CompanyId"] = item.CompanyId
- updateParams["CompanyName"] = item.CompanyName
- updateParams["RealName"] = item.RealName
- updateParams["ModifyTime"] = time.Now()
- updateParams["IsRefuse"] = item.IsRefuse
- updateParams["IsSubjective"] = item.IsSubjective
- updateParams["IsObjective"] = item.IsObjective
- updateParams["AllInYiYao"] = item.AllInYiYao
- updateParams["AllInXiaoFei"] = item.AllInXiaoFei
- updateParams["AllInKeJi"] = item.AllInKeJi
- updateParams["AllInZhiZao"] = item.AllInZhiZao
- updateParams["AllInCeLue"] = item.AllInCeLue
- updateParams["AllInYanXuan"] = item.AllInYanXuan
- whereParam := map[string]interface{}{"mobile": item.Mobile}
- err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
- return
- }
- // 根据用户openid获取token
- func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
- sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 `
- o := orm.NewOrmUsingDB("hz_cygx")
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- type XzsChooseMapResp struct {
- Id int `description:"id"`
- CategoryId int `description:"权益文章对应分类,cygx_article"`
- CharPpermissionName string `description:"权限名称"`
- MatchTypeName string `description:"分类名称"`
- }
- // 根据手机号获取用户关注的产业
- func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- r.id,
- r.chart_permission_name,
- r.match_type_name,
- c.category_id
- FROM
- cygx_report_mapping_cygx AS r
- INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
- INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
- WHERE
- r.chart_permission_id IN (23,100000)`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 添加
- func AddCygxXzsChooseSendFollow(mobile string, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory, itemsZhouqi []*CygxXzsChooseCategoryZhouqi, industryIds, celueIds, zhouqiIds []int) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- var sql string
- if len(industryIds) > 0 {
- //删除原有的关注记录
- sql = `DELETE FROM cygx_industry_fllow WHERE mobile = ? AND industrial_management_id IN (` + utils.GetOrmInReplace(len(industryIds)) + `)`
- _, err = o.Raw(sql, mobile, industryIds).Exec()
- if err != nil {
- return err
- }
- }
- if len(itemsFllow) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
- if err != nil {
- return err
- }
- }
- if len(celueIds) > 0 {
- //删除原有策略报告的关注记录
- sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(celueIds)) + `) `
- _, err = o.Raw(sql, mobile, celueIds).Exec()
- if err != nil {
- return err
- }
- }
- if len(itemsCategory) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsCategory), itemsCategory)
- if err != nil {
- return err
- }
- }
- if len(zhouqiIds) > 0 {
- //删除原有周期的关注记录
- sql = `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(zhouqiIds)) + `) `
- _, err = o.Raw(sql, mobile, zhouqiIds).Exec()
- if err != nil {
- return err
- }
- }
- if len(itemsZhouqi) > 0 {
- //批量添加新的关注记录
- _, err = o.InsertMulti(len(itemsZhouqi), itemsZhouqi)
- if err != nil {
- return err
- }
- }
- return
- }
- // 添加
- func AddCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- //添加所勾选的消息类型
- _, err = o.Insert(item)
- return
- }
- // 修改
- func UpdateCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- //修改现有的类型
- updateParams := make(map[string]interface{})
- updateParams["UserId"] = item.UserId
- updateParams["Mobile"] = item.Mobile
- updateParams["Email"] = item.Email
- updateParams["CompanyId"] = item.CompanyId
- updateParams["CompanyName"] = item.CompanyName
- updateParams["RealName"] = item.RealName
- updateParams["ModifyTime"] = time.Now()
- updateParams["IsRefuse"] = item.IsRefuse
- updateParams["IsSubjective"] = item.IsSubjective
- updateParams["IsObjective"] = item.IsObjective
- ptrStructOrTableName := "cygx_xzs_choose_send"
- whereParam := map[string]interface{}{"mobile": item.Mobile}
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range whereParam {
- qs = qs.Filter(expr, exprV)
- }
- _, err = qs.Update(updateParams)
- return
- }
|