Merge branch 'hhk' of https://git.ngsk.tech/linweidong/besure_server
commit
f322430719
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.framework.common.enums;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 设备连接状态枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceConnectionStatusEnum implements IntArrayValuable {
|
||||
|
||||
CONNECTED(1, "已连接"),
|
||||
DISCONNECTED(2, "已断开");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DeviceConnectionStatusEnum::getStatus).toArray();
|
||||
|
||||
/**
|
||||
* 状态值
|
||||
*/
|
||||
private final Integer status;
|
||||
|
||||
/**
|
||||
* 状态名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为连接状态
|
||||
*/
|
||||
public static boolean isConnected(Integer status) {
|
||||
return ObjUtil.equal(CONNECTED.status, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为断开状态
|
||||
*/
|
||||
public static boolean isDisconnected(Integer status) {
|
||||
return ObjUtil.equal(DISCONNECTED.status, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态值获取枚举实例
|
||||
*/
|
||||
public static DeviceConnectionStatusEnum valueOf(Integer status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
for (DeviceConnectionStatusEnum value : values()) {
|
||||
if (ObjUtil.equal(value.status, status)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.devicecontactmodel.DeviceContactModelDO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo.*;
|
||||
import cn.iocoder.yudao.module.iot.service.devicecontactmodel.DeviceContactModelService;
|
||||
|
||||
@Tag(name = "管理后台 - 采集设备-模型关联")
|
||||
@RestController
|
||||
@RequestMapping("/iot/device-contact-model")
|
||||
@Validated
|
||||
public class DeviceContactModelController {
|
||||
|
||||
@Resource
|
||||
private DeviceContactModelService deviceContactModelService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建采集设备模型-点位管理")
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:create')")
|
||||
public CommonResult<Long> createDeviceContactModel(@Valid @RequestBody DeviceContactModelSaveReqVO createReqVO) {
|
||||
return success(deviceContactModelService.createDeviceContactModel(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新采集设备模型-点位管理")
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:update')")
|
||||
public CommonResult<Boolean> updateDeviceContactModel(@Valid @RequestBody DeviceContactModelSaveReqVO updateReqVO) {
|
||||
deviceContactModelService.updateDeviceContactModel(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除采集设备模型-点位管理")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:delete')")
|
||||
public CommonResult<Boolean> deleteDeviceContactModel(@RequestParam("ids") String ids) {
|
||||
|
||||
// 将逗号分隔的字符串转换为Long类型的List
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(String::trim) // 去除可能存在的空格
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
deviceContactModelService.deleteDeviceContactModel(idList);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得采集设备模型-点位管理")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:query')")
|
||||
public CommonResult<DeviceContactModelRespVO> getDeviceContactModel(@RequestParam("id") Long id) {
|
||||
DeviceContactModelDO deviceContactModel = deviceContactModelService.getDeviceContactModel(id);
|
||||
return success(BeanUtils.toBean(deviceContactModel, DeviceContactModelRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得采集设备模型-点位管理分页")
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:query')")
|
||||
public CommonResult<PageResult<DeviceContactModelRespVO>> getDeviceContactModelPage(@Valid DeviceContactModelPageReqVO pageReqVO) {
|
||||
PageResult<DeviceContactModelDO> pageResult = deviceContactModelService.getDeviceContactModelPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, DeviceContactModelRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出采集设备模型-点位管理 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('iot:device-contact-model:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDeviceContactModelExcel(@Valid DeviceContactModelPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<DeviceContactModelDO> list = deviceContactModelService.getDeviceContactModelPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "采集设备模型-点位管理.xls", "数据", DeviceContactModelRespVO.class,
|
||||
BeanUtils.toBean(list, DeviceContactModelRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 采集设备模型-点位管理分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class DeviceContactModelPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "id集合导出用")
|
||||
private String ids;
|
||||
|
||||
@Schema(description = "设备Id")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(description = "点位编码")
|
||||
private String attributeCode;
|
||||
|
||||
@Schema(description = "点位名称", example = "王五")
|
||||
private String attributeName;
|
||||
|
||||
@Schema(description = "点位类型", example = "1")
|
||||
private String attributeType;
|
||||
|
||||
@Schema(description = "数据类型", example = "1")
|
||||
private String dataType;
|
||||
|
||||
@Schema(description = "寄存器地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "单位")
|
||||
private String dataUnit;
|
||||
|
||||
@Schema(description = "倍率")
|
||||
private Double ratio;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "采集设备模型id", example = "13862")
|
||||
private Long deviceModelId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 采集设备模型-点位管理 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class DeviceContactModelRespVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13209")
|
||||
// @ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "点位编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("点位编码")
|
||||
private String attributeCode;
|
||||
|
||||
@Schema(description = "点位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("点位名称")
|
||||
private String attributeName;
|
||||
|
||||
@Schema(description = "点位类型", example = "1")
|
||||
@ExcelProperty("点位类型")
|
||||
private String attributeType;
|
||||
|
||||
@Schema(description = "数据类型", example = "1")
|
||||
@ExcelProperty("数据类型")
|
||||
private String dataType;
|
||||
|
||||
@Schema(description = "寄存器地址")
|
||||
@ExcelProperty("寄存器地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "单位")
|
||||
@ExcelProperty("单位")
|
||||
private String dataUnit;
|
||||
|
||||
@Schema(description = "倍率")
|
||||
@ExcelProperty("倍率")
|
||||
private Double ratio;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "采集设备模型id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13862")
|
||||
@ExcelProperty("采集设备模型id")
|
||||
private Long deviceModelId;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "排序", example = "1")
|
||||
@ExcelProperty("排序")
|
||||
private int sort;
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 采集设备模型-点位管理新增/修改 Request VO")
|
||||
@Data
|
||||
public class DeviceContactModelSaveReqVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13209")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "点位编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "点位编码不能为空")
|
||||
private String attributeCode;
|
||||
|
||||
@Schema(description = "点位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "点位名称不能为空")
|
||||
private String attributeName;
|
||||
|
||||
@Schema(description = "点位类型", example = "1")
|
||||
private String attributeType;
|
||||
|
||||
@Schema(description = "数据类型", example = "1")
|
||||
private String dataType;
|
||||
|
||||
@Schema(description = "寄存器地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "单位")
|
||||
private String dataUnit;
|
||||
|
||||
@Schema(description = "倍率")
|
||||
private Double ratio;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "采集设备模型id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13862")
|
||||
@NotNull(message = "采集设备模型id不能为空")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(description = "排序", example = "2")
|
||||
private int sort;
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.iot.dal.devicecontactmodel;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 采集设备模型-点位管理 DO
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@TableName("iot_device_contact_model")
|
||||
@KeySequence("iot_device_contact_model_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceContactModelDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 点位编码
|
||||
*/
|
||||
private String attributeCode;
|
||||
/**
|
||||
* 点位名称
|
||||
*/
|
||||
private String attributeName;
|
||||
/**
|
||||
* 点位类型
|
||||
*/
|
||||
private String attributeType;
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
/**
|
||||
* 寄存器地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String dataUnit;
|
||||
/**
|
||||
* 倍率
|
||||
*/
|
||||
private Double ratio;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 采集设备模型id
|
||||
*/
|
||||
private Long deviceId;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private int sort;
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.iot.service.devicecontactmodel;
|
||||
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.dal.devicecontactmodel.DeviceContactModelDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 采集设备模型-点位管理 Service 接口
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
public interface DeviceContactModelService {
|
||||
|
||||
/**
|
||||
* 创建采集设备模型-点位管理
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDeviceContactModel(@Valid DeviceContactModelSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新采集设备模型-点位管理
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDeviceContactModel(@Valid DeviceContactModelSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除采集设备模型-点位管理
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDeviceContactModel(List<Long> id);
|
||||
|
||||
/**
|
||||
* 获得采集设备模型-点位管理
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 采集设备模型-点位管理
|
||||
*/
|
||||
DeviceContactModelDO getDeviceContactModel(Long id);
|
||||
|
||||
/**
|
||||
* 获得采集设备模型-点位管理分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 采集设备模型-点位管理分页
|
||||
*/
|
||||
PageResult<DeviceContactModelDO> getDeviceContactModelPage(DeviceContactModelPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package cn.iocoder.yudao.module.iot.service.devicecontactmodel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.devicecontactmodel.DeviceContactModelDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.mysql.devicecontactmodel.DeviceContactModelMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.DEVICE_CONTACT_MODEL_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 采集设备模型-点位管理 Service 实现类
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DeviceContactModelServiceImpl implements DeviceContactModelService {
|
||||
|
||||
@Resource
|
||||
private DeviceContactModelMapper deviceContactModelMapper;
|
||||
|
||||
@Override
|
||||
public Long createDeviceContactModel(DeviceContactModelSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
DeviceContactModelDO deviceContactModel = BeanUtils.toBean(createReqVO, DeviceContactModelDO.class);
|
||||
deviceContactModelMapper.insert(deviceContactModel);
|
||||
// 返回
|
||||
return deviceContactModel.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceContactModel(DeviceContactModelSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDeviceContactModelExists(updateReqVO.getId());
|
||||
// 更新
|
||||
DeviceContactModelDO updateObj = BeanUtils.toBean(updateReqVO, DeviceContactModelDO.class);
|
||||
deviceContactModelMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceContactModel(List<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
// 校验存在
|
||||
validateDeviceContactModelExists(id);
|
||||
// 删除
|
||||
deviceContactModelMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDeviceContactModelExists(Long id) {
|
||||
if (deviceContactModelMapper.selectById(id) == null) {
|
||||
throw exception(DEVICE_CONTACT_MODEL_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceContactModelDO getDeviceContactModel(Long id) {
|
||||
DeviceContactModelDO deviceContactModelDO = deviceContactModelMapper.selectById(id);
|
||||
return deviceContactModelDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DeviceContactModelDO> getDeviceContactModelPage(DeviceContactModelPageReqVO pageReqVO) {
|
||||
return deviceContactModelMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue