tGovernmentStatistics.js 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const {ObjectId} = require('mongoose').Types;
  5. const {CrudService} = require('naf-framework-mongoose/lib/service');
  6. const {BusinessError, ErrorCode} = require('naf-core').Error;
  7. const moment = require('moment');
  8. class TGovernmentStatisticsService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 't_guidance_unit');
  11. this.model = this.ctx.model.TGuidanceUnit;
  12. this.cModel = this.ctx.model.Claimneed;
  13. this.sModel = this.ctx.model.Stockneed;
  14. this.fModel = this.ctx.model.Financefollow;
  15. this.companyidentifyModel = this.ctx.model.Companyidentify;
  16. this.pModel = this.ctx.model.Profession;
  17. this.dModel = this.ctx.model.Dictionary;
  18. this.loanProModel = this.ctx.model.Loanpro;
  19. this.financeClaimsModel = this.ctx.model.Tfinanceclaims;
  20. this.manageMoneyModel = this.ctx.model.Managemoney;
  21. this.institutionModel = this.ctx.model.Institution;
  22. this.intelligentDockingModel = this.ctx.model.IntelligentDocking;
  23. this.intelligentFollowModel = this.ctx.model.IntelligentFollow;
  24. }
  25. // 企业发布需求金额
  26. async demandAmount(payload) {
  27. let dateType = payload.dateType || '2';
  28. let {startTime, endTime} = this.getTime(payload, dateType);
  29. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  30. const cAgg = [
  31. {
  32. $project: {
  33. status: 1,
  34. money: {
  35. $toDouble: '$money'
  36. },
  37. time: {
  38. $toLong: '$meta.createdAt'
  39. },
  40. year: {
  41. $year: {
  42. $toDate: {
  43. $add: [{
  44. $toLong: '$meta.createdAt'
  45. }, 28800000],
  46. },
  47. },
  48. },
  49. month: {
  50. $month: {
  51. $toDate: {
  52. $add: [{
  53. $toLong: '$meta.createdAt'
  54. }, 28800000],
  55. },
  56. },
  57. },
  58. day: {
  59. $dayOfMonth: {
  60. $toDate: {
  61. $add: [{
  62. $toLong: '$meta.createdAt'
  63. }, 28800000],
  64. },
  65. },
  66. },
  67. },
  68. },
  69. {
  70. $match: this.getTimeMatch("1", {startTime, endTime}, payload),
  71. },
  72. {
  73. $group: this.getTimeGroup("1", dateType)
  74. },
  75. {
  76. $sort: this.getTimeSort(dateType)
  77. },
  78. {
  79. $project: {
  80. _id: 0,
  81. value: 1,
  82. label: this.getTimeLabel(dateType)
  83. },
  84. },
  85. ];
  86. const sAgg = [
  87. {
  88. $project: {
  89. status: 1,
  90. money: {
  91. $toDouble: '$stock_money'
  92. },
  93. time: {
  94. $toLong: '$meta.createdAt'
  95. },
  96. year: {
  97. $year: {
  98. $toDate: {
  99. $add: [{
  100. $toLong: '$meta.createdAt'
  101. }, 28800000],
  102. },
  103. },
  104. },
  105. month: {
  106. $month: {
  107. $toDate: {
  108. $add: [{
  109. $toLong: '$meta.createdAt'
  110. }, 28800000],
  111. },
  112. },
  113. },
  114. day: {
  115. $dayOfMonth: {
  116. $toDate: {
  117. $add: [{
  118. $toLong: '$meta.createdAt'
  119. }, 28800000],
  120. },
  121. },
  122. },
  123. },
  124. },
  125. {
  126. $match: this.getTimeMatch("1", {startTime, endTime}, payload),
  127. },
  128. {
  129. $group: this.getTimeGroup("1", dateType)
  130. },
  131. {
  132. $sort: this.getTimeSort(dateType)
  133. },
  134. {
  135. $project: {
  136. _id: 0,
  137. value: 1,
  138. label: this.getTimeLabel(dateType)
  139. },
  140. },
  141. ];
  142. const iAgg = [
  143. {
  144. $project: {
  145. money: {
  146. $toDouble: '$money'
  147. },
  148. time: {
  149. $toLong: '$meta.createdAt'
  150. },
  151. year: {
  152. $year: {
  153. $toDate: {
  154. $add: [{
  155. $toLong: '$meta.createdAt'
  156. }, 28800000],
  157. },
  158. },
  159. },
  160. month: {
  161. $month: {
  162. $toDate: {
  163. $add: [{
  164. $toLong: '$meta.createdAt'
  165. }, 28800000],
  166. },
  167. },
  168. },
  169. day: {
  170. $dayOfMonth: {
  171. $toDate: {
  172. $add: [{
  173. $toLong: '$meta.createdAt'
  174. }, 28800000],
  175. },
  176. },
  177. },
  178. },
  179. },
  180. {
  181. $match: this.getTimeMatch("9", {startTime, endTime}, payload),
  182. },
  183. {
  184. $group: this.getTimeGroup("9", dateType)
  185. },
  186. {
  187. $sort: this.getTimeSort(dateType)
  188. },
  189. {
  190. $project: {
  191. _id: 0,
  192. value: 1,
  193. label: this.getTimeLabel(dateType)
  194. },
  195. },
  196. ];
  197. let cData = await this.cModel.aggregate(cAgg);
  198. let sData = await this.sModel.aggregate(sAgg);
  199. let iData = await this.intelligentDockingModel.aggregate(iAgg);
  200. let tempData = [...cData, ...sData, ...iData];
  201. let data = this.formatTimeData(timeArray, tempData);
  202. return data;
  203. }
  204. // 解决融资
  205. async financingSolution(payload) {
  206. let dateType = payload.dateType || '2';
  207. let {startTime, endTime} = this.getTime(payload, dateType);
  208. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  209. const fAgg = [
  210. {
  211. $project: {
  212. orcredit: 1,
  213. money: {
  214. $toDouble: '$credit_money'
  215. },
  216. time: {
  217. $toLong: '$credit_time'
  218. },
  219. year: {
  220. $year: {
  221. $toDate: {
  222. $add: [{
  223. $toLong: '$credit_time'
  224. }, 28800000],
  225. },
  226. },
  227. },
  228. month: {
  229. $month: {
  230. $toDate: {
  231. $add: [{
  232. $toLong: '$credit_time'
  233. }, 28800000],
  234. },
  235. },
  236. },
  237. day: {
  238. $dayOfMonth: {
  239. $toDate: {
  240. $add: [{
  241. $toLong: '$credit_time'
  242. }, 28800000],
  243. },
  244. },
  245. },
  246. },
  247. },
  248. {
  249. $match: this.getTimeMatch("2", {startTime, endTime}, payload),
  250. },
  251. {
  252. $group: this.getTimeGroup("2", dateType)
  253. },
  254. {
  255. $sort: this.getTimeSort(dateType)
  256. },
  257. {
  258. $project: {
  259. _id: 0,
  260. value: 1,
  261. label: this.getTimeLabel(dateType)
  262. },
  263. },
  264. ];
  265. const iAgg = [
  266. {
  267. $project: {
  268. orcredit: '$creditStatus',
  269. money: {
  270. $toDouble: '$credit_money'
  271. },
  272. time: {
  273. $toLong: '$credit_time'
  274. },
  275. year: {
  276. $year: {
  277. $toDate: {
  278. $add: [{
  279. $toLong: '$credit_time'
  280. }, 28800000],
  281. },
  282. },
  283. },
  284. month: {
  285. $month: {
  286. $toDate: {
  287. $add: [{
  288. $toLong: '$credit_time'
  289. }, 28800000],
  290. },
  291. },
  292. },
  293. day: {
  294. $dayOfMonth: {
  295. $toDate: {
  296. $add: [{
  297. $toLong: '$credit_time'
  298. }, 28800000],
  299. },
  300. },
  301. },
  302. },
  303. },
  304. {
  305. $match: this.getTimeMatch("2", {startTime, endTime}, payload),
  306. },
  307. {
  308. $group: this.getTimeGroup("2", dateType)
  309. },
  310. {
  311. $sort: this.getTimeSort(dateType)
  312. },
  313. {
  314. $project: {
  315. _id: 0,
  316. value: 1,
  317. label: this.getTimeLabel(dateType)
  318. },
  319. },
  320. ];
  321. let fData = await this.fModel.aggregate(fAgg);
  322. let iData = await this.intelligentFollowModel.aggregate(iAgg);
  323. let tempData = [...fData, ...iData];
  324. let data = this.formatTimeData(timeArray, tempData);
  325. return data;
  326. }
  327. // 注册企业年月
  328. async companyDate(payload) {
  329. let dateType = payload.dateType || '2';
  330. let {startTime, endTime} = this.getTime(payload, dateType);
  331. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  332. const agg = [
  333. {
  334. $project: {
  335. status: 1,
  336. profession_one: 1,
  337. belong_addr_city: 1,
  338. time: {
  339. $toLong: '$meta.createdAt'
  340. },
  341. year: {
  342. $year: {
  343. $toDate: {
  344. $add: [{
  345. $toLong: '$meta.createdAt'
  346. }, 28800000],
  347. },
  348. },
  349. },
  350. month: {
  351. $month: {
  352. $toDate: {
  353. $add: [{
  354. $toLong: '$meta.createdAt'
  355. }, 28800000],
  356. },
  357. },
  358. },
  359. day: {
  360. $dayOfMonth: {
  361. $toDate: {
  362. $add: [{
  363. $toLong: '$meta.createdAt'
  364. }, 28800000],
  365. },
  366. },
  367. },
  368. },
  369. },
  370. {
  371. $match: this.getTimeMatch("3", {startTime, endTime}, payload),
  372. },
  373. {
  374. $group: this.getTimeGroup("3", dateType)
  375. },
  376. {
  377. $sort: this.getTimeSort(dateType)
  378. },
  379. {
  380. $project: {
  381. _id: 0,
  382. value: 1,
  383. label: this.getTimeLabel(dateType)
  384. },
  385. },
  386. ];
  387. let tempData = await this.companyidentifyModel.aggregate(agg);
  388. let data = this.formatTimeData(timeArray, tempData);
  389. return data;
  390. }
  391. // 注册企业行业
  392. async companyIndustry(payload) {
  393. const agg = [
  394. {
  395. $project: {
  396. status: 1,
  397. profession_one: 1,
  398. belong_addr_city: 1,
  399. time: {
  400. $toLong: '$meta.createdAt'
  401. },
  402. year: {
  403. $year: {
  404. $toDate: {
  405. $add: [{
  406. $toLong: '$meta.createdAt'
  407. }, 28800000],
  408. },
  409. },
  410. },
  411. month: {
  412. $month: {
  413. $toDate: {
  414. $add: [{
  415. $toLong: '$meta.createdAt'
  416. }, 28800000],
  417. },
  418. },
  419. },
  420. day: {
  421. $dayOfMonth: {
  422. $toDate: {
  423. $add: [{
  424. $toLong: '$meta.createdAt'
  425. }, 28800000],
  426. },
  427. },
  428. },
  429. },
  430. },
  431. {
  432. $match: this.getMatch("1", payload),
  433. },
  434. {
  435. $group: {
  436. _id: '$profession_one',
  437. value: {
  438. $sum: 1,
  439. },
  440. }
  441. },
  442. {
  443. $sort: {
  444. 'value': -1,
  445. }
  446. },
  447. {
  448. $project: {
  449. _id: 0,
  450. code: '$_id',
  451. value: 1
  452. },
  453. },
  454. ];
  455. let tempData = await this.companyidentifyModel.aggregate(agg);
  456. let professionArray = await this.pModel.find({pcode: '0'});
  457. //let professionTotal = await this.pModel.find({pcode:'0'}).countDocuments();
  458. let data = this.formatData(professionArray, tempData);
  459. let companyTotal = 0;
  460. data.forEach((item) => {
  461. companyTotal += item.value;
  462. });
  463. return {data,companyTotal};
  464. }
  465. // 注册企业地区
  466. async companyRegion(payload) {
  467. const agg = [
  468. {
  469. $project: {
  470. status: 1,
  471. profession_one: 1,
  472. belong_addr_city: 1,
  473. time: {
  474. $toLong: '$meta.createdAt'
  475. },
  476. year: {
  477. $year: {
  478. $toDate: {
  479. $add: [{
  480. $toLong: '$meta.createdAt'
  481. }, 28800000],
  482. },
  483. },
  484. },
  485. month: {
  486. $month: {
  487. $toDate: {
  488. $add: [{
  489. $toLong: '$meta.createdAt'
  490. }, 28800000],
  491. },
  492. },
  493. },
  494. day: {
  495. $dayOfMonth: {
  496. $toDate: {
  497. $add: [{
  498. $toLong: '$meta.createdAt'
  499. }, 28800000],
  500. },
  501. },
  502. },
  503. },
  504. },
  505. {
  506. $match: this.getMatch("2", payload),
  507. },
  508. {
  509. $group: {
  510. _id: '$belong_addr_city',
  511. value: {
  512. $sum: 1,
  513. },
  514. }
  515. },
  516. {
  517. $sort: {
  518. 'value': -1,
  519. }
  520. },
  521. {
  522. $project: {
  523. _id: 0,
  524. code: '$_id',
  525. value: 1
  526. },
  527. },
  528. ];
  529. let tempData = await this.companyidentifyModel.aggregate(agg);
  530. let regionArray = await this.dModel.find({type:'dz',pcode: '220000'});
  531. let regionTotal = await this.dModel.find({type:'dz',pcode: '220000'}).countDocuments();
  532. let data = this.formatData(regionArray, tempData);
  533. let companyTotal = 0;
  534. data.forEach((item) => {
  535. companyTotal += item.value;
  536. });
  537. return {data,companyTotal,regionTotal};
  538. }
  539. // 帮助企业年月
  540. async helpBusinessesDate(payload) {
  541. let dateType = payload.dateType || '2';
  542. let {startTime, endTime} = this.getTime(payload, dateType);
  543. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  544. const fAgg = [
  545. {
  546. $project: {
  547. orcredit: 1,
  548. finceId: 1,
  549. time: {
  550. $toLong: '$credit_time'
  551. },
  552. year: {
  553. $year: {
  554. $toDate: {
  555. $add: [{
  556. $toLong: '$credit_time'
  557. }, 28800000],
  558. },
  559. },
  560. },
  561. month: {
  562. $month: {
  563. $toDate: {
  564. $add: [{
  565. $toLong: '$credit_time'
  566. }, 28800000],
  567. },
  568. },
  569. },
  570. day: {
  571. $dayOfMonth: {
  572. $toDate: {
  573. $add: [{
  574. $toLong: '$credit_time'
  575. }, 28800000],
  576. },
  577. },
  578. },
  579. },
  580. },
  581. {
  582. $match:this.getTimeMatch("4", {startTime, endTime}, payload),
  583. },
  584. {
  585. $group: this.getTimeGroup("4", dateType)
  586. },
  587. {
  588. $sort: this.getTimeSort(dateType)
  589. },
  590. {
  591. $project: {
  592. _id: 0,
  593. value: 1,
  594. label: this.getTimeLabel(dateType)
  595. },
  596. },
  597. ];
  598. const iAgg = [
  599. {
  600. $project: {
  601. orcredit: '$creditStatus',
  602. time: {
  603. $toLong: '$credit_time'
  604. },
  605. year: {
  606. $year: {
  607. $toDate: {
  608. $add: [{
  609. $toLong: '$credit_time'
  610. }, 28800000],
  611. },
  612. },
  613. },
  614. month: {
  615. $month: {
  616. $toDate: {
  617. $add: [{
  618. $toLong: '$credit_time'
  619. }, 28800000],
  620. },
  621. },
  622. },
  623. day: {
  624. $dayOfMonth: {
  625. $toDate: {
  626. $add: [{
  627. $toLong: '$credit_time'
  628. }, 28800000],
  629. },
  630. },
  631. },
  632. },
  633. },
  634. {
  635. $match:this.getTimeMatch("4", {startTime, endTime}, payload),
  636. },
  637. {
  638. $group: this.getTimeGroup("4", dateType)
  639. },
  640. {
  641. $sort: this.getTimeSort(dateType)
  642. },
  643. {
  644. $project: {
  645. _id: 0,
  646. value: 1,
  647. label: this.getTimeLabel(dateType)
  648. },
  649. },
  650. ];
  651. let fData = await this.fModel.aggregate(fAgg);
  652. let iData = await this.intelligentFollowModel.aggregate(iAgg);
  653. let tempData = [...fData, ...iData];
  654. let data = this.formatTimeData(timeArray, tempData);
  655. return data;
  656. }
  657. // 帮助企业行业
  658. async helpBusinessesIndustry(payload) {
  659. const cAgg = [
  660. {
  661. $project: {
  662. orcredit: 1,
  663. objId: {
  664. $toObjectId: "$finceId"
  665. },
  666. time: {
  667. $toLong: '$credit_time'
  668. },
  669. },
  670. },
  671. {
  672. $match:this.getMatch("3", payload),
  673. },
  674. {
  675. $lookup: {
  676. from: 'claim_need',
  677. localField: 'objId',
  678. foreignField: '_id',
  679. as: 'claim_needs',
  680. },
  681. },
  682. {
  683. $unwind: {
  684. path: '$claim_needs',
  685. preserveNullAndEmptyArrays: false,
  686. },
  687. },
  688. {
  689. $lookup: {
  690. from: 'company_identify',
  691. localField: 'claim_needs.userid',
  692. foreignField: 'uid',
  693. as: 'company_identifys',
  694. },
  695. },
  696. {
  697. $unwind: {
  698. path: '$company_identifys',
  699. preserveNullAndEmptyArrays: false,
  700. },
  701. },
  702. {
  703. $group: {
  704. _id: '$company_identifys.profession_one',
  705. value: {
  706. $sum: 1,
  707. },
  708. }
  709. },
  710. {
  711. $sort: {
  712. 'value': - 1,
  713. }
  714. },
  715. {
  716. $project: {
  717. _id: 0,
  718. code: '$_id',
  719. value: 1
  720. },
  721. },
  722. ];
  723. const sAgg = [
  724. {
  725. $project: {
  726. orcredit: 1,
  727. objId: {
  728. $toObjectId: "$finceId"
  729. },
  730. time: {
  731. $toLong: '$credit_time'
  732. },
  733. },
  734. },
  735. {
  736. $match:this.getMatch("3", payload),
  737. },
  738. {
  739. $lookup: {
  740. from: 'stock_need',
  741. localField: 'objId',
  742. foreignField: '_id',
  743. as: 'stock_needs',
  744. },
  745. },
  746. {
  747. $unwind: {
  748. path: '$stock_needs',
  749. preserveNullAndEmptyArrays: false,
  750. },
  751. },
  752. {
  753. $lookup: {
  754. from: 'company_identify',
  755. localField: 'stock_needs.userid',
  756. foreignField: 'uid',
  757. as: 'company_identifys',
  758. },
  759. },
  760. {
  761. $unwind: {
  762. path: '$company_identifys',
  763. preserveNullAndEmptyArrays: false,
  764. },
  765. },
  766. {
  767. $group: {
  768. _id: '$company_identifys.profession_one',
  769. value: {
  770. $sum: 1,
  771. },
  772. }
  773. },
  774. {
  775. $sort: {
  776. 'value': - 1,
  777. }
  778. },
  779. {
  780. $project: {
  781. _id: 0,
  782. code: '$_id',
  783. value: 1
  784. },
  785. },
  786. ];
  787. const iAgg = [
  788. {
  789. $project: {
  790. orcredit: '$creditStatus',
  791. objId: {
  792. $toObjectId: "$intelligentId"
  793. },
  794. time: {
  795. $toLong: '$credit_time'
  796. },
  797. },
  798. },
  799. {
  800. $match:this.getMatch("3", payload),
  801. },
  802. {
  803. $lookup: {
  804. from: 'intelligent_docking',
  805. localField: 'objId',
  806. foreignField: '_id',
  807. as: 'intelligent_dockings',
  808. },
  809. },
  810. {
  811. $unwind: {
  812. path: '$intelligent_dockings',
  813. preserveNullAndEmptyArrays: false,
  814. },
  815. },
  816. {
  817. $lookup: {
  818. from: 'company_identify',
  819. localField: 'intelligent_dockings.uid',
  820. foreignField: 'uid',
  821. as: 'company_identifys',
  822. },
  823. },
  824. {
  825. $unwind: {
  826. path: '$company_identifys',
  827. preserveNullAndEmptyArrays: false,
  828. },
  829. },
  830. {
  831. $group: {
  832. _id: '$company_identifys.profession_one',
  833. value: {
  834. $sum: 1,
  835. },
  836. }
  837. },
  838. {
  839. $sort: {
  840. 'value': - 1,
  841. }
  842. },
  843. {
  844. $project: {
  845. _id: 0,
  846. code: '$_id',
  847. value: 1
  848. },
  849. },
  850. ];
  851. let cData = await this.fModel.aggregate(cAgg);
  852. let sData = await this.fModel.aggregate(sAgg);
  853. let iData = await this.intelligentFollowModel.aggregate(iAgg);
  854. let tempData = [...cData, ...sData, ...iData];
  855. let professionArray = await this.pModel.find({pcode: '0'});
  856. //let professionTotal = await this.pModel.find({pcode:'0'}).countDocuments();
  857. let data = this.formatAddData(professionArray, tempData);
  858. let companyTotal = 0;
  859. data.forEach((item) => {
  860. companyTotal += item.value;
  861. });
  862. return {data,companyTotal};
  863. }
  864. // 帮助企业地区
  865. async helpBusinessesRegion(payload) {
  866. const cAgg = [
  867. {
  868. $project: {
  869. orcredit: 1,
  870. objId: {
  871. $toObjectId: "$finceId"
  872. },
  873. time: {
  874. $toLong: '$credit_time'
  875. },
  876. },
  877. },
  878. {
  879. $match:this.getMatch("4", payload),
  880. },
  881. {
  882. $lookup: {
  883. from: 'claim_need',
  884. localField: 'objId',
  885. foreignField: '_id',
  886. as: 'claim_needs',
  887. },
  888. },
  889. {
  890. $unwind: {
  891. path: '$claim_needs',
  892. preserveNullAndEmptyArrays: false,
  893. },
  894. },
  895. {
  896. $lookup: {
  897. from: 'company_identify',
  898. localField: 'claim_needs.userid',
  899. foreignField: 'uid',
  900. as: 'company_identifys',
  901. },
  902. },
  903. {
  904. $unwind: {
  905. path: '$company_identifys',
  906. preserveNullAndEmptyArrays: false,
  907. },
  908. },
  909. {
  910. $group: {
  911. _id: '$company_identifys.belong_addr_city',
  912. value: {
  913. $sum: 1,
  914. },
  915. }
  916. },
  917. {
  918. $sort: {
  919. 'value': - 1,
  920. }
  921. },
  922. {
  923. $project: {
  924. _id: 0,
  925. code: '$_id',
  926. value: 1
  927. },
  928. },
  929. ];
  930. const sAgg = [
  931. {
  932. $project: {
  933. orcredit: 1,
  934. objId: {
  935. $toObjectId: "$finceId"
  936. },
  937. time: {
  938. $toLong: '$credit_time'
  939. },
  940. },
  941. },
  942. {
  943. $match:this.getMatch("4", payload),
  944. },
  945. {
  946. $lookup: {
  947. from: 'stock_need',
  948. localField: 'objId',
  949. foreignField: '_id',
  950. as: 'stock_needs',
  951. },
  952. },
  953. {
  954. $unwind: {
  955. path: '$stock_needs',
  956. preserveNullAndEmptyArrays: false,
  957. },
  958. },
  959. {
  960. $lookup: {
  961. from: 'company_identify',
  962. localField: 'stock_needs.userid',
  963. foreignField: 'uid',
  964. as: 'company_identifys',
  965. },
  966. },
  967. {
  968. $unwind: {
  969. path: '$company_identifys',
  970. preserveNullAndEmptyArrays: false,
  971. },
  972. },
  973. {
  974. $group: {
  975. _id: '$company_identifys.belong_addr_city',
  976. value: {
  977. $sum: 1,
  978. },
  979. }
  980. },
  981. {
  982. $sort: {
  983. 'value': - 1,
  984. }
  985. },
  986. {
  987. $project: {
  988. _id: 0,
  989. code: '$_id',
  990. value: 1
  991. },
  992. },
  993. ];
  994. const iAgg = [
  995. {
  996. $project: {
  997. orcredit: '$creditStatus',
  998. objId: {
  999. $toObjectId: "$intelligentId"
  1000. },
  1001. time: {
  1002. $toLong: '$credit_time'
  1003. },
  1004. },
  1005. },
  1006. {
  1007. $match:this.getMatch("4", payload),
  1008. },
  1009. {
  1010. $lookup: {
  1011. from: 'intelligent_docking',
  1012. localField: 'objId',
  1013. foreignField: '_id',
  1014. as: 'intelligent_dockings',
  1015. },
  1016. },
  1017. {
  1018. $unwind: {
  1019. path: '$intelligent_dockings',
  1020. preserveNullAndEmptyArrays: false,
  1021. },
  1022. },
  1023. {
  1024. $lookup: {
  1025. from: 'company_identify',
  1026. localField: 'intelligent_dockings.uid',
  1027. foreignField: 'uid',
  1028. as: 'company_identifys',
  1029. },
  1030. },
  1031. {
  1032. $unwind: {
  1033. path: '$company_identifys',
  1034. preserveNullAndEmptyArrays: false,
  1035. },
  1036. },
  1037. {
  1038. $group: {
  1039. _id: '$company_identifys.belong_addr_city',
  1040. value: {
  1041. $sum: 1,
  1042. },
  1043. }
  1044. },
  1045. {
  1046. $sort: {
  1047. 'value': - 1,
  1048. }
  1049. },
  1050. {
  1051. $project: {
  1052. _id: 0,
  1053. code: '$_id',
  1054. value: 1
  1055. },
  1056. },
  1057. ];
  1058. let cData = await this.fModel.aggregate(cAgg);
  1059. let sData = await this.fModel.aggregate(sAgg);
  1060. let iData = await this.intelligentFollowModel.aggregate(iAgg);
  1061. let tempData = [...cData, ...sData, ...iData];
  1062. let regionArray = await this.dModel.find({type:'dz',pcode: '220000'});
  1063. let regionTotal = await this.dModel.find({type:'dz',pcode: '220000'}).countDocuments();
  1064. let data = this.formatAddData(regionArray, tempData);
  1065. let companyTotal = 0;
  1066. data.forEach((item) => {
  1067. companyTotal += item.value;
  1068. });
  1069. return {data,companyTotal,regionTotal};
  1070. }
  1071. // 企业发布需求
  1072. async needCount(payload) {
  1073. let dateType = payload.dateType || '2';
  1074. let {startTime, endTime} = this.getTime(payload, dateType);
  1075. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  1076. const cAgg = [
  1077. {
  1078. $project: {
  1079. status: 1,
  1080. money: {
  1081. $toDouble: '$money'
  1082. },
  1083. time: {
  1084. $toLong: '$meta.createdAt'
  1085. },
  1086. year: {
  1087. $year: {
  1088. $toDate: {
  1089. $add: [{
  1090. $toLong: '$meta.createdAt'
  1091. }, 28800000],
  1092. },
  1093. },
  1094. },
  1095. month: {
  1096. $month: {
  1097. $toDate: {
  1098. $add: [{
  1099. $toLong: '$meta.createdAt'
  1100. }, 28800000],
  1101. },
  1102. },
  1103. },
  1104. day: {
  1105. $dayOfMonth: {
  1106. $toDate: {
  1107. $add: [{
  1108. $toLong: '$meta.createdAt'
  1109. }, 28800000],
  1110. },
  1111. },
  1112. },
  1113. },
  1114. },
  1115. {
  1116. $match: this.getTimeMatch("5", {startTime, endTime}, payload),
  1117. },
  1118. {
  1119. $group: this.getTimeGroup("5", dateType)
  1120. },
  1121. {
  1122. $sort: this.getTimeSort(dateType)
  1123. },
  1124. {
  1125. $project: {
  1126. _id: 0,
  1127. value: 1,
  1128. label: this.getTimeLabel(dateType)
  1129. },
  1130. },
  1131. ];
  1132. const sAgg = [
  1133. {
  1134. $project: {
  1135. status: 1,
  1136. money: {
  1137. $toDouble: '$stock_money'
  1138. },
  1139. time: {
  1140. $toLong: '$meta.createdAt'
  1141. },
  1142. year: {
  1143. $year: {
  1144. $toDate: {
  1145. $add: [{
  1146. $toLong: '$meta.createdAt'
  1147. }, 28800000],
  1148. },
  1149. },
  1150. },
  1151. month: {
  1152. $month: {
  1153. $toDate: {
  1154. $add: [{
  1155. $toLong: '$meta.createdAt'
  1156. }, 28800000],
  1157. },
  1158. },
  1159. },
  1160. day: {
  1161. $dayOfMonth: {
  1162. $toDate: {
  1163. $add: [{
  1164. $toLong: '$meta.createdAt'
  1165. }, 28800000],
  1166. },
  1167. },
  1168. },
  1169. },
  1170. },
  1171. {
  1172. $match: this.getTimeMatch("5", {startTime, endTime}, payload),
  1173. },
  1174. {
  1175. $group: this.getTimeGroup("5", dateType)
  1176. },
  1177. {
  1178. $sort: this.getTimeSort(dateType)
  1179. },
  1180. {
  1181. $project: {
  1182. _id: 0,
  1183. value: 1,
  1184. label: this.getTimeLabel(dateType)
  1185. },
  1186. },
  1187. ];
  1188. const iAgg = [
  1189. {
  1190. $project: {
  1191. time: {
  1192. $toLong: '$meta.createdAt'
  1193. },
  1194. year: {
  1195. $year: {
  1196. $toDate: {
  1197. $add: [{
  1198. $toLong: '$meta.createdAt'
  1199. }, 28800000],
  1200. },
  1201. },
  1202. },
  1203. month: {
  1204. $month: {
  1205. $toDate: {
  1206. $add: [{
  1207. $toLong: '$meta.createdAt'
  1208. }, 28800000],
  1209. },
  1210. },
  1211. },
  1212. day: {
  1213. $dayOfMonth: {
  1214. $toDate: {
  1215. $add: [{
  1216. $toLong: '$meta.createdAt'
  1217. }, 28800000],
  1218. },
  1219. },
  1220. },
  1221. },
  1222. },
  1223. {
  1224. $match: this.getTimeMatch("10", {startTime, endTime}, payload),
  1225. },
  1226. {
  1227. $group: this.getTimeGroup("10", dateType)
  1228. },
  1229. {
  1230. $sort: this.getTimeSort(dateType)
  1231. },
  1232. {
  1233. $project: {
  1234. _id: 0,
  1235. value: 1,
  1236. label: this.getTimeLabel(dateType)
  1237. },
  1238. },
  1239. ];
  1240. let cData = await this.cModel.aggregate(cAgg);
  1241. let sData = await this.sModel.aggregate(sAgg);
  1242. let iData = await this.intelligentDockingModel.aggregate(iAgg);
  1243. let tempData = [...cData, ...sData, ...iData];
  1244. let data = this.formatTimeData(timeArray, tempData);
  1245. return data;
  1246. }
  1247. // 金融产品
  1248. async financialProducts(payload) {
  1249. let dateType = payload.dateType || '2';
  1250. let {startTime, endTime} = this.getTime(payload, dateType);
  1251. let timeArray = this.getTimeArray(startTime, endTime, dateType);
  1252. const loanProAgg = [
  1253. {
  1254. $project: {
  1255. status: 1,
  1256. time: {
  1257. $toLong: '$meta.createdAt'
  1258. },
  1259. year: {
  1260. $year: {
  1261. $toDate: {
  1262. $add: [{
  1263. $toLong: '$meta.createdAt'
  1264. }, 28800000],
  1265. },
  1266. },
  1267. },
  1268. month: {
  1269. $month: {
  1270. $toDate: {
  1271. $add: [{
  1272. $toLong: '$meta.createdAt'
  1273. }, 28800000],
  1274. },
  1275. },
  1276. },
  1277. day: {
  1278. $dayOfMonth: {
  1279. $toDate: {
  1280. $add: [{
  1281. $toLong: '$meta.createdAt'
  1282. }, 28800000],
  1283. },
  1284. },
  1285. },
  1286. },
  1287. },
  1288. {
  1289. $match:this.getTimeMatch("6", {startTime, endTime}, payload),
  1290. },
  1291. {
  1292. $group: this.getTimeGroup("6", dateType)
  1293. },
  1294. {
  1295. $sort: this.getTimeSort(dateType)
  1296. },
  1297. {
  1298. $project: {
  1299. _id: 0,
  1300. value: 1,
  1301. label: this.getTimeLabel(dateType)
  1302. },
  1303. },
  1304. ];
  1305. const financeClaimsAgg = [
  1306. {
  1307. $project: {
  1308. status: 1,
  1309. time: {
  1310. $toLong: '$meta.createdAt'
  1311. },
  1312. year: {
  1313. $year: {
  1314. $toDate: {
  1315. $add: [{
  1316. $toLong: '$meta.createdAt'
  1317. }, 28800000],
  1318. },
  1319. },
  1320. },
  1321. month: {
  1322. $month: {
  1323. $toDate: {
  1324. $add: [{
  1325. $toLong: '$meta.createdAt'
  1326. }, 28800000],
  1327. },
  1328. },
  1329. },
  1330. day: {
  1331. $dayOfMonth: {
  1332. $toDate: {
  1333. $add: [{
  1334. $toLong: '$meta.createdAt'
  1335. }, 28800000],
  1336. },
  1337. },
  1338. },
  1339. },
  1340. },
  1341. {
  1342. $match:this.getTimeMatch("7", {startTime, endTime}, payload),
  1343. },
  1344. {
  1345. $group: this.getTimeGroup("7", dateType)
  1346. },
  1347. {
  1348. $sort: this.getTimeSort(dateType)
  1349. },
  1350. {
  1351. $project: {
  1352. _id: 0,
  1353. value: 1,
  1354. label: this.getTimeLabel(dateType)
  1355. },
  1356. },
  1357. ];
  1358. const manageMoneyAgg = [
  1359. {
  1360. $project: {
  1361. status: 1,
  1362. time: {
  1363. $toLong: '$meta.createdAt'
  1364. },
  1365. year: {
  1366. $year: {
  1367. $toDate: {
  1368. $add: [{
  1369. $toLong: '$meta.createdAt'
  1370. }, 28800000],
  1371. },
  1372. },
  1373. },
  1374. month: {
  1375. $month: {
  1376. $toDate: {
  1377. $add: [{
  1378. $toLong: '$meta.createdAt'
  1379. }, 28800000],
  1380. },
  1381. },
  1382. },
  1383. day: {
  1384. $dayOfMonth: {
  1385. $toDate: {
  1386. $add: [{
  1387. $toLong: '$meta.createdAt'
  1388. }, 28800000],
  1389. },
  1390. },
  1391. },
  1392. },
  1393. },
  1394. {
  1395. $match:this.getTimeMatch("8", {startTime, endTime}, payload),
  1396. },
  1397. {
  1398. $group: this.getTimeGroup("8", dateType)
  1399. },
  1400. {
  1401. $sort: this.getTimeSort(dateType)
  1402. },
  1403. {
  1404. $project: {
  1405. _id: 0,
  1406. value: 1,
  1407. label: this.getTimeLabel(dateType)
  1408. },
  1409. },
  1410. ];
  1411. let loanProData = await this.loanProModel.aggregate(loanProAgg);
  1412. let financeClaimsData = await this.financeClaimsModel.aggregate(financeClaimsAgg);
  1413. let manageMoneyData = await this.manageMoneyModel.aggregate(manageMoneyAgg);
  1414. let tempData = [...loanProData, ...financeClaimsData, ...manageMoneyData];
  1415. let data = this.formatTimeData(timeArray, tempData);
  1416. return data;
  1417. }
  1418. // 服务金融机构
  1419. async financialInstitution(payload) {
  1420. let {skip = 0, limit = 10} = payload;
  1421. let match = {};
  1422. if (payload.name) {
  1423. match.name = {$regex: payload.name, $options: '$i'};
  1424. }
  1425. if (payload.type) {
  1426. match.type = payload.type;
  1427. }
  1428. if (payload.status) {
  1429. match.status = payload.status;
  1430. }
  1431. let sort = {};
  1432. if (payload.sort && payload.asc) {
  1433. sort[payload.sort] = Number.parseInt(payload.asc);
  1434. } else {
  1435. sort = {'meta.createdAt': -1};
  1436. }
  1437. const total = await this.institutionModel.find(match).countDocuments();
  1438. const data = await this.institutionModel.find(match).sort(sort).skip(Number.parseInt(skip)).limit(Number.parseInt(limit));
  1439. return {
  1440. data,
  1441. total,
  1442. };
  1443. }
  1444. // 首页查询
  1445. async pageSelect(payload) {
  1446. let registerCompany = await this.companyidentifyModel.find({'status':'1'}).countDocuments();
  1447. let financialInstitution = await this.institutionModel.find().countDocuments();
  1448. let temp1 = await this.loanProModel.find({'status':'0'}).countDocuments();
  1449. let temp2 = await this.financeClaimsModel.find({'status':'1'}).countDocuments();
  1450. let temp3 = await this.manageMoneyModel.find({'status':'1'}).countDocuments();
  1451. let financialProduct = temp1 + temp2 + temp3;
  1452. let temp4 = await this.cModel.find({'status':'0'}).countDocuments();
  1453. let temp5 = await this.sModel.find({'status':'0'}).countDocuments();
  1454. let tempAdd1 = await this.intelligentDockingModel.find().countDocuments();
  1455. let demandCount = temp4 + temp5 + tempAdd1;
  1456. let temp6 = 0;
  1457. let temp7 = 0;
  1458. let tempAdd2 = 0;
  1459. let data6 = await this.cModel.aggregate([
  1460. {
  1461. $project: {
  1462. status: 1,
  1463. money: {
  1464. $toDouble: '$money'
  1465. },
  1466. },
  1467. },
  1468. {
  1469. $match:
  1470. {
  1471. $expr:
  1472. {
  1473. $and:
  1474. [
  1475. {
  1476. $eq: ['$status', '0'],
  1477. },
  1478. ],
  1479. },
  1480. },
  1481. },
  1482. {
  1483. $group: {
  1484. _id: null,
  1485. value: {
  1486. $sum: '$money',
  1487. },
  1488. }
  1489. },
  1490. ]);
  1491. if(data6.length > 0){
  1492. temp6 = data6[0].value;
  1493. }
  1494. let data7 = await this.sModel.aggregate([
  1495. {
  1496. $project: {
  1497. status: 1,
  1498. money: {
  1499. $toDouble: '$stock_money'
  1500. },
  1501. },
  1502. },
  1503. {
  1504. $match:
  1505. {
  1506. $expr:
  1507. {
  1508. $and:
  1509. [
  1510. {
  1511. $eq: ['$status', '0'],
  1512. },
  1513. ],
  1514. },
  1515. },
  1516. },
  1517. {
  1518. $group: {
  1519. _id: null,
  1520. value: {
  1521. $sum: '$money',
  1522. },
  1523. }
  1524. },
  1525. ]);
  1526. if(data7.length > 0){
  1527. temp7 = data7[0].value;
  1528. }
  1529. let dataAdd2 = await this.intelligentDockingModel.aggregate([
  1530. {
  1531. $project: {
  1532. money: {
  1533. $toDouble: '$money'
  1534. },
  1535. },
  1536. },
  1537. {
  1538. $group: {
  1539. _id: null,
  1540. value: {
  1541. $sum: '$money',
  1542. },
  1543. }
  1544. },
  1545. ]);
  1546. if(dataAdd2.length > 0){
  1547. tempAdd2 = dataAdd2[0].value;
  1548. }
  1549. let demandMoney = temp6 + temp7 + tempAdd2;
  1550. let tempAdd3 = await this.fModel.find({'orcredit':'1'}).countDocuments();
  1551. let tempAdd4 = await this.intelligentFollowModel.find({'creditStatus':'1'}).countDocuments();
  1552. let helpCompany = tempAdd3 + tempAdd4;
  1553. let temp8 = 0;
  1554. let tempAdd5 = 0;
  1555. let data8 = await this.fModel.aggregate([
  1556. {
  1557. $project: {
  1558. orcredit: 1,
  1559. money: {
  1560. $toDouble: '$credit_money'
  1561. }
  1562. },
  1563. },
  1564. {
  1565. $match: {
  1566. $expr:
  1567. {
  1568. $and:
  1569. [
  1570. {
  1571. $eq: ['$orcredit', '1'],
  1572. },
  1573. ],
  1574. },
  1575. },
  1576. },
  1577. {
  1578. $group: {
  1579. _id: null,
  1580. value: {
  1581. $sum: '$money',
  1582. },
  1583. }
  1584. },
  1585. ]);
  1586. let dataAdd5 = await this.intelligentFollowModel.aggregate([
  1587. {
  1588. $project: {
  1589. orcredit: '$creditStatus',
  1590. money: {
  1591. $toDouble: '$credit_money'
  1592. }
  1593. },
  1594. },
  1595. {
  1596. $match: {
  1597. $expr:
  1598. {
  1599. $and:
  1600. [
  1601. {
  1602. $eq: ['$orcredit', '1'],
  1603. },
  1604. ],
  1605. },
  1606. },
  1607. },
  1608. {
  1609. $group: {
  1610. _id: null,
  1611. value: {
  1612. $sum: '$money',
  1613. },
  1614. }
  1615. },
  1616. ]);
  1617. if(data8.length > 0){
  1618. temp8 = data8[0].value;
  1619. }
  1620. if(dataAdd5.length > 0){
  1621. tempAdd5 = dataAdd5[0].value;
  1622. }
  1623. let solutionFinancing = temp8 + tempAdd5;
  1624. return {
  1625. registerCompany,
  1626. financialInstitution,
  1627. financialProduct,
  1628. demandCount,
  1629. demandMoney,
  1630. helpCompany,
  1631. solutionFinancing
  1632. };
  1633. }
  1634. // 银行统计
  1635. async bank(payload) {
  1636. let {skip = 0, limit = 10} = payload;
  1637. let dataAgg = [
  1638. {
  1639. $lookup:
  1640. {
  1641. from: "t_finance_follow",
  1642. let: {
  1643. jg_id: {
  1644. $toString: "$_id"
  1645. }
  1646. },
  1647. pipeline: [
  1648. {
  1649. $match:
  1650. {
  1651. $expr:
  1652. {
  1653. $and:
  1654. [
  1655. {
  1656. $eq: ['$userid', "$$jg_id"]
  1657. },
  1658. ]
  1659. }
  1660. }
  1661. },
  1662. ],
  1663. as: "t_finance_follows"
  1664. }
  1665. },
  1666. {
  1667. $unwind: {
  1668. path: '$t_finance_follows',
  1669. preserveNullAndEmptyArrays: true,
  1670. },
  1671. },
  1672. {
  1673. $group: {
  1674. _id: '$name',
  1675. id: {
  1676. $first: "$_id"
  1677. },
  1678. name: {
  1679. $first: "$name"
  1680. },
  1681. help_count1: {
  1682. $sum: {
  1683. $cond: [{
  1684. $eq: ['$t_finance_follows.orcredit', '1']
  1685. }, 1, 0],
  1686. }
  1687. },
  1688. receive_count1: {
  1689. $sum: {
  1690. $cond: [{
  1691. $eq: ['$t_finance_follows.orcredit', '0']
  1692. }, 1, 0],
  1693. }
  1694. },
  1695. approval_count1: {
  1696. $sum: {
  1697. $cond: [{
  1698. $eq: ['$t_finance_follows.orcredit', '2']
  1699. }, 1, 0],
  1700. }
  1701. },
  1702. refuse_count1: {
  1703. $sum: {
  1704. $cond: [{
  1705. $eq: ['$t_finance_follows.orcredit', '3']
  1706. }, 1, 0],
  1707. }
  1708. },
  1709. sum_count1: {
  1710. $sum: {
  1711. $cond: [{
  1712. $eq: ['$t_finance_follows.orcredit', '1']
  1713. }, '$t_finance_follows.credit_money', 0],
  1714. }
  1715. },
  1716. sum_time1: {
  1717. $sum: {
  1718. $cond: [{
  1719. $eq: ['$t_finance_follows.orcredit', '1']
  1720. }, '$t_finance_follows.accept_time', 0],
  1721. }
  1722. },
  1723. }
  1724. },
  1725. {
  1726. $lookup:
  1727. {
  1728. from: "intelligent_follow",
  1729. let: {
  1730. jg_id: {
  1731. $toString: "$id"
  1732. }
  1733. },
  1734. pipeline: [
  1735. {
  1736. $match:
  1737. {
  1738. $expr:
  1739. {
  1740. $and:
  1741. [
  1742. {
  1743. $eq: ['$uid', "$$jg_id"]
  1744. },
  1745. ]
  1746. }
  1747. }
  1748. },
  1749. ],
  1750. as: "intelligent_follows"
  1751. }
  1752. },
  1753. {
  1754. $unwind: {
  1755. path: '$intelligent_follows',
  1756. preserveNullAndEmptyArrays: true,
  1757. },
  1758. },
  1759. {
  1760. $group: {
  1761. _id: '$name',
  1762. id: {
  1763. $first: "$id"
  1764. },
  1765. help_count1: {
  1766. $first: "$help_count1"
  1767. },
  1768. receive_count1: {
  1769. $first: "$receive_count1"
  1770. },
  1771. approval_count1: {
  1772. $first: "$approval_count1"
  1773. },
  1774. refuse_count1: {
  1775. $first: "$refuse_count1"
  1776. },
  1777. sum_count1: {
  1778. $first: "$sum_count1"
  1779. },
  1780. sum_time1: {
  1781. $first: "$sum_time1"
  1782. },
  1783. help_count2: {
  1784. $sum: {
  1785. $cond: [{
  1786. $eq: ['$intelligent_follows.creditStatus', '1']
  1787. }, 1, 0],
  1788. }
  1789. },
  1790. receive_count2: {
  1791. $sum: {
  1792. $cond: [{
  1793. $eq: ['$intelligent_follows.creditStatus', '0']
  1794. }, 1, 0],
  1795. }
  1796. },
  1797. approval_count2: {
  1798. $sum: {
  1799. $cond: [{
  1800. $eq: ['$intelligent_follows.creditStatus', '2']
  1801. }, 1, 0],
  1802. }
  1803. },
  1804. refuse_count2: {
  1805. $sum: {
  1806. $cond: [{
  1807. $eq: ['$intelligent_follows.creditStatus', '3']
  1808. }, 1, 0],
  1809. }
  1810. },
  1811. sum_count2: {
  1812. $sum: {
  1813. $cond: [{
  1814. $eq: ['$intelligent_follows.creditStatus', '1']
  1815. }, '$intelligent_follows.credit_money', 0],
  1816. }
  1817. },
  1818. sum_time2: {
  1819. $sum: {
  1820. $cond: [{
  1821. $eq: ['$intelligent_follows.creditStatus', '1']
  1822. }, '$intelligent_follows.accept_time', 0],
  1823. }
  1824. },
  1825. }
  1826. },
  1827. {
  1828. $lookup:
  1829. {
  1830. from: "claim_need",
  1831. let: {
  1832. jg_id: {
  1833. $toString: "$id"
  1834. }
  1835. },
  1836. pipeline: [
  1837. {
  1838. $match:
  1839. {
  1840. $expr:
  1841. {
  1842. $and:
  1843. [
  1844. {
  1845. $eq: ['$status', "0"],
  1846. },
  1847. {
  1848. $eq: ['$jg_id', "$$jg_id"]
  1849. },
  1850. ]
  1851. }
  1852. }
  1853. },
  1854. ],
  1855. as: "claim_needs"
  1856. }
  1857. },
  1858. {
  1859. $lookup:
  1860. {
  1861. from: "intelligent_docking",
  1862. let: {
  1863. jg_id: {
  1864. $toString: "$id"
  1865. }
  1866. },
  1867. pipeline: [
  1868. {
  1869. $match:
  1870. {
  1871. $expr:
  1872. {
  1873. $and:
  1874. [
  1875. {
  1876. $eq: ['$jg_id', "$$jg_id"]
  1877. },
  1878. ]
  1879. }
  1880. }
  1881. },
  1882. ],
  1883. as: "intelligent_dockings"
  1884. }
  1885. },
  1886. {
  1887. $project: {
  1888. id: 1,
  1889. help_count1: 1,
  1890. receive_count1: 1,
  1891. approval_count1: 1,
  1892. refuse_count1: 1,
  1893. sum_count1: 1,
  1894. sum_time1: 1,
  1895. help_count2: 1,
  1896. receive_count2: 1,
  1897. approval_count2: 1,
  1898. refuse_count2: 1,
  1899. sum_count2: 1,
  1900. sum_time2: 1,
  1901. push_count1: {
  1902. $size: "$claim_needs"
  1903. },
  1904. push_count2: {
  1905. $size: "$intelligent_dockings"
  1906. },
  1907. }
  1908. },
  1909. {
  1910. $project: {
  1911. _id: 0,
  1912. bank_name: '$_id',
  1913. push_count: {
  1914. $add: ["$push_count1", "$push_count2"]
  1915. },
  1916. // receive_count:{ $add: [ "$receive_count1", "$receive_count2" ] },
  1917. approval_count: {
  1918. $add: ["$approval_count1", "$approval_count2"]
  1919. },
  1920. help_count: {
  1921. $add: ["$help_count1", "$help_count2"]
  1922. },
  1923. refuse_count: {
  1924. $add: ["$refuse_count1", "$refuse_count2"]
  1925. },
  1926. sum_money: {
  1927. $add: ["$sum_count1", "$sum_count2"]
  1928. },
  1929. avg_money: {
  1930. $cond: {
  1931. if : {
  1932. $eq: [{
  1933. $add: ["$help_count1", "$help_count2"]
  1934. }, 0]
  1935. },
  1936. then: 0,
  1937. else : {
  1938. $divide: [{
  1939. $add: ["$sum_count1", "$sum_count2"]
  1940. }, {
  1941. $add: ["$help_count1", "$help_count2"]
  1942. }]
  1943. },
  1944. }
  1945. },
  1946. avg_time: {
  1947. $cond: {
  1948. if : {
  1949. $eq: [{
  1950. $add: ["$help_count1", "$help_count2"]
  1951. }, 0]
  1952. },
  1953. then: 0,
  1954. else : {
  1955. $divide: [{
  1956. $add: ["$sum_time1", "$sum_time2"]
  1957. }, {
  1958. $multiply: [{
  1959. $add: ["$help_count1", "$help_count2"]
  1960. }, 86400000]
  1961. }]
  1962. },
  1963. }
  1964. },
  1965. success_probability: {
  1966. $cond: {
  1967. if : {
  1968. $eq: [{
  1969. $add: ["$help_count1", "$help_count2", "$refuse_count1", "$refuse_count2"]
  1970. }, 0]
  1971. },
  1972. then: 0,
  1973. else : {
  1974. $multiply: [{
  1975. $divide: [{
  1976. $add: ["$help_count1", "$help_count2"]
  1977. }, {
  1978. $add: ["$help_count1", "$help_count2", "$refuse_count1", "$refuse_count2"]
  1979. }]
  1980. }, 100]
  1981. },
  1982. }
  1983. },
  1984. }
  1985. },
  1986. {
  1987. $sort: {success_probability:-1}
  1988. },
  1989. {
  1990. $skip: Number.parseInt(skip),
  1991. },
  1992. {
  1993. $limit:Number.parseInt(limit),
  1994. },
  1995. ];
  1996. let totalAgg = [
  1997. {
  1998. $lookup:
  1999. {
  2000. from: "t_finance_follow",
  2001. let: {
  2002. jg_id: {
  2003. $toString: "$_id"
  2004. }
  2005. },
  2006. pipeline: [
  2007. {
  2008. $match:
  2009. {
  2010. $expr:
  2011. {
  2012. $and:
  2013. [
  2014. {
  2015. $eq: ['$userid', "$$jg_id"]
  2016. },
  2017. ]
  2018. }
  2019. }
  2020. },
  2021. ],
  2022. as: "t_finance_follows"
  2023. }
  2024. },
  2025. {
  2026. $unwind: {
  2027. path: '$t_finance_follows',
  2028. preserveNullAndEmptyArrays: true,
  2029. },
  2030. },
  2031. {
  2032. $group: {
  2033. _id: '$name',
  2034. id: {
  2035. $first: "$_id"
  2036. },
  2037. name: {
  2038. $first: "$name"
  2039. },
  2040. help_count1: {
  2041. $sum: {
  2042. $cond: [{
  2043. $eq: ['$t_finance_follows.orcredit', '1']
  2044. }, 1, 0],
  2045. }
  2046. },
  2047. receive_count1: {
  2048. $sum: {
  2049. $cond: [{
  2050. $eq: ['$t_finance_follows.orcredit', '0']
  2051. }, 1, 0],
  2052. }
  2053. },
  2054. approval_count1: {
  2055. $sum: {
  2056. $cond: [{
  2057. $eq: ['$t_finance_follows.orcredit', '2']
  2058. }, 1, 0],
  2059. }
  2060. },
  2061. refuse_count1: {
  2062. $sum: {
  2063. $cond: [{
  2064. $eq: ['$t_finance_follows.orcredit', '3']
  2065. }, 1, 0],
  2066. }
  2067. },
  2068. sum_count1: {
  2069. $sum: {
  2070. $cond: [{
  2071. $eq: ['$t_finance_follows.orcredit', '1']
  2072. }, '$t_finance_follows.credit_money', 0],
  2073. }
  2074. },
  2075. sum_time1: {
  2076. $sum: {
  2077. $cond: [{
  2078. $eq: ['$t_finance_follows.orcredit', '1']
  2079. }, '$t_finance_follows.accept_time', 0],
  2080. }
  2081. },
  2082. }
  2083. },
  2084. {
  2085. $lookup:
  2086. {
  2087. from: "intelligent_follow",
  2088. let: {
  2089. jg_id: {
  2090. $toString: "$id"
  2091. }
  2092. },
  2093. pipeline: [
  2094. {
  2095. $match:
  2096. {
  2097. $expr:
  2098. {
  2099. $and:
  2100. [
  2101. {
  2102. $eq: ['$uid', "$$jg_id"]
  2103. },
  2104. ]
  2105. }
  2106. }
  2107. },
  2108. ],
  2109. as: "intelligent_follows"
  2110. }
  2111. },
  2112. {
  2113. $unwind: {
  2114. path: '$intelligent_follows',
  2115. preserveNullAndEmptyArrays: true,
  2116. },
  2117. },
  2118. {
  2119. $group: {
  2120. _id: '$name',
  2121. id: {
  2122. $first: "$id"
  2123. },
  2124. help_count1: {
  2125. $first: "$help_count1"
  2126. },
  2127. receive_count1: {
  2128. $first: "$receive_count1"
  2129. },
  2130. approval_count1: {
  2131. $first: "$approval_count1"
  2132. },
  2133. refuse_count1: {
  2134. $first: "$refuse_count1"
  2135. },
  2136. sum_count1: {
  2137. $first: "$sum_count1"
  2138. },
  2139. sum_time1: {
  2140. $first: "$sum_time1"
  2141. },
  2142. help_count2: {
  2143. $sum: {
  2144. $cond: [{
  2145. $eq: ['$intelligent_follows.creditStatus', '1']
  2146. }, 1, 0],
  2147. }
  2148. },
  2149. receive_count2: {
  2150. $sum: {
  2151. $cond: [{
  2152. $eq: ['$intelligent_follows.creditStatus', '0']
  2153. }, 1, 0],
  2154. }
  2155. },
  2156. approval_count2: {
  2157. $sum: {
  2158. $cond: [{
  2159. $eq: ['$intelligent_follows.creditStatus', '2']
  2160. }, 1, 0],
  2161. }
  2162. },
  2163. refuse_count2: {
  2164. $sum: {
  2165. $cond: [{
  2166. $eq: ['$intelligent_follows.creditStatus', '3']
  2167. }, 1, 0],
  2168. }
  2169. },
  2170. sum_count2: {
  2171. $sum: {
  2172. $cond: [{
  2173. $eq: ['$intelligent_follows.creditStatus', '1']
  2174. }, '$intelligent_follows.credit_money', 0],
  2175. }
  2176. },
  2177. sum_time2: {
  2178. $sum: {
  2179. $cond: [{
  2180. $eq: ['$intelligent_follows.creditStatus', '1']
  2181. }, '$intelligent_follows.accept_time', 0],
  2182. }
  2183. },
  2184. }
  2185. },
  2186. {
  2187. $lookup:
  2188. {
  2189. from: "claim_need",
  2190. let: {
  2191. jg_id: {
  2192. $toString: "$id"
  2193. }
  2194. },
  2195. pipeline: [
  2196. {
  2197. $match:
  2198. {
  2199. $expr:
  2200. {
  2201. $and:
  2202. [
  2203. {
  2204. $eq: ['$status', "0"],
  2205. },
  2206. {
  2207. $eq: ['$jg_id', "$$jg_id"]
  2208. },
  2209. ]
  2210. }
  2211. }
  2212. },
  2213. ],
  2214. as: "claim_needs"
  2215. }
  2216. },
  2217. {
  2218. $lookup:
  2219. {
  2220. from: "intelligent_docking",
  2221. let: {
  2222. jg_id: {
  2223. $toString: "$id"
  2224. }
  2225. },
  2226. pipeline: [
  2227. {
  2228. $match:
  2229. {
  2230. $expr:
  2231. {
  2232. $and:
  2233. [
  2234. {
  2235. $eq: ['$jg_id', "$$jg_id"]
  2236. },
  2237. ]
  2238. }
  2239. }
  2240. },
  2241. ],
  2242. as: "intelligent_dockings"
  2243. }
  2244. },
  2245. {
  2246. $project: {
  2247. id: 1,
  2248. help_count1: 1,
  2249. receive_count1: 1,
  2250. approval_count1: 1,
  2251. refuse_count1: 1,
  2252. sum_count1: 1,
  2253. sum_time1: 1,
  2254. help_count2: 1,
  2255. receive_count2: 1,
  2256. approval_count2: 1,
  2257. refuse_count2: 1,
  2258. sum_count2: 1,
  2259. sum_time2: 1,
  2260. push_count1: {
  2261. $size: "$claim_needs"
  2262. },
  2263. push_count2: {
  2264. $size: "$intelligent_dockings"
  2265. },
  2266. }
  2267. },
  2268. {
  2269. $project: {
  2270. _id: 0,
  2271. bank_name: '$_id',
  2272. push_count: {
  2273. $add: ["$push_count1", "$push_count2"]
  2274. },
  2275. // receive_count:{ $add: [ "$receive_count1", "$receive_count2" ] },
  2276. approval_count: {
  2277. $add: ["$approval_count1", "$approval_count2"]
  2278. },
  2279. help_count: {
  2280. $add: ["$help_count1", "$help_count2"]
  2281. },
  2282. refuse_count: {
  2283. $add: ["$refuse_count1", "$refuse_count2"]
  2284. },
  2285. sum_money: {
  2286. $add: ["$sum_count1", "$sum_count2"]
  2287. },
  2288. avg_money: {
  2289. $cond: {
  2290. if : {
  2291. $eq: [{
  2292. $add: ["$help_count1", "$help_count2"]
  2293. }, 0]
  2294. },
  2295. then: 0,
  2296. else : {
  2297. $divide: [{
  2298. $add: ["$sum_count1", "$sum_count2"]
  2299. }, {
  2300. $add: ["$help_count1", "$help_count2"]
  2301. }]
  2302. },
  2303. }
  2304. },
  2305. avg_time: {
  2306. $cond: {
  2307. if : {
  2308. $eq: [{
  2309. $add: ["$help_count1", "$help_count2"]
  2310. }, 0]
  2311. },
  2312. then: 0,
  2313. else : {
  2314. $divide: [{
  2315. $add: ["$sum_time1", "$sum_time2"]
  2316. }, {
  2317. $multiply: [{
  2318. $add: ["$help_count1", "$help_count2"]
  2319. }, 86400000]
  2320. }]
  2321. },
  2322. }
  2323. },
  2324. success_probability: {
  2325. $cond: {
  2326. if : {
  2327. $eq: [{
  2328. $add: ["$help_count1", "$help_count2", "$refuse_count1", "$refuse_count2"]
  2329. }, 0]
  2330. },
  2331. then: 0,
  2332. else : {
  2333. $multiply: [{
  2334. $divide: [{
  2335. $add: ["$help_count1", "$help_count2"]
  2336. }, {
  2337. $add: ["$help_count1", "$help_count2", "$refuse_count1", "$refuse_count2"]
  2338. }]
  2339. }, 100]
  2340. },
  2341. }
  2342. },
  2343. }
  2344. },
  2345. {
  2346. $count: 'total',
  2347. },
  2348. ];
  2349. const data = await this.institutionModel.aggregate(dataAgg);
  2350. const totalTemp = await this.institutionModel.aggregate(totalAgg);
  2351. if (totalTemp.length == 0) {
  2352. totalTemp.push({ total: 0 });
  2353. }
  2354. const [{ total }] = totalTemp;
  2355. return {
  2356. data,
  2357. total,
  2358. };
  2359. }
  2360. /*// 银行统计
  2361. async bank(payload) {
  2362. let {skip = 0, limit = 10} = payload;
  2363. let dataAgg = [
  2364. {
  2365. $lookup:
  2366. {
  2367. from: "t_finance_follow",
  2368. let: {
  2369. jg_id: {
  2370. $toString: "$_id"
  2371. }
  2372. },
  2373. pipeline: [
  2374. {
  2375. $match:
  2376. {
  2377. $expr:
  2378. {
  2379. $and:
  2380. [
  2381. {
  2382. $eq: ['$userid', "$$jg_id"]
  2383. },
  2384. ]
  2385. }
  2386. }
  2387. },
  2388. ],
  2389. as: "t_finance_follows"
  2390. }
  2391. },
  2392. {
  2393. $unwind: {
  2394. path: '$t_finance_follows',
  2395. preserveNullAndEmptyArrays: true,
  2396. },
  2397. },
  2398. {
  2399. $group: {
  2400. _id: '$name',
  2401. id: {
  2402. $first: "$_id"
  2403. },
  2404. name: {
  2405. $first: "$name"
  2406. },
  2407. help_count1: {
  2408. $sum: {
  2409. $cond: [{
  2410. $eq: ['$t_finance_follows.orcredit', '1']
  2411. }, 1, 0],
  2412. }
  2413. },
  2414. ing_count1: {
  2415. $sum: {
  2416. $cond: [{
  2417. $eq: ['$t_finance_follows.orcredit', '0']
  2418. }, 1, 0],
  2419. }
  2420. },
  2421. ing_count2: {
  2422. $sum: {
  2423. $cond: [{
  2424. $eq: ['$t_finance_follows.orcredit', '2']
  2425. }, 1, 0],
  2426. }
  2427. },
  2428. refuse_count1: {
  2429. $sum: {
  2430. $cond: [{
  2431. $eq: ['$t_finance_follows.orcredit', '3']
  2432. }, 1, 0],
  2433. }
  2434. },
  2435. }
  2436. },
  2437. {
  2438. $lookup:
  2439. {
  2440. from: "intelligent_follow",
  2441. let: {
  2442. jg_id: {
  2443. $toString: "$id"
  2444. }
  2445. },
  2446. pipeline: [
  2447. {
  2448. $match:
  2449. {
  2450. $expr:
  2451. {
  2452. $and:
  2453. [
  2454. {
  2455. $eq: ['$uid', "$$jg_id"]
  2456. },
  2457. ]
  2458. }
  2459. }
  2460. },
  2461. ],
  2462. as: "intelligent_follows"
  2463. }
  2464. },
  2465. {
  2466. $unwind: {
  2467. path: '$intelligent_follows',
  2468. preserveNullAndEmptyArrays: true,
  2469. },
  2470. },
  2471. {
  2472. $group: {
  2473. _id: '$name',
  2474. help_count1: {
  2475. $first: "$help_count1"
  2476. },
  2477. help_count2: {
  2478. $sum: {
  2479. $cond: [{
  2480. $eq: ['$intelligent_follows.creditStatus', '1']
  2481. }, 1, 0],
  2482. }
  2483. },
  2484. ing_count1: {
  2485. $first: "$ing_count1"
  2486. },
  2487. ing_count2: {
  2488. $first: "$ing_count2"
  2489. },
  2490. ing_count3: {
  2491. $sum: {
  2492. $cond: [{
  2493. $eq: ['$intelligent_follows.creditStatus', '0']
  2494. }, 1, 0],
  2495. }
  2496. },
  2497. ing_count4: {
  2498. $sum: {
  2499. $cond: [{
  2500. $eq: ['$intelligent_follows.creditStatus', '2']
  2501. }, 1, 0],
  2502. }
  2503. },
  2504. refuse_count1: {
  2505. $first: "$refuse_count1"
  2506. },
  2507. refuse_count2: {
  2508. $sum: {
  2509. $cond: [{
  2510. $eq: ['$intelligent_follows.creditStatus', '3']
  2511. }, 1, 0],
  2512. }
  2513. },
  2514. }
  2515. },
  2516. {
  2517. $project: {
  2518. _id : 0,
  2519. bank_name: '$_id',
  2520. help_count: { $add: [ "$help_count1", "$help_count2" ] },
  2521. ing_count: { $add: [ "$ing_count1", "$ing_count2" , "$ing_count3" , "$ing_count4" ] },
  2522. refuse_count: { $add: [ "$refuse_count1", "$refuse_count2" ] },
  2523. }
  2524. },
  2525. {
  2526. $skip: Number.parseInt(skip),
  2527. },
  2528. {
  2529. $limit:Number.parseInt(limit),
  2530. },
  2531. ];
  2532. let totalAgg = [
  2533. {
  2534. $lookup:
  2535. {
  2536. from: "t_finance_follow",
  2537. let: {
  2538. jg_id: {
  2539. $toString: "$_id"
  2540. }
  2541. },
  2542. pipeline: [
  2543. {
  2544. $match:
  2545. {
  2546. $expr:
  2547. {
  2548. $and:
  2549. [
  2550. {
  2551. $eq: ['$userid', "$$jg_id"]
  2552. },
  2553. ]
  2554. }
  2555. }
  2556. },
  2557. ],
  2558. as: "t_finance_follows"
  2559. }
  2560. },
  2561. {
  2562. $unwind: {
  2563. path: '$t_finance_follows',
  2564. preserveNullAndEmptyArrays: true,
  2565. },
  2566. },
  2567. {
  2568. $group: {
  2569. _id: '$name',
  2570. id: {
  2571. $first: "$_id"
  2572. },
  2573. name: {
  2574. $first: "$name"
  2575. },
  2576. help_count1: {
  2577. $sum: {
  2578. $cond: [{
  2579. $eq: ['$t_finance_follows.orcredit', '1']
  2580. }, 1, 0],
  2581. }
  2582. },
  2583. ing_count1: {
  2584. $sum: {
  2585. $cond: [{
  2586. $eq: ['$t_finance_follows.orcredit', '0']
  2587. }, 1, 0],
  2588. }
  2589. },
  2590. ing_count2: {
  2591. $sum: {
  2592. $cond: [{
  2593. $eq: ['$t_finance_follows.orcredit', '2']
  2594. }, 1, 0],
  2595. }
  2596. },
  2597. refuse_count1: {
  2598. $sum: {
  2599. $cond: [{
  2600. $eq: ['$t_finance_follows.orcredit', '3']
  2601. }, 1, 0],
  2602. }
  2603. },
  2604. }
  2605. },
  2606. {
  2607. $lookup:
  2608. {
  2609. from: "intelligent_follow",
  2610. let: {
  2611. jg_id: {
  2612. $toString: "$id"
  2613. }
  2614. },
  2615. pipeline: [
  2616. {
  2617. $match:
  2618. {
  2619. $expr:
  2620. {
  2621. $and:
  2622. [
  2623. {
  2624. $eq: ['$uid', "$$jg_id"]
  2625. },
  2626. ]
  2627. }
  2628. }
  2629. },
  2630. ],
  2631. as: "intelligent_follows"
  2632. }
  2633. },
  2634. {
  2635. $unwind: {
  2636. path: '$intelligent_follows',
  2637. preserveNullAndEmptyArrays: true,
  2638. },
  2639. },
  2640. {
  2641. $group: {
  2642. _id: '$name',
  2643. help_count1: {
  2644. $first: "$help_count1"
  2645. },
  2646. help_count2: {
  2647. $sum: {
  2648. $cond: [{
  2649. $eq: ['$intelligent_follows.creditStatus', '1']
  2650. }, 1, 0],
  2651. }
  2652. },
  2653. ing_count1: {
  2654. $first: "$ing_count1"
  2655. },
  2656. ing_count2: {
  2657. $first: "$ing_count2"
  2658. },
  2659. ing_count3: {
  2660. $sum: {
  2661. $cond: [{
  2662. $eq: ['$intelligent_follows.creditStatus', '0']
  2663. }, 1, 0],
  2664. }
  2665. },
  2666. ing_count4: {
  2667. $sum: {
  2668. $cond: [{
  2669. $eq: ['$intelligent_follows.creditStatus', '2']
  2670. }, 1, 0],
  2671. }
  2672. },
  2673. refuse_count1: {
  2674. $first: "$refuse_count1"
  2675. },
  2676. refuse_count2: {
  2677. $sum: {
  2678. $cond: [{
  2679. $eq: ['$intelligent_follows.creditStatus', '3']
  2680. }, 1, 0],
  2681. }
  2682. },
  2683. }
  2684. },
  2685. {
  2686. $project: {
  2687. _id : 0,
  2688. bank_name: '$_id',
  2689. help_count: { $add: [ "$help_count1", "$help_count2" ] },
  2690. ing_count: { $add: [ "$ing_count1", "$ing_count2" , "$ing_count3" , "$ing_count4" ] },
  2691. refuse_count: { $add: [ "$refuse_count1", "$refuse_count2" ] },
  2692. }
  2693. },
  2694. {
  2695. $count: 'total',
  2696. },
  2697. ];
  2698. const data = await this.institutionModel.aggregate(dataAgg);
  2699. const totalTemp = await this.institutionModel.aggregate(totalAgg);
  2700. if (totalTemp.length == 0) {
  2701. totalTemp.push({ total: 0 });
  2702. }
  2703. const [{ total }] = totalTemp;
  2704. return {
  2705. data,
  2706. total,
  2707. };
  2708. }*/
  2709. getTime(payload, dateType) {
  2710. if (dateType === '1') {
  2711. let tempYear = moment().get('year');
  2712. let startTime = moment([tempYear]).add(-11, 'years').valueOf();
  2713. if (payload.start_time && payload.end_time) {
  2714. tempYear = moment(Number(payload.end_time)).get('year');
  2715. startTime = Number(payload.start_time);
  2716. }
  2717. let endTime = moment([tempYear]).add(1, 'years').valueOf();
  2718. return {startTime, endTime};
  2719. } else {
  2720. let tempYear = moment().get('year');
  2721. let tempMonth = moment().get('month');
  2722. let startTime = moment([tempYear, tempMonth]).add(-11, 'months').valueOf();
  2723. if (payload.start_time && payload.end_time) {
  2724. tempYear = moment(Number(payload.end_time)).get('year');
  2725. tempMonth = moment(Number(payload.end_time)).get('month');
  2726. startTime = Number(payload.start_time);
  2727. }
  2728. let endTime = moment([tempYear, tempMonth]).add(1, 'months').valueOf();
  2729. return {startTime, endTime};
  2730. }
  2731. }
  2732. getTimeArray(startTime, endTime, dateType) {
  2733. if (dateType === '1') {
  2734. let temp = startTime;
  2735. let timeArray = [];
  2736. while (true) {
  2737. if (temp >= endTime) {
  2738. break;
  2739. }
  2740. let label = moment(temp).get('year') + '';
  2741. timeArray.push({label: label, value: 0});
  2742. temp = moment(temp).add(1, 'years').valueOf();
  2743. }
  2744. return timeArray;
  2745. } else {
  2746. let temp = startTime;
  2747. let timeArray = [];
  2748. while (true) {
  2749. if (temp >= endTime) {
  2750. break;
  2751. }
  2752. let tempMonth = moment(temp).get('month') + 1 >= 10 ? (moment(temp).get('month') + 1).toString() : '0' + (moment(temp).get('month') + 1).toString();
  2753. let label = moment(temp).get('year') + '/' + tempMonth;
  2754. timeArray.push({label: label, value: 0});
  2755. temp = moment(temp).add(1, 'months').valueOf();
  2756. }
  2757. return timeArray;
  2758. }
  2759. }
  2760. getTimeMatch(type, reserve, payload) {
  2761. switch (type) {
  2762. case '1':
  2763. let matchA = [];
  2764. return {
  2765. $expr:
  2766. {
  2767. $and:
  2768. [
  2769. {
  2770. $gte: ['$time', reserve.startTime],
  2771. },
  2772. {
  2773. $lt: ['$time', reserve.endTime],
  2774. },
  2775. {
  2776. $eq: ['$status', '0'],
  2777. },
  2778. ...matchA,
  2779. ],
  2780. },
  2781. };
  2782. case '2':
  2783. let matchB = [];
  2784. return {
  2785. $expr:
  2786. {
  2787. $and:
  2788. [
  2789. {
  2790. $gte: ['$time', reserve.startTime],
  2791. },
  2792. {
  2793. $lt: ['$time', reserve.endTime],
  2794. },
  2795. {
  2796. $eq: ['$orcredit', '1'],
  2797. },
  2798. ...matchB,
  2799. ],
  2800. },
  2801. };
  2802. case '3':
  2803. let matchC = [];
  2804. return {
  2805. $expr:
  2806. {
  2807. $and:
  2808. [
  2809. {
  2810. $gte: ['$time', reserve.startTime],
  2811. },
  2812. {
  2813. $lt: ['$time', reserve.endTime],
  2814. },
  2815. {
  2816. $eq: ['$status', '1'],
  2817. },
  2818. ...matchC,
  2819. ],
  2820. },
  2821. };
  2822. case '4':
  2823. let matchD = [];
  2824. return {
  2825. $expr:
  2826. {
  2827. $and:
  2828. [
  2829. {
  2830. $gte: ['$time', reserve.startTime],
  2831. },
  2832. {
  2833. $lt: ['$time', reserve.endTime],
  2834. },
  2835. {
  2836. $eq: ['$orcredit', '1'],
  2837. },
  2838. ...matchD,
  2839. ],
  2840. },
  2841. };
  2842. case '5':
  2843. let matchE = [];
  2844. return {
  2845. $expr:
  2846. {
  2847. $and:
  2848. [
  2849. {
  2850. $gte: ['$time', reserve.startTime],
  2851. },
  2852. {
  2853. $lt: ['$time', reserve.endTime],
  2854. },
  2855. {
  2856. $eq: ['$status', '0'],
  2857. },
  2858. ...matchE,
  2859. ],
  2860. },
  2861. };
  2862. case '6':
  2863. let matchF = [];
  2864. return {
  2865. $expr:
  2866. {
  2867. $and:
  2868. [
  2869. {
  2870. $gte: ['$time', reserve.startTime],
  2871. },
  2872. {
  2873. $lt: ['$time', reserve.endTime],
  2874. },
  2875. {
  2876. $eq: ['$status', '0'],
  2877. },
  2878. ...matchF,
  2879. ],
  2880. },
  2881. };
  2882. case '7':
  2883. let matchG = [];
  2884. return {
  2885. $expr:
  2886. {
  2887. $and:
  2888. [
  2889. {
  2890. $gte: ['$time', reserve.startTime],
  2891. },
  2892. {
  2893. $lt: ['$time', reserve.endTime],
  2894. },
  2895. {
  2896. $eq: ['$status', '1'],
  2897. },
  2898. ...matchG,
  2899. ],
  2900. },
  2901. };
  2902. case '8':
  2903. let matchH = [];
  2904. return {
  2905. $expr:
  2906. {
  2907. $and:
  2908. [
  2909. {
  2910. $gte: ['$time', reserve.startTime],
  2911. },
  2912. {
  2913. $lt: ['$time', reserve.endTime],
  2914. },
  2915. {
  2916. $eq: ['$status', '1'],
  2917. },
  2918. ...matchH,
  2919. ],
  2920. },
  2921. };
  2922. case '9':
  2923. let matchI = [];
  2924. return {
  2925. $expr:
  2926. {
  2927. $and:
  2928. [
  2929. {
  2930. $gte: ['$time', reserve.startTime],
  2931. },
  2932. {
  2933. $lt: ['$time', reserve.endTime],
  2934. },
  2935. ...matchI,
  2936. ],
  2937. },
  2938. };
  2939. case '10':
  2940. let matchJ = [];
  2941. return {
  2942. $expr:
  2943. {
  2944. $and:
  2945. [
  2946. {
  2947. $gte: ['$time', reserve.startTime],
  2948. },
  2949. {
  2950. $lt: ['$time', reserve.endTime],
  2951. },
  2952. ...matchJ,
  2953. ],
  2954. },
  2955. };
  2956. }
  2957. }
  2958. getTimeGroup(type, dateType) {
  2959. if (dateType === '1') {
  2960. switch (type) {
  2961. case '1':
  2962. return {
  2963. _id: {
  2964. year: '$year',
  2965. },
  2966. value: {
  2967. $sum: '$money',
  2968. },
  2969. }
  2970. case '2':
  2971. return {
  2972. _id: {
  2973. year: '$year',
  2974. },
  2975. value: {
  2976. $sum: '$money',
  2977. },
  2978. }
  2979. case '3':
  2980. return {
  2981. _id: {
  2982. year: '$year',
  2983. },
  2984. value: {
  2985. $sum: 1,
  2986. },
  2987. };
  2988. case '4':
  2989. return {
  2990. _id: {
  2991. year: '$year',
  2992. },
  2993. value: {
  2994. $sum: 1,
  2995. },
  2996. };
  2997. case '5':
  2998. return {
  2999. _id: {
  3000. year: '$year',
  3001. },
  3002. value: {
  3003. $sum: 1,
  3004. },
  3005. };
  3006. case '6':
  3007. return {
  3008. _id: {
  3009. year: '$year',
  3010. },
  3011. value: {
  3012. $sum: 1,
  3013. },
  3014. };
  3015. case '7':
  3016. return {
  3017. _id: {
  3018. year: '$year',
  3019. },
  3020. value: {
  3021. $sum: 1,
  3022. },
  3023. };
  3024. case '8':
  3025. return {
  3026. _id: {
  3027. year: '$year',
  3028. },
  3029. value: {
  3030. $sum: 1,
  3031. },
  3032. };
  3033. case '9':
  3034. return {
  3035. _id: {
  3036. year: '$year',
  3037. },
  3038. value: {
  3039. $sum: '$money',
  3040. },
  3041. }
  3042. case '10':
  3043. return {
  3044. _id: {
  3045. year: '$year',
  3046. },
  3047. value: {
  3048. $sum: 1,
  3049. },
  3050. };
  3051. }
  3052. } else {
  3053. switch (type) {
  3054. case '1':
  3055. return {
  3056. _id: {
  3057. year: '$year',
  3058. month: '$month',
  3059. },
  3060. value: {
  3061. $sum: '$money',
  3062. },
  3063. }
  3064. case '2':
  3065. return {
  3066. _id: {
  3067. year: '$year',
  3068. month: '$month',
  3069. },
  3070. value: {
  3071. $sum: '$money',
  3072. },
  3073. }
  3074. case '3':
  3075. return {
  3076. _id: {
  3077. year: '$year',
  3078. month: '$month',
  3079. },
  3080. value: {
  3081. $sum: 1,
  3082. },
  3083. };
  3084. case '4':
  3085. return {
  3086. _id: {
  3087. year: '$year',
  3088. month: '$month',
  3089. },
  3090. value: {
  3091. $sum: 1,
  3092. },
  3093. };
  3094. case '5':
  3095. return {
  3096. _id: {
  3097. year: '$year',
  3098. month: '$month',
  3099. },
  3100. value: {
  3101. $sum: 1,
  3102. },
  3103. };
  3104. case '6':
  3105. return {
  3106. _id: {
  3107. year: '$year',
  3108. month: '$month',
  3109. },
  3110. value: {
  3111. $sum: 1,
  3112. },
  3113. };
  3114. case '7':
  3115. return {
  3116. _id: {
  3117. year: '$year',
  3118. month: '$month',
  3119. },
  3120. value: {
  3121. $sum: 1,
  3122. },
  3123. };
  3124. case '8':
  3125. return {
  3126. _id: {
  3127. year: '$year',
  3128. month: '$month',
  3129. },
  3130. value: {
  3131. $sum: 1,
  3132. },
  3133. };
  3134. case '9':
  3135. return {
  3136. _id: {
  3137. year: '$year',
  3138. month: '$month',
  3139. },
  3140. value: {
  3141. $sum: '$money',
  3142. },
  3143. }
  3144. case '10':
  3145. return {
  3146. _id: {
  3147. year: '$year',
  3148. month: '$month',
  3149. },
  3150. value: {
  3151. $sum: 1,
  3152. },
  3153. };
  3154. }
  3155. }
  3156. }
  3157. getTimeSort(dateType) {
  3158. if (dateType === '1') {
  3159. return {
  3160. '_id.year': 1,
  3161. }
  3162. } else {
  3163. return {
  3164. '_id.year': 1,
  3165. '_id.month': 1
  3166. }
  3167. }
  3168. }
  3169. getTimeLabel(dateType) {
  3170. if (dateType === '1') {
  3171. return {
  3172. $toString: '$_id.year'
  3173. };
  3174. } else {
  3175. return {
  3176. $concat: [{
  3177. $toString: '$_id.year'
  3178. }, '/', {
  3179. $cond: {
  3180. if: {
  3181. $gte: ["$_id.month", 10]
  3182. },
  3183. then: {
  3184. $toString: '$_id.month'
  3185. },
  3186. else: {
  3187. $concat: ['0', {
  3188. $toString: '$_id.month'
  3189. }]
  3190. }
  3191. }
  3192. }]
  3193. };
  3194. }
  3195. }
  3196. formatTimeData(timeArray, tempData) {
  3197. return timeArray.map(timeItem => {
  3198. let label = timeItem.label;
  3199. let value = timeItem.value;
  3200. tempData.forEach(dataItem => {
  3201. if (timeItem.label === dataItem.label) {
  3202. value += dataItem.value;
  3203. }
  3204. })
  3205. return {label, value};
  3206. });
  3207. }
  3208. getMatch(type, payload) {
  3209. switch (type) {
  3210. case '1':
  3211. let matchA = [];
  3212. if (payload.start_time && payload.end_time) {
  3213. matchA.push({
  3214. $gte: ['$time', Number(payload.start_time)],
  3215. });
  3216. matchA.push({
  3217. $lt: ['$time', Number(payload.end_time)],
  3218. });
  3219. }
  3220. return {
  3221. $expr:
  3222. {
  3223. $and:
  3224. [
  3225. ...matchA,
  3226. {
  3227. $eq: ['$status', '1'],
  3228. },
  3229. ],
  3230. },
  3231. };
  3232. case '2':
  3233. let matchB = [];
  3234. if (payload.start_time && payload.end_time) {
  3235. matchB.push({
  3236. $gte: ['$time', Number(payload.start_time)],
  3237. });
  3238. matchB.push({
  3239. $lt: ['$time', Number(payload.end_time)],
  3240. });
  3241. }
  3242. return {
  3243. $expr:
  3244. {
  3245. $and:
  3246. [
  3247. ...matchB,
  3248. {
  3249. $eq: ['$status', '1'],
  3250. },
  3251. ],
  3252. },
  3253. };
  3254. case '3':
  3255. let matchC = [];
  3256. if (payload.start_time && payload.end_time) {
  3257. matchC.push({
  3258. $gte: ['$time', Number(payload.start_time)],
  3259. });
  3260. matchC.push({
  3261. $lt: ['$time', Number(payload.end_time)],
  3262. });
  3263. }
  3264. return {
  3265. $expr:
  3266. {
  3267. $and:
  3268. [
  3269. ...matchC,
  3270. {
  3271. $eq: ['$orcredit', '1'],
  3272. },
  3273. ],
  3274. },
  3275. };
  3276. case '4':
  3277. let matchD = [];
  3278. if (payload.start_time && payload.end_time) {
  3279. matchD.push({
  3280. $gte: ['$time', Number(payload.start_time)],
  3281. });
  3282. matchD.push({
  3283. $lt: ['$time', Number(payload.end_time)],
  3284. });
  3285. }
  3286. return {
  3287. $expr:
  3288. {
  3289. $and:
  3290. [
  3291. ...matchD,
  3292. {
  3293. $eq: ['$orcredit', '1'],
  3294. },
  3295. ],
  3296. },
  3297. };
  3298. }
  3299. }
  3300. formatData(array, data) {
  3301. return array.map(arrayItem => {
  3302. let label = arrayItem.name;
  3303. let value = 0;
  3304. for (let dataItem of data) {
  3305. if (arrayItem._doc.code === dataItem.code) {
  3306. value = dataItem.value;
  3307. break;
  3308. }
  3309. }
  3310. return {label, value};
  3311. }).sort(function (a, b) {
  3312. return b.value - a.value
  3313. });
  3314. }
  3315. formatAddData(array, data) {
  3316. return array.map(arrayItem => {
  3317. let label = arrayItem.name;
  3318. let value = 0;
  3319. for (let dataItem of data) {
  3320. if (arrayItem._doc.code === dataItem.code) {
  3321. value += dataItem.value;
  3322. }
  3323. }
  3324. return {label, value};
  3325. }).sort(function (a, b) {
  3326. return b.value - a.value
  3327. });
  3328. }
  3329. }
  3330. module.exports = TGovernmentStatisticsService;