Commit 7a4cd252894a28522a4685ebb55170f9576f99dc

Authored by 杨鸣坤
1 parent 0c34a50a

巡检结果 接口开发

... ... @@ -194,16 +194,17 @@ COMMENT ON COLUMN "public"."qg_inspection_record"."tenant_id" IS '租户ID';
194 194
195 195 CREATE TABLE "public"."qg_inspection_details"
196 196 (
197   - "id" varchar(36) PRIMARY KEY,
198   - "check_device_id" varchar(36),
199   - "plan_details" varchar(255),
200   - "record_result" bool,
201   - "show_order" int4,
202   - "tenant_id" varchar(36),
203   - "create_time" timestamp(6),
204   - "creator" varchar(36),
205   - "updater" varchar(36),
206   - "update_time" timestamp(6)
  197 + "id" varchar(36) PRIMARY KEY,
  198 + "check_device_id" varchar(36),
  199 + "plan_details" varchar(255),
  200 + "record_result" bool,
  201 + "show_order" int4,
  202 + "inspection_record_id" varchar(36),
  203 + "tenant_id" varchar(36),
  204 + "create_time" timestamp(6),
  205 + "creator" varchar(36),
  206 + "updater" varchar(36),
  207 + "update_time" timestamp(6)
207 208 );
208 209
209 210 COMMENT ON TABLE "public"."qg_inspection_details" IS '巡检记录明细';
... ... @@ -212,4 +213,5 @@ COMMENT ON COLUMN "public"."qg_inspection_details"."check_device_id" IS '巡检è
212 213 COMMENT ON COLUMN "public"."qg_inspection_details"."plan_details" IS '巡检内容';
213 214 COMMENT ON COLUMN "public"."qg_inspection_details"."record_result" IS '巡检结果';
214 215 COMMENT ON COLUMN "public"."qg_inspection_details"."show_order" IS '排序';
  216 +COMMENT ON COLUMN "public"."qg_inspection_details"."inspection_record_id" IS '巡检记录';
215 217 COMMENT ON COLUMN "public"."qg_inspection_details"."tenant_id" IS '租户ID';
\ No newline at end of file
... ...
... ... @@ -10,17 +10,13 @@ import org.springframework.http.ResponseEntity;
10 10 import org.springframework.security.access.prepost.PreAuthorize;
11 11 import org.springframework.web.bind.annotation.*;
12 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
13   -import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
14   -import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 13 import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO;
16 14 import org.thingsboard.server.common.data.yunteng.enums.TkInspectionPlanStatusEnum;
17   -import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils;
18 15 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
19 16 import org.thingsboard.server.controller.BaseController;
20 17 import org.thingsboard.server.dao.yunteng.service.TkInspectionPlanService;
21 18 import org.thingsboard.server.queue.util.TbCoreComponent;
22 19
23   -import java.sql.Timestamp;
24 20 import java.util.HashMap;
25 21 import java.util.Map;
26 22
... ... @@ -90,17 +86,4 @@ public class TkInspectionPlanController extends BaseController {
90 86 public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException {
91 87 return ResponseEntity.ok(tkInspectionPlanService.delete(id));
92 88 }
93   -
94   - protected void checkTimeAndPut(Map<String, Object> queryMap, Long startTime, Long endTime) {
95   - if (null != endTime && null != startTime) {
96   - if (startTime > endTime) {
97   - throw new TkDataValidationException(
98   - MessageUtils.message(ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getI18nCode()));
99   - }
100   -
101   - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());
102   - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());
103   - }
104   - }
105   -
106 89 }
... ...
1 1 package org.thingsboard.server.controller.yunteng;
2 2
3 3 import io.swagger.annotations.Api;
  4 +import io.swagger.annotations.ApiOperation;
4 5 import lombok.RequiredArgsConstructor;
5 6 import lombok.extern.slf4j.Slf4j;
6   -import org.springframework.web.bind.annotation.RequestMapping;
7   -import org.springframework.web.bind.annotation.RestController;
  7 +import org.apache.commons.collections4.CollectionUtils;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.springframework.http.ResponseEntity;
  10 +import org.springframework.security.access.prepost.PreAuthorize;
  11 +import org.springframework.web.bind.annotation.*;
  12 +import org.thingsboard.server.common.data.exception.ThingsboardException;
  13 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO;
  14 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
8 15 import org.thingsboard.server.controller.BaseController;
9 16 import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService;
10 17 import org.thingsboard.server.queue.util.TbCoreComponent;
11 18
  19 +import java.util.HashMap;
  20 +import java.util.Map;
  21 +
  22 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE;
  23 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE;
  24 +
12 25 @RestController
13 26 @TbCoreComponent
14 27 @RequiredArgsConstructor
... ... @@ -18,4 +31,60 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
18 31 public class TkInspectionRecordController extends BaseController {
19 32 private final TkInspectionRecordService tkInspectionRecordService;
20 33
  34 + @GetMapping(params = {PAGE_SIZE, PAGE})
  35 + @ApiOperation("分页查询")
  36 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  37 + public TkPageData<TkInspectionRecordDTO> page(
  38 + @RequestParam(PAGE_SIZE) int pageSize,
  39 + @RequestParam(PAGE) int page,
  40 + @RequestParam(value = "inspectionPlanId", required = false) String inspectionPlanId,
  41 + @RequestParam(value = "inspectorId", required = false) String inspectorId,
  42 + @RequestParam(value = "startTime", required = false) Long startTime,
  43 + @RequestParam(value = "endTime", required = false) Long endTime,
  44 + @RequestParam(value = "recordResult", required = false) Boolean recordResult
  45 + ) throws ThingsboardException {
  46 + Map<String, Object> queryMap = new HashMap<>();
  47 + queryMap.put(PAGE_SIZE, pageSize);
  48 + queryMap.put(PAGE, page);
  49 + if (StringUtils.isNotBlank(inspectionPlanId)) {
  50 + queryMap.put("inspectionPlanId", inspectionPlanId);
  51 + }
  52 +
  53 + if (StringUtils.isNotBlank(inspectorId)) {
  54 + queryMap.put("inspectorId", inspectorId);
  55 + }
  56 +
  57 + if (recordResult != null) {
  58 + queryMap.put("recordResult", recordResult);
  59 + }
  60 +
  61 + checkTimeAndPut(queryMap, startTime, endTime);
  62 + return tkInspectionRecordService.page(queryMap, getCurrentUser().isTenantAdmin());
  63 + }
  64 +
  65 + @PostMapping("/save")
  66 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  67 + public ResponseEntity<TkInspectionRecordDTO> save(@RequestBody TkInspectionRecordDTO tkInspectionRecordDTO) throws ThingsboardException {
  68 + tkInspectionRecordDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  69 + if (CollectionUtils.isNotEmpty(tkInspectionRecordDTO.getTkInspectionDetailsDTOList())) {
  70 + tkInspectionRecordDTO.getTkInspectionDetailsDTOList()
  71 + .forEach(tkInspectionDetailsDTO -> tkInspectionDetailsDTO.setTenantId(tkInspectionRecordDTO.getTenantId()));
  72 + }
  73 +
  74 + TkInspectionRecordDTO dto = tkInspectionRecordService.save(tkInspectionRecordDTO);
  75 + return ResponseEntity.ok(dto);
  76 + }
  77 +
  78 + @GetMapping("/detail")
  79 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  80 + public ResponseEntity<TkInspectionRecordDTO> detail(@RequestParam("id") String id) throws ThingsboardException {
  81 + return ResponseEntity.ok(tkInspectionRecordService.get(id));
  82 + }
  83 +
  84 + @GetMapping("/delete")
  85 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  86 + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException {
  87 + return ResponseEntity.ok(tkInspectionRecordService.delete(id));
  88 + }
  89 +
21 90 }
... ...
... ... @@ -20,6 +20,9 @@ public class TkInspectionDetailsDTO extends TenantDTO {
20 20 @ApiModelProperty("巡检结果")
21 21 private boolean recordResult;
22 22
  23 + @ApiModelProperty("巡检记录")
  24 + private String inspectionRecordId;
  25 +
23 26 @ApiModelProperty("排序")
24 27 private int showOrder;
25 28 }
... ...
... ... @@ -8,6 +8,7 @@ import lombok.Data;
8 8 import lombok.EqualsAndHashCode;
9 9
10 10 import java.time.LocalDateTime;
  11 +import java.util.List;
