package com.bonus.canteen.core.bus.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.canteen.core.bus.mapper.BusLineMapper;
import com.bonus.canteen.core.bus.model.BusLine;
import com.bonus.canteen.core.bus.service.BusLineService;
import com.bonus.canteen.core.bus.vo.BusDeviceVO;
import com.bonus.canteen.core.bus.vo.BusLineDeviceVO;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class BusLineServiceImpl extends ServiceImpl<BusLineMapper, BusLine> implements BusLineService {
   private static final Logger log = LoggerFactory.getLogger(BusLineServiceImpl.class);
   @Resource
   @Lazy
   private BusLineMapper busLineMapper;


   @Override
   public List<BusLineDeviceVO> queryBusLineAndDeviceList() {
      List<BusLine> busLineList =
              this.list(Wrappers.<BusLine>lambdaQuery()
                      .select(BusLine::getLineId, BusLine::getLineNum, BusLine::getLineName)
                      .eq(BusLine::getDelFlag, LeConstants.COMMON_NO));
      if (CollUtil.isEmpty(busLineList)) {
         return new ArrayList();
      } else {
         List<BusLineDeviceVO> busLineDeviceVOList = BeanUtil.copyToList(busLineList, BusLineDeviceVO.class);
         Iterator var3 = busLineDeviceVOList.iterator();

         while(var3.hasNext()) {
            BusLineDeviceVO busLineDeviceVO = (BusLineDeviceVO)var3.next();
            List<BusDeviceVO> busDeviceVOList = this.busLineMapper.queryBusLineAndDeviceList(busLineDeviceVO.getLineId());
            busLineDeviceVO.setBusDeviceVOList(busDeviceVOList);
         }

         return busLineDeviceVOList;
      }
   }
}
