Commit 7bb3467d159ee7230d29c549ef1f091a1866e32f

Authored by 胡翰林
2 parents 87973a0f a0dab040

Merge remote-tracking branch 'origin/test_hhl_0102' into test_hhl_0102

# Conflicts:
#	application/src/main/data/sql/qg.sql
Showing 19 changed files with 656 additions and 14 deletions
@@ -153,6 +153,7 @@ CREATE TABLE "public"."qg_check_details" @@ -153,6 +153,7 @@ CREATE TABLE "public"."qg_check_details"
153 "check_plan_id" varchar(36), 153 "check_plan_id" varchar(36),
154 "inspection_plan_id" varchar(36), 154 "inspection_plan_id" varchar(36),
155 "plan_details" varchar(255), 155 "plan_details" varchar(255),
  156 + "show_order" int4,
156 "tenant_id" varchar(36), 157 "tenant_id" varchar(36),
157 "create_time" timestamp(6), 158 "create_time" timestamp(6),
158 "creator" varchar(36), 159 "creator" varchar(36),
@@ -167,6 +168,7 @@ COMMENT ON COLUMN "public"."qg_check_details"."check_device_id" IS '巡检设备 @@ -167,6 +168,7 @@ COMMENT ON COLUMN "public"."qg_check_details"."check_device_id" IS '巡检设备
167 COMMENT ON COLUMN "public"."qg_check_details"."check_plan_id" IS '巡检方案'; 168 COMMENT ON COLUMN "public"."qg_check_details"."check_plan_id" IS '巡检方案';
168 COMMENT ON COLUMN "public"."qg_check_details"."inspection_plan_id" IS '巡检计划'; 169 COMMENT ON COLUMN "public"."qg_check_details"."inspection_plan_id" IS '巡检计划';
169 COMMENT ON COLUMN "public"."qg_check_details"."plan_details" IS '方案明细'; 170 COMMENT ON COLUMN "public"."qg_check_details"."plan_details" IS '方案明细';
  171 +COMMENT ON COLUMN "public"."qg_check_details"."show_order" IS '排序';
170 COMMENT ON COLUMN "public"."qg_check_details"."tenant_id" IS '租户ID'; 172 COMMENT ON COLUMN "public"."qg_check_details"."tenant_id" IS '租户ID';
171 173
172 CREATE TABLE "public"."qg_inspection_record" 174 CREATE TABLE "public"."qg_inspection_record"
@@ -195,15 +197,17 @@ COMMENT ON COLUMN "public"."qg_inspection_record"."tenant_id" IS '租户ID'; @@ -195,15 +197,17 @@ COMMENT ON COLUMN "public"."qg_inspection_record"."tenant_id" IS '租户ID';
195 197
196 CREATE TABLE "public"."qg_inspection_details" 198 CREATE TABLE "public"."qg_inspection_details"
197 ( 199 (
198 - "id" varchar(36) PRIMARY KEY,  
199 - "check_device_id" varchar(36),  
200 - "plan_details" varchar(255),  
201 - "record_result" bool,  
202 - "tenant_id" varchar(36),  
203 - "create_time" timestamp(6),  
204 - "creator" varchar(36),  
205 - "updater" varchar(36),  
206 - "update_time" timestamp(6) 200 + "id" varchar(36) PRIMARY KEY,
  201 + "check_device_id" varchar(36),
  202 + "plan_details" varchar(255),
  203 + "record_result" bool,
  204 + "show_order" int4,
  205 + "inspection_record_id" varchar(36),
  206 + "tenant_id" varchar(36),
  207 + "create_time" timestamp(6),
  208 + "creator" varchar(36),
  209 + "updater" varchar(36),
  210 + "update_time" timestamp(6)
207 ); 211 );
208 212
209 COMMENT ON TABLE "public"."qg_inspection_details" IS '巡检记录明细'; 213 COMMENT ON TABLE "public"."qg_inspection_details" IS '巡检记录明细';
@@ -211,6 +215,9 @@ COMMENT ON COLUMN "public"."qg_inspection_details"."id" IS '主键ID'; @@ -211,6 +215,9 @@ COMMENT ON COLUMN "public"."qg_inspection_details"."id" IS '主键ID';
211 COMMENT ON COLUMN "public"."qg_inspection_details"."check_device_id" IS '巡检设备'; 215 COMMENT ON COLUMN "public"."qg_inspection_details"."check_device_id" IS '巡检设备';
212 COMMENT ON COLUMN "public"."qg_inspection_details"."plan_details" IS '巡检内容'; 216 COMMENT ON COLUMN "public"."qg_inspection_details"."plan_details" IS '巡检内容';
213 COMMENT ON COLUMN "public"."qg_inspection_details"."record_result" IS '巡检结果'; 217 COMMENT ON COLUMN "public"."qg_inspection_details"."record_result" IS '巡检结果';
  218 +COMMENT ON COLUMN "public"."qg_inspection_details"."show_order" IS '排序';
  219 +COMMENT ON COLUMN "public"."qg_inspection_details"."inspection_record_id" IS '巡检记录';
  220 +COMMENT ON COLUMN "public"."qg_inspection_details"."tenant_id" IS '租户ID';
