123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- package cygx
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/utils"
- "strconv"
- )
- // 用户互动总数统计
- //func GetUserInteractionTableCountByCompany(companyId int) (item *GetUserInteractionTableCountResp, err error) {
- // o := orm.NewOrm()
- // sql := `SELECT
- // ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.company_id = u.company_id AND h.is_del = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
- // ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
- // ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h INNER JOIN cygx_chart AS a ON h.chart_id = a.chart_id WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
- // ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
- // ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
- // ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = u.company_id AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
- // ( SELECT COUNT(1 ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id INNER JOIN wx_user as wu ON wu.user_id = h.user_id WHERE h.company_id = u.company_id
- // AND t.activity_type=1 AND h.do_fail_type = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
- // ( SELECT COUNT( 1 ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id INNER JOIN wx_user as wu ON wu.user_id = h.user_id WHERE h.company_id = u.company_id
- // AND t.activity_type = 0 AND h.do_fail_type = 0 AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
- // FROM
- // company as u
- // WHERE
- // u.company_id = ?`
- // err = o.Raw(sql, companyId).QueryRow(&item)
- // return
- //}
- // 获取阅读记录数量
- //func GetCygxArticleHistoryCountByCompany(condition string) (count int, err error) {
- // o := orm.NewOrm()
- // sqlCount := ` SELECT COUNT( 1 ) AS count
- //FROM
- // (
- // SELECT
- // COUNT( 1 )
- // FROM
- // cygx_article_history_record_all AS r
- // INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- // INNER JOIN company_product AS cp ON cp.company_id = r.company_id
- // AND cp.product_id = 2
- // INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- // INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- // LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two WHERE r.is_del = 0`
- // if condition != "" {
- // sqlCount += condition
- // }
- // sqlCount += ` GROUP BY r.id ) AS count `
- // err = o.Raw(sqlCount).QueryRow(&count)
- // return
- //}
- // 阅读记录列表
- func GetCygxArticleHistoryRecordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- art.category_name,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.user_id,
- r.real_name,
- r.source as source_platform,
- r.stop_time
- FROM
- cygx_article_history_record_all AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 AND r.is_del = 0 ` + condition + ` GROUP BY r.id ORDER BY ui.article_history_num DESC , r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取用户参会记录数量
- func GetActivityMeetByCompanyCount(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := `SELECT
- COUNT(*) AS count
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0`
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 获取用户参会记录数量(关联用户跟销售的绑定关系跨库查询)
- func GetActivityMeetByCompanyCountWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := `SELECT
- COUNT(*) AS count
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1 = 1
- AND r.do_fail_type = 0`
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 获取用户参会记录
- func GetActivityMeetByCompany(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0
- ` + condition + `
- GROUP BY
- r.id
- ORDER BY
- a.activity_time DESC ,r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 获取用户参会记录(关联用户跟销售的绑定关系跨库查询)
- func GetActivityMeetByCompanyWeekly(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.company_name,
- r.company_id,
- r.real_name,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE
- 1 = 1 AND r.do_fail_type = 0 `
- sql = fmt.Sprintf(sql, databaseName)
- sql += condition + ` GROUP BY r.id ORDER BY a.activity_time DESC ,r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 收藏列表数量
- func GetCygxArticleCollectCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- WHERE 1=1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 收藏列表数量(关联用户跟销售的绑定关系跨库查询)
- func GetCygxArticleCollectCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 收藏列表
- func GetCygxArticleCollectByCompany(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 ` + condition + ` GROUP BY r.id
- ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 收藏列表(关联用户跟销售的绑定关系跨库查询)
- func GetCygxArticleCollectByCompanyWeekly(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := ` SELECT
- art.title,
- art.article_id,
- art.report_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- r.company_name,
- r.company_id,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 `
- sql = fmt.Sprintf(sql, databaseName)
- sql += condition + ` GROUP BY r.id ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 关注产业数量
- func GetCygxIndustryFllowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id WHERE type = 1 AND r.source IN (0,1,2) ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注产业数量(关联用户跟销售的绑定关系跨库查询)
- func GetCygxIndustryFllowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2 WHERE type = 1 AND r.source IN (0,1,2) `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.modify_time as create_time,
- ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.id DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.company_name,
- r.company_id,
- r.modify_time as create_time,
- ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE type = 1 AND r.source IN (0,1,2) `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.id DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者数量
- func GetCygArticleDepartmentFollowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id WHERE type = 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注作者数量
- func GetCygArticleDepartmentFollowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE type = 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 关注作者列表
- func GetCygArticleDepartmentFollowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- m.department_id,
- a.title,
- a.article_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- WHERE r.type = 1 ` + condition + ` GROUP BY r.id
- ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者列表
- func GetCygArticleDepartmentFollowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- m.department_id,
- a.title,
- a.article_id,
- r.company_name,
- r.company_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE r.type = 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY r.id ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountBuCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r WHERE 1= 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountBuCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word as r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- r.key_word,
- r.create_time,
- r.mobile,
- r.real_name
- FROM
- cygx_search_key_word as r
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- r.key_word,
- r.create_time,
- r.mobile,
- r.company_name,
- r.company_id,
- r.real_name
- FROM
- cygx_search_key_word as r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户专项产业调研统计
- func GetCygxActivitySpecialTripCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- COUNT( 1 )
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- WHERE
- 1 = 1
- AND a.publish_status = 1 ` + condition
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户专项产业调研统计
- func GetCygxActivitySpecialTripCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := ` SELECT
- COUNT( 1 )
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE
- 1 = 1
- AND a.publish_status = 1 `
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户专项产业调研列表
- func CygxActivitySpecialTripByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.activity_id,
- r.real_name,
- r.is_meeting
- FROM
- cygx_activity_special_meeting_detail AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- WHERE 1= 1 AND a.publish_status = 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户专项产业调研列表
- func CygxActivitySpecialTripByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.activity_id,
- r.real_name,
- r.company_name,
- r.seller_name,
- r.company_id,
- r.is_meeting
- FROM
- cygx_activity_special_trip AS r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1= 1 AND a.publish_status = 1 `
- sql = fmt.Sprintf(sql, databaseName)
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览统计
- func GetCygxRoadshowCountByCompany(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := `SELECT
- COUNT( 1 ) total
- FROM
- (
- SELECT
- ""
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- WHERE 1=1 ` + condition + `)z `
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户音视频浏览统计
- func GetCygxRoadshowCountByCompanyWeekly(condition string) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sqlCount := `SELECT
- COUNT( 1 ) total
- FROM
- (
- SELECT
- ""
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- ""
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + `)z `
- err = o.Raw(sqlCount).QueryRow(&count)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompany(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompanyWeekly(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- databaseName := utils.GetWeeklyDatabase()
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- INNER JOIN ` + databaseName + `.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户音视频浏览列表
- func GetCygxRoadshowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "逻辑解析" AS file_type
- FROM
- cygx_micro_roadshow_video_history AS r
- INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.video_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "路演回放" AS file_type
- FROM
- cygx_activity_video_history AS r
- INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + ` UNION ALL
- SELECT
- v.voice_name AS media_title,
- r.create_time,
- r.real_name,
- r.mobile,
- r.company_name,
- r.company_id,
- ci.roadshow_num,
- ui.roadshow_num AS ui_roadshow_num,
- "路演回放" AS file_type
- FROM
- cygx_activity_voice_history AS r
- INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1=1 ` + condition + `
- ORDER BY create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 根据时间获取机构互动总数统计
- func GetCompanyInteractionTableCountBytime(companyId int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.company_id = ? AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
- ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
- ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
- ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = ? AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
- ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = ? AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
- ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = ? AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
- ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.company_id = ?
- AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
- ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.company_id = ?
- AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
- FROM
- dual `
- err = o.Raw(sql, companyId, companyId, companyId, companyId, companyId, companyId, companyId, companyId).QueryRow(&item)
- return
- }
- // 根据时间获取机构互动总数统计
- func GetCompanyInteractionTableCountBytimeold(companyId int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.company_id = u.company_id AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS history_num,
- ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS count_num,
- ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS chart_num,
- ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS industry_fllow_num,
- ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.company_id = u.company_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS department_follow_num,
- ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.company_id = u.company_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS key_word_num,
- ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.company_id = u.company_id
- AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS on_line_num,
- ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.company_id = u.company_id
- AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' AND h.create_time < date_format(now(),'%Y-%m-%d') ) AS office_num
- FROM
- company as u
- WHERE
- u.company_id = ?`
- err = o.Raw(sql, companyId).QueryRow(&item)
- return
- }
- // 机构阅读记录列表
- func GetCygxArticleHistoryRecordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.article_id_md5,
- art.publish_date,
- art.category_name,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.user_id,
- r.company_name,
- r.company_id,
- r.real_name,
- r.stop_time,
- r.source as source_platform,
- ui.article_history_num
- FROM
- cygx_article_history_record_all AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- INNER JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- INNER JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- WHERE
- 1=1 AND r.is_del = 0 ` + condition + ` GROUP BY r.id ORDER BY ci.article_history_num DESC ,ui.article_history_num DESC , r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取机构参会记录
- func GetActivityMeetByCompanyList(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- t.activity_type,
- r.signup_type,
- r.is_meeting,
- r.mobile,
- r.real_name,
- a.activity_name,
- a.chart_permission_name,
- a.activity_type_name,
- a.label,
- a.activity_time,
- r.first_meeting_time,
- r.last_meeting_time,
- r.meeting_type_str,
- r.meeting_authentication,
- r.meeting_status_str,
- r.company_name,
- r.company_id,
- r.real_name,
- r.duration
- FROM
- cygx_activity_signup_detail AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0
- ` + condition + `
- GROUP BY
- r.id
- ORDER BY
- a.activity_time DESC,
- r.id DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&item)
- return
- }
- // 机构收藏列表
- func GetCygxArticleCollectByCompanyList(startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT
- art.title,
- art.article_id,
- art.report_id,
- art.article_id_md5,
- art.publish_date,
- re.chart_permission_name,
- re.chart_permission_id,
- r.create_time,
- r.mobile,
- r.real_name,
- re.match_type_name,
- r.company_name,
- r.company_id,
- (
- SELECT
- GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
- FROM
- cygx_industrial_subject AS s
- WHERE
- s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
- ) AS subject_name_str,
- (
- SELECT
- GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
- FROM
- cygx_industrial_management AS man
- WHERE
- man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
- ) AS industry_name
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
- LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
- WHERE
- 1=1 ` + condition + ` GROUP BY r.id
- ORDER BY r.create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 关注产业列表
- func GetCygxIndustryFllowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.industry_name,
- r.mobile,
- r.real_name,
- r.modify_time as create_time,
- r.company_name,
- r.company_id,
- ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id ) AS subject_name_str
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num as ui ON ui.user_id = r.user_id
-
- WHERE type = 1 AND r.source IN (0,1,2) ` + condition + ` ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 关注作者机构列表
- func GetCygArticleDepartmentFollowByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- m.department_id,
- m.nick_name,
- r.modify_time as create_time,
- r.mobile,
- r.real_name,
- r.company_name,
- r.company_id,
- m.department_id,
- i.industry_name,
- a.title,
- a.article_id,
- ( SELECT MAX( create_time ) FROM cygx_article_department_follow WHERE user_id = r.user_id ) AS max_time,
- ( SELECT GROUP_CONCAT( DISTINCT i.industry_name SEPARATOR '/' ) FROM cygx_industrial_management AS i WHERE i.industrial_management_id = mg.industrial_management_id ) AS industry_name,
- ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = i.industrial_management_id ) AS subject_name_str
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- INNER JOIN cygx_article AS a ON a.department_id = m.department_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
- LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
- WHERE r.type = 1 ` + condition + ` GROUP BY r.id
- ORDER BY max_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxSearchKeyWordByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- r.key_word,r.create_time,
- r.mobile,
- r.company_name,
- r.company_id,
- r.real_name
- FROM
- cygx_search_key_word as r
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // 用户搜索关键词列表
- func GetCygxActivitySpecialTripByCompanyList(condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- a.research_theme AS activity_name,
- a.chart_permission_name,
- a.activity_time_text_by_day AS activity_time_text,
- a.city,
- a.special_type AS activity_type,
- r.mobile,
- r.real_name,
- r.is_meeting,
- r.activity_id,
- r.company_name,
- r.seller_name,
- r.real_name
- FROM
- cygx_activity_special_trip as r
- INNER JOIN cygx_activity_special AS a ON a.activity_id = r.activity_id
- LEFT JOIN cygx_company_interaction_num AS ci ON ci.company_id = r.company_id
- LEFT JOIN cygx_user_interaction_num AS ui ON ui.user_id = r.user_id
- WHERE 1= 1 ` + condition + `
- ORDER BY r.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- type CompanyAndCount struct {
- CompanyId int
- Count int
- }
- // 获取用户参会记录数量根据公司分组
- func GetActivityMeetGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,COUNT(*) AS count
- FROM
- cygx_activity_signup AS r
- INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
- INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
- WHERE
- 1 = 1
- AND r.do_fail_type = 0 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 收藏列表数量根据公司分组
- func GetCygxArticleCollectCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_article_collect AS r
- INNER JOIN cygx_article AS art ON art.article_id = r.article_id
- WHERE
- 1 = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 关注产业数量根据公司分组
- func GetCygxIndustryFllowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_industry_fllow AS r
- INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = r.industrial_management_id
- WHERE
- type = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 关注作者数量根据公司分组
- func GetCygArticleDepartmentFollowCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_article_department_follow AS r
- INNER JOIN cygx_article_department AS m ON m.department_id = r.department_id
- WHERE
- type = 1 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 用户搜索关键词统计
- func GetCygxSearchKeyWordCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_search_key_word AS r
- WHERE
- 1 = 1 ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- func GetChartCountGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,
- COUNT(*) AS count
- FROM
- cygx_chart_collect AS r
- INNER JOIN cygx_chart_all AS a ON a.chart_id = r.chart_id
- WHERE
- 1 = 1 ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- func GetCompanyCountGroupBySeller(condition string) (list []*company.CompanyReportRecordGroup, err error) {
- o := orm.NewOrm()
- sqlCount := ` SELECT
- seller_id AS admin_id,
- count(
- DISTINCT ( company_id )) num,
- GROUP_CONCAT( DISTINCT company_id SEPARATOR ',' ) AS company_ids
- FROM company_product
- WHERE 1=1 AND status="试用" ` + condition
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY seller_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
- // 获取文章阅读记录根据公司分组
- func GetArticleHistoryGroupByCompany(condition string) (list []*CompanyAndCount, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT
- r.company_id,COUNT(*) AS count
- FROM
- cygx_article_history_record_all AS r
-
- WHERE
- 1 = 1
- AND r.is_del = 0
- AND r.company_id >0 `
- if condition != "" {
- sqlCount += condition
- }
- sqlCount += ` GROUP BY r.company_id `
- _, err = o.Raw(sqlCount).QueryRows(&list)
- return
- }
|