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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.SpringUtil;
import org.springblade.modules.baseinfo.org.entity.DeptRegionEntity;
import org.springblade.modules.baseinfo.org.service.IDeptRegionService;
import org.springblade.modules.baseinfo.rtu.entity.RtuInfoEntity;
import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
import org.springblade.modules.business.equipment.inspection.report.entity.EquipmentInspectionReportEntity;
import org.springblade.modules.business.equipment.inspection.report.vo.EquipmentInspectionReportVO;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDeptService;

import java.util.List;
import java.util.Objects;

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

public class EquipmentInspectionReportWrapper extends BaseEntityWrapper<EquipmentInspectionReportEntity, EquipmentInspectionReportVO> {
	public static EquipmentInspectionReportWrapper build() {
		return new EquipmentInspectionReportWrapper();
	}

	private static IRtuBaseInfoService rtuBaseInfoService;

	private static IRtuBaseInfoService getRtuBaseInfoService() {
		if (rtuBaseInfoService == null) {
			rtuBaseInfoService = SpringUtil.getBean(IRtuBaseInfoService.class);
		}
		return rtuBaseInfoService;
	}

	private static IDeptRegionService deptRegionService;

	private static IDeptRegionService getDeptRegionService() {
		if (deptRegionService == null) {
			deptRegionService = SpringUtil.getBean(IDeptRegionService.class);
		}
		return deptRegionService;
	}

	private static IDeptService deptService;

	private static IDeptService getDeptService() {
		if (deptService == null) {
			deptService = SpringUtil.getBean(IDeptService.class);
		}
		return deptService;
	}

	@Override
	public EquipmentInspectionReportVO entityVO(EquipmentInspectionReportEntity entity) {
		EquipmentInspectionReportVO vo = Objects.requireNonNull(BeanUtil.copy(entity, EquipmentInspectionReportVO.class));
		return entityVO(vo);
	}

	public EquipmentInspectionReportVO entityVO(EquipmentInspectionReportVO vo) {
//		LambdaQueryWrapper<RtuInfoEntity> rtuwrapper = Wrappers.<RtuInfoEntity>query().lambda();
//		rtuwrapper.eq(RtuInfoEntity::getIsDeleted, 0L);
//		rtuwrapper.eq(RtuInfoEntity::getRtuCode, vo.getRtuCode());
//		RtuInfoEntity rtuInfoEntity = getRtuBaseInfoService().getOne(rtuwrapper);
//		vo.setRtuName(rtuInfoEntity.getRtuName());
//		DictBiz biz = DictBizCache.getById(vo.getWaterSensorType());
//		if (null != biz) {
//			vo.setWaterSensorTypeText(biz.getDictValue());
//		}
//		biz = DictBizCache.getById(vo.getGroundSensorType());
//		if (null != biz) {
//			vo.setGroundSensorTypeText(biz.getDictValue());
//		}
//		biz = DictBizCache.getById(vo.getSatelliteModel());
//		if (null != biz) {
//			vo.setSatelliteModelText(biz.getDictValue());
//		}
//		LambdaQueryWrapper<RtuInfoEntity> rtuwrapper = Wrappers.<RtuInfoEntity>query().lambda();
//		rtuwrapper.eq(RtuInfoEntity::getIsDeleted, 0);
//		rtuwrapper.eq(RtuInfoEntity::getRtuCode, vo.getRtuCode());
//		RtuInfoEntity rtuInfoEntity = getRtuBaseInfoService().getOne(rtuwrapper);
//
//		vo.setRtuName(rtuInfoEntity.getRtuName());
//		vo.setIsRain(rtuInfoEntity.getIsRain());
//		vo.setIsRes(rtuInfoEntity.getIsRes());
//		vo.setIsRiver(rtuInfoEntity.getIsRiver());
//		vo.setIsGround(rtuInfoEntity.getIsGround());
//
//		vo.setAdCity(rtuInfoEntity.getAdCity());
//		vo.setAdDist(rtuInfoEntity.getAdDist());
//
//		String ancestors = vo.getAncestors();
//		if (null != ancestors && ancestors.length() > 0) {
//			String[] ancestorsList = ancestors.split(",");
//			String adCode;
//			if (ancestorsList.length >= 3) {
//				adCode = ancestorsList[2];
//			} else {
//				adCode = vo.getAdCode();
//			}
//			if (null != adCode) {
//				LambdaQueryWrapper<DeptRegionEntity> wrapper = Wrappers.<DeptRegionEntity>query().lambda();
//				wrapper.eq(DeptRegionEntity::getIsDeleted, 0);
//				wrapper.eq(DeptRegionEntity::getAdcd, adCode);
//				List<DeptRegionEntity> deptRegionEntities = getDeptRegionService().list(wrapper);
//				if (null != deptRegionEntities && deptRegionEntities.size() > 0) {
//					String manageCompany = "";
//					for (DeptRegionEntity deptRegionEntity : deptRegionEntities) {
//						Dept dept = getDeptService().getById(deptRegionEntity.getDeptId());
//						if (null != dept) {
//							if (manageCompany.length() > 0) {
//								manageCompany += " / ";
//							}
//							manageCompany += dept.getDeptName();
//						}
//					}
//					vo.setManageCompany(manageCompany);
//				}
//			}
//		}
		return vo;
	}
}
