liujie
2026-07-21 ecc7c13eec83e39d826fb51f18143fac2bb5f5f1
update
7个文件已添加
347 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TDevice.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TDeviceController.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/mapper/TDeviceMapper.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/query/DevicePageList.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TDeviceService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TDeviceServiceImpl.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TDeviceMapper.xml 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TDevice.java
New file
@@ -0,0 +1,65 @@
package com.ruoyi.other.api.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.web.domain.BasePojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * 设备管理对象
 *
 * @author ruoyi
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_device_management")
@ApiModel(value = "TDevice对象", description = "设备管理")
public class TDevice extends BasePojo {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    @ApiModelProperty(value = "设备名称")
    @TableField("device_name")
    private String deviceName;
    @ApiModelProperty(value = "设备序列号")
    @TableField("serial_no")
    private String serialNo;
    @ApiModelProperty(value = "设备型号")
    @TableField("equipment_model")
    private String equipmentModel;
    @ApiModelProperty(value = "合作商类型")
    @TableField("partner_type")
    private Integer partnerType;
    @ApiModelProperty(value = "合作商ID")
    @TableField("partner_id")
    private Integer partnerId;
    @ApiModelProperty(value = "合作商名称")
    @TableField("partner_name")
    private String partnerName;
    @ApiModelProperty(value = "归属电站ID")
    @TableField("site_id")
    private Integer siteId;
    @ApiModelProperty(value = "归属电站名称")
    @TableField("site_name")
    private String siteName;
    @ApiModelProperty(value = "在线状态(0=不在线,1=在线)")
    @TableField("online_status")
    private Integer onlineStatus;
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TDeviceController.java
New file
@@ -0,0 +1,116 @@
package com.ruoyi.other.controller;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.other.api.domain.TDevice;
import com.ruoyi.other.query.DevicePageList;
import com.ruoyi.other.service.TDeviceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
/**
 * 设备管理前端控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/t-device")
public class TDeviceController {
    @Resource
    private TDeviceService deviceService;
    @RequiresPermissions(value = {"/deviceManagement/list"}, logical = Logical.OR)
    @ResponseBody
    @GetMapping("/pageList")
    @ApiOperation(value = "获取设备列表", tags = {"管理后台-设备管理"})
    public AjaxResult<PageInfo<TDevice>> pageList(DevicePageList pageList) {
        PageInfo<TDevice> pageInfo = deviceService.pageList(pageList);
        return AjaxResult.success(pageInfo);
    }
    @RequiresPermissions(value = {"/deviceManagement/add"}, logical = Logical.OR)
    @ResponseBody
    @PostMapping("/addDevice")
    @ApiOperation(value = "添加设备", tags = {"管理后台-设备管理"})
    @Log(title = "【设备管理】添加设备", businessType = BusinessType.INSERT)
    public AjaxResult addDevice(@RequestBody TDevice device) {
        AjaxResult validateResult = validateDevice(device, null);
        if (validateResult != null) {
            return validateResult;
        }
        if (device.getOnlineStatus() == null) {
            device.setOnlineStatus(1);
        }
        deviceService.save(device);
        return AjaxResult.success();
    }
    @RequiresPermissions(value = {"/deviceManagement/select", "/deviceManagement/update"}, logical = Logical.OR)
    @ResponseBody
    @GetMapping("/getDeviceInfo/{id}")
    @ApiOperation(value = "获取设备详情", tags = {"管理后台-设备管理"})
    public AjaxResult<TDevice> getDeviceInfo(@PathVariable Integer id) {
        return AjaxResult.success(deviceService.getById(id));
    }
    @RequiresPermissions(value = {"/deviceManagement/update"}, logical = Logical.OR)
    @ResponseBody
    @PostMapping("/editDevice")
    @ApiOperation(value = "编辑设备", tags = {"管理后台-设备管理"})
    @Log(title = "【设备管理】编辑设备", businessType = BusinessType.UPDATE)
    public AjaxResult editDevice(@RequestBody TDevice device) {
        if (device.getId() == null) {
            return AjaxResult.error("设备ID不能为空");
        }
        AjaxResult validateResult = validateDevice(device, device.getId());
        if (validateResult != null) {
            return validateResult;
        }
        deviceService.updateById(device);
        return AjaxResult.success();
    }
    @RequiresPermissions(value = {"/deviceManagement/del"}, logical = Logical.OR)
    @ResponseBody
    @DeleteMapping("/delDevice")
    @ApiOperation(value = "删除设备", tags = {"管理后台-设备管理"})
    @Log(title = "【设备管理】删除设备", businessType = BusinessType.DELETE)
    public AjaxResult<TDevice> delDevice(Integer[] id) {
        if (id == null || id.length == 0) {
            return AjaxResult.error("请选择要删除的设备");
        }
        deviceService.removeByIds(Arrays.asList(id));
        return AjaxResult.success();
    }
    private AjaxResult validateDevice(TDevice device, Integer excludeId) {
        if (device == null) {
            return AjaxResult.error("设备信息不能为空");
        }
        if (!StringUtils.hasText(device.getDeviceName())) {
            return AjaxResult.error("设备名称不能为空");
        }
        if (!StringUtils.hasText(device.getSerialNo())) {
            return AjaxResult.error("设备序列号不能为空");
        }
        if (!StringUtils.hasText(device.getEquipmentModel())) {
            return AjaxResult.error("设备型号不能为空");
        }
        if (device.getPartnerId() == null) {
            return AjaxResult.error("合作商不能为空");
        }
        if (deviceService.existsBySerialNo(device.getSerialNo(), excludeId)) {
            return AjaxResult.error("设备序列号已存在");
        }
        return null;
    }
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/mapper/TDeviceMapper.java
New file
@@ -0,0 +1,19 @@
package com.ruoyi.other.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.other.api.domain.TDevice;
import com.ruoyi.other.query.DevicePageList;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * 设备管理 Mapper 接口
 *
 * @author ruoyi
 */
public interface TDeviceMapper extends BaseMapper<TDevice> {
    List<TDevice> pageList(PageInfo<TDevice> pageInfo, @Param("req") DevicePageList pageList);
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/query/DevicePageList.java
New file
@@ -0,0 +1,37 @@
package com.ruoyi.other.query;
import com.ruoyi.common.core.web.page.BasePage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
 * 设备管理分页查询
 *
 * @author ruoyi
 */
@Data
@ApiModel
public class DevicePageList extends BasePage {
    @ApiModelProperty(value = "设备名称")
    private String deviceName;
    @ApiModelProperty(value = "设备序列号")
    private String serialNo;
    @ApiModelProperty(value = "设备型号")
    private String equipmentModel;
    @ApiModelProperty(value = "合作商类型")
    private Integer partnerType;
    @ApiModelProperty(value = "合作商ID")
    private Integer partnerId;
    @ApiModelProperty(value = "归属电站ID")
    private Integer siteId;
    @ApiModelProperty(value = "在线状态(0=不在线,1=在线)")
    private Integer onlineStatus;
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TDeviceService.java
New file
@@ -0,0 +1,18 @@
package com.ruoyi.other.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.other.api.domain.TDevice;
import com.ruoyi.other.query.DevicePageList;
/**
 * 设备管理服务类
 *
 * @author ruoyi
 */
public interface TDeviceService extends IService<TDevice> {
    PageInfo<TDevice> pageList(DevicePageList pageList);
    boolean existsBySerialNo(String serialNo, Integer excludeId);
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TDeviceServiceImpl.java
New file
@@ -0,0 +1,40 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.other.api.domain.TDevice;
import com.ruoyi.other.mapper.TDeviceMapper;
import com.ruoyi.other.query.DevicePageList;
import com.ruoyi.other.service.TDeviceService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/**
 * 设备管理服务实现类
 *
 * @author ruoyi
 */
@Service
public class TDeviceServiceImpl extends ServiceImpl<TDeviceMapper, TDevice> implements TDeviceService {
    @Override
    public PageInfo<TDevice> pageList(DevicePageList pageList) {
        PageInfo<TDevice> pageInfo = new PageInfo<>(pageList.getPageCurr(), pageList.getPageSize());
        List<TDevice> list = this.baseMapper.pageList(pageInfo, pageList);
        pageInfo.setRecords(list);
        return pageInfo;
    }
    @Override
    public boolean existsBySerialNo(String serialNo, Integer excludeId) {
        if (!StringUtils.hasText(serialNo)) {
            return false;
        }
        return this.lambdaQuery()
                .eq(TDevice::getSerialNo, serialNo)
                .ne(excludeId != null, TDevice::getId, excludeId)
                .count() > 0;
    }
}
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TDeviceMapper.xml
New file
@@ -0,0 +1,52 @@
<?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="com.ruoyi.other.mapper.TDeviceMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.other.api.domain.TDevice">
        <id column="id" property="id" />
        <result column="device_name" property="deviceName" />
        <result column="serial_no" property="serialNo" />
        <result column="equipment_model" property="equipmentModel" />
        <result column="partner_type" property="partnerType" />
        <result column="partner_id" property="partnerId" />
        <result column="partner_name" property="partnerName" />
        <result column="site_id" property="siteId" />
        <result column="site_name" property="siteName" />
        <result column="online_status" property="onlineStatus" />
        <result column="del_flag" property="delFlag" />
        <result column="create_time" property="createTime" />
    </resultMap>
    <sql id="Base_Column_List">
        id, device_name, serial_no, equipment_model, partner_type, partner_id, partner_name, site_id, site_name, online_status, del_flag, create_time
    </sql>
    <select id="pageList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from t_device_management
        where del_flag = 0
        <if test="null != req.deviceName and '' != req.deviceName">
            and device_name like CONCAT('%', #{req.deviceName}, '%')
        </if>
        <if test="null != req.serialNo and '' != req.serialNo">
            and serial_no like CONCAT('%', #{req.serialNo}, '%')
        </if>
        <if test="null != req.equipmentModel and '' != req.equipmentModel">
            and equipment_model like CONCAT('%', #{req.equipmentModel}, '%')
        </if>
        <if test="null != req.partnerType">
            and partner_type = #{req.partnerType}
        </if>
        <if test="null != req.partnerId">
            and partner_id = #{req.partnerId}
        </if>
        <if test="null != req.siteId">
            and site_id = #{req.siteId}
        </if>
        <if test="null != req.onlineStatus">
            and online_status = #{req.onlineStatus}
        </if>
        order by create_time desc, id desc
    </select>
</mapper>