导入设备excel

This commit is contained in:
jing's 2023-12-03 09:56:01 +08:00
parent 48afb04d94
commit 16775fac5d
18 changed files with 747 additions and 94 deletions

View File

@ -16,6 +16,16 @@ public class OptionalBomConstant {
private final String description;
}
@AllArgsConstructor
@Getter
public enum ChooseStatusEnum implements ValueEnum<Integer> {
CHOOSE_STATUS_NO(0, "可选"),
CHOOSE_STATUS_YES(1, "标配");
private final Integer value;
private final String description;
}
//数据来源 (0 :excel 1:手动录入)
@AllArgsConstructor
@ -48,4 +58,19 @@ public class OptionalBomConstant {
}
@AllArgsConstructor
@Getter
public enum ExcelErrorTagEnum implements ValueEnum<Integer> {
NO(0, "无错误"),
REPEAT (1, "重复的标配"),
MATERIA_NO_UNKOWN (2, "无物料号"),
ALL (3, "同时满足");
private final Integer value;
private final String description;
}
}

View File

@ -0,0 +1,27 @@
package com.nflg.product.bomnew.excel;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ImportExcelField{
@ExcelIgnore
private Integer lineNo;
@ExcelProperty(value="",index = 0)
private String cellFirst;
@ExcelProperty(value="",index = 1)
private String cellSecond;
@ExcelProperty(value="",index = 2)
private String cellThird;
}

View File