214 221
215 CREATE TABLE "public"."qg_preserve_detail" ( 222 CREATE TABLE "public"."qg_preserve_detail" (
216 "id" varchar(36) NOT NULL, 223 "id" varchar(36) NOT NULL,
@@ -39,7 +39,8 @@ public class TkCheckPlanController extends BaseController { @@ -39,7 +39,8 @@ public class TkCheckPlanController extends BaseController {
39 @RequestParam(PAGE_SIZE) int pageSize, 39 @RequestParam(PAGE_SIZE) int pageSize,
40 @RequestParam(PAGE) int page, 40 @RequestParam(PAGE) int page,
41 @RequestParam(value = "name", required = false) String name, 41 @RequestParam(value = "name", required = false) String name,
42 - @RequestParam(value = "type", required = false) TkCheckPlanTypeEnum type 42 + @RequestParam(value = "type", required = false) TkCheckPlanTypeEnum type,
  43 + @RequestParam(value = "status", required = false) TkCheckPlanStatusEnum status
43 ) throws ThingsboardException { 44 ) throws ThingsboardException {
44 Map<String, Object> queryMap = new HashMap<>(); 45 Map<String, Object> queryMap = new HashMap<>();
45 queryMap.put(PAGE_SIZE, pageSize); 46 queryMap.put(PAGE_SIZE, pageSize);
@@ -52,6 +53,10 @@ public class TkCheckPlanController extends BaseController { @@ -52,6 +53,10 @@ public class TkCheckPlanController extends BaseController {
52 queryMap.put("type", type); 53 queryMap.put("type", type);
53 } 54 }
54 55
  56 + if (status != null) {
  57 + queryMap.put("status", status);
  58 + }
  59 +
55 return tkCheckPlanService.page(queryMap, getCurrentUser().isTenantAdmin()); 60 return tkCheckPlanService.page(queryMap, getCurrentUser().isTenantAdmin());
56 } 61 }
57 62
1 package org.thingsboard.server.controller.yunteng; 1 package org.thingsboard.server.controller.yunteng;
2 2
3 import io.swagger.annotations.Api; 3 import io.swagger.annotations.Api;
  4 +import io.swagger.annotations.ApiOperation;
4 import lombok.RequiredArgsConstructor; 5 import lombok.RequiredArgsConstructor;
5 import lombok.extern.slf4j.Slf4j; 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.TkInspectionPlanDTO;
  14 +import org.thingsboard.server.common.data.yunteng.enums.TkInspectionPlanStatusEnum;
  15 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
8 import org.thingsboard.server.controller.BaseController; 16 import org.thingsboard.server.controller.BaseController;
9 import org.thingsboard.server.dao.yunteng.service.TkInspectionPlanService; 17 import org.thingsboard.server.dao.yunteng.service.TkInspectionPlanService;
10 import org.thingsboard.server.queue.util.TbCoreComponent; 18 import org.thingsboard.server.queue.util.TbCoreComponent;
11 19
  20 +import java.util.HashMap;
  21 +import java.util.Map;
  22 +
  23 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE;
  24 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE;
  25 +
12 @RestController 26 @RestController
13 @TbCoreComponent 27 @TbCoreComponent
14 @RequiredArgsConstructor 28 @RequiredArgsConstructor
@@ -18,4 +32,58 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -18,4 +32,58 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
18 public class TkInspectionPlanController extends BaseController { 32 public class TkInspectionPlanController extends BaseController {
19 private final TkInspectionPlanService tkInspectionPlanService; 33 private final TkInspectionPlanService tkInspectionPlanService;
20 34
  35 + @GetMapping(params = {PAGE_SIZE, PAGE})
  36 + @ApiOperation("分页查询")
  37 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  38 + public TkPageData<TkInspectionPlanDTO> page(
  39 + @RequestParam(PAGE_SIZE) int pageSize,
  40 + @RequestParam(PAGE) int page,
  41 + @RequestParam(value = "name", required = false) String name,
  42 + @RequestParam(value = "type", required = false) TkInspectionPlanStatusEnum status,
  43 + @RequestParam(value = "startTime", required = false) Long startTime,
  44 + @RequestParam(value = "endTime", required = false) Long endTime
  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(name)) {
  50 + queryMap.put("name", name);
  51 + }
  52 +
  53 + if (status != null) {
  54 + queryMap.put("status", status);
  55 + }
  56 +
  57 + checkTimeAndPut(queryMap, startTime, endTime);
  58 + return tkInspectionPlanService.page(queryMap, getCurrentUser().isTenantAdmin());
  59 + }
  60 +
  61 + @PostMapping("/save")
  62 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  63 + public ResponseEntity<TkInspectionPlanDTO> save(@RequestBody TkInspectionPlanDTO tkInspectionPlanDTO) throws ThingsboardException {
  64 + tkInspectionPlanDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  65 + if (tkInspectionPlanDTO.getStatus() == null) {
  66 + tkInspectionPlanDTO.setStatus(TkInspectionPlanStatusEnum.NOT_START);
  67 + }
  68 +
  69 + if (CollectionUtils.isNotEmpty(tkInspectionPlanDTO.getTkCheckDetailsDTOList())) {
  70 + tkInspectionPlanDTO.getTkCheckDetailsDTOList()
  71 + .forEach(tkCheckDetailsDTO -> tkCheckDetailsDTO.setTenantId(tkCheckDetailsDTO.getTenantId()));
  72 + }
  73 +
  74 + TkInspectionPlanDTO dto = tkInspectionPlanService.save(tkInspectionPlanDTO);
  75 + return ResponseEntity.ok(dto);
  76 + }
  77 +
  78 + @GetMapping("/detail")
  79 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  80 + public ResponseEntity<TkInspectionPlanDTO> detail(@RequestParam("id") String id) throws ThingsboardException {
  81 + return ResponseEntity.ok(tkInspectionPlanService.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(tkInspectionPlanService.delete(id));
  88 + }
21 } 89 }
1 package org.thingsboard.server.controller.yunteng; 1 package org.thingsboard.server.controller.yunteng;
2 2
3 import io.swagger.annotations.Api; 3 import io.swagger.annotations.Api;
  4 +import io.swagger.annotations.ApiOperation;
4 import lombok.RequiredArgsConstructor; 5 import lombok.RequiredArgsConstructor;
5 import lombok.extern.slf4j.Slf4j; 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 import org.thingsboard.server.controller.BaseController; 15 import org.thingsboard.server.controller.BaseController;
9 import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService; 16 import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService;
10 import org.thingsboard.server.queue.util.TbCoreComponent; 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 @RestController 25 @RestController
13 @TbCoreComponent 26 @TbCoreComponent
14 @RequiredArgsConstructor 27 @RequiredArgsConstructor
@@ -18,4 +31,60 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -18,4 +31,60 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
18 public class TkInspectionRecordController extends BaseController { 31 public class TkInspectionRecordController extends BaseController {
19 private final TkInspectionRecordService tkInspectionRecordService; 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 }
@@ -25,4 +25,7 @@ public class TkCheckDetailsDTO extends TenantDTO { @@ -25,4 +25,7 @@ public class TkCheckDetailsDTO extends TenantDTO {
25 25
26 @ApiModelProperty("方案明细") 26 @ApiModelProperty("方案明细")
27 private String planDetails; 27 private String planDetails;
  28 +
  29 + @ApiModelProperty("排序")
  30 + private int showOrder;
28 } 31 }
@@ -19,4 +19,10 @@ public class TkInspectionDetailsDTO extends TenantDTO { @@ -19,4 +19,10 @@ public class TkInspectionDetailsDTO extends TenantDTO {
19 19
20 @ApiModelProperty("巡检结果") 20 @ApiModelProperty("巡检结果")
21 private boolean recordResult; 21 private boolean recordResult;
  22 +
  23 + @ApiModelProperty("巡检记录")
  24 + private String inspectionRecordId;
  25 +
  26 + @ApiModelProperty("排序")
  27 + private int showOrder;
22 } 28 }
@@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode; @@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode;
9 import org.thingsboard.server.common.data.yunteng.enums.TkInspectionPlanStatusEnum; 9 import org.thingsboard.server.common.data.yunteng.enums.TkInspectionPlanStatusEnum;
10 10
11 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
  12 +import java.util.List;
12 13
13 /** 14 /**
14 * 巡检计划 15 * 巡检计划
@@ -38,4 +39,7 @@ public class TkInspectionPlanDTO extends TenantDTO { @@ -38,4 +39,7 @@ public class TkInspectionPlanDTO extends TenantDTO {
38 39
39 @ApiModelProperty("计划备注") 40 @ApiModelProperty("计划备注")
40 private String remark; 41 private String remark;
  42 +
  43 + @ApiModelProperty("巡检明细")
  44 + private List<TkCheckDetailsDTO> tkCheckDetailsDTOList;
41 } 45 }
@@ -8,6 +8,7 @@ import lombok.Data; @@ -8,6 +8,7 @@ import lombok.Data;
8 import lombok.EqualsAndHashCode; 8 import lombok.EqualsAndHashCode;
9 9
10 import java.time.LocalDateTime; 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,4 +33,17 @@ public class TkInspectionRecordDTO extends TenantDTO {
32 33
33 @ApiModelProperty("巡检结果") 34 @ApiModelProperty("巡检结果")
34 private boolean recordResult; 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 }
@@ -37,4 +37,9 @@ public class TkCheckDetailsEntity extends TenantBaseEntity { @@ -37,4 +37,9 @@ public class TkCheckDetailsEntity extends TenantBaseEntity {
37 * 方案明细 37 * 方案明细
38 */ 38 */
39 private String planDetails; 39 private String planDetails;
  40 +
  41 + /**
  42 + * 排序
  43 + */
  44 + private int showOrder;
40 } 45 }
@@ -27,4 +27,14 @@ public class TkInspectionDetailsEntity extends TenantBaseEntity { @@ -27,4 +27,14 @@ public class TkInspectionDetailsEntity extends TenantBaseEntity {
27 * 巡检结果 27 * 巡检结果
28 */ 28 */
29 private boolean recordResult; 29 private boolean recordResult;
  30 +
  31 + /**
  32 + * 巡检记录
  33 + */
  34 + private String inspectionRecordId;
  35 +
  36 + /**
  37 + * 排序
  38 + */
  39 + private int showOrder;
30 } 40 }
1 package org.thingsboard.server.dao.yunteng.impl; 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 import lombok.RequiredArgsConstructor; 5 import lombok.RequiredArgsConstructor;
4 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.commons.collections4.CollectionUtils;
  8 +import org.apache.commons.lang3.StringUtils;
5 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
  10 +import org.thingsboard.server.common.data.yunteng.dto.TkCheckDetailsDTO;
6 import org.thingsboard.server.dao.yunteng.entities.TkCheckDetailsEntity; 11 import org.thingsboard.server.dao.yunteng.entities.TkCheckDetailsEntity;
7 import org.thingsboard.server.dao.yunteng.mapper.TkCheckDetailsMapper; 12 import org.thingsboard.server.dao.yunteng.mapper.TkCheckDetailsMapper;
8 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; 13 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
9 import org.thingsboard.server.dao.yunteng.service.TkCheckDetailsService; 14 import org.thingsboard.server.dao.yunteng.service.TkCheckDetailsService;
10 15
  16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +import java.util.stream.Collectors;
  19 +
11 @Service 20 @Service
12 @RequiredArgsConstructor 21 @RequiredArgsConstructor
13 @Slf4j 22 @Slf4j
14 public class TkCheckDetailsServiceImpl extends AbstractBaseService<TkCheckDetailsMapper, TkCheckDetailsEntity> 23 public class TkCheckDetailsServiceImpl extends AbstractBaseService<TkCheckDetailsMapper, TkCheckDetailsEntity>
15 implements TkCheckDetailsService { 24 implements TkCheckDetailsService {
  25 + @Override
  26 + public List<TkCheckDetailsDTO> batchSave(List<TkCheckDetailsDTO> checkDetailsDTOList, String inspectionPlanId) {
  27 + List<TkCheckDetailsDTO> oldTkCheckDetailsDTOList = listByInspectionPlanId(inspectionPlanId);
  28 + if (CollectionUtils.isEmpty(checkDetailsDTOList) && CollectionUtils.isNotEmpty(oldTkCheckDetailsDTOList)) {
  29 + List<String> checkDetailsIdList = oldTkCheckDetailsDTOList.stream()
  30 + .map(TkCheckDetailsDTO::getId)
  31 + .collect(Collectors.toList());
  32 + baseMapper.deleteBatchIds(checkDetailsIdList);
  33 + return new ArrayList<>(0);
  34 + }
  35 +
  36 + if (CollectionUtils.isEmpty(oldTkCheckDetailsDTOList) && CollectionUtils.isNotEmpty(checkDetailsDTOList)) {
  37 + List<TkCheckDetailsEntity> tkCheckDetailsEntityList = checkDetailsDTOList.stream().map(checkDetailsDTO -> {
  38 + TkCheckDetailsEntity entity = new TkCheckDetailsEntity();
  39 + checkDetailsDTO.copyToEntity(entity);
  40 + return entity;
  41 + }).collect(Collectors.toList());
  42 +
  43 + insertBatch(tkCheckDetailsEntityList, TkCheckDetailsEntity.class);
  44 + return listByInspectionPlanId(inspectionPlanId);
  45 + }
  46 +
  47 + List<TkCheckDetailsEntity> addEntityList = new ArrayList<>(checkDetailsDTOList.size());
  48 + List<TkCheckDetailsEntity> updateEntityList = new ArrayList<>(checkDetailsDTOList.size());
  49 + List<String> needDeleteIdList = new ArrayList<>(checkDetailsDTOList.size());
  50 + List<String> checkDetailsIdList = CollectionUtils.emptyIfNull(oldTkCheckDetailsDTOList).stream()
  51 + .map(TkCheckDetailsDTO::getId)
  52 + .collect(Collectors.toList());
  53 + for (TkCheckDetailsDTO tkCheckDetailsDTO : checkDetailsDTOList) {
  54 + TkCheckDetailsEntity entity = new TkCheckDetailsEntity();
  55 + tkCheckDetailsDTO.copyToEntity(entity);
  56 + if (StringUtils.isBlank(entity.getId())) {
  57 + addEntityList.add(entity);
  58 + continue;
  59 + }
  60 +
  61 + if (checkDetailsIdList.contains(entity.getId())) {
  62 + updateEntityList.add(entity);
  63 + }
  64 + }
  65 +
  66 +
  67 + if (CollectionUtils.isNotEmpty(addEntityList)) {
  68 + insertBatch(addEntityList, TkCheckDetailsEntity.class);
  69 + }
  70 +
  71 + if (CollectionUtils.isNotEmpty(updateEntityList)) {
  72 + updateEntityList.forEach(tkCheckDetailsEntity -> baseMapper.updateById(tkCheckDetailsEntity));
  73 + List<String> updateIdList = updateEntityList.stream().map(TkCheckDetailsEntity::getId).collect(Collectors.toList());
  74 + checkDetailsIdList.removeAll(updateIdList);
  75 + needDeleteIdList.addAll(checkDetailsIdList);
  76 + } else {
  77 + needDeleteIdList = checkDetailsIdList;
  78 + }
  79 +
  80 + if (CollectionUtils.isNotEmpty(needDeleteIdList)) {
  81 + baseMapper.deleteBatchIds(needDeleteIdList);
  82 + }
  83 +
  84 + return listByInspectionPlanId(inspectionPlanId);
  85 + }
  86 +
  87 + @Override
  88 + public List<TkCheckDetailsDTO> listByInspectionPlanId(String inspectionPlanId) {
  89 + if (StringUtils.isBlank(inspectionPlanId)) {
  90 + return new ArrayList<>(0);
  91 + }
  92 +
  93 + QueryWrapper<TkCheckDetailsEntity> wrapper = new QueryWrapper<>();
  94 + LambdaQueryWrapper<TkCheckDetailsEntity> lambda = wrapper.lambda();
  95 + lambda.eq(TkCheckDetailsEntity::getInspectionPlanId, inspectionPlanId);
  96 + lambda.orderByAsc(TkCheckDetailsEntity::getShowOrder);
  97 + List<TkCheckDetailsEntity> tkCheckDetailsEntitieList = baseMapper.selectList(wrapper);
  98 + return CollectionUtils.emptyIfNull(tkCheckDetailsEntitieList).stream().map(entity -> {
  99 + TkCheckDetailsDTO tkCheckDetailsDTO = new TkCheckDetailsDTO();
  100 + entity.copyToDTO(tkCheckDetailsDTO);
  101 + return tkCheckDetailsDTO;
  102 + }).collect(Collectors.toList());
  103 + }
  104 +
  105 + @Override
  106 + public void deleteByInspectionPlanId(String inspectionPlanId) {
  107 + if (StringUtils.isBlank(inspectionPlanId)) {
  108 + return;
  109 + }
  110 +
  111 + QueryWrapper<TkCheckDetailsEntity> wrapper = new QueryWrapper<>();
  112 + LambdaQueryWrapper<TkCheckDetailsEntity> lambda = wrapper.lambda();
  113 + lambda.eq(TkCheckDetailsEntity::getInspectionPlanId, inspectionPlanId);
  114 + baseMapper.delete(wrapper);
  115 + }
16 } 116 }
@@ -34,6 +34,10 @@ public class TkCheckPlanServiceImpl extends AbstractBaseService<TkCheckPlanMappe @@ -34,6 +34,10 @@ public class TkCheckPlanServiceImpl extends AbstractBaseService<TkCheckPlanMappe
34 lambda.eq(TkCheckPlanEntity::getType, queryMap.get("type").toString()); 34 lambda.eq(TkCheckPlanEntity::getType, queryMap.get("type").toString());
35 } 35 }
36 36
  37 + if (queryMap != null && queryMap.get("status") != null) {
  38 + lambda.eq(TkCheckPlanEntity::getStatus, queryMap.get("status").toString());
  39 + }
  40 +
