industrial_management.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type IndustrialManagementAdd struct {
  8. IndustryName string `description:"产业名称"`
  9. PermissionName string `description:"行业名称"`
  10. ChartPermissionId int `description:"权限id"`
  11. RecommendedIndex int `description:"推荐指数"`
  12. LayoutTime string `description:"布局时间"`
  13. IsNewLabel int `description:"是否属于新标签,1是,0否"`
  14. Source int `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
  15. }
  16. type IndustrialManagementDelte struct {
  17. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  18. }
  19. type NewId struct {
  20. NewId string `description:"新增一条数据产生的新的ID"`
  21. ChartPermissionId int `description:"行业ID"`
  22. }
  23. type CygxIndustrialManagement struct {
  24. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  25. IndustryName string `description:"产业名称"`
  26. ChartPermissionId int `description:"权限id"`
  27. RecommendedIndex int `description:"推荐指数"`
  28. CreateTime time.Time `description:"创建时间"`
  29. LayoutTime string `description:"布局时间"`
  30. IsNewLabel int `description:"是否属于新标签,1是,0否"`
  31. IsHandNewLabel int `description:"是否手动修改新标签,1是,0否"`
  32. IsDeepLabel int `description:"是否属于深度标签,1是,0否"`
  33. IsHandDeepLabel int `description:"是否手动修改深度标签,1是,0否"`
  34. Source int `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
  35. NewArtPublishDate string `description:"关联的最新文章发布时间,排序使用"`
  36. }
  37. type CygxIndustrialManagementEdit struct {
  38. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  39. IndustryName string `description:"产业名称"`
  40. ChartPermissionId int `description:"权限id"`
  41. RecommendedIndex int `description:"推荐指数"`
  42. CreateTime time.Time `description:"创建时间"`
  43. LayoutTime string `description:"布局时间"`
  44. IsNewLabel int `description:"是否属于新标签,1是,0否"`
  45. IsDeepLabel int `description:"是否属于深度标签,1是,0否"`
  46. }
  47. type CygxIndustrialManagementDetail struct {
  48. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  49. IndustryName string `description:"产业名称"`
  50. ChartPermissionId int `description:"权限id"`
  51. RecommendedIndex int `description:"推荐指数"`
  52. CreateTime time.Time `description:"创建时间"`
  53. LayoutTime string `description:"布局时间"`
  54. IsNewLabel int `description:"是否属于新标签,1是,0否"`
  55. IsDeepLabel int `description:"是否属于新标签,1是,0否"`
  56. }
  57. type CygxIndustrialManagementDetailRep struct {
  58. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  59. IndustryName string `description:"产业名称"`
  60. ChartPermissionId int `description:"权限id"`
  61. RecommendedIndex int `description:"推荐指数"`
  62. CreateTime time.Time `description:"创建时间"`
  63. LayoutTime string `description:"布局时间"`
  64. IsNewLabel int `description:"是否属于新标签,1是,0否"`
  65. IsDeepLabel int `description:"是否属于新标签,1是,0否"`
  66. IsShowNewLabel bool `description:"是否展示新标签"`
  67. IsShowDeepLabel bool `description:"是否展示深度标签"`
  68. }
  69. type CygxIndustrialManagementNum struct {
  70. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  71. IndustryName string `description:"产业名称"`
  72. ChartPermissionId int `description:"权限id"`
  73. RecommendedIndex int `description:"推荐指数"`
  74. CreateTime time.Time `description:"创建时间"`
  75. LayoutTime string `description:"布局时间"`
  76. ArtNum int `description:"文章数量"`
  77. ActNum int `description:"活动数量"`
  78. IsRelevance bool `description:"是否存在关联文章"`
  79. HzCover bool `description:"是否弘则覆盖"`
  80. }
  81. type CygxIndustrialManagementNumCheckName struct {
  82. ChartPermissionId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  83. PermissionName string `orm:"column(industry_name)" description:"产业名称"`
  84. RecommendedIndex int `description:"推荐指数"`
  85. CreateTime time.Time `description:"创建时间"`
  86. LayoutTime string `description:"布局时间"`
  87. ArtNum int `description:"文章数量"`
  88. IsRelevance bool `description:"是否存在关联文章"`
  89. }
  90. type GetIndustrialManagementList struct {
  91. List []*CygxIndustrialManagementNum
  92. }
  93. type GetCygxIndustrialManagementList struct {
  94. List []*ArtGroupIndustrialManagementRep
  95. }
  96. // 新增
  97. func AddIndustrialManagement(item *CygxIndustrialManagement) (newId int64, err error) {
  98. o := orm.NewOrmUsingDB("hz_cygx")
  99. newId, err = o.Insert(item)
  100. return
  101. }
  102. // 列表
  103. func GetIndustrialManagementAll(condition, orderColumn string) (items []*CygxIndustrialManagementNum, err error) {
  104. o := orm.NewOrmUsingDB("hz_cygx")
  105. sql := `SELECT *,
  106. ( SELECT COUNT( 1 ) FROM cygx_industrial_article_group_management AS man_g WHERE man_g.industrial_management_id = man.industrial_management_id ) AS art_num,
  107. ( SELECT COUNT( 1 ) FROM cygx_industrial_activity_group_management AS a_g INNER JOIN cygx_activity AS a ON a.activity_id = a_g.activity_id WHERE a_g.industrial_management_id = man.industrial_management_id AND a.publish_status = 1 ) AS act_num
  108. FROM
  109. cygx_industrial_management AS man
  110. WHERE 1 =1 `
  111. if condition != "" {
  112. sql += condition
  113. }
  114. sql += ` ORDER BY ` + orderColumn + ` ASC`
  115. _, err = o.Raw(sql).QueryRows(&items)
  116. return
  117. }
  118. // 列表
  119. func GetIndustrialManagementAllCheckName(ChartPermissionId int, orderColumn string) (items []*CygxIndustrialManagementNumCheckName, err error) {
  120. o := orm.NewOrmUsingDB("hz_cygx")
  121. sql := `SELECT *
  122. FROM
  123. cygx_industrial_management AS man
  124. WHERE
  125. man.chart_permission_id = ? ORDER BY ` + orderColumn + ` ASC`
  126. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  127. return
  128. }
  129. func GetIndustrialManagementAllByReportTime(condition, orderSrt string) (items []*CygxIndustrialManagementNum, err error) {
  130. o := orm.NewOrmUsingDB("hz_cygx")
  131. sql := `SELECT
  132. man.*,art.publish_date,man_g.industrial_management_id as man_gid,
  133. MAX( art.publish_date ) AS update_time,
  134. ( SELECT COUNT( 1 ) FROM cygx_industrial_article_group_management AS man_g WHERE man_g.industrial_management_id = man.industrial_management_id ) AS art_num ,
  135. ( SELECT COUNT( 1 ) FROM cygx_industrial_activity_group_management AS a_g INNER JOIN cygx_activity AS a ON a.activity_id = a_g.activity_id WHERE a_g.industrial_management_id = man.industrial_management_id AND a.publish_status = 1 ) AS act_num
  136. FROM
  137. cygx_industrial_management AS man
  138. LEFT JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  139. LEFT JOIN cygx_article AS art ON art.article_id = man_g.article_id
  140. WHERE 1=1 `
  141. if condition != "" {
  142. sql += condition
  143. }
  144. sql += ` GROUP BY industry_name ORDER BY ` + orderSrt
  145. //fmt.Println(sql)
  146. //ORDER BY update_time DESC`
  147. _, err = o.Raw(sql).QueryRows(&items)
  148. return
  149. }
  150. // 获取产业数量
  151. func GetIndustrialManagementCount(condition string, pars []interface{}) (count int, err error) {
  152. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_management WHERE 1=1 `
  153. if condition != "" {
  154. sqlCount += condition
  155. }
  156. o := orm.NewOrmUsingDB("hz_cygx")
  157. err = o.Raw(sqlCount, pars).QueryRow(&count)
  158. return
  159. }
  160. // 修改
  161. func EditIndustrialManagement(item *CygxIndustrialManagement) (err error) {
  162. sql := `UPDATE cygx_industrial_management SET chart_permission_id=?, industry_name=?, recommended_index=?, layout_time=?,is_new_label=?,is_deep_label=?,is_hand_new_label=?,is_hand_deep_label=? WHERE industrial_management_id=? `
  163. o := orm.NewOrmUsingDB("hz_cygx")
  164. _, err = o.Raw(sql, item.ChartPermissionId, item.IndustryName, item.RecommendedIndex, item.LayoutTime, item.IsNewLabel, item.IsDeepLabel, item.IsHandNewLabel, item.IsHandDeepLabel, item.IndustrialManagementId).Exec()
  165. return
  166. }
  167. // 通过活动添加的标签产业添加的时候二次修改
  168. func EditIndustrialManagementFromAct(item *CygxIndustrialManagement) (err error) {
  169. sql := `UPDATE cygx_industrial_management SET recommended_index=?, layout_time=?,is_new_label=?,is_deep_label=?,is_hand_new_label=?,is_hand_deep_label=?, source = 1 WHERE industry_name=? AND chart_permission_id=?`
  170. o := orm.NewOrmUsingDB("hz_cygx")
  171. _, err = o.Raw(sql, item.RecommendedIndex, item.LayoutTime, item.IsNewLabel, item.IsDeepLabel, item.IsHandNewLabel, item.IsHandDeepLabel, item.IndustryName, item.ChartPermissionId).Exec()
  172. return
  173. }
  174. // 删除数据
  175. func DeleteIndustrialManagement(industrialManagementId int) (err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. to, err := o.Begin()
  178. if err != nil {
  179. return
  180. }
  181. defer func() {
  182. if err != nil {
  183. _ = to.Rollback()
  184. } else {
  185. _ = to.Commit()
  186. }
  187. }()
  188. //删除产业
  189. sql := ` DELETE FROM cygx_industrial_management WHERE industrial_management_id = ?`
  190. _, err = to.Raw(sql, industrialManagementId).Exec()
  191. if err != nil {
  192. return
  193. }
  194. //删除产业关联的活动
  195. sql = ` DELETE FROM cygx_industrial_activity_group_management WHERE industrial_management_id = ?`
  196. _, err = to.Raw(sql, industrialManagementId).Exec()
  197. return
  198. }
  199. // 获取产业数量
  200. func GetIndustrialManagementInfo(industrialManagementId int) (item *CygxIndustrialManagement, err error) {
  201. sqlCount := ` SELECT * FROM cygx_industrial_management WHERE industrial_management_id= ? `
  202. o := orm.NewOrmUsingDB("hz_cygx")
  203. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&item)
  204. return
  205. }
  206. // 获取产业关联的文章数量
  207. func GetIndustrialManagementGroupArtCount(industrialManagementId int) (count int, err error) {
  208. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_article_group_management WHERE industrial_management_id=? `
  209. o := orm.NewOrmUsingDB("hz_cygx")
  210. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  211. return
  212. }
  213. type CygxIndustrialManagementExport struct {
  214. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  215. ChartPermissionName string `description:"行业"`
  216. IndustryName string `description:"产业名称"`
  217. RecommendedIndex int `description:"推荐指数"`
  218. SubjectName string `description:"标的名称"`
  219. AnalystName string `description:"分析师名称"`
  220. }
  221. func GetChartPermissionExport(chartPermissionId int) (items []*CygxIndustrialManagementExport, err error) {
  222. o := orm.NewOrmUsingDB("hz_cygx")
  223. sql := `SELECT
  224. mp.chart_permission_name,
  225. man.industry_name,
  226. man.industrial_management_id,
  227. man.recommended_index,
  228. sub.subject_name,
  229. ana.analyst_name
  230. FROM
  231. cygx_report_mapping AS mp
  232. LEFT JOIN cygx_industrial_management as man ON man.chart_permission_id = mp.chart_permission_id
  233. LEFT JOIN cygx_industrial_subject as sub ON sub.industrial_management_id = man.industrial_management_id
  234. LEFT JOIN cygx_industrial_analyst as ana ON ana.industrial_management_id = man.industrial_management_id
  235. WHERE mp.chart_permission_id = 20`
  236. _, err = o.Raw(sql).QueryRows(&items)
  237. return
  238. }
  239. type CygxIndustrialManagementIdStr struct {
  240. ChartPermissionId int `description:"行业ID"`
  241. ChartPermissionName string `description:"行业名称"`
  242. MatchTypeName string `description:"匹配类型"`
  243. }
  244. func GetChartPermissionIdStr() (items []*CygxIndustrialManagementIdStr, err error) {
  245. o := orm.NewOrmUsingDB("hz_cygx")
  246. sql := `SELECT * FROM cygx_report_mapping WHERE report_type = 1 AND chart_permission_id != 23 GROUP BY chart_permission_id ORDER BY sort DESC `
  247. _, err = o.Raw(sql).QueryRows(&items)
  248. return
  249. }
  250. type IndustrialManagementExport struct {
  251. ChartPermissionName string `description:"行业"`
  252. ChartPermissionReportName string `description:"行业报告数量"`
  253. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  254. IndustryName string `description:"产业名称"`
  255. ChartPermissionId int `description:"权限id"`
  256. RecommendedIndex int `description:"推荐指数"`
  257. SubjectName string `description:"标的名称"`
  258. AnalystName string `description:"分析师名称"`
  259. ReportNum string `description:"产业报告数量"`
  260. }
  261. func GetIndustrialManagementIdStr(chartPermissionId int) (items []*IndustrialManagementExport, err error) {
  262. o := orm.NewOrmUsingDB("hz_cygx")
  263. sql := `SELECT * FROM cygx_industrial_management WHERE chart_permission_id = ?`
  264. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  265. return
  266. }
  267. type GetReportNumLIstExport struct {
  268. MatchTypeName string `description:"权限id"`
  269. TypeNum int `description:"数量"`
  270. }
  271. func GetReportNumLIst(industrialManagementId int) (items []*GetReportNumLIstExport, err error) {
  272. o := orm.NewOrmUsingDB("hz_cygx")
  273. sql := `SELECT
  274. rep.match_type_name,
  275. COUNT(match_type_name) type_num
  276. FROM
  277. cygx_report_mapping AS rep
  278. LEFT JOIN cygx_article AS art ON art.category_id = rep.category_id
  279. LEFT JOIN cygx_industrial_article_group_management AS map_g ON map_g.cygx_article_id =art.id
  280. WHERE
  281. map_g.industrial_management_id = ?
  282. AND art.sub_category_name = rep.sub_category_name
  283. GROUP BY rep.match_type_name
  284. `
  285. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  286. return
  287. }
  288. type GetMatchTypeListRep struct {
  289. ChartPermissionId int `description:"行业ID"`
  290. MatchTypeName string `description:"匹配类型"`
  291. }
  292. func GetMatchTypeList(chartPermissionId int) (items []*GetMatchTypeListRep, err error) {
  293. o := orm.NewOrmUsingDB("hz_cygx")
  294. sql := `SELECT * FROM cygx_report_mapping WHERE chart_permission_id = ? GROUP BY match_type_name `
  295. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  296. return
  297. }
  298. // 获取产业关联的文章数量
  299. func GetchartPermissionReportNameCount(industrialManagementId int) (count int, err error) {
  300. sqlCount := ` SELECT COUNT(1) as count FROM cygx_article as art
  301. INNER JOIN cygx_report_mapping as re ON re.category_id = art.category_id
  302. WHERE
  303. re.report_type = 1
  304. AND re.chart_permission_id = ? `
  305. o := orm.NewOrmUsingDB("hz_cygx")
  306. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  307. return
  308. }
  309. type IndustrialManagementDetial struct {
  310. LayoutTime string `description:"布局时间"`
  311. ArtTotalNum int `description:"文章总数量"`
  312. List []*IndustrialManagementArtTypeList
  313. }
  314. // 通过产业ID获取详情
  315. func GetindustrialManagemenById(industrialManagementId int) (item *CygxIndustrialManagementNum, err error) {
  316. o := orm.NewOrmUsingDB("hz_cygx")
  317. sql := `SELECT man.layout_time, art.publish_date as create_time,
  318. ( SELECT COUNT( 1 ) FROM cygx_industrial_article_group_management AS man_g INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id WHERE man_g.industrial_management_id = man.industrial_management_id AND art.publish_status = 1 ) AS art_num
  319. FROM
  320. cygx_industrial_management AS man
  321. LEFT JOIN cygx_industrial_article_group_management as mang ON mang.industrial_management_id = man.industrial_management_id
  322. LEFT JOIN cygx_article as art ON art.article_id = mang.article_id
  323. WHERE
  324. man.industrial_management_id = ?
  325. ORDER BY art.publish_date ASC LIMIT 1`
  326. err = o.Raw(sql, industrialManagementId).QueryRow(&item)
  327. return
  328. }
  329. type IndustrialManagementArtTypeList struct {
  330. MatchTypeName string `description:"匹配类型"`
  331. ArtNum int `description:"文章数量"`
  332. }
  333. func GetIndustrialManagementArtTypeList(industrialManagementId int) (items []*IndustrialManagementArtTypeList, err error) {
  334. o := orm.NewOrmUsingDB("hz_cygx")
  335. sql := `SELECT
  336. re.match_type_name,
  337. COUNT(*) AS art_num
  338. FROM
  339. cygx_industrial_management AS man
  340. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  341. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  342. INNER JOIN cygx_report_mapping AS re ON re.category_id = art.category_id
  343. WHERE
  344. man.industrial_management_id = ? AND re.match_type_name <> '' AND re.report_type = 2 AND art.publish_status = 1
  345. GROUP BY
  346. re.match_type_name `
  347. sql += ` UNION ALL
  348. SELECT
  349. map.match_type_name,
  350. COUNT(*) AS art_num
  351. FROM
  352. cygx_industrial_management AS im
  353. INNER JOIN cygx_product_interior_industrial_group_management AS man_g ON man_g.industrial_management_id = im.industrial_management_id
  354. INNER JOIN cygx_product_interior AS art ON art.product_interior_id = man_g.product_interior_id
  355. INNER JOIN cygx_report_mapping_cygx AS map ON art.match_type_id = map.id
  356. WHERE
  357. 1 = 1
  358. AND man_g.industrial_management_id = ?
  359. GROUP BY
  360. map.match_type_name `
  361. sql += ` UNION ALL
  362. SELECT
  363. "研选报告",
  364. COUNT(*)
  365. FROM
  366. cygx_industrial_management AS man
  367. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  368. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  369. WHERE
  370. man.industrial_management_id = ? AND art.publish_status = 1 AND art.article_type_id IN (1,2,12)`
  371. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, industrialManagementId).QueryRows(&items)
  372. return
  373. }
  374. // 获取研选路演精华的数量
  375. func GetIndustrialManagementArtYxLYJH(industrialManagementId int) (total int, err error) {
  376. o := orm.NewOrmUsingDB("hz_cygx")
  377. sql := `SELECT
  378. COUNT(*) AS art_num
  379. FROM
  380. cygx_industrial_management AS man
  381. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  382. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  383. WHERE
  384. man.industrial_management_id = ?
  385. AND art.publish_status = 1
  386. AND art.article_type_id IN (13)`
  387. err = o.Raw(sql, industrialManagementId).QueryRow(&total)
  388. return
  389. }
  390. type ArtGroupIndustrialManagementRep struct {
  391. IndustryName string `description:"产业名称"`
  392. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  393. }
  394. // 获取文章关联的产业列表
  395. func GetArtGroupIndustrialManagement(reportId int) (item []*ArtGroupIndustrialManagementRep, err error) {
  396. sql := ` SELECT
  397. man.industry_name
  398. FROM
  399. cygx_industrial_article_group_management AS man_g
  400. INNER JOIN cygx_industrial_management AS man ON man.industrial_management_id = man_g.industrial_management_id
  401. WHERE
  402. man_g.cygx_article_id = ?`
  403. o := orm.NewOrmUsingDB("hz_cygx")
  404. _, err = o.Raw(sql, reportId).QueryRows(&item)
  405. return
  406. }
  407. // 通过ID获取详情
  408. func GetIndustrialManagemenDetailById(industrialManagementId int) (item *CygxIndustrialManagementDetail, err error) {
  409. o := orm.NewOrmUsingDB("hz_cygx")
  410. sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id = ? `
  411. err = o.Raw(sql, industrialManagementId).QueryRow(&item)
  412. return
  413. }
  414. // 通过名称获取详情
  415. func GetIndustrialManagemenDetailByName(industryName string) (item *CygxIndustrialManagementDetail, err error) {
  416. o := orm.NewOrmUsingDB("hz_cygx")
  417. sql := `SELECT * FROM cygx_industrial_management WHERE industry_name = ? `
  418. err = o.Raw(sql, industryName).QueryRow(&item)
  419. return
  420. }
  421. // 获取行业深度,产业关联的文章数量
  422. func GetIndustrialManagementGroupArtCountByDeep(industrialManagementId int) (count int, err error) {
  423. sqlCount := `SELECT COUNT(1) as conut FROM cygx_industrial_article_group_management AS a
  424. INNER JOIN cygx_article AS b ON b.id = a.cygx_article_id
  425. WHERE
  426. a.industrial_management_id = ?
  427. AND b.match_type_name ='行业深度' `
  428. o := orm.NewOrmUsingDB("hz_cygx")
  429. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  430. return
  431. }
  432. // 列表
  433. func GetIndustrialManagement(condition string) (items []*ArtGroupIndustrialManagementRep, err error) {
  434. o := orm.NewOrmUsingDB("hz_cygx")
  435. sql := `SELECT * FROM cygx_industrial_management as art WHERE 1= 1 `
  436. if condition != "" {
  437. sql += condition
  438. }
  439. _, err = o.Raw(sql).QueryRows(&items)
  440. return
  441. }
  442. // 通过多个产业ID获取产业名称
  443. func GetindustrialManagementNames(industrialManagementIds string) (names string, err error) {
  444. sql := ` SELECT
  445. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR '/' ) AS names
  446. FROM
  447. cygx_industrial_management AS m
  448. WHERE
  449. industrial_management_id IN ( ` + industrialManagementIds + `) `
  450. o := orm.NewOrmUsingDB("hz_cygx")
  451. err = o.Raw(sql).QueryRow(&names)
  452. return
  453. }
  454. // 通过多个产业ID获取产业名称
  455. func GetindustrialManagementNamesBySubjectName(subjectnName string, chartPermissionId int) (names string, err error) {
  456. sql := `SELECT
  457. GROUP_CONCAT( DISTINCT m.industry_name SEPARATOR ',' ) AS sellerName
  458. FROM
  459. cygx_industrial_management AS m
  460. WHERE
  461. industrial_management_id IN (
  462. SELECT
  463. industrial_management_id
  464. FROM
  465. cygx_industrial_subject
  466. WHERE
  467. subject_name = ?) AND m.chart_permission_id = ? `
  468. o := orm.NewOrmUsingDB("hz_cygx")
  469. err = o.Raw(sql, subjectnName, chartPermissionId).QueryRow(&names)
  470. return
  471. }
  472. type ReportMappingCategoryRep struct {
  473. CategoryId int `description:"文章分类id"`
  474. SubCategoryName string `description:"产业名称"`
  475. ChartPermissionName string `description:"行业名称"`
  476. }
  477. func GetPermissionMappingCategoryAll() (item []*ReportMappingCategoryRep, err error) {
  478. o := orm.NewOrmUsingDB("hz_cygx")
  479. sql := ` SELECT * FROM cygx_report_mapping GROUP BY category_id `
  480. _, err = o.Raw(sql).QueryRows(&item)
  481. return
  482. }
  483. type CompanyHistoryRecordNewPvRep struct {
  484. RealName string `description:"姓名"`
  485. Mobile string `description:"手机号"`
  486. Email string `description:"邮箱"`
  487. Title string `description:"标题"`
  488. CategoryId int `description:"文章分类id"`
  489. CreateTime string `description:"创建时间"`
  490. StopTime string `description:"阅读停留时间"`
  491. IndustryName string `description:"产业名称"`
  492. PermissionName string `description:"行业名称"`
  493. SubjectNameStr string `description:"标的名称"`
  494. PublishDate string `description:"发布时间"`
  495. }
  496. func GetCompanyHistoryRecordNewPv(mobiles, emails string) (item []*CompanyHistoryRecordNewPvRep, err error) {
  497. //var table string
  498. //table = "cygx_article_history_record_all"
  499. o := orm.NewOrmUsingDB("hz_cygx")
  500. sql := ` SELECT
  501. h.real_name,
  502. h.mobile,
  503. h.email,
  504. a.title,
  505. a.category_id,
  506. h.create_time,
  507. a.publish_date,
  508. h.stop_time,
  509. (
  510. SELECT
  511. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  512. FROM
  513. cygx_industrial_subject AS s
  514. WHERE
  515. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = a.article_id )
  516. ) AS subject_name_str,
  517. (
  518. SELECT
  519. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  520. FROM
  521. cygx_industrial_management AS man
  522. WHERE
  523. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = a.article_id )
  524. ) AS industry_name
  525. FROM
  526. cygx_article_history_record_all AS h
  527. INNER JOIN cygx_article AS a ON a.article_id = h.article_id
  528. WHERE
  529. h.mobile IN (` + mobiles + `) AND h.is_del = 0 OR( h.email IN (` + emails + `) AND h.email <>'' AND h.is_del = 0 ) ORDER BY h.create_time DESC `
  530. _, err = o.Raw(sql).QueryRows(&item)
  531. return
  532. }
  533. // 通过产业名称获取关联的ID
  534. func GetManagementIdsByName(name string) (industrialManagementIds string, err error) {
  535. sql := ` SELECT
  536. GROUP_CONCAT( DISTINCT s.industrial_management_id SEPARATOR ',' ) AS industrial_management_ids
  537. FROM
  538. cygx_industrial_management AS s
  539. WHERE
  540. industry_name =? `
  541. o := orm.NewOrmUsingDB("hz_cygx")
  542. err = o.Raw(sql, name).QueryRow(&industrialManagementIds)
  543. return
  544. }
  545. // 通过产业名称获取关联的ID(模糊查询)
  546. func GetManagementIdsByNameLike(name string) (industrialManagementIds string, err error) {
  547. sql := ` SELECT
  548. GROUP_CONCAT( DISTINCT s.industrial_management_id SEPARATOR ',' ) AS industrial_management_ids
  549. FROM
  550. cygx_industrial_management AS s
  551. WHERE
  552. industry_name LIKE '%` + name + `%'`
  553. o := orm.NewOrmUsingDB("hz_cygx")
  554. err = o.Raw(sql).QueryRow(&industrialManagementIds)
  555. return
  556. }
  557. type CygxReportMappingResp struct {
  558. CategoryId int `description:"行业分类ID"`
  559. ChartPermissionId int `description:"权限id"`
  560. ChartPermissionName string `description:"权限名称"`
  561. PermissionType int `description:"1主观,2客观"`
  562. SubCategoryName string `description:"主题"`
  563. }
  564. // 通过ID获取详情
  565. func GetCygxReportMappingRespByid(categoryId int) (item *CygxReportMappingResp, err error) {
  566. o := orm.NewOrmUsingDB("hz_cygx")
  567. sql := `SELECT * FROM cygx_report_mapping WHERE category_id = ? LIMIT 1`
  568. err = o.Raw(sql, categoryId).QueryRow(&item)
  569. return
  570. }
  571. // IndustryMove 行业移动请求体
  572. type IndustryMove struct {
  573. IndustrialManagementId int `description:"产业ID"`
  574. ChartPermissionId int `description:"权限ID"`
  575. }
  576. // Update 更新产业
  577. func (industryItem *CygxIndustrialManagement) Update(cols []string) (err error) {
  578. o := orm.NewOrmUsingDB("hz_cygx")
  579. _, err = o.Update(industryItem, cols...)
  580. return
  581. }
  582. // GetIndustryListByCondition 获取产业列表
  583. func GetIndustryListByCondition(condition string, pars []interface{}) (list []*CygxIndustrialManagement, err error) {
  584. o := orm.NewOrmUsingDB("hz_cygx")
  585. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  586. if condition != "" {
  587. sql += condition
  588. }
  589. _, err = o.Raw(sql, pars).QueryRows(&list)
  590. return
  591. }
  592. // GetIndustryListByCondition 获取产业列表
  593. func GetIndustryListByConditionByIds(industrialManagementIds []int) (list []*CygxIndustrialManagement, err error) {
  594. lenArr := len(industrialManagementIds)
  595. o := orm.NewOrmUsingDB("hz_cygx")
  596. sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  597. _, err = o.Raw(sql, industrialManagementIds).QueryRows(&list)
  598. return
  599. }
  600. // IndustriesEarliestLayoutTime 产业布局时间
  601. type IndustriesEarliestLayoutTime struct {
  602. IndustrialManagementId int `json:"industrial_management_id" description:"产业ID"`
  603. LayoutTime string `json:"layout_time" description:"布局时间"`
  604. MinArticleTime string `json:"min_article_time" description:"最早报告时间"`
  605. LayoutTime2 time.Time ` orm:"column(layout_time);"description:"布局时间"`
  606. MinArticleTime2 time.Time ` orm:"column(min_article_time);"description:"最早报告时间"`
  607. }
  608. // GetIndustriesEarliestLayoutTime 获取产业最早布局时间
  609. func GetIndustriesEarliestLayoutTime(condition string, pars []interface{}) (list []*IndustriesEarliestLayoutTime, err error) {
  610. o := orm.NewOrmUsingDB("hz_cygx")
  611. sql := `SELECT
  612. idy.industrial_management_id,
  613. idy.layout_time,
  614. MIN(art.publish_date) AS min_article_time
  615. FROM
  616. cygx_industrial_management AS idy
  617. LEFT JOIN cygx_industrial_article_group_management AS argm ON idy.industrial_management_id = argm.industrial_management_id
  618. LEFT JOIN cygx_article AS art ON argm.article_id = art.article_id
  619. WHERE
  620. 1 = 1 `
  621. if condition != "" {
  622. sql += condition
  623. }
  624. sql += ` GROUP BY idy.industrial_management_id`
  625. _, err = o.Raw(sql, pars).QueryRows(&list)
  626. return
  627. }
  628. // GetIndustriesEarliestLayoutTimeByMorningMeeting 根据晨会精华获取产业最早布局时间
  629. func GetIndustriesEarliestLayoutTimeByMorningMeeting(condition string, pars []interface{}) (list []*IndustriesEarliestLayoutTime, err error) {
  630. o := orm.NewOrmUsingDB("hz_cygx")
  631. sql := `SELECT
  632. idy.industrial_management_id,
  633. idy.layout_time,
  634. MIN( mrc.meeting_time ) AS min_article_time
  635. FROM
  636. cygx_industrial_management AS idy
  637. LEFT JOIN cygx_morning_meeting_review_chapter AS mrc ON idy.industrial_management_id = mrc.industry_id
  638. WHERE
  639. 1 = 1 `
  640. if condition != "" {
  641. sql += condition
  642. }
  643. sql += ` GROUP BY idy.industrial_management_id`
  644. _, err = o.Raw(sql, pars).QueryRows(&list)
  645. return
  646. }
  647. // UpdateIndustryLayoutTime 更新产业布局时间
  648. func UpdateIndustryLayoutTime(industryId int, layoutTime string) (err error) {
  649. sql := `UPDATE cygx_industrial_management SET layout_time = ? WHERE industrial_management_id = ? LIMIT 1`
  650. o := orm.NewOrmUsingDB("hz_cygx")
  651. _, err = o.Raw(sql, layoutTime, industryId).Exec()
  652. return
  653. }
  654. // GetYxIndustryUseHzIndustryIds 获取研选产业的报告/活动所使用到的非研选产业IDs-即弘则覆盖
  655. func GetYxIndustryUseHzIndustryIds() (ids []int, err error) {
  656. o := orm.NewOrmUsingDB("hz_cygx")
  657. sql := `SELECT DISTINCT
  658. a.industrial_management_id
  659. FROM
  660. cygx_industrial_activity_group_management AS a
  661. JOIN cygx_industrial_management AS b ON a.industrial_management_id = b.industrial_management_id
  662. JOIN cygx_activity AS c ON a.activity_id = c.activity_id
  663. WHERE
  664. b.chart_permission_id != 31 AND c.chart_permission_id = 31 AND c.publish_status = 1
  665. UNION
  666. SELECT DISTINCT
  667. a.industrial_management_id
  668. FROM
  669. cygx_industrial_article_group_management AS a
  670. JOIN cygx_industrial_management AS b ON a.industrial_management_id = b.industrial_management_id
  671. JOIN cygx_article AS c ON a.article_id = c.article_id
  672. WHERE
  673. c.article_id > 1000000 AND c.article_type_id IN (1,2,12) AND b.chart_permission_id != 31 AND c.publish_status = 1`
  674. _, err = o.Raw(sql).QueryRows(&ids)
  675. return
  676. }
  677. // GetIndustryListWithHzCover 获取产业列表-带弘则覆盖
  678. func GetIndustryListWithHzCover(condition, conditionCover, orderRule string, isCover bool, pars []interface{}) (items []*CygxIndustrialManagementNum, err error) {
  679. o := orm.NewOrmUsingDB("hz_cygx")
  680. sql := `SELECT
  681. man.*, art.publish_date,
  682. man_g.industrial_management_id AS man_gid,
  683. MAX(art.publish_date) AS update_time,
  684. (
  685. SELECT
  686. COUNT(1)
  687. FROM
  688. cygx_industrial_article_group_management AS man_g
  689. WHERE
  690. man_g.industrial_management_id = man.industrial_management_id
  691. ) AS art_num,
  692. (
  693. SELECT
  694. COUNT(1)
  695. FROM
  696. cygx_industrial_activity_group_management AS a_g
  697. INNER JOIN cygx_activity AS a ON a.activity_id = a_g.activity_id
  698. WHERE
  699. a_g.industrial_management_id = man.industrial_management_id
  700. AND a.publish_status = 1
  701. ) AS act_num,
  702. "false" AS hz_cover
  703. FROM
  704. cygx_industrial_management AS man
  705. LEFT JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  706. LEFT JOIN cygx_article AS art ON art.article_id = man_g.article_id
  707. WHERE
  708. 1 = 1 `
  709. sql += condition
  710. sql += ` GROUP BY industry_name`
  711. // 弘则覆盖
  712. if isCover {
  713. sql += ` UNION ALL
  714. SELECT
  715. man.*, art.publish_date,
  716. man_g.industrial_management_id AS man_gid,
  717. MAX(art.publish_date) AS update_time,
  718. (
  719. SELECT
  720. COUNT(1)
  721. FROM
  722. cygx_industrial_article_group_management AS man_g
  723. WHERE
  724. man_g.industrial_management_id = man.industrial_management_id
  725. ) AS art_num,
  726. (
  727. SELECT
  728. COUNT(1)
  729. FROM
  730. cygx_industrial_activity_group_management AS a_g
  731. INNER JOIN cygx_activity AS a ON a.activity_id = a_g.activity_id
  732. WHERE
  733. a_g.industrial_management_id = man.industrial_management_id
  734. AND a.publish_status = 1
  735. ) AS act_num,
  736. "true" AS hz_cover
  737. FROM
  738. cygx_industrial_management AS man
  739. LEFT JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  740. LEFT JOIN cygx_article AS art ON art.article_id = man_g.article_id
  741. WHERE
  742. 1 = 1 `
  743. sql += conditionCover
  744. sql += ` GROUP BY industry_name`
  745. }
  746. if orderRule != "" {
  747. sql += ` ORDER BY ` + orderRule
  748. }
  749. _, err = o.Raw(sql, pars).QueryRows(&items)
  750. return
  751. }
  752. type IndustrialManagement struct {
  753. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  754. UpdateTime string `description:"更新时间"`
  755. PublishDate string `description:"发布时间"`
  756. IndustryName string `description:"产业名称"`
  757. }
  758. // GetIndustrialManagementArticleNewPublishData 获取产业关联文章的最新发布时间
  759. func GetIndustrialManagementArticleNewPublishData() (items []*IndustrialManagement, err error) {
  760. o := orm.NewOrmUsingDB("hz_cygx")
  761. sql := `SELECT
  762. man.industrial_management_id,
  763. MAX( art.publish_date ) AS update_time
  764. FROM
  765. cygx_industrial_management AS man
  766. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  767. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  768. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  769. WHERE
  770. 1 = 1
  771. AND re.report_type = 2
  772. AND art.is_report = 1
  773. AND art.is_class = 1
  774. GROUP BY
  775. man.industry_name
  776. ORDER BY
  777. update_time DESC`
  778. _, err = o.Raw(sql).QueryRows(&items)
  779. return
  780. }
  781. // 时间线的更新时间
  782. func GetTimeLineReportIndustrialPublishdateList(industrialIdArr []int) (items []*IndustrialManagement, err error) {
  783. o := orm.NewOrmUsingDB("hz_cygx")
  784. sql := `SELECT
  785. mmc.industry_id AS industrial_management_id,
  786. MAX( mm.meeting_time ) AS publish_date
  787. FROM
  788. cygx_morning_meeting_review_chapter AS mmc
  789. INNER JOIN cygx_morning_meeting_reviews AS mm
  790. WHERE
  791. mm.id = mmc.meeting_id
  792. AND mm.STATUS = 1
  793. AND mmc.industry_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  794. GROUP BY industrial_management_id ORDER BY publish_date DESC `
  795. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  796. return
  797. }
  798. // UpdateIndustrialManagementArticleNewPublishData 批量修改获取产业关联文章的最新发布时间
  799. func UpdateIndustrialManagementArticleNewPublishData(items map[int]string) (err error) {
  800. o := orm.NewOrmUsingDB("hz_cygx")
  801. p, err := o.Raw("UPDATE cygx_industrial_management SET new_art_publish_date = ? WHERE industrial_management_id = ?").Prepare()
  802. if err != nil {
  803. return
  804. }
  805. defer func() {
  806. _ = p.Close() // 别忘记关闭 statement
  807. }()
  808. for k, v := range items {
  809. _, err = p.Exec(v, k)
  810. if err != nil {
  811. return
  812. }
  813. }
  814. return
  815. }
  816. // GetTopOneMonthArtReadNumIndustry 获取列表
  817. func GetTopOneMonthArtReadNumIndustryAll(condition string, pars []interface{}) (items []*IndustrialManagement, err error) {
  818. o := orm.NewOrmUsingDB("hz_cygx")
  819. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  820. if condition != `` {
  821. sql += condition
  822. }
  823. sql += ` ORDER BY article_read_num DESC `
  824. _, err = o.Raw(sql, pars).QueryRows(&items)
  825. return
  826. }