Showing
1 changed file
with
55 additions
and
63 deletions
1 | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
4 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
5 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
6 | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
7 | 6 | import lombok.RequiredArgsConstructor; |
8 | 7 | import lombok.extern.slf4j.Slf4j; |
9 | -import org.jetbrains.annotations.Nullable; | |
10 | 8 | import org.springframework.stereotype.Service; |
11 | 9 | import org.springframework.transaction.annotation.Transactional; |
12 | 10 | import org.thingsboard.server.common.data.StringUtils; |
13 | -import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
14 | -import org.thingsboard.server.common.data.yunteng.core.exception.NoneTenantAssetException; | |
15 | 11 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
16 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
17 | -import org.thingsboard.server.common.data.yunteng.dto.*; | |
18 | -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
19 | -import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.YtVideoDTO; | |
20 | 15 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
21 | -import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; | |
22 | 16 | import org.thingsboard.server.dao.yunteng.entities.YtVideoEntity; |
23 | -import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; | |
24 | -import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | |
25 | 17 | import org.thingsboard.server.dao.yunteng.mapper.YtVideoMapper; |
26 | -import org.thingsboard.server.dao.yunteng.service.*; | |
18 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
19 | +import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; | |
20 | +import org.thingsboard.server.dao.yunteng.service.YtVideoService; | |
27 | 21 | |
28 | -import java.util.HashSet; | |
29 | 22 | import java.util.List; |
30 | -import java.util.Map; | |
31 | -import java.util.Set; | |
32 | -import java.util.stream.Collectors; | |
33 | 23 | |
34 | 24 | @Slf4j |
35 | 25 | @Service |
36 | 26 | @RequiredArgsConstructor |
37 | 27 | public class YtVideoServiceImpl extends AbstractBaseService<YtVideoMapper, YtVideoEntity> |
38 | - implements YtVideoService { | |
28 | + implements YtVideoService { | |
39 | 29 | |
40 | - private final UserOrganizationMappingService userOrganizationMappingService; | |
30 | + private final UserOrganizationMappingService userOrganizationMappingService; | |
41 | 31 | |
42 | - @Override | |
43 | - public YtPageData<YtVideoDTO> pageDatas(IPage<YtVideoEntity> pageInfrom, | |
44 | - boolean isPtTenantAdmin, String tenantId, String currentUserId, String organizationId, String name, Boolean status) { | |
32 | + @Override | |
33 | + public YtPageData<YtVideoDTO> pageDatas(IPage<YtVideoEntity> pageInfrom, | |
34 | + boolean isPtTenantAdmin, String tenantId, String currentUserId, String organizationId, String name, Boolean status) { | |
45 | 35 | |
46 | - List<String> organizationIds = userOrganizationMappingService.getEnableOrganizationIds(isPtTenantAdmin, tenantId, currentUserId,organizationId); | |
47 | - Wrapper pageFilter = new QueryWrapper<YtVideoEntity>() | |
48 | - .lambda() | |
49 | - .in(organizationIds!=null&& !organizationIds.isEmpty(),YtVideoEntity::getOrganizationId,organizationIds) | |
50 | - .eq(status!=null,YtVideoEntity::getStatus,status) | |
51 | - .like(StringUtils.isNotEmpty(name),YtVideoEntity::getName,name); | |
52 | - IPage<YtVideoDTO> page = | |
53 | - baseMapper.getVideoPage(pageInfrom, tenantId,name,status,organizationIds); | |
54 | - return getPageData(page, YtVideoDTO.class); | |
55 | - } | |
36 | + List<String> organizationIds = userOrganizationMappingService.getEnableOrganizationIds(isPtTenantAdmin, tenantId, currentUserId, organizationId); | |
37 | + Wrapper pageFilter = new QueryWrapper<YtVideoEntity>() | |
38 | + .lambda() | |
39 | + .in(organizationIds != null && !organizationIds.isEmpty(), YtVideoEntity::getOrganizationId, organizationIds) | |
40 | + .eq(status != null, YtVideoEntity::getStatus, status) | |
41 | + .like(StringUtils.isNotEmpty(name), YtVideoEntity::getName, name); | |
42 | + if (organizationIds == null || organizationIds.isEmpty()) { | |
43 | + organizationIds = null; | |
44 | + } | |
45 | + IPage<YtVideoDTO> page = | |
46 | + baseMapper.getVideoPage(pageInfrom, tenantId, name, status, organizationIds); | |
47 | + return getPageData(page, YtVideoDTO.class); | |
48 | + } | |
56 | 49 | |
57 | 50 | |
58 | - @Override | |
59 | - public YtVideoDTO detail(String tenantId, String entityId) { | |
60 | - Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
61 | - .eq(YtVideoEntity::getTenantId,tenantId) | |
62 | - .eq(YtVideoEntity::getId,entityId); | |
63 | - YtVideoEntity self = baseMapper.selectOne(filter); | |
64 | - return self.getDTO(YtVideoDTO.class); | |
65 | - } | |
51 | + @Override | |
52 | + public YtVideoDTO detail(String tenantId, String entityId) { | |
53 | + Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
54 | + .eq(YtVideoEntity::getTenantId, tenantId) | |
55 | + .eq(YtVideoEntity::getId, entityId); | |
56 | + YtVideoEntity self = baseMapper.selectOne(filter); | |
57 | + return self.getDTO(YtVideoDTO.class); | |
58 | + } | |
66 | 59 | |
67 | 60 | |
68 | - @Override | |
69 | - @Transactional(rollbackFor=Exception.class) | |
70 | - public YtVideoDTO saveOrUpdate(YtVideoDTO videoDTO) { | |
71 | - if (StringUtils.isNotEmpty(videoDTO.getId())) { | |
72 | - Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
73 | - .eq(YtVideoEntity::getTenantId,videoDTO.getTenantId()) | |
74 | - .eq(YtVideoEntity::getId,videoDTO.getId()); | |
75 | - YtVideoEntity oldVideo = baseMapper.selectOne(filter); | |
76 | - if (null == oldVideo) { | |
77 | - throw new YtDataValidationException(String.format(ErrorMessage.NOT_EXITED_OR_PERMISSION.getMessage(),videoDTO.getId())); | |
78 | - } | |
79 | - baseMapper.updateById(videoDTO.getEntity(YtVideoEntity.class)); | |
80 | - } else { | |
81 | - baseMapper.insert(videoDTO.getEntity(YtVideoEntity.class)); | |
61 | + @Override | |
62 | + @Transactional(rollbackFor = Exception.class) | |
63 | + public YtVideoDTO saveOrUpdate(YtVideoDTO videoDTO) { | |
64 | + if (StringUtils.isNotEmpty(videoDTO.getId())) { | |
65 | + Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
66 | + .eq(YtVideoEntity::getTenantId, videoDTO.getTenantId()) | |
67 | + .eq(YtVideoEntity::getId, videoDTO.getId()); | |
68 | + YtVideoEntity oldVideo = baseMapper.selectOne(filter); | |
69 | + if (null == oldVideo) { | |
70 | + throw new YtDataValidationException(String.format(ErrorMessage.NOT_EXITED_OR_PERMISSION.getMessage(), videoDTO.getId())); | |
71 | + } | |
72 | + baseMapper.updateById(videoDTO.getEntity(YtVideoEntity.class)); | |
73 | + } else { | |
74 | + baseMapper.insert(videoDTO.getEntity(YtVideoEntity.class)); | |
75 | + } | |
76 | + return videoDTO; | |
82 | 77 | } |
83 | - return videoDTO; | |
84 | - } | |
85 | 78 | |
86 | 79 | |
87 | - | |
88 | - @Override | |
89 | - @Transactional(rollbackFor=Exception.class) | |
90 | - public boolean deleteDataByIds(DeleteDTO deleteDTO) { | |
91 | - Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
92 | - .eq(YtVideoEntity::getTenantId,deleteDTO.getTenantId()) | |
93 | - .in(YtVideoEntity::getId,deleteDTO.getIds()); | |
94 | - return baseMapper.delete(filter) > 0; | |
95 | - } | |
80 | + @Override | |
81 | + @Transactional(rollbackFor = Exception.class) | |
82 | + public boolean deleteDataByIds(DeleteDTO deleteDTO) { | |
83 | + Wrapper filter = new QueryWrapper<YtVideoEntity>().lambda() | |
84 | + .eq(YtVideoEntity::getTenantId, deleteDTO.getTenantId()) | |
85 | + .in(YtVideoEntity::getId, deleteDTO.getIds()); | |
86 | + return baseMapper.delete(filter) > 0; | |
87 | + } | |
96 | 88 | |
97 | 89 | } | ... | ... |