flexbiz-server 12.6.11 → 12.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -3
- package/server/app.js +11 -10
- package/server/auths/local.js +6 -6
- package/server/cluster.js +11 -12
- package/server/controllers/controller.js +14 -3
- package/server/controllers/controllerRPT.js +4 -4
- package/server/controllers/controllerUtils.js +12 -12
- package/server/controllers/createHandler.js +20 -21
- package/server/controllers/deleteHandler.js +3 -3
- package/server/controllers/findHandler.js +49 -48
- package/server/controllers/updateHandler.js +25 -26
- package/server/controllers/viewHandler.js +14 -14
- package/server/flow/handlers.js +2 -2
- package/server/flow/nodes/aiAnalysis.js +7 -7
- package/server/flow/nodes/checkAction.js +7 -0
- package/server/flow/nodes/email.js +7 -8
- package/server/flow/utils.js +58 -1
- package/server/global.js +1 -1
- package/server/libs/WorkerStaticPool.js +19 -18
- package/server/libs/cdpskh.js +3 -2
- package/server/libs/cdpstk.js +11 -11
- package/server/libs/cktk.js +3 -3
- package/server/libs/ckvt.js +10 -10
- package/server/libs/ckvtnpp.js +6 -5
- package/server/libs/ckvttt.js +5 -5
- package/server/libs/ctvt.js +6 -6
- package/server/libs/dkcn.js +1 -1
- package/server/libs/dktk.js +4 -3
- package/server/libs/docs.js +31 -25
- package/server/libs/dtbanletheosp.js +4 -1
- package/server/libs/email.js +2 -2
- package/server/libs/executiveDashboard.js +8 -0
- package/server/libs/getGiaban.js +2 -2
- package/server/libs/kpistatus.js +38 -36
- package/server/libs/kqchamcong.js +12 -0
- package/server/libs/kqhdkd.js +8 -0
- package/server/libs/post-book.js +4 -3
- package/server/libs/post-socai.js +2 -2
- package/server/libs/post-sokho.js +5 -5
- package/server/libs/redis-cache.js +0 -0
- package/server/libs/sctcnkh.js +18 -0
- package/server/libs/sessionContext.js +6 -11
- package/server/libs/socaitk.js +9 -0
- package/server/libs/thnxt.js +2 -1
- package/server/libs/tinhgiatb.js +4 -4
- package/server/libs/tuoinophaithu.js +11 -10
- package/server/libs/tuoinophaitra.js +12 -10
- package/server/libs/utils.js +8 -4
- package/server/libs/vectorService.js +12 -8
- package/server/models/actionLog.js +2 -0
- package/server/models/aimemory.js +1 -0
- package/server/models/app.js +3 -2
- package/server/models/approve.js +4 -4
- package/server/models/chat_message.js +2 -0
- package/server/models/chat_session.js +2 -0
- package/server/models/checkin.js +2 -2
- package/server/models/chitietluongds.js +4 -3
- package/server/models/customer.js +8 -9
- package/server/models/data_list_config.js +2 -2
- package/server/models/dmchietkhau.js +3 -4
- package/server/models/dmchietkhauhd.js +3 -4
- package/server/models/dmdiemthuong.js +2 -4
- package/server/models/dmhoahonghd.js +2 -3
- package/server/models/dmhoahongnpp.js +2 -3
- package/server/models/dmletet.js +2 -2
- package/server/models/dmphatdichvu.js +1 -2
- package/server/models/filechunk.js +2 -2
- package/server/models/hd2.js +9 -11
- package/server/models/hd3.js +10 -11
- package/server/models/listinfo.js +3 -1
- package/server/models/pc0.js +4 -4
- package/server/models/pn1.js +9 -11
- package/server/models/pn2.js +3 -3
- package/server/models/pnc.js +9 -10
- package/server/models/pnh.js +5 -6
- package/server/models/pnk.js +7 -7
- package/server/models/pxc.js +9 -10
- package/server/models/pxh.js +6 -7
- package/server/models/pxk.js +7 -8
- package/server/models/schedule.js +17 -16
- package/server/models/sokho.js +10 -11
- package/server/models/step.js +1 -1
- package/server/modules/lists/bg-cdvt.js +1 -1
- package/server/modules/lists/bg-cdvtnpp.js +1 -1
- package/server/modules/lists/ls-chat_session.js +5 -0
- package/server/modules/lists/ls-checkin.js +11 -12
- package/server/modules/lists/ls-chitietluongds.js +2 -2
- package/server/modules/lists/ls-customer.js +20 -20
- package/server/modules/lists/ls-dmnv.js +12 -11
- package/server/modules/lists/ls-file.js +5 -5
- package/server/modules/lists/ls-mailsent.js +3 -3
- package/server/modules/lists/ls-warranty.js +3 -4
- package/server/modules/reports/calc-tinhluong.js +42 -40
- package/server/modules/reports/rp-dtbanlekempk.js +1 -1
- package/server/modules/reports/rp-dtbanletheoctkempk.js +13 -13
- package/server/modules/reports/rp-kgchamcong.js +1 -12
- package/server/modules/reports/rp-kqhdkd.js +1 -7
- package/server/modules/reports/rp-phanbochitienchohoadon.js +1 -1
- package/server/modules/reports/rp-ptcttct.js +2 -2
- package/server/modules/reports/rp-sctcnkh.js +4 -19
- package/server/modules/reports/rp-socaitk.js +1 -8
- package/server/modules/systems/sys-app.js +20 -19
- package/server/modules/vouchers/vo-hd2.js +71 -85
- package/server/modules/vouchers/vo-hd3.js +15 -21
- package/server/modules/vouchers/vo-pbl.js +48 -48
- package/server/modules/vouchers/vo-pc1.js +11 -11
- package/server/modules/vouchers/vo-pc2.js +13 -12
- package/server/modules/vouchers/vo-pgh.js +12 -15
- package/server/modules/vouchers/vo-pn1.js +27 -33
- package/server/modules/vouchers/vo-pnc.js +14 -15
- package/server/modules/vouchers/vo-pnh.js +12 -15
- package/server/modules/vouchers/vo-pnk.js +11 -15
- package/server/modules/vouchers/vo-po1.js +0 -0
- package/server/modules/vouchers/vo-pxc.js +24 -22
- package/server/modules/vouchers/vo-pxh.js +13 -22
- package/server/modules/vouchers/vo-pxk.js +11 -16
- package/server/route.js +32 -32
- package/server/workers/inputWorker.js +8 -8
- package/server/workers/reportWorker.js +3 -4
- package/server/workers/sendEmail.js +11 -11
- package/server/workers/worker-utils.js +3 -1
- package/server/actions/mailtemplate.js +0 -142
- package/server/actions/schedule.js +0 -23
- package/server/libs/schedule.js +0 -18
- package/server/models/bds_area.js +0 -4
- package/server/models/bds_block.js +0 -3
- package/server/models/bds_building.js +0 -4
- package/server/models/bds_floor.js +0 -3
- package/server/models/bds_floordetail.js +0 -9
- package/server/models/bds_nhadat.js +0 -13
- package/server/models/bds_nhadat_moigioi_ban.js +0 -3
- package/server/models/bds_nhomnhadat.js +0 -4
- package/server/models/bds_phanloainhadat.js +0 -3
- package/server/models/campaign.js +0 -6
- package/server/models/form.js +0 -3
- package/server/models/formvalue.js +0 -3
- package/server/models/hlink.js +0 -2
- package/server/models/hlinkvalue.js +0 -2
- package/server/models/kbm_bcdkt.js +0 -4
- package/server/models/kbm_kqhdkd.js +0 -3
- package/server/models/kbm_lcttgt.js +0 -5
- package/server/models/kbm_lctttt.js +0 -4
- package/server/models/kbm_pttct.js +0 -4
- package/server/models/kbm_tkgtgt.js +0 -5
- package/server/models/mailschedule.js +0 -2
- package/server/models/waitevent.js +0 -2
- package/server/modules/lists/ls-bds_area.js +0 -3
- package/server/modules/lists/ls-bds_block.js +0 -1
- package/server/modules/lists/ls-bds_building.js +0 -3
- package/server/modules/lists/ls-bds_dmnhbds.js +0 -6
- package/server/modules/lists/ls-bds_floor.js +0 -2
- package/server/modules/lists/ls-bds_floordetail.js +0 -19
- package/server/modules/lists/ls-bds_nhadat.js +0 -19
- package/server/modules/lists/ls-bds_nhadat_moigioi_ban.js +0 -9
- package/server/modules/lists/ls-bds_nhomnhadat.js +0 -1
- package/server/modules/lists/ls-bds_phanloainhadat.js +0 -1
- package/server/modules/lists/ls-campaign.js +0 -1
- package/server/modules/lists/ls-dmnhnd.js +0 -1
- package/server/modules/lists/ls-formvalue.js +0 -1
- package/server/modules/lists/ls-hlink.js +0 -1
- package/server/modules/lists/ls-hlinkvalue.js +0 -1
- package/server/modules/lists/ls-mailschedule.js +0 -7
- package/server/modules/lists/ls-waitevent.js +0 -1
- package/server/modules/public/form.js +0 -7
- package/server/modules/public/hlink.js +0 -3
package/server/flow/utils.js
CHANGED
|
@@ -1,2 +1,59 @@
|
|
|
1
|
+
const Nodes=[{type:"inject",label:"L\u1ecbch ch\u1ea1y",category:"Input",description:"B\u1eaft \u0111\u1ea7u flow th\u1ee7 c\u00f4ng ho\u1eb7c theo l\u1ecbch tr\u00ecnh (m\u1ed9t l\u1ea7n, l\u1eb7p l\u1ea1i theo kho\u1ea3ng th\u1eddi gian, ho\u1eb7c v\u00e0o th\u1eddi \u0111i\u1ec3m c\u1ee5 th\u1ec3). C\u00f3 th\u1ec3 g\u1eedi \u0111i m\u1ed9t payload (d\u1eef li\u1ec7u) ban \u0111\u1ea7u.",metadata:[{name:"payloadType",label:"Lo\u1ea1i Payload",type:"select",required:!0,options:[{value:"string",
|
|
2
|
+
label:"String"},{value:"json",label:"JSON"},{value:"script",label:"Script"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"date",label:"Timestamp"}],"default":"string"},{name:"payload",label:"Payload",type:"code","default":""},{name:"helpTextScript",label:"H\u01b0\u1edbng d\u1eabn",type:"helpText",text:"Script tr\u1ea3 v\u1ec1 m\u1ed9t JSON data. Tham s\u1ed1 c\u00f3 s\u1eb5n \u0111\u1ec3 s\u1eed d\u1ee5ng: moment"},{name:"repeat",label:"L\u1eb7p l\u1ea1i",type:"select",
|
|
3
|
+
required:!0,options:[{value:"once",label:"M\u1ed9t l\u1ea7n"},{value:"interval",label:"Theo kho\u1ea3ng th\u1eddi gian"},{value:"at",label:"V\u00e0o th\u1eddi \u0111i\u1ec3m c\u1ee5 th\u1ec3"}],"default":"once"},{name:"interval",label:"Kho\u1ea3ng th\u1eddi gian (gi\u00e2y)",type:"number","default":1},{name:"at",label:"V\u00e0o l\u00fac (HH:mm)",type:"text","default":"00:00"},{name:"onceAtStart",label:"Inject m\u1ed9t l\u1ea7n khi b\u1eaft \u0111\u1ea7u?",type:"checkbox","default":!1}],outputDescription:"D\u1eef li\u1ec7u (payload) \u0111\u1ea7u ra \u0111\u01b0\u1ee3c t\u1ea1o t\u1ef1 \u0111\u1ed9ng d\u1ef1a tr\u00ean c\u1ea5u h\u00ecnh 'Lo\u1ea1i Payload'. K\u1ebft qu\u1ea3 c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t Chu\u1ed7i (String), S\u1ed1 nguy\u00ean/th\u1ef1c (Number), Gi\u00e1 tr\u1ecb \u0110\u00fang/Sai (Boolean), \u0110\u1ed1i t\u01b0\u1ee3ng/M\u1ea3ng (JSON), Th\u1eddi gian hi\u1ec7n t\u1ea1i t\u00ednh b\u1eb1ng mili-gi\u00e2y (Timestamp), ho\u1eb7c gi\u00e1 tr\u1ecb t\u00f9y ch\u1ec9nh \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 t\u1eeb \u0111o\u1ea1n m\u00e3 Script."},
|
|
4
|
+
{type:"checkaction",label:"Ch\u1ed1ng tr\u00f9ng l\u1eb7p",category:"Logic",description:"Ki\u1ec3m tra xem m\u1ed9t h\u00e0nh \u0111\u1ed9ng \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n tr\u01b0\u1edbc \u0111\u00f3 ch\u01b0a d\u1ef1a v\u00e0o Kh\u00f3a duy nh\u1ea5t (Idempotency Key). S\u1eed d\u1ee5ng database \u0111\u1ec3 ng\u0103n ch\u1eb7n lu\u1ed3ng (flow) ch\u1ea1y l\u1eb7p l\u1ea1i m\u1ed9t t\u00e1c v\u1ee5 (vd: g\u1eedi mail, tr\u1eeb ti\u1ec1n 2 l\u1ea7n).",outputDescription:"Tr\u1ea3 v\u1ec1 m\u1ed9t Object ch\u1ee9a c\u1edd `isDuplicate` (true/false) \u0111\u1ec3 r\u1ebd nh\u00e1nh flow. N\u1ebfu `isDuplicate: true`, h\u00e0nh \u0111\u1ed9ng n\u00e0y \u0111\u00e3 ho\u1eb7c \u0111ang \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n. Thu\u1ed9c t\u00ednh `originalPayload` gi\u1eef nguy\u00ean d\u1eef li\u1ec7u g\u1ed1c \u0111\u1ec3 c\u00e1c node ph\u00eda sau ti\u1ebfp t\u1ee5c s\u1eed d\u1ee5ng.",
|
|
5
|
+
metadata:[{name:"mode",label:"Ch\u1ebf \u0111\u1ed9 ho\u1ea1t \u0111\u1ed9ng",type:"select",required:!0,options:[{value:"check_and_lock",label:"1. Ki\u1ec3m tra & Kh\u00f3a (Check & Lock)"},{value:"mark_success",label:"2. \u0110\u00e1nh d\u1ea5u Th\u00e0nh c\u00f4ng"},{value:"mark_failed",label:"3. \u0110\u00e1nh d\u1ea5u Th\u1ea5t b\u1ea1i"}],"default":"check_and_lock",helpText:"Ch\u1ecdn 'Ki\u1ec3m tra & Kh\u00f3a' tr\u01b0\u1edbc khi th\u1ef1c hi\u1ec7n h\u00e0nh \u0111\u1ed9ng. Ch\u1ecdn '\u0110\u00e1nh d\u1ea5u...' sau khi h\u00e0nh \u0111\u1ed9ng \u0111\u00e3 ho\u00e0n t\u1ea5t."},
|
|
6
|
+
{name:"actionType",label:"T\u00ean lo\u1ea1i h\u00e0nh \u0111\u1ed9ng (Action Type)",type:"text",required:!0,"default":"SEND_EMAIL",helpText:"Ph\u00e2n lo\u1ea1i h\u00e0nh \u0111\u1ed9ng (VD: SEND_EMAIL, PROCESS_PAYMENT)."},{name:"idempotencyKeyPath",label:"\u0110\u01b0\u1eddng d\u1eabn l\u1ea5y Kh\u00f3a (t\u1eeb Payload)",type:"text",required:!0,"default":"userId",helpText:"Kh\u00f3a duy nh\u1ea5t. V\u00ed d\u1ee5 nh\u1eadp 'userId' th\u00ec h\u1ec7 th\u1ed1ng s\u1ebd l\u1ea5y payload.userId l\u00e0m kh\u00f3a. Nh\u1eadp 'user.email' s\u1ebd l\u1ea5y payload.user.email."}]},
|
|
7
|
+
{type:"email",label:"G\u1eedi email",category:"Output",description:"G\u1eedi email. Th\u00f4ng tin ng\u01b0\u1eddi nh\u1eadn, ch\u1ee7 \u0111\u1ec1, n\u1ed9i dung c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh c\u1ed1 \u0111\u1ecbnh ho\u1eb7c l\u1ea5y t\u1eeb payload \u0111\u1ea7u v\u00e0o.",metadata:[{name:"to",label:"\u0110\u1ebfn (To)",type:"text",default:"",helper:"\u0110\u1ecba ch\u1ec9 email ng\u01b0\u1eddi nh\u1eadn. N\u1ebfu payload l\u00e0 m\u1ea3ng c\u00e1c object {to, subject, message} th\u00ec s\u1ebd g\u1eedi nhi\u1ec1u mail."},
|
|
8
|
+
{name:"subject",label:"Ch\u1ee7 \u0111\u1ec1",type:"text",default:""},{name:"message",label:"N\u1ed9i dung (HTML)",type:"textarea",default:""}],outputDescription:"Tr\u1ea3 v\u1ec1 m\u1ed9t Object (JSON) ch\u1ee9a k\u1ebft qu\u1ea3 g\u1eedi. Bao g\u1ed3m: \n- `successful`: M\u1ea3ng ch\u1ee9a th\u00f4ng tin c\u00e1c email g\u1eedi th\u00e0nh c\u00f4ng, m\u1ed7i ph\u1ea7n t\u1eed \u0111i k\u00e8m tr\u01b0\u1eddng `inputPayload` ch\u1ee9a nguy\u00ean b\u1ea3n d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o c\u1ee7a ng\u01b0\u1eddi nh\u1eadn \u0111\u00f3.\n- `failed`: M\u1ea3ng ch\u1ee9a c\u00e1c email l\u1ed7i, k\u00e8m theo l\u00fd do l\u1ed7i (`error`) v\u00e0 d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o (`inputPayload`)."},
|
|
9
|
+
{type:"webhook",label:"Webhook",category:"Input",description:"T\u1ea1o m\u1ed9t endpoint HTTP \u0111\u1ec3 nh\u1eadn d\u1eef li\u1ec7u t\u1eeb b\u00ean ngo\u00e0i v\u00e0 k\u00edch ho\u1ea1t flow. H\u1ed7 tr\u1ee3 x\u00e1c minh webhook (challenge-response).",metadata:[{name:"path",label:"\u0110\u01b0\u1eddng d\u1eabn (Path)",type:"text",default:"",required:!0,helper:"Ph\u1ea7n cu\u1ed1i c\u1ee7a URL webhook (v\u00ed d\u1ee5: /mydata). Ph\u1ea3i l\u00e0 duy nh\u1ea5t."},{name:"fullpath",label:"URL \u0111\u1ea7y \u0111\u1ee7",
|
|
10
|
+
type:"text",default:"",readOnly:!0},{name:"method",label:"Ph\u01b0\u01a1ng th\u1ee9c HTTP (Data)",type:"select",default:"POST",required:!0,options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"}]},{name:"verificationMethod",label:"Ph\u01b0\u01a1ng th\u1ee9c X\u00e1c minh",type:"select",default:"GET",helper:"Ph\u01b0\u01a1ng th\u1ee9c HTTP d\u00f9ng cho y\u00eau c\u1ea7u x\u00e1c minh (th\u01b0\u1eddng l\u00e0 GET).",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"}]},{name:"verificationChallengeQueryParam",
|
|
11
|
+
label:"Param Challenge X\u00e1c minh",type:"text",default:"",helper:"T\u00ean query parameter ch\u1ee9a m\u00e3 challenge. v\u00ed d\u1ee5 'hub.challenge'"},{name:"verificationTokenQueryParam",label:"Param Token X\u00e1c minh",type:"text",default:"",helper:"T\u00ean query parameter ch\u1ee9a m\u00e3 verify token (n\u1ebfu c\u00f3). v\u00ed d\u1ee5: 'hub.verify_token'"},{name:"verificationTokenValue",label:"Gi\u00e1 tr\u1ecb Token X\u00e1c minh",type:"text",default:"",helper:"Gi\u00e1 tr\u1ecb verify token c\u1ea7n kh\u1edbp (n\u1ebfu c\u00f3)."}]},
|
|
12
|
+
{type:"function",label:"X\u1eed l\u00fd d\u1eef li\u1ec7u",category:"Function",description:"Th\u1ef1c thi m\u1ed9t \u0111o\u1ea1n m\u00e3 JavaScript t\u00f9y ch\u1ec9nh \u0111\u1ec3 x\u1eed l\u00fd payload ho\u1eb7c th\u1ef1c hi\u1ec7n logic ph\u1ee9c t\u1ea1p.",metadata:[{name:"code",label:"Code JavaScript",type:"code",default:"// D\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o c\u00f3 s\u1eb5n trong bi\u1ebfn `payload`\n// Tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u m\u1edbi \u0111\u1ec3 chuy\u1ec3n cho node ti\u1ebfp theo\nreturn payload;",
|
|
13
|
+
required:!0,helper:"Bi\u1ebfn c\u00f3 s\u1eb5n: payload (\u0111\u1ea7u v\u00e0o), node (th\u00f4ng tin node), console, moment, numeral, _ (lodash). D\u00f9ng `return` \u0111\u1ec3 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3."}]},{type:"foreachitem",label:"For Each Item",category:"Function",description:"L\u1eb7p qua t\u1eebng ph\u1ea7n t\u1eed trong m\u1ed9t danh s\u00e1ch (m\u1ea3ng) t\u1eeb payload. V\u1edbi m\u1ed7i ph\u1ea7n t\u1eed, k\u00edch ho\u1ea1t c\u00e1c node ti\u1ebfp theo, truy\u1ec1n ph\u1ea7n t\u1eed \u0111\u00f3 l\u00e0m payload m\u1edbi cho nh\u00e1nh t\u01b0\u01a1ng \u1ee9ng.",
|
|
14
|
+
metadata:[{name:"listPath",label:"\u0110\u01b0\u1eddng d\u1eabn \u0111\u1ebfn Danh s\u00e1ch",type:"text",default:"payload",helper:"\u0110\u01b0\u1eddng d\u1eabn \u0111\u1ebfn m\u1ea3ng trong payload c\u1ea7n l\u1eb7p (v\u00ed d\u1ee5: 'payload.items', 'results.users'). N\u1ebfu \u0111\u1ec3 tr\u1ed1ng ho\u1eb7c 'payload', s\u1ebd coi to\u00e0n b\u1ed9 payload \u0111\u1ea7u v\u00e0o l\u00e0 danh s\u00e1ch."},{name:"outputItemAs",label:"\u0110\u1eb7t t\u00ean cho Payload Ph\u1ea7n t\u1eed",type:"text",
|
|
15
|
+
default:"",helper:"T\u00ean c\u1ee7a thu\u1ed9c t\u00ednh s\u1ebd ch\u1ee9a ph\u1ea7n t\u1eed hi\u1ec7n t\u1ea1i trong payload g\u1eedi \u0111i cho c\u00e1c node sau. V\u00ed d\u1ee5: n\u1ebfu \u0111\u1eb7t l\u00e0 'currentItem', payload s\u1ebd l\u00e0 { currentItem: ... }. N\u1ebfu b\u1ecf tr\u1ed1ng, payload s\u1ebd l\u00e0 ch\u00ednh ph\u1ea7n t\u1eed \u0111\u00f3."}]},{type:"aianalysis",label:"AI Agent",category:"Function",description:"S\u1eed d\u1ee5ng AI \u0111\u1ec3 t\u1ea1o n\u1ed9i dung ho\u1eb7c ph\u00e2n t\u00edch d\u1eef li\u1ec7u d\u1ef1a tr\u00ean d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o l\u00e0 payload. Payload c\u00f3 th\u1ec3 l\u00e0m m\u1ed9t m\u1ea3ng, m\u1ed7i ph\u1ea7n t\u1eed c\u1ee7a m\u1ea3ng c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t y\u00eau c\u1ea7u x\u1eed l\u00fd ri\u00eang n\u1ebfu ch\u1ecdn tu\u1ef3 ch\u1ecdn 'X\u1eed l\u00fd t\u1eebng d\u00f2ng'",
|
|
16
|
+
metadata:[{name:"template",label:"M\u1eabu c\u00e2u l\u1ec7nh",type:"select",default:"",options:[{label:"L\u1ea5y th\u00f4ng tin kh\u00e1ch h\u00e0ng",value:"T\u1eeb danh s\u00e1ch cu\u1ed9c h\u1ed9i tho\u1ea1i, h\u00e3y tr\u00edch xu\u1ea5t id, fb_id, page_id, t\u00ean, s\u1ed1 \u0111i\u1ec7n tho\u1ea1i, \u0111\u1ecba ch\u1ec9, email v\u00e0 ph\u00e2n lo\u1ea1i (c\u00e1c lo\u1ea1i: \u0111\u00e3 mua h\u00e0ng, ti\u1ec1m n\u0103ng, kh\u00f4ng c\u00f3 nhu c\u1ea7u, ch\u01b0a x\u00e1c \u0111\u1ecbnh) c\u1ee7a kh\u00e1ch h\u00e0ng trong m\u1ed7i cu\u1ed9c h\u1ed9i tho\u1ea1i. Tr\u1ea3 v\u1ec1 d\u01b0\u1edbi d\u1ea1ng JSON nh\u01b0: [{'id':'id','fb_id':'fb_id','page_id':'page_id','name':'T\u00ean', 'phone':'\u0110i\u1ec7n tho\u1ea1i', 'address':'\u0110\u1ecba ch\u1ec9','email':'\u0111\u1ecba ch\u1ec9 email','category':'Ph\u00e2n lo\u1ea1i'}]. Tr\u1ea3 l\u1eddi c\u00e2u h\u1ecfi v\u00e0 ch\u1ec9 tr\u1ea3 v\u1ec1 JSON h\u1ee3p l\u1ec7. Kh\u00f4ng tr\u1ea3 l\u1eddi v\u0103n b\u1ea3n, b\u00ecnh lu\u1eadn, ho\u1eb7c gi\u1ea3i th\u00edch."},
|
|
17
|
+
{label:"None",value:""}]},{name:"prompt",label:"C\u00e2u l\u1ec7nh",type:"textarea",default:"",required:!0,helper:"C\u00e2u l\u1ec7nh y\u00eau c\u1ea7u AI th\u1ef1c hi\u1ec7n m\u1ed9t vi\u1ec7c g\u00ec \u0111\u00f3 d\u1ef1a tr\u00ean d\u1eef li\u1ec7u l\u00e0 payload \u0111\u1ea7u v\u00e0o"},{name:"handle_multi_line",label:"X\u1eed l\u00fd t\u1eebng d\u00f2ng",type:"checkbox",default:!1,helper:"N\u1ebfu payload l\u00e0 m\u1ed9t m\u1ea3ng d\u1eef li\u1ec7u th\u00ec m\u1ed7i d\u00f2ng l\u00e0 m\u1ed9t y\u00eau c\u1ea7u?"}]},
|
|
18
|
+
{type:"delay",label:"T\u1ea1m d\u1eebng",category:"Function",description:"T\u1ea1m d\u1eebng lu\u1ed3ng th\u1ef1c thi c\u1ee7a flow trong m\u1ed9t kho\u1ea3ng th\u1eddi gian nh\u1ea5t \u0111\u1ecbnh (t\u00ednh b\u1eb1ng mili gi\u00e2y).",metadata:[{name:"milliseconds",label:"Th\u1eddi gian ch\u1edd (ms)",type:"number",default:1E3,required:!0}]},{type:"debug",label:"Debug",category:"Output",description:"Hi\u1ec3n th\u1ecb payload ho\u1eb7c th\u00f4ng tin kh\u00e1c ra c\u1eeda s\u1ed5 Debug ho\u1eb7c Console c\u1ee7a tr\u00ecnh duy\u1ec7t \u0111\u1ec3 g\u1ee1 l\u1ed7i.",
|
|
19
|
+
metadata:[{name:"to",label:"Hi\u1ec3n th\u1ecb t\u1edbi",type:"select",required:!0,options:[{value:"console",label:"Browser console"},{value:"debugWindow",label:"C\u1eeda s\u1ed5 Debug (n\u1ebfu c\u00f3)"}],"default":"debugWindow"},{name:"output",label:"N\u1ed9i dung hi\u1ec3n th\u1ecb",type:"select","default":"inputPayload",required:!0,options:[{value:"inputPayload",label:"Payload \u0111\u1ea7u v\u00e0o"},{value:"outputData",label:"Payload \u0111\u1ea7u ra (c\u1ee7a node tr\u01b0\u1edbc)"},{value:"full",
|
|
20
|
+
label:"To\u00e0n b\u1ed9 th\u00f4ng \u0111i\u1ec7p (bao g\u1ed3m c\u1ea3 payload)"}]}]},{type:"httprequest",label:"Http Request",category:"Network",description:"G\u1eedi m\u1ed9t y\u00eau c\u1ea7u HTTP (GET, POST, PUT, DELETE) \u0111\u1ebfn m\u1ed9t URL \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh. Headers v\u00e0 body c\u00f3 th\u1ec3 l\u1ea5y t\u1eeb c\u1ea5u h\u00ecnh ho\u1eb7c payload.",metadata:[{name:"method",label:"Ph\u01b0\u01a1ng th\u1ee9c",type:"select",required:!0,options:[{value:"get",
|
|
21
|
+
label:"GET"},{value:"post",label:"POST"},{value:"put",label:"PUT"},{value:"delete",label:"DELETE"},{value:"patch",label:"PATCH"}],"default":"get"},{name:"url",label:"URL",type:"text",required:!0,"default":""},{name:"headers",label:"Headers (JSON)",type:"textarea","default":"{}",helper:'Nh\u1eadp d\u01b0\u1edbi d\u1ea1ng JSON. V\u00ed d\u1ee5: {"Content-Type": "application/json", "Authorization": "Bearer YOUR_TOKEN"}. C\u00f3 th\u1ec3 l\u1ea5y t\u1eeb payload.headers n\u1ebfu c\u00f3.',options:{language:"json"}},
|
|
22
|
+
{name:"bodyType",label:"Lo\u1ea1i Body",type:"select",options:[{value:"none",label:"None"},{value:"json",label:"JSON"},{value:"raw",label:"Raw Text"}],"default":"none"},{name:"body",label:"Body",type:"textarea","default":"",helper:"Nh\u1eadp n\u1ed9i dung body. N\u1ebfu l\u00e0 JSON, nh\u1eadp JSON h\u1ee3p l\u1ec7. C\u00f3 th\u1ec3 l\u1ea5y t\u1eeb payload.body n\u1ebfu c\u00f3.",options:{language:"json"}}]},{type:"zalosendmessage",label:"G\u1eedi tin nh\u1eafn zalo",category:"Output",description:"G\u1eedi tin nh\u1eafn zalo. Payload c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t m\u1ea3ng ch\u1ee9a messageText,phone",
|
|
23
|
+
metadata:[{name:"templateId",label:"ID m\u1eabu tin nh\u1eafn",type:"text",required:!0,default:"",helper:"Id c\u1ee7a m\u1eabu tin nh\u1eafn \u0111\u00e3 \u0111\u0103ng k\u00fd v\u1edbi zalo. B\u1ea1n c\u1ea7n khai b\u00e1o th\u00f4ng tin k\u1ebft n\u1ed1i v\u1edbi zalo trong ph\u1ea7n c\u00e0i \u0111\u1eb7t th\u00f4ng tin c\u00f4ng ty (m\u1ee5c k\u1ebft n\u1ed1i d\u1ecbch v\u1ee5 b\u00ean th\u1ee9 3)."},{name:"defaultMessage",label:"Tin nh\u1eafn",type:"textarea",default:"",helper:"N\u1ed9i dung tin nh\u1eafn. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.messageText'."},
|
|
24
|
+
{name:"recipientId",label:"Ng\u01b0\u1eddi nh\u1eadn",type:"text",default:"",helper:"Ng\u01b0\u1eddi nh\u1eadn. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.phone' ho\u1eb7c 'payload.recipientId'"}]},{type:"facebook",label:"FB Webhook",category:"Input",description:"T\u1ea1o endpoint chuy\u00ean bi\u1ec7t \u0111\u1ec3 nh\u1eadn s\u1ef1 ki\u1ec7n t\u1eeb Facebook Messenger Platform. T\u1ef1 \u0111\u1ed9ng x\u1eed l\u00fd x\u00e1c minh v\u00e0 t\u00f9y ch\u1ecdn x\u00e1c th\u1ef1c ch\u1eef k\u00fd payload.",
|
|
25
|
+
metadata:[{name:"path",label:"\u0110\u01b0\u1eddng d\u1eabn (Path)",type:"text",default:"",required:!0,helper:"Ph\u1ea7n cu\u1ed1i c\u1ee7a URL webhook (v\u00ed d\u1ee5: /facebook-bot). Ph\u1ea3i l\u00e0 duy nh\u1ea5t."},{name:"fullpath",label:"URL \u0111\u1ea7y \u0111\u1ee7",type:"text",default:"",readOnly:!0},{name:"verifyTokenValue",label:"Verify Token",type:"text",default:"",required:!0,helper:"Chu\u1ed7i b\u00ed m\u1eadt b\u1ea1n nh\u1eadp v\u00e0o ph\u1ea7n c\u00e0i \u0111\u1eb7t Webhook c\u1ee7a App Facebook."},
|
|
26
|
+
{name:"appSecret",label:"App Secret (T\u00f9y ch\u1ecdn, khuy\u1ebfn ngh\u1ecb)",type:"text",default:"",helper:"App Secret c\u1ee7a App Facebook \u0111\u1ec3 x\u00e1c th\u1ef1c ch\u1eef k\u00fd payload (X-Hub-Signature-256). N\u00ean \u0111\u01b0\u1ee3c b\u1ea3o m\u1eadt."}]},{type:"facebooksendmessage",label:"G\u1eedi FB Message",category:"Output",description:"G\u1eedi tin nh\u1eafn t\u1edbi ng\u01b0\u1eddi d\u00f9ng Facebook Messenger th\u00f4ng qua Send API, s\u1eed d\u1ee5ng Page Access Token. Payload c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t m\u1ea3ng ch\u1ee9a pageId,messageText,recipientId",
|
|
27
|
+
metadata:[{name:"pageId",label:"Facebook Page ID",type:"autocomplete",ref_model:"fbpage",ref_field:"page_id",ref_label:"page_title",default:"",required:!1,helper:"ID c\u1ee7a trang Facebook s\u1ebd g\u1eedi tin nh\u1eafn. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.pageId'. Ch\u00fa \u00fd: Ng\u01b0\u1eddi nh\u1eadn ph\u1ea3i t\u1eebng chat v\u1edbi Page th\u00ec Page m\u1edbi g\u1eedi \u0111\u01b0\u1ee3c tin nh\u1eafn cho ng\u01b0\u1eddi \u0111\u00f3"},{name:"defaultMessage",label:"Tin nh\u1eafn m\u1eb7c \u0111\u1ecbnh (Text)",
|
|
28
|
+
type:"code",default:"",helper:"N\u1ed9i dung tin nh\u1eafn. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.messageText' ho\u1eb7c 'payload.messagePayload'. N\u1ed9i dung c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c k\u1ebft h\u1ee3p v\u1edbi d\u1ef1 li\u1ec7u t\u1eeb payload. V\u00ed d\u1ee5: 'Ch\u00fac m\u1eebng sinh nh\u1eadt ${payload.ten_kh}'"},{name:"messageTemplate",label:"Message Template (JSON)",type:"code",default:"",helper:"Nh\u1eadp c\u1ea5u tr\u00fac JSON \u0111\u1ea7y \u0111\u1ee7 cho thu\u1ed9c t\u00ednh 'message' c\u1ee7a Send API (v\u00ed d\u1ee5: template, attachment, quick_replies). S\u1ebd ghi \u0111\u00e8 defaultMessage v\u00e0 payload.messageText.",
|
|
29
|
+
options:{language:"json"}},{name:"recipientId",label:"User facebook ID c\u1ee7a ng\u01b0\u1eddi nh\u1eadn m\u1eb7c \u0111\u1ecbnh",type:"text",default:"",helper:"Ng\u01b0\u1eddi nh\u1eadn tin nh\u1eafn. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.recipientId'"},{name:"tag",label:"Lo\u1ea1i tag s\u1eed d\u1ee5ng",type:"select",options:[{value:"ACCOUNT_UPDATE",label:"(ACCOUNT_UPDATE) C\u1eadp nh\u1eadt t\u00e0i kho\u1ea3n"},{value:"CONFIRMED_EVENT_UPDATE",label:"(CONFIRMED_EVENT_UPDATE) X\u00e1c nh\u1eadn s\u1ef1 ki\u1ec7n"},
|
|
30
|
+
{value:"CUSTOMER_FEEDBACK",label:"(CUSTOMER_FEEDBACK) Ph\u1ea3n h\u1ed3i t\u1eeb nh\u00e2n vi\u00ean h\u1ed7 tr\u1ee3"},{value:"POST_PURCHASE_UPDATE",label:"(POST_PURCHASE_UPDATE) C\u1eadp nh\u1eadt \u0111\u01a1n h\u00e0ng"}],default:"",helper:"\u0110\u1ec3 g\u1eedi tin nh\u1eafn cho user \u0111\u00e3 \u0111\u01b0\u1ee3c t\u01b0\u01a1ng t\u00e1c qu\u00e1 24 gi\u1edd c\u1ea7n s\u1eed d\u1ee5ng m\u1ed9t lo\u1ea1i tab. L\u01b0u \u00fd: vi\u1ec7c s\u1eed d\u1ee5ng sai Message Tag c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn vi\u1ec7c Trang c\u1ee7a b\u1ea1n b\u1ecb h\u1ea1n ch\u1ebf g\u1eedi tin nh\u1eafn."}]},
|
|
31
|
+
{type:"facebookconversations",label:"FB Conversations",category:"Input",description:"L\u1ea5y danh s\u00e1ch c\u00e1c cu\u1ed9c h\u1ed9i tho\u1ea1i trong Facebook Messenger.",metadata:[{name:"pageId",label:"Facebook Page ID",type:"autocomplete",ref_model:"fbpage",ref_field:"page_id",ref_label:"page_title",default:"",required:!0,helper:"ID c\u1ee7a Trang Facebook."},{name:"user_id",label:"User id",type:"text",default:"",helper:"User id c\u1ee7a cu\u1ed9c h\u1ed9i tho\u1ea1i c\u1ea7n l\u1ea5y (tu\u1ef3 ch\u1ecdn)."}]},
|
|
32
|
+
{type:"facebookcreatepost",label:"Facebook Create Post",category:"Output",description:"\u0110\u0103ng m\u1ed9t b\u00e0i vi\u1ebft m\u1edbi (v\u0103n b\u1ea3n, link, h\u00ecnh \u1ea3nh) l\u00ean m\u1ed9t Trang Facebook c\u1ee5 th\u1ec3.",metadata:[{name:"page_id",label:"Facebook Page ID",type:"autocomplete",ref_model:"fbpage",ref_field:"page_id",ref_label:"page_title",required:!0,default:"",helper:"ID c\u1ee7a Trang Facebook b\u1ea1n mu\u1ed1n \u0111\u0103ng b\u00e0i l\u00ean."},{name:"message",label:"N\u1ed9i dung b\u00e0i vi\u1ebft (Message)",
|
|
33
|
+
type:"textarea",default:"",helper:"S\u1ebd \u01b0u ti\u00ean l\u1ea5y t\u1eeb 'payload.message' ho\u1eb7c 'payload.text' n\u1ebfu c\u00f3, sau \u0111\u00f3 m\u1edbi \u0111\u1ebfn gi\u00e1 tr\u1ecb c\u1ea5u h\u00ecnh \u1edf \u0111\u00e2y."},{name:"link",label:"Link \u0111\u00ednh k\u00e8m (T\u00f9y ch\u1ecdn)",type:"text",default:"",helper:"URL b\u1ea1n mu\u1ed1n chia s\u1ebb c\u00f9ng b\u00e0i vi\u1ebft. Facebook s\u1ebd t\u1ef1 \u0111\u1ed9ng t\u1ea1o preview cho link n\u00e0y. S\u1ebd \u01b0u ti\u00ean l\u1ea5y t\u1eeb 'payload.link' n\u1ebfu c\u00f3, sau \u0111\u00f3 m\u1edbi \u0111\u1ebfn gi\u00e1 tr\u1ecb c\u1ea5u h\u00ecnh \u1edf \u0111\u00e2y."},
|
|
34
|
+
{name:"image_url",label:"URL H\u00ecnh \u1ea3nh \u0111\u00ednh k\u00e8m (T\u00f9y ch\u1ecdn)",type:"text",default:"",helper:"URL c\u00f4ng khai c\u1ee7a h\u00ecnh \u1ea3nh b\u1ea1n mu\u1ed1n \u0111\u0103ng. S\u1ebd \u01b0u ti\u00ean l\u1ea5y t\u1eeb 'payload.image_url' n\u1ebfu c\u00f3, sau \u0111\u00f3 m\u1edbi \u0111\u1ebfn gi\u00e1 tr\u1ecb c\u1ea5u h\u00ecnh \u1edf \u0111\u00e2y."},{name:"published",label:"Xu\u1ea5t b\u1ea3n ngay?",type:"checkbox",default:!0,helper:"N\u1ebfu \u0111\u01b0\u1ee3c ch\u1ecdn, b\u00e0i vi\u1ebft s\u1ebd \u0111\u01b0\u1ee3c \u0111\u0103ng c\u00f4ng khai ngay l\u1eadp t\u1ee9c. N\u1ebfu kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ecdn, b\u00e0i vi\u1ebft s\u1ebd \u0111\u01b0\u1ee3c t\u1ea1o d\u01b0\u1edbi d\u1ea1ng b\u1ea3n nh\u00e1p (unpublished post) tr\u00ean Trang c\u1ee7a b\u1ea1n v\u00e0 b\u1ea1n c\u00f3 th\u1ec3 xu\u1ea5t b\u1ea3n n\u00f3 sau t\u1eeb m\u1ee5c 'C\u00f4ng c\u1ee5 \u0111\u0103ng' c\u1ee7a Trang. S\u1ebd \u01b0u ti\u00ean l\u1ea5y t\u1eeb 'payload.published' n\u1ebfu c\u00f3, sau \u0111\u00f3 m\u1edbi \u0111\u1ebfn gi\u00e1 tr\u1ecb c\u1ea5u h\u00ecnh \u1edf \u0111\u00e2y."}]},
|
|
35
|
+
{type:"savedata",label:"L\u01b0u tr\u1eef",category:"Output",description:"L\u01b0u tr\u1eef d\u1eef li\u1ec7u c\u1ee7a node tr\u01b0\u1edbc v\u00e0o database.",metadata:[{name:"title",label:"T\u00ean l\u01b0u tr\u1eef",type:"text",default:"",required:!0}]},{type:"switch",label:"Switch",category:"Logic",description:"Ph\u00e2n nh\u00e1nh lu\u1ed3ng d\u1ef1a tr\u00ean gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed9t thu\u1ed9c t\u00ednh trong payload. \u0110\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc \u0111\u1ec3 g\u1eedi payload \u0111\u1ebfn c\u00e1c \u0111\u1ea7u ra kh\u00e1c nhau.",
|
|
36
|
+
metadata:[{name:"propertyToCheck",label:"Gi\u00e1 tr\u1ecb c\u1ea7n ki\u1ec3m tra",type:"code",required:!0,default:"payload.value",helper:"\u0110\u01b0\u1eddng d\u1eabn \u0111\u1ebfn thu\u1ed9c t\u00ednh trong payload c\u1ea7n ki\u1ec3m tra (v\u00ed d\u1ee5: payload.status, payload.data.amount). S\u1eed d\u1ee5ng d\u1ea5u ch\u1ea5m '.' \u0111\u1ec3 truy c\u1eadp thu\u1ed9c t\u00ednh l\u1ed3ng nhau."},{name:"rules",label:"Quy t\u1eafc ph\u00e2n nh\u00e1nh",type:"list",fields:[{name:"operator",label:"To\u00e1n t\u1eed",
|
|
37
|
+
type:"select",required:!0,options:[{value:"==",label:"b\u1eb1ng (==) (so s\u00e1nh l\u1ecfng)"},{value:"!=",label:"kh\u00e1c (!=) (so s\u00e1nh l\u1ecfng)"},{value:"===",label:"b\u1eb1ng (===) (so s\u00e1nh nghi\u00eam ng\u1eb7t)"},{value:"!==",label:"kh\u00e1c (!==) (so s\u00e1nh nghi\u00eam ng\u1eb7t)"},{value:">",label:"l\u1edbn h\u01a1n (>)"},{value:"<",label:"nh\u1ecf h\u01a1n (<)"},{value:">=",label:"l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng (>=)"},{value:"<=",label:"nh\u1ecf h\u01a1n ho\u1eb7c b\u1eb1ng (<=)"},
|
|
38
|
+
{value:"contains",label:"ch\u1ee9a (chu\u1ed7i)"},{value:"notcontains",label:"kh\u00f4ng ch\u1ee9a (chu\u1ed7i)"},{value:"startsWith",label:"b\u1eaft \u0111\u1ea7u b\u1eb1ng (chu\u1ed7i)"},{value:"endsWith",label:"k\u1ebft th\u00fac b\u1eb1ng (chu\u1ed7i)"},{value:"regex",label:"kh\u1edbp Regex"},{value:"isType",label:"l\u00e0 ki\u1ec3u d\u1eef li\u1ec7u"},{value:"isEmpty",label:"l\u00e0 r\u1ed7ng/null/undefined"},{value:"isNotEmpty",label:"kh\u00f4ng r\u1ed7ng/null/undefined"}],default:"=="},{name:"valueToCompare",
|
|
39
|
+
label:"Gi\u00e1 tr\u1ecb so s\u00e1nh",type:"text",default:"",helper:"Gi\u00e1 tr\u1ecb \u0111\u1ec3 so s\u00e1nh v\u1edbi thu\u1ed9c t\u00ednh. Nh\u1eadp 'true'/'false' cho boolean, s\u1ed1 cho number, 'null', 'undefined', ho\u1eb7c t\u00ean ki\u1ec3u d\u1eef li\u1ec7u ('string', 'array'...) cho to\u00e1n t\u1eed 'isType'."},{name:"outputHandleId",label:"\u0110\u1ea7u ra (Handle ID)",type:"text",default:"output_1",required:!0,helper:"ID duy nh\u1ea5t cho c\u1ed5ng \u0111\u1ea7u ra n\u00e0y (v\u00ed d\u1ee5: 'case1', 'approved', 'default'). D\u00f9ng \u0111\u1ec3 n\u1ed1i c\u1ea1nh."}],
|
|
40
|
+
default:[{operator:"==",valueToCompare:"true",outputHandleId:"output_1"}]},{name:"stopAfterFirstMatch",label:"D\u1eebng sau khi kh\u1edbp quy t\u1eafc \u0111\u1ea7u ti\u00ean?",type:"checkbox",default:!0,helper:"N\u1ebfu ch\u1ecdn, flow ch\u1ec9 \u0111i theo nh\u00e1nh \u0111\u1ea7u ti\u00ean kh\u1edbp. N\u1ebfu kh\u00f4ng ch\u1ecdn, flow c\u00f3 th\u1ec3 \u0111i theo nhi\u1ec1u nh\u00e1nh n\u1ebfu nhi\u1ec1u quy t\u1eafc c\u00f9ng kh\u1edbp."},{name:"defaultOutputHandleId",label:"\u0110\u1ea7u ra M\u1eb7c \u0111\u1ecbnh (Handle ID)",
|
|
41
|
+
type:"text",default:"output_default",helper:"ID c\u1ee7a c\u1ed5ng \u0111\u1ea7u ra s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng n\u1ebfu kh\u00f4ng c\u00f3 quy t\u1eafc n\u00e0o kh\u1edbp. B\u1ecf tr\u1ed1ng n\u1ebfu kh\u00f4ng c\u1ea7n \u0111\u1ea7u ra m\u1eb7c \u0111\u1ecbnh."}]},{type:"data",label:"Ch\u1ee9ng t\u1eeb, danh m\u1ee5c",category:"C\u00f4ng ty",description:"Th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c T\u1ea1o (create), C\u1eadp nh\u1eadt (update), L\u1ea5y danh s\u00e1ch (list), \u0110\u1ebfm (count) ch\u1ee9ng t\u1eeb ho\u1eb7c danh m\u1ee5c h\u1ec7 th\u1ed1ng.",
|
|
42
|
+
metadata:[{name:"code",label:"Lo\u1ea1i d\u1eef li\u1ec7u",type:"autocomplete",ref_model:"chucnang",ref_api:"listinfo",ref_field:"code",ref_label:"title",ref_data_fields:"code,title,search_form",condition:{is_endpoint:!0,require_id_app:!0},default:"",required:!0},{name:"action",label:"H\u00e0ng \u0111\u1ed9ng",type:"select",default:"list",required:!0,options:[{value:"create",label:"T\u1ea1o m\u1edbi"},{value:"update",label:"C\u1eadp nh\u1eadt"},{value:"findAndUpdate",label:"T\u00ecm v\u00e0 c\u1eadp nh\u1eadt"},
|
|
43
|
+
{value:"list",label:"L\u1ea5y danh s\u00e1ch"},{value:"count",label:"\u0110\u1ebfm s\u1ed1 l\u01b0\u1ee3ng record"}]},{name:"helpTextList",label:"H\u1ed7 tr\u1ee3",type:"helpText",text:"\u0110i\u1ec1u ki\u1ec7n l\u1ecdc \u01b0u ti\u00ean l\u1ea5y t\u1eeb 'payload.condition' r\u1ed3i \u0111\u1ebfn 'payload'"},{name:"helpTextFindAndUpdate",label:"H\u1ed7 tr\u1ee3",type:"helpText",text:"Payload c\u1ea7n c\u00f3 condition \u0111\u1ec3 l\u00e0m \u0111i\u1ec1u ki\u1ec7n l\u1ecdc v\u00e0 data c\u1ea7n c\u1eadp nh\u1eadt d\u1eef li\u1ec7u"},
|
|
44
|
+
{name:"handle_condition_script",label:"X\u1eed l\u00fd \u0111i\u1ec1u ki\u1ec7n l\u1ecdc tr\u01b0\u1edbc khi ch\u1ea1y node",type:"code",default:"",required:!1,helper:"Bi\u1ebfn c\u00f3 s\u1eb5n: payload (\u0111\u1ea7u v\u00e0o t\u1eeb node tr\u01b0\u1edbc), condition (\u0111i\u1ec1u ki\u1ec7n hi\u1ec7n t\u1ea1i). D\u00f9ng `return` \u0111\u1ec3 tr\u1ea3 v\u1ec1 \u0111i\u1ec1u ki\u1ec7n m\u1edbi."},{name:"handle_data_script",label:"X\u1eed l\u00fd d\u1eef li\u1ec7u tr\u01b0\u1edbc khi tr\u1ea3 v\u1ec1 cho node ti\u1ebfp theo",
|
|
45
|
+
type:"code",default:"",required:!1,helper:"Bi\u1ebfn c\u00f3 s\u1eb5n: payload (\u0111\u1ea7u v\u00e0o t\u1eeb node tr\u01b0\u1edbc), condition (\u0111i\u1ec1u ki\u1ec7n hi\u1ec7n t\u1ea1i), data (d\u1eef li\u1ec7u hi\u1ec7n t\u1ea1i). D\u00f9ng `return` \u0111\u1ec3 tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u m\u1edbi."}],outputDescription:{type:"object | array",description:"K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 linh ho\u1ea1t d\u1ef1a tr\u00ean c\u1ea5u h\u00ecnh thu\u1ed9c t\u00ednh 'action' c\u1ee7a node.",
|
|
46
|
+
byAction:{create_or_update:{description:"Tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u (Object ho\u1eb7c M\u1ea3ng c\u00e1c Object) \u0111\u00e3 \u0111\u01b0\u1ee3c x\u1eed l\u00fd t\u1ea1o m\u1edbi ho\u1eb7c c\u1eadp nh\u1eadt th\u00e0nh c\u00f4ng trong Database. Ki\u1ec3u d\u1eef li\u1ec7u \u0111\u1ed3ng b\u1ed9 theo payload \u0111\u1ea7u v\u00e0o.",example:{_id:"65d8f...",code:"NV001",name:"Nguy\u1ec5n V\u0103n A"}},list:{description:"Tr\u1ea3 v\u1ec1 m\u1ed9t M\u1ea3ng (Array) c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng t\u00ecm th\u1ea5y th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n. D\u1eef li\u1ec7u c\u00f3 th\u1ec3 thay \u0111\u1ed5i c\u1ea5u tr\u00fac n\u1ebfu s\u1eed d\u1ee5ng \u0111o\u1ea1n m\u00e3 script t\u00f9y bi\u1ebfn d\u1eef li\u1ec7u.",
|
|
47
|
+
example:[{_id:"1",code:"A"},{_id:"2",code:"B"}]},count:{description:"Tr\u1ea3 v\u1ec1 m\u1ed9t Object ch\u1ee9a t\u1ed5ng s\u1ed1 l\u01b0\u1ee3ng b\u1ea3n ghi v\u00e0 \u0111i\u1ec1u ki\u1ec7n t\u00ecm ki\u1ebfm \u0111i k\u00e8m.",example:{rows_number:15,condition:{status:"active",id_app:"app_id"}}}}}},{type:"event",label:"S\u1ef1 ki\u1ec7n",category:"C\u00f4ng ty",description:"L\u1eafng nghe c\u00e1c s\u1ef1 ki\u1ec7n khi d\u1eef li\u1ec7u c\u00f4ng ty c\u00f3 s\u1ef1 thay \u0111\u1ed5i: v\u00ed d\u1ee5 nh\u01b0 th\u00eam m\u1edbi, c\u1eadp nh\u1eadt hay xo\u00e1",
|
|
48
|
+
metadata:[{name:"code",label:"Lo\u1ea1i d\u1eef li\u1ec7u",type:"autocomplete",ref_model:"chucnang",ref_api:"listinfo",ref_field:"code",ref_label:"title",ref_data_fields:"code,title,api_code",condition:{is_endpoint:!0,require_id_app:!0},default:"",required:!0},{name:"event",label:"s\u1ef1 ki\u1ec7n",type:"select",default:"new",required:!0,options:[{value:"new",label:"T\u1ea1o m\u1edbi"},{value:"update",label:"C\u1eadp nh\u1eadt"},{value:"delete",label:"xo\u00e1"},{value:"request_approved",label:"Y\u00eau c\u1ea7u \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t"},
|
|
49
|
+
{value:"request_denied",label:"Y\u00eau c\u1ea7u b\u1ecb t\u1eeb ch\u1ed1i"}]},{name:"channel",label:"K\u00eanh",type:"text",default:"",required:!0,readOnly:!0},{name:"condition_script",label:"\u0110i\u1ec1u ki\u1ec7n k\u00edch ho\u1ea1t node.",type:"code",default:"",required:!1,helper:"Bi\u1ebfn c\u00f3 s\u1eb5n: eventPayload (d\u1eef li\u1ec7u t\u1eeb Redis sau khi parse),initialPayload (d\u1eef li\u1ec7u t\u1eeb node tr\u01b0\u1edbc),nodeData (c\u1ea5u h\u00ecnh hi\u1ec7n t\u1ea1i c\u1ee7a node). D\u00f9ng `return` \u0111\u1ec3 tr\u1ea3 gi\u00e1 tr\u1ecb true or false."},
|
|
50
|
+
{name:"handle_data_script",label:"X\u1eed l\u00fd d\u1eef li\u1ec7u tr\u01b0\u1edbc khi g\u1eedi sang node ti\u1ebfp theo",type:"code",default:"",required:!1,helper:"Bi\u1ebfn c\u00f3 s\u1eb5n: data. D\u00f9ng `return` \u0111\u1ec3 tr\u1ea3 gi\u00e1 tr\u1ecb m\u1edbi."}],outputDescription:{type:"object",description:"Khi c\u00f3 m\u1ed9t h\u00e0nh \u0111\u1ed9ng t\u00e1c \u0111\u1ed9ng l\u00ean ch\u1ee9ng t\u1eeb/danh m\u1ee5c (Th\u00eam, S\u1eeda, X\u00f3a, Duy\u1ec7t), node s\u1ebd l\u1eadp t\u1ee9c k\u00edch ho\u1ea1t v\u00e0 truy\u1ec1n d\u1eef li\u1ec7u c\u1ee7a ch\u00ednh b\u1ea3n ghi (item) \u0111\u00f3 cho c\u00e1c node ti\u1ebfp theo."}},
|
|
51
|
+
{type:"pushnotification",label:"G\u1eedi th\u00f4ng b\u00e1o",category:"C\u00f4ng ty",description:"G\u1eedi th\u00f4ng b\u00e1o t\u1edbi ng\u01b0\u1eddi d\u00f9ng trong c\u00f4ng ty.",metadata:[{name:"defaultMessage",label:"Tin nh\u1eafn m\u1eb7c \u0111\u1ecbnh (Text)",type:"code",default:"",helper:"N\u1ed9i dung g\u1eedi. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.messageText'. N\u1ed9i dung c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c k\u1ebft h\u1ee3p v\u1edbi d\u1ef1 li\u1ec7u t\u1eeb payload. V\u00ed d\u1ee5: 'Ch\u1ee9ng t\u1eeb c\u00f3 s\u1ed1 ${payload.so_ct} c\u1ea7n x\u1eed l\u00fd'"},
|
|
52
|
+
{name:"recipientId",label:"Ng\u01b0\u1eddi nh\u1eadn",type:"autocomplete",ref_model:"participant",ref_field:"email",ref_label:"name",multiple:!0,default:"",helper:"Ng\u01b0\u1eddi nh\u1eadn th\u00f4ng b\u00e1o. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.recipientId'"}]},{type:"report",label:"B\u00e1o c\u00e1o",category:"C\u00f4ng ty",description:"Ch\u1ea1y m\u1ed9t b\u00e1o c\u00e1o t\u1eeb d\u1eef li\u1ec7u c\u1ee7a c\u00f4ng ty.",metadata:[{name:"code",label:"B\u00e1o c\u00e1o",type:"autocomplete",
|
|
53
|
+
ref_model:"reportinfo",ref_field:"code",ref_label:"title",ref_data_fields:"code,title,form_condition_info",default:"",required:!0},{name:"condition",label:"\u0110i\u1ec1u ki\u1ec7n m\u1eb7c \u0111\u1ecbnh",type:"formbase",default:{},helper:"\u0110i\u1ec1u ki\u1ec7n \u0111\u1ec3 ch\u1ea1y b\u00e1o c\u00e1o. \u01afu ti\u00ean l\u1ea5y t\u1eeb 'payload.condition'."},{name:"rpt_id",label:"M\u1eabu in",type:"select",ref_model:"rpt",ref_field:"_id",ref_label:"ten_mau_in",default:"",helper:"M\u1eabu in \u0111\u1ec3 render b\u00e1o c\u00e1o. N\u1ebfu kh\u00f4ng ch\u1ecdn m\u1eabu in th\u00ec s\u1ebd tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u d\u1ea1ng json"},
|
|
54
|
+
{name:"send_to",label:"G\u1eedi b\u00e1o c\u00e1o t\u1edbi",type:"autocomplete",ref_model:"participant",ref_field:"email",ref_label:"name",multiple:!0,default:"",helper:"G\u1eedi b\u00e1o c\u00e1o t\u1edbi ng\u01b0\u1eddi d\u00f9ng"}]},{type:"customer",label:"Kh\u00e1ch h\u00e0ng",category:"C\u00f4ng ty",description:"C\u00e1c thao t\u00e1c li\u00ean quan \u0111\u1ebfn kh\u00e1ch h\u00e0ng nh\u01b0 t\u1ea1o m\u1edbi, c\u1eadp nh\u1eadt, l\u1ea5y danh s\u00e1ch",metadata:[{name:"action",label:"H\u00e0ng \u0111\u1ed9ng",
|
|
55
|
+
type:"select",default:"create",required:!0,options:[{value:"create",label:"T\u1ea1o m\u1ed9t ho\u1eb7c nhi\u1ec1u kh\u00e1ch h\u00e0ng m\u1edbi"},{value:"createorupdate",label:"T\u1ea1o m\u1edbi ho\u1eb7c c\u1eadp nh\u1eadt m\u1ed9t ho\u1eb7c nhi\u1ec1u kh\u00e1ch h\u00e0ng"},{value:"list",label:"L\u1ea5y danh s\u00e1ch"}]},{name:"nh_kh",label:"Nh\u00f3m kh\u00e1ch h\u00e0ng",type:"select",default:"",required:!1,ref_model:"dmnhkh",ref_field:"_id",ref_label:"group_name",condition:{group_kind:1,status:!0}},
|
|
56
|
+
{name:"trang_thai",label:"Tr\u1ea1ng th\u00e1i",type:"select",default:"",required:!1,ref_model:"trangthai",ref_field:"ma_trang_thai",ref_label:"ten_trang_thai",condition:{ma_ct:"CUSTOMER"}},{name:"ngay_sinh_hom_nay",label:"Ch\u1ec9 l\u1ea5y kh\u00e1ch c\u00f3 ng\u00e0y sinh h\u00f4m nay",type:"checkbox",default:!1,required:!1},{name:"kh_co_fb_id",label:"Ch\u1ec9 l\u1ea5y kh\u00e1ch c\u00f3 Favebook ID",type:"checkbox",default:!1,required:!1},{name:"kh_co_dien_thoai",label:"Ch\u1ec9 l\u1ea5y kh\u00e1ch c\u00f3 s\u1ed1 \u0111i\u1ec7n tho\u1ea1i",
|
|
57
|
+
type:"checkbox",default:!1,required:!1},{name:"query",label:"\u0110i\u1ec1u ki\u1ec7n kh\u00e1c",type:"code",helper:"Script tr\u1ea3 v\u1ec1 th\u00eam c\u00e1c \u0111i\u1ec1u ki\u1ec7n kh\u00e1c. C\u00e1c tham s\u1ed1 c\u00f3 s\u1eb5n: moment,numeral,_,payload",default:"",required:!1}]}];
|
|
1
58
|
async function getPageAccessToken($id_app_page$$,$page_id$$){return($id_app_page$$=await global.getModel("fbpage").findOne({id_app:$id_app_page$$,page_id:$page_id$$}).lean())&&$id_app_page$$.page_access_token?$id_app_page$$.page_access_token:null}
|
|
2
|
-
const getConfigValue=($node$$,$payload$$,$key$$,$defaultValue$$,$alternativePayloadKeys$$=[])=>{if($payload$$&&typeof $payload$$==="object"){if($payload$$[$key$$]!==void 0&&$payload$$[$key$$]!==null)return $payload$$[$key$$];for(const $altKey$$ of $alternativePayloadKeys$$)if($payload$$[$altKey$$]!==void 0&&$payload$$[$altKey$$]!==null)return $payload$$[$altKey$$]}return $defaultValue$$};module.exports={getConfigValue,getPageAccessToken};
|
|
59
|
+
const getConfigValue=($node$$,$payload$$,$key$$,$defaultValue$$,$alternativePayloadKeys$$=[])=>{if($payload$$&&typeof $payload$$==="object"){if($payload$$[$key$$]!==void 0&&$payload$$[$key$$]!==null)return $payload$$[$key$$];for(const $altKey$$ of $alternativePayloadKeys$$)if($payload$$[$altKey$$]!==void 0&&$payload$$[$altKey$$]!==null)return $payload$$[$altKey$$]}return $defaultValue$$};module.exports={getConfigValue,getPageAccessToken,Nodes};
|
package/server/global.js
CHANGED
|
@@ -2,7 +2,7 @@ const fs=require("fs"),async=require("async"),logger=require("./libs/logger.js")
|
|
|
2
2
|
function globalListinfoCodePlugin($schema$$){$schema$$.path("listinfo_code")||$schema$$.add({listinfo_code:{type:String,default:null}});$schema$$.path("id_client")||$schema$$.add({id_client:{type:String,default:null}})}global.blockchainTransactionPool=new TransactionPool;global.new_schedules=[];global.rootDir=__dirname;global.ctrlVouchers={};global.controllers={};global.report_controllers={};global.postingVouchers={};global.cacheDatas={};
|
|
3
3
|
global.socketContainer={loadConnectionId:async()=>new Promise($res$$=>{global.clientRedis.get("client-io",function($err$$,$reply$$){if($err$$)return console.error($err$$),$res$$({});if($reply$$)try{let $ios$$=JSON.parse($reply$$);return $res$$($ios$$||{})}catch($e$$){return console.error($e$$),$res$$({})}else return $res$$({})})}),saveConnectionId:async($clientIO$$={})=>new Promise(($res$$,$rej$$)=>{global.clientRedis.set("client-io",JSON.stringify($clientIO$$),$e$$=>{if($e$$)return console.error($e$$),
|
|
4
4
|
$rej$$($e$$);$res$$($clientIO$$)})})};global.clientIO={};global.model_books="socai socaitmp socainpp vsocai sokho sokhott sokhonpp sokhokhongton sosanxuat vatvao vatra phucap".split(" ");global.secu_models="asskey assproduct assperiod assinvestment asssell assbuy assneedtobuy asswithdraw asscashwithdraw wallet assfindhash assbank asstransaction assissue token tokens user app listinfo right otp payload smsaccount emailaccount".split(" ");global.webPush=require("web-push");global.mongoose=require("mongoose");
|
|
5
|
-
global.mongoose.plugin(mongooseSecurityPlugin);require("./libs/mongoosePatch.js");global.mongoose.plugin(leanID);global.mongoose.plugin(deletePost);global.mongoose.plugin(globalListinfoCodePlugin);global.mongoose.plugin(function($schema$$){$schema$$.set("versionKey",!1)});global.Schema=global.mongoose.Schema;
|
|
5
|
+
const originalCast=global.mongoose.Number.cast();global.mongoose.Number.cast(function($value$$){return typeof $value$$==="number"&&Number.isNaN($value$$)?0:originalCast($value$$)});global.mongoose.plugin(mongooseSecurityPlugin);require("./libs/mongoosePatch.js");global.mongoose.plugin(leanID);global.mongoose.plugin(deletePost);global.mongoose.plugin(globalListinfoCodePlugin);global.mongoose.plugin(function($schema$$){$schema$$.set("versionKey",!1)});global.Schema=global.mongoose.Schema;
|
|
6
6
|
global.getModel=$model_name_name$$=>{$model_name_name$$=$model_name_name$$.split(".js")[0];var $_requireFields_manualMap_model_model_path_mySchema$$={kbmpttct:"kbmPttct",kbmtkgtgt:"kbmTkgtgt",token:"tokens",bn1:"pc1",bc1:"pt1"};$_requireFields_manualMap_model_model_path_mySchema$$[$model_name_name$$]&&($model_name_name$$=$_requireFields_manualMap_model_model_path_mySchema$$[$model_name_name$$]);if($_requireFields_manualMap_model_model_path_mySchema$$=mongoose.models[$model_name_name$$])return $_requireFields_manualMap_model_model_path_mySchema$$;
|
|
7
7
|
if(((global.configs||{}).paths||{}).models&&($_requireFields_manualMap_model_model_path_mySchema$$=((global.configs||{}).paths||{}).models+"/"+$model_name_name$$+".js",fs.existsSync($_requireFields_manualMap_model_model_path_mySchema$$)))return require($_requireFields_manualMap_model_model_path_mySchema$$);$_requireFields_manualMap_model_model_path_mySchema$$=__dirname+"/models/"+$model_name_name$$+".js";if(fs.existsSync($_requireFields_manualMap_model_model_path_mySchema$$))return require($_requireFields_manualMap_model_model_path_mySchema$$);
|
|
8
8
|
console.error("model",$model_name_name$$,"is not exists. create new model");$_requireFields_manualMap_model_model_path_mySchema$$={...require("./models/listinfo").requireFields};$_requireFields_manualMap_model_model_path_mySchema$$=new global.Schema($_requireFields_manualMap_model_model_path_mySchema$$,{strict:!1});return global.mongoose.model($model_name_name$$,$_requireFields_manualMap_model_model_path_mySchema$$)};global.getLib=$lib_name$$=>require("./libs/"+$lib_name$$);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
const {Worker}=require("worker_threads"),fs=require("fs"),_=require("lodash"),crypto=require("crypto"),moment=require("moment"),redisCache=require("./redis-cache"),v8=require("v8");
|
|
2
|
-
class WorkerPool{constructor($filename_i$$,$maxQueue_worker$$=0,$maxWorkers$$=1,$defaultTimeout$$=
|
|
3
|
-
this.workers={};this.poolName=$poolName$$;this.SCALE_THRESHOLD_LAG=40;this.SCALE_COOLDOWN=2E3;this.lastScaleTime=0;Logger.info(this.poolName,"\u0111ang t\u1ea1o s\u1eb5n",$pre_created_workers$$,"workers/",$maxWorkers$$);for($filename_i$$=0;$filename_i$$<Math.min($pre_created_workers$$,$maxWorkers$$);$filename_i$$++)$maxQueue_worker$$=this.createWorker(),this.workers[$maxQueue_worker$$.id]=$maxQueue_worker$$}
|
|
4
|
-
|
|
5
|
-
20)Logger.info(`[${this.poolName}] High Load detected (Avg Lag: ${$avgLag_workersList$$.toFixed(2)}ms, Queue: ${this.queue.length}). Scaling up...`)
|
|
6
|
-
{id:`worker-${crypto.randomBytes(20).toString("hex")}`,isBusy:!1,time_responded:new Date,lag:0};$wk$$.worker=new Worker(this.filename);$wk$$.worker.on("message",
|
|
7
|
-
$message$$.lag,this.checkLoadAndScale();else{var $task$$;try{($task$$=$message$$.id_task?this.queue_running.find($q$$=>$q$$.id==$message$$.id_task):$wk$$.task)&&
|
|
8
|
-
$task$$.
|
|
9
|
-
$
|
|
10
|
-
$q$$.id==$wk$$.task.id);if($task$$){clearTimeout($task$$.timeoutId);$task$$.finished=new Date;$task$$.status=9;$task$$.message="\u0110\u00e3 c\u00f3 l\u1ed7i x\u1ea3y ra trong h\u1ec7 th\u1ed1ng. H\u00e3y th\u1eed l\u1ea1i";
|
|
11
|
-
$task$$.id,$e$$.message)}$task$$.callback&&$task$$.callback({error:$task$$.message},$task$$.id);this.queue_running=this.queue_running.filter($q$$=>$q$$.id!==$task$$.id)}}delete this.workers[$wk$$.id]
|
|
12
|
-
if(!$wk$$)if(Object.keys(this.workers).length===0)$wk$$=this.createWorker(),this.workers[$wk$$.id]=$wk$$;else{this.checkLoadAndScale();break}if($wk$$){if(!this.workerIsAlive($wk$$)){Logger.error("[",
|
|
13
|
-
|
|
14
|
-
$
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
class WorkerPool{constructor($filename_i$$,$maxQueue_worker$$=0,$maxWorkers$$=1,$defaultTimeout$$=6E4,$pre_created_workers$$=0,$poolName$$="WorkerPool"){if(!fs.existsSync($filename_i$$))throw Error("Worker file does not exist");this.filename=$filename_i$$;this.maxWorkers=$maxWorkers$$;(this.maxQueue=$maxQueue_worker$$)&&this.maxQueue<$maxWorkers$$&&(this.maxQueue=$maxWorkers$$);this.defaultTimeout=$defaultTimeout$$;this.pre_created_workers=$pre_created_workers$$;this.queue=[];this.queue_running=[];
|
|
3
|
+
this.workers={};this.poolName=$poolName$$;this.SCALE_THRESHOLD_LAG=40;this.SCALE_COOLDOWN=2E3;this.lastScaleTime=0;Logger.info(this.poolName,"\u0111ang t\u1ea1o s\u1eb5n",$pre_created_workers$$,"workers/",$maxWorkers$$);for($filename_i$$=0;$filename_i$$<Math.min($pre_created_workers$$,$maxWorkers$$);$filename_i$$++)$maxQueue_worker$$=this.createWorker(),this.workers[$maxQueue_worker$$.id]=$maxQueue_worker$$}async terminateWorkerGracefully($wk$$){if($wk$$&&$wk$$.worker){$wk$$.isDying=!0;try{$wk$$.worker.postMessage({type:"KILL_SIGNAL"})}catch($e$$){$wk$$.worker.terminate();
|
|
4
|
+
return}var $forceKillTimeout$$=setTimeout(()=>{Logger.warn(`[${this.poolName}] Worker ${$wk$$.id} kh\u00f4ng ch\u1ecbu ch\u1ebft an to\u00e0n. \u00c9p terminate!`);$wk$$.worker.terminate()},3E3);$wk$$.worker.once("exit",()=>{clearTimeout($forceKillTimeout$$)})}}checkLoadAndScale(){const $now$$=Date.now();if(!($now$$-this.lastScaleTime<this.SCALE_COOLDOWN)){var $avgLag_workersList$$=Object.values(this.workers),$hasBacklog_totalWorkers_wk$$=$avgLag_workersList$$.length;if(!($hasBacklog_totalWorkers_wk$$>=
|
|
5
|
+
this.maxWorkers)&&$hasBacklog_totalWorkers_wk$$!==0){var $totalLag$$=0;$avgLag_workersList$$.forEach($w$$=>$totalLag$$+=$w$$.lag||0);$avgLag_workersList$$=$totalLag$$/$hasBacklog_totalWorkers_wk$$;$hasBacklog_totalWorkers_wk$$=this.queue.length>$hasBacklog_totalWorkers_wk$$;if($avgLag_workersList$$>this.SCALE_THRESHOLD_LAG||$hasBacklog_totalWorkers_wk$$&&$avgLag_workersList$$>20)Logger.info(`[${this.poolName}] High Load detected (Avg Lag: ${$avgLag_workersList$$.toFixed(2)}ms, Queue: ${this.queue.length}). Scaling up...`),
|
|
6
|
+
$hasBacklog_totalWorkers_wk$$=this.createWorker(),this.workers[$hasBacklog_totalWorkers_wk$$.id]=$hasBacklog_totalWorkers_wk$$,this.lastScaleTime=$now$$}}}workerIsAlive($wk$$){return!$wk$$.worker||$wk$$.worker.threadId<=0||moment().diff(moment($wk$$.time_responded),"seconds")>(($wk$$.task||{}).timeout||this.defaultTimeout)/1E3?!1:!0}createWorker(){const $wk$$={id:`worker-${crypto.randomBytes(20).toString("hex")}`,isBusy:!1,time_responded:new Date,lag:0};$wk$$.worker=new Worker(this.filename);$wk$$.worker.on("message",
|
|
7
|
+
async $rawMessage$$=>{$wk$$.time_responded=new Date;let $message$$=$rawMessage$$;if(Buffer.isBuffer($rawMessage$$)||$rawMessage$$ instanceof Uint8Array)try{$message$$=v8.deserialize($rawMessage$$)}catch($e$$){Logger.error(`[${this.poolName}] L\u1ed7i deserialize message t\u1eeb worker:`,$e$$)}if($message$$&&$message$$.type==="metrics")$wk$$.lag=$message$$.lag,this.checkLoadAndScale();else{var $task$$;try{($task$$=$message$$.id_task?this.queue_running.find($q$$=>$q$$.id==$message$$.id_task):$wk$$.task)&&
|
|
8
|
+
clearTimeout($task$$.timeoutId);if($task$$&&$task$$.callback)if($message$$.id_task&&$message$$.id_task!==$task$$.id)Logger.error("[",this.poolName,"] K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 kh\u00f4ng \u0111\u00fang cho task",$task$$.id,$message$$);else{$task$$.finished=new Date;$task$$.status=5;$task$$.message="\u0110\u00e3 th\u1ef1c hi\u1ec7n xong";$task$$.result=$message$$&&Array.isArray($message$$)?void 0:$message$$;if($task$$.save_log)try{let {finished:$finished$$,status:$status$$,message:$message$$,
|
|
9
|
+
result:$result$$}=$task$$;await redisCache.updateObject($task$$.id,{finished:$finished$$,status:$status$$,message:$message$$,result:$result$$})}catch($e$$){Logger.error("[",this.poolName,"] can't update task status",$task$$.id,$e$$.message)}this.queue_running=this.queue_running.filter($q$$=>$q$$.id!==$task$$.id);$task$$.callback($message$$,$task$$.id)}delete $wk$$.task;$wk$$.isBusy=!1;this.processQueue()}catch($e$$){Logger.error("[",this.poolName,"]",$e$$);try{delete $wk$$.task,$wk$$.isBusy=!1,this.processQueue()}catch($e$$){Logger.error("[",
|
|
10
|
+
this.poolName,"] cancel current task",$e$$)}}}});$wk$$.worker.on("error",$error$$=>{Logger.error("Worker error:",$error$$);this.terminateWorkerGracefully($wk$$)});$wk$$.worker.on("exit",async $code$$=>{Logger.error("[",this.poolName,"]",`: worker exited with code ${$code$$}. Creating new worker...`);if($wk$$.task){let $task$$=this.queue_running.find($q$$=>$q$$.id==$wk$$.task.id);if($task$$){clearTimeout($task$$.timeoutId);$task$$.finished=new Date;$task$$.status=9;$task$$.message="\u0110\u00e3 c\u00f3 l\u1ed7i x\u1ea3y ra trong h\u1ec7 th\u1ed1ng. H\u00e3y th\u1eed l\u1ea1i";
|
|
11
|
+
let {finished:$finished$$,status:$status$$,message:$message$$,result:$result$$}=$task$$;if($task$$.save_log)try{await redisCache.updateObject($task$$.id,{finished:$finished$$,status:$status$$,message:$message$$,result:$result$$})}catch($e$$){Logger.error("[",this.poolName,"] can't update task status",$task$$.id,$e$$.message)}$task$$.callback&&$task$$.callback({error:$task$$.message},$task$$.id);this.queue_running=this.queue_running.filter($q$$=>$q$$.id!==$task$$.id)}}delete this.workers[$wk$$.id];
|
|
12
|
+
$code$$=this.createWorker();this.workers[$code$$.id]=$code$$;this.processQueue()});return $wk$$}async processQueue($id_worker$$){for(let $i$$=0;$i$$<this.maxWorkers&&this.queue.length!=0;$i$$++){let $wk$$=Object.values(this.workers).find($w$$=>!$w$$.isBusy&&!$w$$.task&&(!$id_worker$$||$id_worker$$==$w$$.id));if(!$wk$$)if(Object.keys(this.workers).length===0)$wk$$=this.createWorker(),this.workers[$wk$$.id]=$wk$$;else{this.checkLoadAndScale();break}if($wk$$){if(!this.workerIsAlive($wk$$)){Logger.error("[",
|
|
13
|
+
this.poolName,"]: Worker",$wk$$.id,"b\u1ecb zombie. Ti\u1ebfn h\u00e0nh terminate...");delete $wk$$.task;this.terminateWorkerGracefully($wk$$);continue}const $task$$=this.queue.shift();if($task$$){$task$$.status=2;$task$$.message="\u0110ang th\u1ef1c hi\u1ec7n";this.queue_running.push($task$$);if($task$$.save_log)try{let {finished:$finished$$,status:$status$$,message:$message$$,result:$result$$}=$task$$;await redisCache.updateObject($task$$.id,{finished:$finished$$,status:$status$$,message:$message$$,
|
|
14
|
+
result:$result$$})}catch($e$$){Logger.error("[",this.poolName,"] can't update task status",$task$$.id,$e$$.message)}$wk$$.isBusy=!0;$wk$$.task=$task$$;$task$$.params.id_worker=$wk$$.id;try{const $bufferParams$$=v8.serialize($task$$.params);$wk$$.worker.postMessage($bufferParams$$,[$bufferParams$$.buffer])}catch($err$$){Logger.error(`[${this.poolName}] L\u1ed7i serialize task params. Fallback sang g\u1eedi th\u01b0\u1eddng.`,$err$$),$wk$$.worker.postMessage($task$$.params)}$task$$.timeoutId=setTimeout(async()=>
|
|
15
|
+
{this.queue_running=this.queue_running.filter($q$$=>$q$$.id!==$task$$.id);$task$$.finished=new Date;$task$$.status=9;$task$$.message=`\u0110\u00e3 h\u1ebft th\u1eddi gian th\u1ef1c hi\u1ec7n (Time out: ${$task$$.timeout||this.defaultTimeout} ms)`;let {finished:$finished$$,status:$status$$,message:$message$$,result:$result$$}=$task$$;if($task$$.save_log)try{await redisCache.updateObject($task$$.id,{finished:$finished$$,status:$status$$,message:$message$$,result:$result$$})}catch($e$$){Logger.error("[",
|
|
16
|
+
this.poolName,"] can't update task status",$task$$.id,$e$$.message)}$task$$.callback&&$task$$.callback({error:$task$$.message},$task$$.id);Logger.error(`[${this.poolName}] Task ${$task$$.id} TIMEOUT! Terminating worker ${$wk$$.id}...`);delete $wk$$.task;this.terminateWorkerGracefully($wk$$)},$task$$.timeout||this.defaultTimeout)}}}}async pushToQueue($params$$,$callback$$,$timeout$$=0,$id_worker$$){let $save_log$$=!0;$params$$.id_task||($params$$.id_task=`task-${crypto.randomBytes(20).toString("hex")}`,
|
|
17
|
+
$save_log$$=!1);$timeout$$=$timeout$$||this.defaultTimeout;const $task$$={id:$params$$.id_task,start:new Date,params:_.cloneDeep($params$$),timeout:$timeout$$,status:0,save_log:$save_log$$};delete $task$$.params.configs;delete $task$$.params.user;delete $task$$.params.data;$task$$.params.req&&(delete $task$$.params.req.user,delete $task$$.params.req.body,delete ($task$$.params.req.query||{}).access_token);try{try{$save_log$$&&await redisCache.setObject($params$$.id_task,$task$$)}catch($e$$){Logger.error("[",
|
|
18
|
+
this.poolName,"] Kh\u00f4ng th\u1ec3 l\u01b0u task t\u1edbi redis:",$e$$.message)}this.queue.push({id:$params$$.id_task,params:$params$$,callback:$callback$$,timeout:$timeout$$,status:0,save_log:$save_log$$});this.processQueue($id_worker$$)}catch($e$$){Logger.error("[",this.poolName,"] : l\u1ed7i \u0111\u1ea9y task t\u1edbi queue",$e$$),$callback$$({error:$e$$.error||$e$$.message||$e$$})}}async exec($args_params$$,$callback$$=()=>{},$timeout$$=0){if(this.maxQueue>0&&this.queue.length>=this.maxQueue)Logger.error("[",
|
|
19
|
+
this.poolName,"]",": queue is full"),$callback$$({error:"Queue is full"});else if($args_params$$.load)for(let $id_worker$$ of Object.keys(this.workers)){let $params$$=_.cloneDeep($args_params$$);this.pushToQueue($params$$,$callback$$,$timeout$$,$id_worker$$)}else $args_params$$=_.cloneDeep($args_params$$),this.pushToQueue($args_params$$,$callback$$,$timeout$$)}fullQueue(){return this.maxQueue>0&&this.queue.length>=this.maxQueue}busy(){return Object.values(this.workers).filter($w$$=>!$w$$.isBusy).length==
|
|
20
|
+
0}destroy(){for(const $worker$$ of Object.values(this.workers))$worker$$.terminate();this.workers={};this.queue=[]}}module.exports=WorkerPool;
|
package/server/libs/cdpskh.js
CHANGED
|
@@ -10,5 +10,6 @@ ps_no_nt:0,ps_co_nt:0,ck_no:0,ck_co:0,ck_no_nt:0,ck_co_nt:0});$dkRes$$.forEach($
|
|
|
10
10
|
{var $item$jscomp$2_key$$=$getGroupKey$$($r$$);$dataMap$$.has($item$jscomp$2_key$$)||$dataMap$$.set($item$jscomp$2_key$$,$initItem$$(_.pick($r$$,$groupBy$$)));$item$jscomp$2_key$$=$dataMap$$.get($item$jscomp$2_key$$);$item$jscomp$2_key$$.ps_no+=$r$$.ps_no||0;$item$jscomp$2_key$$.ps_co+=$r$$.ps_co||0;$item$jscomp$2_key$$.ps_no_nt+=$r$$.ps_no_nt||0;$item$jscomp$2_key$$.ps_co_nt+=$r$$.ps_co_nt||0});$ckRes$$.forEach($r$$=>{var $item$jscomp$3_key$$=$getGroupKey$$($r$$);$dataMap$$.has($item$jscomp$3_key$$)||
|
|
11
11
|
$dataMap$$.set($item$jscomp$3_key$$,$initItem$$(_.pick($r$$,$groupBy$$)));$item$jscomp$3_key$$=$dataMap$$.get($item$jscomp$3_key$$);$item$jscomp$3_key$$.ck_no+=$r$$.du_no00||0;$item$jscomp$3_key$$.ck_co+=$r$$.du_co00||0;$item$jscomp$3_key$$.ck_no_nt+=$r$$.du_no_nt00||0;$item$jscomp$3_key$$.ck_co_nt+=$r$$.du_co_nt00||0});let $finalData$$=Array.from($dataMap$$.values()).map($d$$=>{var $netCk_netDk$$=$d$$.dk_no-$d$$.dk_co,$netCkNt_netDkNt$$=$d$$.dk_no_nt-$d$$.dk_co_nt;$netCk_netDk$$>0?($d$$.dk_no=$netCk_netDk$$,
|
|
12
12
|
$d$$.dk_co=0):($d$$.dk_co=Math.abs($netCk_netDk$$),$d$$.dk_no=0);$netCkNt_netDkNt$$>0?($d$$.dk_no_nt=$netCkNt_netDkNt$$,$d$$.dk_co_nt=0):($d$$.dk_co_nt=Math.abs($netCkNt_netDkNt$$),$d$$.dk_no_nt=0);$netCk_netDk$$=$d$$.ck_no-$d$$.ck_co;$netCkNt_netDkNt$$=$d$$.ck_no_nt-$d$$.ck_co_nt;$netCk_netDk$$>0?($d$$.ck_no=$netCk_netDk$$,$d$$.ck_co=0):($d$$.ck_co=Math.abs($netCk_netDk$$),$d$$.ck_no=0);$netCkNt_netDkNt$$>0?($d$$.ck_no_nt=$netCkNt_netDkNt$$,$d$$.ck_co_nt=0):($d$$.ck_co_nt=Math.abs($netCkNt_netDkNt$$),
|
|
13
|
-
$d$$.ck_no_nt=0);return $d$$});$finalData$$=$finalData$$.filter($row$$=>Math.abs($row$$.dk_no)+Math.abs($row$$.dk_co)+Math.abs($row$$.ps_no)+Math.abs($row$$.ps_co)+Math.abs($row$$.ck_no)+Math.abs($row$$.ck_co)+(Math.abs($row$$.dk_no_nt)+Math.abs($row$$.dk_co_nt)+Math.abs($row$$.ps_no_nt)+Math.abs($row$$.ps_co_nt)+Math.abs($row$$.ck_no_nt)+Math.abs($row$$.ck_co_nt))!==0)
|
|
14
|
-
$
|
|
13
|
+
$d$$.ck_no_nt=0);return $d$$});$finalData$$=$finalData$$.filter($row$$=>Math.abs($row$$.dk_no)+Math.abs($row$$.dk_co)+Math.abs($row$$.ps_no)+Math.abs($row$$.ps_co)+Math.abs($row$$.ck_no)+Math.abs($row$$.ck_co)+(Math.abs($row$$.dk_no_nt)+Math.abs($row$$.dk_co_nt)+Math.abs($row$$.ps_no_nt)+Math.abs($row$$.ps_co_nt)+Math.abs($row$$.ck_no_nt)+Math.abs($row$$.ck_co_nt))!==0);if($query$$.tinh_tong_cong||$query$$.chi_hien_tong_cong){let $total_row$$={dien_giai:"T\u1ed5ng c\u1ed9ng",dk_no:0,dk_co:0,ps_no:0,
|
|
14
|
+
ps_co:0,ck_no:0,ck_co:0,dk_no_nt:0,dk_co_nt:0,ps_no_nt:0,ps_co_nt:0,ck_no_nt:0,ck_co_nt:0};$finalData$$.forEach($r$$=>{$total_row$$.dk_no+=$r$$.dk_no||0;$total_row$$.dk_co+=$r$$.dk_co||0;$total_row$$.ps_no+=$r$$.ps_no||0;$total_row$$.ps_co+=$r$$.ps_co||0;$total_row$$.ck_no+=$r$$.ck_no||0;$total_row$$.ck_co+=$r$$.ck_co||0;$total_row$$.dk_no_nt+=$r$$.dk_no_nt||0;$total_row$$.dk_co_nt+=$r$$.dk_co_nt||0;$total_row$$.ps_no_nt+=$r$$.ps_no_nt||0;$total_row$$.ps_co_nt+=$r$$.ps_co_nt||0;$total_row$$.ck_no_nt+=
|
|
15
|
+
$r$$.ck_no_nt||0;$total_row$$.ck_co_nt+=$r$$.ck_co_nt||0});$query$$.chi_hien_tong_cong?$finalData$$=[$total_row$$]:$finalData$$.push($total_row$$)}return $fn$$?$fn$$(null,$finalData$$):$finalData$$}catch($error$$){$errMsg_pDauKy$$=$error$$.message||$error$$;if($fn$$)return $fn$$(Error($errMsg_pDauKy$$));throw $error$$;}};
|
package/server/libs/cdpstk.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const dktk=require("./dktk"),cktk=require("./cktk"),pstk=require("./pstk"),Account=global.getModel("account"),async=require("async"),
|
|
2
|
-
module.exports=function($query$$,$
|
|
3
|
-
$query$$.tu_ngay;$condition$$.groupBy=["tk"];dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)},{model:"socaitc"})}
|
|
4
|
-
$
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
const dktk=require("./dktk"),cktk=require("./cktk"),pstk=require("./pstk"),Account=global.getModel("account"),async=require("async"),setBacTKCon=($data$$,$tk_me$$,$bac_tk_me$$)=>{$data$$.filter($d$$=>$d$$.tk_me==$tk_me$$).forEach($tk$$=>{$tk$$.bac_tk=$bac_tk_me$$+1;setBacTKCon($data$$,$tk$$.tk,$tk$$.bac_tk)})};
|
|
2
|
+
module.exports=async function($query$$,$callback$$){try{if(!$query$$.tu_ngay||!$query$$.den_ngay||!$query$$.id_app)throw Error("H\u00e0m n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1 tu_ngay,den_ngay,id_app");$query$$.tk||($query$$.tk="");let $bac_tk$$=Number($query$$.bac_tk||0);delete $query$$.bac_tk;let $chi_lay_tk_con$$=$query$$.chi_lay_tk_con;delete $query$$.chi_lay_tk_con;const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({dk:function($callback$$){let $condition$$={...$query$$};
|
|
3
|
+
$condition$$.ngay=$query$$.tu_ngay;$condition$$.groupBy=["tk"];dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)},{model:"socaitc"})},ps:function($callback$$){let $condition$$={id_app:$query$$.id_app},$tk$$=$query$$.tk;if(Array.isArray($tk$$)){let $tks$$;$tk$$.forEach(function($t$$){$tks$$=$tks$$?$tks$$+"|^"+$t$$:"^"+$t$$});$tks$$||="^";$tk$$={$regex:$tks$$,$options:"i"}}else $tk$$={$regex:"^"+$tk$$,$options:"i"};$condition$$.tk=$tk$$;
|
|
4
|
+
$query$$.ma_dvcs&&($condition$$.ma_dvcs=$query$$.ma_dvcs);$condition$$.ngay_ct={$gte:$query$$.tu_ngay,$lte:$query$$.den_ngay};$query$$.ma_kho&&($condition$$.ma_kho=$query$$.ma_kho);pstk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)},{model:"socaitt",groupBy:["tk"]})},ck:function($callback$$){let $condition$$={...$query$$};$condition$$.ngay=$query$$.den_ngay;$condition$$.groupBy=["tk"];cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);
|
|
5
|
+
$callback$$(null,$result$$)},{model:"socaitc"})}},function($error$$,$results$$){if($error$$)return $reject$$($error$$);let $data$$=$results$$.ps;$results$$.dk.forEach(function($r$$){$r$$.dk_no=$r$$.du_no00;$r$$.dk_co=$r$$.du_co00;$r$$.dk_no_nt=$r$$.du_no_nt00;$r$$.dk_co_nt=$r$$.du_co_nt00;$data$$.push($r$$)});$results$$.ck.forEach(function($r$$){$r$$.ck_no=$r$$.du_no00;$r$$.ck_co=$r$$.du_co00;$r$$.ck_no_nt=$r$$.du_no_nt00;$r$$.ck_co_nt=$r$$.du_co_nt00;$data$$.push($r$$)});$data$$.groupBy("tk",[{name:"dk_no",
|
|
6
|
+
value:"dk_no"},{name:"dk_co",value:"dk_co"},{name:"dk_no_nt",value:"dk_no_nt"},{name:"dk_co_nt",value:"dk_co_nt"},{name:"ps_no",value:"ps_no"},{name:"ps_co",value:"ps_co"},{name:"ps_no_nt",value:"ps_no_nt"},{name:"ps_co_nt",value:"ps_co_nt"},{name:"ck_no",value:"ck_no"},{name:"ck_co",value:"ck_co"},{name:"ck_no_nt",value:"ck_no_nt"},{name:"ck_co_nt",value:"ck_co_nt"}],function($error$$,$data$$){if($chi_lay_tk_con$$)return $resolve$$($data$$);let $cdpstkme$$=[];async.map($data$$,function($acc$$,$callback$$){$acc$$.loai_tk=
|
|
7
|
+
1;let $tk$$=$acc$$.tk;async.forever(function($next$$){Account.find({tk:$tk$$,id_app:$query$$.id_app},{tk_me:1},function($error1_vTK$$,$r$$){$r$$&&$r$$.length==1&&$r$$[0].tk_me?($error1_vTK$$={...$acc$$},$error1_vTK$$.tk=$r$$[0].tk_me,$cdpstkme$$.push($error1_vTK$$),$tk$$=$r$$[0].tk_me,$next$$()):$next$$("finish or has error")})},function(){$callback$$()})},function(){$cdpstkme$$.groupBy("tk",[{name:"dk_no",value:"dk_no"},{name:"dk_co",value:"dk_co"},{name:"dk_no_nt",value:"dk_no_nt"},{name:"dk_co_nt",
|
|
8
|
+
value:"dk_co_nt"},{name:"ps_no",value:"ps_no"},{name:"ps_co",value:"ps_co"},{name:"ps_no_nt",value:"ps_no_nt"},{name:"ps_co_nt",value:"ps_co_nt"},{name:"ck_no",value:"ck_no"},{name:"ck_co",value:"ck_co"},{name:"ck_no_nt",value:"ck_no_nt"},{name:"ck_co_nt",value:"ck_co_nt"}],function($error$$,$dataTkMe$$){if($error$$)return $reject$$($error$$);async.map($dataTkMe$$,function($tkMe$$,$callback$$){Account.find({tk:$tkMe$$.tk,id_app:$query$$.id_app},{tk_cn:1,loai_tk:1},function($e3_tk$$,$rtk$$){if($rtk$$?.length!=
|
|
9
|
+
1)return $callback$$(null);$e3_tk$$=$rtk$$[0];$tkMe$$.loai_tk=$e3_tk$$.loai_tk;if($e3_tk$$.tk_cn&&!$query$$.bu_tru)return $data$$.push($tkMe$$),$callback$$(null);$tkMe$$.dk_no-=$tkMe$$.dk_co;$tkMe$$.ck_no-=$tkMe$$.ck_co;$tkMe$$.dk_no_nt-=$tkMe$$.dk_co_nt;$tkMe$$.ck_no_nt-=$tkMe$$.ck_co_nt;$tkMe$$.dk_no<0?($tkMe$$.dk_co=Math.abs($tkMe$$.dk_no),$tkMe$$.dk_no=0):$tkMe$$.dk_co=0;$tkMe$$.dk_no_nt<0?($tkMe$$.dk_co_nt=Math.abs($tkMe$$.dk_no_nt),$tkMe$$.dk_no_nt=0):$tkMe$$.dk_co_nt=0;$tkMe$$.ck_no<0?($tkMe$$.ck_co=
|
|
10
|
+
Math.abs($tkMe$$.ck_no),$tkMe$$.ck_no=0):$tkMe$$.ck_co=0;$tkMe$$.ck_no_nt<0?($tkMe$$.ck_co_nt=Math.abs($tkMe$$.ck_no_nt),$tkMe$$.ck_no_nt=0):$tkMe$$.ck_co_nt=0;$data$$.push($tkMe$$);$callback$$(null)})},async function(){await $data$$.asyncJoinModel2($query$$.id_app,Account,{where:"tk",fields:"tk_me"});$data$$.filter($d$$=>!$d$$.tk_me).forEach($d$$=>{$d$$.bac_tk=1;setBacTKCon($data$$,$d$$.tk,$d$$.bac_tk)});$data$$.filter($d$$=>$d$$.loai_tk==0||$d$$.bac_tk===1).forEach($d$$=>$d$$.bold=!0);$data$$=$data$$.filter($row$$=>
|
|
11
|
+
Math.abs($row$$.dk_no)+Math.abs($row$$.dk_co)+Math.abs($row$$.ps_no)+Math.abs($row$$.ps_co)+Math.abs($row$$.ck_no)+Math.abs($row$$.ck_co)+(Math.abs($row$$.dk_no_nt)+Math.abs($row$$.dk_co_nt)+Math.abs($row$$.ps_no_nt)+Math.abs($row$$.ps_co_nt)+Math.abs($row$$.ck_no_nt)+Math.abs($row$$.ck_co_nt))!==0&&(!$bac_tk$$||$row$$.bac_tk<=Number($bac_tk$$)));$resolve$$($data$$)})})})})})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/cktk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const cktt=require("./cktt"),ckcn=require("./ckcn"),async=require("async");
|
|
2
|
-
module.exports=function($condition$$,$
|
|
3
|
-
["tk","ma_kh"];$bu_tru$$===!0&&($_group$$=["tk"]);let $_condition$$={...$condition$$};$_condition$$.groupBy=$_group$$;ckcn($_condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$bu_tru$$===!0&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=0;$r$$.du_no_nt00<0?($r$$.du_co_nt00=
|
|
4
|
-
$result$$)},{model:"socaitc"})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $
|
|
2
|
+
module.exports=async function($condition$$,$callback$$){try{if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)throw Error("ngay and id_app parameter required");let $tk$$=$condition$$.tk;$tk$$||="";let $bu_tru$$=$condition$$.bu_tru;$bu_tru$$||=!1;$condition$$.groupBy=$condition$$.groupBy||["tk"];const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({tt:function($callback$$){cktt($condition$$,function($error$$,$report$$){if($error$$)return $callback$$($error$$);$callback$$(null,
|
|
3
|
+
$report$$)},{model:"socaitt"})},cn:function($callback$$){let $_group$$=["tk","ma_kh"];$bu_tru$$===!0&&($_group$$=["tk"]);let $_condition$$={...$condition$$};$_condition$$.groupBy=$_group$$;ckcn($_condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$bu_tru$$===!0&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=0;$r$$.du_no_nt00<0?($r$$.du_co_nt00=
|
|
4
|
+
Math.abs($r$$.du_no_nt00),$r$$.du_no_nt00=0):$r$$.du_co_nt00=0});$callback$$(null,$result$$)},{model:"socaitc"})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $reject$$($error$jscomp$4_report$$);$error$jscomp$4_report$$=$results$$.tt.concat($results$$.cn);$resolve$$($error$jscomp$4_report$$)})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/ckvt.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const dmvt=global.getModel("dmvt"),sokho=global.getModel("sokho"),hanmucton=global.getModel("hanmucton"),ckvtcapphat=require("./ckvtcapphat"),utils=require("./utils"),_=require("lodash"),moment=require("moment"),buildAggregatePipeline=($match$$,$groupByCols$$)=>{const $groupId$$={};$groupByCols$$.forEach($col$$=>$groupId$$[$col$$]=`$${$col$$}`);return[{$match:$match$$},{$group:{_id:$groupId$$,sl_nhap:{$sum:"$sl_nhap_qd"},sl_xuat:{$sum:"$sl_xuat_qd"},tien_nhap:{$sum:"$tien_nhap"},tien_xuat:{$sum:"$tien_xuat"},
|
|
2
2
|
ton00:{$sum:"$ton00"},du00:{$sum:"$du00"}}},{$project:{_id:0,...$groupByCols$$.reduce(($acc$$,$curr$$)=>({...$acc$$,[$curr$$]:`$_id.${$curr$$}`}),{}),sl_nhap:1,sl_xuat:1,tien_nhap:1,tien_xuat:1,ton00:1,du00:1}}]};
|
|
3
|
-
module.exports=async($condition$$,$
|
|
4
|
-
$condition$$.groupBy||$condition$$.groupby||["ma_vt"];if(_.isString($groupBy$$))try{$groupBy$$=$groupBy$$.includes("[")?JSON.parse($groupBy$$):$groupBy$$.split(",")}catch($e$$){$groupBy$$=["ma_vt"]}const $ngay$$=moment($condition$$.ngay).endOf("date").toDate(),[$app$$,$lastLockData$$]=await Promise.all([global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean(),global.getModel("cdvttheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},
|
|
5
|
-
if(!$app$$)
|
|
6
|
-
|
|
7
|
-
($e$$,$rs$$)=>$resolve$$($rs$$||[]))),$pDauKy$$=(async()=>{const $c_dk$$={id_app:$id_app$$};$nam$$?$c_dk$$.nam=$nam$$:$c_dk$$.den_ngay=$ngay_ks$$;Object.assign($c_dk$$,$buildFilter$$());return $CdvtModel$$.aggregate(buildAggregatePipeline($c_dk$$,$groupBy$$))})(),$pPhatSinh$$=(async()=>{var $pipeline_query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};Object.assign($pipeline_query$$,$buildFilter$$());$condition$$.id_ct&&($pipeline_query$$.id_ct={$ne:$condition$$.id_ct})
|
|
8
|
-
buildAggregatePipeline($pipeline_query$$,$groupBy$$);return sokho.aggregate($pipeline_query$$).inTxn()})(),$pHanMuc$$=hanmucton.find($buildFilter$$({id_app:$id_app$$})).lean(),$pDefault$$=(async()=>{const $q$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($q$$.ma_vt=$ma_vt$$);return dmvt.find($q$$,{ma_vt:1,ton_kho_mac_dinh:1}).lean()})(),[$ckData$$,$dnData$$,$psData$$,$hmData$$,$dfData$$]=await Promise.all([$pCkcapphat$$,$pDauKy$$,$pPhatSinh$$,$pHanMuc
|
|
9
|
-
new Map,$getGroupKey$$=$item$$=>$groupBy$$.map($k$$=>$item$$[$k$$]||"").join("||");$merge_ngay_tinh_dn$$=($JSCompiler_temp_const$jscomp$0$$,$type$$)=>{if($JSCompiler_temp_const$jscomp$0$$)for(const $item$$ of $JSCompiler_temp_const$jscomp$0$$){const $key$$=$getGroupKey$$($item$$);if(!$dataMap$$.has($key$$)){$JSCompiler_temp_const$jscomp$0$$=$dataMap$$;var $JSCompiler_temp_const$$=$JSCompiler_temp_const$jscomp$0$$.set;const $obj$$=_.pick($item$$,$groupBy$$);$obj$$.ton00=0
|
|
10
|
-
0;$obj$$.sl_xuat=0;$obj$$.tien_nhap=0;$obj$$.tien_xuat=0;$obj$$.ton00_capphat=0;$obj$$.du00_capphat=0;$obj$$.ton_kho_mac_dinh=0;$obj$$.ton_toi_thieu=0;$obj$$.ton_toi_da=0;$JSCompiler_temp_const$$.call($JSCompiler_temp_const$jscomp$0$$,$key$$,$obj$$)}$JSCompiler_temp_const$jscomp$0$$=$dataMap$$.get($key$$);$type$$==="dn"?($JSCompiler_temp_const$jscomp$0$$.ton00+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00+=$item$$.du00||0):$type$$==="ps"?($JSCompiler_temp_const$jscomp$0$$.sl_nhap
|
|
11
|
-
0,$JSCompiler_temp_const$jscomp$0$$.sl_xuat+=$item$$.sl_xuat||0,$JSCompiler_temp_const$jscomp$0$$.tien_nhap+=$item$$.tien_nhap||0,$JSCompiler_temp_const$jscomp$0$$.tien_xuat+=$item$$.tien_xuat||0):$type$$==="capphat"?($JSCompiler_temp_const$jscomp$0$$.ton00_capphat+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00_capphat+=$item$$.du00||0):$type$$==="default"?$JSCompiler_temp_const$jscomp$0$$.ton_kho_mac_dinh=$item$$.ton_kho_mac_dinh||0:$type$$==="hanmuc"&&($JSCompiler_temp_const$jscomp$0$$.ton_toi_thieu=
|
|
3
|
+
module.exports=async($condition$$,$callback$$)=>{try{!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);$condition$$.ngay||($condition$$.ngay=new Date);const {ma_dvcs:$ma_dvcs$$,ma_kho:$ma_kho$$,id_app:$id_app$$}=$condition$$;let $ma_vt$$=$condition$$.ma_vt;if(_.isString($ma_vt$$)&&$ma_vt$$.includes("["))try{$ma_vt$$=JSON.parse($ma_vt$$),$ma_vt$$.length===0&&($ma_vt$$=void 0)}catch($e$$){Logger.error("[ckvt] parse ma_vt",$e$$,$ma_vt$$)}$ma_vt$$&&_.isArray($ma_vt$$)&&
|
|
4
|
+
($ma_vt$$={$in:$ma_vt$$});let $groupBy$$=$condition$$.groupBy||$condition$$.groupby||["ma_vt"];if(_.isString($groupBy$$))try{$groupBy$$=$groupBy$$.includes("[")?JSON.parse($groupBy$$):$groupBy$$.split(",")}catch($e$$){$groupBy$$=["ma_vt"]}const $ngay$$=moment($condition$$.ngay).endOf("date").toDate(),[$app$$,$lastLockData$$]=await Promise.all([global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean(),global.getModel("cdvttheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},
|
|
5
|
+
{den_ngay:1}).sort({den_ngay:-1}).lean()]);if(!$app$$)throw"C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i";let $ngay_ks$$=$lastLockData$$?$lastLockData$$.den_ngay:null;$ngay_ks$$&&=moment($ngay_ks$$).endOf("date").toDate();var $merge_ngay_tinh_dn$$=$condition$$.tu_ngay&&new Date($condition$$.tu_ngay)<$ngay$$?moment($condition$$.tu_ngay).endOf("date").toDate():$ngay$$;let $ngay_dn$$=moment($merge_ngay_tinh_dn$$).startOf("year").toDate(),$nam$$,$CdvtModel$$;!$ngay_ks$$||$ngay_ks$$<$ngay_dn$$?($CdvtModel$$=
|
|
6
|
+
global.getModel("cdvt"),$nam$$=$merge_ngay_tinh_dn$$.getFullYear()):($CdvtModel$$=global.getModel("cdvttheongay"),$ngay_dn$$=moment($ngay_ks$$).startOf("date").add(1,"days").toDate());const $buildFilter$$=($base$$={})=>{const $q$$={...$base$$};$ma_kho$$&&($q$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($q$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($q$$.ma_vt=$ma_vt$$);["ma_lo","han_sd","ma_tt1","ma_tt2","ma_tt3"].forEach($f$$=>{$condition$$[$f$$]&&($q$$[$f$$]=$condition$$[$f$$])});return $q$$},$pCkcapphat$$=new Promise($resolve$$=>
|
|
7
|
+
ckvtcapphat($condition$$,($e$$,$rs$$)=>$resolve$$($rs$$||[]))),$pDauKy$$=(async()=>{const $c_dk$$={id_app:$id_app$$};$nam$$?$c_dk$$.nam=$nam$$:$c_dk$$.den_ngay=$ngay_ks$$;Object.assign($c_dk$$,$buildFilter$$());return $CdvtModel$$.aggregate(buildAggregatePipeline($c_dk$$,$groupBy$$))})(),$pPhatSinh$$=(async()=>{var $pipeline_query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};Object.assign($pipeline_query$$,$buildFilter$$());$condition$$.id_ct&&($pipeline_query$$.id_ct={$ne:$condition$$.id_ct});
|
|
8
|
+
$pipeline_query$$=buildAggregatePipeline($pipeline_query$$,$groupBy$$);return sokho.aggregate($pipeline_query$$).inTxn()})(),$pHanMuc$$=hanmucton.find($buildFilter$$({id_app:$id_app$$})).lean(),$pDefault$$=(async()=>{const $q$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($q$$.ma_vt=$ma_vt$$);return dmvt.find($q$$,{ma_vt:1,ton_kho_mac_dinh:1}).lean()})(),[$ckData$$,$dnData$$,$psData$$,$hmData$$,$dfData$$]=await Promise.all([$pCkcapphat$$,$pDauKy$$,$pPhatSinh$$,$pHanMuc$$,
|
|
9
|
+
$pDefault$$]),$dataMap$$=new Map,$getGroupKey$$=$item$$=>$groupBy$$.map($k$$=>$item$$[$k$$]||"").join("||");$merge_ngay_tinh_dn$$=($JSCompiler_temp_const$jscomp$0$$,$type$$)=>{if($JSCompiler_temp_const$jscomp$0$$)for(const $item$$ of $JSCompiler_temp_const$jscomp$0$$){const $key$$=$getGroupKey$$($item$$);if(!$dataMap$$.has($key$$)){$JSCompiler_temp_const$jscomp$0$$=$dataMap$$;var $JSCompiler_temp_const$$=$JSCompiler_temp_const$jscomp$0$$.set;const $obj$$=_.pick($item$$,$groupBy$$);$obj$$.ton00=0;
|
|
10
|
+
$obj$$.du00=0;$obj$$.sl_nhap=0;$obj$$.sl_xuat=0;$obj$$.tien_nhap=0;$obj$$.tien_xuat=0;$obj$$.ton00_capphat=0;$obj$$.du00_capphat=0;$obj$$.ton_kho_mac_dinh=0;$obj$$.ton_toi_thieu=0;$obj$$.ton_toi_da=0;$JSCompiler_temp_const$$.call($JSCompiler_temp_const$jscomp$0$$,$key$$,$obj$$)}$JSCompiler_temp_const$jscomp$0$$=$dataMap$$.get($key$$);$type$$==="dn"?($JSCompiler_temp_const$jscomp$0$$.ton00+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00+=$item$$.du00||0):$type$$==="ps"?($JSCompiler_temp_const$jscomp$0$$.sl_nhap+=
|
|
11
|
+
$item$$.sl_nhap||0,$JSCompiler_temp_const$jscomp$0$$.sl_xuat+=$item$$.sl_xuat||0,$JSCompiler_temp_const$jscomp$0$$.tien_nhap+=$item$$.tien_nhap||0,$JSCompiler_temp_const$jscomp$0$$.tien_xuat+=$item$$.tien_xuat||0):$type$$==="capphat"?($JSCompiler_temp_const$jscomp$0$$.ton00_capphat+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00_capphat+=$item$$.du00||0):$type$$==="default"?$JSCompiler_temp_const$jscomp$0$$.ton_kho_mac_dinh=$item$$.ton_kho_mac_dinh||0:$type$$==="hanmuc"&&($JSCompiler_temp_const$jscomp$0$$.ton_toi_thieu=
|
|
12
12
|
$item$$.ton_toi_thieu||0,$JSCompiler_temp_const$jscomp$0$$.ton_toi_da=$item$$.ton_toi_da||0)}};$merge_ngay_tinh_dn$$($dnData$$,"dn");$merge_ngay_tinh_dn$$($psData$$,"ps");$merge_ngay_tinh_dn$$($ckData$$,"capphat");$merge_ngay_tinh_dn$$($dfData$$,"default");$merge_ngay_tinh_dn$$($hmData$$,"hanmuc");const $results$$=Array.from($dataMap$$.values()).map($r$$=>{$r$$.sl_nhap=utils.round($r$$.sl_nhap,4);$r$$.sl_xuat=utils.round($r$$.sl_xuat,4);$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,
|
|
13
|
-
4);$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0);$r$$.sl_nhap=0;$r$$.sl_xuat=0;$r$$.tien_nhap=0;$r$$.tien_xuat=0;$r$$.ton=utils.round($r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),4);$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);return $r$$})
|
|
13
|
+
4);$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0);$r$$.sl_nhap=0;$r$$.sl_xuat=0;$r$$.tien_nhap=0;$r$$.tien_xuat=0;$r$$.ton=utils.round($r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),4);$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);return $r$$});return $callback$$?$callback$$(null,$results$$):$results$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/ckvtnpp.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const cdvt=global.getModel("cdvtnpp"),sokho=global.getModel("sokhonpp"),utils=require("./utils"),async=require("async"),underscore=require("underscore"),moment=require("moment");
|
|
2
|
-
module.exports=async($condition$$,$
|
|
3
|
-
|
|
2
|
+
module.exports=async($condition$$,$callback$$)=>{!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;if(underscore.isString($ma_vt$$)&&$ma_vt$$.indexOf("[")>=0&&$ma_vt$$.indexOf("]")>0)try{$ma_vt$$=JSON.parse($ma_vt$$),$ma_vt$$.length==0&&($ma_vt$$=void 0)}catch($e$$){Logger.error($e$$)}$ma_vt$$&&underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $ngay$$,
|
|
3
|
+
$nam$$,$ngay_dn$$;$ngay$$=moment($condition$$.ngay).endOf("date").toDate();if($condition$$.tu_ngay){let $tu_ngay$$=new Date($condition$$.tu_ngay);$nam$$=$tu_ngay$$.getFullYear();$ngay_dn$$=moment($tu_ngay$$).startOf("year").toDate()}else $nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate();let $id_app$$=$condition$$.id_app;try{let $result$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};
|
|
4
4
|
$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($c_dk$$.ma_kh=$condition$$.ma_kh);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,
|
|
5
5
|
$results$$)}).catch($error$$=>{$callback$$($error$$)})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);
|
|
6
|
-
$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)return $
|
|
7
|
-
$
|
|
8
|
-
"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>{if($e$$)return $
|
|
6
|
+
$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)return $reject$$(Error($data_error$$));
|
|
7
|
+
$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps).concat($groupBy_results$$.ton_kho_mac_dinh).concat($groupBy_results$$.hanmucton);($groupBy_results$$=$condition$$.groupBy||$condition$$.groupby)||($groupBy_results$$=["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){Logger.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,
|
|
8
|
+
"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>{if($e$$)return $reject$$(Error($e$$));for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0,$r$$.ton=$r$$.ton00,$r$$.du=$r$$.du00;$resolve$$($groups$$)})})});return $callback$$?$callback$$(null,
|
|
9
|
+
$result$$):$result$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/ckvttt.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const cdvt=global.getModel("cdvt"),dmvt=global.getModel("dmvt"),sokho=global.getModel("sokhott"),ckvtcapphat=require("./ckvtcapphat"),hanmucton=global.getModel("hanmucton"),utils=require("./utils"),async=require("async"),underscore=require("underscore"),moment=require("moment");
|
|
2
|
-
module.exports=async($condition$$,$
|
|
3
|
-
|
|
2
|
+
module.exports=async($condition$$,$callback$$)=>{!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;$ma_vt$$&&underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $ngay$$,$nam$$,$ngay_dn$$;$ngay$$=moment($condition$$.ngay).endOf("date").toDate();if($condition$$.tu_ngay){let $tu_ngay$$=new Date($condition$$.tu_ngay);$nam$$=$tu_ngay$$.getFullYear();$ngay_dn$$=
|
|
3
|
+
moment($tu_ngay$$).startOf("year").toDate()}else $nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate();let $id_app$$=$condition$$.id_app;try{let $result$$=await new Promise(($resolve$$,$reject$$)=>{async.series({ckcapphat:$callback$$=>{setImmediate(()=>{ckvtcapphat($condition$$,($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})},dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);
|
|
4
4
|
$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},hanmucton:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};
|
|
5
5
|
$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);hanmucton.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},
|
|
6
6
|
ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);
|
|
7
7
|
$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokho.find($query$$).inTxn().lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})},ton_kho_mac_dinh:$callback$$=>{setImmediate(()=>{let $query$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);dmvt.find($query$$,{ma_vt:1,
|
|
8
|
-
ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{Logger.error($e$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $
|
|
8
|
+
ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{Logger.error($e$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $reject$$(Error($ckcapphat_error$$));$ckcapphat_error$$=$data_results$$.ckcapphat.map($c$$=>{$c$$.ton00_capphat=$c$$.ton00;$c$$.du00_capphat=$c$$.du00;$c$$.ton00=0;$c$$.du00=0;return $c$$});$data_results$$=$data_results$$.dn.concat($data_results$$.ps).concat($ckcapphat_error$$).concat($data_results$$.ton_kho_mac_dinh).concat($data_results$$.hanmucton);
|
|
9
9
|
($ckcapphat_error$$=$condition$$.groupBy||$condition$$.groupby)||($ckcapphat_error$$=["ma_vt"]);if(underscore.isString($ckcapphat_error$$))if($ckcapphat_error$$.indexOf("[")>=0)try{$ckcapphat_error$$=JSON.parse($ckcapphat_error$$)}catch($e$$){Logger.error($e$$)}else $ckcapphat_error$$=$ckcapphat_error$$.split(",");$data_results$$.groupBy($ckcapphat_error$$,"sl_nhap sl_xuat ton00 du00 ton00_capphat du00_capphat tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>
|
|
10
|
-
{if($e$$)return $
|
|
11
|
-
|
|
10
|
+
{if($e$$)return $reject$$(Error($e$$));setImmediate(()=>{$condition$$.canh_bao_ton_min&&($groups$$=$groups$$.filter($g$$=>$g$$.ton_toi_thieu&&$g$$.ton_toi_thieu>$g$$.ton00));$condition$$.canh_bao_ton_max&&($groups$$=$groups$$.filter($g$$=>$g$$.ton_toi_da&&$g$$.ton_toi_da<$g$$.ton00));for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,
|
|
11
|
+
$r$$.tien_nhap=0,$r$$.tien_xuat=0,$r$$.ton=$r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);$resolve$$($groups$$)})})})});return $callback$$?$callback$$(null,$result$$):$result$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/ctvt.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const dkvt=require("./dkvt"),sokho=global.getModel("sokho"),async=require("async");
|
|
2
|
-
module.exports=function($condition$$,$
|
|
3
|
-
{dkvt($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})}
|
|
4
|
-
$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})}
|
|
5
|
-
5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){
|
|
6
|
-
$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){
|
|
7
|
-
sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$
|
|
2
|
+
module.exports=async function($condition$$,$callback$$){try{if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))throw"L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app";let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;const $data$$=await new Promise(($resolve$$,
|
|
3
|
+
$reject$$)=>{async.parallel({dn:function($callback$$){dkvt($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})},ps:function($callback$$){let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&
|
|
4
|
+
($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})}},function($error$$,$results$$){if($error$$)return $reject$$($error$$);
|
|
5
|
+
let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){let $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){let $du_dau$$=$results$$.dn.csum("du00");$callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){let $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){let $tien_nhap$$=$results$$.ps.csum("tien_nhap");
|
|
6
|
+
$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){let $sl_xuat$$=$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){let $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",
|
|
7
|
+
sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$resolve$$($data$$)})})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
|
package/server/libs/dkcn.js
CHANGED
|
@@ -11,4 +11,4 @@ $qObj$$.ma_kh=$condition$$.ma_kh);"ma_dvcs ma_kho ma_bp ma_phi ma_nv ma_nv_giao_
|
|
|
11
11
|
($queryPS$$.id_ct={$ne:$condition$$.ex_id_ct});const $pPhatSinh$$=(async()=>new Promise(($resolve$$,$reject$$)=>{Vsocai.find($queryPS$$,($err$$,$res$$)=>$err$$?$reject$$($err$$):$resolve$$($res$$),{model:$options$$.model,groupBy:$groupBy$$})}))(),[$dauKyResults$$,$phatSinhResults$$]=await Promise.all([$pDauKy$$,$pPhatSinh$$]),$dataMap$$=new Map;$getGroupKey_ngay$$=$item$$=>$groupBy$$.map($k$$=>$item$$[$k$$]?String($item$$[$k$$]):"").join("||");$initItem_ngay_dn$$=$keyData$$=>({...$keyData$$,du_no00:0,
|
|
12
12
|
du_co00:0,du_no_nt00:0,du_co_nt00:0,ps_no:0,ps_co:0,ps_no_nt:0,ps_co_nt:0});for(const $item$$ of $dauKyResults$$){const $key$$=$getGroupKey_ngay$$($item$$);$dataMap$$.has($key$$)||$dataMap$$.set($key$$,$initItem_ngay_dn$$(_.pick($item$$,$groupBy$$)));const $current$$=$dataMap$$.get($key$$);$current$$.du_no00+=$item$$.du_no00||0;$current$$.du_co00+=$item$$.du_co00||0;$current$$.du_no_nt00+=$item$$.du_no_nt00||0;$current$$.du_co_nt00+=$item$$.du_co_nt00||0}for(const $item$$ of $phatSinhResults$$){const $key$$=
|
|
13
13
|
$getGroupKey_ngay$$($item$$);$dataMap$$.has($key$$)||$dataMap$$.set($key$$,$initItem_ngay_dn$$(_.pick($item$$,$groupBy$$)));const $current$$=$dataMap$$.get($key$$);$current$$.ps_no+=$item$$.ps_no||0;$current$$.ps_co+=$item$$.ps_co||0;$current$$.ps_no_nt+=$item$$.ps_no_nt||0;$current$$.ps_co_nt+=$item$$.ps_co_nt||0}const $finalResult$$=Array.from($dataMap$$.values()).map($r$$=>{const $netDebit$$=$r$$.du_no00+$r$$.ps_no-($r$$.du_co00+$r$$.ps_co),$netDebitNt$$=$r$$.du_no_nt00+$r$$.ps_no_nt-($r$$.du_co_nt00+
|
|
14
|
-
$r$$.ps_co_nt);$netDebit$$>=0?($r$$.du_no00=$netDebit$$,$r$$.du_co00=0):($r$$.du_no00=0,$r$$.du_co00=Math.abs($netDebit$$));$netDebitNt$$>=0?($r$$.du_no_nt00=$netDebitNt$$,$r$$.du_co_nt00=0):($r$$.du_no_nt00=0,$r$$.du_co_nt00=Math.abs($netDebitNt$$));$r$$.ps_no=0;$r$$.ps_co=0;$r$$.ps_no_nt=0;$r$$.ps_co_nt=0;return $r$$})
|
|
14
|
+
$r$$.ps_co_nt);$netDebit$$>=0?($r$$.du_no00=$netDebit$$,$r$$.du_co00=0):($r$$.du_no00=0,$r$$.du_co00=Math.abs($netDebit$$));$netDebitNt$$>=0?($r$$.du_no_nt00=$netDebitNt$$,$r$$.du_co_nt00=0):($r$$.du_no_nt00=0,$r$$.du_co_nt00=Math.abs($netDebitNt$$));$r$$.ps_no=0;$r$$.ps_co=0;$r$$.ps_no_nt=0;$r$$.ps_co_nt=0;return $r$$});return $fn$$?$fn$$(null,$finalResult$$):$finalResult$$}catch($error$$){if($fn$$)return $fn$$($error$$);throw $error$$;}};
|
package/server/libs/dktk.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const bgaccs=require("./dktt"),bgcustaccs=require("./dkcn"),async=require("async");
|
|
2
|
-
module.exports=function($condition$$,$
|
|
3
|
-
($_group$$=["tk"]);let $_condition$$=Object.assign({},$condition$$);$_condition$$.groupBy=$_group$$;bgcustaccs($_condition$$,function($error$$,$result$$){$error$$?$callback$$($error$$):($bu_tru$$&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=0;$r$$.du_no_nt00<
|
|
4
|
-
{model:"socaitt",queryByDateHour:$options$$.queryByDateHour})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $
|
|
2
|
+
module.exports=async function($condition$$,$callback$$,$options$$={}){try{if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)throw Error("ngay and id_app required");let $bu_tru$$=$condition$$.bu_tru;$bu_tru$$||=!1;$condition$$.groupBy=$condition$$.groupBy||["tk"];const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({tt:function($callback$$){bgaccs({...$condition$$},function($error$$,$report$$){$error$$?$callback$$($error$$):$callback$$(null,$report$$)},{model:"socaitt",
|
|
3
|
+
queryByDateHour:$options$$.queryByDateHour})},cn:function($callback$$){let $_group$$=["tk","ma_kh"];$bu_tru$$===!0&&($_group$$=["tk"]);let $_condition$$=Object.assign({},$condition$$);$_condition$$.groupBy=$_group$$;bgcustaccs($_condition$$,function($error$$,$result$$){$error$$?$callback$$($error$$):($bu_tru$$&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=0;$r$$.du_no_nt00<
|
|
4
|
+
0?($r$$.du_co_nt00=Math.abs($r$$.du_no_nt00),$r$$.du_no_nt00=0):$r$$.du_co_nt00=0}),$callback$$(null,$result$$))},{model:"socaitt",queryByDateHour:$options$$.queryByDateHour})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $reject$$($error$jscomp$4_report$$);$error$jscomp$4_report$$=$results$$.tt.concat($results$$.cn);$resolve$$($error$jscomp$4_report$$)})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);
|
|
5
|
+
throw $e$$;}};
|