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


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.baseinfo.region.entity.RegionInfoEntity;
import org.springblade.modules.baseinfo.region.entity.RegionTreeNodeEntity;
import org.springblade.modules.baseinfo.region.service.IBaseInfoRegionService;

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

	private static IBaseInfoRegionService baseInfoRegionService;

	private static IBaseInfoRegionService getBaseInfoRegionService() {
		if (baseInfoRegionService == null) {
			baseInfoRegionService = SpringUtil.getBean(IBaseInfoRegionService.class);
		}
		return baseInfoRegionService;
	}

	public static RegionInfoNodeWrapper build() {
		return new RegionInfoNodeWrapper();
	}

	@Override
	public RegionTreeNodeEntity entityVO(RegionInfoEntity entity) {
		RegionTreeNodeEntity nodeEntity = new RegionTreeNodeEntity();
		nodeEntity.setId(entity.getAdcd());
		nodeEntity.setValue(entity.getAdcd());
		nodeEntity.setTitle(entity.getAdnm());
		nodeEntity.setKey(entity.getAdcd());
		nodeEntity.setParentId(entity.getParentCode());
		LambdaQueryWrapper<RegionInfoEntity> queryWrapper= Wrappers.<RegionInfoEntity>query().lambda();
		queryWrapper.eq(RegionInfoEntity::getParentCode,entity.getAdcd());
		queryWrapper.eq(RegionInfoEntity::getIsDeleted,0);
		if (getBaseInfoRegionService().count(queryWrapper)>0){
			nodeEntity.setHasChildren(true);
		}else{
			nodeEntity.setHasChildren(false);
		}
		return nodeEntity;
	}

}
