report_article.go 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  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. go cygxService.AddCygxReportMappingCategoryGroupByArticleId(item.ArticleId) // 手动修改报告归类
  907. br.Ret = 200
  908. br.Success = true
  909. br.Msg = "操作成功"
  910. br.IsAddLog = true
  911. }
  912. // @Title 报告详情
  913. // @Description 获取报告详情接口
  914. // @Param ReportId query int true "报告ID"
  915. // @Success Ret=200 {object} cygx.CygxArticleReport
  916. // @router /reportArticle/detail [get]
  917. func (this *ReportArticleController) Detail() {
  918. br := new(models.BaseResponse).Init()
  919. defer func() {
  920. this.Data["json"] = br
  921. this.ServeJSON()
  922. }()
  923. AdminUser := this.SysUser
  924. if AdminUser == nil {
  925. br.Msg = "请登录"
  926. br.ErrMsg = "请登录,用户信息为空"
  927. br.Ret = 408
  928. return
  929. }
  930. //reportId, _ := this.GetInt("ReportId")
  931. //if reportId < 1 {
  932. // br.Msg = "请输入报告ID"
  933. // return
  934. //}
  935. //articleInfo, err := cygx.GetArticleIdInfoByreportIdEdit(reportId)
  936. //if err != nil {
  937. // br.Msg = "报告不存在"
  938. // br.ErrMsg = "报告ID错误,Err:" + err.Error()
  939. // return
  940. //}
  941. articleId, _ := this.GetInt("ArticleId")
  942. if articleId < 1 {
  943. br.Msg = "请输入文章ID"
  944. return
  945. }
  946. articleInfo, err := cygx.GetArticleIdInfoByreportIdEdit(articleId)
  947. if err != nil {
  948. br.Msg = "文章内容不存在"
  949. br.ErrMsg = "纪要ID错误,Err:" + err.Error()
  950. return
  951. }
  952. industrialList, err := cygx.GetIndustrialArticleGroupManagementList(articleInfo.ArticleId)
  953. if err != nil && err.Error() != utils.ErrNoRow() {
  954. br.Msg = "获取信息失败"
  955. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(articleInfo.ArticleId)
  956. return
  957. }
  958. subjectList, err := cygx.GetSubjectArticleGroupManagementList(articleInfo.ArticleId)
  959. if err != nil && err.Error() != utils.ErrNoRow() {
  960. br.Msg = "获取信息失败"
  961. br.ErrMsg = "获取活动关联的标的列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(articleInfo.ArticleId)
  962. return
  963. }
  964. articleInfo.PublishDate = cygxService.ArticlePublishDate(articleInfo.PublishDate)
  965. articleInfo.ListIndustrial = industrialList
  966. articleInfo.ListSubject = subjectList
  967. if articleInfo.ChartPermissionIds != "" {
  968. chartPermissionIdArr := strings.Split(articleInfo.ChartPermissionIds, ",")
  969. if len(chartPermissionIdArr) > 0 {
  970. articleInfo.ChartPermissionId, _ = strconv.Atoi(chartPermissionIdArr[0])
  971. }
  972. }
  973. br.Ret = 200
  974. br.Success = true
  975. br.Msg = "获取成功"
  976. br.Data = articleInfo
  977. }
  978. // @Title 获取作者列表
  979. // @Description 获取作者列表接口
  980. // @Param KeyWord query string true "搜索关键词"
  981. // @Success Ret=200 {object} cygx.CygxArticleDepartmentList
  982. // @router /reportArticle/departmentList [get]
  983. func (this *ReportArticleController) DepartmentList() {
  984. br := new(models.BaseResponse).Init()
  985. defer func() {
  986. this.Data["json"] = br
  987. this.ServeJSON()
  988. }()
  989. sysUser := this.SysUser
  990. if sysUser == nil {
  991. br.Msg = "请登录"
  992. br.ErrMsg = "请登录,SysUser Is Empty"
  993. br.Ret = 408
  994. return
  995. }
  996. var condition string
  997. keyWord := this.GetString("KeyWord")
  998. if keyWord != "" {
  999. condition = `WHERE nick_name LIKE'%` + keyWord + `%' ORDER BY create_time DESC `
  1000. } else {
  1001. condition += ` ORDER BY create_time DESC`
  1002. }
  1003. list, err := cygx.GetCygxArticleDepartmentList(condition)
  1004. if err != nil {
  1005. br.Msg = "获取失败"
  1006. br.ErrMsg = "获取失败,Err:" + err.Error()
  1007. return
  1008. }
  1009. resp := new(cygx.CygxArticleDepartmentList)
  1010. resp.List = list
  1011. br.Ret = 200
  1012. br.Success = true
  1013. br.Msg = "获取成功"
  1014. br.Data = resp
  1015. }
  1016. // @Title 下载客户阅读记录
  1017. // @Description 下载客户阅读记录接口
  1018. // @Param CompanyId query int true "公司ID"
  1019. // @Success Ret=200
  1020. // @router /reportArticle/companyHistory [get]
  1021. func (this *IndustrialSubjectController) CompanyHistory() {
  1022. br := new(models.BaseResponse).Init()
  1023. defer func() {
  1024. this.Data["json"] = br
  1025. this.ServeJSON()
  1026. }()
  1027. sysUser := this.SysUser
  1028. if sysUser == nil {
  1029. br.Msg = "请登录"
  1030. br.ErrMsg = "请登录,SysUser Is Empty"
  1031. return
  1032. }
  1033. companyId, _ := this.GetInt("CompanyId")
  1034. if companyId < 1 {
  1035. br.Msg = "请输入公司ID"
  1036. return
  1037. }
  1038. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1039. var isCanDownload bool
  1040. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1041. if err != nil {
  1042. br.Msg = "获取失败"
  1043. br.ErrMsg = "获取失败,Err:" + err.Error()
  1044. return
  1045. }
  1046. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1047. isCanDownload = true
  1048. }
  1049. if !isCanDownload {
  1050. br.Msg = "暂无下载权限"
  1051. return
  1052. }
  1053. //获取企业客户信息
  1054. companyInfo, err := company.GetCompanyById(companyId)
  1055. if err != nil {
  1056. br.Msg = "获取失败"
  1057. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. mapChartPermissionName := make(map[int]string)
  1061. listMap, err := cygx.GetPermissionMappingCategoryAll()
  1062. if err != nil {
  1063. br.Msg = "获取失败"
  1064. br.ErrMsg = "获取失败,Err:" + err.Error()
  1065. return
  1066. }
  1067. for _, v := range listMap {
  1068. mapChartPermissionName[v.CategoryId] = v.ChartPermissionName
  1069. }
  1070. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1071. if err != nil && err.Error() != utils.ErrNoRow() {
  1072. br.Msg = "获取信息失败"
  1073. br.ErrMsg = "获取客户手机号信息失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. if mobiles != "" {
  1077. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1078. mobiles = "'" + mobiles + "'"
  1079. } else {
  1080. mobiles = "'1'"
  1081. }
  1082. emails, err := models.GetCompanyUserEmailsByCompanyId(companyId)
  1083. if err != nil && err.Error() != utils.ErrNoRow() {
  1084. br.Msg = "获取信息失败"
  1085. br.ErrMsg = "获取客户邮箱信息失败,Err:" + err.Error()
  1086. return
  1087. }
  1088. if emails != "" {
  1089. emails = strings.Replace(emails, ",", "','", -1)
  1090. emails = "'" + emails + "'"
  1091. } else {
  1092. emails = "'1'"
  1093. }
  1094. list, err := cygx.GetCompanyHistoryRecordNewPv(mobiles, emails)
  1095. if err != nil {
  1096. br.Msg = "获取失败"
  1097. br.ErrMsg = "获取失败,Err:" + err.Error()
  1098. return
  1099. }
  1100. for k, v := range list {
  1101. list[k].PermissionName = mapChartPermissionName[v.CategoryId]
  1102. }
  1103. //创建excel
  1104. dir, err := os.Executable()
  1105. exPath := filepath.Dir(dir)
  1106. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1107. xlsxFile := xlsx.NewFile()
  1108. if err != nil {
  1109. br.Msg = "生成文件失败"
  1110. br.ErrMsg = "生成文件失败"
  1111. return
  1112. }
  1113. style := xlsx.NewStyle()
  1114. alignment := xlsx.Alignment{
  1115. Horizontal: "center",
  1116. Vertical: "center",
  1117. WrapText: true,
  1118. }
  1119. style.Alignment = alignment
  1120. style.ApplyAlignment = true
  1121. sheet, err := xlsxFile.AddSheet("客户阅读记录")
  1122. if err != nil {
  1123. br.Msg = "新增Sheet失败"
  1124. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1125. return
  1126. }
  1127. //标头
  1128. rowTitle := sheet.AddRow()
  1129. cellA := rowTitle.AddCell()
  1130. cellA.Value = "姓名"
  1131. cellB := rowTitle.AddCell()
  1132. cellB.Value = "手机号/邮箱"
  1133. cellC := rowTitle.AddCell()
  1134. cellC.Value = "报告标题"
  1135. cellD := rowTitle.AddCell()
  1136. cellD.Value = "所属行业"
  1137. cellE := rowTitle.AddCell()
  1138. cellE.Value = "所属产业"
  1139. cellF := rowTitle.AddCell()
  1140. cellF.Value = "关联标的"
  1141. cellG := rowTitle.AddCell()
  1142. cellG.Value = "发布时间"
  1143. cellH := rowTitle.AddCell()
  1144. cellH.Value = "阅读时间"
  1145. cellI := rowTitle.AddCell()
  1146. cellI.Value = "阅读时长"
  1147. for _, item := range list {
  1148. row := sheet.AddRow()
  1149. cellA := row.AddCell()
  1150. cellA.Value = item.RealName
  1151. cellB := row.AddCell()
  1152. cellB.Value = item.Mobile
  1153. if item.Mobile == "" {
  1154. cellB.Value = item.Email
  1155. }
  1156. cellC := row.AddCell()
  1157. cellC.Value = item.Title
  1158. cellD := row.AddCell()
  1159. if item.CategoryId == 0 {
  1160. cellD.Value = "研选"
  1161. } else {
  1162. cellD.Value = item.PermissionName
  1163. }
  1164. cellE := row.AddCell()
  1165. cellE.Value = item.IndustryName
  1166. cellF := row.AddCell()
  1167. cellF.Value = item.SubjectNameStr
  1168. cellG := row.AddCell()
  1169. cellG.Value = item.PublishDate
  1170. cellH := row.AddCell()
  1171. cellH.Value = item.CreateTime
  1172. cellI := row.AddCell()
  1173. cellI.Value = item.StopTime
  1174. }
  1175. err = xlsxFile.Save(downLoadnFilePath)
  1176. if err != nil {
  1177. br.Msg = "保存文件失败"
  1178. br.ErrMsg = "保存文件失败"
  1179. return
  1180. }
  1181. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1182. downloadFileName := companyInfo.CompanyName + "阅读记录" + randStr + ".xlsx"
  1183. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1184. defer func() {
  1185. os.Remove(downLoadnFilePath)
  1186. }()
  1187. br.Ret = 200
  1188. br.Success = true
  1189. br.Msg = "导出成功"
  1190. }
  1191. // @Title 客户其他行为数据
  1192. // @Description 下载客户其他行为数据接口
  1193. // @Param CompanyId query int true "公司ID"
  1194. // @Success Ret=200
  1195. // @router /reportArticle/companyOtherHistory [get]
  1196. func (this *IndustrialSubjectController) CompanyOtherHistory() {
  1197. br := new(models.BaseResponse).Init()
  1198. defer func() {
  1199. this.Data["json"] = br
  1200. this.ServeJSON()
  1201. }()
  1202. sysUser := this.SysUser
  1203. if sysUser == nil {
  1204. br.Msg = "请登录"
  1205. br.ErrMsg = "请登录,SysUser Is Empty"
  1206. return
  1207. }
  1208. companyId, _ := this.GetInt("CompanyId")
  1209. if companyId <= 0 {
  1210. br.Msg = "请选择客户"
  1211. br.ErrMsg = "客户参数错误"
  1212. return
  1213. }
  1214. //获取企业客户信息
  1215. companyInfo, err := company.GetCompanyById(companyId)
  1216. if err != nil {
  1217. br.Msg = "获取失败"
  1218. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1219. return
  1220. }
  1221. var condition string
  1222. var pars []interface{}
  1223. //非管理员,那么只能看到该产品下的联系人
  1224. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1225. productId := services.GetProductId(sysUser.RoleTypeCode)
  1226. condition += ` AND b.product_id = ? `
  1227. pars = append(pars, productId)
  1228. //流失客户(除非是超级管理员或者是部门管理员,要不然不允许看对应的联系人)
  1229. var companyProduct *company.CompanyProduct
  1230. if productId == 2 && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1231. // 当前是权益权限,且非 权益管理员
  1232. tmpCompanyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
  1233. companyProduct = tmpCompanyProduct
  1234. if companyProduct != nil && companyProduct.Status == utils.COMPANY_STATUS_LOSE {
  1235. condition += ` AND seller_id=? `
  1236. pars = append(pars, sysUser.AdminId)
  1237. }
  1238. }
  1239. }
  1240. list, err := company.GetCompanyUserListV2(condition, pars, companyId, 0, 1000)
  1241. if err != nil {
  1242. br.Msg = "获取失败"
  1243. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1244. return
  1245. }
  1246. var userIdstr string
  1247. for _, v := range list {
  1248. userIdstr += strconv.Itoa(int(v.UserId)) + ","
  1249. }
  1250. userIdstr = strings.TrimRight(userIdstr, ",")
  1251. resp := new(cygx.CompanyOtherHistoryListResp)
  1252. condition = ` AND user_id IN (` + userIdstr + `)`
  1253. listArticle, err := cygx.GetArticleCollectList(condition)
  1254. if err != nil {
  1255. br.Msg = "获取失败"
  1256. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1257. return
  1258. }
  1259. listIndustry, err := cygx.GetCygxIndustryList(companyId)
  1260. if err != nil {
  1261. br.Msg = "获取失败"
  1262. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1263. return
  1264. }
  1265. listDepartment, err := cygx.GetArticleDepartmentList(companyId)
  1266. if err != nil {
  1267. br.Msg = "获取失败"
  1268. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. //listkeyWord, err := cygx.GetCygxUserSearchKeyWordList(userIdstr)
  1272. //if err != nil {
  1273. // br.Msg = "获取失败"
  1274. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1275. // return
  1276. //}
  1277. //listkeyWord, err := cygx.GetCygxUserSearchKeyWordList(userIdstr)
  1278. //if err != nil {
  1279. // br.Msg = "获取失败"
  1280. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1281. // return
  1282. //}
  1283. for _, v := range list {
  1284. userItem := new(cygx.CompanyOtherHistoryList)
  1285. var artItems []*cygx.CygxArticleCollect
  1286. var industryItems []*cygx.CygxArticleIndustry
  1287. var departmentItems []*cygx.ArticleDepartment
  1288. //var keyWordItems []*cygx.KeyWord
  1289. for _, vArt := range listArticle {
  1290. if vArt.UserId == int(v.UserId) {
  1291. artItems = append(artItems, vArt)
  1292. }
  1293. }
  1294. for _, vIn := range listIndustry {
  1295. if vIn.UserId == int(v.UserId) {
  1296. industryItems = append(industryItems, vIn)
  1297. }
  1298. }
  1299. for _, vDe := range listDepartment {
  1300. if vDe.UserId == int(v.UserId) {
  1301. departmentItems = append(departmentItems, vDe)
  1302. }
  1303. }
  1304. //for _, vKw := range listkeyWord {
  1305. // if vKw.UserId == int(v.UserId) {
  1306. // keyWordItems = append(keyWordItems, vKw)
  1307. // }
  1308. //}
  1309. if len(artItems) > 0 || len(industryItems) > 0 || len(departmentItems) > 0 {
  1310. userItem.RealName = v.RealName
  1311. userItem.Email = v.Email
  1312. userItem.Mobile = v.Mobile
  1313. userItem.ListArticle = artItems
  1314. userItem.ListIndustrial = industryItems
  1315. userItem.ListDepartment = departmentItems
  1316. //userItem.ListKeyWord = keyWordItems
  1317. resp.List = append(resp.List, userItem)
  1318. }
  1319. }
  1320. //创建excel
  1321. dir, err := os.Executable()
  1322. exPath := filepath.Dir(dir)
  1323. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1324. xlsxFile := xlsx.NewFile()
  1325. if err != nil {
  1326. br.Msg = "生成文件失败"
  1327. br.ErrMsg = "生成文件失败"
  1328. return
  1329. }
  1330. style := xlsx.NewStyle()
  1331. alignment := xlsx.Alignment{
  1332. Horizontal: "center",
  1333. Vertical: "center",
  1334. WrapText: true,
  1335. }
  1336. style.Alignment = alignment
  1337. style.ApplyAlignment = true
  1338. sheet, err := xlsxFile.AddSheet("客户其他行为数据(收藏,关注)")
  1339. if err != nil {
  1340. br.Msg = "新增Sheet失败"
  1341. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1342. return
  1343. }
  1344. //标题样式
  1345. titleStyle := xlsx.NewStyle()
  1346. titleFont := xlsx.NewFont(16, "宋体")
  1347. titleFont.Bold = true
  1348. titleStyle.Font = *titleFont
  1349. titleStyle.Alignment = alignment
  1350. sheet.SetColWidth(0, 0, 20)
  1351. sheet.SetColWidth(1, 1, 20)
  1352. sheet.SetColWidth(2, 2, 20)
  1353. sheet.SetColWidth(3, 3, 20)
  1354. sheet.SetColWidth(4, 4, 20)
  1355. titleSonStyle := xlsx.NewStyle()
  1356. titleSonFont := xlsx.NewFont(16, "宋体")
  1357. titleSonFont.Bold = true
  1358. titleSonStyle.Font = *titleSonFont
  1359. for _, item := range resp.List {
  1360. rowTitle := sheet.AddRow()
  1361. //标题列
  1362. titleCell := rowTitle.AddCell()
  1363. titleCell.HMerge = 6 //向右合并列数,不包括自身列
  1364. titleCell.SetValue("客户姓名:" + item.RealName + " 手机号/邮箱:" + item.Mobile)
  1365. titleCell.SetStyle(titleStyle)
  1366. //文章
  1367. if len(item.ListArticle) > 0 {
  1368. rowArticle := sheet.AddRow()
  1369. cellA := rowArticle.AddCell()
  1370. cellA.Value = "收藏报告"
  1371. cellB := rowArticle.AddCell()
  1372. cellB.Value = "收藏时间"
  1373. cellC := rowArticle.AddCell()
  1374. cellC.Value = "发布时间"
  1375. cellD := rowArticle.AddCell()
  1376. cellD.Value = "报告类型"
  1377. cellE := rowArticle.AddCell()
  1378. cellE.Value = "所属产业"
  1379. cellF := rowArticle.AddCell()
  1380. cellF.Value = "关联标的"
  1381. cellA.SetStyle(titleSonStyle)
  1382. cellB.SetStyle(titleSonStyle)
  1383. cellC.SetStyle(titleSonStyle)
  1384. cellD.SetStyle(titleSonStyle)
  1385. cellE.SetStyle(titleSonStyle)
  1386. cellF.SetStyle(titleSonStyle)
  1387. for _, vArt := range item.ListArticle {
  1388. rowArticleVal := sheet.AddRow()
  1389. cellA := rowArticleVal.AddCell()
  1390. cellA.Value = vArt.Title
  1391. cellB := rowArticleVal.AddCell()
  1392. cellB.Value = vArt.CreateTime
  1393. cellC := rowArticleVal.AddCell()
  1394. cellC.Value = vArt.PublishDate
  1395. cellD := rowArticleVal.AddCell()
  1396. cellD.Value = vArt.MatchTypeName
  1397. cellE := rowArticleVal.AddCell()
  1398. cellE.Value = vArt.IndustryName
  1399. cellF := rowArticleVal.AddCell()
  1400. cellF.Value = vArt.SubjectName
  1401. }
  1402. }
  1403. //产业
  1404. if len(item.ListIndustrial) > 0 {
  1405. rowIndustrial := sheet.AddRow()
  1406. cellA := rowIndustrial.AddCell()
  1407. cellA.Value = "关注产业"
  1408. cellB := rowIndustrial.AddCell()
  1409. cellB.Value = "关注时间"
  1410. cellA.SetStyle(titleSonStyle)
  1411. cellB.SetStyle(titleSonStyle)
  1412. for _, vArt := range item.ListIndustrial {
  1413. rowIndustrialVal := sheet.AddRow()
  1414. cellA := rowIndustrialVal.AddCell()
  1415. cellA.Value = vArt.IndustryName
  1416. cellB := rowIndustrialVal.AddCell()
  1417. cellB.Value = vArt.CreateTime
  1418. }
  1419. }
  1420. //作者
  1421. if len(item.ListDepartment) > 0 {
  1422. rowDepartment := sheet.AddRow()
  1423. cellA := rowDepartment.AddCell()
  1424. cellA.Value = "关注作者"
  1425. cellB := rowDepartment.AddCell()
  1426. cellB.Value = "关注时间"
  1427. cellC := rowDepartment.AddCell()
  1428. cellC.Value = "作者相关产业"
  1429. cellA.SetStyle(titleSonStyle)
  1430. cellB.SetStyle(titleSonStyle)
  1431. cellC.SetStyle(titleSonStyle)
  1432. for _, vArt := range item.ListDepartment {
  1433. rowDepartmentVal := sheet.AddRow()
  1434. cellA := rowDepartmentVal.AddCell()
  1435. cellA.Value = vArt.NickName
  1436. cellB := rowDepartmentVal.AddCell()
  1437. cellB.Value = vArt.CreateTime
  1438. cellC := rowDepartmentVal.AddCell()
  1439. cellC.Value = vArt.IndustryName
  1440. }
  1441. }
  1442. }
  1443. err = xlsxFile.Save(downLoadnFilePath)
  1444. if err != nil {
  1445. br.Msg = "保存文件失败"
  1446. br.ErrMsg = "保存文件失败"
  1447. return
  1448. }
  1449. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1450. downloadFileName := companyInfo.CompanyName + "其他行为数据(收藏,关注)" + randStr + ".xlsx"
  1451. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1452. defer func() {
  1453. os.Remove(downLoadnFilePath)
  1454. }()
  1455. br.Ret = 200
  1456. br.Data = resp
  1457. br.Success = true
  1458. br.Msg = "导出成功"
  1459. }
  1460. // @Title 客户阅读量月度统计
  1461. // @Description 客户阅读量月度统计
  1462. // @Param CompanyId query int true "公司ID"
  1463. // @Success Ret=200
  1464. // @router /reportArticle/companyCount [get]
  1465. func (this *IndustrialSubjectController) CompanyCount() {
  1466. br := new(models.BaseResponse).Init()
  1467. defer func() {
  1468. this.Data["json"] = br
  1469. this.ServeJSON()
  1470. }()
  1471. sysUser := this.SysUser
  1472. if sysUser == nil {
  1473. br.Msg = "请登录"
  1474. br.ErrMsg = "请登录,SysUser Is Empty"
  1475. return
  1476. }
  1477. companyId, _ := this.GetInt("CompanyId")
  1478. if companyId < 1 {
  1479. br.Msg = "请输入公司ID"
  1480. return
  1481. }
  1482. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1483. var isCanDownload bool
  1484. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1485. if err != nil {
  1486. br.Msg = "获取失败"
  1487. br.ErrMsg = "获取失败,Err:" + err.Error()
  1488. return
  1489. }
  1490. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1491. isCanDownload = true
  1492. }
  1493. if !isCanDownload {
  1494. br.Msg = "暂无下载权限"
  1495. return
  1496. }
  1497. //获取企业客户信息
  1498. companyInfo, err := company.GetCompanyById(companyId)
  1499. if err != nil {
  1500. br.Msg = "获取失败"
  1501. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1502. return
  1503. }
  1504. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1505. if err != nil && err.Error() != utils.ErrNoRow() {
  1506. br.Msg = "获取信息失败"
  1507. br.ErrMsg = "获取客户手机号信息失败,Err:" + err.Error()
  1508. return
  1509. }
  1510. if mobiles != "" {
  1511. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1512. mobiles = "'" + mobiles + "'"
  1513. } else {
  1514. mobiles = "'1'"
  1515. }
  1516. emails, err := models.GetCompanyUserEmailsByCompanyId(companyId)
  1517. if err != nil && err.Error() != utils.ErrNoRow() {
  1518. br.Msg = "获取信息失败"
  1519. br.ErrMsg = "获取客户邮箱信息失败,Err:" + err.Error()
  1520. return
  1521. }
  1522. if emails != "" {
  1523. emails = strings.Replace(emails, ",", "','", -1)
  1524. emails = "'" + emails + "'"
  1525. } else {
  1526. emails = "'1'"
  1527. }
  1528. listDate, err := cygx.GetCompanyHistoryRecordPvGroupDate(mobiles, emails)
  1529. if err != nil {
  1530. br.Msg = "获取失败"
  1531. br.ErrMsg = "获取失败,Err:" + err.Error()
  1532. return
  1533. }
  1534. dateMap := make(map[string]int)
  1535. permissionNameMap := make(map[string]int)
  1536. list, err := cygx.GetCompanyHistoryRecordPv(mobiles, emails)
  1537. if err != nil {
  1538. br.Msg = "获取失败"
  1539. br.ErrMsg = "获取失败,Err:" + err.Error()
  1540. return
  1541. }
  1542. for _, v := range list {
  1543. if dateMap[v.CreateTime] == 0 {
  1544. dateMap[v.CreateTime] = 1
  1545. } else {
  1546. dateMap[v.CreateTime] += 1
  1547. }
  1548. if v.CategoryId == 0 {
  1549. v.PermissionName = "研选"
  1550. }
  1551. if permissionNameMap[v.CreateTime+v.PermissionName] == 0 {
  1552. permissionNameMap[v.CreateTime+v.PermissionName] = 1
  1553. } else {
  1554. permissionNameMap[v.CreateTime+v.PermissionName] += 1
  1555. }
  1556. }
  1557. //创建excel
  1558. dir, err := os.Executable()
  1559. exPath := filepath.Dir(dir)
  1560. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1561. xlsxFile := xlsx.NewFile()
  1562. if err != nil {
  1563. br.Msg = "生成文件失败"
  1564. br.ErrMsg = "生成文件失败"
  1565. return
  1566. }
  1567. style := xlsx.NewStyle()
  1568. alignment := xlsx.Alignment{
  1569. Horizontal: "center",
  1570. Vertical: "center",
  1571. WrapText: true,
  1572. }
  1573. style.Alignment = alignment
  1574. style.ApplyAlignment = true
  1575. sheet, err := xlsxFile.AddSheet("客户阅读量月度统计")
  1576. if err != nil {
  1577. br.Msg = "新增Sheet失败"
  1578. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1579. return
  1580. }
  1581. //标头
  1582. rowTitle := sheet.AddRow()
  1583. cellA := rowTitle.AddCell()
  1584. cellA.Value = "月份"
  1585. cellB := rowTitle.AddCell()
  1586. cellB.Value = "总阅读数"
  1587. cellC := rowTitle.AddCell()
  1588. cellC.Value = "医药"
  1589. cellD := rowTitle.AddCell()
  1590. cellD.Value = "消费"
  1591. cellE := rowTitle.AddCell()
  1592. cellE.Value = "科技"
  1593. cellF := rowTitle.AddCell()
  1594. cellF.Value = "智造"
  1595. cellG := rowTitle.AddCell()
  1596. cellG.Value = "策略"
  1597. cellH := rowTitle.AddCell()
  1598. cellH.Value = "研选"
  1599. for _, item := range listDate {
  1600. row := sheet.AddRow()
  1601. cellA := row.AddCell()
  1602. cellA.Value = item.CreateTimes
  1603. cellB := row.AddCell()
  1604. cellB.Value = strconv.Itoa(dateMap[item.CreateTimes])
  1605. cellC := row.AddCell()
  1606. cellC.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"医药"])
  1607. cellD := row.AddCell()
  1608. cellD.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"消费"])
  1609. cellE := row.AddCell()
  1610. cellE.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"科技"])
  1611. cellF := row.AddCell()
  1612. cellF.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"智造"])
  1613. cellG := row.AddCell()
  1614. cellG.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"策略"])
  1615. cellH := row.AddCell()
  1616. cellH.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"研选"])
  1617. }
  1618. err = xlsxFile.Save(downLoadnFilePath)
  1619. if err != nil {
  1620. br.Msg = "保存文件失败"
  1621. br.ErrMsg = "保存文件失败"
  1622. return
  1623. }
  1624. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1625. downloadFileName := companyInfo.CompanyName + "客户阅读量月度统计" + randStr + ".xlsx"
  1626. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1627. defer func() {
  1628. os.Remove(downLoadnFilePath)
  1629. }()
  1630. br.Ret = 200
  1631. br.Success = true
  1632. br.Msg = "导出成功"
  1633. }
  1634. // @Title 客户导出文件种类
  1635. // @Description 客户导出文件种类接口
  1636. // @Success Ret=200 {object} cygx.NameAndUrlList
  1637. // @router /company/exportList [get]
  1638. func (this *ReportArticleController) ExportList() {
  1639. br := new(models.BaseResponse).Init()
  1640. defer func() {
  1641. this.Data["json"] = br
  1642. this.ServeJSON()
  1643. }()
  1644. sysUser := this.SysUser
  1645. if sysUser == nil {
  1646. br.Msg = "请登录"
  1647. br.ErrMsg = "请登录,SysUser Is Empty"
  1648. br.Ret = 408
  1649. return
  1650. }
  1651. detail, err := cygx.GetCygxConfigDetailByCode("export_list")
  1652. if err != nil {
  1653. br.Msg = "获取失败"
  1654. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1655. return
  1656. }
  1657. resp := new(cygx.NameAndUrlList)
  1658. exportList := strings.Split(detail.ConfigValue, "{|}")
  1659. for _, v := range exportList {
  1660. item := new(cygx.NameAndUrl)
  1661. vslice := strings.Split(v, "_")
  1662. item.Name = vslice[0]
  1663. item.Url = vslice[len(vslice)-1]
  1664. resp.List = append(resp.List, item)
  1665. }
  1666. br.Ret = 200
  1667. br.Success = true
  1668. br.Msg = "获取成功"
  1669. br.Data = resp
  1670. }
  1671. // @Title 留言列表详情
  1672. // @Description 获取留言列表详情接口
  1673. // @Param ArticleId query int true "文章ID"
  1674. // @Success 200 {object} cygx.ArticleCommentListResp
  1675. // @router /reportArticle/commentList [get]
  1676. func (this *ReportArticleController) CommentList() {
  1677. br := new(models.BaseResponse).Init()
  1678. defer func() {
  1679. this.Data["json"] = br
  1680. this.ServeJSON()
  1681. }()
  1682. sysUser := this.SysUser
  1683. if sysUser == nil {
  1684. br.Msg = "请登录"
  1685. br.ErrMsg = "请登录,SysUser Is Empty"
  1686. return
  1687. }
  1688. articleId, _ := this.GetInt("ArticleId")
  1689. articleInfo, _ := cygx.GetArticleIdInfoByArticleId(articleId)
  1690. if articleInfo == nil {
  1691. br.Msg = "操作失败"
  1692. br.ErrMsg = "报告ID错误"
  1693. return
  1694. }
  1695. list, err := cygx.GetArticleCommentList(articleInfo.ArticleId)
  1696. resp := new(cygx.ArticleCommentListResp)
  1697. if err != nil {
  1698. br.Msg = "获取留言失败"
  1699. br.ErrMsg = "获取留言失败,Err:" + err.Error()
  1700. return
  1701. }
  1702. resp.List = list
  1703. br.Ret = 200
  1704. br.Success = true
  1705. br.Msg = "获取成功"
  1706. br.Data = resp
  1707. }
  1708. // @Title 提问详情excel表格下载
  1709. // @Description 提问详情excel表格下载接口
  1710. // @Param SummaryManageId query int true "纪要ID"
  1711. // @Success 200 导出成功
  1712. // @router /reportArticle/commnetListExport [get]
  1713. func (this *ReportArticleController) CommentListExport() {
  1714. br := new(models.BaseResponse).Init()
  1715. defer func() {
  1716. this.Data["json"] = br
  1717. this.ServeJSON()
  1718. }()
  1719. sysUser := this.SysUser
  1720. if sysUser == nil {
  1721. br.Msg = "请登录"
  1722. br.ErrMsg = "请登录,SysUser Is Empty"
  1723. return
  1724. }
  1725. articleId, _ := this.GetInt("ArticleId")
  1726. articleInfo, _ := cygx.GetArticleIdInfoByArticleId(articleId)
  1727. if articleInfo == nil {
  1728. br.Msg = "操作失败"
  1729. br.ErrMsg = "报告ID错误"
  1730. return
  1731. }
  1732. list, err := cygx.GetArticleCommentList(articleInfo.ArticleId)
  1733. if err != nil {
  1734. br.Msg = "获取失败"
  1735. br.ErrMsg = "获取失败,Err:" + err.Error()
  1736. return
  1737. }
  1738. //创建excel
  1739. dir, err := os.Executable()
  1740. exPath := filepath.Dir(dir)
  1741. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1742. xlsxFile := xlsx.NewFile()
  1743. if err != nil {
  1744. br.Msg = "生成文件失败"
  1745. br.ErrMsg = "生成文件失败"
  1746. return
  1747. }
  1748. style := xlsx.NewStyle()
  1749. alignment := xlsx.Alignment{
  1750. Horizontal: "center",
  1751. Vertical: "center",
  1752. WrapText: true,
  1753. }
  1754. style.Alignment = alignment
  1755. style.ApplyAlignment = true
  1756. sheet, err := xlsxFile.AddSheet("名单")
  1757. if err != nil {
  1758. br.Msg = "新增Sheet失败"
  1759. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1760. return
  1761. }
  1762. //标头
  1763. rowTitle := sheet.AddRow()
  1764. cellA := rowTitle.AddCell()
  1765. cellA.Value = "姓名"
  1766. cellB := rowTitle.AddCell()
  1767. cellB.Value = "公司名称"
  1768. cellC := rowTitle.AddCell()
  1769. cellC.Value = "留言"
  1770. cellD := rowTitle.AddCell()
  1771. cellD.Value = "提交时间"
  1772. for _, item := range list {
  1773. row := sheet.AddRow()
  1774. cellA := row.AddCell()
  1775. cellA.Value = item.RealName
  1776. cellB := row.AddCell()
  1777. cellB.Value = item.CompanyName
  1778. cellC := row.AddCell()
  1779. cellC.Value = item.Content
  1780. cellD := row.AddCell()
  1781. cellD.Value = item.CreateTime
  1782. }
  1783. err = xlsxFile.Save(downLoadnFilePath)
  1784. if err != nil {
  1785. br.Msg = "保存文件失败"
  1786. br.ErrMsg = "保存文件失败"
  1787. return
  1788. }
  1789. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1790. downloadFileName := "留言列表" + randStr + ".xlsx"
  1791. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1792. defer func() {
  1793. os.Remove(downLoadnFilePath)
  1794. }()
  1795. br.Success = true
  1796. br.Ret = 200
  1797. br.Msg = "导出成功"
  1798. }
  1799. // @Title 新建报告类型
  1800. // @Description 新建报告类型接口
  1801. // @Param request body cygx.CygxReportMappingCygxAdd true "type json string"
  1802. // @Success Ret=200 {object} cygx.CygxReportMappingCygx
  1803. // @router /reportMapping/add [post]
  1804. func (this *IndustrialSubjectController) ReportMappingAdd() {
  1805. br := new(models.BaseResponse).Init()
  1806. defer func() {
  1807. this.Data["json"] = br
  1808. this.ServeJSON()
  1809. }()
  1810. sysUser := this.SysUser
  1811. if sysUser == nil {
  1812. br.Msg = "请登录"
  1813. br.ErrMsg = "请登录,SysUser Is Empty"
  1814. br.Ret = 408
  1815. return
  1816. }
  1817. var req cygx.CygxReportMappingCygxAdd
  1818. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1819. if err != nil {
  1820. br.Msg = "参数解析异常!"
  1821. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1822. return
  1823. }
  1824. var condition string
  1825. var pars []interface{}
  1826. reportType := req.ReportType
  1827. chartPermissionId := req.ChartPermissionId
  1828. chartPermissionName := req.ChartPermissionName
  1829. matchTypeName := req.MatchTypeName
  1830. condition = ` AND match_type_name = ? AND chart_permission_id = ? `
  1831. pars = append(pars, matchTypeName, chartPermissionId)
  1832. total, err := cygx.GetCygxReportMappingCygxCount(condition, pars)
  1833. if err != nil {
  1834. br.Msg = "新建报告类型失败"
  1835. br.ErrMsg = "新建报告类型失败,Err:" + err.Error()
  1836. return
  1837. }
  1838. if total > 0 {
  1839. br.Msg = "名称已存在"
  1840. br.ErrMsg = "名称已存在,Err:" + matchTypeName
  1841. return
  1842. }
  1843. maxDeatil, err := cygx.GetCygxReportMappingCelueMaxDetail()
  1844. if err != nil {
  1845. br.Msg = "新建报告类型失败"
  1846. br.ErrMsg = "GetCygxReportMappingCelueMaxDetail,Err:" + err.Error()
  1847. return
  1848. }
  1849. itemCygx := new(cygx.CygxReportMappingCygx)
  1850. itemCygx.ChartPermissionId = chartPermissionId
  1851. itemCygx.ChartPermissionName = chartPermissionName
  1852. itemCygx.MatchTypeName = matchTypeName
  1853. itemCygx.ReportType = reportType
  1854. itemCygx.IsReport = 1
  1855. itemCygx.CreateTime = time.Now()
  1856. itemCygx.ModifyTime = time.Now()
  1857. itemCelue := new(cygx.CygxReportMappingCelue)
  1858. itemCelue.ChartPermissionId = chartPermissionId
  1859. itemCelue.ChartPermissionName = chartPermissionName
  1860. itemCelue.SubCategoryName = matchTypeName
  1861. itemCelue.ReportType = reportType
  1862. itemCelue.IsReport = 1
  1863. itemCelue.CategoryId = maxDeatil.CategoryId + 1
  1864. itemCelue.CreateTime = time.Now()
  1865. itemCelue.ModifyTime = time.Now()
  1866. itemCygxId, err := cygx.AddCygxReportMappingCygx(itemCygx, itemCelue)
  1867. if err != nil {
  1868. br.Msg = "新建报告类型失败"
  1869. br.ErrMsg = "AddCygxReportMappingCygx,Err:" + err.Error()
  1870. return
  1871. }
  1872. resp := new(cygx.CygxReportMappingCygx)
  1873. resp.Id = int(itemCygxId)
  1874. resp.MatchTypeName = matchTypeName
  1875. br.Ret = 200
  1876. br.Success = true
  1877. br.Data = resp
  1878. br.Msg = "分类成功"
  1879. br.IsAddLog = true
  1880. }