fix:设备地图相关接口迁移

V0.5.x
tangfudong 2023-06-29 18:35:29 +08:00
parent 6e5de54e6e
commit cec5a72856
9 changed files with 83 additions and 62 deletions

View File

@ -134,5 +134,5 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
* *
* @return * @return
*/ */
List<Map<String, Object>> findByProductNodeType(String uid); List<DeviceInfo> findByProductNodeType(String uid);
} }

View File

@ -10,12 +10,12 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.Constants; import cc.iotkit.common.constant.Constants;
import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.data.cache.DeviceInfoCacheEvict; import cc.iotkit.data.cache.DeviceInfoCacheEvict;
import cc.iotkit.data.cache.DeviceInfoCachePut; import cc.iotkit.data.cache.DeviceInfoCachePut;
import cc.iotkit.common.api.Paging; import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.stats.DataItem; import cc.iotkit.model.stats.DataItem;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -131,7 +131,7 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
} }
@Override @Override
public List<Map<String, Object>> findByProductNodeType(String uid) { public List<DeviceInfo> findByProductNodeType(String uid) {
return deviceInfoData.findByProductNodeType(uid); return deviceInfoData.findByProductNodeType(uid);
} }

View File

@ -10,8 +10,8 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.stats.DataItem; import cc.iotkit.model.stats.DataItem;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -172,7 +172,7 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
} }
@Override @Override
public List<Map<String, Object>> findByProductNodeType(String uid) { public List<DeviceInfo> findByProductNodeType(String uid) {
return deviceInfoData.findByProductNodeType(uid); return deviceInfoData.findByProductNodeType(uid);
} }

View File

