package com.engine.organization.transmethod;

import com.engine.organization.entity.DeleteParam;
import com.engine.organization.mapper.job.JobMapper;
import com.engine.organization.mapper.scheme.GradeMapper;
import com.engine.organization.mapper.scheme.LevelMapper;
import com.engine.organization.mapper.scheme.SchemeMapper;
import com.engine.organization.mapper.sequence.SequenceMapper;
import com.engine.organization.util.db.MapperProxyFactory;

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 JobTransMethod {

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

    public static String getLevelName(String levelId) {
        LevelMapper levelMapper = MapperProxyFactory.getProxy(LevelMapper.class);
        List<Map<String, Object>> maps = levelMapper.listLevelsByIds(DeleteParam.builder().ids(levelId).build().getIds());
        String levelName = maps.stream().map(item -> (String) item.get("name")).collect(Collectors.joining(","));
        return levelName;
    }

    public static String getGradeName(String gradeId) {
        GradeMapper gradeMapper = MapperProxyFactory.getProxy(GradeMapper.class);
        return gradeMapper.getGradeByID(Long.parseLong(gradeId)).getGradeName();
    }

    public static String getSequenceName(String sequenceId) {
        SequenceMapper sequenceMapper = MapperProxyFactory.getProxy(SequenceMapper.class);
        return sequenceMapper.getSequenceByID(Long.parseLong(sequenceId)).getSequenceName();
    }

    public static String getSchemeName(String schemeId) {
        SchemeMapper schemeMapper = MapperProxyFactory.getProxy(SchemeMapper.class);
        return schemeMapper.getSchemeByID(Long.parseLong(schemeId)).getSchemeName();
    }

    public static String getIsKeySpan(String isKey) {
        if ("1".equals(isKey)) {
            return "是";
        } else {
            return "否";
        }
    }

    public static String getSexName(String sexValue) {
        String sexName = "男";
        if ("1".equals(sexValue)) {
            sexName = "女";
        }
        return sexName;
    }

}
