mirror of
https://gitee.com/wkeyuan/DWSurvey.git
synced 2024-12-01 19:49:01 +08:00
添加文件上传题
This commit is contained in:
parent
f7e597a2dc
commit
2b5acf7634
@ -29,11 +29,13 @@ public enum QuType {
|
||||
CHENCHECKBOX("矩阵多选题","chen-checkbox", 13),
|
||||
COMPCHENRADIO("复合矩阵单选题","comp-chen-radio", 14),
|
||||
|
||||
UPLOADFILE("文件上传题","sendfile",15),
|
||||
PAGETAG("分页标记","pagetag",16),
|
||||
PARAGRAPH("段落说明","paragraph",17),
|
||||
CHENSCORE("矩阵评分题","chen-score", 18);
|
||||
|
||||
|
||||
|
||||
private String cnName;
|
||||
private String actionName;
|
||||
private int index;
|
||||
|
@ -0,0 +1,312 @@
|
||||
package net.diaowen.dwsurvey.controller.question;
|
||||
|
||||
import net.diaowen.common.CheckType;
|
||||
import net.diaowen.common.QuType;
|
||||
import net.diaowen.common.plugs.page.Page;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
import net.diaowen.dwsurvey.entity.QuestionLogic;
|
||||
import net.diaowen.dwsurvey.service.AnUploadFileManager;
|
||||
import net.diaowen.dwsurvey.service.QuestionManager;
|
||||
import net.diaowen.dwsurvey.service.SurveyDirectoryManager;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 填空题 action
|
||||
* @author KeYuan(keyuan258@gmail.com)
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/api/dwsurvey/app/design/qu-upload-file")
|
||||
public class QuUploadFileController {
|
||||
@Autowired
|
||||
private QuestionManager questionManager;
|
||||
@Autowired
|
||||
private AnUploadFileManager anUploadFileManager;
|
||||
@Autowired
|
||||
private SurveyDirectoryManager surveyDirectoryManager;
|
||||
|
||||
@RequestMapping("/ajaxSave.do")
|
||||
public String ajaxSave(HttpServletRequest request,HttpServletResponse response) throws Exception {
|
||||
try{
|
||||
Question entity=ajaxBuildSaveOption(request);
|
||||
questionManager.save(entity);
|
||||
String resultJson=buildResultJson(entity);
|
||||
response.getWriter().write(resultJson);
|
||||
//返回各部分ID
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
response.getWriter().write("error");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Question ajaxBuildSaveOption(HttpServletRequest request) throws UnsupportedEncodingException {
|
||||
String quId=request.getParameter("quId");
|
||||
String belongId=request.getParameter("belongId");
|
||||
String quTitle=request.getParameter("quTitle");
|
||||
String orderById=request.getParameter("orderById");
|
||||
String tag=request.getParameter("tag");
|
||||
//isRequired 是否必选
|
||||
String isRequired=request.getParameter("isRequired");
|
||||
|
||||
String answerInputWidth=request.getParameter("answerInputWidth");
|
||||
String answerInputRow=request.getParameter("answerInputRow");
|
||||
|
||||
String contactsAttr=request.getParameter("contactsAttr");
|
||||
String contactsField=request.getParameter("contactsField");
|
||||
|
||||
String checkType=request.getParameter("checkType");
|
||||
String paramInt01=request.getParameter("paramInt01");//上传文件类型
|
||||
String paramInt02=request.getParameter("paramInt02");
|
||||
|
||||
/** 某一类型题目特有的 **/
|
||||
//hv 1水平显示 2垂直显示
|
||||
String hv=request.getParameter("hv");
|
||||
//randOrder 选项随机排列
|
||||
String randOrder=request.getParameter("randOrder");
|
||||
String cellCount=request.getParameter("cellCount");
|
||||
|
||||
if("".equals(quId)){
|
||||
quId=null;
|
||||
}
|
||||
Question entity=questionManager.getModel(quId);
|
||||
entity.setBelongId(belongId);
|
||||
if(quTitle!=null){
|
||||
quTitle=URLDecoder.decode(quTitle,"utf-8");
|
||||
entity.setQuTitle(quTitle);
|
||||
}
|
||||
|
||||
String quNote = request.getParameter("quNote");
|
||||
if(quNote!=null){
|
||||
quNote=URLDecoder.decode(quNote,"utf-8");
|
||||
entity.setQuNote(quNote);
|
||||
}
|
||||
|
||||
entity.setOrderById(Integer.parseInt(orderById));
|
||||
entity.setTag(Integer.parseInt(tag));
|
||||
entity.setQuType(QuType.UPLOADFILE);
|
||||
//参数
|
||||
isRequired=(isRequired==null || "".equals(isRequired))?"0":isRequired;
|
||||
hv=(hv==null || "".equals(hv))?"0":hv;
|
||||
randOrder=(randOrder==null || "".equals(randOrder))?"0":randOrder;
|
||||
cellCount=(cellCount==null || "".equals(cellCount))?"0":cellCount;
|
||||
paramInt01=(paramInt01==null || "".equals(paramInt01))?"0":paramInt01;
|
||||
paramInt02=(paramInt02==null || "".equals(paramInt02))?"10":paramInt02;
|
||||
|
||||
|
||||
contactsAttr=(contactsAttr==null || "".equals(contactsAttr))?"0":contactsAttr;
|
||||
entity.setContactsAttr(Integer.parseInt(contactsAttr));
|
||||
entity.setContactsField(contactsField);
|
||||
|
||||
answerInputWidth=(answerInputWidth==null || "".equals(answerInputWidth))?"300":answerInputWidth;
|
||||
answerInputRow=(answerInputRow==null || "".equals(answerInputRow))?"1":answerInputRow;
|
||||
entity.setAnswerInputWidth(Integer.parseInt(answerInputWidth));
|
||||
entity.setAnswerInputRow(Integer.parseInt(answerInputRow));
|
||||
|
||||
entity.setIsRequired(Integer.parseInt(isRequired));
|
||||
entity.setHv(Integer.parseInt(hv));
|
||||
entity.setRandOrder(Integer.parseInt(randOrder));
|
||||
entity.setCellCount(Integer.parseInt(cellCount));
|
||||
entity.setParamInt01(Integer.parseInt(paramInt01));
|
||||
entity.setParamInt02(Integer.parseInt(paramInt02));
|
||||
|
||||
checkType=(checkType==null || "".equals(checkType))?"NO":checkType;
|
||||
entity.setCheckType(CheckType.valueOf(checkType));
|
||||
|
||||
//逻辑选项设置
|
||||
Map<String, Object> quLogicIdMap=WebUtils.getParametersStartingWith(request, "quLogicId_");
|
||||
List<QuestionLogic> quLogics=new ArrayList<QuestionLogic>();
|
||||
for (String key : quLogicIdMap.keySet()) {
|
||||
String cgQuItemId=request.getParameter("cgQuItemId_"+key);
|
||||
String skQuId=request.getParameter("skQuId_"+key);
|
||||
String visibility=request.getParameter("visibility_"+key);
|
||||
String logicType=request.getParameter("logicType_"+key);
|
||||
Object quLogicId=quLogicIdMap.get(key);
|
||||
String quLogicIdValue=(quLogicId!=null)?quLogicId.toString():"";
|
||||
|
||||
QuestionLogic quLogic=new QuestionLogic();
|
||||
if("".equals(quLogic)){
|
||||
quLogic=null;
|
||||
}
|
||||
quLogic.setId(quLogicIdValue);
|
||||
quLogic.setCgQuItemId(cgQuItemId);
|
||||
quLogic.setSkQuId(skQuId);
|
||||
quLogic.setVisibility(Integer.parseInt(visibility));
|
||||
quLogic.setTitle(key);
|
||||
quLogic.setLogicType(logicType);
|
||||
quLogics.add(quLogic);
|
||||
}
|
||||
entity.setQuestionLogics(quLogics);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static String buildResultJson(Question entity){
|
||||
//{id:'null',quItems:[{id:'null',title:'null'},{id:'null',title:'null'}]}
|
||||
StringBuffer strBuf=new StringBuffer();
|
||||
strBuf.append("{id:'").append(entity.getId());
|
||||
strBuf.append("',orderById:");
|
||||
strBuf.append(entity.getOrderById());
|
||||
|
||||
strBuf.append(",quLogics:[");
|
||||
List<QuestionLogic> questionLogics=entity.getQuestionLogics();
|
||||
if(questionLogics!=null){
|
||||
for (QuestionLogic questionLogic : questionLogics) {
|
||||
strBuf.append("{id:'").append(questionLogic.getId());
|
||||
strBuf.append("',title:'").append(questionLogic.getTitle()).append("'},");
|
||||
}
|
||||
}
|
||||
int strLen=strBuf.length();
|
||||
if(strBuf.lastIndexOf(",")==(strLen-1)){
|
||||
strBuf.replace(strLen-1, strLen, "");
|
||||
}
|
||||
strBuf.append("]}");
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
|
||||
//取上传题结果
|
||||
@RequestMapping("/answers.do")
|
||||
public ModelAndView answers(Page<AnUplodFile> anPage, String quId, String surveyId) throws Exception {
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
anPage.setPageSize(10000);
|
||||
Criterion cri1 = Restrictions.eq("quId",quId);
|
||||
anPage = anUploadFileManager.findPage(anPage, cri1);
|
||||
modelAndView.addObject("anPage",anPage);
|
||||
modelAndView.addObject("directory",surveyDirectoryManager.get(surveyId));
|
||||
modelAndView.addObject("surveyId",surveyId);
|
||||
modelAndView.setViewName("/diaowen-da/upload-files");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@RequestMapping("/download.do")
|
||||
public String download(HttpServletRequest request,HttpServletResponse response,String id) throws Exception {
|
||||
String anuploadId = id;
|
||||
AnUplodFile anUplodFile = anUploadFileManager.getModel(anuploadId);
|
||||
//设置Content-Disposition
|
||||
//response.sendRedirect(request.getContextPath()+anUplodFile.getFilePath());
|
||||
String fileName =anUplodFile.getFileName();
|
||||
String rootPath = request.getServletContext().getRealPath("/");
|
||||
String filePath = anUplodFile.getFilePath().replaceAll("\\\\", File.separator);
|
||||
filePath = filePath.replaceAll("/", File.separator);
|
||||
File file = new File(rootPath+filePath);
|
||||
//如果文件不存在
|
||||
if(!file.exists()){
|
||||
request.setAttribute("message", "您要下载的资源已被删除!!");
|
||||
request.getRequestDispatcher("/message.jsp").forward(request, response);
|
||||
return null;
|
||||
}
|
||||
//处理文件名
|
||||
fileName=fileName.replaceAll("\\+","");
|
||||
fileName=anUplodFile.getRandomCode()+"-"+fileName;
|
||||
//设置响应头,控制浏览器下载该文件
|
||||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
//读取要下载的文件,保存到文件输入流
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
//创建输出流
|
||||
OutputStream out = response.getOutputStream();
|
||||
//创建缓冲区
|
||||
byte buffer[] = new byte[1024];
|
||||
int len = 0;
|
||||
//循环将输入流中的内容读取到缓冲区当中
|
||||
while((len=in.read(buffer))>0){
|
||||
//输出缓冲区的内容到浏览器,实现文件下载
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
//关闭文件输入流
|
||||
in.close();
|
||||
//关闭输出流
|
||||
out.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//批量打包下载 -- //只打包当前页的
|
||||
/*
|
||||
* 批量下载另存为
|
||||
*/
|
||||
@RequestMapping("/batDownload.do")
|
||||
public String batDownload(HttpServletRequest request,HttpServletResponse response,Page<AnUplodFile> anPage,String quId) throws IOException {
|
||||
Criterion cri1 = Restrictions.eq("quId",quId);
|
||||
anPage = anUploadFileManager.findPage(anPage, cri1);
|
||||
|
||||
String tmpFileName = "ga_"+quId+".zip";
|
||||
byte[] buffer = new byte[1024];
|
||||
String rootPath = request.getServletContext().getRealPath("/upload/work/");
|
||||
File dir = new File(rootPath);
|
||||
if(!dir.exists()){
|
||||
dir.mkdirs();
|
||||
}
|
||||
String strZipPath = request.getServletContext().getRealPath("/upload/work/"+tmpFileName);
|
||||
try {
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(strZipPath));
|
||||
List<AnUplodFile> result = anPage.getResult();
|
||||
// 下载的文件集合
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
AnUplodFile anUplodFile = result.get(i);
|
||||
FileInputStream fis = new FileInputStream(request.getServletContext().getRealPath(anUplodFile.getFilePath()));
|
||||
out.putNextEntry(new ZipEntry(anUplodFile.getRandomCode()+"-"+anUplodFile.getFileName()));
|
||||
//设置压缩文件内的字符编码,不然会变成乱码
|
||||
// out.setComment();
|
||||
int len;
|
||||
// 读入需要下载的文件的内容,打包到zip文件
|
||||
while ((len = fis.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
out.closeEntry();
|
||||
fis.close();
|
||||
}
|
||||
out.close();
|
||||
//saveAs("work/"+tmpFileName, tmpFileName);
|
||||
|
||||
//设置响应头,控制浏览器下载该文件
|
||||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(tmpFileName, "UTF-8"));
|
||||
//读取要下载的文件,保存到文件输入流
|
||||
FileInputStream in = new FileInputStream(new File(strZipPath));
|
||||
//创建输出流
|
||||
OutputStream respOut = response.getOutputStream();
|
||||
//创建缓冲区
|
||||
byte respBuffer[] = new byte[1024];
|
||||
int len = 0;
|
||||
//循环将输入流中的内容读取到缓冲区当中
|
||||
while((len=in.read(buffer))>0){
|
||||
//输出缓冲区的内容到浏览器,实现文件下载
|
||||
respOut.write(buffer, 0, len);
|
||||
}
|
||||
respOut.flush();
|
||||
//关闭文件输入流
|
||||
in.close();
|
||||
//关闭输出流
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.getWriter().write("批量导出异常!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -7,10 +7,13 @@ import net.diaowen.common.plugs.httpclient.PageResult;
|
||||
import net.diaowen.common.plugs.httpclient.ResultUtils;
|
||||
import net.diaowen.common.plugs.page.Page;
|
||||
import net.diaowen.common.utils.UserAgentUtils;
|
||||
import net.diaowen.common.utils.ZipUtil;
|
||||
import net.diaowen.dwsurvey.config.DWSurveyConfig;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
import net.diaowen.dwsurvey.entity.SurveyAnswer;
|
||||
import net.diaowen.dwsurvey.entity.SurveyDirectory;
|
||||
import net.diaowen.dwsurvey.service.AnUploadFileManager;
|
||||
import net.diaowen.dwsurvey.service.SurveyAnswerManager;
|
||||
import net.diaowen.dwsurvey.service.SurveyDirectoryManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -23,6 +26,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -36,6 +40,8 @@ public class MySurveyAnswerController {
|
||||
private SurveyAnswerManager surveyAnswerManager;
|
||||
@Autowired
|
||||
private AccountManager accountManager;
|
||||
@Autowired
|
||||
private AnUploadFileManager anUploadFileManager;
|
||||
/**
|
||||
* 获取答卷列表
|
||||
* @return
|
||||
@ -127,10 +133,30 @@ public class MySurveyAnswerController {
|
||||
if(!user.getId().equals(survey.getUserId())){
|
||||
return "没有相应数据权限";
|
||||
}
|
||||
//直接导出excel
|
||||
savePath=surveyAnswerManager.exportXLS(surveyId,savePath);
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode("dwsurvey_"+survey.getSid()+".xlsx", "UTF-8"));
|
||||
request.getRequestDispatcher(savePath).forward(request,response);
|
||||
List<AnUplodFile> anUplodFiles = anUploadFileManager.findAnswer(surveyId);
|
||||
if(anUplodFiles!=null && anUplodFiles.size()>0 && expUpQu!=null && "1".equals(expUpQu)){
|
||||
//直接导出excel,不存在上传文件的问题
|
||||
savePath = surveyAnswerManager.exportXLS(surveyId,savePath,true);
|
||||
//启用压缩导出
|
||||
String fromPath =DWSurveyConfig.DWSURVEY_WEB_FILE_PATH+"/webin/expfile/"+surveyId;
|
||||
fromPath = fromPath.replace("/", File.separator);
|
||||
|
||||
String zipPath = DWSurveyConfig.DWSURVEY_WEB_FILE_PATH+"/webin/zip/".replace("/", File.separator);
|
||||
File file = new File(zipPath);
|
||||
if (!file.exists())
|
||||
file.mkdirs();
|
||||
|
||||
String toPath = zipPath+surveyId + ".zip";
|
||||
toPath = toPath.replace("/",File.separator);
|
||||
ZipUtil.createZip(fromPath, toPath, false);
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode("dwsurvey_"+survey.getSid()+".zip", "UTF-8"));
|
||||
request.getRequestDispatcher("/webin/zip/"+ surveyId + ".zip").forward(request,response);
|
||||
}else{
|
||||
//直接导出excel,不存在上传文件的问题
|
||||
savePath=surveyAnswerManager.exportXLS(surveyId,savePath, false);
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode("dwsurvey_"+survey.getSid()+".xlsx", "UTF-8"));
|
||||
request.getRequestDispatcher(savePath).forward(request,response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
|
19
src/main/java/net/diaowen/dwsurvey/dao/AnUploadFileDao.java
Executable file
19
src/main/java/net/diaowen/dwsurvey/dao/AnUploadFileDao.java
Executable file
@ -0,0 +1,19 @@
|
||||
package net.diaowen.dwsurvey.dao;
|
||||
|
||||
import net.diaowen.common.dao.BaseDao;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
|
||||
/**
|
||||
* 填空题 interface
|
||||
* @author KeYuan(keyuan258@gmail.com)
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*
|
||||
*/
|
||||
public interface AnUploadFileDao extends BaseDao<AnUplodFile, String> {
|
||||
|
||||
public void findGroupStats(Question question);
|
||||
|
||||
}
|
30
src/main/java/net/diaowen/dwsurvey/dao/impl/AnUploadFileDaoImpl.java
Executable file
30
src/main/java/net/diaowen/dwsurvey/dao/impl/AnUploadFileDaoImpl.java
Executable file
@ -0,0 +1,30 @@
|
||||
package net.diaowen.dwsurvey.dao.impl;
|
||||
|
||||
import net.diaowen.common.dao.BaseDaoImpl;
|
||||
import net.diaowen.dwsurvey.dao.AnUploadFileDao;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 填空 dao
|
||||
* @author keyuan(keyuan258@gmail.com)
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public class AnUploadFileDaoImpl extends BaseDaoImpl<AnUplodFile, String> implements AnUploadFileDao {
|
||||
|
||||
@Override
|
||||
public void findGroupStats(Question question) {
|
||||
String sql="select count(case when file_path='' then file_path end) emptyCount, count(case when file_path!='' then file_path end) blankCount from t_an_uplodfile where visibility=1 and qu_id=?";
|
||||
Object[] objs=(Object[]) this.getSession().createSQLQuery(sql).setParameter(1, question.getId()).uniqueResult();
|
||||
|
||||
question.setRowContent(objs[0].toString());//未回答数
|
||||
question.setOptionContent(objs[1].toString());//回答的项数
|
||||
question.setAnCount(Integer.parseInt(objs[1].toString()));
|
||||
}
|
||||
|
||||
}
|
96
src/main/java/net/diaowen/dwsurvey/entity/AnUplodFile.java
Executable file
96
src/main/java/net/diaowen/dwsurvey/entity/AnUplodFile.java
Executable file
@ -0,0 +1,96 @@
|
||||
package net.diaowen.dwsurvey.entity;
|
||||
|
||||
import net.diaowen.common.base.entity.IdEntity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 答卷 多选题保存表
|
||||
* @author keyuan
|
||||
* @date 2012-10-21下午9:26:43
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="t_an_uplodfile")
|
||||
public class AnUplodFile extends IdEntity {
|
||||
|
||||
//所属问卷ID
|
||||
private String belongId;
|
||||
//对应的答卷信息表
|
||||
private String belongAnswerId;
|
||||
//题目 ID
|
||||
private String quId;
|
||||
//文件地址
|
||||
private String filePath;
|
||||
//文件名称
|
||||
private String fileName;
|
||||
//随机码
|
||||
private String randomCode;
|
||||
|
||||
private Integer visibility=1;
|
||||
|
||||
public AnUplodFile(){
|
||||
|
||||
}
|
||||
public AnUplodFile(String surveyId, String surveyAnswerId, String quId,
|
||||
String filePath, String fileName, String randomCode) {
|
||||
this.belongId=surveyId;
|
||||
this.belongAnswerId=surveyAnswerId;
|
||||
this.quId=quId;
|
||||
this.filePath=filePath;
|
||||
this.fileName=fileName;
|
||||
this.randomCode = randomCode;
|
||||
}
|
||||
public String getBelongId() {
|
||||
return belongId;
|
||||
}
|
||||
public void setBelongId(String belongId) {
|
||||
this.belongId = belongId;
|
||||
}
|
||||
public String getBelongAnswerId() {
|
||||
return belongAnswerId;
|
||||
}
|
||||
public void setBelongAnswerId(String belongAnswerId) {
|
||||
this.belongAnswerId = belongAnswerId;
|
||||
}
|
||||
public String getQuId() {
|
||||
return quId;
|
||||
}
|
||||
public void setQuId(String quId) {
|
||||
this.quId = quId;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public Integer getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
public void setVisibility(Integer visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public String getRandomCode() {
|
||||
return randomCode;
|
||||
}
|
||||
|
||||
public void setRandomCode(String randomCode) {
|
||||
this.randomCode = randomCode;
|
||||
}
|
||||
}
|
@ -268,6 +268,7 @@ public class Question extends IdEntity{
|
||||
private List<AnScore> anScores=new ArrayList<AnScore>();
|
||||
private Integer anCount=0;
|
||||
private List<AnOrder> anOrders = new ArrayList<AnOrder>();
|
||||
private List<AnUplodFile> anUplodFiles=new ArrayList<AnUplodFile>();
|
||||
|
||||
//逻辑设置
|
||||
private List<QuestionLogic> questionLogics;
|
||||
@ -422,6 +423,15 @@ public class Question extends IdEntity{
|
||||
this.anOrders = anOrders;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public List<AnUplodFile> getAnUplodFiles() {
|
||||
return anUplodFiles;
|
||||
}
|
||||
|
||||
public void setAnUplodFiles(List<AnUplodFile> anUplodFiles) {
|
||||
this.anUplodFiles = anUplodFiles;
|
||||
}
|
||||
|
||||
//统计json
|
||||
public String statJson="";
|
||||
@Transient
|
||||
|
24
src/main/java/net/diaowen/dwsurvey/service/AnUploadFileManager.java
Executable file
24
src/main/java/net/diaowen/dwsurvey/service/AnUploadFileManager.java
Executable file
@ -0,0 +1,24 @@
|
||||
package net.diaowen.dwsurvey.service;
|
||||
|
||||
import net.diaowen.common.service.BaseService;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 填空题
|
||||
* @author keyuan(keyuan258@gmail.com)
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*/
|
||||
public interface AnUploadFileManager extends BaseService<AnUplodFile, String> {
|
||||
|
||||
public List<AnUplodFile> findAnswer(String belongAnswerId, String quId);
|
||||
|
||||
public void findGroupStats(Question question);
|
||||
|
||||
public List<AnUplodFile> findAnswer(String belongAnswerId);
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ public interface SurveyAnswerManager extends BaseService<SurveyAnswer, String>{
|
||||
|
||||
public Long getCountByIp(String surveyId, String ip);
|
||||
|
||||
public String exportXLS(String surveyId, String savePath);
|
||||
public String exportXLS(String surveyId, String savePath, boolean isExpUpQu);
|
||||
|
||||
public SurveyStats surveyStatsData(SurveyStats surveyStats);
|
||||
|
||||
|
52
src/main/java/net/diaowen/dwsurvey/service/impl/AnUploadFileManagerImpl.java
Executable file
52
src/main/java/net/diaowen/dwsurvey/service/impl/AnUploadFileManagerImpl.java
Executable file
@ -0,0 +1,52 @@
|
||||
package net.diaowen.dwsurvey.service.impl;
|
||||
|
||||
import net.diaowen.common.service.BaseServiceImpl;
|
||||
import net.diaowen.dwsurvey.dao.AnUploadFileDao;
|
||||
import net.diaowen.dwsurvey.entity.AnUplodFile;
|
||||
import net.diaowen.dwsurvey.entity.Question;
|
||||
import net.diaowen.dwsurvey.service.AnUploadFileManager;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 填空题
|
||||
* @author keyuan(keyuan258@gmail.com)
|
||||
*
|
||||
* https://github.com/wkeyuan/DWSurvey
|
||||
* http://dwsurvey.net
|
||||
*/
|
||||
@Service
|
||||
public class AnUploadFileManagerImpl extends BaseServiceImpl<AnUplodFile, String> implements AnUploadFileManager {
|
||||
|
||||
@Autowired
|
||||
private AnUploadFileDao anUploadFileDao;
|
||||
|
||||
@Override
|
||||
public void setBaseDao() {
|
||||
this.baseDao=anUploadFileDao;
|
||||
}
|
||||
|
||||
//根据exam_user信息查询答案
|
||||
public List<AnUplodFile> findAnswer(String belongAnswerId, String quId){
|
||||
//belongAnswerId quId
|
||||
Criterion criterion1=Restrictions.eq("belongAnswerId", belongAnswerId);
|
||||
Criterion criterion2=Restrictions.eq("quId", quId);
|
||||
return anUploadFileDao.find(criterion1,criterion2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findGroupStats(Question question) {
|
||||
anUploadFileDao.findGroupStats(question);
|
||||
}
|
||||
|
||||
public List<AnUplodFile> findAnswer(String surveyId){
|
||||
//belongAnswerId quId
|
||||
Criterion criterion1=Restrictions.eq("belongId", surveyId);
|
||||
return anUploadFileDao.find(criterion1);
|
||||
}
|
||||
|
||||
}
|
@ -7,9 +7,11 @@ import net.diaowen.common.service.BaseServiceImpl;
|
||||
import net.diaowen.common.utils.RunAnswerUtil;
|
||||
import net.diaowen.common.utils.excel.XLSXExportUtil;
|
||||
import net.diaowen.common.utils.parsehtml.HtmlUtil;
|
||||
import net.diaowen.dwsurvey.config.DWSurveyConfig;
|
||||
import net.diaowen.dwsurvey.dao.SurveyAnswerDao;
|
||||
import net.diaowen.dwsurvey.entity.*;
|
||||
import net.diaowen.dwsurvey.service.*;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@ -205,7 +208,7 @@ public class SurveyAnswerManagerImpl extends
|
||||
|
||||
|
||||
@Override
|
||||
public String exportXLS(String surveyId, String savePath) {
|
||||
public String exportXLS(String surveyId, String savePath, boolean isExpUpQu) {
|
||||
String basepath = surveyId + "";
|
||||
String urlPath = "/webin/expfile/" + basepath + "/";// 下载所用的地址
|
||||
String path = urlPath.replace("/", File.separator);// 文件系统路径
|
||||
@ -236,7 +239,7 @@ public class SurveyAnswerManagerImpl extends
|
||||
SurveyAnswer surveyAnswer = answers.get(j);
|
||||
String surveyAnswerId = surveyAnswer.getId();
|
||||
exportUtil.createRow(j+1);
|
||||
exportXLSRow(exportUtil, surveyAnswerId, questions, surveyAnswer);
|
||||
exportXLSRow(exportUtil, surveyAnswerId, questions, surveyAnswer, (j+1), savePath, isExpUpQu);
|
||||
}
|
||||
exportUtil.exportXLS();
|
||||
} catch (Exception e) {
|
||||
@ -245,14 +248,16 @@ public class SurveyAnswerManagerImpl extends
|
||||
return urlPath + fileName;
|
||||
}
|
||||
|
||||
private void exportXLSRow(XLSXExportUtil exportUtil,String surveyAnswerId, List<Question> questions,SurveyAnswer surveyAnswer) {
|
||||
private void exportXLSRow(XLSXExportUtil exportUtil,String surveyAnswerId, List<Question> questions,SurveyAnswer surveyAnswer,int orderNum, String savePath, boolean isExpUpQu) {
|
||||
new RunAnswerUtil().getQuestionMap(questions,surveyAnswerId);
|
||||
int cellIndex = 0;
|
||||
int quNum=0;
|
||||
for (Question question : questions) {
|
||||
QuType quType = question.getQuType();
|
||||
if(quType==QuType.PAGETAG || quType==QuType.PARAGRAPH){
|
||||
continue;
|
||||
}
|
||||
quNum++;
|
||||
String quName = question.getQuName();
|
||||
String titleName = quType.getCnName();
|
||||
if (quType == QuType.YESNO) {// 是非题
|
||||
@ -422,6 +427,36 @@ public class SurveyAnswerManagerImpl extends
|
||||
}
|
||||
exportUtil.setCell(cellIndex++, answerScore);
|
||||
}
|
||||
}else if (quType == QuType.UPLOADFILE) {
|
||||
//为导出文件
|
||||
String upFilePath = File.separator + "webin" + File.separator + "upload" + File.separator;
|
||||
List<AnUplodFile> anUplodFiles = question.getAnUplodFiles();
|
||||
String answerBuf = "";
|
||||
|
||||
String toFilePath = "";
|
||||
if(isExpUpQu){
|
||||
// String toFilePath = savePath+File.separator+orderNum+File.separator+HtmlUtil.removeTagFromText(titleName);
|
||||
// String toFilePath = savePath + File.separator + orderNum + File.separator + quNum + "_" + HtmlUtil.removeTagFromText(titleName);
|
||||
toFilePath = savePath + File.separator + orderNum + File.separator + "Q_" + quNum;
|
||||
File file = new File(toFilePath);
|
||||
if (!file.exists()) file.mkdirs();
|
||||
}
|
||||
for (AnUplodFile anUplodFile : anUplodFiles) {
|
||||
answerBuf += anUplodFile.getFileName() + " ";
|
||||
if(isExpUpQu){
|
||||
File fromFile = new File(DWSurveyConfig.DWSURVEY_WEB_FILE_PATH + anUplodFile.getFilePath());
|
||||
if (fromFile.exists()) {
|
||||
File toFile = new File(toFilePath + File.separator + anUplodFile.getFileName());
|
||||
try {
|
||||
FileUtil.copyFile(fromFile, toFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// answerBuf=answerBuf.substring(0,answerBuf.lastIndexOf(" "));
|
||||
exportUtil.setCell(cellIndex++, answerBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user