tGovernmentStatistics.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836
  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. getTime(payload, dateType) {
  1635. if (dateType === '1') {
  1636. let tempYear = moment().get('year');
  1637. let startTime = moment([tempYear]).add(-11, 'years').valueOf();
  1638. if (payload.start_time && payload.end_time) {
  1639. tempYear = moment(Number(payload.end_time)).get('year');
  1640. startTime = Number(payload.start_time);
  1641. }
  1642. let endTime = moment([tempYear]).add(1, 'years').valueOf();
  1643. return {startTime, endTime};
  1644. } else {
  1645. let tempYear = moment().get('year');
  1646. let tempMonth = moment().get('month');
  1647. let startTime = moment([tempYear, tempMonth]).add(-11, 'months').valueOf();
  1648. if (payload.start_time && payload.end_time) {
  1649. tempYear = moment(Number(payload.end_time)).get('year');
  1650. tempMonth = moment(Number(payload.end_time)).get('month');
  1651. startTime = Number(payload.start_time);
  1652. }
  1653. let endTime = moment([tempYear, tempMonth]).add(1, 'months').valueOf();
  1654. return {startTime, endTime};
  1655. }
  1656. }
  1657. getTimeArray(startTime, endTime, dateType) {
  1658. if (dateType === '1') {
  1659. let temp = startTime;
  1660. let timeArray = [];
  1661. while (true) {
  1662. if (temp >= endTime) {
  1663. break;
  1664. }
  1665. let label = moment(temp).get('year') + '';
  1666. timeArray.push({label: label, value: 0});
  1667. temp = moment(temp).add(1, 'years').valueOf();
  1668. }
  1669. return timeArray;
  1670. } else {
  1671. let temp = startTime;
  1672. let timeArray = [];
  1673. while (true) {
  1674. if (temp >= endTime) {
  1675. break;
  1676. }
  1677. let tempMonth = moment(temp).get('month') + 1 >= 10 ? (moment(temp).get('month') + 1).toString() : '0' + (moment(temp).get('month') + 1).toString();
  1678. let label = moment(temp).get('year') + '/' + tempMonth;
  1679. timeArray.push({label: label, value: 0});
  1680. temp = moment(temp).add(1, 'months').valueOf();
  1681. }
  1682. return timeArray;
  1683. }
  1684. }
  1685. getTimeMatch(type, reserve, payload) {
  1686. switch (type) {
  1687. case '1':
  1688. let matchA = [];
  1689. return {
  1690. $expr:
  1691. {
  1692. $and:
  1693. [
  1694. {
  1695. $gte: ['$time', reserve.startTime],
  1696. },
  1697. {
  1698. $lt: ['$time', reserve.endTime],
  1699. },
  1700. {
  1701. $eq: ['$status', '0'],
  1702. },
  1703. ...matchA,
  1704. ],
  1705. },
  1706. };
  1707. case '2':
  1708. let matchB = [];
  1709. return {
  1710. $expr:
  1711. {
  1712. $and:
  1713. [
  1714. {
  1715. $gte: ['$time', reserve.startTime],
  1716. },
  1717. {
  1718. $lt: ['$time', reserve.endTime],
  1719. },
  1720. {
  1721. $eq: ['$orcredit', '1'],
  1722. },
  1723. ...matchB,
  1724. ],
  1725. },
  1726. };
  1727. case '3':
  1728. let matchC = [];
  1729. return {
  1730. $expr:
  1731. {
  1732. $and:
  1733. [
  1734. {
  1735. $gte: ['$time', reserve.startTime],
  1736. },
  1737. {
  1738. $lt: ['$time', reserve.endTime],
  1739. },
  1740. {
  1741. $eq: ['$status', '1'],
  1742. },
  1743. ...matchC,
  1744. ],
  1745. },
  1746. };
  1747. case '4':
  1748. let matchD = [];
  1749. return {
  1750. $expr:
  1751. {
  1752. $and:
  1753. [
  1754. {
  1755. $gte: ['$time', reserve.startTime],
  1756. },
  1757. {
  1758. $lt: ['$time', reserve.endTime],
  1759. },
  1760. {
  1761. $eq: ['$orcredit', '1'],
  1762. },
  1763. ...matchD,
  1764. ],
  1765. },
  1766. };
  1767. case '5':
  1768. let matchE = [];
  1769. return {
  1770. $expr:
  1771. {
  1772. $and:
  1773. [
  1774. {
  1775. $gte: ['$time', reserve.startTime],
  1776. },
  1777. {
  1778. $lt: ['$time', reserve.endTime],
  1779. },
  1780. {
  1781. $eq: ['$status', '0'],
  1782. },
  1783. ...matchE,
  1784. ],
  1785. },
  1786. };
  1787. case '6':
  1788. let matchF = [];
  1789. return {
  1790. $expr:
  1791. {
  1792. $and:
  1793. [
  1794. {
  1795. $gte: ['$time', reserve.startTime],
  1796. },
  1797. {
  1798. $lt: ['$time', reserve.endTime],
  1799. },
  1800. {
  1801. $eq: ['$status', '0'],
  1802. },
  1803. ...matchF,
  1804. ],
  1805. },
  1806. };
  1807. case '7':
  1808. let matchG = [];
  1809. return {
  1810. $expr:
  1811. {
  1812. $and:
  1813. [
  1814. {
  1815. $gte: ['$time', reserve.startTime],
  1816. },
  1817. {
  1818. $lt: ['$time', reserve.endTime],
  1819. },
  1820. {
  1821. $eq: ['$status', '1'],
  1822. },
  1823. ...matchG,
  1824. ],
  1825. },
  1826. };
  1827. case '8':
  1828. let matchH = [];
  1829. return {
  1830. $expr:
  1831. {
  1832. $and:
  1833. [
  1834. {
  1835. $gte: ['$time', reserve.startTime],
  1836. },
  1837. {
  1838. $lt: ['$time', reserve.endTime],
  1839. },
  1840. {
  1841. $eq: ['$status', '1'],
  1842. },
  1843. ...matchH,
  1844. ],
  1845. },
  1846. };
  1847. case '9':
  1848. let matchI = [];
  1849. return {
  1850. $expr:
  1851. {
  1852. $and:
  1853. [
  1854. {
  1855. $gte: ['$time', reserve.startTime],
  1856. },
  1857. {
  1858. $lt: ['$time', reserve.endTime],
  1859. },
  1860. ...matchI,
  1861. ],
  1862. },
  1863. };
  1864. case '10':
  1865. let matchJ = [];
  1866. return {
  1867. $expr:
  1868. {
  1869. $and:
  1870. [
  1871. {
  1872. $gte: ['$time', reserve.startTime],
  1873. },
  1874. {
  1875. $lt: ['$time', reserve.endTime],
  1876. },
  1877. ...matchJ,
  1878. ],
  1879. },
  1880. };
  1881. }
  1882. }
  1883. getTimeGroup(type, dateType) {
  1884. if (dateType === '1') {
  1885. switch (type) {
  1886. case '1':
  1887. return {
  1888. _id: {
  1889. year: '$year',
  1890. },
  1891. value: {
  1892. $sum: '$money',
  1893. },
  1894. }
  1895. case '2':
  1896. return {
  1897. _id: {
  1898. year: '$year',
  1899. },
  1900. value: {
  1901. $sum: '$money',
  1902. },
  1903. }
  1904. case '3':
  1905. return {
  1906. _id: {
  1907. year: '$year',
  1908. },
  1909. value: {
  1910. $sum: 1,
  1911. },
  1912. };
  1913. case '4':
  1914. return {
  1915. _id: {
  1916. year: '$year',
  1917. },
  1918. value: {
  1919. $sum: 1,
  1920. },
  1921. };
  1922. case '5':
  1923. return {
  1924. _id: {
  1925. year: '$year',
  1926. },
  1927. value: {
  1928. $sum: 1,
  1929. },
  1930. };
  1931. case '6':
  1932. return {
  1933. _id: {
  1934. year: '$year',
  1935. },
  1936. value: {
  1937. $sum: 1,
  1938. },
  1939. };
  1940. case '7':
  1941. return {
  1942. _id: {
  1943. year: '$year',
  1944. },
  1945. value: {
  1946. $sum: 1,
  1947. },
  1948. };
  1949. case '8':
  1950. return {
  1951. _id: {
  1952. year: '$year',
  1953. },
  1954. value: {
  1955. $sum: 1,
  1956. },
  1957. };
  1958. case '9':
  1959. return {
  1960. _id: {
  1961. year: '$year',
  1962. },
  1963. value: {
  1964. $sum: '$money',
  1965. },
  1966. }
  1967. case '10':
  1968. return {
  1969. _id: {
  1970. year: '$year',
  1971. },
  1972. value: {
  1973. $sum: 1,
  1974. },
  1975. };
  1976. }
  1977. } else {
  1978. switch (type) {
  1979. case '1':
  1980. return {
  1981. _id: {
  1982. year: '$year',
  1983. month: '$month',
  1984. },
  1985. value: {
  1986. $sum: '$money',
  1987. },
  1988. }
  1989. case '2':
  1990. return {
  1991. _id: {
  1992. year: '$year',
  1993. month: '$month',
  1994. },
  1995. value: {
  1996. $sum: '$money',
  1997. },
  1998. }
  1999. case '3':
  2000. return {
  2001. _id: {
  2002. year: '$year',
  2003. month: '$month',
  2004. },
  2005. value: {
  2006. $sum: 1,
  2007. },
  2008. };
  2009. case '4':
  2010. return {
  2011. _id: {
  2012. year: '$year',
  2013. month: '$month',
  2014. },
  2015. value: {
  2016. $sum: 1,
  2017. },
  2018. };
  2019. case '5':
  2020. return {
  2021. _id: {
  2022. year: '$year',
  2023. month: '$month',
  2024. },
  2025. value: {
  2026. $sum: 1,
  2027. },
  2028. };
  2029. case '6':
  2030. return {
  2031. _id: {
  2032. year: '$year',
  2033. month: '$month',
  2034. },
  2035. value: {
  2036. $sum: 1,
  2037. },
  2038. };
  2039. case '7':
  2040. return {
  2041. _id: {
  2042. year: '$year',
  2043. month: '$month',
  2044. },
  2045. value: {
  2046. $sum: 1,
  2047. },
  2048. };
  2049. case '8':
  2050. return {
  2051. _id: {
  2052. year: '$year',
  2053. month: '$month',
  2054. },
  2055. value: {
  2056. $sum: 1,
  2057. },
  2058. };
  2059. case '9':
  2060. return {
  2061. _id: {
  2062. year: '$year',
  2063. month: '$month',
  2064. },
  2065. value: {
  2066. $sum: '$money',
  2067. },
  2068. }
  2069. case '10':
  2070. return {
  2071. _id: {
  2072. year: '$year',
  2073. month: '$month',
  2074. },
  2075. value: {
  2076. $sum: 1,
  2077. },
  2078. };
  2079. }
  2080. }
  2081. }
  2082. getTimeSort(dateType) {
  2083. if (dateType === '1') {
  2084. return {
  2085. '_id.year': 1,
  2086. }
  2087. } else {
  2088. return {
  2089. '_id.year': 1,
  2090. '_id.month': 1
  2091. }
  2092. }
  2093. }
  2094. getTimeLabel(dateType) {
  2095. if (dateType === '1') {
  2096. return {
  2097. $toString: '$_id.year'
  2098. };
  2099. } else {
  2100. return {
  2101. $concat: [{
  2102. $toString: '$_id.year'
  2103. }, '/', {
  2104. $cond: {
  2105. if: {
  2106. $gte: ["$_id.month", 10]
  2107. },
  2108. then: {
  2109. $toString: '$_id.month'
  2110. },
  2111. else: {
  2112. $concat: ['0', {
  2113. $toString: '$_id.month'
  2114. }]
  2115. }
  2116. }
  2117. }]
  2118. };
  2119. }
  2120. }
  2121. formatTimeData(timeArray, tempData) {
  2122. return timeArray.map(timeItem => {
  2123. let label = timeItem.label;
  2124. let value = timeItem.value;
  2125. tempData.forEach(dataItem => {
  2126. if (timeItem.label === dataItem.label) {
  2127. value += dataItem.value;
  2128. }
  2129. })
  2130. return {label, value};
  2131. });
  2132. }
  2133. getMatch(type, payload) {
  2134. switch (type) {
  2135. case '1':
  2136. let matchA = [];
  2137. if (payload.start_time && payload.end_time) {
  2138. matchA.push({
  2139. $gte: ['$time', Number(payload.start_time)],
  2140. });
  2141. matchA.push({
  2142. $lt: ['$time', Number(payload.end_time)],
  2143. });
  2144. }
  2145. return {
  2146. $expr:
  2147. {
  2148. $and:
  2149. [
  2150. ...matchA,
  2151. {
  2152. $eq: ['$status', '1'],
  2153. },
  2154. ],
  2155. },
  2156. };
  2157. case '2':
  2158. let matchB = [];
  2159. if (payload.start_time && payload.end_time) {
  2160. matchB.push({
  2161. $gte: ['$time', Number(payload.start_time)],
  2162. });
  2163. matchB.push({
  2164. $lt: ['$time', Number(payload.end_time)],
  2165. });
  2166. }
  2167. return {
  2168. $expr:
  2169. {
  2170. $and:
  2171. [
  2172. ...matchB,
  2173. {
  2174. $eq: ['$status', '1'],
  2175. },
  2176. ],
  2177. },
  2178. };
  2179. case '3':
  2180. let matchC = [];
  2181. if (payload.start_time && payload.end_time) {
  2182. matchC.push({
  2183. $gte: ['$time', Number(payload.start_time)],
  2184. });
  2185. matchC.push({
  2186. $lt: ['$time', Number(payload.end_time)],
  2187. });
  2188. }
  2189. return {
  2190. $expr:
  2191. {
  2192. $and:
  2193. [
  2194. ...matchC,
  2195. {
  2196. $eq: ['$orcredit', '1'],
  2197. },
  2198. ],
  2199. },
  2200. };
  2201. case '4':
  2202. let matchD = [];
  2203. if (payload.start_time && payload.end_time) {
  2204. matchD.push({
  2205. $gte: ['$time', Number(payload.start_time)],
  2206. });
  2207. matchD.push({
  2208. $lt: ['$time', Number(payload.end_time)],
  2209. });
  2210. }
  2211. return {
  2212. $expr:
  2213. {
  2214. $and:
  2215. [
  2216. ...matchD,
  2217. {
  2218. $eq: ['$orcredit', '1'],
  2219. },
  2220. ],
  2221. },
  2222. };
  2223. }
  2224. }
  2225. formatData(array, data) {
  2226. return array.map(arrayItem => {
  2227. let label = arrayItem.name;
  2228. let value = 0;
  2229. for (let dataItem of data) {
  2230. if (arrayItem._doc.code === dataItem.code) {
  2231. value = dataItem.value;
  2232. break;
  2233. }
  2234. }
  2235. return {label, value};
  2236. }).sort(function (a, b) {
  2237. return b.value - a.value
  2238. });
  2239. }
  2240. formatAddData(array, data) {
  2241. return array.map(arrayItem => {
  2242. let label = arrayItem.name;
  2243. let value = 0;
  2244. for (let dataItem of data) {
  2245. if (arrayItem._doc.code === dataItem.code) {
  2246. value += dataItem.value;
  2247. }
  2248. }
  2249. return {label, value};
  2250. }).sort(function (a, b) {
  2251. return b.value - a.value
  2252. });
  2253. }
  2254. }
  2255. module.exports = TGovernmentStatisticsService;