Commit 126d0080af837fc3d45780716936ae9dc36f00e3

Authored by 盛长浩
1 parent a4f07b37

设备管理类型功能

... ... @@ -386,3 +386,24 @@ CREATE TABLE "public"."qg_preserve_detail_status" (
386 386 );
387 387
388 388 COMMENT ON TABLE "public"."qg_preserve_detail_status" IS '保养记录明细状态';
  389 +
  390 +--智能设备管理
  391 +--设备类型
  392 +CREATE TABLE "public"."qg_brain_device_category" (
  393 +"id" varchar(36) NOT NULL,
  394 +"name" varchar(100),
  395 +"code" varchar(100),
  396 +"status" varchar(50),
  397 +"notes" varchar(500),
  398 +"create_time" timestamp(6),
  399 +"creator" varchar(36),
  400 +"updater" varchar(36),
  401 +"update_time" timestamp(6),
  402 +CONSTRAINT "qg_brain_device_category_pkey" PRIMARY KEY ("id")
  403 +);
  404 +
  405 +COMMENT ON TABLE "public"."qg_brain_device_category" IS '设备类型';
  406 +COMMENT ON COLUMN "public"."qg_brain_device_category"."name" IS '设备类型名称';
  407 +COMMENT ON COLUMN "public"."qg_brain_device_category"."code" IS '设备类型编码';
  408 +COMMENT ON COLUMN "public"."qg_brain_device_category"."status" IS '状态';
  409 +COMMENT ON COLUMN "public"."qg_brain_device_category"."notes" IS '备注';
... ...
  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.dto.BrainDeviceCategoryDTO;
  13 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
  14 +import org.thingsboard.server.controller.BaseController;
  15 +import org.thingsboard.server.dao.yunteng.service.BrainDeviceCategoryService;
  16 +import org.thingsboard.server.queue.util.TbCoreComponent;
  17 +
  18 +import java.util.HashMap;
  19 +import java.util.Map;
  20 +
  21 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE;
  22 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE;
  23 +
  24 +@RestController
  25 +@TbCoreComponent
  26 +@RequiredArgsConstructor
  27 +@RequestMapping("api/yt/brain/category")
  28 +@Api(tags = {"巡检记录"})
  29 +@Slf4j
  30 +public class BrainDeviceCategoryController extends BaseController {
  31 + private final BrainDeviceCategoryService brainDeviceCategoryService;
  32 +
  33 + @PostMapping("/pageData")
  34 + @ApiOperation("分页查询")
  35 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  36 + public TkPageData<BrainDeviceCategoryDTO> page(
  37 + @RequestParam(PAGE_SIZE) int pageSize,
  38 + @RequestParam(PAGE) int page,
  39 + @RequestParam(value = "name", required = false) String name,
  40 + @RequestParam(value = "code", required = false) String code,
  41 + @RequestParam(value = "status", required = false) String status
  42 + ) throws ThingsboardException {
  43 + Map<String, Object> queryMap = new HashMap<>();
  44 + queryMap.put(PAGE_SIZE, pageSize);
  45 + queryMap.put(PAGE, page);
  46 + if (StringUtils.isNotBlank(name)) {
  47 + queryMap.put("name", name);
  48 + }
  49 +
  50 + if (StringUtils.isNotBlank(code)) {
  51 + queryMap.put("code", code);
  52 + }
  53 +
  54 + if (StringUtils.isNotBlank(status)) {
  55 + queryMap.put("status", status);
  56 + }
  57 + return brainDeviceCategoryService.page(queryMap);
  58 + }
  59 +
  60 + @PostMapping("/save")
  61 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  62 + public ResponseEntity<BrainDeviceCategoryDTO> save(@RequestBody BrainDeviceCategoryDTO brainDeviceCategoryDTO) throws ThingsboardException {
  63 + BrainDeviceCategoryDTO dto = brainDeviceCategoryService.save(brainDeviceCategoryDTO);
  64 + return ResponseEntity.ok(dto);
  65 + }
  66 +
  67 + @GetMapping("/detail")
  68 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  69 + public ResponseEntity<BrainDeviceCategoryDTO> detail(@RequestParam("id") String id) throws ThingsboardException {
  70 + return ResponseEntity.ok(brainDeviceCategoryService.detail(id));
  71 + }
  72 +
  73 + @GetMapping("/delete")
  74 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
  75 + public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException {
  76 + return ResponseEntity.ok(brainDeviceCategoryService.delete(id));
  77 + }
  78 +
  79 +}
... ...
  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 BrainDeviceCategoryDTO extends BaseDTO {
  10 +
  11 + @ApiModelProperty(value = "设备类型名称")
  12 + private String name;
  13 + @ApiModelProperty(value = "设备类型编码")
  14 + private String code;
  15 + @ApiModelProperty(value = "状态")
  16 + private String status;
  17 + @ApiModelProperty(value = "备注")
  18 + private String notes;
  19 +}
... ...
1 1 /**
2 2 * Copyright © 2016-2024 The Thingsboard Authors
3   - *
  3 + * <p>
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
6 6 * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
  7 + * <p>
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + * <p>
10 10 * Unless required by applicable law or agreed to in writing, software
11 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
... ... @@ -45,7 +45,7 @@ public class ModelConstants {
45 45 */
46 46 public static final String ID_PROPERTY = "id";
47 47 public static final String CREATED_TIME_PROPERTY = "created_time";
48   - //thingskit
  48 + //thingskit
49 49 public static final String STATUS_PROPERTY = "status";
50 50 public static final String USER_ID_PROPERTY = "user_id";
51 51 public static final String TENANT_ID_PROPERTY = "tenant_id";
... ... @@ -71,7 +71,7 @@ public class ModelConstants {
71 71 public static final String EVENT_TIME_COLUMN = "event_time";
72 72 public static final String EVENT_TYPE_COLUMN = "event_type";
73 73 public static final String EVENT_VALUE_COLUMN = "event_value";
74   - public static final String DATA_COMBINATION_IS_DEFAULT_PROPERTY= "is_data_combination";
  74 + public static final String DATA_COMBINATION_IS_DEFAULT_PROPERTY = "is_data_combination";
75 75
76 76 /**
77 77 * User constants.
... ... @@ -689,11 +689,16 @@ public class ModelConstants {
689 689 public static final String TKINSTALLLOCATION_TABLE_NAME = "qg_install_location";//设备台账
690 690 public static final String TKSUPPLIER_TABLE_NAME = "qg_supplier";//供应商
691 691
692   - public static final String TKINSPECTIONPLAN_TABLE_NAME= "qg_inspection_plan"; // 巡检计划
693   - public static final String TKCHECKPLAN_TABLE_NAME= "qg_check_plan"; // 巡检/保养方案
694   - public static final String TKCHECKDETAILS_TABLE_NAME= "qg_check_details"; // 巡检明细
695   - public static final String TKINSPECTIONRECORD_TABLE_NAME= "qg_inspection_record"; // 巡检记录
696   - public static final String TKINSPECTIONDETAILS_TABLE_NAME= "qg_inspection_details"; // 巡检记录明细
  692 + public static final String TKINSPECTIONPLAN_TABLE_NAME = "qg_inspection_plan"; // 巡检计划
  693 + public static final String TKCHECKPLAN_TABLE_NAME = "qg_check_plan"; // 巡检/保养方案
  694 + public static final String TKCHECKDETAILS_TABLE_NAME = "qg_check_details"; // 巡检明细
  695 + public static final String TKINSPECTIONRECORD_TABLE_NAME = "qg_inspection_record"; // 巡检记录
  696 + public static final String TKINSPECTIONDETAILS_TABLE_NAME = "qg_inspection_details"; // 巡检记录明细
  697 +
  698 + /**
  699 + * 智能设备管理模块
  700 + */
  701 + public static final String BRAINDEVICECAGEGORY_TABLE_NAME = "qg_brain_device_category";//设备类型
697 702
698 703 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};
699 704
... ...
  1 +package org.thingsboard.server.dao.yunteng.entities;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import lombok.Getter;
  6 +import lombok.Setter;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +@Getter
  11 +@Setter
  12 +public class BrainBaseEntity extends BaseEntity {
  13 +
  14 + private static final long serialVersionUID = -4315734960161684909L;
  15 +
  16 + @TableField(fill = FieldFill.INSERT)
  17 + private String creator;
  18 +
  19 + @TableField(fill = FieldFill.UPDATE)
  20 + private String updater;
  21 +
  22 + @TableField(fill = FieldFill.INSERT)
  23 + private LocalDateTime createTime;
  24 +
  25 + @TableField(fill = FieldFill.UPDATE)
  26 + private LocalDateTime updateTime;
  27 +
  28 +}
