report_article.go 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/models/system"
  12. "hongze/hz_crm_api/services"
  13. cygxService "hongze/hz_crm_api/services/cygx"
  14. "hongze/hz_crm_api/utils"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 报告管理
  22. type ReportArticleController struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 主题列表
  26. // @Description 获取主题列表接口
  27. // @Param ChartPermissionId query int true "分类ID"
  28. // @Success 200 {object} cygx.CygxReportMappingListRep
  29. // @router /reportMappingist/list [get]
  30. func (this *ReportArticleController) CygxReportMappingist() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. sysUser := this.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. return
  41. }
  42. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  43. if chartPermissionId < 1 {
  44. br.Msg = "请输入分类ID"
  45. return
  46. }
  47. list, err := cygx.CygxReportMappingist(chartPermissionId)
  48. if err != nil {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取失败,Err:" + err.Error()
  51. return
  52. }
  53. resp := new(cygx.CygxReportMappingListRep)
  54. resp.List = list
  55. br.Ret = 200
  56. br.Success = true
  57. br.Msg = "获取成功"
  58. br.Data = resp
  59. }
  60. // @Title 报告匹配类型列表
  61. // @Description 获取报告匹配类型列表接口
  62. // @Success 200 {object} cygx.CygxReportMappingMatchTypeRep
  63. // @Param ChartPermissionId query int true "分类ID"
  64. // @router /reportMappingMatchTypeRep/list [get]
  65. func (this *ReportArticleController) CygxReportMappingMatchTypeList() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. sysUser := this.SysUser
  72. if sysUser == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,SysUser Is Empty"
  75. return
  76. }
  77. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  78. var condition string
  79. var pars []interface{}
  80. if chartPermissionId > 0 {
  81. condition += ` AND chart_permission_id = ? `
  82. pars = append(pars, chartPermissionId)
  83. }
  84. list, err := cygx.GetCygxReportMappingCygxList(condition, pars, 0, 0)
  85. if err != nil {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取失败,Err:" + err.Error()
  88. return
  89. }
  90. resp := new(cygx.CygxCygxReportMappingCygxResp)
  91. resp.List = list
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "获取成功"
  95. br.Data = resp
  96. }
  97. // @Title 报告列表
  98. // @Description 报告列表接口
  99. // @Param PageSize query int true "每页数据条数"
  100. // @Param CurrentIndex query int true "当前页页码,从1开始"
  101. // @Param IsFilter query int true "是否过滤 ,1是,0否,不传默认为0"
  102. // @Param IsClass query int true "是否归类 ,1是,0否 ,不传默认为0"
  103. // @Param ChartPermissionId query int true "行业ID --> 一级分类列表中 ChartPermissionId"
  104. // @Param SubCategoryName query string true "主题"
  105. // @Param MatchTypeName query string true "报告匹配类型"
  106. // @Param IndustrialManagementId int string true "产业ID"
  107. // @Param StartDate query string true "开始时间用0 补齐,列如2021-03-06 08:09:01"
  108. // @Param EndDate query string true "结束时间用0 补齐,列如2021-03-06 08:09:01"
  109. // @Param KeyWord query string true "搜索关键词"
  110. // @Param KeyWordStock query string true "搜索关键词.个股标签,关联标的部分"
  111. // @Success 200 {object} cygx.GetReportArticleListRep
  112. // @router /reportArticle/list [get]
  113. func (this *ReportArticleController) ReportArticleList() {
  114. br := new(models.BaseResponse).Init()
  115. defer func() {
  116. this.Data["json"] = br
  117. this.ServeJSON()
  118. }()
  119. sysUser := this.SysUser
  120. if sysUser == nil {
  121. br.Msg = "请登录"
  122. br.ErrMsg = "请登录,SysUser Is Empty"
  123. return
  124. }
  125. pageSize, _ := this.GetInt("PageSize")
  126. currentIndex, _ := this.GetInt("CurrentIndex")
  127. isFilter, _ := this.GetInt("IsFilter")
  128. isClass, _ := this.GetInt("IsClass")
  129. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  130. subCategoryName := this.GetString("SubCategoryName")
  131. matchTypeName := this.GetString("MatchTypeName")
  132. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  133. startDate := this.GetString("StartDate")
  134. endDate := this.GetString("EndDate")
  135. keyWord := this.GetString("KeyWord")
  136. keyWordStock := this.GetString("KeyWordStock")
  137. reportLabel := this.GetString("ReportLabel") // 查研观向7.4-报告标签
  138. var startSize int
  139. if pageSize <= 0 {
  140. pageSize = utils.PageSize20
  141. }
  142. if currentIndex <= 0 {
  143. currentIndex = 1
  144. }
  145. startSize = utils.StartIndex(currentIndex, pageSize)
  146. var condition string
  147. var pars []interface{}
  148. listPermission, errper := cygx.GetPermissionMappingCategoryID()
  149. if errper != nil {
  150. br.Msg = "获取失败"
  151. br.ErrMsg = "获取失败,Err:" + errper.Error()
  152. return
  153. }
  154. condition += ` AND art.is_report = 1 AND re.id !=28 `
  155. if isClass == 0 {
  156. condition += ` AND art.is_class = 0 `
  157. } else {
  158. condition += ` AND art.is_class = 1 `
  159. if industrialManagementId > 0 {
  160. condition += ` AND man.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
  161. }
  162. }
  163. if keyWord != "" {
  164. condition += ` AND (art.title LIKE '%` + keyWord + `%' ) `
  165. }
  166. //个股标签跟标的的搜索
  167. if keyWordStock != "" {
  168. condition += ` AND (art.stock LIKE '%` + keyWordStock + `%' OR art.article_id IN (SELECT article_id FROM cygx_industrial_article_group_subject WHERE industrial_subject_id IN (SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name LIKE '%` + keyWordStock + `%')) ) `
  169. }
  170. if isFilter == 0 {
  171. condition += ` AND art.is_filter = 0 `
  172. } else {
  173. condition += ` AND art.is_filter = 1 `
  174. }
  175. //行业
  176. if chartPermissionId > 0 {
  177. condition += ` AND re.chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  178. }
  179. //主题
  180. if subCategoryName != "" {
  181. condition += ` AND ret.sub_category_name = ` + "'" + subCategoryName + "' "
  182. }
  183. //发布时间
  184. if startDate != "" {
  185. condition += ` AND art.publish_date >= ` + "'" + startDate + " 00:00:00'"
  186. }
  187. if endDate != "" {
  188. condition += ` AND art.publish_date <= ` + "'" + endDate + " 23:59:59'"
  189. }
  190. //报告匹配类型
  191. if matchTypeName != "" {
  192. condition += ` AND re.match_type_name = ` + "'" + matchTypeName + "' "
  193. }
  194. // 报告标签
  195. if reportLabel != "" {
  196. keywords := "%" + reportLabel + "%"
  197. // 查询包含关键词的产业/标的所关联的报告IDs
  198. artIds, e := cygx.GetArticleIdsFromIndustryAndSubjectGroupByKeyword(keywords)
  199. if e != nil {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "产业/标的关键词获取文章IDs失败, Err:" + e.Error()
  202. return
  203. }
  204. if len(artIds) > 0 {
  205. condition += ` AND art.article_id IN (` + utils.GetOrmInReplace(len(artIds)) + `)`
  206. pars = append(pars, artIds)
  207. }
  208. }
  209. total, err := cygx.GetReportArticleCount(condition, pars)
  210. if err != nil {
  211. br.Msg = "获取失败"
  212. br.ErrMsg = "获取失败,Err:" + err.Error()
  213. return
  214. }
  215. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC `
  216. //fmt.Println(condition)
  217. list, err := cygx.GetReportArticleList(condition, pars, startSize, pageSize, isClass)
  218. if err != nil {
  219. br.Msg = "获取失败"
  220. br.ErrMsg = "获取失败,Err:" + err.Error()
  221. return
  222. }
  223. reportMap := make(map[int]string)
  224. listMap, err := cygx.GetReportMapping()
  225. if err != nil {
  226. br.Msg = "获取失败"
  227. br.ErrMsg = "获取映射分类失败,Err:" + err.Error()
  228. return
  229. }
  230. for _, v := range listMap {
  231. reportMap[v.CategoryId] = v.MatchTypeName
  232. }
  233. var articleIds string
  234. for k, v := range list {
  235. var isShowButton bool
  236. if sysUser.RoleTypeCode == "rai_admin" || sysUser.RoleTypeCode == "rai_researcher" || sysUser.RoleTypeCode == "admin" {
  237. isShowButton = true
  238. } else {
  239. isShowButton = false
  240. }
  241. list[k].MatchTypeName = reportMap[v.CategoryId]
  242. list[k].ShowButton = true
  243. for _, vper := range listPermission {
  244. if v.CategoryId == vper.CategoryId {
  245. isShowButton = false
  246. }
  247. list[k].ShowButton = isShowButton
  248. }
  249. articleIds += strconv.Itoa(v.ArticleId) + ","
  250. }
  251. mapCommment := make(map[int]int)
  252. if articleIds != "" {
  253. articleIds = strings.TrimRight(articleIds, ",")
  254. condition = ` AND art.article_id IN (` + articleIds + `)`
  255. listPv, err := cygx.GetReportArticleListPvUv(condition)
  256. if err != nil {
  257. br.Msg = "获取失败"
  258. br.ErrMsg = "获取PV,Uv 失败,Err:" + err.Error()
  259. return
  260. }
  261. var condition string
  262. var pars []interface{}
  263. condition = ` AND k.article_id IN (` + articleIds + `)`
  264. listComment, err := cygx.GetArticleCommentListSearch(condition, pars)
  265. if err != nil {
  266. br.Msg = "获取失败"
  267. br.ErrMsg = "获取失败,Err:" + err.Error()
  268. return
  269. }
  270. for _, v := range listComment {
  271. mapCommment[v.ArticleId]++
  272. }
  273. if len(listPv) > 0 {
  274. for _, pv := range listPv {
  275. for k, v := range list {
  276. if v.ArticleId == pv.ArticleId {
  277. list[k].Pv = pv.Pv
  278. list[k].Uv = pv.Uv
  279. list[k].ClPv = pv.ClPv
  280. list[k].ClUv = pv.ClUv
  281. list[k].CollectionNum = pv.CollectionNum
  282. }
  283. }
  284. }
  285. }
  286. }
  287. //ListIndustrial []*IndustrialActivityGroupManagementRep
  288. //ListSubject []*SubjectActivityGroupManagementRep
  289. mapIndustrial := make(map[int]string)
  290. mapSubject := make(map[string]string)
  291. mapIndustrialList := make(map[int][]*cygx.IndustrialActivityGroupManagementRep)
  292. mapSubjectList := make(map[int][]*cygx.SubjectActivityGroupManagementRep)
  293. if articleIds != "" {
  294. industrialList, err := cygx.GetIndustrialArticleGroupListByarticleIds(articleIds)
  295. if err != nil {
  296. br.Msg = "获取失败"
  297. br.ErrMsg = "获取失败,GetIndustrialArticleGroupListByarticleIds Err:" + err.Error()
  298. return
  299. }
  300. subjectList, err := cygx.GetSubjectArticleGroupListByarticleIds(articleIds)
  301. if err != nil {
  302. br.Msg = "获取失败"
  303. br.ErrMsg = "获取失败,GetSubjectArticleGroupListByarticleIds Err:" + err.Error()
  304. return
  305. }
  306. //合并活动对应的多个标的
  307. for _, v := range subjectList {
  308. mapSubject[fmt.Sprint(v.ArticleId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  309. itemSubject := new(cygx.SubjectActivityGroupManagementRep)
  310. itemSubject.SubjectName = v.SubjectName
  311. itemSubject.IndustrialSubjectId = v.IndustrialSubjectId
  312. mapSubjectList[v.ArticleId] = append(mapSubjectList[v.ArticleId], itemSubject)
  313. }
  314. //活动对应的产业
  315. for _, v := range industrialList {
  316. var labelSubject string
  317. labelSubject = mapSubject[fmt.Sprint(v.ArticleId, "_", v.IndustrialManagementId)]
  318. if labelSubject != "" {
  319. mapIndustrial[v.ArticleId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  320. } else {
  321. mapIndustrial[v.ArticleId] += v.IndustryName + ","
  322. }
  323. itemindustrial := new(cygx.IndustrialActivityGroupManagementRep)
  324. itemindustrial.IndustryName = v.IndustryName
  325. itemindustrial.IndustrialManagementId = v.IndustrialManagementId
  326. mapIndustrialList[v.ArticleId] = append(mapIndustrialList[v.ArticleId], itemindustrial)
  327. }
  328. }
  329. for k, v := range list {
  330. if mapIndustrial[v.ArticleId] != "" {
  331. list[k].Label = strings.TrimRight(mapIndustrial[v.ArticleId], ",")
  332. }
  333. if v.SubCategoryName == "专项调研" {
  334. v.PublishDate = cygxService.ArticlePublishDate(v.PublishDate)
  335. }
  336. list[k].CommentNum = mapCommment[v.ArticleId]
  337. list[k].ListIndustrial = mapIndustrialList[v.ArticleId]
  338. list[k].ListSubject = mapSubjectList[v.ArticleId]
  339. }
  340. fmt.Println(mapCommment)
  341. page := paging.GetPaging(currentIndex, pageSize, total)
  342. resp := new(cygx.GetReportArticleListRep)
  343. resp.List = list
  344. resp.Paging = page
  345. br.Ret = 200
  346. br.Success = true
  347. br.Msg = "获取成功"
  348. br.Data = resp
  349. }
  350. // @Title 过滤报告
  351. // @Description 过滤报告接口
  352. // @Param ReportId query int true "报告ID"
  353. // @Success Ret=200
  354. // @router /reportArticle/filter [post]
  355. func (this *IndustrialSubjectController) ReportArticleFilter() {
  356. br := new(models.BaseResponse).Init()
  357. defer func() {
  358. this.Data["json"] = br
  359. this.ServeJSON()
  360. }()
  361. sysUser := this.SysUser
  362. if sysUser == nil {
  363. br.Msg = "请登录"
  364. br.ErrMsg = "请登录,SysUser Is Empty"
  365. br.Ret = 408
  366. return
  367. }
  368. //if sysUser.RoleTypeCode != "rai_admin" && sysUser.RoleTypeCode != "rai_researcher" && sysUser.RoleTypeCode != "admin" {
  369. // br.Msg = "你没有操作权限请联系管理员"
  370. // return
  371. //}
  372. var req cygx.CygxReportArticleID
  373. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  374. if err != nil {
  375. br.Msg = "参数解析异常!"
  376. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  377. return
  378. }
  379. reportId := req.ReportId
  380. reportInfo, err := cygx.GetReportArticleId(reportId)
  381. if reportInfo == nil {
  382. br.Msg = "报告ID不存在!"
  383. return
  384. }
  385. if err != nil {
  386. br.Msg = "过滤失败!"
  387. br.ErrMsg = "过滤失败,Err:" + err.Error()
  388. return
  389. }
  390. if reportInfo.IsFilter == 1 {
  391. br.Msg = "您已过滤请勿重复操作!"
  392. return
  393. }
  394. if reportInfo.ReportType != 2 {
  395. br.Msg = "操作失败!"
  396. br.ErrMsg = "报告类型不属于产业报告!"
  397. return
  398. }
  399. err = cygx.FilterReportArticle(reportId)
  400. if err != nil {
  401. br.Msg = "过滤失败"
  402. br.ErrMsg = "过滤失败,Err:" + err.Error()
  403. return
  404. }
  405. br.Ret = 200
  406. br.Success = true
  407. br.Msg = "过滤成功"
  408. br.IsAddLog = true
  409. }
  410. // @Title 报告归类
  411. // @Description 报告归类接口
  412. // @Param request body cygx.ReportArticleClassificationResp true "type json string"
  413. // @Success Ret=200
  414. // @router /reportArticle/classification [post]
  415. func (this *IndustrialSubjectController) ReportArticleClassification() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. //if sysUser.RoleTypeCode != "rai_admin" && sysUser.RoleTypeCode != "rai_researcher" && sysUser.RoleTypeCode != "admin" {
  429. // br.Msg = "你没有操作权限请联系管理员"
  430. // return
  431. //}
  432. var req cygx.ReportArticleClassificationResp
  433. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  434. if err != nil {
  435. br.Msg = "参数解析异常!"
  436. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  437. return
  438. }
  439. var pars []interface{}
  440. var condition string
  441. reportId := req.ReportId
  442. industrialManagementIdStr := req.IndustrialManagementId
  443. reportInfo, _ := cygx.GetReportArticleId(reportId)
  444. if reportInfo == nil {
  445. br.Msg = "报告ID不存在!"
  446. return
  447. }
  448. if reportInfo.ReportType != 2 {
  449. br.Msg = "操作失败!"
  450. br.ErrMsg = "报告类型不属于产业报告!"
  451. return
  452. }
  453. industrialStrList := strings.Split(industrialManagementIdStr, ",")
  454. for _, v := range industrialStrList {
  455. condition = `AND industrial_management_id = ` + v
  456. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  457. if totalIndustrialManagement < 1 {
  458. br.Msg = "操作失败"
  459. br.ErrMsg = "操作失败,产业不存在IndustrialManagementId:" + v
  460. return
  461. }
  462. }
  463. if req.IndustrialSubjectIdStr != "0" && req.IndustrialSubjectIdStr != "" {
  464. strList := strings.Split(req.IndustrialSubjectIdStr, ",")
  465. for _, v := range strList {
  466. condition = `AND industrial_subject_id = ` + v + ` AND industrial_management_id IN ( ` + industrialManagementIdStr + `)`
  467. totalIndustrialSubject, _ := cygx.GetIndustrialSubjectCount(condition, pars)
  468. if totalIndustrialSubject < 1 {
  469. br.Msg = "操作失败"
  470. br.ErrMsg = "操作失败,标的不存在IndustrialSubjectId:" + v
  471. return
  472. }
  473. }
  474. }
  475. err = cygx.ReportArticleClassificationEditNew(req.ReportId, industrialManagementIdStr, reportInfo.ArticleId, req.IndustrialSubjectIdStr)
  476. if err != nil {
  477. br.Msg = "分类失败"
  478. br.ErrMsg = "分类失败,Err:" + err.Error()
  479. return
  480. }
  481. go cygxService.DoArticleOnenIdWxTemplateMsg(reportInfo.ArticleId, 2)
  482. br.Ret = 200
  483. br.Success = true
  484. br.Msg = "分类成功"
  485. br.IsAddLog = true
  486. }
  487. // @Title 是否展示操作按钮
  488. // @Description 获取是否展示操作按钮接口
  489. // @Success Ret=200 {object} cygx.ShowButton
  490. // @router /reportArticle/showButton [get]
  491. func (this *IndustrialSubjectController) ShowButton() {
  492. br := new(models.BaseResponse).Init()
  493. defer func() {
  494. this.Data["json"] = br
  495. this.ServeJSON()
  496. }()
  497. sysUser := this.SysUser
  498. if sysUser == nil {
  499. br.Msg = "请登录"
  500. br.ErrMsg = "请登录,SysUser Is Empty"
  501. return
  502. }
  503. resp := new(cygx.ShowButton)
  504. if sysUser.RoleTypeCode == "rai_admin" || sysUser.RoleTypeCode == "rai_researcher" || sysUser.RoleTypeCode == "admin" {
  505. resp.IsShowButton = true
  506. }
  507. br.Ret = 200
  508. br.Success = true
  509. br.Msg = "获取成功"
  510. br.Data = resp
  511. }
  512. // @Title 下载阅读明细
  513. // @Description 获取下载阅读明细接口
  514. // @Param ReportId query int true "报告ID"
  515. // @Success Ret=200
  516. // @router /reportArticle/export [get]
  517. func (this *IndustrialSubjectController) Export() {
  518. br := new(models.BaseResponse).Init()
  519. defer func() {
  520. this.Data["json"] = br
  521. this.ServeJSON()
  522. }()
  523. sysUser := this.SysUser
  524. if sysUser == nil {
  525. br.Msg = "请登录"
  526. br.ErrMsg = "请登录,SysUser Is Empty"
  527. return
  528. }
  529. reportId, _ := this.GetInt("ReportId")
  530. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  531. resp := new(cygx.CanDownload)
  532. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  533. if errAdmin != nil {
  534. br.Msg = "获取失败"
  535. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  536. return
  537. }
  538. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  539. resp.IsCanDownload = true
  540. }
  541. var list []*cygx.ReportExportRep
  542. var err error
  543. if resp.IsCanDownload == false {
  544. if adminInfo.RoleTypeCode == "rai_group" {
  545. //if sysUser.Authority == 2 {
  546. //组长查看本组所有组员
  547. //fmt.Println("组长")
  548. sqlStr := ` AND h.user_id IN (SELECT user_id FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(sysUser.AdminId) + ` ) )) `
  549. listSeller, errSeller := cygx.GetReportExportRep(reportId, sqlStr)
  550. list = listSeller
  551. err = errSeller
  552. } else {
  553. //组员查看自己
  554. //fmt.Println("组员")
  555. sqlStr := ` AND h.user_id IN (SELECT user_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(sysUser.AdminId) + `) `
  556. listSeller, errSeller := cygx.GetReportExportRep(reportId, sqlStr)
  557. list = listSeller
  558. err = errSeller
  559. }
  560. } else {
  561. sqlStr := ""
  562. listAdmin, errAdmin := cygx.GetReportExportRep(reportId, sqlStr)
  563. list = listAdmin
  564. err = errAdmin
  565. }
  566. if err != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取失败,Err:" + err.Error()
  569. return
  570. }
  571. var listNew []*cygx.ReportExportRep
  572. for k, v := range list {
  573. if k > 0 && list[k].Id == list[k-1].Id {
  574. list[k-1].SellerName = list[k-1].SellerName + "/" + v.SellerName
  575. }
  576. }
  577. for k, v := range list {
  578. if k > 0 && list[k].Id != list[k-1].Id {
  579. listNew = append(listNew, v)
  580. }
  581. }
  582. //创建excel
  583. dir, err := os.Executable()
  584. exPath := filepath.Dir(dir)
  585. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  586. xlsxFile := xlsx.NewFile()
  587. if err != nil {
  588. br.Msg = "生成文件失败"
  589. br.ErrMsg = "生成文件失败"
  590. return
  591. }
  592. style := xlsx.NewStyle()
  593. alignment := xlsx.Alignment{
  594. Horizontal: "center",
  595. Vertical: "center",
  596. WrapText: true,
  597. }
  598. style.Alignment = alignment
  599. style.ApplyAlignment = true
  600. sheet, err := xlsxFile.AddSheet("关键词搜索统计")
  601. if err != nil {
  602. br.Msg = "新增Sheet失败"
  603. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  604. return
  605. }
  606. //标头
  607. rowTitle := sheet.AddRow()
  608. cellA := rowTitle.AddCell()
  609. cellA.Value = "姓名"
  610. cellB := rowTitle.AddCell()
  611. cellB.Value = "公司名"
  612. cellC := rowTitle.AddCell()
  613. cellC.Value = "销售名称"
  614. cellD := rowTitle.AddCell()
  615. cellD.Value = "阅读时间"
  616. cellE := rowTitle.AddCell()
  617. cellE.Value = "停留时间(s)"
  618. for _, item := range listNew {
  619. row := sheet.AddRow()
  620. cellA := row.AddCell()
  621. cellA.Value = item.RealName
  622. cellB := row.AddCell()
  623. cellB.Value = item.CompanyName
  624. cellC := row.AddCell()
  625. cellC.Value = item.SellerName
  626. cellD := row.AddCell()
  627. cellD.Value = item.CreateTime
  628. cellE := row.AddCell()
  629. cellE.Value = item.StopTime
  630. }
  631. err = xlsxFile.Save(downLoadnFilePath)
  632. if err != nil {
  633. br.Msg = "保存文件失败"
  634. br.ErrMsg = "保存文件失败"
  635. return
  636. }
  637. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  638. downloadFileName := "阅读明细统计列表" + randStr + ".xlsx"
  639. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  640. defer func() {
  641. os.Remove(downLoadnFilePath)
  642. }()
  643. br.Ret = 200
  644. br.Success = true
  645. br.Msg = "导出成功"
  646. }
  647. // @Title 通过报告ID获取对应的匹配类型
  648. // @Description 通过报告ID获取对应的匹配类型接口
  649. // @Param ReportId query int true "报告ID"
  650. // @Success 200 {object} cygx.ReportMatchTypeNameList
  651. // @router /reportArticle/getMatchTypeName [get]
  652. func (this *IndustrialSubjectController) GetMatchTypeNameByReportId() {
  653. br := new(models.BaseResponse).Init()
  654. defer func() {
  655. this.Data["json"] = br
  656. this.ServeJSON()
  657. }()
  658. sysUser := this.SysUser
  659. if sysUser == nil {
  660. br.Msg = "请登录"
  661. br.ErrMsg = "请登录,SysUser Is Empty"
  662. return
  663. }
  664. reportId, _ := this.GetInt("ReportId")
  665. detail, err := cygx.GetArticleDetailById(reportId)
  666. if err != nil {
  667. br.Msg = "获取信息失败"
  668. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  669. return
  670. }
  671. list, err := cygx.GetMatchTypeName(detail.CategoryId)
  672. if err != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  675. return
  676. }
  677. resp := new(cygx.ReportMatchTypeNameList)
  678. resp.List = list
  679. br.Ret = 200
  680. br.Success = true
  681. br.Msg = "获取成功"
  682. br.Data = resp
  683. }
  684. // @Title 修改报告的匹配类型
  685. // @Description 修改报告的匹配类型接口
  686. // @Param request body cygx.UpdateReportMatchTypeNameRep true "type json string"
  687. // @Success Ret=200
  688. // @router /reportArticle/updateMatchTypeName [post]
  689. func (this *IndustrialSubjectController) UpdateMatchTypeName() {
  690. br := new(models.BaseResponse).Init()
  691. defer func() {
  692. this.Data["json"] = br
  693. this.ServeJSON()
  694. }()
  695. sysUser := this.SysUser
  696. if sysUser == nil {
  697. br.Msg = "请登录"
  698. br.ErrMsg = "请登录,SysUser Is Empty"
  699. return
  700. }
  701. var req cygx.UpdateReportMatchTypeNameRep
  702. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  703. reportId := req.ReportId
  704. if err != nil {
  705. br.Msg = "参数解析异常!"
  706. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  707. return
  708. }
  709. detail, err := cygx.GetMatchTypeNameById(req.MatchID)
  710. if err != nil {
  711. br.Msg = "获取信息失败"
  712. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  713. return
  714. }
  715. detailArt, err := cygx.GetArticleDetailById(reportId)
  716. if err != nil {
  717. br.Msg = "获取信息失败"
  718. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  719. return
  720. }
  721. err = cygx.UpdateReportMatchTypeName(detail.MatchTypeName, detail.ReportType, detail.CategoryId, req.ReportId, detailArt.IsSummary, detailArt.IsClass)
  722. if err != nil {
  723. br.Msg = "修改失败"
  724. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  725. return
  726. }
  727. go cygxService.DoArticleOnenIdWxTemplateMsg(detailArt.ArticleId, 2)
  728. go cygxService.AddCygxReportMappingCategoryGroupByArticleId(detailArt.ArticleId) // 手动修改报告归类
  729. br.Ret = 200
  730. br.Success = true
  731. br.Msg = "修改成功"
  732. br.IsAddLog = true
  733. }
  734. // @Title 报告内容的保存与发布
  735. // @Description 报告内容的保存与发布接口
  736. // @Param request body cygx.ReportAddRep true "type json string"
  737. // @Success 200 操作成功
  738. // @router /reportArticle/PreserveAndPublish [post]
  739. func (this *ReportArticleController) PreserveAndPublish() {
  740. br := new(models.BaseResponse).Init()
  741. defer func() {
  742. this.Data["json"] = br
  743. this.ServeJSON()
  744. }()
  745. AdminUser := this.SysUser
  746. if AdminUser == nil {
  747. br.Msg = "请登录"
  748. br.ErrMsg = "请登录,用户信息为空"
  749. br.Ret = 408
  750. return
  751. }
  752. var req cygx.ReportAddRep
  753. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  754. if err != nil {
  755. br.Msg = "参数解析异常!"
  756. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  757. return
  758. }
  759. if req.Title == "" {
  760. br.Msg = "标题不可为空"
  761. br.ErrMsg = "标题不可为空"
  762. return
  763. }
  764. if req.Abstract == "" {
  765. br.Msg = "摘要不可为空"
  766. br.ErrMsg = "摘要不可为空"
  767. return
  768. }
  769. var articleId int
  770. industrialManagementIds := req.IndustrialManagementIds
  771. industrialSubjectIds := req.IndustrialSubjectIds
  772. chartPermissionId := req.ChartPermissionId
  773. publishDate := req.PublishDate
  774. if industrialManagementIds == "" {
  775. br.Msg = "请选择产业"
  776. return
  777. }
  778. if publishDate == "" {
  779. br.Msg = "请选择发布时间"
  780. return
  781. }
  782. industryIds := make([]int, 0)
  783. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  784. for _, v := range industrialManagementIdList {
  785. i, err := strconv.Atoi(v)
  786. if err != nil {
  787. br.Msg = "参数解析异常!"
  788. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIds
  789. return
  790. }
  791. industryIds = append(industryIds, i)
  792. }
  793. if industrialSubjectIds != "" {
  794. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  795. for _, v := range industrialSubjectIdList {
  796. _, err := strconv.Atoi(v)
  797. if err != nil {
  798. br.Msg = "参数解析异常!"
  799. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIds
  800. return
  801. }
  802. }
  803. }
  804. var pars []interface{}
  805. var condition string
  806. condition += ` AND chart_permission_id = ? AND sub_category_name = '专项调研' `
  807. pars = append(pars, chartPermissionId)
  808. charInfo, err := cygx.GetReportMappingDetail(condition, pars)
  809. if err != nil {
  810. br.Msg = "请选择所属行业"
  811. br.ErrMsg = "获取所属行业信息失败,Err:" + err.Error()
  812. return
  813. }
  814. var articleIdNew int
  815. if articleId == 0 {
  816. maxArticleIdArticleInfo, errMax := cygx.GetMaxArticleIdInfo()
  817. if errMax != nil {
  818. br.Msg = "发布失败"
  819. br.ErrMsg = "发布失败,Err:" + errMax.Error()
  820. return
  821. }
  822. if maxArticleIdArticleInfo.ArticleId < utils.SummaryArticleId {
  823. articleIdNew = utils.SummaryArticleId
  824. } else {
  825. articleIdNew = maxArticleIdArticleInfo.ArticleId + 1
  826. }
  827. }
  828. expertNumStr, expertContentStr, interviewDateStr, fileLink := cygx.BodyAnalysis(req.Body)
  829. item := new(cygx.CygxArticle)
  830. item.AdminId = AdminUser.AdminId
  831. item.AdminName = AdminUser.AdminName
  832. item.Title = req.Title
  833. item.Body = cygxService.GetRichtext(req.Body)
  834. item.BodyText, _ = cygx.GetReportContentTextSub(item.Body)
  835. item.Abstract = req.Abstract
  836. item.CategoryName = charInfo.MatchTypeName
  837. item.SubCategoryName = charInfo.SubCategoryName
  838. item.ArticleId = articleId
  839. item.CreateDate = time.Now()
  840. item.LastUpdatedTime = time.Now()
  841. item.IsReport = 1
  842. item.IsSummary = 1
  843. item.Source = 1
  844. item.IsClass = 1
  845. item.IsReport = 1
  846. item.ReportType = 2
  847. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdNew))
  848. item.UpdateFrequency = "unknow"
  849. item.SellerAndMobile = req.SellerAndMobile
  850. item.ExpertBackground = expertContentStr
  851. item.ExpertNumber = expertNumStr
  852. item.InterviewDate = interviewDateStr
  853. item.FileLink = fileLink
  854. item.CategoryId = charInfo.CategoryId
  855. item.CategoryIdTwo = charInfo.CategoryId
  856. item.ChartPermissionIds = strconv.Itoa(chartPermissionId)
  857. item.PublishDate = utils.StrTimeToTime(publishDate + " 00:00:00") //时间字符串格式转时间格式
  858. //处理作者内容的格式信息
  859. if req.DoType == 1 {
  860. item.PublishStatus = 1
  861. }
  862. itemDepartment := new(cygx.CygxArticleDepartment)
  863. if req.ArticleId == 0 {
  864. item.ArticleId = articleIdNew
  865. //需求修改纪要的新增与修改与报告一致
  866. _, err := cygx.AddAReportrticle(item, 0, "", "", itemDepartment, industrialManagementIds, industrialSubjectIds)
  867. if err != nil {
  868. br.Msg = "发布失败"
  869. br.ErrMsg = "发布失败,Err:" + err.Error()
  870. return
  871. }
  872. } else {
  873. articleInfo, err := cygx.GetArticleIdInfoByArticleId(req.ArticleId)
  874. if err != nil {
  875. br.Msg = "文章不存在"
  876. return
  877. }
  878. if item.PublishStatus == 0 {
  879. item.PublishStatus = articleInfo.PublishStatus
  880. }
  881. item.ArticleId = req.ArticleId
  882. err = cygx.EditReportrticle(item, 0, "", "", articleInfo.PublishStatus, itemDepartment, industrialManagementIds, industrialSubjectIds)
  883. if err != nil {
  884. br.Msg = "发布失败"
  885. br.ErrMsg = "发布失败,Err:" + err.Error()
  886. return
  887. }
  888. }
  889. //if req.DoType == 1 {
  890. // go cygxService.DoArticleOnenIdWxTemplateMsg(articleId, 1)
  891. //}
  892. //{|1|}表示报告类型,{|2|}表示纪要类型
  893. //cygx.UpdateSubjecIds(subjectIds+"—"+strconv.Itoa(industrialDetail.IndustrialManagementId)+"{|2|}", industrialDetail.IndustrialManagementId, articleId)
  894. if item.PublishStatus == 1 {
  895. services.EsAddOrEditData(item)
  896. go cygxService.UpdateResourceData(item.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  897. }
  898. // 查研观向7.4-更新产业布局时间
  899. if len(industryIds) > 0 {
  900. go cygxService.UpdateIndustryLayoutTime(industryIds, false)
  901. }
  902. if len(industryIds) > 0 && req.DoType == 1 {
  903. //查研观向8.2.1专项调研报告模板消息推送
  904. cygxService.SendWxMsgWithCygxActivitySpecialArticle(item.ArticleId)
  905. }
  906. br.Ret = 200
  907. br.Success = true
  908. br.Msg = "操作成功"
  909. br.IsAddLog = true
  910. }
  911. // @Title 报告详情
  912. // @Description 获取报告详情接口
  913. // @Param ReportId query int true "报告ID"
  914. // @Success Ret=200 {object} cygx.CygxArticleReport
  915. // @router /reportArticle/detail [get]
  916. func (this *ReportArticleController) Detail() {
  917. br := new(models.BaseResponse).Init()
  918. defer func() {
  919. this.Data["json"] = br
  920. this.ServeJSON()
  921. }()
  922. AdminUser := this.SysUser
  923. if AdminUser == nil {
  924. br.Msg = "请登录"
  925. br.ErrMsg = "请登录,用户信息为空"
  926. br.Ret = 408
  927. return
  928. }
  929. //reportId, _ := this.GetInt("ReportId")
  930. //if reportId < 1 {
  931. // br.Msg = "请输入报告ID"
  932. // return
  933. //}
  934. //articleInfo, err := cygx.GetArticleIdInfoByreportIdEdit(reportId)
  935. //if err != nil {
  936. // br.Msg = "报告不存在"
  937. // br.ErrMsg = "报告ID错误,Err:" + err.Error()
  938. // return
  939. //}
  940. articleId, _ := this.GetInt("ArticleId")
  941. if articleId < 1 {
  942. br.Msg = "请输入文章ID"
  943. return
  944. }
  945. articleInfo, err := cygx.GetArticleIdInfoByreportIdEdit(articleId)
  946. if err != nil {
  947. br.Msg = "文章内容不存在"
  948. br.ErrMsg = "纪要ID错误,Err:" + err.Error()
  949. return
  950. }
  951. industrialList, err := cygx.GetIndustrialArticleGroupManagementList(articleInfo.ArticleId)
  952. if err != nil && err.Error() != utils.ErrNoRow() {
  953. br.Msg = "获取信息失败"
  954. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(articleInfo.ArticleId)
  955. return
  956. }
  957. subjectList, err := cygx.GetSubjectArticleGroupManagementList(articleInfo.ArticleId)
  958. if err != nil && err.Error() != utils.ErrNoRow() {
  959. br.Msg = "获取信息失败"
  960. br.ErrMsg = "获取活动关联的标的列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(articleInfo.ArticleId)
  961. return
  962. }
  963. articleInfo.PublishDate = cygxService.ArticlePublishDate(articleInfo.PublishDate)
  964. articleInfo.ListIndustrial = industrialList
  965. articleInfo.ListSubject = subjectList
  966. if articleInfo.ChartPermissionIds != "" {
  967. chartPermissionIdArr := strings.Split(articleInfo.ChartPermissionIds, ",")
  968. if len(chartPermissionIdArr) > 0 {
  969. articleInfo.ChartPermissionId, _ = strconv.Atoi(chartPermissionIdArr[0])
  970. }
  971. }
  972. br.Ret = 200
  973. br.Success = true
  974. br.Msg = "获取成功"
  975. br.Data = articleInfo
  976. }
  977. // @Title 获取作者列表
  978. // @Description 获取作者列表接口
  979. // @Param KeyWord query string true "搜索关键词"
  980. // @Success Ret=200 {object} cygx.CygxArticleDepartmentList
  981. // @router /reportArticle/departmentList [get]
  982. func (this *ReportArticleController) DepartmentList() {
  983. br := new(models.BaseResponse).Init()
  984. defer func() {
  985. this.Data["json"] = br
  986. this.ServeJSON()
  987. }()
  988. sysUser := this.SysUser
  989. if sysUser == nil {
  990. br.Msg = "请登录"
  991. br.ErrMsg = "请登录,SysUser Is Empty"
  992. br.Ret = 408
  993. return
  994. }
  995. var condition string
  996. keyWord := this.GetString("KeyWord")
  997. if keyWord != "" {
  998. condition = `WHERE nick_name LIKE'%` + keyWord + `%' ORDER BY create_time DESC `
  999. } else {
  1000. condition += ` ORDER BY create_time DESC`
  1001. }
  1002. list, err := cygx.GetCygxArticleDepartmentList(condition)
  1003. if err != nil {
  1004. br.Msg = "获取失败"
  1005. br.ErrMsg = "获取失败,Err:" + err.Error()
  1006. return
  1007. }
  1008. resp := new(cygx.CygxArticleDepartmentList)
  1009. resp.List = list
  1010. br.Ret = 200
  1011. br.Success = true
  1012. br.Msg = "获取成功"
  1013. br.Data = resp
  1014. }
  1015. // @Title 下载客户阅读记录
  1016. // @Description 下载客户阅读记录接口
  1017. // @Param CompanyId query int true "公司ID"
  1018. // @Success Ret=200
  1019. // @router /reportArticle/companyHistory [get]
  1020. func (this *IndustrialSubjectController) CompanyHistory() {
  1021. br := new(models.BaseResponse).Init()
  1022. defer func() {
  1023. this.Data["json"] = br
  1024. this.ServeJSON()
  1025. }()
  1026. sysUser := this.SysUser
  1027. if sysUser == nil {
  1028. br.Msg = "请登录"
  1029. br.ErrMsg = "请登录,SysUser Is Empty"
  1030. return
  1031. }
  1032. companyId, _ := this.GetInt("CompanyId")
  1033. if companyId < 1 {
  1034. br.Msg = "请输入公司ID"
  1035. return
  1036. }
  1037. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1038. var isCanDownload bool
  1039. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1040. if err != nil {
  1041. br.Msg = "获取失败"
  1042. br.ErrMsg = "获取失败,Err:" + err.Error()
  1043. return
  1044. }
  1045. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1046. isCanDownload = true
  1047. }
  1048. if !isCanDownload {
  1049. br.Msg = "暂无下载权限"
  1050. return
  1051. }
  1052. //获取企业客户信息
  1053. companyInfo, err := company.GetCompanyById(companyId)
  1054. if err != nil {
  1055. br.Msg = "获取失败"
  1056. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1057. return
  1058. }
  1059. mapChartPermissionName := make(map[int]string)
  1060. listMap, err := cygx.GetPermissionMappingCategoryAll()
  1061. if err != nil {
  1062. br.Msg = "获取失败"
  1063. br.ErrMsg = "获取失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. for _, v := range listMap {
  1067. mapChartPermissionName[v.CategoryId] = v.ChartPermissionName
  1068. }
  1069. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1070. if err != nil && err.Error() != utils.ErrNoRow() {
  1071. br.Msg = "获取信息失败"
  1072. br.ErrMsg = "获取客户手机号信息失败,Err:" + err.Error()
  1073. return
  1074. }
  1075. if mobiles != "" {
  1076. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1077. mobiles = "'" + mobiles + "'"
  1078. } else {
  1079. mobiles = "'1'"
  1080. }
  1081. emails, err := models.GetCompanyUserEmailsByCompanyId(companyId)
  1082. if err != nil && err.Error() != utils.ErrNoRow() {
  1083. br.Msg = "获取信息失败"
  1084. br.ErrMsg = "获取客户邮箱信息失败,Err:" + err.Error()
  1085. return
  1086. }
  1087. if emails != "" {
  1088. emails = strings.Replace(emails, ",", "','", -1)
  1089. emails = "'" + emails + "'"
  1090. } else {
  1091. emails = "'1'"
  1092. }
  1093. list, err := cygx.GetCompanyHistoryRecordNewPv(mobiles, emails)
  1094. if err != nil {
  1095. br.Msg = "获取失败"
  1096. br.ErrMsg = "获取失败,Err:" + err.Error()
  1097. return
  1098. }
  1099. for k, v := range list {
  1100. list[k].PermissionName = mapChartPermissionName[v.CategoryId]
  1101. }
  1102. //创建excel
  1103. dir, err := os.Executable()
  1104. exPath := filepath.Dir(dir)
  1105. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1106. xlsxFile := xlsx.NewFile()
  1107. if err != nil {
  1108. br.Msg = "生成文件失败"
  1109. br.ErrMsg = "生成文件失败"
  1110. return
  1111. }
  1112. style := xlsx.NewStyle()
  1113. alignment := xlsx.Alignment{
  1114. Horizontal: "center",
  1115. Vertical: "center",
  1116. WrapText: true,
  1117. }
  1118. style.Alignment = alignment
  1119. style.ApplyAlignment = true
  1120. sheet, err := xlsxFile.AddSheet("客户阅读记录")
  1121. if err != nil {
  1122. br.Msg = "新增Sheet失败"
  1123. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1124. return
  1125. }
  1126. //标头
  1127. rowTitle := sheet.AddRow()
  1128. cellA := rowTitle.AddCell()
  1129. cellA.Value = "姓名"
  1130. cellB := rowTitle.AddCell()
  1131. cellB.Value = "手机号/邮箱"
  1132. cellC := rowTitle.AddCell()
  1133. cellC.Value = "报告标题"
  1134. cellD := rowTitle.AddCell()
  1135. cellD.Value = "所属行业"
  1136. cellE := rowTitle.AddCell()
  1137. cellE.Value = "所属产业"
  1138. cellF := rowTitle.AddCell()
  1139. cellF.Value = "关联标的"
  1140. cellG := rowTitle.AddCell()
  1141. cellG.Value = "发布时间"
  1142. cellH := rowTitle.AddCell()
  1143. cellH.Value = "阅读时间"
  1144. cellI := rowTitle.AddCell()
  1145. cellI.Value = "阅读时长"
  1146. for _, item := range list {
  1147. row := sheet.AddRow()
  1148. cellA := row.AddCell()
  1149. cellA.Value = item.RealName
  1150. cellB := row.AddCell()
  1151. cellB.Value = item.Mobile
  1152. if item.Mobile == "" {
  1153. cellB.Value = item.Email
  1154. }
  1155. cellC := row.AddCell()
  1156. cellC.Value = item.Title
  1157. cellD := row.AddCell()
  1158. if item.CategoryId == 0 {
  1159. cellD.Value = "研选"
  1160. } else {
  1161. cellD.Value = item.PermissionName
  1162. }
  1163. cellE := row.AddCell()
  1164. cellE.Value = item.IndustryName
  1165. cellF := row.AddCell()
  1166. cellF.Value = item.SubjectNameStr
  1167. cellG := row.AddCell()
  1168. cellG.Value = item.PublishDate
  1169. cellH := row.AddCell()
  1170. cellH.Value = item.CreateTime
  1171. cellI := row.AddCell()
  1172. cellI.Value = item.StopTime
  1173. }
  1174. err = xlsxFile.Save(downLoadnFilePath)
  1175. if err != nil {
  1176. br.Msg = "保存文件失败"
  1177. br.ErrMsg = "保存文件失败"
  1178. return
  1179. }
  1180. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1181. downloadFileName := companyInfo.CompanyName + "阅读记录" + randStr + ".xlsx"
  1182. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1183. defer func() {
  1184. os.Remove(downLoadnFilePath)
  1185. }()
  1186. br.Ret = 200
  1187. br.Success = true
  1188. br.Msg = "导出成功"
  1189. }
  1190. // @Title 客户其他行为数据
  1191. // @Description 下载客户其他行为数据接口
  1192. // @Param CompanyId query int true "公司ID"
  1193. // @Success Ret=200
  1194. // @router /reportArticle/companyOtherHistory [get]
  1195. func (this *IndustrialSubjectController) CompanyOtherHistory() {
  1196. br := new(models.BaseResponse).Init()
  1197. defer func() {
  1198. this.Data["json"] = br
  1199. this.ServeJSON()
  1200. }()
  1201. sysUser := this.SysUser
  1202. if sysUser == nil {
  1203. br.Msg = "请登录"
  1204. br.ErrMsg = "请登录,SysUser Is Empty"
  1205. return
  1206. }
  1207. companyId, _ := this.GetInt("CompanyId")
  1208. if companyId <= 0 {
  1209. br.Msg = "请选择客户"
  1210. br.ErrMsg = "客户参数错误"
  1211. return
  1212. }
  1213. //获取企业客户信息
  1214. companyInfo, err := company.GetCompanyById(companyId)
  1215. if err != nil {
  1216. br.Msg = "获取失败"
  1217. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1218. return
  1219. }
  1220. var condition string
  1221. var pars []interface{}
  1222. //非管理员,那么只能看到该产品下的联系人
  1223. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1224. productId := services.GetProductId(sysUser.RoleTypeCode)
  1225. condition += ` AND b.product_id = ? `
  1226. pars = append(pars, productId)
  1227. //流失客户(除非是超级管理员或者是部门管理员,要不然不允许看对应的联系人)
  1228. var companyProduct *company.CompanyProduct
  1229. if productId == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1230. // 当前是权益权限,且非 权益管理员
  1231. tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
  1232. companyProduct = tmpCompanyProduct
  1233. if companyProduct != nil && companyProduct.Status == utils.COMPANY_STATUS_LOSE {
  1234. condition += ` AND seller_id=? `
  1235. pars = append(pars, sysUser.AdminId)
  1236. }
  1237. }
  1238. }
  1239. list, err := company.GetCompanyUserListV2(condition, pars, companyId, 0, 1000)
  1240. if err != nil {
  1241. br.Msg = "获取失败"
  1242. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1243. return
  1244. }
  1245. var userIdstr string
  1246. for _, v := range list {
  1247. userIdstr += strconv.Itoa(int(v.UserId)) + ","
  1248. }
  1249. userIdstr = strings.TrimRight(userIdstr, ",")
  1250. resp := new(cygx.CompanyOtherHistoryListResp)
  1251. condition = ` AND user_id IN (` + userIdstr + `)`
  1252. listArticle, err := cygx.GetArticleCollectList(condition)
  1253. if err != nil {
  1254. br.Msg = "获取失败"
  1255. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. listIndustry, err := cygx.GetCygxIndustryList(companyId)
  1259. if err != nil {
  1260. br.Msg = "获取失败"
  1261. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1262. return
  1263. }
  1264. listDepartment, err := cygx.GetArticleDepartmentList(companyId)
  1265. if err != nil {
  1266. br.Msg = "获取失败"
  1267. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1268. return
  1269. }
  1270. //listkeyWord, err := cygx.GetCygxUserSearchKeyWordList(userIdstr)
  1271. //if err != nil {
  1272. // br.Msg = "获取失败"
  1273. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1274. // return
  1275. //}
  1276. //listkeyWord, err := cygx.GetCygxUserSearchKeyWordList(userIdstr)
  1277. //if err != nil {
  1278. // br.Msg = "获取失败"
  1279. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1280. // return
  1281. //}
  1282. for _, v := range list {
  1283. userItem := new(cygx.CompanyOtherHistoryList)
  1284. var artItems []*cygx.CygxArticleCollect
  1285. var industryItems []*cygx.CygxArticleIndustry
  1286. var departmentItems []*cygx.ArticleDepartment
  1287. //var keyWordItems []*cygx.KeyWord
  1288. for _, vArt := range listArticle {
  1289. if vArt.UserId == int(v.UserId) {
  1290. artItems = append(artItems, vArt)
  1291. }
  1292. }
  1293. for _, vIn := range listIndustry {
  1294. if vIn.UserId == int(v.UserId) {
  1295. industryItems = append(industryItems, vIn)
  1296. }
  1297. }
  1298. for _, vDe := range listDepartment {
  1299. if vDe.UserId == int(v.UserId) {
  1300. departmentItems = append(departmentItems, vDe)
  1301. }
  1302. }
  1303. //for _, vKw := range listkeyWord {
  1304. // if vKw.UserId == int(v.UserId) {
  1305. // keyWordItems = append(keyWordItems, vKw)
  1306. // }
  1307. //}
  1308. if len(artItems) > 0 || len(industryItems) > 0 || len(departmentItems) > 0 {
  1309. userItem.RealName = v.RealName
  1310. userItem.Email = v.Email
  1311. userItem.Mobile = v.Mobile
  1312. userItem.ListArticle = artItems
  1313. userItem.ListIndustrial = industryItems
  1314. userItem.ListDepartment = departmentItems
  1315. //userItem.ListKeyWord = keyWordItems
  1316. resp.List = append(resp.List, userItem)
  1317. }
  1318. }
  1319. //创建excel
  1320. dir, err := os.Executable()
  1321. exPath := filepath.Dir(dir)
  1322. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1323. xlsxFile := xlsx.NewFile()
  1324. if err != nil {
  1325. br.Msg = "生成文件失败"
  1326. br.ErrMsg = "生成文件失败"
  1327. return
  1328. }
  1329. style := xlsx.NewStyle()
  1330. alignment := xlsx.Alignment{
  1331. Horizontal: "center",
  1332. Vertical: "center",
  1333. WrapText: true,
  1334. }
  1335. style.Alignment = alignment
  1336. style.ApplyAlignment = true
  1337. sheet, err := xlsxFile.AddSheet("客户其他行为数据(收藏,关注)")
  1338. if err != nil {
  1339. br.Msg = "新增Sheet失败"
  1340. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1341. return
  1342. }
  1343. //标题样式
  1344. titleStyle := xlsx.NewStyle()
  1345. titleFont := xlsx.NewFont(16, "宋体")
  1346. titleFont.Bold = true
  1347. titleStyle.Font = *titleFont
  1348. titleStyle.Alignment = alignment
  1349. sheet.SetColWidth(0, 0, 20)
  1350. sheet.SetColWidth(1, 1, 20)
  1351. sheet.SetColWidth(2, 2, 20)
  1352. sheet.SetColWidth(3, 3, 20)
  1353. sheet.SetColWidth(4, 4, 20)
  1354. titleSonStyle := xlsx.NewStyle()
  1355. titleSonFont := xlsx.NewFont(16, "宋体")
  1356. titleSonFont.Bold = true
  1357. titleSonStyle.Font = *titleSonFont
  1358. for _, item := range resp.List {
  1359. rowTitle := sheet.AddRow()
  1360. //标题列
  1361. titleCell := rowTitle.AddCell()
  1362. titleCell.HMerge = 6 //向右合并列数,不包括自身列
  1363. titleCell.SetValue("客户姓名:" + item.RealName + " 手机号/邮箱:" + item.Mobile)
  1364. titleCell.SetStyle(titleStyle)
  1365. //文章
  1366. if len(item.ListArticle) > 0 {
  1367. rowArticle := sheet.AddRow()
  1368. cellA := rowArticle.AddCell()
  1369. cellA.Value = "收藏报告"
  1370. cellB := rowArticle.AddCell()
  1371. cellB.Value = "收藏时间"
  1372. cellC := rowArticle.AddCell()
  1373. cellC.Value = "发布时间"
  1374. cellD := rowArticle.AddCell()
  1375. cellD.Value = "报告类型"
  1376. cellE := rowArticle.AddCell()
  1377. cellE.Value = "所属产业"
  1378. cellF := rowArticle.AddCell()
  1379. cellF.Value = "关联标的"
  1380. cellA.SetStyle(titleSonStyle)
  1381. cellB.SetStyle(titleSonStyle)
  1382. cellC.SetStyle(titleSonStyle)
  1383. cellD.SetStyle(titleSonStyle)
  1384. cellE.SetStyle(titleSonStyle)
  1385. cellF.SetStyle(titleSonStyle)
  1386. for _, vArt := range item.ListArticle {
  1387. rowArticleVal := sheet.AddRow()
  1388. cellA := rowArticleVal.AddCell()
  1389. cellA.Value = vArt.Title
  1390. cellB := rowArticleVal.AddCell()
  1391. cellB.Value = vArt.CreateTime
  1392. cellC := rowArticleVal.AddCell()
  1393. cellC.Value = vArt.PublishDate
  1394. cellD := rowArticleVal.AddCell()
  1395. cellD.Value = vArt.MatchTypeName
  1396. cellE := rowArticleVal.AddCell()
  1397. cellE.Value = vArt.IndustryName
  1398. cellF := rowArticleVal.AddCell()
  1399. cellF.Value = vArt.SubjectName
  1400. }
  1401. }
  1402. //产业
  1403. if len(item.ListIndustrial) > 0 {
  1404. rowIndustrial := sheet.AddRow()
  1405. cellA := rowIndustrial.AddCell()
  1406. cellA.Value = "关注产业"
  1407. cellB := rowIndustrial.AddCell()
  1408. cellB.Value = "关注时间"
  1409. cellA.SetStyle(titleSonStyle)
  1410. cellB.SetStyle(titleSonStyle)
  1411. for _, vArt := range item.ListIndustrial {
  1412. rowIndustrialVal := sheet.AddRow()
  1413. cellA := rowIndustrialVal.AddCell()
  1414. cellA.Value = vArt.IndustryName
  1415. cellB := rowIndustrialVal.AddCell()
  1416. cellB.Value = vArt.CreateTime
  1417. }
  1418. }
  1419. //作者
  1420. if len(item.ListDepartment) > 0 {
  1421. rowDepartment := sheet.AddRow()
  1422. cellA := rowDepartment.AddCell()
  1423. cellA.Value = "关注作者"
  1424. cellB := rowDepartment.AddCell()
  1425. cellB.Value = "关注时间"
  1426. cellC := rowDepartment.AddCell()
  1427. cellC.Value = "作者相关产业"
  1428. cellA.SetStyle(titleSonStyle)
  1429. cellB.SetStyle(titleSonStyle)
  1430. cellC.SetStyle(titleSonStyle)
  1431. for _, vArt := range item.ListDepartment {
  1432. rowDepartmentVal := sheet.AddRow()
  1433. cellA := rowDepartmentVal.AddCell()
  1434. cellA.Value = vArt.NickName
  1435. cellB := rowDepartmentVal.AddCell()
  1436. cellB.Value = vArt.CreateTime
  1437. cellC := rowDepartmentVal.AddCell()
  1438. cellC.Value = vArt.IndustryName
  1439. }
  1440. }
  1441. }
  1442. err = xlsxFile.Save(downLoadnFilePath)
  1443. if err != nil {
  1444. br.Msg = "保存文件失败"
  1445. br.ErrMsg = "保存文件失败"
  1446. return
  1447. }
  1448. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1449. downloadFileName := companyInfo.CompanyName + "其他行为数据(收藏,关注)" + randStr + ".xlsx"
  1450. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1451. defer func() {
  1452. os.Remove(downLoadnFilePath)
  1453. }()
  1454. br.Ret = 200
  1455. br.Data = resp
  1456. br.Success = true
  1457. br.Msg = "导出成功"
  1458. }
  1459. // @Title 客户阅读量月度统计
  1460. // @Description 客户阅读量月度统计
  1461. // @Param CompanyId query int true "公司ID"
  1462. // @Success Ret=200
  1463. // @router /reportArticle/companyCount [get]
  1464. func (this *IndustrialSubjectController) CompanyCount() {
  1465. br := new(models.BaseResponse).Init()
  1466. defer func() {
  1467. this.Data["json"] = br
  1468. this.ServeJSON()
  1469. }()
  1470. sysUser := this.SysUser
  1471. if sysUser == nil {
  1472. br.Msg = "请登录"
  1473. br.ErrMsg = "请登录,SysUser Is Empty"
  1474. return
  1475. }
  1476. companyId, _ := this.GetInt("CompanyId")
  1477. if companyId < 1 {
  1478. br.Msg = "请输入公司ID"
  1479. return
  1480. }
  1481. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1482. var isCanDownload bool
  1483. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1484. if err != nil {
  1485. br.Msg = "获取失败"
  1486. br.ErrMsg = "获取失败,Err:" + err.Error()
  1487. return
  1488. }
  1489. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1490. isCanDownload = true
  1491. }
  1492. if !isCanDownload {
  1493. br.Msg = "暂无下载权限"
  1494. return
  1495. }
  1496. //获取企业客户信息
  1497. companyInfo, err := company.GetCompanyById(companyId)
  1498. if err != nil {
  1499. br.Msg = "获取失败"
  1500. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1501. return
  1502. }
  1503. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1504. if err != nil && err.Error() != utils.ErrNoRow() {
  1505. br.Msg = "获取信息失败"
  1506. br.ErrMsg = "获取客户手机号信息失败,Err:" + err.Error()
  1507. return
  1508. }
  1509. if mobiles != "" {
  1510. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1511. mobiles = "'" + mobiles + "'"
  1512. } else {
  1513. mobiles = "'1'"
  1514. }
  1515. emails, err := models.GetCompanyUserEmailsByCompanyId(companyId)
  1516. if err != nil && err.Error() != utils.ErrNoRow() {
  1517. br.Msg = "获取信息失败"
  1518. br.ErrMsg = "获取客户邮箱信息失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. if emails != "" {
  1522. emails = strings.Replace(emails, ",", "','", -1)
  1523. emails = "'" + emails + "'"
  1524. } else {
  1525. emails = "'1'"
  1526. }
  1527. listDate, err := cygx.GetCompanyHistoryRecordPvGroupDate(mobiles, emails)
  1528. if err != nil {
  1529. br.Msg = "获取失败"
  1530. br.ErrMsg = "获取失败,Err:" + err.Error()
  1531. return
  1532. }
  1533. dateMap := make(map[string]int)
  1534. permissionNameMap := make(map[string]int)
  1535. list, err := cygx.GetCompanyHistoryRecordPv(mobiles, emails)
  1536. if err != nil {
  1537. br.Msg = "获取失败"
  1538. br.ErrMsg = "获取失败,Err:" + err.Error()
  1539. return
  1540. }
  1541. for _, v := range list {
  1542. if dateMap[v.CreateTime] == 0 {
  1543. dateMap[v.CreateTime] = 1
  1544. } else {
  1545. dateMap[v.CreateTime] += 1
  1546. }
  1547. if v.CategoryId == 0 {
  1548. v.PermissionName = "研选"
  1549. }
  1550. if permissionNameMap[v.CreateTime+v.PermissionName] == 0 {
  1551. permissionNameMap[v.CreateTime+v.PermissionName] = 1
  1552. } else {
  1553. permissionNameMap[v.CreateTime+v.PermissionName] += 1
  1554. }
  1555. }
  1556. //创建excel
  1557. dir, err := os.Executable()
  1558. exPath := filepath.Dir(dir)
  1559. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1560. xlsxFile := xlsx.NewFile()
  1561. if err != nil {
  1562. br.Msg = "生成文件失败"
  1563. br.ErrMsg = "生成文件失败"
  1564. return
  1565. }
  1566. style := xlsx.NewStyle()
  1567. alignment := xlsx.Alignment{
  1568. Horizontal: "center",
  1569. Vertical: "center",
  1570. WrapText: true,
  1571. }
  1572. style.Alignment = alignment
  1573. style.ApplyAlignment = true
  1574. sheet, err := xlsxFile.AddSheet("客户阅读量月度统计")
  1575. if err != nil {
  1576. br.Msg = "新增Sheet失败"
  1577. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1578. return
  1579. }
  1580. //标头
  1581. rowTitle := sheet.AddRow()
  1582. cellA := rowTitle.AddCell()
  1583. cellA.Value = "月份"
  1584. cellB := rowTitle.AddCell()
  1585. cellB.Value = "总阅读数"
  1586. cellC := rowTitle.AddCell()
  1587. cellC.Value = "医药"
  1588. cellD := rowTitle.AddCell()
  1589. cellD.Value = "消费"
  1590. cellE := rowTitle.AddCell()
  1591. cellE.Value = "科技"
  1592. cellF := rowTitle.AddCell()
  1593. cellF.Value = "智造"
  1594. cellG := rowTitle.AddCell()
  1595. cellG.Value = "策略"
  1596. cellH := rowTitle.AddCell()
  1597. cellH.Value = "研选"
  1598. for _, item := range listDate {
  1599. row := sheet.AddRow()
  1600. cellA := row.AddCell()
  1601. cellA.Value = item.CreateTimes
  1602. cellB := row.AddCell()
  1603. cellB.Value = strconv.Itoa(dateMap[item.CreateTimes])
  1604. cellC := row.AddCell()
  1605. cellC.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"医药"])
  1606. cellD := row.AddCell()
  1607. cellD.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"消费"])
  1608. cellE := row.AddCell()
  1609. cellE.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"科技"])
  1610. cellF := row.AddCell()
  1611. cellF.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"智造"])
  1612. cellG := row.AddCell()
  1613. cellG.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"策略"])
  1614. cellH := row.AddCell()
  1615. cellH.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"研选"])
  1616. }
  1617. err = xlsxFile.Save(downLoadnFilePath)
  1618. if err != nil {
  1619. br.Msg = "保存文件失败"
  1620. br.ErrMsg = "保存文件失败"
  1621. return
  1622. }
  1623. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1624. downloadFileName := companyInfo.CompanyName + "客户阅读量月度统计" + randStr + ".xlsx"
  1625. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1626. defer func() {
  1627. os.Remove(downLoadnFilePath)
  1628. }()
  1629. br.Ret = 200
  1630. br.Success = true
  1631. br.Msg = "导出成功"
  1632. }
  1633. // @Title 客户导出文件种类
  1634. // @Description 客户导出文件种类接口
  1635. // @Success Ret=200 {object} cygx.NameAndUrlList
  1636. // @router /company/exportList [get]
  1637. func (this *ReportArticleController) ExportList() {
  1638. br := new(models.BaseResponse).Init()
  1639. defer func() {
  1640. this.Data["json"] = br
  1641. this.ServeJSON()
  1642. }()
  1643. sysUser := this.SysUser
  1644. if sysUser == nil {
  1645. br.Msg = "请登录"
  1646. br.ErrMsg = "请登录,SysUser Is Empty"
  1647. br.Ret = 408
  1648. return
  1649. }
  1650. detail, err := cygx.GetCygxConfigDetailByCode("export_list")
  1651. if err != nil {
  1652. br.Msg = "获取失败"
  1653. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1654. return
  1655. }
  1656. resp := new(cygx.NameAndUrlList)
  1657. exportList := strings.Split(detail.ConfigValue, "{|}")
  1658. for _, v := range exportList {
  1659. item := new(cygx.NameAndUrl)
  1660. vslice := strings.Split(v, "_")
  1661. item.Name = vslice[0]
  1662. item.Url = vslice[len(vslice)-1]
  1663. resp.List = append(resp.List, item)
  1664. }
  1665. br.Ret = 200
  1666. br.Success = true
  1667. br.Msg = "获取成功"
  1668. br.Data = resp
  1669. }
  1670. // @Title 留言列表详情
  1671. // @Description 获取留言列表详情接口
  1672. // @Param ArticleId query int true "文章ID"
  1673. // @Success 200 {object} cygx.ArticleCommentListResp
  1674. // @router /reportArticle/commentList [get]
  1675. func (this *ReportArticleController) CommentList() {
  1676. br := new(models.BaseResponse).Init()
  1677. defer func() {
  1678. this.Data["json"] = br
  1679. this.ServeJSON()
  1680. }()
  1681. sysUser := this.SysUser
  1682. if sysUser == nil {
  1683. br.Msg = "请登录"
  1684. br.ErrMsg = "请登录,SysUser Is Empty"
  1685. return
  1686. }
  1687. articleId, _ := this.GetInt("ArticleId")
  1688. articleInfo, _ := cygx.GetArticleIdInfoByArticleId(articleId)
  1689. if articleInfo == nil {
  1690. br.Msg = "操作失败"
  1691. br.ErrMsg = "报告ID错误"
  1692. return
  1693. }
  1694. list, err := cygx.GetArticleCommentList(articleInfo.ArticleId)
  1695. resp := new(cygx.ArticleCommentListResp)
  1696. if err != nil {
  1697. br.Msg = "获取留言失败"
  1698. br.ErrMsg = "获取留言失败,Err:" + err.Error()
  1699. return
  1700. }
  1701. resp.List = list
  1702. br.Ret = 200
  1703. br.Success = true
  1704. br.Msg = "获取成功"
  1705. br.Data = resp
  1706. }
  1707. // @Title 提问详情excel表格下载
  1708. // @Description 提问详情excel表格下载接口
  1709. // @Param SummaryManageId query int true "纪要ID"
  1710. // @Success 200 导出成功
  1711. // @router /reportArticle/commnetListExport [get]
  1712. func (this *ReportArticleController) CommentListExport() {
  1713. br := new(models.BaseResponse).Init()
  1714. defer func() {
  1715. this.Data["json"] = br
  1716. this.ServeJSON()
  1717. }()
  1718. sysUser := this.SysUser
  1719. if sysUser == nil {
  1720. br.Msg = "请登录"
  1721. br.ErrMsg = "请登录,SysUser Is Empty"
  1722. return
  1723. }
  1724. articleId, _ := this.GetInt("ArticleId")
  1725. articleInfo, _ := cygx.GetArticleIdInfoByArticleId(articleId)
  1726. if articleInfo == nil {
  1727. br.Msg = "操作失败"
  1728. br.ErrMsg = "报告ID错误"
  1729. return
  1730. }
  1731. list, err := cygx.GetArticleCommentList(articleInfo.ArticleId)
  1732. if err != nil {
  1733. br.Msg = "获取失败"
  1734. br.ErrMsg = "获取失败,Err:" + err.Error()
  1735. return
  1736. }
  1737. //创建excel
  1738. dir, err := os.Executable()
  1739. exPath := filepath.Dir(dir)
  1740. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1741. xlsxFile := xlsx.NewFile()
  1742. if err != nil {
  1743. br.Msg = "生成文件失败"
  1744. br.ErrMsg = "生成文件失败"
  1745. return
  1746. }
  1747. style := xlsx.NewStyle()
  1748. alignment := xlsx.Alignment{
  1749. Horizontal: "center",
  1750. Vertical: "center",
  1751. WrapText: true,
  1752. }
  1753. style.Alignment = alignment
  1754. style.ApplyAlignment = true
  1755. sheet, err := xlsxFile.AddSheet("名单")
  1756. if err != nil {
  1757. br.Msg = "新增Sheet失败"
  1758. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1759. return
  1760. }
  1761. //标头
  1762. rowTitle := sheet.AddRow()
  1763. cellA := rowTitle.AddCell()
  1764. cellA.Value = "姓名"
  1765. cellB := rowTitle.AddCell()
  1766. cellB.Value = "公司名称"
  1767. cellC := rowTitle.AddCell()
  1768. cellC.Value = "留言"
  1769. cellD := rowTitle.AddCell()
  1770. cellD.Value = "提交时间"
  1771. for _, item := range list {
  1772. row := sheet.AddRow()
  1773. cellA := row.AddCell()
  1774. cellA.Value = item.RealName
  1775. cellB := row.AddCell()
  1776. cellB.Value = item.CompanyName
  1777. cellC := row.AddCell()
  1778. cellC.Value = item.Content
  1779. cellD := row.AddCell()
  1780. cellD.Value = item.CreateTime
  1781. }
  1782. err = xlsxFile.Save(downLoadnFilePath)
  1783. if err != nil {
  1784. br.Msg = "保存文件失败"
  1785. br.ErrMsg = "保存文件失败"
  1786. return
  1787. }
  1788. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1789. downloadFileName := "留言列表" + randStr + ".xlsx"
  1790. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1791. defer func() {
  1792. os.Remove(downLoadnFilePath)
  1793. }()
  1794. br.Success = true
  1795. br.Ret = 200
  1796. br.Msg = "导出成功"
  1797. }
  1798. // @Title 新建报告类型
  1799. // @Description 新建报告类型接口
  1800. // @Param request body cygx.CygxReportMappingCygxAdd true "type json string"
  1801. // @Success Ret=200 {object} cygx.CygxReportMappingCygx
  1802. // @router /reportMapping/add [post]
  1803. func (this *IndustrialSubjectController) ReportMappingAdd() {
  1804. br := new(models.BaseResponse).Init()
  1805. defer func() {
  1806. this.Data["json"] = br
  1807. this.ServeJSON()
  1808. }()
  1809. sysUser := this.SysUser
  1810. if sysUser == nil {
  1811. br.Msg = "请登录"
  1812. br.ErrMsg = "请登录,SysUser Is Empty"
  1813. br.Ret = 408
  1814. return
  1815. }
  1816. var req cygx.CygxReportMappingCygxAdd
  1817. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1818. if err != nil {
  1819. br.Msg = "参数解析异常!"
  1820. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1821. return
  1822. }
  1823. var condition string
  1824. var pars []interface{}
  1825. reportType := req.ReportType
  1826. chartPermissionId := req.ChartPermissionId
  1827. chartPermissionName := req.ChartPermissionName
  1828. matchTypeName := req.MatchTypeName
  1829. condition = ` AND match_type_name = ? AND chart_permission_id = ? `
  1830. pars = append(pars, matchTypeName, chartPermissionId)
  1831. total, err := cygx.GetCygxReportMappingCygxCount(condition, pars)
  1832. if err != nil {
  1833. br.Msg = "新建报告类型失败"
  1834. br.ErrMsg = "新建报告类型失败,Err:" + err.Error()
  1835. return
  1836. }
  1837. if total > 0 {
  1838. br.Msg = "名称已存在"
  1839. br.ErrMsg = "名称已存在,Err:" + matchTypeName
  1840. return
  1841. }
  1842. maxDeatil, err := cygx.GetCygxReportMappingCelueMaxDetail()
  1843. if err != nil {
  1844. br.Msg = "新建报告类型失败"
  1845. br.ErrMsg = "GetCygxReportMappingCelueMaxDetail,Err:" + err.Error()
  1846. return
  1847. }
  1848. itemCygx := new(cygx.CygxReportMappingCygx)
  1849. itemCygx.ChartPermissionId = chartPermissionId
  1850. itemCygx.ChartPermissionName = chartPermissionName
  1851. itemCygx.MatchTypeName = matchTypeName
  1852. itemCygx.ReportType = reportType
  1853. itemCygx.IsReport = 1
  1854. itemCygx.CreateTime = time.Now()
  1855. itemCygx.ModifyTime = time.Now()
  1856. itemCelue := new(cygx.CygxReportMappingCelue)
  1857. itemCelue.ChartPermissionId = chartPermissionId
  1858. itemCelue.ChartPermissionName = chartPermissionName
  1859. itemCelue.SubCategoryName = matchTypeName
  1860. itemCelue.ReportType = reportType
  1861. itemCelue.IsReport = 1
  1862. itemCelue.CategoryId = maxDeatil.CategoryId + 1
  1863. itemCelue.CreateTime = time.Now()
  1864. itemCelue.ModifyTime = time.Now()
  1865. itemCygxId, err := cygx.AddCygxReportMappingCygx(itemCygx, itemCelue)
  1866. if err != nil {
  1867. br.Msg = "新建报告类型失败"
  1868. br.ErrMsg = "AddCygxReportMappingCygx,Err:" + err.Error()
  1869. return
  1870. }
  1871. resp := new(cygx.CygxReportMappingCygx)
  1872. resp.Id = int(itemCygxId)
  1873. resp.MatchTypeName = matchTypeName
  1874. br.Ret = 200
  1875. br.Success = true
  1876. br.Data = resp
  1877. br.Msg = "分类成功"
  1878. br.IsAddLog = true
  1879. }