@ -14,8 +14,9 @@ import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.product.Category; import cc.iotkit.model.product.Category;
import cc.iotkit.model.product.Product; import cc.iotkit.model.product.Product;
import cc.iotkit.model.stats.DataItem; import cc.iotkit.model.stats.DataItem;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -28,28 +29,34 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo;
import static cc.iotkit.data.model.QTbProduct.tbProduct;
@Primary @Primary
@Service @Service
@RequiredArgsConstructor
public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceInfo, String> { public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceInfo, String> {
@Autowired
private DeviceInfoRepository deviceInfoRepository; private final DeviceInfoRepository deviceInfoRepository;
@Autowired
private DeviceSubUserRepository deviceSubUserRepository; private final DeviceSubUserRepository deviceSubUserRepository;
@Autowired
private DeviceGroupMappingRepository deviceGroupMappingRepository; private final DeviceGroupMappingRepository deviceGroupMappingRepository;
@Autowired
private DeviceGroupRepository deviceGroupRepository; private final DeviceGroupRepository deviceGroupRepository;
@Autowired
private DeviceTagRepository deviceTagRepository; private final DeviceTagRepository deviceTagRepository;
@Autowired
private JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
@Autowired
@Qualifier("productDataCache") @Qualifier("productDataCache")
private IProductData productData; private final IProductData productData;
@Autowired
@Qualifier("categoryDataCache") @Qualifier("categoryDataCache")
private ICategoryData categoryData; private final ICategoryData categoryData;
private final JPAQueryFactory jpaQueryFactory;
@Override @Override
public JpaRepository getBaseRepository() { public JpaRepository getBaseRepository() {
@ -190,15 +197,10 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
} }
@Override @Override
public List<Map<String, Object>> findByProductNodeType(String uid) { public List<DeviceInfo> findByProductNodeType(String uid) {
String sql = "SELECT\n" + List<TbDeviceInfo> devices=jpaQueryFactory.select(tbDeviceInfo).from(tbDeviceInfo)
"a.id,\n" + .join(tbProduct).on(tbProduct.nodeType.eq(0).and(tbDeviceInfo.productKey.eq(tbProduct.productKey))).fetch();
"a.device_name\n" + return MapstructUtils.convert(devices,DeviceInfo.class);
"FROM device_info a JOIN product p ON p.node_type=0 AND a.product_key=p.id";
if (StringUtils.isNotBlank(uid)) {
sql += " WHERE a.uid='" + uid + "'";
}
return jdbcTemplate.queryForList(sql);
} }
@Override @Override

View File

@ -10,13 +10,8 @@
package cc.iotkit.manager.controller; package cc.iotkit.manager.controller;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request; import cc.iotkit.common.api.Request;
import cc.iotkit.common.constant.Constants;
import cc.iotkit.common.enums.ErrCode;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.satoken.utils.AuthUtil;
import cc.iotkit.common.utils.ReflectUtil;
import cc.iotkit.common.utils.UniqueIdUtil;
import cc.iotkit.manager.dto.bo.device.*; import cc.iotkit.manager.dto.bo.device.*;
import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo; import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo;
import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo;
@ -25,26 +20,29 @@ import cc.iotkit.manager.dto.bo.thingmodel.ThingModelMessageBo;
import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo;
import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo;
import cc.iotkit.manager.service.*; import cc.iotkit.manager.service.DeviceService;
import cc.iotkit.manager.service.IDeviceService;
import cc.iotkit.manager.service.IProductService;
import cc.iotkit.model.InvokeResult; import cc.iotkit.model.InvokeResult;
import cc.iotkit.common.api.Paging;
import cc.iotkit.model.device.DeviceConfig; import cc.iotkit.model.device.DeviceConfig;
import cc.iotkit.model.device.DeviceGroup; import cc.iotkit.model.device.DeviceGroup;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;
import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.device.message.ThingModelMessage;
import io.swagger.annotations.*; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Api(tags = {"设备"}) @Api(tags = {"设备"})
@Slf4j @Slf4j
@ -99,9 +97,9 @@ public class DeviceController {
return deviceServiceImpl.selectChildrenPageList(deviceId); return deviceServiceImpl.selectChildrenPageList(deviceId);
} }
@ApiOperation("获取网关") @ApiOperation("获取网关设备")
@PostMapping("/parentDevices") @PostMapping("/getParentDevices")
public List<Map<String, Object>> getParentDevices() { public List<ParentDeviceVo> getParentDevices() {
return deviceServiceImpl.getParentDevices(); return deviceServiceImpl.getParentDevices();
} }

View File

@ -1,28 +1,22 @@
package cc.iotkit.manager.dto.vo.deviceinfo; package cc.iotkit.manager.dto.vo.deviceinfo;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping; import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping; import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.ToString;
import java.util.Date;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
@ApiModel(value = "DeviceInfoVo") @ApiModel(value = "DeviceInfoVo")
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@AutoMapper(target = DeviceInfo.class) @AutoMapper(target = DeviceInfo.class)
public class DeviceInfoVo implements Serializable { public class DeviceInfoVo implements Serializable {
private static final long serialVersionUID = -1L; private static final long serialVersionUID = -1L;

View File

@ -0,0 +1,21 @@
package cc.iotkit.manager.dto.vo.deviceinfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Authortfd
* @Date2023/6/29 14:30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ParentDeviceVo {
private String id;
private String deviceName;
}

View File

@ -11,6 +11,7 @@ import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo;
import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo;
import cc.iotkit.model.device.DeviceConfig; import cc.iotkit.model.device.DeviceConfig;
import cc.iotkit.model.device.DeviceGroup; import cc.iotkit.model.device.DeviceGroup;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
@ -19,7 +20,6 @@ import cc.iotkit.model.device.message.ThingModelMessage;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Author: jay * @Author: jay
@ -34,7 +34,7 @@ public interface IDeviceService {
List<DeviceInfoVo> selectChildrenPageList(String deviceId); List<DeviceInfoVo> selectChildrenPageList(String deviceId);
List<Map<String, Object>> getParentDevices(); List<ParentDeviceVo> getParentDevices();
DeviceInfo getDetail(String deviceId); DeviceInfo getDetail(String deviceId);

View File

@ -24,6 +24,7 @@ import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo;
import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo;
import cc.iotkit.manager.service.DataOwnerService; import cc.iotkit.manager.service.DataOwnerService;
import cc.iotkit.manager.service.DeferredDataConsumer; import cc.iotkit.manager.service.DeferredDataConsumer;
import cc.iotkit.manager.service.DeviceService; import cc.iotkit.manager.service.DeviceService;
@ -44,7 +45,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.stream.Collectors;
/** /**
* @Author: jay * @Author: jay
@ -157,12 +158,17 @@ public class DeviceServiceImpl implements IDeviceService {
} }
@Override @Override
public List<Map<String, Object>> getParentDevices() { public List<ParentDeviceVo> getParentDevices() {
String uid = ""; String uid = "";
List<ParentDeviceVo> pdv = null;
if (!AuthUtil.isAdmin()) { if (!AuthUtil.isAdmin()) {
uid = AuthUtil.getUserId(); uid = AuthUtil.getUserId();
} }
return deviceInfoData.findByProductNodeType(uid); List<DeviceInfo> ret=deviceInfoData.findByProductNodeType(uid);
if(ret.size()>0){
pdv=ret.stream().map(r->ParentDeviceVo.builder().id(r.getId()).deviceName(r.getDeviceName()).build()).collect(Collectors.toList());
}
return pdv;
} }
@Override @Override