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)
资源推荐
资源详情
资源评论
收起资源包目录
javaWEB期末课程大作业问卷调查系统源代码.zip (890个子文件)
SurveyController.class 14KB
SurveyController.class 14KB
Survey.class 9KB
Survey.class 9KB
Question.class 8KB
Question.class 8KB
QuestionServiceImpl.class 7KB
QuestionServiceImpl.class 7KB
SurveyServiceImpl.class 7KB
SurveyServiceImpl.class 7KB
AdminController.class 5KB
AdminController.class 5KB
BeanMapUtils.class 5KB
BeanMapUtils.class 5KB
AdminServiceImpl.class 4KB
AdminServiceImpl.class 4KB
QuestionOpt.class 4KB
QuestionOpt.class 4KB
AnswerOpt.class 4KB
AnswerOpt.class 4KB
Logtable.class 4KB
Logtable.class 4KB
AnswerTxt.class 4KB
AnswerTxt.class 4KB
Admin.class 4KB
Admin.class 4KB
MapControl.class 4KB
MapControl.class 4KB
QuestionController.class 3KB
QuestionController.class 3KB
Page.class 3KB
Page.class 3KB
LoginController.class 3KB
LoginController.class 3KB
DYController.class 3KB
DYController.class 3KB
LogController.class 3KB
LogController.class 3KB
MapParameter.class 2KB
MapParameter.class 2KB
LogAopAspect.class 2KB
LogAopAspect.class 2KB
IndexController.class 2KB
IndexController.class 2KB
SessionInterceptor.class 2KB
SessionInterceptor.class 2KB
myResultMap.class 2KB
myResultMap.class 2KB
LogtableServiceImpl.class 2KB
LogtableServiceImpl.class 2KB
SurveyDao.class 1KB
SurveyDao.class 1KB
QuestionService.class 1KB
QuestionService.class 1KB
SurveyService.class 1KB
SurveyService.class 1KB
SessionUtils.class 1KB
SessionUtils.class 1KB
DateConvert.class 1KB
DateConvert.class 1KB
ScheduleTask.class 947B
ScheduleTask.class 947B
QuestionDao.class 805B
QuestionDao.class 805B
QuestionOptDao.class 802B
QuestionOptDao.class 802B
AdminDao.class 720B
AdminDao.class 720B
AdminService.class 649B
AdminService.class 649B
AnswerOptDao.class 580B
AnswerOptDao.class 580B
LogtableDao.class 569B
LogtableDao.class 569B
LogAnno.class 439B
LogAnno.class 439B
AnswerTxtDao.class 403B
AnswerTxtDao.class 403B
LogtableService.class 322B
LogtableService.class 322B
test.class 237B
layui.css 82KB
layui.css 82KB
layui.css 71KB
layui.css 71KB
font-awesome.css 37KB
font-awesome.css 37KB
font-awesome.min.css 30KB
font-awesome.min.css 30KB
layuimini.css 20KB
layuimini.css 20KB
wangEditor.css 17KB
wangEditor.css 17KB
layer.css 15KB
layer.css 15KB
wangEditor.min.css 15KB
wangEditor.min.css 15KB
layer.css 14KB
layer.css 14KB
layui.mobile.css 11KB
共 890 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
程序员张小妍
- 粉丝: 1w+
- 资源: 3243
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 非常好的电子设计小软件GIF2BMP非常好用的软件.zip
- 非常好的电子设计小软件GIF Resize非常好用的软件.zip
- 非常好的电子设计小软件C2B转换助手 V1.1非常好用的软件.zip
- 非常好的电子设计小软件Axialis IconWorkshop(图标制作软件)非常好用的软件.zip
- 非常好的电子设计小软件amo的编程小工具集合非常好用的软件.zip
- 国家社科基金网站数据可视化展示-SSP.zip
- 技术资料分享信利4.3单芯片TFT1N4633-Ev1.0非常好的技术资料.zip
- 技术资料分享手机-SMS-PDU-格式参考手册非常好的技术资料.zip
- 技术资料分享Z-Stackapi函数非常好的技术资料.zip
- 技术资料分享Z-Stack-API-Chinese非常好的技术资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页