report_article.go 59 KB

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