【新增】 产品物模型分页

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;
/**
* IOT 物模型功能类型枚举类
* IOT 产品功能类型枚举类
*
* @author ahh
*/
@AllArgsConstructor
@Getter
public enum IotThingModelTypeEnum implements IntArrayValuable {
public enum IotProductFunctionTypeEnum implements IntArrayValuable {
/**
* 属性
@ -28,7 +28,7 @@ public enum IotThingModelTypeEnum implements IntArrayValuable {
*/
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;
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.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
@ -71,4 +74,12 @@ public class IotThinkModelFunctionController {
List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId);
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.ThingModelProperty;
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 jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
@ -38,7 +38,7 @@ public class IotThinkModelFunctionSaveReqVO {
@Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "功能类型不能为空")
@InEnum(IotThingModelTypeEnum.class)
@InEnum(IotProductFunctionTypeEnum.class)
private Integer type;
@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.IotThinkModelFunctionSaveReqVO;
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.Mapping;
import org.mapstruct.factory.Mappers;
@ -26,21 +26,21 @@ public interface IotThinkModelFunctionConvert {
IotThinkModelFunctionDO convert(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 null;
}
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 null;
}
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 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.ThingModelService;
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.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -65,7 +66,7 @@ public class IotThinkModelFunctionDO extends BaseDO {
/**
* 功能类型
* <p>
* 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotThingModelTypeEnum}
* 枚举 {@link IotProductFunctionTypeEnum}
*/
private Integer type;

View File

@ -1,7 +1,9 @@
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.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import org.apache.ibatis.annotations.Mapper;
@ -15,6 +17,16 @@ import java.util.List;
@Mapper
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) {
return selectOne(IotThinkModelFunctionDO::getProductId, productId,
IotThinkModelFunctionDO::getIdentifier, identifier);

View File

@ -1,5 +1,7 @@
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.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import jakarta.validation.Valid;
@ -51,4 +53,12 @@ public interface IotThinkModelFunctionService {
* @return 产品物模型列表
*/
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.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.object.ObjectUtils;
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.ThingModelArrayType;
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.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
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.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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -55,7 +57,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.insert(function);
// 3. 如果创建的是属性需要更新默认的事件和服务
if (Objects.equals(createReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
}
return function.getId();
@ -82,7 +84,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.updateById(thinkModelFunction);
// 4. 如果更新的是属性需要更新默认的事件和服务
if (Objects.equals(updateReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
}
}
@ -107,7 +109,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.deleteById(id);
// 3. 如果删除的是属性需要更新默认的事件和服务
if (Objects.equals(functionDO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) {
if (Objects.equals(functionDO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey());
}
}
@ -133,13 +135,18 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
return thinkModelFunctionMapper.selectListByProductId(productId);
}
@Override
public PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
return thinkModelFunctionMapper.selectPage(pageReqVO);
}
/**
* 创建默认的事件和服务
*/
public void createDefaultEventsAndServices(Long productId, String productKey) {
// 1. 获取当前属性列表
List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper
.selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType());
.selectListByProductIdAndType(productId, IotProductFunctionTypeEnum.PROPERTY.getType());
// 2. 生成新的事件和服务列表
List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>();
@ -166,7 +173,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
productId,
Arrays.asList("post", "set", "get"),
Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType())
Arrays.asList(IotProductFunctionTypeEnum.EVENT.getType(), IotProductFunctionTypeEnum.SERVICE.getType())
);
// 3.1 使用 diffList 方法比较新旧列表
@ -229,7 +236,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(event.getIdentifier())
.setName(event.getName())
.setDescription(event.getDescription())
.setType(IotThingModelTypeEnum.EVENT.getType())
.setType(IotProductFunctionTypeEnum.EVENT.getType())
.setEvent(event);
}
@ -243,7 +250,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(service.getIdentifier())
.setName(service.getName())
.setDescription(service.getDescription())
.setType(IotThingModelTypeEnum.SERVICE.getType())
.setType(IotProductFunctionTypeEnum.SERVICE.getType())
.setService(service);
}