Search in sources :

Example 31 with LogDetail

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

the class OperationLogInterceptor method postHandle.

/**
 * <pre>
 * 功能描述:在调用controller具体方法中,返回前拦截
 * 使用示范:
 *
 * @param request HttpServletRequest
 * @param response HttpServletRequest
 * @param object Object
 * @throws Exception
 * </pre>
 */
@SuppressWarnings("rawtypes")
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object, ModelAndView modelAndView) throws Exception {
    if (object instanceof HandlerMethod) {
        // 完整请求路径
        String requestUri = request.getRequestURI();
        // 项目路径
        String contextPath = request.getContextPath();
        // 模块路径
        String url = requestUri.substring(contextPath.length());
        Boolean isAccess = false;
        // 不拦截excludeUrls中配置的url请求
        for (String requestUrl : excludeUrls) {
            if (requestUrl.endsWith("/**")) {
                if (url.startsWith(requestUrl.substring(0, requestUrl.length() - 3))) {
                    isAccess = true;
                    break;
                }
            } else if (url.startsWith(requestUrl)) {
                isAccess = true;
                break;
            }
        }
        if (!isAccess) {
            HandlerMethod handlerMethod = (HandlerMethod) object;
            // 类名
            Class cls = handlerMethod.getBeanType();
            // 类中的所有方法
            Method[] methods = cls.getMethods();
            // 方法用途
            String logRemark = "";
            // 业务类型
            String businessType = "";
            HttpSession session = null;
            try {
                session = request.getSession();
            } catch (Exception e) {
                logger.warn("session为空时出现异常:{}", e.getMessage());
            }
            if (ObjectUtil.notNull(session)) {
                PmphUser pmphUser = (PmphUser) session.getAttribute(Const.SESSION_PMPH_USER);
                if (ObjectUtil.notNull(pmphUser)) {
                    // 调用接口方法
                    String subUrl = url.substring(url.lastIndexOf("/") + 1, url.length());
                    for (Method method : methods) {
                        LogDetail logObj = method.getAnnotation(LogDetail.class);
                        if (ObjectUtil.notNull(logObj) && method.getName().equals(subUrl)) {
                            logRemark = logObj.logRemark();
                            businessType = logObj.businessType();
                            break;
                        }
                    }
                    // 获取用户访问设备类型
                    String deviceType = DeviceUtils.isMobileDevice(request);
                    // 此处调用 sysOperationService 保存方法
                    sysOperationService.addSysOperation(new SysOperation(pmphUser.getId(), pmphUser.getUsername(), pmphUser.getRealname(), DateUtil.getCurrentTime(), url + "-" + logRemark, StringUtil.getClientIP(request), businessType, deviceType));
                }
            }
        }
    }
}
Also used : LogDetail(com.bc.pmpheep.annotation.LogDetail) SysOperation(com.bc.pmpheep.back.po.SysOperation) PmphUser(com.bc.pmpheep.back.po.PmphUser) HttpSession(javax.servlet.http.HttpSession) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 32 with LogDetail

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

the class FileDownLoadController method declarationExcel.

/**
 * 功能描述:申报表批量导出excel
 *
 * @param materialId
 *            教材id
 * @param textBookids
 *            书籍id集合
 * @param realname
 *            条件查询的账号或者姓名
 * @param position
 *            条件查询 职务
 * @param title
 *            条件查询 职称
 * @param orgName
 *            条件查询 工作单位
 * @param unitName
 *            条件查询 申报单位
 * @param positionType
 *            条件查询 申报职位 ;null全部 1主编 2副主编 3编委
 * @param onlineProgress
 *            1待审核 3已经审核
 * @param offlineProgress
 *            0 未 2 收到
 * @param request
 * @param response
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报表批量导出excel")
@RequestMapping(value = "/excel/declaration", method = RequestMethod.GET)
public void declarationExcel(Long materialId, String textBookids, String realname, String position, String title, String orgName, String unitName, Integer positionType, Integer onlineProgress, Integer offlineProgress, HttpServletRequest request, HttpServletResponse response) {
    Workbook workbook = null;
    try {
        workbook = excelHelper.fromDeclarationEtcBOList(materialService.getMaterialById(materialId), materialExtensionService.getMaterialExtensionByMaterialId(materialId), declarationService.declarationEtcBO(materialId, textBookids, realname, position, title, orgName, unitName, positionType, onlineProgress, offlineProgress), "专家信息表");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    // try {
    StringBuilder sb = new StringBuilder("attachment;fileName=");
    String materialName;
    String userAgent = request.getHeader("User-Agent");
    materialName = returnFileName(request, materialService.getMaterialNameById(materialId));
    // if (userAgent.toLowerCase().contains("mozilla")) {
    // materialName =
    // URLEncoder.encode(materialService.getMaterialNameById(materialId), "UTF-8");
    // } else {
    // materialName =
    // new String(materialService.getMaterialNameById(materialId).getBytes("utf-8"),
    // "ISO8859-1");
    // }
    sb.append(materialName);
    sb.append(".");
    SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd.HHmm");
    sb.append(sdf.format(new Date()));
    sb.append(".xls");
    response.setHeader("Content-Disposition", sb.toString().replace("+", "%20"));
    // }
    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) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) SimpleDateFormat(java.text.SimpleDateFormat) Workbook(org.apache.poi.ss.usermodel.Workbook) Date(java.util.Date) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with LogDetail

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

the class FileDownLoadController method orgUserExportEcel.

/**
 * 机构用户export
 */
