resource_data.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models/cygx"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. "time"
  10. )
  11. //首页最新页面数据逻辑处理
  12. //activity
  13. //activityspecial
  14. //activityvideo
  15. //activityvoice
  16. //article
  17. //meetingreviewchapt
  18. //minutessummary
  19. //newchart
  20. //productinterior
  21. //reportselection
  22. //researchsummary
  23. //roadshow
  24. //func init() {
  25. // UpdateMicroRoadshowResourceData(7)
  26. //}
  27. // 更新活动
  28. func UpdateActivityResourceData(sourceId int) {
  29. var err error
  30. //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
  31. defer func() {
  32. if err != nil {
  33. fmt.Println("err:", err)
  34. go alarm_msg.SendAlarmMsg("更新活动 失败,UpdateActivityResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  35. }
  36. }()
  37. var source = utils.CYGX_OBJ_ACTIVITY
  38. var condition string
  39. var pars []interface{}
  40. condition = ` AND publish_status = 1 AND activity_id = ? `
  41. pars = append(pars, sourceId)
  42. total, e := cygx.GetActivityCount(condition, pars)
  43. if e != nil {
  44. err = errors.New("GetCygxReportSelection, Err: " + e.Error())
  45. return
  46. }
  47. //如果取消发布了就做删除处理
  48. if total == 0 {
  49. e = cygx.DeleteResourceData(sourceId, source)
  50. if e != nil {
  51. err = errors.New("DeleteResourceData, Err: " + e.Error())
  52. return
  53. }
  54. //删除 cygx_resource_data 表关联的产业ID,标的ID
  55. e = cygx.DeleteCygxResourceDataGroup(sourceId, source)
  56. if e != nil {
  57. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  58. return
  59. }
  60. } else {
  61. //判断是否存在,如果不存在就新增,存在就更新
  62. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  63. if e != nil {
  64. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  65. return
  66. }
  67. detail, e := cygx.GetAddActivityInfoById(sourceId)
  68. if e != nil {
  69. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  70. return
  71. }
  72. var resourceDataId int
  73. publishDate := detail.CreateTime // 活动创建时间作为排序时间
  74. item := new(cygx.CygxResourceData)
  75. var industrialName string
  76. var subjectName string
  77. //建立首页资源表,与产业的关系
  78. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(sourceId, 1)
  79. if e != nil && e.Error() != utils.ErrNoRow() {
  80. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId))
  81. return
  82. }
  83. for _, v := range industrialList {
  84. industrialName += v.IndustryName
  85. }
  86. //建立首页资源表,与标的 的关系
  87. subjectList, e := cygx.GetSubjectActivityGroupManagementList(sourceId, 1)
  88. if e != nil && e.Error() != utils.ErrNoRow() {
  89. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId))
  90. return
  91. }
  92. for _, v := range subjectList {
  93. subjectName += v.SubjectName
  94. }
  95. item.SourceId = sourceId
  96. item.Source = source
  97. //分析师电话会(C类)
  98. item.SearchTag = detail.ActivityTypeName
  99. item.ChartPermissionId = detail.ChartPermissionId
  100. item.PublishDate = publishDate
  101. item.SearchTitle = detail.ActivityName
  102. item.SearchContent = detail.Label + industrialName + subjectName
  103. item.SearchOrderTime = detail.ActivityTime
  104. item.CreateTime = time.Now()
  105. if totalData == 0 {
  106. newId, e := cygx.AddCygxResourceData(item)
  107. if e != nil {
  108. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  109. return
  110. }
  111. resourceDataId = int(newId)
  112. } else {
  113. e = cygx.UpdateResourceDataByItem(item)
  114. if e != nil {
  115. err = errors.New("UpdateResourceData, Err: " + e.Error())
  116. return
  117. }
  118. sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source)
  119. if e != nil {
  120. err = errors.New("UpdateResourceData, Err: " + e.Error())
  121. return
  122. }
  123. resourceDataId = sourceDetail.Id
  124. }
  125. var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement
  126. for _, v := range industrialList {
  127. var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement)
  128. industrialItem.SourceId = sourceId
  129. industrialItem.Source = source
  130. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  131. industrialItem.ResourceDataId = resourceDataId
  132. industrialItem.CreateTime = time.Now()
  133. industrialItems = append(industrialItems, industrialItem)
  134. }
  135. //建立首页资源表,与标的 的关系
  136. var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject
  137. for _, v := range subjectList {
  138. var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject)
  139. subjectItem.SourceId = sourceId
  140. subjectItem.Source = source
  141. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  142. subjectItem.ResourceDataId = resourceDataId
  143. subjectItem.CreateTime = time.Now()
  144. subjectItems = append(subjectItems, subjectItem)
  145. }
  146. //插入关联信息
  147. e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  148. if e != nil {
  149. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  150. return
  151. }
  152. }
  153. return
  154. }
  155. // 更新专项调研活动
  156. func UpdateActivitySpecialResourceData(sourceId int) {
  157. var err error
  158. defer func() {
  159. if err != nil {
  160. fmt.Println("err:", err)
  161. go alarm_msg.SendAlarmMsg("更新活动 失败,UpdateActivitySpecialResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  162. }
  163. }()
  164. var source = utils.CYGX_OBJ_ACTIVITYSPECIAL
  165. var condition string
  166. var pars []interface{}
  167. condition = ` AND publish_status = 1 AND activity_id = ? `
  168. pars = append(pars, sourceId)
  169. total, e := cygx.GetActivityCount(condition, pars)
  170. if e != nil {
  171. err = errors.New("GetCygxReportSelection, Err: " + e.Error())
  172. return
  173. }
  174. activityInfo, e := cygx.GetAddActivityInfoSpecialById(sourceId)
  175. if e != nil {
  176. err = errors.New("GetAddActivityInfoSpecialById, Err: " + e.Error())
  177. return
  178. }
  179. //如果取消发布了就做删除处理
  180. if total == 0 {
  181. e = cygx.DeleteResourceData(sourceId, source)
  182. if e != nil {
  183. err = errors.New("DeleteResourceData, Err: " + e.Error())
  184. return
  185. }
  186. //删除 cygx_resource_data 表关联的产业ID,标的ID
  187. e = cygx.DeleteCygxResourceDataGroup(sourceId, source)
  188. if e != nil {
  189. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  190. return
  191. }
  192. } else {
  193. //判断是否存在,如果不存在就新增,存在就更新
  194. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  195. if e != nil {
  196. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  197. return
  198. }
  199. var resourceDataId int
  200. publishDate := activityInfo.PublishDate
  201. item := new(cygx.CygxResourceData)
  202. item.SourceId = sourceId
  203. item.Source = source
  204. //分析师电话会(C类)
  205. item.SearchTag = ""
  206. item.PublishDate = publishDate
  207. item.ChartPermissionId = activityInfo.ChartPermissionId
  208. item.CreateTime = time.Now()
  209. item.SearchTitle = activityInfo.ResearchTheme
  210. item.SearchContent = activityInfo.Label + activityInfo.IndustrialName + activityInfo.IndustrialSubjectName
  211. if activityInfo.Days > 0 {
  212. item.SearchOrderTime = activityInfo.ActivityTime
  213. } else {
  214. item.SearchOrderTime = activityInfo.PublishDate
  215. }
  216. if totalData == 0 {
  217. newId, e := cygx.AddCygxResourceData(item)
  218. if e != nil {
  219. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  220. return
  221. }
  222. resourceDataId = int(newId)
  223. } else {
  224. e = cygx.UpdateResourceDataByItem(item)
  225. if e != nil {
  226. err = errors.New("UpdateResourceData, Err: " + e.Error())
  227. return
  228. }
  229. sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source)
  230. if e != nil {
  231. err = errors.New("UpdateResourceData, Err: " + e.Error())
  232. return
  233. }
  234. resourceDataId = sourceDetail.Id
  235. }
  236. //建立首页资源表,与产业的关系
  237. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(sourceId, 2)
  238. if e != nil && e.Error() != utils.ErrNoRow() {
  239. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(sourceId))
  240. return
  241. }
  242. var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement
  243. for _, v := range industrialList {
  244. var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement)
  245. industrialItem.SourceId = sourceId
  246. industrialItem.Source = source
  247. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  248. industrialItem.ResourceDataId = resourceDataId
  249. industrialItem.CreateTime = time.Now()
  250. industrialItems = append(industrialItems, industrialItem)
  251. }
  252. //建立首页资源表,与标的 的关系
  253. subjectList, e := cygx.GetSubjectArticleGroupManagementList(sourceId)
  254. if e != nil && e.Error() != utils.ErrNoRow() {
  255. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  256. return
  257. }
  258. var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject
  259. for _, v := range subjectList {
  260. var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject)
  261. subjectItem.SourceId = sourceId
  262. subjectItem.Source = source
  263. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  264. subjectItem.ResourceDataId = resourceDataId
  265. subjectItem.CreateTime = time.Now()
  266. subjectItems = append(subjectItems, subjectItem)
  267. }
  268. //插入关联信息
  269. e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  270. if e != nil {
  271. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  272. return
  273. }
  274. }
  275. return
  276. }
  277. // 更新文章
  278. func UpdateArticleResourceData(sourceId int) {
  279. var err error
  280. defer func() {
  281. if err != nil {
  282. fmt.Println("err:", err)
  283. go alarm_msg.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  284. }
  285. }()
  286. var source = utils.CYGX_OBJ_ARTICLE
  287. var condition string
  288. var pars []interface{}
  289. condition = ` AND publish_status = 1 AND article_id = ? `
  290. pars = append(pars, sourceId)
  291. total, e := cygx.GetCygxArticleCount(condition, pars)
  292. if e != nil {
  293. err = errors.New("GetCygxReportSelection, Err: " + err.Error())
  294. return
  295. }
  296. //如果取消发布了就做删除处理
  297. if total == 0 {
  298. e = cygx.DeleteResourceData(sourceId, source)
  299. if e != nil {
  300. err = errors.New("DeleteResourceData, Err: " + e.Error())
  301. return
  302. }
  303. //删除 cygx_resource_data 表关联的产业ID,标的ID
  304. e = cygx.DeleteCygxResourceDataGroup(sourceId, source)
  305. if e != nil {
  306. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  307. return
  308. }
  309. } else {
  310. //判断是否存在,如果不存在就新增,存在就更新
  311. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  312. if e != nil {
  313. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  314. return
  315. }
  316. detail, e := cygx.GetArticleDetailByArticleId(sourceId)
  317. if e != nil {
  318. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  319. return
  320. }
  321. var resourceDataId int
  322. //publishDate := detail.CreateDate
  323. publishDate := time.Now().Format(utils.FormatDateTime)
  324. item := new(cygx.CygxResourceData)
  325. if detail.ArticleTypeId > 0 {
  326. item.SearchTag = detail.ArticleTypeName // 研选类型名称
  327. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  328. } else {
  329. item.SearchTag = detail.MatchTypeName
  330. //获取文章分类详情
  331. detailCategory, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  332. if detailCategory != nil {
  333. item.ChartPermissionId = detailCategory.ChartPermissionId
  334. }
  335. }
  336. var industrialName string
  337. var subjectName string
  338. //建立首页资源表,与产业的关系
  339. industrialList, e := cygx.GetIndustrialArticleGroupManagementList(sourceId)
  340. if e != nil && e.Error() != utils.ErrNoRow() {
  341. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  342. return
  343. }
  344. for _, v := range industrialList {
  345. industrialName += v.IndustryName
  346. }
  347. //建立首页资源表,与标的 的关系
  348. subjectList, e := cygx.GetSubjectArticleGroupManagementList(sourceId)
  349. if e != nil && e.Error() != utils.ErrNoRow() {
  350. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  351. return
  352. }
  353. for _, v := range subjectList {
  354. subjectName += v.SubjectName
  355. }
  356. item.SourceId = sourceId
  357. item.Source = source
  358. item.PublishDate = publishDate
  359. item.CreateTime = time.Now()
  360. item.SearchTitle = detail.Title
  361. annotation, e := utils.GetHtmlContentText(detail.Annotation)
  362. if e != nil && e.Error() != utils.ErrNoRow() {
  363. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  364. return
  365. }
  366. abstract, e := utils.GetHtmlContentText(detail.Abstract)
  367. if e != nil && e.Error() != utils.ErrNoRow() {
  368. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  369. return
  370. }
  371. item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
  372. item.SearchOrderTime = detail.PublishDate
  373. if totalData == 0 {
  374. newId, e := cygx.AddCygxResourceData(item)
  375. if e != nil {
  376. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  377. return
  378. }
  379. resourceDataId = int(newId)
  380. } else {
  381. e = cygx.UpdateResourceDataByItem(item)
  382. if e != nil {
  383. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  384. return
  385. }
  386. sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source)
  387. if e != nil {
  388. err = errors.New("GetCygxResourceDataByIdAndSource, Err: " + e.Error())
  389. return
  390. }
  391. resourceDataId = sourceDetail.Id
  392. }
  393. var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement
  394. for _, v := range industrialList {
  395. var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement)
  396. industrialItem.SourceId = sourceId
  397. industrialItem.Source = source
  398. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  399. industrialItem.ResourceDataId = resourceDataId
  400. industrialItem.CreateTime = time.Now()
  401. industrialItems = append(industrialItems, industrialItem)
  402. industrialName += v.IndustryName
  403. }
  404. var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject
  405. for _, v := range subjectList {
  406. var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject)
  407. subjectItem.SourceId = sourceId
  408. subjectItem.Source = source
  409. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  410. subjectItem.ResourceDataId = resourceDataId
  411. subjectItem.CreateTime = time.Now()
  412. subjectItems = append(subjectItems, subjectItem)
  413. subjectName += v.SubjectName
  414. }
  415. //插入关联信息
  416. e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  417. if e != nil {
  418. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  419. return
  420. }
  421. }
  422. return
  423. }
  424. // 更新产品内测
  425. func UpdateProductInteriorResourceData(sourceId int) {
  426. var err error
  427. defer func() {
  428. if err != nil {
  429. fmt.Println("err:", err)
  430. go alarm_msg.SendAlarmMsg("更新产品内测 失败,UpdateProductInteriorResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  431. }
  432. }()
  433. var source = utils.CYGX_OBJ_PRODUCTINTERIOR
  434. var condition string
  435. var pars []interface{}
  436. condition = ` AND visible_range = 1 AND product_interior_id = ? `
  437. pars = append(pars, sourceId)
  438. total, e := cygx.GetCygxProductInteriorCount(condition, pars)
  439. if e != nil {
  440. err = errors.New("GetCygxReportSelection, Err: " + e.Error())
  441. return
  442. }
  443. //如果取消发布了就做删除处理
  444. if total == 0 {
  445. e = cygx.DeleteResourceData(sourceId, source)
  446. if e != nil {
  447. err = errors.New("DeleteResourceData, Err: " + e.Error())
  448. return
  449. }
  450. //删除 cygx_resource_data 表关联的产业ID,标的ID
  451. e = cygx.DeleteCygxResourceDataGroup(sourceId, source)
  452. if e != nil {
  453. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  454. return
  455. }
  456. } else {
  457. //判断是否存在,如果不存在就新增,存在就更新
  458. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  459. if e != nil {
  460. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  461. return
  462. }
  463. detail, e := cygx.GetCygxProductInteriorDetail(sourceId)
  464. if e != nil {
  465. err = errors.New("GetCygxReportSelectionInfoById, Err: " + err.Error())
  466. return
  467. }
  468. mapMatchTypeName := GetCygxReportMappingCygxListMap() //报告匹配类型
  469. var resourceDataId int
  470. publishDate := detail.CreateTime
  471. item := new(cygx.CygxResourceData)
  472. var industrialName string
  473. var subjectName string
  474. //建立首页资源表,与产业的关系
  475. industrialList, e := cygx.GetProductInteriorIndustrialGroupManagementList(sourceId)
  476. if e != nil && e.Error() != utils.ErrNoRow() {
  477. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  478. return
  479. }
  480. for _, v := range industrialList {
  481. industrialName += v.IndustryName
  482. }
  483. //建立首页资源表,与标的 的关系
  484. subjectList, e := cygx.GetProductInteriorIndustrialGroupSubjecttList(sourceId)
  485. if e != nil && e.Error() != utils.ErrNoRow() {
  486. err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  487. return
  488. }
  489. for _, v := range subjectList {
  490. subjectName += v.SubjectName
  491. }
  492. item.SourceId = sourceId
  493. item.Source = source
  494. item.SearchTag = mapMatchTypeName[detail.MatchTypeId]
  495. item.PublishDate = publishDate
  496. if item.SearchTag != "观点周递" {
  497. item.ChartPermissionId = detail.ChartPermissionId //首页筛选任何行业时,无法筛选出【观点周递】类型的报告
  498. }
  499. item.CreateTime = time.Now()
  500. item.SearchTitle = detail.Title
  501. item.SearchContent = detail.Abstract + industrialName + subjectName
  502. item.SearchOrderTime = detail.PublishTime
  503. if totalData == 0 {
  504. newId, e := cygx.AddCygxResourceData(item)
  505. if e != nil {
  506. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  507. return
  508. }
  509. resourceDataId = int(newId)
  510. } else {
  511. e = cygx.UpdateResourceDataByItem(item)
  512. if e != nil {
  513. err = errors.New("UpdateResourceData, Err: " + e.Error())
  514. return
  515. }
  516. sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source)
  517. if e != nil {
  518. err = errors.New("UpdateResourceData, Err: " + e.Error())
  519. return
  520. }
  521. resourceDataId = sourceDetail.Id
  522. }
  523. var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement
  524. for _, v := range industrialList {
  525. var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement)
  526. industrialItem.SourceId = sourceId
  527. industrialItem.Source = source
  528. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  529. industrialItem.ResourceDataId = resourceDataId
  530. industrialItem.CreateTime = time.Now()
  531. industrialItems = append(industrialItems, industrialItem)
  532. }
  533. var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject
  534. for _, v := range subjectList {
  535. var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject)
  536. subjectItem.SourceId = sourceId
  537. subjectItem.Source = source
  538. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  539. subjectItem.ResourceDataId = resourceDataId
  540. subjectItem.CreateTime = time.Now()
  541. subjectItems = append(subjectItems, subjectItem)
  542. }
  543. //插入关联信息
  544. e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  545. if e != nil {
  546. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  547. return
  548. }
  549. }
  550. return
  551. }
  552. // 更新晨会精华 (跟踪点评)
  553. func UpdateMeetingreviewchaptResourceData(sourceId int) {
  554. var err error
  555. defer func() {
  556. if err != nil {
  557. fmt.Println("err:", err)
  558. go alarm_msg.SendAlarmMsg("更新产品内测 失败,UpdateMeetingreviewchaptResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  559. }
  560. }()
  561. var source = utils.CYGX_OBJ_MEETINGREVIEWCHAPT
  562. total, e := cygx.GetCygxMorningMeetingReviewChapterCount(sourceId)
  563. if e != nil {
  564. err = errors.New("GetCygxReportSelection, Err: " + e.Error())
  565. return
  566. }
  567. //如果取消发布了就做删除处理
  568. if total == 0 {
  569. e = cygx.DeleteResourceData(sourceId, source)
  570. if e != nil {
  571. err = errors.New("DeleteResourceData, Err: " + e.Error())
  572. return
  573. }
  574. //删除 cygx_resource_data 表关联的产业ID,标的ID
  575. e = cygx.DeleteCygxResourceDataGroup(sourceId, source)
  576. if e != nil {
  577. err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
  578. return
  579. }
  580. } else {
  581. //判断是否存在,如果不存在就新增,存在就更新
  582. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  583. if e != nil {
  584. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  585. return
  586. }
  587. detail, e := cygx.GetCygxMorningMeetingReviewChapterDetail(sourceId)
  588. if e != nil {
  589. err = errors.New("GetCygxMorningMeetingReviewChapterDetail" + e.Error())
  590. return
  591. }
  592. var resourceDataId int
  593. publishDate := time.Now().Format(utils.FormatDateTime)
  594. item := new(cygx.CygxResourceData)
  595. var industrialName string
  596. var subjectName string
  597. //建立首页资源表,与产业的关系
  598. var condition string
  599. var pars []interface{}
  600. condition = " AND industrial_management_id = ? "
  601. pars = append(pars, detail.IndustryId)
  602. //建立首页资源表,与产业的关系
  603. industrialList, e := cygx.GetTopOneMonthArtReadNumIndustryAll(condition, pars)
  604. if e != nil && e.Error() != utils.ErrNoRow() {
  605. err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  606. return
  607. }
  608. for _, v := range industrialList {
  609. industrialName += v.IndustryName
  610. }
  611. if detail.IndustrialSubjectIds != "" {
  612. condition = ""
  613. pars = make([]interface{}, 0)
  614. condition = " AND industrial_subject_id IN (" + detail.IndustrialSubjectIds + ") "
  615. //建立首页资源表,与标的 的关系
  616. subjectList, e := cygx.GetCygxIndustrialSubjectListCondition(condition, pars)
  617. if e != nil && e.Error() != utils.ErrNoRow() {
  618. err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  619. return
  620. }
  621. for _, v := range subjectList {
  622. subjectName += v.SubjectName
  623. }
  624. }
  625. item.SourceId = sourceId
  626. item.Source = source
  627. item.SearchTag = "晨会精华"
  628. item.PublishDate = publishDate
  629. item.ChartPermissionId = detail.ChartPermissionId
  630. item.CreateTime = time.Now()
  631. item.SearchTitle = industrialName + subjectName + "晨会精华"
  632. content, e := utils.GetHtmlContentText(detail.Content)
  633. if e != nil && e.Error() != utils.ErrNoRow() {
  634. err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  635. return
  636. }
  637. item.SearchContent = content
  638. item.SearchOrderTime = detail.MeetingTime.Format(utils.FormatDateTime)
  639. if totalData == 0 {
  640. newId, e := cygx.AddCygxResourceData(item)
  641. if e != nil {
  642. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  643. return
  644. }
  645. resourceDataId = int(newId)
  646. } else {
  647. e = cygx.UpdateResourceDataByItem(item)
  648. if e != nil {
  649. err = errors.New("UpdateResourceData, Err: " + e.Error())
  650. return
  651. }
  652. sourceDetail, e := cygx.GetCygxResourceDataByIdAndSource(sourceId, source)
  653. if e != nil {
  654. err = errors.New("UpdateResourceData, Err: " + e.Error())
  655. return
  656. }
  657. resourceDataId = sourceDetail.Id
  658. }
  659. var industrialItems []*cygx.CygxResourceDataIndustrialGroupManagement
  660. for _, v := range industrialList {
  661. var industrialItem = new(cygx.CygxResourceDataIndustrialGroupManagement)
  662. industrialItem.SourceId = sourceId
  663. industrialItem.Source = source
  664. industrialItem.IndustrialManagementId = v.IndustrialManagementId
  665. industrialItem.ResourceDataId = resourceDataId
  666. industrialItem.CreateTime = time.Now()
  667. industrialItems = append(industrialItems, industrialItem)
  668. }
  669. //return
  670. var subjectItems []*cygx.CygxResourceDataIndustrialGroupSubject
  671. //晨会精华如果关联的标的就做查询
  672. if detail.IndustrialSubjectIds != "" {
  673. condition = ""
  674. pars = make([]interface{}, 0)
  675. condition = " AND industrial_subject_id IN (" + detail.IndustrialSubjectIds + ") "
  676. //建立首页资源表,与标的 的关系
  677. subjectList, e := cygx.GetCygxIndustrialSubjectListCondition(condition, pars)
  678. if e != nil && e.Error() != utils.ErrNoRow() {
  679. err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
  680. return
  681. }
  682. for _, v := range subjectList {
  683. var subjectItem = new(cygx.CygxResourceDataIndustrialGroupSubject)
  684. subjectItem.SourceId = sourceId
  685. subjectItem.Source = source
  686. subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
  687. subjectItem.ResourceDataId = resourceDataId
  688. subjectItem.CreateTime = time.Now()
  689. subjectItems = append(subjectItems, subjectItem)
  690. }
  691. }
  692. //插入关联信息
  693. e = cygx.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
  694. if e != nil {
  695. err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
  696. return
  697. }
  698. }
  699. return
  700. }
  701. // 更新报告精选(重点公司)
  702. func UpdateReportSelectionResourceData(sourceId int) {
  703. var err error
  704. defer func() {
  705. if err != nil {
  706. fmt.Println("err:", err)
  707. go alarm_msg.SendAlarmMsg("更新报告精选(重点公司) 失败,UpdateReportSelectionResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  708. }
  709. }()
  710. var source = utils.CYGX_OBJ_REPORTSELECTION
  711. var condition string
  712. var pars []interface{}
  713. condition = ` AND visible_range = 1 AND article_id = ? `
  714. pars = append(pars, sourceId)
  715. total, e := cygx.GetCygxReportSelection(condition, pars)
  716. if e != nil {
  717. err = errors.New("GetCygxReportSelection, Err: " + e.Error())
  718. return
  719. }
  720. //如果取消发布了就做删除处理
  721. if total == 0 {
  722. e = cygx.DeleteResourceData(sourceId, source)
  723. if e != nil {
  724. err = errors.New("DeleteResourceData, Err: " + e.Error())
  725. return
  726. }
  727. } else {
  728. //判断是否存在,如果不存在就新增,存在就更新
  729. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  730. if e != nil {
  731. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  732. return
  733. }
  734. detail, e := cygx.GetCygxReportSelectionInfoById(sourceId)
  735. if e != nil {
  736. err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  737. return
  738. }
  739. publishDate := detail.PublishDate
  740. item := new(cygx.CygxResourceData)
  741. item.SourceId = sourceId
  742. item.Source = source
  743. item.SearchTag = "重点公司"
  744. item.PublishDate = publishDate
  745. item.CreateTime = time.Now()
  746. item.SearchTitle = detail.Title
  747. item.SearchContent = ""
  748. item.SearchOrderTime = detail.PublishDate
  749. if totalData == 0 {
  750. _, e := cygx.AddCygxResourceData(item)
  751. if e != nil {
  752. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  753. return
  754. }
  755. } else {
  756. e = cygx.UpdateResourceDataByItem(item)
  757. if e != nil {
  758. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  759. return
  760. }
  761. }
  762. }
  763. return
  764. }
  765. // 更新本周研究汇总
  766. func UpdateResearchSummaryResourceData(sourceId int) {
  767. var err error
  768. defer func() {
  769. if err != nil {
  770. fmt.Println("err:", err)
  771. go alarm_msg.SendAlarmMsg("更新本周研究汇总 失败,UpdateResearchSummaryResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  772. }
  773. }()
  774. var source = utils.CYGX_OBJ_RESEARCHSUMMARY
  775. var condition string
  776. var pars []interface{}
  777. condition = ` AND visible_range = 1 AND article_id = ? `
  778. pars = append(pars, sourceId)
  779. total, e := cygx.GetCygxResearchSummary(condition, pars)
  780. if e != nil {
  781. err = errors.New("GetCygxResearchSummary, Err: " + e.Error())
  782. return
  783. }
  784. //如果取消发布了就做删除处理
  785. if total == 0 {
  786. e = cygx.DeleteResourceData(sourceId, source)
  787. if e != nil {
  788. err = errors.New("DeleteResourceData, Err: " + e.Error())
  789. return
  790. }
  791. } else {
  792. //判断是否存在,如果不存在就新增,存在就更新
  793. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  794. if e != nil {
  795. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  796. return
  797. }
  798. detail, e := cygx.GetCygxResearchSummaryInfoById(sourceId)
  799. if e != nil {
  800. err = errors.New("GetCygxResearchSummaryInfoById, Err: " + e.Error())
  801. return
  802. }
  803. publishDate := time.Now().Format(utils.FormatDateTime)
  804. item := new(cygx.CygxResourceData)
  805. item.SourceId = sourceId
  806. item.Source = source
  807. item.SearchTag = "本周研究汇总"
  808. item.PublishDate = publishDate
  809. item.CreateTime = time.Now()
  810. item.SearchTitle = detail.Title
  811. item.SearchContent = ""
  812. item.SearchOrderTime = detail.PublishDate
  813. if totalData == 0 {
  814. _, e := cygx.AddCygxResourceData(item)
  815. if e != nil {
  816. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  817. return
  818. }
  819. } else {
  820. e = cygx.UpdateResourceDataByItem(item)
  821. if e != nil {
  822. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  823. return
  824. }
  825. }
  826. }
  827. return
  828. }
  829. // 更新上周纪要汇总
  830. func UpdateMinutesSummaryResourceData(sourceId int) {
  831. var err error
  832. defer func() {
  833. if err != nil {
  834. fmt.Println("err:", err)
  835. go alarm_msg.SendAlarmMsg("更新上周纪要汇总 失败,UpdateMinutesSummaryResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  836. }
  837. }()
  838. var source = utils.CYGX_OBJ_MINUTESSUMMARY
  839. var condition string
  840. var pars []interface{}
  841. condition = ` AND visible_range = 1 AND article_id = ? `
  842. pars = append(pars, sourceId)
  843. total, e := cygx.GetCygxMinutesSummary(condition, pars)
  844. if e != nil {
  845. err = errors.New("GetCygxResearchSummary, Err: " + e.Error())
  846. return
  847. }
  848. //如果取消发布了就做删除处理
  849. if total == 0 {
  850. e = cygx.DeleteResourceData(sourceId, source)
  851. if e != nil {
  852. err = errors.New("DeleteResourceData, Err: " + e.Error())
  853. return
  854. }
  855. } else {
  856. //判断是否存在,如果不存在就新增,存在就更新
  857. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  858. if e != nil {
  859. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  860. return
  861. }
  862. detail, e := cygx.GetCygxMinutesSummaryInfoById(sourceId)
  863. if e != nil {
  864. err = errors.New("GetCygxMinutesSummaryInfoById, Err: " + e.Error())
  865. return
  866. }
  867. publishDate := time.Now().Format(utils.FormatDateTime)
  868. item := new(cygx.CygxResourceData)
  869. item.SourceId = sourceId
  870. item.Source = source
  871. item.SearchTag = "上周纪要汇总"
  872. item.PublishDate = publishDate
  873. item.CreateTime = time.Now()
  874. item.SearchTitle = detail.Title
  875. item.SearchContent = ""
  876. item.SearchOrderTime = detail.PublishDate
  877. if totalData == 0 {
  878. _, e := cygx.AddCygxResourceData(item)
  879. if e != nil {
  880. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  881. return
  882. }
  883. } else {
  884. e = cygx.UpdateResourceDataByItem(item)
  885. if e != nil {
  886. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  887. return
  888. }
  889. }
  890. }
  891. return
  892. }
  893. // 更新活动音频
  894. func UpdateActivityVoiceResourceData(sourceId int) {
  895. time.Sleep(1 * time.Second) // 添加1秒的延迟
  896. var err error
  897. defer func() {
  898. if err != nil {
  899. fmt.Println("err:", err)
  900. go alarm_msg.SendAlarmMsg("更新更新活动音频 失败,UpdateActivityVoiceResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  901. }
  902. }()
  903. var source = utils.CYGX_OBJ_ACTIVITYVOICE
  904. var condition string
  905. var pars []interface{}
  906. condition = ` AND activity_voice_id = ? `
  907. pars = append(pars, sourceId)
  908. total, e := cygx.GetCygxActivityVoiceCount(condition, pars)
  909. if e != nil {
  910. err = errors.New("GetCygxResearchSummary, Err: " + e.Error())
  911. return
  912. }
  913. //如果取消发布了就做删除处理
  914. if total == 0 {
  915. e = cygx.DeleteResourceData(sourceId, source)
  916. if e != nil {
  917. err = errors.New("DeleteResourceData, Err: " + e.Error())
  918. return
  919. }
  920. } else {
  921. //获取音频详情
  922. voiceDetail, e := cygx.GetCygxActivityVoiceReqDetailByActivityVoiceId(sourceId)
  923. if e != nil {
  924. err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
  925. return
  926. }
  927. activityId := voiceDetail.ActivityId
  928. //获取活动详情
  929. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  930. if e != nil {
  931. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  932. return
  933. }
  934. //判断是否存在,如果不存在就新增,存在就更新
  935. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  936. if e != nil {
  937. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  938. return
  939. }
  940. publishDate := time.Now().Format(utils.FormatDateTime)
  941. item := new(cygx.CygxResourceData)
  942. var industrialName string
  943. var subjectName string
  944. //建立首页资源表,与产业的关系
  945. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  946. if e != nil && e.Error() != utils.ErrNoRow() {
  947. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId))
  948. return
  949. }
  950. for _, v := range industrialList {
  951. industrialName += v.IndustryName
  952. }
  953. //建立首页资源表,与标的 的关系
  954. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  955. if e != nil && e.Error() != utils.ErrNoRow() {
  956. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId))
  957. return
  958. }
  959. for _, v := range subjectList {
  960. subjectName += v.SubjectName
  961. }
  962. item.SourceId = sourceId
  963. item.Source = source
  964. //易董办会的分析师电话会,为路演回放
  965. if voiceDetail.FileType == 1 {
  966. item.SearchTag = "路演回放"
  967. } else {
  968. item.SearchTag = "调研反馈"
  969. }
  970. item.PublishDate = publishDate
  971. item.ChartPermissionId = activityInfo.ChartPermissionId
  972. item.CreateTime = utils.StrDateToDate(activityInfo.ActivityTime)
  973. item.SearchTitle = voiceDetail.VoiceName
  974. item.SearchContent = activityInfo.Label + industrialName + subjectName
  975. item.SearchOrderTime = activityInfo.ActivityTime
  976. if totalData == 0 {
  977. _, e := cygx.AddCygxResourceData(item)
  978. if e != nil {
  979. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  980. return
  981. }
  982. } else {
  983. e = cygx.UpdateResourceDataByItem(item)
  984. if e != nil {
  985. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  986. return
  987. }
  988. }
  989. }
  990. return
  991. }
  992. // 更新活动视频
  993. func UpdateActivityVideoResourceData(sourceId int) {
  994. time.Sleep(1 * time.Second) // 添加1秒的延迟
  995. var err error
  996. defer func() {
  997. if err != nil {
  998. fmt.Println("err:", err)
  999. go alarm_msg.SendAlarmMsg("更新更新活动视频 失败,UpdateActivityVideoResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  1000. }
  1001. }()
  1002. var source = utils.CYGX_OBJ_ACTIVITYVIDEO
  1003. var condition string
  1004. var pars []interface{}
  1005. condition = ` AND v.video_id = ? `
  1006. pars = append(pars, sourceId)
  1007. total, e := cygx.GetActivityVideoCount(condition, pars)
  1008. if e != nil {
  1009. err = errors.New("GetCygxResearchSummary, Err: " + e.Error())
  1010. return
  1011. }
  1012. //如果取消发布了就做删除处理
  1013. if total == 0 {
  1014. e = cygx.DeleteResourceData(sourceId, source)
  1015. if e != nil {
  1016. err = errors.New("DeleteResourceData, Err: " + e.Error())
  1017. return
  1018. }
  1019. } else {
  1020. videoDetail, e := cygx.GetCygxActivityVideoReqDetailByVideoId(sourceId)
  1021. if e != nil {
  1022. err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
  1023. return
  1024. }
  1025. activityId := videoDetail.ActivityId
  1026. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  1027. if e != nil {
  1028. err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
  1029. return
  1030. }
  1031. //判断是否存在,如果不存在就新增,存在就更新
  1032. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  1033. if e != nil {
  1034. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  1035. return
  1036. }
  1037. publishDate := time.Now().Format(utils.FormatDateTime)
  1038. item := new(cygx.CygxResourceData)
  1039. var industrialName string
  1040. var subjectName string
  1041. //建立首页资源表,与产业的关系
  1042. industrialList, e := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  1043. if e != nil && e.Error() != utils.ErrNoRow() {
  1044. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId))
  1045. return
  1046. }
  1047. for _, v := range industrialList {
  1048. industrialName += v.IndustryName
  1049. }
  1050. //建立首页资源表,与标的 的关系
  1051. subjectList, e := cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  1052. if e != nil && e.Error() != utils.ErrNoRow() {
  1053. err = errors.New("GetIndustrialActivityGroupManagementList, Err: " + e.Error() + "activityId:" + strconv.Itoa(activityId))
  1054. return
  1055. }
  1056. for _, v := range subjectList {
  1057. subjectName += v.SubjectName
  1058. }
  1059. item.SourceId = sourceId
  1060. item.Source = source
  1061. //易董办会的分析师电话会,为路演回放
  1062. if videoDetail.FileType == 1 {
  1063. item.SearchTag = "路演回放"
  1064. } else {
  1065. item.SearchTag = "调研反馈"
  1066. }
  1067. item.PublishDate = publishDate
  1068. item.ChartPermissionId = activityInfo.ChartPermissionId
  1069. item.CreateTime = utils.StrDateToDate(activityInfo.ActivityTime)
  1070. item.SearchTitle = videoDetail.VideoName
  1071. item.SearchContent = activityInfo.Label + industrialName + subjectName
  1072. item.SearchOrderTime = activityInfo.ActivityTime
  1073. if totalData == 0 {
  1074. _, e := cygx.AddCygxResourceData(item)
  1075. if e != nil {
  1076. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  1077. return
  1078. }
  1079. } else {
  1080. e = cygx.UpdateResourceDataByItem(item)
  1081. if e != nil {
  1082. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  1083. return
  1084. }
  1085. }
  1086. }
  1087. return
  1088. }
  1089. // 更新产业视频
  1090. func UpdateMicroRoadshowResourceData(sourceId int) {
  1091. var err error
  1092. defer func() {
  1093. if err != nil {
  1094. fmt.Println("err:", err)
  1095. go alarm_msg.SendAlarmMsg("更新产业视频 失败,UpdateMicroRoadshowResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
  1096. }
  1097. }()
  1098. var source = utils.CYGX_OBJ_ROADSHOW
  1099. var condition string
  1100. var pars []interface{}
  1101. condition = ` AND publish_status = 1 AND video_id = ? `
  1102. pars = append(pars, sourceId)
  1103. total, e := cygx.GetMicroRoadshowVideoListCount(condition, pars)
  1104. if e != nil {
  1105. err = errors.New("GetMicroRoadshowVideoListCount, Err: " + e.Error())
  1106. return
  1107. }
  1108. //如果取消发布了就做删除处理
  1109. if total == 0 {
  1110. e = cygx.DeleteResourceData(sourceId, source)
  1111. if e != nil {
  1112. err = errors.New("DeleteResourceData, Err: " + e.Error())
  1113. return
  1114. }
  1115. } else {
  1116. //判断是否存在,如果不存在就新增,存在就更新
  1117. totalData, e := cygx.GetCygxReportSelectionBySourceAndId(sourceId, source)
  1118. if e != nil {
  1119. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  1120. return
  1121. }
  1122. detail, e := cygx.GetMicroRoadshowVideoByVideoId(sourceId)
  1123. if e != nil {
  1124. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  1125. return
  1126. }
  1127. publishDate := time.Now().Format(utils.FormatDateTime)
  1128. item := new(cygx.CygxResourceData)
  1129. item.SourceId = sourceId
  1130. item.Source = source
  1131. item.SearchTag = ""
  1132. item.PublishDate = publishDate
  1133. item.ChartPermissionId = detail.ChartPermissionId
  1134. item.CreateTime = time.Now()
  1135. item.SearchTitle = detail.VideoName
  1136. item.SearchContent = detail.IndustryName
  1137. item.SearchOrderTime = detail.PublishDate.Format(utils.FormatDateTime)
  1138. if totalData == 0 {
  1139. _, e := cygx.AddCygxResourceData(item)
  1140. if e != nil {
  1141. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  1142. return
  1143. }
  1144. } else {
  1145. e = cygx.UpdateResourceDataByItem(item)
  1146. if e != nil {
  1147. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  1148. return
  1149. }
  1150. }
  1151. }
  1152. return
  1153. }
  1154. //func init() {
  1155. // UpdateAskserieVideoResourceData(7)
  1156. //}
  1157. // 更新问答系列 写入首页最新 cygx_resource_data 表
  1158. func UpdateAskserieVideoResourceData(sourceId int) {
  1159. var err error
  1160. defer func() {
  1161. if err != nil {
  1162. fmt.Println(err)
  1163. go alarm_msg.SendAlarmMsg(fmt.Sprint("更新问答系列ourceId: ", sourceId, err.Error()), 2)
  1164. }
  1165. }()
  1166. var source = utils.CYGX_OBJ_ASKSERIEVIDEO
  1167. var condition string
  1168. var pars []interface{}
  1169. condition = ` AND publish_status = 1 AND askserie_video_id = ? `
  1170. pars = append(pars, sourceId)
  1171. total, e := cygx.GetCygxAskserieVideoCount(condition, pars)
  1172. if e != nil {
  1173. err = errors.New("GetCygxAskserieVideoCount, Err: " + e.Error())
  1174. return
  1175. }
  1176. //如果取消发布了就做删除处理
  1177. if total == 0 {
  1178. e = cygx.DeleteResourceData(sourceId, source)
  1179. if e != nil {
  1180. err = errors.New("DeleteResourceData, Err: " + e.Error())
  1181. return
  1182. }
  1183. } else {
  1184. //判断是否存在,如果不存在就新增,存在就更新
  1185. totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  1186. if e != nil {
  1187. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  1188. return
  1189. }
  1190. detail, e := cygx.GetCygxAskserieVideoDetail(sourceId)
  1191. if e != nil {
  1192. err = errors.New("GetCygxAskserieVideoDetail, Err: " + e.Error())
  1193. return
  1194. }
  1195. publishDate := time.Now().Format(utils.FormatDateTime)
  1196. item := new(cygx.CygxResourceData)
  1197. item.SourceId = sourceId
  1198. item.Source = source
  1199. item.PublishDate = publishDate
  1200. item.ChartPermissionId = detail.ChartPermissionId
  1201. item.CreateTime = time.Now()
  1202. item.SearchTitle = detail.VideoName
  1203. item.SearchContent = detail.IndustryName
  1204. item.SearchOrderTime = detail.PublishDate
  1205. if totalData == 0 {
  1206. _, e := cygx.AddCygxResourceData(item)
  1207. if e != nil {
  1208. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  1209. return
  1210. }
  1211. } else {
  1212. e = cygx.UpdateResourceDataByItem(item)
  1213. if e != nil {
  1214. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  1215. return
  1216. }
  1217. }
  1218. }
  1219. return
  1220. }
  1221. func init300() {
  1222. //var condition string
  1223. //var pars []interface{}
  1224. //
  1225. //{
  1226. // //活动
  1227. // var condition string
  1228. // var pars []interface{}
  1229. // condition = " AND publish_status = 1 AND activity_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'activity') "
  1230. // list, err := cygx.GetActivityListAll(condition, pars, 0, 9999)
  1231. // if err != nil {
  1232. // fmt.Println(err)
  1233. // }
  1234. //
  1235. // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY)
  1236. // //if err != nil {
  1237. // // fmt.Println(err)
  1238. // //}
  1239. // fmt.Println(len(list))
  1240. // for _, v := range list {
  1241. // fmt.Println(v.ActivityId)
  1242. // UpdateActivityResourceData(v.ActivityId)
  1243. // }
  1244. //}
  1245. //12.4
  1246. //{
  1247. // //活动
  1248. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY)
  1249. // if err != nil {
  1250. // fmt.Println(err)
  1251. // }
  1252. //
  1253. // for _, v := range list {
  1254. // detail, e := cygx.GetAddActivityInfoById(v.SourceId)
  1255. // if e != nil {
  1256. // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  1257. // fmt.Println(err)
  1258. // return
  1259. // }
  1260. // item := new(cygx.CygxResourceData)
  1261. // item.SourceId = v.SourceId
  1262. // item.Source = utils.CYGX_OBJ_ACTIVITY
  1263. // item.ChartPermissionId = detail.ChartPermissionId
  1264. // fmt.Println(v.Source)
  1265. // err = cygx.UpdateChartPermissionIdResourceDataByItem(item)
  1266. // if err != nil {
  1267. // fmt.Println(err)
  1268. // return
  1269. // }
  1270. // }
  1271. //}
  1272. //{
  1273. // //专项调研活动
  1274. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYSPECIAL)
  1275. // if err != nil {
  1276. // fmt.Println(err)
  1277. // }
  1278. // for _, v := range list {
  1279. // fmt.Println(v.Source)
  1280. // UpdateActivitySpecialResourceData(v.SourceId)
  1281. // }
  1282. //}
  1283. //{
  1284. // var condition string
  1285. // var pars []interface{}
  1286. // condition = " AND publish_status = 1 AND article_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'article') "
  1287. //
  1288. // list, err := cygx.GetArticleRoadshowEssenceList(condition, pars, 0, 9999)
  1289. // if err != nil {
  1290. // fmt.Println(err)
  1291. // return
  1292. // }
  1293. // fmt.Println(len(list))
  1294. // //return
  1295. // //文章
  1296. // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE)
  1297. // //if err != nil {
  1298. // // fmt.Println(err)
  1299. // //}
  1300. // for _, v := range list {
  1301. // fmt.Println(v.ArticleId)
  1302. // UpdateArticleResourceData(v.ArticleId)
  1303. // }
  1304. //}
  1305. //{
  1306. // //文章//12.4
  1307. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE)
  1308. // if err != nil {
  1309. // fmt.Println(err)
  1310. // return
  1311. // }
  1312. // for _, v := range list {
  1313. // detail, e := cygx.GetArticleDetailByArticleId(v.SourceId)
  1314. // if e != nil {
  1315. // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  1316. // fmt.Println(err)
  1317. // return
  1318. // }
  1319. //
  1320. // item := new(cygx.CygxResourceData)
  1321. // if detail.ArticleTypeId > 0 {
  1322. // //item.SearchTag = detail.ArticleTypeName // 研选类型名称
  1323. // item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  1324. // } else {
  1325. // //item.SearchTag = detail.MatchTypeName
  1326. // //获取文章分类详情
  1327. // detailCategory, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  1328. // if detailCategory != nil {
  1329. // item.ChartPermissionId = detailCategory.ChartPermissionId
  1330. // }else{
  1331. // detailCategoryTwo, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryIdTwo)
  1332. // if detailCategoryTwo != nil {
  1333. // item.ChartPermissionId = detailCategoryTwo.ChartPermissionId
  1334. // }
  1335. // }
  1336. // }
  1337. // item.SourceId = v.SourceId
  1338. // item.Source = utils.CYGX_OBJ_ARTICLE
  1339. // fmt.Println(v.Source)
  1340. // err = cygx.UpdateChartPermissionIdResourceDataByItem(item)
  1341. // if err != nil {
  1342. // fmt.Println(err)
  1343. // return
  1344. // }
  1345. // }
  1346. //}
  1347. //{
  1348. // //产品内测
  1349. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_PRODUCTINTERIOR)
  1350. // if err != nil {
  1351. // fmt.Println(err)
  1352. // }
  1353. // for _, v := range list {
  1354. // fmt.Println(v.Source)
  1355. // UpdateProductInteriorResourceData(v.SourceId)
  1356. // }
  1357. //}
  1358. //
  1359. //{
  1360. // //晨会精华
  1361. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT)
  1362. // if err != nil {
  1363. // fmt.Println(err)
  1364. // }
  1365. // for _, v := range list {
  1366. // fmt.Println(v.Source)
  1367. // UpdateMeetingreviewchaptResourceData(v.SourceId)
  1368. // }
  1369. //}
  1370. //
  1371. //{
  1372. // //重点公司
  1373. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_REPORTSELECTION)
  1374. // if err != nil {
  1375. // fmt.Println(err)
  1376. // }
  1377. // for _, v := range list {
  1378. // fmt.Println(v.Source)
  1379. // //UpdateReportSelectionResourceData(v.SourceId)
  1380. // }
  1381. //}
  1382. //
  1383. //{
  1384. // //更新本周研究汇总
  1385. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_RESEARCHSUMMARY)
  1386. // if err != nil {
  1387. // fmt.Println(err)
  1388. // }
  1389. // for _, v := range list {
  1390. // fmt.Println(v.Source)
  1391. // //UpdateResearchSummaryResourceData(v.SourceId)
  1392. // }
  1393. //}
  1394. //
  1395. //{
  1396. // //更新本周研究汇总
  1397. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MINUTESSUMMARY)
  1398. // if err != nil {
  1399. // fmt.Println(err)
  1400. // }
  1401. // for _, v := range list {
  1402. // fmt.Println(v.Source)
  1403. // //UpdateMinutesSummaryResourceData(v.SourceId)
  1404. // }
  1405. //}
  1406. //{
  1407. // //活动音频
  1408. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVOICE)
  1409. // if err != nil {
  1410. // fmt.Println(err)
  1411. // }
  1412. // for _, v := range list {
  1413. // fmt.Println(v.Source)
  1414. // UpdateActivityVoiceResourceData(v.SourceId)
  1415. // }
  1416. //}
  1417. //{
  1418. // //活动视频
  1419. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVIDEO)
  1420. // if err != nil {
  1421. // fmt.Println(err)
  1422. // }
  1423. // for _, v := range list {
  1424. // fmt.Println(v.SourceId)
  1425. // UpdateActivityVideoResourceData(v.SourceId)
  1426. // }
  1427. //}
  1428. //{
  1429. // //活动音频
  1430. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ROADSHOW)
  1431. // if err != nil {
  1432. // fmt.Println(err)
  1433. // }
  1434. // for _, v := range list {
  1435. // fmt.Println(v.Source)
  1436. // UpdateMicroRoadshowResourceData(v.SourceId)
  1437. // }
  1438. //}
  1439. //{
  1440. // //问答系列视频
  1441. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ASKSERIEVIDEO)
  1442. // if err != nil {
  1443. // fmt.Println(err)
  1444. // }
  1445. // for _, v := range list {
  1446. // fmt.Println(v.SourceId)
  1447. // UpdateAskserieVideoResourceData(v.SourceId)
  1448. // }
  1449. //}
  1450. //{
  1451. // //晨会精华
  1452. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT)
  1453. // if err != nil {
  1454. // fmt.Println(err)
  1455. // }
  1456. // for _, v := range list {
  1457. // fmt.Println(v.SourceId)
  1458. // UpdateMeetingreviewchaptResourceData(v.SourceId)
  1459. // }
  1460. //}
  1461. //{
  1462. // //研选专栏
  1463. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_YANXUANSPECIAL)
  1464. // if err != nil {
  1465. // fmt.Println(err)
  1466. // }
  1467. // for _, v := range list {
  1468. // fmt.Println(v.SourceId)
  1469. // UpdateYanxuanSpecialResourceData(v.SourceId)
  1470. // }
  1471. //}
  1472. }