resource_data.go 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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.CreateTime // 活动创建时间作为排序时间
  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. }
  1271. industrialItem, e := cygx.GetIndustrialManagementInfo(sourceId)
  1272. if e != nil {
  1273. err = errors.New("GetIndustrialManagementInfo, Err: " + e.Error())
  1274. return
  1275. }
  1276. var subjectNames []string
  1277. listSub, e := cygx.GetcygxIndustrialSubject(sourceId)
  1278. if e != nil {
  1279. err = errors.New("GetcygxIndustrialSubject, Err: " + e.Error())
  1280. return
  1281. }
  1282. for _, v := range listSub {
  1283. subjectNames = append(subjectNames, v.SubjectName)
  1284. }
  1285. //判断是否存在,如果不存在就新增,存在就更新
  1286. totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  1287. if e != nil {
  1288. err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
  1289. return
  1290. }
  1291. item := new(cygx.CygxResourceData)
  1292. item.SourceId = sourceId
  1293. item.Source = source
  1294. item.PublishDate = maxData
  1295. item.CreateTime = time.Now()
  1296. if len(subjectNames) == 0 {
  1297. item.SearchTitle = industrialItem.IndustryName
  1298. } else {
  1299. item.SearchTitle = industrialItem.IndustryName + "," + strings.Join(subjectNames, ",")
  1300. }
  1301. item.SearchContent = ""
  1302. item.SearchOrderTime = maxData
  1303. //fmt.Println(item)
  1304. //return
  1305. if totalData == 0 {
  1306. _, e := cygx.AddCygxResourceData(item)
  1307. if e != nil {
  1308. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  1309. return
  1310. }
  1311. } else {
  1312. e = cygx.UpdateResourceDataByItem(item)
  1313. if e != nil {
  1314. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  1315. return
  1316. }
  1317. }
  1318. return
  1319. }
  1320. func init300() {
  1321. //var condition string
  1322. //var pars []interface{}
  1323. //
  1324. //{
  1325. // //活动
  1326. // var condition string
  1327. // var pars []interface{}
  1328. // condition = " AND publish_status = 1 AND activity_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'activity') "
  1329. // list, err := cygx.GetActivityListAll(condition, pars, 0, 9999)
  1330. // if err != nil {
  1331. // fmt.Println(err)
  1332. // }
  1333. //
  1334. // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY)
  1335. // //if err != nil {
  1336. // // fmt.Println(err)
  1337. // //}
  1338. // fmt.Println(len(list))
  1339. // for _, v := range list {
  1340. // fmt.Println(v.ActivityId)
  1341. // UpdateActivityResourceData(v.ActivityId)
  1342. // }
  1343. //}
  1344. //12.4
  1345. //{
  1346. // //活动
  1347. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITY)
  1348. // if err != nil {
  1349. // fmt.Println(err)
  1350. // }
  1351. //
  1352. // for _, v := range list {
  1353. // detail, e := cygx.GetAddActivityInfoById(v.SourceId)
  1354. // if e != nil {
  1355. // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  1356. // fmt.Println(err)
  1357. // return
  1358. // }
  1359. // item := new(cygx.CygxResourceData)
  1360. // item.SourceId = v.SourceId
  1361. // item.Source = utils.CYGX_OBJ_ACTIVITY
  1362. // item.ChartPermissionId = detail.ChartPermissionId
  1363. // fmt.Println(v.Source)
  1364. // err = cygx.UpdateChartPermissionIdResourceDataByItem(item)
  1365. // if err != nil {
  1366. // fmt.Println(err)
  1367. // return
  1368. // }
  1369. // }
  1370. //}
  1371. //{
  1372. // //专项调研活动
  1373. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYSPECIAL)
  1374. // if err != nil {
  1375. // fmt.Println(err)
  1376. // }
  1377. // for _, v := range list {
  1378. // fmt.Println(v.Source)
  1379. // UpdateActivitySpecialResourceData(v.SourceId)
  1380. // }
  1381. //}
  1382. //{
  1383. // var condition string
  1384. // var pars []interface{}
  1385. // condition = " AND publish_status = 1 AND article_id NOT IN (SELECT source_id FROM cygx_resource_data WHERE source = 'article') "
  1386. //
  1387. // list, err := cygx.GetArticleRoadshowEssenceList(condition, pars, 0, 9999)
  1388. // if err != nil {
  1389. // fmt.Println(err)
  1390. // return
  1391. // }
  1392. // fmt.Println(len(list))
  1393. // //return
  1394. // //文章
  1395. // //list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE)
  1396. // //if err != nil {
  1397. // // fmt.Println(err)
  1398. // //}
  1399. // for _, v := range list {
  1400. // fmt.Println(v.ArticleId)
  1401. // UpdateArticleResourceData(v.ArticleId)
  1402. // }
  1403. //}
  1404. //{
  1405. // //文章//12.4
  1406. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ARTICLE)
  1407. // if err != nil {
  1408. // fmt.Println(err)
  1409. // return
  1410. // }
  1411. // for _, v := range list {
  1412. // detail, e := cygx.GetArticleDetailByArticleId(v.SourceId)
  1413. // if e != nil {
  1414. // err = errors.New("GetCygxReportSelectionInfoById, Err: " + e.Error())
  1415. // fmt.Println(err)
  1416. // return
  1417. // }
  1418. //
  1419. // item := new(cygx.CygxResourceData)
  1420. // if detail.ArticleTypeId > 0 {
  1421. // //item.SearchTag = detail.ArticleTypeName // 研选类型名称
  1422. // item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  1423. // } else {
  1424. // //item.SearchTag = detail.MatchTypeName
  1425. // //获取文章分类详情
  1426. // detailCategory, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
  1427. // if detailCategory != nil {
  1428. // item.ChartPermissionId = detailCategory.ChartPermissionId
  1429. // }else{
  1430. // detailCategoryTwo, _ := cygx.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryIdTwo)
  1431. // if detailCategoryTwo != nil {
  1432. // item.ChartPermissionId = detailCategoryTwo.ChartPermissionId
  1433. // }
  1434. // }
  1435. // }
  1436. // item.SourceId = v.SourceId
  1437. // item.Source = utils.CYGX_OBJ_ARTICLE
  1438. // fmt.Println(v.Source)
  1439. // err = cygx.UpdateChartPermissionIdResourceDataByItem(item)
  1440. // if err != nil {
  1441. // fmt.Println(err)
  1442. // return
  1443. // }
  1444. // }
  1445. //}
  1446. //{
  1447. // //产品内测
  1448. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_PRODUCTINTERIOR)
  1449. // if err != nil {
  1450. // fmt.Println(err)
  1451. // }
  1452. // for _, v := range list {
  1453. // fmt.Println(v.Source)
  1454. // UpdateProductInteriorResourceData(v.SourceId)
  1455. // }
  1456. //}
  1457. //
  1458. //{
  1459. // //晨会精华
  1460. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT)
  1461. // if err != nil {
  1462. // fmt.Println(err)
  1463. // }
  1464. // for _, v := range list {
  1465. // fmt.Println(v.Source)
  1466. // UpdateMeetingreviewchaptResourceData(v.SourceId)
  1467. // }
  1468. //}
  1469. //
  1470. //{
  1471. // //重点公司
  1472. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_REPORTSELECTION)
  1473. // if err != nil {
  1474. // fmt.Println(err)
  1475. // }
  1476. // for _, v := range list {
  1477. // fmt.Println(v.Source)
  1478. // //UpdateReportSelectionResourceData(v.SourceId)
  1479. // }
  1480. //}
  1481. //
  1482. //{
  1483. // //更新本周研究汇总
  1484. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_RESEARCHSUMMARY)
  1485. // if err != nil {
  1486. // fmt.Println(err)
  1487. // }
  1488. // for _, v := range list {
  1489. // fmt.Println(v.Source)
  1490. // //UpdateResearchSummaryResourceData(v.SourceId)
  1491. // }
  1492. //}
  1493. //
  1494. //{
  1495. // //更新本周研究汇总
  1496. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MINUTESSUMMARY)
  1497. // if err != nil {
  1498. // fmt.Println(err)
  1499. // }
  1500. // for _, v := range list {
  1501. // fmt.Println(v.Source)
  1502. // //UpdateMinutesSummaryResourceData(v.SourceId)
  1503. // }
  1504. //}
  1505. //{
  1506. // //活动音频
  1507. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVOICE)
  1508. // if err != nil {
  1509. // fmt.Println(err)
  1510. // }
  1511. // for _, v := range list {
  1512. // fmt.Println(v.Source)
  1513. // UpdateActivityVoiceResourceData(v.SourceId)
  1514. // }
  1515. //}
  1516. //{
  1517. // //活动视频
  1518. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ACTIVITYVIDEO)
  1519. // if err != nil {
  1520. // fmt.Println(err)
  1521. // }
  1522. // for _, v := range list {
  1523. // fmt.Println(v.SourceId)
  1524. // UpdateActivityVideoResourceData(v.SourceId)
  1525. // }
  1526. //}
  1527. //{
  1528. // //活动音频
  1529. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ROADSHOW)
  1530. // if err != nil {
  1531. // fmt.Println(err)
  1532. // }
  1533. // for _, v := range list {
  1534. // fmt.Println(v.Source)
  1535. // UpdateMicroRoadshowResourceData(v.SourceId)
  1536. // }
  1537. //}
  1538. //{
  1539. // //问答系列视频
  1540. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_ASKSERIEVIDEO)
  1541. // if err != nil {
  1542. // fmt.Println(err)
  1543. // }
  1544. // for _, v := range list {
  1545. // fmt.Println(v.SourceId)
  1546. // UpdateAskserieVideoResourceData(v.SourceId)
  1547. // }
  1548. //}
  1549. //{
  1550. // //晨会精华
  1551. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_MEETINGREVIEWCHAPT)
  1552. // if err != nil {
  1553. // fmt.Println(err)
  1554. // }
  1555. // for _, v := range list {
  1556. // fmt.Println(v.SourceId)
  1557. // UpdateMeetingreviewchaptResourceData(v.SourceId)
  1558. // }
  1559. //}
  1560. //{
  1561. // //研选专栏
  1562. // list, err := cygx.GetCygxResourceDataListBysource(utils.CYGX_OBJ_YANXUANSPECIAL)
  1563. // if err != nil {
  1564. // fmt.Println(err)
  1565. // }
  1566. // for _, v := range list {
  1567. // fmt.Println(v.SourceId)
  1568. // UpdateYanxuanSpecialResourceData(v.SourceId)
  1569. // }
  1570. //}
  1571. }