package com.bonus.sgzb.material.service.impl;

import com.bonus.sgzb.base.api.domain.MaMachine;
import com.bonus.sgzb.base.domain.vo.IotRecordVo;
import com.bonus.sgzb.base.mapper.BaseIotMachineMapper;
import com.bonus.sgzb.material.domain.LeaseRecord;
import com.bonus.sgzb.material.mapper.LeaseRecordMapper;
import com.bonus.sgzb.material.service.LeaseRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author hay
 * @date 2023/12/20 14:55
 */
@Service
public class LeaseRecordServiceImpl implements LeaseRecordService {

    @Resource
    private LeaseRecordMapper leaseRecordMapper;

    @Resource
    private BaseIotMachineMapper baseIotMachineMapper;
    @Override
    public List<LeaseRecord> getLeaseRecordList(LeaseRecord bean) {
        List<LeaseRecord> listMaMachine =leaseRecordMapper.getLeaseRecordList(bean);
        if (listMaMachine.size() > 0){
            for (LeaseRecord leaseRecord : listMaMachine) {
                //根据机具编码查询iot设备
                    List<IotRecordVo>  iotRecordVoList = baseIotMachineMapper.selectList(leaseRecord.getMaCode());
                    leaseRecord.setIotNum(iotRecordVoList.size());
                    //判断是否绑定了iot设备
                    if (iotRecordVoList.size()>0){
                        for (int i = 0; i < iotRecordVoList.size(); i++) {
                            //保存定位iot设备编码
                            if ("125".equals(iotRecordVoList.get(i).getIotType())){
                                leaseRecord.setIotCode(iotRecordVoList.get(i).getIotCode());
                            }
                        }
                }
            }
        }
        return listMaMachine;
    }
}
