feat(warehouse): update copy method to return boolean and handle multiple IDs

This commit is contained in:
2025-03-11 21:04:00 +08:00
parent 6e05dd8201
commit 0330b89869
2 changed files with 35 additions and 34 deletions

View File

@@ -55,8 +55,10 @@ public class WarehouseController {
@PostMapping("/copy")
public WarehouseDto copy(@RequestBody IdRequest request) {
return this.service.copy(request);
public Boolean copy(@RequestBody IdRequest request) {
this.service.copy(request);
return true;
}

View File

@@ -57,7 +57,6 @@ public class WarehouseService extends BaseService<WarehouseEntity, WarehouseRepo
shelveDto.setCode("default");
shelveDto.setRemarks("默认货架");
warehouseShelveService.create(shelveDto);
return getById(entity.getId());
@@ -99,49 +98,49 @@ public class WarehouseService extends BaseService<WarehouseEntity, WarehouseRepo
return page.map(this.mapper::toDto);
}
@Autowired
WarehouseShelveRepository warehouseShelveRepository;
@Autowired WarehouseShelveRepository warehouseShelveRepository;
public WarehouseDto copy(IdRequest request) {
public void copy(IdRequest request) {
for (String id : request.getIds()) {
WarehouseEntity entity = this.get(request.getId());
WarehouseEntity entity = this.get(id);
WarehouseEntity copy = new WarehouseEntity();
WarehouseEntity copy = new WarehouseEntity();
BeanUtil.copyProperties(entity, copy);
BeanUtil.copyProperties(entity, copy);
copy.setId(null);
copy.setCode(copy.getCode() + "_副本");
copy.setId(null);
copy.setName(copy.getName() + "_暂存");
copy.setCode(copy.getCode() + "_暂存");
this.repository.save(copy);
this.repository.save(copy);
List<WarehouseShelveEntity> all =
warehouseShelveRepository.findAll(
new Specification<WarehouseShelveEntity>() {
@Override
public Predicate toPredicate(
Root<WarehouseShelveEntity> root,
CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
List<WarehouseShelveEntity> all = warehouseShelveRepository.findAll(new Specification<WarehouseShelveEntity>() {
@Override
public Predicate toPredicate(Root<WarehouseShelveEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get("warehouse").get("id"), request.getId())
);
return criteriaBuilder.and(
criteriaBuilder.equal(
root.get("warehouse").get("id"),
id));
}
});
for (WarehouseShelveEntity shelveEntity : all) {
WarehouseShelveEntity copyShelve = new WarehouseShelveEntity();
BeanUtil.copyProperties(shelveEntity, copyShelve);
copyShelve.setId(null);
copyShelve.setWarehouse(copy);
warehouseShelveRepository.save(copyShelve);
}
});
for (WarehouseShelveEntity shelveEntity : all) {
WarehouseShelveEntity copyShelve = new WarehouseShelveEntity();
BeanUtil.copyProperties(shelveEntity, copyShelve);
copyShelve.setId(null);
copyShelve.setWarehouse(copy);
warehouseShelveRepository.save(copyShelve);
}
return this.getById(copy.getId());
}
}