@ -0,0 +1,131 @@
package com.nflg.product.bomnew.excel;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.enums.CellExtraTypeEnum;
import com.alibaba.excel.metadata.CellExtra;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.List;
public class ImportExcelHelper<T> {
private static final Logger LOGGER = LoggerFactory.getLogger(ImportExcelHelper.class);
/**
* 返回解析后的List
*
* @param: fileName 文件名
* @param: clazz Excel对应属性名
* @param: sheetNo 要解析的sheet
* @param: headRowNumber 正文起始行
* @return java.util.List<T> 解析后的List
*/
public List<T> getList(InputStream inputStream, Class<T> clazz, Integer sheetNo, Integer headRowNumber) {
ImportExcelListener<T> listener = new ImportExcelListener<>(headRowNumber);
try {
EasyExcel.read(inputStream, clazz, listener).extraRead(CellExtraTypeEnum.MERGE).sheet(sheetNo).headRowNumber(headRowNumber).doRead();
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
List<CellExtra> extraMergeInfoList = listener.getExtraMergeInfoList();
if (CollectionUtil.isEmpty(extraMergeInfoList)) {
return listener.getData();
}
List<T> data = explainMergeData(listener.getData(), extraMergeInfoList, headRowNumber);
return data;
}
/**
* 处理合并单元格
*
* @param data 解析数据
* @param extraMergeInfoList 合并单元格信息
* @param headRowNumber 起始行
* @return 填充好的解析数据
*/
private List<T> explainMergeData(List<T> data, List<CellExtra> extraMergeInfoList, Integer headRowNumber) {
//循环所有合并单元格信息
extraMergeInfoList.forEach(cellExtra -> {
int firstRowIndex = cellExtra.getFirstRowIndex() - headRowNumber;
int lastRowIndex = cellExtra.getLastRowIndex() - headRowNumber;
int firstColumnIndex = cellExtra.getFirstColumnIndex();
int lastColumnIndex = cellExtra.getLastColumnIndex();
//获取初始值
Object initValue = getInitValueFromList(firstRowIndex, firstColumnIndex, data);
//设置值
for (int i = firstRowIndex; i <= lastRowIndex; i++) {
for (int j = firstColumnIndex; j <= lastColumnIndex; j++) {
setInitValueToList(initValue, i, j, data);
}
}
});
return data;
}
/**
* 设置合并单元格的值
*
* @param filedValue
* @param rowIndex
* @param columnIndex
* @param data 解析数据
*/
public void setInitValueToList(Object filedValue, Integer rowIndex, Integer columnIndex, List<T> data) {
T object = data.get(rowIndex);
for (Field field : object.getClass().getDeclaredFields()) {
//提升反射性能关闭安全检查
field.setAccessible(true);
ExcelProperty annotation = field.getAnnotation(ExcelProperty.class);
if (annotation != null) {
if (annotation.index() == columnIndex) {
try {
field.set(object, filedValue);
break;
} catch (IllegalAccessException e) {
LOGGER.error("设置合并单元格的值异常:"+e.getMessage());
}
}
}
}
}
/**
* 获取合并单元格的初始值
* rowIndex对应list的索引
* columnIndex对应实体内的字段
*
* @param firstRowIndex 起始行
* @param firstColumnIndex 起始列
* @param data 列数据
* @return 初始值
*/
private Object getInitValueFromList(Integer firstRowIndex, Integer firstColumnIndex, List<T> data) {
Object filedValue = null;
T object = data.get(firstRowIndex);
for (Field field : object.getClass().getDeclaredFields()) {
//提升反射性能关闭安全检查
field.setAccessible(true);
ExcelProperty annotation = field.getAnnotation(ExcelProperty.class);
if (annotation != null) {
if (annotation.index() == firstColumnIndex) {
try {
filedValue = field.get(object);
break;
} catch (IllegalAccessException e) {
LOGGER.error("设置合并单元格的初始值异常:"+e.getMessage());
}
}
}
}
return filedValue;
}
}

View File

@ -0,0 +1,143 @@
package com.nflg.product.bomnew.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellExtra;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.fastjson.JSON;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Excel模板的读取监听类
*/
public class ImportExcelListener<T> extends AnalysisEventListener<T> {
private static final Logger LOGGER = LoggerFactory.getLogger(ImportExcelListener.class);
/**
* 解析的数据
*/
List<T> list = new ArrayList<>();
/**
* 正文起始行
*/
private Integer headRowNumber;
/**
* 合并单元格
*/
private List<CellExtra> extraMergeInfoList = new ArrayList<>();
public ImportExcelListener(Integer headRowNumber) {
this.headRowNumber = headRowNumber;
}
/**
* 这个每一条数据解析都会来调用
*
* @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()}
* @param context context
*/
@Override
public void invoke(T data, AnalysisContext context) {
// 如果一行Excel数据均为空值则不装载该行数据
if(isLineNullValue(data)){
return;
}
LOGGER.info("解析到一条数据: {}", JSON.toJSONString(data));
// 获取Excle行号(从0开始)
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
try {
BeanUtils.setProperty(data, "lineNo", rowIndex+1);
} catch (IllegalAccessException e) {
LOGGER.error("ImportExcelListener.invoke 设置行号异常: ", e);
} catch (InvocationTargetException e) {
LOGGER.error("ImportExcelListener.invoke 设置行号异常: ", e);
}
list.add(data);
}
/**
* 所有数据解析完成了 都会来调用
*
* @param context context
*/
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
LOGGER.info("所有数据解析完成!");
}
/**
* 返回解析出来的List
*/
public List<T> getData() {
return list;
}
/**
* 读取额外信息合并单元格
*/
@Override
public void extra(CellExtra extra, AnalysisContext context) {
LOGGER.info("读取到了一条额外信息:{}", JSON.toJSONString(extra));
switch (extra.getType()) {
case MERGE: {
LOGGER.info(
"额外信息是合并单元格,而且覆盖了一个区间,在firstRowIndex:{},firstColumnIndex;{},lastRowIndex:{},lastColumnIndex:{}",
extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(),
extra.getLastColumnIndex());
if (extra.getRowIndex() >= headRowNumber) {
extraMergeInfoList.add(extra);
}
break;
}
default:
}
}
/**
* 返回解析出来的合并单元格List
*/
public List<CellExtra> getExtraMergeInfoList() {
return extraMergeInfoList;
}
/**
* 判断整行单元格数据是否均为空 true是 false否
*/
private boolean isLineNullValue(T data) {
if (data instanceof String) {
return Objects.isNull(data);
}
try {
List<Field> fields = Arrays.stream(data.getClass().getDeclaredFields())
.filter(f -> f.isAnnotationPresent(ExcelProperty.class))
.collect(Collectors.toList());
List<Boolean> lineNullList = new ArrayList<>(fields.size());
for (Field field : fields) {
field.setAccessible(true);
Object value = field.get(data);
if (Objects.isNull(value)) {
lineNullList.add(Boolean.TRUE);
} else {
lineNullList.add(Boolean.FALSE);
}
}
return lineNullList.stream().allMatch(Boolean.TRUE::equals);
} catch (Exception e) {
LOGGER.error("读取数据行[{}]解析失败: {}", data, e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,246 @@
package com.nflg.product.bomnew.excel;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteTable;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.nflg.product.bomnew.pojo.vo.OptionalEbomMainVO;
import org.apache.poi.ss.usermodel.*;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class PreviewExcelExportHelper {
public void buildHeader(int maxColumn, OptionalEbomMainVO header , WriteSheet sheet, ExcelWriter writer, AtomicInteger tableNoCounting) {
//自定义到处样式
WriteCellStyle cellStyle = new WriteCellStyle();
//水平居中
cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont writeFont = new WriteFont();
//加粗
writeFont.setBold(Boolean.TRUE);
//字体大小
writeFont.setFontHeightInPoints((short) 14);
cellStyle.setWriteFont(writeFont);
WriteTable table = EasyExcel
.writerTable(tableNoCounting.get())
.needHead(Boolean.FALSE)
.registerWriteHandler(
new OnceAbsoluteMergeStrategy(tableNoCounting.get() - 1, tableNoCounting.getAndIncrement() - 1, 0, maxColumn)
)
.registerWriteHandler(new HorizontalCellStyleStrategy(cellStyle, cellStyle))
.build();
//在这里由于EasyExcel使用List<List<String>>这样的数据来构建一个表里面的List<String>表示一行数据
//所以我们这里一次只构建一行数据一行数据中只有一个单元格的数据一行数据就作为一个表格写入
//故有几个标题就需要构建几次表格
List<String> cellList = new ArrayList<>();
cellList.add(String.format("%s选配清单",header.getDeviceName()));
//因为需要合并单元格到列数最大的单元格处这里如果不添加空字符串则不会构建单元格在合并单元格的时候就会报错
// for (int i = 0; i < maxColumn - 1; ++i) {
// cellList.add("");
// }
List<List<String>> rowList = new ArrayList<>();
rowList.add(cellList);
//写入表格
writer.write(rowList, sheet, table);
//第二行
table = EasyExcel
.writerTable(tableNoCounting.get())
.needHead(Boolean.FALSE)
// .registerWriteHandler(new HorizontalCellStyleStrategy(cellStyle, cellStyle))
.registerWriteHandler(new PreviewExcelExportHelper.CellColorSheetWriteHandler())
.build();
cellList.clear();
rowList.clear();
cellList.add("机型编号:");
cellList.add(String.format("%s",header.getDeviceNo()));
cellList.add("机型名称:");
cellList.add(String.format("%s",header.getDeviceName()));
rowList.add(cellList);
writer.write(rowList, sheet, table);
tableNoCounting.getAndIncrement();
table = EasyExcel
.writerTable(tableNoCounting.get())
.needHead(Boolean.FALSE)
.registerWriteHandler(
new OnceAbsoluteMergeStrategy(tableNoCounting.get() - 1, tableNoCounting.getAndIncrement() - 1, 0, maxColumn)
)
// .registerWriteHandler(new HorizontalCellStyleStrategy(cellStyle, cellStyle))
.build();
rowList.clear();
writer.write(rowList, sheet, table);
}
public static class CellColorSheetWriteHandler implements CellWriteHandler {
private final Logger LOGGER = LoggerFactory.getLogger(CellColorSheetWriteHandler.class);
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
}
@Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
Head head, Integer relativeRowIndex, Boolean isHead) {
LOGGER.info("第{}行,第{}列写入完成。", cell.getRowIndex(), cell.getColumnIndex());
int rowIndex = cell.getRowIndex();
int cellIndex = cell.getColumnIndex();
// if(rowIndex==1){
// switch (cellIndex){
// case 0:
// case 2: {
// CellStyle cellStyle = cell.getSheet().getWorkbook().createCellStyle();
// cellStyle.setFillBackgroundColor(IndexedColors.GREEN.index);
// cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// cellStyle.setBorderLeft(BorderStyle.THIN);
// cellStyle.setLeftBorderColor((short) 0);
// cellStyle.setBorderTop(BorderStyle.THIN);
// cellStyle.setTopBorderColor((short) 0);
// cellStyle.setBorderRight(BorderStyle.THIN);
// cellStyle.setRightBorderColor((short) 0);
// cellStyle.setBorderBottom(BorderStyle.THIN);
// cellStyle.setBottomBorderColor((short) 0);
// // 字体
// Font headWriteFont = cell.getSheet().getWorkbook().createFont();
// //设置字体名字
// headWriteFont.setFontName("宋体");
// //设置字体大小
// headWriteFont.setFontHeightInPoints((short) 11);
// headWriteFont.setBold(true);
// cellStyle.setFont(headWriteFont);
// //设置水平对齐的样式为居中对齐;
// cellStyle.setAlignment(HorizontalAlignment.RIGHT);
// //设置垂直对齐的样式为居中对齐;
// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// cell.setCellStyle(cellStyle);
// }
// break;
//
//
// case 1:
// case 3: {
// CellStyle cellStyle = cell.getSheet().getWorkbook().createCellStyle();
// cellStyle.setFillBackgroundColor(IndexedColors.GREEN.index);
// cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// cellStyle.setBorderLeft(BorderStyle.THIN);
// cellStyle.setLeftBorderColor((short) 0);
// cellStyle.setBorderTop(BorderStyle.THIN);
// cellStyle.setTopBorderColor((short) 0);
// cellStyle.setBorderRight(BorderStyle.THIN);
// cellStyle.setRightBorderColor((short) 0);
// cellStyle.setBorderBottom(BorderStyle.THIN);
// cellStyle.setBottomBorderColor((short) 0);
// // 字体
// Font headWriteFont = cell.getSheet().getWorkbook().createFont();
// //设置字体名字
// headWriteFont.setFontName("宋体");
// //设置字体大小
// headWriteFont.setFontHeightInPoints((short) 11);
// cellStyle.setFont(headWriteFont);
// //设置水平对齐的样式为居中对齐;
// cellStyle.setAlignment(HorizontalAlignment.CENTER);
// //设置垂直对齐的样式为居中对齐;
// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// cell.setCellStyle(cellStyle);
// }
// break;
//
// }
// }
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
}
}
public static WriteCellStyle getBodyStyle(HorizontalAlignment horizontalAlignment ) {
WriteCellStyle bodyWriteCellStyle = new WriteCellStyle();
// 字体
WriteFont headWriteFont = new WriteFont();
//设置字体名字
headWriteFont.setFontName("宋体");
//设置字体大小
headWriteFont.setFontHeightInPoints((short) 11);
//设置底边框;
bodyWriteCellStyle.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
bodyWriteCellStyle.setBottomBorderColor((short) 0);
//设置左边框;
bodyWriteCellStyle.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
bodyWriteCellStyle.setLeftBorderColor((short) 0);
//设置右边框;
bodyWriteCellStyle.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
bodyWriteCellStyle.setRightBorderColor((short) 0);
//设置顶边框;
bodyWriteCellStyle.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
bodyWriteCellStyle.setTopBorderColor((short) 0);
//设置自动换行;
bodyWriteCellStyle.setWrapped(false);
//设置水平对齐的样式为居中对齐;
bodyWriteCellStyle.setHorizontalAlignment(horizontalAlignment);
//设置垂直对齐的样式为居中对齐;
bodyWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return bodyWriteCellStyle;
}
}

View File

@ -31,4 +31,8 @@ public interface MaterialMainMapper extends BaseMapper<MaterialMainEntity> {
List<BaseMaterialVO> getMaterialByDrawingNo(@Param("drawingNos") List<String> drawingNos);
List<BaseMaterialVO> getMaterialByAnyNo(@Param("drawingNos") List<String> drawingNos);
}

View File

@ -26,22 +26,22 @@ public class OptionalEbomImportChildAddDTO implements Serializable {
/**
* 物料编码
*/
@ApiModelProperty(value = "物料编码")
private String materialNo;
// @ApiModelProperty(value = "物料编码")
// private String materialNo;
/**
* 物料名
*/
@ApiModelProperty(value = "物料名")
private String materialName;
// @ApiModelProperty(value = "物料名")
// private String materialName;
/**
* 物料描述
*/
@ApiModelProperty(value = "物料描述")
private String materialDesc;
// @ApiModelProperty(value = "物料描述")
// private String materialDesc;
/**
* 图号
*/
@ApiModelProperty(value = "图号")
@ApiModelProperty(value = "图号/物料编码")
private String drawingNo;
/**
* 部件类型(1 单选 2 多选)

View File

@ -98,4 +98,21 @@ public class OptionalEbomImportChildDTO implements Serializable {
private String createdBy;
private Integer lineNo;
/**
* 是否忽略 物料号
*/
private Boolean tag;
/**
* 错误类型
* 第0位表示重复的标配 第1位无物料号
*
*/
private int error ;
}

View File

@ -3,33 +3,69 @@ package com.nflg.product.bomnew.pojo.dto;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.Data;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@Data
@ApiModel("选项信息")
@Accessors(chain = true)
public class OptionalEbomImportDTO implements Serializable {
/**主键*/ @ApiModelProperty(value = "主键")
public class OptionalEbomImportDTO<T> implements Serializable {
/**
* 主键
*/
@ApiModelProperty(value = "主键")
private Long rowId;
/**根节点id*/ @ApiModelProperty(value = "根节点id")
/**
* 根节点id
*/
@ApiModelProperty(value = "根节点id")
private Long rootRowId;
/**上层id*/ @ApiModelProperty(value = "上层id")
/**
* 上层id
*/
@ApiModelProperty(value = "上层id")
private Long parentRowId;
/**选项名*/ @ApiModelProperty(value = "选项名")
/**
* 选项名
*/
@ApiModelProperty(value = "选项名")
private String optionName;
/**创建时间*/ @ApiModelProperty(value = "创建时间")
@ApiModelProperty(value = "选项图号")
private String optionDrawingNo;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private Date createdTime;
/**是否删除(0 :否 1是)*/ @ApiModelProperty(value = "是否删除(0 :否 1是)")
/**
* 是否删除(0 : 1)
*/
@ApiModelProperty(value = "是否删除(0 :否 1是)")
private Integer isDel;
@ApiModelProperty(value = "操作人编码")
private String createdBy;
private List<T> child;
private boolean error;
}

View File

@ -49,6 +49,10 @@ public class OptionalEbomImportEntity implements Serializable {
@TableField(value = "option_name")
@ApiModelProperty(value = "选项名")
private String optionName;
@TableField(value = "option_drawing_no")
@ApiModelProperty(value = "选项图号")
private String optionDrawingNo;
/**
* 创建时间
*/

View File

@ -90,7 +90,7 @@ public class OptionalEbomImportChildVO implements Serializable {
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private LocalDateTime createdTime;
private Date createdTime;
/**
* 操作人编码
*/

View File

@ -45,6 +45,8 @@ public class OptionalEbomImportVO<T> implements Serializable {
*/
@ApiModelProperty(value = "选项名")
private String optionName;
@ApiModelProperty(value = "选项图号")
private String optionDrawingNo;
/**
* 创建时间
*/

View File

@ -33,16 +33,17 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
/**
* 获取物料信息
*
* @param materialNos
* @return
*/
public List<BaseMaterialVO> getMaterialBaseInfo(@Param("materialNos") List<String> materialNos){
public List<BaseMaterialVO> getMaterialBaseInfo(@Param("materialNos") List<String> materialNos) {
return this.getBaseMapper().getMaterialBaseInfo(materialNos);
}
public List<MaterialMateVO> getMateialMate(){
public List<MaterialMateVO> getMateialMate() {
return this.getBaseMapper().getMateialMate();
}
@ -75,9 +76,9 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
* @param setFun
* @param <T>
*/
public <T> void initMaterialForDrawdingNo(List<T> list, Function<T, String> getDrawingNoFun, BiConsumer<T, String>... setFun) {
public <T> void initMaterialForDrawdingNo(List<T> list, Function<T, String> getDrawingNoFun, BiConsumer<T, String>... setFun) {
List<String> drawingNos = list.stream().map(getDrawingNoFun).collect(Collectors.toList());
if(CollUtil.isNotEmpty(drawingNos)) {
if (CollUtil.isNotEmpty(drawingNos)) {
List<BaseMaterialVO> materialList = SpringUtil.getBean(MaterialMainMapper.class).getMaterialByDrawingNo(drawingNos);
Map<String, BaseMaterialVO> materialVOMap = ListCommonUtil.listToMap(materialList, BaseMaterialVO::getDrawingNo);
for (T t : list) {
@ -96,4 +97,44 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
}
public <T> void initMaterialForDrawdingNoImmul(List<T> list, Function<T, String> getDrawingNoFun, BiConsumer<T, String> setMaterialNoFun,BiConsumer<T, String> setMaterialDescFun) {
List<String> drawingNos = list.stream().map(getDrawingNoFun).collect(Collectors.toList());
if (CollUtil.isNotEmpty(drawingNos)) {
List<BaseMaterialVO> materialList = SpringUtil.getBean(MaterialMainMapper.class).getMaterialByDrawingNo(drawingNos);
Map<String, BaseMaterialVO> materialVOMap = ListCommonUtil.listToMap(materialList, BaseMaterialVO::getDrawingNo);
for (T t : list) {
String drawingNo = getDrawingNoFun.apply(t);
BaseMaterialVO materialVO = materialVOMap.get(drawingNo);
if (materialVO != null) {
setMaterialNoFun.accept( t,materialVO.getMaterialNo());
setMaterialDescFun .accept( t,materialVO.getMaterialDesc());
// for (BiConsumer<T, String> setFun1 : setFun) {
// setFun1.accept(t, materialVO.getMaterialNo());
// }
}
}
}
}
/**
* @param drawingNos 图号 物料号
* @return
*/
public List<BaseMaterialVO> initMaterialForAnyNo(List<String> drawingNos) {
if (CollUtil.isNotEmpty(drawingNos)) {
List<BaseMaterialVO> materialList = SpringUtil.getBean(MaterialMainMapper.class).getMaterialByAnyNo(drawingNos);
return materialList;
}
return null;
}
}

View File

@ -3,6 +3,7 @@ package com.nflg.product.bomnew.service;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -14,112 +15,70 @@ import com.nflg.product.bomnew.pojo.dto.OptionalEbomImportChildAddDTO;
import com.nflg.product.bomnew.pojo.dto.OptionalEbomImportChildDTO;
import com.nflg.product.bomnew.pojo.dto.OptionalEbomMainDelDTO;
import com.nflg.product.bomnew.pojo.entity.OptionalEbomImportChildEntity;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.pojo.vo.OptionalEbomImportChildVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* ebom选配件表(OptionalEbomImportChild)服务实现类
*
*/
@Service
public class OptionalEbomImportChildService extends ServiceImpl<OptionalEbomImportChildMapper, OptionalEbomImportChildEntity> {
public List<OptionalEbomImportChildVO> getByRootRowIdList( Long rootRowId){
public List<OptionalEbomImportChildVO> getByRootRowIdList(Long rootRowId) {
return getBaseMapper().getByRootRowIdList(rootRowId);
}
private OptionalEbomImportChildEntity vo2entity(OptionalEbomImportChildVO vo){
OptionalEbomImportChildEntity entity=new OptionalEbomImportChildEntity();
BeanUtils.copyProperties(vo,entity);
entity.setCreatedTime(new Date());
entity.setUpdatedTime(entity.getCreatedTime());
// entity.setCreatedBy(SessionUtil.getUserCode());
return entity;
}
/**
* 标配
* @param entities
* @return
*/
public Boolean insertPartTypeRadio( List<OptionalEbomImportChildVO> entities){
if(entities==null || entities.size()==0){
return false;
}
List<OptionalEbomImportChildEntity> lists= Convert.convert(new TypeReference<List<OptionalEbomImportChildEntity>>() {}, entities);
lists.forEach(item->{
item.setCreatedBy(SessionUtil.getUserCode());
item.setCreatedTime(new Date());
item.setUpdatedTime(new Date());
});
return this.saveOrUpdateBatch(lists) ;
}
public Boolean insertPartTypeCheckbox( OptionalEbomImportChildVO vo){
OptionalEbomImportChildEntity entity= Convert.convert(new TypeReference<OptionalEbomImportChildEntity>() {}, vo);
entity.setPartType(OptionalBomConstant.PartTypeEnum.PART_TYPE_CHECBOX.getValue());
entity.setCreatedBy(SessionUtil.getUserCode());
entity.setCreatedTime(new Date());
entity.setUpdatedTime(new Date());
return this.save(entity);
}
/**
* 添加选配数据
*
* @param dto
* @return
*/
public Boolean insertOption(OptionalEbomImportChildAddDTO dto) throws NflgBusinessException {
String nos = dto.getDrawingNo();
//先统一后分割
String[] array = nos.replace("", ";").split(";");
List<String> listNo = Arrays.stream(array).collect(Collectors.toList());
if(dto.getPartType()==OptionalBomConstant.PartTypeEnum.PART_TYPE_RADIO.getValue()){
OptionalEbomImportChildVO vo=Convert.convert(new TypeReference<OptionalEbomImportChildVO>() {}, dto);
List<OptionalEbomImportChildVO> list=new ArrayList<>();
list.add(vo);
list.forEach(item->{
item.setSource(OptionalBomConstant.SourceTypeEnum.SOURCE_INPUT.getValue());
});
List<BaseMaterialVO> materialListVo = SpringUtil.getBean(MaterialMainService.class).initMaterialForAnyNo(listNo);
List<OptionalEbomImportChildEntity> optionList = Convert.convert(new TypeReference<List<OptionalEbomImportChildEntity>>() {
}, materialListVo);
return insertPartTypeRadio(list);
}
optionList.forEach(item -> {
if(dto.getPartType()==OptionalBomConstant.PartTypeEnum.PART_TYPE_CHECBOX.getValue()){
OptionalEbomImportChildVO vo=Convert.convert(new TypeReference<OptionalEbomImportChildVO>() {}, dto);
vo.setSource(OptionalBomConstant.SourceTypeEnum.SOURCE_INPUT.getValue());
return insertPartTypeCheckbox(vo);
}
item.setSource(OptionalBomConstant.SourceTypeEnum.SOURCE_INPUT.getValue());
item.setCreatedBy(SessionUtil.getUserCode());
item.setRootRowId(dto.getRootRowId());
item.setParentRowId(dto.getParentRowId());
item.setPartType(dto.getPartType());
item.setRemak(dto.getRemak());
item.setCreatedTime(new Date());
item.setUpdatedTime(new Date());
});
return this.saveOrUpdateBatch(optionList);
return false;
}
public Boolean openCloseStatus(OptionalEbomImportChildVO vo) {
public Boolean openCloseStatus( OptionalEbomImportChildVO vo) {
OptionalEbomImportChildEntity entity= Convert.convert(OptionalEbomImportChildEntity.class,vo);
OptionalEbomImportChildEntity entity = Convert.convert(OptionalEbomImportChildEntity.class, vo);
entity.setUpdatedTime(new Date());
return this.updateById(entity);
return this.updateById(entity);
}
@ -131,18 +90,18 @@ public class OptionalEbomImportChildService extends ServiceImpl<OptionalEbomImpo
// }
public Boolean deleteByRootId( OptionalEbomMainDelDTO dto){
public Boolean deleteByRootId(OptionalEbomMainDelDTO dto) {
List<Long> longList = dto.getRowIdList();
String rowIds = longList.stream().map(Object::toString)
.collect(Collectors.joining(","));
return getBaseMapper().deleteByRootId(rowIds)>0;
return getBaseMapper().deleteByRootId(rowIds) > 0;
}
public Boolean deleteByRowId(List<Long> longIds){
public Boolean deleteByRowId(List<Long> longIds) {
String rowIds = longIds.stream().map(Object::toString)
.collect(Collectors.joining(","));
return getBaseMapper().deleteByRowId(rowIds)>0;
return getBaseMapper().deleteByRowId(rowIds) > 0;
}
}

View File

@ -56,6 +56,7 @@ public class OptionalEbomMainService extends ServiceImpl<OptionalEbomMainMapper,
return b;
}
@Transactional(rollbackFor = Exception.class)
public Boolean deleteByRowIds(OptionalEbomMainDelDTO dto) {
List<Long> longList = dto.getRowIdList();

View File

@ -99,4 +99,20 @@
</select>
<select id="getMaterialByAnyNo" resultType="com.nflg.product.bomnew.pojo.vo.BaseMaterialVO">
select material_no, material_name, material_desc, procure_type, project_type, material_state,drawing_no,material_category_code ,material_get_type
from t_material_main
where drawing_no in
<foreach collection="drawingNos" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
or
material_no in
<foreach collection="drawingNos" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
</mapper>

View File

@ -77,7 +77,6 @@
<select id="getPreviewOptionList" resultType="com.nflg.product.bomnew.pojo.vo.OptionalEbomImportChildVO" >
SELECT t1.row_id,
t1.parent_row_id,
t1.root_row_id,
@ -95,7 +94,7 @@
t1.created_by,
t2.choose_status from
t_optional_ebom_config_r as t2 LEFT JOIN t_optional_ebom_import_child as t1 on t2.option_row_id=t1.row_id
where t1.is_enable=1 and t2.parent_row_id=#{rowId} and (t1.drawing_no!=null or t1.drawing_no!='')
where t1.is_enable=1 and t2.parent_row_id=#{rowId} and (t1.material_no!=null or t1.material_no!='')
</select>

View File

@ -7,13 +7,15 @@
<result property="rootRowId" column="root_row_id" jdbcType="INTEGER"/>
<result property="parentRowId" column="parent_row_id" jdbcType="INTEGER"/>
<result property="optionName" column="option_name" jdbcType="VARCHAR"/>
<result property="optionDrawingNo" column="option_drawing_no" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="isDel" column="is_del" jdbcType="INTEGER"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List" >
row_id,root_row_id,parent_row_id,option_name,created_time,is_del,created_by
row_id,root_row_id,parent_row_id,option_name,option_drawing_no,created_time,is_del,created_by
</sql>
<!--查询单个-->
<select id="queryById" resultMap="OptionalEbomImportMap">