工程量清单

This commit is contained in:
2025-08-12 09:11:43 +08:00
parent 3aa5c53149
commit 604d1b6da2
25 changed files with 2121 additions and 1 deletions

View File

@ -0,0 +1,226 @@
package org.dromara.common.excel.coryUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 工程量清单解析
* @Author 铁憨憨
* @Date 2025/8/11 16:29
* @Version 1.0
*/
public class BillOfQuantitiesUtils {
// 中文数字正则表达式,用于检测顶层节点
private static final String CHINESE_NUMBERS_REGEX = "[一二三四五六七八九十]+";
// 标记是否已找到中文数字开头的行
private static boolean foundChineseStart = false;
public static void main(String[] args) {
try {
// 文件路径,请根据实际情况修改
FileInputStream file = new FileInputStream(new File(
"E:\\cory\\app\\xwechat_files\\wxid_8q1mhp57yu6p22_50ad\\msg\\file\\2025-08\\设计管理模块说明\\8、工程量清单表.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
System.out.println("===== 工作表: " + sheet.getSheetName() + " =====");
// 重置标记,处理新工作表时重新开始检测
foundChineseStart = false;
List<List<String>> data = new ArrayList<>();
boolean isFirstRow = true;
for (Row row : sheet) {
// 跳过表头行
if (isFirstRow) {
isFirstRow = false;
continue;
}
List<String> rowData = new ArrayList<>();
// 读取A到E列索引0到4
for (int cellIndex = 0; cellIndex < 5; cellIndex++) {
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
rowData.add(getCellValue(cell));
}
// 检查是否找到中文数字开头的行
String aColumnValue = rowData.get(0).trim();
if (aColumnValue.matches(CHINESE_NUMBERS_REGEX)) {
foundChineseStart = true;
}
// 只有找到中文数字开头的行之后,才开始收集数据
if (foundChineseStart) {
data.add(rowData);
}
}
if (!data.isEmpty()) {
// 构建树形结构
TreeNode root = new TreeNode(new ArrayList<>());
Map<String, TreeNode> nodeMap = new HashMap<>();
nodeMap.put("", root);
List<String> nonEmptyKeys = new ArrayList<>(); // 记录非空A列值的顺序
for (List<String> row : data) {
String key = row.get(0).trim();
TreeNode node = new TreeNode(row);
if (!key.isEmpty()) {
String parentKey = getParentKey(key);
TreeNode parent = nodeMap.get(parentKey);
if (parent == null) {
parent = new TreeNode(new ArrayList<>());
nodeMap.put(parentKey, parent);
TreeNode grandParent = nodeMap.get(getParentKey(parentKey));
if (grandParent != null) {
grandParent.addChild(parent);
} else {
// 如果没有更高级别的父节点,就挂到根节点
root.addChild(parent);
}
}
parent.addChild(node);
nodeMap.put(key, node);
nonEmptyKeys.add(key);
} else {
// A列为空挂到上一个非空节点下
if (!nonEmptyKeys.isEmpty()) {
String lastKey = nonEmptyKeys.get(nonEmptyKeys.size() - 1);
TreeNode parent = nodeMap.get(lastKey);
if (parent != null) {
parent.addChild(node);
}
} else {
root.addChild(node);
}
}
}
// 打印树形结构
printTree(root, 0);
} else {
System.out.println("该工作表中未找到以中文数字(一、二、三...)开头的数据行");
}
}
workbook.close();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 获取单元格的值,处理不同数据类型
*/
private static String getCellValue(Cell cell) {
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case STRING:
return cell.getStringCellValue().trim();
case NUMERIC:
// 处理数字,移除不必要的.0后缀
String numericValue = String.valueOf(cell.getNumericCellValue());
if (numericValue.endsWith(".0")) {
return numericValue.substring(0, numericValue.length() - 2);
}
return numericValue;
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
default:
return "";
}
}
/**
* 根据A列的值确定父节点的键
*/
private static String getParentKey(String key) {
// 中文数字(一、二、三...)的父节点是根节点
if (key.matches(CHINESE_NUMBERS_REGEX)) {
return "";
}
// 数字格式1、1.1、1.2.1等)的父节点是上一级
if (key.matches("\\d+(\\.\\d+)*")) {
int lastDotIndex = key.lastIndexOf('.');
if (lastDotIndex > 0) {
return key.substring(0, lastDotIndex);
} else {
// 一级数字如1、2的父节点是根节点或最近的中文数字节点
return "";
}
}
// 其他格式默认父节点是根节点
return "";
}
/**
* 以可视化方式打印树形结构
*/
private static void printTree(TreeNode node, int depth) {
// 跳过空的中间节点
if (node.data.isEmpty() && node.children.size() == 1) {
printTree(node.children.get(0), depth);
return;
}
if (!node.data.isEmpty()) {
// 打印层级连接线
for (int i = 0; i < depth; i++) {
// 最后一级节点用└──,其他用├──
if (i == depth - 1) {
System.out.print("└── ");
} else {
System.out.print("");
}
}
// 打印数据突出显示A列的值
System.out.println("[" + node.data.get(0) + "] " + node.data.subList(1, node.data.size()));
}
// 递归打印子节点
for (TreeNode child : node.children) {
printTree(child, depth + 1);
}
}
/**
* 树形节点类
*/
static class TreeNode {
List<String> data;
List<TreeNode> children;
TreeNode(List<String> data) {
this.data = data;
this.children = new ArrayList<>();
}
void addChild(TreeNode child) {
this.children.add(child);
}
}
}

View File

@ -0,0 +1,358 @@
package org.dromara.common.excel.coryUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author 铁憨憨
* @Date 2025/8/11 16:44
* @Version 1.0
*/
public class ExcelReader {
// 中文数字正则表达式,用于检测顶层节点
public static final String CHINESE_NUMBERS_REGEX = "[一二三四五六七八九十]+";
public static void main(String[] args) {
try {
// 1. 读取Excel中所有sheet的完整数据
String filePath = "E:\\cory\\app\\xwechat_files\\wxid_8q1mhp57yu6p22_50ad\\msg\\file\\2025-08\\设计管理模块说明\\8、工程量清单表.xls";
ExcelData excelData = readExcelData(filePath);
// ExcelData excelData = ExcelReader.readExcelFromMultipartFile(file);
// 2. 处理每个sheet的数据并打印树形结构
for (SheetData sheetData : excelData.getSheetDataList()) {
System.out.println("===== 工作表: " + sheetData.getSheetName() + " =====");
if (sheetData.getData().isEmpty()) {
System.out.println("该工作表中未找到以中文数字(一、二、三...)开头的数据行");
continue;
}
// 构建树形结构
TreeNode root = buildTree(sheetData.getData());
// 打印树形结构
printTree(root, 0);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 从MultipartFile读取Excel数据
*/
public static ExcelData readExcelFromMultipartFile(MultipartFile file) throws IOException {
if (file.isEmpty()) {
throw new IllegalArgumentException("上传的文件为空");
}
ExcelData excelData = new ExcelData();
List<SheetData> sheetDataList = new ArrayList<>();
// 获取文件名判断文件类型
String fileName = file.getOriginalFilename();
if (fileName == null || (!fileName.toLowerCase().endsWith(".xls") && !fileName.toLowerCase().endsWith(".xlsx"))) {
throw new IllegalArgumentException("不支持的文件类型仅支持xls和xlsx格式");
}
boolean isXlsx = fileName.toLowerCase().endsWith(".xlsx");
// 从MultipartFile获取输入流
try (InputStream stream = file.getInputStream();
org.apache.poi.ss.usermodel.Workbook workbook = isXlsx ?
new XSSFWorkbook(stream) : new HSSFWorkbook(stream)) {
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(sheetIndex);
SheetData sheetData = new SheetData();
sheetData.setSheetName(sheet.getSheetName());
processSheetData(sheet, sheetData);
sheetDataList.add(sheetData);
}
}
excelData.setSheetDataList(sheetDataList);
return excelData;
}
/**
* 文件路径来读取
* 读取Excel文件的完整数据并封装为实体
*/
public static ExcelData readExcelData(String filePath) throws IOException {
ExcelData excelData = new ExcelData();
List<SheetData> sheetDataList = new ArrayList<>();
FileInputStream file = new FileInputStream(new File(filePath));
boolean isXlsx = filePath.toLowerCase().endsWith(".xlsx");
// 根据文件后缀选择对应的Workbook实现
try (org.apache.poi.ss.usermodel.Workbook workbook = isXlsx ?
new XSSFWorkbook(file) : new HSSFWorkbook(file)) {
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(sheetIndex);
SheetData sheetData = new SheetData();
sheetData.setSheetName(sheet.getSheetName());
// 处理单个sheet的数据
processSheetData(sheet, sheetData);
sheetDataList.add(sheetData);
}
} finally {
file.close();
}
excelData.setSheetDataList(sheetDataList);
return excelData;
}
/**
* 处理单个工作表的数据
*/
private static void processSheetData(org.apache.poi.ss.usermodel.Sheet sheet, SheetData sheetData) {
boolean foundChineseStart = false;
List<List<String>> data = new ArrayList<>();
boolean isFirstRow = true;
for (Row row : sheet) {
// 跳过表头行
if (isFirstRow) {
isFirstRow = false;
continue;
}
List<String> rowData = new ArrayList<>();
// 读取A到E列索引0到4
for (int cellIndex = 0; cellIndex < 5; cellIndex++) {
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
rowData.add(getCellValue(cell));
}
// 检查是否找到中文数字开头的行
String aColumnValue = rowData.get(0).trim();
if (aColumnValue.matches(CHINESE_NUMBERS_REGEX)) {
foundChineseStart = true;
}
// 只有找到中文数字开头的行之后,才开始收集数据
if (foundChineseStart) {
data.add(rowData);
}
}
sheetData.setData(data);
}
/**
* 根据数据构建树形结构
*/
public static TreeNode buildTree(List<List<String>> data) {
TreeNode root = new TreeNode(new ArrayList<>());
Map<String, TreeNode> nodeMap = new HashMap<>();
nodeMap.put("", root);
List<String> nonEmptyKeys = new ArrayList<>(); // 记录非空A列值的顺序
for (List<String> row : data) {
String key = row.get(0).trim();
TreeNode node = new TreeNode(row);
if (!key.isEmpty()) {
String parentKey = getParentKey(key);
TreeNode parent = nodeMap.get(parentKey);
if (parent == null) {
parent = new TreeNode(new ArrayList<>());
nodeMap.put(parentKey, parent);
TreeNode grandParent = nodeMap.get(getParentKey(parentKey));
if (grandParent != null) {
grandParent.addChild(parent);
} else {
// 如果没有更高级别的父节点,就挂到根节点
root.addChild(parent);
}
}
parent.addChild(node);
nodeMap.put(key, node);
nonEmptyKeys.add(key);
} else {
// A列为空挂到上一个非空节点下
if (!nonEmptyKeys.isEmpty()) {
String lastKey = nonEmptyKeys.get(nonEmptyKeys.size() - 1);
TreeNode parent = nodeMap.get(lastKey);
if (parent != null) {
parent.addChild(node);
}
} else {
root.addChild(node);
}
}
}
return root;
}
/**
* 以可视化方式打印树形结构
*/
public static void printTree(TreeNode node, int depth) {
// 跳过空的中间节点
if (node.data.isEmpty() && node.children.size() == 1) {
printTree(node.children.get(0), depth);
return;
}
if (!node.data.isEmpty()) {
// 打印层级连接线
for (int i = 0; i < depth; i++) {
// 最后一级节点用└──,其他用├──
if (i == depth - 1) {
System.out.print("└── ");
} else {
System.out.print("");
}
}
// 打印数据突出显示A列的值
System.out.println("[" + node.data.get(0) + "] " + node.data.subList(1, node.data.size()));
}
// 递归打印子节点
for (TreeNode child : node.children) {
printTree(child, depth + 1);
}
}
/**
* 获取单元格的值,处理不同数据类型
*/
private static String getCellValue(Cell cell) {
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case STRING:
return cell.getStringCellValue().trim();
case NUMERIC:
// 处理数字,移除不必要的.0后缀
String numericValue = String.valueOf(cell.getNumericCellValue());
if (numericValue.endsWith(".0")) {
return numericValue.substring(0, numericValue.length() - 2);
}
return numericValue;
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
default:
return "";
}
}
/**
* 根据A列的值确定父节点的键
*/
private static String getParentKey(String key) {
// 中文数字(一、二、三...)的父节点是根节点
if (key.matches(CHINESE_NUMBERS_REGEX)) {
return "";
}
// 数字格式1、1.1、1.2.1等)的父节点是上一级
if (key.matches("\\d+(\\.\\d+)*")) {
int lastDotIndex = key.lastIndexOf('.');
if (lastDotIndex > 0) {
return key.substring(0, lastDotIndex);
} else {
// 一级数字如1、2的父节点是根节点或最近的中文数字节点
return "";
}
}
// 其他格式默认父节点是根节点
return "";
}
/**
* Excel数据实体类包含所有工作表数据
*/
public static class ExcelData {
private List<SheetData> sheetDataList;
public List<SheetData> getSheetDataList() {
return sheetDataList;
}
public void setSheetDataList(List<SheetData> sheetDataList) {
this.sheetDataList = sheetDataList;
}
}
/**
* 工作表数据实体类,包含单个工作表的名称和数据
*/
public static class SheetData {
private String sheetName;
private List<List<String>> data;
public String getSheetName() {
return sheetName;
}
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
}
public List<List<String>> getData() {
return data;
}
public void setData(List<List<String>> data) {
this.data = data;
}
}
/**
* 树形节点类
*/
public static class TreeNode {
List<String> data;
List<TreeNode> children;
public TreeNode(List<String> data) {
this.data = data;
this.children = new ArrayList<>();
}
public void addChild(TreeNode child) {
this.children.add(child);
}
public List<String> getData() {
return data;
}
public List<TreeNode> getChildren() {
return children;
}
}
}

View File

@ -0,0 +1,23 @@
package org.dromara.common.excel.coryUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @Author 铁憨憨
* @Date 2025/8/11 16:44
* @Version 1.0
*/
public class TreeNode {
List<String> data;
List<TreeNode> children;
TreeNode(List<String> data) {
this.data = data;
this.children = new ArrayList<>();
}
void addChild(TreeNode child) {
this.children.add(child);
}
}

View File

@ -49,7 +49,7 @@ public class BusCailiaoshebeiController extends BaseController {
* 设计-新增批次号
*/
@SaCheckPermission("cailiaoshebei:cailiaoshebei:pcAdd")
@Log(title = "设计-批次号列表", businessType = BusinessType.INSERT)
@Log(title = "设计-新增批次号", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping("/pcAdd")
public R<Void> pcAdd(@Validated(AddGroup.class) @RequestBody BusCailiaoshebeiPiciAddReq bo) {

View File

@ -11,4 +11,9 @@ public interface MinioPathConstant {
String ContactNotice = "contactNotice";
// 联系单模板
String ContactNoticeTemplate = "contactNotice/template";
// 设计
String Design = "design";
// 设计工程量清单
String BillOfQuantities = Design+"/billOfQuantities";
}

View File

@ -0,0 +1,105 @@
package org.dromara.design.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.dromara.design.domain.bo.BusBillofquantitiesBo;
import org.dromara.design.service.IBusBillofquantitiesService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
/**
* 工程量清单
*
* @author Lion Li
* @date 2025-08-11
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/design/billofquantities")
public class BusBillofquantitiesController extends BaseController {
private final IBusBillofquantitiesService busBillofquantitiesService;
/**
* 查询工程量清单列表
*/
@SaCheckPermission("design:billofquantities:list")
@GetMapping("/list")
public TableDataInfo<BusBillofquantitiesVo> list(BusBillofquantitiesBo bo, PageQuery pageQuery) {
return busBillofquantitiesService.queryPageList(bo, pageQuery);
}
/**
* 导出工程量清单列表
*/
@SaCheckPermission("design:billofquantities:export")
@Log(title = "工程量清单", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(BusBillofquantitiesBo bo, HttpServletResponse response) {
List<BusBillofquantitiesVo> list = busBillofquantitiesService.queryList(bo);
ExcelUtil.exportExcel(list, "工程量清单", BusBillofquantitiesVo.class, response);
}
/**
* 获取工程量清单详细信息
*
* @param id 主键
*/
@SaCheckPermission("design:billofquantities:query")
@GetMapping("/{id}")
public R<BusBillofquantitiesVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(busBillofquantitiesService.queryById(id));
}
/**
* 新增工程量清单
*/
@SaCheckPermission("design:billofquantities:add")
@Log(title = "工程量清单", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody BusBillofquantitiesBo bo) {
return toAjax(busBillofquantitiesService.insertByBo(bo));
}
/**
* 修改工程量清单
*/
@SaCheckPermission("design:billofquantities:edit")
@Log(title = "工程量清单", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusBillofquantitiesBo bo) {
return toAjax(busBillofquantitiesService.updateByBo(bo));
}
/**
* 删除工程量清单
*
* @param ids 主键串
*/
@SaCheckPermission("design:billofquantities:remove")
@Log(title = "工程量清单", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(busBillofquantitiesService.deleteWithValidByIds(List.of(ids), true));
}
}

View File

@ -0,0 +1,141 @@
package org.dromara.design.controller;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.design.domain.bo.ImportExcelFileReq;
import org.dromara.design.domain.bo.ObtainAllVersionNumbersReq;
import org.dromara.design.domain.bo.ObtainTheListReq;
import org.dromara.design.domain.dto.ObtainTheListRes;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.design.domain.vo.BusBillofquantitiesVersionsVo;
import org.dromara.design.domain.bo.BusBillofquantitiesVersionsBo;
import org.dromara.design.service.IBusBillofquantitiesVersionsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 工程量清单版本
*
* @author Lion Li
* @date 2025-08-11
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/design/billofquantitiesVersions")
public class BusBillofquantitiesVersionsController extends BaseController {
private final IBusBillofquantitiesVersionsService busBillofquantitiesVersionsService;
/**
* 查询工程量清单版本列表
*/
@SaCheckPermission("design:billofquantitiesVersions:list")
@GetMapping("/list")
public TableDataInfo<BusBillofquantitiesVersionsVo> list(BusBillofquantitiesVersionsBo bo, PageQuery pageQuery) {
return busBillofquantitiesVersionsService.queryPageList(bo, pageQuery);
}
/**
* 导出工程量清单版本列表
*/
@SaCheckPermission("design:billofquantitiesVersions:export")
@Log(title = "工程量清单版本", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(BusBillofquantitiesVersionsBo bo, HttpServletResponse response) {
List<BusBillofquantitiesVersionsVo> list = busBillofquantitiesVersionsService.queryList(bo);
ExcelUtil.exportExcel(list, "工程量清单版本", BusBillofquantitiesVersionsVo.class, response);
}
/**
* 获取工程量清单版本详细信息
*
* @param id 主键
*/
@SaCheckPermission("design:billofquantitiesVersions:query")
@GetMapping("/{id}")
public R<BusBillofquantitiesVersionsVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(busBillofquantitiesVersionsService.queryById(id));
}
/**
* 新增工程量清单版本
*/
@SaCheckPermission("design:billofquantitiesVersions:add")
@Log(title = "工程量清单版本", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody BusBillofquantitiesVersionsBo bo) {
return toAjax(busBillofquantitiesVersionsService.insertByBo(bo));
}
/**
* 修改工程量清单版本
*/
@SaCheckPermission("design:billofquantitiesVersions:edit")
@Log(title = "工程量清单版本", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusBillofquantitiesVersionsBo bo) {
return toAjax(busBillofquantitiesVersionsService.updateByBo(bo));
}
/**
* 删除工程量清单版本
*
* @param ids 主键串
*/
@SaCheckPermission("design:billofquantitiesVersions:remove")
@Log(title = "工程量清单版本", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(busBillofquantitiesVersionsService.deleteWithValidByIds(List.of(ids), true));
}
/**
* 导入excel
*/
@SaCheckPermission("design:billofquantitiesVersions:importExcelFile")
@Log(title = "导入excel", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping("/importExcelFile")
public R<Void> importExcelFile(ImportExcelFileReq bo, @RequestParam("file") MultipartFile file) throws IOException {
return toAjax(busBillofquantitiesVersionsService.importExcelFile(bo,file));
}
/**
* 获取所有版本号
*/
@SaCheckPermission("design:billofquantitiesVersions:obtainAllVersionNumbers")
@GetMapping("/obtainAllVersionNumbers")
public TableDataInfo<BusBillofquantitiesVersionsVo> obtainAllVersionNumbers(ObtainAllVersionNumbersReq bo, PageQuery pageQuery) {
return busBillofquantitiesVersionsService.obtainAllVersionNumbers(bo, pageQuery);
}
/**
* 获取工程量清单
*/
@SaCheckPermission("design:billofquantitiesVersions:obtainTheList")
@GetMapping("/obtainTheList")
public R<List<ObtainTheListRes>> obtainTheList(ObtainTheListReq bo, PageQuery pageQuery) {
return R.ok(busBillofquantitiesVersionsService.obtainTheList(bo));
}
}

View File

@ -0,0 +1,81 @@
package org.dromara.design.domain;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
/**
* 工程量清单对象 bus_billofquantities
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("bus_billofquantities")
public class BusBillofquantities extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId(value = "id")
private Long id;
/**
* 版本号
*/
private String versions;
/**
* 表名
*/
private String sheet;
/**
* 子ID
*/
private String sid;
/**
* 父ID
*/
private String pid;
/**
* 编号
*/
private String num;
/**
* 名称
*/
private String name;
/**
* 规格
*/
private String specification;
/**
* 单位
*/
private String unit;
/**
* 数量
*/
private int quantity;
/**
* 备注
*/
private String remark;
}

View File

@ -0,0 +1,43 @@
package org.dromara.design.domain;
import lombok.experimental.Accessors;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
/**
* 工程量清单版本对象 bus_billofquantities_versions
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("bus_billofquantities_versions")
@Accessors(chain = true)
public class BusBillofquantitiesVersions extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId(value = "id")
private Long id;
/**
* 工单类型(字典)
*/
private String workOrderType;
/**
* 版本号
*/
private String versions;
}

View File

@ -0,0 +1,83 @@
package org.dromara.design.domain.bo;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
/**
* 工程量清单业务对象 bus_billofquantities
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = BusBillofquantities.class, reverseConvertGenerate = false)
public class BusBillofquantitiesBo extends BaseEntity {
/**
* 主键ID
*/
@NotNull(message = "主键ID不能为空", groups = { EditGroup.class })
private Long id;
/**
* 版本号
*/
@NotBlank(message = "版本号不能为空", groups = { AddGroup.class, EditGroup.class })
private String versions;
/**
* 表名
*/
@NotBlank(message = "表名不能为空", groups = { AddGroup.class, EditGroup.class })
private String sheet;
/**
* 子ID
*/
private String sid;
/**
* 父ID
*/
private String pid;
/**
* 编号
*/
private String num;
/**
* 名称
*/
private String name;
/**
* 规格
*/
private String specification;
/**
* 单位
*/
private String unit;
/**
* 数量
*/
private Long quantity;
/**
* 备注
*/
private String remark;
}

View File

@ -0,0 +1,42 @@
package org.dromara.design.domain.bo;
import org.dromara.design.domain.BusBillofquantitiesVersions;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
/**
* 工程量清单版本业务对象 bus_billofquantities_versions
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = BusBillofquantitiesVersions.class, reverseConvertGenerate = false)
public class BusBillofquantitiesVersionsBo extends BaseEntity {
/**
* 主键ID
*/
@NotNull(message = "主键ID不能为空", groups = { EditGroup.class })
private Long id;
/**
* 工单类型(字典)
*/
@NotBlank(message = "工单类型(字典)不能为空", groups = { AddGroup.class, EditGroup.class })
private String workOrderType;
/**
* 版本号
*/
@NotBlank(message = "版本号不能为空", groups = { AddGroup.class, EditGroup.class })
private String versions;
}

