原始BOM-导入
This commit is contained in:
parent
e4e733d61f
commit
5d840850f2
|
|
@ -2,24 +2,37 @@ package com.nflg.product.bomnew.api.user;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.pojo.dto.BomNewOriginalExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.OriginalSaveBomDTO;
|
||||
import com.nflg.product.bomnew.pojo.query.OriginalBomQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
||||
import com.nflg.product.bomnew.service.BomNewOriginalParentService;
|
||||
import com.nflg.product.bomnew.util.EecExcelUtil;
|
||||
import com.nflg.product.bomnew.util.TreeNode;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListMapSheet;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
|
|
@ -106,14 +119,24 @@ public class OriginalBomApi extends BaseApi {
|
|||
|
||||
}
|
||||
|
||||
@GetMapping("getOriginalBomExcelTemplate")
|
||||
@ApiOperation("原始BOM导入模板下载")
|
||||
public void getAttrGroupExcelTemplate(HttpServletResponse response) throws IOException {
|
||||
EecExcelUtil.setResponseExcelHeader(response, "OriginalBomTemplate");
|
||||
new Workbook("物料导入", "").addSheet(new ListSheet<>("sheet1", ImmutableList.of(new BomNewOriginalExcelDTO()))).writeTo(response.getOutputStream());
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation("导入")
|
||||
@PostMapping("importBom")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Boolean> importBom(@RequestParam(value = "file")MultipartFile file){
|
||||
public ResultVO<Boolean> importBom(@RequestParam(value = "file")MultipartFile file) throws IOException {
|
||||
if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) {
|
||||
return ResultVO.error("请上传Excel文件");
|
||||
}
|
||||
originalParentService.importBom(file);
|
||||
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
return ResultVO.success(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.nflg.product.bomnew.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @decription
|
||||
* @Author 大米
|
||||
* @Date 2022/8/9 15:43
|
||||
**/
|
||||
@Data
|
||||
public class BaseImportExcelDTO {
|
||||
|
||||
@ApiModelProperty("行号")
|
||||
private int rowNum;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.product.bomnew.pojo.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
|
@ -11,40 +12,60 @@ import java.math.BigDecimal;
|
|||
* 原始BOM-excel 导入DTO
|
||||
*/
|
||||
@Data
|
||||
public class BomNewOriginalExcelDTO {
|
||||
public class BomNewOriginalExcelDTO extends BaseImportExcelDTO {
|
||||
|
||||
@ApiModelProperty("uuid")
|
||||
private String uuid;
|
||||
|
||||
@ExcelColumn("层次")
|
||||
private String levelNo;
|
||||
private Integer levelNo;
|
||||
|
||||
@ExcelColumn("物料编码")
|
||||
private String materialNo;
|
||||
|
||||
@ExcelColumn("图号")
|
||||
private String drawingNo;
|
||||
private String chartNo;
|
||||
|
||||
@ExcelColumn("名称")
|
||||
private String materialName;
|
||||
|
||||
@ExcelColumn("材料")
|
||||
private String materialTexture;
|
||||
private String material;
|
||||
|
||||
|
||||
@ExcelColumn(value = "数量")
|
||||
private BigDecimal num;
|
||||
private Integer qty;
|
||||
|
||||
@ExcelColumn("单位")
|
||||
private String unitName;
|
||||
|
||||
@ExcelColumn(value = "版本")
|
||||
private String currentVersion;
|
||||
private String rev;
|
||||
|
||||
|
||||
@ExcelColumn(value = "单重")
|
||||
private BigDecimal unitWeight;
|
||||
private BigDecimal weight;
|
||||
|
||||
|
||||
@ExcelColumn(value = "备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("父标识")
|
||||
private String parentKey;
|
||||
|
||||
private String designBy;
|
||||
|
||||
@ApiModelProperty("排序号")
|
||||
private Integer orderNo;
|
||||
|
||||
public String getDesignBy() {
|
||||
return SessionUtil.getUserCode();
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createdBy;
|
||||
|
||||
public String getCreatedBy() {
|
||||
return SessionUtil.getUserCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,32 +2,39 @@ package com.nflg.product.bomnew.service;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.product.base.core.config.SpringContextUtils;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.OriginalConstant;
|
||||
import com.nflg.product.bomnew.constant.OriginalEditStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalSourceEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewOriginalParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.BomNewOriginalExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.OriginalSaveBomDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomOriginalCadParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.OriginalBomQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalPlmBomVO;
|
||||
import com.nflg.product.bomnew.service.domain.OriginalBom.OriginalBomDetailTask;
|
||||
import com.nflg.product.bomnew.service.domain.OriginalBom.OriginalBomToEBomConvert;
|
||||
import com.nflg.product.bomnew.service.domain.OriginalBom.PlmBomToOriginalConvert;
|
||||
import com.nflg.product.bomnew.util.*;
|
||||
import org.apache.commons.collections.map.LinkedMap;
|
||||
import org.bouncycastle.cert.dane.DANEEntry;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
|
@ -147,23 +154,22 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
child.setDeptName(parentEntity.getDeptName());
|
||||
child.setSource(parentEntity.getSource());
|
||||
//非本人则为借用件
|
||||
if(child.getCreatedBy().equals(SessionUtil.getUserCode()) && OriginalStatusEnum.UN_CONVERT.equalsValue(parentEntity.getStatus()) ){
|
||||
if (child.getCreatedBy().equals(SessionUtil.getUserCode()) && OriginalStatusEnum.UN_CONVERT.equalsValue(parentEntity.getStatus())) {
|
||||
child.setStatus(OriginalStatusEnum.REFERENCE.getValue());
|
||||
}else {
|
||||
} else {
|
||||
child.setStatus(OriginalStatusEnum.BORROWED_PARTS.getValue());
|
||||
}
|
||||
}
|
||||
else { //无BOM-版本时 确定版本号
|
||||
} else { //无BOM-版本时 确定版本号
|
||||
child.setStatus(OriginalStatusEnum.UN_CONVERT.getValue());
|
||||
child.setSource(Objects.nonNull(parent)? parent.getSource(): OriginalSourceEnum.CAD_IMPORT.getValue());
|
||||
child.setSource(Objects.nonNull(parent) ? parent.getSource() : OriginalSourceEnum.CAD_IMPORT.getValue());
|
||||
child.setDeviseUserCode(parent.getDeviseUserCode());
|
||||
child.setDeviseName(parent.getDeviseName());
|
||||
child.setDeptName(parent.getDeptName());
|
||||
if( MaterialshouldBomExistUtil.checkShouldBomExist(child)){
|
||||
child.setCurrentVersion(OriginalConstant.NO_BOM_VERSION);
|
||||
child.setStatus(OriginalStatusEnum.UN_CONVERT.getValue());
|
||||
// child.setEditStatus(OriginalEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
}
|
||||
if (MaterialshouldBomExistUtil.checkShouldBomExist(child)) {
|
||||
child.setCurrentVersion(OriginalConstant.NO_BOM_VERSION);
|
||||
child.setStatus(OriginalStatusEnum.UN_CONVERT.getValue());
|
||||
// child.setEditStatus(OriginalEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,8 +179,6 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<TreeNode<BomOriginalListVO>> getChildTree(Long rowId) throws ExecutionException, InterruptedException {
|
||||
|
||||
List<BomOriginalListVO> bomTree = getBomTree(rowId);
|
||||
|
|
@ -242,7 +246,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
for (BomOriginalCadParentEntity parent : parents) {
|
||||
//转原始BOM
|
||||
convert.convertOriginalBom(parent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(convert.getResultParent())) {
|
||||
|
|
@ -253,19 +257,19 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
}
|
||||
//删除plm临时表数据
|
||||
List<Integer> delRowIds = parents.stream().map(u -> u.getRowId()).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(delRowIds)) {
|
||||
if (CollUtil.isNotEmpty(delRowIds)) {
|
||||
originalCadParentService.getBaseMapper().deleteBatchIds(delRowIds);
|
||||
originalCadParentService.getBaseMapper().delChildByParentRowIds(delRowIds);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算层级数和根节点状态
|
||||
*/
|
||||
public void computeLevelNumAndRootState() {
|
||||
public void computeLevelNumAndRootState() {
|
||||
//计算树的层级数
|
||||
CompletableFuture.runAsync(()->{
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
this.compucteLevelNum();
|
||||
this.getBaseMapper().updateRootState();
|
||||
|
|
@ -278,7 +282,6 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除BOM
|
||||
*
|
||||
|
|
@ -287,7 +290,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
public Boolean del(Long bomRowId) throws ExecutionException, InterruptedException {
|
||||
|
||||
BomNewOriginalParentEntity parentEntity = this.getBaseMapper().selectById(bomRowId);
|
||||
VUtils.isTure(Objects.isNull(parentEntity) ).throwMessage("该节点不存在,请检查参数是否正确");
|
||||
VUtils.isTure(Objects.isNull(parentEntity)).throwMessage("该节点不存在,请检查参数是否正确");
|
||||
VUtils.isTure(!parentEntity.getCreatedBy().equals(SessionUtil.getUserCode())).throwMessage("该节点不属于你,你无权删除");
|
||||
List<BomOriginalListVO> bomTree = getBomTree(bomRowId);
|
||||
|
||||
|
|
@ -347,11 +350,65 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
ebomChildService.saveOrUpdateBatch(convert.getEBomChildResult());
|
||||
}
|
||||
//将原始BOM转为已处理
|
||||
if(CollUtil.isNotEmpty(convert.getHasHandlerParentIds())){
|
||||
if (CollUtil.isNotEmpty(convert.getHasHandlerParentIds())) {
|
||||
this.getBaseMapper().updateBomState(OriginalStatusEnum.OVER_CONVERT.getValue(), convert.getHasHandlerParentIds());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ThreadLocal<Integer> rowNum = new ThreadLocal<>();
|
||||
|
||||
public static ThreadLocal<List<BomNewOriginalExcelDTO>> excelContextTL = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 原始BOM导入
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importBom(MultipartFile file) throws IOException {
|
||||
rowNum.set(1);
|
||||
excelContextTL.set(new ArrayList<>());
|
||||
EecExcelUtil.handlerExcel(file.getInputStream(), BomNewOriginalExcelDTO.class, BomNewOriginalParentService::handlerExcelRow);
|
||||
List<BomNewOriginalExcelDTO> excelContext = excelContextTL.get();
|
||||
List<Integer> noLevelNo = excelContext.stream().filter(u -> Objects.isNull(u.getLevelNo())).map(u->u.getRowNum()).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isNotEmpty(noLevelNo)).throwMessage(StrUtil.join(",",noLevelNo )+"层次为空");
|
||||
List<Integer> noDrawingNo = excelContext.stream().filter(u -> StrUtil.isBlank(u.getChartNo())).map(u->u.getRowNum()).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isNotEmpty(noDrawingNo)).throwMessage(StrUtil.join(",",noDrawingNo )+"图号为空");
|
||||
List<Integer> noNum = excelContext.stream().filter(u -> Objects.isNull(u.getQty())).map(u->u.getRowNum()).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isNotEmpty(noNum)).throwMessage( StrUtil.join(",",noNum )+"数量为空");
|
||||
|
||||
for (BomNewOriginalExcelDTO data : excelContext) {
|
||||
List<BomNewOriginalExcelDTO> parentData = excelContext.stream().filter(u -> u.getLevelNo().equals(data.getLevelNo() - 1) && u.getRowNum() < data.getRowNum())
|
||||
.sorted(Comparator.comparing(BomNewOriginalExcelDTO::getRowNum).reversed()).limit(1).collect(Collectors.toList());
|
||||
data.setParentKey(CollUtil.isNotEmpty(parentData) ? StrUtil.join("-", parentData.get(0).getLevelNo(), parentData.get(0).getRowNum()) : "0");
|
||||
|
||||
}
|
||||
//转换
|
||||
for (BomNewOriginalExcelDTO data : excelContext) {
|
||||
PlmBomToOriginalConvert convert = new PlmBomToOriginalConvert();
|
||||
List<BomNewOriginalExcelDTO> chileds = excelContext.stream().filter(u -> u.getParentKey().equals(data.getLevelNo() + "-" + data.getRowNum())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(chileds)) {
|
||||
convert.convertOriginalBomFromExcel(Convert.convert(BomOriginalPlmBomVO.class, data), Convert.toList(BomOriginalPlmBomVO.class, chileds));
|
||||
|
||||
if (CollUtil.isNotEmpty(convert.getResultParent())) {
|
||||
this.saveOrUpdateBatch(convert.getResultParent());
|
||||
}
|
||||
if (CollUtil.isNotEmpty(convert.getResultChild())) {
|
||||
originalChildService.saveOrUpdateBatch(convert.getResultChild());
|
||||
}
|
||||
}
|
||||
}
|
||||
excelContextTL.remove();
|
||||
}
|
||||
|
||||
public static void handlerExcelRow(BomNewOriginalExcelDTO data) {
|
||||
data.setRowNum(rowNum.get());
|
||||
data.setOrderNo(data.getLevelNo());
|
||||
data.setChartNo(StrUtil.trim(data.getChartNo()).replace("(","(").replace(")",")").replace(" ",""));
|
||||
rowNum.set(rowNum.get() + 1);
|
||||
|
||||
excelContextTL.get().add(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public abstract class BaseConvert {
|
|||
*
|
||||
* @param material
|
||||
*/
|
||||
protected BomNewOriginalParentEntity buildParentEntity(BomOriginalPlmBomVO material ,String preVersion) {
|
||||
protected BomNewOriginalParentEntity buildParentEntity(BomOriginalPlmBomVO material ,String preVersion,OriginalSourceEnum originalSourceEnum) {
|
||||
|
||||
|
||||
BomNewOriginalParentEntity parentEntity = new BomNewOriginalParentEntity();
|
||||
|
|
@ -123,7 +123,7 @@ public abstract class BaseConvert {
|
|||
parentEntity.setEditStatus(OriginalEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
parentEntity.setDeptRowId(SessionUtil.getPartRowId());
|
||||
parentEntity.setDeptName(SessionUtil.getFullDeptName());
|
||||
parentEntity.setSource(OriginalSourceEnum.CAD_IMPORT.getValue());
|
||||
parentEntity.setSource(originalSourceEnum.getValue());
|
||||
parentEntity.setCreatedBy(material.getCreatedBy());
|
||||
parentEntity.setCreatedTime(LocalDateTime.now());
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalConstant;
|
||||
import com.nflg.product.bomnew.constant.OriginalSourceEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.MaterialMainMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.*;
|
||||
|
|
@ -45,16 +46,30 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(ImmutableList.of(parent));
|
||||
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(childs);
|
||||
//开始转原始BOM
|
||||
handlerBom();
|
||||
handlerBom(OriginalSourceEnum.CAD_IMPORT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void convertOriginalBomFromExcel(BomOriginalPlmBomVO inParent, List<BomOriginalPlmBomVO> inChilds) {
|
||||
childs = inChilds;
|
||||
parent=inParent;
|
||||
//初始化物料信息
|
||||
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(ImmutableList.of(parent));
|
||||
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(childs);
|
||||
//开始转原始BOM
|
||||
handlerBom(OriginalSourceEnum.MANUAL_IMPORT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理父类
|
||||
*/
|
||||
private void handlerBom() {
|
||||
private void handlerBom(OriginalSourceEnum originalSourceEnum) {
|
||||
|
||||
//检查BOM
|
||||
checkBom();
|
||||
|
|
@ -65,11 +80,11 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
BomNewOriginalParentEntity originalBom = getOriginalBomForMaterial(parent.getChartNo());
|
||||
//沒有原始BOM
|
||||
if (Objects.isNull(originalBom)) {
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent, "");
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent, "",originalSourceEnum);
|
||||
if (StrUtil.isNotBlank(parent.getMaterialCategoryCode()) && parent.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE) && CollUtil.isEmpty(childs)) {
|
||||
handlerCommonMaterial(parentEntity);
|
||||
} else {
|
||||
handlerChild(parentEntity);
|
||||
handlerChild(parentEntity,originalSourceEnum);
|
||||
}
|
||||
} else { //有原始BOM
|
||||
//草稿状态
|
||||
|
|
@ -79,7 +94,7 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
if (originalBom.getCreatedBy().equals(parent.getCreatedBy()) ) {
|
||||
// 删除旧的内容
|
||||
delBomChild(originalBom.getRowId());
|
||||
handlerChild(originalBom);
|
||||
handlerChild(originalBom,originalSourceEnum);
|
||||
} else { //用户不一致
|
||||
if (isSame(getBomChild(originalBom.getRowId()), Convert.toList(BomNewOriginalChildEntity.class, childs))) {
|
||||
VUtils.isTure(true).throwMessage("数据和" + originalBom.getCreatedBy() + "导入的数据不一致,请沟通处理");
|
||||
|
|
@ -102,10 +117,10 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
} else { //ebom为正式状态
|
||||
// BOM结构不相同
|
||||
if (!isSame(getBomChild(originalBom.getRowId()), Convert.toList(BomNewOriginalChildEntity.class, childs))) {
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent, originalBom.getCurrentVersion());
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent, originalBom.getCurrentVersion(),originalSourceEnum);
|
||||
originalBom.setLastVersionIs(0);
|
||||
this.resultParent.add(originalBom);
|
||||
handlerChild(parentEntity);
|
||||
handlerChild(parentEntity,originalSourceEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +131,7 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
{
|
||||
BomNewOriginalParentEntity oBOM =getOriginalBomForMaterial(parent.getChartNo());
|
||||
if(Objects.isNull(oBOM)){
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent,"");
|
||||
BomNewOriginalParentEntity parentEntity = buildParentEntity(parent,"",originalSourceEnum);
|
||||
|
||||
if (StrUtil.isNotBlank(parent.getMaterialCategoryCode()) && parent.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE) && CollUtil.isEmpty(childs)) {
|
||||
handlerCommonMaterial(parentEntity);
|
||||
|
|
@ -126,7 +141,7 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
|
||||
}
|
||||
|
||||
private void handlerChild(BomNewOriginalParentEntity parentEntity) {
|
||||
private void handlerChild(BomNewOriginalParentEntity parentEntity ,OriginalSourceEnum originalSourceEnum) {
|
||||
|
||||
for (BomOriginalPlmBomVO childVo : childs) {
|
||||
//一般零部件
|
||||
|
|
@ -136,7 +151,7 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
List<BomNewOriginalParentEntity> parentResultOne = this.resultParent.stream().filter(u -> u.getDrawingNo().equals(childVo.getChartNo())).collect(Collectors.toList());
|
||||
if (Objects.isNull(originalBomForMaterial) && CollUtil.isEmpty(parentResultOne) ) {
|
||||
childVo.setCreatedBy(parentEntity.getCreatedBy());
|
||||
BomNewOriginalParentEntity parentEntity1 = buildParentEntity(childVo, "");
|
||||
BomNewOriginalParentEntity parentEntity1 = buildParentEntity(childVo, "",originalSourceEnum);
|
||||
handlerCommonMaterial(parentEntity1);
|
||||
}
|
||||
buildChildEntity(childVo,parentEntity);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,167 @@
|
|||
package com.nflg.product.bomnew.util;
|
||||
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
import org.ttzero.excel.reader.ExcelReader;
|
||||
import org.ttzero.excel.reader.Row;
|
||||
import org.ttzero.excel.reader.Sheet;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* eecExcel
|
||||
*
|
||||
* @Author 大米
|
||||
* @Date 2022-03-23
|
||||
*/
|
||||
public class EecExcelUtil {
|
||||
|
||||
/**
|
||||
* 下载本地文件
|
||||
*
|
||||
* @param filePath 文件地址
|
||||
* @param response 输出流
|
||||
* @param fileName 文件名
|
||||
* @param format
|
||||
*/
|
||||
public static void downLocalFile(String filePath, HttpServletResponse response, String fileName, String format) throws IOException {
|
||||
response.setHeader("content-Type", "application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
System.out.println("开始下载文件");
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
ServletOutputStream ouputStream = response.getOutputStream();
|
||||
byte b[] = new byte[1024];
|
||||
int n;
|
||||
while ((n = inputStream.read(b)) != -1) {
|
||||
ouputStream.write(b, 0, n);
|
||||
}
|
||||
ouputStream.close();
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void setResponseExcelHeader(HttpServletResponse response, String fileName) throws UnsupportedEncodingException {
|
||||
response.setHeader("content-Type", "application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "utf-8"));
|
||||
|
||||
}
|
||||
|
||||
public static void eecExcel(String fileName, ListSheet sheet, HttpServletResponse response) throws IOException {
|
||||
setResponseExcelHeader(response, fileName);
|
||||
new Workbook().addSheet(sheet
|
||||
).writeTo(response.getOutputStream());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 行读取excel sheet 0
|
||||
*
|
||||
* @param hanlder
|
||||
* @param inputStream
|
||||
*/
|
||||
public static <T, U> void iteratorRead(BiConsumer<T, U> hanlder, InputStream inputStream, Class<T> cls, U u) {
|
||||
try (ExcelReader reader = ExcelReader.read(inputStream)) {
|
||||
Sheet sheet = reader.sheet(0);
|
||||
Iterator<Row> ite = sheet.iterator();
|
||||
while (ite.hasNext()) {
|
||||
hanlder.accept(ite.next().to(cls), u);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new NflgBusinessException(STATE.BusinessError, "读取EXCEL 失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取EXCEL 所有内容
|
||||
*
|
||||
* @param inputStream
|
||||
* @param clc
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <T> List<T> getExcelContext(InputStream inputStream, Class<T> clc) throws IOException {
|
||||
try {
|
||||
return ExcelReader.read(inputStream)
|
||||
.sheet(0)
|
||||
.dataRows() // 所有数据列,会过滤掉表头
|
||||
.map(row -> row.to(clc))// 列数据转Stock对象
|
||||
.collect(Collectors.toList());// 转为对象数组
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new NflgBusinessException(STATE.BusinessError, "读取EXCEL 失败,请检查模板是否正确:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 每行excel 做处理
|
||||
*
|
||||
* @param inputStream
|
||||
* @param clc
|
||||
* @param handler
|
||||
* @param <T>
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static <T extends BaseImportExcelDTO> List<T> handlerExcel(InputStream inputStream, Class<T> clc, Consumer<T> handler) {
|
||||
|
||||
try (ExcelReader reader = ExcelReader.read(inputStream)) {
|
||||
|
||||
reader.sheet(0).dataRows().map(row-> row.to(clc)
|
||||
// T t= row.too(clc);
|
||||
// t.setRowNum(row.getRowNum());
|
||||
// return t ;
|
||||
).forEach(u -> {
|
||||
if(handler!=null) {
|
||||
handler.accept(u);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, "excel 解析失败,请检查模板是否正确");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取sheet名称
|
||||
* @param inputStream
|
||||
* @return
|
||||
*/
|
||||
public static String getSheetName(InputStream inputStream){
|
||||
try (ExcelReader reader = ExcelReader.read(inputStream)) {
|
||||
return reader.sheet(0).getName();
|
||||
} catch (IOException e) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, "excel 解析失败,请检查模板是否正确");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除excel单元格中的空格,excel导入时的字符串空格ASCII值为160,而空格(space)的ASCII值是32
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String StringTrim(String str) {
|
||||
return str.replaceAll("[\\s\\u00A0]+", "").trim();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue