Showing
17 changed files
with
434 additions
and
34 deletions
... | ... | @@ -2,6 +2,7 @@ CREATE TABLE "public"."qg_malfunction_reason" ( |
2 | 2 | "id" varchar(36) NOT NULL, |
3 | 3 | "code" varchar(50), |
4 | 4 | "reason" varchar(200), |
5 | + "status" varchar(50), | |
5 | 6 | "tenant_id" varchar(36), |
6 | 7 | "create_time" timestamp(6), |
7 | 8 | "creator" varchar(36), |
... | ... | @@ -15,6 +16,7 @@ ALTER TABLE "public"."qg_malfunction_reason" OWNER TO "postgres"; |
15 | 16 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."id" IS '主键ID'; |
16 | 17 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."code" IS '故障编码'; |
17 | 18 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."reason" IS '故障原因'; |
19 | +COMMENT ON COLUMN "public"."qg_malfunction_reason"."status" IS '状态'; | |
18 | 20 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."tenant_id" IS '租户ID'; |
19 | 21 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."create_time" IS '创建时间'; |
20 | 22 | COMMENT ON COLUMN "public"."qg_malfunction_reason"."updater" IS '更新用户'; |
... | ... | @@ -24,8 +26,11 @@ COMMENT ON COLUMN "public"."qg_malfunction_reason"."creator" IS '创建用户'; |
24 | 26 | |
25 | 27 | ALTER TABLE device |
26 | 28 | ADD COLUMN IF NOT EXISTS director_id varchar(36); |
29 | +ALTER TABLE device | |
30 | + ADD COLUMN IF NOT EXISTS category_id varchar(36); | |
27 | 31 | |
28 | 32 | COMMENT ON COLUMN "public"."device"."director_id" IS '负责人id'; |
33 | +COMMENT ON COLUMN "public"."device"."category_id" IS '设备类别id'; | |
29 | 34 | |
30 | 35 | |
31 | 36 | CREATE TABLE "public"."qg_repair_order" ( |
... | ... | @@ -265,3 +270,21 @@ COMMENT ON COLUMN "public"."qg_preserve_record"."preserve_plan_id" IS '保养计 |
265 | 270 | COMMENT ON COLUMN "public"."qg_preserve_record"."preserve_date" IS '保养日期'; |
266 | 271 | COMMENT ON COLUMN "public"."qg_preserve_record"."preserve_by" IS '保养日期'; |
267 | 272 | COMMENT ON COLUMN "public"."qg_preserve_record"."preserve_status" IS '状态'; |
273 | + | |
274 | +CREATE TABLE "public"."qg_device_cagegory" ( | |
275 | + "id" varchar(36) NOT NULL, | |
276 | + "name" varchar(50), | |
277 | + "parent_id" varchar(36), | |
278 | + "cagegory_order" int4, | |
279 | + "tenant_id" varchar(36), | |
280 | + "create_time" timestamp(6), | |
281 | + "creator" varchar(36), | |
282 | + "updater" varchar(36), | |
283 | + "update_time" timestamp(6) | |
284 | +CONSTRAINT "qg_device_cagegory_pkey" PRIMARY KEY ("id") | |
285 | +); | |
286 | + | |
287 | +COMMENT ON TABLE "public"."qg_device_cagegory" IS '设备分类'; | |
288 | +COMMENT ON COLUMN "public"."qg_device_cagegory"."name" IS '保养记录编码'; | |
289 | +COMMENT ON COLUMN "public"."qg_device_cagegory"."parent_id" IS '保养计划id'; | |
290 | +COMMENT ON COLUMN "public"."qg_device_cagegory"."order" IS '排序'; | ... | ... |
application/src/main/java/org/thingsboard/server/controller/TkDeviceCagegoryController.java
0 → 100644
1 | +package org.thingsboard.server.controller; | |
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.TkDeviceCagegoryDTO; | |
12 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceCagegoryService; | |
13 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
14 | + | |
15 | +import java.util.List; | |
16 | + | |
17 | +@RestController | |
18 | +@TbCoreComponent | |
19 | +@RequiredArgsConstructor | |
20 | +@RequestMapping("api/yt/deviceCagegory") | |
21 | +@Api(tags = {"设备类型管理"}) | |
22 | +@Slf4j | |
23 | +public class TkDeviceCagegoryController extends BaseController { | |
24 | + private final TkDeviceCagegoryService tkDeviceCagegoryService; | |
25 | + | |
26 | + @PostMapping("/getCagegoryByParentid") | |
27 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
28 | + @ApiOperation("根据父类型获取设备类别") | |
29 | + public List<TkDeviceCagegoryDTO> getCagegoryByParentid(@RequestBody TkDeviceCagegoryDTO dto) throws ThingsboardException { | |
30 | + return tkDeviceCagegoryService.getCagegoryByParentid(dto.getParentId()); | |
31 | + } | |
32 | + | |
33 | + @PostMapping("/getAllCagegory") | |
34 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
35 | + @ApiOperation("根据父类型获取设备类别") | |
36 | + public List<TkDeviceCagegoryDTO> getAllCagegory() throws ThingsboardException { | |
37 | + return tkDeviceCagegoryService.getAllCagegory(); | |
38 | + } | |
39 | + | |
40 | + @PostMapping("/save") | |
41 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
42 | + public ResponseEntity<TkDeviceCagegoryDTO> save(@RequestBody TkDeviceCagegoryDTO tkMalfunctionReasonDTO) throws ThingsboardException { | |
43 | + tkMalfunctionReasonDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | |
44 | + TkDeviceCagegoryDTO deviceDTO = tkDeviceCagegoryService.save(tkMalfunctionReasonDTO); | |
45 | + return ResponseEntity.ok(deviceDTO); | |
46 | + } | |
47 | + | |
48 | + @GetMapping("/delete") | |
49 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
50 | + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { | |
51 | + return ResponseEntity.ok(tkDeviceCagegoryService.delete(id)); | |
52 | + } | |
53 | + | |
54 | + @GetMapping("/detail") | |
55 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
56 | + @ApiOperation("保养计划详情") | |
57 | + public ResponseEntity<TkDeviceCagegoryDTO> detail(@RequestParam("id") String id) throws ThingsboardException { | |
58 | + TkDeviceCagegoryDTO dto = tkDeviceCagegoryService.detail(id); | |
59 | + return ResponseEntity.ok(dto); | |
60 | + } | |
61 | + | |
62 | +} | ... | ... |
... | ... | @@ -8,6 +8,7 @@ import org.springframework.http.ResponseEntity; |
8 | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
9 | 9 | import org.springframework.web.bind.annotation.*; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
11 | 12 | import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
13 | 14 | import org.thingsboard.server.controller.BaseController; |
... | ... | @@ -15,7 +16,6 @@ import org.thingsboard.server.dao.yunteng.service.TkMalfunctionReasonService; |
15 | 16 | import org.thingsboard.server.queue.util.TbCoreComponent; |
16 | 17 | |
17 | 18 | import java.util.List; |
18 | -import java.util.Map; | |
19 | 19 | |
20 | 20 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; |
21 | 21 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; |
... | ... | @@ -35,20 +35,19 @@ public class TkMalfunctionReasonController extends BaseController { |
35 | 35 | public TkPageData<TkMalfunctionReasonDTO> pageMalfunctionReason( |
36 | 36 | @RequestParam(PAGE_SIZE) int pageSize, |
37 | 37 | @RequestParam(PAGE) int page, |
38 | - @RequestBody Map<String, Object> queryMap) | |
38 | + @RequestBody TkMalfunctionReasonDTO dto) | |
39 | 39 | throws ThingsboardException { |
40 | - queryMap.put(PAGE, page); | |
41 | - queryMap.put(PAGE_SIZE, pageSize); | |
42 | - return tkMalfunctionReasonService.page(getCurrentUser().getCurrentTenantId(), queryMap); | |
40 | + dto.setPage(page); | |
41 | + dto.setPageSize(pageSize); | |
42 | + return tkMalfunctionReasonService.page(dto); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | @PostMapping("/list") |
46 | 46 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") |
47 | 47 | @ApiOperation("获取满足条件的所有设备") |
48 | 48 | public List<TkMalfunctionReasonDTO> list( |
49 | - @RequestBody Map<String, Object> queryMap) throws ThingsboardException { | |
50 | - | |
51 | - return tkMalfunctionReasonService.list(getCurrentUser().getCurrentTenantId(), queryMap); | |
49 | + @RequestBody TkMalfunctionReasonDTO queryMap) throws ThingsboardException { | |
50 | + return tkMalfunctionReasonService.list(queryMap); | |
52 | 51 | } |
53 | 52 | |
54 | 53 | @PostMapping("/save") |
... | ... | @@ -65,5 +64,26 @@ public class TkMalfunctionReasonController extends BaseController { |
65 | 64 | return ResponseEntity.ok(tkMalfunctionReasonService.delete(id)); |
66 | 65 | } |
67 | 66 | |
67 | + @GetMapping("/detail") | |
68 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
69 | + @ApiOperation("保养计划详情") | |
70 | + public ResponseEntity<TkMalfunctionReasonDTO> detail(@RequestParam("id") String id) throws ThingsboardException { | |
71 | + TkMalfunctionReasonDTO dto = tkMalfunctionReasonService.detail(id); | |
72 | + return ResponseEntity.ok(dto); | |
73 | + } | |
74 | + | |
75 | + @PostMapping("/updateStatus") | |
76 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
77 | + @ApiOperation("更新保养计划状态") | |
78 | + public ResponseEntity<TkMalfunctionReasonDTO> updateStatus(@RequestBody TkMalfunctionReasonDTO dto) throws ThingsboardException { | |
79 | + TkMalfunctionReasonDTO orderInfo = tkMalfunctionReasonService.detail(dto.getId()); | |
80 | + if (orderInfo == null) { | |
81 | + throw new TkDataValidationException("保养计划不存在!"); | |
82 | + } | |
83 | + | |
84 | + tkMalfunctionReasonService.updateStatus(dto.getId(), dto.getStatus()); | |
85 | + return ResponseEntity.ok(orderInfo); | |
86 | + } | |
87 | + | |
68 | 88 | |
69 | 89 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkDeviceCagegoryDTO.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 | +import java.util.List; | |
8 | + | |
9 | +@EqualsAndHashCode(callSuper = true) | |
10 | +@Data | |
11 | +public class TkDeviceCagegoryDTO extends TenantDTO { | |
12 | + | |
13 | + @ApiModelProperty(value = "类别名称") | |
14 | + private String name; | |
15 | + @ApiModelProperty(value = "父级id") | |
16 | + private String parentId; | |
17 | + @ApiModelProperty(value = "排序") | |
18 | + private Integer cagegoryOrder; | |
19 | + @ApiModelProperty(value = "子类别") | |
20 | + private List<TkDeviceCagegoryDTO> children; | |
21 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkMalfunctionReasonDTO.java
... | ... | @@ -13,4 +13,13 @@ public class TkMalfunctionReasonDTO extends TenantDTO { |
13 | 13 | |
14 | 14 | @ApiModelProperty(value = "原因") |
15 | 15 | private String reason; |
16 | + | |
17 | + @ApiModelProperty(value = "状态(ENABLE启用,DISABLE停用)") | |
18 | + private String status; | |
19 | + | |
20 | + @ApiModelProperty(value = "页号") | |
21 | + private Integer page; | |
22 | + | |
23 | + @ApiModelProperty(value = "页码") | |
24 | + private Integer pageSize; | |
16 | 25 | } | ... | ... |
... | ... | @@ -680,9 +680,10 @@ public class ModelConstants { |
680 | 680 | * 维修记录 |
681 | 681 | */ |
682 | 682 | public static final String TKREPAIRRECORD_TABLE_NAME = "qg_repair_record"; |
683 | - public static final String TKPRESERVEPLAN_TABLE_NAME = "qg_preserve_plan"; | |
684 | - public static final String TKPRESERVEDETAIL_TABLE_NAME = "qg_preserve_detail"; | |
685 | - public static final String TKPRESERVERECORD_TABLE_NAME = "qg_preserve_record"; | |
683 | + public static final String TKPRESERVEPLAN_TABLE_NAME = "qg_preserve_plan";//保养计划 | |
684 | + public static final String TKPRESERVEDETAIL_TABLE_NAME = "qg_preserve_detail";//保养详情 | |
685 | + public static final String TKPRESERVERECORD_TABLE_NAME = "qg_preserve_record";//保养记录 | |
686 | + public static final String TKDEVICECAGEGORY_TABLE_NAME = "qg_device_cagegory";//保养记录 | |
686 | 687 | |
687 | 688 | public static final String TKINSPECTIONPLAN_TABLE_NAME= "qg_inspection_plan"; // 巡检计划 |
688 | 689 | public static final String TKCHECKPLAN_TABLE_NAME= "qg_check_plan"; // 巡检/保养方案 | ... | ... |
1 | +package org.thingsboard.server.dao.util; | |
2 | + | |
3 | +import com.google.common.collect.Lists; | |
4 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceCagegoryDTO; | |
5 | + | |
6 | +import java.util.HashMap; | |
7 | +import java.util.List; | |
8 | +import java.util.Map; | |
9 | + | |
10 | +/** | |
11 | + * 用于获取树形结构 | |
12 | + */ | |
13 | +public class TkDeviceCagegoryUtil { | |
14 | + | |
15 | + private List<TkDeviceCagegoryDTO> rootList; // 根节点对象存放到这里 | |
16 | + | |
17 | + private List<TkDeviceCagegoryDTO> bodyList; // 其他节点存放到这里,可以包含根节点 | |
18 | + | |
19 | + public TkDeviceCagegoryUtil(List<TkDeviceCagegoryDTO> rootList, List<TkDeviceCagegoryDTO> bodyList) { | |
20 | + this.rootList = rootList; | |
21 | + this.bodyList = bodyList; | |
22 | + } | |
23 | + | |
24 | + public List<TkDeviceCagegoryDTO> getTree() { | |
25 | + if (bodyList != null && !bodyList.isEmpty()) { | |
26 | + // 声明一个map,用来过滤已操作过的数据 | |
27 | + Map<String, String> map = new HashMap<>(); | |
28 | + rootList.forEach(beanTree -> getChild(beanTree, map)); | |
29 | + return rootList; | |
30 | + } | |
31 | + return null; | |
32 | + } | |
33 | + | |
34 | + public void getChild(TkDeviceCagegoryDTO beanTree, Map<String, String> map) { | |
35 | + List<TkDeviceCagegoryDTO> childList = Lists.newArrayList(); | |
36 | + bodyList.stream().filter(c -> !map.containsKey(c.getId())).filter(c -> c.getParentId().equals(beanTree.getId())) | |
37 | + .forEach(c -> { | |
38 | + map.put(c.getId(), c.getParentId()); | |
39 | + getChild(c, map); | |
40 | + childList.add(c); | |
41 | + }); | |
42 | + beanTree.setChildren(childList); | |
43 | + } | |
44 | + | |
45 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/TkDeviceCagegoryEntity.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.TKDEVICECAGEGORY_TABLE_NAME, autoResultMap = true) | |
14 | +public class TkDeviceCagegoryEntity extends TenantBaseEntity { | |
15 | + private String name; | |
16 | + private String parentId; | |
17 | + private Integer cagegoryOrder; | |
18 | +} | ... | ... |
... | ... | @@ -446,7 +446,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
446 | 446 | organizationIds.toArray(new String[organizationIds.size()])); |
447 | 447 | } |
448 | 448 | //过滤当前组织的上级组织的账号 |
449 | - userIds = filterParentUserId(tenantId,organizationId,userIds); | |
449 | + //userIds = filterParentUserId(tenantId,organizationId,userIds); | |
450 | 450 | return userIds; |
451 | 451 | } |
452 | 452 | |
... | ... | @@ -466,7 +466,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
466 | 466 | } |
467 | 467 | } |
468 | 468 | if(!filterUserIds.isEmpty()){ |
469 | - filterUserIds.remove(currentUserId); | |
469 | +// filterUserIds.remove(currentUserId); | |
470 | 470 | userIds = new ArrayList<>(); |
471 | 471 | userIds.addAll(filterUserIds); |
472 | 472 | } | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/TkDeviceCagegoryServiceImpl.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 lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.commons.collections4.CollectionUtils; | |
8 | +import org.apache.commons.lang3.StringUtils; | |
9 | +import org.springframework.stereotype.Service; | |
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
11 | +import org.thingsboard.server.common.data.id.TenantId; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceCagegoryDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; | |
15 | +import org.thingsboard.server.dao.util.TkDeviceCagegoryUtil; | |
16 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceCagegoryEntity; | |
17 | +import org.thingsboard.server.dao.yunteng.mapper.TkDeviceCagegoryMapper; | |
18 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
19 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceCagegoryService; | |
20 | + | |
21 | +import java.util.List; | |
22 | +import java.util.Optional; | |
23 | +import java.util.stream.Collectors; | |
24 | + | |
25 | +@Service | |
26 | +@RequiredArgsConstructor | |
27 | +@Slf4j | |
28 | +public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCagegoryMapper, TkDeviceCagegoryEntity> | |
29 | + implements TkDeviceCagegoryService { | |
30 | + | |
31 | + @Override | |
32 | + public TkDeviceCagegoryDTO save(TkDeviceCagegoryDTO tkDeviceCagegoryDTO) throws ThingsboardException { | |
33 | + checkDto(tkDeviceCagegoryDTO); | |
34 | + TkDeviceCagegoryEntity entity = new TkDeviceCagegoryEntity(); | |
35 | + if (StringUtils.isBlank(tkDeviceCagegoryDTO.getId())) { | |
36 | + tkDeviceCagegoryDTO.copyToEntity(entity); | |
37 | + baseMapper.insert(entity); | |
38 | + } else { | |
39 | + LambdaQueryWrapper<TkDeviceCagegoryEntity> filter = new QueryWrapper<TkDeviceCagegoryEntity>().lambda() | |
40 | + .eq(TkDeviceCagegoryEntity::getId, tkDeviceCagegoryDTO.getId()); | |
41 | + entity = tkDeviceCagegoryDTO.getEntity(TkDeviceCagegoryEntity.class); | |
42 | + baseMapper.update(entity, filter); | |
43 | + } | |
44 | + | |
45 | + | |
46 | + entity.copyToDTO(tkDeviceCagegoryDTO); | |
47 | + return tkDeviceCagegoryDTO; | |
48 | + } | |
49 | + | |
50 | + private void checkDto(TkDeviceCagegoryDTO dto) throws ThingsboardException { | |
51 | + if (StringUtils.isBlank(dto.getTenantId())) { | |
52 | + dto.setTenantId(SpringBeanUtils.getTenantId().getId().toString()); | |
53 | + } | |
54 | + } | |
55 | + | |
56 | + @Override | |
57 | + public TkDeviceCagegoryDTO detail(String id) throws ThingsboardException { | |
58 | + TkDeviceCagegoryDTO result = null; | |
59 | + TkDeviceCagegoryEntity entity = baseMapper.selectById(id); | |
60 | + if (entity != null) { | |
61 | + result = new TkDeviceCagegoryDTO(); | |
62 | + entity.copyToDTO(result); | |
63 | + } | |
64 | + return result; | |
65 | + } | |
66 | + | |
67 | + @Override | |
68 | + public boolean delete(String id) throws ThingsboardException { | |
69 | + List<TkDeviceCagegoryDTO> cagegoryList = getCagegoryByParentid(id); | |
70 | + if (CollectionUtils.isNotEmpty(cagegoryList)) { | |
71 | + throw new TkDataValidationException("类别下还有子项不能删除不存在!"); | |
72 | + } | |
73 | + int count = baseMapper.deleteById(id); | |
74 | + return count > 0; | |
75 | + } | |
76 | + | |
77 | + @Override | |
78 | + public List<TkDeviceCagegoryDTO> getAllCagegory() throws ThingsboardException { | |
79 | + List<TkDeviceCagegoryDTO> topMenuList = getCagegoryByParentid(null); | |
80 | + List<TkDeviceCagegoryDTO> subMenu = getSubCategory(); | |
81 | + TkDeviceCagegoryUtil utils = new TkDeviceCagegoryUtil(topMenuList, subMenu); | |
82 | + List<TkDeviceCagegoryDTO> result = utils.getTree(); | |
83 | + return result; | |
84 | + } | |
85 | + | |
86 | + private List<TkDeviceCagegoryDTO> getSubCategory() throws ThingsboardException { | |
87 | + QueryWrapper<TkDeviceCagegoryEntity> queryWrapper = new QueryWrapper(); | |
88 | + LambdaQueryWrapper<TkDeviceCagegoryEntity> lambda = queryWrapper.lambda(); | |
89 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
90 | + lambda.eq(TkDeviceCagegoryEntity::getTenantId, tenantId.getId().toString()); | |
91 | + lambda.isNotNull(TkDeviceCagegoryEntity::getParentId); | |
92 | + lambda.orderByAsc(TkDeviceCagegoryEntity::getCagegoryOrder); | |
93 | + | |
94 | + List<TkDeviceCagegoryEntity> entityList = baseMapper.selectList(queryWrapper); | |
95 | + return Optional.ofNullable(entityList).map(all -> all.stream().map(item -> item.getDTO(TkDeviceCagegoryDTO.class)) | |
96 | + .collect(Collectors.toList())).orElse(null); | |
97 | + } | |
98 | + | |
99 | + | |
100 | + @Override | |
101 | + public List<TkDeviceCagegoryDTO> getCagegoryByParentid(String parentId) throws ThingsboardException { | |
102 | + QueryWrapper<TkDeviceCagegoryEntity> queryWrapper = new QueryWrapper(); | |
103 | + LambdaQueryWrapper<TkDeviceCagegoryEntity> lambda = queryWrapper.lambda(); | |
104 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
105 | + lambda.eq(TkDeviceCagegoryEntity::getTenantId, tenantId.getId().toString()); | |
106 | + if (StringUtils.isBlank(parentId)) { | |
107 | + lambda.isNull(TkDeviceCagegoryEntity::getParentId); | |
108 | + } else { | |
109 | + lambda.eq(TkDeviceCagegoryEntity::getParentId, parentId); | |
110 | + } | |
111 | + | |
112 | + lambda.orderByAsc(TkDeviceCagegoryEntity::getCagegoryOrder); | |
113 | + | |
114 | + List<TkDeviceCagegoryEntity> entityList = baseMapper.selectList(queryWrapper); | |
115 | + return Optional.ofNullable(entityList).map(all -> all.stream().map(item -> item.getDTO(TkDeviceCagegoryDTO.class)) | |
116 | + .collect(Collectors.toList())).orElse(null); | |
117 | + } | |
118 | +} | ... | ... |
... | ... | @@ -2,15 +2,16 @@ package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5 | -import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
6 | 6 | import lombok.RequiredArgsConstructor; |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
8 | 8 | import org.apache.commons.lang3.StringUtils; |
9 | 9 | import org.springframework.stereotype.Service; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | +import org.thingsboard.server.common.data.id.TenantId; | |
11 | 12 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; |
13 | -import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.enums.MalfunctionReasonStatusEnum; | |
14 | 15 | import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
16 | 17 | import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; |
... | ... | @@ -19,7 +20,6 @@ import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
19 | 20 | import org.thingsboard.server.dao.yunteng.service.TkMalfunctionReasonService; |
20 | 21 | |
21 | 22 | import java.util.List; |
22 | -import java.util.Map; | |
23 | 23 | import java.util.Optional; |
24 | 24 | import java.util.stream.Collectors; |
25 | 25 | |
... | ... | @@ -29,35 +29,49 @@ import java.util.stream.Collectors; |
29 | 29 | public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfunctionReasonMapper, TkMalfunctionReasonEntity> |
30 | 30 | implements TkMalfunctionReasonService { |
31 | 31 | @Override |
32 | - public TkPageData<TkMalfunctionReasonDTO> page(String tenantId, Map<String, Object> queryMap) { | |
32 | + public TkPageData<TkMalfunctionReasonDTO> page(TkMalfunctionReasonDTO condition) throws ThingsboardException { | |
33 | 33 | |
34 | 34 | QueryWrapper<TkMalfunctionReasonEntity> wrapper = new QueryWrapper<>(); |
35 | 35 | LambdaQueryWrapper<TkMalfunctionReasonEntity> lambda = wrapper.lambda(); |
36 | - lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId); | |
37 | - if (queryMap != null && queryMap.get("code") != null) { | |
38 | - lambda.like(TkMalfunctionReasonEntity::getCode, queryMap.get("code").toString()); | |
36 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
37 | + lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId.getId().toString()); | |
38 | + if (StringUtils.isNotBlank(condition.getCode())) { | |
39 | + lambda.like(TkMalfunctionReasonEntity::getCode, condition.getCode()); | |
39 | 40 | } |
40 | - if (queryMap != null && queryMap.get("reason") != null) { | |
41 | - lambda.like(TkMalfunctionReasonEntity::getReason, queryMap.get("reason").toString()); | |
41 | + | |
42 | + if (StringUtils.isNotBlank(condition.getReason())) { | |
43 | + lambda.like(TkMalfunctionReasonEntity::getReason, condition.getReason()); | |
42 | 44 | } |
43 | 45 | |
44 | - IPage<TkMalfunctionReasonEntity> page = baseMapper.selectPage( | |
45 | - getPage(queryMap, "create_time", false), wrapper); | |
46 | + if (StringUtils.isNotBlank(condition.getStatus())) { | |
47 | + lambda.eq(TkMalfunctionReasonEntity::getStatus, condition.getStatus()); | |
48 | + } | |
46 | 49 | |
50 | + Page<TkMalfunctionReasonEntity> page = new Page<>(); | |
51 | + page.setCurrent(condition.getPage()); | |
52 | + page.setSize(condition.getPageSize()); | |
53 | + page = baseMapper.selectPage(page, wrapper); | |
47 | 54 | return getPageData(page, TkMalfunctionReasonDTO.class); |
48 | 55 | } |
49 | 56 | |
50 | 57 | @Override |
51 | - public List<TkMalfunctionReasonDTO> list(String tenantId, Map<String, Object> queryMap) { | |
58 | + public List<TkMalfunctionReasonDTO> list(TkMalfunctionReasonDTO condition) throws ThingsboardException { | |
52 | 59 | QueryWrapper<TkMalfunctionReasonEntity> wrapper = new QueryWrapper<>(); |
53 | 60 | LambdaQueryWrapper<TkMalfunctionReasonEntity> lambda = wrapper.lambda(); |
54 | - lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId); | |
55 | - if (queryMap != null && queryMap.get("code") != null) { | |
56 | - lambda.like(TkMalfunctionReasonEntity::getCode, queryMap.get("code").toString()); | |
61 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
62 | + lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId.getId().toString()); | |
63 | + if (StringUtils.isNotBlank(condition.getCode())) { | |
64 | + lambda.like(TkMalfunctionReasonEntity::getCode, condition.getCode()); | |
65 | + } | |
66 | + | |
67 | + if (StringUtils.isNotBlank(condition.getReason())) { | |
68 | + lambda.like(TkMalfunctionReasonEntity::getReason, condition.getReason()); | |
57 | 69 | } |
58 | - if (queryMap != null && queryMap.get("reason") != null) { | |
59 | - lambda.like(TkMalfunctionReasonEntity::getReason, queryMap.get("reason").toString()); | |
70 | + | |
71 | + if (StringUtils.isNotBlank(condition.getStatus())) { | |
72 | + lambda.eq(TkMalfunctionReasonEntity::getStatus, condition.getStatus()); | |
60 | 73 | } |
74 | + | |
61 | 75 | List<TkMalfunctionReasonEntity> entitys = baseMapper.selectList(wrapper); |
62 | 76 | return Optional.ofNullable(entitys).map(all -> all.stream().map(item -> item.getDTO(TkMalfunctionReasonDTO.class)) |
63 | 77 | .collect(Collectors.toList())).orElse(null); |
... | ... | @@ -83,6 +97,33 @@ public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfun |
83 | 97 | return tkMalfunctionReasonDTO; |
84 | 98 | } |
85 | 99 | |
100 | + @Override | |
101 | + public TkMalfunctionReasonDTO detail(String id) throws ThingsboardException { | |
102 | + TkMalfunctionReasonDTO result = null; | |
103 | + TkMalfunctionReasonEntity entity = baseMapper.selectById(id); | |
104 | + if (entity != null) { | |
105 | + result = new TkMalfunctionReasonDTO(); | |
106 | + entity.copyToDTO(result); | |
107 | + } | |
108 | + return result; | |
109 | + } | |
110 | + | |
111 | + @Override | |
112 | + public void updateStatus(String id, String status) throws ThingsboardException { | |
113 | + TkMalfunctionReasonEntity entity = baseMapper.selectById(id); | |
114 | + if (entity == null) { | |
115 | + throw new TkDataValidationException("故障原因不存在!"); | |
116 | + } | |
117 | + MalfunctionReasonStatusEnum statusEnum = MalfunctionReasonStatusEnum.valueOf(status); | |
118 | + if (statusEnum == null) { | |
119 | + throw new TkDataValidationException("故障原因状态不存在!"); | |
120 | + } | |
121 | + entity.setStatus(statusEnum.name()); | |
122 | + LambdaQueryWrapper<TkMalfunctionReasonEntity> filter = new QueryWrapper<TkMalfunctionReasonEntity>().lambda() | |
123 | + .eq(TkMalfunctionReasonEntity::getId, entity.getId()); | |
124 | + baseMapper.update(entity, filter); | |
125 | + } | |
126 | + | |
86 | 127 | private void checkDto(TkMalfunctionReasonDTO dto) throws ThingsboardException { |
87 | 128 | if (StringUtils.isBlank(dto.getTenantId())) { |
88 | 129 | dto.setTenantId(SpringBeanUtils.getTenantId().getId().toString()); | ... | ... |
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.TkDeviceCagegoryEntity; | |
6 | + | |
7 | +@Mapper | |
8 | +public interface TkDeviceCagegoryMapper extends BaseMapper<TkDeviceCagegoryEntity> { | |
9 | + | |
10 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/TkDeviceCagegoryService.java
0 → 100644
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.TkDeviceCagegoryDTO; | |
5 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceCagegoryEntity; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +public interface TkDeviceCagegoryService extends BaseService<TkDeviceCagegoryEntity> { | |
10 | + | |
11 | + TkDeviceCagegoryDTO save(TkDeviceCagegoryDTO tkDeviceCagegoryDTO) throws ThingsboardException; | |
12 | + | |
13 | + TkDeviceCagegoryDTO detail(String id) throws ThingsboardException; | |
14 | + | |
15 | + boolean delete(String id) throws ThingsboardException; | |
16 | + | |
17 | + List<TkDeviceCagegoryDTO> getAllCagegory() throws ThingsboardException; | |
18 | + | |
19 | + List<TkDeviceCagegoryDTO> getCagegoryByParentid(String parentId) throws ThingsboardException; | |
20 | +} | ... | ... |
... | ... | @@ -7,16 +7,19 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
7 | 7 | import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; |
8 | 8 | |
9 | 9 | import java.util.List; |
10 | -import java.util.Map; | |
11 | 10 | |
12 | 11 | public interface TkMalfunctionReasonService extends BaseService<TkMalfunctionReasonEntity> { |
13 | 12 | |
14 | - TkPageData<TkMalfunctionReasonDTO> page(String tenantId, Map<String, Object> queryMap); | |
13 | + TkPageData<TkMalfunctionReasonDTO> page(TkMalfunctionReasonDTO condition) throws ThingsboardException; | |
15 | 14 | |
16 | - List<TkMalfunctionReasonDTO> list(String tenantId, Map<String, Object> queryMap); | |
15 | + List<TkMalfunctionReasonDTO> list(TkMalfunctionReasonDTO condition) throws ThingsboardException; | |
17 | 16 | |
18 | 17 | TkMalfunctionReasonDTO save(TkMalfunctionReasonDTO tkMalfunctionReasonDTO) throws ThingsboardException; |
19 | 18 | |
19 | + TkMalfunctionReasonDTO detail(String id) throws ThingsboardException; | |
20 | + | |
21 | + void updateStatus(String id, String status) throws ThingsboardException; | |
22 | + | |
20 | 23 | boolean delete(String id); |
21 | 24 | |
22 | 25 | ... | ... |
... | ... | @@ -96,7 +96,7 @@ |
96 | 96 | profile_id,ifd.device_profile_id |
97 | 97 | ,ifd.sn,ifd.brand,ifd.name,ifd.alias,ifd.device_info,ifd.tenant_id |
98 | 98 | ,ifd.label,ifd.device_type,ifd.created_time,ifd.update_time,ifd.creator, |
99 | - ifd.updater,ifd.organization_id,ifd.alarm_status,ifd.description | |
99 | + ifd.updater,ifd.organization_id,ifd.alarm_status,ifd.description,ifd.director_id,ifd.category_id | |
100 | 100 | <!-- ,attrAt.long_v last_activity_time,attrCt.long_v last_connect_time--> |
101 | 101 | </sql> |
102 | 102 | <sql id="detailColumns"> | ... | ... |