Receiving the rear end of the data stream processing data (incomplete)

@Aspect
@Order(10)
public class RestControllerAspect {

    public static final Logger logger = LoggerFactory.getLogger(RestControllerAspect.class);

    @Resource
    private OfficeCommonService officeCommonService;

    @Pointcut("execution(public * com.sinosig.epassport.application.controller..*.*(..))")
    public void restful() {
    }

    private static String[] types = {"java.lang.Integer", "java.lang.Double",
            "java.lang.Float", "java.lang.Long", "java.lang.Short",
            "java.lang.Byte", "java.lang.Boolean", "java.lang.Char",
            "java.lang.String", "int", "double", "long", "short", "byte",
            "boolean", "char", "float"};

    @Around("restful()")
    public Object execute(ProceedingJoinPoint pjp) throws Throwable {
        ResultModel rm = new ResultModel();
        Object target = pjp.getTarget();
        processingBefore();
        if (target instanceof BeforeControllerHanding) {
            java.lang.reflect.Method method = Refs.getMethod(pjp.getTarget(), pjp.getSignature().getName());
            if (method.getReturnType() == Void.TYPE) {
                logger.warn("return type is void, not wrap");
                return pjp.proceed();
            }
            StringBuilder sb = new StringBuilder();
            //获取所有的参数
            Object[] args = pjp.getArgs();
            for (int k = 0; k < args.length; k++) {
                Object arg = args[k];
                // 获取对象类型
                String typeName = arg.getClass().getTypeName();
                for (String t : types) {
                    //1 判断是否是基础类型
                    if (t.equals(typeName)) {
                        return sb.append(arg + "; ");

                    } else {
                        Map fieldsValue = (Map) getFieldsValue(arg);

                        String sysNo = (String) fieldsValue.get("sysNo");
                        String sysPwd = (String) fieldsValue.get("sysPwd");
                        List <AccessControlEntity> sysNoAndPwd = officeCommonService.findSysNoAndPwd (sysNo, sysPwd); 
                        if (sysNo.isEmpty() || sysPwd.isEmpty()) {
                            return new new ResultModel (to false, "", "or a subsystem to access the account password is not blank"); 
                        } the else IF (sysNoAndPwd sysNoAndPwd.size == null || () <= 0) { 
                            return new new ResultModel (to false, "", "account number or password error"); 
                        } the else { 
                            return pjp.proceed (); 
                        } 
                    } 
                } 
            } 
            return null; 
        } 
        IF (the instanceof RestControllerHandling target) { 
            the try { 
                the java.lang.reflect.Method = Refs.getMethod Method (pjp.getTarget (), pjp.getSignature () getName ());. 
                IF (Method.getReturnType () == Void.TYPE) {
                    logger.warn("return type is void, not wrap");
                    return pjp.proceed();
                }
                Object result = pjp.proceed();
                rm.setResultData(result.toString());
                rm.setSuccess(true);
                rm.setMessage("");
            } catch (DaoException e) {
                rm.setMessage("数据访问错误");
                logger.error(e.getMessage(), e);
            } catch (NoLoginException e) {
                rm.setMessage("用户未登录或登陆已失效");
                logger.error(e.getMessage(), e);
            } catch (CaptchaErrorException e) {
                rm.setMessage("验证码错误");
                logger.error(e.getMessage(), e);
            } catch (ValidationException e) {
                rm.setMessage(e.getMessage());
                logger.error(e.getMessage(), e);
            } catch (Throwable e) {
                rm.setMessage("系统错误");
                logger.error(e.getMessage(), e);
            }
        } else {
            return pjp.proceed();
        }

        return rm;
    }


    private void processingBefore() {
        try {
            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            if (requestAttributes instanceof ServletRequestAttributes) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                Page page = PageSelector.getPage();
                page.reset();
                String enabledPage = request.getParameter("enabledPage");
                String pageSizePm = request.getParameter("pageSize");
                String pageIndexPm = request.getParameter("pageIndex");
                if ("0".equals(enabledPage) || "N".equalsIgnoreCase(enabledPage) || "false".equalsIgnoreCase(enabledPage)) {

                } else {
                    if (!Strings.isEmpty(pageSizePm) && !Strings.isEmpty(pageIndexPm)) {
                        Strings.toInteger the pageSize = int (pageSizePm,. 1); 
                        int = Strings.toInteger the pageIndex (pageIndexPm, 10); 
                        page.setPaging (to true); 
                        page.setPageSize (the pageSize); 
        // Get all fields by reflection, getFileds () Gets a modified public field 
        // getDeclaredFields obtain a modified private protected public fields 
        field [] fields = obj.getClass () getDeclaredFields ().;
                        page.setCurrentPage(pageIndex);
                    }
                } 
            } 


        } The catch (Exception E) { 
            logger.error (e.getMessage (), E); 
        } 
    } 


    // parse entity class, the entity class attributes acquired 
    public static getFieldsValue Object (Object obj) { 
        String typeName = obj. getClass () the getTypeName ();. 
        for (String T: types) { 
            IF (t.equals (typeName)) { 
                return ""; 
            } 
        } 
        the Map <Object, Object> = new new Map the HashMap <> (); 
        for (Field, F: Fields) { 
            // access private variables in the reflective 
            f.setAccessible (to true); 
            the try { 
                for (String STR: types) {
                    // here there will be problems if the entity class which continues to contain the entity classes, you can not get here. 
                    // In fact, we can go through recursively processing entity class contains questions entity class. 
                    IF (f.getType () getName () the equals (STR)..) { 
                        map.put (f.getName (), f.get (obj));  
                    }
                } 
            } the catch (an IllegalArgumentException E) { 
                e.printStackTrace (); 
            the catch} (IllegalAccessException E) { 
                e.printStackTrace (); 
            } 
        } 
        return Map; 
    } 
}

  

Guess you like

Origin www.cnblogs.com/otways/p/11458170.html