UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.25 kB
const _Notification=global.getModel("notification"),controller=require("../../controllers/controllerRPT"),tinhGt=require("../../libs/tinhGt"),async=require("async"),utils=require("../../libs/utils"); module.exports=function($router$$){new controller($router$$,"tinhgiathanh",async function($req$$,$callback$$){const $condition$$=$req$$.query;$condition$$.nam=Number($condition$$.nam);$condition$$.thang=Number($condition$$.thang);const $email$$=$req$$.user.email,$id_app$$=$condition$$.id_app;if(!$condition$$.nam||!$condition$$.thang)return _Notification.createNotification($email$$,$email$$,"Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,thang","Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,thang", null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,thang");var $dsbp_error$$=require("moment"),$bpcon_ngay_ks_tu_ngay$$=$dsbp_error$$([Number($condition$$.nam),Number($condition$$.thang)-1,1]).startOf("month").toDate();if($bpcon_ngay_ks_tu_ngay$$=await utils.isBookLocked({id_app:$req$$.user.current_id_app,ngay_ct:$bpcon_ngay_ks_tu_ngay$$}))return $dsbp_error$$=`Kh\u00f4ng th\u1ec3 t\u00ednh gi\u00e1 th\u00e0nh. \u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${$dsbp_error$$($bpcon_ngay_ks_tu_ngay$$).format("DD/MM/YYYY")}`, _Notification.createNotification($email$$,$email$$,$dsbp_error$$,$dsbp_error$$,null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$$($dsbp_error$$);$dsbp_error$$=[];$condition$$.tinh_theo_cong_doan?($dsbp_error$$={id_app:$condition$$.id_app,la_cong_doan_sx:!0,status:!0},$condition$$.ma_bp&&($bpcon_ngay_ks_tu_ngay$$=await global.getModel("dmbp").getChilrenByMaBP($condition$$.id_app,$condition$$.ma_bp),$bpcon_ngay_ks_tu_ngay$$.push($condition$$.ma_bp),$dsbp_error$$.ma_bp={$in:$bpcon_ngay_ks_tu_ngay$$}), $dsbp_error$$=(await global.getModel("dmbp").find($dsbp_error$$).sort({stt:1}).lean()).map($r$$=>$r$$.ma_bp)):$dsbp_error$$=[$condition$$.ma_bp];async.mapSeries($dsbp_error$$,($bp$$,$callback$$)=>{tinhGt({...$condition$$,ma_bp:$bp$$},($e$$,$ctgt$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$ctgt$$)})},async $e$$=>{$e$$?(Logger.info("\u26a0\ufe0f[tinhgiatb] Th\u00f4ng b\u00e1o l\u1ed7i t\u1edbi ng\u01b0\u1eddi t\u00ednh"),_Notification.createNotification($email$$,$email$$,$e$$.message||$e$$.error|| $e$$,$e$$.message||$e$$.error||$e$$,null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$$($e$$)):(Logger.info("\u26a0\ufe0f[tinhgiatb] Th\u00f4ng b\u00e1o k\u1ebft qu\u1ea3 t\u1edbi ng\u01b0\u1eddi t\u00ednh"),_Notification.createNotification($email$$,$email$$,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 th\u00e0nh xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 th\u00e0nh xong",null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$$(null))})},{stream:!1, useSession:!0,cache:!1,queue:!0,timeout:18E6,waiting_message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. B\u1ea1n c\u00f3 th\u1ec3 chuy\u1ec3n sang trang kh\u00e1c \u0111\u1ec3 l\u00e0m vi\u1ec7c. Khi ch\u01b0\u01a1ng tr\u00ecnh th\u1ef1c hi\u1ec7n xong s\u1ebd g\u1eedi th\u00f4ng b\u00e1o cho b\u1ea1n."})};