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

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.enums.IsValidEnum;
import org.springblade.modules.business.equipment.inspection.plan.entity.EquipmentInspectionPlanEntity;
import org.springblade.modules.business.equipment.inspection.plan.vo.EquipmentInspectionPlanVO;
import org.springblade.modules.business.rtu.base.entity.RtuInfoEntity;
import org.springblade.modules.business.rtu.base.vo.RtuInfoVO;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

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

	@Override
	public EquipmentInspectionPlanVO entityVO(EquipmentInspectionPlanEntity entity) {
		EquipmentInspectionPlanVO equipmentInspectionPlanVO = Objects.requireNonNull(BeanUtil.copy(entity, EquipmentInspectionPlanVO.class));

//		Date dt = new Date();
//		if (dt.after(entity.getInspectionEndTime())){
//			equipmentInspectionPlanVO.setPlanClose(IsValidEnum.VALID_1.getCode());
//		}else{
//			equipmentInspectionPlanVO.setPlanClose(IsValidEnum.VALID_2.getCode());
//		}

		return equipmentInspectionPlanVO;
	}

	public void planQuery(Map<String, Object> plan) {
		// 此场景仅在 pg数据库 map类型传参的情况下需要处理，entity传参已经包含数据类型，则无需关心
		// 针对 pg数据库 int类型字段查询需要强转的处理示例
		String searchKey = "inspectionId";
		if (Func.isNotEmpty(plan.get(searchKey))) {
			// 数据库字段为int类型，设置"="查询，具体查询参数请见 @org.springblade.core.mp.support.SqlKeyword
			plan.put(searchKey.concat("_equal"), Func.toLong(plan.get(searchKey)));
			// 默认"like"查询，pg数据库 场景会报错，所以将其删除
			plan.remove(searchKey);
		}
	}

}
