Search in sources :

Example 1 with AjaxResult

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);
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) JSONObject(com.alibaba.fastjson.JSONObject) Expriment(com.hfut.entity.Expriment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with 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";
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) List(java.util.List) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with AjaxResult

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();
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) List(java.util.List) CustomException(com.hfut.exception.CustomException) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) IOException(java.io.IOException) CustomException(com.hfut.exception.CustomException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with AjaxResult

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();
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) ArrayList(java.util.ArrayList)

Example 5 with AjaxResult

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();
}
Also used : AjaxResult(com.hfut.entity.AjaxResult)

Aggregations

AjaxResult (com.hfut.entity.AjaxResult)63 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)56 JSONObject (com.alibaba.fastjson.JSONObject)30 User (com.hfut.entity.User)6 Subject (org.apache.shiro.subject.Subject)6 CustomException (com.hfut.exception.CustomException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Expriment (com.hfut.entity.Expriment)3 LGraDesignWorkload (com.hfut.entity.LGraDesignWorkload)3 LGraPracticeWorkload (com.hfut.entity.LGraPracticeWorkload)3 LMatchWorkload (com.hfut.entity.LMatchWorkload)3 LNetWorkload (com.hfut.entity.LNetWorkload)3 LPracticeWorkload (com.hfut.entity.LPracticeWorkload)3 LProjectWorkload (com.hfut.entity.LProjectWorkload)3 LocalCourseWorkload (com.hfut.entity.LocalCourseWorkload)3 LocalDesignWorkload (com.hfut.entity.LocalDesignWorkload)3 LocalExpWorkload (com.hfut.entity.LocalExpWorkload)3 RemoteDesignWorkload (com.hfut.entity.RemoteDesignWorkload)3