Search in sources :

Example 6 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class FileDownLoadController method download.

/**
 * 小组文件下载
 *
 * @param id
 *            图片在MongoDB中的id
 * @param groupId
 *            小组id
 * @param response
 *            服务响应
 * @return ResponseBean对象
 */
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "小组文件下载")
@RequestMapping(value = "/groupfile/download/{id}", method = RequestMethod.GET)
public ResponseBean download(@PathVariable("id") String id, @RequestParam("groupId") long groupId, HttpServletRequest request, HttpServletResponse response) {
    if (groupId < 1) {
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "小组id错误(负数或零)");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    GridFSDBFile file = fileService.get(id);
    if (null == file) {
        logger.warn("未找到id为'{}'的文件", id);
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "未找到对应文件");
    }
    String fileName = returnFileName(request, file.getFilename());
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    try (OutputStream out = response.getOutputStream()) {
        file.writeTo(out);
        out.flush();
        out.close();
        return new ResponseBean(groupFileService.updatePmphGroupFileOfDown(groupId, id));
    } catch (IOException ex) {
        logger.warn("文件下载时出现IO异常:{}", ex.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class FileDownLoadController method exportResultSchool.

/**
 * Description:申报结果统计页面按申报单位统计导出统计结果
 *
 * @author:lyc
 * @date:2018年1月9日上午11:16:01
 * @param
 * @return void
 */
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报结果统计页面按申报单位统计导出统计结果")
@RequestMapping(value = "/result/exportResultSchool", method = RequestMethod.GET)
public void exportResultSchool(Long materialId, String schoolName, Integer state, HttpServletRequest request, HttpServletResponse response) {
    PageParameter<DeclarationResultSchoolVO> pageParameter = new PageParameter<>(1, 50000);
    DeclarationResultSchoolVO declarationResultSchoolVO = new DeclarationResultSchoolVO();
    declarationResultSchoolVO.setMaterialId(materialId);
    declarationResultSchoolVO.setSchoolName(schoolName);
    pageParameter.setParameter(declarationResultSchoolVO);
    Workbook workbook = null;
    List<DeclarationResultSchoolVO> list = null;
    String sheetName = "";
    if (state.intValue() == 1) {
        list = decPositionService.listChosenDeclarationResultSchoolVOs(pageParameter).getRows();
        sheetName = "申报结果按单位统计(按当选数排序)";
    } else if (state.intValue() == 2) {
        list = decPositionService.listPresetDeclarationResultSchoolVOs(pageParameter).getRows();
        sheetName = "申报结果按单位统计(按申报数排序)";
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "未知的排序方式");
    }
    if (list.size() == 0) {
        list.add(new DeclarationResultSchoolVO());
    }
    try {
        workbook = excelHelper.fromBusinessObjectList(list, sheetName);
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    Material material = materialService.getMaterialById(materialId);
    String fileName = returnFileName(request, material.getMaterialName() + ".xls");
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    try (OutputStream out = response.getOutputStream()) {
        workbook.write(out);
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.warn("文件下载时出现IO异常: {}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) DeclarationResultSchoolVO(com.bc.pmpheep.back.vo.DeclarationResultSchoolVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) Workbook(org.apache.poi.ss.usermodel.Workbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class BookUserCommentController method list.

/**
 * 功能描述:分页初始化/模糊查询图书评论
 *
 * @param pageSize
 *            当页的数据条数
 * @param pageNumber
 *            当前页码
 * @param name
 *            数据名称/isbn
 * @param isAuth
 *            是否通过审核
 * @return
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "分页初始化/模糊查询图书评论")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseBean list(Integer pageSize, Integer pageNumber, String name, Integer isAuth, Boolean isLong) {
    PageParameter<BookUserCommentVO> pageParameter = new PageParameter<>(pageNumber, pageSize);
    BookUserCommentVO bookUserCommentVO = new BookUserCommentVO();
    bookUserCommentVO.setIsAuth(isAuth);
    // 去除空格
    bookUserCommentVO.setName(name.replaceAll(" ", ""));
    bookUserCommentVO.setIsLong(isLong);
    pageParameter.setParameter(bookUserCommentVO);
    return new ResponseBean(bookUserCommentService.listBookUserComment(pageParameter));
}
Also used : BookUserCommentVO(com.bc.pmpheep.back.vo.BookUserCommentVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class BookVideoController method addVideo.

@ResponseBody
@RequestMapping(value = "/addVideo", method = RequestMethod.POST)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "保存微视频信息")
public ResponseBean<Integer> addVideo(Long userId, Long bookId, String title, String origPath, String origFileName, Long origFileSize, String path, String fileName, Long fileSize, @RequestParam("cover") MultipartFile cover) throws IOException {
    BookVideo bookVideo = new BookVideo();
    bookVideo.setBookId(bookId);
    bookVideo.setTitle(title);
    bookVideo.setOrigPath(origPath);
    bookVideo.setOrigFileName(origFileName);
    bookVideo.setOrigFileSize(origFileSize);
    bookVideo.setPath(path);
    bookVideo.setFileName(fileName);
    bookVideo.setFileSize(fileSize);
    return new ResponseBean(bookVideoService.addBookVideoFront(userId, bookVideo, cover));
}
Also used : ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) BookVideo(com.bc.pmpheep.back.po.BookVideo) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with LogDetail

use of com.bc.pmpheep.annotation.LogDetail in project pmph by BCSquad.

the class BookVideoController method addBookVideo.

/**
 * 保存视频
 *
 * @param request
 * @param cover
 * @throws java.io.IOException
 * @introduction
 * @author Mryang
 * @createDate 2018年2月10日 下午5:34:12
 * @return
 */
@ResponseBody
@RequestMapping(value = "/addBookVideo", method = RequestMethod.POST)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "保存微视频信息")
public ResponseBean<Integer> addBookVideo(HttpServletRequest request, Long bookId, String title, String origPath, String origFileName, Long origFileSize, String path, String fileName, Long fileSize, @RequestParam("cover") MultipartFile cover) throws IOException {
    String sessionId = CookiesUtil.getSessionId(request);
    if (StringUtil.isEmpty(sessionId)) {
        return new ResponseBean(new CheckedServiceException(CheckedExceptionBusiness.BOOK_VEDIO, CheckedExceptionResult.USER_SESSION, "尚未登录或session已过期"));
    }
    BookVideo bookVideo = new BookVideo();
    bookVideo.setBookId(bookId);
    bookVideo.setTitle(title);
    bookVideo.setOrigPath(origPath);
    bookVideo.setOrigFileName(origFileName);
    bookVideo.setOrigFileSize(origFileSize);
    bookVideo.setPath(path);
    bookVideo.setFileName(fileName);
    bookVideo.setFileSize(fileSize);
    return new ResponseBean(bookVideoService.addBookVideo(sessionId, bookVideo, cover));
}
Also used : ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) BookVideo(com.bc.pmpheep.back.po.BookVideo) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogDetail (com.bc.pmpheep.annotation.LogDetail)83 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)82 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)61 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)43 IOException (java.io.IOException)28 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)24 OutputStream (java.io.OutputStream)18 BufferedOutputStream (java.io.BufferedOutputStream)17 Workbook (org.apache.poi.ss.usermodel.Workbook)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 ArrayList (java.util.ArrayList)7 Material (com.bc.pmpheep.back.po.Material)6 TopicLog (com.bc.pmpheep.back.po.TopicLog)5 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 BookVideo (com.bc.pmpheep.back.po.BookVideo)3 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)3 Topic (com.bc.pmpheep.back.po.Topic)3 DeclarationResultSchoolVO (com.bc.pmpheep.back.vo.DeclarationResultSchoolVO)3