Search in sources :

Example 71 with LogDetail

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

the class MaterialController method getTempFile.

/**
 * 获取临时文件
 *
 * @param tempId
 * @param response 服务响应
 */
@LogDetail(businessType = Business_Type, logRemark = "获取临时文件")
@RequestMapping(value = "getTempFile", method = RequestMethod.GET)
public void getTempFile(String tempFileId, HttpServletRequest request, HttpServletResponse response) {
    byte[] fileByte = (byte[]) request.getSession(false).getAttribute(tempFileId);
    response.setContentType("image/png");
    try (OutputStream out = response.getOutputStream()) {
        out.write(fileByte, 0, fileByte.length);
        out.flush();
        out.close();
    } catch (IOException ex) {
        logger.error("文件下载时出现IO异常:{}", ex.getMessage());
    } catch (Exception ex) {
        logger.warn("图片查看时出现异常:{}", ex.getMessage());
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) IOException(java.io.IOException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with LogDetail

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

the class MaterialController method update.

/**
 * 更新遴选公告
 *
 * @param sessionId
 * @param material
 *            教材对象
 * @param materialContacts
 *            多个教材联系人
 * @param materialExtensions
 *            多个教材扩展项
 * @param MaterialProjectEditors
 *            多个教材扩项目编辑
 * @param materialExtra
 *            教材通知备
 * @param materialNoticeAttachments
 *            多个教材通知
 * @param noticeFiles
 *            通知文件
 * @param materialNoteAttachments
 *            多个教材备注
 * @param noteFiles
 *            备注文件
 * @return
 */
@ResponseBody
@LogDetail(businessType = Business_Type, logRemark = "修改遴选公告")
@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResponseBean update(MaterialVO materialVO, HttpServletRequest request, // MultipartFile[] noteFiles,
String deadline, String actualDeadline, String ageDeadline) {
    try {
        materialVO.getMaterial().setDeadline(DateUtil.str3Date(deadline));
        materialVO.getMaterial().setActualDeadline(DateUtil.str3Date(actualDeadline));
        materialVO.getMaterial().setAgeDeadline(DateUtil.str3Date(ageDeadline));
        return new ResponseBean(materialService.addOrUpdateMaterial(request, materialVO, // noteFiles,
        true));
    } catch (IOException e) {
        ResponseBean responseBean = new ResponseBean(e);
        responseBean.setData("上传文件失败");
        return responseBean;
    } catch (Exception e) {
        ResponseBean responseBean = new ResponseBean(e);
        responseBean.setData(e.getMessage());
        return responseBean;
    }
}
Also used : ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) IOException(java.io.IOException) IOException(java.io.IOException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with LogDetail

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

the class MaterialExtraController method history.

/**
 * <pre>
 * 功能描述:查询历史教材通知列表
 * 使用示范:
 *
 * @param pageNumber 当前页数
 * @param pageSize 当前页条数
 * @param request
 * @return
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSINESS_TYPE, logRemark = "查询历史教材通知列表")
@RequestMapping(value = "/history", method = RequestMethod.GET)
public ResponseBean history(@RequestParam(name = "pageNumber", defaultValue = "1") Integer pageNumber, @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize, HttpServletRequest request) {
    PageParameter<MateriaHistorylVO> pageParameter = new PageParameter<>(pageNumber, pageSize);
    MateriaHistorylVO materiaHistorylVO = new MateriaHistorylVO();
    pageParameter.setParameter(materiaHistorylVO);
    String sessionId = CookiesUtil.getSessionId(request);
    return new ResponseBean(materialExtraService.listMaterialHistory(pageParameter, sessionId));
}
Also used : MateriaHistorylVO(com.bc.pmpheep.back.vo.MateriaHistorylVO) 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 74 with LogDetail

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

the class OrgController method excel.

@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "解析批量导入的发布学校数据")
@RequestMapping(value = "/orgExport", method = RequestMethod.POST)
public ResponseBean excel(MultipartFile file, HttpServletRequest req) {
    if (null == file || file.isEmpty()) {
        return new ResponseBean("没有文件");
    }
    // 文件名称
    String name = file.getOriginalFilename();
    // 文件类型
    String fileType = name.substring(name.lastIndexOf("."));
    InputStream in = null;
    try {
        in = file.getInputStream();
    } catch (FileNotFoundException e) {
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未获取到文件");
    } catch (Exception e) {
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未知异常");
    }
    Workbook workbook = null;
    try {
        if ((".xls").equals(fileType)) {
            workbook = new HSSFWorkbook(in);
        } else if ((".xlsx").equals(fileType)) {
            workbook = new XSSFWorkbook(in);
        } else {
            if (null != in) {
                try {
                    in.close();
                } catch (Exception ee) {
                } finally {
                    in = null;
                }
            }
            return new ResponseBean("读取的不是Excel文件");
        }
    } catch (IOException e) {
        if (null != workbook) {
            try {
                workbook.close();
            } catch (Exception ee) {
            } finally {
                workbook = null;
            }
        }
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("读取文件异常");
    } catch (Exception e) {
        if (null != workbook) {
            try {
                workbook.close();
            } catch (Exception ee) {
            } finally {
                workbook = null;
            }
        }
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未知异常");
    }
    // sheet数目
    // int sheetTotal = workbook.getNumberOfSheets() ;
    Sheet sheet = workbook.getSheetAt(0);
    List<Org> orgs = new ArrayList<Org>(sheet.getLastRowNum());
    List<String> erros = new ArrayList<String>(sheet.getLastRowNum());
    for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
        Row row = sheet.getRow(rowNum);
        if (null == row) {
            continue;
        }
        Cell cell1 = row.getCell(0);
        Cell cell2 = row.getCell(1);
        Cell cell3 = row.getCell(2);
        String value1 = StringUtil.getCellValue(cell1);
        String value2 = StringUtil.getCellValue(cell2);
        String value3 = StringUtil.getCellValue(cell3);
        if (StringUtil.notEmpty(value2) && StringUtil.notEmpty(value3)) {
            Org org = orgService.getOrgByNameAndUserName(value2, value3);
            if (null != org) {
                orgs.add(org);
            } else {
                erros.add("系统找不到机构名称为\"" + value2 + "\",机构代码为\"" + value3 + "\"的机构");
            }
        } else {
            if (StringUtil.isEmpty(value1) && StringUtil.isEmpty(value2) && StringUtil.isEmpty(value3)) {
            } else {
                erros.add("第" + rowNum + "条数据填写不完整 ");
            }
        }
    }
    if (null != workbook) {
        try {
            workbook.close();
        } catch (Exception e) {
        } finally {
            workbook = null;
        }
    }
    if (null != in) {
        try {
            in.close();
        } catch (Exception e) {
        } finally {
            in = null;
        }
    }
    Map<String, Object> res = new HashMap<String, Object>();
    res.put("orgs", orgs);
    res.put("erros", erros);
    return new ResponseBean(res);
}
Also used : Org(com.bc.pmpheep.back.po.Org) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with LogDetail

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

the class OrgUserController method importExcel.

@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "机构用户管理界面导入Excel文件")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public ResponseBean importExcel(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request) {
    Map<String, Object> map = new HashedMap();
    String sessionId = CookiesUtil.getSessionId(request);
    HttpSession session = SessionContext.getSession(sessionId);
    String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
    try {
        List<OrgVO> list = orgUserService.importExcel(file);
        map.put("uuid", uuid);
        map.put("list", list);
        session.setAttribute(uuid, list);
    } catch (CheckedServiceException e) {
        return new ResponseBean(e);
    } catch (IOException e) {
        return new ResponseBean(e);
    }
    return new ResponseBean(map);
}
Also used : OrgVO(com.bc.pmpheep.back.vo.OrgVO) HttpSession(javax.servlet.http.HttpSession) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) IOException(java.io.IOException) HashedMap(org.apache.commons.collections.map.HashedMap) 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