php 获取北森测评报告地址

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 获取北森测评报告地址相关的知识,希望对你有一定的参考价值。


<?php
/*
 * 获取北森测评报告地址
 */
$startM = memory_get_usage(); //记录开始内存量
$startT = microtime(true); //记录开始时间
// +---------------------------------------------------------------------------+
// | An absolute filesystem path to our webapp/config.php script.              |
// +---------------------------------------------------------------------------+
require_once(dirname(__FILE__) . '/../webapp/config.php');
// +---------------------------------------------------------------------------+
// | An absolute filesystem path to the agavi/agavi.php script.                |
// +---------------------------------------------------------------------------+
require_once(AG_APP_DIR . '/agavi.php');
require_once(AG_DOC_ROOT . '/lib/DatabaseUtils.class.php');
  
//只显示error级别错误
error_reporting(E_ERROR | E_PARSE);
  
//判断执行页数,设定默认页数
if (isset($argv[1])&&$argv[1]>0){
    $page = $argv[1];
} else {
    $page = 1;
}
  
//设置脚本运行锁
if ($page==1&&file_exists('beiSenReport.lock')){
    echo '已有相同脚本在运行';
    exit;
} else if ($page==1&&!file_exists('beiSenReport.lock')){
    $status = file_put_contents('beiSenReport.lock','');
    if ($status === false) {
        echo "没有写入权限\n";
        exit;
    }
    echo "开始运行\n";
}
  
//设置每页数量及起始条数
$limit = 10;
$offset = ($page-1)*$limit;
Context::getInstance()->initialize();
$conn = Propel::getConnection();
$nowTime = strtotime(date('Y-m-d'));
  
//开始查询总页数
$c = new Criteria();
$c->addSelectColumn(AssessmentUserPeer::INFO_ID);
$c->addSelectColumn(AssessmentUserPeer::CODE);
$c->addSelectColumn(AssessmentUserPeer::ACTIVITY_ID);
$c->addSelectColumn(AssessmentUserPeer::EMAIL);
$c->add(AssessmentUserPeer::IS_TEST, 1, Criteria::EQUAL);
$total = AssessmentUserPeer::doCount($c);
$totalPage = ceil($total/$limit);
  
if ($page==1) {
    echo date("Y-m-d H:i:s") , ":总条数:" , $total , ";总页数:" , $totalPage , "\n";
}
  
//记录脚本页数
echo date("Y-m-d H:i:s") , ":开始执行第" , $page , "页,";
//开始查询记录
$c->setOffset($offset);
$c->setLimit($limit);
$RS = AssessmentUserPeer::doSelectRS($c);
$RS->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$request = array();
$result = array();
$info_ids =array();
while ($RS->next()) {
    $row = $RS->getRow();
    if (!empty($row['ACTIVITY_ID'])&&!empty($row['EMAIL'])&&!empty($row['CODE'])) {
        $request[$row['ACTIVITY_ID']][]=array('email'=>$row['EMAIL'],'sn'=>$row['CODE']);
        $info_ids[$row['CODE']] = $row['INFO_ID'];
    }  
}
  
//调用北森接口文件
$beiSenApi = new BeisenApi();
  
//请求北森接口,并更新数据库
foreach ($request as $activity_id => $email_sn_list) {
    $results = $beiSenApi->getActivityResultBySnEmails($activity_id, $email_sn_list);
    foreach ($results as $activity) {
        $save_activity = $activity['activity_id'];
        $code='';
        foreach ($activity['testee_list'] as $key => $tester) {
            $summaryreport = array();
            foreach ($tester['sn_list'] as $key => $testReport) {
                $code = $testReport['sn'];
                $summaryreport = $testReport['summaryreport'];
                $reports=array();
                foreach ($testReport['test_report_list'] as $key => $reportList) {
                    $reports[$reportList['test']['id']]=array('name'=>$reportList['test']['name'], 'list'=>$reportList['report_list']);
                }
  
                if (!empty($info_ids[$code])&&!empty($reports)) {
                    $report_json = json_encode(array('summaryreport'=>$summaryreport, 'reports'=>$reports), JSON_UNESCAPED_UNICODE);
                    $sql = "UPDATE t_assessment_user SET is_test=2, report_url='{$report_json}' WHERE info_id={$info_ids[$code]};";
                    $conn->executeQuery($sql);
                }
            }
        }
    }
}
  
  
$endM = memory_get_usage();//结束内存
$endT = microtime(true); //记录结束时间
  
//释放变量
unset($request);
unset($results);
unset($beiSenApi);
unset($report_json);
unset($summaryreport);
unset($activity);
unset($c);
unset($RS);
  
  
$usedM = sprintf("消耗内存%.2fMB", ($endM-$startM)/1024/1024);
$usedT = sprintf("消耗时间%.2f秒", $endT-$startT);
  
//记录内存时间消耗
echo date("Y-m-d H:i:s") , ":第". $page , "页执行结束," , $usedM  , ',' , $usedT , "\n";
  
//准备执行下一页
$nextPage = $page+1;
if ($nextPage<=$totalPage) {
    system('php get_beisen_report_links.php ' . $nextPage . " >> beiSenReportRun.Log &");
}
  
//结束运行,解除文件锁
if ($page==$totalPage) {
    echo "运行结束\n";
    unlink('beiSenReport.lock');
    exit;
}
exit;

以上是关于php 获取北森测评报告地址的主要内容,如果未能解决你的问题,请参考以下文章

借力一体化战略,北森云能否在HR SaaS领域更胜一筹?

北森E轮融资过亿美金,HR SaaS赛道单笔融资再创新高 |经纬低调新闻

招聘(大连)北森云计算 .NET 专场招聘

北森iTalentX 3.0:聚焦场景一体,开启HR全面数字化时代

php登录注册源码+效果图+效果视频+实训报告

SaaS面临盈利挑战 平台之争北森胜算几何?