派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
src/main/java/com/qxueyou/scc/sys/action/ImgController.java
@@ -68,41 +68,41 @@
   /**
    * 根据请求的id查询数据生成图片
    * 根据请求的id查询数据生成图片
    * @param
    * @return
    */
   @RequestMapping(value = "/createImg",method = RequestMethod.GET)
   @ResponseBody
   public ResponseEntity<byte[]> draw(String studentNo,String examBatchId, HttpServletRequest req, HttpServletResponse resp) throws Exception {
      //获取准考证信息
      //获取准考证信息
      Map<String,String> stu = getStudent(studentNo,examBatchId);
      ResponseEntity<byte[]> entity = null;
      ByteArrayOutputStream bo=null;  //字节流
      ByteArrayOutputStream bo=null;  //字节流
      String fileName=UUID.randomUUID().toString() +".jpg";
      HttpStatus statusCode = HttpStatus.CREATED;
      String header = req.getHeader("User-Agent").toUpperCase();
      try {
         if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {
            fileName = URLEncoder.encode(fileName, "gbk");
            fileName = fileName.replace("+", "%20");    // IE下载文件名空格变+号问题
            fileName = fileName.replace("+", "%20");    // IE下载文件名空格变+号问题
            statusCode = HttpStatus.OK;
         } else {
            fileName = new String(fileName.getBytes("gbk"), "ISO8859-1");
         }
          bo=new ByteArrayOutputStream();
         String simg="static/images/ca.jpg";
         if (stu.get("classRoomName").contains("八卦岭")) {
         if (stu.get("classRoomName").contains("八卦岭")) {
            simg="static/images/cb.jpg";
         }
         //生成图片流
         //生成图片流
         DrawingUtil.drawImage("static/images/cc.jpg",
               simg,
               stu.get("name"),
               stu.get("studentNo"),
               stu.get("examName"),
//               "深圳市保安员资格考试",
//               "深圳市保安员资格考试",
//               "SZBAZGKS" +
                     stu.get("studentNo").substring(stu.get("studentNo").length()>=6?stu.get("studentNo").length()-6:0),
               stu.get("number"),
@@ -113,14 +113,14 @@
               stu.get("startTime"),
               stu.get("endTime"),
               stu.get("sex"),bo);
          //设置头信息
          //设置头信息
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);//static/images/ca1.jpg
         //UUID作为文件名
         //UUID作为文件名
         headers.setContentDispositionFormData("attachment",fileName);
         //获取字节数据
         //获取字节数据
         byte[] bytes = bo.toByteArray();
         //交给spring
         //交给spring
         entity = new ResponseEntity<byte[]>(bytes, headers, statusCode);
//      } catch (IOException e) {
//
@@ -137,46 +137,46 @@
      return entity;
   }
   private Map<String,String> getStudent(String studentNo,String examBatchId){
      //获取用户信息
      //获取用户信息
      StuStudent stu=null;
      if (studentNo!=null&&!"".equals(studentNo)&&!"null".equals(studentNo)){
          stu = studentService.getStudentByNo(studentNo);
      }else {
          stu= studentService.getStudentByUserId(ClientUtils.getUserId());
      }
      //获取批次信息
      //获取批次信息
      ExamBatchInfo examBatchInfo = examBatchService.queryExamBatchDetail(examBatchId);
      ExamInfo examInfo = examBatchInfo.getExamInfo();
      //获取考点名称
      //获取考点名称
      String classRoomId=examBatchInfo.getClassRoomID();
      ClassRoom detail = classRoomService.detail(classRoomId);
      String classRoomName = detail.getName();
      //获取考点地址
      //获取考点地址
      String address = detail.getAddress();
      //获取考场名称
      //获取考场名称
      String examRoomName=examBatchInfo.getExamRoomName();
      //获取考试开始结束时间
      //获取考试开始结束时间
      String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examBatchInfo.getStartTime());
      String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examBatchInfo.getEndTime());
      //根据批次Id查询所在组Id与组的所有考生集合
      //根据批次Id查询所在组Id与组的所有考生集合
      String classId = examBatchService.queryExamBatchByClassId(examBatchId).getClassId();
//      RedisTemplate redisTemplate = new RedisTemplate<>();
//      //取出
//      //取出
//      List<StuStudent> students = (List<StuStudent>) redisTemplate.boundHashOps("Hashlist").get("students");
//      if(students==null){
//         students= studentService.getStudentByclassId(classId);
//      //存储
//      //存储
//         redisTemplate.boundHashOps("Hashlist").put("students", students);
//      }
//      int number=1;
      String number = ClientUtils.getUserInfo().getInfo("age");
//      for (int i=1;i<=students.size();i++) {
//         if (students.get(i-1).getStudentNo().equals(stu.getStudentNo()) ) {
//            //座位号
//            //座位号
//            number=i;
//         }
//      }
      //添加信息
      //添加信息
      Map<String,String> student=new HashMap<>();
      student.put("name",stu.getName());
      student.put("studentNo",stu.getStudentNo());
@@ -199,8 +199,8 @@
      student.put("startTime",startTime);
      student.put("endTime",endTime);
      student.put("number",number+"");
      student.put("sex",stu.getSex()?"男":"女");
      //TODO 下载状态
      student.put("sex",stu.getSex()?"男":"女");
      //TODO 下载状态
      studentService.updateImgStudent(stu.getStudentId());
      ClientUtils.getUserInfo().setInfo("age",String.valueOf(Integer.parseInt(number)+1));
      return student;