首页>代码>SSM开发强迫症简易自测量问卷系统,包括后台管理系统>/yhQuestion/src/main/java/com/yanhui/controller/backend/PaperManageController.java
package com.yanhui.controller.backend; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.yanhui.constant.Global; import com.yanhui.controller.common.BaseController; import com.yanhui.pojo.Answer; import com.yanhui.pojo.Paper; import com.yanhui.pojo.Question; import com.yanhui.pojo.SurveyType; import com.yanhui.pojo.User; import com.yanhui.util.PropUtils; import com.yanhui.util.QrcodeUtil; import com.yanhui.util.StringUtil; import com.yanhui.util._fileUtil; @Controller @RequestMapping("/yhmanage/paper/") public class PaperManageController extends BaseController{ /** * 生成问卷 * @return */ @RequestMapping("/questions-paper-create") public String questionsPaperCreate(Integer paperId, HttpServletRequest request) { Map<String,Object> map = new HashMap<String,Object>(); Paper paper = paperService.findById(paperId); request.setAttribute("paper", paper); //url地址 http://localhost:8080/yhQuestion/manage/index.html?paperId=1 String url = ""; url = request.getScheme()+"://"; //请求协议 http 或 https url+=request.getHeader("host"); // 请求服务器 http://localhost:8080 url+="/yhQuestion/manage/index-test.html?paperId="+paperId; //url+=request.getRequestURI(); // 工程名 // if(request.getQueryString()!=null) //判断请求参数是否为空 // url+="?"+request.getQueryString(); System.out.println(url); request.setAttribute("url", url); //二维码 QrcodeUtil qrcodeUtil = new QrcodeUtil(); // String imgPath = "d:/我的图片/yanhui.png"; //前缀 String prefixString = UUID.randomUUID().toString().replace("-","")+UUID.randomUUID().toString().replace("-","").substring(2,7); String fileName = prefixString + StringUtil.getCharAndNumr(6,3) + ".png"; String imgPath = request.getSession().getServletContext().getRealPath("/") + "/file/picture/" + fileName; System.out.println(imgPath); String urlImage = qrcodeUtil.getQrcodeImgBycontents(url,imgPath); String resultImage = "file/picture/" + fileName; request.setAttribute("urlImage", resultImage); return Global.WEB_BACK_PAGE + "/paper/paperCreate"; } /** * 跳转到编辑题目页面 * @return */ @RequestMapping("/questions-paper-list") public String questionsPaperList(Integer paperId, HttpServletRequest request) { Map<String,Object> map = new HashMap<String,Object>(); map.put("paperId", paperId); map.put("status", Global.STATUS_1+""); List<Question> questionList = questionService.listForPage(map); for(Question question : questionList){ Integer questionId = question.getId(); map.put("questionId", questionId); List<Answer> anwerList = answerService.listForPage(map); question.setAnswers(anwerList); } request.setAttribute("questionList", questionList); Paper paper = paperService.findById(paperId); request.setAttribute("paper", paper); return Global.WEB_BACK_PAGE + "/question/questionsPaperList"; } /** * 跳转到编辑页面 * @return */ @RequestMapping("/edit-paper") public String editPager(Integer id, HttpServletRequest request) { if(id!=null){ Paper paper = paperService.findById(id); request.setAttribute("paper", paper); } Map<String,Object> map = new HashMap<String,Object>(); List<SurveyType> typeList = surveyTypeService.listForPage(map); request.setAttribute("typeList", typeList); return Global.WEB_BACK_PAGE + "/paper/paperEdit"; } /** * 批量删除 * @param id * @return */ @RequestMapping("/deletePapers") @ResponseBody public Map<String,Object> deletePapers(String ids){ Map<String,Object> result = new HashMap<String,Object>(); try { String[] arry = ids.split(","); for (int i = 0; i < arry.length; i++) { String id = arry[i]; if(!id.equals("")){ paperService.deleteById(Integer.parseInt(id)); } } result.put("status", Global.STATUS_1); } catch (Exception e) { result.put("status", Global.STATUS_0); } return result; } /** * 删除 * @param id * @return */ @RequestMapping("/deletePaper") @ResponseBody public Map<String,Object> deletePaper(Integer id){ Map<String,Object> result = new HashMap<String,Object>(); try { paperService.deleteById(id); result.put("status", Global.STATUS_1); } catch (Exception e) { result.put("status", Global.STATUS_0); } return result; } /** * 跳转到用户添加页面 * @return */ @RequestMapping("/user-add") public String addUserPage(Integer id, HttpServletRequest request) { if(id!=null){ User user = userService.findById(id); request.setAttribute("user", user); } return "/admin/user/user-add"; } /** * 添加用户 * @return */ @RequestMapping("/insertPaper") @ResponseBody public Map<String,Object> insertPaper(Paper paper, HttpServletRequest request){ Map<String,Object> map = new HashMap<String,Object>(); try { Integer id = paper.getId(); if(id != null){ //更新 paperService.update(paper); map.put("message", Global.MSG_UPDATE_SUCCESS); }else{ //添加 paperService.insert(paper); map.put("message", Global.MSG_ADD_SUCCESS); } map.put("status", Global.STATUS_1); } catch (Exception e) { map.put("status", Global.STATUS_0); map.put("message", Global.MSG_FAIL); } return map; } /** * 启用或停用状态 * @return */ @RequestMapping("/updatePaperStatus") @ResponseBody public Map<String,Object> updatePaperStatus(Integer id, HttpServletRequest request){ Map<String,Object> map = new HashMap<String,Object>(); try { Paper paper = paperService.findById(id); Integer status = paper.getStatus(); if(status == 1){ //修改为禁用 paper.setStatus(Global.STATUS_0); }else{ //修改为可用 paper.setStatus(Global.STATUS_1); } paperService.update(paper); map.put("message", Global.MSG_UPDATE_SUCCESS); } catch (Exception e) { map.put("message", Global.MSG_FAIL); } return map; } @RequestMapping("/findById") @ResponseBody public Map<String,Object> findById(int id){ System.out.println("------------"+PropUtils.get("setting.version")); Map<String,Object> map = new HashMap<String, Object>(); User user = userService.findById(id); map.put("user", user); return map; } }