【新增】 产品物模型分页

This commit is contained in:
安浩浩 2024-09-29 21:37:40 +08:00
parent 1719b69ef7
commit 1995c322e7
9 changed files with 91 additions and 18 deletions

View File

@ -7,13 +7,13 @@ import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
/** /**
* IOT 物模型功能类型枚举类 * IOT 产品功能类型枚举类
* *
* @author ahh * @author ahh
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotThingModelTypeEnum implements IntArrayValuable { public enum IotProductFunctionTypeEnum implements IntArrayValuable {
/** /**
* 属性 * 属性
@ -28,7 +28,7 @@ public enum IotThingModelTypeEnum implements IntArrayValuable {
*/ */
EVENT(3, "事件"); EVENT(3, "事件");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotThingModelTypeEnum::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray();
/** /**
* 类型 * 类型

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction; package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert; import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
@ -71,4 +74,12 @@ public class IotThinkModelFunctionController {
List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId); List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId);
return success(respVO); return success(respVO);
} }
@GetMapping("/page")
@Operation(summary = "获得IoT 产品物模型分页")
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
}
} }

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class IotThinkModelFunctionPageReqVO extends PageParam {
@Schema(description = "功能标识")
private String identifier;
@Schema(description = "功能名称", example = "张三")
private String name;
@Schema(description = "功能类型", example = "1")
@InEnum(IotProductFunctionTypeEnum.class)
private Integer type;
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "产品ID不能为空")
private Long productId;
}

View File

@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum; import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -38,7 +38,7 @@ public class IotThinkModelFunctionSaveReqVO {
@Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "功能类型不能为空") @NotNull(message = "功能类型不能为空")
@InEnum(IotThingModelTypeEnum.class) @InEnum(IotProductFunctionTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum; import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -26,21 +26,21 @@ public interface IotThinkModelFunctionConvert {
IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean); IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean);
default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) { default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
return bean.getProperty(); return bean.getProperty();
} }
return null; return null;
} }
default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) { default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotThingModelTypeEnum.EVENT.getType())) { if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.EVENT.getType())) {
return bean.getEvent(); return bean.getEvent();
} }
return null; return null;
} }
default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) { default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotThingModelTypeEnum.SERVICE.getType())) { if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.SERVICE.getType())) {
return bean.getService(); return bean.getService();
} }
return null; return null;

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@ -65,7 +66,7 @@ public class IotThinkModelFunctionDO extends BaseDO {
/** /**
* 功能类型 * 功能类型
* <p> * <p>
* 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum} * 枚举 {@link IotProductFunctionTypeEnum}
*/ */
private Integer type; private Integer type;

View File

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction; package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -15,6 +17,16 @@ import java.util.List;
@Mapper @Mapper
public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFunctionDO> { public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFunctionDO> {
default PageResult<IotThinkModelFunctionDO> selectPage(IotThinkModelFunctionPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<IotThinkModelFunctionDO>()
.eqIfPresent(IotThinkModelFunctionDO::getIdentifier, reqVO.getIdentifier())
.likeIfPresent(IotThinkModelFunctionDO::getName, reqVO.getName())
.eqIfPresent(IotThinkModelFunctionDO::getType, reqVO.getType())
.eqIfPresent(IotThinkModelFunctionDO::getProductId, reqVO.getProductId())
.orderByDesc(IotThinkModelFunctionDO::getId));
}
default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) { default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) {
return selectOne(IotThinkModelFunctionDO::getProductId, productId, return selectOne(IotThinkModelFunctionDO::getProductId, productId,
IotThinkModelFunctionDO::getIdentifier, identifier); IotThinkModelFunctionDO::getIdentifier, identifier);

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.iot.service.thinkmodelfunction; package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -51,4 +53,12 @@ public interface IotThinkModelFunctionService {
* @return 产品物模型列表 * @return 产品物模型列表
*/ */
List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductId(Long productId); List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductId(Long productId);
/**
* 获得产品物模型分页
*
* @param pageReqVO 分页查询
* @return 产品物模型分页
*/
PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
} }

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
@ -11,12 +12,13 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArraySpecs; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArraySpecs;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArrayType; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArrayType;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelTextType; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelTextType;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert; import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper; import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper;
import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum; import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum; import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -55,7 +57,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.insert(function); thinkModelFunctionMapper.insert(function);
// 3. 如果创建的是属性需要更新默认的事件和服务 // 3. 如果创建的是属性需要更新默认的事件和服务
if (Objects.equals(createReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
} }
return function.getId(); return function.getId();
@ -82,7 +84,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.updateById(thinkModelFunction); thinkModelFunctionMapper.updateById(thinkModelFunction);
// 4. 如果更新的是属性需要更新默认的事件和服务 // 4. 如果更新的是属性需要更新默认的事件和服务
if (Objects.equals(updateReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
} }
} }
@ -107,7 +109,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.deleteById(id); thinkModelFunctionMapper.deleteById(id);
// 3. 如果删除的是属性需要更新默认的事件和服务 // 3. 如果删除的是属性需要更新默认的事件和服务
if (Objects.equals(functionDO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { if (Objects.equals(functionDO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey()); createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey());
} }
} }
@ -133,13 +135,18 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
return thinkModelFunctionMapper.selectListByProductId(productId); return thinkModelFunctionMapper.selectListByProductId(productId);
} }
@Override
public PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
return thinkModelFunctionMapper.selectPage(pageReqVO);
}
/** /**
* 创建默认的事件和服务 * 创建默认的事件和服务
*/ */
public void createDefaultEventsAndServices(Long productId, String productKey) { public void createDefaultEventsAndServices(Long productId, String productKey) {
// 1. 获取当前属性列表 // 1. 获取当前属性列表
List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper
.selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType()); .selectListByProductIdAndType(productId, IotProductFunctionTypeEnum.PROPERTY.getType());
// 2. 生成新的事件和服务列表 // 2. 生成新的事件和服务列表
List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>(); List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>();
@ -166,7 +173,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes( List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
productId, productId,
Arrays.asList("post", "set", "get"), Arrays.asList("post", "set", "get"),
Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType()) Arrays.asList(IotProductFunctionTypeEnum.EVENT.getType(), IotProductFunctionTypeEnum.SERVICE.getType())
); );
// 3.1 使用 diffList 方法比较新旧列表 // 3.1 使用 diffList 方法比较新旧列表
@ -229,7 +236,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(event.getIdentifier()) .setIdentifier(event.getIdentifier())
.setName(event.getName()) .setName(event.getName())
.setDescription(event.getDescription()) .setDescription(event.getDescription())
.setType(IotThingModelTypeEnum.EVENT.getType()) .setType(IotProductFunctionTypeEnum.EVENT.getType())
.setEvent(event); .setEvent(event);
} }
@ -243,7 +250,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(service.getIdentifier()) .setIdentifier(service.getIdentifier())
.setName(service.getName()) .setName(service.getName())
.setDescription(service.getDescription()) .setDescription(service.getDescription())
.setType(IotThingModelTypeEnum.SERVICE.getType()) .setType(IotProductFunctionTypeEnum.SERVICE.getType())
.setService(service); .setService(service);
} }