package com.engine.organization.transmethod;

import cn.hutool.core.convert.Convert;
import com.engine.organization.entity.DeleteParam;
import com.engine.organization.enums.ModuleTypeEnum;
import com.engine.organization.mapper.staff.StaffPlanMapper;
import com.engine.organization.util.db.MapperProxyFactory;
import org.apache.commons.lang3.StringUtils;
import weaver.systeminfo.SystemEnv;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description:
 * @author:dxfeng
 * @createTime: 2022/05/25
 * @version: 1.0
 */
public class StaffPlanTransMethod {

    public static String getSpanById(String planId) {
        StaffPlanMapper planMapper = MapperProxyFactory.getProxy(StaffPlanMapper.class);
        List<Map<String, Object>> maps = planMapper.listPlansByIds(DeleteParam.builder().ids(planId).build().getIds());
        String names = maps.stream().map(item -> (String) item.get("name")).collect(Collectors.joining(","));
        return names;
    }

    public static String getFormatDateString(String dateStr) {
        if (StringUtils.isNotBlank(dateStr)) {
            return dateStr.substring(0, 10);
        }
        return "";
    }


    public static String getControlDimension(String controlDimension, String languageId) {
        Integer language = Convert.toInt(languageId, -1);

        if (!"".equals(controlDimension)) {
            for (ModuleTypeEnum myEnum : ModuleTypeEnum.values()) {
                if (myEnum.getValue() == Integer.parseInt(controlDimension)) {
                    if (-1 == language) {
                        return myEnum.getDefaultLabel();
                    }
                    Integer labelId = myEnum.getLabelId();
                    return SystemEnv.getHtmlLabelName(labelId, language);
                }
            }
        }
        return "/";
    }
}
