package com.yuchen.saas.park.service.wrapper;

import com.yuchen.saas.park.api.entity.elevator.SaasParkElevatorManageLocationEntity;
import com.yuchen.saas.park.api.entity.elevator.SaasParkElevatorPermissionElevatorGroup;
import com.yuchen.saas.park.api.vo.elevator.ElevatorPointGroupVO;
import com.yuchen.saas.park.service.mapper.elevator.SaasParkElevatorManageLocationMapper;
import com.yuchen.saas.park.service.util.StringUtils;
import org.nest.springwrap.core.mp.support.BaseEntityWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: baichaojie
 * @CreateTime: 2024/07/15 17:50
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class ElevatorGroupWrapper extends BaseEntityWrapper<SaasParkElevatorPermissionElevatorGroup, ElevatorPointGroupVO> {

    @Resource
    private SaasParkElevatorManageLocationMapper saasParkElevatorManageLocationMapper;

    @Override
    public ElevatorPointGroupVO entityVO(SaasParkElevatorPermissionElevatorGroup entity) {
        ElevatorPointGroupVO billVo = new ElevatorPointGroupVO();
        BeanUtils.copyProperties(entity, billVo);

        if(!StringUtils.isEmpty(billVo.getElevatorRange())) {


            String [] str=billVo.getElevatorRange().split(",");
            List<String> list=new ArrayList<>(Arrays.asList(str));

            List<SaasParkElevatorManageLocationEntity> listByIds = saasParkElevatorManageLocationMapper.getListByIds(list);
            billVo.setElevatorList(listByIds);

            String levatorRangeStr = "";
            for (int i = 0; i < listByIds.size(); i++) {
                if (i != listByIds.size() - 1) {
                    levatorRangeStr += listByIds.get(i).getElevatorName() + ",";
                }else {
                    levatorRangeStr += listByIds.get(i).getElevatorName();
                }
            }
            billVo.setElevatorRangeStr(levatorRangeStr);
            billVo.setElevatorRangeString(levatorRangeStr);

        }
        if(billVo.getParkId()!=null){
            String parkName=saasParkElevatorManageLocationMapper.getParkNameByParkId(billVo.getParkId().toString());
            if(!StringUtils.isEmpty(parkName)){
                billVo.setParkName(parkName);
            }
        }


        return billVo;
    }
}