package com.prolog.rdc.tms.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.prolog.common.util.ToolKits;
import com.prolog.rdc.tms.service.SysRefdatadService;

import cn.hutool.core.util.ObjectUtil;

/**
 * 
 *
 * 字典翻译工具类
 *
 * @className :ConvertorUtil
 * @author :fanzw
 * @creationTime :2022/06/22
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/06/22
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
public class ConvertorUtil {

	/**
	 * 字典翻译批量请求
	 * 
	 * @param sysFeign
	 * @param params
	 * @return
	 */
	public static Map<String, Object> listDropDownData(SysRefdatadService sysRefdatadService, List<String> params) {
		ToolKits.isParamNull(params, "翻译请求参数不为空");

		List<Map<String, Object>> maps = Lists.newArrayList();
		for (String param : params) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("objectcode", param);
			map.put("groupcode1", null);
			map.put("groupcode2", null);
			map.put("code", null);

			maps.add(map);
		}

		// 字典翻译请求
		Map<String, Object> map = sysRefdatadService.ListDropDownData(maps);

		return map;
	}

	/**
	 * 通过code翻译name
	 * 
	 * @param list
	 * @param objectcode
	 * @param code
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String getName(Map<String, Object> maps, String objectcode, String code) {
		List<Map<String, Object>> list = ObjectUtil.isEmpty(maps) ? null : (List<Map<String, Object>>) maps.get(objectcode);

		if (list == null || list.size() == 0 || code == null || code.equals("") || code.equals("null")) {
			return null;
		}

		String massage = null;
		for (Map<String, Object> map : list) {
			if ((map.get("value")).equals(code)) {
				massage = map.get("text").toString();
				break;
			}
		}

		return massage == null ? code : massage;
	}

	/**
	 * 通过name查询code
	 * 
	 * @param list
	 * @param objectcode
	 * @param name
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String getCode(Map<String, Object> maps, String objectcode, String name) {
		List<Map<String, Object>> list = ObjectUtil.isEmpty(maps) ? null : (List<Map<String, Object>>) maps.get(objectcode);

		if (list == null || list.size() == 0 || name == null || name.equals("") || name.equals("null")) {
			return null;
		}

		String massage = null;
		for (Map<String, Object> map : list) {
			if ((map.get("text")).equals(name)) {
				massage = map.get("value").toString();
				break;
			}
		}

		return massage == null ? name : massage;
	}

}