... ...
  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.BRAINDEVICECAGEGORY_TABLE_NAME, autoResultMap = true)
  14 +public class BrainDeviceCategoryEntity extends BrainBaseEntity {
  15 + /**
  16 + * 设备类型名称
  17 + */
  18 + private String name;
  19 +
  20 + /**
  21 + * 设备类型编码
  22 + */
  23 + private String code;
  24 + /**
  25 + * 状态
  26 + */
  27 + private String status;
  28 + /**
  29 + * 备注
  30 + */
  31 + private String notes;
  32 +}
... ...
  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.exception.ThingsboardException;
  12 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  13 +import org.thingsboard.server.common.data.yunteng.dto.BrainDeviceCategoryDTO;
  14 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
  15 +import org.thingsboard.server.dao.yunteng.entities.BrainDeviceCategoryEntity;
  16 +import org.thingsboard.server.dao.yunteng.mapper.BrainDeviceCategoryMapper;
  17 +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
  18 +import org.thingsboard.server.dao.yunteng.service.BrainDeviceCategoryService;
  19 +
  20 +import java.util.List;
  21 +import java.util.Map;
  22 +import java.util.UUID;
  23 +
  24 +@Service
  25 +@RequiredArgsConstructor
  26 +@Slf4j
  27 +public class BrainDeviceCategoryServiceImpl extends AbstractBaseService<BrainDeviceCategoryMapper, BrainDeviceCategoryEntity>
  28 + implements BrainDeviceCategoryService {
  29 +
  30 + @Override
  31 + public TkPageData<BrainDeviceCategoryDTO> page(Map<String, Object> params) throws ThingsboardException {
  32 + TkPageData<BrainDeviceCategoryDTO> result = new TkPageData<>();
  33 + IPage<BrainDeviceCategoryEntity> page =
  34 + getPage(params, "create_time", false);
  35 + IPage<BrainDeviceCategoryDTO> pageData = baseMapper.getDataPage(page, params);
  36 + if (pageData != null) {
  37 + result.setItems(pageData.getRecords());
  38 + }
  39 + result.setTotal(Long.valueOf(pageData.getTotal()).intValue());
  40 + return result;
  41 + }
  42 +
  43 + @Override
  44 + public BrainDeviceCategoryDTO save(BrainDeviceCategoryDTO brainDeviceCategoryDTO) throws ThingsboardException {
  45 + checkDto(brainDeviceCategoryDTO);
  46 + if (StringUtils.isBlank(brainDeviceCategoryDTO.getId()) && checkDuplicateData(brainDeviceCategoryDTO)) {
  47 + throw new TkDataValidationException("设备类型编码重复!");
  48 + }
  49 + BrainDeviceCategoryEntity entity = new BrainDeviceCategoryEntity();
  50 + if (StringUtils.isBlank(brainDeviceCategoryDTO.getId())) {
  51 + brainDeviceCategoryDTO.copyToEntity(entity);
  52 + String id = UUID.randomUUID().toString();
  53 + entity.setId(id);
  54 + baseMapper.insert(entity);
  55 + } else {
  56 + LambdaQueryWrapper<BrainDeviceCategoryEntity> filter = new QueryWrapper<BrainDeviceCategoryEntity>().lambda()
  57 + .eq(BrainDeviceCategoryEntity::getId, brainDeviceCategoryDTO.getId());
  58 + entity = brainDeviceCategoryDTO.getEntity(BrainDeviceCategoryEntity.class);
  59 + baseMapper.update(entity, filter);
  60 + }
  61 +
  62 +
  63 + entity.copyToDTO(brainDeviceCategoryDTO);
  64 + return brainDeviceCategoryDTO;
  65 + }
  66 +
  67 + private void checkDto(BrainDeviceCategoryDTO dto) throws ThingsboardException {
  68 + if (StringUtils.isBlank(dto.getName())) {
  69 + throw new TkDataValidationException("设备类型名称不能为空!");
  70 + }
  71 +
  72 + if (StringUtils.isBlank(dto.getCode())) {
  73 + throw new TkDataValidationException("设备类型编码不能为空!");
  74 + }
  75 +
  76 + if (StringUtils.isBlank(dto.getStatus())) {
  77 + throw new TkDataValidationException("设备类型状态不能为空!");
  78 + }
  79 + }
  80 +
  81 + private boolean checkDuplicateData(BrainDeviceCategoryDTO BrainDeviceCategoryDTO) throws ThingsboardException {
  82 + Boolean result = false;
  83 + QueryWrapper<BrainDeviceCategoryEntity> queryWrapper = new QueryWrapper();
  84 + LambdaQueryWrapper<BrainDeviceCategoryEntity> lambda = queryWrapper.lambda();
  85 + lambda.eq(BrainDeviceCategoryEntity::getCode, BrainDeviceCategoryDTO.getCode());
  86 + List<BrainDeviceCategoryEntity> entityList = baseMapper.selectList(queryWrapper);
  87 + if (CollectionUtils.isNotEmpty(entityList)) {
  88 + return true;
  89 + }
  90 +
  91 + return result;
  92 + }
  93 +
  94 + @Override
  95 + public BrainDeviceCategoryDTO detail(String id) throws ThingsboardException {
  96 + BrainDeviceCategoryDTO result = null;
  97 + BrainDeviceCategoryEntity entity = baseMapper.selectById(id);
  98 + if (entity != null) {
  99 + result = new BrainDeviceCategoryDTO();
  100 + entity.copyToDTO(result);
  101 + }
  102 + return result;
  103 + }
  104 +
  105 + @Override
  106 + public boolean delete(String id) throws ThingsboardException {
  107 + int count = baseMapper.deleteById(id);
  108 + return count > 0;
  109 + }
  110 +}
