6 changed files with 348 additions and 0 deletions
-
128modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java
-
44modules/thing/src/main/java/com/thing/thing/dictRelation/dto/IotThingStaticDictDTO.java
-
61modules/thing/src/main/java/com/thing/thing/dictRelation/entity/IotThingStaticDictEntity.java
-
16modules/thing/src/main/java/com/thing/thing/dictRelation/mapper/IotThingStaticDictMapper.java
-
23modules/thing/src/main/java/com/thing/thing/dictRelation/service/IotThingStaticDictService.java
-
76modules/thing/src/main/java/com/thing/thing/dictRelation/service/impl/IotThingStaticDictServiceImpl.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<PageData<IotThingStaticDictDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
PageData<IotThingStaticDictDTO> page = iotThingStaticDictService.getPageData(params, IotThingStaticDictDTO.class); |
|||
return new Result<PageData<IotThingStaticDictDTO>>().ok(page); |
|||
} |
|||
|
|||
@GetMapping("{id}") |
|||
@Operation(summary="信息") |
|||
public Result<IotThingStaticDictDTO> get(@PathVariable("id") Long id){ |
|||
IotThingStaticDictDTO data = iotThingStaticDictService.getByIdAs(id, IotThingStaticDictDTO.class); |
|||
return new Result<IotThingStaticDictDTO>().ok(data); |
|||
} |
|||
|
|||
@GetMapping("entityId/{entityId}") |
|||
@Operation(summary="信息") |
|||
public Result<List<IotThingStaticDictDTO> > getByEntityId(@PathVariable("entityId") Long entityId){ |
|||
List<IotThingStaticDictDTO> listData = iotThingStaticDictService.getByEntityId(entityId); |
|||
return new Result<List<IotThingStaticDictDTO> >().ok(listData); |
|||
} |
|||
|
|||
@PostMapping |
|||
@Operation(summary="保存") |
|||
@LogOperation("保存") |
|||
public Result<Void> save(@RequestBody IotThingStaticDictDTO dto){ |
|||
//效验数据 |
|||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|||
iotThingStaticDictService.saveDto(dto); |
|||
return new Result<>(); |
|||
} |
|||
|
|||
@PostMapping("batchSave") |
|||
@Operation(summary="保存") |
|||
@LogOperation("保存") |
|||
public Result<Void> batchSave(@RequestBody List<IotThingStaticDictDTO> list){ |
|||
list.forEach(iotThingStaticDictService::saveDto); |
|||
return new Result<>(); |
|||
} |
|||
|
|||
@PutMapping |
|||
@Operation(summary="修改") |
|||
@LogOperation("修改") |
|||
public Result<Void> update(@RequestBody IotThingStaticDictDTO dto){ |
|||
//效验数据 |
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
iotThingStaticDictService.updateDto(dto); |
|||
return new Result<>(); |
|||
} |
|||
|
|||
@DeleteMapping |
|||
@Operation(summary="删除") |
|||
@LogOperation("删除") |
|||
public Result<Void> delete(@RequestBody Long[] ids){ |
|||
//效验数据 |
|||
AssertUtils.isArrayEmpty(ids, "id"); |
|||
iotThingStaticDictService.batchDelete(ids); |
|||
return new Result<>(); |
|||
} |
|||
|
|||
@GetMapping("group") |
|||
@Operation(summary="静态指标组") |
|||
public Result<List<String>> group(){ |
|||
List<String> groups = iotThingStaticDictService.groups(); |
|||
return new Result<List<String>>().ok(groups); |
|||
} |
|||
|
|||
@GetMapping("type") |
|||
@Operation(summary="静态指标类型") |
|||
public Result<List<String>> type(){ |
|||
List<String> types = iotThingStaticDictService.types(); |
|||
return new Result<List<String>>().ok(types); |
|||
} |
|||
|
|||
/** |
|||
*@GetMapping("export") |
|||
*@Operation(summary="导出") |
|||
*@LogOperation("导出") |
|||
*public void export(@Parameter(hidden = true) @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception { |
|||
* List<IotThingStaticDictDTO> list = iotThingStaticDictService.listAs(params, IotThingStaticDictDTO.class); |
|||
* //ExcelUtils.exportExcelToTarget(response, null, "物实体静态字典", list, IotThingStaticDictExcel.class); |
|||
*} |
|||
*/ |
|||
|
|||
} |
|||
@ -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; |
|||
|
|||
} |
|||
@ -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; |
|||
} |
|||
@ -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<IotThingStaticDictEntity> { |
|||
|
|||
} |
|||
@ -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<IotThingStaticDictEntity> { |
|||
|
|||
List<String> groups(); |
|||
|
|||
List<String> types(); |
|||
|
|||
List<IotThingStaticDictDTO> getByEntityId(Long entityId); |
|||
|
|||
} |
|||
@ -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<IotThingStaticDictMapper, IotThingStaticDictEntity> implements IotThingStaticDictService { |
|||
|
|||
@Override |
|||
public QueryWrapper getWrapper(Map<String, Object> 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<String> groups() { |
|||
QueryWrapper select = new QueryWrapper().select(IOT_THING_STATIC_DICT_ENTITY.GROUP) |
|||
.eq(IotThingStaticDictEntity::getTenantCode, UserContext.getRealTenantCode()); |
|||
|
|||
List<String> list = mapper.selectListByQueryAs(select, String.class); |
|||
|
|||
if(CollectionUtils.isEmpty(list)){ |
|||
return Lists.newArrayList("默认组"); |
|||
} |
|||
return list.stream().distinct().toList(); |
|||
} |
|||
|
|||
@Override |
|||
public List<String> types() { |
|||
QueryWrapper select = new QueryWrapper().select(IOT_THING_STATIC_DICT_ENTITY.TYPE) |
|||
.eq(IotThingStaticDictEntity::getTenantCode, UserContext.getRealTenantCode()); |
|||
List<String> list = mapper.selectListByQueryAs(select, String.class); |
|||
if(CollectionUtils.isEmpty(list)){ |
|||
return Lists.newArrayList("默认类型"); |
|||
} |
|||
return list.stream().distinct().toList(); |
|||
} |
|||
|
|||
@Override |
|||
public List<IotThingStaticDictDTO> getByEntityId(Long entityId) { |
|||
QueryWrapper select = new QueryWrapper().eq(IotThingStaticDictEntity::getEntityId, entityId); |
|||
return mapper.selectListByQueryAs(select, IotThingStaticDictDTO.class); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue