123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php
- /**
- * Created by 上海互教教育科技有限公司.
- * User: 刘红伟
- * QQ : 454303753
- * Date: 2018/5/8 0008
- * Time: 下午 15:04
- */
- class BacklogController extends Controller{
- public function actionIndex(){
- $data = array();
- $_rs = array();
- $group_backlog = array();
- $group_exam = array();
- $time = time()-24*3600*14;
- $condition[] = "e.is_backlog = 0 ";
- $condition[] = "e.upload_status > 0 ";
- // $condition[] = "e.subject_id in (3,6) ";
- $condition[] = "e.complete_time > ".$time;
- $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3) ";
- $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
- // debug($rs);
- if($rs){
- foreach ($rs as $v){
- $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
- $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
- }
- foreach ($rs as $k=>$v){
- if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
- $num = array_sum($group_backlog[$v['exam_group_id']]);
- $count = count($group_exam[$v['exam_group_id']]);
- if($num == $count){
- unset($rs[$k]);
- }else{
- $_rs[$v['exam_group_id']]['result'][] = $v;
- $_rs[$v['exam_group_id']]['exam_name'] = $v['exam_name'];
- $_rs[$v['exam_group_id']]['exam_group_id'] = $v['exam_group_id'];
- }
- }
- }
- }
- $data['rs'] = $_rs;
- $this->render("index",$data);
- }
- public function actionAjaxSend(){
- $exam_id = Req::post("exam_id");
- $is_uploaded_count = Req::post("is_uploaded_count");
- $students_count = Req::post("students_count");
- $class_id = Req::post("class_id");
- $_num = 0;
- if($exam_id>0){
- $rs = Exam::model()->updateAll(array('is_backlog'=>1,'update_time'=>time()),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($rs){
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if(Yii::app()->params['handle_log_on_off'])
- {
- if($exam_data){
- writeFileLog(jsonEncode(array(
- "exam_group_id" => $exam_data->exam_group_id,
- "school_id" => $this->schoolId,
- "coach_id" => $this->coachId,
- "exam_id" => $exam_id,
- "class_id" => $exam_data->class_id,
- "upload_num" => $is_uploaded_count,
- "total_num" => $students_count,
- "title" => '发送待办',
- "type" => 0,
- "date"=>date('Y-m-d H:i:s'),
- )));
- }
- }
- $this->schoolManager->saveExamProcess($exam_data->exam_group_id,7,time(),$exam_id,$exam_data->class_id);
- $time = time()-24*3600*14;
- $condition[] = "e.is_backlog = 0 ";
- $condition[] = "e.upload_status > 0 ";
- $condition[] = "e.complete_time > ".$time;
- $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
- $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
- if($rs){
- foreach ($rs as $v){
- $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
- $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
- }
- foreach ($rs as $k=>$v){
- if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
- $num = array_sum($group_backlog[$v['exam_group_id']]);
- $count = count($group_exam[$v['exam_group_id']]);
- if($num == $count){
- unset($rs[$k]);
- }
- }
- }
- foreach ($rs as $k=>$v){
- if($v['is_uploaded_count'] == 0){
- unset($rs[$k]);
- }
- }
- }else{
- $rs = array();
- }
- //发送消息队列
- if (isset($exam_data->exam_group_id)) {
- $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_data->exam_group_id,'examIds'=>array($exam_id));
- $this->sendStomp($stomp_data);
- //发送消息
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>3,
- 'subject_id'=>$exam_data->subject_id,
- 'send_type'=>'exam',
- 'exam_group_id'=>$exam_data->exam_group_id,
- 'exam_ids'=>array($exam_id)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- }
- unset($exam_data);
- echo json_encode(array('status'=>1,'count'=>count($rs)));exit;
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionAjaxAllSend(){
- $exam_group_id = Req::post("exam_group_id");
- if($exam_group_id>0){
- $subjectId=0;
- $condition[] = "e.is_backlog = 0 ";
- $condition[] = "e.upload_status > 0 ";
- $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
- $condition[] = "e.exam_group_id = ".$exam_group_id;
- $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
- $exam_ids = array();
- $class_ids = array();
- $name = '';
- $batchExamProcess=array();
- if($rs){
- foreach ($rs as $v){
- $name = $v['exam_name'];
- $subjectId=$v['subject_id'];
- if($v['is_uploaded_count'] == $v['students_count']){
- $exam_ids[$v['exam_id']] = $v['exam_id'];
- $class_ids[$v['class_id']] = $v['class_id'];
- $batchExamProcess[]=array(
- 'exam_id'=>$v['exam_id'],
- 'class_id'=>$v['class_id'],
- 'action_type'=>7,
- 'action_time'=>time()
- );
- }
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $rs = Exam::model()->updateAll(array('is_backlog'=>1,'update_time'=>time()),$criteria);
- if($rs){
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => $exam_group_id,
- "school_id" => $this->schoolId,
- "coach_id" => $this->coachId,
- "exam_id" => implode(',',$exam_ids),
- "class_id" => implode(',',$class_ids),
- "upload_num" => 0,
- "total_num" => 0,
- "title" => '待办',
- "type" => 1,
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $this->schoolManager->saveExamProcessBatch($exam_group_id,$batchExamProcess);
- $time = time()-24*3600*14;
- $condition[] = "e.is_backlog = 0 ";
- $condition[] = "e.upload_status > 0 ";
- $condition[] = "e.complete_time > ".$time;
- $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
- $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
- if($rs){
- foreach ($rs as $v){
- $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
- $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
- }
- foreach ($rs as $k=>$v){
- if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
- $num = array_sum($group_backlog[$v['exam_group_id']]);
- $count = count($group_exam[$v['exam_group_id']]);
- if($num == $count){
- unset($rs[$k]);
- }
- }
- }
- foreach ($rs as $k=>$v){
- if($v['is_uploaded_count'] == 0){
- unset($rs[$k]);
- }
- }
- }else{
- $rs = array();
- }
- //发送消息队列
- if ($exam_ids) {
- $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_group_id,'examIds'=>array_keys($exam_ids));
- $this->sendStomp($stomp_data);
- //发送消息
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>3,
- 'subject_id'=>$subjectId,
- 'send_type'=>'exam',
- 'exam_group_id'=>$exam_group_id,
- 'exam_ids'=>array_values($exam_ids)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- }
- echo json_encode(array('status'=>1,'count'=>count($rs)));exit;
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- /**
- * 发送消息队列
- * @return mixed
- */
- private function sendStomp($data = array())
- {
- if ($data) {
- $conf = new RdKafka\Conf();
- $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
- $producer = new RdKafka\Producer($conf);
- $topic = $producer->newTopic("zsyte-marking-finished-notify");
- $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data));
- $producer->poll(0);
- $result = $producer->flush(10000);
- if($result===0){
- return true;
- }
- // $destination = 'zsyte.markingFinishedNotify';
- //
- // $stomp_address = Yii::app()->params['markingFinishedNotifyAddress'];
- //
- // $stomp = new Stomp($stomp_address);
- // $stomp->subscribe($destination);
- //
- //// $data = array('schoolId'=>123,'examGroupId'=>45679794,'examIds'=>array('54646465'));
- //
- // $bool = $stomp->send($destination, json_encode($data));
- }
- return false;
- }
- //搜索已发送待办考试
- public function actionAjaxGetBacklogExam(){
- $examName = Req::post("examName");
- $time = time()-24*3600*14;
- $condition[] = "e.is_backlog =1 ";
- $condition[] = "e.name ='".$examName."' ";
- $condition[] = "e.complete_time > ".$time;
- $sql="SELECT e.exam_group_id,e.exam_id,e.name,e.is_backlog,c.class_name,complete_time,e.tpl_data FROM `exam` e ";
- $sql.="join class c on c.class_id=e.class_id ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $sql.=" order by e.create_time desc ";
- $exam = $this->sConn->createCommand($sql)->queryAll();
- $result=array();
- $list=array();
- if($exam){
- foreach ($exam as $val){
- $tplData=json_decode($val['tpl_data'],true);
- $val['exam_date']=$tplData['examDate'];
- unset($val['tpl_data']);
- $list[$val['exam_group_id']][]=$val;
- }
- }
- //生成Html
- $html='<tr><td>考试名称</td><td>考试日期</td><td>已发送班级</td><td>重置操作</td></tr>';
- foreach ($list as $eg=>$item){
- $first=1;
- $classCount=count($item);
- foreach ($item as $value){
- if($first==1){
- $html.='<tr >';
- $html.='<td rowspan="'.$classCount.'">'.$value['name'].'</td>';
- $html.='<td rowspan="'.$classCount.'">'.$value['exam_date'].'</td>';
- $html.='<td>'.$value['class_name'].'</td>';
- $html.='<td><span class="send-repeat blue-font" id="'.$value['exam_id'].'">生成产品</span></td>';
- $html.='</tr>';
- $first=0;
- }else{
- $html.='<tr>';
- $html.='<td>'.$value['class_name'].'</td>';
- $html.='<td><span class="send-repeat blue-font" id="'.$value['exam_id'].'">生成产品</span></td>';
- $html.='</tr>';
- }
- }
- }
- $result['status']=1;
- $result['data']=$html;
- $result['exam']=count($list);
- exit(jsonEncode($result));
- }
- }
|