重庆 配件管理导入

This commit is contained in:
76164 2024-08-08 17:36:26 +08:00
parent 7c210bb1cb
commit e33f2f7673
3 changed files with 99 additions and 55 deletions

View File

@ -2,7 +2,7 @@ package com.bonus.sgzb.common.core.constant;
/** /**
* 通用常量信息 * 通用常量信息
* *
* @author ruoyi * @author ruoyi
*/ */
public class Constants public class Constants
@ -56,6 +56,12 @@ public class Constants
* 失败标记 * 失败标记
*/ */
public static final Integer FAIL = 500; public static final Integer FAIL = 500;
/*
* 区分系统标记
* */
public static final String UPLOAD_DIR="/data/sgzb/";
public static final String UPLOAD_DIR_WIN="D:/data/sgzb";
/** /**
* 登录成功状态 * 登录成功状态

View File

@ -4,6 +4,7 @@ import com.bonus.sgzb.base.domain.MaPartType;
import com.bonus.sgzb.base.domain.MapType; import com.bonus.sgzb.base.domain.MapType;
import com.bonus.sgzb.base.service.ExcelService; import com.bonus.sgzb.base.service.ExcelService;
import com.bonus.sgzb.base.service.IPartTypeService; 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.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController; import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.web.domain.AjaxResult;
@ -33,7 +34,7 @@ import java.util.Map;
* @since 2023-11-27 16:44:02 * @since 2023-11-27 16:44:02
*/ */
@RestController @RestController
@RequestMapping("/base/maPartType") @RequestMapping("maPartType")
public class MaPartTypeController extends BaseController { public class MaPartTypeController extends BaseController {
/** /**
* 服务对象 * 服务对象
@ -44,8 +45,6 @@ public class MaPartTypeController extends BaseController {
@Resource @Resource
private ExcelService excelService; private ExcelService excelService;
private static final String UPLOAD_DIR = "D:/work/wcy";
/** /**
* 查询配件类型列表 * 查询配件类型列表
@ -89,21 +88,34 @@ public class MaPartTypeController extends BaseController {
@PostMapping("/readExcel") @PostMapping("/readExcel")
public AjaxResult readExcelFile(@RequestParam("file") MultipartFile file) throws IOException { 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()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
// 获取文件名 // 获取文件名
String fileName = file.getOriginalFilename(); 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()); file.transferTo(filePath.toFile());
Map<String, Map<String, List<MapType>>> stringMapMap = excelService.readExcelFile(filePath.toString()); Map<String, Map<String, List<MapType>>> stringMapMap = excelService.readExcelFile(filePath.toString());
return AjaxResult.success(); return AjaxResult.success();
} }
@ -115,45 +127,45 @@ public class MaPartTypeController extends BaseController {
} }
/** /**
* poi * poi
* 删除配件管理类型 * 删除配件管理类型
* *
* @param paId * @param paId
* @return * @return
*/ */
@DeleteMapping("/{paId}") @DeleteMapping("/{paId}")
public AjaxResult delete (@PathVariable("paId") Long paId){ public AjaxResult delete (@PathVariable("paId") Long paId){
if (maPartTypeService.hasChildBypaId(paId)) { if (maPartTypeService.hasChildBypaId(paId)) {
return warn("存在下级仓库列表,不允许删除"); return warn("存在下级仓库列表,不允许删除");
}
return toAjax(maPartTypeService.deletePaById(paId));
} }
return toAjax(maPartTypeService.deletePaById(paId));
/**
* 根据id获取数据
*
* @param paId
* @return
*/
@GetMapping("/{paId}")
public AjaxResult getById (@PathVariable("paId") Long paId){
MaPartType bean = maPartTypeService.getById(paId);
return AjaxResult.success(bean);
}
/**
* 根据id修改数据
*
* @param maPartType
* @return
*/
@PostMapping("/updateById")
public AjaxResult updateById (@RequestBody MaPartType maPartType){
maPartType.setUpdateBy(SecurityUtils.getUsername());
return toAjax(maPartTypeService.updateById(maPartType));
}
} }
/**
* 根据id获取数据
*
* @param paId
* @return
*/
@GetMapping("/{paId}")
public AjaxResult getById (@PathVariable("paId") Long paId){
MaPartType bean = maPartTypeService.getById(paId);
return AjaxResult.success(bean);
}
/**
* 根据id修改数据
*
* @param maPartType
* @return
*/
@PostMapping("/updateById")
public AjaxResult updateById (@RequestBody MaPartType maPartType){
maPartType.setUpdateBy(SecurityUtils.getUsername());
return toAjax(maPartTypeService.updateById(maPartType));
}
}

View File

@ -1,14 +1,10 @@
package com.bonus.sgzb.base.service.impl;// ExcelServiceImpl.java package com.bonus.sgzb.base.service.impl;// ExcelServiceImpl.java
import com.bonus.sgzb.base.domain.MaPartType; import com.bonus.sgzb.base.domain.MaPartType;
import com.bonus.sgzb.base.domain.MapType; import com.bonus.sgzb.base.domain.MapType;
import com.bonus.sgzb.base.mapper.ExcelMapper; import com.bonus.sgzb.base.mapper.ExcelMapper;
import com.bonus.sgzb.base.service.ExcelService; import com.bonus.sgzb.base.service.ExcelService;
import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.common.security.utils.SecurityUtils;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
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.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -44,7 +40,37 @@ public class ExcelServiceImpl implements ExcelService {
while (iterator.hasNext()) { while (iterator.hasNext()) {
Row currentRow = iterator.next(); Row currentRow = iterator.next();
if (currentRow.getRowNum() == 0) { 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; continue;
} }
@ -163,7 +189,7 @@ public class ExcelServiceImpl implements ExcelService {
for (Map.Entry<String, List<MapType>> secondLevel : firstLevel.getValue().entrySet()) { for (Map.Entry<String, List<MapType>> secondLevel : firstLevel.getValue().entrySet()) {
System.out.println("\tlevel_2: " + secondLevel.getKey()); System.out.println("\tlevel_2: " + secondLevel.getKey());
//TODO, sql查询是否有此名字 + parentId=firstLevelId, select * from ma_part_type where name=? and parent_id = firstLevelId; //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 //TODO, 以上返回 maPartType_level2
if (Objects.nonNull(maPartType_level2)) { if (Objects.nonNull(maPartType_level2)) {
looplevel3(secondLevel, outExist, maPartType_level2.getPaId()); looplevel3(secondLevel, outExist, maPartType_level2.getPaId());