flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.25 kB
JavaScript
const model=global.getModel("rpt"),file=global.getModel("file"),parameter=global.getModel("parameter"),controller=require("../../controllers/controller"),fs=require("fs"),path=require("path"),async=require("async");
module.exports=function($router$$){(new controller($router$$,model,"rpt",{sort:{ma_cn:1},notNeedRight:($user$$,$options$$={})=>($options$$.action||"").toLowerCase()=="view"?!0:!1,onFinding:($user$$,$condition$$,$next$$,$_condition_dir_root_templates_options$$={})=>{if($condition$$.ma_cn&&$_condition_dir_root_templates_options$$.req&&$_condition_dir_root_templates_options$$.req.query&&!$_condition_dir_root_templates_options$$.req.query.count){$_condition_dir_root_templates_options$$=configs.paths.templates||
path.dirname(__dirname);let $p$$="/templates/excels/"+$condition$$.ma_cn.toLowerCase()+".xlsx",$templatePath$$=path.dirname($_condition_dir_root_templates_options$$)+$p$$;fs.existsSync($templatePath$$)||($p$$="/templates/excels/reports/"+$condition$$.ma_cn.toLowerCase()+".xlsx",$templatePath$$=path.dirname($_condition_dir_root_templates_options$$)+$p$$);fs.existsSync($templatePath$$)?($_condition_dir_root_templates_options$$={id_app:$user$$.current_id_app,ma_cn:$condition$$.ma_cn.toUpperCase()},model.countDocuments($_condition_dir_root_templates_options$$,
function($error$$,$count$$){if($error$$)return $next$$($error$$);$count$$===0?model.create({id_app:$user$$.current_id_app,ma_cn:$condition$$.ma_cn,ten_mau_in:"M\u1eabu chu\u1ea9n",file_mau_in:$p$$},$e$$=>{$next$$($e$$,$condition$$)}):$next$$(null,$condition$$)})):$next$$(null,$condition$$)}else $next$$(null,$condition$$)},onView:($user$$,$items$$,$next$$)=>{async.mapLimit($items$$,20,async $item$$=>{if($item$$.file_mau_in&&$item$$.file_mau_in.indexOf("/file/download")>0){var $_f_file_id_params$$=
$item$$.file_mau_in.split("/").pop();if($_f_file_id_params$$=await file.findOne({_id:$_f_file_id_params$$}))$item$$.file=$_f_file_id_params$$.file}$item$$.parameters&&$item$$.parameters.length>0||($_f_file_id_params$$=await parameter.find({id_app:$user$$.current_id_app,id_rpt:$item$$._id.toString()}).lean(),$_f_file_id_params$$.forEach(($r$$,$i$$)=>{$r$$.line=$i$$}),$item$$.parameters=$_f_file_id_params$$)},()=>{$next$$(null,$items$$)})}})).route()};