DeviceInHandler.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.fdkankan.manage.factory;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.fdkankan.manage.common.ResultCode;
  4. import com.fdkankan.manage.constant.CameraOutTypeEnum;
  5. import com.fdkankan.manage.entity.AgentNew;
  6. import com.fdkankan.manage.exception.BusinessException;
  7. import com.fdkankan.manage.service.ICameraService;
  8. import com.fdkankan.manage.service.IExcelService;
  9. import com.fdkankan.manage.vo.request.CameraInOutParam;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Component;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. @Slf4j
  18. @Component("deviceIn")
  19. public class DeviceInHandler implements ImportExcelHandler{
  20. @Autowired
  21. private IExcelService excelService;
  22. @Autowired
  23. private ICameraService cameraService;
  24. @Override
  25. public int importExcel(List<HashMap<Integer, String>> excelRowList) {
  26. if(CollUtil.isEmpty(excelRowList)){
  27. return 0;
  28. }
  29. List<String> wifiNameList = new ArrayList<>();
  30. List<Integer> errorIndex = new ArrayList<>();
  31. Integer index = 0;
  32. for (HashMap<Integer, String> map : excelRowList) {
  33. index ++;
  34. if(index == 0 && !map.get(0).equals("设备入库模板")){
  35. throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
  36. }
  37. if(index <4){ //从第四行开始
  38. continue;
  39. }
  40. String wifiName = map.get(0);
  41. if(StringUtils.isBlank(wifiName)){
  42. errorIndex.add(index -3);
  43. }
  44. wifiNameList.add(wifiName);
  45. }
  46. excelService.toExcelError(errorIndex);
  47. if(wifiNameList.size() <=0){
  48. throw new BusinessException(ResultCode.IN_TEMPLATE_EMPTY);
  49. }
  50. return cameraService.ins(wifiNameList);
  51. }
  52. }