View File

@ -0,0 +1,26 @@
package org.dromara.design.domain.bo;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.experimental.Accessors;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import java.io.Serializable;
/**
* @Author 铁憨憨
* @Date 2025/8/11 18:20
* @Version 1.0
*/
@Data
@Accessors(chain = true)
public class ImportExcelFileReq implements Serializable {
/**
* 工单类型(字典)
*/
@NotBlank(message = "工单类型(字典)不能为空", groups = { AddGroup.class, EditGroup.class })
private String workOrderType;
}

View File

@ -0,0 +1,24 @@
package org.dromara.design.domain.bo;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @Author 铁憨憨
* @Date 2025/8/11 20:18
* @Version 1.0
*/
@Data
@Accessors(chain = true)
public class ObtainAllVersionNumbersReq implements Serializable {
/**
* 工单类型(字典)
*/
@NotBlank(message = "工单类型(字典)不能为空")
private String workOrderType;
}

View File

@ -0,0 +1,39 @@
package org.dromara.design.domain.bo;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.experimental.Accessors;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import java.io.Serializable;
/**
* @Author 铁憨憨
* @Date 2025/8/11 20:14
* @Version 1.0
*/
@Data
@Accessors(chain = true)
public class ObtainTheListReq implements Serializable {
// /**
// * 工单类型(字典)
// */
// @NotBlank(message = "工单类型(字典)不能为空")
// private String workOrderType;
/**
* 版本号
*/
@NotBlank(message = "版本号不能为空")
private String versions;
/**
* 表名
*/
@NotBlank(message = "表名不能为空")
private String sheet;
}

