package org.springblade.openinterface.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springblade.common.cache.SysCache;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.openinterface.dto.smartdevice.SmartDeviceDto;
import org.springblade.smartapplication.smartsmoke.entity.SmartDevice;

import java.util.Objects;

/**
 * Created By lidexi in 2021/3/25
 **/
public class SmartDeviceAppWrapper extends BaseEntityWrapper<SmartDevice, SmartDeviceDto> {

	private IDictBizService dictBizService;

	private SmartDeviceAppWrapper(IDictBizService dictBizService){
		this.dictBizService = dictBizService;
	}

	public static SmartDeviceAppWrapper build(IDictBizService dictBizService){
		return new SmartDeviceAppWrapper(dictBizService);
	}

	@Override
	public SmartDeviceDto entityVO(SmartDevice entity) {
		SmartDeviceDto smartDeviceDto = Objects.requireNonNull(BeanUtil.copy(entity,SmartDeviceDto.class));
		DictBiz dictBiz = dictBizService.getBaseMapper().selectOne(new QueryWrapper<>(new DictBiz()).lambda().eq(DictBiz::getCode, "device_type").eq(DictBiz::getDictKey, entity.getDeviceType()));
		if(dictBiz != null){
			smartDeviceDto.setDeviceTypeName(dictBiz.getDictValue());
		}
		return smartDeviceDto;
	}
}
