Browse Source

增加mq工具api
改造excel导入

dsx 2 năm trước cách đây
mục cha
commit
408e38af2f

+ 62 - 0
src/main/java/com/fdkankan/manage/factory/CustomerRelaHandler.java

@@ -0,0 +1,62 @@
+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 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;
+
+@Component("customerRela")
+public class CustomerRelaHandler implements ImportExcelHandler{
+
+    @Autowired
+    private IExcelService excelService;
+    @Autowired
+    private ICameraService cameraService;
+
+    @Override
+    public int importExcel(List<HashMap<Integer, String>> excelRowList) {
+
+        if(CollUtil.isEmpty(excelRowList)){
+            return 0;
+        }
+
+        List<Integer> errorIndex = new ArrayList<>();
+        List<CameraInOutParam> companyParams = new ArrayList<>();
+
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index ++;
+            if(index == 0 && !map.get(0).equals("客户关联模板")){
+                throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
+            }
+            if(index <4){
+                continue;
+            }
+            CameraInOutParam param = new CameraInOutParam();
+            param.setCompanyName(map.get(0));
+            param.setSnCode(map.get(1));
+            if(StringUtils.isBlank(param.getSnCode()) || StringUtils.isBlank(param.getCompanyName())){
+                errorIndex.add(index -3 );
+            }
+            companyParams.add(param);
+        }
+        excelService.toExcelError(errorIndex);
+
+        if(companyParams.size() <=0){
+            throw new BusinessException(ResultCode.COMPANY_TEMPLATE_EMPTY);
+        }
+
+        return cameraService.updateCompany(companyParams);
+    }
+}

+ 48 - 1
src/main/java/com/fdkankan/manage/factory/DeviceInHandler.java

@@ -1,15 +1,62 @@
 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<HashMap<Integer, String>> excelRowList) {
-        return 0;
+
+        if(CollUtil.isEmpty(excelRowList)){
+            return 0;
+        }
+
+        List<String> wifiNameList = new ArrayList<>();
+        List<Integer> errorIndex = new ArrayList<>();
+        Integer index = 0;
+        for (HashMap<Integer, String> 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);
     }
 }

+ 101 - 0
src/main/java/com/fdkankan/manage/factory/DeviceOutHandler.java

@@ -0,0 +1,101 @@
+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.IAgentNewService;
+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("deviceOut")
+public class DeviceOutHandler implements ImportExcelHandler{
+
+    @Autowired
+    private IAgentNewService agentNewService;
+    @Autowired
+    private IExcelService excelService;
+    @Autowired
+    private ICameraService cameraService;
+
+    @Override
+    public int importExcel(List<HashMap<Integer, String>> excelRowList) {
+
+        if(CollUtil.isEmpty(excelRowList)){
+            return 0;
+        }
+
+        List<CameraInOutParam> params = new ArrayList<>();
+        List<Integer> errorIndex = new ArrayList<>();
+
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index ++;
+            if(index == 0 && !map.get(0).equals("设备出库模板")){
+                throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
+            }
+            if(index <4){
+                continue;
+            }
+            String snCode = map.get(0);
+            String outTypeString = map.get(1);
+            String companyName = map.get(2);
+            String orderSn = map.get(3);
+            String agentName = map.get(4);
+            CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
+            if(outTypeEnum == null || StringUtils.isBlank(snCode)){
+                log.error("outError-->出库错误:出库类型为空或snCode为空:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
+                        ,snCode,outTypeString,companyName,orderSn,agentName);
+                errorIndex.add(index -3);
+            }
+            CameraInOutParam param = new CameraInOutParam();
+            if(outTypeEnum != null){
+                int outType = outTypeEnum.getCode();
+                param.setOutType(outType);
+            }
+            if(param.getOutType() != null && param.getOutType() == 4 && StringUtils.isBlank(agentName)){
+                log.error("outError-->出库错误:经销商为空错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
+                        ,snCode,outTypeString,companyName,orderSn,agentName);
+                errorIndex.add(index -3);
+            }
+            if(param.getOutType() != null && param.getOutType() != 4 && StringUtils.isNotBlank(agentName)){
+                log.error("outError-->出库错误:出库类型错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
+                        ,snCode,outTypeString,companyName,orderSn,agentName);
+                errorIndex.add(index -3);
+            }
+            if(StringUtils.isNotBlank(agentName)){
+                AgentNew agentNew = agentNewService.getByName(agentName);
+                if(agentNew == null){
+                    log.error("outError-->出库错误:代理商不存在:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
+                            ,snCode,outTypeString,companyName,orderSn,agentName);
+                    errorIndex.add(index -3);
+                }else {
+                    param.setAgentId(agentNew.getId());
+                }
+            }
+            param.setCompanyName(companyName);
+            param.setOrderSn(orderSn);
+            param.setSnCode(snCode);
+            params.add(param);
+        }
+
+        excelService.toExcelError(errorIndex);
+
+        if(params.size() <=0){
+            throw new BusinessException(ResultCode.OUT_TEMPLATE_EMPTY);
+        }
+
+        return cameraService.outs(params);
+    }
+}

