lyhzzz 9 месяцев назад
Родитель
Сommit
a6d6b49162

+ 3 - 0
src/main/java/com/fdkankan/manage/common/ResultCode.java

@@ -82,6 +82,9 @@ public enum ResultCode  {
 
     AUTH_TYPE_ERROR(60015, "无需分享给自己"),
 
+    TEMPLATE_EMPTY(60016, "模板数据为空"),
+
+
     ;
 
     private Integer code;

+ 1 - 0
src/main/java/com/fdkankan/manage/controller/ExcelController.java

@@ -39,6 +39,7 @@ public class ExcelController {
             case 0 : fileName = "cameraIn.xlsx"; break;
             case 1 : fileName = "cameraOut.xlsx"; break;
             case 2 : fileName = "cameraCompany.xlsx"; break;
+            case 6 : fileName = "platformUser.xlsx"; break;
             default: throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/"+fileName);

+ 7 - 0
src/main/java/com/fdkankan/manage/service/ICameraService.java

@@ -6,6 +6,7 @@ import com.fdkankan.manage.entity.Camera;
 import com.fdkankan.manage.vo.request.CameraInOutParam;
 import com.fdkankan.manage.vo.request.CameraParam;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -39,4 +40,10 @@ public interface ICameraService extends IService<Camera> {
     Integer outs(List<CameraInOutParam> params);
 
     Integer updateCompany(List<CameraInOutParam> companyParams);
+
+    Integer insExcelList(List<HashMap<Integer, String>> excelRowList);
+
+    Integer outExcelList(List<HashMap<Integer, String>> excelRowList);
+
+    Integer companyExcelList(List<HashMap<Integer, String>> excelRowList);
 }

+ 3 - 0
src/main/java/com/fdkankan/manage/service/IJyUserPlatformService.java

@@ -7,6 +7,7 @@ import com.fdkankan.manage.vo.request.JyPlatformVo;
 import com.fdkankan.manage.vo.request.JyUserPlatformAddParam;
 import com.fdkankan.manage.vo.request.JyUserPlatformParam;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -40,4 +41,6 @@ public interface IJyUserPlatformService extends IService<JyUserPlatform> {
 
 
     void updatePlatformId(Integer id, Integer toPlatformId);
+
+    Integer addPlatformUser(List<HashMap<Integer, String>> excelRowList);
 }

+ 124 - 0
src/main/java/com/fdkankan/manage/service/impl/CameraServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.common.constant.Constant;
 import com.fdkankan.common.util.MD5;
 import com.fdkankan.manage.common.*;
+import com.fdkankan.manage.constant.CameraOutTypeEnum;
 import com.fdkankan.manage.entity.*;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.common.util.DateUtil;
@@ -19,6 +20,7 @@ import com.fdkankan.manage.vo.request.CameraInOutParam;
 import com.fdkankan.manage.vo.request.CameraParam;
 import com.fdkankan.manage.vo.response.CameraDataVo;
 import com.fdkankan.manage.vo.response.CameraDetailVo;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -36,6 +38,7 @@ import java.util.stream.Collectors;
  * @since 2022-06-16
  */
 @Service
+@Slf4j
 public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implements ICameraService {
 
     @Autowired
@@ -456,6 +459,7 @@ IOrderService orderService;
         for (String snCode : snCodeList) {
             Camera camera = snCodeMap.get(snCode);
             if(camera == null || detailMap.get(camera.getId()) ==null){
+                log.error("excel-export-error-->:相机未入库:snCode:{}",snCode);
                 errorList.add(snCodeList.indexOf(snCode) );
             }
         }
@@ -465,4 +469,124 @@ IOrderService orderService;
         return resultMap;
     }
 
+
+    @Override
+    public Integer insExcelList(List<HashMap<Integer, String>> excelRowList) {
+        List<String> wifiNameList = new ArrayList<>();
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index ++;
+            if(map.isEmpty()){
+                continue;
+            }
+            if(index == 0 && !map.get(0).equals("设备入库模板")){
+                throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
+            }
+            if(index <4){   //从第四行开始
+                continue;
+            }
+            String wifiName = map.get(0);
+            wifiNameList.add(wifiName);
+        }
+
+        if(wifiNameList.size() <=0){
+            throw new BusinessException(ResultCode.IN_TEMPLATE_EMPTY);
+        }
+        return this.ins(wifiNameList);
+    }
+
+    @Autowired
+    IAgentNewService agentNewService;
+    @Override
+    public Integer outExcelList(List<HashMap<Integer, String>> excelRowList) {
+        List<CameraInOutParam> params = new ArrayList<>();
+        List<Integer> errorIndex = new ArrayList<>();
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index ++;
+            if(map.isEmpty()){
+                continue;
+            }
+            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);
+            String buyDate = map.get(5);
+            CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
+            if(outTypeEnum == null || StringUtils.isBlank(snCode) || StringUtils.isBlank(buyDate)){
+                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);
+            }
+            param.setBuyDate(buyDate);
+            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 this.outs(params);
+    }
+
+    @Override
+    public Integer companyExcelList(List<HashMap<Integer, String>> excelRowList) {
+        List<CameraInOutParam> companyParams = new ArrayList<>();
+        List<Integer> errorIndex = new ArrayList<>();
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index ++;
+            if(map.isEmpty()){
+                continue;
+            }
+            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 this.updateCompany(companyParams);
+    }
 }

