Showing
3 changed files
with
23 additions
and
1 deletions
... | ... | @@ -12,6 +12,8 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio |
12 | 12 | import org.thingsboard.server.common.data.yunteng.dto.TkPreserveDetailStatusDTO; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.enums.PreserveDetailStatusEnum; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; |
15 | +import org.thingsboard.server.dao.yunteng.entities.TenantBaseEntity; | |
16 | +import org.thingsboard.server.dao.yunteng.entities.TkPreserveDetailEntity; | |
15 | 17 | import org.thingsboard.server.dao.yunteng.entities.TkPreserveDetailStatusEntity; |
16 | 18 | import org.thingsboard.server.dao.yunteng.mapper.TkPreserveDetailStatusMapper; |
17 | 19 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
... | ... | @@ -44,6 +46,15 @@ public class TkPreserveDetailStatusServiceImpl extends AbstractBaseService<TkPre |
44 | 46 | } |
45 | 47 | |
46 | 48 | @Override |
49 | + public void deleteNotInIdEqRecordId(String recordId, List<String> notinIds) throws ThingsboardException { | |
50 | + baseMapper.delete(new QueryWrapper<TkPreserveDetailStatusEntity>() | |
51 | + .lambda().eq(TkPreserveDetailStatusEntity::getPreserveRecordId, recordId) | |
52 | + .eq(TenantBaseEntity::getTenantId, SpringBeanUtils.getTenantId().getId().toString()) | |
53 | + .notIn(TkPreserveDetailStatusEntity::getId, notinIds) | |
54 | + ); | |
55 | + } | |
56 | + | |
57 | + @Override | |
47 | 58 | public List<TkPreserveDetailStatusDTO> listByPreserveRecordId(List<String> preserveRecordId) throws ThingsboardException { |
48 | 59 | if (CollectionUtils.isEmpty(preserveRecordId)) { |
49 | 60 | throw new TkDataValidationException("保养记录id不能为空!"); | ... | ... |
... | ... | @@ -88,11 +88,12 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR |
88 | 88 | @Transactional |
89 | 89 | public TkPreserveRecordDTO save(TkPreserveRecordDTO dto) throws ThingsboardException { |
90 | 90 | checkDto(dto); |
91 | - | |
91 | + Boolean isAdd = false; | |
92 | 92 | TkPreserveRecordEntity entity = new TkPreserveRecordEntity(); |
93 | 93 | if (StringUtils.isBlank(dto.getId())) { |
94 | 94 | dto.copyToEntity(entity); |
95 | 95 | baseMapper.insert(entity); |
96 | + isAdd = true; | |
96 | 97 | } else { |
97 | 98 | LambdaQueryWrapper<TkPreserveRecordEntity> filter = new QueryWrapper<TkPreserveRecordEntity>().lambda() |
98 | 99 | .eq(TkPreserveRecordEntity::getId, dto.getId()); |
... | ... | @@ -103,6 +104,14 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR |
103 | 104 | String id = dto.getId(); |
104 | 105 | List<TkPreserveDetailStatusDTO> preserveDetailStatusList = dto.getPreserveDetailStatusList(); |
105 | 106 | if (CollectionUtils.isNotEmpty(preserveDetailStatusList)) { |
107 | + List<String> detaulStatusIdList = preserveDetailStatusList.stream().filter(e -> StringUtils.isNotBlank(e.getId())) | |
108 | + .map(BaseDTO::getId).collect(Collectors.toList()); | |
109 | + if (isAdd == false) { | |
110 | + if (CollectionUtils.isEmpty(detaulStatusIdList)) { | |
111 | + detaulStatusIdList.add("empty"); | |
112 | + } | |
113 | + tkPreserveDetailStatusService.deleteNotInIdEqRecordId(id, detaulStatusIdList); | |
114 | + } | |
106 | 115 | for (TkPreserveDetailStatusDTO tkPreserveDetailStatusDTO : preserveDetailStatusList) { |
107 | 116 | tkPreserveDetailStatusDTO.setPreserveRecordId(id); |
108 | 117 | tkPreserveDetailStatusService.save(tkPreserveDetailStatusDTO); | ... | ... |
... | ... | @@ -9,5 +9,7 @@ import java.util.List; |
9 | 9 | public interface TkPreserveDetailStatusService extends BaseService<TkPreserveDetailStatusEntity> { |
10 | 10 | TkPreserveDetailStatusDTO save(TkPreserveDetailStatusDTO dto) throws ThingsboardException; |
11 | 11 | |
12 | + void deleteNotInIdEqRecordId(String recordId, List<String> notinIds) throws ThingsboardException; | |
13 | + | |
12 | 14 | List<TkPreserveDetailStatusDTO> listByPreserveRecordId(List<String> preserveRecordId) throws ThingsboardException; |
13 | 15 | } | ... | ... |