Showing
11 changed files
with
202 additions
and
8 deletions
@@ -38,6 +38,7 @@ public class TkInspectionRecordController extends BaseController { | @@ -38,6 +38,7 @@ public class TkInspectionRecordController extends BaseController { | ||
38 | @RequestParam(PAGE_SIZE) int pageSize, | 38 | @RequestParam(PAGE_SIZE) int pageSize, |
39 | @RequestParam(PAGE) int page, | 39 | @RequestParam(PAGE) int page, |
40 | @RequestParam(value = "inspectionPlanId", required = false) String inspectionPlanId, | 40 | @RequestParam(value = "inspectionPlanId", required = false) String inspectionPlanId, |
41 | + @RequestParam(value = "inspectionPlanName", required = false) String inspectionPlanName, | ||
41 | @RequestParam(value = "inspectorId", required = false) String inspectorId, | 42 | @RequestParam(value = "inspectorId", required = false) String inspectorId, |
42 | @RequestParam(value = "startTime", required = false) Long startTime, | 43 | @RequestParam(value = "startTime", required = false) Long startTime, |
43 | @RequestParam(value = "endTime", required = false) Long endTime, | 44 | @RequestParam(value = "endTime", required = false) Long endTime, |
@@ -50,6 +51,10 @@ public class TkInspectionRecordController extends BaseController { | @@ -50,6 +51,10 @@ public class TkInspectionRecordController extends BaseController { | ||
50 | queryMap.put("inspectionPlanId", inspectionPlanId); | 51 | queryMap.put("inspectionPlanId", inspectionPlanId); |
51 | } | 52 | } |
52 | 53 | ||
54 | + if (StringUtils.isNotBlank(inspectionPlanName)) { | ||
55 | + queryMap.put("inspectionPlanName", inspectionPlanName); | ||
56 | + } | ||
57 | + | ||
53 | if (StringUtils.isNotBlank(inspectorId)) { | 58 | if (StringUtils.isNotBlank(inspectorId)) { |
54 | queryMap.put("inspectorId", inspectorId); | 59 | queryMap.put("inspectorId", inspectorId); |
55 | } | 60 | } |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkInspectionDetailsDTO.java
@@ -14,6 +14,9 @@ public class TkInspectionDetailsDTO extends TenantDTO { | @@ -14,6 +14,9 @@ public class TkInspectionDetailsDTO extends TenantDTO { | ||
14 | @ApiModelProperty("巡检设备") | 14 | @ApiModelProperty("巡检设备") |
15 | private String checkDeviceId; | 15 | private String checkDeviceId; |
16 | 16 | ||
17 | + @ApiModelProperty("设备详情") | ||
18 | + private TkDeviceAccountDTO tkDeviceAccountDTO; | ||
19 | + | ||
17 | @ApiModelProperty("巡检内容") | 20 | @ApiModelProperty("巡检内容") |
18 | private String planDetails; | 21 | private String planDetails; |
19 | 22 |
@@ -42,4 +42,10 @@ public class TkInspectionPlanDTO extends TenantDTO { | @@ -42,4 +42,10 @@ public class TkInspectionPlanDTO extends TenantDTO { | ||
42 | 42 | ||
43 | @ApiModelProperty("巡检明细") | 43 | @ApiModelProperty("巡检明细") |
44 | private List<TkCheckDetailsDTO> tkCheckDetailsDTOList; | 44 | private List<TkCheckDetailsDTO> tkCheckDetailsDTOList; |
45 | + | ||
46 | + @ApiModelProperty("巡检记录") | ||
47 | + private List<TkInspectionRecordDTO> tkInspectionRecordDTOList; | ||
48 | + | ||
49 | + @ApiModelProperty("巡检计划id集合") | ||
50 | + private List<String> inspectionPlanIdList; | ||
45 | } | 51 | } |
@@ -23,9 +23,15 @@ public class TkInspectionRecordDTO extends TenantDTO { | @@ -23,9 +23,15 @@ public class TkInspectionRecordDTO extends TenantDTO { | ||
23 | @ApiModelProperty("巡检计划") | 23 | @ApiModelProperty("巡检计划") |
24 | private String inspectionPlanId; | 24 | private String inspectionPlanId; |
25 | 25 | ||
26 | + @ApiModelProperty("巡检计划实体") | ||
27 | + private TkInspectionPlanDTO tkInspectionPlanDTO; | ||
28 | + | ||
26 | @ApiModelProperty("巡检人") | 29 | @ApiModelProperty("巡检人") |
27 | private String inspectorId; | 30 | private String inspectorId; |
28 | 31 | ||
32 | + @ApiModelProperty("巡检人实体") | ||
33 | + private UserDTO userDTO; | ||
34 | + | ||
29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | 35 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
30 | @ApiModelProperty(value = "巡检日期") | 36 | @ApiModelProperty(value = "巡检日期") |
31 | @JsonSerialize(using = LocalDateTimeSerializer.class) | 37 | @JsonSerialize(using = LocalDateTimeSerializer.class) |
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ||
10 | import com.google.common.collect.Sets; | 10 | import com.google.common.collect.Sets; |
11 | import lombok.RequiredArgsConstructor; | 11 | import lombok.RequiredArgsConstructor; |
12 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
13 | +import org.apache.commons.collections4.CollectionUtils; | ||
13 | import org.apache.commons.lang3.RandomStringUtils; | 14 | import org.apache.commons.lang3.RandomStringUtils; |
14 | import org.apache.commons.lang3.StringUtils; | 15 | import org.apache.commons.lang3.StringUtils; |
15 | import org.springframework.context.ApplicationEventPublisher; | 16 | import org.springframework.context.ApplicationEventPublisher; |
@@ -40,6 +41,7 @@ import org.thingsboard.server.common.data.yunteng.enums.UserStatusEnum; | @@ -40,6 +41,7 @@ import org.thingsboard.server.common.data.yunteng.enums.UserStatusEnum; | ||
40 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | 41 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
41 | import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | 42 | import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; |
42 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 43 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
44 | +import org.thingsboard.server.dao.model.sql.UserEntity; | ||
43 | import org.thingsboard.server.dao.user.UserService; | 45 | import org.thingsboard.server.dao.user.UserService; |
44 | import org.thingsboard.server.dao.yunteng.entities.*; | 46 | import org.thingsboard.server.dao.yunteng.entities.*; |
45 | import org.thingsboard.server.dao.yunteng.mapper.*; | 47 | import org.thingsboard.server.dao.yunteng.mapper.*; |
@@ -940,6 +942,25 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -940,6 +942,25 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
940 | return entities.stream().map(entity->entity.getId()).collect(Collectors.toList()); | 942 | return entities.stream().map(entity->entity.getId()).collect(Collectors.toList()); |
941 | } | 943 | } |
942 | 944 | ||
945 | + @Override | ||
946 | + public List<UserDTO> findUserByUserIdList(List<String> userIdList) { | ||
947 | + if (CollectionUtils.isEmpty(userIdList)) { | ||
948 | + return new ArrayList<>(0); | ||
949 | + } | ||
950 | + | ||
951 | + List<SysUserEntity> entities = | ||
952 | + baseMapper.selectList( | ||
953 | + new LambdaQueryWrapper<SysUserEntity>() | ||
954 | + .in(SysUserEntity::getId, userIdList)); | ||
955 | + if (null != entities && !entities.isEmpty()) { | ||
956 | + return entities.stream() | ||
957 | + .map(entity -> entity.getDTO(UserDTO.class)) | ||
958 | + .collect(Collectors.toList()); | ||
959 | + } | ||
960 | + | ||
961 | + return null; | ||
962 | + } | ||
963 | + | ||
943 | private void checkPassword(AccountReqDTO accountReqDTO, SysUserEntity user) { | 964 | private void checkPassword(AccountReqDTO accountReqDTO, SysUserEntity user) { |
944 | if (null == user | 965 | if (null == user |
945 | || StringUtils.isEmpty(accountReqDTO.getPassword()) | 966 | || StringUtils.isEmpty(accountReqDTO.getPassword()) |
@@ -7,10 +7,13 @@ import lombok.extern.slf4j.Slf4j; | @@ -7,10 +7,13 @@ import lombok.extern.slf4j.Slf4j; | ||
7 | import org.apache.commons.collections4.CollectionUtils; | 7 | import org.apache.commons.collections4.CollectionUtils; |
8 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
9 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
11 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccountDTO; | ||
10 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO; | 12 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO; |
11 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity; | 13 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity; |
12 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionDetailsMapper; | 14 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionDetailsMapper; |
13 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 15 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
16 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceAccountService; | ||
14 | import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService; | 17 | import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService; |
15 | 18 | ||
16 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
@@ -22,6 +25,8 @@ import java.util.stream.Collectors; | @@ -22,6 +25,8 @@ import java.util.stream.Collectors; | ||
22 | @Slf4j | 25 | @Slf4j |
23 | public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspectionDetailsMapper, TkInspectionDetailsEntity> | 26 | public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspectionDetailsMapper, TkInspectionDetailsEntity> |
24 | implements TkInspectionDetailsService { | 27 | implements TkInspectionDetailsService { |
28 | + private TkDeviceAccountService tkDeviceAccountService; | ||
29 | + | ||
25 | @Override | 30 | @Override |
26 | public List<TkInspectionDetailsDTO> batchSave(List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList, String inspectionRecordId) { | 31 | public List<TkInspectionDetailsDTO> batchSave(List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList, String inspectionRecordId) { |
27 | List<TkInspectionDetailsDTO> oldTkInspectionDetailsDTOList = listByInspectionRecordId(inspectionRecordId); | 32 | List<TkInspectionDetailsDTO> oldTkInspectionDetailsDTOList = listByInspectionRecordId(inspectionRecordId); |
@@ -97,6 +102,13 @@ public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspec | @@ -97,6 +102,13 @@ public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspec | ||
97 | return CollectionUtils.emptyIfNull(tkInspectionDetailsEntityList).stream().map(entity -> { | 102 | return CollectionUtils.emptyIfNull(tkInspectionDetailsEntityList).stream().map(entity -> { |
98 | TkInspectionDetailsDTO tkInspectionDetailsDTO = new TkInspectionDetailsDTO(); | 103 | TkInspectionDetailsDTO tkInspectionDetailsDTO = new TkInspectionDetailsDTO(); |
99 | entity.copyToDTO(tkInspectionDetailsDTO); | 104 | entity.copyToDTO(tkInspectionDetailsDTO); |
105 | + try { | ||
106 | + TkDeviceAccountDTO tkDeviceAccountDTO = tkDeviceAccountService.load(tkInspectionDetailsDTO.getCheckDeviceId()); | ||
107 | + tkInspectionDetailsDTO.setTkDeviceAccountDTO(tkDeviceAccountDTO); | ||
108 | + } catch (ThingsboardException e) { | ||
109 | + throw new RuntimeException(e); | ||
110 | + } | ||
111 | + | ||
100 | return tkInspectionDetailsDTO; | 112 | return tkInspectionDetailsDTO; |
101 | }).collect(Collectors.toList()); | 113 | }).collect(Collectors.toList()); |
102 | } | 114 | } |
@@ -6,11 +6,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | @@ -6,11 +6,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | ||
6 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
7 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
8 | import org.apache.commons.collections4.CollectionUtils; | 8 | import org.apache.commons.collections4.CollectionUtils; |
9 | +import org.apache.commons.collections4.MapUtils; | ||
9 | import org.apache.commons.lang3.StringUtils; | 10 | import org.apache.commons.lang3.StringUtils; |
10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
11 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | 12 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
12 | import org.thingsboard.server.common.data.yunteng.dto.TkCheckDetailsDTO; | 13 | import org.thingsboard.server.common.data.yunteng.dto.TkCheckDetailsDTO; |
13 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO; | 14 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO; |
15 | +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO; | ||
14 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
15 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; | 17 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; |
16 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionPlanMapper; | 18 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionPlanMapper; |
@@ -23,6 +25,7 @@ import java.time.LocalDateTime; | @@ -23,6 +25,7 @@ import java.time.LocalDateTime; | ||
23 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
24 | import java.util.List; | 26 | import java.util.List; |
25 | import java.util.Map; | 27 | import java.util.Map; |
28 | +import java.util.stream.Collectors; | ||
26 | 29 | ||
27 | @Service | 30 | @Service |
28 | @RequiredArgsConstructor | 31 | @RequiredArgsConstructor |
@@ -68,7 +71,25 @@ public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectio | @@ -68,7 +71,25 @@ public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectio | ||
68 | IPage<TkInspectionPlanEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false), | 71 | IPage<TkInspectionPlanEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false), |
69 | wrapper); | 72 | wrapper); |
70 | 73 | ||
71 | - return getPageData(page, TkInspectionPlanDTO.class); | 74 | + if (CollectionUtils.isEmpty(page.getRecords())) { |
75 | + return getPageData(page, TkInspectionPlanDTO.class); | ||
76 | + } | ||
77 | + | ||
78 | + List<TkInspectionPlanEntity> inspectionPlanEntityList = page.getRecords(); | ||
79 | + List<String> inspectionPlanIdList = inspectionPlanEntityList.stream().map(TkInspectionPlanEntity::getId).collect(Collectors.toList()); | ||
80 | + Map<String, List<TkInspectionRecordDTO>> recordDtoMap = tkInspectionRecordService.mapByInspectionPlanId(inspectionPlanIdList); | ||
81 | + if (MapUtils.isEmpty(recordDtoMap)) { | ||
82 | + return getPageData(page, TkInspectionPlanDTO.class); | ||
83 | + } | ||
84 | + | ||
85 | + TkPageData<TkInspectionPlanDTO> dtoPage = getPageData(page, TkInspectionPlanDTO.class); | ||
86 | + List<TkInspectionPlanDTO> tkInspectionPlanDTOList = new ArrayList<>(dtoPage.getItems()); | ||
87 | + tkInspectionPlanDTOList.forEach(tkInspectionPlanDTO -> { | ||
88 | + tkInspectionPlanDTO.setTkInspectionRecordDTOList(recordDtoMap.get(tkInspectionPlanDTO.getId())); | ||
89 | + }); | ||
90 | + | ||
91 | + dtoPage.setItems(tkInspectionPlanDTOList); | ||
92 | + return dtoPage; | ||
72 | } | 93 | } |
73 | 94 | ||
74 | @Override | 95 | @Override |
@@ -124,6 +145,34 @@ public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectio | @@ -124,6 +145,34 @@ public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectio | ||
124 | return count > 0; | 145 | return count > 0; |
125 | } | 146 | } |
126 | 147 | ||
148 | + @Override | ||
149 | + public List<TkInspectionPlanDTO> selectByCondition(TkInspectionPlanDTO tkInspectionPlanDTO) { | ||
150 | + if (tkInspectionPlanDTO == null || StringUtils.isBlank(tkInspectionPlanDTO.getTenantId())) { | ||
151 | + return new ArrayList<>(0); | ||
152 | + } | ||
153 | + | ||
154 | + QueryWrapper<TkInspectionPlanEntity> wrapper = new QueryWrapper<>(); | ||
155 | + LambdaQueryWrapper<TkInspectionPlanEntity> lambda = wrapper.lambda(); | ||
156 | + lambda.eq(TkInspectionPlanEntity::getTenantId, tkInspectionPlanDTO.getTenantId()); | ||
157 | + if (StringUtils.isNotBlank(tkInspectionPlanDTO.getName())) { | ||
158 | + lambda.like(TkInspectionPlanEntity::getName, tkInspectionPlanDTO.getName()); | ||
159 | + } | ||
160 | + | ||
161 | + if (CollectionUtils.isNotEmpty(tkInspectionPlanDTO.getInspectionPlanIdList())) { | ||
162 | + lambda.in(TkInspectionPlanEntity::getId, tkInspectionPlanDTO.getInspectionPlanIdList()); | ||
163 | + } | ||
164 | + | ||
165 | + // todo ymk 后续有什么查询条件再加 | ||
166 | + | ||
167 | + lambda.orderByAsc(TkInspectionPlanEntity::getCreateTime); | ||
168 | + List<TkInspectionPlanEntity> inspectionPlanEntityList = baseMapper.selectList(wrapper); | ||
169 | + return CollectionUtils.emptyIfNull(inspectionPlanEntityList).stream().map(inspectionPlanEntity -> { | ||
170 | + TkInspectionPlanDTO dto = new TkInspectionPlanDTO(); | ||
171 | + inspectionPlanEntity.copyToDTO(dto); | ||
172 | + return dto; | ||
173 | + }).collect(Collectors.toList()); | ||
174 | + } | ||
175 | + | ||
127 | private void checkDto(TkInspectionPlanDTO dto) { | 176 | private void checkDto(TkInspectionPlanDTO dto) { |
128 | if (StringUtils.isBlank(dto.getTenantId())) { | 177 | if (StringUtils.isBlank(dto.getTenantId())) { |
129 | throw new TkDataValidationException("租户id为空!"); | 178 | throw new TkDataValidationException("租户id为空!"); |
@@ -7,21 +7,22 @@ import lombok.RequiredArgsConstructor; | @@ -7,21 +7,22 @@ import lombok.RequiredArgsConstructor; | ||
7 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
8 | import org.apache.commons.collections4.CollectionUtils; | 8 | import org.apache.commons.collections4.CollectionUtils; |
9 | import org.apache.commons.lang3.StringUtils; | 9 | import org.apache.commons.lang3.StringUtils; |
10 | +import org.springframework.context.annotation.Lazy; | ||
10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
11 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | 12 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
12 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO; | 13 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO; |
14 | +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO; | ||
13 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO; | 15 | import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO; |
16 | +import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | ||
14 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
15 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; | 18 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; |
16 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionRecordMapper; | 19 | import org.thingsboard.server.dao.yunteng.mapper.TkInspectionRecordMapper; |
17 | -import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
18 | -import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService; | ||
19 | -import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService; | 20 | +import org.thingsboard.server.dao.yunteng.service.*; |
20 | 21 | ||
21 | import java.time.LocalDateTime; | 22 | import java.time.LocalDateTime; |
22 | -import java.util.ArrayList; | ||
23 | -import java.util.List; | ||
24 | -import java.util.Map; | 23 | +import java.util.*; |
24 | +import java.util.function.Function; | ||
25 | +import java.util.stream.Collectors; | ||
25 | 26 | ||
26 | @Service | 27 | @Service |
27 | @RequiredArgsConstructor | 28 | @RequiredArgsConstructor |
@@ -29,6 +30,9 @@ import java.util.Map; | @@ -29,6 +30,9 @@ import java.util.Map; | ||
29 | public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspectionRecordMapper, TkInspectionRecordEntity> | 30 | public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspectionRecordMapper, TkInspectionRecordEntity> |
30 | implements TkInspectionRecordService { | 31 | implements TkInspectionRecordService { |
31 | private final TkInspectionDetailsService tkInspectionDetailsService; | 32 | private final TkInspectionDetailsService tkInspectionDetailsService; |
33 | + @Lazy | ||
34 | + private final TkInspectionPlanService tkInspectionPlanService; | ||
35 | + private final TkUserService tkUserService; | ||
32 | 36 | ||
33 | @Override | 37 | @Override |
34 | public TkPageData<TkInspectionRecordDTO> page(Map<String, Object> queryMap, String tenantId) { | 38 | public TkPageData<TkInspectionRecordDTO> page(Map<String, Object> queryMap, String tenantId) { |
@@ -39,6 +43,20 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | @@ -39,6 +43,20 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | ||
39 | lambda.eq(TkInspectionRecordEntity::getInspectionPlanId, queryMap.get("inspectionPlanId").toString()); | 43 | lambda.eq(TkInspectionRecordEntity::getInspectionPlanId, queryMap.get("inspectionPlanId").toString()); |
40 | } | 44 | } |
41 | 45 | ||
46 | + if (queryMap != null && queryMap.get("inspectionPlanName") != null) { | ||
47 | + String inspectionPlanName = queryMap.get("inspectionPlanName").toString(); | ||
48 | + TkInspectionPlanDTO condition = new TkInspectionPlanDTO(); | ||
49 | + condition.setName(inspectionPlanName); | ||
50 | + condition.setTenantId(tenantId); | ||
51 | + List<TkInspectionPlanDTO> tkInspectionPlanDTOList = tkInspectionPlanService.selectByCondition(condition); | ||
52 | + if (CollectionUtils.isEmpty(tkInspectionPlanDTOList)) { | ||
53 | + return new TkPageData<>(); | ||
54 | + } | ||
55 | + | ||
56 | + List<String> inspectionPlanIdList = tkInspectionPlanDTOList.stream().map(TkInspectionPlanDTO::getId).collect(Collectors.toList()); | ||
57 | + lambda.in(TkInspectionRecordEntity::getInspectionPlanId, inspectionPlanIdList); | ||
58 | + } | ||
59 | + | ||
42 | if (queryMap != null && queryMap.get("inspectorId") != null) { | 60 | if (queryMap != null && queryMap.get("inspectorId") != null) { |
43 | lambda.eq(TkInspectionRecordEntity::getInspectorId, queryMap.get("inspectorId").toString()); | 61 | lambda.eq(TkInspectionRecordEntity::getInspectorId, queryMap.get("inspectorId").toString()); |
44 | } | 62 | } |
@@ -57,7 +75,34 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | @@ -57,7 +75,34 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | ||
57 | IPage<TkInspectionRecordEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false), | 75 | IPage<TkInspectionRecordEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false), |
58 | wrapper); | 76 | wrapper); |
59 | 77 | ||
60 | - return getPageData(page, TkInspectionRecordDTO.class); | 78 | + TkPageData<TkInspectionRecordDTO> pageData = getPageData(page, TkInspectionRecordDTO.class); |
79 | + if (pageData == null || CollectionUtils.isEmpty(pageData.getItems())) { | ||
80 | + return pageData; | ||
81 | + } | ||
82 | + | ||
83 | + List<TkInspectionRecordDTO> tkInspectionRecordDTOList = new ArrayList<>(pageData.getItems()); | ||
84 | + List<String> inspectionPlanIdList = tkInspectionRecordDTOList.stream().map(TkInspectionRecordDTO::getInspectionPlanId).collect(Collectors.toList()); | ||
85 | + Set<String> inspectorIds = tkInspectionRecordDTOList.stream().map(TkInspectionRecordDTO::getInspectorId).collect(Collectors.toSet()); | ||
86 | + TkInspectionPlanDTO condition = new TkInspectionPlanDTO(); | ||
87 | + condition.setTenantId(tenantId); | ||
88 | + condition.setInspectionPlanIdList(inspectionPlanIdList); | ||
89 | + List<TkInspectionPlanDTO> inspectionPlanDTOLst = tkInspectionPlanService.selectByCondition(condition); | ||
90 | + List<UserDTO> userDTOList = tkUserService.findUserByUserIdList(new ArrayList<>(inspectorIds)); | ||
91 | + Map<String, TkInspectionPlanDTO> tkInspectionPlanDTOMap = CollectionUtils.emptyIfNull(inspectionPlanDTOLst) | ||
92 | + .stream() | ||
93 | + .collect(Collectors.toMap(TkInspectionPlanDTO::getId, Function.identity(), (a, b) -> a)); | ||
94 | + Map<String, UserDTO> userDTOMap = CollectionUtils.emptyIfNull(userDTOList) | ||
95 | + .stream() | ||
96 | + .collect(Collectors.toMap(UserDTO::getId, Function.identity(), (a, b) -> a)); | ||
97 | + tkInspectionRecordDTOList.forEach(tkInspectionRecordDTO -> { | ||
98 | + TkInspectionPlanDTO tkInspectionPlanDTO = tkInspectionPlanDTOMap.get(tkInspectionRecordDTO.getInspectionPlanId()); | ||
99 | + tkInspectionRecordDTO.setTkInspectionPlanDTO(tkInspectionPlanDTO); | ||
100 | + UserDTO userDTO = userDTOMap.get(tkInspectionRecordDTO.getInspectorId()); | ||
101 | + tkInspectionRecordDTO.setUserDTO(userDTO); | ||
102 | + }); | ||
103 | + | ||
104 | + pageData.setItems(tkInspectionRecordDTOList); | ||
105 | + return pageData; | ||
61 | } | 106 | } |
62 | 107 | ||
63 | @Override | 108 | @Override |
@@ -99,10 +144,18 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | @@ -99,10 +144,18 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | ||
99 | } | 144 | } |
100 | 145 | ||
101 | TkInspectionRecordEntity entity = baseMapper.selectById(id); | 146 | TkInspectionRecordEntity entity = baseMapper.selectById(id); |
147 | + if (entity == null) { | ||
148 | + return new TkInspectionRecordDTO(); | ||
149 | + } | ||
150 | + | ||
102 | TkInspectionRecordDTO tkInspectionRecordDTO = new TkInspectionRecordDTO(); | 151 | TkInspectionRecordDTO tkInspectionRecordDTO = new TkInspectionRecordDTO(); |
103 | entity.copyToDTO(tkInspectionRecordDTO); | 152 | entity.copyToDTO(tkInspectionRecordDTO); |
104 | List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList = tkInspectionDetailsService.listByInspectionRecordId(id); | 153 | List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList = tkInspectionDetailsService.listByInspectionRecordId(id); |
105 | tkInspectionRecordDTO.setTkInspectionDetailsDTOList(tkInspectionDetailsDTOList); | 154 | tkInspectionRecordDTO.setTkInspectionDetailsDTOList(tkInspectionDetailsDTOList); |
155 | + TkInspectionPlanDTO tkInspectionPlanDTO = tkInspectionPlanService.get(tkInspectionRecordDTO.getInspectionPlanId()); | ||
156 | + tkInspectionRecordDTO.setTkInspectionPlanDTO(tkInspectionPlanDTO); | ||
157 | + UserDTO userDTO = tkUserService.findUserInfoById(tkInspectionRecordDTO.getInspectorId()); | ||
158 | + tkInspectionRecordDTO.setUserDTO(userDTO); | ||
106 | return tkInspectionRecordDTO; | 159 | return tkInspectionRecordDTO; |
107 | } | 160 | } |
108 | 161 | ||
@@ -113,6 +166,37 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | @@ -113,6 +166,37 @@ public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspect | ||
113 | return count > 0; | 166 | return count > 0; |
114 | } | 167 | } |
115 | 168 | ||
169 | + @Override | ||
170 | + public Map<String, List<TkInspectionRecordDTO>> mapByInspectionPlanId(List<String> inspectionPlanIdList) { | ||
171 | + if (CollectionUtils.isEmpty(inspectionPlanIdList)) { | ||
172 | + return new HashMap<>(0); | ||
173 | + } | ||
174 | + | ||
175 | + QueryWrapper<TkInspectionRecordEntity> wrapper = new QueryWrapper<>(); | ||
176 | + LambdaQueryWrapper<TkInspectionRecordEntity> lambda = wrapper.lambda(); | ||
177 | + lambda.in(TkInspectionRecordEntity::getInspectionPlanId, inspectionPlanIdList); | ||
178 | + lambda.orderByAsc(TkInspectionRecordEntity::getCreateTime); | ||
179 | + List<TkInspectionRecordEntity> tkInspectionRecordEntityList = baseMapper.selectList(wrapper); | ||
180 | + if (CollectionUtils.isEmpty(tkInspectionRecordEntityList)) { | ||
181 | + return new HashMap<>(0); | ||
182 | + } | ||
183 | + | ||
184 | + Map<String, List<TkInspectionRecordDTO>> map = new HashMap<>(inspectionPlanIdList.size()); | ||
185 | + tkInspectionRecordEntityList.forEach(entity -> { | ||
186 | + TkInspectionRecordDTO dto = new TkInspectionRecordDTO(); | ||
187 | + entity.copyToDTO(dto); | ||
188 | + List<TkInspectionRecordDTO> dtoList = map.get(dto.getInspectionPlanId()); | ||
189 | + if (CollectionUtils.isEmpty(dtoList)) { | ||
190 | + dtoList = new ArrayList<>(1); | ||
191 | + } | ||
192 | + | ||
193 | + dtoList.add(dto); | ||
194 | + map.put(dto.getInspectionPlanId(), dtoList); | ||
195 | + }); | ||
196 | + | ||
197 | + return map; | ||
198 | + } | ||
199 | + | ||
116 | private void checkDto(TkInspectionRecordDTO dto) { | 200 | private void checkDto(TkInspectionRecordDTO dto) { |
117 | if (StringUtils.isBlank(dto.getTenantId())) { | 201 | if (StringUtils.isBlank(dto.getTenantId())) { |
118 | throw new TkDataValidationException("租户id为空!"); | 202 | throw new TkDataValidationException("租户id为空!"); |
@@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO; | @@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO; | ||
4 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 4 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
5 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; | 5 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; |
6 | 6 | ||
7 | +import java.util.List; | ||
7 | import java.util.Map; | 8 | import java.util.Map; |
8 | 9 | ||
9 | public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEntity> { | 10 | public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEntity> { |
@@ -15,4 +16,6 @@ public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEnt | @@ -15,4 +16,6 @@ public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEnt | ||
15 | TkInspectionPlanDTO get(String id); | 16 | TkInspectionPlanDTO get(String id); |
16 | 17 | ||
17 | boolean delete(String id); | 18 | boolean delete(String id); |
19 | + | ||
20 | + List<TkInspectionPlanDTO> selectByCondition(TkInspectionPlanDTO tkInspectionPlanDTO); | ||
18 | } | 21 | } |
@@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO; | @@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO; | ||
4 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 4 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
5 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; | 5 | import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; |
6 | 6 | ||
7 | +import java.util.List; | ||
7 | import java.util.Map; | 8 | import java.util.Map; |
8 | 9 | ||
9 | public interface TkInspectionRecordService extends BaseService<TkInspectionRecordEntity> { | 10 | public interface TkInspectionRecordService extends BaseService<TkInspectionRecordEntity> { |
@@ -15,4 +16,6 @@ public interface TkInspectionRecordService extends BaseService<TkInspectionRecor | @@ -15,4 +16,6 @@ public interface TkInspectionRecordService extends BaseService<TkInspectionRecor | ||
15 | TkInspectionRecordDTO get(String id); | 16 | TkInspectionRecordDTO get(String id); |
16 | 17 | ||
17 | boolean delete(String id); | 18 | boolean delete(String id); |
19 | + | ||
20 | + Map<String, List<TkInspectionRecordDTO>> mapByInspectionPlanId(List<String> inspectionPlanIdList); | ||
18 | } | 21 | } |
@@ -180,4 +180,6 @@ public interface TkUserService { | @@ -180,4 +180,6 @@ public interface TkUserService { | ||
180 | * @return 用户ID列表 | 180 | * @return 用户ID列表 |
181 | */ | 181 | */ |
182 | List<String> findUserIdsByTenantId(String tenantId); | 182 | List<String> findUserIdsByTenantId(String tenantId); |
183 | + | ||
184 | + List<UserDTO> findUserByUserIdList(List<String> userIdList); | ||
183 | } | 185 | } |