+ 11 - 105
src/main/java/com/fdkankan/manage/service/impl/ExcelServiceImpl.java

@@ -9,10 +9,7 @@ import com.fdkankan.manage.entity.AgentNew;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.constant.CameraOutTypeEnum;
 import com.fdkankan.manage.entity.Company;
-import com.fdkankan.manage.service.IAgentNewService;
-import com.fdkankan.manage.service.ICameraService;
-import com.fdkankan.manage.service.ICompanyService;
-import com.fdkankan.manage.service.IExcelService;
+import com.fdkankan.manage.service.*;
 import com.fdkankan.manage.util.ExcelUtil;
 import com.fdkankan.manage.vo.request.CameraInOutParam;
 import lombok.extern.slf4j.Slf4j;
@@ -48,6 +45,8 @@ public class ExcelServiceImpl implements IExcelService {
     ICameraService cameraService;
     @Autowired
     IAgentNewService agentNewService;
+    @Autowired
+    IJyUserPlatformService jyUserPlatformService;
 
     public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,ExcelWriter excelWriter) throws Exception {
         response.setContentType("application/vnd.ms-excel");
@@ -91,110 +90,17 @@ public class ExcelServiceImpl implements IExcelService {
         try {
             excelRowList = ExcelUtil.getExcelRowList(file);
         }catch (Exception e){
+            log.info("updateExcel-error:{}",e);
             throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
         }
-        List<String> wifiNameList = new ArrayList<>();
-        List<CameraInOutParam> params = new ArrayList<>();
-        List<CameraInOutParam> companyParams = new ArrayList<>();
-        List<Integer> errorIndex = new ArrayList<>();
-        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);
+        switch (type){
+            case 0 :return cameraService.insExcelList(excelRowList);
+            case 1 :return cameraService.outExcelList(excelRowList);
+            case 2 :return cameraService.companyExcelList(excelRowList);
+            case 6 :return jyUserPlatformService.addPlatformUser(excelRowList);
+            default:
+                throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
-        return 0;
     }
 
     @Override

+ 55 - 4
src/main/java/com/fdkankan/manage/service/impl/JyUserPlatformServiceImpl.java

@@ -10,17 +10,17 @@ import com.fdkankan.manage.entity.JyPlatform;
 import com.fdkankan.manage.entity.JyUserPlatform;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.mapper.IJyUserPlatformMapper;
+import com.fdkankan.manage.service.IExcelService;
 import com.fdkankan.manage.service.IJyUserPlatformService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fdkankan.manage.vo.request.JyPlatformVo;
-import com.fdkankan.manage.vo.request.JyUserPlatformAddParam;
-import com.fdkankan.manage.vo.request.JyUserPlatformParam;
-import com.fdkankan.manage.vo.request.JyUserPlatformVo;
+import com.fdkankan.manage.vo.request.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -130,4 +130,55 @@ public class JyUserPlatformServiceImpl extends ServiceImpl<IJyUserPlatformMapper
         }
         return null;
     }
