批量替代BOM
This commit is contained in:
parent
7f15b9b35a
commit
6db6bc3bef
|
|
@ -14,15 +14,19 @@ import com.nflg.product.bomnew.service.BatchBomService;
|
|||
import com.nflg.product.bomnew.service.BomNewEbomExportToSAP;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.service.MaterialMainService;
|
||||
import com.nflg.product.bomnew.util.EecExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -91,4 +95,11 @@ public class BatchBomApi extends BaseApi {
|
|||
}
|
||||
return ResultVO.success();
|
||||
}
|
||||
|
||||
@PostMapping("exportExcel")
|
||||
@ApiOperation("数据导出")
|
||||
public void exportExcel(@RequestBody BatchBomQuery query, HttpServletResponse response) throws IOException {
|
||||
EecExcelUtil.setResponseExcelHeader(response, "批量替代" + query.getMaterialNo() + "_" + new Date().getTime());
|
||||
batchBomService.getExportExcelWork(query).writeTo(response.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,4 +53,10 @@ public class BatchBomQuery implements Serializable {
|
|||
|
||||
@ApiModelProperty("统计结束时间")
|
||||
private String endDate;
|
||||
|
||||
@ApiModelProperty(value = "设置每页显示条数")
|
||||
private Long pageSize = 20L;
|
||||
|
||||
@ApiModelProperty(value = "当前页")
|
||||
private Long page = 1L;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.DateTypeEnum;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomParentMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomChildMapper;
|
||||
|
|
@ -33,6 +32,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import nflg.product.common.constant.STATE;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.ttzero.excel.entity.Column;
|
||||
import org.ttzero.excel.entity.ListMapSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -65,6 +67,8 @@ public class BatchBomService {
|
|||
private BomNewPbomChildMapper bomNewPbomChildMapper;
|
||||
@Resource
|
||||
private MaterialMainService materialMainService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
public BomPageVO<Map<String, Object>, BomTbHeaderVO> getParentBomList(BatchBomQuery batchBomQuery) {
|
||||
if (!(batchBomQuery.getMaterialUnit().equals(batchBomQuery.getNewMaterialUnit()))
|
||||
|
|
@ -214,7 +218,7 @@ public class BatchBomService {
|
|||
List<Map<String, Object>> records = new ArrayList<>(resultList.size());
|
||||
resultList.forEach(result -> records.add(BeanUtil.beanToMap(result)));
|
||||
pageVO.setRecords(records);
|
||||
pageVO.setPages(records.size());
|
||||
pageVO.setPages(1L);
|
||||
pageVO.setCurrent(1L);
|
||||
pageVO.setPageSize(Long.MAX_VALUE);
|
||||
pageVO.setTotal(records.size());
|
||||
|
|
@ -293,11 +297,12 @@ public class BatchBomService {
|
|||
BaseMaterialVO newMaterialInfo= materialBaseInfo.get(0);
|
||||
List<Long> addRowIds = new ArrayList<>(baseBomVOList.size()); // 需要加入历史表的父级BOM ID
|
||||
List<Long> delRowIds = new ArrayList<>(baseBomVOList.size()); // 需要从正式表删除的父级BOM ID
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
int createdJob = userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue();
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
// 找到父级
|
||||
BomNewEbomParentEntity ebomParentEntity = bomNewEbomParentService.lambdaQuery().eq(BomNewEbomParentEntity::getRowId, baseBomVO.getParentRowId()).one();
|
||||
if (ObjectUtil.isNotEmpty(ebomParentEntity)) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 找到该父级的所有子级列表
|
||||
List<BomNewEbomChildEntity> ebomChildEntities = bomNewEbomChildService.lambdaQuery().eq(BomNewEbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
// 在子级列表中找到要被替换的那条子级
|
||||
|
|
@ -315,6 +320,12 @@ public class BatchBomService {
|
|||
newParent.setModifyTime(now);
|
||||
newParent.setSapState(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
newParent.setSapTime(null);
|
||||
newParent.setDeptRowId(SessionUtil.getDepartRowId());
|
||||
newParent.setDeptName(SessionUtil.getDepartName());
|
||||
newParent.setDeviseName(SessionUtil.getRealName());
|
||||
newParent.setDeviseUserCode(SessionUtil.getUserCode());
|
||||
newParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
newParent.setCreatedJob(createdJob);
|
||||
// 构建新版的子级规则:其他子级复制一份,被替换的子级改物料编码,数量,单位等
|
||||
List<BomNewEbomChildEntity> newChildList = new ArrayList<>(ebomChildEntities.size());
|
||||
otherChildren.forEach(item -> {
|
||||
|
|
@ -326,6 +337,7 @@ public class BatchBomService {
|
|||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newChild.setCreatedTime(now);
|
||||
newChild.setModifyTime(now);
|
||||
newChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newChildList.add(newChild);
|
||||
});
|
||||
BomNewEbomChildEntity newReplaceChild = new BomNewEbomChildEntity();
|
||||
|
|
@ -345,6 +357,7 @@ public class BatchBomService {
|
|||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
newChildList.add(newReplaceChild);
|
||||
bomNewEbomParentService.save(newParent);
|
||||
|
|
@ -370,7 +383,7 @@ public class BatchBomService {
|
|||
.one();
|
||||
if (ObjectUtil.isNotEmpty(draftParent)) {
|
||||
// 草稿版本 A01 -> A02,A01.1 -> A02.1
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split(".");
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split("\\.");
|
||||
String newVersion = VersionUtil.getNextVersion(currentVersionArr[0]);
|
||||
if (currentVersionArr.length > 1) {
|
||||
newVersion += "." + currentVersionArr[1];
|
||||
|
|
@ -378,6 +391,32 @@ public class BatchBomService {
|
|||
draftParent.setCurrentVersion(newVersion);
|
||||
draftParent.setModifyTime(LocalDateTime.now());
|
||||
bomNewEbomParentService.updateById(draftParent);
|
||||
// 子级有原物料号,也要替代成新物料号
|
||||
List<BomNewEbomChildEntity> draftChildren = bomNewEbomChildService.lambdaQuery().eq(BomNewEbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
if (CollectionUtil.isNotEmpty(draftChildren)) {
|
||||
List<BomNewEbomChildEntity> replaceChildren = draftChildren.stream().filter(child -> baseBomVO.getMaterialNo().equals(child.getMaterialNo())).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(replaceChildren)) {
|
||||
for (BomNewEbomChildEntity newReplaceChild: replaceChildren) {
|
||||
newReplaceChild.setRowId(IdWorker.getId());
|
||||
newReplaceChild.setIdentityNo(draftParent.getRowId() + "_" + newReplaceChild.getRowId());
|
||||
newReplaceChild.setMaterialNo(baseBomVO.getNewMaterialNo()); // 新物料编码
|
||||
newReplaceChild.setDrawingNo(newMaterialInfo.getDrawingNo());
|
||||
newReplaceChild.setMaterialName(newMaterialInfo.getMaterialName());
|
||||
newReplaceChild.setMaterialDesc(newMaterialInfo.getMaterialDesc()); // 新物料描述
|
||||
newReplaceChild.setMaterialTexture(newMaterialInfo.getMaterialTexture());
|
||||
newReplaceChild.setMaterialUnit(baseBomVO.getNewUnit()); // 新单位
|
||||
newReplaceChild.setNum(baseBomVO.getNewNum()); // 新数量
|
||||
newReplaceChild.setMaterialCategoryCode(newMaterialInfo.getMaterialCategoryCode());
|
||||
// TODO 新单重?新总重?要不要更新
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
}
|
||||
bomNewEbomChildService.updateBatchById(replaceChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return addRowIds;
|
||||
|
|
@ -399,11 +438,12 @@ public class BatchBomService {
|
|||
BaseMaterialVO newMaterialInfo= materialBaseInfo.get(0);
|
||||
List<Long> addRowIds = new ArrayList<>(baseBomVOList.size()); // 需要加入历史表的父级BOM ID
|
||||
List<Long> delRowIds = new ArrayList<>(baseBomVOList.size()); // 需要从正式表删除的父级BOM ID
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
int createdJob = userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue();
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
// 找到父级
|
||||
BomNewPbomParentEntity pbomParentEntity = bomNewPbomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getRowId, baseBomVO.getParentRowId()).one();
|
||||
if (ObjectUtil.isNotEmpty(pbomParentEntity)) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 找到该父级的所有子级列表
|
||||
List<BomNewPbomChildEntity> pbomChildEntities = bomNewPbomChildService.lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
// 在子级列表中找到要被替换的那条子级
|
||||
|
|
@ -421,6 +461,12 @@ public class BatchBomService {
|
|||
newParent.setModifyTime(now);
|
||||
newParent.setSapState(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
newParent.setSapTime(null);
|
||||
newParent.setDeptRowId(SessionUtil.getDepartRowId());
|
||||
newParent.setDeptName(SessionUtil.getDepartName());
|
||||
newParent.setDeviseName(SessionUtil.getRealName());
|
||||
newParent.setDeviseUserCode(SessionUtil.getUserCode());
|
||||
newParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
newParent.setCreatedJob(createdJob);
|
||||
// 构建新版的子级规则:其他子级复制一份,被替换的子级改物料编码,数量,单位等
|
||||
List<BomNewPbomChildEntity> newChildList = new ArrayList<>(pbomChildEntities.size());
|
||||
otherChildren.forEach(item -> {
|
||||
|
|
@ -432,6 +478,7 @@ public class BatchBomService {
|
|||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newChild.setCreatedTime(now);
|
||||
newChild.setModifyTime(now);
|
||||
newChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newChildList.add(newChild);
|
||||
});
|
||||
BomNewPbomChildEntity newReplaceChild = new BomNewPbomChildEntity();
|
||||
|
|
@ -451,6 +498,7 @@ public class BatchBomService {
|
|||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
newChildList.add(newReplaceChild);
|
||||
bomNewPbomParentService.save(newParent);
|
||||
|
|
@ -476,7 +524,7 @@ public class BatchBomService {
|
|||
.one();
|
||||
if (ObjectUtil.isNotEmpty(draftParent)) {
|
||||
// 草稿版本 A01 -> A02,A01.1 -> A02.1
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split(".");
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split("\\.");
|
||||
String newVersion = VersionUtil.getNextVersion(currentVersionArr[0]);
|
||||
if (currentVersionArr.length > 1) {
|
||||
newVersion += "." + currentVersionArr[1];
|
||||
|
|
@ -484,8 +532,60 @@ public class BatchBomService {
|
|||
draftParent.setCurrentVersion(newVersion);
|
||||
draftParent.setModifyTime(LocalDateTime.now());
|
||||
bomNewPbomParentService.updateById(draftParent);
|
||||
// 子级有原物料号,也要替代成新物料号
|
||||
List<BomNewPbomChildEntity> draftChildren = bomNewPbomChildService.lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
if (CollectionUtil.isNotEmpty(draftChildren)) {
|
||||
List<BomNewPbomChildEntity> replaceChildren = draftChildren.stream().filter(child -> baseBomVO.getMaterialNo().equals(child.getMaterialNo())).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(replaceChildren)) {
|
||||
for (BomNewPbomChildEntity newReplaceChild: replaceChildren) {
|
||||
newReplaceChild.setRowId(IdWorker.getId());
|
||||
newReplaceChild.setIdentityNo(draftParent.getRowId() + "_" + newReplaceChild.getRowId());
|
||||
newReplaceChild.setMaterialNo(baseBomVO.getNewMaterialNo()); // 新物料编码
|
||||
newReplaceChild.setDrawingNo(newMaterialInfo.getDrawingNo());
|
||||
newReplaceChild.setMaterialName(newMaterialInfo.getMaterialName());
|
||||
newReplaceChild.setMaterialDesc(newMaterialInfo.getMaterialDesc()); // 新物料描述
|
||||
newReplaceChild.setMaterialTexture(newMaterialInfo.getMaterialTexture());
|
||||
newReplaceChild.setMaterialUnit(baseBomVO.getNewUnit()); // 新单位
|
||||
newReplaceChild.setNum(baseBomVO.getNewNum()); // 新数量
|
||||
newReplaceChild.setMaterialCategoryCode(newMaterialInfo.getMaterialCategoryCode());
|
||||
// TODO 新单重?新总重?要不要更新
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setCreatedBy(SessionUtil.getUserCode());
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
}
|
||||
bomNewPbomChildService.updateBatchById(replaceChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return addRowIds;
|
||||
}
|
||||
|
||||
public Workbook getExportExcelWork(BatchBomQuery query) {
|
||||
BomPageVO list = this.getParentBomList(query);
|
||||
long pages = list.getPages();
|
||||
List<BaseBomVO> voList = list.getRecords();
|
||||
Integer pageCount = Math.toIntExact(pages + 1);
|
||||
return new Workbook().addSheet(new ListMapSheet("bom", getExcelColumns(getTbHeaders())) {
|
||||
Long n = 1L;
|
||||
|
||||
@Override
|
||||
protected List<Map<String, ?>> more() {
|
||||
query.setPage(n);
|
||||
return n++ < pageCount ? Convert.convert(new TypeReference<List<Map<String, ?>>>() {
|
||||
}, voList) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Column[] getExcelColumns(List<BomTbHeaderVO> headers) {
|
||||
Column[] excelColumns = new Column[headers.size()];
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
BomTbHeaderVO h = headers.get(i);
|
||||
excelColumns[i] = new Column(h.getDisplayHeaderName(), h.getValueHeaderName(), String.class);
|
||||
}
|
||||
return excelColumns;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue