Showing
24 changed files
with
1105 additions
and
0 deletions
application/src/main/data/sql/qg.sql
0 → 100644
1 | +CREATE TABLE "public"."qg_malfunction_reason" ( | |
2 | + "id" varchar(36) NOT NULL, | |
3 | + "code" varchar(50), | |
4 | + "reason" varchar(200), | |
5 | + "tenant_id" varchar(36), | |
6 | + "create_time" timestamp(6), | |
7 | + "creator" varchar(36), | |
8 | + "updater" varchar(36), | |
9 | + "update_time" timestamp(6), | |
10 | + "remark" varchar(255), | |
11 | + CONSTRAINT "qg_malfunction_reason_pkey" PRIMARY KEY ("id") | |
12 | +); | |
13 | + | |
14 | +ALTER TABLE "public"."qg_malfunction_reason" OWNER TO "postgres"; | |
15 | + | |
16 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."id" IS '主键ID'; | |
17 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."code" IS '故障编码'; | |
18 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."reason" IS '故障原因'; | |
19 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."tenant_id" IS '租户ID'; | |
20 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."create_time" IS '创建时间'; | |
21 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."updater" IS '更新用户'; | |
22 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."update_time" IS '更新时间'; | |
23 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."creator" IS '创建用户'; | |
24 | + | |
25 | + | |
26 | +ALTER TABLE device | |
27 | + ADD COLUMN IF NOT EXISTS director_id varchar(36); | |
28 | + | |
29 | +COMMENT ON COLUMN "public"."device"."director_id" IS '负责人id'; | |
30 | + | |
31 | + | |
32 | +CREATE TABLE "public"."qg_repair_order" ( | |
33 | + "id" varchar(36) NOT NULL, | |
34 | + "device_id" varchar(36), | |
35 | + "report_date" timestamp(6), | |
36 | + "report_by" varchar(36), | |
37 | + "status" varchar(50), | |
38 | + "emergency" bool, | |
39 | + "situation_img" varchar(200), | |
40 | + "description" varchar(500), | |
41 | + "tenant_id" varchar(36), | |
42 | + "create_time" timestamp(6), | |
43 | + "creator" varchar(36), | |
44 | + "updater" varchar(36), | |
45 | + "update_time" timestamp(6), | |
46 | + "remark" varchar(255), | |
47 | + CONSTRAINT "qg_repair_order_pkey" PRIMARY KEY ("id") | |
48 | +); | |
49 | + | |
50 | +ALTER TABLE "public"."qg_repair_order" OWNER TO "postgres"; | |
51 | + | |
52 | +COMMENT ON COLUMN "public"."qg_repair_order"."id" IS '主键ID'; | |
53 | +COMMENT ON COLUMN "public"."qg_repair_order"."device_id" IS '设备id'; | |
54 | +COMMENT ON COLUMN "public"."qg_repair_order"."report_date" IS '报修时间'; | |
55 | +COMMENT ON COLUMN "public"."qg_repair_order"."report_by" IS '报修人'; | |
56 | +COMMENT ON COLUMN "public"."qg_repair_order"."report_by" IS '报修人'; | |
57 | +COMMENT ON COLUMN "public"."qg_repair_order"."status" IS '工单状态'; | |
58 | +COMMENT ON COLUMN "public"."qg_repair_order"."emergency" IS '是否紧急'; | |
59 | +COMMENT ON COLUMN "public"."qg_repair_order"."situation_img" IS 'situation_img'; | |
60 | +COMMENT ON COLUMN "public"."qg_repair_order"."tenant_id" IS '租户ID'; | |
61 | +COMMENT ON COLUMN "public"."qg_repair_order"."create_time" IS '创建时间'; | |
62 | +COMMENT ON COLUMN "public"."qg_repair_order"."updater" IS '更新用户'; | |
63 | +COMMENT ON COLUMN "public"."qg_repair_order"."update_time" IS '更新时间'; | |
64 | +COMMENT ON COLUMN "public"."qg_repair_order"."creator" IS '创建用户'; | |
65 | + | |
66 | + | |
67 | +CREATE TABLE "public"."qg_repair_record" ( | |
68 | + "id" varchar(36) NOT NULL, | |
69 | + "order_id" varchar(36), | |
70 | + "repair_date" timestamp(6), | |
71 | + "repair_by" varchar(36), | |
72 | + "description" varchar(500), | |
73 | + "tenant_id" varchar(36), | |
74 | + "create_time" timestamp(6), | |
75 | + "creator" varchar(36), | |
76 | + "updater" varchar(36), | |
77 | + "update_time" timestamp(6), | |
78 | + "remark" varchar(255), | |
79 | + CONSTRAINT "qg_repair_record_pkey" PRIMARY KEY ("id") | |
80 | +); | |
81 | + | |
82 | +ALTER TABLE "public"."qg_repair_record" OWNER TO "postgres"; | |
83 | + | |
84 | +COMMENT ON COLUMN "public"."qg_repair_record"."id" IS '主键ID'; | |
85 | +COMMENT ON COLUMN "public"."qg_repair_record"."order_id" IS '维修工单id'; | |
86 | +COMMENT ON COLUMN "public"."qg_repair_record"."repair_date" IS '维修时间'; | |
87 | +COMMENT ON COLUMN "public"."qg_repair_record"."repair_by" IS '维修人'; | |
88 | +COMMENT ON COLUMN "public"."qg_repair_record"."description" IS '维修情况说明'; | |
89 | +COMMENT ON COLUMN "public"."qg_repair_record"."tenant_id" IS '租户ID'; | |
90 | +COMMENT ON COLUMN "public"."qg_repair_record"."create_time" IS '创建时间'; | |
91 | +COMMENT ON COLUMN "public"."qg_repair_record"."updater" IS '更新用户'; | |
92 | +COMMENT ON COLUMN "public"."qg_repair_record"."update_time" IS '更新时间'; | |
93 | +COMMENT ON COLUMN "public"."qg_repair_record"."creator" IS '创建用户'; | |
\ No newline at end of file | ... | ... |
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import io.swagger.annotations.Api; | |
4 | +import io.swagger.annotations.ApiOperation; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.springframework.http.ResponseEntity; | |
8 | +import org.springframework.security.access.prepost.PreAuthorize; | |
9 | +import org.springframework.web.bind.annotation.*; | |
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
11 | +import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; | |
12 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
13 | +import org.thingsboard.server.controller.BaseController; | |
14 | +import org.thingsboard.server.dao.yunteng.service.TkMalfunctionReasonService; | |
15 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
16 | + | |
17 | +import java.util.List; | |
18 | +import java.util.Map; | |
19 | + | |
20 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
21 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
22 | + | |
23 | +@RestController | |
24 | +@TbCoreComponent | |
25 | +@RequiredArgsConstructor | |
26 | +@RequestMapping("api/yt/mr") | |
27 | +@Api(tags = {"故障原因管理"}) | |
28 | +@Slf4j | |
29 | +public class TkMalfunctionReasonController extends BaseController { | |
30 | + private final TkMalfunctionReasonService tkMalfunctionReasonService; | |
31 | + | |
32 | + @PostMapping("/pageData") | |
33 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
34 | + @ApiOperation("获取满足条件的所有设备") | |
35 | + public TkPageData<TkMalfunctionReasonDTO> pageMalfunctionReason( | |
36 | + @RequestParam(PAGE_SIZE) int pageSize, | |
37 | + @RequestParam(PAGE) int page, | |
38 | + @RequestBody Map<String, Object> queryMap) | |
39 | + throws ThingsboardException { | |
40 | + queryMap.put(PAGE, page); | |
41 | + queryMap.put(PAGE_SIZE, pageSize); | |
42 | + return tkMalfunctionReasonService.page(getCurrentUser().getCurrentTenantId(), queryMap); | |
43 | + } | |
44 | + | |
45 | + @PostMapping("/list") | |
46 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
47 | + @ApiOperation("获取满足条件的所有设备") | |
48 | + public List<TkMalfunctionReasonDTO> list( | |
49 | + @RequestBody Map<String, Object> queryMap) throws ThingsboardException { | |
50 | + | |
51 | + return tkMalfunctionReasonService.list(getCurrentUser().getCurrentTenantId(), queryMap); | |
52 | + } | |
53 | + | |
54 | + @PostMapping("/save") | |
55 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
56 | + public ResponseEntity<TkMalfunctionReasonDTO> save(@RequestBody TkMalfunctionReasonDTO tkMalfunctionReasonDTO) throws ThingsboardException { | |
57 | + tkMalfunctionReasonDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | |
58 | + TkMalfunctionReasonDTO deviceDTO = tkMalfunctionReasonService.save(tkMalfunctionReasonDTO); | |
59 | + return ResponseEntity.ok(deviceDTO); | |
60 | + } | |
61 | + | |
62 | + @GetMapping("/delete") | |
63 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
64 | + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { | |
65 | + return ResponseEntity.ok(tkMalfunctionReasonService.delete(id)); | |
66 | + } | |
67 | + | |
68 | + | |
69 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/TkRepairOrderController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import io.swagger.annotations.Api; | |
4 | +import io.swagger.annotations.ApiOperation; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.http.ResponseEntity; | |
9 | +import org.springframework.security.access.prepost.PreAuthorize; | |
10 | +import org.springframework.web.bind.annotation.*; | |
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.RepairOrderStatusEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
17 | +import org.thingsboard.server.controller.BaseController; | |
18 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceService; | |
19 | +import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService; | |
20 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
21 | + | |
22 | +import java.util.UUID; | |
23 | + | |
24 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
25 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
26 | + | |
27 | +@RestController | |
28 | +@TbCoreComponent | |
29 | +@RequiredArgsConstructor | |
30 | +@RequestMapping("api/yt/repairOrder") | |
31 | +@Api(tags = {"维修工单管理"}) | |
32 | +@Slf4j | |
33 | +public class TkRepairOrderController extends BaseController { | |
34 | + | |
35 | + private final TkRepairOrderService tkRepairOrderService; | |
36 | + | |
37 | + private final TkDeviceService tkdeviceService; | |
38 | + | |
39 | + @PostMapping("/save") | |
40 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
41 | + @ApiOperation("维修工单保存") | |
42 | + public ResponseEntity<TkRepairOrderDTO> save(@RequestBody TkRepairOrderDTO dto) throws ThingsboardException { | |
43 | + String currentTenantId = getCurrentUser().getCurrentTenantId(); | |
44 | + dto.setTenantId(currentTenantId); | |
45 | + if (StringUtils.isNotBlank(dto.getDeviceId())) { | |
46 | + DeviceDTO deviceInfo = tkdeviceService.checkDeviceByTenantIdAndDeviceId | |
47 | + (UUID.fromString(currentTenantId), UUID.fromString(dto.getDeviceId())); | |
48 | + if (deviceInfo == null) { | |
49 | + throw new TkDataValidationException("设备不存在!"); | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + if (StringUtils.isBlank(dto.getId())) { | |
54 | + TkRepairOrderDTO roInfo = tkRepairOrderService.loadByDeviceId(dto.getDeviceId()); | |
55 | + if (roInfo != null && RepairOrderStatusEnum.valueOf(roInfo.getStatus()) == RepairOrderStatusEnum.SCHEDULING) { | |
56 | + throw new TkDataValidationException("该设备已报修!"); | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + if (StringUtils.isBlank(dto.getStatus())) { | |
61 | + dto.setStatus(RepairOrderStatusEnum.SCHEDULING.name()); | |
62 | + } | |
63 | + | |
64 | + TkRepairOrderDTO deviceDTO = tkRepairOrderService.save(dto); | |
65 | + return ResponseEntity.ok(deviceDTO); | |
66 | + } | |
67 | + | |
68 | + @GetMapping("/delete") | |
69 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
70 | + @ApiOperation("维修工单删除") | |
71 | + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { | |
72 | + return ResponseEntity.ok(tkRepairOrderService.delete(id)); | |
73 | + } | |
74 | + | |
75 | + @GetMapping("/detail") | |
76 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
77 | + @ApiOperation("维修工单详情") | |
78 | + public ResponseEntity<TkRepairOrderDTO> detail(@RequestParam("id") String id) throws ThingsboardException { | |
79 | + TkRepairOrderDTO deviceDTO = tkRepairOrderService.detail(id); | |
80 | + return ResponseEntity.ok(deviceDTO); | |
81 | + } | |
82 | + | |
83 | + @PostMapping("/pageData") | |
84 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
85 | + @ApiOperation("维修工单列表") | |
86 | + public TkPageData<TkRepairOrderDTO> pageMalfunctionReason( | |
87 | + @RequestParam(PAGE_SIZE) int pageSize, | |
88 | + @RequestParam(PAGE) int page, | |
89 | + @RequestBody TkRepairOrderDTO params) | |
90 | + throws ThingsboardException { | |
91 | + params.setPage(page); | |
92 | + params.setPageSize(pageSize); | |
93 | + return tkRepairOrderService.page(getCurrentUser().getCurrentTenantId(), params); | |
94 | + } | |
95 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/TkRepairRecordController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import io.swagger.annotations.Api; | |
4 | +import io.swagger.annotations.ApiOperation; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.http.ResponseEntity; | |
9 | +import org.springframework.security.access.prepost.PreAuthorize; | |
10 | +import org.springframework.web.bind.annotation.*; | |
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairRecordDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.RepairOrderStatusEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
17 | +import org.thingsboard.server.controller.BaseController; | |
18 | +import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService; | |
19 | +import org.thingsboard.server.dao.yunteng.service.TkRepairRecordService; | |
20 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
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 | + | |
25 | +@RestController | |
26 | +@TbCoreComponent | |
27 | +@RequiredArgsConstructor | |
28 | +@RequestMapping("api/yt/repairRecord") | |
29 | +@Api(tags = {"维修记录"}) | |
30 | +@Slf4j | |
31 | +public class TkRepairRecordController extends BaseController { | |
32 | + private final TkRepairRecordService tkRepairRecordService; | |
33 | + | |
34 | + private final TkRepairOrderService tkRepairOrderService; | |
35 | + | |
36 | + @PostMapping("/save") | |
37 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
38 | + @ApiOperation("维修记录保存") | |
39 | + public ResponseEntity<TkRepairRecordDTO> save(@RequestBody TkRepairRecordDTO dto) throws ThingsboardException { | |
40 | + String currentTenantId = getCurrentUser().getCurrentTenantId(); | |
41 | + dto.setTenantId(currentTenantId); | |
42 | + if (StringUtils.isNotBlank(dto.getOrderId())) { | |
43 | + TkRepairOrderDTO repairOrderDTO = tkRepairOrderService.load(dto.getOrderId()); | |
44 | + if (repairOrderDTO == null) { | |
45 | + throw new TkDataValidationException("维修工单不存在!"); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + | |
50 | + TkRepairRecordDTO deviceDTO = tkRepairRecordService.save(dto); | |
51 | + | |
52 | + tkRepairOrderService.updateStatus(dto.getOrderId(),RepairOrderStatusEnum.REPAIRFINISH.name()); | |
53 | + return ResponseEntity.ok(deviceDTO); | |
54 | + } | |
55 | + | |
56 | + @GetMapping("/delete") | |
57 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
58 | + @ApiOperation("维修记录删除") | |
59 | + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { | |
60 | + return ResponseEntity.ok(tkRepairRecordService.delete(id)); | |
61 | + } | |
62 | + | |
63 | + @GetMapping("/detail") | |
64 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
65 | + @ApiOperation("维修记录详情") | |
66 | + public ResponseEntity<TkRepairRecordDTO> detail(@RequestParam("id") String id) throws ThingsboardException { | |
67 | + TkRepairRecordDTO dto = tkRepairRecordService.detail(id); | |
68 | + return ResponseEntity.ok(dto); | |
69 | + } | |
70 | + | |
71 | + @PostMapping("/pageData") | |
72 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
73 | + @ApiOperation("维修工单列表") | |
74 | + public TkPageData<TkRepairRecordDTO> page( | |
75 | + @RequestParam(PAGE_SIZE) int pageSize, | |
76 | + @RequestParam(PAGE) int page, | |
77 | + @RequestBody TkRepairRecordDTO params) | |
78 | + throws ThingsboardException { | |
79 | + params.setPage(page); | |
80 | + params.setPageSize(pageSize); | |
81 | + return tkRepairRecordService.page(getCurrentUser().getCurrentTenantId(), params); | |
82 | + } | |
83 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkMalfunctionReasonDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | + | |
7 | +@EqualsAndHashCode(callSuper = true) | |
8 | +@Data | |
9 | +public class TkMalfunctionReasonDTO extends TenantDTO { | |
10 | + | |
11 | + @ApiModelProperty(value = "故障编码") | |
12 | + private String code; | |
13 | + | |
14 | + @ApiModelProperty(value = "原因") | |
15 | + private String reason; | |
16 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkRepairOrderDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | |
4 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
5 | +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |
6 | +import io.swagger.annotations.ApiModelProperty; | |
7 | +import lombok.Data; | |
8 | +import lombok.EqualsAndHashCode; | |
9 | + | |
10 | +import java.time.LocalDateTime; | |
11 | + | |
12 | +@EqualsAndHashCode(callSuper = true) | |
13 | +@Data | |
14 | +public class TkRepairOrderDTO extends TenantDTO { | |
15 | + | |
16 | + @ApiModelProperty(value = "设备id") | |
17 | + private String deviceId; | |
18 | + | |
19 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |
20 | + @ApiModelProperty(value = "报修时间") | |
21 | + @JsonSerialize(using = LocalDateTimeSerializer.class) | |
22 | + private LocalDateTime reportDate; | |
23 | + | |
24 | + @ApiModelProperty(value = "报修人") | |
25 | + private String reportBy; | |
26 | + | |
27 | + @ApiModelProperty(value = "状态(RepairOrderStatusEnum) SCHEDULING排期中 REPAIRFINISH维修完成 ACCEPTANCEPASSED验收通过") | |
28 | + private String status; | |
29 | + | |
30 | + @ApiModelProperty(value = "是否紧急") | |
31 | + private Boolean emergency; | |
32 | + | |
33 | + @ApiModelProperty(value = "故障情况拍照") | |
34 | + private String situationImg; | |
35 | + | |
36 | + @ApiModelProperty(value = "故障描述") | |
37 | + private String description; | |
38 | + | |
39 | + @ApiModelProperty(value = "关联设备") | |
40 | + private DeviceDTO deviceInfo; | |
41 | + | |
42 | + @ApiModelProperty(value = "查询开始时间") | |
43 | + private LocalDateTime startDate; | |
44 | + | |
45 | + @ApiModelProperty(value = "查询开始结束") | |
46 | + private LocalDateTime endDate; | |
47 | + | |
48 | + @ApiModelProperty(value = "页号") | |
49 | + private Integer page; | |
50 | + | |
51 | + @ApiModelProperty(value = "页码") | |
52 | + private Integer pageSize; | |
53 | + | |
54 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkRepairRecordDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | |
4 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
5 | +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |
6 | +import io.swagger.annotations.ApiModelProperty; | |
7 | +import lombok.Data; | |
8 | +import lombok.EqualsAndHashCode; | |
9 | + | |
10 | +import java.time.LocalDateTime; | |
11 | + | |
12 | +@EqualsAndHashCode(callSuper = true) | |
13 | +@Data | |
14 | +public class TkRepairRecordDTO extends TenantDTO { | |
15 | + | |
16 | + @ApiModelProperty(value = "维修工单id") | |
17 | + private String orderId; | |
18 | + | |
19 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |
20 | + @ApiModelProperty(value = "维修时间") | |
21 | + @JsonSerialize(using = LocalDateTimeSerializer.class) | |
22 | + private LocalDateTime repairDate; | |
23 | + | |
24 | + @ApiModelProperty(value = "维修人id") | |
25 | + private String repairBy; | |
26 | + | |
27 | + @ApiModelProperty(value = "维修人姓名") | |
28 | + private String repairName; | |
29 | + | |
30 | + @ApiModelProperty(value = "维修情况说明") | |
31 | + private String description; | |
32 | + | |
33 | + @ApiModelProperty(value = "维修工单") | |
34 | + private TkRepairOrderDTO tkRepairOrderDTO; | |
35 | + | |
36 | + @ApiModelProperty(value = "查询开始时间") | |
37 | + private LocalDateTime startDate; | |
38 | + | |
39 | + @ApiModelProperty(value = "查询开始结束") | |
40 | + private LocalDateTime endDate; | |
41 | + | |
42 | + @ApiModelProperty(value = "页号") | |
43 | + private Integer page; | |
44 | + | |
45 | + @ApiModelProperty(value = "页码") | |
46 | + private Integer pageSize; | |
47 | + | |
48 | +} | ... | ... |
... | ... | @@ -666,6 +666,21 @@ public class ModelConstants { |
666 | 666 | public static final String NOTIFICATION_TEMPLATE_NOTIFICATION_TYPE_PROPERTY = "notification_type"; |
667 | 667 | public static final String NOTIFICATION_TEMPLATE_CONFIGURATION_PROPERTY = "configuration"; |
668 | 668 | |
669 | + /** | |
670 | + * 故障原因. | |
671 | + */ | |
672 | + public static final String MALFUNCTIONREASON_TABLE_NAME = "qg_malfunction_reason"; | |
673 | + | |
674 | + /** | |
675 | + * 维修工单 | |
676 | + */ | |
677 | + public static final String TKREPAIRORDER_TABLE_NAME = "qg_repair_order"; | |
678 | + | |
679 | + /** | |
680 | + * 维修记录 | |
681 | + */ | |
682 | + public static final String TKREPAIRRECORD_TABLE_NAME = "qg_repair_record"; | |
683 | + | |
669 | 684 | protected static final String[] NONE_AGGREGATION_COLUMNS = new String[]{LONG_VALUE_COLUMN, DOUBLE_VALUE_COLUMN, BOOLEAN_VALUE_COLUMN, STRING_VALUE_COLUMN, JSON_VALUE_COLUMN, KEY_COLUMN, TS_COLUMN}; |
670 | 685 | |
671 | 686 | protected static final String[] COUNT_AGGREGATION_COLUMNS = new String[]{count(LONG_VALUE_COLUMN), count(DOUBLE_VALUE_COLUMN), count(BOOLEAN_VALUE_COLUMN), count(STRING_VALUE_COLUMN), count(JSON_VALUE_COLUMN), max(TS_COLUMN)}; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/TkMalfunctionReasonEntity.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.entities; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableName; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import org.thingsboard.server.dao.model.ModelConstants; | |
7 | + | |
8 | +/** | |
9 | + * 故障原因 | |
10 | + */ | |
11 | +@Data | |
12 | +@EqualsAndHashCode(callSuper = true) | |
13 | +@TableName(value = ModelConstants.MALFUNCTIONREASON_TABLE_NAME, autoResultMap = true) | |
14 | +public class TkMalfunctionReasonEntity extends TenantBaseEntity { | |
15 | + private String code; | |
16 | + private String reason; | |
17 | + | |
18 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.entities; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableName; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import org.thingsboard.server.dao.model.ModelConstants; | |
7 | + | |
8 | +import java.time.LocalDateTime; | |
9 | + | |
10 | +/** | |
11 | + * 维修工单 | |
12 | + */ | |
13 | +@Data | |
14 | +@EqualsAndHashCode(callSuper = true) | |
15 | +@TableName(value = ModelConstants.TKREPAIRORDER_TABLE_NAME, autoResultMap = true) | |
16 | +public class TkRepairOrderEntity extends TenantBaseEntity { | |
17 | + | |
18 | + private String deviceId; | |
19 | + | |
20 | + private LocalDateTime reportDate; | |
21 | + | |
22 | + private String reportBy; | |
23 | + | |
24 | + private String status; | |
25 | + | |
26 | + private Boolean emergency; | |
27 | + | |
28 | + private String situationImg; | |
29 | + | |
30 | + private String description; | |
31 | + | |
32 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.entities; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableName; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import org.thingsboard.server.dao.model.ModelConstants; | |
7 | + | |
8 | +import java.time.LocalDateTime; | |
9 | + | |
10 | +/** | |
11 | + * 维修记录 | |
12 | + */ | |
13 | +@Data | |
14 | +@EqualsAndHashCode(callSuper = true) | |
15 | +@TableName(value = ModelConstants.TKREPAIRRECORD_TABLE_NAME, autoResultMap = true) | |
16 | +public class TkRepairRecordEntity extends TenantBaseEntity { | |
17 | + | |
18 | + private String orderId; | |
19 | + | |
20 | + private LocalDateTime repairDate; | |
21 | + | |
22 | + private String repairBy; | |
23 | + | |
24 | + private String description; | |
25 | + | |
26 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/TkMalfunctionReasonServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
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; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.apache.commons.lang3.StringUtils; | |
9 | +import org.springframework.stereotype.Service; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; | |
12 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
13 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
14 | +import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; | |
15 | +import org.thingsboard.server.dao.yunteng.mapper.TkMalfunctionReasonMapper; | |
16 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
17 | +import org.thingsboard.server.dao.yunteng.service.TkMalfunctionReasonService; | |
18 | + | |
19 | +import java.util.List; | |
20 | +import java.util.Map; | |
21 | +import java.util.Optional; | |
22 | +import java.util.stream.Collectors; | |
23 | + | |
24 | +@Service | |
25 | +@RequiredArgsConstructor | |
26 | +@Slf4j | |
27 | +public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfunctionReasonMapper, TkMalfunctionReasonEntity> | |
28 | + implements TkMalfunctionReasonService { | |
29 | + @Override | |
30 | + public TkPageData<TkMalfunctionReasonDTO> page(String tenantId, Map<String, Object> queryMap) { | |
31 | + | |
32 | + QueryWrapper<TkMalfunctionReasonEntity> wrapper = new QueryWrapper<>(); | |
33 | + LambdaQueryWrapper<TkMalfunctionReasonEntity> lambda = wrapper.lambda(); | |
34 | + lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId); | |
35 | + if (queryMap != null && queryMap.get("code") != null) { | |
36 | + lambda.eq(TkMalfunctionReasonEntity::getCode, queryMap.get("code").toString()); | |
37 | + } | |
38 | + if (queryMap != null && queryMap.get("reason") != null) { | |
39 | + lambda.eq(TkMalfunctionReasonEntity::getReason, queryMap.get("reason").toString()); | |
40 | + } | |
41 | + | |
42 | + IPage<TkMalfunctionReasonEntity> page = baseMapper.selectPage( | |
43 | + getPage(queryMap, "create_time", false), wrapper); | |
44 | + | |
45 | + return getPageData(page, TkMalfunctionReasonDTO.class); | |
46 | + } | |
47 | + | |
48 | + @Override | |
49 | + public List<TkMalfunctionReasonDTO> list(String tenantId, Map<String, Object> queryMap) { | |
50 | + QueryWrapper<TkMalfunctionReasonEntity> wrapper = new QueryWrapper<>(); | |
51 | + LambdaQueryWrapper<TkMalfunctionReasonEntity> lambda = wrapper.lambda(); | |
52 | + lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId); | |
53 | + if (queryMap != null && queryMap.get("code") != null) { | |
54 | + lambda.eq(TkMalfunctionReasonEntity::getCode, queryMap.get("code").toString()); | |
55 | + } | |
56 | + if (queryMap != null && queryMap.get("reason") != null) { | |
57 | + lambda.eq(TkMalfunctionReasonEntity::getReason, queryMap.get("reason").toString()); | |
58 | + } | |
59 | + List<TkMalfunctionReasonEntity> entitys = baseMapper.selectList(wrapper); | |
60 | + return Optional.ofNullable(entitys).map(all -> all.stream().map(item -> item.getDTO(TkMalfunctionReasonDTO.class)) | |
61 | + .collect(Collectors.toList())).orElse(null); | |
62 | + | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + public TkMalfunctionReasonDTO save(TkMalfunctionReasonDTO tkMalfunctionReasonDTO) { | |
67 | + checkDto(tkMalfunctionReasonDTO); | |
68 | + TkMalfunctionReasonEntity entity = new TkMalfunctionReasonEntity(); | |
69 | + if (StringUtils.isBlank(tkMalfunctionReasonDTO.getId())) { | |
70 | + tkMalfunctionReasonDTO.copyToEntity(entity); | |
71 | + baseMapper.insert(entity); | |
72 | + } else { | |
73 | + LambdaQueryWrapper<TkMalfunctionReasonEntity> filter = new QueryWrapper<TkMalfunctionReasonEntity>().lambda() | |
74 | + .eq(TkMalfunctionReasonEntity::getId, tkMalfunctionReasonDTO.getId()); | |
75 | + entity = tkMalfunctionReasonDTO.getEntity(TkMalfunctionReasonEntity.class); | |
76 | + baseMapper.update(entity, filter); | |
77 | + } | |
78 | + | |
79 | + | |
80 | + entity.copyToDTO(tkMalfunctionReasonDTO); | |
81 | + return tkMalfunctionReasonDTO; | |
82 | + } | |
83 | + | |
84 | + private void checkDto(TkMalfunctionReasonDTO dto) { | |
85 | + if (StringUtils.isBlank(dto.getTenantId())) { | |
86 | + throw new TkDataValidationException("租户id为空!"); | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + @Override | |
91 | + public boolean delete(String id) { | |
92 | + int count = baseMapper.deleteById(id); | |
93 | + return count > 0; | |
94 | + } | |
95 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
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; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.apache.commons.collections4.CollectionUtils; | |
9 | +import org.apache.commons.lang3.StringUtils; | |
10 | +import org.springframework.stereotype.Service; | |
11 | +import org.thingsboard.server.common.data.User; | |
12 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
13 | +import org.thingsboard.server.common.data.id.TenantId; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
15 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
16 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
17 | +import org.thingsboard.server.common.data.yunteng.enums.RepairOrderStatusEnum; | |
18 | +import org.thingsboard.server.common.data.yunteng.utils.CopyUtils; | |
19 | +import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; | |
20 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
21 | +import org.thingsboard.server.dao.yunteng.entities.TenantBaseEntity; | |
22 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairOrderEntity; | |
23 | +import org.thingsboard.server.dao.yunteng.mapper.TkRepairOrderMapper; | |
24 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
25 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceService; | |
26 | +import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService; | |
27 | + | |
28 | +import java.time.LocalDateTime; | |
29 | +import java.util.HashMap; | |
30 | +import java.util.List; | |
31 | +import java.util.Map; | |
32 | +import java.util.UUID; | |
33 | +import java.util.stream.Collectors; | |
34 | + | |
35 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
36 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
37 | + | |
38 | +@Service | |
39 | +@RequiredArgsConstructor | |
40 | +@Slf4j | |
41 | +public class TkRepairOrderServiceImpl extends AbstractBaseService<TkRepairOrderMapper, TkRepairOrderEntity> | |
42 | + implements TkRepairOrderService { | |
43 | + | |
44 | + private final TkDeviceService tkdeviceService; | |
45 | + | |
46 | + @Override | |
47 | + public TkPageData<TkRepairOrderDTO> page(String tenantId, TkRepairOrderDTO params) { | |
48 | + QueryWrapper<TkRepairOrderEntity> queryWrapper = getCondition(tenantId, params); | |
49 | + getCondition(tenantId, params); | |
50 | + Map<String, Object> queryMap = new HashMap<>(); | |
51 | + queryMap.put(PAGE, params.getPage()); | |
52 | + queryMap.put(PAGE_SIZE, params.getPageSize()); | |
53 | + IPage<TkRepairOrderEntity> page = baseMapper.selectPage( | |
54 | + getPage(queryMap, "create_time", false), queryWrapper); | |
55 | + | |
56 | + TkPageData<TkRepairOrderDTO> pageData = getPageData(page, TkRepairOrderDTO.class); | |
57 | + if (pageData != null && CollectionUtils.isNotEmpty(pageData.getItems())) { | |
58 | + pageData.getItems().forEach(item -> { | |
59 | + String deviceId = item.getDeviceId(); | |
60 | + if (StringUtils.isNotBlank(deviceId)) { | |
61 | + DeviceDTO deviceDTO = tkdeviceService.checkDeviceByTenantIdAndDeviceId(UUID.fromString(tenantId), UUID.fromString(deviceId)); | |
62 | + item.setDeviceInfo(deviceDTO); | |
63 | + } | |
64 | + }); | |
65 | + } | |
66 | + return pageData; | |
67 | + } | |
68 | + | |
69 | + private QueryWrapper<TkRepairOrderEntity> getCondition(String tenantId, TkRepairOrderDTO params) { | |
70 | + QueryWrapper<TkRepairOrderEntity> queryWrapper = new QueryWrapper<>(); | |
71 | + LambdaQueryWrapper<TkRepairOrderEntity> lambda = queryWrapper.lambda(); | |
72 | + lambda.eq(TenantBaseEntity::getTenantId, tenantId); | |
73 | + if (StringUtils.isNotBlank(params.getDeviceId())) { | |
74 | + lambda.eq(TkRepairOrderEntity::getDeviceId, params.getDeviceId()); | |
75 | + } | |
76 | + if (params.getStartDate() != null) { | |
77 | + lambda.ge(TkRepairOrderEntity::getReportDate, params.getStartDate()); | |
78 | + } | |
79 | + if (params.getEndDate() != null) { | |
80 | + lambda.le(TkRepairOrderEntity::getReportDate, params.getEndDate()); | |
81 | + } | |
82 | + | |
83 | + if (StringUtils.isNotBlank(params.getReportBy())) { | |
84 | + lambda.eq(TkRepairOrderEntity::getReportBy, params.getReportBy()); | |
85 | + } | |
86 | + | |
87 | + if (StringUtils.isNotBlank(params.getStatus())) { | |
88 | + lambda.eq(TkRepairOrderEntity::getStatus, params.getStatus()); | |
89 | + } | |
90 | + | |
91 | + if (params.getEmergency() != null) { | |
92 | + lambda.eq(TkRepairOrderEntity::getEmergency, params.getEmergency()); | |
93 | + } | |
94 | + return queryWrapper; | |
95 | + } | |
96 | + | |
97 | + | |
98 | + @Override | |
99 | + public TkRepairOrderDTO save(TkRepairOrderDTO dto) { | |
100 | + checkDto(dto); | |
101 | + if (dto.getReportDate() == null) { | |
102 | + dto.setReportDate(LocalDateTime.now()); | |
103 | + } | |
104 | + | |
105 | + TkRepairOrderEntity entity = new TkRepairOrderEntity(); | |
106 | + if (StringUtils.isBlank(dto.getId())) { | |
107 | + dto.copyToEntity(entity); | |
108 | + baseMapper.insert(entity); | |
109 | + } else { | |
110 | + LambdaQueryWrapper<TkRepairOrderEntity> filter = new QueryWrapper<TkRepairOrderEntity>().lambda() | |
111 | + .eq(TkRepairOrderEntity::getId, dto.getId()); | |
112 | + entity = dto.getEntity(TkRepairOrderEntity.class); | |
113 | + baseMapper.update(entity, filter); | |
114 | + } | |
115 | + entity.copyToDTO(dto); | |
116 | + return dto; | |
117 | + } | |
118 | + | |
119 | + @Override | |
120 | + public TkRepairOrderDTO detail(String id) throws ThingsboardException { | |
121 | + TkRepairOrderDTO detail = new TkRepairOrderDTO(); | |
122 | + TkRepairOrderEntity entity = baseMapper.selectById(id); | |
123 | + if (entity == null) { | |
124 | + throw new TkDataValidationException("数据不存在!"); | |
125 | + } | |
126 | + entity.copyToDTO(detail); | |
127 | + String deviceId = entity.getDeviceId(); | |
128 | + if (StringUtils.isNotBlank(deviceId)) { | |
129 | + TenantId tenantInfo = SpringBeanUtils.getTenantId(); | |
130 | + DeviceDTO deviceDTO = tkdeviceService.checkDeviceByTenantIdAndDeviceId(tenantInfo.getId(), UUID.fromString(deviceId)); | |
131 | + detail.setDeviceInfo(deviceDTO); | |
132 | + } | |
133 | + | |
134 | + return detail; | |
135 | + } | |
136 | + | |
137 | + @Override | |
138 | + public TkRepairOrderDTO load(String id) throws ThingsboardException { | |
139 | + TkRepairOrderDTO result = new TkRepairOrderDTO(); | |
140 | + TkRepairOrderEntity entity = baseMapper.selectById(id); | |
141 | + entity.copyToDTO(result); | |
142 | + return result; | |
143 | + } | |
144 | + | |
145 | + @Override | |
146 | + public TkRepairOrderDTO loadByDeviceId(String deviceId) throws ThingsboardException { | |
147 | + TkRepairOrderDTO result = new TkRepairOrderDTO(); | |
148 | + QueryWrapper<TkRepairOrderEntity> queryWrapper = new QueryWrapper<>(); | |
149 | + LambdaQueryWrapper<TkRepairOrderEntity> lambda = queryWrapper.lambda(); | |
150 | + lambda.eq(TenantBaseEntity::getTenantId, SpringBeanUtils.getTenantId().toString()); | |
151 | + lambda.eq(TkRepairOrderEntity::getDeviceId, deviceId); | |
152 | + TkRepairOrderEntity entity = baseMapper.selectOne(queryWrapper); | |
153 | + entity.copyToDTO(result); | |
154 | + return result; | |
155 | + } | |
156 | + | |
157 | + @Override | |
158 | + public void updateStatus(String id, String status) throws ThingsboardException { | |
159 | + TkRepairOrderDTO orderDTO = load(id); | |
160 | + if (orderDTO == null) { | |
161 | + throw new TkDataValidationException("工单不存在!"); | |
162 | + } | |
163 | + RepairOrderStatusEnum statusEnum = RepairOrderStatusEnum.valueOf(status); | |
164 | + if (statusEnum == null) { | |
165 | + throw new TkDataValidationException("工单状态不存在!"); | |
166 | + } | |
167 | + TkRepairOrderEntity entity = new TkRepairOrderEntity(); | |
168 | + orderDTO.copyToEntity(entity); | |
169 | + entity.setStatus(statusEnum.name()); | |
170 | + LambdaQueryWrapper<TkRepairOrderEntity> filter = new QueryWrapper<TkRepairOrderEntity>().lambda() | |
171 | + .eq(TkRepairOrderEntity::getId, entity.getId()); | |
172 | + baseMapper.update(entity, filter); | |
173 | + } | |
174 | + | |
175 | + private void checkDto(TkRepairOrderDTO dto) { | |
176 | + if (StringUtils.isBlank(dto.getDeviceId())) { | |
177 | + throw new TkDataValidationException("设备不能为空!"); | |
178 | + } | |
179 | + | |
180 | + if (StringUtils.isBlank(dto.getReportBy())) { | |
181 | + throw new TkDataValidationException("报修人不能为空!"); | |
182 | + } | |
183 | + | |
184 | + if (StringUtils.isBlank(dto.getTenantId())) { | |
185 | + throw new TkDataValidationException("租户id为空!"); | |
186 | + } | |
187 | + } | |
188 | + | |
189 | + @Override | |
190 | + public boolean delete(String id) { | |
191 | + int count = baseMapper.deleteById(id); | |
192 | + return count > 0; | |
193 | + } | |
194 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
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; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.apache.commons.collections4.CollectionUtils; | |
9 | +import org.apache.commons.lang3.StringUtils; | |
10 | +import org.springframework.stereotype.Service; | |
11 | +import org.thingsboard.server.common.data.User; | |
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.dto.TkRepairOrderDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairRecordDTO; | |
16 | +import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | |
17 | +import org.thingsboard.server.common.data.yunteng.utils.CopyUtils; | |
18 | +import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; | |
19 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
20 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceEntity; | |
21 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairRecordEntity; | |
22 | +import org.thingsboard.server.dao.yunteng.mapper.TkRepairRecordMapper; | |
23 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
24 | +import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService; | |
25 | +import org.thingsboard.server.dao.yunteng.service.TkRepairRecordService; | |
26 | +import org.thingsboard.server.dao.yunteng.service.TkUserService; | |
27 | + | |
28 | +import java.time.LocalDateTime; | |
29 | +import java.util.HashMap; | |
30 | +import java.util.List; | |
31 | +import java.util.Map; | |
32 | +import java.util.stream.Collectors; | |
33 | + | |
34 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
35 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
36 | + | |
37 | +@Service | |
38 | +@RequiredArgsConstructor | |
39 | +@Slf4j | |
40 | +public class TkRepairRecordServiceImpl extends AbstractBaseService<TkRepairRecordMapper, TkRepairRecordEntity> | |
41 | + implements TkRepairRecordService { | |
42 | + | |
43 | + private final TkRepairOrderService tkRepairOrderService; | |
44 | + | |
45 | + | |
46 | + private final TkUserService tkUserService; | |
47 | + | |
48 | + @Override | |
49 | + public TkPageData<TkRepairRecordDTO> page(String tenantId, TkRepairRecordDTO params) { | |
50 | + TkPageData<TkRepairRecordDTO> result = new TkPageData<>(); | |
51 | + Map<String, Object> queryMap = new HashMap<>(); | |
52 | + queryMap.put(PAGE, params.getPage()); | |
53 | + queryMap.put(PAGE_SIZE, params.getPageSize()); | |
54 | + IPage<TkRepairRecordEntity> page = | |
55 | + getPage(queryMap, "rr.create_time", false); | |
56 | + IPage<TkRepairRecordDTO> pageData = baseMapper.getRepairRecordPage(page, queryMap); | |
57 | + if (pageData != null && CollectionUtils.isNotEmpty(pageData.getRecords())) { | |
58 | + List<TkRepairRecordDTO> dataList = pageData.getRecords().stream().map(item -> { | |
59 | + TkRepairRecordDTO dto = new TkRepairRecordDTO(); | |
60 | + CopyUtils.copyProperties(item, dto); | |
61 | + return dto; | |
62 | + | |
63 | + }).collect(Collectors.toList()); | |
64 | + result.setItems(dataList); | |
65 | + } | |
66 | + result.setTotal(Long.valueOf(pageData.getTotal()).intValue()); | |
67 | + | |
68 | + return result; | |
69 | + } | |
70 | + | |
71 | + @Override | |
72 | + public TkRepairRecordDTO save(TkRepairRecordDTO dto) { | |
73 | + checkDto(dto); | |
74 | + if (dto.getRepairDate() == null) { | |
75 | + dto.setRepairDate(LocalDateTime.now()); | |
76 | + } | |
77 | + | |
78 | + TkRepairRecordEntity entity = new TkRepairRecordEntity(); | |
79 | + if (StringUtils.isBlank(dto.getId())) { | |
80 | + dto.copyToEntity(entity); | |
81 | + baseMapper.insert(entity); | |
82 | + } else { | |
83 | + LambdaQueryWrapper<TkRepairRecordEntity> filter = new QueryWrapper<TkRepairRecordEntity>().lambda() | |
84 | + .eq(TkRepairRecordEntity::getId, dto.getId()); | |
85 | + entity = dto.getEntity(TkRepairRecordEntity.class); | |
86 | + baseMapper.update(entity, filter); | |
87 | + } | |
88 | + entity.copyToDTO(dto); | |
89 | + return dto; | |
90 | + } | |
91 | + | |
92 | + private void checkDto(TkRepairRecordDTO dto) { | |
93 | + if (StringUtils.isBlank(dto.getOrderId())) { | |
94 | + throw new TkDataValidationException("维修工单不能为空!"); | |
95 | + } | |
96 | + | |
97 | + if (StringUtils.isBlank(dto.getRepairBy())) { | |
98 | + throw new TkDataValidationException("维修人不能为空!"); | |
99 | + } | |
100 | + | |
101 | + if (StringUtils.isBlank(dto.getTenantId())) { | |
102 | + throw new TkDataValidationException("租户id为空!"); | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + | |
107 | + @Override | |
108 | + public TkRepairRecordDTO detail(String id) throws ThingsboardException { | |
109 | + TkRepairRecordDTO detail = new TkRepairRecordDTO(); | |
110 | + TkRepairRecordEntity entity = baseMapper.selectById(id); | |
111 | + if (entity == null) { | |
112 | + throw new TkDataValidationException("数据不存在!"); | |
113 | + } | |
114 | + entity.copyToDTO(detail); | |
115 | + String orderId = entity.getOrderId(); | |
116 | + if (StringUtils.isNotBlank(orderId)) { | |
117 | + TkRepairOrderDTO repairOrderDTO = tkRepairOrderService.load(orderId); | |
118 | + detail.setTkRepairOrderDTO(repairOrderDTO); | |
119 | + } | |
120 | + UserDTO userInfo = tkUserService.findUserInfoById(detail.getRepairBy()); | |
121 | + detail.setRepairName(userInfo.getRealName()); | |
122 | + | |
123 | + return detail; | |
124 | + } | |
125 | + | |
126 | + @Override | |
127 | + public boolean delete(String id) { | |
128 | + int count = baseMapper.deleteById(id); | |
129 | + return count > 0; | |
130 | + } | |
131 | +} | |
132 | + | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/mapper/TkMalfunctionReasonMapper.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import org.apache.ibatis.annotations.Mapper; | |
5 | +import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; | |
6 | + | |
7 | +@Mapper | |
8 | +public interface TkMalfunctionReasonMapper extends BaseMapper<TkMalfunctionReasonEntity> { | |
9 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import org.apache.ibatis.annotations.Mapper; | |
5 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairOrderEntity; | |
6 | + | |
7 | +@Mapper | |
8 | +public interface TkRepairOrderMapper extends BaseMapper<TkRepairOrderEntity> { | |
9 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import org.apache.ibatis.annotations.Mapper; | |
6 | +import org.apache.ibatis.annotations.Param; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairRecordDTO; | |
8 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairRecordEntity; | |
9 | + | |
10 | +import java.util.Map; | |
11 | + | |
12 | +@Mapper | |
13 | +public interface TkRepairRecordMapper extends BaseMapper<TkRepairRecordEntity> { | |
14 | + | |
15 | + IPage<TkRepairRecordDTO> getRepairRecordPage(IPage<?> page, @Param("queryMap") Map<String, Object> queryMap); | |
16 | + | |
17 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/TkMalfunctionReasonService.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | + | |
4 | +import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; | |
5 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
6 | +import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; | |
7 | + | |
8 | +import java.util.List; | |
9 | +import java.util.Map; | |
10 | + | |
11 | +public interface TkMalfunctionReasonService extends BaseService<TkMalfunctionReasonEntity> { | |
12 | + | |
13 | + TkPageData<TkMalfunctionReasonDTO> page(String tenantId, Map<String, Object> queryMap); | |
14 | + | |
15 | + List<TkMalfunctionReasonDTO> list(String tenantId, Map<String, Object> queryMap); | |
16 | + | |
17 | + TkMalfunctionReasonDTO save(TkMalfunctionReasonDTO tkMalfunctionReasonDTO); | |
18 | + | |
19 | + boolean delete(String id); | |
20 | + | |
21 | + | |
22 | + | |
23 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | + | |
4 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
5 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
6 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
7 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairOrderEntity; | |
8 | + | |
9 | +import java.util.Map; | |
10 | + | |
11 | +public interface TkRepairOrderService extends BaseService<TkRepairOrderEntity> { | |
12 | + | |
13 | + TkPageData<TkRepairOrderDTO> page(String tenantId, TkRepairOrderDTO params); | |
14 | + | |
15 | + TkRepairOrderDTO save(TkRepairOrderDTO dto); | |
16 | + | |
17 | + TkRepairOrderDTO detail(String id) throws ThingsboardException; | |
18 | + | |
19 | + TkRepairOrderDTO load(String id) throws ThingsboardException; | |
20 | + | |
21 | + TkRepairOrderDTO loadByDeviceId(String deviceId) throws ThingsboardException; | |
22 | + | |
23 | + void updateStatus(String id, String status) throws ThingsboardException; | |
24 | + | |
25 | + boolean delete(String id); | |
26 | + | |
27 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
4 | +import org.thingsboard.server.common.data.yunteng.dto.TkRepairRecordDTO; | |
5 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
6 | +import org.thingsboard.server.dao.yunteng.entities.TkRepairRecordEntity; | |
7 | + | |
8 | +public interface TkRepairRecordService extends BaseService<TkRepairRecordEntity>{ | |
9 | + | |
10 | + TkPageData<TkRepairRecordDTO> page(String tenantId, TkRepairRecordDTO params); | |
11 | + | |
12 | + TkRepairRecordDTO save(TkRepairRecordDTO dto); | |
13 | + | |
14 | + TkRepairRecordDTO detail(String id) throws ThingsboardException; | |
15 | + | |
16 | + boolean delete(String id); | |
17 | + | |
18 | +} | ... | ... |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | + | |
4 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.TkRepairRecordMapper"> | |
5 | + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.TkRepairRecordDTO" id="repairRecordMap"> | |
6 | + <result property="id" column="id" /> | |
7 | + <result property="repairDate" column="repair_date" /> | |
8 | + <result property="orderId" column="order_id" /> | |
9 | + <result property="repairBy" column="repair_by" /> | |
10 | + <result property="description" column="description" /> | |
11 | + <result property="repairName" column="repairName" /> | |
12 | + </resultMap> | |
13 | + <select id="getRepairRecordPage" resultMap="repairRecordMap"> | |
14 | + SELECT rr.id,rr.order_id,rr.repair_date,rr.repair_by,rr.description | |
15 | + ,rr.tenant_id,rr.create_time,rr.updater,rr.update_time,rr.creator,su.real_name as repairName | |
16 | + from qg_repair_record rr | |
17 | + inner join sys_user su on su.id=rr.repair_by | |
18 | + </select> | |
19 | +</mapper> | |
\ No newline at end of file | ... | ... |