add iot and machine

plp
chenshuichuan 2 years ago
parent 15ac0a328e
commit 4a4ac36709

@ -24,6 +24,7 @@
<module>yudao-module-crm</module>
<module>yudao-module-erp</module>
<module>yudao-module-mes</module>
<module>yudao-module-iot</module>
</modules>
<name>${project.artifactId}</name>

@ -10,6 +10,17 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
public interface ErrorCodeConstants {
// ========== GoView 模块 1-003-000-000 ==========
ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备不存在");
ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备属性不存在");
ErrorCode FORMULA_NOT_EXISTS = new ErrorCode(1_003_000_000, "公式不存在");
ErrorCode FORMULA_DETAIL_NOT_EXISTS = new ErrorCode(1_003_000_000, "公式明细不存在");
ErrorCode GATEWAY_NOT_EXISTS = new ErrorCode(1_003_000_000, "网关不存在");
ErrorCode KANBAN_NOT_EXISTS = new ErrorCode(1_003_000_000, "看板不存在");
ErrorCode ORGANIZATION_EXITS_CHILDREN = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode ORGANIZATION_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode ORGANIZATION_PARENT_ERROR = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode ORGANIZATION_PARENT_NOT_EXITS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode ORGANIZATION_PARENT_IS_CHILD = new ErrorCode(1_003_000_000, "GoView 项目不存在");
ErrorCode ORGANIZATION_NAME_DUPLICATE = new ErrorCode(1_003_000_000, "GoView 项目不存在");
}

