/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.yjxt.business.warn.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.core.tool.utils.SpringUtil;
import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
import org.springblade.modules.yjxt.business.resident.dto.DangerAreaResidentInfoDTO;
import org.springblade.modules.yjxt.business.resident.service.IDangerAreaResidentService;
import org.springblade.modules.yjxt.business.transfer.dto.DamageTransferPersonInfoDTO;
import org.springblade.modules.yjxt.business.transfer.service.IDamageTransferPersonService;
import org.springblade.modules.yjxt.business.warn.entity.OriginalWarningInfoEntity;
import org.springblade.modules.yjxt.business.warn.vo.OriginalWarningInfoVO;


import java.util.Objects;

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

    private static IRtuBaseInfoService rtuBaseInfoService;

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


    private static IDangerAreaResidentService dangerAreaResidentService;

    private static IDangerAreaResidentService getDangerAreaResidentService() {
        if (dangerAreaResidentService == null) {
            dangerAreaResidentService = SpringUtil.getBean(IDangerAreaResidentService.class);
        }
        return dangerAreaResidentService;
    }


    private static IDamageTransferPersonService damageTransferPersonService;

    private static IDamageTransferPersonService getDamageTransferPersonService() {
        if (damageTransferPersonService == null) {
            damageTransferPersonService = SpringUtil.getBean(IDamageTransferPersonService.class);
        }
        return damageTransferPersonService;
    }

    @Override
    public OriginalWarningInfoVO entityVO(OriginalWarningInfoEntity entity) {
        OriginalWarningInfoVO vo = Objects.requireNonNull(BeanUtil.copy(entity, OriginalWarningInfoVO.class));
//        if (Func.notNull(vo.getRtuCode())){
////           RtuInfoEntity rtuInfoEntity= getRtuBaseInfoService().rtuInfoByRtuCode(vo.getRtuCode());
////           if (Func.notNull(rtuInfoEntity)){
////               if (Func.notNull(rtuInfoEntity.getLat()) && Func.notNull(rtuInfoEntity.getLng())){
////                   vo.setWarnLgtd();
////               }
////           }
////        }

        DangerAreaResidentInfoDTO residentInfoDTO=new DangerAreaResidentInfoDTO();
        residentInfoDTO.setDangerAreaCode(entity.getWarnAdcd());
        long totalTransferPerson =getDangerAreaResidentService().residentCount(residentInfoDTO);

        DamageTransferPersonInfoDTO transferPersonInfoDTO = new DamageTransferPersonInfoDTO();
        transferPersonInfoDTO.setWarnId(Func.toStr(entity.getId()));
        long safetyTransferPerson = getDamageTransferPersonService().transferPersonCount(transferPersonInfoDTO);

        vo.setTotalTransferPerson(totalTransferPerson);
        vo.setSafetyTransferPerson(safetyTransferPerson);

        return vo;
    }
}
