package com.zm.order.tool.server.cipher;

import net.sf.jsqlparser.JSQLParserException;
import org.springframework.util.StringUtils;

import com.zm.order.tool.server.utils.SpringContextUtil;

import cn.qmai.data.encrypt.service.DataEncryptService;

/**
 * <p>
 *
 * </p>
 *
 * @author nianchang
 * @date 2023/12/20 4:11 下午
 */
public enum CipherEnum {

    /**
     * 加密
     */
    ENCRYPT,

    /**
     * 解密
     */
    DECRYPT,

    ;

    public static String execute(CipherEnum type, String target) throws JSQLParserException {
        if (type == null || StringUtils.isEmpty(target)) {
            return target;
        }
        DataEncryptService encryptService = SpringContextUtil.getBean(DataEncryptService.class);
        return type == ENCRYPT ? encryptService.encrypt(target) : encryptService.decrypt(target);
    }
}
