resource_data.go 50 KB

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