|
@@ -71,64 +71,65 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
|
|
|
@Override
|
|
|
public Integer uploadExcel(MultipartFile file, Integer type) {
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ assert originalFilename != null;
|
|
|
+ String fileType=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
|
|
|
+ if (!fileType.equalsIgnoreCase("xls") && !fileType.equalsIgnoreCase("xlsx")) {
|
|
|
+ throw new BusinessException(50001,"文件格式校验,需为excel文件;");
|
|
|
+ }
|
|
|
+ List<HashMap<Integer, String>> excelRowList = new ArrayList<>();
|
|
|
try {
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- assert originalFilename != null;
|
|
|
- String fileType=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
|
|
|
- if (!fileType.equalsIgnoreCase("xls") && !fileType.equalsIgnoreCase("xlsx")) {
|
|
|
- throw new BusinessException(-1,"文件格式校验,需为excel文件;");
|
|
|
- }
|
|
|
- List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
|
|
|
- List<String> wifiNameList = new ArrayList<>();
|
|
|
- List<CameraInOutParam> params = new ArrayList<>();
|
|
|
- List<CameraInOutParam> companyParams = new ArrayList<>();
|
|
|
- for (HashMap<Integer, String> map : excelRowList) {
|
|
|
- if(type == 0){ //入库
|
|
|
- String wifiName = map.get(0);
|
|
|
- wifiNameList.add(wifiName);
|
|
|
- }else if(type == 1){ //出库
|
|
|
- String snCode = map.get(0);
|
|
|
- String outTypeString = map.get(1);
|
|
|
- String companyName = map.get(2);
|
|
|
- String orderSn = map.get(3);
|
|
|
+ excelRowList = ExcelUtil.getExcelRowList(file);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new BusinessException(50002,"模板错误");
|
|
|
+ }
|
|
|
+ List<String> wifiNameList = new ArrayList<>();
|
|
|
+ List<CameraInOutParam> params = new ArrayList<>();
|
|
|
+ List<CameraInOutParam> companyParams = new ArrayList<>();
|
|
|
+ for (HashMap<Integer, String> map : excelRowList) {
|
|
|
+ if(type == 0){ //入库
|
|
|
+ String wifiName = map.get(0);
|
|
|
+ wifiNameList.add(wifiName);
|
|
|
+ }else if(type == 1){ //出库
|
|
|
+ String snCode = map.get(0);
|
|
|
+ String outTypeString = map.get(1);
|
|
|
+ String companyName = map.get(2);
|
|
|
+ String orderSn = map.get(3);
|
|
|
|
|
|
- CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
|
|
|
- if(outTypeEnum == null){
|
|
|
- throw new BusinessException(-1,"出库类型错误:"+outTypeString);
|
|
|
- }
|
|
|
- int outType = outTypeEnum.getCode();
|
|
|
- Company company = companyService.getCompanyByName(companyName);
|
|
|
- CameraInOutParam param = new CameraInOutParam();
|
|
|
- param.setCompanyId(company.getId());
|
|
|
- param.setOutType(outType);
|
|
|
- param.setOrderSn(orderSn);
|
|
|
- param.setSnCode(snCode);
|
|
|
- params.add(param);
|
|
|
- }else if(type == 2){ //关联客户
|
|
|
- CameraInOutParam param = new CameraInOutParam();
|
|
|
- param.setCompanyName(map.get(0));
|
|
|
- param.setSnCode(map.get(1));
|
|
|
- companyParams.add(param);
|
|
|
+ CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
|
|
|
+ if(outTypeEnum == null){
|
|
|
+ throw new BusinessException(50003,"出库类型错误:"+outTypeString);
|
|
|
}
|
|
|
+ int outType = outTypeEnum.getCode();
|
|
|
+ Company company = companyService.getCompanyByName(companyName);
|
|
|
+ CameraInOutParam param = new CameraInOutParam();
|
|
|
+ param.setCompanyId(company.getId());
|
|
|
+ param.setOutType(outType);
|
|
|
+ param.setOrderSn(orderSn);
|
|
|
+ param.setSnCode(snCode);
|
|
|
+ params.add(param);
|
|
|
+ }else if(type == 2){ //关联客户
|
|
|
+ CameraInOutParam param = new CameraInOutParam();
|
|
|
+ param.setCompanyName(map.get(0));
|
|
|
+ param.setSnCode(map.get(1));
|
|
|
+ companyParams.add(param);
|
|
|
}
|
|
|
- if(type == 0 && wifiNameList.size() <=0){
|
|
|
- throw new BusinessException(-1,"入库模板数据为空");
|
|
|
- }else if(type == 1 && params.size() <=0){
|
|
|
- throw new BusinessException(-1,"出库模板数据为空");
|
|
|
- }else if(type == 2 && companyParams.size() <=0){
|
|
|
- throw new BusinessException(-1,"客户关联数据为空");
|
|
|
- }
|
|
|
- if(wifiNameList.size() >0){
|
|
|
- return cameraService.ins(wifiNameList);
|
|
|
- }
|
|
|
- if(params.size() >0){
|
|
|
- return cameraService.outs(params);
|
|
|
- }
|
|
|
- if(companyParams.size() >0){
|
|
|
- return cameraService.updateCompany(companyParams);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- throw new BusinessException(-1,"模板错误");
|
|
|
+ }
|
|
|
+ if(type == 0 && wifiNameList.size() <=0){
|
|
|
+ throw new BusinessException(50004,"入库模板数据为空");
|
|
|
+ }else if(type == 1 && params.size() <=0){
|
|
|
+ throw new BusinessException(50005,"出库模板数据为空");
|
|
|
+ }else if(type == 2 && companyParams.size() <=0){
|
|
|
+ throw new BusinessException(50006,"客户关联数据为空");
|
|
|
+ }
|
|
|
+ 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;
|
|
|
}
|