package org.agt.module.license.framework.operatelog.core;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.mzt.logapi.service.IParseFunction;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.agt.module.license.dal.dataobject.customer.CustomerDO;
import org.agt.module.license.dal.mysql.customer.CustomerMapper;
import org.springframework.stereotype.Component;

/**
 * 管理员名字的 {@link IParseFunction} 实现类
 *
 * @author HUIHUI
 */
@Slf4j
@Component
public class CustomerNameParseFunction implements IParseFunction {

    public static final String NAME = "getCustomerName";

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public String functionName() {
        return NAME;
    }

    @Override
    public String apply(Object value) {
        if (StrUtil.isEmptyIfStr(value)) {
            return "";
        }

        // 获取用户信息
        CustomerDO customer = customerMapper.selectById(Convert.toLong(value));
        if (customer == null) {
            log.warn("[apply][获取客户{{}}为空", value);
            return "";
        }
        return customer.getName();
    }

}
