修改物资设备清单相关修改

This commit is contained in:
2025-09-24 14:36:04 +08:00
parent a177ab3067
commit faff11ad6f
7 changed files with 95 additions and 50 deletions

View File

@ -141,8 +141,8 @@ public class BusMrpBaseController extends BaseController {
* 获取剩余量
*/
@GetMapping("/remaining")
public R<Map<String,Object>> remaining(Long suppliespriceId,Long mrpBaseId) {
return R.ok(busMrpBaseService.remaining(suppliespriceId,mrpBaseId));
public R<Map<String,Object>> remaining(Long projectId, String suppliespriceName,String specification,Long mrpBaseId) {
return R.ok(busMrpBaseService.remaining(projectId,suppliespriceName,specification,mrpBaseId));
}
@ -209,7 +209,19 @@ public class BusMrpBaseController extends BaseController {
// // 3. 递归组装树形结构从顶级节点pid=0开始
// List<ObtainTheListRes> treeList = buildTree("0", parentMap);
// return R.ok(treeList);
return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>().eq(BusBillofquantities::getPid, req.getSid())));
List<BusBillofquantities> busBillofquantities = busBillofquantitiesService.getBaseMapper()
.selectList(new LambdaQueryWrapper<BusBillofquantities>()
.eq(BusBillofquantities::getProjectId, req.getProjectId())
.eq(BusBillofquantities::getName, req.getSid()));
List<String> sids = new ArrayList<>();
busBillofquantities.forEach(busBillofquantities1 -> {
sids.add(busBillofquantities1.getSid());
});
return R.ok(busBillofquantitiesService
.getBaseMapper()
.selectList(new LambdaQueryWrapper<BusBillofquantities>()
.eq(BusBillofquantities::getProjectId, req.getProjectId())
.in(BusBillofquantities::getPid, sids)));
}
private List<ObtainTheListRes> buildTree(String parentId, Map<String, List<ObtainTheListRes>> parentMap) {

View File

@ -86,5 +86,5 @@ public interface IBusMrpBaseService extends IService<BusMrpBase>{
/**
* 获取物资已有数量
*/
Map<String, Object> remaining(Long suppliespriceId, Long mrpBaseId);
Map<String, Object> remaining(Long projectId, String suppliespriceName, String specification, Long mrpBaseId);
}

View File

@ -75,7 +75,7 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
planBo.setMrpBaseId(id);
List<BusMaterialbatchdemandplanVo> voList = planservice.queryList(planBo);
for (BusMaterialbatchdemandplanVo vo : voList) {
Map<String, Object> map = remaining(vo.getSuppliespriceId(), id);
Map<String, Object> map = remaining(vo.getProjectId(),vo.getName(), vo.getSpecification(), id);
vo.setRemaining(Convert.toBigDecimal(map.get("remainingQuantity")));
}
busMrpVo.setMrpBaseBo(busMrpBaseVo);
@ -190,25 +190,34 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
if (CollectionUtil.isNotEmpty(dto.getPlanList())) {
// 按 suppliespriceId 分组统计本次提交的数量
Map<Long, BigDecimal> batchSumMap = dto.getPlanList().stream()
Map<String, BigDecimal> batchSumMap = dto.getPlanList().stream()
.collect(Collectors.groupingBy(
BusMaterialbatchdemandplanBo::getSuppliespriceId,
// 关键修改:使用 name + specification 拼接作为分组键
item -> {
String name = item.getName() != null ? item.getName() : "";
String spec = item.getSpecification() != null ? item.getSpecification() : "";
return name + "&&&" + spec;
},
Collectors.reducing(
BigDecimal.ZERO,
BusMaterialbatchdemandplanBo::getDemandQuantity,
item -> {
BigDecimal quantity = item.getDemandQuantity();
return quantity != null ? quantity : BigDecimal.ZERO;
},
BigDecimal::add
)
));
// 检查每种物料是否超出数量限制
for (Map.Entry<Long, BigDecimal> entry : batchSumMap.entrySet()) {
Long suppliespriceId = entry.getKey();
for (Map.Entry<String, BigDecimal> entry : batchSumMap.entrySet()) {
String biaoshi = entry.getKey();
BigDecimal batchSum = entry.getValue();
String[] split = biaoshi.split("&&&");
// 获取数据库中已有的数量
List<BusMaterialbatchdemandplan> existingList = planservice.list(
Wrappers.lambdaQuery(BusMaterialbatchdemandplan.class)
.eq(BusMaterialbatchdemandplan::getSuppliespriceId, suppliespriceId)
.eq(BusMaterialbatchdemandplan::getName, split[0])
.eq(BusMaterialbatchdemandplan::getSpecification,split[1])
.ne(BusMaterialbatchdemandplan::getMrpBaseId, convert.getId()) // 排除当前批次
);
@ -217,13 +226,29 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 检查总数量是否超出限制
BusBillofquantities billofquantities = busBillofquantitiesService.getById(suppliespriceId);
if (existingSum.add(batchSum).compareTo(billofquantities.getQuantity()) > 0) {
List<BusBillofquantities> busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>()
.eq(BusBillofquantities::getProjectId, dto.getMrpBaseBo().getProjectId())
.eq(BusBillofquantities::getName, split[0])
.eq(BusBillofquantities::getSpecification, split[1]));
BigDecimal quantity = busBillofquantities.stream()
.map(BusBillofquantities::getQuantity)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
if (existingSum.add(batchSum).compareTo(quantity) > 0) {
// 找到超出限制的物料名称用于提示
String itemName = dto.getPlanList().stream()
.filter(plan -> plan.getSuppliespriceId().equals(suppliespriceId))
.filter(item -> {
String name = item.getName() != null ? item.getName() : "";
String spec = item.getSpecification() != null ? item.getSpecification() : "";
return (name + "&&&" + spec).equals(biaoshi);
})
.findFirst()
.map(BusMaterialbatchdemandplanBo::getName)
.map(item -> {
String name = item.getName() != null ? item.getName() : "";
String spec = item.getSpecification() != null ? item.getSpecification() : "";
return "名称:“"+name + "”,规格:“" + spec+"";
})
.orElse("未知物料");
throw new ServiceException(itemName + "超出数量");
}
@ -272,13 +297,23 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
@Override
public Map<String, Object> remaining(Long suppliespriceId, Long mrpBaseId) {
public Map<String, Object> remaining(Long projectId, String suppliespriceName, String specification, Long mrpBaseId) {
Map<String, Object> map = new HashMap<>();
BusBillofquantities byId = busBillofquantitiesService.getById(suppliespriceId);
List<BusBillofquantities> busBillofquantities = busBillofquantitiesService.getBaseMapper()
.selectList(new LambdaQueryWrapper<BusBillofquantities>()
.eq(BusBillofquantities::getProjectId, projectId)
.eq(BusBillofquantities::getName, suppliespriceName)
.eq(BusBillofquantities::getSpecification,specification));
BigDecimal quantity = busBillofquantities.stream()
.map(BusBillofquantities::getQuantity)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// BusBillofquantities byId = busBillofquantitiesService.getById(suppliespriceId);
// 获取数据库中已有的数量
List<BusMaterialbatchdemandplan> existingList = planservice.list(
Wrappers.lambdaQuery(BusMaterialbatchdemandplan.class)
.eq(BusMaterialbatchdemandplan::getSuppliespriceId, suppliespriceId)
.eq(BusMaterialbatchdemandplan::getName, suppliespriceName)
.eq(BusMaterialbatchdemandplan::getSpecification ,specification)
.ne(mrpBaseId!=null,BusMaterialbatchdemandplan::getMrpBaseId, mrpBaseId)// 排除当前批次
);
BigDecimal reduce = BigDecimal.ZERO;
@ -287,11 +322,11 @@ public class BusMrpBaseServiceImpl extends ServiceImpl<BusMrpBaseMapper, BusMrpB
.map(BusMaterialbatchdemandplan::getDemandQuantity)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
map.put("remainingQuantity",byId.getQuantity().subtract(reduce));
map.put("specification",byId.getSpecification());
map.put("unit",byId.getUnit());
map.put("remark",byId.getRemark());
map.put("name",byId.getName());
map.put("remainingQuantity",quantity.subtract(reduce));
map.put("specification",busBillofquantities.getFirst().getSpecification());
map.put("unit",busBillofquantities.getFirst().getUnit());
map.put("remark",busBillofquantities.getFirst().getRemark());
map.put("name",busBillofquantities.getFirst().getName());
return map;
}

View File

@ -42,4 +42,6 @@ public class CoryObtainTheListReq implements Serializable {
private String sid;
private String name;
}

View File

@ -211,7 +211,8 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
// if (!Objects.equals(bo.getWorkOrderType(), "3")) {
// 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid
List<BusBillofquantities> allMaterials = new ArrayList<>();
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
if (Objects.equals(bo.getWorkOrderType(), "3")){
ExcelReader.SheetData sheetData = excelData.getSheetDataList().getFirst();
String sheetName = sheetData.getSheetName();
List<List<String>> rowDataList = sheetData.getData();
// 构建当前Sheet的树形结构复用ExcelReader的buildTree方法
@ -220,30 +221,21 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
// 递归遍历树形结构生成sid和pid
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
}else {
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
String sheetName = sheetData.getSheetName();
List<List<String>> rowDataList = sheetData.getData();
// 构建当前Sheet的树形结构复用ExcelReader的buildTree方法
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
// 存储节点映射TreeNode → ExcelMaterial用于子节点关联父节点
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
// 递归遍历树形结构生成sid和pid
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
}
}
// 3. 批量插入数据库
if (Objects.equals(bo.getWorkOrderType(), "3")){
List<BusBillofquantities> busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>().eq(BusBillofquantities::getProjectId, bo.getProjectId()));
Set<String> names = busBillofquantities.stream()
.filter(Objects::nonNull)
.map(obj->{
String name = Optional.ofNullable (obj.getName ()).orElse ("");
String specification = Optional.ofNullable (obj.getSpecification ()).orElse ("");
String remark = Optional.ofNullable (obj.getRemark ()).orElse ("");
return name+"+"+specification+"+"+remark;
})
.collect(Collectors.toSet());
for (BusBillofquantities allMaterial : allMaterials) {
String biaoqian = allMaterial.getName()+"+"+allMaterial.getSpecification()+"+"+allMaterial.getRemark();
if (names.contains(biaoqian)) {
throw new ServiceException("名称:“"+allMaterial.getName()+"+”规格:”"+allMaterial.getSpecification()+"“+”备注:“"+allMaterial.getRemark()+"已存在,请修改后重新上传!");
}
allMaterial.setProjectId(bo.getProjectId());
}
}else {
for (BusBillofquantities allMaterial : allMaterials) {
allMaterial.setProjectId(bo.getProjectId());
}
for (BusBillofquantities allMaterial : allMaterials) {
allMaterial.setProjectId(bo.getProjectId());
}
boolean b = busBillofquantitiesService.saveBatch(allMaterials);
if (!b) {

View File

@ -468,5 +468,9 @@ public class DesUserServiceImpl extends ServiceImpl<DesUserMapper, DesUser> impl
DataValidationConstraint constraint = helper.createFormulaListConstraint(personRange);
// 作用范围第2行到100行第四列
CellRangeAddressList addressList = new CellRangeAddressList(1, 100, rowCount, rowCount);
DataValidation validation = helper.createValidation(constraint, addressList);
validation.setShowErrorBox(true);
mainSheet.addValidationData(validation);
}
}

View File

@ -203,9 +203,9 @@ public class BusBillofquantitiesLimitListServiceImpl extends ServiceImpl<BusBill
.forEach(item -> {
item.setPrice(item.getUnitPrice().multiply(item.getQuantity()).setScale(4, RoundingMode.HALF_UP));
});
if (bo.getType().equals(LimitListTypeEnum.SPECIAL.getCode())) {
return listVoList;
}
// if (bo.getType().equals(LimitListTypeEnum.SPECIAL.getCode())) {
// return listVoList;
// }
//构建父子映射
Map<String, List<BusBillofquantitiesLimitListVo>> parentMap = listVoList.stream()