All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zyy.common.service.impl.JudgeHandle Maven / Gradle / Ivy

package com.zyy.common.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zyy.common.aspect.HandleAspect;
import com.zyy.common.factory.HandleFactory;
import com.zyy.common.model.HandleModel;
import com.zyy.common.model.JudgeModel;
import com.zyy.common.model.TemplateModel;
import com.zyy.common.service.HandleService;
import com.zyy.common.util.OgnlUtil;
import com.zyy.common.util.RegUtil;
import com.zyy.common.util.TokenModel;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@AllArgsConstructor
public class JudgeHandle implements HandleService {

    private final ObjectMapper objectMapper;

    /**
     * 处理handle
     *
     * @param model      处理模板
     * @param proceed    数据对象
     * @param tokenModel 用户对象
     */
    @Override
    public void handleRun(TemplateModel model, Object proceed, TokenModel tokenModel) {
        try {
            String template = model.getContext();
            String parse = RegUtil.parse("\\{\\{(.+?)\\}\\}", template, proceed, tokenModel);
            JudgeModel judgeModel = objectMapper.readValue(parse, JudgeModel.class);
            if (OgnlUtil.getIfValue(proceed, judgeModel.getExpression())) {
                TemplateModel tep = HandleAspect.templateStaticMapper.selectByPrimaryKey(judgeModel.getTemplateId());
                HandleFactory.execute(tep.getType(), tep, proceed, tokenModel);
            }
        } catch (JsonProcessingException e) {
            log.info("JudgeHandle#Error", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy