package com.yuchen.saas.park.service.service.elevator.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thinkunion.sdk.iot.bean.api.CallingDeviceServiceResponse;
import com.yuchen.saas.park.api.dto.elevator.iot.request.CarCallDTO;
import com.yuchen.saas.park.api.dto.elevator.iot.request.KeepDoorDTO;
import com.yuchen.saas.park.api.dto.park.IoTEvent;
import com.yuchen.saas.park.api.dto.pldoor.CallDeviceServiceDto;
import com.yuchen.saas.park.api.entity.elevator.SaasParkElevatorManageLocationEntity;
import com.yuchen.saas.park.api.entity.elevator.SaasParkElevatorMonitorRunningStateEntity;
import com.yuchen.saas.park.api.entity.park.PmgBatParkInfo;
import com.yuchen.saas.park.api.entity.property.PropertyBuildingUnit;
import com.yuchen.saas.park.api.entity.property.PropertyBuildings;
import com.yuchen.saas.park.api.request.ElevatorMonitorRunningStateRequest;
import com.yuchen.saas.park.api.request.ThirdCallElevatorRequest;
import com.yuchen.saas.park.api.response.ElevatorMonitorRunningStateResponse;
import com.yuchen.saas.park.api.response.ThirdElevatorMonitorRunningStateResponse;
import com.yuchen.saas.park.service.iot.IoTRemoteService;
import com.yuchen.saas.park.service.mapper.elevator.SaasParkElevatorManageLocationMapper;
import com.yuchen.saas.park.service.mapper.elevator.SaasParkElevatorMonitorRunningStateMapper;
import com.yuchen.saas.park.service.mapper.property.PropertyBuildingUnitMapper;
import com.yuchen.saas.park.service.mapper.property.PropertyBuildingsMapper;
import com.yuchen.saas.park.service.service.PmgBatParkInfoService;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorMonitorRunningStateService;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 梯控-电梯监测-运行状态 服务实现类
 * </p>
 *
 * @author baichaojie
 * @since 2024-06-21
 */
@Service
@Slf4j
public class SaasParkElevatorMonitorRunningStateServiceImpl extends BaseServiceImpl<SaasParkElevatorMonitorRunningStateMapper, SaasParkElevatorMonitorRunningStateEntity> implements ISaasParkElevatorMonitorRunningStateService {

    // 电梯状态上报
    private final String LIFTSTATUS = "liftStatus";
    //设备状态更新上报
    private final String DEVSTATEUPDATE = "devStateUpdate";

    private final String KEEPDOOR = "keepDoor";

    private final String CARCALL = "carCall";


    @Resource
    private SaasParkElevatorManageLocationMapper saasParkElevatorManageLocationMapper;

    @Resource
    private PropertyBuildingsMapper propertyBuildingsMapper;

    @Resource
    private PropertyBuildingUnitMapper propertyBuildingUnitMapper;

    //@Resource
    //private ISaasParkElevatorMonitorRunningStateService iSaasParkElevatorMonitorRunningStateService;

    @Resource
    private SaasParkElevatorMonitorRunningStateMapper saasParkElevatorMonitorRunningStateMapper;


    @Resource
    private IoTRemoteService ioTRemoteService;

    @Autowired
    private PmgBatParkInfoService pmgBatParkInfoService;

    @Override
    public R<IPage<ThirdElevatorMonitorRunningStateResponse>> thirdList(ElevatorMonitorRunningStateRequest qryDTO, Query query) {

        Page<SaasParkElevatorMonitorRunningStateEntity> page = new Page<>(query.getCurrent(), query.getSize());
        //分页查询
        LambdaQueryWrapper<SaasParkElevatorMonitorRunningStateEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getParkId()), SaasParkElevatorMonitorRunningStateEntity::getParkId, qryDTO.getParkId());
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getBuildingId()), SaasParkElevatorMonitorRunningStateEntity::getBuildingId, qryDTO.getBuildingId());
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getUnitId()), SaasParkElevatorMonitorRunningStateEntity::getUnitId, qryDTO.getUnitId());
        //设备状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getErrorStatus()), SaasParkElevatorMonitorRunningStateEntity::getErrorStatus, qryDTO.getErrorStatus());
        //运行状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getRunningDirection()), SaasParkElevatorMonitorRunningStateEntity::getRunningDirection, qryDTO.getRunningDirection());
        //联网状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getIsOnline()), SaasParkElevatorMonitorRunningStateEntity::getIsOnline, qryDTO.getIsOnline());
        //设备id
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getId()), SaasParkElevatorMonitorRunningStateEntity::getElevatorMokuaiId, qryDTO.getId());

        IPage<SaasParkElevatorMonitorRunningStateEntity> pages = this.page(page, lambdaQueryWrapper);

        List<SaasParkElevatorMonitorRunningStateEntity> saasParkElevatorMonitorRunningStateEntity = pages.getRecords();


        if (saasParkElevatorMonitorRunningStateEntity.isEmpty()) {
            return R.data(Condition.getPage(query));
        }

        //组装返回response
        IPage<ThirdElevatorMonitorRunningStateResponse> pageVo = new Page(pages.getCurrent(), pages.getSize(), pages.getTotal());
        List<ThirdElevatorMonitorRunningStateResponse> records = this.thirdListVO(pages.getRecords());

        pageVo.setRecords(records);
        return R.data(pageVo);

    }


    @Override
    public R<IPage<ElevatorMonitorRunningStateResponse>> list(ElevatorMonitorRunningStateRequest qryDTO, Query query) {

        Page<SaasParkElevatorMonitorRunningStateEntity> page = new Page<>(query.getCurrent(), query.getSize());
        //分页查询
        LambdaQueryWrapper<SaasParkElevatorMonitorRunningStateEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getParkId()), SaasParkElevatorMonitorRunningStateEntity::getParkId, qryDTO.getParkId());
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getBuildingId()), SaasParkElevatorMonitorRunningStateEntity::getBuildingId, qryDTO.getBuildingId());
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getUnitId()), SaasParkElevatorMonitorRunningStateEntity::getUnitId, qryDTO.getUnitId());
        //设备状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getErrorStatus()), SaasParkElevatorMonitorRunningStateEntity::getErrorStatus, qryDTO.getErrorStatus());
        //运行状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getRunningDirection()), SaasParkElevatorMonitorRunningStateEntity::getRunningDirection, qryDTO.getRunningDirection());
        //联网状态
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getIsOnline()), SaasParkElevatorMonitorRunningStateEntity::getIsOnline, qryDTO.getIsOnline());
        //设备点id
        lambdaQueryWrapper.eq(Func.isNotEmpty(qryDTO.getId()), SaasParkElevatorMonitorRunningStateEntity::getElevatorMokuaiId, qryDTO.getId());
        IPage<SaasParkElevatorMonitorRunningStateEntity> pages = this.page(page, lambdaQueryWrapper);

        List<SaasParkElevatorMonitorRunningStateEntity> saasParkElevatorMonitorRunningStateEntity = pages.getRecords();


        if (saasParkElevatorMonitorRunningStateEntity.isEmpty()) {
            return R.data(Condition.getPage(query));
        }

        //组装返回response
        IPage<ElevatorMonitorRunningStateResponse> pageVo = new Page(pages.getCurrent(), pages.getSize(), pages.getTotal());
        List<ElevatorMonitorRunningStateResponse> records = this.listVO(pages.getRecords());

        pageVo.setRecords(records);
        return R.data(pageVo);

    }

    @Override
    public boolean receiveIotEvent(String jsonObjectContent) throws Exception {
        // 处理接收到的iot事件
        log.info("====== 接收到的iot上报设备事件:{}", jsonObjectContent);
        if (Func.isEmpty(jsonObjectContent)) {
            log.error("====== 接收到的iot上报事件为空");
            return false;
        }
        IoTEvent ioTEvent = JSON.parseObject(jsonObjectContent, IoTEvent.class);
        if (Func.isEmpty(ioTEvent) || Func.isEmpty(ioTEvent.getIdentifier())) {
            throw new RuntimeException("====== 接收到的iot上报事件为空");
        }
        String identifier = ioTEvent.getIdentifier();
        if (identifier.equals(LIFTSTATUS)) {
            //电梯状态上报
            saveLiftStatus(ioTEvent, ioTEvent.getDeviceName());
        } else if (identifier.equals(DEVSTATEUPDATE)) {
            //设备状态更新上报
            saveDevStateUpdateUp(ioTEvent, ioTEvent.getDeviceName());
        }
        return true;
    }

    @Override
    public boolean callElevator(ThirdCallElevatorRequest thirdCallElevatorRequest) {

        log.info("====== 呼梯id:{},楼层:{}", thirdCallElevatorRequest.getId(), thirdCallElevatorRequest.getDesDoor());


        SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectById(thirdCallElevatorRequest.getId());
        if (saasParkElevatorManageLocationEntity == null) {
            throw new RuntimeException("呼叫的电梯不存在");
        }

//        if ("1".equals(saasParkElevatorManageLocationEntity.getOnlineStatus())) {
//            throw new RuntimeException("呼叫的电梯未在线");
//        }

        CallDeviceServiceDto callDeviceServiceDto = new CallDeviceServiceDto();
        callDeviceServiceDto.setIdentify(CARCALL);
        callDeviceServiceDto.setProductKey(saasParkElevatorManageLocationEntity.getProductKey());
        callDeviceServiceDto.setDeviceName(saasParkElevatorManageLocationEntity.getDeviceDid());
        Map<String, Object> in = new HashMap<>();
        try {

            CarCallDTO carCallDTO = new CarCallDTO();
            carCallDTO.setCarDoor(thirdCallElevatorRequest.getCarDoor() == null ? 0 : thirdCallElevatorRequest.getCarDoor());//0前面,1后门
            carCallDTO.setDesDoor(thirdCallElevatorRequest.getDesDoor());//目标楼层
            carCallDTO.setRobotID("11111");//机器人ID

            if (saasParkElevatorManageLocationEntity.getDeviceDid() == null) {
                throw new RuntimeException("呼叫的电梯未接入IOT");
            }
            carCallDTO.setDeviceID(saasParkElevatorManageLocationEntity.getIotDeviceId());

            in.put("robotID", carCallDTO.getRobotID());
            in.put("carDoor", carCallDTO.getCarDoor());
            in.put("desDoor", carCallDTO.getDesDoor());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        callDeviceServiceDto.setParams(in);
        String json = JSONObject.toJSONString(callDeviceServiceDto);
        Map map = JSONObject.parseObject(json, Map.class);

        //调用接口
        log.info("====== 呼梯参数：{}", json);
        CallingDeviceServiceResponse response = ioTRemoteService.callServiceReturn(map);
        if (Func.isNotEmpty(response)) {
            boolean result = false;
            String resultJson = JSONObject.toJSONString(response);
            log.info("====== 呼梯返回数据：{}", resultJson);
            if (response.getCode().equals("200")) {
                result = true;
            }
            return result;
        }
        return false;

    }

    @Override
    public boolean keepElevatorDoor(Long id, int status) {

        log.info("====== 电梯保持开关门id:{}", id);
        log.info("====== 电梯保持开关门状态:{}", status);

        SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectById(id);
        if (saasParkElevatorManageLocationEntity == null) {
            throw new RuntimeException("呼叫的电梯不存在");
        }

//        if ("1".equals(saasParkElevatorManageLocationEntity.getOnlineStatus())) {
//            throw new RuntimeException("呼叫的电梯未在线");
//        }

        CallDeviceServiceDto callDeviceServiceDto = new CallDeviceServiceDto();
        callDeviceServiceDto.setIdentify(KEEPDOOR);
        callDeviceServiceDto.setProductKey(saasParkElevatorManageLocationEntity.getProductKey());
        callDeviceServiceDto.setDeviceName(saasParkElevatorManageLocationEntity.getDeviceDid());
        Map<String, Object> in = new HashMap<>();
        try {

            KeepDoorDTO keepDoorDTO = new KeepDoorDTO();
            keepDoorDTO.setKeepOpenDoor(status);//0关,1开
            keepDoorDTO.setRobotID("11111");//机器人ID

            if (saasParkElevatorManageLocationEntity.getDeviceDid() == null) {
                throw new RuntimeException("要保持开门的电梯未接入IOT");
            }
            //keepDoorDTO.setDeviceID(saasParkElevatorManageLocationEntity.getIotDeviceId());

            in.put("robotID", keepDoorDTO.getRobotID());
            in.put("keepOpenDoor", keepDoorDTO.getKeepOpenDoor());
            //in.put("deviceID", keepDoorDTO.getDeviceID());

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        callDeviceServiceDto.setParams(in);
        String json = JSONObject.toJSONString(callDeviceServiceDto);
        Map map = JSONObject.parseObject(json, Map.class);

        //调用接口
        log.info("====== 发送开门保持指令参数：{}", json);
        CallingDeviceServiceResponse response = ioTRemoteService.callServiceReturn(map);
        if (Func.isNotEmpty(response)) {
            boolean result = false;
            String resultJson = JSONObject.toJSONString(response);
            log.info("====== 发送开门保持指令返回数据：{}", resultJson);
            if (response.getCode().equals("200")) {
                result = true;
            }
            return result;
        }
        return false;


    }

    /**
     * 设备状态更新上报保存数据库
     *
     * @param ioTEvent
     */
    private void saveDevStateUpdateUp(IoTEvent ioTEvent, String deviceName) {

        if (Func.isNotEmpty(ioTEvent) && Func.isNotEmpty(ioTEvent.getOut())) {
            Map<String, Object> out = ioTEvent.getOut();
            List<Map<String, Object>> list = (List<Map<String, Object>>) out.get("data");
            List<SaasParkElevatorMonitorRunningStateEntity> saasParkElevatorMonitorRunningStateEntityList = new ArrayList<>();
            for (Map<String, Object> outMap : list) {
                //根据iot传过来的设备name获取门禁点里对应的设备
                SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectOne(Wrappers.<SaasParkElevatorManageLocationEntity>lambdaQuery()
                        .eq(SaasParkElevatorManageLocationEntity::getDeviceName, deviceName).last("limit 1"));

                if (saasParkElevatorManageLocationEntity == null) {
                    continue;
                }


                //根据iot传过来的设备id获取系统数据库中该设备的运行状态信息
                //根据iot传过来的设备id获取系统数据库中该设备的运行状态信息
                SaasParkElevatorMonitorRunningStateEntity saasParkElevatorMonitorRunningStateEntity = saasParkElevatorMonitorRunningStateMapper.selectOne(Wrappers.<SaasParkElevatorMonitorRunningStateEntity>lambdaQuery()
                        .eq(SaasParkElevatorMonitorRunningStateEntity::getElevatorMokuaiId, saasParkElevatorManageLocationEntity.getId()).last("limit 1"));

                if (saasParkElevatorMonitorRunningStateEntity == null) {
                    //记录不存在添加一条
                    saasParkElevatorMonitorRunningStateEntity = new SaasParkElevatorMonitorRunningStateEntity();

                    saasParkElevatorMonitorRunningStateEntity.setParkId(saasParkElevatorManageLocationEntity.getParkId());
                    saasParkElevatorMonitorRunningStateEntity.setUnitId(saasParkElevatorManageLocationEntity.getUnitId());
                    saasParkElevatorMonitorRunningStateEntity.setBuildingId(saasParkElevatorManageLocationEntity.getBuildingId());
                    saasParkElevatorMonitorRunningStateEntity.setElevatorMokuaiId(saasParkElevatorManageLocationEntity.getId());
                    if (saasParkElevatorMonitorRunningStateEntity.getCreateTime() == null) {
                        saasParkElevatorMonitorRunningStateEntity.setCreateTime(new Date());
                    }


                }
                saasParkElevatorMonitorRunningStateEntity.setUpdateTime(new Date());
                saasParkElevatorMonitorRunningStateEntity.setIsDeleted(0);


                String deviceState = outMap.get("deviceState").toString();
                Integer isOnLine = 0;
                if ((int) Double.parseDouble(deviceState) == 1) {
                    isOnLine = 1;
                }
                saasParkElevatorMonitorRunningStateEntity.setIsOnline(isOnLine);
                saasParkElevatorMonitorRunningStateEntityList.add(saasParkElevatorMonitorRunningStateEntity);
            }
            saveOrUpdateBatch(saasParkElevatorMonitorRunningStateEntityList);
        }


    }

    /**
     * 电梯状态上报保存数据库
     *
     * @param ioTEvent
     */
    private void saveLiftStatus(IoTEvent ioTEvent, String deviceName) {
        if (Func.isNotEmpty(ioTEvent) && Func.isNotEmpty(ioTEvent.getOut())) {
            Map<String, Object> out = ioTEvent.getOut();
            List<Map<String, Object>> list = (List<Map<String, Object>>) out.get("data");
            List<SaasParkElevatorMonitorRunningStateEntity> saasParkElevatorMonitorRunningStateEntityList = new ArrayList<>();
            for (Map<String, Object> outMap : list) {


                //根据iot传过来的设备name获取门禁点里对应的设备

                SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectOne(Wrappers.<SaasParkElevatorManageLocationEntity>lambdaQuery()
                        .eq(SaasParkElevatorManageLocationEntity::getDeviceName, deviceName).last("limit 1"));

                if (saasParkElevatorManageLocationEntity == null) {
                    continue;
                }


                //根据iot传过来的设备id获取系统数据库中该设备的运行状态信息
                SaasParkElevatorMonitorRunningStateEntity saasParkElevatorMonitorRunningStateEntity = saasParkElevatorMonitorRunningStateMapper.selectOne(Wrappers.<SaasParkElevatorMonitorRunningStateEntity>lambdaQuery()
                        .eq(SaasParkElevatorMonitorRunningStateEntity::getElevatorMokuaiId, saasParkElevatorManageLocationEntity.getId()).last("limit 1"));

                if (saasParkElevatorMonitorRunningStateEntity == null) {
                    //记录不存在添加一条
                    saasParkElevatorMonitorRunningStateEntity = new SaasParkElevatorMonitorRunningStateEntity();

                    saasParkElevatorMonitorRunningStateEntity.setParkId(saasParkElevatorManageLocationEntity.getParkId());
                    saasParkElevatorMonitorRunningStateEntity.setUnitId(saasParkElevatorManageLocationEntity.getUnitId());
                    saasParkElevatorMonitorRunningStateEntity.setBuildingId(saasParkElevatorManageLocationEntity.getBuildingId());
                    saasParkElevatorMonitorRunningStateEntity.setElevatorMokuaiId(saasParkElevatorManageLocationEntity.getId());
                    if (saasParkElevatorMonitorRunningStateEntity.getCreateTime() == null) {
                        saasParkElevatorMonitorRunningStateEntity.setCreateTime(new Date());
                    }


                }
                saasParkElevatorMonitorRunningStateEntity.setUpdateTime(new Date());
                saasParkElevatorMonitorRunningStateEntity.setIsDeleted(0);



                // saasParkElevatorMonitorRunningStateEntity.setIsOnline(outMap.get("isOnline").toString());

                //维修状态 平台:(0异常、1正常)  IOT<oss>:(0正常使用、1停止使用)
                String oss = outMap.get("oss").toString();
                Integer repairStatus = 0;
                if ((int) Double.parseDouble(oss) == 0) {
                    repairStatus = 1;
                }
                saasParkElevatorMonitorRunningStateEntity.setRepairStatus(repairStatus);

                //故障状态 平台:(0异常、1正常)  IOT<fault>:(0正常、1异常)
                String fault = outMap.get("fault").toString();
                Integer errorStatus = 0;
                if ((int) Double.parseDouble(fault) == 0) {
                    errorStatus = 1;
                }
                saasParkElevatorMonitorRunningStateEntity.setErrorStatus(errorStatus);

                //物理楼层pFloor
                String pFloor = outMap.get("pFloor").toString();
                Integer nowFloor = (int) Double.parseDouble(pFloor);

                //IOT给的楼层转成系统的楼层
                Integer softFloor = getSoftFloor(nowFloor, saasParkElevatorManageLocationEntity.getStartFloor(), saasParkElevatorManageLocationEntity.getEndFloor());

                saasParkElevatorMonitorRunningStateEntity.setNowFloor(softFloor);

                //运行方向 平台:(1上行,-1下行,0停止) IOT<direction>:(1上行,2下行,0停止)
                String direction = outMap.get("direction").toString();
                Integer runningDirection = 0;
                if ((int) Double.parseDouble(direction) == 1) {
                    runningDirection = 1;
                }
                if ((int) Double.parseDouble(direction) == 2) {
                    runningDirection = -1;
                }
                if ((int) Double.parseDouble(direction) == 0) {
                    runningDirection = 0;
                }
                saasParkElevatorMonitorRunningStateEntity.setRunningDirection(runningDirection);

                //开门状态 平台(0关 1开 2关门到位 3开门到位)
                String door = outMap.get("door").toString();
                Integer openStatus = 0;
                if ((int) Double.parseDouble(door) == 0) {
                    openStatus = 0;
                }
                if ((int) Double.parseDouble(door) == 1) {
                    openStatus = 1;
                }
                if ((int) Double.parseDouble(door) == 2) {
                    openStatus = 2;
                }
                if ((int) Double.parseDouble(door) == 3) {
                    openStatus = 3;
                }
                saasParkElevatorMonitorRunningStateEntity.setOpenStatus(openStatus);

                saasParkElevatorMonitorRunningStateEntityList.add(saasParkElevatorMonitorRunningStateEntity);
            }
            saveOrUpdateBatch(saasParkElevatorMonitorRunningStateEntityList);
        }
    }

    private Integer getSoftFloor(Integer nowFloor, Integer startFloor, Integer endFloor) {

        Integer softFloor = 1;
        if (startFloor == null) {
            startFloor = 1;
        }
        if (endFloor == null) {
            endFloor = 100;
        }

        if (startFloor < 0) {
            //存在地下室
            softFloor = nowFloor - 1 + startFloor + 1;
        }
        if (startFloor > 0) {
            //存在地下室
            softFloor = nowFloor - 1 + startFloor;
        }

        return softFloor;

    }


    private List<ElevatorMonitorRunningStateResponse> listVO(List<SaasParkElevatorMonitorRunningStateEntity> list) {
        return list.stream().map(entity -> {
            ElevatorMonitorRunningStateResponse elevatorMonitorRunningStateResponse = new ElevatorMonitorRunningStateResponse();
            BeanUtils.copyProperties(entity, elevatorMonitorRunningStateResponse);

            SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectById(entity.getElevatorMokuaiId());

            if (saasParkElevatorManageLocationEntity != null) {
                elevatorMonitorRunningStateResponse.setElevatorName(saasParkElevatorManageLocationEntity.getElevatorName());
                elevatorMonitorRunningStateResponse.setFaceDeviceIds(saasParkElevatorManageLocationEntity.getFaceDeviceIds());
                elevatorMonitorRunningStateResponse.setVideoDeviceIds(saasParkElevatorManageLocationEntity.getVideoDeviceIds());
            }

            PmgBatParkInfo parkInfo = pmgBatParkInfoService.getById(entity.getParkId());
            if (Func.isNotEmpty(parkInfo)) {
                elevatorMonitorRunningStateResponse.setParkName(parkInfo.getParkName());
            }

            PropertyBuildings propertyBuildings = propertyBuildingsMapper.selectById(entity.getBuildingId());
            if (propertyBuildings != null) {
                elevatorMonitorRunningStateResponse.setBuildingName(propertyBuildings.getBuildingName());
            }

            PropertyBuildingUnit propertyBuildingUnit = propertyBuildingUnitMapper.selectById(entity.getUnitId());
            if (propertyBuildingUnit != null) {
                elevatorMonitorRunningStateResponse.setUnitName(propertyBuildingUnit.getUnitName());
            }


            return elevatorMonitorRunningStateResponse;
        }).collect(Collectors.toList());
    }


    private List<ThirdElevatorMonitorRunningStateResponse> thirdListVO(List<SaasParkElevatorMonitorRunningStateEntity> list) {
        return list.stream().map(entity -> {
            ThirdElevatorMonitorRunningStateResponse elevatorMonitorRunningStateResponse = new ThirdElevatorMonitorRunningStateResponse();
            BeanUtils.copyProperties(entity, elevatorMonitorRunningStateResponse);

            SaasParkElevatorManageLocationEntity saasParkElevatorManageLocationEntity = saasParkElevatorManageLocationMapper.selectById(entity.getElevatorMokuaiId());

            if (saasParkElevatorManageLocationEntity != null) {
                elevatorMonitorRunningStateResponse.setElevatorName(saasParkElevatorManageLocationEntity.getElevatorName());
                //elevatorMonitorRunningStateResponse.setFaceDeviceIds(saasParkElevatorManageLocationEntity.getFaceDeviceIds());
                //elevatorMonitorRunningStateResponse.setVideoDeviceIds(saasParkElevatorManageLocationEntity.getVideoDeviceIds());
            }

            PmgBatParkInfo parkInfo = pmgBatParkInfoService.getById(entity.getParkId());
            if (Func.isNotEmpty(parkInfo)) {
                elevatorMonitorRunningStateResponse.setParkName(parkInfo.getParkName());
            }

            PropertyBuildings propertyBuildings = propertyBuildingsMapper.selectById(entity.getBuildingId());
            if (propertyBuildings != null) {
                elevatorMonitorRunningStateResponse.setBuildingName(propertyBuildings.getBuildingName());
            }

            PropertyBuildingUnit propertyBuildingUnit = propertyBuildingUnitMapper.selectById(entity.getUnitId());
            if (propertyBuildingUnit != null) {
                elevatorMonitorRunningStateResponse.setUnitName(propertyBuildingUnit.getUnitName());
            }

            elevatorMonitorRunningStateResponse.setId(entity.getElevatorMokuaiId());
            return elevatorMonitorRunningStateResponse;
        }).collect(Collectors.toList());
    }

}