37 IPage<TkCheckPlanEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false), 41 IPage<TkCheckPlanEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false),
38 wrapper); 42 wrapper);
39 43
1 package org.thingsboard.server.dao.yunteng.impl; 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 import lombok.RequiredArgsConstructor; 5 import lombok.RequiredArgsConstructor;
4 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.commons.collections4.CollectionUtils;
  8 +import org.apache.commons.lang3.StringUtils;
5 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
  10 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO;
6 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity; 11 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity;
7 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionDetailsMapper; 12 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionDetailsMapper;
8 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; 13 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
9 import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService; 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 @Service 20 @Service
12 @RequiredArgsConstructor 21 @RequiredArgsConstructor
13 @Slf4j 22 @Slf4j
14 public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspectionDetailsMapper, TkInspectionDetailsEntity> 23 public class TkInspectionDetailsServiceImpl extends AbstractBaseService<TkInspectionDetailsMapper, TkInspectionDetailsEntity>
15 implements TkInspectionDetailsService { 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 package org.thingsboard.server.dao.yunteng.impl; 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 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
4 import lombok.extern.slf4j.Slf4j; 7 import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.collections4.CollectionUtils;
  9 +import org.apache.commons.lang3.StringUtils;
5 import org.springframework.stereotype.Service; 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.TkCheckDetailsDTO;
  13 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO;
  14 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
6 import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; 15 import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity;
7 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionPlanMapper; 16 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionPlanMapper;
8 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; 17 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
  18 +import org.thingsboard.server.dao.yunteng.service.TkCheckDetailsService;
9 import org.thingsboard.server.dao.yunteng.service.TkInspectionPlanService; 19 import org.thingsboard.server.dao.yunteng.service.TkInspectionPlanService;
  20 +import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService;
  21 +
  22 +import java.time.LocalDateTime;
  23 +import java.util.ArrayList;
  24 +import java.util.List;
  25 +import java.util.Map;
10 26
11 @Service 27 @Service
12 @RequiredArgsConstructor 28 @RequiredArgsConstructor
13 @Slf4j 29 @Slf4j
14 public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectionPlanMapper, TkInspectionPlanEntity> 30 public class TkInspectionPlanServiceImpl extends AbstractBaseService<TkInspectionPlanMapper, TkInspectionPlanEntity>
15 implements TkInspectionPlanService { 31 implements TkInspectionPlanService {
  32 + private final TkCheckDetailsService tkCheckDetailsService;
  33 + private final TkInspectionRecordService tkInspectionRecordService;
  34 +
  35 + @Override
  36 + public TkPageData<TkInspectionPlanDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin) {
  37 + QueryWrapper<TkInspectionPlanEntity> wrapper = new QueryWrapper<>();
  38 + LambdaQueryWrapper<TkInspectionPlanEntity> lambda = wrapper.lambda();
  39 + if (queryMap != null && queryMap.get("name") != null) {
  40 + lambda.eq(TkInspectionPlanEntity::getName, queryMap.get("name").toString());
  41 + }
  42 +
  43 + if (queryMap != null && queryMap.get("status") != null) {
  44 + lambda.eq(TkInspectionPlanEntity::getStatus, queryMap.get("status").toString());
  45 + }
  46 +
  47 + if (queryMap != null && queryMap.get("startTime") != null && queryMap.get("endTime") != null) {
  48 + LocalDateTime startTime = (LocalDateTime) queryMap.get("startTime");
  49 + LocalDateTime endTime = (LocalDateTime) queryMap.get("endTime");
  50 + lambda.ge(TkInspectionPlanEntity::getStartTime, startTime);
  51 + lambda.le(TkInspectionPlanEntity::getEndTime, endTime);
  52 + }
  53 +
  54 + IPage<TkInspectionPlanEntity> page = baseMapper.selectPage(getPage(queryMap, "create_time", false),
  55 + wrapper);
  56 +
  57 + return getPageData(page, TkInspectionPlanDTO.class);
  58 + }
  59 +
  60 + @Override
  61 + public TkInspectionPlanDTO save(TkInspectionPlanDTO tkInspectionPlanDTO) {
  62 + List<TkCheckDetailsDTO> checkDetailsDTOList = new ArrayList<>(tkInspectionPlanDTO.getTkCheckDetailsDTOList());
  63 + checkDto(tkInspectionPlanDTO);
  64 + TkInspectionPlanEntity entity = new TkInspectionPlanEntity();
  65 + if (StringUtils.isBlank(tkInspectionPlanDTO.getId())) {
  66 + tkInspectionPlanDTO.copyToEntity(entity);
  67 + baseMapper.insert(entity);
  68 + } else {
  69 + LambdaQueryWrapper<TkInspectionPlanEntity> filter = new QueryWrapper<TkInspectionPlanEntity>().lambda()
  70 + .eq(TkInspectionPlanEntity::getId, tkInspectionPlanDTO.getId());
  71 + entity = tkInspectionPlanDTO.getEntity(TkInspectionPlanEntity.class);
  72 + baseMapper.update(entity, filter);
  73 + }
  74 +
  75 + entity.copyToDTO(tkInspectionPlanDTO);
  76 + String id = tkInspectionPlanDTO.getId();
  77 + for (int index = 0; index < checkDetailsDTOList.size(); index++) {
  78 + if (CollectionUtils.isEmpty(checkDetailsDTOList)) {
  79 + continue;
  80 + }
  81 +
  82 + TkCheckDetailsDTO checkDetailsDTO = checkDetailsDTOList.get(index);
  83 + checkDetailsDTO.setInspectionPlanId(id);
  84 + checkDetailsDTO.setShowOrder(index);
  85 + }
  86 +
  87 + List<TkCheckDetailsDTO> tkCheckDetailsDTOList = tkCheckDetailsService.batchSave(checkDetailsDTOList, id);
  88 + tkInspectionPlanDTO.setTkCheckDetailsDTOList(tkCheckDetailsDTOList);
  89 + return tkInspectionPlanDTO;
  90 + }
  91 +
  92 + @Override
  93 + public TkInspectionPlanDTO get(String id) {
  94 + if (StringUtils.isBlank(id)) {
  95 + return new TkInspectionPlanDTO();
  96 + }
  97 +
  98 + TkInspectionPlanEntity entity = baseMapper.selectById(id);
  99 + TkInspectionPlanDTO tkInspectionPlanDTO = new TkInspectionPlanDTO();
  100 + entity.copyToDTO(tkInspectionPlanDTO);
  101 + List<TkCheckDetailsDTO> checkDetailsDTOList = tkCheckDetailsService.listByInspectionPlanId(id);
  102 + tkInspectionPlanDTO.setTkCheckDetailsDTOList(checkDetailsDTOList);
  103 + return tkInspectionPlanDTO;
  104 + }
  105 +
  106 + @Override
  107 + public boolean delete(String id) {
  108 + tkCheckDetailsService.deleteByInspectionPlanId(id);
  109 + int count = baseMapper.deleteById(id);
  110 + return count > 0;
  111 + }
  112 +
  113 + private void checkDto(TkInspectionPlanDTO dto) {
  114 + if (StringUtils.isBlank(dto.getTenantId())) {
  115 + throw new TkDataValidationException("租户id为空!");
  116 + }
  117 + }
16 } 118 }
1 package org.thingsboard.server.dao.yunteng.impl; 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 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
4 import lombok.extern.slf4j.Slf4j; 7 import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.collections4.CollectionUtils;
  9 +import org.apache.commons.lang3.StringUtils;