+
+    @Autowired
+    IExcelService excelService;
+
+    @Override
+    public Integer addPlatformUser(List<HashMap<Integer, String>> excelRowList) {
+        List<JyUserPlatformAddParam> params = new ArrayList<>();
+        List<Integer> errorIndex = new ArrayList<>();
+        Integer index = 0;
+        for (HashMap<Integer, String> map : excelRowList) {
+            index++;
+            if (map.isEmpty()) {
+                continue;
+            }
+            if (index == 0 && !map.get(0).equals("平台用户模板")) {
+                throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
+            }
+            if (index < 4) {
+                continue;
+            }
+            String name = map.get(0);
+            String idCard = map.get(1);
+            if(StringUtils.isBlank(name) || StringUtils.isBlank(idCard)){
+                errorIndex.add(index -3 );
+                continue;
+            }
+            JyUserPlatformAddParam param = new JyUserPlatformAddParam();
+            param.setName(name);
+            param.setIdCard(idCard);
+            params.add(param);
+        }
+        excelService.toExcelError(errorIndex);
+        if(params.size() <=0){
+            throw new BusinessException(ResultCode.TEMPLATE_EMPTY);
+        }
+        return this.addPlatformUsers(params);
+    }
+
+    private Integer addPlatformUsers(List<JyUserPlatformAddParam> params) {
+        Integer count = 0;
+        for (JyUserPlatformAddParam param : params) {
+            JyUserPlatform userPlatform = this.getByIdCard(param.getIdCard());
+            if(userPlatform == null){
+                continue;
+            }
+            count ++;
+            param.setId(userPlatform.getId());
+            this.addByParam(param);
+        }
+        return count;
+    }
 }

+ 17 - 5
src/main/java/com/fdkankan/manage/util/ExcelUtil.java

@@ -1,10 +1,12 @@
 package com.fdkankan.manage.util;
 
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -31,22 +33,32 @@ public class ExcelUtil {
             for (int cellNum=0;cellNum<= row.getLastCellNum();cellNum++){
                 Cell cell = row.getCell(cellNum);
                 if(cell != null){
-                    String value = fommartNum(cell.toString().trim());
-                    map.put(cellNum,value);
+                    DataFormatter dataFormatter = new DataFormatter();
+                    String cellValue = dataFormatter.formatCellValue(cell);
+                    map.put(cellNum,cellValue);
                 }
+
             }
             rowList.add(map);
         }
         return rowList;
     }
 
-  private static  String fommartNum(String value){
+    private static  String fommartNum(String value){
         try {
-            return Double.valueOf(value).intValue() +"";
+            if(isNumeric2(value) && value.contains(".")){
+                return Double.valueOf(value).intValue() +"";
+            }
         }catch (Exception e){
             return value;
         }
-  }
+        return value;
+    }
+
+    public static boolean isNumeric2(String str) {
+        return str != null && str.matches("-?\\d+(\\.\\d+)?");
+    }
+
 
 
     //获取WorkBook对象

+ 6 - 0
src/main/java/com/fdkankan/manage/vo/request/CameraInOutParam.java

@@ -13,4 +13,10 @@ public class CameraInOutParam {
     private String companyName;     //客户名
 
     private Integer agentId;
+
+    private String buyDate;
+
+    private Integer cameraType;
+
+    private String wifiNamePrefix;
 }

+ 4 - 0
src/main/java/com/fdkankan/manage/vo/request/JyUserPlatformAddParam.java

@@ -7,4 +7,8 @@ public class JyUserPlatformAddParam {
 
     private Integer id;
     private Integer platformId;
+
+    //导入参数
+    private String name;
+    private String idCard;
 }

BIN
src/main/resources/template/platformUser.xlsx