package com.fdkankan.manage.factory; import cn.hutool.core.collection.CollUtil; import com.fdkankan.manage.common.ResultCode; import com.fdkankan.manage.constant.CameraOutTypeEnum; import com.fdkankan.manage.entity.AgentNew; import com.fdkankan.manage.exception.BusinessException; import com.fdkankan.manage.service.ICameraService; import com.fdkankan.manage.service.IExcelService; import com.fdkankan.manage.vo.request.CameraInOutParam; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @Slf4j @Component("deviceIn") public class DeviceInHandler implements ImportExcelHandler{ @Autowired private IExcelService excelService; @Autowired private ICameraService cameraService; @Override public int importExcel(List> excelRowList) { if(CollUtil.isEmpty(excelRowList)){ return 0; } List wifiNameList = new ArrayList<>(); List errorIndex = new ArrayList<>(); Integer index = 0; for (HashMap map : excelRowList) { index ++; if(index == 0 && !map.get(0).equals("设备入库模板")){ throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR); } if(index <4){ //从第四行开始 continue; } String wifiName = map.get(0); if(StringUtils.isBlank(wifiName)){ errorIndex.add(index -3); } wifiNameList.add(wifiName); } excelService.toExcelError(errorIndex); if(wifiNameList.size() <=0){ throw new BusinessException(ResultCode.IN_TEMPLATE_EMPTY); } return cameraService.ins(wifiNameList); } }