/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.business.rtu.base.wrapper;


import org.springblade.common.cache.DictBizCache;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.rtu.base.entity.RtuInfoEntity;
import org.springblade.modules.business.rtu.base.vo.RtuInfoVO;
import org.springblade.modules.system.entity.DictBiz;

import java.util.*;

/***
 * Date:2022/8/22
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
public class RtuInfoWrapper extends BaseEntityWrapper<RtuInfoEntity, RtuInfoVO> {
	public static RtuInfoWrapper build() {
		return new RtuInfoWrapper();
	}

	@Override
	public RtuInfoVO entityVO(RtuInfoEntity entity) {
		RtuInfoVO rtuInfoVO = Objects.requireNonNull(BeanUtil.copy(entity, RtuInfoVO.class));

		rtuInfoVO.setAreaName(entity.getAdCity() + "/" + entity.getAdDist());

//		List<DictBiz> dicts = DictBizCache.getList("rtu_kind");
//
//		rtuInfoVO.setKindList(dicts);




//		Map<String, Object> kindMap = new HashMap<>();
//		String rtuKinds = rtuInfoVO.getRtuKinds();
//		if (rtuKinds != null) {
//			String[] kinds = rtuKinds.split(",");
//			for (String k : kinds) {
//				kindMap.put(k, k);
//			}
//		}

//		String rtuKindsName = "";
//		for (DictBiz d : dicts) {
//			Map<String, Object> item = new HashMap<>();
//			item.put("key", d.getDictKey());
//			item.put("value", d.getDictValue());
//			if (kindMap.containsKey(""+d.getId())) {
//				if (rtuKindsName.length() > 0) {
//					rtuKindsName += "/";
//				}
//				rtuKindsName += d.getDictValue();
//				item.put("check", true);
//			} else {
//				item.put("check", false);
//			}
//			kindList.add(item);
//		}

	//	rtuInfoVO.setKindList(kindList);
		return rtuInfoVO;
	}

	public void appendInfo(RtuInfoVO rtuInfoVO) {
		rtuInfoVO.setAreaName(rtuInfoVO.getAdCity() + "/" + rtuInfoVO.getAdDist());

		List<DictBiz> dicts = DictBizCache.getList("rtu_kind");
		LinkedList<Map<String, Object>> kindList = new LinkedList<>();


		Map<String, Object> kindMap = new HashMap<>();
		String rtuKinds = rtuInfoVO.getRtuKinds();
		if (rtuKinds != null) {
			String[] kinds = rtuKinds.split(",");
			for (String k : kinds) {
				kindMap.put(k, k);
			}
		}

		String rtuKindDesc = "";
		for (DictBiz d : dicts) {
			Map<String, Object> item = new HashMap<>();
			item.put("key", d.getDictKey());
			item.put("value", d.getDictValue());
			if (kindMap.containsKey(""+d.getId())) {
				if (rtuKindDesc.length() > 0) {
					rtuKindDesc += "/";
				}
				rtuKindDesc += d.getDictValue();
				item.put("check", true);
			} else {
				item.put("check", false);
			}
			kindList.add(item);
		}
		rtuInfoVO.setRtuKindDesc(rtuKindDesc);

	}
}
