diff --git a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaType.java b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaType.java index 0036a3f..20ef0f8 100644 --- a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaType.java +++ b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/MaType.java @@ -31,12 +31,12 @@ public class MaType extends BaseEntity { /** 类型名称 */ @ApiModelProperty(value = "类型名称") - @Excel(name = "名称") + @Excel(name = "类型名称") private String typeName; /** 规格名称 */ - @ApiModelProperty(value = "规格名称") - @Excel(name = "名称") + @ApiModelProperty(value = "规格型号") + @Excel(name = "规格型号") private String modelName; /** 替换类型ID */ @@ -69,7 +69,7 @@ public class MaType extends BaseEntity { /** 计量单位 */ @ApiModelProperty(value = "计量单位") - @Excel(name = "计量单位") + @Excel(name = "单位") private String unitName; /** 管理方式 */ diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java index 3b4c701..20f2005 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java @@ -433,9 +433,7 @@ public class PoiOutPage { return workbook; } - public static void excelForcheckEach(HSSFWorkbook workbook,HSSFSheet sheet,List> resultLease,List> resultLose,List> resultRepair,List> resultScrap,List> resultsReduction, - List listLease,List listLose,List listRepair,List listScrap,List listReduction, String projectName, String unit, - BigDecimal totalCostLease, BigDecimal totalCostLose, BigDecimal totalCostRepair, BigDecimal totalCostScrap,BigDecimal totalCostReduction) { + public static void excelForcheckEach(HSSFWorkbook workbook,HSSFSheet sheet,List> resultLease,List listLease) { sheet.setDefaultColumnWidth(15); // 设置列宽 @@ -448,145 +446,12 @@ public class PoiOutPage { int rowNum = 0; // 填充表头 - rowNum = createHeaderRow(sheet, rowNum, listLease, headerStyle); + rowNum = createHeaderRowTwo(sheet, rowNum, listLease, headerStyle); // 填充数据行 if (resultLease != null && !resultLease.isEmpty()) { rowNum = createDataRows(sheet, rowNum, resultLease, contentStyle, listLease.size()); - } else { - // 如果没有数据,则仅显示表头 -// rowNum++; -// rowNum = createDataRows(sheet, rowNum, resultLease, contentStyle, listLease.size()); - HSSFRow row = sheet.createRow(rowNum++); - HSSFCell cell = row.createCell(0); - cell.setCellStyle(headerStyle); - cell.setCellValue("暂无数据"); - sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listLease.size() - 1))); - CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listLease.size() - 1)); - // 设置边框样式 - RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); } - rowNum = createTotalRow(sheet, rowNum, listLease, totalCostLease, headerStyle); - - /** - * 维修费用明细 - */ - // 填充标题行 - rowNum = createTitleRowStyleCost(sheet, rowNum, "维修费用明细", titleStyle, listRepair.size()); - // 填充表头 - rowNum = createHeaderRow(sheet, rowNum, listRepair, headerStyle); - // 填充数据行 - if (resultRepair!= null &&!resultRepair.isEmpty()) { - rowNum = createDataRows(sheet, rowNum, resultRepair, contentStyle, listRepair.size()); - } else { - // 如果没有数据,则仅显示表头 -// rowNum++; -// rowNum = createDataRows(sheet, rowNum, resultRepair, contentStyle, listRepair.size()); - HSSFRow row = sheet.createRow(rowNum++); - HSSFCell cell = row.createCell(0); - cell.setCellStyle(headerStyle); - cell.setCellValue("暂无数据"); - sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listRepair.size() - 1))); - CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listRepair.size() - 1)); - // 设置边框样式 - RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); - } - rowNum = createTotalRow(sheet, rowNum, listRepair, totalCostRepair, headerStyle); - - /** - * 报废费用明细 - */ - // 填充标题行 - rowNum = createTitleRowStyleCost(sheet, rowNum, "报废费用明细", titleStyle, listScrap.size()); - // 填充表头 - rowNum = createHeaderRow(sheet, rowNum, listScrap, headerStyle); - // 填充数据行 - if (resultScrap!= null &&!resultScrap.isEmpty()) { - rowNum = createDataRows(sheet, rowNum, resultScrap, contentStyle, listScrap.size()); - } else { - // 如果没有数据,则仅显示表头 -// rowNum++; -// rowNum = createDataRows(sheet, rowNum, resultScrap, contentStyle, listScrap.size()); - HSSFRow row = sheet.createRow(rowNum++); - HSSFCell cell = row.createCell(0); - cell.setCellStyle(headerStyle); - cell.setCellValue("暂无数据"); - sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listScrap.size() - 1))); - CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listScrap.size() - 1)); - // 设置边框样式 - RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); - } - rowNum = createTotalRow(sheet, rowNum, listScrap, totalCostScrap, headerStyle); - - /** - * 丢失费用明细 - */ - // 填充标题行 - rowNum = createTitleRowStyleCost(sheet, rowNum, "丢失费用明细", titleStyle, listLose.size()); - // 填充表头 - rowNum = createHeaderRow(sheet, rowNum, listLose, headerStyle); - // 填充数据行 - if (resultLose!= null &&!resultLose.isEmpty()) { - rowNum = createDataRows(sheet, rowNum, resultLose, contentStyle, listLose.size()); - } else { - // 如果没有数据,则仅显示表头 -// rowNum++; -// rowNum = createDataRows(sheet, rowNum, resultLose, contentStyle, listLose.size()); - HSSFRow row = sheet.createRow(rowNum++); - HSSFCell cell = row.createCell(0); - cell.setCellStyle(headerStyle); - cell.setCellValue("暂无数据"); - sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listLose.size() - 1))); - CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listLose.size() - 1)); - // 设置边框样式 - RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); - } - rowNum = createTotalRow(sheet, rowNum, listLose, totalCostLose, headerStyle); - - /** - * 减免费用明细 - */ - // 填充标题行 - rowNum = createTitleRowStyleCost(sheet, rowNum, "减免费用明细", titleStyle, listReduction.size()); - // 填充表头 - rowNum = createHeaderRow(sheet, rowNum, listReduction, headerStyle); - // 填充数据行 - if (resultsReduction != null && !resultsReduction.isEmpty()) { - rowNum = createDataRows(sheet, rowNum, resultsReduction, contentStyle, listReduction.size()); - } else { - // 如果没有数据,则仅显示表头 -// rowNum++; -// rowNum = createDataRows(sheet, rowNum, resultLease, contentStyle, listLease.size()); - HSSFRow row = sheet.createRow(rowNum++); - HSSFCell cell = row.createCell(0); - cell.setCellStyle(headerStyle); - cell.setCellValue("暂无数据"); - sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listReduction.size() - 1))); - CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (listReduction.size() - 1)); - // 设置边框样式 - RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); - RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); - } - rowNum = createTotalRow(sheet, rowNum, listReduction, totalCostReduction, headerStyle); - - - //合计 - BigDecimal totalCostAll = totalCostLease.add(totalCostLose).add(totalCostRepair).add(totalCostScrap).add(totalCostReduction); - rowNum = createTotalRowAll(sheet, rowNum, listScrap, totalCostAll, headerStyle); } @@ -1116,6 +981,18 @@ public class PoiOutPage { return rowNum; } + private static int createHeaderRowTwo(HSSFSheet sheet, int rowNum, List list, HSSFCellStyle headerStyle) { + HSSFRow row = sheet.createRow(rowNum++); + row.setHeightInPoints(20); + for (int j = 0; j < list.size(); j++) { + HSSFCell cell = row.createCell(j); + String header = list.get(j); + cell.setCellStyle(headerStyle); + cell.setCellValue(header != null ? header : ""); + } + return rowNum; + } + /** * 创建数据行 */ diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/PurchaseCheckInfoController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/PurchaseCheckInfoController.java index c250279..300eb1b 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/PurchaseCheckInfoController.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/PurchaseCheckInfoController.java @@ -2,14 +2,17 @@ package com.bonus.sgzb.material.controller; import java.io.OutputStream; import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import cn.hutool.core.convert.Convert; import com.alibaba.fastjson.JSONObject; +import com.bonus.sgzb.base.api.domain.MaType; import com.bonus.sgzb.base.api.domain.SltAgreementInfo; import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit; import com.bonus.sgzb.common.security.annotation.RequiresPermissions; @@ -31,6 +34,8 @@ import com.bonus.sgzb.common.core.web.controller.BaseController; import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.utils.poi.ExcelUtil; import com.bonus.sgzb.common.core.web.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; + /** * 新购验收任务 * @@ -165,38 +170,85 @@ public class PurchaseCheckInfoController extends BaseController { * 机具模板下载--all */ @ApiOperation(value = "机具模板下载") - @PreventRepeatSubmit -// @RequiresPermissions("settlement:info:export") - @Log(title = "机具模板下载") - @PostMapping("/downLoadTypeModel") public void downLoadTypeModel(HttpServletResponse response, @RequestParam("params") String params) { -// try { -// List sltAgreementInfo = JSONObject.parseArray(params,SltAgreementInfo.class); -// // 创建工作簿 -// HSSFWorkbook workbook = new HSSFWorkbook(); -// int sheetIndex = 1; -// -// // 创建工作表 -// HSSFSheet sheet = workbook.createSheet("机具新增" + sheetIndex); -// -// // 创建工作簿和工作表 -// PoiOutPage.excelForcheckEach(workbook, sheet, resultsLease,resultsLose,resultsRepair,resultsScrap,resultsReduction, headersLease,headersLose,headersRepair,headersScrap,headersReduction,projectName,unitName,totalCostLease,totalCostLose,totalCostRepair,totalCostScrap,totalCostReduction); -// -// sheetIndex++; -// -// OutputStream out = null; -// response.setContentType("application/vnd.ms-excel;charset=UTF-8"); -// response.addHeader("Content-Disposition", -// "attachment;filename=" + URLEncoder.encode("各结算明细", "UTF-8") + ".xls"); -// response.setHeader("Pragma", "No-cache"); -// out = response.getOutputStream(); -// workbook.write(out); -// out.flush(); -// out.close(); -// -// } catch (Exception e) { -// log.error(e.toString(), e); -// } + try { + + // 创建工作簿 + HSSFWorkbook workbook = new HSSFWorkbook(); + int sheetIndex = 1; + + // 创建工作表 + HSSFSheet sheet = workbook.createSheet("机具新增"); + //创建表头 + ArrayList list = new ArrayList(); + list.add("类型名称"); + list.add("规格型号"); + list.add("单位"); + //数据转换 + Map map = new LinkedHashMap(); + map.put("typeName",null ); + map.put("modelName",null ); + map.put("nuitName", null); + List> maps = new ArrayList>(); + maps.add(map); + // 创建工作簿和工作表 + PoiOutPage.excelForcheckEach(workbook, sheet,maps,list); + sheetIndex++; + HSSFSheet sheetTwo = workbook.createSheet("机具类型规格"); + //创建表头 + ArrayList listTwo = new ArrayList(); + listTwo.add("类型名称"); + listTwo.add("规格型号"); + listTwo.add("单位"); + + List listType = purchaseCheckInfoService.selectMaTypeList(); + List type = Convert.toList(MaType.class, listType); + List> mapsType = new ArrayList>(); + //数据转换 + if (type!= null) { + int sizeLease = type.size(); + for (int i = 0; i < sizeLease; i++) { + MaType bean = type.get(i); + Map mapTwo = new LinkedHashMap(); + mapTwo.put("typeName",bean.getTypeName()); + mapTwo.put("modelName",bean.getModelName() ); + mapTwo.put("nuitName", bean.getUnitName()); + mapsType.add(mapTwo); + } + }else{ + map.put("typeName",null ); + map.put("modelName",null ); + map.put("nuitName", null); + mapsType.add(map); + } + // 创建工作簿和工作表 + PoiOutPage.excelForcheckEach(workbook, sheetTwo,mapsType,listTwo); + sheetIndex++; + OutputStream out = null; + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.addHeader("Content-Disposition", + "attachment;filename=" + URLEncoder.encode("模板下载", "UTF-8") + ".xls"); + response.setHeader("Pragma", "No-cache"); + out = response.getOutputStream(); + workbook.write(out); + out.flush(); + out.close(); + + } catch (Exception e) { + logger.error("模板下载失败", e); + } + } + + /** + * 物资信息导入 + * @param file + * @return + */ + @ApiOperation(value = "物资信息导入") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file) + { + return purchaseCheckInfoService.importTbPeople(file); } } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/PurchaseCheckInfoMapper.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/PurchaseCheckInfoMapper.java index 9dfa986..2f119bf 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/PurchaseCheckInfoMapper.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/PurchaseCheckInfoMapper.java @@ -1,5 +1,6 @@ package com.bonus.sgzb.material.mapper; +import com.bonus.sgzb.base.api.domain.MaType; import com.bonus.sgzb.material.domain.BmNoticeInfo; import com.bonus.sgzb.base.api.domain.MachinePart; import com.bonus.sgzb.material.domain.PurchaseCheckInfo; @@ -128,4 +129,8 @@ public interface PurchaseCheckInfoMapper { * @return */ List getWholeSetDetails(PurchaseCheckInfo purchaseCheckInfo); + + List selectMaTypeList(); + + List selectTypeDetail(MaType type); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IPurchaseCheckInfoService.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IPurchaseCheckInfoService.java index e42a89b..c496c86 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IPurchaseCheckInfoService.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/IPurchaseCheckInfoService.java @@ -1,9 +1,12 @@ package com.bonus.sgzb.material.service; +import com.bonus.sgzb.base.api.domain.MaType; import com.bonus.sgzb.base.api.domain.MachinePart; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.material.domain.PurchaseCheckInfo; import com.bonus.sgzb.material.domain.PurchaseInput; import com.bonus.sgzb.material.vo.NoticeInfoVO; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -114,4 +117,17 @@ public interface IPurchaseCheckInfoService * @return */ List getWholeSetDetails(PurchaseCheckInfo purchaseCheckInfo); + + /** + * 查询类型规格 + * @return + */ + List selectMaTypeList(); + + /** + * 物资信息导入 + * @param file + * @return + */ + AjaxResult importTbPeople(MultipartFile file); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/PurchaseCheckInfoServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/PurchaseCheckInfoServiceImpl.java index 3be0d2b..331001f 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/PurchaseCheckInfoServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/PurchaseCheckInfoServiceImpl.java @@ -1,9 +1,15 @@ package com.bonus.sgzb.material.service.impl; +import com.bonus.sgzb.base.api.domain.MaType; import com.bonus.sgzb.base.api.domain.MachinePart; import com.bonus.sgzb.common.core.utils.DateUtils; +import com.bonus.sgzb.common.core.utils.HttpCodeEnum; import com.bonus.sgzb.common.core.utils.StringHelper; +import com.bonus.sgzb.common.core.utils.StringUtils; +import com.bonus.sgzb.common.core.utils.poi.ExcelUtil; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.security.utils.SecurityUtils; +import com.bonus.sgzb.material.config.MaterialConstants; import com.bonus.sgzb.material.domain.*; import com.bonus.sgzb.material.mapper.PurchaseCheckDetailsMapper; import com.bonus.sgzb.material.mapper.PurchaseCheckInfoMapper; @@ -12,12 +18,20 @@ import com.bonus.sgzb.material.service.IPurchaseCheckInfoService; import com.bonus.sgzb.material.vo.GlobalContants; import com.bonus.sgzb.material.vo.NoticeInfoVO; import com.bonus.sgzb.system.api.RemoteUserService; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; /** * 新购验收任务Service业务层处理 @@ -318,4 +332,172 @@ public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService { } return send; } + + @Override + public List selectMaTypeList() { + List listType = purchaseCheckInfoMapper.selectMaTypeList(); + return listType; + } + + /** + * 物资信息导入 + * @param file + * @return + */ + @Override + public AjaxResult importTbPeople(MultipartFile file) { + String fileName = file.getOriginalFilename(); + if (fileName != null) { + String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1); + if (!MaterialConstants.XLSX.equalsIgnoreCase(fileExtension)) { + // 文件后缀名不符合要求 + return AjaxResult.error("导入失败:文件后缀名不符合要求,必须为xlsx结尾"); + } + } + try { + InputStream inputStream = file.getInputStream(); + Workbook workbook = new XSSFWorkbook(inputStream); // 处理.xlsx文件 + + Sheet sheet = workbook.getSheetAt(0); + // 得到Excel的行数 + int totalRows = sheet.getPhysicalNumberOfRows(); + // 检查是否有行数 + if (totalRows <= 1) { + throw new IllegalArgumentException("导入失败:Excel文件中没有数据,请检查后重新导入"); + } + // 读取第一行表头 + Row headerRow = sheet.getRow(0); + if (headerRow == null) { + throw new IllegalArgumentException("导入失败:文件中没有表头"); + } + // 获取表头的列数 + int totalCells = headerRow.getPhysicalNumberOfCells(); + // 预期的表头列数为11列,可以根据实际需求修改这个条件 + if (totalCells != 3) { + throw new IllegalArgumentException("导入失败:表头列数与预期不符,请检查导入模板"); + } +// // 获取数据行数 +// int rowCount = sheet.getLastRowNum() + 1; +// if (rowCount > 50) { +// throw new IllegalArgumentException("导入失败:数据总条数不能超过 50 条"); +// } + // 读取表头内容并验证每一列 + extractedText(headerRow, totalCells); + //读取Excel表格数据,做非空及格式判断 + extractedCell(sheet, totalRows, totalCells); + ExcelUtil util = new ExcelUtil<>(MaType.class); + List maDevList = util.importExcel(file.getInputStream()); + List templateVos = new ArrayList<>(); + // 判断装备类目是否为空,查询装备id及价格 + if (!CollectionUtils.isEmpty(maDevList)) { + int i =1; + for (MaType devTemplateVo : maDevList) { + i++; + if (StringUtils.isNotBlank(devTemplateVo.getTypeName()) && StringUtils.isNotBlank(devTemplateVo.getModelName()) && StringUtils.isNotBlank(devTemplateVo.getUnitName())) { + // 根据物资类型详情 + List list = purchaseCheckInfoMapper.selectTypeDetail(devTemplateVo); + if (!CollectionUtils.isEmpty(list)) { + if(list.size()!=1){ + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "第"+i+"行数据有误,请检查"); + } + MaType devType = list.get(0); + devTemplateVo.setTypeId(devType.getTypeId()); + templateVos.add(devTemplateVo); + }else{ + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "第"+i+"行数据有误,请检查"); + } + } + } + } + return AjaxResult.success(templateVos); + } catch (IOException e) { + e.printStackTrace(); + } + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg()); + } + + /** + * 读取Excel表格数据,做非空及格式判断 + * @param headerRow + * @param totalCells + */ + private void extractedText(Row headerRow, int totalCells) { + for (int cellNum = 0; cellNum < totalCells; cellNum++) { + Cell cell = headerRow.getCell(cellNum); + // 获取单元格内容并去除首尾空格 + String headerValue = cell.getStringCellValue().trim(); + // 根据列索引进行验证 + switch (cellNum) { + case 0: + if (!"类型名称".equals(headerValue)) { + throw new IllegalArgumentException("第 " + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板"); + } + break; + case 1: + if (!"规格型号".equals(headerValue)) { + throw new IllegalArgumentException("第 " + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板"); + } + break; + case 2: + if (!"单位".equals(headerValue)) { + throw new IllegalArgumentException("第 " + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板"); + } + break; + default: + break; + } + } + } + + /** + * 读取Excel表格数据,做非空判断 + * @param sheet + * @param totalRows + * @param totalCells + */ + private void extractedCell(Sheet sheet, int totalRows, int totalCells) { + //读取Excel表格数据,做非空判断 + // 循环Excel行数 + DataFormatter dataFormatter = new DataFormatter(); + for (int r = 1; r < totalRows; r++) { + Row row = sheet.getRow(r); + // 循环Excel列数 + for (int c = 0; c < totalCells; c++) { + Cell cell = row.getCell(c); + String cellValue = ""; + if (cell != null && cell.getCellType() == CellType.STRING) { + cellValue = cell.getStringCellValue(); + } + if (c == 5) { + cellValue = dataFormatter.formatCellValue(row.getCell(c)); + } + switch (c) { + case 0: + checkBlank(cellValue, r, c); + break; + case 1: + checkBlank(cellValue, r, c); + break; + case 2: + checkBlank(cellValue, r, c); + break; + default: + break; + } + } + } + } + + /** + * 检查数据是否为空 + * @param cellValue + * @param rowIndex + * @param colIndex + */ + private void checkBlank(String cellValue, int rowIndex, int colIndex) { + if (StringUtils.isBlank(cellValue)) { + throw new IllegalArgumentException( + String.format("第 %d 行,第 %d 列数据为空,请检查后重新导入", rowIndex + 1, colIndex + 1)); + } + } } diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/PurchaseCheckInfoMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/PurchaseCheckInfoMapper.xml index df1f1c8..09fbc3c 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/PurchaseCheckInfoMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/PurchaseCheckInfoMapper.xml @@ -339,4 +339,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" or mt3.type_name like concat('%', #{keyWord}, '%')) + + + + \ No newline at end of file diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SelectMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SelectMapper.xml index 5101bad..60f3088 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SelectMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SelectMapper.xml @@ -152,7 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id WHERE mm.ma_code is not null and mm.ma_status in (15) GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id - WHERE mt.del_flag = '0' and mt.is_whole_set IS NULL + WHERE mt.del_flag = '0' AND mt.level IN ('1','2')