11 12
12 13 /**
13 14 * 巡检记录
... ... @@ -32,4 +33,17 @@ public class TkInspectionRecordDTO extends TenantDTO {
32 33
33 34 @ApiModelProperty("巡检结果")
34 35 private boolean recordResult;
  36 +
  37 + @ApiModelProperty("巡检记录明细")
  38 + private List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList;
  39 +
  40 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  41 + @ApiModelProperty(value = "巡检日期-筛选开始日期")
  42 + @JsonSerialize(using = LocalDateTimeSerializer.class)
  43 + private LocalDateTime startTime;
  44 +
  45 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  46 + @ApiModelProperty(value = "巡检日期-筛选结束日期")
  47 + @JsonSerialize(using = LocalDateTimeSerializer.class)
  48 + private LocalDateTime endTime;
35 49 }
... ...
... ... @@ -29,6 +29,11 @@ public class TkInspectionDetailsEntity extends TenantBaseEntity {
29 29 private boolean recordResult;
30 30
31 31 /**
  32 + * 巡检记录
  33 + */
  34 + private String inspectionRecordId;
  35 +
  36 + /**
32 37 * 排序
33 38 */
34 39 private int showOrder;
... ...
... ... @@ -26,7 +26,9 @@ public class TkCheckDetailsServiceImpl extends AbstractBaseService<TkCheckDetail
26 26 public List<TkCheckDetailsDTO> batchSave(List<TkCheckDetailsDTO> checkDetailsDTOList, String inspectionPlanId) {
27 27 List<TkCheckDetailsDTO> oldTkCheckDetailsDTOList = listByInspectionPlanId(inspectionPlanId);
28 28 if (CollectionUtils.isEmpty(checkDetailsDTOList) && CollectionUtils.isNotEmpty(oldTkCheckDetailsDTOList)) {
29   - List<String> checkDetailsIdList = oldTkCheckDetailsDTOList.stream().map(TkCheckDetailsDTO::getId).collect(Collectors.toList());
  29 + List<String> checkDetailsIdList = oldTkCheckDetailsDTOList.stream()
  30 + .map(TkCheckDetailsDTO::getId)
  31 + .collect(Collectors.toList());
30 32 baseMapper.deleteBatchIds(checkDetailsIdList);
31 33 return new ArrayList<>(0);
32 34 }
... ... @@ -82,6 +84,7 @@ public class TkCheckDetailsServiceImpl extends AbstractBaseService<TkCheckDetail
82 84 return listByInspectionPlanId(inspectionPlanId);
83 85 }
84 86
  87 + @Override
