设备
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
5be00ca4e2
commit
78f01d39bb
@ -0,0 +1,89 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.device;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import 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.system.controller.admin.device.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.device.DeviceDO;
|
||||
import cn.iocoder.yudao.module.system.service.device.DeviceService;
|
||||
|
||||
@Tag(name = "管理后台 - 设备")
|
||||
@RestController
|
||||
@RequestMapping("/system/device")
|
||||
@Validated
|
||||
public class DeviceController {
|
||||
|
||||
@Resource
|
||||
private DeviceService deviceService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建设备")
|
||||
public CommonResult<Integer> createDevice(@Valid @RequestBody DeviceSaveReqVO createReqVO) {
|
||||
return success(deviceService.createDevice(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新设备")
|
||||
public CommonResult<Boolean> updateDevice(@Valid @RequestBody DeviceSaveReqVO updateReqVO) {
|
||||
deviceService.updateDevice(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除设备")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
public CommonResult<Boolean> deleteDevice(@RequestParam("id") Integer id) {
|
||||
deviceService.deleteDevice(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得设备")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<DeviceRespVO> getDevice(@RequestParam("id") Integer id) {
|
||||
DeviceDO device = deviceService.getDevice(id);
|
||||
return success(BeanUtils.toBean(device, DeviceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得设备分页")
|
||||
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")
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.system.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 = "设备名称", example = "赵六")
|
||||
private String devicename;
|
||||
|
||||
@Schema(description = "设备ID/编号")
|
||||
private String devicecode;
|
||||
|
||||
@Schema(description = "设备类型", example = "1")
|
||||
private String devicetype;
|
||||
|
||||
@Schema(description = "设备位置")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "设备状态(0:待激活 1 在线 2 离线 ,3 禁用 )", example = "2")
|
||||
private Integer devicestatus;
|
||||
|
||||
@Schema(description = "机构ID", example = "25227")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
private String orgname;
|
||||
|
||||
@Schema(description = "设备描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] updatetime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String createby;
|
||||
|
||||
@Schema(description = "更新人")
|
||||
private String updateby;
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.device.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 设备 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class DeviceRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "5161")
|
||||
@ExcelProperty("主键ID")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@ExcelProperty("设备名称")
|
||||
private String devicename;
|
||||
|
||||
@Schema(description = "设备ID/编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("设备ID/编号")
|
||||
private String devicecode;
|
||||
|
||||
@Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("设备类型")
|
||||
private String devicetype;
|
||||
|
||||
@Schema(description = "设备位置")
|
||||
@ExcelProperty("设备位置")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "设备状态(0:待激活 1 在线 2 离线 ,3 禁用 )", example = "2")
|
||||
@ExcelProperty("设备状态(0:待激活 1 在线 2 离线 ,3 禁用 )")
|
||||
private Integer devicestatus;
|
||||
|
||||
@Schema(description = "机构ID", example = "25227")
|
||||
@ExcelProperty("机构ID")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
@ExcelProperty("机构名称")
|
||||
private String orgname;
|
||||
|
||||
@Schema(description = "设备描述", example = "你说的对")
|
||||
@ExcelProperty("设备描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatetime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
@ExcelProperty("创建人")
|
||||
private String createby;
|
||||
|
||||
@Schema(description = "更新人")
|
||||
@ExcelProperty("更新人")
|
||||
private String updateby;
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.device.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 设备新增/修改 Request VO")
|
||||
@Data
|
||||
public class DeviceSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "5161")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotEmpty(message = "设备名称不能为空")
|
||||
private String devicename;
|
||||
|
||||
@Schema(description = "设备ID/编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "设备ID/编号不能为空")
|
||||
private String devicecode;
|
||||
|
||||
@Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotEmpty(message = "设备类型不能为空")
|
||||
private String devicetype;
|
||||
|
||||
@Schema(description = "设备位置")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "设备状态(0:待激活 1 在线 2 离线 ,3 禁用 )", example = "2")
|
||||
private Integer devicestatus;
|
||||
|
||||
@Schema(description = "机构ID", example = "25227")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
private String orgname;
|
||||
|
||||
@Schema(description = "设备描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatetime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String createby;
|
||||
|
||||
@Schema(description = "更新人")
|
||||
private String updateby;
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package cn.iocoder.yudao.module.system.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("tb_device")
|
||||
@KeySequence("tb_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 Integer id;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String devicename;
|
||||
/**
|
||||
* 设备ID/编号
|
||||
*/
|
||||
private String devicecode;
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String devicetype;
|
||||
/**
|
||||
* 设备位置
|
||||
*/
|
||||
private String location;
|
||||
/**
|
||||
* 设备状态(0:待激活 1 在线 2 离线 ,3 禁用 )
|
||||
*/
|
||||
private Integer devicestatus;
|
||||
/**
|
||||
* 机构ID
|
||||
*/
|
||||
private Integer orgid;
|
||||
/**
|
||||
* 机构名称
|
||||
*/
|
||||
private String orgname;
|
||||
/**
|
||||
* 设备描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createtime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatetime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createby;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateby;
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.device;
|
||||
|
||||
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.system.dal.dataobject.device.DeviceDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.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>()
|
||||
.likeIfPresent(DeviceDO::getDevicename, reqVO.getDevicename())
|
||||
.eqIfPresent(DeviceDO::getDevicecode, reqVO.getDevicecode())
|
||||
.eqIfPresent(DeviceDO::getDevicetype, reqVO.getDevicetype())
|
||||
.eqIfPresent(DeviceDO::getLocation, reqVO.getLocation())
|
||||
.eqIfPresent(DeviceDO::getDevicestatus, reqVO.getDevicestatus())
|
||||
.eqIfPresent(DeviceDO::getOrgid, reqVO.getOrgid())
|
||||
.likeIfPresent(DeviceDO::getOrgname, reqVO.getOrgname())
|
||||
.eqIfPresent(DeviceDO::getDescription, reqVO.getDescription())
|
||||
.betweenIfPresent(DeviceDO::getCreatetime, reqVO.getCreatetime())
|
||||
.betweenIfPresent(DeviceDO::getUpdatetime, reqVO.getUpdatetime())
|
||||
.eqIfPresent(DeviceDO::getCreateby, reqVO.getCreateby())
|
||||
.eqIfPresent(DeviceDO::getUpdateby, reqVO.getUpdateby())
|
||||
.orderByDesc(DeviceDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.system.service.device;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.device.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.device.DeviceDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 设备 Service 接口
|
||||
*
|
||||
* @author 全智安
|
||||
*/
|
||||
public interface DeviceService {
|
||||
|
||||
/**
|
||||
* 创建设备
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createDevice(@Valid DeviceSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新设备
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDevice(@Valid DeviceSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDevice(Integer id);
|
||||
|
||||
/**
|
||||
* 获得设备
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 设备
|
||||
*/
|
||||
DeviceDO getDevice(Integer id);
|
||||
|
||||
/**
|
||||
* 获得设备分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 设备分页
|
||||
*/
|
||||
PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.system.service.device;
|
||||
|
||||
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.system.controller.admin.device.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.device.DeviceDO;
|
||||
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.system.dal.mysql.device.DeviceMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 设备 Service 实现类
|
||||
*
|
||||
* @author 全智安
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
@Resource
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
@Override
|
||||
public Integer 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
|
||||
public void deleteDevice(Integer id) {
|
||||
// 校验存在
|
||||
validateDeviceExists(id);
|
||||
// 删除
|
||||
deviceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateDeviceExists(Integer id) {
|
||||
if (deviceMapper.selectById(id) == null) {
|
||||
throw exception(DEVICE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceDO getDevice(Integer id) {
|
||||
return deviceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
|
||||
return deviceMapper.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.system.dal.mysql.device.DeviceMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user