+ 1 - 100
src/main/java/com/fdkankan/manage/service/impl/ExcelServiceImpl.java

@@ -102,106 +102,7 @@ public class ExcelServiceImpl implements IExcelService {
         List<Integer> errorIndex = new ArrayList<>();
 
         ImportExcelHandler handler = ExcelHandlerFactory.getHandler(ImportExcelType.get(type).message());
-        handler.importExcel(excelRowList);
-
-        Integer index = 0;
-        for (HashMap<Integer, String> map : excelRowList) {
-            index ++;
-            if(type == 0){      //入库
-                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);
-            }else if(type == 1){    //出库
-                if(index == 0 && !map.get(0).equals("设备出库模板")){
-                    throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
-                }
-                if(index <4){
-                    continue;
-                }
-                String snCode = map.get(0);
-                String outTypeString = map.get(1);
-                String companyName = map.get(2);
-                String orderSn = map.get(3);
-                String agentName = map.get(4);
-                CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
-                if(outTypeEnum == null || StringUtils.isBlank(snCode)){
-                    log.error("outError-->出库错误:出库类型为空或snCode为空:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
-                            ,snCode,outTypeString,companyName,orderSn,agentName);
-                    errorIndex.add(index -3);
-                }
-                CameraInOutParam param = new CameraInOutParam();
-                if(outTypeEnum != null){
-                    int outType = outTypeEnum.getCode();
-                    param.setOutType(outType);
-                }
-                if(param.getOutType() != null && param.getOutType() == 4 && StringUtils.isBlank(agentName)){
-                    log.error("outError-->出库错误:经销商为空错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
-                            ,snCode,outTypeString,companyName,orderSn,agentName);
-                    errorIndex.add(index -3);
-                }
-                if(param.getOutType() != null && param.getOutType() != 4 && StringUtils.isNotBlank(agentName)){
-                    log.error("outError-->出库错误:出库类型错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
-                            ,snCode,outTypeString,companyName,orderSn,agentName);
-                    errorIndex.add(index -3);
-                }
-                if(StringUtils.isNotBlank(agentName)){
-                    AgentNew agentNew = agentNewService.getByName(agentName);
-                    if(agentNew == null){
-                        log.error("outError-->出库错误:代理商不存在:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
-                                ,snCode,outTypeString,companyName,orderSn,agentName);
-                        errorIndex.add(index -3);
-                    }else {
-                        param.setAgentId(agentNew.getId());
-                    }
-                }
-                param.setCompanyName(companyName);
-                param.setOrderSn(orderSn);
-                param.setSnCode(snCode);
-                params.add(param);
-            }else if(type == 2){   //关联客户
-                if(index == 0 && !map.get(0).equals("客户关联模板")){
-                    throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
-                }
-                if(index <4){
-                    continue;
-                }
-                CameraInOutParam param = new CameraInOutParam();
-                param.setCompanyName(map.get(0));
-                param.setSnCode(map.get(1));
-                if(StringUtils.isBlank(param.getSnCode()) || StringUtils.isBlank(param.getCompanyName())){
-                    errorIndex.add(index -3 );
-                }
-                companyParams.add(param);
-            }
-        }
-         this.toExcelError(errorIndex);
-
-        if(type == 0 && wifiNameList.size() <=0){
-            throw new BusinessException(ResultCode.IN_TEMPLATE_EMPTY);
-        }else if(type == 1 && params.size() <=0){
-
-            throw new BusinessException(ResultCode.OUT_TEMPLATE_EMPTY);
-        }else if(type == 2 && companyParams.size() <=0){
-            throw new BusinessException(ResultCode.COMPANY_TEMPLATE_EMPTY);
-        }
-        if(wifiNameList.size() >0){
-            return cameraService.ins(wifiNameList);
-        }
-        if(params.size() >0){
-            return cameraService.outs(params);
-        }
-        if(companyParams.size() >0){
-            return cameraService.updateCompany(companyParams);
-        }
-        return 0;
+        return handler.importExcel(excelRowList);
     }
 
     @Override