View File

@ -0,0 +1,86 @@
package org.dromara.design.domain.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @Author 铁憨憨
* @Date 2025/8/11 20:48
* @Version 1.0
*/
@Data
@Accessors(chain = true)
public class ObtainTheListRes implements Serializable {
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long id;
/**
* 版本号
*/
@ExcelProperty(value = "版本号")
private String versions;
/**
* 表名
*/
@ExcelProperty(value = "表名")
private String sheet;
/**
* 父子ID
*/
@ExcelProperty(value = "父子ID")
private Long pid;
/**
* 编号
*/
@ExcelProperty(value = "编号")
private String num;
/**
* 名称
*/
@ExcelProperty(value = "名称")
private String name;
/**
* 规格
*/
@ExcelProperty(value = "规格")
private String specification;
/**
* 单位
*/
@ExcelProperty(value = "单位")
private String unit;
/**
* 数量
*/
@ExcelProperty(value = "数量")
private Long quantity;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
/**
* 子节点
*/
private List<ObtainTheListRes> children = new ArrayList<>();
}

View File

@ -0,0 +1,51 @@
package org.dromara.design.domain.vo;
import org.dromara.design.domain.BusBillofquantitiesVersions;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 工程量清单版本视图对象 bus_billofquantities_versions
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = BusBillofquantitiesVersions.class)
public class BusBillofquantitiesVersionsVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long id;
/**
* 工单类型(字典)
*/
@ExcelProperty(value = "工单类型(字典)", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "work_order_type")
private String workOrderType;
/**
* 版本号
*/
@ExcelProperty(value = "版本号")
private String versions;
}