... ...
  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.BrainDeviceCategoryDTO;
  8 +import org.thingsboard.server.dao.yunteng.entities.BrainDeviceCategoryEntity;
  9 +
  10 +import java.util.Map;
  11 +
  12 +@Mapper
  13 +public interface BrainDeviceCategoryMapper extends BaseMapper<BrainDeviceCategoryEntity> {
  14 +
  15 + IPage<BrainDeviceCategoryDTO> getDataPage(IPage<?> page, @Param("queryMap") Map<String, Object> queryMap);
  16 +}
... ...
  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.BrainDeviceCategoryDTO;
  5 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
  6 +import org.thingsboard.server.dao.yunteng.entities.BrainDeviceCategoryEntity;
  7 +
  8 +import java.util.Map;
  9 +
  10 +public interface BrainDeviceCategoryService extends BaseService<BrainDeviceCategoryEntity> {
  11 +
  12 + TkPageData<BrainDeviceCategoryDTO> page(Map<String, Object> params) throws ThingsboardException;
  13 +
  14 + BrainDeviceCategoryDTO save(BrainDeviceCategoryDTO BrainDeviceCategoryDTO) throws ThingsboardException;
  15 +
  16 + BrainDeviceCategoryDTO detail(String id) throws ThingsboardException;
  17 +
  18 + boolean delete(String id) throws ThingsboardException;
  19 +}
... ...
  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.BrainDeviceCategoryMapper">
  5 + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.BrainDeviceCategoryDTO" id="brainDeviceCategoryMap">
  6 + <result property="id" column="id"/>
  7 + <result property="name" column="name"/>
  8 + <result property="code" column="code"/>
  9 + <result property="status" column="status"/>
  10 + <result property="notes" column="notes"/>
  11 + <result property="createTime" column="create_time"/>
  12 + <result property="updater" column="updater"/>
  13 + <result property="updateTime" column="update_time"/>
  14 + <result property="creator" column="creator"/>
  15 + </resultMap>
  16 + <select id="getDataPage" resultMap="brainDeviceCategoryMap">
  17 + SELECT
  18 + o.id,o.name,o.code,o.status,o.notes,o.create_time,o.updater,o.update_time,o.creator
  19 + from qg_brain_device_category o
  20 + <where>
  21 + <if test="queryMap.code !=null and queryMap.code !=''">
  22 + AND o.code ILIKE concat('%',#{queryMap.code}::TEXT,'%')
  23 + </if>
  24 + <if test="queryMap.name !=null and queryMap.name !=''">
  25 + AND o.name ILIKE concat('%',#{queryMap.name}::TEXT,'%')
  26 + </if>
  27 + <if test="queryMap.status !=null and queryMap.status !=''">
  28 + AND o.status = #{queryMap.status}
  29 + </if>
  30 + </where>
  31 + </select>
  32 +</mapper>
\ No newline at end of file
... ...