use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class ExpController method saveLoad.
@RequestMapping(value = "/saveExp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String saveLoad(HttpServletRequest request) throws Exception {
Map<String, String[]> req = request.getParameterMap();
AjaxResult ajaxResult = new AjaxResult();
if (req.get("data") != null) {
JSONObject jsonObject = JSON.parseObject(String.valueOf(req.get("data")[0]));
Expriment workload;
workload = JSON.parseObject(String.valueOf(jsonObject), Expriment.class);
if (expService.updateLoad(workload)) {
ajaxResult.ok();
ajaxResult.setMsg("保存成功");
} else {
ajaxResult.failed();
ajaxResult.setMsg("保存失败");
}
} else {
ajaxResult.failed();
ajaxResult.setMsg("参数错误");
}
return JSON.toJSONString(ajaxResult);
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class TeachingController method uploadTeaching.
@RequestMapping(value = "/upload/teaching", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String uploadTeaching(@RequestParam(value = "file", required = false) MultipartFile buildInfo, HttpServletRequest request, HttpServletResponse response) {
if (!buildInfo.isEmpty()) {
String path = request.getSession().getServletContext().getRealPath("/upload") + File.separatorChar + buildInfo.getOriginalFilename();
// 需要先保存在本地
File file;
AjaxResult ajaxResult = new AjaxResult();
List list = null;
file = new File(path);
try {
buildInfo.transferTo(file);
logger.info(path);
// 解析
teachingService.saveAsData(path);
} catch (IOException e) {
e.printStackTrace();
}
}
return "failed";
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class UploadExcel method importExcel.
@RequestMapping(value = "/uploadExcel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String importExcel(@RequestParam(value = "file", required = false) MultipartFile buildInfo, HttpServletRequest request, HttpServletResponse response) {
if (buildInfo != null) {
String path = request.getSession().getServletContext().getRealPath("/upload") + File.separatorChar + buildInfo.getOriginalFilename();
// 需要先保存在本地
File file = null;
AjaxResult ajaxResult = new AjaxResult();
try {
file = ToolKit.getFileFromBytes(buildInfo.getBytes(), path);
} catch (CustomException e) {
e.printStackTrace();
ajaxResult.failed();
ajaxResult.setMsg(e.getMessage());
return ajaxResult.toString();
} catch (IOException e) {
e.printStackTrace();
ajaxResult.failed();
ajaxResult.setMsg(e.getMessage());
return ajaxResult.toString();
}
List list = null;
String type = request.getParameter("type");
System.out.println(type);
try {
switch(type) {
case ExcelServiceImpl.REMOTE_TEACH:
// 这里是解析excel文件
list = excelService.inTeachWorkload(file);
list = remoteTeachService.insertLoadByList(list);
break;
case ExcelServiceImpl.REMOTE_EXP:
// 这里是解析excel文件
list = excelService.inExpWorkLoad(file);
list = remoteExpService.insertLoadByList(list);
break;
case ExcelServiceImpl.REMOTE_DESIGN:
list = excelService.inDesignList(file);
list = designService.insertLoadByList(list);
break;
case ExcelServiceImpl.REMOTE_GRA:
list = excelService.inGraduateWorkload(file);
list = graService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_COURSE:
list = excelService.inLCourseWorkload(file);
list = localCourseService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_EXP:
list = excelService.inLExpWorkload(file);
list = localExpService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_DESIGN:
list = excelService.inLDesignWorkload(file);
list = localDesignService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_GRA_PRACTICE:
list = excelService.inLGraPracticeWorkload(file);
list = localGraPracticeService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_GRA_DESIGN:
list = excelService.inLGraDesignWorkload(file);
list = localGraDesignService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_PRACTICE:
list = excelService.inLPracticeWorkload(file);
list = localPracticeService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_PROJECT:
list = excelService.inLProjectWorkload(file);
list = localProjectService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_MATCH:
list = excelService.inLMatchWorkload(file);
list = localMatchService.insertLoadByList(list);
break;
case ExcelServiceImpl.LOACAL_NET:
list = excelService.inLNetWorkload(file);
list = localNetService.insertLoadByList(list);
break;
case ExcelServiceImpl.EXP:
list = excelService.inExpriment(file);
list = exprimentService.insertLoadByList(list);
break;
case ExcelServiceImpl.REMOTE_NON_LESSON:
list = excelService.inNonLesson(file);
list = nonLessonService.insertLoadByList(list);
break;
default:
}
} catch (Exception e) {
e.printStackTrace();
// 这里做的是一个插入数据库功能
ajaxResult.setMsg(e.getMessage());
ajaxResult.failed();
ajaxResult.setData(list);
return ajaxResult.toString();
}
ToolKit.deleteFile(path);
if (list.size() == 0) {
ajaxResult.ok();
ajaxResult.setMsg("导入成功");
return ajaxResult.toString();
} else {
ajaxResult.failed();
ajaxResult.setMsg("导入失败");
return ajaxResult.toString();
}
}
AjaxResult ajaxResult = new AjaxResult<>();
ajaxResult.failed();
return ajaxResult.toString();
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class TeacherController method deleteTeacher.
@RequestMapping(value = "/teacher/delete/list", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = RequestMethod.POST)
@ResponseBody
public String deleteTeacher(@RequestParam(name = "data") String s) {
ArrayList<Integer> list = (ArrayList<Integer>) JSON.parseArray(s, Integer.class);
AjaxResult result = new AjaxResult();
if (teacherService.deleteTeacher(list)) {
result.ok();
} else {
result.failed();
result.setMsg("用户不存在");
}
return result.toString();
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class TeacherController method deleteTeacher.
@RequestMapping(value = "/teacher/delete", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = RequestMethod.POST)
@ResponseBody
public String deleteTeacher(Teacher teacher) {
AjaxResult result = new AjaxResult();
if (teacher != null) {
teacherService.deleteTeacher(teacher.getName());
result.ok();
} else {
result.failed();
result.setMsg("资源错误");
}
return result.toString();
}
Aggregations