report_article.go 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975
  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/roadshow"
  12. "hongze/hz_crm_api/models/system"
  13. "hongze/hz_crm_api/services"
  14. cygxService "hongze/hz_crm_api/services/cygx"
  15. "hongze/hz_crm_api/utils"
  16. "html"
  17. "os"
  18. "path/filepath"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // 报告管理
  24. type ReportArticleController struct {
  25. controllers.BaseAuthController
  26. }
  27. // @Title 主题列表
  28. // @Description 获取主题列表接口
  29. // @Param ChartPermissionId query int true "分类ID"
  30. // @Success 200 {object} cygx.CygxReportMappingListRep
  31. // @router /reportMappingist/list [get]
  32. func (this *ReportArticleController) CygxReportMappingist() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. return
  43. }
  44. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  45. if chartPermissionId < 1 {
  46. br.Msg = "请输入分类ID"
  47. return
  48. }
  49. list, err := cygx.CygxReportMappingist(chartPermissionId)
  50. if err != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取失败,Err:" + err.Error()
  53. return
  54. }
  55. resp := new(cygx.CygxReportMappingListRep)
  56. resp.List = list
  57. br.Ret = 200
  58. br.Success = true
  59. br.Msg = "获取成功"
  60. br.Data = resp
  61. }
  62. // @Title 报告匹配类型列表
  63. // @Description 获取报告匹配类型列表接口
  64. // @Success 200 {object} cygx.CygxReportMappingMatchTypeRep
  65. // @Param ChartPermissionId query int true "分类ID"
  66. // @router /reportMappingMatchTypeRep/list [get]
  67. func (this *ReportArticleController) CygxReportMappingMatchTypeList() {
  68. br := new(models.BaseResponse).Init()
  69. defer func() {
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. sysUser := this.SysUser
  74. if sysUser == nil {
  75. br.Msg = "请登录"
  76. br.ErrMsg = "请登录,SysUser Is Empty"
  77. return
  78. }
  79. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  80. var condition string
  81. var pars []interface{}
  82. if chartPermissionId > 0 {
  83. condition += ` AND chart_permission_id = ? `
  84. pars = append(pars, chartPermissionId)
  85. }
  86. list, err := cygx.GetCygxReportMappingCygxList(condition, pars, 0, 0)
  87. if err != nil {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取失败,Err:" + err.Error()
  90. return
  91. }
  92. resp := new(cygx.CygxCygxReportMappingCygxResp)
  93. resp.List = list
  94. br.Ret = 200
  95. br.Success = true
  96. br.Msg = "获取成功"
  97. br.Data = resp
  98. }
  99. // @Title 报告列表
  100. // @Description 报告列表接口
  101. // @Param PageSize query int true "每页数据条数"
  102. // @Param CurrentIndex query int true "当前页页码,从1开始"
  103. // @Param IsFilter query int true "是否过滤 ,1是,0否,不传默认为0"
  104. // @Param IsClass query int true "是否归类 ,1是,0否 ,不传默认为0"
  105. // @Param ChartPermissionId query int true "行业ID --> 一级分类列表中 ChartPermissionId"
  106. // @Param SubCategoryName query string true "主题"
  107. // @Param MatchTypeName query string true "报告匹配类型"
  108. // @Param IndustrialManagementId int string true "产业ID"
  109. // @Param StartDate query string true "开始时间用0 补齐,列如2021-03-06 08:09:01"
  110. // @Param EndDate query string true "结束时间用0 补齐,列如2021-03-06 08:09:01"
  111. // @Param KeyWord query string true "搜索关键词"
  112. // @Param KeyWordStock query string true "搜索关键词.个股标签,关联标的部分"
  113. // @Success 200 {object} cygx.GetReportArticleListRep
  114. // @router /reportArticle/list [get]
  115. func (this *ReportArticleController) ReportArticleList() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. sysUser := this.SysUser
  122. if sysUser == nil {
  123. br.Msg = "请登录"
  124. br.ErrMsg = "请登录,SysUser Is Empty"
  125. return
  126. }
  127. pageSize, _ := this.GetInt("PageSize")
  128. currentIndex, _ := this.GetInt("CurrentIndex")
  129. isFilter, _ := this.GetInt("IsFilter")
  130. isClass, _ := this.GetInt("IsClass")
  131. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  132. subCategoryName := this.GetString("SubCategoryName")
  133. matchTypeName := this.GetString("MatchTypeName")
  134. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  135. startDate := this.GetString("StartDate")
  136. endDate := this.GetString("EndDate")
  137. keyWord := this.GetString("KeyWord")
  138. keyWordStock := this.GetString("KeyWordStock")
  139. reportLabel := this.GetString("ReportLabel") // 查研观向7.4-报告标签
  140. var startSize int
  141. if pageSize <= 0 {
  142. pageSize = utils.PageSize20
  143. }
  144. if currentIndex <= 0 {
  145. currentIndex = 1
  146. }
  147. startSize = utils.StartIndex(currentIndex, pageSize)
  148. var condition string
  149. var pars []interface{}
  150. listPermission, errper := cygx.GetPermissionMappingCategoryID()
  151. if errper != nil {
  152. br.Msg = "获取失败"
  153. br.ErrMsg = "获取失败,Err:" + errper.Error()
  154. return
  155. }
  156. condition += ` AND art.is_report = 1 AND re.id !=28 `
  157. if isClass == 0 {
  158. condition += ` AND art.is_class = 0 `
  159. } else {
  160. condition += ` AND art.is_class = 1 `
  161. if industrialManagementId > 0 {
  162. condition += ` AND man.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
  163. }
  164. }
  165. if keyWord != "" {
  166. condition += ` AND (art.title LIKE '%` + keyWord + `%' ) `
  167. }
  168. //个股标签跟标的的搜索
  169. if keyWordStock != "" {
  170. 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 + `%')) ) `
  171. }
  172. if isFilter == 0 {
  173. condition += ` AND art.is_filter = 0 `
  174. } else {
  175. condition += ` AND art.is_filter = 1 `
  176. }
  177. //行业
  178. if chartPermissionId > 0 {
  179. condition += ` AND re.chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  180. }
  181. //主题
  182. if subCategoryName != "" {
  183. condition += ` AND art.sub_category_name = ` + "'" + subCategoryName + "' "
  184. }
  185. //发布时间
  186. if startDate != "" {
  187. condition += ` AND art.publish_date >= ` + "'" + startDate + " 00:00:00'"
  188. }
  189. if endDate != "" {
  190. condition += ` AND art.publish_date <= ` + "'" + endDate + " 23:59:59'"
  191. }
  192. //报告匹配类型
  193. if matchTypeName != "" && chartPermissionId > 0 {
  194. //condition += ` AND re.match_type_name = ` + "'" + matchTypeName + "' "
  195. //mappingCygxDetai, err := cygx.GetCygxReportMappingCygxDetailByNameAndChartPermissionId(matchTypeName, chartPermissionId)
  196. //if err != nil && err.Error() != utils.ErrNoRow() {
  197. // br.Msg = "获取失败"
  198. // br.ErrMsg = "获取失败,Err:" + err.Error()
  199. // return
  200. //}
  201. //if mappingCygxDetai == nil {
  202. // resp := new(cygx.GetReportArticleListRep)
  203. // resp.List = make([]*cygx.CygxReportArticle, 0)
  204. // page := paging.GetPaging(currentIndex, pageSize, 0)
  205. // resp.Paging = page
  206. // br.Ret = 200
  207. // br.Success = true
  208. // br.Msg = "获取成功"
  209. // br.Data = resp
  210. // return
  211. //}
  212. //这里量不大,走一下子查询
  213. //condition += ` AND art.category_id IN ( SELECT category_id_celue FROM cygx_report_mapping_group WHERE id_cygx = ` + strconv.Itoa(mappingCygxDetai.Id) + ` ) `
  214. condition += ` AND art.category_id IN ( SELECT category_id FROM cygx_report_mapping WHERE match_type_name = ` + "'" + matchTypeName + "'" + ` ) `
  215. }
  216. // 报告标签
  217. if reportLabel != "" {
  218. keywords := "%" + reportLabel + "%"
  219. // 查询包含关键词的产业/标的所关联的报告IDs
  220. artIds, e := cygx.GetArticleIdsFromIndustryAndSubjectGroupByKeyword(keywords)
  221. if e != nil {
  222. br.Msg = "获取失败"
  223. br.ErrMsg = "产业/标的关键词获取文章IDs失败, Err:" + e.Error()
  224. return
  225. }
  226. if len(artIds) > 0 {
  227. condition += ` AND art.article_id IN (` + utils.GetOrmInReplace(len(artIds)) + `)`
  228. pars = append(pars, artIds)
  229. }
  230. }
  231. total, err := cygx.GetReportArticleCount(condition, pars)
  232. if err != nil {
  233. br.Msg = "获取失败"
  234. br.ErrMsg = "获取失败,Err:" + err.Error()
  235. return
  236. }
  237. //return
  238. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC `
  239. //fmt.Println(condition)
  240. list, err := cygx.GetReportArticleList(condition, pars, startSize, pageSize, isClass)
  241. if err != nil {
  242. br.Msg = "获取失败"
  243. br.ErrMsg = "获取失败,Err:" + err.Error()
  244. return
  245. }
  246. reportMap := make(map[int]string)
  247. listMap, err := cygx.GetReportMapping()
  248. if err != nil {
  249. br.Msg = "获取失败"
  250. br.ErrMsg = "获取映射分类失败,Err:" + err.Error()
  251. return
  252. }
  253. for _, v := range listMap {
  254. reportMap[v.CategoryId] = v.MatchTypeName
  255. }
  256. var articleIds string
  257. for k, v := range list {
  258. var isShowButton bool
  259. if sysUser.RoleTypeCode == "rai_admin" || sysUser.RoleTypeCode == "rai_researcher" || sysUser.RoleTypeCode == "admin" {
  260. isShowButton = true
  261. } else {
  262. isShowButton = false
  263. }
  264. list[k].MatchTypeName = reportMap[v.CategoryId]
  265. list[k].ShowButton = true
  266. for _, vper := range listPermission {
  267. if v.CategoryId == vper.CategoryId {
  268. isShowButton = false
  269. }
  270. list[k].ShowButton = isShowButton
  271. }
  272. articleIds += strconv.Itoa(v.ArticleId) + ","
  273. }
  274. mapCommment := make(map[int]int)
  275. if articleIds != "" {
  276. articleIds = strings.TrimRight(articleIds, ",")
  277. condition = ` AND art.article_id IN (` + articleIds + `)`
  278. listPv, err := cygx.GetReportArticleListPvUv(condition)
  279. if err != nil {
  280. br.Msg = "获取失败"
  281. br.ErrMsg = "获取PV,Uv 失败,Err:" + err.Error()
  282. return
  283. }
  284. var condition string
  285. var pars []interface{}
  286. condition = ` AND k.article_id IN (` + articleIds + `)`
  287. listComment, err := cygx.GetArticleCommentListSearch(condition, pars)
  288. if err != nil {
  289. br.Msg = "获取失败"
  290. br.ErrMsg = "获取失败,Err:" + err.Error()
  291. return
  292. }
  293. for _, v := range listComment {
  294. mapCommment[v.ArticleId]++
  295. }
  296. if len(listPv) > 0 {
  297. for _, pv := range listPv {
  298. for k, v := range list {
  299. if v.ArticleId == pv.ArticleId {
  300. list[k].Pv = pv.Pv
  301. list[k].Uv = pv.Uv
  302. list[k].ClPv = pv.ClPv
  303. list[k].ClUv = pv.ClUv
  304. list[k].CollectionNum = pv.CollectionNum
  305. }
  306. }
  307. }
  308. }
  309. }
  310. //ListIndustrial []*IndustrialActivityGroupManagementRep
  311. //ListSubject []*SubjectActivityGroupManagementRep
  312. mapIndustrial := make(map[int]string)
  313. mapSubject := make(map[string]string)
  314. mapIndustrialList := make(map[int][]*cygx.IndustrialActivityGroupManagementRep)
  315. mapSubjectList := make(map[int][]*cygx.SubjectActivityGroupManagementRep)
  316. if articleIds != "" {
  317. industrialList, err := cygx.GetIndustrialArticleGroupListByarticleIds(articleIds)
  318. if err != nil {
  319. br.Msg = "获取失败"
  320. br.ErrMsg = "获取失败,GetIndustrialArticleGroupListByarticleIds Err:" + err.Error()
  321. return
  322. }
  323. subjectList, err := cygx.GetSubjectArticleGroupListByarticleIds(articleIds)
  324. if err != nil {
  325. br.Msg = "获取失败"
  326. br.ErrMsg = "获取失败,GetSubjectArticleGroupListByarticleIds Err:" + err.Error()
  327. return
  328. }
  329. //合并活动对应的多个标的
  330. for _, v := range subjectList {
  331. mapSubject[fmt.Sprint(v.ArticleId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  332. itemSubject := new(cygx.SubjectActivityGroupManagementRep)
  333. itemSubject.SubjectName = v.SubjectName
  334. itemSubject.IndustrialSubjectId = v.IndustrialSubjectId
  335. mapSubjectList[v.ArticleId] = append(mapSubjectList[v.ArticleId], itemSubject)
  336. }
  337. //活动对应的产业
  338. for _, v := range industrialList {
  339. var labelSubject string
  340. labelSubject = mapSubject[fmt.Sprint(v.ArticleId, "_", v.IndustrialManagementId)]
  341. if labelSubject != "" {
  342. mapIndustrial[v.ArticleId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  343. } else {
  344. mapIndustrial[v.ArticleId] += v.IndustryName + ","
  345. }
  346. itemindustrial := new(cygx.IndustrialActivityGroupManagementRep)
  347. itemindustrial.IndustryName = v.IndustryName
  348. itemindustrial.IndustrialManagementId = v.IndustrialManagementId
  349. mapIndustrialList[v.ArticleId] = append(mapIndustrialList[v.ArticleId], itemindustrial)
  350. }
  351. }
  352. for k, v := range list {
  353. if mapIndustrial[v.ArticleId] != "" {
  354. list[k].Label = strings.TrimRight(mapIndustrial[v.ArticleId], ",")
  355. }
  356. if v.SubCategoryName == "专项调研" {
  357. v.PublishDate = cygxService.ArticlePublishDate(v.PublishDate)
  358. }
  359. list[k].CommentNum = mapCommment[v.ArticleId]
  360. list[k].ListIndustrial = mapIndustrialList[v.ArticleId]
  361. list[k].ListSubject = mapSubjectList[v.ArticleId]
  362. if v.ReportId > 0 {
  363. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/ricc/yb/report/" + strconv.Itoa(v.ReportId)
  364. } else {
  365. list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
  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. }
  1913. func init() {
  1914. initart()
  1915. }
  1916. func initart() {
  1917. //行业
  1918. var condition string
  1919. var pars []interface{}
  1920. condition += ` AND re.chart_permission_id = 62 `
  1921. //报告匹配类型
  1922. //9.5 13:52
  1923. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC `
  1924. listart, err := cygx.GetReportArticleList(condition, pars, 0, 2000, 1)
  1925. if err != nil {
  1926. fmt.Println(err)
  1927. return
  1928. }
  1929. //创建excel
  1930. dir, err := os.Executable()
  1931. exPath := filepath.Dir(dir)
  1932. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1933. xlsxFile := xlsx.NewFile()
  1934. if err != nil {
  1935. fmt.Println(err)
  1936. return
  1937. }
  1938. style := xlsx.NewStyle()
  1939. alignment := xlsx.Alignment{
  1940. Horizontal: "center",
  1941. Vertical: "center",
  1942. WrapText: true,
  1943. }
  1944. style.Alignment = alignment
  1945. style.ApplyAlignment = true
  1946. redStyle := xlsx.NewStyle()
  1947. redStyle.Alignment = alignment
  1948. redStyle.ApplyAlignment = true
  1949. redStyle.Font.Color = "ff0000"
  1950. //定义底色需要标黄的 单元格颜色
  1951. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  1952. redStyle.Fill = redFill
  1953. //redStyle.Border = *border
  1954. var sheetName string
  1955. sheetName = "PV"
  1956. sheet, err := xlsxFile.AddSheet(sheetName)
  1957. if err != nil {
  1958. fmt.Println(err)
  1959. return
  1960. }
  1961. //标头
  1962. rowTitle := sheet.AddRow()
  1963. cellAt := rowTitle.AddCell()
  1964. cellAt.Value = "标题"
  1965. cellPd := rowTitle.AddCell()
  1966. cellPd.Value = "发布时间"
  1967. cellA := rowTitle.AddCell()
  1968. cellA.Value = "姓名"
  1969. cellB := rowTitle.AddCell()
  1970. cellB.Value = "手机号"
  1971. cellC := rowTitle.AddCell()
  1972. cellC.Value = "公司名称"
  1973. cellD := rowTitle.AddCell()
  1974. cellD.Value = "所属销售"
  1975. cellDfw := rowTitle.AddCell()
  1976. cellDfw.Value = "服务销售"
  1977. cellDCreatedTime := rowTitle.AddCell()
  1978. cellDCreatedTime.Value = "阅读时间(最后一次)"
  1979. cellE := rowTitle.AddCell()
  1980. cellE.Value = "停留时长(多次合计))"
  1981. cellF := rowTitle.AddCell()
  1982. cellF.Value = "阅读来源"
  1983. cellStatus := rowTitle.AddCell()
  1984. cellStatus.Value = "客户状态"
  1985. cellTc := rowTitle.AddCell()
  1986. cellTc.Value = "签约套餐"
  1987. hasmobile := make(map[string]bool)
  1988. for _, v := range listart {
  1989. articleId := v.ArticleId
  1990. condition = ` AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则
  1991. list, err := cygx.GetArticleHistoryList(articleId, condition)
  1992. if err != nil {
  1993. fmt.Println(err)
  1994. return
  1995. }
  1996. //上一次的阅读记录
  1997. list_H, err := cygx.GetArticleHistoryList_H(articleId, condition)
  1998. if err != nil {
  1999. fmt.Println(err)
  2000. return
  2001. }
  2002. mapArticle_H := make(map[string]bool)
  2003. for _, vPv := range list_H {
  2004. if !utils.ValidateMobileFormatat(vPv.Mobile) {
  2005. continue
  2006. }
  2007. mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] = true
  2008. }
  2009. listClPv, err := cygx.GetCygxCelueArticleHistoryRecordPvAll(strconv.Itoa(articleId))
  2010. if err != nil && err.Error() != utils.ErrNoRow() {
  2011. fmt.Println(err)
  2012. return
  2013. }
  2014. listClPv_H, err := cygx.GetCygxCelueArticleHistoryRecordPvAll_H(strconv.Itoa(articleId))
  2015. if err != nil && err.Error() != utils.ErrNoRow() {
  2016. fmt.Println(err)
  2017. return
  2018. }
  2019. for _, vPv := range listClPv_H {
  2020. if !utils.ValidateMobileFormatat(vPv.Mobile) {
  2021. continue
  2022. }
  2023. mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] = true
  2024. }
  2025. var listDate []*cygx.ArticleHistoryRep
  2026. var mobiles []string
  2027. var mapMobileCy = make(map[string]bool)
  2028. var mapMobileCl = make(map[string]bool)
  2029. mapstopTime := make(map[string]int)
  2030. if len(list) > 0 {
  2031. for _, vPv := range list {
  2032. if !utils.ValidateMobileFormatat(vPv.Mobile) {
  2033. continue
  2034. }
  2035. if mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] {
  2036. continue
  2037. }
  2038. mobiles = append(mobiles, vPv.Mobile)
  2039. stopTime, _ := strconv.Atoi(vPv.StopTime)
  2040. mapstopTime[vPv.Mobile] += stopTime
  2041. }
  2042. }
  2043. if len(listClPv) > 0 {
  2044. for _, vPv := range listClPv {
  2045. if !utils.ValidateMobileFormatat(vPv.Mobile) {
  2046. continue
  2047. }
  2048. vPv.Ly = "1"
  2049. //if vPv.Mobile != "" {
  2050. mobiles = append(mobiles, vPv.Mobile)
  2051. //}
  2052. if mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] {
  2053. continue
  2054. }
  2055. }
  2056. }
  2057. listUser, err := models.GetWxUserRaiSllerListByUserMobile(mobiles)
  2058. if err != nil {
  2059. fmt.Println(err)
  2060. return
  2061. }
  2062. listUserFicc, err := models.GetWxUserRaiSllerListByUserMobileFiic(mobiles)
  2063. if err != nil {
  2064. fmt.Println(err)
  2065. return
  2066. }
  2067. mapuserMapbil := make(map[string]*models.WxUserSller)
  2068. var companyIds []int
  2069. for _, vuser := range listUser {
  2070. //mapuserMapbil[vuser.Mobile] = vuser
  2071. companyIds = append(companyIds, vuser.CompanyId)
  2072. }
  2073. //合并合同所对应的权限
  2074. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapByIds(companyIds)
  2075. if err != nil {
  2076. fmt.Println(err)
  2077. return
  2078. }
  2079. //fmt.Println(companyIds)
  2080. //for k, vuser := range mappermissionName {
  2081. // fmt.Println(k, vuser)
  2082. //}
  2083. //fmt.Println(mappermissionName)
  2084. for _, vuser := range listUser {
  2085. vuser.ChartPermissionName = mappermissionName[vuser.CompanyId]
  2086. mapuserMapbil[vuser.Mobile] = vuser
  2087. }
  2088. for _, vuser := range listUserFicc {
  2089. vuser.Status = ""
  2090. vuser.SellerName = ""
  2091. if mapuserMapbil[vuser.Mobile] == nil {
  2092. mapuserMapbil[vuser.Mobile] = vuser
  2093. }
  2094. }
  2095. if len(list) > 0 {
  2096. for _, vPv := range list {
  2097. if !utils.ValidateMobileFormatat(vPv.Mobile) || mapMobileCy[vPv.Mobile] {
  2098. continue
  2099. }
  2100. if mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] {
  2101. continue
  2102. }
  2103. if hasmobile[vPv.Mobile] {
  2104. continue
  2105. }
  2106. hasmobile[vPv.Mobile] = true
  2107. mapMobileCy[vPv.Mobile] = true
  2108. listDate = append(listDate, vPv)
  2109. }
  2110. }
  2111. if len(listClPv) > 0 {
  2112. for _, vPv := range listClPv {
  2113. if !utils.ValidateMobileFormatat(vPv.Mobile) || mapMobileCl[vPv.Mobile] {
  2114. continue
  2115. }
  2116. if mapArticle_H[fmt.Sprint("m_", vPv.Mobile)] {
  2117. continue
  2118. }
  2119. if hasmobile[vPv.Mobile] {
  2120. continue
  2121. }
  2122. hasmobile[vPv.Mobile] = true
  2123. mapMobileCl[vPv.Mobile] = true
  2124. listDate = append(listDate, vPv)
  2125. }
  2126. }
  2127. //rowtitle := sheet.AddRow()
  2128. //cellADatatitle := rowtitle.AddCell()
  2129. //cellADatatitle.Value = v.Title
  2130. for _, item := range listDate {
  2131. row := sheet.AddRow()
  2132. cellADatatitle := row.AddCell()
  2133. cellADatatitle.Value = v.Title
  2134. cellADataPd := row.AddCell()
  2135. cellADataPd.Value = v.PublishDate
  2136. cellAData := row.AddCell()
  2137. cellAData.Value = item.RealName
  2138. //if item.Ly == "1" {
  2139. // cellAData.SetStyle(redStyle)
  2140. //}
  2141. cellBData := row.AddCell()
  2142. cellBData.Value = item.Mobile
  2143. cellCData := row.AddCell()
  2144. //cellCData.Value = item.CompanyName
  2145. cellDData := row.AddCell()
  2146. cellDDataFw := row.AddCell()
  2147. //cellDData.Value = item.SellerName
  2148. cellEData := row.AddCell()
  2149. cellEData.Value = item.CreateTime
  2150. cellFData := row.AddCell()
  2151. if item.Ly == "" {
  2152. cellFData.Value = strconv.Itoa(mapstopTime[item.Mobile])
  2153. }
  2154. //fmt.Println(item.Source)
  2155. cellLyData := row.AddCell()
  2156. switch item.Source {
  2157. case "MOBILE":
  2158. cellLyData.Value = "小程序"
  2159. case "WEB":
  2160. cellLyData.Value = "网页版"
  2161. case "CELUE":
  2162. cellLyData.Value = "vmp"
  2163. }
  2164. cellStatusData := row.AddCell()
  2165. cellermissionNameData := row.AddCell()
  2166. if mapuserMapbil[item.Mobile] != nil {
  2167. cellCData.Value = mapuserMapbil[item.Mobile].CompanyName
  2168. cellDData.Value = mapuserMapbil[item.Mobile].SellerName
  2169. cellDDataFw.Value = mapuserMapbil[item.Mobile].ShareSeller
  2170. cellStatusData.Value = mapuserMapbil[item.Mobile].Status
  2171. cellermissionNameData.Value = mapuserMapbil[item.Mobile].ChartPermissionName
  2172. if mapuserMapbil[item.Mobile].RealName != "" {
  2173. cellAData.Value = mapuserMapbil[item.Mobile].RealName
  2174. }
  2175. }
  2176. }
  2177. err = xlsxFile.Save(downLoadnFilePath)
  2178. if err != nil {
  2179. fmt.Println(err)
  2180. return
  2181. }
  2182. }
  2183. }
  2184. func initAct() {
  2185. var condition string
  2186. mapMobile := make(map[string]bool)
  2187. mapuserMapbil := make(map[int]*models.WxUserSller)
  2188. //var activityIds []int
  2189. //activityIds = []int{5590, 5658, 5734, 5747, 5805, 5833, 5832, 5865, 5887, 5872, 5889, 5870, 5892, 5890, 5935, 5976, 5946, 6005,6062} // 2024-12-19 15:55
  2190. //activityIds = []int{6005} // 2024-10-31 17:15
  2191. //activityIds = []int{6052} // 2024-11-07 16:45
  2192. activity_ids := " 5590, 5658, 5734, 5747, 5805, 5833, 5832, 5865, 5887, 5872, 5889, 5870, 5892, 5890, 5935, 5976, 5946, 6005,6062,6174,6224,6254 "
  2193. condition = " AND s.activity_id IN (" + activity_ids + ") AND ( is_meeting = 1 OR duration != '' ) AND s.create_time < '2024-12-12 15:30' "
  2194. listH, err := cygx.GetActivityMeetByUser(condition, 0, 9999)
  2195. if err != nil {
  2196. fmt.Println(err)
  2197. return
  2198. }
  2199. mobileMap := make(map[string]bool)
  2200. for _, v := range listH {
  2201. mobileMap[v.Mobile] = true
  2202. }
  2203. fmt.Println(mobileMap)
  2204. condition = " AND s.activity_id IN (" + activity_ids + ") AND ( is_meeting = 1 OR duration != '' ) AND s.create_time > '2024-12-12 15:30' "
  2205. list, err := cygx.GetActivityMeetByUser(condition, 0, 1000)
  2206. fmt.Println(list)
  2207. fmt.Println()
  2208. if err != nil && err.Error() != utils.ErrNoRow() {
  2209. fmt.Println(err)
  2210. return
  2211. }
  2212. var listData []*cygx.UserInteraction
  2213. //for _, vid := range activityIds {
  2214. // activityId := strconv.Itoa(vid)
  2215. //
  2216. // //activityId := "5865"
  2217. // //condition = " AND s.activity_id = " + activityId + " AND duration != '' AND s.create_time < '2024-09-06 09:20' "
  2218. // //condition = " AND s.activity_id = " + activityId + " AND (is_meeting = 1 OR AND duration != '' ) AND s.create_time < '2024-09-13 10:30' "
  2219. // //list_H, err := cygx.GetActivityMeetByUser(condition, 0, 1000)
  2220. // //if err != nil && err.Error() != utils.ErrNoRow() {
  2221. // // fmt.Println(err)
  2222. // // return
  2223. // //}
  2224. // //
  2225. // //for _, v := range list_H {
  2226. // // mapMobile[v.Mobile+"_"+activityId] = true
  2227. // //}
  2228. //
  2229. // //condition = " AND s.activity_id = 5833 AND duration != '' "
  2230. // //condition = " AND s.activity_id = " + activityId + " AND duration != '' " // 2024-09-06 09:20
  2231. // condition = " AND s.activity_id = " + activityId + " AND ( is_meeting = 1 OR duration != '' ) AND s.create_time > '2024-10-31 17:15' "
  2232. // list, err := cygx.GetActivityMeetByUser(condition, 0, 1000)
  2233. // if err != nil && err.Error() != utils.ErrNoRow() {
  2234. // fmt.Println(err)
  2235. // return
  2236. // }
  2237. //
  2238. // var companyIds []int
  2239. // for _, vuser := range list {
  2240. // //mapuserMapbil[vuser.Mobile] = vuser
  2241. // companyIds = append(companyIds, vuser.CompanyId)
  2242. // listData = append(listData, vuser)
  2243. // }
  2244. //
  2245. // listCompany, err := models.GetWxUserRaiSllerListByUserComapnyId(companyIds)
  2246. // if err != nil {
  2247. // fmt.Println(err)
  2248. // return
  2249. // }
  2250. //
  2251. // //合并合同所对应的权限
  2252. // mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapByIds(companyIds)
  2253. // if err != nil {
  2254. // fmt.Println(err)
  2255. // return
  2256. // }
  2257. // for _, v := range listCompany {
  2258. // v.ChartPermissionName = mappermissionName[v.CompanyId]
  2259. // mapuserMapbil[v.CompanyId] = v
  2260. // }
  2261. //
  2262. // listCompanyFicc, err := models.GetWxUserRaiSllerListByUserComapnyIdFicc(companyIds)
  2263. // if err != nil {
  2264. // fmt.Println(err)
  2265. // return
  2266. // }
  2267. //
  2268. // for _, v := range listCompanyFicc {
  2269. // if mapuserMapbil[v.CompanyId] != nil {
  2270. // continue
  2271. // }
  2272. // v.Status = ""
  2273. // v.SellerName = ""
  2274. // mapuserMapbil[v.CompanyId] = v
  2275. // }
  2276. //}
  2277. var companyIds []int
  2278. for _, vuser := range list {
  2279. fmt.Println(vuser.Mobile)
  2280. if mobileMap[vuser.Mobile] {
  2281. continue
  2282. }
  2283. companyIds = append(companyIds, vuser.CompanyId)
  2284. listData = append(listData, vuser)
  2285. }
  2286. listCompany, err := models.GetWxUserRaiSllerListByUserComapnyId(companyIds)
  2287. if err != nil {
  2288. fmt.Println(err)
  2289. return
  2290. }
  2291. //合并合同所对应的权限
  2292. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapByIds(companyIds)
  2293. if err != nil {
  2294. fmt.Println(err)
  2295. return
  2296. }
  2297. for _, v := range listCompany {
  2298. v.ChartPermissionName = mappermissionName[v.CompanyId]
  2299. mapuserMapbil[v.CompanyId] = v
  2300. }
  2301. listCompanyFicc, err := models.GetWxUserRaiSllerListByUserComapnyIdFicc(companyIds)
  2302. if err != nil {
  2303. fmt.Println(err)
  2304. return
  2305. }
  2306. for _, v := range listCompanyFicc {
  2307. if mapuserMapbil[v.CompanyId] != nil {
  2308. continue
  2309. }
  2310. v.Status = ""
  2311. v.SellerName = ""
  2312. mapuserMapbil[v.CompanyId] = v
  2313. }
  2314. //创建excel
  2315. dir, err := os.Executable()
  2316. exPath := filepath.Dir(dir)
  2317. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2318. xlsxFile := xlsx.NewFile()
  2319. if err != nil {
  2320. fmt.Println(err)
  2321. return
  2322. }
  2323. style := xlsx.NewStyle()
  2324. alignment := xlsx.Alignment{
  2325. Horizontal: "center",
  2326. Vertical: "center",
  2327. WrapText: true,
  2328. }
  2329. style.Alignment = alignment
  2330. style.ApplyAlignment = true
  2331. redStyle := xlsx.NewStyle()
  2332. redStyle.Alignment = alignment
  2333. redStyle.ApplyAlignment = true
  2334. redStyle.Font.Color = "ff0000"
  2335. //定义底色需要标黄的 单元格颜色
  2336. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2337. redStyle.Fill = redFill
  2338. //redStyle.Border = *border
  2339. var sheetName string
  2340. sheetName = "到会信息"
  2341. sheet, err := xlsxFile.AddSheet(sheetName)
  2342. if err != nil {
  2343. fmt.Println(err)
  2344. return
  2345. }
  2346. //标头
  2347. rowTitle := sheet.AddRow()
  2348. cellAct := rowTitle.AddCell()
  2349. cellAct.Value = "活动名称/报告标题"
  2350. cellActime := rowTitle.AddCell()
  2351. cellActime.Value = " 活动时间/发布时间"
  2352. cellA := rowTitle.AddCell()
  2353. cellA.Value = "姓名"
  2354. cellB := rowTitle.AddCell()
  2355. cellB.Value = "手机号"
  2356. cellC := rowTitle.AddCell()
  2357. cellC.Value = "公司名称"
  2358. cellD := rowTitle.AddCell()
  2359. cellD.Value = "所属销售"
  2360. cellDfw := rowTitle.AddCell()
  2361. cellDfw.Value = "服务销售"
  2362. cellYd := rowTitle.AddCell()
  2363. cellYd.Value = "阅读时间"
  2364. cellstopTime := rowTitle.AddCell()
  2365. cellstopTime.Value = "停留时长"
  2366. cellLy := rowTitle.AddCell()
  2367. cellLy.Value = "阅读来源"
  2368. cellStatus := rowTitle.AddCell()
  2369. cellStatus.Value = "客户状态"
  2370. cellTc := rowTitle.AddCell()
  2371. cellTc.Value = "签约套餐"
  2372. for _, item := range listData {
  2373. if mapMobile[item.Mobile] {
  2374. continue
  2375. }
  2376. row := sheet.AddRow()
  2377. cellActData := row.AddCell()
  2378. cellActData.Value = item.ActivityName
  2379. cellActimeData := row.AddCell()
  2380. cellActimeData.Value = item.ActivityTime
  2381. cellAData := row.AddCell()
  2382. cellAData.Value = item.RealName
  2383. //if item.Ly == "1" {
  2384. // cellAData.SetStyle(redStyle)
  2385. //}
  2386. cellBData := row.AddCell()
  2387. cellBData.Value = item.Mobile
  2388. cellCData := row.AddCell()
  2389. //cellCData.Value = item.CompanyName
  2390. cellDData := row.AddCell()
  2391. cellDDatafw := row.AddCell()
  2392. //cellDData.Value = item.SellerName
  2393. cellYdData := row.AddCell()
  2394. cellYdData.Value = ""
  2395. cellstopTimeData := row.AddCell()
  2396. cellstopTimeData.Value = ""
  2397. cellLyData := row.AddCell()
  2398. cellLyData.Value = ""
  2399. cellStatusData := row.AddCell()
  2400. cellermissionNameData := row.AddCell()
  2401. if mapuserMapbil[item.CompanyId] != nil {
  2402. cellCData.Value = mapuserMapbil[item.CompanyId].CompanyName
  2403. cellDData.Value = mapuserMapbil[item.CompanyId].SellerName
  2404. cellDDatafw.Value = mapuserMapbil[item.CompanyId].ShareSeller
  2405. cellStatusData.Value = mapuserMapbil[item.CompanyId].Status
  2406. cellermissionNameData.Value = mapuserMapbil[item.CompanyId].ChartPermissionName
  2407. }
  2408. }
  2409. err = xlsxFile.Save(downLoadnFilePath)
  2410. if err != nil {
  2411. fmt.Println(err)
  2412. return
  2413. }
  2414. }
  2415. func initarta() {
  2416. //行业
  2417. var condition string
  2418. var pars []interface{}
  2419. condition += ` AND share_seller_id In (702,703,704,707) `
  2420. listProduct, err := company.GetCompanyProductList(condition, pars)
  2421. if err != nil {
  2422. fmt.Println(err)
  2423. return
  2424. }
  2425. var companyIds []int
  2426. mapSeller := make(map[int]string)
  2427. for _, v := range listProduct {
  2428. companyIds = append(companyIds, v.CompanyId)
  2429. mapSeller[v.CompanyId] = v.ShareSeller
  2430. }
  2431. //报告匹配类型
  2432. pars = make([]interface{}, 0)
  2433. condition = ` AND re.chart_permission_id IN (23,53) `
  2434. listart, err := cygx.GetReportArticleList(condition, pars, 0, 4000, 1)
  2435. if err != nil {
  2436. fmt.Println(err)
  2437. return
  2438. }
  2439. mapArticleTitle := make(map[int]string)
  2440. mapchart_permission_name := make(map[int]string)
  2441. var articleIds []int
  2442. for _, v := range listart {
  2443. mapArticleTitle[v.ArticleId] = v.Title
  2444. mapchart_permission_name[v.ArticleId] = v.ChartPermissionName
  2445. articleIds = append(articleIds, v.ArticleId)
  2446. }
  2447. //创建excel
  2448. dir, err := os.Executable()
  2449. exPath := filepath.Dir(dir)
  2450. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2451. xlsxFile := xlsx.NewFile()
  2452. if err != nil {
  2453. fmt.Println(err)
  2454. return
  2455. }
  2456. style := xlsx.NewStyle()
  2457. alignment := xlsx.Alignment{
  2458. Horizontal: "center",
  2459. Vertical: "center",
  2460. WrapText: true,
  2461. }
  2462. style.Alignment = alignment
  2463. style.ApplyAlignment = true
  2464. redStyle := xlsx.NewStyle()
  2465. redStyle.Alignment = alignment
  2466. redStyle.ApplyAlignment = true
  2467. redStyle.Font.Color = "ff0000"
  2468. //定义底色需要标黄的 单元格颜色
  2469. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2470. redStyle.Fill = redFill
  2471. //redStyle.Border = *border
  2472. var sheetName string
  2473. sheetName = "PV"
  2474. sheet, err := xlsxFile.AddSheet(sheetName)
  2475. if err != nil {
  2476. fmt.Println(err)
  2477. return
  2478. }
  2479. //标头
  2480. rowTitle := sheet.AddRow()
  2481. cellA := rowTitle.AddCell()
  2482. cellA.Value = "姓名"
  2483. cellB := rowTitle.AddCell()
  2484. cellB.Value = "手机号"
  2485. cellC := rowTitle.AddCell()
  2486. cellC.Value = "公司名称"
  2487. cellD := rowTitle.AddCell()
  2488. cellD.Value = "服务销售"
  2489. cellDCreatedTime := rowTitle.AddCell()
  2490. cellDCreatedTime.Value = "最近阅读时间"
  2491. cellE := rowTitle.AddCell()
  2492. cellE.Value = "行业"
  2493. cellF := rowTitle.AddCell()
  2494. cellF.Value = "报告标题"
  2495. //articleId := v.ArticleId
  2496. //condition = ` AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则
  2497. list, err := cygx.GetArticleHistoryListInit(articleIds, companyIds)
  2498. if err != nil {
  2499. fmt.Println(err)
  2500. return
  2501. }
  2502. mapMobile := make(map[string]bool)
  2503. for _, item := range list {
  2504. if mapMobile[item.Mobile] {
  2505. continue
  2506. }
  2507. row := sheet.AddRow()
  2508. cellAData := row.AddCell()
  2509. cellAData.Value = item.RealName
  2510. cellBData := row.AddCell()
  2511. cellBData.Value = item.Mobile
  2512. cellCData := row.AddCell()
  2513. cellCData.Value = item.CompanyName
  2514. cellDData := row.AddCell()
  2515. cellDData.Value = mapSeller[item.CompanyId]
  2516. cellEData := row.AddCell()
  2517. cellEData.Value = item.CreateTime
  2518. cellEcData := row.AddCell()
  2519. cellEcData.Value = mapchart_permission_name[item.ArticleId]
  2520. cellFData := row.AddCell()
  2521. cellFData.Value = mapArticleTitle[item.ArticleId]
  2522. mapMobile[item.Mobile] = true
  2523. }
  2524. err = xlsxFile.Save(downLoadnFilePath)
  2525. if err != nil {
  2526. fmt.Println(err)
  2527. return
  2528. }
  2529. }
  2530. func initActList() {
  2531. var condition string
  2532. var pars []interface{}
  2533. condition = " AND chart_permission_id = 31 AND activity_time >= '2024-03-01' AND activity_time <= '2024-09-21' AND activity_type_id = 3 AND publish_status = 1 AND yidong_activity_id = '' ORDER BY activity_time ASC "
  2534. list, errList := cygx.GetActivityListAll(condition, pars, 0, 999)
  2535. if errList != nil {
  2536. fmt.Println(errList)
  2537. return
  2538. }
  2539. //创建excel
  2540. dir, err := os.Executable()
  2541. exPath := filepath.Dir(dir)
  2542. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2543. xlsxFile := xlsx.NewFile()
  2544. if err != nil {
  2545. fmt.Println(err)
  2546. return
  2547. }
  2548. style := xlsx.NewStyle()
  2549. alignment := xlsx.Alignment{
  2550. Horizontal: "center",
  2551. Vertical: "center",
  2552. WrapText: true,
  2553. }
  2554. style.Alignment = alignment
  2555. style.ApplyAlignment = true
  2556. redStyle := xlsx.NewStyle()
  2557. redStyle.Alignment = alignment
  2558. redStyle.ApplyAlignment = true
  2559. redStyle.Font.Color = "ff0000"
  2560. //定义底色需要标黄的 单元格颜色
  2561. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2562. redStyle.Fill = redFill
  2563. //redStyle.Border = *border
  2564. var sheetName string
  2565. sheetName = "到会信息"
  2566. sheet, err := xlsxFile.AddSheet(sheetName)
  2567. if err != nil {
  2568. fmt.Println(err)
  2569. return
  2570. }
  2571. //标头
  2572. rowTitle := sheet.AddRow()
  2573. cellA := rowTitle.AddCell()
  2574. cellA.Value = "活动名称"
  2575. cellB := rowTitle.AddCell()
  2576. cellB.Value = "活动时间"
  2577. cellC := rowTitle.AddCell()
  2578. cellC.Value = "活动标签"
  2579. for _, item := range list {
  2580. row := sheet.AddRow()
  2581. cellAData := row.AddCell()
  2582. cellAData.Value = item.ActivityName
  2583. cellBData := row.AddCell()
  2584. cellBData.Value = item.ActivityTime
  2585. cellCData := row.AddCell()
  2586. cellCData.Value = item.Label
  2587. }
  2588. err = xlsxFile.Save(downLoadnFilePath)
  2589. if err != nil {
  2590. fmt.Println(err)
  2591. return
  2592. }
  2593. }
  2594. func initOrder() {
  2595. var condition string
  2596. var pars []interface{}
  2597. //condition = " WHERE 1 = 1 AND source In ('article','yanxuanspecial') AND order_status = 2 GROUP BY order_id ASC "
  2598. condition = " AND source In ('activity') AND order_status = 2 GROUP BY order_id DESC "
  2599. list, errList := cygx.GetCygxOrderList(condition, pars, 0, 9999)
  2600. if errList != nil {
  2601. fmt.Println(errList)
  2602. return
  2603. }
  2604. //创建excel
  2605. dir, err := os.Executable()
  2606. exPath := filepath.Dir(dir)
  2607. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2608. xlsxFile := xlsx.NewFile()
  2609. if err != nil {
  2610. fmt.Println(err)
  2611. return
  2612. }
  2613. style := xlsx.NewStyle()
  2614. alignment := xlsx.Alignment{
  2615. Horizontal: "center",
  2616. Vertical: "center",
  2617. WrapText: true,
  2618. }
  2619. style.Alignment = alignment
  2620. style.ApplyAlignment = true
  2621. redStyle := xlsx.NewStyle()
  2622. redStyle.Alignment = alignment
  2623. redStyle.ApplyAlignment = true
  2624. redStyle.Font.Color = "ff0000"
  2625. //定义底色需要标黄的 单元格颜色
  2626. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2627. redStyle.Fill = redFill
  2628. //redStyle.Border = *border
  2629. var sheetName string
  2630. sheetName = "活动"
  2631. sheet, err := xlsxFile.AddSheet(sheetName)
  2632. if err != nil {
  2633. fmt.Println(err)
  2634. return
  2635. }
  2636. //标头
  2637. //rowTitle := sheet.AddRow()
  2638. //cellA := rowTitle.AddCell()
  2639. //cellA.Value = "姓名"
  2640. //cellB := rowTitle.AddCell()
  2641. //cellB.Value = "手机号"
  2642. //cellC := rowTitle.AddCell()
  2643. //cellC.Value = "公司名称"
  2644. //
  2645. //cellMoney := rowTitle.AddCell()
  2646. //cellMoney.Value = "金额"
  2647. //
  2648. //cellname := rowTitle.AddCell()
  2649. //cellname.Value = "活动名称"
  2650. //
  2651. //cellTime := rowTitle.AddCell()
  2652. //cellTime.Value = "支付时间"
  2653. //
  2654. //for _, item := range list {
  2655. //
  2656. // row := sheet.AddRow()
  2657. // cellAData := row.AddCell()
  2658. // cellAData.Value = item.RealName
  2659. //
  2660. // cellBData := row.AddCell()
  2661. // cellBData.Value = item.Mobile
  2662. // cellCData := row.AddCell()
  2663. // cellCData.Value = item.CompanyName
  2664. //
  2665. // cellCMoneyData := row.AddCell()
  2666. // cellCMoneyData.Value = fmt.Sprint(item.PayMoney)
  2667. //
  2668. // cellCnameData := row.AddCell()
  2669. // cellCnameData.Value = item.SourceTitle
  2670. //
  2671. // cellTimeata := row.AddCell()
  2672. // cellTimeata.Value = item.PayTime.Format(utils.FormatDateTime)
  2673. //}
  2674. var mobiles []string
  2675. var activityIds []int
  2676. for _, v := range list {
  2677. mobiles = append(mobiles, v.Mobile)
  2678. activityIds = append(activityIds, v.SourceId)
  2679. }
  2680. pars = make([]interface{}, 0)
  2681. inviteNameMap := cygxService.GetCygxUserBusinessCardMap(mobiles) // 根据手机号获取邀请人
  2682. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  2683. pars = append(pars, activityIds)
  2684. listActivity, errList := cygx.GetActivityListAllInit(condition, pars)
  2685. if errList != nil {
  2686. fmt.Println(errList)
  2687. return
  2688. }
  2689. mapHost := make(map[int]string)
  2690. for _, v := range listActivity {
  2691. mapHost[v.ActivityId] = v.Host
  2692. }
  2693. rowTitle := sheet.AddRow()
  2694. cellA := rowTitle.AddCell()
  2695. cellA.Value = "姓名"
  2696. cellB := rowTitle.AddCell()
  2697. cellB.Value = "手机号"
  2698. cellC := rowTitle.AddCell()
  2699. cellC.Value = "公司名称"
  2700. cellSeller := rowTitle.AddCell()
  2701. cellSeller.Value = "所属销售"
  2702. cellInviteName := rowTitle.AddCell()
  2703. cellInviteName.Value = "推荐人"
  2704. cellMoney := rowTitle.AddCell()
  2705. cellMoney.Value = "金额"
  2706. cellname := rowTitle.AddCell()
  2707. cellname.Value = "报告标题"
  2708. cellNickename := rowTitle.AddCell()
  2709. cellNickename.Value = "作者"
  2710. cellTime := rowTitle.AddCell()
  2711. cellTime.Value = "支付时间"
  2712. for _, item := range list {
  2713. row := sheet.AddRow()
  2714. cellAData := row.AddCell()
  2715. cellAData.Value = item.RealName
  2716. cellBData := row.AddCell()
  2717. cellBData.Value = item.Mobile
  2718. cellCData := row.AddCell()
  2719. cellCData.Value = item.CompanyName
  2720. cellSellerData := row.AddCell()
  2721. cellSellerData.Value = item.SellerName
  2722. cellInviteNameData := row.AddCell()
  2723. if item.ShareName != "" {
  2724. cellInviteNameData.Value = item.ShareName
  2725. } else {
  2726. cellInviteNameData.Value = inviteNameMap[item.Mobile]
  2727. }
  2728. cellCMoneyData := row.AddCell()
  2729. cellCMoneyData.Value = fmt.Sprint(item.PayMoney)
  2730. cellCnameData := row.AddCell()
  2731. cellCnameData.Value = item.SourceTitle
  2732. cellNickenameData := row.AddCell()
  2733. cellNickenameData.Value = mapHost[item.SourceId]
  2734. cellTimeata := row.AddCell()
  2735. cellTimeata.Value = item.PayTime.Format(utils.FormatDateTime)
  2736. }
  2737. err = xlsxFile.Save(downLoadnFilePath)
  2738. if err != nil {
  2739. fmt.Println(err)
  2740. return
  2741. }
  2742. }
  2743. func initOrderArticle() {
  2744. var condition string
  2745. var pars []interface{}
  2746. condition = " AND source In ('article','yanxuanspecial') AND order_status = 2 GROUP BY order_id DESC "
  2747. list, errList := cygx.GetCygxOrderList(condition, pars, 0, 9999)
  2748. if errList != nil {
  2749. fmt.Println(errList)
  2750. return
  2751. }
  2752. var articleIds []int
  2753. var yanxuanArticleids []int
  2754. for _, v := range list {
  2755. if v.Source == "article" {
  2756. articleIds = append(articleIds, v.SourceId)
  2757. }
  2758. if v.Source == "yanxuanspecial" {
  2759. yanxuanArticleids = append(yanxuanArticleids, v.SourceId)
  2760. }
  2761. }
  2762. pars = make([]interface{}, 0)
  2763. condition = " AND art.article_id IN (" + utils.GetOrmInReplace(len(articleIds)) + ") GROUP BY art.article_id "
  2764. pars = append(pars, articleIds)
  2765. mapArtcileNickName := make(map[int]string)
  2766. listartcile, errList := cygx.GetSummaryManageListInit(condition, pars, 0, 999)
  2767. if errList != nil {
  2768. fmt.Println(errList)
  2769. return
  2770. }
  2771. for _, v := range listartcile {
  2772. mapArtcileNickName[v.ArticleId] = v.NickName
  2773. }
  2774. //fmt.Println(mapArtcileNickName)
  2775. //return
  2776. pars = make([]interface{}, 0)
  2777. condition = " AND a.id IN (" + utils.GetOrmInReplace(len(yanxuanArticleids)) + ") "
  2778. pars = append(pars, yanxuanArticleids)
  2779. mapArtcileNickNameYx := make(map[int]string)
  2780. listartcileYx, errList := cygx.GetYanxuanSpecialList(condition, pars, 0, 999)
  2781. if errList != nil {
  2782. fmt.Println(errList)
  2783. return
  2784. }
  2785. for _, v := range listartcileYx {
  2786. mapArtcileNickNameYx[v.Id] = v.NickName
  2787. }
  2788. var mobiles []string
  2789. for _, v := range list {
  2790. mobiles = append(mobiles, v.Mobile)
  2791. }
  2792. inviteNameMap := cygxService.GetCygxUserBusinessCardMap(mobiles) // 根据手机号获取邀请人
  2793. //创建excel
  2794. dir, err := os.Executable()
  2795. exPath := filepath.Dir(dir)
  2796. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2797. xlsxFile := xlsx.NewFile()
  2798. if err != nil {
  2799. fmt.Println(err)
  2800. return
  2801. }
  2802. style := xlsx.NewStyle()
  2803. alignment := xlsx.Alignment{
  2804. Horizontal: "center",
  2805. Vertical: "center",
  2806. WrapText: true,
  2807. }
  2808. style.Alignment = alignment
  2809. style.ApplyAlignment = true
  2810. redStyle := xlsx.NewStyle()
  2811. redStyle.Alignment = alignment
  2812. redStyle.ApplyAlignment = true
  2813. redStyle.Font.Color = "ff0000"
  2814. //定义底色需要标黄的 单元格颜色
  2815. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2816. redStyle.Fill = redFill
  2817. //redStyle.Border = *border
  2818. var sheetName string
  2819. sheetName = "活动"
  2820. sheet, err := xlsxFile.AddSheet(sheetName)
  2821. if err != nil {
  2822. fmt.Println(err)
  2823. return
  2824. }
  2825. //标头
  2826. rowTitle := sheet.AddRow()
  2827. cellA := rowTitle.AddCell()
  2828. cellA.Value = "姓名"
  2829. cellB := rowTitle.AddCell()
  2830. cellB.Value = "手机号"
  2831. cellC := rowTitle.AddCell()
  2832. cellC.Value = "公司名称"
  2833. cellSeller := rowTitle.AddCell()
  2834. cellSeller.Value = "所属销售"
  2835. cellInviteName := rowTitle.AddCell()
  2836. cellInviteName.Value = "推荐人"
  2837. cellMoney := rowTitle.AddCell()
  2838. cellMoney.Value = "金额"
  2839. cellname := rowTitle.AddCell()
  2840. cellname.Value = "报告标题"
  2841. cellNickename := rowTitle.AddCell()
  2842. cellNickename.Value = "作者"
  2843. cellTime := rowTitle.AddCell()
  2844. cellTime.Value = "支付时间"
  2845. for _, item := range list {
  2846. row := sheet.AddRow()
  2847. cellAData := row.AddCell()
  2848. cellAData.Value = item.RealName
  2849. cellBData := row.AddCell()
  2850. cellBData.Value = item.Mobile
  2851. cellCData := row.AddCell()
  2852. cellCData.Value = item.CompanyName
  2853. cellSellerData := row.AddCell()
  2854. cellSellerData.Value = item.SellerName
  2855. cellInviteNameData := row.AddCell()
  2856. if item.ShareName != "" {
  2857. cellInviteNameData.Value = item.ShareName
  2858. } else {
  2859. cellInviteNameData.Value = inviteNameMap[item.Mobile]
  2860. }
  2861. cellCMoneyData := row.AddCell()
  2862. cellCMoneyData.Value = fmt.Sprint(item.PayMoney)
  2863. cellCnameData := row.AddCell()
  2864. cellCnameData.Value = item.SourceTitle
  2865. cellNickenameData := row.AddCell()
  2866. if item.Source == "article" {
  2867. fmt.Println(mapArtcileNickName[item.SourceId])
  2868. cellNickenameData.Value = mapArtcileNickName[item.SourceId]
  2869. }
  2870. if item.Source == "yanxuanspecial" {
  2871. cellNickenameData.Value = mapArtcileNickNameYx[item.SourceId]
  2872. }
  2873. cellTimeata := row.AddCell()
  2874. cellTimeata.Value = item.PayTime.Format(utils.FormatDateTime)
  2875. }
  2876. err = xlsxFile.Save(downLoadnFilePath)
  2877. if err != nil {
  2878. fmt.Println(err)
  2879. return
  2880. }
  2881. }
  2882. func initRsList() {
  2883. list, errList := roadshow.GetCalendarDetailListinit()
  2884. if errList != nil {
  2885. fmt.Println(errList)
  2886. return
  2887. }
  2888. //创建excel
  2889. dir, err := os.Executable()
  2890. exPath := filepath.Dir(dir)
  2891. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2892. xlsxFile := xlsx.NewFile()
  2893. if err != nil {
  2894. fmt.Println(err)
  2895. return
  2896. }
  2897. style := xlsx.NewStyle()
  2898. alignment := xlsx.Alignment{
  2899. Horizontal: "center",
  2900. Vertical: "center",
  2901. WrapText: true,
  2902. }
  2903. style.Alignment = alignment
  2904. style.ApplyAlignment = true
  2905. redStyle := xlsx.NewStyle()
  2906. redStyle.Alignment = alignment
  2907. redStyle.ApplyAlignment = true
  2908. redStyle.Font.Color = "ff0000"
  2909. //定义底色需要标黄的 单元格颜色
  2910. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  2911. redStyle.Fill = redFill
  2912. //redStyle.Border = *border
  2913. var sheetName string
  2914. sheetName = "活动"
  2915. sheet, err := xlsxFile.AddSheet(sheetName)
  2916. if err != nil {
  2917. fmt.Println(err)
  2918. return
  2919. }
  2920. //标头
  2921. rowTitle := sheet.AddRow()
  2922. cellA := rowTitle.AddCell()
  2923. cellA.Value = "研究员"
  2924. cellB := rowTitle.AddCell()
  2925. cellB.Value = "路演时间"
  2926. cellC := rowTitle.AddCell()
  2927. cellC.Value = "公司名"
  2928. cellMoney := rowTitle.AddCell()
  2929. cellMoney.Value = "销售"
  2930. for _, item := range list {
  2931. row := sheet.AddRow()
  2932. cellAData := row.AddCell()
  2933. cellAData.Value = item.ResearcherName
  2934. cellBData := row.AddCell()
  2935. cellBData.Value = item.StartDate + " " + item.StartTime
  2936. cellCData := row.AddCell()
  2937. cellCData.Value = item.CompanyName
  2938. cellCnameData := row.AddCell()
  2939. cellCnameData.Value = item.SysUserRealName
  2940. }
  2941. err = xlsxFile.Save(downLoadnFilePath)
  2942. if err != nil {
  2943. fmt.Println(err)
  2944. return
  2945. }
  2946. }
  2947. func initHistoryRemarList() {
  2948. remarkList, err := company.GetCompanyHistoryRemarkListInitExport()
  2949. if err != nil {
  2950. fmt.Println(err)
  2951. return
  2952. }
  2953. var companyids []int
  2954. //var companyidsMap +
  2955. resp := new(company.CompanyHistoryRemarkListResp)
  2956. for _, v := range remarkList {
  2957. item := new(company.CompanyHistoryRemarkResp)
  2958. item.CompanyId = v.CompanyId
  2959. if !utils.InArrayByInt(companyids, v.CompanyId) {
  2960. companyids = append(companyids, v.CompanyId)
  2961. }
  2962. item.Content = v.Content
  2963. item.SysAdminName = v.SysAdminName
  2964. //item.SysAdminName = v.C
  2965. item.CreateTime = v.ShowTime.Format(utils.FormatDateTime)
  2966. switch v.TableName {
  2967. case "company_service_record":
  2968. item.RemarkType = "沟通记录"
  2969. case "company_product_remark":
  2970. item.RemarkType = "备注"
  2971. case "company_no_renewed_note":
  2972. item.RemarkType = "未续约备注"
  2973. case "company_renewal_reason":
  2974. item.RemarkType = "未续约说明"
  2975. case "cygx_user_feedback":
  2976. item.RemarkType = "交流反馈(" + v.RealName + ")"
  2977. default:
  2978. item.RemarkType = "备注"
  2979. }
  2980. resp.List = append(resp.List, item)
  2981. }
  2982. listCompany, err := company.GetOverseasCompanysByCompanyIds(companyids)
  2983. if err != nil {
  2984. fmt.Println(err)
  2985. return
  2986. }
  2987. mapCompamyName := make(map[int]string)
  2988. for _, v := range listCompany {
  2989. mapCompamyName[v.CompanyId] = v.CompanyName
  2990. }
  2991. //创建excel
  2992. dir, err := os.Executable()
  2993. exPath := filepath.Dir(dir)
  2994. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2995. xlsxFile := xlsx.NewFile()
  2996. if err != nil {
  2997. fmt.Println(err)
  2998. return
  2999. }
  3000. style := xlsx.NewStyle()
  3001. alignment := xlsx.Alignment{
  3002. Horizontal: "center",
  3003. Vertical: "center",
  3004. WrapText: true,
  3005. }
  3006. style.Alignment = alignment
  3007. style.ApplyAlignment = true
  3008. redStyle := xlsx.NewStyle()
  3009. redStyle.Alignment = alignment
  3010. redStyle.ApplyAlignment = true
  3011. redStyle.Font.Color = "ff0000"
  3012. //定义底色需要标黄的 单元格颜色
  3013. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3014. redStyle.Fill = redFill
  3015. //redStyle.Border = *border
  3016. var sheetName string
  3017. sheetName = "备注"
  3018. sheet, err := xlsxFile.AddSheet(sheetName)
  3019. if err != nil {
  3020. fmt.Println(err)
  3021. return
  3022. }
  3023. //标头
  3024. rowTitle := sheet.AddRow()
  3025. cellA := rowTitle.AddCell()
  3026. cellA.Value = "录入人"
  3027. cellB := rowTitle.AddCell()
  3028. cellB.Value = " 录入时间"
  3029. cellC := rowTitle.AddCell()
  3030. cellC.Value = " 客户名称"
  3031. cellMoney := rowTitle.AddCell()
  3032. cellMoney.Value = "录入类型"
  3033. cellConct := rowTitle.AddCell()
  3034. cellConct.Value = "录入内容"
  3035. for _, item := range resp.List {
  3036. row := sheet.AddRow()
  3037. cellAData := row.AddCell()
  3038. cellAData.Value = item.SysAdminName
  3039. cellBData := row.AddCell()
  3040. cellBData.Value = item.CreateTime
  3041. cellCData := row.AddCell()
  3042. cellCData.Value = mapCompamyName[item.CompanyId]
  3043. cellCnameData := row.AddCell()
  3044. cellCnameData.Value = item.RemarkType
  3045. cellContentData := row.AddCell()
  3046. cellContentData.Value = item.Content
  3047. }
  3048. err = xlsxFile.Save(downLoadnFilePath)
  3049. if err != nil {
  3050. fmt.Println(err)
  3051. return
  3052. }
  3053. }
  3054. func initcygx_user_feedback() {
  3055. remarkList, err := cygx.GetCygxUserFeedbackListIni2t()
  3056. if err != nil {
  3057. fmt.Println(err)
  3058. return
  3059. }
  3060. var companyids []int
  3061. var sellerIds []int
  3062. var adminIds []int
  3063. //var companyidsMap
  3064. for _, v := range remarkList {
  3065. item := new(company.CompanyHistoryRemarkResp)
  3066. item.CompanyId = v.CompanyId
  3067. if !utils.InArrayByInt(companyids, v.CompanyId) {
  3068. companyids = append(companyids, v.CompanyId)
  3069. }
  3070. if !utils.InArrayByInt(sellerIds, v.SellerId) {
  3071. sellerIds = append(sellerIds, v.SellerId)
  3072. }
  3073. if !utils.InArrayByInt(adminIds, v.AdminId) {
  3074. adminIds = append(adminIds, v.AdminId)
  3075. }
  3076. }
  3077. sysUserList, err := system.GetAdminList()
  3078. if err != nil {
  3079. fmt.Println(err)
  3080. return
  3081. }
  3082. adminMap := make(map[int]*system.Admin, 0)
  3083. for _, v := range sysUserList {
  3084. adminMap[v.AdminId] = v
  3085. }
  3086. listCompany, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyids)
  3087. if err != nil {
  3088. fmt.Println(err)
  3089. return
  3090. }
  3091. mapCompamyName := make(map[int]*company.CompanyProduct)
  3092. for _, v := range listCompany {
  3093. mapCompamyName[v.CompanyId] = v
  3094. }
  3095. //创建excel
  3096. dir, err := os.Executable()
  3097. exPath := filepath.Dir(dir)
  3098. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3099. xlsxFile := xlsx.NewFile()
  3100. if err != nil {
  3101. fmt.Println(err)
  3102. return
  3103. }
  3104. style := xlsx.NewStyle()
  3105. alignment := xlsx.Alignment{
  3106. Horizontal: "center",
  3107. Vertical: "center",
  3108. WrapText: true,
  3109. }
  3110. style.Alignment = alignment
  3111. style.ApplyAlignment = true
  3112. redStyle := xlsx.NewStyle()
  3113. redStyle.Alignment = alignment
  3114. redStyle.ApplyAlignment = true
  3115. redStyle.Font.Color = "ff0000"
  3116. //定义底色需要标黄的 单元格颜色
  3117. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3118. redStyle.Fill = redFill
  3119. //redStyle.Border = *border
  3120. var sheetName string
  3121. sheetName = "针对kp的交流反馈"
  3122. sheet, err := xlsxFile.AddSheet(sheetName)
  3123. if err != nil {
  3124. fmt.Println(err)
  3125. return
  3126. }
  3127. //标头
  3128. rowTitle := sheet.AddRow()
  3129. cellA := rowTitle.AddCell()
  3130. cellA.Value = "服务销售姓名"
  3131. cellB := rowTitle.AddCell()
  3132. cellB.Value = " kp姓名"
  3133. cellC := rowTitle.AddCell()
  3134. cellC.Value = " 公司名称"
  3135. cellMoney := rowTitle.AddCell()
  3136. cellMoney.Value = "原销售"
  3137. cellConct := rowTitle.AddCell()
  3138. cellConct.Value = "交流反馈内容"
  3139. cellTime := rowTitle.AddCell()
  3140. cellTime.Value = "录入时间"
  3141. var SellerNameArr []string
  3142. for _, item := range sysUserList {
  3143. if !utils.InArrayByStr(SellerNameArr, item.RealName) {
  3144. SellerNameArr = append(SellerNameArr, item.RealName)
  3145. }
  3146. }
  3147. fmt.Println(SellerNameArr)
  3148. for _, v := range SellerNameArr {
  3149. fmt.Println(v)
  3150. }
  3151. //return
  3152. for _, v := range adminIds {
  3153. for _, item := range remarkList {
  3154. if item.AdminId != v {
  3155. //fmt.Println(v)
  3156. continue
  3157. }
  3158. fmt.Println(v)
  3159. row := sheet.AddRow()
  3160. cellAData := row.AddCell()
  3161. cellAData.Value = adminMap[item.AdminId].RealName
  3162. cellBData := row.AddCell()
  3163. cellBData.Value = item.RealName
  3164. cellCData := row.AddCell()
  3165. cellCData.Value = item.CompanyName
  3166. cellCnameData := row.AddCell()
  3167. cellCnameData.Value = mapCompamyName[item.CompanyId].SellerName
  3168. cellContentData := row.AddCell()
  3169. cellContentData.Value = item.Content
  3170. cellTimeData := row.AddCell()
  3171. cellTimeData.Value = item.CreateTime.Format(utils.FormatDateTime)
  3172. }
  3173. }
  3174. err = xlsxFile.Save(downLoadnFilePath)
  3175. if err != nil {
  3176. fmt.Println(err)
  3177. return
  3178. }
  3179. }
  3180. func initcompany_history_remark() {
  3181. remarkList, err := company.GetCompanyHistoryRemarkListInitExportinit()
  3182. if err != nil {
  3183. fmt.Println(err)
  3184. return
  3185. }
  3186. var companyids []int
  3187. var adminIds []int
  3188. //var companyidsMap
  3189. for _, v := range remarkList {
  3190. item := new(company.CompanyHistoryRemarkResp)
  3191. item.CompanyId = v.CompanyId
  3192. if !utils.InArrayByInt(companyids, v.CompanyId) {
  3193. companyids = append(companyids, v.CompanyId)
  3194. }
  3195. if !utils.InArrayByInt(adminIds, v.SysAdminId) {
  3196. adminIds = append(adminIds, v.SysAdminId)
  3197. }
  3198. switch v.TableName {
  3199. case "company_service_record":
  3200. item.RemarkType = "沟通记录"
  3201. case "company_product_remark":
  3202. item.RemarkType = "历史备注"
  3203. case "company_no_renewed_note":
  3204. item.RemarkType = "未续约备注"
  3205. case "company_renewal_reason":
  3206. item.RemarkType = "未续约说明"
  3207. case "cygx_user_feedback":
  3208. item.RemarkType = "交流反馈(" + v.RealName + ")"
  3209. default:
  3210. item.RemarkType = "备注"
  3211. }
  3212. }
  3213. listCompany, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyids)
  3214. if err != nil {
  3215. fmt.Println(err)
  3216. return
  3217. }
  3218. sysUserList, err := system.GetAdminList()
  3219. if err != nil {
  3220. fmt.Println(err)
  3221. return
  3222. }
  3223. adminMap := make(map[int]*system.Admin, 0)
  3224. for _, v := range sysUserList {
  3225. adminMap[v.AdminId] = v
  3226. }
  3227. mapCompamyName := make(map[int]*company.CompanyProduct)
  3228. for _, v := range listCompany {
  3229. mapCompamyName[v.CompanyId] = v
  3230. }
  3231. //创建excel
  3232. dir, err := os.Executable()
  3233. exPath := filepath.Dir(dir)
  3234. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3235. xlsxFile := xlsx.NewFile()
  3236. if err != nil {
  3237. fmt.Println(err)
  3238. return
  3239. }
  3240. style := xlsx.NewStyle()
  3241. alignment := xlsx.Alignment{
  3242. Horizontal: "center",
  3243. Vertical: "center",
  3244. WrapText: true,
  3245. }
  3246. style.Alignment = alignment
  3247. style.ApplyAlignment = true
  3248. redStyle := xlsx.NewStyle()
  3249. redStyle.Alignment = alignment
  3250. redStyle.ApplyAlignment = true
  3251. redStyle.Font.Color = "ff0000"
  3252. //定义底色需要标黄的 单元格颜色
  3253. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3254. redStyle.Fill = redFill
  3255. //redStyle.Border = *border
  3256. var sheetName string
  3257. sheetName = "针对kp的交流反馈"
  3258. sheet, err := xlsxFile.AddSheet(sheetName)
  3259. if err != nil {
  3260. fmt.Println(err)
  3261. return
  3262. }
  3263. //标头
  3264. rowTitle := sheet.AddRow()
  3265. cellA := rowTitle.AddCell()
  3266. cellA.Value = "服务销售姓名"
  3267. cellC := rowTitle.AddCell()
  3268. cellC.Value = " 公司名称"
  3269. cellMoney := rowTitle.AddCell()
  3270. cellMoney.Value = "原销售"
  3271. cellConct := rowTitle.AddCell()
  3272. cellConct.Value = "交流反馈内容"
  3273. cellType := rowTitle.AddCell()
  3274. cellType.Value = "记录类型"
  3275. cellTime := rowTitle.AddCell()
  3276. cellTime.Value = "录入时间"
  3277. var SellerNameArr []string
  3278. for _, item := range remarkList {
  3279. if !utils.InArrayByStr(SellerNameArr, mapCompamyName[item.CompanyId].ShareSeller) {
  3280. SellerNameArr = append(SellerNameArr, mapCompamyName[item.CompanyId].ShareSeller)
  3281. }
  3282. }
  3283. fmt.Println(SellerNameArr)
  3284. for _, v := range SellerNameArr {
  3285. fmt.Println(v)
  3286. }
  3287. //return
  3288. for _, v := range adminIds {
  3289. for _, item := range remarkList {
  3290. if item.SysAdminId != v {
  3291. //fmt.Println(v)
  3292. continue
  3293. }
  3294. fmt.Println(v)
  3295. row := sheet.AddRow()
  3296. cellAData := row.AddCell()
  3297. cellAData.Value = item.SysAdminName
  3298. cellCData := row.AddCell()
  3299. cellCData.Value = mapCompamyName[item.CompanyId].CompanyName
  3300. cellCnameData := row.AddCell()
  3301. cellCnameData.Value = mapCompamyName[item.CompanyId].SellerName
  3302. cellContentData := row.AddCell()
  3303. cellContentData.Value = item.Content
  3304. celltypeData := row.AddCell()
  3305. switch item.TableName {
  3306. case "company_service_record":
  3307. celltypeData.Value = "沟通记录"
  3308. case "company_product_remark":
  3309. celltypeData.Value = "历史备注"
  3310. default:
  3311. celltypeData.Value = "历史备注"
  3312. }
  3313. cellTimeData := row.AddCell()
  3314. cellTimeData.Value = item.CreateTime.Format(utils.FormatDateTime)
  3315. }
  3316. }
  3317. err = xlsxFile.Save(downLoadnFilePath)
  3318. if err != nil {
  3319. fmt.Println(err)
  3320. return
  3321. }
  3322. }
  3323. func initRsListinit() {
  3324. list, errList := roadshow.GetRsCalendarMeetingUserByRaiinit()
  3325. if errList != nil {
  3326. fmt.Println(errList)
  3327. return
  3328. }
  3329. var companyids []int
  3330. //var companyidsMap
  3331. var rsCalendarIds []int
  3332. for _, v := range list {
  3333. if !utils.InArrayByInt(companyids, v.CompanyId) {
  3334. companyids = append(companyids, v.CompanyId)
  3335. }
  3336. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  3337. }
  3338. listCompany, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyids)
  3339. if err != nil {
  3340. fmt.Println(err)
  3341. return
  3342. }
  3343. mapCompamyName := make(map[int]*company.CompanyProduct)
  3344. for _, v := range listCompany {
  3345. mapCompamyName[v.CompanyId] = v
  3346. }
  3347. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  3348. mapRsCalendarLabel = cygxService.GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  3349. //创建excel
  3350. dir, err := os.Executable()
  3351. exPath := filepath.Dir(dir)
  3352. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3353. xlsxFile := xlsx.NewFile()
  3354. if err != nil {
  3355. fmt.Println(err)
  3356. return
  3357. }
  3358. style := xlsx.NewStyle()
  3359. alignment := xlsx.Alignment{
  3360. Horizontal: "center",
  3361. Vertical: "center",
  3362. WrapText: true,
  3363. }
  3364. style.Alignment = alignment
  3365. style.ApplyAlignment = true
  3366. redStyle := xlsx.NewStyle()
  3367. redStyle.Alignment = alignment
  3368. redStyle.ApplyAlignment = true
  3369. redStyle.Font.Color = "ff0000"
  3370. //定义底色需要标黄的 单元格颜色
  3371. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3372. redStyle.Fill = redFill
  3373. //redStyle.Border = *border
  3374. var sheetName string
  3375. sheetName = "活动"
  3376. sheet, err := xlsxFile.AddSheet(sheetName)
  3377. if err != nil {
  3378. fmt.Println(err)
  3379. return
  3380. }
  3381. //标头
  3382. rowTitle := sheet.AddRow()
  3383. cellA := rowTitle.AddCell()
  3384. cellA.Value = "公司名称"
  3385. cellB := rowTitle.AddCell()
  3386. cellB.Value = "所属服务销售"
  3387. cellC := rowTitle.AddCell()
  3388. cellC.Value = "原销售"
  3389. cellD := rowTitle.AddCell()
  3390. cellD.Value = "姓名"
  3391. cellE := rowTitle.AddCell()
  3392. cellE.Value = "手机号"
  3393. cellF := rowTitle.AddCell()
  3394. cellF.Value = "路演时间"
  3395. cellG := rowTitle.AddCell()
  3396. cellG.Value = "研究员"
  3397. cellH := rowTitle.AddCell()
  3398. cellH.Value = "路演形式"
  3399. cellI := rowTitle.AddCell()
  3400. cellI.Value = "路演主题"
  3401. cellJ := rowTitle.AddCell()
  3402. cellJ.Value = "主题标签"
  3403. for _, v := range companyids {
  3404. for _, item := range list {
  3405. if item.CompanyId != v {
  3406. //fmt.Println(v)
  3407. continue
  3408. }
  3409. row := sheet.AddRow()
  3410. cellAData := row.AddCell()
  3411. cellAData.Value = item.CompanyName
  3412. cellBData := row.AddCell()
  3413. cellCData := row.AddCell()
  3414. if mapCompamyName[item.CompanyId] != nil {
  3415. cellBData.Value = mapCompamyName[item.CompanyId].ShareSeller
  3416. cellCData.Value = mapCompamyName[item.CompanyId].SellerName
  3417. }
  3418. cellDData := row.AddCell()
  3419. cellDData.Value = item.RealName
  3420. cellEData := row.AddCell()
  3421. cellEData.Value = item.Mobile
  3422. cellFData := row.AddCell()
  3423. cellFData.Value = item.StartDate + " " + item.StartTime
  3424. cellGData := row.AddCell()
  3425. cellGData.Value = item.ResearcherName
  3426. cellHData := row.AddCell()
  3427. cellHData.Value = item.RoadshowType
  3428. cellIData := row.AddCell()
  3429. cellIData.Value = item.RoadShowTheme
  3430. cellJData := row.AddCell()
  3431. cellJData.Value = strings.Join(mapRsCalendarLabel[item.RsCalendarId], ",")
  3432. }
  3433. }
  3434. err = xlsxFile.Save(downLoadnFilePath)
  3435. if err != nil {
  3436. fmt.Println(err)
  3437. return
  3438. }
  3439. }
  3440. //func init() {
  3441. // initart22()
  3442. //}
  3443. func initYaxuan() {
  3444. udi := 121323
  3445. var nickname = "鱼与塘"
  3446. listYax, errList := cygx.GetYanxuanSpecialListByconditioninit(udi)
  3447. if errList != nil {
  3448. fmt.Println(errList)
  3449. return
  3450. }
  3451. //创建excel
  3452. dir, err := os.Executable()
  3453. exPath := filepath.Dir(dir)
  3454. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3455. xlsxFile := xlsx.NewFile()
  3456. if err != nil {
  3457. fmt.Println(err)
  3458. return
  3459. }
  3460. style := xlsx.NewStyle()
  3461. alignment := xlsx.Alignment{
  3462. Horizontal: "center",
  3463. Vertical: "center",
  3464. WrapText: true,
  3465. }
  3466. style.Alignment = alignment
  3467. style.ApplyAlignment = true
  3468. redStyle := xlsx.NewStyle()
  3469. redStyle.Alignment = alignment
  3470. redStyle.ApplyAlignment = true
  3471. redStyle.Font.Color = "ff0000"
  3472. //定义底色需要标黄的 单元格颜色
  3473. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3474. redStyle.Fill = redFill
  3475. //redStyle.Border = *border
  3476. var sheetName string
  3477. sheetName = "活动"
  3478. sheet, err := xlsxFile.AddSheet(sheetName)
  3479. if err != nil {
  3480. fmt.Println(err)
  3481. return
  3482. }
  3483. //标头
  3484. rowTitle := sheet.AddRow()
  3485. cellA := rowTitle.AddCell()
  3486. cellA.Value = "文章标题"
  3487. cellB := rowTitle.AddCell()
  3488. cellB.Value = "发布时间"
  3489. cellC := rowTitle.AddCell()
  3490. cellC.Value = "作者昵称"
  3491. cellD := rowTitle.AddCell()
  3492. cellD.Value = "读者手机号"
  3493. cellE := rowTitle.AddCell()
  3494. cellE.Value = "姓名"
  3495. cellF := rowTitle.AddCell()
  3496. cellF.Value = "公司名"
  3497. for _, v := range listYax {
  3498. var condition string
  3499. var pars []interface{}
  3500. condition = ` AND yanxuan_special_id = ? AND company_id != 16 GROUP BY mobile ORDER BY create_time DESC `
  3501. pars = append(pars, v.Id)
  3502. list, err := cygx.GetCygxYanxuanSpecialRecordList(condition, pars)
  3503. if err != nil {
  3504. fmt.Println(err)
  3505. return
  3506. }
  3507. for _, item := range list {
  3508. row := sheet.AddRow()
  3509. cellAData := row.AddCell()
  3510. cellAData.Value = v.Title
  3511. cellBData := row.AddCell()
  3512. cellBData.Value = v.PublishTime.Format(utils.FormatDateTime)
  3513. cellCData := row.AddCell()
  3514. cellCData.Value = nickname
  3515. cellDData := row.AddCell()
  3516. cellDData.Value = item.RealName
  3517. cellEData := row.AddCell()
  3518. cellEData.Value = item.Mobile
  3519. cellFData := row.AddCell()
  3520. cellFData.Value = item.CompanyName
  3521. }
  3522. }
  3523. err = xlsxFile.Save(downLoadnFilePath)
  3524. if err != nil {
  3525. fmt.Println(err)
  3526. return
  3527. }
  3528. }
  3529. func initart22() {
  3530. //行业
  3531. var condition string
  3532. var pars []interface{}
  3533. condition += ` AND art.publish_date >= '2024-10-01'
  3534. AND art.publish_status = 1
  3535. AND art.article_type_id = 0 `
  3536. //return
  3537. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC `
  3538. //fmt.Println(condition)
  3539. list, err := cygx.GetReportArticleList(condition, pars, 0, 9999, 1)
  3540. if err != nil {
  3541. fmt.Println(err)
  3542. return
  3543. }
  3544. fmt.Println("list", len(list))
  3545. //return
  3546. reportMap := make(map[int]string)
  3547. listMap, err := cygx.GetReportMapping()
  3548. if err != nil {
  3549. fmt.Println(err)
  3550. return
  3551. }
  3552. for _, v := range listMap {
  3553. reportMap[v.CategoryId] = v.MatchTypeName
  3554. }
  3555. //创建excel
  3556. dir, err := os.Executable()
  3557. exPath := filepath.Dir(dir)
  3558. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3559. xlsxFile := xlsx.NewFile()
  3560. if err != nil {
  3561. fmt.Println(err)
  3562. return
  3563. }
  3564. style := xlsx.NewStyle()
  3565. alignment := xlsx.Alignment{
  3566. Horizontal: "center",
  3567. Vertical: "center",
  3568. WrapText: true,
  3569. }
  3570. style.Alignment = alignment
  3571. style.ApplyAlignment = true
  3572. redStyle := xlsx.NewStyle()
  3573. redStyle.Alignment = alignment
  3574. redStyle.ApplyAlignment = true
  3575. redStyle.Font.Color = "ff0000"
  3576. //定义底色需要标黄的 单元格颜色
  3577. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  3578. redStyle.Fill = redFill
  3579. //redStyle.Border = *border
  3580. var sheetName string
  3581. sheetName = "数据"
  3582. sheet, err := xlsxFile.AddSheet(sheetName)
  3583. if err != nil {
  3584. fmt.Println(err)
  3585. return
  3586. }
  3587. //标头
  3588. rowTitle := sheet.AddRow()
  3589. cellAt := rowTitle.AddCell()
  3590. cellAt.Value = " 报告名称 "
  3591. cellPd := rowTitle.AddCell()
  3592. cellPd.Value = "行业"
  3593. //cellA := rowTitle.AddCell()
  3594. //cellA.Value = "系列"
  3595. cellB := rowTitle.AddCell()
  3596. cellB.Value = "发布时间"
  3597. for _, v := range list {
  3598. //if v.SubCategoryName != "行业深度" {
  3599. // continue
  3600. //}
  3601. row := sheet.AddRow()
  3602. cellADatatitle := row.AddCell()
  3603. cellADatatitle.Value = v.Title
  3604. cellADataPd := row.AddCell()
  3605. if v.ChartPermissionName == "" {
  3606. cellADataPd.Value = v.CategoryName
  3607. } else {
  3608. cellADataPd.Value = v.ChartPermissionName
  3609. }
  3610. //cellAData := row.AddCell()
  3611. //cellAData.Value = v.SubCategoryName
  3612. cellBData := row.AddCell()
  3613. cellBData.Value = v.PublishDate
  3614. }
  3615. err = xlsxFile.Save(downLoadnFilePath)
  3616. if err != nil {
  3617. fmt.Println(err)
  3618. return
  3619. }
  3620. }