@ -0,0 +1,138 @@
package cn.iocoder.yudao.module.iot.controller.admin.device;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO;
import cn.iocoder.yudao.module.iot.service.device.DeviceService;
@Tag(name = "管理后台 - 物联设备")
@RestController
@RequestMapping("/iot/device")
@Validated
public class DeviceController {
@Resource
private DeviceService deviceService;
@PostMapping("/create")
@Operation(summary = "创建物联设备")
@PreAuthorize("@ss.hasPermission('iot:device:create')")
public CommonResult<Long> createDevice(@Valid @RequestBody DeviceSaveReqVO createReqVO) {
return success(deviceService.createDevice(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新物联设备")
@PreAuthorize("@ss.hasPermission('iot:device:update')")
public CommonResult<Boolean> updateDevice(@Valid @RequestBody DeviceSaveReqVO updateReqVO) {
deviceService.updateDevice(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除物联设备")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:device:delete')")
public CommonResult<Boolean> deleteDevice(@RequestParam("id") Long id) {
deviceService.deleteDevice(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得物联设备")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<DeviceRespVO> getDevice(@RequestParam("id") Long id) {
DeviceDO device = deviceService.getDevice(id);
return success(BeanUtils.toBean(device, DeviceRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得物联设备分页")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<PageResult<DeviceRespVO>> getDevicePage(@Valid DevicePageReqVO pageReqVO) {
PageResult<DeviceDO> pageResult = deviceService.getDevicePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DeviceRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出物联设备 Excel")
@PreAuthorize("@ss.hasPermission('iot:device:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDeviceExcel(@Valid DevicePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DeviceDO> list = deviceService.getDevicePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物联设备.xls", "数据", DeviceRespVO.class,
BeanUtils.toBean(list, DeviceRespVO.class));
}
// ==================== 子表(设备属性) ====================
@GetMapping("/device-attribute/page")
@Operation(summary = "获得设备属性分页")
@Parameter(name = "deviceId", description = "设备id")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<PageResult<DeviceAttributeDO>> getDeviceAttributePage(PageParam pageReqVO,
@RequestParam("deviceId") Long deviceId) {
return success(deviceService.getDeviceAttributePage(pageReqVO, deviceId));
}
@PostMapping("/device-attribute/create")
@Operation(summary = "创建设备属性")
@PreAuthorize("@ss.hasPermission('iot:device:create')")
public CommonResult<Long> createDeviceAttribute(@Valid @RequestBody DeviceAttributeDO deviceAttribute) {
return success(deviceService.createDeviceAttribute(deviceAttribute));
}
@PutMapping("/device-attribute/update")
@Operation(summary = "更新设备属性")
@PreAuthorize("@ss.hasPermission('iot:device:update')")
public CommonResult<Boolean> updateDeviceAttribute(@Valid @RequestBody DeviceAttributeDO deviceAttribute) {
deviceService.updateDeviceAttribute(deviceAttribute);
return success(true);
}
@DeleteMapping("/device-attribute/delete")
@Parameter(name = "id", description = "编号", required = true)
@Operation(summary = "删除设备属性")
@PreAuthorize("@ss.hasPermission('iot:device:delete')")
public CommonResult<Boolean> deleteDeviceAttribute(@RequestParam("id") Long id) {
deviceService.deleteDeviceAttribute(id);
return success(true);
}
@GetMapping("/device-attribute/get")
@Operation(summary = "获得设备属性")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<DeviceAttributeDO> getDeviceAttribute(@RequestParam("id") Long id) {
return success(deviceService.getDeviceAttribute(id));
}
}

@ -0,0 +1,103 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import lombok.*;
import java.util.*;
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 DevicePageReqVO extends PageParam {
@Schema(description = "设备配置id", example = "14050")
private String deviceConfigId;
@Schema(description = "设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "李四")
private String deviceName;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "Siemens系列(S7-300、S7-1500)")
private String siemensSeries;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String siemensConnectParam;
@Schema(description = "读取任务方式(0无1有)", example = "2")
private String readCronType;
@Schema(description = "读取任务时间间隔")
private Integer readRepeatValue;
@Schema(description = "读取任务时间间隔单位")
private String readRepeatUnit;
@Schema(description = "读取任务时间表达式")
private String readCron;
@Schema(description = "写入任务时间间隔", example = "1")
private String writeCronType;
@Schema(description = "写入任务时间间隔")
private Integer writeRepeatValue;
@Schema(description = "写入任务时间间隔单位")
private String writeRepeatUnit;
@Schema(description = "写入任务时间表达式")
private String writeCron;
@Schema(description = "是否持久化(0不持久化1持久化)")
private String localPersistent;
@Schema(description = "上传方式(1实时2自定义)")
private String uploadRate;
@Schema(description = "上传频率", example = "19796")
private Integer rateCount;
@Schema(description = "modbus协议类型(serial-rtu)")
private String modbusProtocol;
@Schema(description = "modbus模式(client)")
private String modbusPattern;
@Schema(description = "modbus串口号", example = "李四")
private String portName;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String modbusConnectParam;
@Schema(description = "读地址是否连续(0否1是)")
private String modbusReadAddrGap;
@Schema(description = "是否已下发(0下,1没下)")
private String isUpload;
@Schema(description = "网关id", example = "6304")
private Long gatewayId;
@Schema(description = "组织设备id", example = "23150")
private Long orgId;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,144 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 物联设备 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DeviceRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8540")
@ExcelProperty("ID")
private Long id;
@Schema(description = "设备配置id", example = "14050")
@ExcelProperty("设备配置id")
private String deviceConfigId;
@Schema(description = "设备编号")
@ExcelProperty("设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "李四")
@ExcelProperty("设备名称")
private String deviceName;
@Schema(description = "设备类型", example = "2")
@ExcelProperty("设备类型")
private String deviceType;
@Schema(description = "Siemens系列(S7-300、S7-1500)")
@ExcelProperty(value = "Siemens系列(S7-300、S7-1500)", converter = DictConvert.class)
@DictFormat("iot_siemens_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String siemensSeries;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
@ExcelProperty("连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String siemensConnectParam;
@Schema(description = "读取任务方式(0无1有)", example = "2")
@ExcelProperty(value = "读取任务方式(0无1有)", converter = DictConvert.class)
@DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String readCronType;
@Schema(description = "读取任务时间间隔")
@ExcelProperty("读取任务时间间隔")
private Integer readRepeatValue;
@Schema(description = "读取任务时间间隔单位")
@ExcelProperty(value = "读取任务时间间隔单位", converter = DictConvert.class)
@DictFormat("iot_device_data_unit") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String readRepeatUnit;
@Schema(description = "读取任务时间表达式")
@ExcelProperty("读取任务时间表达式")
private String readCron;
@Schema(description = "写入任务时间间隔", example = "1")
@ExcelProperty("写入任务时间间隔")
private String writeCronType;
@Schema(description = "写入任务时间间隔")
@ExcelProperty("写入任务时间间隔")
private Integer writeRepeatValue;
@Schema(description = "写入任务时间间隔单位")
@ExcelProperty("写入任务时间间隔单位")
private String writeRepeatUnit;
@Schema(description = "写入任务时间表达式")
@ExcelProperty("写入任务时间表达式")
private String writeCron;
@Schema(description = "是否持久化(0不持久化1持久化)")
@ExcelProperty(value = "是否持久化(0不持久化1持久化)", converter = DictConvert.class)
@DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String localPersistent;
@Schema(description = "上传方式(1实时2自定义)")
@ExcelProperty(value = "上传方式(1实时2自定义)", converter = DictConvert.class)
@DictFormat("iot_device_uploading_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String uploadRate;
@Schema(description = "上传频率", example = "19796")
@ExcelProperty("上传频率")
private Integer rateCount;
@Schema(description = "modbus协议类型(serial-rtu)")
@ExcelProperty(value = "modbus协议类型(serial-rtu)", converter = DictConvert.class)
@DictFormat("iot_modbus_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String modbusProtocol;
@Schema(description = "modbus模式(client)")
@ExcelProperty(value = "modbus模式(client)", converter = DictConvert.class)
@DictFormat("iot_modbus_mold") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String modbusPattern;
@Schema(description = "modbus串口号", example = "李四")
@ExcelProperty(value = "modbus串口号", converter = DictConvert.class)
@DictFormat("iot_modbus_port") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String portName;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
@ExcelProperty("连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String modbusConnectParam;
@Schema(description = "读地址是否连续(0否1是)")
@ExcelProperty(value = "读地址是否连续(0否1是)", converter = DictConvert.class)
@DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String modbusReadAddrGap;
@Schema(description = "是否已下发(0下,1没下)")
@ExcelProperty(value = "是否已下发(0下,1没下)", converter = DictConvert.class)
@DictFormat("iot_1_or_0") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String isUpload;
@Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6304")
@ExcelProperty("网关id")
private Long gatewayId;
@Schema(description = "组织设备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23150")
@ExcelProperty("组织设备id")
private Long orgId;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 物联设备新增/修改 Request VO")
@Data
public class DeviceSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8540")
private Long id;
@Schema(description = "设备配置id", example = "14050")
private String deviceConfigId;
@Schema(description = "设备编号")
private String deviceCode;
@Schema(description = "设备名称", example = "李四")
private String deviceName;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "Siemens系列(S7-300、S7-1500)")
private String siemensSeries;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String siemensConnectParam;
@Schema(description = "读取任务方式(0无1有)", example = "2")
private String readCronType;
@Schema(description = "读取任务时间间隔")
private Integer readRepeatValue;
@Schema(description = "读取任务时间间隔单位")
private String readRepeatUnit;
@Schema(description = "读取任务时间表达式")
private String readCron;
@Schema(description = "写入任务时间间隔", example = "1")
private String writeCronType;
@Schema(description = "写入任务时间间隔")
private Integer writeRepeatValue;
@Schema(description = "写入任务时间间隔单位")
private String writeRepeatUnit;
@Schema(description = "写入任务时间表达式")
private String writeCron;
@Schema(description = "是否持久化(0不持久化1持久化)")
private String localPersistent;
@Schema(description = "上传方式(1实时2自定义)")
private String uploadRate;
@Schema(description = "上传频率", example = "19796")
private Integer rateCount;
@Schema(description = "modbus协议类型(serial-rtu)")
private String modbusProtocol;
@Schema(description = "modbus模式(client)")
private String modbusPattern;
@Schema(description = "modbus串口号", example = "李四")
private String portName;
@Schema(description = "连接参数(波特率,数据位,停止位,校验位 例如960081N")
private String modbusConnectParam;
@Schema(description = "读地址是否连续(0否1是)")
private String modbusReadAddrGap;
@Schema(description = "是否已下发(0下,1没下)")
private String isUpload;
@Schema(description = "网关id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6304")
@NotNull(message = "网关id不能为空")
private Long gatewayId;
@Schema(description = "组织设备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23150")
@NotNull(message = "组织设备id不能为空")
private Long orgId;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
}

@ -0,0 +1,138 @@
package cn.iocoder.yudao.module.iot.controller.admin.formula;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.formula.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDetailDO;
import cn.iocoder.yudao.module.iot.service.formula.FormulaService;
@Tag(name = "管理后台 - 计算公式")
@RestController
@RequestMapping("/iot/formula")
@Validated
public class FormulaController {
@Resource
private FormulaService formulaService;
@PostMapping("/create")
@Operation(summary = "创建计算公式")
@PreAuthorize("@ss.hasPermission('iot:formula:create')")
public CommonResult<Long> createFormula(@Valid @RequestBody FormulaSaveReqVO createReqVO) {
return success(formulaService.createFormula(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新计算公式")
@PreAuthorize("@ss.hasPermission('iot:formula:update')")
public CommonResult<Boolean> updateFormula(@Valid @RequestBody FormulaSaveReqVO updateReqVO) {
formulaService.updateFormula(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除计算公式")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:formula:delete')")
public CommonResult<Boolean> deleteFormula(@RequestParam("id") Long id) {
formulaService.deleteFormula(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得计算公式")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:formula:query')")
public CommonResult<FormulaRespVO> getFormula(@RequestParam("id") Long id) {
FormulaDO formula = formulaService.getFormula(id);
return success(BeanUtils.toBean(formula, FormulaRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得计算公式分页")
@PreAuthorize("@ss.hasPermission('iot:formula:query')")
public CommonResult<PageResult<FormulaRespVO>> getFormulaPage(@Valid FormulaPageReqVO pageReqVO) {
PageResult<FormulaDO> pageResult = formulaService.getFormulaPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, FormulaRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出计算公式 Excel")
@PreAuthorize("@ss.hasPermission('iot:formula:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportFormulaExcel(@Valid FormulaPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<FormulaDO> list = formulaService.getFormulaPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "计算公式.xls", "数据", FormulaRespVO.class,
BeanUtils.toBean(list, FormulaRespVO.class));
}
// ==================== 子表(计算公式明细) ====================
@GetMapping("/formula-detail/page")
@Operation(summary = "获得计算公式明细分页")
@Parameter(name = "formulaId", description = "计算公式ID")
@PreAuthorize("@ss.hasPermission('iot:formula:query')")
public CommonResult<PageResult<FormulaDetailDO>> getFormulaDetailPage(PageParam pageReqVO,
@RequestParam("formulaId") Long formulaId) {
return success(formulaService.getFormulaDetailPage(pageReqVO, formulaId));
}
@PostMapping("/formula-detail/create")
@Operation(summary = "创建计算公式明细")
@PreAuthorize("@ss.hasPermission('iot:formula:create')")
public CommonResult<Long> createFormulaDetail(@Valid @RequestBody FormulaDetailDO formulaDetail) {
return success(formulaService.createFormulaDetail(formulaDetail));
}
@PutMapping("/formula-detail/update")
@Operation(summary = "更新计算公式明细")
@PreAuthorize("@ss.hasPermission('iot:formula:update')")
public CommonResult<Boolean> updateFormulaDetail(@Valid @RequestBody FormulaDetailDO formulaDetail) {
formulaService.updateFormulaDetail(formulaDetail);
return success(true);
}
@DeleteMapping("/formula-detail/delete")
@Parameter(name = "id", description = "编号", required = true)
@Operation(summary = "删除计算公式明细")
@PreAuthorize("@ss.hasPermission('iot:formula:delete')")
public CommonResult<Boolean> deleteFormulaDetail(@RequestParam("id") Long id) {
formulaService.deleteFormulaDetail(id);
return success(true);
}
@GetMapping("/formula-detail/get")
@Operation(summary = "获得计算公式明细")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:formula:query')")
public CommonResult<FormulaDetailDO> getFormulaDetail(@RequestParam("id") Long id) {
return success(formulaService.getFormulaDetail(id));
}
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.iot.controller.admin.formula.vo;
import lombok.*;
import java.util.*;
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 FormulaPageReqVO extends PageParam {
@Schema(description = "公式名称", example = "王五")
private String name;
@Schema(description = "公式编号")
private String formulaCode;
@Schema(description = "公式")
private String formula;
@Schema(description = "结果类型(产量,电耗,浆耗,水耗,气耗,参数)", example = "1")
private String resultType;
@Schema(description = "机台ID", example = "12374")
private Long machineId;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.controller.admin.formula.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 计算公式 Response VO")
@Data
@ExcelIgnoreUnannotated
public class FormulaRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31788")
@ExcelProperty("ID")
private Long id;
@Schema(description = "公式名称", example = "王五")
@ExcelProperty("公式名称")
private String name;
@Schema(description = "公式编号")
@ExcelProperty("公式编号")
private String formulaCode;
@Schema(description = "公式")
@ExcelProperty("公式")
private String formula;
@Schema(description = "结果类型(产量,电耗,浆耗,水耗,气耗,参数)", example = "1")
@ExcelProperty(value = "结果类型(产量,电耗,浆耗,水耗,气耗,参数)", converter = DictConvert.class)
@DictFormat("mes_data_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String resultType;
@Schema(description = "机台ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12374")
@ExcelProperty("机台ID")
private Long machineId;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.iot.controller.admin.formula.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 计算公式新增/修改 Request VO")
@Data
public class FormulaSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31788")
private Long id;
@Schema(description = "公式名称", example = "王五")
private String name;
@Schema(description = "公式编号")
private String formulaCode;
@Schema(description = "公式")
private String formula;
@Schema(description = "结果类型(产量,电耗,浆耗,水耗,气耗,参数)", example = "1")
private String resultType;
@Schema(description = "机台ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12374")
@NotNull(message = "机台ID不能为空")
private Long machineId;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
}

@ -0,0 +1,138 @@
package cn.iocoder.yudao.module.iot.controller.admin.gateway;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.gateway.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import cn.iocoder.yudao.module.iot.service.gateway.GatewayService;
@Tag(name = "管理后台 - 网关")
@RestController
@RequestMapping("/iot/gateway")
@Validated
public class GatewayController {
@Resource
private GatewayService gatewayService;
@PostMapping("/create")
@Operation(summary = "创建网关")
@PreAuthorize("@ss.hasPermission('iot:gateway:create')")
public CommonResult<Long> createGateway(@Valid @RequestBody GatewaySaveReqVO createReqVO) {
return success(gatewayService.createGateway(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新网关")
@PreAuthorize("@ss.hasPermission('iot:gateway:update')")
public CommonResult<Boolean> updateGateway(@Valid @RequestBody GatewaySaveReqVO updateReqVO) {
gatewayService.updateGateway(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除网关")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:gateway:delete')")
public CommonResult<Boolean> deleteGateway(@RequestParam("id") Long id) {
gatewayService.deleteGateway(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得网关")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:gateway:query')")
public CommonResult<GatewayRespVO> getGateway(@RequestParam("id") Long id) {
GatewayDO gateway = gatewayService.getGateway(id);
return success(BeanUtils.toBean(gateway, GatewayRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得网关分页")
@PreAuthorize("@ss.hasPermission('iot:gateway:query')")
public CommonResult<PageResult<GatewayRespVO>> getGatewayPage(@Valid GatewayPageReqVO pageReqVO) {
PageResult<GatewayDO> pageResult = gatewayService.getGatewayPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, GatewayRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出网关 Excel")
@PreAuthorize("@ss.hasPermission('iot:gateway:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportGatewayExcel(@Valid GatewayPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<GatewayDO> list = gatewayService.getGatewayPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "网关.xls", "数据", GatewayRespVO.class,
BeanUtils.toBean(list, GatewayRespVO.class));
}
// ==================== 子表(物联设备) ====================
@GetMapping("/device/page")
@Operation(summary = "获得物联设备分页")
@Parameter(name = "gatewayId", description = "网关id")
@PreAuthorize("@ss.hasPermission('iot:gateway:query')")
public CommonResult<PageResult<DeviceDO>> getDevicePage(PageParam pageReqVO,
@RequestParam("gatewayId") Long gatewayId) {
return success(gatewayService.getDevicePage(pageReqVO, gatewayId));
}
@PostMapping("/device/create")
@Operation(summary = "创建物联设备")
@PreAuthorize("@ss.hasPermission('iot:gateway:create')")
public CommonResult<Long> createDevice(@Valid @RequestBody DeviceDO device) {
return success(gatewayService.createDevice(device));
}
@PutMapping("/device/update")
@Operation(summary = "更新物联设备")
@PreAuthorize("@ss.hasPermission('iot:gateway:update')")
public CommonResult<Boolean> updateDevice(@Valid @RequestBody DeviceDO device) {
gatewayService.updateDevice(device);
return success(true);
}
@DeleteMapping("/device/delete")
@Parameter(name = "id", description = "编号", required = true)
@Operation(summary = "删除物联设备")
@PreAuthorize("@ss.hasPermission('iot:gateway:delete')")
public CommonResult<Boolean> deleteDevice(@RequestParam("id") Long id) {
gatewayService.deleteDevice(id);
return success(true);
}
@GetMapping("/device/get")
@Operation(summary = "获得物联设备")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:gateway:query')")
public CommonResult<DeviceDO> getDevice(@RequestParam("id") Long id) {
return success(gatewayService.getDevice(id));
}
}

@ -0,0 +1,49 @@
package cn.iocoder.yudao.module.iot.controller.admin.gateway.vo;
import lombok.*;
import java.util.*;
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 GatewayPageReqVO extends PageParam {
@Schema(description = "管理地址")
private String adminIp;
@Schema(description = "管理账号", example = "芋艿")
private String username;
@Schema(description = "管理密码")
private String password;
@Schema(description = "网关名字", example = "赵六")
private String gatewayName;
@Schema(description = "备注", example = "随便")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "网关编码")
private String gatewayCode;
@Schema(description = "网关状态", example = "1")
private String gatewayStatus;
@Schema(description = "订阅主题")
private String topic;
}

@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.iot.controller.admin.gateway.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 网关 Response VO")
@Data
@ExcelIgnoreUnannotated
public class GatewayRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "28060")
@ExcelProperty("ID")
private Long id;
@Schema(description = "管理地址")
@ExcelProperty("管理地址")
private String adminIp;
@Schema(description = "管理账号", example = "芋艿")
@ExcelProperty("管理账号")
private String username;
@Schema(description = "管理密码")
@ExcelProperty("管理密码")
private String password;
@Schema(description = "网关名字", example = "赵六")
@ExcelProperty("网关名字")
private String gatewayName;
@Schema(description = "备注", example = "随便")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "网关编码")
@ExcelProperty("网关编码")
private String gatewayCode;
@Schema(description = "网关状态", example = "1")
@ExcelProperty(value = "网关状态", converter = DictConvert.class)
@DictFormat("iot_gateway_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String gatewayStatus;
@Schema(description = "订阅主题")
@ExcelProperty("订阅主题")
private String topic;
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.iot.controller.admin.gateway.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 网关新增/修改 Request VO")
@Data
public class GatewaySaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "28060")
private Long id;
@Schema(description = "管理地址")
private String adminIp;
@Schema(description = "管理账号", example = "芋艿")
private String username;
@Schema(description = "管理密码")
private String password;
@Schema(description = "网关名字", example = "赵六")
private String gatewayName;
@Schema(description = "备注", example = "随便")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
@Schema(description = "网关编码")
private String gatewayCode;
@Schema(description = "网关状态", example = "1")
private String gatewayStatus;
@Schema(description = "订阅主题")
private String topic;
}

@ -0,0 +1,93 @@
package cn.iocoder.yudao.module.iot.controller.admin.iotorganization;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.iotorganization.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import cn.iocoder.yudao.module.iot.service.iotorganization.IotOrganizationService;
@Tag(name = "管理后台 - IOT组织")
@RestController
@RequestMapping("/iot/organization")
@Validated
public class IotOrganizationController {
@Resource
private IotOrganizationService organizationService;
@PostMapping("/create")
@Operation(summary = "创建IOT组织")
@PreAuthorize("@ss.hasPermission('iot:organization:create')")
public CommonResult<Long> createOrganization(@Valid @RequestBody IotOrganizationSaveReqVO createReqVO) {
return success(organizationService.createOrganization(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新IOT组织")
@PreAuthorize("@ss.hasPermission('iot:organization:update')")
public CommonResult<Boolean> updateOrganization(@Valid @RequestBody IotOrganizationSaveReqVO updateReqVO) {
organizationService.updateOrganization(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除IOT组织")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:organization:delete')")
public CommonResult<Boolean> deleteOrganization(@RequestParam("id") Long id) {
organizationService.deleteOrganization(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得IOT组织")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:organization:query')")
public CommonResult<IotOrganizationRespVO> getOrganization(@RequestParam("id") Long id) {
IotOrganizationDO organization = organizationService.getOrganization(id);
return success(BeanUtils.toBean(organization, IotOrganizationRespVO.class));
}
@GetMapping("/list")
@Operation(summary = "获得IOT组织列表")
@PreAuthorize("@ss.hasPermission('iot:organization:query')")
public CommonResult<List<IotOrganizationRespVO>> getOrganizationList(@Valid IotOrganizationListReqVO listReqVO) {
List<IotOrganizationDO> list = organizationService.getOrganizationList(listReqVO);
return success(BeanUtils.toBean(list, IotOrganizationRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出IOT组织 Excel")
@PreAuthorize("@ss.hasPermission('iot:organization:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportOrganizationExcel(@Valid IotOrganizationListReqVO listReqVO,
HttpServletResponse response) throws IOException {
List<IotOrganizationDO> list = organizationService.getOrganizationList(listReqVO);
// 导出 Excel
ExcelUtils.write(response, "IOT组织.xls", "数据", IotOrganizationRespVO.class,
BeanUtils.toBean(list, IotOrganizationRespVO.class));
}
}

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - IOT组织列表 Request VO")
@Data
public class IotOrganizationListReqVO {
@Schema(description = "显示顺序")
private Integer sort;
@Schema(description = "负责人/工人", example = "11964")
private Long workerUserId;
@Schema(description = "绑定工位id", example = "21787")
private Long orgId;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "组织名称", example = "赵六")
private String name;
@Schema(description = "父组织id", example = "10729")
private Long parentId;
@Schema(description = "组织状态", example = "2")
private Integer status;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "组织等级")
private String orgClass;
@Schema(description = "机台类型", example = "2")
private String machineType;
}

@ -0,0 +1,66 @@
package cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - IOT组织 Response VO")
@Data
@ExcelIgnoreUnannotated
public class IotOrganizationRespVO {
@Schema(description = "组织id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24521")
@ExcelProperty("组织id")
private Long id;
@Schema(description = "显示顺序")
@ExcelProperty("显示顺序")
private Integer sort;
@Schema(description = "负责人/工人", example = "11964")
@ExcelProperty("负责人/工人")
private Long workerUserId;
@Schema(description = "绑定工位id", example = "21787")
@ExcelProperty("绑定工位id")
private Long orgId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "组织名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@ExcelProperty("组织名称")
private String name;
@Schema(description = "父组织id", requiredMode = Schema.RequiredMode.REQUIRED, example = "10729")
@ExcelProperty("父组织id")
private Long parentId;
@Schema(description = "组织状态", example = "2")
@ExcelProperty(value = "组织状态", converter = DictConvert.class)
@DictFormat("mes_machine_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Integer status;
@Schema(description = "设备类型", example = "2")
@ExcelProperty(value = "设备类型", converter = DictConvert.class)
@DictFormat("iot_device_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String deviceType;
@Schema(description = "组织等级")
@ExcelProperty(value = "组织等级", converter = DictConvert.class)
@DictFormat("iot_org_class") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String orgClass;
@Schema(description = "机台类型", example = "2")
@ExcelProperty(value = "机台类型", converter = DictConvert.class)
@DictFormat("mes_org_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String machineType;
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - IOT组织新增/修改 Request VO")
@Data
public class IotOrganizationSaveReqVO {
@Schema(description = "组织id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24521")
private Long id;
@Schema(description = "显示顺序")
private Integer sort;
@Schema(description = "负责人/工人", example = "11964")
private Long workerUserId;
@Schema(description = "绑定工位id", example = "21787")
private Long orgId;
@Schema(description = "组织名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@NotEmpty(message = "组织名称不能为空")
private String name;
@Schema(description = "父组织id", requiredMode = Schema.RequiredMode.REQUIRED, example = "10729")
@NotNull(message = "父组织id不能为空")
private Long parentId;
@Schema(description = "组织状态", example = "2")
private Integer status;
@Schema(description = "设备类型", example = "2")
private String deviceType;
@Schema(description = "组织等级")
private String orgClass;
@Schema(description = "机台类型", example = "2")
private String machineType;
}

@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.iot.controller.admin.kanban;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.kanban.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.kanban.KanbanDO;
import cn.iocoder.yudao.module.iot.service.kanban.KanbanService;
@Tag(name = "管理后台 - 物联看板")
@RestController
@RequestMapping("/iot/kanban")
@Validated
public class KanbanController {
@Resource
private KanbanService kanbanService;
@PostMapping("/create")
@Operation(summary = "创建物联看板")
@PreAuthorize("@ss.hasPermission('iot:kanban:create')")
public CommonResult<Long> createKanban(@Valid @RequestBody KanbanSaveReqVO createReqVO) {
return success(kanbanService.createKanban(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新物联看板")
@PreAuthorize("@ss.hasPermission('iot:kanban:update')")
public CommonResult<Boolean> updateKanban(@Valid @RequestBody KanbanSaveReqVO updateReqVO) {
kanbanService.updateKanban(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除物联看板")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:kanban:delete')")
public CommonResult<Boolean> deleteKanban(@RequestParam("id") Long id) {
kanbanService.deleteKanban(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得物联看板")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:kanban:query')")
public CommonResult<KanbanRespVO> getKanban(@RequestParam("id") Long id) {
KanbanDO kanban = kanbanService.getKanban(id);
return success(BeanUtils.toBean(kanban, KanbanRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得物联看板分页")
@PreAuthorize("@ss.hasPermission('iot:kanban:query')")
public CommonResult<PageResult<KanbanRespVO>> getKanbanPage(@Valid KanbanPageReqVO pageReqVO) {
PageResult<KanbanDO> pageResult = kanbanService.getKanbanPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, KanbanRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出物联看板 Excel")
@PreAuthorize("@ss.hasPermission('iot:kanban:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportKanbanExcel(@Valid KanbanPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<KanbanDO> list = kanbanService.getKanbanPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物联看板.xls", "数据", KanbanRespVO.class,
BeanUtils.toBean(list, KanbanRespVO.class));
}
}

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.iot.controller.admin.kanban.vo;
import lombok.*;
import java.util.*;
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 KanbanPageReqVO extends PageParam {
@Schema(description = "编码")
private String code;
@Schema(description = "标题")
private String title;
@Schema(description = "缩略图")
private String img;
@Schema(description = "访问地址", example = "https://www.iocoder.cn")
private String viewUrl;
@Schema(description = "标签")
private String tags;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.iot.controller.admin.kanban.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 物联看板 Response VO")
@Data
@ExcelIgnoreUnannotated
public class KanbanRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22557")
@ExcelProperty("ID")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("编码")
private String code;
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("标题")
private String title;
@Schema(description = "缩略图")
@ExcelProperty("缩略图")
private String img;
@Schema(description = "访问地址", example = "https://www.iocoder.cn")
@ExcelProperty("访问地址")
private String viewUrl;
@Schema(description = "标签")
@ExcelProperty("标签")
private String tags;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "是否启用", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.iot.controller.admin.kanban.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 物联看板新增/修改 Request VO")
@Data
public class KanbanSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22557")
private Long id;
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "编码不能为空")
private String code;
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "标题不能为空")
private String title;
@Schema(description = "缩略图")
private String img;
@Schema(description = "访问地址", example = "https://www.iocoder.cn")
private String viewUrl;
@Schema(description = "标签")
private String tags;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
}

@ -0,0 +1,177 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.device;
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_attribute")
@KeySequence("iot_device_attribute_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceAttributeDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String attributeCode;
/**
*
*/
private String address;
/**
*
*/
private String attributeName;
/**
*
*/
private String description;
/**
*
*/
private String addressType;
/**
*
*/
private String addressOffset;
/**
* 2
*/
private String address2Type;
/**
* 2
*/
private String address2Offset;
/**
*
*/
private String groupName;
/**
* id
*/
private Integer groupId;
/**
*
*/
private String securityType;
/**
*
*/
private String ioStatus;
/**
* 线(01)
*
* {@link TODO iot_1_or_0 }
*/
private String isLinearTransfer;
/**
*
*
* {@link TODO iot_device_data_type }
*/
private String dataType;
/**
*
*/
private String unit;
/**
*
*/
private String inMinValue;
/**
*
*/
private String inMaxValue;
/**
*
*/
private String outMinValue;
/**
*
*/
private String outMaxValue;
/**
*
*/
private String outDataType;
/**
*
*/
private Integer siemensFieldPrecision;
/**
*
*/
private String modbusSlaveId;
/**
*
*/
private String modbusFieldAddress;
/**
*
*/
private String modbusAddressType;
/**
*
*/
private String modbusFieldSize;
/**
* 10
*/
private String modbusFieldPrecision;
/**
*
*/
private String modbusFieldOrder;
/**
* mqttbinary,octal,hexadecimal,decimal
*/
private String sourceDataType;
/**
* binary,octal,hexadecimal,decimal
*
* {@link TODO iot_device_data_transfer_type }
*/
private String transferDataType;
/**
*
*/
private String factor;
/**
* id
*/
private Long gatewayId;
/**
* id
*/
private Long deviceId;
/**
* id
*/
private Long orgId;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
}

@ -0,0 +1,159 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.device;
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")
@KeySequence("iot_device_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
* id
*/
private String deviceConfigId;
/**
*
*/
private String deviceCode;
/**
*
*/
private String deviceName;
/**
*
*/
private String deviceType;
/**
* Siemens(S7-300S7-1500)
*
* {@link TODO iot_siemens_type }
*/
private String siemensSeries;
/**
* ( 960081N
*/
private String siemensConnectParam;
/**
* (01)
*
* {@link TODO iot_1_or_0 }
*/
private String readCronType;
/**
*
*/
private Integer readRepeatValue;
/**
*
*
* {@link TODO iot_device_data_unit }
*/
private String readRepeatUnit;
/**
*
*/
private String readCron;
/**
*
*/
private String writeCronType;
/**
*
*/
private Integer writeRepeatValue;
/**
*
*/
private String writeRepeatUnit;
/**
*
*/
private String writeCron;
/**
* (01)
*
* {@link TODO iot_1_or_0 }
*/
private String localPersistent;
/**
* (12)
*
* {@link TODO iot_device_uploading_type }
*/
private String uploadRate;
/**
*
*/
private Integer rateCount;
/**
* modbus(serial-rtu)
*
* {@link TODO iot_modbus_type }
*/
private String modbusProtocol;
/**
* modbus(client)
*
* {@link TODO iot_modbus_mold }
*/
private String modbusPattern;
/**
* modbus
*
* {@link TODO iot_modbus_port }
*/
private String portName;
/**
* ( 960081N
*/
private String modbusConnectParam;
/**
* (01)
*
* {@link TODO iot_1_or_0 }
*/
private String modbusReadAddrGap;
/**
* (0,1)
*
* {@link TODO iot_1_or_0 }
*/
private String isUpload;
/**
* id
*/
private Long gatewayId;
/**
* id
*/
private Long orgId;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
}

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.formula;
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_formula")
@KeySequence("iot_formula_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FormulaDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String name;
/**
*
*/
private String formulaCode;
/**
*
*/
private String formula;
/**
*
*
* {@link TODO mes_data_type }
*/
private String resultType;
/**
* ID
*/
private Long machineId;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
}

@ -0,0 +1,83 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.formula;
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_formula_detail")
@KeySequence("iot_formula_detail_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FormulaDetailDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
* ID
*/
private Long formulaId;
/**
*
*/
private String formulaCode;
/**
*
*/
private String name;
/**
* ID
*/
private Long deviceId;
/**
* ID
*/
private Long attributeId;
/**
*
*/
private String attributeName;
/**
*
*/
private String address;
/**
*
*/
private String demoValue;
/**
* sum:max-min:-
*
* {@link TODO iot_formula_var_type }
*/
private String sumType;
/**
* day,week,month
*
* {@link TODO iot_formula_cal_rang }
*/
private String sumRange;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
}

@ -0,0 +1,69 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.gateway;
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_gateway")
@KeySequence("iot_gateway_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GatewayDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String adminIp;
/**
*
*/
private String username;
/**
*
*/
private String password;
/**
*
*/
private String gatewayName;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
/**
*
*/
private String gatewayCode;
/**
*
*
* {@link TODO iot_gateway_status }
*/
private String gatewayStatus;
/**
*
*/
private String topic;
}

@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization;
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;
/**
* IOT DO
*
* @author
*/
@TableName("iot_iot_organization")
@KeySequence("iot_iot_organization_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IotOrganizationDO extends BaseDO {
public static final Long PARENT_ID_ROOT = 0L;
/**
* id
*/
@TableId
private Long id;
/**
*
*/
private Integer sort;
/**
* /
*/
private Long workerUserId;
/**
* id
*/
private Long orgId;
/**
*
*/
private String name;
/**
* id
*/
private Long parentId;
/**
*
*
* {@link TODO mes_machine_status }
*/
private Integer status;
/**
*
*
* {@link TODO iot_device_type }
*/
private String deviceType;
/**
*
*
* {@link TODO iot_org_class }
*/
private String orgClass;
/**
*
*
* {@link TODO mes_org_type }
*/
private String machineType;
}

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.iot.dal.dataobject.kanban;
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_kanban")
@KeySequence("iot_kanban_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class KanbanDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String code;
/**
*
*/
private String title;
/**
*
*/
private String img;
/**
* 访
*/
private String viewUrl;
/**
*
*/
private String tags;
/**
*
*/
private String remark;
/**
*
*
* {@link TODO infra_boolean_string }
*/
private Boolean isEnable;
}

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.iot.dal.mysql.device;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author
*/
@Mapper
public interface DeviceAttributeMapper extends BaseMapperX<DeviceAttributeDO> {
default PageResult<DeviceAttributeDO> selectPage(PageParam reqVO, Long deviceId) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceAttributeDO>()
.eq(DeviceAttributeDO::getDeviceId, deviceId)
.orderByDesc(DeviceAttributeDO::getId));
}
default int deleteByDeviceId(Long deviceId) {
return delete(DeviceAttributeDO::getDeviceId, deviceId);
}
}

@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.iot.dal.mysql.device;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface DeviceMapper extends BaseMapperX<DeviceDO> {
default PageResult<DeviceDO> selectPage(DevicePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
.eqIfPresent(DeviceDO::getDeviceConfigId, reqVO.getDeviceConfigId())
.eqIfPresent(DeviceDO::getDeviceCode, reqVO.getDeviceCode())
.likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
.eqIfPresent(DeviceDO::getDeviceType, reqVO.getDeviceType())
.eqIfPresent(DeviceDO::getSiemensSeries, reqVO.getSiemensSeries())
.eqIfPresent(DeviceDO::getSiemensConnectParam, reqVO.getSiemensConnectParam())
.eqIfPresent(DeviceDO::getReadCronType, reqVO.getReadCronType())
.eqIfPresent(DeviceDO::getReadRepeatValue, reqVO.getReadRepeatValue())
.eqIfPresent(DeviceDO::getReadRepeatUnit, reqVO.getReadRepeatUnit())
.eqIfPresent(DeviceDO::getReadCron, reqVO.getReadCron())
.eqIfPresent(DeviceDO::getWriteCronType, reqVO.getWriteCronType())
.eqIfPresent(DeviceDO::getWriteRepeatValue, reqVO.getWriteRepeatValue())
.eqIfPresent(DeviceDO::getWriteRepeatUnit, reqVO.getWriteRepeatUnit())
.eqIfPresent(DeviceDO::getWriteCron, reqVO.getWriteCron())
.eqIfPresent(DeviceDO::getLocalPersistent, reqVO.getLocalPersistent())
.eqIfPresent(DeviceDO::getUploadRate, reqVO.getUploadRate())
.eqIfPresent(DeviceDO::getRateCount, reqVO.getRateCount())
.eqIfPresent(DeviceDO::getModbusProtocol, reqVO.getModbusProtocol())
.eqIfPresent(DeviceDO::getModbusPattern, reqVO.getModbusPattern())
.eqIfPresent(DeviceDO::getPortName, reqVO.getPortName())
.eqIfPresent(DeviceDO::getModbusConnectParam, reqVO.getModbusConnectParam())
.eqIfPresent(DeviceDO::getModbusReadAddrGap, reqVO.getModbusReadAddrGap())
.eqIfPresent(DeviceDO::getIsUpload, reqVO.getIsUpload())
.eqIfPresent(DeviceDO::getGatewayId, reqVO.getGatewayId())
.eqIfPresent(DeviceDO::getOrgId, reqVO.getOrgId())
.eqIfPresent(DeviceDO::getRemark, reqVO.getRemark())
.eqIfPresent(DeviceDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(DeviceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DeviceDO::getId));
}
default PageResult<DeviceDO> selectPage(PageParam reqVO, Long gatewayId) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
.eq(DeviceDO::getGatewayId, gatewayId)
.orderByDesc(DeviceDO::getId));
}
default int deleteByGatewayId(Long gatewayId) {
return delete(DeviceDO::getGatewayId, gatewayId);
}
}

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.iot.dal.mysql.formula;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDetailDO;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author
*/
@Mapper
public interface FormulaDetailMapper extends BaseMapperX<FormulaDetailDO> {
default PageResult<FormulaDetailDO> selectPage(PageParam reqVO, Long formulaId) {
return selectPage(reqVO, new LambdaQueryWrapperX<FormulaDetailDO>()
.eq(FormulaDetailDO::getFormulaId, formulaId)
.orderByDesc(FormulaDetailDO::getId));
}
default int deleteByFormulaId(Long formulaId) {
return delete(FormulaDetailDO::getFormulaId, formulaId);
}
}

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.iot.dal.mysql.formula;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.formula.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface FormulaMapper extends BaseMapperX<FormulaDO> {
default PageResult<FormulaDO> selectPage(FormulaPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<FormulaDO>()
.likeIfPresent(FormulaDO::getName, reqVO.getName())
.eqIfPresent(FormulaDO::getFormulaCode, reqVO.getFormulaCode())
.eqIfPresent(FormulaDO::getFormula, reqVO.getFormula())
.eqIfPresent(FormulaDO::getResultType, reqVO.getResultType())
.eqIfPresent(FormulaDO::getMachineId, reqVO.getMachineId())
.eqIfPresent(FormulaDO::getRemark, reqVO.getRemark())
.eqIfPresent(FormulaDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(FormulaDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(FormulaDO::getId));
}
}

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.iot.dal.mysql.gateway;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.gateway.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface GatewayMapper extends BaseMapperX<GatewayDO> {
default PageResult<GatewayDO> selectPage(GatewayPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<GatewayDO>()
.eqIfPresent(GatewayDO::getAdminIp, reqVO.getAdminIp())
.likeIfPresent(GatewayDO::getUsername, reqVO.getUsername())
.eqIfPresent(GatewayDO::getPassword, reqVO.getPassword())
.likeIfPresent(GatewayDO::getGatewayName, reqVO.getGatewayName())
.eqIfPresent(GatewayDO::getRemark, reqVO.getRemark())
.eqIfPresent(GatewayDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(GatewayDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(GatewayDO::getGatewayCode, reqVO.getGatewayCode())
.eqIfPresent(GatewayDO::getGatewayStatus, reqVO.getGatewayStatus())
.eqIfPresent(GatewayDO::getTopic, reqVO.getTopic())
.orderByDesc(GatewayDO::getId));
}
}

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.iot.dal.mysql.iotorganization;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo.*;
/**
* IOT Mapper
*
* @author
*/
@Mapper
public interface IotOrganizationMapper extends BaseMapperX<IotOrganizationDO> {
default List<IotOrganizationDO> selectList(IotOrganizationListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<IotOrganizationDO>()
.eqIfPresent(IotOrganizationDO::getSort, reqVO.getSort())
.eqIfPresent(IotOrganizationDO::getWorkerUserId, reqVO.getWorkerUserId())
.eqIfPresent(IotOrganizationDO::getOrgId, reqVO.getOrgId())
.betweenIfPresent(IotOrganizationDO::getCreateTime, reqVO.getCreateTime())
.likeIfPresent(IotOrganizationDO::getName, reqVO.getName())
.eqIfPresent(IotOrganizationDO::getParentId, reqVO.getParentId())
.eqIfPresent(IotOrganizationDO::getStatus, reqVO.getStatus())
.eqIfPresent(IotOrganizationDO::getDeviceType, reqVO.getDeviceType())
.eqIfPresent(IotOrganizationDO::getOrgClass, reqVO.getOrgClass())
.eqIfPresent(IotOrganizationDO::getMachineType, reqVO.getMachineType())
.orderByDesc(IotOrganizationDO::getId));
}
default IotOrganizationDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(IotOrganizationDO::getParentId, parentId, IotOrganizationDO::getName, name);
}
default Long selectCountByParentId(Long parentId) {
return selectCount(IotOrganizationDO::getParentId, parentId);
}
}

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.iot.dal.mysql.kanban;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.kanban.KanbanDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.kanban.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface KanbanMapper extends BaseMapperX<KanbanDO> {
default PageResult<KanbanDO> selectPage(KanbanPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<KanbanDO>()
.eqIfPresent(KanbanDO::getCode, reqVO.getCode())
.eqIfPresent(KanbanDO::getTitle, reqVO.getTitle())
.eqIfPresent(KanbanDO::getImg, reqVO.getImg())
.eqIfPresent(KanbanDO::getRemark, reqVO.getRemark())
.eqIfPresent(KanbanDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(KanbanDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(KanbanDO::getId));
}
}

@ -24,7 +24,7 @@ public class SecurityConfiguration {
@Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
registry.antMatchers("/iot/**").permitAll(); // 积木报表
registry.antMatchers("/iot/open/**").permitAll(); // 积木报表
}
};

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.iot.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* mes web Configuration
*
* @author
*/
@Configuration(proxyBeanMethods = false)
public class IotWebConfiguration {
/**
* crm API
*/
@Bean
public GroupedOpenApi iotGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("iot");
}
}

@ -0,0 +1,4 @@
/**
* crm web
*/
package cn.iocoder.yudao.module.iot.framework.web;

@ -0,0 +1,98 @@
package cn.iocoder.yudao.module.iot.service.device;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import javax.validation.Valid;
/**
* Service
*
* @author
*/
public interface DeviceService {
/**
*
*
* @param createReqVO
* @return
*/
Long createDevice(@Valid DeviceSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateDevice(@Valid DeviceSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteDevice(Long id);
/**
*
*
* @param id
* @return
*/
DeviceDO getDevice(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
// ==================== 子表(设备属性) ====================
/**
*
*
* @param pageReqVO
* @param deviceId id
* @return
*/
PageResult<DeviceAttributeDO> getDeviceAttributePage(PageParam pageReqVO, Long deviceId);
/**
*
*
* @param deviceAttribute
* @return
*/
Long createDeviceAttribute(@Valid DeviceAttributeDO deviceAttribute);
/**
*
*
* @param deviceAttribute
*/
void updateDeviceAttribute(@Valid DeviceAttributeDO deviceAttribute);
/**
*
*
* @param id
*/
void deleteDeviceAttribute(Long id);
/**
*
*
* @param id
* @return
*/
DeviceAttributeDO getDeviceAttribute(Long id);
}

@ -0,0 +1,127 @@
package cn.iocoder.yudao.module.iot.service.device;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceAttributeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceAttributeMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceMapper deviceMapper;
@Resource
private DeviceAttributeMapper deviceAttributeMapper;
@Override
public Long createDevice(DeviceSaveReqVO createReqVO) {
// 插入
DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class);
deviceMapper.insert(device);
// 返回
return device.getId();
}
@Override
public void updateDevice(DeviceSaveReqVO updateReqVO) {
// 校验存在
validateDeviceExists(updateReqVO.getId());
// 更新
DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
deviceMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDevice(Long id) {
// 校验存在
validateDeviceExists(id);
// 删除
deviceMapper.deleteById(id);
// 删除子表
deleteDeviceAttributeByDeviceId(id);
}
private void validateDeviceExists(Long id) {
if (deviceMapper.selectById(id) == null) {
throw exception(DEVICE_NOT_EXISTS);
}
}
@Override
public DeviceDO getDevice(Long id) {
return deviceMapper.selectById(id);
}
@Override
public PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
return deviceMapper.selectPage(pageReqVO);
}
// ==================== 子表(设备属性) ====================
@Override
public PageResult<DeviceAttributeDO> getDeviceAttributePage(PageParam pageReqVO, Long deviceId) {
return deviceAttributeMapper.selectPage(pageReqVO, deviceId);
}
@Override
public Long createDeviceAttribute(DeviceAttributeDO deviceAttribute) {
deviceAttributeMapper.insert(deviceAttribute);
return deviceAttribute.getId();
}
@Override
public void updateDeviceAttribute(DeviceAttributeDO deviceAttribute) {
// 校验存在
validateDeviceAttributeExists(deviceAttribute.getId());
// 更新
deviceAttributeMapper.updateById(deviceAttribute);
}
@Override
public void deleteDeviceAttribute(Long id) {
// 校验存在
validateDeviceAttributeExists(id);
// 删除
deviceAttributeMapper.deleteById(id);
}
@Override
public DeviceAttributeDO getDeviceAttribute(Long id) {
return deviceAttributeMapper.selectById(id);
}
private void validateDeviceAttributeExists(Long id) {
if (deviceAttributeMapper.selectById(id) == null) {
throw exception(DEVICE_ATTRIBUTE_NOT_EXISTS);
}
}
private void deleteDeviceAttributeByDeviceId(Long deviceId) {
deviceAttributeMapper.deleteByDeviceId(deviceId);
}
}

@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.iot.service.formula;
import javax.validation.Valid;
import cn.iocoder.yudao.module.iot.controller.admin.formula.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDetailDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface FormulaService {
/**
*
*
* @param createReqVO
* @return
*/
Long createFormula(@Valid FormulaSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateFormula(@Valid FormulaSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteFormula(Long id);
/**
*
*
* @param id
* @return
*/
FormulaDO getFormula(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<FormulaDO> getFormulaPage(FormulaPageReqVO pageReqVO);
// ==================== 子表(计算公式明细) ====================
/**
*
*
* @param pageReqVO
* @param formulaId ID
* @return
*/
PageResult<FormulaDetailDO> getFormulaDetailPage(PageParam pageReqVO, Long formulaId);
/**
*
*
* @param formulaDetail
* @return
*/
Long createFormulaDetail(@Valid FormulaDetailDO formulaDetail);
/**
*
*
* @param formulaDetail
*/
void updateFormulaDetail(@Valid FormulaDetailDO formulaDetail);
/**
*
*
* @param id
*/
void deleteFormulaDetail(Long id);
/**
*
*
* @param id
* @return
*/
FormulaDetailDO getFormulaDetail(Long id);
}

@ -0,0 +1,126 @@
package cn.iocoder.yudao.module.iot.service.formula;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.formula.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDetailDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.formula.FormulaMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.formula.FormulaDetailMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class FormulaServiceImpl implements FormulaService {
@Resource
private FormulaMapper formulaMapper;
@Resource
private FormulaDetailMapper formulaDetailMapper;
@Override
public Long createFormula(FormulaSaveReqVO createReqVO) {
// 插入
FormulaDO formula = BeanUtils.toBean(createReqVO, FormulaDO.class);
formulaMapper.insert(formula);
// 返回
return formula.getId();
}
@Override
public void updateFormula(FormulaSaveReqVO updateReqVO) {
// 校验存在
validateFormulaExists(updateReqVO.getId());
// 更新
FormulaDO updateObj = BeanUtils.toBean(updateReqVO, FormulaDO.class);
formulaMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteFormula(Long id) {
// 校验存在
validateFormulaExists(id);
// 删除
formulaMapper.deleteById(id);
// 删除子表
deleteFormulaDetailByFormulaId(id);
}
private void validateFormulaExists(Long id) {
if (formulaMapper.selectById(id) == null) {
throw exception(FORMULA_NOT_EXISTS);
}
}
@Override
public FormulaDO getFormula(Long id) {
return formulaMapper.selectById(id);
}
@Override
public PageResult<FormulaDO> getFormulaPage(FormulaPageReqVO pageReqVO) {
return formulaMapper.selectPage(pageReqVO);
}
// ==================== 子表(计算公式明细) ====================
@Override
public PageResult<FormulaDetailDO> getFormulaDetailPage(PageParam pageReqVO, Long formulaId) {
return formulaDetailMapper.selectPage(pageReqVO, formulaId);
}
@Override
public Long createFormulaDetail(FormulaDetailDO formulaDetail) {
formulaDetailMapper.insert(formulaDetail);
return formulaDetail.getId();
}
@Override
public void updateFormulaDetail(FormulaDetailDO formulaDetail) {
// 校验存在
validateFormulaDetailExists(formulaDetail.getId());
// 更新
formulaDetailMapper.updateById(formulaDetail);
}
@Override
public void deleteFormulaDetail(Long id) {
// 校验存在
validateFormulaDetailExists(id);
// 删除
formulaDetailMapper.deleteById(id);
}
@Override
public FormulaDetailDO getFormulaDetail(Long id) {
return formulaDetailMapper.selectById(id);
}
private void validateFormulaDetailExists(Long id) {
if (formulaDetailMapper.selectById(id) == null) {
throw exception(FORMULA_DETAIL_NOT_EXISTS);
}
}
private void deleteFormulaDetailByFormulaId(Long formulaId) {
formulaDetailMapper.deleteByFormulaId(formulaId);
}
}

@ -0,0 +1,96 @@
package cn.iocoder.yudao.module.iot.service.gateway;
import javax.validation.Valid;
import cn.iocoder.yudao.module.iot.controller.admin.gateway.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface GatewayService {
/**
*
*
* @param createReqVO
* @return
*/
Long createGateway(@Valid GatewaySaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateGateway(@Valid GatewaySaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteGateway(Long id);
/**
*
*
* @param id
* @return
*/
GatewayDO getGateway(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<GatewayDO> getGatewayPage(GatewayPageReqVO pageReqVO);
// ==================== 子表(物联设备) ====================
/**
*
*
* @param pageReqVO
* @param gatewayId id
* @return
*/
PageResult<DeviceDO> getDevicePage(PageParam pageReqVO, Long gatewayId);
/**
*
*
* @param device
* @return
*/
Long createDevice(@Valid DeviceDO device);
/**
*
*
* @param device
*/
void updateDevice(@Valid DeviceDO device);
/**
*
*
* @param id
*/
void deleteDevice(Long id);
/**
*
*
* @param id
* @return
*/
DeviceDO getDevice(Long id);
}

@ -0,0 +1,125 @@
package cn.iocoder.yudao.module.iot.service.gateway;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import cn.iocoder.yudao.module.iot.controller.admin.gateway.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.gateway.GatewayMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class GatewayServiceImpl implements GatewayService {
@Resource
private GatewayMapper gatewayMapper;
@Resource
private DeviceMapper deviceMapper;
@Override
public Long createGateway(GatewaySaveReqVO createReqVO) {
// 插入
GatewayDO gateway = BeanUtils.toBean(createReqVO, GatewayDO.class);
gatewayMapper.insert(gateway);
// 返回
return gateway.getId();
}
@Override
public void updateGateway(GatewaySaveReqVO updateReqVO) {
// 校验存在
validateGatewayExists(updateReqVO.getId());
// 更新
GatewayDO updateObj = BeanUtils.toBean(updateReqVO, GatewayDO.class);
gatewayMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteGateway(Long id) {
// 校验存在
validateGatewayExists(id);
// 删除
gatewayMapper.deleteById(id);
// 删除子表
deleteDeviceByGatewayId(id);
}
private void validateGatewayExists(Long id) {
if (gatewayMapper.selectById(id) == null) {
throw exception(GATEWAY_NOT_EXISTS);
}
}
@Override
public GatewayDO getGateway(Long id) {
return gatewayMapper.selectById(id);
}
@Override
public PageResult<GatewayDO> getGatewayPage(GatewayPageReqVO pageReqVO) {
return gatewayMapper.selectPage(pageReqVO);
}
// ==================== 子表(物联设备) ====================
@Override
public PageResult<DeviceDO> getDevicePage(PageParam pageReqVO, Long gatewayId) {
return deviceMapper.selectPage(pageReqVO, gatewayId);
}
@Override
public Long createDevice(DeviceDO device) {
deviceMapper.insert(device);
return device.getId();
}
@Override
public void updateDevice(DeviceDO device) {
// 校验存在
validateDeviceExists(device.getId());
// 更新
deviceMapper.updateById(device);
}
@Override
public void deleteDevice(Long id) {
// 校验存在
validateDeviceExists(id);
// 删除
deviceMapper.deleteById(id);
}
@Override
public DeviceDO getDevice(Long id) {
return deviceMapper.selectById(id);
}
private void validateDeviceExists(Long id) {
if (deviceMapper.selectById(id) == null) {
throw exception(DEVICE_NOT_EXISTS);
}
}
private void deleteDeviceByGatewayId(Long gatewayId) {
deviceMapper.deleteByGatewayId(gatewayId);
}
}

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.iot.service.iotorganization;
import java.util.*;
import javax.validation.Valid;
import cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* IOT Service
*
* @author
*/
public interface IotOrganizationService {
/**
* IOT
*
* @param createReqVO
* @return
*/
Long createOrganization(@Valid IotOrganizationSaveReqVO createReqVO);
/**
* IOT
*
* @param updateReqVO
*/
void updateOrganization(@Valid IotOrganizationSaveReqVO updateReqVO);
/**
* IOT
*
* @param id
*/
void deleteOrganization(Long id);
/**
* IOT
*
* @param id
* @return IOT
*/
IotOrganizationDO getOrganization(Long id);
/**
* IOT
*
* @param listReqVO
* @return IOT
*/
List<IotOrganizationDO> getOrganizationList(IotOrganizationListReqVO listReqVO);
}

@ -0,0 +1,133 @@
package cn.iocoder.yudao.module.iot.service.iotorganization;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.iotorganization.IotOrganizationMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* IOT Service
*
* @author
*/
@Service
@Validated
public class IotOrganizationServiceImpl implements IotOrganizationService {
@Resource
private IotOrganizationMapper iotOrganizationMapper;
@Override
public Long createOrganization(IotOrganizationSaveReqVO createReqVO) {
// 校验父组织id的有效性
validateParentOrganization(null, createReqVO.getParentId());
// 校验组织名称的唯一性
validateOrganizationNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
// 插入
IotOrganizationDO organization = BeanUtils.toBean(createReqVO, IotOrganizationDO.class);
iotOrganizationMapper.insert(organization);
// 返回
return organization.getId();
}
@Override
public void updateOrganization(IotOrganizationSaveReqVO updateReqVO) {
// 校验存在
validateOrganizationExists(updateReqVO.getId());
// 校验父组织id的有效性
validateParentOrganization(updateReqVO.getId(), updateReqVO.getParentId());
// 校验组织名称的唯一性
validateOrganizationNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
// 更新
IotOrganizationDO updateObj = BeanUtils.toBean(updateReqVO, IotOrganizationDO.class);
iotOrganizationMapper.updateById(updateObj);
}
@Override
public void deleteOrganization(Long id) {
// 校验存在
validateOrganizationExists(id);
// 校验是否有子IOT组织
if (iotOrganizationMapper.selectCountByParentId(id) > 0) {
throw exception(ORGANIZATION_EXITS_CHILDREN);
}
// 删除
iotOrganizationMapper.deleteById(id);
}
private void validateOrganizationExists(Long id) {
if (iotOrganizationMapper.selectById(id) == null) {
throw exception(ORGANIZATION_NOT_EXISTS);
}
}
private void validateParentOrganization(Long id, Long parentId) {
if (parentId == null || IotOrganizationDO.PARENT_ID_ROOT.equals(parentId)) {
return;
}
// 1. 不能设置自己为父IOT组织
if (Objects.equals(id, parentId)) {
throw exception(ORGANIZATION_PARENT_ERROR);
}
// 2. 父IOT组织不存在
IotOrganizationDO parentOrganization = iotOrganizationMapper.selectById(parentId);
if (parentOrganization == null) {
throw exception(ORGANIZATION_PARENT_NOT_EXITS);
}
// 3. 递归校验父IOT组织如果父IOT组织是自己的子IOT组织则报错避免形成环路
if (id == null) { // id 为空,说明新增,不需要考虑环路
return;
}
for (int i = 0; i < Short.MAX_VALUE; i++) {
// 3.1 校验环路
parentId = parentOrganization.getParentId();
if (Objects.equals(id, parentId)) {
throw exception(ORGANIZATION_PARENT_IS_CHILD);
}
// 3.2 继续递归下一级父IOT组织
if (parentId == null || IotOrganizationDO.PARENT_ID_ROOT.equals(parentId)) {
break;
}
parentOrganization = iotOrganizationMapper.selectById(parentId);
if (parentOrganization == null) {
break;
}
}
}
private void validateOrganizationNameUnique(Long id, Long parentId, String name) {
IotOrganizationDO organization = iotOrganizationMapper.selectByParentIdAndName(parentId, name);
if (organization == null) {
return;
}
// 如果 id 为空,说明不用比较是否为相同 id 的IOT组织
if (id == null) {
throw exception(ORGANIZATION_NAME_DUPLICATE);
}
if (!Objects.equals(organization.getId(), id)) {
throw exception(ORGANIZATION_NAME_DUPLICATE);
}
}
@Override
public IotOrganizationDO getOrganization(Long id) {
return iotOrganizationMapper.selectById(id);
}
@Override
public List<IotOrganizationDO> getOrganizationList(IotOrganizationListReqVO listReqVO) {
return iotOrganizationMapper.selectList(listReqVO);
}
}

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.iot.service.kanban;
import javax.validation.Valid;
import cn.iocoder.yudao.module.iot.controller.admin.kanban.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.kanban.KanbanDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface KanbanService {
/**
*
*
* @param createReqVO
* @return
*/
Long createKanban(@Valid KanbanSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateKanban(@Valid KanbanSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteKanban(Long id);
/**
*
*
* @param id
* @return
*/
KanbanDO getKanban(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<KanbanDO> getKanbanPage(KanbanPageReqVO pageReqVO);
}

@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.iot.service.kanban;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.iot.controller.admin.kanban.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.kanban.KanbanDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.kanban.KanbanMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class KanbanServiceImpl implements KanbanService {
@Resource
private KanbanMapper kanbanMapper;
@Override
public Long createKanban(KanbanSaveReqVO createReqVO) {
// 插入
KanbanDO kanban = BeanUtils.toBean(createReqVO, KanbanDO.class);
kanbanMapper.insert(kanban);
// 返回
return kanban.getId();
}
@Override
public void updateKanban(KanbanSaveReqVO updateReqVO) {
// 校验存在
validateKanbanExists(updateReqVO.getId());
// 更新
KanbanDO updateObj = BeanUtils.toBean(updateReqVO, KanbanDO.class);
kanbanMapper.updateById(updateObj);
}
@Override
public void deleteKanban(Long id) {
// 校验存在
validateKanbanExists(id);
// 删除
kanbanMapper.deleteById(id);
}
private void validateKanbanExists(Long id) {
if (kanbanMapper.selectById(id) == null) {
throw exception(KANBAN_NOT_EXISTS);
}
}
@Override
public KanbanDO getKanban(Long id) {
return kanbanMapper.selectById(id);
}
@Override
public PageResult<KanbanDO> getKanbanPage(KanbanPageReqVO pageReqVO) {
return kanbanMapper.selectPage(pageReqVO);
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.formula.FormulaMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.gateway.GatewayMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.iotorganization.IotOrganizationMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.kanban.KanbanMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,231 @@
package cn.iocoder.yudao.module.iot.service.device;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link DeviceServiceImpl}
*
* @author
*/
@Import(DeviceServiceImpl.class)
public class DeviceServiceImplTest extends BaseDbUnitTest {
@Resource
private DeviceServiceImpl deviceService;
@Resource
private DeviceMapper deviceMapper;
@Test
public void testCreateDevice_success() {
// 准备参数
DeviceSaveReqVO createReqVO = randomPojo(DeviceSaveReqVO.class).setId(null);
// 调用
Long deviceId = deviceService.createDevice(createReqVO);
// 断言
assertNotNull(deviceId);
// 校验记录的属性是否正确
DeviceDO device = deviceMapper.selectById(deviceId);
assertPojoEquals(createReqVO, device, "id");
}
@Test
public void testUpdateDevice_success() {
// mock 数据
DeviceDO dbDevice = randomPojo(DeviceDO.class);
deviceMapper.insert(dbDevice);// @Sql: 先插入出一条存在的数据
// 准备参数
DeviceSaveReqVO updateReqVO = randomPojo(DeviceSaveReqVO.class, o -> {
o.setId(dbDevice.getId()); // 设置更新的 ID
});
// 调用
deviceService.updateDevice(updateReqVO);
// 校验是否更新正确
DeviceDO device = deviceMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, device);
}
@Test
public void testUpdateDevice_notExists() {
// 准备参数
DeviceSaveReqVO updateReqVO = randomPojo(DeviceSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> deviceService.updateDevice(updateReqVO), DEVICE_NOT_EXISTS);
}
@Test
public void testDeleteDevice_success() {
// mock 数据
DeviceDO dbDevice = randomPojo(DeviceDO.class);
deviceMapper.insert(dbDevice);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbDevice.getId();
// 调用
deviceService.deleteDevice(id);
// 校验数据不存在了
assertNull(deviceMapper.selectById(id));
}
@Test
public void testDeleteDevice_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> deviceService.deleteDevice(id), DEVICE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetDevicePage() {
// mock 数据
DeviceDO dbDevice = randomPojo(DeviceDO.class, o -> { // 等会查询到
o.setDeviceConfigId(null);
o.setDeviceCode(null);
o.setDeviceName(null);
o.setDeviceType(null);
o.setSiemensSeries(null);
o.setSiemensConnectParam(null);
o.setReadCronType(null);
o.setReadRepeatValue(null);
o.setReadRepeatUnit(null);
o.setReadCron(null);
o.setWriteCronType(null);
o.setWriteRepeatValue(null);
o.setWriteRepeatUnit(null);
o.setWriteCron(null);
o.setLocalPersistent(null);
o.setUploadRate(null);
o.setRateCount(null);
o.setModbusProtocol(null);
o.setModbusPattern(null);
o.setPortName(null);
o.setModbusConnectParam(null);
o.setModbusReadAddrGap(null);
o.setIsUpload(null);
o.setGatewayId(null);
o.setOrgId(null);
o.setRemark(null);
o.setIsEnable(null);
o.setCreateTime(null);
});
deviceMapper.insert(dbDevice);
// 测试 deviceConfigId 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceConfigId(null)));
// 测试 deviceCode 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceCode(null)));
// 测试 deviceName 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceName(null)));
// 测试 deviceType 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setDeviceType(null)));
// 测试 siemensSeries 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setSiemensSeries(null)));
// 测试 siemensConnectParam 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setSiemensConnectParam(null)));
// 测试 readCronType 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadCronType(null)));
// 测试 readRepeatValue 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadRepeatValue(null)));
// 测试 readRepeatUnit 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadRepeatUnit(null)));
// 测试 readCron 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setReadCron(null)));
// 测试 writeCronType 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteCronType(null)));
// 测试 writeRepeatValue 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteRepeatValue(null)));
// 测试 writeRepeatUnit 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteRepeatUnit(null)));
// 测试 writeCron 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setWriteCron(null)));
// 测试 localPersistent 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setLocalPersistent(null)));
// 测试 uploadRate 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setUploadRate(null)));
// 测试 rateCount 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setRateCount(null)));
// 测试 modbusProtocol 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusProtocol(null)));
// 测试 modbusPattern 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusPattern(null)));
// 测试 portName 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setPortName(null)));
// 测试 modbusConnectParam 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusConnectParam(null)));
// 测试 modbusReadAddrGap 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setModbusReadAddrGap(null)));
// 测试 isUpload 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setIsUpload(null)));
// 测试 gatewayId 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setGatewayId(null)));
// 测试 orgId 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setOrgId(null)));
// 测试 remark 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setRemark(null)));
// 测试 isEnable 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setIsEnable(null)));
// 测试 createTime 不匹配
deviceMapper.insert(cloneIgnoreId(dbDevice, o -> o.setCreateTime(null)));
// 准备参数
DevicePageReqVO reqVO = new DevicePageReqVO();
reqVO.setDeviceConfigId(null);
reqVO.setDeviceCode(null);
reqVO.setDeviceName(null);
reqVO.setDeviceType(null);
reqVO.setSiemensSeries(null);
reqVO.setSiemensConnectParam(null);
reqVO.setReadCronType(null);
reqVO.setReadRepeatValue(null);
reqVO.setReadRepeatUnit(null);
reqVO.setReadCron(null);
reqVO.setWriteCronType(null);
reqVO.setWriteRepeatValue(null);
reqVO.setWriteRepeatUnit(null);
reqVO.setWriteCron(null);
reqVO.setLocalPersistent(null);
reqVO.setUploadRate(null);
reqVO.setRateCount(null);
reqVO.setModbusProtocol(null);
reqVO.setModbusPattern(null);
reqVO.setPortName(null);
reqVO.setModbusConnectParam(null);
reqVO.setModbusReadAddrGap(null);
reqVO.setIsUpload(null);
reqVO.setGatewayId(null);
reqVO.setOrgId(null);
reqVO.setRemark(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<DeviceDO> pageResult = deviceService.getDevicePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbDevice, pageResult.getList().get(0));
}
}

@ -0,0 +1,160 @@
package cn.iocoder.yudao.module.iot.service.formula;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.formula.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.formula.FormulaDO;
import cn.iocoder.yudao.module.iot.dal.mysql.formula.FormulaMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link FormulaServiceImpl}
*
* @author
*/
@Import(FormulaServiceImpl.class)
public class FormulaServiceImplTest extends BaseDbUnitTest {
@Resource
private FormulaServiceImpl formulaService;
@Resource
private FormulaMapper formulaMapper;
@Test
public void testCreateFormula_success() {
// 准备参数
FormulaSaveReqVO createReqVO = randomPojo(FormulaSaveReqVO.class).setId(null);
// 调用
Long formulaId = formulaService.createFormula(createReqVO);
// 断言
assertNotNull(formulaId);
// 校验记录的属性是否正确
FormulaDO formula = formulaMapper.selectById(formulaId);
assertPojoEquals(createReqVO, formula, "id");
}
@Test
public void testUpdateFormula_success() {
// mock 数据
FormulaDO dbFormula = randomPojo(FormulaDO.class);
formulaMapper.insert(dbFormula);// @Sql: 先插入出一条存在的数据
// 准备参数
FormulaSaveReqVO updateReqVO = randomPojo(FormulaSaveReqVO.class, o -> {
o.setId(dbFormula.getId()); // 设置更新的 ID
});
// 调用
formulaService.updateFormula(updateReqVO);
// 校验是否更新正确
FormulaDO formula = formulaMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, formula);
}
@Test
public void testUpdateFormula_notExists() {
// 准备参数
FormulaSaveReqVO updateReqVO = randomPojo(FormulaSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> formulaService.updateFormula(updateReqVO), FORMULA_NOT_EXISTS);
}
@Test
public void testDeleteFormula_success() {
// mock 数据
FormulaDO dbFormula = randomPojo(FormulaDO.class);
formulaMapper.insert(dbFormula);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbFormula.getId();
// 调用
formulaService.deleteFormula(id);
// 校验数据不存在了
assertNull(formulaMapper.selectById(id));
}
@Test
public void testDeleteFormula_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> formulaService.deleteFormula(id), FORMULA_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetFormulaPage() {
// mock 数据
FormulaDO dbFormula = randomPojo(FormulaDO.class, o -> { // 等会查询到
o.setName(null);
o.setFormulaCode(null);
o.setFormula(null);
o.setResultType(null);
o.setMachineId(null);
o.setRemark(null);
o.setIsEnable(null);
o.setCreateTime(null);
});
formulaMapper.insert(dbFormula);
// 测试 name 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setName(null)));
// 测试 formulaCode 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setFormulaCode(null)));
// 测试 formula 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setFormula(null)));
// 测试 resultType 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setResultType(null)));
// 测试 machineId 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setMachineId(null)));
// 测试 remark 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setRemark(null)));
// 测试 isEnable 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setIsEnable(null)));
// 测试 createTime 不匹配
formulaMapper.insert(cloneIgnoreId(dbFormula, o -> o.setCreateTime(null)));
// 准备参数
FormulaPageReqVO reqVO = new FormulaPageReqVO();
reqVO.setName(null);
reqVO.setFormulaCode(null);
reqVO.setFormula(null);
reqVO.setResultType(null);
reqVO.setMachineId(null);
reqVO.setRemark(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<FormulaDO> pageResult = formulaService.getFormulaPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbFormula, pageResult.getList().get(0));
}
}

@ -0,0 +1,168 @@
package cn.iocoder.yudao.module.iot.service.gateway;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.gateway.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import cn.iocoder.yudao.module.iot.dal.mysql.gateway.GatewayMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link GatewayServiceImpl}
*
* @author
*/
@Import(GatewayServiceImpl.class)
public class GatewayServiceImplTest extends BaseDbUnitTest {
@Resource
private GatewayServiceImpl gatewayService;
@Resource
private GatewayMapper gatewayMapper;
@Test
public void testCreateGateway_success() {
// 准备参数
GatewaySaveReqVO createReqVO = randomPojo(GatewaySaveReqVO.class).setId(null);
// 调用
Long gatewayId = gatewayService.createGateway(createReqVO);
// 断言
assertNotNull(gatewayId);
// 校验记录的属性是否正确
GatewayDO gateway = gatewayMapper.selectById(gatewayId);
assertPojoEquals(createReqVO, gateway, "id");
}
@Test
public void testUpdateGateway_success() {
// mock 数据
GatewayDO dbGateway = randomPojo(GatewayDO.class);
gatewayMapper.insert(dbGateway);// @Sql: 先插入出一条存在的数据
// 准备参数
GatewaySaveReqVO updateReqVO = randomPojo(GatewaySaveReqVO.class, o -> {
o.setId(dbGateway.getId()); // 设置更新的 ID
});
// 调用
gatewayService.updateGateway(updateReqVO);
// 校验是否更新正确
GatewayDO gateway = gatewayMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, gateway);
}
@Test
public void testUpdateGateway_notExists() {
// 准备参数
GatewaySaveReqVO updateReqVO = randomPojo(GatewaySaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> gatewayService.updateGateway(updateReqVO), GATEWAY_NOT_EXISTS);
}
@Test
public void testDeleteGateway_success() {
// mock 数据
GatewayDO dbGateway = randomPojo(GatewayDO.class);
gatewayMapper.insert(dbGateway);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbGateway.getId();
// 调用
gatewayService.deleteGateway(id);
// 校验数据不存在了
assertNull(gatewayMapper.selectById(id));
}
@Test
public void testDeleteGateway_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> gatewayService.deleteGateway(id), GATEWAY_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetGatewayPage() {
// mock 数据
GatewayDO dbGateway = randomPojo(GatewayDO.class, o -> { // 等会查询到
o.setAdminIp(null);
o.setUsername(null);
o.setPassword(null);
o.setGatewayName(null);
o.setRemark(null);
o.setIsEnable(null);
o.setCreateTime(null);
o.setGatewayCode(null);
o.setGatewayStatus(null);
o.setTopic(null);
});
gatewayMapper.insert(dbGateway);
// 测试 adminIp 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setAdminIp(null)));
// 测试 username 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setUsername(null)));
// 测试 password 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setPassword(null)));
// 测试 gatewayName 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setGatewayName(null)));
// 测试 remark 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setRemark(null)));
// 测试 isEnable 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setIsEnable(null)));
// 测试 createTime 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setCreateTime(null)));
// 测试 gatewayCode 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setGatewayCode(null)));
// 测试 gatewayStatus 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setGatewayStatus(null)));
// 测试 topic 不匹配
gatewayMapper.insert(cloneIgnoreId(dbGateway, o -> o.setTopic(null)));
// 准备参数
GatewayPageReqVO reqVO = new GatewayPageReqVO();
reqVO.setAdminIp(null);
reqVO.setUsername(null);
reqVO.setPassword(null);
reqVO.setGatewayName(null);
reqVO.setRemark(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setGatewayCode(null);
reqVO.setGatewayStatus(null);
reqVO.setTopic(null);
// 调用
PageResult<GatewayDO> pageResult = gatewayService.getGatewayPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbGateway, pageResult.getList().get(0));
}
}

@ -0,0 +1,165 @@
package cn.iocoder.yudao.module.iot.service.iotorganization;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.iotorganization.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.iotorganization.IotOrganizationDO;
import cn.iocoder.yudao.module.iot.dal.mysql.iotorganization.IotOrganizationMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link IotOrganizationServiceImpl}
*
* @author
*/
@Import(IotOrganizationServiceImpl.class)
public class IotOrganizationServiceImplTest extends BaseDbUnitTest {
@Resource
private IotOrganizationServiceImpl organizationService;
@Resource
private IotOrganizationMapper organizationMapper;
@Test
public void testCreateOrganization_success() {
// 准备参数
IotOrganizationSaveReqVO createReqVO = randomPojo(IotOrganizationSaveReqVO.class).setId(null);
// 调用
Long organizationId = organizationService.createOrganization(createReqVO);
// 断言
assertNotNull(organizationId);
// 校验记录的属性是否正确
IotOrganizationDO organization = organizationMapper.selectById(organizationId);
assertPojoEquals(createReqVO, organization, "id");
}
@Test
public void testUpdateOrganization_success() {
// mock 数据
IotOrganizationDO dbOrganization = randomPojo(IotOrganizationDO.class);
organizationMapper.insert(dbOrganization);// @Sql: 先插入出一条存在的数据
// 准备参数
IotOrganizationSaveReqVO updateReqVO = randomPojo(IotOrganizationSaveReqVO.class, o -> {
o.setId(dbOrganization.getId()); // 设置更新的 ID
});
// 调用
organizationService.updateOrganization(updateReqVO);
// 校验是否更新正确
IotOrganizationDO organization = organizationMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, organization);
}
@Test
public void testUpdateOrganization_notExists() {
// 准备参数
IotOrganizationSaveReqVO updateReqVO = randomPojo(IotOrganizationSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> organizationService.updateOrganization(updateReqVO), ORGANIZATION_NOT_EXISTS);
}
@Test
public void testDeleteOrganization_success() {
// mock 数据
IotOrganizationDO dbOrganization = randomPojo(IotOrganizationDO.class);
organizationMapper.insert(dbOrganization);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbOrganization.getId();
// 调用
organizationService.deleteOrganization(id);
// 校验数据不存在了
assertNull(organizationMapper.selectById(id));
}
@Test
public void testDeleteOrganization_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> organizationService.deleteOrganization(id), ORGANIZATION_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetOrganizationList() {
// mock 数据
IotOrganizationDO dbOrganization = randomPojo(IotOrganizationDO.class, o -> { // 等会查询到
o.setSort(null);
o.setWorkerUserId(null);
o.setOrgId(null);
o.setCreateTime(null);
o.setName(null);
o.setParentId(null);
o.setStatus(null);
o.setDeviceType(null);
o.setOrgClass(null);
o.setMachineType(null);
});
organizationMapper.insert(dbOrganization);
// 测试 sort 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setSort(null)));
// 测试 workerUserId 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setWorkerUserId(null)));
// 测试 orgId 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setOrgId(null)));
// 测试 createTime 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setCreateTime(null)));
// 测试 name 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setName(null)));
// 测试 parentId 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setParentId(null)));
// 测试 status 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setStatus(null)));
// 测试 deviceType 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setDeviceType(null)));
// 测试 orgClass 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setOrgClass(null)));
// 测试 machineType 不匹配
organizationMapper.insert(cloneIgnoreId(dbOrganization, o -> o.setMachineType(null)));
// 准备参数
IotOrganizationListReqVO reqVO = new IotOrganizationListReqVO();
reqVO.setSort(null);
reqVO.setWorkerUserId(null);
reqVO.setOrgId(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setName(null);
reqVO.setParentId(null);
reqVO.setStatus(null);
reqVO.setDeviceType(null);
reqVO.setOrgClass(null);
reqVO.setMachineType(null);
// 调用
List<IotOrganizationDO> list = organizationService.getOrganizationList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbOrganization, list.get(0));
}
}

@ -0,0 +1,150 @@
package cn.iocoder.yudao.module.iot.service.kanban;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.iot.controller.admin.kanban.vo.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.kanban.KanbanDO;
import cn.iocoder.yudao.module.iot.dal.mysql.kanban.KanbanMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link KanbanServiceImpl}
*
* @author
*/
@Import(KanbanServiceImpl.class)
public class KanbanServiceImplTest extends BaseDbUnitTest {
@Resource
private KanbanServiceImpl kanbanService;
@Resource
private KanbanMapper kanbanMapper;
@Test
public void testCreateKanban_success() {
// 准备参数
KanbanSaveReqVO createReqVO = randomPojo(KanbanSaveReqVO.class).setId(null);
// 调用
Long kanbanId = kanbanService.createKanban(createReqVO);
// 断言
assertNotNull(kanbanId);
// 校验记录的属性是否正确
KanbanDO kanban = kanbanMapper.selectById(kanbanId);
assertPojoEquals(createReqVO, kanban, "id");
}
@Test
public void testUpdateKanban_success() {
// mock 数据
KanbanDO dbKanban = randomPojo(KanbanDO.class);
kanbanMapper.insert(dbKanban);// @Sql: 先插入出一条存在的数据
// 准备参数
KanbanSaveReqVO updateReqVO = randomPojo(KanbanSaveReqVO.class, o -> {
o.setId(dbKanban.getId()); // 设置更新的 ID
});
// 调用
kanbanService.updateKanban(updateReqVO);
// 校验是否更新正确
KanbanDO kanban = kanbanMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, kanban);
}
@Test
public void testUpdateKanban_notExists() {
// 准备参数
KanbanSaveReqVO updateReqVO = randomPojo(KanbanSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> kanbanService.updateKanban(updateReqVO), KANBAN_NOT_EXISTS);
}
@Test
public void testDeleteKanban_success() {
// mock 数据
KanbanDO dbKanban = randomPojo(KanbanDO.class);
kanbanMapper.insert(dbKanban);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbKanban.getId();
// 调用
kanbanService.deleteKanban(id);
// 校验数据不存在了
assertNull(kanbanMapper.selectById(id));
}
@Test
public void testDeleteKanban_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> kanbanService.deleteKanban(id), KANBAN_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetKanbanPage() {
// mock 数据
KanbanDO dbKanban = randomPojo(KanbanDO.class, o -> { // 等会查询到
o.setCode(null);
o.setTitle(null);
o.setImg(null);
o.setRemark(null);
o.setIsEnable(null);
o.setCreateTime(null);
});
kanbanMapper.insert(dbKanban);
// 测试 code 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setCode(null)));
// 测试 title 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setTitle(null)));
// 测试 img 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setImg(null)));
// 测试 remark 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setRemark(null)));
// 测试 isEnable 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setIsEnable(null)));
// 测试 createTime 不匹配
kanbanMapper.insert(cloneIgnoreId(dbKanban, o -> o.setCreateTime(null)));
// 准备参数
KanbanPageReqVO reqVO = new KanbanPageReqVO();
reqVO.setCode(null);
reqVO.setTitle(null);
reqVO.setImg(null);
reqVO.setRemark(null);
reqVO.setIsEnable(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<KanbanDO> pageResult = kanbanService.getKanbanPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbKanban, pageResult.getList().get(0));
}
}

@ -1 +1,23 @@
DELETE FROM "report_go_view_project";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_device";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_formula";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_device_attribute";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_formula_detail";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_gateway";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_iot_organization";
-- 将该删表 SQL 语句,添加到 yudao-module-iot-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "iot_kanban";
-- 将该删表 SQL 语句,添加到 yudao-module-mes-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "mes_machine_component";

@ -1,14 +1,209 @@
CREATE TABLE IF NOT EXISTS "report_go_view_project" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL,
"pic_url" varchar,
"content" varchar,
"status" varchar NOT NULL,
"remark" varchar,
"creator" varchar DEFAULT '',
CREATE TABLE IF NOT EXISTS "iot_device"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"device_config_id" varchar,
"device_code" varchar,
"device_name" varchar,
"device_type" varchar,
"siemens_series" varchar,
"siemens_connect_param" varchar,
"read_cron_type" varchar,
"read_repeat_value" int,
"read_repeat_unit" varchar,
"read_cron" varchar,
"write_cron_type" varchar,
"write_repeat_value" int,
"write_repeat_unit" varchar,
"write_cron" varchar,
"local_persistent" varchar,
"upload_rate" varchar,
"rate_count" int,
"modbus_protocol" varchar,
"modbus_pattern" varchar,
"port_name" varchar,
"modbus_connect_param" varchar,
"modbus_read_addr_gap" varchar,
"is_upload" varchar,
"gateway_id" bigint NOT NULL,
"org_id" bigint NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '物联设备表';
CREATE TABLE IF NOT EXISTS "iot_formula"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar,
"formula_code" varchar,
"formula" varchar,
"result_type" varchar,
"machine_id" bigint NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '计算公式';
CREATE TABLE IF NOT EXISTS "iot_device_attribute"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"attribute_code" varchar NOT NULL,
"address" varchar,
"attribute_name" varchar NOT NULL,
"description" varchar,
"address_type" varchar,
"address_offset" varchar,
"address2_type" varchar,
"address2_offset" varchar,
"group_name" varchar,
"group_id" int,
"security_type" varchar,
"io_status" varchar,
"is_linear_transfer" varchar,
"data_type" varchar,
"unit" varchar,
"in_min_value" varchar,
"in_max_value" varchar,
"out_min_value" varchar,
"out_max_value" varchar,
"out_data_type" varchar,
"siemens_field_precision" int,
"modbus_slave_id" varchar,
"modbus_field_address" varchar,
"modbus_address_type" varchar,
"modbus_field_size" varchar,
"modbus_field_precision" varchar,
"modbus_field_order" varchar,
"source_data_type" varchar,
"transfer_data_type" varchar,
"factor" varchar,
"gateway_id" bigint NOT NULL,
"device_id" bigint NOT NULL,
"org_id" bigint NOT NULL,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '设备属性表';
CREATE TABLE IF NOT EXISTS "iot_formula_detail"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"formula_id" bigint NOT NULL,
"formula_code" varchar,
"name" varchar,
"device_id" bigint NOT NULL,
"attribute_id" bigint NOT NULL,
"attribute_name" varchar NOT NULL,
"address" varchar,
"demo_value" varchar,
"sum_type" varchar,
"sum_range" varchar,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '计算公式明细';
CREATE TABLE IF NOT EXISTS "iot_gateway"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"admin_ip" varchar,
"username" varchar,
"password" varchar,
"gateway_name" varchar,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
"gateway_code" varchar,
"gateway_status" varchar,
"topic" varchar,
PRIMARY KEY ("id")
) COMMENT '网关表';
CREATE TABLE IF NOT EXISTS "iot_iot_organization"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"sort" int,
"worker_user_id" bigint,
"org_id" bigint,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
"name" varchar NOT NULL,
"parent_id" bigint NOT NULL,
"status" int,
"device_type" varchar,
"org_class" varchar,
"machine_type" varchar,
PRIMARY KEY ("id")
) COMMENT 'IOT组织表';
CREATE TABLE IF NOT EXISTS "iot_kanban"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"code" varchar NOT NULL,
"title" varchar NOT NULL,
"view_url" varchar,
"tags" varchar,
"img" varchar,
"remark" varchar,
"is_enable" bit NOT NULL,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint,
PRIMARY KEY ("id")
) COMMENT '物联看板';
CREATE TABLE IF NOT EXISTS "mes_machine_component"
(
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL,
"parent_id" bigint NOT NULL,
"sort" int NOT NULL,
"org_id" bigint NOT NULL,
"serial_code" varchar,
"outgoing_time" varchar,
"outgoing_report" varchar,
"position" varchar,
"standard" varchar,
"remark" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
"status" int NOT NULL,
"component_type" int NOT NULL,
"machine_type" varchar,
PRIMARY KEY ("id")
) COMMENT 'GoView 项目表';
) COMMENT '机台组织';

@ -38,4 +38,10 @@ public interface ErrorCodeConstants {
ErrorCode WORK_TEAM_DETAIL_NOT_EXISTS = new ErrorCode(5_0071, "班组成员不存在");
ErrorCode PRODUCE_REPORT_NOT_EXISTS = new ErrorCode(5_008, "生产报工单不存在");
ErrorCode PRODUCE_REPORT_DETAIL_NOT_EXISTS = new ErrorCode(5_0081, "生产报工明细不存在");
ErrorCode MACHINE_COMPONENT_EXITS_CHILDREN = new ErrorCode(5_008, "生产报工单不存在");
ErrorCode MACHINE_COMPONENT_NOT_EXISTS = new ErrorCode(5_0081, "生产报工明细不存在");
ErrorCode MACHINE_COMPONENT_PARENT_ERROR = new ErrorCode(5_0081, "生产报工明细不存在");
ErrorCode MACHINE_COMPONENT_PARENT_NOT_EXITS = new ErrorCode(5_008, "生产报工单不存在");
ErrorCode MACHINE_COMPONENT_PARENT_IS_CHILD = new ErrorCode(5_0081, "生产报工明细不存在");
ErrorCode MACHINE_COMPONENT_NAME_DUPLICATE = new ErrorCode(5_0081, "生产报工明细不存在");
}

@ -0,0 +1,93 @@
package cn.iocoder.yudao.module.mes.controller.admin.machine;
import org.springframework.web.bind.annotation.*;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;
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.mes.controller.admin.machine.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import cn.iocoder.yudao.module.mes.service.machine.MachineComponentService;
@Tag(name = "管理后台 - 机台")
@RestController
@RequestMapping("/mes/machine-component")
@Validated
public class MachineComponentController {
@Resource
private MachineComponentService machineComponentService;
@PostMapping("/create")
@Operation(summary = "创建机台")
@PreAuthorize("@ss.hasPermission('mes:machine-component:create')")
public CommonResult<Long> createMachineComponent(@Valid @RequestBody MachineComponentSaveReqVO createReqVO) {
return success(machineComponentService.createMachineComponent(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新机台")
@PreAuthorize("@ss.hasPermission('mes:machine-component:update')")
public CommonResult<Boolean> updateMachineComponent(@Valid @RequestBody MachineComponentSaveReqVO updateReqVO) {
machineComponentService.updateMachineComponent(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除机台")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('mes:machine-component:delete')")
public CommonResult<Boolean> deleteMachineComponent(@RequestParam("id") Long id) {
machineComponentService.deleteMachineComponent(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得机台")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:machine-component:query')")
public CommonResult<MachineComponentRespVO> getMachineComponent(@RequestParam("id") Long id) {
MachineComponentDO machineComponent = machineComponentService.getMachineComponent(id);
return success(BeanUtils.toBean(machineComponent, MachineComponentRespVO.class));
}
@GetMapping("/list")
@Operation(summary = "获得机台列表")
@PreAuthorize("@ss.hasPermission('mes:machine-component:query')")
public CommonResult<List<MachineComponentRespVO>> getMachineComponentList(@Valid MachineComponentListReqVO listReqVO) {
List<MachineComponentDO> list = machineComponentService.getMachineComponentList(listReqVO);
return success(BeanUtils.toBean(list, MachineComponentRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出机台 Excel")
@PreAuthorize("@ss.hasPermission('mes:machine-component:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportMachineComponentExcel(@Valid MachineComponentListReqVO listReqVO,
HttpServletResponse response) throws IOException {
List<MachineComponentDO> list = machineComponentService.getMachineComponentList(listReqVO);
// 导出 Excel
ExcelUtils.write(response, "机台.xls", "数据", MachineComponentRespVO.class,
BeanUtils.toBean(list, MachineComponentRespVO.class));
}
}

@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.mes.controller.admin.machine.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 机台列表 Request VO")
@Data
public class MachineComponentListReqVO {
@Schema(description = "装备名称", example = "芋艿")
private String name;
@Schema(description = "父id", example = "24628")
private Long parentId;
@Schema(description = "显示顺序")
private Integer sort;
@Schema(description = "组织机台ID", example = "13753")
private Long orgId;
@Schema(description = "装备SN号")
private String serialCode;
@Schema(description = "出厂日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] outgoingTime;
@Schema(description = "出厂报告")
private String outgoingReport;
@Schema(description = "位置")
private String position;
@Schema(description = "规格")
private String standard;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "状态", example = "1")
private Integer status;
@Schema(description = "组织类型", example = "1")
private Integer componentType;
@Schema(description = "机台类型", example = "1")
private String machineType;
}

@ -0,0 +1,81 @@
package cn.iocoder.yudao.module.mes.controller.admin.machine.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 机台 Response VO")
@Data
@ExcelIgnoreUnannotated
public class MachineComponentRespVO {
@Schema(description = "装备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12527")
@ExcelProperty("装备id")
private Long id;
@Schema(description = "装备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@ExcelProperty("装备名称")
private String name;
@Schema(description = "父id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24628")
@ExcelProperty("父id")
private Long parentId;
@Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("显示顺序")
private Integer sort;
@Schema(description = "组织机台ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13753")
@ExcelProperty("组织机台ID")
private Long orgId;
@Schema(description = "装备SN号")
@ExcelProperty("装备SN号")
private String serialCode;
@Schema(description = "出厂日期")
@ExcelProperty("出厂日期")
private LocalDateTime outgoingTime;
@Schema(description = "出厂报告")
@ExcelProperty("出厂报告")
private String outgoingReport;
@Schema(description = "位置")
@ExcelProperty("位置")
private String position;
@Schema(description = "规格")
@ExcelProperty("规格")
private String standard;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat("mes_machine_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Integer status;
@Schema(description = "组织类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "组织类型", converter = DictConvert.class)
@DictFormat("mes_machine_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Integer componentType;
@Schema(description = "机台类型", example = "1")
@ExcelProperty(value = "机台类型", converter = DictConvert.class)
@DictFormat("mes_org_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String machineType;
}

@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.mes.controller.admin.machine.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 机台新增/修改 Request VO")
@Data
public class MachineComponentSaveReqVO {
@Schema(description = "装备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12527")
private Long id;
@Schema(description = "装备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@NotEmpty(message = "装备名称不能为空")
private String name;
@Schema(description = "父id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24628")
@NotNull(message = "父id不能为空")
private Long parentId;
@Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "显示顺序不能为空")
private Integer sort;
@Schema(description = "组织机台ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13753")
@NotNull(message = "组织机台ID不能为空")
private Long orgId;
@Schema(description = "装备SN号")
private String serialCode;
@Schema(description = "出厂日期")
private LocalDateTime outgoingTime;
@Schema(description = "出厂报告")
private String outgoingReport;
@Schema(description = "位置")
private String position;
@Schema(description = "规格")
private String standard;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
private Integer status;
@Schema(description = "组织类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "组织类型不能为空")
private Integer componentType;
@Schema(description = "机台类型", example = "1")
private String machineType;
}

@ -0,0 +1,92 @@
package cn.iocoder.yudao.module.mes.dal.dataobject.machine;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
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("mes_machine_component")
@KeySequence("mes_machine_component_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MachineComponentDO extends BaseDO {
public static final Long PARENT_ID_ROOT = 0L;
/**
* id
*/
@TableId
private Long id;
/**
*
*/
private String name;
/**
* id
*/
private Long parentId;
/**
*
*/
private Integer sort;
/**
* ID
*/
private Long orgId;
/**
* SN
*/
private String serialCode;
/**
*
*/
private LocalDateTime outgoingTime;
/**
*
*/
private String outgoingReport;
/**
*
*/
private String position;
/**
*
*/
private String standard;
/**
*
*/
private String remark;
/**
*
*
* {@link TODO mes_machine_status }
*/
private Integer status;
/**
*
*
* {@link TODO mes_machine_type }
*/
private Integer componentType;
/**
*
*
* {@link TODO mes_org_type }
*/
private String machineType;
}

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.mes.dal.mysql.machine;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.machine.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface MachineComponentMapper extends BaseMapperX<MachineComponentDO> {
default List<MachineComponentDO> selectList(MachineComponentListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<MachineComponentDO>()
.likeIfPresent(MachineComponentDO::getName, reqVO.getName())
.eqIfPresent(MachineComponentDO::getParentId, reqVO.getParentId())
.eqIfPresent(MachineComponentDO::getSort, reqVO.getSort())
.eqIfPresent(MachineComponentDO::getOrgId, reqVO.getOrgId())
.eqIfPresent(MachineComponentDO::getSerialCode, reqVO.getSerialCode())
.betweenIfPresent(MachineComponentDO::getOutgoingTime, reqVO.getOutgoingTime())
.eqIfPresent(MachineComponentDO::getOutgoingReport, reqVO.getOutgoingReport())
.eqIfPresent(MachineComponentDO::getPosition, reqVO.getPosition())
.eqIfPresent(MachineComponentDO::getStandard, reqVO.getStandard())
.eqIfPresent(MachineComponentDO::getRemark, reqVO.getRemark())
.betweenIfPresent(MachineComponentDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(MachineComponentDO::getStatus, reqVO.getStatus())
.eqIfPresent(MachineComponentDO::getComponentType, reqVO.getComponentType())
.eqIfPresent(MachineComponentDO::getMachineType, reqVO.getMachineType())
.orderByDesc(MachineComponentDO::getId));
}
default MachineComponentDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(MachineComponentDO::getParentId, parentId, MachineComponentDO::getName, name);
}
default Long selectCountByParentId(Long parentId) {
return selectCount(MachineComponentDO::getParentId, parentId);
}
}

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.mes.service.machine;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.machine.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import javax.validation.Valid;
/**
* Service
*
* @author
*/
public interface MachineComponentService {
/**
*
*
* @param createReqVO
* @return
*/
Long createMachineComponent(@Valid MachineComponentSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateMachineComponent(@Valid MachineComponentSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteMachineComponent(Long id);
/**
*
*
* @param id
* @return
*/
MachineComponentDO getMachineComponent(Long id);
/**
*
*
* @param listReqVO
* @return
*/
List<MachineComponentDO> getMachineComponentList(MachineComponentListReqVO listReqVO);
}

@ -0,0 +1,138 @@
package cn.iocoder.yudao.module.mes.service.machine;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.machine.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.dal.mysql.machine.MachineComponentMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class MachineComponentServiceImpl implements MachineComponentService {
@Resource
private MachineComponentMapper machineComponentMapper;
@Override
public Long createMachineComponent(MachineComponentSaveReqVO createReqVO) {
// 校验父id的有效性
validateParentMachineComponent(null, createReqVO.getParentId());
// 校验装备名称的唯一性
validateMachineComponentNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
// 插入
MachineComponentDO machineComponent = BeanUtils.toBean(createReqVO, MachineComponentDO.class);
machineComponentMapper.insert(machineComponent);
// 返回
return machineComponent.getId();
}
@Override
public void updateMachineComponent(MachineComponentSaveReqVO updateReqVO) {
// 校验存在
validateMachineComponentExists(updateReqVO.getId());
// 校验父id的有效性
validateParentMachineComponent(updateReqVO.getId(), updateReqVO.getParentId());
// 校验装备名称的唯一性
validateMachineComponentNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
// 更新
MachineComponentDO updateObj = BeanUtils.toBean(updateReqVO, MachineComponentDO.class);
machineComponentMapper.updateById(updateObj);
}
@Override
public void deleteMachineComponent(Long id) {
// 校验存在
validateMachineComponentExists(id);
// 校验是否有子机台
if (machineComponentMapper.selectCountByParentId(id) > 0) {
throw exception(MACHINE_COMPONENT_EXITS_CHILDREN);
}
// 删除
machineComponentMapper.deleteById(id);
}
private void validateMachineComponentExists(Long id) {
if (machineComponentMapper.selectById(id) == null) {
throw exception(MACHINE_COMPONENT_NOT_EXISTS);
}
}
private void validateParentMachineComponent(Long id, Long parentId) {
if (parentId == null || MachineComponentDO.PARENT_ID_ROOT.equals(parentId)) {
return;
}
// 1. 不能设置自己为父机台
if (Objects.equals(id, parentId)) {
throw exception(MACHINE_COMPONENT_PARENT_ERROR);
}
// 2. 父机台不存在
MachineComponentDO parentMachineComponent = machineComponentMapper.selectById(parentId);
if (parentMachineComponent == null) {
throw exception(MACHINE_COMPONENT_PARENT_NOT_EXITS);
}
// 3. 递归校验父机台,如果父机台是自己的子机台,则报错,避免形成环路
if (id == null) { // id 为空,说明新增,不需要考虑环路
return;
}
for (int i = 0; i < Short.MAX_VALUE; i++) {
// 3.1 校验环路
parentId = parentMachineComponent.getParentId();
if (Objects.equals(id, parentId)) {
throw exception(MACHINE_COMPONENT_PARENT_IS_CHILD);
}
// 3.2 继续递归下一级父机台
if (parentId == null || MachineComponentDO.PARENT_ID_ROOT.equals(parentId)) {
break;
}
parentMachineComponent = machineComponentMapper.selectById(parentId);
if (parentMachineComponent == null) {
break;
}
}
}
private void validateMachineComponentNameUnique(Long id, Long parentId, String name) {
MachineComponentDO machineComponent = machineComponentMapper.selectByParentIdAndName(parentId, name);
if (machineComponent == null) {
return;
}
// 如果 id 为空,说明不用比较是否为相同 id 的机台
if (id == null) {
throw exception(MACHINE_COMPONENT_NAME_DUPLICATE);
}
if (!Objects.equals(machineComponent.getId(), id)) {
throw exception(MACHINE_COMPONENT_NAME_DUPLICATE);
}
}
@Override
public MachineComponentDO getMachineComponent(Long id) {
return machineComponentMapper.selectById(id);
}
@Override
public List<MachineComponentDO> getMachineComponentList(MachineComponentListReqVO listReqVO) {
return machineComponentMapper.selectList(listReqVO);
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.mes.dal.mysql.machine.MachineComponentMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,181 @@
package cn.iocoder.yudao.module.mes.service.machine;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.mes.controller.admin.machine.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import cn.iocoder.yudao.module.mes.dal.mysql.machine.MachineComponentMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link MachineComponentServiceImpl}
*
* @author
*/
@Import(MachineComponentServiceImpl.class)
public class MachineComponentServiceImplTest extends BaseDbUnitTest {
@Resource
private MachineComponentServiceImpl machineComponentService;
@Resource
private MachineComponentMapper machineComponentMapper;
@Test
public void testCreateMachineComponent_success() {
// 准备参数
MachineComponentSaveReqVO createReqVO = randomPojo(MachineComponentSaveReqVO.class).setId(null);
// 调用
Long machineComponentId = machineComponentService.createMachineComponent(createReqVO);
// 断言
assertNotNull(machineComponentId);
// 校验记录的属性是否正确
MachineComponentDO machineComponent = machineComponentMapper.selectById(machineComponentId);
assertPojoEquals(createReqVO, machineComponent, "id");
}
@Test
public void testUpdateMachineComponent_success() {
// mock 数据
MachineComponentDO dbMachineComponent = randomPojo(MachineComponentDO.class);
machineComponentMapper.insert(dbMachineComponent);// @Sql: 先插入出一条存在的数据
// 准备参数
MachineComponentSaveReqVO updateReqVO = randomPojo(MachineComponentSaveReqVO.class, o -> {
o.setId(dbMachineComponent.getId()); // 设置更新的 ID
});
// 调用
machineComponentService.updateMachineComponent(updateReqVO);
// 校验是否更新正确
MachineComponentDO machineComponent = machineComponentMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, machineComponent);
}
@Test
public void testUpdateMachineComponent_notExists() {
// 准备参数
MachineComponentSaveReqVO updateReqVO = randomPojo(MachineComponentSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> machineComponentService.updateMachineComponent(updateReqVO), MACHINE_COMPONENT_NOT_EXISTS);
}
@Test
public void testDeleteMachineComponent_success() {
// mock 数据
MachineComponentDO dbMachineComponent = randomPojo(MachineComponentDO.class);
machineComponentMapper.insert(dbMachineComponent);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbMachineComponent.getId();
// 调用
machineComponentService.deleteMachineComponent(id);
// 校验数据不存在了
assertNull(machineComponentMapper.selectById(id));
}
@Test
public void testDeleteMachineComponent_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> machineComponentService.deleteMachineComponent(id), MACHINE_COMPONENT_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetMachineComponentList() {
// mock 数据
MachineComponentDO dbMachineComponent = randomPojo(MachineComponentDO.class, o -> { // 等会查询到
o.setName(null);
o.setParentId(null);
o.setSort(null);
o.setOrgId(null);
o.setSerialCode(null);
o.setOutgoingTime(null);
o.setOutgoingReport(null);
o.setPosition(null);
o.setStandard(null);
o.setRemark(null);
o.setCreateTime(null);
o.setStatus(null);
o.setComponentType(null);
o.setMachineType(null);
});
machineComponentMapper.insert(dbMachineComponent);
// 测试 name 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setName(null)));
// 测试 parentId 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setParentId(null)));
// 测试 sort 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setSort(null)));
// 测试 orgId 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setOrgId(null)));
// 测试 serialCode 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setSerialCode(null)));
// 测试 outgoingTime 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setOutgoingTime(null)));
// 测试 outgoingReport 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setOutgoingReport(null)));
// 测试 position 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setPosition(null)));
// 测试 standard 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setStandard(null)));
// 测试 remark 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setRemark(null)));
// 测试 createTime 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setCreateTime(null)));
// 测试 status 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setStatus(null)));
// 测试 componentType 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setComponentType(null)));
// 测试 machineType 不匹配
machineComponentMapper.insert(cloneIgnoreId(dbMachineComponent, o -> o.setMachineType(null)));
// 准备参数
MachineComponentListReqVO reqVO = new MachineComponentListReqVO();
reqVO.setName(null);
reqVO.setParentId(null);
reqVO.setSort(null);
reqVO.setOrgId(null);
reqVO.setSerialCode(null);
reqVO.setOutgoingTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setOutgoingReport(null);
reqVO.setPosition(null);
reqVO.setStandard(null);
reqVO.setRemark(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setStatus(null);
reqVO.setComponentType(null);
reqVO.setMachineType(null);
// 调用
List<MachineComponentDO> list = machineComponentService.getMachineComponentList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbMachineComponent, list.get(0));
}
}

@ -119,6 +119,12 @@
<artifactId>yudao-module-mes-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- ERP 相关模块。默认注释,保证编译速度 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-iot-biz</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
<build>

@ -58,5 +58,14 @@ public class DefaultController {
return CommonResult.error(NOT_IMPLEMENTED.getCode(),
"[支付模块 yudao-module-pay - 已禁用][参考 https://doc.iocoder.cn/pay/build/ 开启]");
}
@RequestMapping(value = {"/admin-api/iot/**"})
public CommonResult<Boolean> iot404() {
return CommonResult.error(NOT_IMPLEMENTED.getCode(),
"[iot模块 yudao-module-pay - 已禁用][参考 https://doc.iocoder.cn/pay/build/ 开启]");
}
@RequestMapping(value = {"/admin-api/mes/**"})
public CommonResult<Boolean> mes404() {
return CommonResult.error(NOT_IMPLEMENTED.getCode(),
"[mes模块 yudao-module-pay - 已禁用][参考 https://doc.iocoder.cn/pay/build/ 开启]");
}
}

Loading…
Cancel
Save