首页>代码>SSM开发强迫症简易自测量问卷系统,包括后台管理系统>/yhQuestion/src/main/java/com/yanhui/controller/backend/PaperTypeManageController.java
package com.yanhui.controller.backend; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.json.JSONObject; 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.SurveyType; @Controller @RequestMapping("/yhmanage/paperType/") public class PaperTypeManageController extends BaseController{ /** * 问卷类型树 * @return * @throws Exception */ @RequestMapping("/getPaperTypeList") public void getPaperTypeList(String page, String name, HttpServletRequest request, HttpServletResponse response) throws Exception{ //写入到前台 request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); JSONArray array = new JSONArray(); Map<String,Object> map = new HashMap<String,Object>(); List<SurveyType> surveyTypeList = surveyTypeService.listForPage(map); for (SurveyType type : surveyTypeList) { JSONObject jsonObject = new JSONObject(); jsonObject.put("id",type.getId()); jsonObject.put("name",type.getName()); jsonObject.put("pId",type.getParentId()); array.put(jsonObject); } System.out.println(array.toString()); response.getWriter().write(array.toString()); response.getWriter().flush(); response.getWriter().close(); } @RequestMapping("/insertPaperType") @ResponseBody public Map<String,Object> insertPaperType(SurveyType surveyType, HttpServletRequest request){ Map<String,Object> map = new HashMap<String,Object>(); try { Integer id = surveyType.getId(); if(id != null){ //更新 surveyTypeService.update(surveyType); map.put("message", Global.MSG_UPDATE_SUCCESS); }else{ //添加 surveyTypeService.insert(surveyType); map.put("message", Global.MSG_ADD_SUCCESS); } } catch (Exception e) { map.put("message", Global.MSG_FAIL); } return map; } /** * 删除 * @param id * @return */ @RequestMapping("/deletePaperType") @ResponseBody public Map<String,Object> deletePaperType(Integer id){ Map<String,Object> map = new HashMap<String,Object>(); try { map.put("parentId", id); List<SurveyType> list = surveyTypeService.listForPage(map); for(SurveyType type : list){ surveyTypeService.deleteById(type.getId()); } surveyTypeService.deleteById(id); map.put("message", Global.MSG_DEL_SUCCESS); } catch (Exception e) { map.put("message", Global.MSG_FAIL); } return map; } // /** // * 跳转到编辑页面 // * @return // */ // @RequestMapping("/edit-paper") // public String editPager(Integer id, HttpServletRequest request) { // if(id!=null){ // Paper paper = paperService.findById(id); // request.setAttribute("paper", paper); // } // 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("/deletePaperType") // @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("/startOrStopUser") // @ResponseBody // public Map<String,Object> startOrStopUser(Integer id, HttpServletRequest request){ // Map<String,Object> map = new HashMap<String,Object>(); // User user = userService.findById(id); // Boolean isActive = user.getIsActive(); // if(isActive){ // //修改为禁用 // user.setIsActive(false); // map.put("status", 0); // }else{ // //修改为可用 // user.setIsActive(true); // map.put("status", 1); // } // userService.update(user); // 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; // } }