mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-07-26 15:38:57 +08:00
feat(InventoryCheckDetail): update details field type and enhance entity management
This commit is contained in:
@@ -2,7 +2,6 @@ package cn.lihongjie.coal.inventoryCheck.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.dto.CreateInventoryCheckDetailDto;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -175,6 +174,6 @@ public class InventoryCheckDetailDto extends OrgCommonDto {
|
||||
@Comment("其他偏差")
|
||||
private Double pc5;
|
||||
|
||||
private java.util.List<CreateInventoryCheckDetailDto> details;
|
||||
private java.util.List<cn.lihongjie.coal.inventoryCheckDetail.dto.InventoryCheckDetailDto> details;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import cn.lihongjie.coal.inventoryCheckDetail.mapper.InventoryCheckDetailMapper;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.repository.InventoryCheckDetailRepository;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.service.InventoryCheckDetailService;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -58,34 +60,7 @@ public class InventoryCheckService
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
private void saveDetails(
|
||||
InventoryCheckEntity entity, List<CreateInventoryCheckDetailDto> details) {
|
||||
|
||||
this.inventoryCheckDetailRepository.delete(
|
||||
(Specification<InventoryCheckDetailEntity>)
|
||||
(root, query, criteriaBuilder) ->
|
||||
criteriaBuilder.equal(
|
||||
root.get("inventoryCheck").get("id"), entity.getId()));
|
||||
|
||||
List<InventoryCheckDetailEntity> list =
|
||||
details.stream()
|
||||
.map(
|
||||
x -> {
|
||||
return inventoryCheckDetailMapper.toEntity(x);
|
||||
})
|
||||
.toList();
|
||||
|
||||
list.forEach(
|
||||
x -> {
|
||||
x.setCheckTime(entity.getCheckTime());
|
||||
x.setInventoryCheck(entity);
|
||||
});
|
||||
|
||||
inventoryCheckDetailRepository.saveAll(list);
|
||||
|
||||
// 计算并更新统计信息
|
||||
calculateAndUpdateStatistics(entity);
|
||||
}
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
private void calculateAndUpdateStatistics(InventoryCheckEntity entity) {
|
||||
// 获取所有明细
|
||||
@@ -236,6 +211,40 @@ public class InventoryCheckService
|
||||
inventoryCheckDetailService.deleteByInventoryCheckId(request.getIds());
|
||||
}
|
||||
|
||||
private void saveDetails(
|
||||
InventoryCheckEntity entity, List<CreateInventoryCheckDetailDto> details) {
|
||||
|
||||
this.inventoryCheckDetailRepository.delete(
|
||||
(Specification<InventoryCheckDetailEntity>)
|
||||
(root, query, criteriaBuilder) ->
|
||||
criteriaBuilder.equal(
|
||||
root.get("inventoryCheck").get("id"), entity.getId()));
|
||||
|
||||
List<InventoryCheckDetailEntity> list =
|
||||
details.stream()
|
||||
.map(
|
||||
x -> {
|
||||
return inventoryCheckDetailMapper.toEntity(x);
|
||||
})
|
||||
.toList();
|
||||
|
||||
list.forEach(
|
||||
x -> {
|
||||
x.setCheckTime(entity.getCheckTime());
|
||||
x.setInventoryCheck(entity);
|
||||
});
|
||||
|
||||
inventoryCheckDetailRepository.saveAll(list);
|
||||
|
||||
em.flush();
|
||||
|
||||
em.clear();
|
||||
|
||||
|
||||
// 计算并更新统计信息
|
||||
calculateAndUpdateStatistics(entity);
|
||||
}
|
||||
|
||||
public cn.lihongjie.coal.inventoryCheck.dto.InventoryCheckDetailDto getById(String id) {
|
||||
InventoryCheckEntity entity = repository.get(id);
|
||||
|
||||
@@ -248,11 +257,17 @@ public class InventoryCheckService
|
||||
criteriaBuilder.equal(
|
||||
root.get("inventoryCheck").get("id"), id));
|
||||
|
||||
// refresh detail from database
|
||||
|
||||
|
||||
// details.forEach(em::refresh);
|
||||
|
||||
|
||||
cn.lihongjie.coal.inventoryCheck.dto.InventoryCheckDetailDto detailDto =
|
||||
mapper.toDetailDto(entity);
|
||||
|
||||
|
||||
detailDto.setDetails(details.stream().map(inventoryCheckDetailMapper::toCreate).toList());
|
||||
detailDto.setDetails(details.stream().map(inventoryCheckDetailMapper::toDto).toList());
|
||||
|
||||
return detailDto;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user