package com.qxueyou.scc.sys.action;
|
|
import com.qxueyou.scc.admin.classes.model.ClsClass;
|
import com.qxueyou.scc.admin.classes.service.IClassService;
|
import com.qxueyou.scc.admin.classroom.model.ClassRoom;
|
import com.qxueyou.scc.admin.classroom.service.IClassRoomService;
|
import com.qxueyou.scc.base.dao.CommonDAO;
|
import com.qxueyou.scc.base.util.*;
|
import com.qxueyou.scc.exam.model.ExamBatchInfo;
|
import com.qxueyou.scc.exam.model.ExamInfo;
|
import com.qxueyou.scc.exam.model.ExamResultV;
|
import com.qxueyou.scc.exam.service.IExamBatchService;
|
import com.qxueyou.scc.exam.service.IExamService;
|
import com.qxueyou.scc.sys.utils.DrawingUtil;
|
import com.qxueyou.scc.teach.student.model.StuStudent;
|
import com.qxueyou.scc.teach.student.service.IStudentService;
|
import com.qxueyou.scc.user.service.IUserService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* @author luodong
|
* @version 1.0
|
* @date 2020/5/25 15:01
|
*/
|
@Controller
|
@RequestMapping(value = "/certImage")
|
public class ImgController {
|
|
@Autowired
|
IStudentService studentService;
|
|
|
@Autowired
|
private CommonDAO commonDAO;
|
|
@Autowired
|
IUserService userService;
|
|
@Autowired
|
IClassService classService;
|
|
@Autowired
|
IExamService examService;
|
|
@Autowired
|
IExamBatchService examBatchService;
|
|
@Autowired
|
private IClassRoomService classRoomService;
|
|
|
/**
|
* ¸ù¾ÝÇëÇóµÄ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; //×Ö½ÚÁ÷
|
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ÏÂÔØÎļþÃû¿Õ¸ñ±ä+ºÅÎÊÌâ
|
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("°ËØÔÁë")) {
|
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"),
|
stu.get("classRoomName"),
|
stu.get("examRoomName"),
|
stu.get("address"),
|
stu.get("address2"),
|
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×÷ΪÎļþÃû
|
headers.setContentDispositionFormData("attachment",fileName);
|
//»ñÈ¡×Ö½ÚÊý¾Ý
|
byte[] bytes = bo.toByteArray();
|
//½»¸øspring
|
entity = new ResponseEntity<byte[]>(bytes, headers, statusCode);
|
// } catch (IOException e) {
|
//
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
} finally {
|
try {
|
assert bo != null;
|
bo.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
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Óë×éµÄËùÓп¼Éú¼¯ºÏ
|
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());
|
student.put("classRoomName",classRoomName);
|
student.put("examName",examInfo.getExamName());
|
if(address.contains("/")){
|
String[] split = address.split("/");
|
if(split.length>=2){
|
student.put("address",split[0]);
|
student.put("address2",split[1]);
|
}else {
|
student.put("address",address);
|
student.put("address2",address);
|
}
|
}else {
|
student.put("address",address);
|
student.put("address2",address);
|
}
|
student.put("examRoomName",examRoomName);
|
student.put("startTime",startTime);
|
student.put("endTime",endTime);
|
student.put("number",number+"");
|
student.put("sex",stu.getSex()?"ÄÐ":"Å®");
|
//TODO ÏÂÔØ×´Ì¬
|
studentService.updateImgStudent(stu.getStudentId());
|
ClientUtils.getUserInfo().setInfo("age",String.valueOf(Integer.parseInt(number)+1));
|
return student;
|
}
|
}
|