SemesterController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php
  2. /**
  3. * 学期管理控制器类
  4. * @author jiangfei
  5. * @date 2015-08-17 18:22:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class SemesterController extends Controller{
  9. public $inciseTables=array(
  10. 'student_paper_topic_rs',
  11. 'student_paper_relation',
  12. 'student_improve_score_plan_topics',
  13. 'student_wrong_plan_topics',
  14. 'student_upload_result'
  15. );
  16. public function init(){
  17. parent::init();
  18. //判断教员权限
  19. /* if (Yii::app()->session['coachInfo']['leader'] !=1 ) {
  20. Yii::app()->jump->error('您无权限操作!');
  21. } */
  22. }
  23. // 学期列表
  24. public function actionIndex(){
  25. $word = Req::get("word");
  26. $currSemester = $this->schoolManager->getCurrSemester();
  27. $condition = array();
  28. if($word){
  29. if(is_numeric($word)){
  30. $condition = array("school_year = '{$word}'");
  31. }
  32. else{
  33. $condition = array("semester_name like '%{$word}%'");
  34. }
  35. }
  36. //$semesList = Semester::model()->getSemesList($condition);
  37. $semestersList = $this->schoolManager->getSemestersList($condition);
  38. // 是否有正在使用学期
  39. $flag = 1;
  40. if (Yii::app()->session['coachInfo']['leader'] !=1 ) {
  41. foreach ($semestersList["rs"] as $list) {
  42. if ($list['status'] == 1) {
  43. $flag = 2;
  44. break;
  45. }
  46. }
  47. } else {
  48. $flag = 2;
  49. }
  50. $data = array();
  51. $data['list'] = Arr::toObj($semestersList["rs"]);
  52. $data['pages'] = $semestersList["pager"];
  53. $data['page_total'] = $semestersList["pager"]->rowsCount;
  54. $data["word"] = $word;
  55. $data["currSemester"] = $currSemester;
  56. $data["flag"] = $flag;
  57. unset($semesList);
  58. $this->render('index',$data);
  59. }
  60. // 添加学期
  61. public function actionAdd(){
  62. if (Yii::app()->request->getIsPostRequest()){
  63. //$name = safe_replace($_POST['name']);
  64. //$period = safe_replace($_POST['period']);
  65. $start_time = safe_replace($_POST['start_time']);
  66. $end_time = safe_replace($_POST['end_time']);
  67. $status = safe_replace($_POST['status']);
  68. $school_year= safe_replace($_POST['school_year']);
  69. $semesterCode = Req::post("semester");
  70. $name = $this->schoolManager->getSemesterNameByCode($semesterCode);
  71. if (empty($name) || empty($school_year) || empty($start_time) || empty($end_time)){
  72. Yii::app()->jump->error('请确认学期信息是否填写完整!');
  73. }
  74. if(!is_numeric($school_year) || strlen($school_year) > 4)
  75. Yii::app()->jump->error('学年不能超过4位数字!');
  76. if (strtotime($start_time) >= strtotime($end_time)) {
  77. Yii::app()->jump->error('学期开始时间不能大于或等于结束时间!');
  78. }
  79. $isExistence=$this->schoolManager->getOneSemester();
  80. $isNowSemester=1;
  81. if($isExistence){
  82. $isNowSemester=0; //设置为非当前学期
  83. $lastSemester = $this->schoolManager->getTheYearLastSemester($school_year);
  84. if($lastSemester && strtotime($start_time) <= $lastSemester["start_time"])
  85. Yii::app()->jump->error('学期开始时间不能小于之前的学期!');
  86. if (Semester::model()->count('semester_name="'.$name.'"')){
  87. Yii::app()->jump->error('该学期名称已存在!');
  88. }
  89. //创建表
  90. $inciseTables = $this->inciseTables;
  91. foreach ($inciseTables as $inciseTable) {
  92. $newTableName = $inciseTable . '_' . $semesterCode; //新学期表名
  93. $existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow(); //查询新学期表是否存在
  94. if (!$existTable) {
  95. $this->sConn->createCommand('CREATE TABLE '.$newTableName.' LIKE '.$inciseTable)->execute();
  96. }
  97. }
  98. // 若新添加学期设置为可用则更新其他学期不可用
  99. if ($status == 1 && Semester::model()->count('status=1')) {
  100. Semester::model()->updateAll(array('status'=>'0'));
  101. Yii::app()->session['session_semester_name'] = $name;
  102. $isNowSemester=1;
  103. }
  104. }
  105. $semesterModel = new Semester();
  106. //$semesterModel->semester_id = getUUID();
  107. $semesterModel->semester_id =getUniqueId($this->schoolId);
  108. $semesterModel->semester_name= $name;
  109. $semesterModel->school_year = $school_year;
  110. $semesterModel->refer_code = $semesterCode;
  111. //$semesterModel->period = $period;
  112. $semesterModel->start_time = strtotime($start_time);
  113. $semesterModel->end_time = strtotime($end_time);
  114. $semesterModel->create_time = time();
  115. $semesterModel->status = $isNowSemester;
  116. if ($semesterModel->save()) {
  117. if ($status == 1) {
  118. Yii::app()->session['session_semester_id'] = $semesterModel->attributes['semester_id'];
  119. }
  120. $this->redirect(array('semester/index'));
  121. } else {
  122. Yii::app()->jump->error('学期创建失败!');
  123. }
  124. }
  125. $data = array();
  126. $this->render('add',$data);
  127. }
  128. // 学期编辑
  129. public function actionEdit(){
  130. $smtid = safe_replace(Yii::app()->request->getQuery('smtid'));
  131. if (empty($smtid)) {
  132. Yii::app()->jump->error('您访问的页面不存在!');
  133. }
  134. // 当前学期信息
  135. $info = Semester::model()->find('semester_id=:smtid',array(':smtid'=>$smtid));
  136. if (empty($info)) {
  137. Yii::app()->jump->error('无法编辑该学期信息!');
  138. }
  139. if (Yii::app()->request->getIsPostRequest()){
  140. $school_year = safe_replace($_POST['school_year']);
  141. $start_time = safe_replace($_POST['start_time']);
  142. $end_time = safe_replace($_POST['end_time']);
  143. $status = safe_replace($_POST['status']);
  144. $semesterCode = safe_replace($_POST['semester']);
  145. $semester_name = $this->schoolManager->getSemesterNameByCode($semesterCode);
  146. if ( empty($start_time) || empty($end_time) || empty($semester_name)){
  147. Yii::app()->jump->error('请确认学期信息是否填写完整!');
  148. }
  149. if (strtotime($start_time) >= strtotime($end_time)) {
  150. Yii::app()->jump->error('学期开始时间不能大于结束时间!');
  151. }
  152. $model = new Model();
  153. if($model->isCurrentSemester($smtid) && $status == 0){
  154. Yii::app()->jump->error('不能将当前学期设为未使用!');
  155. }
  156. $checkRepeat=Semester::model()->count('semester_id != :seid and refer_code=:code',array(':seid'=>$info->semester_id,':code'=>$semesterCode));
  157. if($checkRepeat){
  158. Yii::app()->jump->error('已有相同学期!');
  159. }
  160. /* $semester_one = $this->schoolManager->getThisYearSemesterName($semester_name);
  161. if(!$semester_one)
  162. {
  163. Yii::app()->jump->error('填写的学期格式不正确!');
  164. }*/
  165. // 若更新学期为可用则更新其他学期不可用
  166. if ($status == 1 && Semester::model()->count('semester_id != :seid and status=1',array(':seid'=>$info->semester_id))) {
  167. if($return=$this->ExchangeTable(Yii::app()->session['session_semester_id'],$smtid)) {
  168. Semester::model()->updateAll(array('status'=>'0'));
  169. $expireTime = isset(Yii::app()->params["redisCloud"]["expire_time"]) ? Yii::app()->params["redisCloud"]["expire_time"] : 86400;
  170. $server = Yii::app()->params["redisCloud"]["servers"];
  171. $redis = new Redis();
  172. $redis->connect($server["host"], $server["port"]);
  173. if(isset($server['password'])){
  174. $redis->auth($server['password']);
  175. }
  176. $redis->select($server['database']);
  177. $redis->set('zsy_student:school_semester_id:'.$this->schoolId,$smtid);
  178. $redis->expire('zsy_student:school_semester_id:'.$this->schoolId,$expireTime);
  179. }else{
  180. Yii::app()->jump->error('学期修改失败!数据表重复,请联系技术支持处理');
  181. }
  182. }
  183. $info->semester_name = $semester_name;
  184. $info->school_year = $school_year;
  185. $info->refer_code = $semesterCode;
  186. $info->start_time = strtotime($start_time);
  187. $info->end_time = strtotime($end_time);
  188. $info->status = $status;
  189. if ($info->save()) {
  190. if(Yii::app()->params['handle_log_on_off'])
  191. {
  192. writeFileLog(jsonEncode(array(
  193. "exam_group_id" => 0,
  194. "operate_project" => 'zsyas2',
  195. "school_id" => $this->schoolId,
  196. "title" => '学期修改',
  197. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  198. "operate_method" => $this->action,
  199. "operate_url" => $this->getRoute(),
  200. "operate_sql" =>'',
  201. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  202. "date"=>date('Y-m-d H:i:s')
  203. )));
  204. }
  205. if ($status == 1) {
  206. Yii::app()->session['session_semester_id'] = $smtid;
  207. }
  208. $this->redirect(array('semester/index'));
  209. } else {
  210. Yii::app()->jump->error('学期修改失败!');
  211. }
  212. }
  213. $c_semester_data = $this->schoolManager->getThisYearSemesterDictionary($info->school_year);
  214. $data = array();
  215. $data['info'] = $info;
  216. $data['c_info'] = $c_semester_data;
  217. if($info->status==1){
  218. $this->render('edit',$data);
  219. }else{
  220. $this->render('edit2',$data);
  221. }
  222. }
  223. public function actionDelSemesterAct(){
  224. $semesterId = Req::post("semesterId");
  225. $rs = $this->schoolManager->delSemester($semesterId);
  226. echo json_encode($rs);exit;
  227. }
  228. public function actionChange(){
  229. $word = Req::get("word");
  230. $currSemester = $this->schoolManager->getCurrSemester();
  231. $condition = "";
  232. if($word){
  233. if(is_numeric($word)){
  234. $condition = "school_year = '{$word}'";
  235. }
  236. else{
  237. $condition = "semester_name like '%{$word}%'";
  238. }
  239. }
  240. $_class_data = ClassModel::model()->findAll('semester_id=:seid and is_hide=0 and grade<>3 and grade<>9',array(':seid'=>$this->semesterId));
  241. $classes=array();
  242. foreach ($_class_data as $datum){
  243. $classes[$datum['class_type']][]=array(
  244. 'class_id'=>$datum['class_id'],
  245. 'class_name'=>$datum['class_name'],
  246. 'grade'=>$datum['grade'],
  247. );
  248. }
  249. $semesList = Semester::model()->getSemesList($condition);
  250. $data = array();
  251. $data['list'] = $semesList['result'];
  252. $data['pages'] = $semesList['page'];
  253. $data['page_total'] = $semesList['page_total'];
  254. $data["word"] = $word;
  255. $data["currSemester"] = $currSemester;
  256. $data['classes']=$classes;
  257. unset($semesList);
  258. $this->render('change',$data);
  259. }
  260. public function actionChangeSemesterAct(){
  261. $semesterId = Req::post("semesterId"); //学期id
  262. $RetainClass=Req::post('RetainClass'); //保留班级
  263. $Graduation=Req::post('Graduation'); //毕业班
  264. $classUp=Req::post('classUp'); //升班
  265. $classNameArr=Req::post('classNameArr'); //升班后班级名称
  266. $gradeDirector=Req::post('gradeDirector'); //年级主任升班与否 1同步升班,2不同步
  267. $classNewNameArr=array();
  268. if($classUp==1){
  269. foreach ($classNameArr as $item){
  270. $arrTemp=explode('///',$item);
  271. $classNewNameArr[(string)$arrTemp[0]]=$arrTemp[1];
  272. }
  273. }
  274. $oldSemesterId=Yii::app()->session['session_semester_id']; //原学期
  275. $semester = $this->schoolManager->getSemester($semesterId);
  276. //切割表
  277. // if($return=$this->ExchangeTable($oldSemesterId,$semesterId)){
  278. $rs = $this->schoolManager->changeSemesterByStudentAndClass($semesterId,$oldSemesterId,$RetainClass,$Graduation,$classNewNameArr,$gradeDirector);
  279. if($rs["code"] == 0){
  280. Yii::app()->session['session_semester_id'] = $semester["semester_id"];
  281. Yii::app()->session['session_semester_name'] = $semester["semester_name"];
  282. if ($semester["status"] == 1){
  283. unset(Yii::app()->session['session_semester_state']);
  284. }
  285. $expireTime = isset(Yii::app()->params["redisCloud"]["expire_time"]) ? Yii::app()->params["redisCloud"]["expire_time"] : 86400;
  286. $server = Yii::app()->params["redisCloud"]["servers"];
  287. $redis = new Redis();
  288. $redis->connect($server["host"], $server["port"]);
  289. if(isset($server['password'])){
  290. $redis->auth($server['password']);
  291. }
  292. $redis->select($server['database']);
  293. $redis->set('zsy_student:school_semester_id:'.$this->schoolId,$semesterId);
  294. $redis->expire('zsy_student:school_semester_id:'.$this->schoolId,$expireTime);
  295. }
  296. // }else{
  297. // $rs["code"] =3001;
  298. // echo json_encode($rs);exit;
  299. // }
  300. if(Yii::app()->params['handle_log_on_off'])
  301. {
  302. writeFileLog(jsonEncode(array(
  303. "exam_group_id" => 0,
  304. "operate_project" => 'zsyas2',
  305. "school_id" => $this->schoolId,
  306. "title" => '切换学期',
  307. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  308. "operate_method" => $this->action,
  309. "operate_url" => $this->getRoute(),
  310. "operate_sql" =>'',
  311. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  312. "date"=>date('Y-m-d H:i:s')
  313. )));
  314. }
  315. echo json_encode($rs);exit;
  316. }
  317. public function actionGetThisYearSemesterDictionary(){
  318. $year = Req::get("year");
  319. $rs = $this->schoolManager->getThisYearSemesterDictionary($year);
  320. echo json_encode($rs);exit;
  321. }
  322. public function actionGetThisYearSemesters(){
  323. $year = Req::get("year");
  324. $semesters = $this->schoolManager->getSemesters(array("school_year = '{$year}'"), array("semester_id desc"), 0, 20);
  325. echo json_encode($semesters);exit;
  326. }
  327. //切换学期交换表名
  328. /*
  329. * $oldSemester 旧学期(当前学期)
  330. * $newSemester 新学期(切换到的学期)
  331. * */
  332. private function ExchangeTable($oldSemester,$newSemester){
  333. $inciseTables = $this->inciseTables;
  334. $oldSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$oldSemester."'")->queryRow();
  335. $newSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$newSemester."'")->queryRow();
  336. $trans = $this->sConn->beginTransaction();
  337. try{
  338. foreach ($inciseTables as $inciseTable) {
  339. $newTableName = $inciseTable . '_' . $newSemester['refer_code']; //新学期表名
  340. $oldTableName= $inciseTable . '_' . $oldSemester['refer_code']; //旧学期(当前学期)需要改的名字
  341. $existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow(); //查询新学期表是否存在
  342. if($existTable){
  343. //修改当前的表名
  344. $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
  345. if($existOldTable){
  346. //throw new Exception('3001');
  347. //重复表进行重命名
  348. $bakTableName=$oldTableName.'_'.date('YmdHis');
  349. $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
  350. }
  351. $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
  352. //修改新学期表名
  353. $this->sConn->createCommand("ALTER TABLE ".$newTableName." RENAME TO ".$inciseTable)->execute();
  354. }else{
  355. //修改当前的表名
  356. $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
  357. if($existOldTable){
  358. //throw new Exception('3001');
  359. //重复表进行重命名
  360. $bakTableName=$oldTableName.'_'.date('YmdHis');
  361. $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
  362. }
  363. $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
  364. //创建新学期表
  365. $this->sConn->createCommand('CREATE TABLE '.$inciseTable.' LIKE '.$oldTableName)->execute();
  366. }
  367. }
  368. $trans->commit();
  369. return true;
  370. }catch (Exception $e){
  371. $trans->rollback();
  372. return false;
  373. }
  374. return false;
  375. }
  376. //分表操作
  377. private function InciseTable($semesterId){
  378. $inciseTables = $this->inciseTables;
  379. $semester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$semesterId."'")->queryRow();
  380. if ($semester) {
  381. $isExistTable=false;
  382. foreach ($inciseTables as $inciseTable) {
  383. $isExistTable=false;
  384. $newTableName = $inciseTable . '_' . $semester['refer_code'];
  385. $existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow();
  386. if ($existTable){
  387. $checkData=$this->sConn->createCommand("select * from ".$newTableName)->queryRow();
  388. if($checkData){
  389. return true;
  390. }else{
  391. $isExistTable=true;
  392. }
  393. }
  394. if($isExistTable){
  395. switch ($inciseTable){
  396. case 'student_paper_topic_rs':
  397. $rrs=$this->disposeStudentPaperTopicRs($semester['semester_id'], $newTableName);
  398. if(!$rrs) return false;
  399. break;
  400. case 'student_paper_relation':
  401. $rrs=$this->disposeStudentPaperRelation($semester['semester_id'], $newTableName);
  402. if(!$rrs) return false;
  403. break;
  404. case 'student_improve_score_plan_topics':
  405. $rrs=$this->disposeStudentImproveScorePlanTopics($semester['semester_id'], $newTableName);
  406. if(!$rrs) return false;
  407. break;
  408. case 'student_wrong_plan_topics':
  409. $rrs=$this->disposeStudentWrongPlanTopics($semester['semester_id'], $newTableName);
  410. if(!$rrs) return false;
  411. break;
  412. }
  413. }else{
  414. // 创建分表
  415. if ($this->sConn->createCommand('CREATE TABLE '.$newTableName.' LIKE '.$inciseTable)->execute()) {
  416. switch ($inciseTable){
  417. case 'student_paper_topic_rs':
  418. $rrs=$this->disposeStudentPaperTopicRs($semester['semester_id'], $newTableName);
  419. if(!$rrs) return false;
  420. break;
  421. case 'student_paper_relation':
  422. $rrs=$this->disposeStudentPaperRelation($semester['semester_id'], $newTableName);
  423. if(!$rrs) return false;
  424. break;
  425. case 'student_improve_score_plan_topics':
  426. $rrs=$this->disposeStudentImproveScorePlanTopics($semester['semester_id'], $newTableName);
  427. if(!$rrs) return false;
  428. break;
  429. case 'student_wrong_plan_topics':
  430. $rrs=$this->disposeStudentWrongPlanTopics($semester['semester_id'], $newTableName);
  431. if(!$rrs) return false;
  432. break;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. return true;
  439. }
  440. //分割rs表
  441. private function disposeStudentPaperTopicRs($semesterId, $newTableName)
  442. {
  443. if (empty($semesterId) || empty($newTableName) ) return true;
  444. // 学期总数
  445. $countSql = 'SELECT count(sptr.id) as num FROM student_paper_topic_rs sptr JOIN paper p ON sptr.paper_id = p.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.semester_id = "'.$semesterId.'"';
  446. $countInfo = $this->sConn->createCommand($countSql)->queryRow();
  447. $totalNum = $countInfo['num'];
  448. if (!$totalNum) {
  449. return true;
  450. }
  451. $num = 1;
  452. $pageSize = 10000;
  453. $pageNum = ceil($totalNum / $pageSize);
  454. $offsetSql = 'SELECT sptr.id FROM student_paper_topic_rs sptr JOIN paper p ON sptr.paper_id = p.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.semester_id = "'.$semesterId.'" order by sptr.id asc limit 1';
  455. $res = $this->sConn->createCommand($offsetSql)->queryRow();
  456. if (!isset($res['id'])) return true; // 当前学期没有数据
  457. $offset = $res['id'];
  458. // 获取上一条
  459. $preSql = 'SELECT id from student_paper_topic_rs where id < '.$offset.' order by id DESC limit 1';
  460. $preRes = $this->sConn->createCommand($preSql)->queryRow();
  461. $offset = isset($preRes['id']) ? $preRes['id'] : $offset;
  462. while ($num <= $pageNum) {
  463. // 获取当前起点后的还需处理的数据总数
  464. if (($num * $pageSize) > $totalNum) {
  465. $tmepCountSql = 'SELECT count(sptr.id) as num FROM student_paper_topic_rs sptr JOIN paper p ON sptr.paper_id = p.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.semester_id = "'.$semesterId.'" and sptr.id > "'.$offset.'"';
  466. $tempCountRes = $this->sConn->createCommand($tmepCountSql)->queryRow();
  467. if (empty($tempCountRes['num'])) break;
  468. $pageSize = $tempCountRes['num'];
  469. }
  470. $lastSql = 'SELECT sptr.id FROM student_paper_topic_rs sptr JOIN paper p ON sptr.paper_id = p.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.semester_id = "'.$semesterId.'" and sptr.id > "'.$offset.'" order by sptr.id asc limit '.($pageSize-1).', 1';
  471. $offsetResult = $this->sConn->createCommand($lastSql)->queryRow();
  472. if (isset($offsetResult['id'])) {
  473. $limitId = $offsetResult['id'];
  474. $sql = 'INSERT INTO '.$newTableName.' SELECT sptr.* FROM student_paper_topic_rs sptr JOIN paper p ON sptr.paper_id = p.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.semester_id = "'.$semesterId.'" and sptr.id > "'.$offset.'" AND sptr.id <= "'.$limitId.'"' ;
  475. if (!$this->sConn->createCommand($sql)->execute()) {
  476. return false;
  477. }
  478. $offset = $limitId;
  479. }
  480. ++$num;
  481. }
  482. unset($res, $preRes, $countInfo);
  483. return true;
  484. }
  485. //切割relation表
  486. private function disposeStudentPaperRelation($semesterId, $newTableName)
  487. {
  488. if (empty($semesterId) || empty($newTableName) ) return true;
  489. $paperIds = array();
  490. $paperSql = "SELECT paper_id from student_paper_relation WHERE semester_id = '{$semesterId}' GROUP BY paper_id";
  491. $paperInfo = $this->sConn->createCommand($paperSql)->queryAll();
  492. if ($paperInfo) {
  493. foreach ($paperInfo as $key=>$info) {
  494. $paperIds[] = $info['paper_id'];
  495. }
  496. $groupPaper = array_chunk($paperIds, 50);
  497. foreach ($groupPaper as $key=>$item) {
  498. $sql = "INSERT INTO {$newTableName} SELECT * FROM `student_paper_relation` WHERE semester_id = '{$semesterId}' and paper_id in (".implode(',', $item).")";
  499. $this->sConn->createCommand($sql)->execute();
  500. }
  501. }
  502. unset($paperInfo,$sql,$paperIds,$groupPaper);
  503. return true;
  504. }
  505. private function disposeStudentImproveScorePlanTopics($semesterId, $newTableName)
  506. {
  507. if (empty($semesterId) || empty($newTableName)) return true;
  508. $examSql = "SELECT exam_id FROM `exam` WHERE `semester_id` = '{$semesterId}'";
  509. $examInfo = $this->sConn->createCommand($examSql)->queryAll();
  510. if (empty($examInfo)) {
  511. return true;
  512. }
  513. $examIds = array();
  514. foreach ($examInfo as $exam) {
  515. $examIds[] = $exam['exam_id'];
  516. }
  517. $groupExam = array_chunk($examIds, 30);
  518. foreach ($groupExam as $key => $loop) {
  519. $sql = 'INSERT INTO '.$newTableName.' SELECT * FROM student_improve_score_plan_topics WHERE `plan_id` in ('.implode(',',$loop).')';
  520. $this->sConn->createCommand($sql)->execute();
  521. }
  522. unset($examInfo,$examIds,$sql);
  523. return true;
  524. }
  525. private function disposeStudentWrongPlanTopics($semesterId, $newTableName)
  526. {
  527. if (empty($semesterId) || empty($newTableName)) return true;
  528. $examSql = "SELECT exam_id FROM `exam` WHERE `semester_id` = '{$semesterId}'";
  529. $examInfo = $this->sConn->createCommand($examSql)->queryAll();
  530. if (empty($examInfo)) {
  531. return true;
  532. }
  533. $examIds = array();
  534. foreach ($examInfo as $exam) {
  535. $examIds[] = $exam['exam_id'];
  536. }
  537. $groupExam = array_chunk($examIds, 30);
  538. foreach ($groupExam as $key => $loop) {
  539. $sql = 'INSERT INTO '.$newTableName.' SELECT * FROM student_wrong_plan_topics WHERE `wrong_plan_id` in ('.implode(',',$loop).')';
  540. $this->sConn->createCommand($sql)->execute();
  541. }
  542. unset($examInfo,$examIds,$sql);
  543. return true;
  544. }
  545. }