diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java new file mode 100644 index 0000000..74aa81d --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java @@ -0,0 +1,128 @@ +package com.thing.thing.dictRelation.controller; + +import com.thing.common.core.annotation.LogOperation; +import com.thing.common.core.constants.Constant; +import com.thing.common.core.validator.AssertUtils; +import com.thing.common.core.validator.ValidatorUtils; +import com.thing.common.core.validator.group.AddGroup; +import com.thing.common.core.validator.group.DefaultGroup; +import com.thing.common.core.validator.group.UpdateGroup; +import com.thing.common.core.web.response.PageData; +import com.thing.common.core.web.response.Result; + +import com.thing.thing.dictRelation.dto.IotThingStaticDictDTO; +import com.thing.thing.dictRelation.service.IotThingStaticDictService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** +* 物实体静态字典 +* +* @author xc +* @since 3.0 2024-10-08 +*/ +@RestController +@RequestMapping("v2/static/dict") +@Tag(name="物实体静态字典") +@RequiredArgsConstructor +public class IotThingStaticDictController { + + private final IotThingStaticDictService iotThingStaticDictService; + + @GetMapping("page") + @Operation(summary="分页") + @Parameters({ + @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) , + @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , + @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , + @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") + }) + public Result> page(@Parameter(hidden = true) @RequestParam Map params){ + PageData page = iotThingStaticDictService.getPageData(params, IotThingStaticDictDTO.class); + return new Result>().ok(page); + } + + @GetMapping("{id}") + @Operation(summary="信息") + public Result get(@PathVariable("id") Long id){ + IotThingStaticDictDTO data = iotThingStaticDictService.getByIdAs(id, IotThingStaticDictDTO.class); + return new Result().ok(data); + } + + @GetMapping("entityId/{entityId}") + @Operation(summary="信息") + public Result > getByEntityId(@PathVariable("entityId") Long entityId){ + List listData = iotThingStaticDictService.getByEntityId(entityId); + return new Result >().ok(listData); + } + + @PostMapping + @Operation(summary="保存") + @LogOperation("保存") + public Result save(@RequestBody IotThingStaticDictDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + iotThingStaticDictService.saveDto(dto); + return new Result<>(); + } + + @PostMapping("batchSave") + @Operation(summary="保存") + @LogOperation("保存") + public Result batchSave(@RequestBody List list){ + list.forEach(iotThingStaticDictService::saveDto); + return new Result<>(); + } + + @PutMapping + @Operation(summary="修改") + @LogOperation("修改") + public Result update(@RequestBody IotThingStaticDictDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + iotThingStaticDictService.updateDto(dto); + return new Result<>(); + } + + @DeleteMapping + @Operation(summary="删除") + @LogOperation("删除") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + iotThingStaticDictService.batchDelete(ids); + return new Result<>(); + } + + @GetMapping("group") + @Operation(summary="静态指标组") + public Result> group(){ + List groups = iotThingStaticDictService.groups(); + return new Result>().ok(groups); + } + + @GetMapping("type") + @Operation(summary="静态指标类型") + public Result> type(){ + List types = iotThingStaticDictService.types(); + return new Result>().ok(types); + } + + /** + *@GetMapping("export") + *@Operation(summary="导出") + *@LogOperation("导出") + *public void export(@Parameter(hidden = true) @RequestParam Map params, HttpServletResponse response) throws Exception { + * List list = iotThingStaticDictService.listAs(params, IotThingStaticDictDTO.class); + * //ExcelUtils.exportExcelToTarget(response, null, "物实体静态字典", list, IotThingStaticDictExcel.class); + *} + */ + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/dto/IotThingStaticDictDTO.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/dto/IotThingStaticDictDTO.java new file mode 100644 index 0000000..8ca77c1 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/dto/IotThingStaticDictDTO.java @@ -0,0 +1,44 @@ +package com.thing.thing.dictRelation.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** +* 物实体静态字典 +* +* @author xc +* @since 3.0 2024-10-08 +*/ +@Data +@Schema(description = "物实体静态字典") +public class IotThingStaticDictDTO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + private Long id; + @Schema(description = "物实体id") + private Long entityId; + @Schema(description = "属性名称") + private String name; + @Schema(description = "属性编码") + private String code; + @Schema(description = "属性类型") + private String type; + @Schema(description = "组") + private String group; + @Schema(description = "时间戳") + private Long ts; + @Schema(description = "值") + private String val; + private Long creator; + private Long createDate; + private Long updater; + private Long updateDate; + @Schema(description = "单位") + private String unit; + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/entity/IotThingStaticDictEntity.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/entity/IotThingStaticDictEntity.java new file mode 100644 index 0000000..70b4059 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/entity/IotThingStaticDictEntity.java @@ -0,0 +1,61 @@ +package com.thing.thing.dictRelation.entity; + +import com.mybatisflex.annotation.Table; + +import com.thing.common.orm.entity.BaseDateEntity; +import com.thing.common.orm.entity.BaseInfoEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 物实体静态字典 + * + * @author xc + * @since 3.0 2024-10-08 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper=false) +@Table("iot_thing_static_dict") +public class IotThingStaticDictEntity extends BaseInfoEntity { + @Serial + private static final long serialVersionUID = 1L; + + /** + * 物实体id + */ + private Long entityId; + /** + * 属性名称 + */ + private String name; + /** + * 属性编码 + */ + private String code; + /** + * 属性类型 + */ + private String type; + /** + * 组 + */ + private String group; + /** + * 时间戳 + */ + private Long ts; + /** + * 值 + */ + private String val; + + /** + * 单位 + */ + private String unit; +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/mapper/IotThingStaticDictMapper.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/mapper/IotThingStaticDictMapper.java new file mode 100644 index 0000000..a9562d2 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/mapper/IotThingStaticDictMapper.java @@ -0,0 +1,16 @@ +package com.thing.thing.dictRelation.mapper; + +import com.thing.common.orm.mapper.PowerBaseMapper; +import com.thing.thing.dictRelation.entity.IotThingStaticDictEntity; +import org.apache.ibatis.annotations.Mapper; + +/** +* 物实体静态字典 +* +* @author xc +* @since 3.0 2024-10-08 +*/ +@Mapper +public interface IotThingStaticDictMapper extends PowerBaseMapper { + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/service/IotThingStaticDictService.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/service/IotThingStaticDictService.java new file mode 100644 index 0000000..bc3d05e --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/service/IotThingStaticDictService.java @@ -0,0 +1,23 @@ +package com.thing.thing.dictRelation.service; + +import com.thing.common.orm.service.IBaseService; +import com.thing.thing.dictRelation.dto.IotThingStaticDictDTO; +import com.thing.thing.dictRelation.entity.IotThingStaticDictEntity; + +import java.util.List; + +/** + * 物实体静态字典 + * + * @author xc + * @since 3.0 2024-10-08 + */ +public interface IotThingStaticDictService extends IBaseService { + + List groups(); + + List types(); + + List getByEntityId(Long entityId); + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingStaticDictServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingStaticDictServiceImpl.java new file mode 100644 index 0000000..5d2ef94 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingStaticDictServiceImpl.java @@ -0,0 +1,76 @@ +package com.thing.thing.dictRelation.service.impl; + +import cn.hutool.core.map.MapUtil; +import com.google.common.collect.Lists; +import com.mybatisflex.core.query.QueryWrapper; +import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.sys.security.context.UserContext; +import com.thing.thing.dictRelation.dto.IotThingStaticDictDTO; +import com.thing.thing.dictRelation.entity.IotThingStaticDictEntity; +import com.thing.thing.dictRelation.mapper.IotThingStaticDictMapper; +import com.thing.thing.dictRelation.service.IotThingStaticDictService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static com.thing.thing.dictRelation.entity.table.IotThingStaticDictEntityTableDef.IOT_THING_STATIC_DICT_ENTITY; + +/** + * 物实体静态字典 + * + * @author xc + * @since 3.0 2024-10-08 + */ +@Service +public class IotThingStaticDictServiceImpl extends BaseServiceImpl implements IotThingStaticDictService { + + @Override + public QueryWrapper getWrapper(Map params){ + QueryWrapper wrapper = new QueryWrapper(); + String code = (String) params.get("code"); + Long entityId = MapUtil.getLong(params, "entityId"); + Long beginTime = MapUtil.getLong(params, "beginTime"); + Long endTime = MapUtil.getLong(params, "endTime"); + if(StringUtils.isNotBlank(code)){ + wrapper.where(IOT_THING_STATIC_DICT_ENTITY.NAME.like(code).or(IOT_THING_STATIC_DICT_ENTITY.CODE.like(code))); + } + wrapper.eq(IotThingStaticDictEntity::getEntityId, entityId, !Objects.isNull(entityId)); + wrapper.between(IotThingStaticDictEntity::getTs, beginTime, endTime, !Objects.isNull(beginTime) && !Objects.isNull(endTime)); + return wrapper; + } + + + @Override + public List groups() { + QueryWrapper select = new QueryWrapper().select(IOT_THING_STATIC_DICT_ENTITY.GROUP) + .eq(IotThingStaticDictEntity::getTenantCode, UserContext.getRealTenantCode()); + + List list = mapper.selectListByQueryAs(select, String.class); + + if(CollectionUtils.isEmpty(list)){ + return Lists.newArrayList("默认组"); + } + return list.stream().distinct().toList(); + } + + @Override + public List types() { + QueryWrapper select = new QueryWrapper().select(IOT_THING_STATIC_DICT_ENTITY.TYPE) + .eq(IotThingStaticDictEntity::getTenantCode, UserContext.getRealTenantCode()); + List list = mapper.selectListByQueryAs(select, String.class); + if(CollectionUtils.isEmpty(list)){ + return Lists.newArrayList("默认类型"); + } + return list.stream().distinct().toList(); + } + + @Override + public List getByEntityId(Long entityId) { + QueryWrapper select = new QueryWrapper().eq(IotThingStaticDictEntity::getEntityId, entityId); + return mapper.selectListByQueryAs(select, IotThingStaticDictDTO.class); + } +} \ No newline at end of file