149 lines
4.9 KiB
Plaintext
149 lines
4.9 KiB
Plaintext
|
|
package com.bonus.camera.controller;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import java.text.SimpleDateFormat;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.List;
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import org.apache.commons.io.FileUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.stereotype.Controller;
|
||
|
|
import org.springframework.ui.Model;
|
||
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||
|
|
|
||
|
|
import com.bonus.camera.beans.Encodes;
|
||
|
|
import com.bonus.camera.beans.ScreenBeans;
|
||
|
|
import com.bonus.camera.beans.WrapperResponseEntity;
|
||
|
|
import com.bonus.camera.beans.cameraBeans;
|
||
|
|
import com.bonus.camera.service.CamersService;
|
||
|
|
import com.bonus.seat.beans.SeatBean;
|
||
|
|
import com.bonus.seat.service.SeatService;
|
||
|
|
import com.bonus.sys.AjaxRes;
|
||
|
|
import com.bonus.sys.BaseController;
|
||
|
|
import com.bonus.sys.IPHelper;
|
||
|
|
import com.bonus.sys.Page;
|
||
|
|
import com.bonus.sys.UserShiroHelper;
|
||
|
|
|
||
|
|
@Controller
|
||
|
|
@RequestMapping("/backstage/camera/")
|
||
|
|
public class CameraController extends BaseController<cameraBeans> {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private CamersService service;
|
||
|
|
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
SeatService seatservice;
|
||
|
|
|
||
|
|
@RequestMapping("list")
|
||
|
|
public String List(Model model) {
|
||
|
|
return "/camera/cameraList";
|
||
|
|
}
|
||
|
|
@RequestMapping("savecamera")
|
||
|
|
@ResponseBody
|
||
|
|
public AjaxRes savecamera(HttpServletRequest req,@RequestBody cameraBeans o) {
|
||
|
|
AjaxRes ar = getAjaxRes();
|
||
|
|
try {
|
||
|
|
ar =service.savecamera(req,o);
|
||
|
|
ar.setSucceedMsg("添加考试人员成功");
|
||
|
|
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
ar.setFailMsg("新增座位号人员失败,异常处理!");
|
||
|
|
}
|
||
|
|
return ar;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@RequestMapping("findByPage")
|
||
|
|
public String findByPage(@RequestBody Page<cameraBeans> page, cameraBeans o, Model model) {
|
||
|
|
try {
|
||
|
|
o = page.getObj();
|
||
|
|
page = service.findByPage(o, page);
|
||
|
|
if (page.getResults() != null && page.getResults().size() != 0) {
|
||
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy");// 设置日期格式
|
||
|
|
String date = df.format(new Date());
|
||
|
|
for (int i = 0; i < page.getResults().size(); i++) {
|
||
|
|
cameraBeans bean = page.getResults().get(i);
|
||
|
|
page.getResults().set(i, bean);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
model.addAttribute("page", page);
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
}
|
||
|
|
return "/camera/cameraDetails";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping("cameraFormPage")
|
||
|
|
public String questionFormPage(Model model) {
|
||
|
|
List<SeatBean> findRoomInfo = seatservice.findRoomInfo();
|
||
|
|
model.addAttribute("findRoomInfo", findRoomInfo);
|
||
|
|
return "/camera/cameraForm";
|
||
|
|
}
|
||
|
|
@RequestMapping("siteFormPage")
|
||
|
|
public String siteFormPage(Model model) {
|
||
|
|
|
||
|
|
return "/camera/siteFormPage";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@ResponseBody
|
||
|
|
@RequestMapping(value = "img_upload")
|
||
|
|
public String imgUpload(@RequestParam String imgBase64Data, HttpServletRequest request) {
|
||
|
|
WrapperResponseEntity entity = new WrapperResponseEntity();
|
||
|
|
String team="";
|
||
|
|
try {
|
||
|
|
|
||
|
|
if (imgBase64Data == null || "".equals(imgBase64Data)) {
|
||
|
|
entity.setData("上传失败,上传图片数据为空!");
|
||
|
|
}
|
||
|
|
String projectPath = request.getSession().getServletContext().getRealPath("/");
|
||
|
|
String imgFilePath = "/upload/";
|
||
|
|
String getippath="23.50.192.222";
|
||
|
|
//String bathpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/"+"upload/";
|
||
|
|
String bathpath = request.getScheme()+"://"+getippath+":"+request.getServerPort()+request.getContextPath()+"/"+"upload/";
|
||
|
|
File uploadPathFile = new File(projectPath + imgFilePath);
|
||
|
|
|
||
|
|
// 创建父类文件
|
||
|
|
if (!uploadPathFile.exists() && !uploadPathFile.isDirectory()) {
|
||
|
|
uploadPathFile.mkdirs();
|
||
|
|
}
|
||
|
|
String picName = new Date().getTime() + ".jpg";
|
||
|
|
//picName = request.getParameter("imageUrl");
|
||
|
|
File imgeFile = new File(projectPath + imgFilePath, picName);
|
||
|
|
if (!imgeFile.exists()) {
|
||
|
|
imgeFile.createNewFile();
|
||
|
|
}
|
||
|
|
// 对base64进行解码
|
||
|
|
byte[] result = Encodes.decodeBase64(imgBase64Data);
|
||
|
|
// 使用Apache提供的工具类将图片写到指定路径下
|
||
|
|
FileUtils.writeByteArrayToFile(imgeFile, result);
|
||
|
|
entity.setData(imgFilePath + imgeFile.getName());
|
||
|
|
ScreenBeans bean=new ScreenBeans();
|
||
|
|
bean.setPicture(bathpath+picName);
|
||
|
|
String ipAddr = IPHelper.getRemortIP(request);
|
||
|
|
bean.setIppath(ipAddr);
|
||
|
|
String name = UserShiroHelper.getCurrentUser().getName();
|
||
|
|
bean.setPictureName(name);
|
||
|
|
Date d = new Date();
|
||
|
|
SimpleDateFormat sbf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
|
|
String format = sbf.format(d);
|
||
|
|
bean.setPictureTime(format);
|
||
|
|
service.insertScreen(bean);
|
||
|
|
System.out.println( request.getRemoteAddr());
|
||
|
|
team="1";
|
||
|
|
} catch (Exception e) {
|
||
|
|
team="0";
|
||
|
|
e.printStackTrace();
|
||
|
|
entity.setData("上传失败,系统异常");
|
||
|
|
}
|
||
|
|
return team;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|