85 88 public List<TkCheckDetailsDTO> listByInspectionPlanId(String inspectionPlanId) {
86 89 if (StringUtils.isBlank(inspectionPlanId)) {
87 90 return new ArrayList<>(0);
... ...
1 1 package org.thingsboard.server.dao.yunteng.impl;
2 2
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 5 import lombok.RequiredArgsConstructor;
4 6 import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.commons.collections4.CollectionUtils;
  8 +import org.apache.commons.lang3.StringUtils;
5 9 import org.springframework.stereotype.Service;
  10 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO;
6 11 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity;
7 12 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionDetailsMapper;
8 13 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
9 14 import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService;
10 15
  16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +import java.util.stream.Collectors;
  19 +
11 20 @Service
12 21 @RequiredArgsConstructor
13 22 @Slf4j
14 23 public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspectionDetailsMapper, TkInspectionDetailsEntity>
15 24 implements TkInspectionDetailsService {
  25 + @Override
  26 + public List<TkInspectionDetailsDTO> batchSave(List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList, String inspectionRecordId) {
  27 + List<TkInspectionDetailsDTO> oldTkInspectionDetailsDTOList = listByInspectionRecordId(inspectionRecordId);
  28 + if (CollectionUtils.isEmpty(tkInspectionDetailsDTOList) && CollectionUtils.isNotEmpty(oldTkInspectionDetailsDTOList)) {
  29 + List<String> inspectionDetailsIdList = oldTkInspectionDetailsDTOList.stream()
  30 + .map(TkInspectionDetailsDTO::getId)
  31 + .collect(Collectors.toList());
  32 + baseMapper.deleteBatchIds(inspectionDetailsIdList);
  33 + return new ArrayList<>(0);
  34 + }
  35 +
  36 + if (CollectionUtils.isEmpty(oldTkInspectionDetailsDTOList) && CollectionUtils.isNotEmpty(tkInspectionDetailsDTOList)) {
  37 + List<TkInspectionDetailsEntity> tkInspectionDetailsEntityList = tkInspectionDetailsDTOList.stream().map(tkInspectionDetailsDTO -> {
  38 + TkInspectionDetailsEntity entity = new TkInspectionDetailsEntity();
  39 + tkInspectionDetailsDTO.copyToEntity(entity);
  40 + return entity;
  41 + }).collect(Collectors.toList());
  42 +
  43 + insertBatch(tkInspectionDetailsEntityList, TkInspectionDetailsEntity.class);
  44 + return listByInspectionRecordId(inspectionRecordId);
  45 + }
  46 +
  47 + List<TkInspectionDetailsEntity> addEntityList = new ArrayList<>(tkInspectionDetailsDTOList.size());
  48 + List<TkInspectionDetailsEntity> updateEntityList = new ArrayList<>(tkInspectionDetailsDTOList.size());
  49 + List<String> needDeleteIdList = new ArrayList<>(tkInspectionDetailsDTOList.size());
  50 + List<String> inspectionDetailsIdList = CollectionUtils.emptyIfNull(oldTkInspectionDetailsDTOList).stream()
  51 + .map(TkInspectionDetailsDTO::getId)
  52 + .collect(Collectors.toList());
  53 + for (TkInspectionDetailsDTO tkInspectionDetailsDTO : tkInspectionDetailsDTOList) {
  54 + TkInspectionDetailsEntity entity = new TkInspectionDetailsEntity();
  55 + tkInspectionDetailsDTO.copyToEntity(entity);
  56 + if (StringUtils.isBlank(entity.getId())) {
  57 + addEntityList.add(entity);
  58 + continue;
  59 + }
  60 +
  61 + if (inspectionDetailsIdList.contains(entity.getId())) {
  62 + updateEntityList.add(entity);
  63 + }
  64 + }
  65 +
  66 + if (CollectionUtils.isNotEmpty(addEntityList)) {
  67 + insertBatch(addEntityList, TkInspectionDetailsEntity.class);
  68 + }
  69 +
  70 + if (CollectionUtils.isNotEmpty(updateEntityList)) {
  71 + updateEntityList.forEach(tkInspectionDetailsEntity -> baseMapper.updateById(tkInspectionDetailsEntity));
  72 + List<String> updateIdList = updateEntityList.stream().map(TkInspectionDetailsEntity::getId).collect(Collectors.toList());
  73 + inspectionDetailsIdList.retainAll(updateIdList);
  74 + needDeleteIdList.addAll(inspectionDetailsIdList);
  75 + } else {
  76 + needDeleteIdList = inspectionDetailsIdList;
  77 + }
  78 +
  79 + if (CollectionUtils.isNotEmpty(needDeleteIdList)) {
  80 + baseMapper.deleteBatchIds(needDeleteIdList);
  81 + }
  82 +
  83 + return listByInspectionRecordId(inspectionRecordId);
  84 + }
  85 +
  86 + @Override
  87 + public List<TkInspectionDetailsDTO> listByInspectionRecordId(String inspectionRecordId) {
  88 + if (StringUtils.isBlank(inspectionRecordId)) {
  89 + return new ArrayList<>(0);
  90 + }
  91 +
  92 + QueryWrapper<TkInspectionDetailsEntity> wrapper = new QueryWrapper<>();
  93 + LambdaQueryWrapper<TkInspectionDetailsEntity> lambda = wrapper.lambda();
  94 + lambda.eq(TkInspectionDetailsEntity::getInspectionRecordId, inspectionRecordId);
  95 + lambda.orderByAsc(TkInspectionDetailsEntity::getShowOrder);
  96 + List<TkInspectionDetailsEntity> tkInspectionDetailsEntityList = baseMapper.selectList(wrapper);
  97 + return CollectionUtils.emptyIfNull(tkInspectionDetailsEntityList).stream().map(entity -> {
  98 + TkInspectionDetailsDTO tkInspectionDetailsDTO = new TkInspectionDetailsDTO();
  99 + entity.copyToDTO(tkInspectionDetailsDTO);
  100 + return tkInspectionDetailsDTO;
  101 + }).collect(Collectors.toList());
  102 + }
  103 +
  104 + @Override
  105 + public void deleteByInspectionRecordId(String inspectionRecordId) {
  106 + if (StringUtils.isBlank(inspectionRecordId)) {
  107 + return;
  108 + }
  109 +
  110 + QueryWrapper<TkInspectionDetailsEntity> wrapper = new QueryWrapper<>();
  111 + LambdaQueryWrapper<TkInspectionDetailsEntity> lambda = wrapper.lambda();
  112 + lambda.eq(TkInspectionDetailsEntity::getInspectionRecordId, inspectionRecordId);
  113 + baseMapper.delete(wrapper);
  114 + }
16 115 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.impl;
2 2
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5 +import com.baomidou.mybatisplus.core.metadata.IPage;
3 6 import lombok.RequiredArgsConstructor;
4 7 import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.collections4.CollectionUtils;
  9 +import org.apache.commons.lang3.StringUtils;
5 10 import org.springframework.stereotype.Service;
  11 +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.TkInspectionRecordDTO;
  14 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
6 15 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity;
7 16 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionRecordMapper;
8 17 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
  18 +import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService;
9 19 import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService;
10 20
  21 +import java.time.LocalDateTime;
  22 +import java.util.ArrayList;
  23 +import java.util.List;
  24 +import java.util.Map;
  25 +
11 26 @Service
12 27 @RequiredArgsConstructor
13 28 @Slf4j
14 29 public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspectionRecordMapper, TkInspectionRecordEntity>
15 30 implements TkInspectionRecordService {
  31 + private final TkInspectionDetailsService tkInspectionDetailsService;
  32 +
  33 + @Override
  34 + public TkPageData<TkInspectionRecordDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin) {
  35 + QueryWrapper<TkInspectionRecordEntity> wrapper = new QueryWrapper<>();
  36 + LambdaQueryWrapper<TkInspectionRecordEntity> lambda = wrapper.lambda();
  37 + if (queryMap != null && queryMap.get("inspectionPlanId") != null) {
  38 + lambda.eq(TkInspectionRecordEntity::getInspectionPlanId, queryMap.get("inspectionPlanId").toString());
  39 + }
  40 +
  41 + if (queryMap != null && queryMap.get("inspectorId") != null) {
  42 + lambda.eq(TkInspectionRecordEntity::getInspectorId, queryMap.get("inspectorId").toString());
  43 + }
  44 +
  45 + if (queryMap != null && queryMap.get("recordResult") != null) {
  46 + lambda.eq(TkInspectionRecordEntity::isRecordResult, queryMap.get("recordResult").toString());
  47 + }
  48 +
  49 + if (queryMap != null && queryMap.get("startTime") != null && queryMap.get("endTime") != null) {
  50 + LocalDateTime startTime = (LocalDateTime) queryMap.get("startTime");
  51 + LocalDateTime endTime = (LocalDateTime) queryMap.get("endTime");
  52 + lambda.ge(TkInspectionRecordEntity::getCheckDate, startTime);
  53 + lambda.le(TkInspectionRecordEntity::getCheckDate, endTime);
  54 + }
  55 +
  56 + IPage<TkInspectionRecordEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false),
  57 + wrapper);
  58 +
  59 + return getPageData(page, TkInspectionRecordDTO.class);
  60 + }
  61 +
  62 + @Override
  63 + public TkInspectionRecordDTO save(TkInspectionRecordDTO tkInspectionRecordDTO) {
  64 + List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList = new ArrayList<>(tkInspectionRecordDTO.getTkInspectionDetailsDTOList());
  65 + checkDto(tkInspectionRecordDTO);
  66 + TkInspectionRecordEntity entity = new TkInspectionRecordEntity();
  67 + if (StringUtils.isBlank(tkInspectionRecordDTO.getId())) {
  68 + tkInspectionRecordDTO.copyToEntity(entity);
  69 + baseMapper.insert(entity);
  70 + } else {
  71 + LambdaQueryWrapper<TkInspectionRecordEntity> filter = new QueryWrapper<TkInspectionRecordEntity>().lambda()
  72 + .eq(TkInspectionRecordEntity::getId, tkInspectionRecordDTO.getId());
  73 + entity = tkInspectionRecordDTO.getEntity(TkInspectionRecordEntity.class);
  74 + baseMapper.update(entity, filter);
  75 + }
  76 +
  77 + entity.copyToDTO(tkInspectionRecordDTO);
  78 + String id = tkInspectionRecordDTO.getId();
  79 + for (int index = 0; index < tkInspectionDetailsDTOList.size(); index++) {
  80 + if (CollectionUtils.isEmpty(tkInspectionDetailsDTOList)) {
  81 + continue;
  82 + }
  83 +
  84 + TkInspectionDetailsDTO tkInspectionDetailsDTO = tkInspectionDetailsDTOList.get(index);
  85 + tkInspectionDetailsDTO.setInspectionRecordId(id);
  86 + tkInspectionDetailsDTO.setShowOrder(index);
  87 + }
  88 +
  89 + List<TkInspectionDetailsDTO> detailsDTOList = tkInspectionDetailsService.batchSave(tkInspectionDetailsDTOList, id);
  90 + tkInspectionRecordDTO.setTkInspectionDetailsDTOList(detailsDTOList);
  91 + return tkInspectionRecordDTO;
  92 + }
  93 +
  94 + @Override
  95 + public TkInspectionRecordDTO get(String id) {
  96 + if (StringUtils.isBlank(id)) {
  97 + return new TkInspectionRecordDTO();
  98 + }
  99 +
  100 + TkInspectionRecordEntity entity = baseMapper.selectById(id);
  101 + TkInspectionRecordDTO tkInspectionRecordDTO = new TkInspectionRecordDTO();
  102 + entity.copyToDTO(tkInspectionRecordDTO);
  103 + List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList = tkInspectionDetailsService.listByInspectionRecordId(id);
  104 + tkInspectionRecordDTO.setTkInspectionDetailsDTOList(tkInspectionDetailsDTOList);
  105 + return tkInspectionRecordDTO;
  106 + }
  107 +
  108 + @Override
  109 + public boolean delete(String id) {
  110 + tkInspectionDetailsService.deleteByInspectionRecordId(id);
  111 + int count = baseMapper.deleteById(id);
  112 + return count > 0;
  113 + }
  114 +
  115 + private void checkDto(TkInspectionRecordDTO dto) {
  116 + if (StringUtils.isBlank(dto.getTenantId())) {
  117 + throw new TkDataValidationException("租户id为空!");
  118 + }
  119 + }
16 120 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO;
3 4 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity;
4 5
  6 +import java.util.List;
  7 +
5 8 public interface TkInspectionDetailsService extends BaseService<TkInspectionDetailsEntity> {
  9 +
  10 + List<TkInspectionDetailsDTO> batchSave(List<TkInspectionDetailsDTO> tkInspectionDetailsDTOList, String inspectionRecordId);
  11 +
  12 + List<TkInspectionDetailsDTO> listByInspectionRecordId(String inspectionRecordId);
  13 +
  14 + void deleteByInspectionRecordId(String inspectionRecordId);
6 15 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionRecordDTO;
  4 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
3 5 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity;
4 6
  7 +import java.util.Map;
  8 +
5 9 public interface TkInspectionRecordService extends BaseService<TkInspectionRecordEntity> {
  10 +
  11 + TkPageData<TkInspectionRecordDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin);
  12 +
  13 + TkInspectionRecordDTO save(TkInspectionRecordDTO tkInspectionRecordDTO);
  14 +
  15 + TkInspectionRecordDTO get(String id);
  16 +
  17 + boolean delete(String id);
6 18 }
... ...