View File

@ -0,0 +1,92 @@
package org.dromara.design.domain.vo;
import org.dromara.design.domain.BusBillofquantities;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 工程量清单视图对象 bus_billofquantities
*
* @author Lion Li
* @date 2025-08-11
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = BusBillofquantities.class)
public class BusBillofquantitiesVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long id;
/**
* 版本号
*/
@ExcelProperty(value = "版本号")
private String versions;
/**
* 表名
*/
@ExcelProperty(value = "表名")
private String sheet;
/**
* 父子ID
*/
@ExcelProperty(value = "父子ID")
private Long pid;
/**
* 编号
*/
@ExcelProperty(value = "编号")
private String num;
/**
* 名称
*/
@ExcelProperty(value = "名称")
private String name;
/**
* 规格
*/
@ExcelProperty(value = "规格")
private String specification;
/**
* 单位
*/
@ExcelProperty(value = "单位")
private String unit;
/**
* 数量
*/
@ExcelProperty(value = "数量")
private Long quantity;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
}

View File

@ -0,0 +1,15 @@
package org.dromara.design.mapper;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
/**
* 工程量清单Mapper接口
*
* @author Lion Li
* @date 2025-08-11
*/
public interface BusBillofquantitiesMapper extends BaseMapperPlus<BusBillofquantities, BusBillofquantitiesVo> {
}

