flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.23 kB
JavaScript
'use strict';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$$={})=>"view"==($options$$.action||"").toLowerCase()?!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$$);0===$count$$?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.mapSeries($items$$,async $item$$=>{$item$$.file_mau_in&&0<$item$$.file_mau_in.indexOf("/file/download")&&($_f_file_id_params$$=$item$$.file_mau_in.split("/").pop(),
$_f_file_id_params$$=await file.findOne({_id:$_f_file_id_params$$}))&&($item$$.file=$_f_file_id_params$$.file);if(!($item$$.parameters&&0<$item$$.parameters.length)){var $_f_file_id_params$$=await parameter.find({id_rpt:$item$$._id.toString()});$_f_file_id_params$$.forEach(($r$$,$i$$)=>{$r$$.line=$i$$});$item$$.parameters=$_f_file_id_params$$}},()=>{$next$$(null,$items$$)})}})).route()};