重庆 配件管理导入
This commit is contained in:
parent
7c210bb1cb
commit
e33f2f7673
|
|
@ -56,6 +56,12 @@ public class Constants
|
|||
* 失败标记
|
||||
*/
|
||||
public static final Integer FAIL = 500;
|
||||
/*
|
||||
* 区分系统标记
|
||||
* */
|
||||
public static final String UPLOAD_DIR="/data/sgzb/";
|
||||
|
||||
public static final String UPLOAD_DIR_WIN="D:/data/sgzb";
|
||||
|
||||
/**
|
||||
* 登录成功状态
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.bonus.sgzb.base.domain.MaPartType;
|
|||
import com.bonus.sgzb.base.domain.MapType;
|
||||
import com.bonus.sgzb.base.service.ExcelService;
|
||||
import com.bonus.sgzb.base.service.IPartTypeService;
|
||||
import com.bonus.sgzb.common.core.constant.Constants;
|
||||
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.sgzb.common.core.web.controller.BaseController;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
|
|
@ -33,7 +34,7 @@ import java.util.Map;
|
|||
* @since 2023-11-27 16:44:02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/base/maPartType")
|
||||
@RequestMapping("maPartType")
|
||||
public class MaPartTypeController extends BaseController {
|
||||
/**
|
||||
* 服务对象
|
||||
|
|
@ -44,8 +45,6 @@ public class MaPartTypeController extends BaseController {
|
|||
@Resource
|
||||
private ExcelService excelService;
|
||||
|
||||
private static final String UPLOAD_DIR = "D:/work/wcy";
|
||||
|
||||
|
||||
/**
|
||||
* 查询配件类型列表
|
||||
|
|
@ -89,21 +88,34 @@ public class MaPartTypeController extends BaseController {
|
|||
|
||||
@PostMapping("/readExcel")
|
||||
public AjaxResult readExcelFile(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
boolean isLinux = false;
|
||||
if (os.contains("nix") || os.contains("nux") || os.contains("linux")) {
|
||||
isLinux = true;
|
||||
}
|
||||
// 创建上传目录,如果不存在的话
|
||||
File dir = new File(UPLOAD_DIR);
|
||||
File dir = null;
|
||||
if (isLinux){
|
||||
dir = new File(Constants.UPLOAD_DIR);
|
||||
}else {
|
||||
dir = new File(Constants.UPLOAD_DIR_WIN);
|
||||
}
|
||||
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
// 获取文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
Path filePath;
|
||||
// 定义文件路径
|
||||
Path filePath = Paths.get(UPLOAD_DIR, fileName);
|
||||
if (isLinux){
|
||||
filePath = Paths.get(Constants.UPLOAD_DIR, fileName);
|
||||
}else {
|
||||
filePath = Paths.get(Constants.UPLOAD_DIR_WIN, fileName);
|
||||
}
|
||||
|
||||
// 保存文件
|
||||
file.transferTo(filePath.toFile());
|
||||
|
||||
Map<String, Map<String, List<MapType>>> stringMapMap = excelService.readExcelFile(filePath.toString());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
package com.bonus.sgzb.base.service.impl;// ExcelServiceImpl.java
|
||||
|
||||
import com.bonus.sgzb.base.domain.MaPartType;
|
||||
import com.bonus.sgzb.base.domain.MapType;
|
||||
import com.bonus.sgzb.base.mapper.ExcelMapper;
|
||||
import com.bonus.sgzb.base.service.ExcelService;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -44,7 +40,37 @@ public class ExcelServiceImpl implements ExcelService {
|
|||
while (iterator.hasNext()) {
|
||||
Row currentRow = iterator.next();
|
||||
if (currentRow.getRowNum() == 0) {
|
||||
// 跳过标题行
|
||||
// 校验模板
|
||||
Cell zeroLevelCell = currentRow.getCell(0);
|
||||
Cell firstLevelCell = currentRow.getCell(1);
|
||||
Cell secondLevelCell = currentRow.getCell(2);
|
||||
Cell thirdLevelCell = currentRow.getCell(3);
|
||||
Cell fourthLevelCell = currentRow.getCell(4);
|
||||
Cell fifthLevelCell = currentRow.getCell(5);
|
||||
String zeroLevel = getCellValueAsString(zeroLevelCell);
|
||||
String firstLevel = getCellValueAsString(firstLevelCell);
|
||||
String secondLevel = getCellValueAsString(secondLevelCell);
|
||||
String thirdLevel = getCellValueAsString(thirdLevelCell);
|
||||
String fourthLevel = getCellValueAsString(fourthLevelCell);
|
||||
String fifthLevel = getCellValueAsString(fifthLevelCell);
|
||||
if (!(zeroLevel.equals("序号"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
if (!(firstLevel.equals("配件类型"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
if (!(secondLevel.equals("配件名称"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
if (!(thirdLevel.equals("规格型号"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
if (!(fourthLevel.equals("单位"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
if (!(fifthLevel.equals("价格"))){
|
||||
throw new RuntimeException("导入模板不正确");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +189,7 @@ public class ExcelServiceImpl implements ExcelService {
|
|||
for (Map.Entry<String, List<MapType>> secondLevel : firstLevel.getValue().entrySet()) {
|
||||
System.out.println("\tlevel_2: " + secondLevel.getKey());
|
||||
//TODO, sql查询:是否有此名字 + parentId=firstLevelId, select * from ma_part_type where name=? and parent_id = firstLevelId;
|
||||
MaPartType maPartType_level2 = excelMapper.selectMa(firstLevel.getKey(),firstLevelId);
|
||||
MaPartType maPartType_level2 = excelMapper.selectMa(secondLevel.getKey(),firstLevelId);
|
||||
//TODO, 以上返回 maPartType_level2
|
||||
if (Objects.nonNull(maPartType_level2)) {
|
||||
looplevel3(secondLevel, outExist, maPartType_level2.getPaId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue