首页>代码>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;
	}
}
最近下载更多
                
                shuangfu     LV25
                2023年12月2日
            
            
        
                孙龙52     LV6
                2022年7月25日
            
            
        
                泓鼎168     LV20
                2022年3月9日
            
            
        
                wanglinddad     LV55
                2021年12月20日
            
            
        
                qianzf     LV12
                2021年7月21日
            
            
        
                ygbuhuide     LV4
                2021年5月14日
            
            
        
                一字清华     LV8
                2021年1月13日
            
            
        
                123456nty     LV37
                2020年12月16日
            
            
        
                xiadongdong     LV12
                2020年10月22日
            
            
        
                as5675020     LV5
                2020年9月18日
            
            
        
最近浏览更多
                
                奋斗的小蚂蚁     LV16
                10月28日
            
            
        
                ma406805131     LV19
                2024年12月18日
            
            
        
                15578157792     LV7
                2024年12月10日
            
            
        
                pilipala888    
                2024年9月10日
            
            
                    暂无贡献等级
            
        
                Song3LL    
                2024年7月22日
            
            
                    暂无贡献等级
            
        
                老猪1978     LV1
                2024年6月3日
            
            
        
                1109851097     LV1
                2024年5月7日
            
            
        
                admin_z     LV22
                2024年1月28日
            
            
        
                minjing123     LV8
                2024年1月4日
            
            
        
                shuangfu     LV25
                2023年12月2日
            
            
        
                
                
    