@RequestMapping(value = "/orgUserExportEcel", method = RequestMethod.GET)
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出excel")
@ResponseBody
public void orgUserExportEcel(HttpServletRequest request, HttpServletResponse response, String name, String orgName, String orgTypeName, Integer isHospital) {
    PageParameter pageParameter = new PageParameter<>();
    OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
    if (StringUtil.notEmpty(orgName)) {
        orgAndOrgUserVO.setOrgName(orgName.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(name)) {
        // 去除空格
        orgAndOrgUserVO.setName(name.replaceAll(" ", ""));
    }
    if (StringUtil.notEmpty(orgTypeName)) {
        // 去除空格
        orgAndOrgUserVO.setOrgTypeName(orgTypeName.replaceAll(" ", ""));
    }
    orgAndOrgUserVO.setIsHospital(isHospital);
    pageParameter.setParameter(orgAndOrgUserVO);
    pageParameter.setStart(null);
    // export
    Workbook workbook = null;
    List<OrgAndOrgUserVO> orgList = null;
    try {
        orgList = orgUserService.getListOrgUser(pageParameter).getRows();
        workbook = excelHelper.fromBusinessObjectList(orgList, "机构账户信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String fileName = returnFileName(request, "机构账户信息.xls");
    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 : OrgAndOrgUserVO(com.bc.pmpheep.back.vo.OrgAndOrgUserVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) 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) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 34 with LogDetail

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

the class FileDownLoadController method exportSituationSchool.

/**
 * Description:申报情况统计页面按申报单位统计导出统计结果
 *
 * @author:lyc
 * @date:2018年1月9日上午10:29:21
 * @param
 * @return void
 */
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "申报情况统计页面按申报单位统计导出统计结果")
@RequestMapping(value = "/result/exportSituationSchool", method = RequestMethod.GET)
public void exportSituationSchool(Long materialId, String schoolName, Integer state, HttpServletRequest request, HttpServletResponse response) {
    PageParameter<DeclarationSituationSchoolResultVO> pageParameter = new PageParameter<>(1, 50000);
    DeclarationSituationSchoolResultVO declarationSituationSchoolResultVO = new DeclarationSituationSchoolResultVO();
    declarationSituationSchoolResultVO.setMaterialId(materialId);
    declarationSituationSchoolResultVO.setSchoolName(schoolName);
    pageParameter.setParameter(declarationSituationSchoolResultVO);
    Workbook workbook = null;
    List<DeclarationSituationSchoolResultVO> list = null;
    String sheetName = "";
    if (state.intValue() == 1) {
        list = decPositionService.listChosenDeclarationSituationSchoolResultVOs(pageParameter).getRows();
        sheetName = "申报情况按单位统计(按当选数排序)";
    } else if (state.intValue() == 2) {
        list = decPositionService.listPresetDeclarationSituationSchoolResultVOs(pageParameter).getRows();
        sheetName = "申报情况按单位统计(按申报数排序)";
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "未知的排序方式");
    }
    if (list.size() == 0) {
        list.add(new DeclarationSituationSchoolResultVO());
    }
    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) 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) DeclarationSituationSchoolResultVO(com.bc.pmpheep.back.vo.DeclarationSituationSchoolResultVO) LogDetail(com.bc.pmpheep.annotation.LogDetail) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with LogDetail

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

the class FileDownLoadController method allOrg.

/**
 * <pre>
 * 功能描述:导出所有学校
 * 使用示范:
 *
 * &#64;param request
 * &#64;param response
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出所有学校")
@RequestMapping(value = "/excel/allOrg", method = RequestMethod.GET)
public void allOrg(HttpServletRequest request, HttpServletResponse response) {
    Workbook workbook = null;
    List<OrgExclVO> orgList = null;
    try {
        orgList = orgService.listAllOrgToExcel();
        workbook = excelHelper.fromBusinessObjectList(orgList, "所有学校信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String fileName = returnFileName(request, "所有学校" + ".xls");
    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 : OrgExclVO(com.bc.pmpheep.back.vo.OrgExclVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) 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) 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