5 import org.springframework.stereotype.Service; 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 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; 15 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity;
7 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionRecordMapper; 16 import org.thingsboard.server.dao.yunteng.mapper.TkInspectionRecordMapper;
8 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; 17 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
  18 +import org.thingsboard.server.dao.yunteng.service.TkInspectionDetailsService;
9 import org.thingsboard.server.dao.yunteng.service.TkInspectionRecordService; 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 @Service 26 @Service
12 @RequiredArgsConstructor 27 @RequiredArgsConstructor
13 @Slf4j 28 @Slf4j
14 public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspectionRecordMapper, TkInspectionRecordEntity> 29 public class TkInspectionRecordServiceImpl extends AbstractBaseService<TkInspectionRecordMapper, TkInspectionRecordEntity>
15 implements TkInspectionRecordService { 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 package org.thingsboard.server.dao.yunteng.service; 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.dto.TkCheckDetailsDTO;
3 import org.thingsboard.server.dao.yunteng.entities.TkCheckDetailsEntity; 4 import org.thingsboard.server.dao.yunteng.entities.TkCheckDetailsEntity;
4 5
  6 +import java.util.List;
  7 +
5 public interface TkCheckDetailsService extends BaseService<TkCheckDetailsEntity> { 8 public interface TkCheckDetailsService extends BaseService<TkCheckDetailsEntity> {
  9 +
  10 + List<TkCheckDetailsDTO> batchSave(List<TkCheckDetailsDTO> checkDetailsDTOList, String inspectionPlanId);
  11 +
  12 + List<TkCheckDetailsDTO> listByInspectionPlanId(String inspectionPlanId);
  13 +
  14 + void deleteByInspectionPlanId(String inspectionPlanId);
6 } 15 }
1 package org.thingsboard.server.dao.yunteng.service; 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionDetailsDTO;
3 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity; 4 import org.thingsboard.server.dao.yunteng.entities.TkInspectionDetailsEntity;
4 5
  6 +import java.util.List;
  7 +
5 public interface TkInspectionDetailsService extends BaseService<TkInspectionDetailsEntity> { 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 package org.thingsboard.server.dao.yunteng.service; 1 package org.thingsboard.server.dao.yunteng.service;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.dto.TkInspectionPlanDTO;
  4 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
3 import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity; 5 import org.thingsboard.server.dao.yunteng.entities.TkInspectionPlanEntity;
4 6
  7 +import java.util.Map;
  8 +
5 public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEntity> { 9 public interface TkInspectionPlanService extends BaseService<TkInspectionPlanEntity> {
  10 +
  11 + TkPageData<TkInspectionPlanDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin);
  12 +
  13 + TkInspectionPlanDTO save(TkInspectionPlanDTO tkInspectionPlanDTO);
  14 +
  15 + TkInspectionPlanDTO get(String id);
  16 +
  17 + boolean delete(String id);
6 } 18 }
1 package org.thingsboard.server.dao.yunteng.service; 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 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity; 5 import org.thingsboard.server.dao.yunteng.entities.TkInspectionRecordEntity;
4 6
  7 +import java.util.Map;
  8 +
5 public interface TkInspectionRecordService extends BaseService<TkInspectionRecordEntity> { 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 }