首页 > 代码库 > hybris interceptor 应用于对象保存前的数据验证

hybris interceptor 应用于对象保存前的数据验证

package com.aaa.backoffice.Interceptors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.aaa.core.model.CAHOrderApprovedConfigModel;
import com.aaa.core.services.util.dao.CahCommonDao;

import de.hybris.platform.servicelayer.interceptor.InterceptorContext;
import de.hybris.platform.servicelayer.interceptor.InterceptorException;
import de.hybris.platform.servicelayer.interceptor.PrepareInterceptor;
import de.hybris.platform.servicelayer.model.ModelService;

public class OrderApprovedConfigSavingInterceptor implements PrepareInterceptor<OrderApprovedConfigModel> {

    private final static Logger LOG = LoggerFactory.getLogger(OrderApprovedConfigSavingInterceptor.class);

    @Autowired
    private ModelService modelService;

    @Autowired
    private CahCommonDao cahCommonDao;

    @Override
    public void onPrepare(OrderApprovedConfigModel config, InterceptorContext arg1) throws InterceptorException {
        // 内容check
        checkSavedValues(config);
        // 保存Code
        String code = config.getSalesOrg().getUid()+"-"+config.getOrderReason().getCode()+"-"+config.getOrderType();
        config.setCode(code);
    }

    private void checkSavedValues(OrderApprovedConfigModel config) throws InterceptorException {

        if (null == config.getSalesOrg()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getOrderReason()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getOrderType()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getRoles()) {
            throw new InterceptorException("请选择角色!");
        }

       
    }
}

 

hybris interceptor 应用于对象保存前的数据验证