package org.jeecg.common.util.mapstruct;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import org.mapstruct.Named;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @description: Mapping通用转换
 * @author: niugeng
 * @create: 2024-01-25 11:58
 **/
@Component
public class TypeConversionWorker {

    /**
     * 对象转json字符串
     *
     * @param obj
     * @return
     */
    @Named("toJsonString")
    public String toJsonString(Object obj) {
        if (Objects.isNull(obj)) {
            return null;
        }
        return JSON.toJSONString(obj);
    }

    @Named("dateToRq")
    public String dateToRq(String date ){
        return StrUtil.sub(date,0,10);
    }

}
