北森后端一面
Posted fei1013
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了北森后端一面相关的知识,希望对你有一定的参考价值。
1、非技术问题
自我介绍
对于转语言接受吗,你会怎么做
有遇到很重大的困难,怎么面对的
2、技术问题
数组、链表适用场景,时间复杂度
怎么优化链表的访问效率(多维链表)
要解释字典,我说c++没有字典,就让我说哈希表
前台线程、后台线程区别
自己创建线程和从线程池中取出的区别(为了提示我上一个问题得前台线程、后台线程)
保证多线程同步的机制(答了锁、条件变量、信号量,问还有吗,后面解释的也模模糊糊,没听懂)
索引种类(答得稀碎,给我上课了)
select、poll、epoll
追问在可连接的并发数的区别(提示后说了会受到系统数量限制:1024)
用了哪些设计模式:单例模式
详细说双重检测
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;
以上是关于北森后端一面的主要内容,如果未能解决你的问题,请参考以下文章