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

import org.springblade.common.cache.DictBizCache;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.enums.EquipmentStatusEnum;
import org.springblade.modules.business.rtumanage.entity.RtuStatusEntity;
import org.springblade.modules.business.rtumanage.vo.RtuStatusVO;
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 RtuManageWrapper extends BaseEntityWrapper<RtuStatusEntity, RtuStatusVO> {
	public static RtuManageWrapper build() {
		return new RtuManageWrapper();
	}

	@Override
	public RtuStatusVO entityVO(RtuStatusEntity entity) {
		RtuStatusVO rtuStatusVO = Objects.requireNonNull(BeanUtil.copy(entity, RtuStatusVO.class));
//		List<DictBiz> dicts= DictBizCache.getList("rtu_kind");
//		LinkedList<Map<String, Object>> kindList = new LinkedList<>();
//
//
//		Map<String,Object> kindMap=new HashMap<>();
//		String rtuKinds = entity.getRtuKinds();
//		if (rtuKinds != null) {
//			String[] kinds = rtuKinds.split(",");
//			for (String k : kinds) {
//				kindMap.put(k,k);
//			}
//		}
//
//		for (DictBiz d: dicts){
//			Map<String, Object> item = new HashMap<>();
//			item.put("key", d.getDictKey());
//			item.put("value", d.getDictValue());
//			if (kindMap.containsKey(d.getDictKey())){
//				item.put("check",true);
//			}else{
//				item.put("check",false);
//			}
//			kindList.add(item);
//		}
//
//		rtuInfoVO.setKindList(kindList);
		return rtuStatusVO;
	}

	public void toVoInfo(RtuStatusVO rtuStatusVO) {

		rtuStatusVO.setAreaName(rtuStatusVO.getAdCity() + "/" + rtuStatusVO.getAdDist());

		if (rtuStatusVO.getRunStatusId() == null){
			rtuStatusVO.setRunStatusId(EquipmentStatusEnum.STATUS_RUN.getCode());
		}

		List<DictBiz> dicts = DictBizCache.getList("rtu_kind");
		Map<String, Object> kindMap = new HashMap<>();
		String rtuKinds = rtuStatusVO.getRtuKinds();
		if (rtuKinds != null) {
			String[] kinds = rtuKinds.split(",");
			for (String k : kinds) {
				kindMap.put(k, k);
			}
		}
		String rtuKindDesc = "";
		for (DictBiz d : dicts) {
			if (kindMap.containsKey("" + d.getId())) {
				if (rtuKindDesc.length() > 0) {
					rtuKindDesc += "/";
				}
				rtuKindDesc += d.getDictValue();
			}
		}
		rtuStatusVO.setRtuKindDesc(rtuKindDesc);
	}


}
