mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat(warehouse): update copy method to return boolean and handle multiple IDs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user