View File

@ -0,0 +1,30 @@
package org.dromara.design.mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.design.domain.BusBillofquantitiesVersions;
import org.dromara.design.domain.bo.ObtainTheListReq;
import org.dromara.design.domain.dto.ObtainTheListRes;
import org.dromara.design.domain.vo.BusBillofquantitiesVersionsVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import java.util.List;
/**
* 工程量清单版本Mapper接口
*
* @author Lion Li
* @date 2025-08-11
*/
public interface BusBillofquantitiesVersionsMapper extends BaseMapperPlus<BusBillofquantitiesVersions, BusBillofquantitiesVersionsVo> {
/**
* 分页查询工程量清单版本列表
*
* @param bo 查询条件
* @return 工程量清单版本列表
*/
List<ObtainTheListRes> obtainTheList(@Param("bo") ObtainTheListReq bo);
}

View File

@ -0,0 +1,70 @@
package org.dromara.design.service;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.dromara.design.domain.bo.BusBillofquantitiesBo;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Collection;
import java.util.List;
/**
* 工程量清单Service接口
*
* @author Lion Li
* @date 2025-08-11
*/
public interface IBusBillofquantitiesService extends IService<BusBillofquantities>{
/**
* 查询工程量清单
*
* @param id 主键
* @return 工程量清单
*/
BusBillofquantitiesVo queryById(Long id);
/**
* 分页查询工程量清单列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 工程量清单分页列表
*/
TableDataInfo<BusBillofquantitiesVo> queryPageList(BusBillofquantitiesBo bo, PageQuery pageQuery);
/**
* 查询符合条件的工程量清单列表
*
* @param bo 查询条件
* @return 工程量清单列表
*/
List<BusBillofquantitiesVo> queryList(BusBillofquantitiesBo bo);
/**
* 新增工程量清单
*
* @param bo 工程量清单
* @return 是否新增成功
*/
Boolean insertByBo(BusBillofquantitiesBo bo);
/**
* 修改工程量清单
*
* @param bo 工程量清单
* @return 是否修改成功
*/
Boolean updateByBo(BusBillofquantitiesBo bo);
/**
* 校验并批量删除工程量清单信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@ -0,0 +1,94 @@
package org.dromara.design.service;
import org.dromara.common.core.domain.R;
import org.dromara.design.domain.bo.ImportExcelFileReq;
import org.dromara.design.domain.bo.ObtainAllVersionNumbersReq;
import org.dromara.design.domain.bo.ObtainTheListReq;
import org.dromara.design.domain.dto.ObtainTheListRes;
import org.dromara.design.domain.vo.BusBillofquantitiesVersionsVo;
import org.dromara.design.domain.bo.BusBillofquantitiesVersionsBo;
import org.dromara.design.domain.BusBillofquantitiesVersions;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.service.IService;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
/**
* 工程量清单版本Service接口
*
* @author Lion Li
* @date 2025-08-11
*/
public interface IBusBillofquantitiesVersionsService extends IService<BusBillofquantitiesVersions>{
/**
* 查询工程量清单版本
*
* @param id 主键
* @return 工程量清单版本
*/
BusBillofquantitiesVersionsVo queryById(Long id);
/**
* 分页查询工程量清单版本列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 工程量清单版本分页列表
*/
TableDataInfo<BusBillofquantitiesVersionsVo> queryPageList(BusBillofquantitiesVersionsBo bo, PageQuery pageQuery);
/**
* 查询符合条件的工程量清单版本列表
*
* @param bo 查询条件
* @return 工程量清单版本列表
*/
List<BusBillofquantitiesVersionsVo> queryList(BusBillofquantitiesVersionsBo bo);
/**
* obtainTheList
*
* @param bo 工程量清单版本
* @return 是否新增成功
*/
Boolean insertByBo(BusBillofquantitiesVersionsBo bo);
/**
* 修改工程量清单版本
*
* @param bo 工程量清单版本
* @return 是否修改成功
*/
Boolean updateByBo(BusBillofquantitiesVersionsBo bo);
/**
* 校验并批量删除工程量清单版本信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 导入excel
*/
Boolean importExcelFile(ImportExcelFileReq bo, MultipartFile file) throws IOException;
/**
* 获取所有版本号
*/
TableDataInfo<BusBillofquantitiesVersionsVo> obtainAllVersionNumbers(ObtainAllVersionNumbersReq bo, PageQuery pageQuery);
/**
* 获取工程量清单
*/
List<ObtainTheListRes> obtainTheList(ObtainTheListReq bo);
}

View File

@ -0,0 +1,138 @@
package org.dromara.design.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.dromara.design.domain.bo.BusBillofquantitiesBo;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.design.mapper.BusBillofquantitiesMapper;
import org.dromara.design.service.IBusBillofquantitiesService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
/**
* 工程量清单Service业务层处理
*
* @author Lion Li
* @date 2025-08-11
*/
@RequiredArgsConstructor
@Service
public class BusBillofquantitiesServiceImpl extends ServiceImpl<BusBillofquantitiesMapper, BusBillofquantities> implements IBusBillofquantitiesService {
private final BusBillofquantitiesMapper baseMapper;
/**
* 查询工程量清单
*
* @param id 主键
* @return 工程量清单
*/
@Override
public BusBillofquantitiesVo queryById(Long id){
return baseMapper.selectVoById(id);
}
/**
* 分页查询工程量清单列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 工程量清单分页列表
*/
@Override
public TableDataInfo<BusBillofquantitiesVo> queryPageList(BusBillofquantitiesBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<BusBillofquantities> lqw = buildQueryWrapper(bo);
Page<BusBillofquantitiesVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询符合条件的工程量清单列表
*
* @param bo 查询条件
* @return 工程量清单列表
*/
@Override
public List<BusBillofquantitiesVo> queryList(BusBillofquantitiesBo bo) {
LambdaQueryWrapper<BusBillofquantities> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<BusBillofquantities> buildQueryWrapper(BusBillofquantitiesBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<BusBillofquantities> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BusBillofquantities::getId);
lqw.eq(StringUtils.isNotBlank(bo.getVersions()), BusBillofquantities::getVersions, bo.getVersions());
lqw.eq(StringUtils.isNotBlank(bo.getSheet()), BusBillofquantities::getSheet, bo.getSheet());
lqw.eq(bo.getPid() != null, BusBillofquantities::getPid, bo.getPid());
lqw.eq(StringUtils.isNotBlank(bo.getNum()), BusBillofquantities::getNum, bo.getNum());
lqw.like(StringUtils.isNotBlank(bo.getName()), BusBillofquantities::getName, bo.getName());
lqw.eq(StringUtils.isNotBlank(bo.getSpecification()), BusBillofquantities::getSpecification, bo.getSpecification());
lqw.eq(StringUtils.isNotBlank(bo.getUnit()), BusBillofquantities::getUnit, bo.getUnit());
lqw.eq(bo.getQuantity() != null, BusBillofquantities::getQuantity, bo.getQuantity());
return lqw;
}
/**
* 新增工程量清单
*
* @param bo 工程量清单
* @return 是否新增成功
*/
@Override
public Boolean insertByBo(BusBillofquantitiesBo bo) {
BusBillofquantities add = MapstructUtils.convert(bo, BusBillofquantities.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改工程量清单
*
* @param bo 工程量清单
* @return 是否修改成功
*/
@Override
public Boolean updateByBo(BusBillofquantitiesBo bo) {
BusBillofquantities update = MapstructUtils.convert(bo, BusBillofquantities.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(BusBillofquantities entity){
//TODO 做一些数据校验,如唯一约束
}
/**
* 校验并批量删除工程量清单信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
}

View File

@ -0,0 +1,320 @@
package org.dromara.design.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.excel.coryUtils.ExcelReader;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.utils.BatchNumberGenerator;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.design.domain.bo.ImportExcelFileReq;
import org.dromara.design.domain.bo.ObtainAllVersionNumbersReq;
import org.dromara.design.domain.bo.ObtainTheListReq;
import org.dromara.design.domain.dto.ObtainTheListRes;
import org.dromara.design.domain.vo.BusBillofquantitiesVo;
import org.dromara.design.mapper.BusBillofquantitiesMapper;
import org.dromara.design.service.IBusBillofquantitiesService;
import org.dromara.system.domain.vo.SysOssUploadVo;
import org.dromara.system.service.ISysOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.dromara.design.domain.bo.BusBillofquantitiesVersionsBo;
import org.dromara.design.domain.vo.BusBillofquantitiesVersionsVo;
import org.dromara.design.domain.BusBillofquantitiesVersions;
import org.dromara.design.mapper.BusBillofquantitiesVersionsMapper;
import org.dromara.design.service.IBusBillofquantitiesVersionsService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static org.dromara.common.constant.MinioPathConstant.BillOfQuantities;
/**
* 工程量清单版本Service业务层处理
*
* @author Lion Li
* @date 2025-08-11
*/
@RequiredArgsConstructor
@Service
public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillofquantitiesVersionsMapper, BusBillofquantitiesVersions> implements IBusBillofquantitiesVersionsService {
private final BusBillofquantitiesVersionsMapper baseMapper;
private final IBusBillofquantitiesService busBillofquantitiesService;
@Autowired
private ISysOssService ossService;
/**
* 查询工程量清单版本
*
* @param id 主键
* @return 工程量清单版本
*/
@Override
public BusBillofquantitiesVersionsVo queryById(Long id){
return baseMapper.selectVoById(id);
}
/**
* 分页查询工程量清单版本列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 工程量清单版本分页列表
*/
@Override
public TableDataInfo<BusBillofquantitiesVersionsVo> queryPageList(BusBillofquantitiesVersionsBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = buildQueryWrapper(bo);
Page<BusBillofquantitiesVersionsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询符合条件的工程量清单版本列表
*
* @param bo 查询条件
* @return 工程量清单版本列表
*/
@Override
public List<BusBillofquantitiesVersionsVo> queryList(BusBillofquantitiesVersionsBo bo) {
LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<BusBillofquantitiesVersions> buildQueryWrapper(BusBillofquantitiesVersionsBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BusBillofquantitiesVersions::getId);
lqw.eq(StringUtils.isNotBlank(bo.getWorkOrderType()), BusBillofquantitiesVersions::getWorkOrderType, bo.getWorkOrderType());
lqw.eq(StringUtils.isNotBlank(bo.getVersions()), BusBillofquantitiesVersions::getVersions, bo.getVersions());
return lqw;
}
/**
* 新增工程量清单版本
*
* @param bo 工程量清单版本
* @return 是否新增成功
*/
@Override
public Boolean insertByBo(BusBillofquantitiesVersionsBo bo) {
BusBillofquantitiesVersions add = MapstructUtils.convert(bo, BusBillofquantitiesVersions.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改工程量清单版本
*
* @param bo 工程量清单版本
* @return 是否修改成功
*/
@Override
public Boolean updateByBo(BusBillofquantitiesVersionsBo bo) {
BusBillofquantitiesVersions update = MapstructUtils.convert(bo, BusBillofquantitiesVersions.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(BusBillofquantitiesVersions entity){
//TODO 做一些数据校验,如唯一约束
}
/**
* 校验并批量删除工程量清单版本信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
/**
* 导入excel
*/
@Override
@Transactional
public Boolean importExcelFile(ImportExcelFileReq bo, MultipartFile file) throws IOException {
//0、创建版本
// SysOssUploadVo wordEntity = ossService.uploadWithNoSave(file, ossService.minioFileName(BillOfQuantities,file));
String banBen = BatchNumberGenerator.generateBatchNumber("GCLBB-");
int insert = baseMapper.insert(new BusBillofquantitiesVersions().
setWorkOrderType(bo.getWorkOrderType()).
setVersions(banBen));
if(insert<=0){
throw new ServiceException("创建版本失败");
}
//1、获取到解析数据
ExcelReader.ExcelData excelData = ExcelReader.readExcelFromMultipartFile(file);
// 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid
List<BusBillofquantities> allMaterials = new ArrayList<>();
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
String sheetName = sheetData.getSheetName();
List<List<String>> rowDataList = sheetData.getData();
// 构建当前Sheet的树形结构复用ExcelReader的buildTree方法
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
// 存储节点映射TreeNode → ExcelMaterial用于子节点关联父节点
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
// 递归遍历树形结构生成sid和pid
traverseTree(rootNode, nodeMap, allMaterials, sheetName,banBen);
}
// 3. 批量插入数据库
return busBillofquantitiesService.saveBatch(allMaterials);
}
@Override
public TableDataInfo<BusBillofquantitiesVersionsVo> obtainAllVersionNumbers(ObtainAllVersionNumbersReq bo, PageQuery pageQuery) {
LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BusBillofquantitiesVersions::getId);
lqw.eq(StringUtils.isNotBlank(bo.getWorkOrderType()), BusBillofquantitiesVersions::getWorkOrderType, bo.getWorkOrderType());
lqw.last("create_time desc");
Page<BusBillofquantitiesVersionsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
@Override
public List<ObtainTheListRes> obtainTheList(ObtainTheListReq bo) {
// 1. 从数据库查询所有符合条件的扁平数据
List<ObtainTheListRes> flatList = baseMapper.obtainTheList(bo);
if (flatList.isEmpty()) {
return Collections.emptyList();
}
// 2. 构建父子映射key=父节点pidvalue=该父节点的所有子节点
Map<Long, List<ObtainTheListRes>> parentMap = flatList.stream()
.collect(Collectors.groupingBy(ObtainTheListRes::getPid));
// 3. 递归组装树形结构从顶级节点pid=0开始
List<ObtainTheListRes> treeList = buildTree(0L, parentMap);
return treeList;
}
/**
* 递归构建树形结构
* @param parentId 父节点ID顶级节点为0
* @param parentMap 父子映射表key=pidvalue=子节点列表)
* @return 组装好的子树列表
*/
private List<ObtainTheListRes> buildTree(Long parentId, Map<Long, List<ObtainTheListRes>> parentMap) {
// 获取当前父节点的所有直接子节点
List<ObtainTheListRes> children = parentMap.getOrDefault(parentId, Collections.emptyList());
if (children.isEmpty()) {
return Collections.emptyList();
}
// 为每个子节点递归设置其下一级子节点
for (ObtainTheListRes child : children) {
// 递归查询当前子节点的子节点,设置为它的子树
List<ObtainTheListRes> subChildren = buildTree(child.getId(), parentMap);
// 注意需要在Vo中添加子节点列表字段用于存储子树
child.setChildren(subChildren);
}
return children;
}
/**
* 递归遍历树形结构生成sid和pid
* 规则A列为中文数字一、二、三...的节点为顶级节点pid=0
*/
private void traverseTree(ExcelReader.TreeNode currentNode,
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap,
List<BusBillofquantities> allMaterials,
String sheetName,
String banBen) {
// 跳过空节点(无实际数据的中间节点)
if (currentNode.getData().isEmpty()) {
for (ExcelReader.TreeNode child : currentNode.getChildren()) {
traverseTree(child, nodeMap, allMaterials, sheetName,banBen);
}
return;
}
// 获取当前节点A列的值num
List<String> rowData = currentNode.getData();
String aNum = rowData.size() >= 1 ? rowData.get(0).trim() : "";
// 生成当前节点的sid
String sid = BatchNumberGenerator.generateBatchNumber("GCLQD-");
// 确定pid顶级节点A列为中文数字pid=0否则pid=父节点的sid
String pid = determineParentId(currentNode, aNum, nodeMap);
// 封装数据到实体类
BusBillofquantities material = new BusBillofquantities();
material.setSheet(sheetName);
material.setSid(sid);
material.setPid(pid);
material.setNum(aNum);
material.setName(rowData.size() >= 2 ? rowData.get(1).trim() : "");
material.setUnit(rowData.size() >= 3 ? rowData.get(2).trim() : "");
material.setQuantity(Integer.parseInt(rowData.size() >= 4 ? rowData.get(3).trim() : ""));
material.setRemark(rowData.size() >= 5 ? rowData.get(4).trim() : "");
// 存储映射关系供子节点查询父sid
nodeMap.put(currentNode, material);
allMaterials.add(material);
// 递归处理子节点
for (ExcelReader.TreeNode child : currentNode.getChildren()) {
traverseTree(child, nodeMap, allMaterials, sheetName,banBen);
}
}
/**
* 确定当前节点的pid
* 1. 若为顶级节点A列为中文数字pid=0
* 2. 否则pid=父节点的sid
*/
private String determineParentId(ExcelReader.TreeNode currentNode,
String aNum,
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap) {
// 检查是否为顶级节点A列为中文数字一、二、三...
if (aNum.matches(ExcelReader.CHINESE_NUMBERS_REGEX)) {
return "0"; // 顶级节点pid固定为0
}
// 非顶级节点查找父节点的sid
// 遍历nodeMap找到当前节点的父节点通过Tree结构的父子关系反向查找
for (Map.Entry<ExcelReader.TreeNode, BusBillofquantities> entry : nodeMap.entrySet()) {
ExcelReader.TreeNode parentNode = entry.getKey();
if (parentNode.getChildren().contains(currentNode)) {
return entry.getValue().getSid(); // 父节点的sid
}
}
// 异常情况:未找到父节点(默认顶级节点处理,避免数据丢失)
return "0";
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.design.mapper.BusBillofquantitiesMapper">
</mapper>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.design.mapper.BusBillofquantitiesVersionsMapper">
<select id="obtainTheList" resultType="org.dromara.design.domain.dto.ObtainTheListRes">>
select
*
from
bus_billofquantities
<where>
<if test="versions != null">
bo.versions = #{versions}
</if>
<if test="sheet != null">
bo.sheet = #{sheet}
</if>
</where>
</select>
</mapper>