BacklogController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: 刘红伟
  5. * QQ : 454303753
  6. * Date: 2018/5/8 0008
  7. * Time: 下午 15:04
  8. */
  9. class BacklogController extends Controller{
  10. public function actionIndex(){
  11. $data = array();
  12. $_rs = array();
  13. $group_backlog = array();
  14. $group_exam = array();
  15. $time = time()-24*3600*14;
  16. $condition[] = "e.is_backlog = 0 ";
  17. $condition[] = "e.upload_status > 0 ";
  18. // $condition[] = "e.subject_id in (3,6) ";
  19. $condition[] = "e.complete_time > ".$time;
  20. $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3) ";
  21. $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
  22. // debug($rs);
  23. if($rs){
  24. foreach ($rs as $v){
  25. $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
  26. $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
  27. }
  28. foreach ($rs as $k=>$v){
  29. if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
  30. $num = array_sum($group_backlog[$v['exam_group_id']]);
  31. $count = count($group_exam[$v['exam_group_id']]);
  32. if($num == $count){
  33. unset($rs[$k]);
  34. }else{
  35. $_rs[$v['exam_group_id']]['result'][] = $v;
  36. $_rs[$v['exam_group_id']]['exam_name'] = $v['exam_name'];
  37. $_rs[$v['exam_group_id']]['exam_group_id'] = $v['exam_group_id'];
  38. }
  39. }
  40. }
  41. }
  42. $data['rs'] = $_rs;
  43. $this->render("index",$data);
  44. }
  45. public function actionAjaxSend(){
  46. $exam_id = Req::post("exam_id");
  47. $is_uploaded_count = Req::post("is_uploaded_count");
  48. $students_count = Req::post("students_count");
  49. $class_id = Req::post("class_id");
  50. $_num = 0;
  51. if($exam_id>0){
  52. $rs = Exam::model()->updateAll(array('is_backlog'=>1,'update_time'=>time()),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  53. if($rs){
  54. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  55. if(Yii::app()->params['handle_log_on_off'])
  56. {
  57. if($exam_data){
  58. writeFileLog(jsonEncode(array(
  59. "exam_group_id" => $exam_data->exam_group_id,
  60. "school_id" => $this->schoolId,
  61. "coach_id" => $this->coachId,
  62. "exam_id" => $exam_id,
  63. "class_id" => $exam_data->class_id,
  64. "upload_num" => $is_uploaded_count,
  65. "total_num" => $students_count,
  66. "title" => '发送待办',
  67. "type" => 0,
  68. "date"=>date('Y-m-d H:i:s'),
  69. )));
  70. }
  71. }
  72. $this->schoolManager->saveExamProcess($exam_data->exam_group_id,7,time(),$exam_id,$exam_data->class_id);
  73. $time = time()-24*3600*14;
  74. $condition[] = "e.is_backlog = 0 ";
  75. $condition[] = "e.upload_status > 0 ";
  76. $condition[] = "e.complete_time > ".$time;
  77. $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
  78. $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
  79. if($rs){
  80. foreach ($rs as $v){
  81. $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
  82. $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
  83. }
  84. foreach ($rs as $k=>$v){
  85. if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
  86. $num = array_sum($group_backlog[$v['exam_group_id']]);
  87. $count = count($group_exam[$v['exam_group_id']]);
  88. if($num == $count){
  89. unset($rs[$k]);
  90. }
  91. }
  92. }
  93. foreach ($rs as $k=>$v){
  94. if($v['is_uploaded_count'] == 0){
  95. unset($rs[$k]);
  96. }
  97. }
  98. }else{
  99. $rs = array();
  100. }
  101. //发送消息队列
  102. if (isset($exam_data->exam_group_id)) {
  103. $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_data->exam_group_id,'examIds'=>array($exam_id));
  104. $this->sendStomp($stomp_data);
  105. //发送消息
  106. $sendMsg=array(
  107. 'school_id'=>$this->schoolId,
  108. 'msg_type'=>3,
  109. 'subject_id'=>$exam_data->subject_id,
  110. 'send_type'=>'exam',
  111. 'exam_group_id'=>$exam_data->exam_group_id,
  112. 'exam_ids'=>array($exam_id)
  113. );
  114. sendDataToKafka('php-product-html',$sendMsg);
  115. }
  116. unset($exam_data);
  117. echo json_encode(array('status'=>1,'count'=>count($rs)));exit;
  118. }
  119. }
  120. echo json_encode(array('status'=>0));exit;
  121. }
  122. public function actionAjaxAllSend(){
  123. $exam_group_id = Req::post("exam_group_id");
  124. if($exam_group_id>0){
  125. $subjectId=0;
  126. $condition[] = "e.is_backlog = 0 ";
  127. $condition[] = "e.upload_status > 0 ";
  128. $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
  129. $condition[] = "e.exam_group_id = ".$exam_group_id;
  130. $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
  131. $exam_ids = array();
  132. $class_ids = array();
  133. $name = '';
  134. $batchExamProcess=array();
  135. if($rs){
  136. foreach ($rs as $v){
  137. $name = $v['exam_name'];
  138. $subjectId=$v['subject_id'];
  139. if($v['is_uploaded_count'] == $v['students_count']){
  140. $exam_ids[$v['exam_id']] = $v['exam_id'];
  141. $class_ids[$v['class_id']] = $v['class_id'];
  142. $batchExamProcess[]=array(
  143. 'exam_id'=>$v['exam_id'],
  144. 'class_id'=>$v['class_id'],
  145. 'action_type'=>7,
  146. 'action_time'=>time()
  147. );
  148. }
  149. }
  150. }
  151. $criteria = new CDbCriteria();
  152. $criteria->addInCondition('exam_id',$exam_ids);
  153. $rs = Exam::model()->updateAll(array('is_backlog'=>1,'update_time'=>time()),$criteria);
  154. if($rs){
  155. if(Yii::app()->params['handle_log_on_off'])
  156. {
  157. writeFileLog(jsonEncode(array(
  158. "exam_group_id" => $exam_group_id,
  159. "school_id" => $this->schoolId,
  160. "coach_id" => $this->coachId,
  161. "exam_id" => implode(',',$exam_ids),
  162. "class_id" => implode(',',$class_ids),
  163. "upload_num" => 0,
  164. "total_num" => 0,
  165. "title" => '待办',
  166. "type" => 1,
  167. "date"=>date('Y-m-d H:i:s')
  168. )));
  169. }
  170. $this->schoolManager->saveExamProcessBatch($exam_group_id,$batchExamProcess);
  171. $time = time()-24*3600*14;
  172. $condition[] = "e.is_backlog = 0 ";
  173. $condition[] = "e.upload_status > 0 ";
  174. $condition[] = "e.complete_time > ".$time;
  175. $condition[] = "(eg.mark_type = 0 or eg.import_score_type=3)";
  176. $rs = $this->schoolManager->getBacklogList($condition,array('e.create_time desc,e.exam_id'));
  177. if($rs){
  178. foreach ($rs as $v){
  179. $group_backlog[$v['exam_group_id']][] = $v['is_backlog'];
  180. $group_exam[$v['exam_group_id']][$v['exam_id']] = $v['exam_id'];
  181. }
  182. foreach ($rs as $k=>$v){
  183. if(isset($group_backlog[$v['exam_group_id']]) && isset($group_exam[$v['exam_group_id']])){
  184. $num = array_sum($group_backlog[$v['exam_group_id']]);
  185. $count = count($group_exam[$v['exam_group_id']]);
  186. if($num == $count){
  187. unset($rs[$k]);
  188. }
  189. }
  190. }
  191. foreach ($rs as $k=>$v){
  192. if($v['is_uploaded_count'] == 0){
  193. unset($rs[$k]);
  194. }
  195. }
  196. }else{
  197. $rs = array();
  198. }
  199. //发送消息队列
  200. if ($exam_ids) {
  201. $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_group_id,'examIds'=>array_keys($exam_ids));
  202. $this->sendStomp($stomp_data);
  203. //发送消息
  204. $sendMsg=array(
  205. 'school_id'=>$this->schoolId,
  206. 'msg_type'=>3,
  207. 'subject_id'=>$subjectId,
  208. 'send_type'=>'exam',
  209. 'exam_group_id'=>$exam_group_id,
  210. 'exam_ids'=>array_values($exam_ids)
  211. );
  212. sendDataToKafka('php-product-html',$sendMsg);
  213. }
  214. echo json_encode(array('status'=>1,'count'=>count($rs)));exit;
  215. }
  216. }
  217. echo json_encode(array('status'=>0));exit;
  218. }
  219. /**
  220. * 发送消息队列
  221. * @return mixed
  222. */
  223. private function sendStomp($data = array())
  224. {
  225. if ($data) {
  226. $conf = new RdKafka\Conf();
  227. $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
  228. $producer = new RdKafka\Producer($conf);
  229. $topic = $producer->newTopic("zsyte-marking-finished-notify");
  230. $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data));
  231. $producer->poll(0);
  232. $result = $producer->flush(10000);
  233. if($result===0){
  234. return true;
  235. }
  236. // $destination = 'zsyte.markingFinishedNotify';
  237. //
  238. // $stomp_address = Yii::app()->params['markingFinishedNotifyAddress'];
  239. //
  240. // $stomp = new Stomp($stomp_address);
  241. // $stomp->subscribe($destination);
  242. //
  243. //// $data = array('schoolId'=>123,'examGroupId'=>45679794,'examIds'=>array('54646465'));
  244. //
  245. // $bool = $stomp->send($destination, json_encode($data));
  246. }
  247. return false;
  248. }
  249. //搜索已发送待办考试
  250. public function actionAjaxGetBacklogExam(){
  251. $examName = Req::post("examName");
  252. $time = time()-24*3600*14;
  253. $condition[] = "e.is_backlog =1 ";
  254. $condition[] = "e.name ='".$examName."' ";
  255. $condition[] = "e.complete_time > ".$time;
  256. $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 ";
  257. $sql.="join class c on c.class_id=e.class_id ";
  258. if($condition){
  259. $sql.=" where ".implode(' and ',$condition);
  260. }
  261. $sql.=" order by e.create_time desc ";
  262. $exam = $this->sConn->createCommand($sql)->queryAll();
  263. $result=array();
  264. $list=array();
  265. if($exam){
  266. foreach ($exam as $val){
  267. $tplData=json_decode($val['tpl_data'],true);
  268. $val['exam_date']=$tplData['examDate'];
  269. unset($val['tpl_data']);
  270. $list[$val['exam_group_id']][]=$val;
  271. }
  272. }
  273. //生成Html
  274. $html='<tr><td>考试名称</td><td>考试日期</td><td>已发送班级</td><td>重置操作</td></tr>';
  275. foreach ($list as $eg=>$item){
  276. $first=1;
  277. $classCount=count($item);
  278. foreach ($item as $value){
  279. if($first==1){
  280. $html.='<tr >';
  281. $html.='<td rowspan="'.$classCount.'">'.$value['name'].'</td>';
  282. $html.='<td rowspan="'.$classCount.'">'.$value['exam_date'].'</td>';
  283. $html.='<td>'.$value['class_name'].'</td>';
  284. $html.='<td><span class="send-repeat blue-font" id="'.$value['exam_id'].'">生成产品</span></td>';
  285. $html.='</tr>';
  286. $first=0;
  287. }else{
  288. $html.='<tr>';
  289. $html.='<td>'.$value['class_name'].'</td>';
  290. $html.='<td><span class="send-repeat blue-font" id="'.$value['exam_id'].'">生成产品</span></td>';
  291. $html.='</tr>';
  292. }
  293. }
  294. }
  295. $result['status']=1;
  296. $result['data']=$html;
  297. $result['exam']=count($list);
  298. exit(jsonEncode($result));
  299. }
  300. }