package com.cico.nest.lcdp.boot.core.system.framework.operatelog.core;

import cn.hutool.core.util.StrUtil;
import com.cico.nest.lcdp.boot.api.system.dept.DeptApi;
import com.cico.nest.lcdp.boot.api.system.dept.dto.DeptRespDTO;
import com.mzt.logapi.service.IParseFunction;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


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

    public static final String NAME = "getDeptById";

    @Resource
    private DeptApi deptApi;

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

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

        // 获取部门信息
        DeptRespDTO dept = deptApi.getDept(value.toString());
        if (dept == null) {
            log.warn("[apply][获取部门{{}}为空", value);
            return "";
        }
        return dept.getName();
    }

}
