package com.huliyong.controller;
import com.github.pagehelper.PageInfo;
import com.huliyong.pojo.*;
import com.huliyong.service.AdminService;
import com.huliyong.service.QuestionService;
import com.huliyong.service.SurveyService;
import com.huliyong.utils.MapControl;
import com.huliyong.utils.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.*;
/**
* @Auther: H_L_Y
* @Date: 2020/12/26
* @Description: com.huliyong.controller
*/
@Controller
@RequestMapping("/survey")
public class SurveyController {
@Autowired
private SurveyService surveyService;
@Autowired
private AdminService adminService;
@Autowired
private QuestionService questionService;
@GetMapping("/list")
public String toList(){
return "survey/list";
}
@PostMapping("/query")
@ResponseBody
public Map<String,Object> query(Survey survey, @RequestParam("page") int page , @RequestParam("limit") int limit){
System.out.println(page+" Survey "+limit);
PageInfo pageInfo = surveyService.queryByPage(survey, page, limit);
List<Survey> list = pageInfo.getList();
//创建者信息写入survey对象
for (Survey entity : list) {
entity.setAdmin(adminService.selectByPrimaryKey(entity.getCreator()));
}
list.forEach(System.out::println);
HashMap<String,Object> map = new HashMap<>();
map.put("code",0);
map.put("msg","");
map.put("count",pageInfo.getTotal());
map.put("data",list);
return map;
}
@GetMapping("/create")
public String to_create(){
return "survey/add";
}
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Survey survey, HttpServletRequest request){
Admin currAdmin = SessionUtils.getAdmin(request);
survey.setCreator(currAdmin.getId());
survey.setState(Survey.state_create);
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.insert(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
System.out.println(ids);
int result = surveyService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Survey survey){
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.updateByPrimaryKeySelective(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@GetMapping("/detail")
public String detail(Integer id, ModelMap modelMap){
Survey survey = surveyService.selectByPrimaryKey(id);
modelMap.addAttribute("survey",survey);
return "survey/update";
}
@RequestMapping("/ttt")
public void TTT(){
surveyService.updateState();
}
@GetMapping("/question")
public String question(Integer id,ModelMap modelMap){
Survey survey = surveyService.selectByPrimaryKey(id);
modelMap.addAttribute("survey",survey);
return "survey/question";
}
@GetMapping("/preview/{id}")
public String preview(@PathVariable("id") Integer id,ModelMap modelMap){
Survey survey = surveyService.selectByPrimaryKey(id);
Question question = new Question();
question.setSurveyId(survey.getId());
//查询一个问卷中的所有问题及选项
List<Question> questions = questionService.queryByPage(question);
//将问题设置为survey的属性
survey.setQuestions(questions);
modelMap.addAttribute("survey",survey);
return "survey/preview";
}
@RequestMapping(value = "/upload",method = RequestMethod.POST)
public String upload(Integer id, @RequestParam("file") MultipartFile multipartFile, HttpServletRequest request){
//上传的位置
String path = request.getSession().getServletContext().getRealPath("/upload/");
//判断该路径是否存在
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
//上传文件项
String filename = multipartFile.getOriginalFilename();
String uuid = UUID.randomUUID().toString().replace("-", "");
String saveName = uuid + "_" + filename.substring(filename.lastIndexOf(File.separator) + 1);
try {
multipartFile.transferTo(new File(path, saveName));
Survey survey = new Survey();
survey.setId(id);
survey.setBgimg(saveName);
surveyService.updateByPrimaryKeySelective(survey);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:preview/"+id;
}
@PostMapping("/publish")
@ResponseBody
public Map<String,Object> publish(Integer id,HttpServletRequest request){
Survey param = surveyService.selectByPrimaryKey(id);
if(!Survey.state_exec.equals(param.getState())){
return MapControl.getInstance().error("操作失败,当前问卷未在执行中!").getMap();
}
String uuid = "/dy/"+UUID.randomUUID().toString();
Survey survey = new Survey();
survey.setId(id);
//http://localhost:8080/survey/ieieas-asdf-asdf-3-asd-f-asdf
String url = "http://"+request.getServerName()+ ":" + request.getServerPort() + request.getContextPath()+uuid;
survey.setUrl(url);
surveyService.updateByPrimaryKeySelective(survey);
return MapControl.getInstance().success().getMap();
}
@PostMapping("/submit")
@ResponseBody
public Map<String,Object> submit(@RequestBody List<Map<String,Object>> list){
List<AnswerOpt> optList = new ArrayList();
List<AnswerTxt> txtList = new ArrayList();
String uuid = UUID.randomUUID().toString();
for (Map<String, Object> stringObjectMap : list) {
if(object2String(stringObjectMap.get("type")).equals("1") || object2String(stringObjectMap.get("type")).equals("2")){
List<Object> opts = (List<Object>) stringObjectMap.get("opts");
for (Object opt : opts) {
AnswerOpt answerOpt = new AnswerOpt();
answerOpt.setQuestionId(object2Integer(stringObjectMap.get("questionId")));
answerOpt.setSurveyId(object2Integer(stringObjectMap.get("surveyId")));
answerOpt.setType(object2String(stringObjectMap.get("type")));
answerOpt.setOptId(object2Integer(opt));
answerOpt.setCreateTime(new Date());
answerOpt.setVoter(uuid);
optList.add(answerOpt);
}
}
if(object2String(stringObjectMap.get("type")).equals("3") || object2String(stringObjectMap.get("type")).equals("4")){
AnswerTxt answerTxt = new AnswerTxt();
answerTxt.setQuestionId(object2Integer(stringObjectMap.get("questionId")));
answerTxt.setSurveyId(object2Integer(stringObjectMap.get("surveyId")));
answerTxt.setResult(object2String(strin
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
javaWEB大作业问卷调查系统源代码。实现 用户登录,创建问卷(含单选,多选,简答),发布问卷,回答问卷,导出问卷,用户登录记录 技术 数据库:MySQL8.0 数据库设计软件:Power Designer16.5 IDE:IDEA Web容器:Apache Tomcat 8.5 项目管理工具:Maven 后端技术:Spring+Spring MVC+MyBatis(SSM框架) 前端技术:LayUI(Vue/React) 技术 数据库:MySQL8.0 数据库设计软件:Power Designer16.5 IDE:IDEA Web容器:Apache Tomcat 8.5 项目管理工具:Maven 后端技术:Spring+Spring MVC+MyBatis(SSM框架) 前端技术:LayUI(Vue/React)
资源推荐
资源详情
资源评论











收起资源包目录





































































































共 890 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9

张小妍的博客
- 粉丝: 1w+
- 资源: 2009
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
前往页